Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is...
Transcript of Meshing and Geometry - khu.ac.krcvlab.khu.ac.kr/gl7.pdfPolygons (1/2) Definition Object that is...
Meshing and Geometry
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
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
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
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
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
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
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
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
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
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
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
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
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