03 Pengenalan Open GL
03 Pengenalan Open GL
Implicit Surfaces
Polygon
Polygon Meshes
Meshes
Parametric
Parametric Surfaces
Surfaces
Implicit
Implicit Surfaces
Surfaces
Constructive
Constructive Solid
Solid Geometry
Geometry
10/01/02
Modeling Complex Shapes
• We want to build models of very complicated
objects
• An equation for a sphere is possible, but how
about an equation for a telephone, or a face?
• Complexity is achieved using simple pieces
– polygons, parametric surfaces, or implicit surfaces
• Goals
– Model anything with arbitrary precision (in principle)
– Easy to build and modify
– Efficient computations (for rendering, collisions, etc.)
– Easy to implement (a minor consideration...)
2
What do we need from shapes
in Computer Graphics?
3
Curve Representations
Polygon Meshes
Parametric Surfaces
Implicit Surfaces
4
Polygon Meshes
• Any shape can be modeled out of
polygons
– if you use enough of them…
• Polygons with how many sides?
– Can use triangles, quadrilaterals, pentagons, … n-
gons
– Triangles are most common.
– When > 3 sides are used, ambiguity about what to do
when polygon nonplanar, or concave, or self-
intersecting.
• Polygon meshes are built out of
– vertices (points)
– edges (line segments between vertices) edges
faces
– faces (polygons bounded by edges)
5 vertices
Polygon Models in OpenGL
• for faceted shading • for smooth shading
glNormal3fv(n); glBegin(GL_POLYGONS);
glBegin(GL_POLYGONS); glNormal3fv(normal1);
glVertex3fv(vert1); glVertex3fv(vert1);
glVertex3fv(vert2); glNormal3fv(normal2);
glVertex3fv(vert3); glVertex3fv(vert2);
glEnd(); glNormal3fv(normal3);
glVertex3fv(vert3);
glEnd();
6
Normals
7
Where Meshes Come From
• Specify manually
– Write out all polygons
– Write some code to generate them
– Interactive editing: move vertices in space
8
Data Structures for Polygon Meshes
• Simplest (but dumb)
– float triangle[n][3][3]; (each triangle stores 3 (x,y,z) points)
– redundant: each vertex stored multiple times
• Vertex List, Face List
– List of vertices, each vertex consists of (x,y,z) geometric (shape)
info only
– List of triangles, each a triple of vertex id’s (or pointers) topological
(connectivity, adjacency) info only
Fine for many purposes, but finding the faces adjacent to a vertex
takes O(F) time for a model with F faces. Such queries are
important for topological editing.
• Fancier schemes:
Store more topological info so adjacency queries can be answered in
O(1) time.
Winged-edge data structure – edge structures contain all topological
info (pointers to adjacent vertices, edges, and faces).
9
A File Format for Polygon Models: OBJ
# OBJ file for a 2x2x2 cube
v -1.0 1.0 1.0 - vertex 1
v -1.0 -1.0 1.0 - vertex 2
v 1.0 -1.0 1.0 - vertex 3
v 1.0 1.0 1.0 - …
v -1.0 1.0 -1.0
v -1.0 -1.0 -1.0
v 1.0 -1.0 -1.0 Syntax:
v 1.0 1.0 -1.0
f 1 2 3 4 v x y z - a vertex at (x,y,z)
f 8 7 6 5
f 4 3 7 8
f 5 1 4 8 f v1 v2 … vn
f 5 6 2 1 a face with vertices v1, v2, … vn
f 2 6 7 3
# anything - comment
10
How Many Polygons to Use?
11
Why Level of Detail?
• Different models for near and far objects
• Different models for rendering and collision detection
• Compression of data recorded from the real world
12
Problems with Triangular Meshes?
• Need a lot of polygons to represent smooth shapes
• Need a lot of polygons to represent detailed shapes
• Hard to edit
• Need to move individual vertices
• Intersection test? Inside/outside test?
13
Curve Representations
Polygon Meshes
Parametric Surfaces
Implicit Surfaces
14
Parametric Surfaces
p(u,v) = [x(u,v), y(u,v), z(u,v)]
bezier patch
15
Parametric Surfaces
p(u,v) = [x(u,v), y(u,v), z(u,v)]
16
Parametric Surfaces
Why better than polygon meshes?
– Much more compact
– More convenient to control --- just edit control points
– Easy to construct from control points
17
Curve Representations
Polygon Meshes
Parametric Surfaces
Implicit Surfaces
18
Two Ways to Define a Circle
Parametric Implicit
F>0
F=0
u
F<0
19
Surface Representations
well defined inside/outside
polygons and splines do not have this information
Computing is hard:
implicit functions for a cube?
telephone?
ellipsoid parabolic
F<0?
X + kV F=0?
F>0?
F(X + kV) = 0
22
Surfaces from Implicit Functions
• Constant Value Surfaces are called
(depending on whom you ask):
– constant value surfaces
– level sets
– isosurfaces
23
Blobby Models
24
Blobby Models
25
Blobby Models
26
Blobby Models
27
Blobby Models
28
How to draw implicit surfaces?
• It’s easy to ray trace implicit surfaces
– because of that easy intersection test
• Volume Rendering can display them
• Convert to polygons: the Marching Cubes
algorithm
– Divide space into cubes
– Evaluate implicit function at each cube vertex
– Do root finding or linear interpolation along each
edge
– Polygonize on a cube-by-cube basis
29
Constructive Solid Geometry (CSG)
Generate complex shapes with basic building
blocks
machine an object - saw parts off, drill holes
glue pieces together
30
Constructive Solid Geometry (CSG)
Generate complex shapes with basic building
blocks
machine an object - saw parts off, drill holes
glue pieces together
31
A CSG Train
Subtract From
To get
Examples:
– Use cylinders to drill holes
– Use rectangular blocks to cut slots
– Use half-spaces to cut planar faces
– Use surfaces swept from curves34as jigsaws, etc.
Implicit Functions for Booleans
•Recall the implicit function for a solid: F(x,y,z)<0
•Boolean operations are replaced by arithmetic:
– MAX replaces AND (intersection)
– MIN replaces OR (union)
– MINUS replaces NOT(unary subtraction)
A B
•Thus
– F(Intersect(A,B)) = MAX(F(A),F(B))
F1<0 F2<0
– F(Union(A,B)) = MIN(F(A),F(B))
– F(Subtract(A,B)) = MAX(F(A), -F(B))
F1<0 F2<0
35
Implicit Surfaces
36
Announcements
Graded:
Written Assignment – Joel
37