Document

advertisement
Mesh Representation, part I
based on:
Data Structures for Graphics, chapter 12 in
Fundamentals 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
manifold
11
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 S 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 necessarily 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 selfintersect
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 triangles
adjacent vertices
adjacent edges
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 triangles
non-adjacent vertices
non-adjacent edges
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 edge and triangle
incident edge and vertex
incident vertex and triangle
20
Orientation of triangles
• By convention, triangles of a manifold are oriented
so that from the outside, the triangle is counterclockwise (and seen from the inside it is clockwise)
21
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 strip
22
Non-orientable surfaces
Klein bottle
Möbius strip
non-orientable surface
without boundary
23
Triangle mesh schemes (simple)
•
•
•
•
Separate triangles mesh
Shared vertex mesh
Indexed triangle mesh
....
24
Separate triangles mesh
• Each triangle is an object that stores the coordinates
of its vertices
 the same coordinates are stored multiple times
v6
v1
v2
v7
T1
T2
v5
T3
v3
T4
T5
T6
T2 (x1,y1,z1) (x2,y2,z2) (x5,y5,z5)
T3 (x2,y2,z2) (x3,y3,z3) (x5,y5,z5)
T7
v4
T1 (x1,y1,z1) (x5,y5,z5) (x6,y6,z6)
v8




25
Shared vertex mesh
• Each vertex is an object that stores its three coordinates
• Each triangle is an object that stores references to its
vertices
v1 (x1,y1,z1)
v2 (x2,y2,z2)
v3 (x3,y3,z3)
v6
v1
v2
v7
T1
T2
v5
T3
v3
T4
T5 T6
T7
v4
v8
T1
v1 v5 v6
T2
v1 v2 v5
T3


v2 v3 v5




26
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
v6
v1
v2
v7
T1
T2
v5
T3
v3
T4
T5 T6
T7
v4
v8
A[1][1] = 1
A[1][2] = 5
A[1][3] = 6
A[2][1] = 1
A[2][2] = 2
A[2][3] = 5


v1 (x1,y1,z1)
v2 (x2,y2,z2)
v3 (x3,y3,z3)


27
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 = 2
28
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
29
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
v12
v6
v1
v2
T11
T1
v7
T6
T
5
T2
v5
v4 T7 T12
T3 T4
T10 v8
T9 T8
v3
v10
v
9
v11
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
v12
v6
v1
v2
T11
T1
v7
T6
T
5
T2
v5
v4 T7 T12
T3 T4
T10 v8
T9 T8
v3
v10
v
9
indexed mesh:
345, 465, 647, 487
v11
triangle fan
435678 means triangles
with fan center at 4 and
sequence 35678
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
v12
v6
v1
v2
T11
T1
v7
T6
T
5
T2
v5
v4 T7 T12
T3 T4
T10 v8
T9 T8
v3
v10
v
9
indexed mesh:
345, 465, 647, 487
v11
triangle strip
235467(12) means first
triangle 235, then 35 with 4,
then 54 with 6, then 46 32…
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
v
12
v6
v1
v2
T1
T2
v5
T3
v3
T5
T11
T6
v4
T4
T9
T8
v9
T7
T10
v7
v11
T12
v8
v10
33
Model with triangle strips shown
34
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
indices per triangle
without strips
4
1.5
3
5
1.4
3
6
1.33
3
7
1.29
3
8
1.25
3
• Minimizing the number of strips is basically a puzzle
35
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
v1
be followed efficiently
v2
v12
v6
T11
T1
T2
T3
v3
T5 T6
v5
v4
T4
T9
T8
v9
v7
T7
v8
T10
v10
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
v1
be followed efficiently
v2
v12
v6
T2
T11
T1
• In an indexed mesh,
T3
how do you find the three
v3
vertices “opposite” a triangle?
(v1, v3, and v7 for the shown triangle)
T5 T6
v5
v4
T4
T9
T8
v9
v7
T7
v8
T10
v10
37
Triangle neighbor structure
• Take the shared vertex mesh and add a pointer from
each triangle to the three adjacent triangles
• Optional: let a vertex have a pointer to one incident
triangle
Triangle {
Triangle nbr[3]
Vertex v[3]
…
}
v[0]
nbr[2]
v[2]
nbr[0]
nbr[1]
v[1]
38
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)
39
Triangle neighbor structure
• How do you find the three vertices opposite a
triangle t?
• The adjacent triangles are directly accessed as
t.nbr[0], t.nbr[1], and t.nbr[2]
v12
v6
T11 v
• For t.nbr[0], we determine
v1
7
T1 T T6
the vertex that is not equal
5
T2
v
5
v4 T7
to t.v[0] or t.v[1]
v2
T3 T4
v8
• For t.nbr[1] and t.nbr[2]
T10
T9 T8
it is analogous
v
3
v9
v10
40
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)
41
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)
42
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 plane
a. using an indexed mesh?
b. using a triangle neighbor structure?
43
Winged-edge structure
• Stores connectivity at edges instead of vertices
• 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
e7
e3
e11
e8
e12 e14
e9
e4
v6
e2
e13
e1
e5
e6
v1
e10
v2
T2
T1 T
v5 5
T3
T4
v3
v7
T6
T7
v4
v8
44
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
e7
e3
e11
e8
e12 e14
e9
e4
v6
e2
e13
e1
e5
e6
v1
e10
v2
T2
T1 T
v5 5
T3
T4
v3
v7
T6
T7
v4
v8
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
head
v6
rnext
e8
e14
lnext
T6
right
e1
T5
left
e5
rprev
e2
lprev
v4
46
tail
Winged-edge structure
Edge {
Edge lprev, lnext, rprev, rnext;
Vertex head, tail;
Face left, right
}
Vertex {
double x, y, z;
Edge e; // any incident
}
head
lnext
rnext
right
left
rprev
lprev
tail
Triangle {
Edge e; // any incident
}
47
Questions
1. 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
4. For a given triangle t, write code for reporting the coordinates
of the opposite vertices
5. For a given vertex v, write code for reporting the coordinates
48
of all the adjacent vertices
Download