Mesh Representation, part I
description
Transcript of Mesh Representation, part I
Mesh Representation, part I
based on: Data Structures for Graphics, chapter 12 inFundamentals of Computer Graphics, 3rd ed.
(Shirley & Marschner)
1
3D objects
• A single 3D object has a volume that is bounded by 2-dimensional patches (surfaces)
• These 2-dimensional boundary patches are bounded by 1-dimensional features (curves or edges)
• These 1-dimensional features are bounded by 0-dimensional things (points, called vertices)
2
3D objects
facets
edges vertices
3
3D objects
• We typically represent the boundary; the interior is implied to be the bounded subspace
• We will assume linear boundaries here, so we have facets, edges, and vertices (and the interior)
4
Triangle meshes
• Many freeform shapes consist of (many) triangles
5
Triangle meshes
• How are triangles, edges, and vertices allowed to connect?
• How do we represent (store) triangle meshes?• How efficient are such schemes?
6
Manifolds
• A manifold is “watertight”: the interior is separated from the exterior everywhere
• Very locally at every point on the manifold, it “looks like” the very local situation on a sphere
7
Manifolds
• A manifold is “watertight”: the interior is separated from the exterior everywhere
• Very locally at every point on the manifold, it “looks like” the very local situation on a sphere
8
Manifolds
• Technically, we are discussing a 2-manifold in 3D• For any point on the 2-manifold, consider an
arbitrarily small sphere centered at that point, and intersect the sphere boundary with the 2-manifold: this should be one closed loop
9
Manifolds
10
Manifolds
not a manifold manifold11
Triangle meshes for manifolds
• A triangle mesh can be a manifold only if the following two local conditions are satisfied– Every edge is shared by exactly two triangles– Every vertex has a single, complete loop of triangles
around it• A global condition is that the manifold does not
self-intersect
12
Manifolds with boundary
• A disk in 3D space is a manifold with boundary; the boundary is a circle
• Any surface or surface patch is a manifold with boundary if– very locally at any point p, it is like how it is very locally at
some point on a disk (boundary circle or interior) the neighborhood of p is a single closed loop or one non-closed curve
13
Manifolds with boundary
14
Manifolds with boundary
• Manifolds with boundary are not watertight• Self-intersecting surfaces cannot be manifolds with
(nor without) boundary• Surfaces with parts that are thin tentacles cannot be
manifolds with (nor without) boundary
15
Triangle meshes for manifolds with boundary
• A triangle mesh can be a manifold with boundary only if the following two local conditions are satisfied– Every edge is shared by one or two triangles– Every vertex connects to a single edge-connected set of
triangles• A global condition is that the manifold does not self-
intersect
16
Triangle meshes
• For manifolds with or without boundary• Store triangles• Store coordinates of vertices• Possibly store edges, adjacencies of triangles, etc.,
depending on the scheme
9 vertices, 16 edges, and 8 triangles in a triangle mesh
17
Triangle meshes
• Features of the same dimensionality are adjacent or not (two vertices, or two edges, or two triangles)
• Features of different dimensionality are incident or not (vertex-edge, vertex-triangle, edge-triangle)
adjacent edges
adjacent verticesadjacent triangles
18
Triangle meshes
• Features of the same dimensionality are adjacent or not (two vertices, or two edges, or two triangles)
• Features of different dimensionality are incident or not (vertex-edge, vertex-triangle, edge-triangle)
non-adjacent edges
non-adjacent verticesnon-adjacent triangles
19
Triangle meshes
• Features of the same dimensionality are adjacent or not (two vertices, or two edges, or two triangles)
• Features of different dimensionality are incident or not (vertex-edge, vertex-triangle, edge-triangle)
incident vertex and triangle
incident edge and vertexincident edge and triangle
20
Triangle meshes
• Features of the same dimensionality k>0 are adjacent if and only if their boundaries (or their closures) contain the same feature of dimensionality k – 1
• Vertices are adjacent if they are endpoints of some edge (incident on a common edge)
• Features of different dimensionality are incident if the feature with lower dimensionality is a subset of the boundary (or closure) of the feature with higher dimensionality
21
Orientation of triangles
• By convention, triangles of a manifold are oriented so that from the outside, the triangle is counter-clockwise (and seen from the inside it is clockwise)
22
Orientation is not needed for representation, but it may be convenient for coding to use a consistent orientation
Orientation of triangles
• For a manifold with boundary, we can define a front and a back where the front has triangles oriented counter-clockwise
• This only works for orientable surfaces with boundary
Möbius strip23
Non-orientable surfaces
Möbius strip
Klein bottle
non-orientable surface without boundary 24
Triangle mesh schemes (simple)
• Separate triangles mesh• Shared vertex mesh• Indexed triangle mesh• ....
25
Separate triangles mesh
• Each triangle is an object that stores the coordinates of its vertices the same coordinates are stored multiple times
T6T5
T4T3
T2
T1
T7
v7
v6
v5
v4
v3
v2
v1
v8
T3
T2
T1 (x1,y1,z1) (x5,y5,z5) (x6,y6,z6)
(x1,y1,z1) (x5,y5,z5)(x2,y2,z2)
(x3,y3,z3) (x5,y5,z5)(x2,y2,z2)
26
Shared vertex mesh
• Each vertex is an object that stores its coordinates• Each triangle is an object that stores references to its
vertices
T6T5
T4T3
T2
T1
T7
v7
v6
v5
v4
v3
v2
v1
v8 T3
T2
T1
(x1,y1,z1)(x2,y2,z2)(x3,y3,z3)
v1
v2
v3
v1 v5 v6
v1 v2 v5
v2 v3 v5
27
Indexed triangle mesh
• Same as shared vertex mesh but the j-th vertex of the i-th triangle is addressed as Array[ i ][ j ], j = 1,2,3 and i = 1,2, ..., no. of triangles
T6T5
T4T3
T2
T1
T7
v7
v6
v5
v4
v3
v2
v1
v8
28
A[1][1] = 1A[1][2] = 5A[1][3] = 6A[2][1] = 1A[2][2] = 2A[2][3] = 5
(x1,y1,z1)(x2,y2,z2)(x3,y3,z3)
v1
v2
v3
Comparison of simple meshes
• Assume same storage for floats, ints, and pointers:– Separate triangles mesh: 9 nt units for nt triangles– Other two: 3 nv + 3 nt units for nv vertices and nt triangles
• In meshes we roughly have: nt 2 nv
Why? – All triangles have 3 edges, and most of the edges are
incident to 2 triangles. So 3 nt 2 ne– Euler’s formula for connected planar graphs states
nv – ne + nt = 229
Comparison of simple meshes
• Assume same storage for floats, ints, and pointers:– Separate triangles mesh: 9 nt units for nt triangles– Other two: 3 nv + 3 nt units for nv vertices and nt triangles
• In meshes we roughly have: nt 2 nv
• Separate triangles mesh: 18 nv units of storage• Shared or indexed mesh: 9 nv units of storage
30
In-memory versus transfer
• Indexed triangle meshes are the most common in-memory representation of triangle meshes
• For transferring meshes, triangle fans and triangle strips can save bandwidth
T6T5
T4T3
T2
T1
T7
v7
v6
v5v2
v1
v4T12
T10T9 T8
T11
v8
v12
v11
v10v9
v3
31
In-memory versus transfer
• Indexed triangle meshes are the most common in-memory representation of triangle meshes
• For transferring meshes, triangle fans and triangle strips can save bandwidth
T6T5
T4T3
T2
T1
T7
v7
v6
v5
v3
v2
v1
v4T12
T10T9 T8
T11
v8
v12
v11
v10v9
triangle fan
345, 465, 647, 487
435678 means triangles with fan center at 4 and sequence 35678
indexed mesh:
32
In-memory versus transfer
• Indexed triangle meshes are the most common in-memory representation of triangle meshes
• For transferring meshes, triangle fans and triangle strips can save bandwidth
T6T5
T4T3
T2
T1
T7
v7
v6
v5
v3
v2
v1
v4T12
T10T9 T8
T11
v8
v12
v11
v10v9
triangle strip
345, 465, 647, 487
235467(12) means first triangle 235, then 35 with 4, then 54 with 6, then 46 …
indexed mesh:
33
In-memory versus transfer
• Triangle fans/strips use k+2 indices for a fan/strip with k triangles; an indexed mesh would use 3k indices
• We need a decomposition of the mesh into fans or strips
• Strips are often long, fans seldom
T6T5
T4T3
T2
T1
T7
v7
v6
v5
v3
v2
v1
v4T12
T10T9 T8
T11
v8
v12
v11
v10v934
Model with triangle strips shown
35
Efficiency of triangle strips
• Suppose a surface with n triangles can be represented using m triangle strips, then we need n + 2m indices
avg strip length 4 5 6 7 8indices per triangle 1.5 1.4 1.33 1.291.25without strips 3 3 3 3 3
• Minimizing the number of strips is basically a puzzle
36
Connectivity structures for meshes
• Let triangles have direct access to the adjacent triangles– Allows efficient editing of the mesh– Allows neighborhoods on the mesh
to be explored efficiently– Allows paths on the mesh to
be followed efficiently T6T5
T4T3
T2
T1
T7
v7
v6
v5v2
v1
v4
T10T9 T8
T11
v8
v12
v10v9
v3
37
Connectivity structures for meshes
• Let triangles have direct access to the adjacent triangles– Allows efficient editing of the mesh– Allows neighborhoods on the mesh
to be explored efficiently– Allows paths on the mesh to
be followed efficiently
• In an indexed mesh, how do you find the three vertices “opposite” a triangle?(v1, v3, and v7 for the shown triangle)
T6T5
T4T3
T2
T1
T7
v7
v6
v5v2
v1
v4
T10T9 T8
T11
v8
v12
v10v9
v3
38
Triangle neighbor structure
• Take the shared vertex mesh and add a pointer from each triangle to the three adjacent triangles
• Optional: let each vertex have a pointer to one incident triangle
nbr[0]
nbr[2]
nbr[1]
v[2]
v[1]
v[0]Triangle { Triangle nbr[3] Vertex v[3] …}
39
Triangle neighbor structure
• For manifolds with boundary, a triangle at the boundary will have one of its nbr[.] point to NIL, or use index –1 to reference a neighbor(a triangle can also have two edges that are on the boundary of the manifold)
40
Triangle neighbor structure
• How do you find the three vertices opposite a triangle t?
• The adjacent triangles are directly accessed ast.nbr[0], t.nbr[1], and t.nbr[2]
• For t.nbr[0], we determinethe vertex that is not equal to t.v[0] or t.v[1]
• For t.nbr[1] and t.nbr[2] it is analogous
T6T5
T4T3
T2
T1
T7
v7
v6
v5v2
v1
v4
T10T9 T8
T11
v8
v12
v10v9
v3
41
Triangle neighbor structure
• Expressed in algorithmic efficiency notation:– In an indexed mesh, finding opposite vertices for a triangle
takes linear time in the mesh size, O(n)– In a triangle neighbor structure, finding opposite vertices
takes constant time (independent of mesh size), O(1)
42
Triangle neighbor structure
• Storage usage expressed in number of vertices nv:– An indexed mesh uses 9 nv units of storage – A triangle neighbor structure uses 15 nv units of storage
(a triangle uses 6 units and a vertex uses 3 units, and there are roughly twice as many triangles as vertices)
43
Questions: height profile
1. A triangle mesh can be used to represent a terrain, where the third coordinate is height above sea level.
How efficiently can you compute a height profile, a cross-section with a given vertical planea. using an indexed mesh?b. using a triangle neighbor structure?
44
Winged-edge structure
• Stores connectivity at edges instead of triangles• For one edge, say, e1:– Two vertices are important: v4 and v6
– Two triangles are important: T5 and T6
– Four edges are important: e2, e14, e5, and e8
T6T5
T4T3
T2
T1
T7
v7
v6
v5
v4
v3
v2
v1
v8
e7
e6
e5
e4
e3
e2
e1
e8
e12
e11
e10e9
e13
e14
45
Winged-edge structure
• Give e1 a direction, then– v4 is the tail and v6 is the head
– T5 is to the left and T6 is to the right
– e2 is previous on the left side, e14 is next on the left side, e5 is previous on the right side, and e8 is next on the right side
T6T5
T4T3
T2
T1
T7
v7
v6
v5
v4
v3
v2
v1
v8
e7
e6
e5
e4
e3
e2
e1
e8
e12
e11
e10e9
e13
e14
46
Winged-edge structure
• Give e1 a direction, then– v4 is the tail and v6 is the head
– T5 is to the left and T6 is to the right
– e2 is previous on the left side, e14 is next on the left side, e5 is previous on the right side, and e8 is next on the right side
T6T5
v6
v4
e5
e2
e1
e8e14 lnext
left
head
tail
right
lprev
rnext
rprev
47
Winged-edge structure
lnext
left
head
tail
right
lprev
rnext
rprev
Edge { Edge lprev, lnext, rprev, rnext; Vertex head, tail; Triangle left, right}
Vertex { double x, y, z; Edge e; // any incident}
Triangle { Edge e; // any incident}
48
Questions1. The triangle strip savings table shows only the average number
of indices when triangle strips have an average length. We must also transfer the vertices themselves. Assuming that indices and coordinates use the same amount of storage, make a table with the total transfer savings when using triangle strips
2. Analyze how much storage the winged-edge structure needs for a mesh with nv vertices
3. For a given triangle t, write code for reporting the coordinates of its vertices (winged-edge)
4. For a given triangle t, write code for reporting the coordinates of the opposite vertices (winged-edge)
5. For a given vertex v, write code for reporting the coordinates of all the adjacent vertices (winged-edge)
49