General Triangle Models: Representations and Collision

65
General Triangle Models: Representations and Collision David Johnson

description

General Triangle Models: Representations and Collision. David Johnson. Triangle Models. Boundary-representation (B-rep) Collection of surfaces to represent a volume Manifold Closed model Every edge has two triangles. Polygon Modeling. - PowerPoint PPT Presentation

Transcript of General Triangle Models: Representations and Collision

Page 1: General Triangle Models: Representations and Collision

General Triangle Models:Representations and

CollisionDavid Johnson

Page 2: General Triangle Models: Representations and Collision

Triangle Models►Boundary-

representation (B-rep) Collection of

surfaces to represent a volume

►Manifold Closed model Every edge has

two triangles

Page 3: General Triangle Models: Representations and Collision

Polygon Modeling►Polygons are the dominant force

in modeling for real-time graphics►Why?

Page 4: General Triangle Models: Representations and Collision

Polygons Dominate►Everything can be turned into

polygons (almost everything) Normally an error associated with the

conversion, but with time and space it may be possible to reduce this error

►We know how to render polygons quickly

►Many operations are easy to do with polygons

►Memory and disk space is cheap►Simplicity and inertia

Page 5: General Triangle Models: Representations and Collision

What’s Bad About Polygons?►What are some disadvantages of

polygonal representations?

Page 6: General Triangle Models: Representations and Collision

Polygons Aren’t Great► They are always an approximation to curved

surfaces But can be as good as you want, if you are willing

to pay in size Normal vectors are approximate They throw away information

► They can be very unstructured► They are hard to globally parameterize

How do we parameterize them for texture mapping?

► It is difficult to perform many geometric operations

Page 7: General Triangle Models: Representations and Collision

Polygon Meshes► A mesh is a set of polygons connected to

form an object► A mesh has several components, or

geometric entities: Faces Edges, the boundary between faces Vertices, the boundaries between edges, or

where three or more faces meet Normals, Texture coordinates, colors, shading

coefficients, etc► Some components are implicit, given the

others For instance, given faces and vertices can

determine edges

Page 8: General Triangle Models: Representations and Collision

Polygonal Data Structures► Polygon mesh data structures are

application dependent► Different applications require different

operations to be fast Find the neighbor of a given face Find the faces that surround a vertex

► You typically choose: Which features to store explicitly (vertices, faces,

normals, etc) Which relationships you want to be explicit

(vertices belonging to faces, neighbors, faces at a vertex, etc)

Page 9: General Triangle Models: Representations and Collision

Triangle Meshes►We will look at triangle mesh data

structures Can triangulate general polygon

Page 10: General Triangle Models: Representations and Collision

Triangle Soup

►Many models are just lists of triangles What does the model below look like in

a floating point computer?T1: v1, v2, v3T2: v4, v5, v6T3: v7, v8, v9T4: v10, v11, v12etc…

T1

T2 T3

T4T5 T6

Page 11: General Triangle Models: Representations and Collision

Triangle Soup

►No connection between triangles Some models are produced like this, so

may have to work with it

T1: v1, v2, v3T2: v4, v5, v6T3: v7, v8, v9T4: v10, v11, v12etc…

T1

T2 T3

T4T5 T6

Page 12: General Triangle Models: Representations and Collision

Triangle Soup Evaluation►What are the advantages?

It’s very simple to read, write, transmit, etc.

A common output format from CAD modelers

►BIG disadvantage: No higher order information No information about neighbors No open/closed information No guarantees on

degeneracies/manifoldness

Page 13: General Triangle Models: Representations and Collision

Vertex-Face Mesh

► There are reasons not to store the vertices explicitly at each polygon Wastes memory - each vertex repeated many

times Very messy to find neighboring polygons Difficult to ensure that polygons meet correctly

► Solution: Indirection Put all the vertices in a list Each face stores the list indices of its vertices

► Advantages? Disadvantages?

v0

v2

v1v4

v3

v0 v2 v3 v4v1vertices

0 2 1 0 1 4 1 2 3 1 3 4faces

Page 14: General Triangle Models: Representations and Collision

Vertex-Face Evaluation►Advantages:

Saving in storage:►Vertex index might be only 2 bytes, and a

vertex is probably 12 bytes►Each vertex gets used at least 3 and generally

4-6 times, but is only stored once Normals, texture coordinates, colors etc.

can all be stored the same way►Disadvantages:

Connectivity information is not explicit How would you find a neighbor

face/shared vertex?

Page 15: General Triangle Models: Representations and Collision

Add more data►Face data structure

Face:►Neighbors = [find1, find2, find3]►Vertices = [vind1, vind2, vind3]

Vertex:►Coords = [x,y,z]►Neighborfaces = [find1,..,findn];

Page 16: General Triangle Models: Representations and Collision

Some problems►Edges are implicit►Number of neighbors to vertex is

variable►Use vertex-edge-face structures

Winged edge Half-edge

Page 17: General Triangle Models: Representations and Collision

Half-edge►Half-edge

leading vertex Face on left Edge ahead Flipped Edge

►Everything points to one thing

Page 18: General Triangle Models: Representations and Collision

Collision Methods for Triangle Models

►Models may have millions of triangles►For two models with m and n triangles

Brute force: m*n triangle-triangle intersections

> 1012 intersection computations for two objects

►Need an acceleration structure

Page 19: General Triangle Models: Representations and Collision

Bounding Volumes► Objects are often not

colliding Need fast reject for this

case Surround with some

bounding object►Like a sphere

► Why stop with one layer of rejection testing? Build a bounding volume

hierarchy (BVH)►A tree

Page 20: General Triangle Models: Representations and Collision

Bounding Volume Hierarchies► Model Hierarchy:

each node has a simple volume that bounds a set of triangles

children contain volumes that each bound a different portion of the parent’s triangles

The leaves of the hierarchy usually contain individual triangles

► A binary bounding volume hierarchy:

Page 21: General Triangle Models: Representations and Collision

BVH-Based Collision Detection

Page 22: General Triangle Models: Representations and Collision

Type of Bounding Volumes► Spheres► Ellipsoids► Axis-Aligned Bounding Boxes (AABB)► Oriented Bounding Boxes (OBBs)► Convex Hulls► k-Discrete Orientation Polytopes (k-dop)► Spherical Shells ► Swept-Sphere Volumes (SSVs)

Point Swetp Spheres (PSS) Line Swept Spheres (LSS) Rectangle Swept Spheres (RSS) Triangle Swept Spheres (TSS)

Page 23: General Triangle Models: Representations and Collision

Observations► Simple primitives (spheres, AABBs, etc.) do very well

with respect to the overlap cost. But they cannot fit some long skinny primitives tightly.

► More complex primitives (minimal ellipsoids, OBBs, etc.) provide tight fits, but checking for overlap between them is relatively expensive.

► Cost of BV updates needs to be considered.

Page 24: General Triangle Models: Representations and Collision

Trade-off in Choosing BV’s

increasing complexity & tightness of fit

decreasing cost of (overlap tests + BV update)

AABB OBBSphere Convex Hull6-dop

Page 25: General Triangle Models: Representations and Collision

Bounding Volume Hierarchies (Example: Spheres, PSS)

Page 26: General Triangle Models: Representations and Collision

Bounding Volume Hierarchies (Example: AABB)

Page 27: General Triangle Models: Representations and Collision

Bounding Volume Hierarchies (Example: k-DOPs,

k=6,14,18,26)

Level 0

Note: k=6 is a AABB.

Page 28: General Triangle Models: Representations and Collision

Bounding Volume Hierarchies (Example: k-DOPs,

k=6,14,18,26)

Level 1

Page 29: General Triangle Models: Representations and Collision

Bounding Volume Hierarchies (Example: k-DOPs,

k=6,14,18,26)

Level 2

Page 30: General Triangle Models: Representations and Collision

Bounding Volume Hierarchies (Example: k-DOPs,

k=6,14,18,26)

Level 5

Page 31: General Triangle Models: Representations and Collision

Bounding Volume Hierarchies (Example: k-DOPs,

k=6,14,18,26)

Level 8

Page 32: General Triangle Models: Representations and Collision

Building Hierarchies ► Choices of Bounding Volumes

cost function & constraints

► Top-Down vs. Bottom-up speed vs. fitting

► Depth vs. breadth branching factors

► Splitting factors where & how

Page 33: General Triangle Models: Representations and Collision

Sphere-Trees► A sphere-tree is a hierarchy of sets of spheres, used to

approximate an object

► Advantages: Simplicity in checking overlaps between two bounding

spheres Invariant to rotations and can apply the same transformation

to the centers, if objects are rigid

► Shortcomings: Not always the best approximation (esp bad for long, skinny

objects) Lack of good methods on building sphere-trees

Page 34: General Triangle Models: Representations and Collision

Methods for Building Sphere-Trees

► “Tile” the triangles and build the tree bottom-up

► Covering each vertex with a sphere and group them together

► Compute the medial axis and use it as a skeleton for multi-res sphere-covering

► Others……

Page 35: General Triangle Models: Representations and Collision

Building an OBBTree

Recursive top-down construction: partition and refit

Page 36: General Triangle Models: Representations and Collision

Given some polygons,consider their vertices...

Building an OBB Tree

Page 37: General Triangle Models: Representations and Collision

… and an arbitrary line

Building an OBB Tree

Page 38: General Triangle Models: Representations and Collision

Project onto the line

Consider variance ofdistribution on the line

Building an OBB Tree

Page 39: General Triangle Models: Representations and Collision

Different line,different variance

Building an OBB Tree

Page 40: General Triangle Models: Representations and Collision

Maximum Variance

Building an OBB Tree

Page 41: General Triangle Models: Representations and Collision

Minimal Variance

Building an OBB Tree

Page 42: General Triangle Models: Representations and Collision

Given by eigenvectorsof covariance matrixof coordinatesof original points

Building an OBB Tree

Page 43: General Triangle Models: Representations and Collision

Choose bounding boxoriented this way

Building an OBB Tree

Page 44: General Triangle Models: Representations and Collision

Building an OBB Tree: FittingCovariance matrix ofpoint coordinates describesstatistical spread of cloud.

OBB is aligned with directions ofgreatest and least spread (which are guaranteed to be

orthogonal).

Page 45: General Triangle Models: Representations and Collision

Good Box

Building an OBB Tree

Page 46: General Triangle Models: Representations and Collision

Add points:worse Box

Building an OBB Tree

Page 47: General Triangle Models: Representations and Collision

More points:terrible box

Building an OBB Tree

Page 48: General Triangle Models: Representations and Collision

Compute with extremal points only

Building an OBB Tree

Page 49: General Triangle Models: Representations and Collision

“Even” distribution: good box

Building an OBB Tree

Page 50: General Triangle Models: Representations and Collision

“Uneven” distribution: bad box

Building an OBB Tree

Page 51: General Triangle Models: Representations and Collision

Fix: Compute facets of convex hull...

Building an OBB Tree

Page 52: General Triangle Models: Representations and Collision

Better: Integrate over facets

Building an OBB Tree

Page 53: General Triangle Models: Representations and Collision

Building an OBB Tree

… and sample them uniformly

Page 54: General Triangle Models: Representations and Collision

Building an OBB Tree: Summary

OBB Fitting algorithm:

►covariance-based►use of convex hull►not foiled by extreme distributions►O(n log n) fitting time for single BV►O(n log2 n) fitting time for entire tree

Page 55: General Triangle Models: Representations and Collision

Tree Traversal

Disjoint bounding volumes:No possible collision

Page 56: General Triangle Models: Representations and Collision

Overlapping bounding volumes:• split one box into children• test children against other box

Tree Traversal

Page 57: General Triangle Models: Representations and Collision

Tree Traversal

Page 58: General Triangle Models: Representations and Collision

Tree TraversalHierarchy of tests

Page 59: General Triangle Models: Representations and Collision

Separating Axis Theorem

· L is a separating axis for OBBs A & B, since A & B become disjoint intervals under projection onto L

Page 60: General Triangle Models: Representations and Collision

Separating Axis Theorem

Two polytopes A and B are disjoint iff there

exists a separating axis which is:

perpendicular to a face from either or

perpendicular to an edge from each

Page 61: General Triangle Models: Representations and Collision

Implications of TheoremGiven two generic polytopes, each with E

edges and F faces, number of candidate axes to test is:

2F + E2

OBBs have only E = 3 distinct edge directions, and only F = 3 distinct face normals. OBBs need at most 15 axis tests.

Because edge directions and normals each form orthogonal frames, the axis tests are rather simple.

Page 62: General Triangle Models: Representations and Collision

OBB Overlap Test: An Axis Test

sha

bas h h+>L is a separating axis iff:

L

hb

Page 63: General Triangle Models: Representations and Collision

OBB Overlap Test: Axis Test Details

Box centers project to interval midpoints, somidpoint separation is length of vector T’s image.

A

B

nTAT

BT

s

nTT · BAs

Page 64: General Triangle Models: Representations and Collision

OBB Overlap Test: Axis Test Details

► Half-length of interval is sum of box axis images.

n

B

rB

nRnRnR ··· BBBB bbbr 332211

Page 65: General Triangle Models: Representations and Collision

Implementation: RAPID► Available at:

http://www.cs.unc.edu/~geom/OBB► Part of V-COLLIDE:

http://www.cs.unc.edu/~geom/V_COLLIDE

► Thousands of users have ftp’ed the code

► Used for virtual prototyping, dynamic simulation, robotics & computer animation