Spring 2017 CSCI 621: Digital

1.2 Surface Representation & Data Structures

Hao Li http://cs621.hao-li.com 1 Administrative

• No class next Tuesday, due to Siggraph deadline

• Introduction to first programming exercise on Jan 24th

Siggraph Deadline 2013@ILM!

2 Last Time

Geometry Processing

Reconstruction

Rendering

Capture Analysis

Reproduction

Manipulation

3 Geometric Representations

point based quad mesh mesh

implicit surfaces / particles volumetric tetrahedrons4 Geometric Representations

point based quad mesh

Surface Representations

implicit surfaces / particles volumetric tetrahedrons5 High Resolution

6 Large scenes

7 Outline

• Parametric Approximations

• Polygonal Meshes

• Data Structures

8 Parametric Representation

Surface is the range of a function f : IR 2 IR 3, = f() ⇥ S

2D example: A Circle f : [0, 2] IR 2 r cos(t) r f(t)= r sin(t) ⇥

9 Parametric Representation

Surface is the range of a function f : IR 2 IR 3, = f() ⇥ S

2D example: Island coast line f : [0, 2] IR 2 r cos(? t) f(t)= r sin(? t) ⇥

10 Piecewise Approximation

Surface is the range of a function f : IR 2 IR 3, = f() ⇥ S

2D example: Island coast line f : [0, 2] IR 2 r cos(? t) f(t)= r sin(? t) ⇥

11 Polynomial Approximation

Polynomials are computable functions

p p i f(t)= ci t = c˜i i(t) i=0 i=0 Taylor expansion up to degree p p 1 g(h)= g(i)(0) hi + O hp+1 i! i=0 ⇤ ⇥ Error for approximation g by polynomial f

f(t )=g(t ) , 0 t <

12 Polynomial Approximation

Approximation error is O(hp+1)

Improve approximation quality by • increasing p … higher order polynomials • decreasing h … shorter / more segments

Issues (p+1) • smoothness of the target data ( max f ( t ) ) t • smoothness condition between segments

13 Polygonal Meshes

Polygonal meshes are a good compromise 2 • Piecewise linear approximation → error is O(h )

3 6 12 24

25% 6.5% 1.7% 0.4%

14 Polygonal Meshes

Polygonal meshes are a good compromise 2 • Piecewise linear approximation → error is O(h ) • Error inversely proportional to #faces

15 Polygonal Meshes

Polygonal meshes are a good compromise 2 • Piecewise linear approximation → error is O(h ) • Error inversely proportional to #faces • Arbitrary topology surfaces

16 Polygonal Meshes

Polygonal meshes are a good compromise 2 • Piecewise linear approximation → error is O(h ) • Error inversely proportional to #faces • Arbitrary topology surfaces • Piecewise smooth surfaces

17 Polygonal Meshes

Polygonal meshes are a good compromise 2 • Piecewise linear approximation → error is O(h ) • Error inversely proportional to #faces • Arbitrary topology surfaces • Piecewise smooth surfaces • Adaptive sampling

18 Polygonal Meshes

Polygonal meshes are a good compromise 2 • Piecewise linear approximation → error is O(h ) • Error inversely proportional to #faces • Arbitrary topology surfaces • Piecewise smooth surfaces • Adaptive sampling • Efficient GPU-based rendering/processing

19 Outline

• Parametric Approximations

• Polygonal Meshes

• Data Structures

20 Graph Definitions

B A • Graph {V,E} E D F C I H G

J K

21 Graph Definitions

B A • Graph {V,E} E D F • Vertices V = {A,B,C,…,K} C I H G

J K

22 Graph Definitions

B A • Graph {V,E} E D F • Vertices V = {A,B,C,…,K} C • Edges E = {(AB),(AE),(CD),…} I H G

J K

23 Graph Definitions

B A • Graph {V,E} E D F • Vertices V = {A,B,C,…,K} C • Edges E = {(AB),(AE),(CD),…} I H • Faces F = {(ABE),(EBF),(EFIH),…} G

J K

24 Graph Definitions

B A

E Vertex degree or valence: D F C number of incident edges I • deg(A) = 4 H • deg(E) = 5 G

J K

25 Connectivity

Connected: B A Path of edges connecting every two vertices E D F C I H G

J K

26 Connectivity

Connected: B Path of edges connecting A every two vertices E D F C Subgraph: I Graph {V’,E’} is a subgraph of graph H {V,E} if V’ is a subset of V and E’ is a G subset of E incident on V’.

J K

27 Connectivity

Connected: B Path of edges connecting A every two vertices E D F C Subgraph: I Graph {V’,E’} is a subgraph of graph H {V,E} if V’ is a subset of V and E’ is a G subset of E incident on V’.

J K

28 Connectivity

Connected: B Path of edges connecting A every two vertices E D F C Subgraph: I Graph {V’,E’} is a subgraph of graph H {V,E} if V’ is a subset of V and E’ is a G subset of E incident on V’.

K J Connected Components: Maximally connected subgraph

29 Connectivity

Connected: B Path of edges connecting A every two vertices E D F C Subgraph: I Graph {V’,E’} is a subgraph of graph H {V,E} if V’ is a subset of V and E’ is a G subset of E incident on V’.

K J Connected Components: Maximally connected subgraph

30 Graph Embedding

d Embedding: Graph is embedded in R , if d each vertex is assigned a position in R .

2 3 Embedding in R Embedding in R 31 Graph Embedding

d Embedding: Graph is embedded in R , if d each vertex is assigned a position in R .

3 Embedding in R 32 Planar Graph

Planar Graph Graph whose vertices and edges can be 2 embedded in R such that its edges do not intersect

Straight Line Planar Graph Plane Graph Plane Graph

33

Triangulation: B Straight line plane graph where every A face is a triangle

E D F C Why? • simple homogenous data structure I H • efficient rendering G • simplifies algorithms • by definition, triangle is planar K J • any can be triangulated

34 Mesh

• Mesh: straight-line graph 3 embedded in R

• Boundary edge: adjacent to exactly 1 face

• Regular edge: adjacent to exactly 2 faces

• Singular edge: adjacent to more than 2 faces

• Closed mesh: mesh with no boundary edges

35 Polygon

A geometric graph Q =(V,E) d with V = p 0 , p 1 ,..., p n 1 in R , d 2 { } and E = (p0, p1) ...(pn 2, pn 1) { } is called a polygon

A polygon is called • flat, if all edges are on a plane • closed, if p0 = pn 1

36 While digital artists call it Wireframe, …

37 Polygonal Mesh

A set M of finite number of closed Q i if: • Intersection of inner polygonal areas is empty • Intersection of 2 polygons from M is either empty, a point p P or an edge e E 2 2 • Every edge e E belongs to at least one polygon 2 • The set of all edges which belong only to one polygon are called edges of the polygonal mesh and are either empty or form a single closed polygon

38 Polygonal Mesh Notation

= ( v , e , f ) M { i} { j} { k}

geometry v R3 i

39 Polygonal Mesh Notation

= ( v , e , f ) M { i} { j} { k}

geometry v R3 i topology e , f R3 i i

40 Global Topology: Genus

• Genus: Maximal number of closed simple cutting curves that do not disconnect the graph into multiple components. • Or half the maximal number of closed paths that do no disconnect the mesh • Informally, the number of holes or handles

Genus 0 Genus 1 Genus 2 Genus 3

41 Euler Poincaré Formula

• For a closed polygonal mesh of genus g , the relation of the number V of vertices, E of edges, and F of faces is given by Euler’s formula:

V E + F = 2(1 g)

• The term 2(1 g ) is called the Euler characteristic

42 Euler Poincaré Formula

V E + F = 2(1 g) 4 6 + 4 = 2(1 0)

43 Euler Poincaré Formula

V E + F = 2(1 g) 16 32 + 16 = 2(1 1)

44 Average Valence of Closed Triangle Mesh

Theorem: Average vertex degree in a closed manifold triangle mesh is ~6

Proof: Each face has 3 edges and each edge is counted twice: 3F = 2E by Euler’s formula: V+F-E = V+2E/3-E = 2-2g Thus E = 3(V-2+2g)

So average degree = 2E/V = 6(V-2+2g)/V ~6 for large V

45 Euler Consequences

Triangle mesh statistics • F 2V ⇡ • E 3V ⇡ • Average valence = 6

Quad mesh statistics • F V ⇡ • E 2V ⇡ • Average valence = 4

46 Euler Characteristic

Sphere Torus Moebius Strip Klein Bottle

=2 =0 =0 =0

47 How many pentagons?

48 How many pentagons?

Any closed surface of genus 0 consisting only of hexagons and pentagons and where every vertex has valence 3 must have exactly 12 pentagons

49 Two-Manifold Surfaces

Local neighborhoods are disk-shaped

f(D✏[u, v]) = D[f(u, v)]

Guarantees meaningful neighbor enumeration • required by most algorithms

Non-manifold Examples:

50 Outline

• Parametric Approximations

• Polygonal Meshes

• Data Structures

51 Mesh Data Structures

• How to store geometry & connectivity? • compact storage and file formats • Efficient algorithms on meshes • Time-critical operations • All vertices/edges of a face • All incident vertices/edges/faces of a vertex

52 Data Structures

What should be stored? • Geometry: 3D vertex coordinates • Connectivity: Vertex adjacency • Attributes: • normals, color, texture coordinates, etc. • Per Vertex, per face, per edge

53 Data Structures

What should it support? • Rendering • Queries • What are the vertices of face #3? • Is vertex #6 adjacent to vertex #12? • Which faces are adjacent to face #7? • Modifications • Remove/add a vertex/face • Vertex split, edge collapse

54 Data Structures

Different Data Structures: • Time to construct (preprocessing) • Time to answer a query • Random access to vertices/edges/faces • Fast mesh traversal • Fast Neighborhood query • Time to perform an operation • split/merge • Space complexity • Redundancy

55 Data Structures

Different Data Structures: • Different topological data storage • Most important ones are face and edge-based (since they encode connectivity) • Design decision ~ memory/speed trade-off

56 Face Set (STL)

Face: • 3 vertex positions x11 y11 z11 x12 y12 z12 x13 y13 z13

x21 y21 z21 x22 y22 z22 x23 y23 z23 ......

xF1 yF1 zF1 xF2 yF2 zF2 xF3 yF3 zF3

9*4 = 36 B/f (single precision) 72 B/v (Euler Poincaré)

No explicit connectivity

57 Shared Vertex (OBJ,OFF)

Indexed Face List: Vertices Triangles • Vertex: position x1 y1 z1 i11 i12 i13 • Face: Vertex Indices ......

xV yV zV ......

...

iF1 iF2 iF3

12 B/v + 12 B/f = 36B/v

No explicit adjacency info

58 Face-Based Connectivity

Vertex: • position • 1 face

Face: • 3 vertices • 3 face neighbors

64 B/v

No edges: Special case handling for arbitrary polygons 59 Edges always have the same topological structure

Efficient handling of polygons with variable valence

60 (Winged) Edge-Based Connectivity

Vertex: • position • 1 edge

Edge: • 2 vertices • 2 faces • 4 edges 120 B/v

Face: Edges have no orientation: • 1 edges special case handling for neighbors 61 Halfedge-Based Connectivity

Vertex: • position • 1 halfedge

Edge: • 1 vertex • 1 face • 1, 2, or 3 halfedges 96 to 144 B/v

Face: Edges have orientation: No- runtime overhead due to • 1 halfedge arbitrary faces

62 Arbitrary Faces during Modeling

63 One-Ring Traversal

1. Start at vertex

64 One-Ring Traversal

1. Start at vertex 2. Outgoing halfedge

65 One-Ring Traversal

1. Start at vertex 2. Outgoing halfedge 3. Opposite halfedge

66 One-Ring Traversal

1. Start at vertex 2. Outgoing halfedge 3. Opposite halfedge 4. Next halfedge

67 One-Ring Traversal

1. Start at vertex 2. Outgoing halfedge 3. Opposite halfedge 4. Next halfedge 5. Opposite

68 One-Ring Traversal

1. Start at vertex 2. Outgoing halfedge 3. Opposite halfedge 4. Next halfedge 5. Opposite 6. Next 7. …

69 Halfedge datastructure Libraries

CGAL • www.cgal.org • • Free for non-commercial use

OpenMesh • www.openmesh.org • Mesh processing • Free, LGPL license

70 Why Openmesh?

Flexible / Lightweight • Random access to vertices/edges/faces • Arbitrary scalar types • Arrays or lists as underlying kernels

Efficient in space and time • Dynamic memory management for array-based meshes (not in CGAL) • Extendable to specialized kernels for non-manifold meshes (not in CGAL)

Easy to Use

71 Literature

• Textbook: Chapter • http://www.openmesh.org • Kettner, Using generic programming for designing a data structure for polyhedral surfaces, Symp. on Comp. Geom., 1998 • Campagna et al., Directed Edges - A Scalable Representation for Triangle Meshes, Journal of Graphics Tools 4(3), 1998 • Botsch et al., OpenMesh - A generic and efficient polygon mesh data structure, OpenSG Symp. 2002

72 TODO

Learn the terms and notations

73 Next Next Time

• Explicit & Implicit Surfaces

• Exercise 1: Getting Started with Mesh Processing

74 http://cs621.hao-li.com

Thanks!

75