48
Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides by Marc van Kreveld 1

Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

Embed Size (px)

Citation preview

Page 1: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

Mesh Representation, part I

based on: Data Structures for Graphics, chapter 12 inFundamentals of Computer Graphics, 3rd ed.

(Shirley & Marschner)Slides by Marc van Kreveld

1

Page 2: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

Page 3: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

3D objects

facets

edges vertices

3

Page 4: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

Page 5: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

Triangle meshes

• Many freeform shapes consist of (many) triangles

5

Page 6: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

Triangle meshes

• How are triangles, edges, and vertices allowed to connect?

• How do we represent (store) triangle meshes?• How efficient are such schemes?

6

Page 7: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

Page 8: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

Page 9: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

Page 10: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

Manifolds

10

Page 11: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

Manifolds

not a manifold manifold11

Page 12: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

Page 13: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

Page 14: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

Manifolds with boundary

14

Page 15: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

Page 16: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

Page 17: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

Page 18: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

Triangle meshes

• Features of the same dimensionality are adjacent or not (two vertices, or two edges, or two triangles)– two vertices are adjacent if they are connected by an edge– two edges are adjacent if they have a common vertex– two triangles are adjacent if they share an edge

adjacent edges

adjacent verticesadjacent triangles

18

Page 19: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

Triangle meshes

• Features of the same dimensionality are adjacent or not (two vertices, or two edges, or two triangles)– two vertices are adjacent if they are connected by an edge– two edges are adjacent if they have a common vertex– two triangles are adjacent if they share an edge

non-adjacent edges

non-adjacent verticesnon-adjacent triangles

19

Page 20: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

Triangle meshes

• Features of different dimensionality are incident or not (vertex-edge, vertex-triangle, edge-triangle), incident if one feature is in the boundary (closure) of the other feature

incident vertex and triangle

incident edge and vertexincident edge and triangle

20

Page 21: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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)

21

Page 22: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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 strip22

Page 23: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

Non-orientable surfaces

Möbius strip

Klein bottle

non-orientable surface without boundary 23

Page 24: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

Triangle mesh schemes (simple)

• Separate triangles mesh• Shared vertex mesh• Indexed triangle mesh• ....

24

Page 25: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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)

25

Page 26: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

Shared vertex mesh

• Each vertex is an object that stores its three 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

26

Page 27: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

27

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

Page 28: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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 = 228

Page 29: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

Page 30: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

30

Page 31: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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:

31

Page 32: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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:

32

Page 33: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

v10v933

Page 34: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

Model with triangle strips shown

34

Page 35: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

35

Page 36: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

36

Page 37: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

37

Page 38: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

nbr[0]

nbr[2]

nbr[1]

v[2]

v[1]

v[0]Triangle { Triangle nbr[3] Vertex v[3] …}

38

Page 39: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

Page 40: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

40

Page 41: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

Page 42: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

Page 43: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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?

43

Page 44: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

Winged-edge structure

• Stores connectivity at edges instead of at 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

44

Page 45: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

45

Page 46: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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

46

Page 47: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

Winged-edge structure

lnext

left

head

tail

right

lprev

rnext

rprev

Edge { Edge lprev, lnext, rprev, rnext; Vertex head, tail; Face left, right}

Vertex { double x, y, z; Edge e; // any incident}

Triangle { Edge e; // any incident}

47

Page 48: Mesh Representation, part I based on: Data Structures for Graphics, chapter 12 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides

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 (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) 48