Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is...

54
Meshing and Geometry

Transcript of Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is...

Page 1: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Meshing and Geometry

Page 2: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Points in OpenGL

glBegin(GL_POINTS);

glVertex2fv(p0);

glVertex2fv(p1);

glVertex2fv(p2);

glVertex2fv(p3);

glVertex2fv(p4);

glVertex2fv(p5);

glVertex2fv(p6);

glVertex2fv(p7);

glEnd();

p0 p1

p2

p3

p4

p5

p6

p7

Page 3: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Lines in OpenGL (1/3)

Line Segments glBegin(GL_LINES);

glVertex2fv(p0);

glVertex2fv(p1);

glVertex2fv(p2);

glVertex2fv(p3);

glVertex2fv(p4);

glVertex2fv(p5);

glVertex2fv(p6);

glVertex2fv(p7);

glEnd();

p0 p1

p2

p3

p4

p5

p6

p7

Page 4: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Lines in OpenGL (2/3)

Polylines – Line Strip glBegin(GL_LINE_STRIP);

glVertex2fv(p0);

glVertex2fv(p1);

glVertex2fv(p2);

glVertex2fv(p3);

glVertex2fv(p4);

glVertex2fv(p5);

glVertex2fv(p6);

glVertex2fv(p7);

glEnd();

p0 p1

p2

p3

p4

p5

p6

p7

Page 5: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Lines in OpenGL (3/3)

Polylines – Line Loop glBegin(GL_LINE_LOOP);

glVertex2fv(p0);

glVertex2fv(p1);

glVertex2fv(p2);

glVertex2fv(p3);

glVertex2fv(p4);

glVertex2fv(p5);

glVertex2fv(p6);

glVertex2fv(p7);

glEnd();

p0 p1

p2

p3

p4

p5

p6

p7

Page 6: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Polygons (1/2)

Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Simple Polygon No pair of edges of a polygon cross each other

Simple Nonsimple

Page 7: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Polygons (2/2)

Convexity If all points on the line segment between any two points inside the object, or on its boundary, are inside the object

Convex Objects

p1

p2

Page 8: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Polygons in OpenGL (1/6)

Polygon glBegin(GL_POLYGON);

glVertex2fv(p0);

glVertex2fv(p1);

glVertex2fv(p2);

glVertex2fv(p3);

glVertex2fv(p4);

glVertex2fv(p5);

glVertex2fv(p6);

glVertex2fv(p7);

glEnd();

p0 p1

p2

p3

p4

p5

p6

p7

Page 9: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Polygons in OpenGL (2/6)

Quadrilaterals glBegin(GL_QUADS);

glVertex2fv(p0);

glVertex2fv(p1);

glVertex2fv(p2);

glVertex2fv(p3);

glVertex2fv(p4);

glVertex2fv(p5);

glVertex2fv(p6);

glVertex2fv(p7);

glEnd();

p0 p1

p2

p3

p4

p5

p6

p7

Page 10: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Polygons in OpenGL (3/6)

Quadstrip glBegin(GL_QUAD_STRIP);

glVertex2fv(p1);

glVertex2fv(p2);

glVertex2fv(p3);

glVertex2fv(p0);

glVertex2fv(p4);

glVertex2fv(p7);

glVertex2fv(p5);

glVertex2fv(p6);

glEnd();

p0 p1

p2

p3

p4

p5

p6

p7

Page 11: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Polygons in OpenGL (4/6)

Triangles glBegin(GL_TRIANGLES);

glVertex2fv(p0);

glVertex2fv(p1);

glVertex2fv(p2);

glVertex2fv(p3);

glVertex2fv(p4);

glVertex2fv(p5);

glVertex2fv(p6);

glVertex2fv(p7);

glEnd();

p0 p1

p2

p3

p4

p5

p6

p7

Page 12: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Polygons in OpenGL (5/6)

Triangle Strip glBegin(GL_TRIANGLE_STRIP);

glVertex2fv(p0);

glVertex2fv(p7);

glVertex2fv(p1);

glVertex2fv(p6);

glVertex2fv(p2);

glVertex2fv(p5);

glVertex2fv(p3);

glVertex2fv(p4);

glEnd();

p0 p1

p2

p3

p4

p5

p6

p7

Page 13: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Polygons in OpenGL (6/6)

Triangle Fan glBegin(GL_TRIANGLE_FAN);

glVertex2fv(p0);

glVertex2fv(p1);

glVertex2fv(p2);

glVertex2fv(p3);

glVertex2fv(p4);

glVertex2fv(p5);

glVertex2fv(p6);

glVertex2fv(p7);

glEnd();

p0 p1

p2

p3

p4

p5

p6

p7

Page 14: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

triangle code

void triangle( point a, point b, point c)

{

glBegin(GL_POLYGON);

glVertex3fv(a);

glVertex3fv(b);

glVertex3fv(c);

glEnd();

}

Page 15: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

subdivision code

void divide_triangle(point a, point b, point c, int

m)

{

point v1, v2, v3;

int j;

if(m>0)

{

for(j=0; j<3; j++) v1[j]=(a[j]+b[j])/2;

for(j=0; j<3; j++) v2[j]=(a[j]+c[j])/2;

for(j=0; j<3; j++) v3[j]=(b[j]+c[j])/2;

divide_triangle(a, v1, v2, m-1);

divide_triangle(c, v2, v3, m-1);

divide_triangle(b, v3, v1, m-1);

}

else(triangle(a,b,c));

}

Page 16: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

tetrahedron code

void tetrahedron( int m)

{

glColor3f(1.0,0.0,0.0);

divide_triangle(v[0], v[1], v[2], m);

glColor3f(0.0,1.0,0.0);

divide_triangle(v[3], v[2], v[1], m);

glColor3f(0.0,0.0,1.0);

divide_triangle(v[0], v[3], v[1], m);

glColor3f(0.0,0.0,0.0);

divide_triangle(v[0], v[2], v[3], m);

}

Page 17: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Almost Correct

Because the triangles are drawn in the order they are defined in the program, the front triangles are not always rendered in front of triangles behind them

get this

want this

Page 18: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Hidden-Surface Removal

We want to see only those surfaces in front of other surfaces

OpenGL uses a hidden-surface method called the z-buffer algorithm that saves depth information as objects are rendered so that only the front objects appear in the image

Page 19: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Using the z-buffer algorithm

The algorithm uses an extra buffer, the z-buffer, to store depth information as geometry travels down the pipeline

It must be Requested in main.c

-glutInitDisplayMode

(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH)

Enabled in init.c -glEnable(GL_DEPTH_TEST)

Cleared in the display callback -glClear(GL_COLOR_BUFFER_BIT |

GL_DEPTH_BUFFER_BIT)

Page 20: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Meshlab

1. Model loading (points, edges, meshes)

2. Orthographic

3. Shader

4. Filters (Smoothing)

5. Lighting (Ctrl+shift+left mouse)

Page 21: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Delaunay triangulation

1. For any triangle in Delaunay triangulation, the circle passing through its three vertices has no other vertices in its interior.

2. For any edge in the Delaunay triangulation, there is no circle passing through the endpoints (vertices) of this edge that includes another vertex in its interior.

3. If we consider the set of angles of all the triangles in a triangulation, the Delaunay triangulation has the greatest minimum angle.

Page 22: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Delaunay triangulation

Page 23: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Delaunay triangulation

Page 24: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)

Delaunay triangulation

- The act of flipping one edge can require the

flipping of other edges

- The triangulation has a O(n log n) complexity

Page 25: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 26: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 27: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 28: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 29: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 30: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 31: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 32: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 33: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 34: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 35: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 36: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 37: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 38: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 39: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 40: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 41: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 42: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 43: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 44: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 45: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 46: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 47: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 48: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 49: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 50: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 51: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 52: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)
Page 54: Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is closed as a line loop, but that has an interior (Fill is guaranteed for convex polygon)