Computer Graphics

Computer Graphics
Course SS 2007
Model Representation
computer graphics & visualization
Object representation
• In computer graphics we often deal with
polygonal approximations of continuous objects
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• What is a polygon?
– It consists of points
• A point is represented by three floating-point numbers
called a vertex
– Points are connected via line segments (edges)
• Connected series of line segments are specified in terms
of the vertices at their endpoints
– A polygon is the interior of a closed planar
connected series of line segments
• The sides do not cross each other and exactly two sides
meet at every vertex
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• What is a polygon?
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• What is a polygon mesh?
– Objects are typically considered to be hollow
– They are modelled by a surface composed of a
number of polygons (faces) – the mesh
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Types of polygon meshes
– Triangle meshes and quad meshes
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Types of polygon meshes
– Triangle meshes and
quad meshes
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Polygon meshes
– n-ring of a vertex is the set of vertices for which a
path to that vertex of length n exist
– Valence of a vertex is the number of adjacent edges
(= number of adjacent vertices)
1-ring
2-ring
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Polygon meshes
– A polygon mesh must satisfy the following criteria
• The intersection of two faces is either empty, or a
common vertex, or a common edge
Not allowed are:
Faces overlap
T-vertex
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Polygon meshes
– We only consider manifold meshes
• A mesh where every edge must be shared by exactly 2
faces, except the border edges
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Polygon meshes
– We only consider orientable surfaces
• Normals can be ordered consistently
Examples of non-orientable meshes
Möbius strip
Klein bottle
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• A polygonal approximation is an approximation
of a continuous surface by a polygon mesh
Example: Approximation of a curve
Different approximations of a sphere
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• A polygonal approximation typically consists of
a discrete set of points of the continuous
surface, which are connected via edges
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Polygonal approximation are typical adaptive in
that more polygons are used in regions of high
curvature
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Adaptive polygonal
approximations
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Triangle mesh representation
– Geometry: where are the vertices positioned
– Topology: how are they connected
– Explicit representation:
store three vertices for each of the n triangles
n*3*3 = 9n floats
– High redundancy
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Triangle mesh representation
– Shared vertex („indexed face set“) representation
– Array of coordinates of all vertices (3n floats)
– Array of triangles with indices into the vertex list
(3n integers)
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Indexed face set representation
– Less redundancy than explicit representation
– Separation of geometry and topology
• Amenable to more efficient compression schemes
– Mesh operators still difficult to realize
• Think about how to implement the following operations:
get_neighbor
traverse_1-ring
compute_vertex_normal
etc.
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Extended shared vertex representation:
– Array of vertices, each with a reference to one
adjacent triangle (convention for border vertices:
right border triangle): 3n floats + 1n integers
– Array of triangles, each with a reference to adjacent
triangles (at the border: -1): 6n integers
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Graphical representation of polygon meshes
Wireframe
Shaded
Shaded wireframe
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• For the rendering of polygon meshes we need
– The objects shape, i.e. the geometric
representation including normals
• 3D object coordinates (vertices)
• 3D normal vectors
– The objects appearance
• Material properties like color, reflection properties,
textures etc.
– The lighting environment, i.e. light sources and their
properties
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Surface normals
– The vectors
perpendicular to
the surface
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• How to specify surface normals
– In computer graphics we typically specify one
normal per vertex
• Can be computed directly from the surface
representation (see later in course)
• Can be computed for every planar face and averaged at
the vertices

Nv
k
i 1

Ni

Ni
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Polygon models (triangle meshes)
Per-vertex:
Coordinate (x,y,z)
Color (RGB)
Normal (nx,ny,nz)
Light and material
properties:
Light source type
Color
Reflectivity
Tansparency ...
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• How to make triangle meshes look solid
Shading
Need to fill triangles with color
– But, remember that we only have per-vertex colors
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• How to make triangle meshes look solid
Constant
color per face
Vertex colors
are interpolated
across every face
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• How to interpolate inside a triangle
– Given:
n+1 points xi with function values fi
– Problem:
Can we find a polynomial p of degree of at most n
that interpolates fi at the points xi , i.e.,
p(x ) = f , j= 0, . . . , n.
j
j
j
– If so, then f at any point x can be interpolated by
evaluating this polynomial at x
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• The interpolation problem has a unique
solution that depends continuously on the data
– Scalar values fi are given at vertices (xi,yi,zi)
p(x) = a+bx+cy
– Polynomial can be obtained by
solving the system
1 x0
1 x1
1 x2
y0
y1
y2
a
b
c
f0
f1
f2
f0
f2
f1
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• The existance of the polynomial
p(x) = a+bx+cy
What does it mean?
– Obviously it is linear in x, y
– Interpolated values along any ray in the plane
spanned by the triangle are linear along that ray
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Barycentric interpolation in a triangle
– Inside a triangle the function value at any point x
can be computed as
f(x) = 0f0 + 1f1 + 2f1
with 0 + 1 + 2 = 1 (the barycentric coordinates)
This also holds for the coordinate of x:
x = i i ·xi and i i = 1
→ Can be used to solve for unknown coefficients
i
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Barycentric coordinates from area
considerations
x1
1=A1/A
x
x2
A1
Opposite
local area
A
x3
– This means that we can easily evaluate arbitrary
per-vertex attributes in the interior of a triangle!
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation

P1
2

P3

P
3
1
1
Barycentric coordinates




P
1P1
2 P2
3 P3
area( PP2 P3 )
2
area( PP3P1 )
3
area( PP1P2 )
Inside triangle criteria

P2
0
1
1
0
2
1
0
3
1
1
2
3
1
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Ray tracing of triangle meshes
– We know that any point p inside a triangle can be
represented as
p = 0p0 + 1p1 + 2p1
= (1- 1- 2)p0 + 1p1 + 2p1
= p0 + 1(p1-p0)+ 2(p2-p0)
– As p is on the ray:
peye + t d = p0 + 1(p1-p0)+
2(p2-p0)
• Requires solution of a 3x3 system of linear equations
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Ray-polygon intersection
– Find intersection with plane of support
– Test whether point is inside 3D polygon
• Project onto xy plane
• Test whether point is inside 2D polygon
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Point-in-polygon test
– Count the number of intersections of an arbitrary
ray and the polygon edges
• Even number: point is outside
• Odd number: point is inside
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Ray tracing of surfaces
• Now we will focus on general representations
of surfaces in 3D
– Implicit representation
– Parametric representation
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Implicit representation
– Surface described by the set of points that lie/don´t
lie on surface
{( x, y, z) V | f ( x, y, z) 0}
,V
R3
– Example unit sphere:
x
2
y
2
z
2
1 0
– Cannot compute surface values directly
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Important surfaces in computer graphics
– Quadric surfaces:
Ax2 + By2 + Cz2 + Dxy + Exz + Fyz + Gx + Hy + Iz + J = 0
Planes, spheres, cylinders, cones, ellipsoids,
paraboloids etc.
ellipsoid
paraboloids
hyperboloids
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Ray tracing quadrics

• Substitute ray equation p(t ) p0 td
into quadrics equation yields a quadratic
equation Aqt 2 Bqt Cq 0
with solutions
t0
( Bq
Bq2 4 Aq Cq ) / 2 Aq
t1
( Bq
Bq2 4 Aq Cq ) / 2 Aq
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Ray tracing quadrics
– If the quadratic equation has two real roots, then the
ray’s line intersects the surface twice
– If it has one real root of multiplicity two then the ray
grazes the surface
– If it has two complex roots (negative discriminant)
then the ray misses the surface.
– If there are real roots, their signs should be tested,
since they are at or behind the origin of the ray
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Ray tracing quadrics
Algorithm:
If Aq = 0 then t = -Cq / Bq
If Aq ≠ 0, then
If (Bq2 - 4AqCq ) < 0.0 then there is no
intersection
Compute t0 and if t0 > 0 then done else compute t1
Once t is found compute r(t)
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• For implicit surfaces the normal at a surface
point p is given by

n
f ( p)
f ( p) / x
f ( p) / y
f ( p) / z
2 Ap x Dp y Ep z G
2Bp y Dp x Fp z H
2Cp z Ep x Fp y I
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Example: sphere
( x cx ) 2 ( y c y ) 2 ( z c z ) 2

n
f ( p)

n
 
2( p c )
R2
0
2( x cx )
2( y c y )
2( z cz )
The vector from the center to the point on the sphere
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Parametric surfaces
– Surfaces defined by a parametric equation involving a
mapping from R2 to R3
x = f(u,v), y = g(u,v), z = h(u,v)
Parametric unit sphere:
: [0:2π]
Azimuth
: [0:π]
Zenith
x = cos( )*sin( )
y = sin( )*sin( )
z = cos( )
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Intersecting the ray with a parametric surface
px + t dx = f(u,v)
py + t dy = g(u,v)
pz + t dz = h(u,v)
-> Yields 3 equations and 3 unknowns -> solve it
-> Might be complicated for non-simple f,g and h
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Object representation
• Intersecting the ray with a parametric surface
– The partial derivatives fu(u0,v0) and fv(u0,v0) lie on
the tangent plane to the surface at the point (u0,v0).
– The normal is given by

n
f (u0 , v0 )
u
g (u0 , v0 )
u
h(u0 , v0 )
u
f (u 0 , v0 )
v
g ( u0 , v0 )
v
h(u0 , v0 )
v
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Spheres-over-plane
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Spheres-over-plane
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Spheres-over-plane
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Spheres-over-plane
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Spheres-over-plane
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Spheres-over-plane (mirror 10)
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Spheres-over-plane
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Spheres-over-plane
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Spheres-over-plane
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Spheres-over-plane
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Spheres-over-plane (glass 10)
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization
Spheres-over-plane (glass/mirror)
Computer Graphics – SS 07
Prof. Dr. Rüdiger Westermann – Computer Graphics and Visualization Group
computer graphics & visualization