Meshing and Geometry
Points in OpenGL glbegin(gl_points); glvertex2fv(p0); glvertex2fv(p1); p7 p0 p1 glvertex2fv(p2); glvertex2fv(p3); p6 p2 glvertex2fv(p4); glvertex2fv(p5); p5 p3 glvertex2fv(p6); glvertex2fv(p7); p4 glend();
Lines in OpenGL (1/3) Line Segments glbegin(gl_lines); glvertex2fv(p0); glvertex2fv(p1); p7 p0 p1 glvertex2fv(p2); glvertex2fv(p3); glvertex2fv(p4); p6 p2 glvertex2fv(p5); glvertex2fv(p6); p5 p3 glvertex2fv(p7); glend(); p4
Lines in OpenGL (2/3) Polylines Line Strip glbegin(gl_line_strip); glvertex2fv(p0); glvertex2fv(p1); p7 p0 p1 glvertex2fv(p2); glvertex2fv(p3); glvertex2fv(p4); p6 p2 glvertex2fv(p5); glvertex2fv(p6); glvertex2fv(p7); glend(); p5 p4 p3
Lines in OpenGL (3/3) Polylines Line Loop glbegin(gl_line_loop); glvertex2fv(p0); glvertex2fv(p1); p7 p0 p1 glvertex2fv(p2); glvertex2fv(p3); glvertex2fv(p4); p6 p2 glvertex2fv(p5); glvertex2fv(p6); glvertex2fv(p7); glend(); p5 p4 p3
Definition Polygons (1/2) 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
Convexity Polygons (2/2) If all points on the line segment between any two points inside the object, or on its boundary, are inside the object p1 p2 Convex Objects
Polygons in OpenGL (1/6) Polygon glbegin(gl_polygon); glvertex2fv(p0); glvertex2fv(p1); p7 p0 p1 glvertex2fv(p2); glvertex2fv(p3); glvertex2fv(p4); p6 p2 glvertex2fv(p5); glvertex2fv(p6); glvertex2fv(p7); glend(); p5 p4 p3
Polygons in OpenGL (2/6) Quadrilaterals glbegin(gl_quads); glvertex2fv(p0); glvertex2fv(p1); p7 p0 p1 glvertex2fv(p2); glvertex2fv(p3); glvertex2fv(p4); p6 p2 glvertex2fv(p5); glvertex2fv(p6); glvertex2fv(p7); glend(); p5 p4 p3
Polygons in OpenGL (3/6) Quadstrip glbegin(gl_quad_strip); glvertex2fv(p1); glvertex2fv(p2); p7 p0 p1 glvertex2fv(p3); glvertex2fv(p0); glvertex2fv(p4); p6 p2 glvertex2fv(p7); glvertex2fv(p5); glvertex2fv(p6); glend(); p5 p4 p3
Polygons in OpenGL (4/6) Triangles glbegin(gl_triangles); glvertex2fv(p0); glvertex2fv(p1); p7 p0 p1 glvertex2fv(p2); glvertex2fv(p3); glvertex2fv(p4); p6 p2 glvertex2fv(p5); glvertex2fv(p6); glvertex2fv(p7); glend(); p5 p4 p3
Polygons in OpenGL (5/6) Triangle Strip glbegin(gl_triangle_strip); glvertex2fv(p0); glvertex2fv(p7); p7 p0 p1 glvertex2fv(p1); glvertex2fv(p6); glvertex2fv(p2); p6 p2 glvertex2fv(p5); glvertex2fv(p3); glvertex2fv(p4); glend(); p5 p4 p3
Polygons in OpenGL (6/6) Triangle Fan glbegin(gl_triangle_fan); glvertex2fv(p0); glvertex2fv(p1); p7 p0 p1 glvertex2fv(p2); glvertex2fv(p3); glvertex2fv(p4); p6 p2 glvertex2fv(p5); glvertex2fv(p6); glvertex2fv(p7); glend(); p5 p4 p3
triangle code void triangle( point a, point b, point c) { glbegin(gl_polygon); glvertex3fv(a); glvertex3fv(b); glvertex3fv(c); glend(); }
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)); }
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); }
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
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
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)
Meshlab 1. Model loading (points, edges, meshes) 2. Orthographic 3. Shader 4. Filters (Smoothing) 5. Lighting (Ctrl+shift+left mouse)
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.
Delaunay triangulation
Delaunay triangulation
Delaunay triangulation - The act of flipping one edge can require the flipping of other edges - The triangulation has a O(n log n) complexity
https://www.youtube.com/watch?v=1uyi8t5dvf0 https://www.youtube.com/watch?v=_1m4t73l4ee https://www.youtube.com/watch?v=xzmg0grxhye