1 Computer Graphics Chapter 7 3D Object Modeling.

42
1 Computer Graphics Computer Graphics Chapter 7 Chapter 7 3D Object Modeling 3D Object Modeling

Transcript of 1 Computer Graphics Chapter 7 3D Object Modeling.

Page 1: 1 Computer Graphics Chapter 7 3D Object Modeling.

11

Computer GraphicsComputer Graphics

Chapter 7Chapter 73D Object Modeling3D Object Modeling

Page 2: 1 Computer Graphics Chapter 7 3D Object Modeling.

22

3D Object Representation3D Object Representation A surface can be analytically A surface can be analytically

generated using its function generated using its function involving the coordinates. involving the coordinates.

An object can be represented in An object can be represented in terms of its vertices, edges and terms of its vertices, edges and polygons. (Wire Frame, polygons. (Wire Frame, Polygonal Mesh etc.)Polygonal Mesh etc.)

Curves and surfaces can also be Curves and surfaces can also be designed using splines by designed using splines by specifying a set of few control specifying a set of few control points. points.

y = f(x,z)

x y z . . .

Page 3: 1 Computer Graphics Chapter 7 3D Object Modeling.

33

Solid Modeling - PolyhedronSolid Modeling - Polyhedron A polyhedron is a connected mesh of simple planar A polyhedron is a connected mesh of simple planar

polygons that encloses a finite amount of space. polygons that encloses a finite amount of space.

A polyhedron is a special case of a polygon mesh that A polyhedron is a special case of a polygon mesh that satisfies the following properties:satisfies the following properties:

Every edge is shared by exactly two faces.Every edge is shared by exactly two faces.

At least three edges meet at each vertex.At least three edges meet at each vertex. Faces do not interpenetrate. Faces at most touch Faces do not interpenetrate. Faces at most touch

along a common edge.along a common edge. Euler’s formulaEuler’s formula : If : If FF, , EE, , VV represent the number of represent the number of

faces, vertices and edges of a polyhedron, then faces, vertices and edges of a polyhedron, then

VV + + FF EE = 2. = 2.

Page 4: 1 Computer Graphics Chapter 7 3D Object Modeling.

44

3D Object Representation3D Object Representation

The data for polygonal meshes The data for polygonal meshes can be represented in two ways.can be represented in two ways. Method 1:Method 1:

Vertex ListVertex List Normal ListNormal List Face List (Polygon List)Face List (Polygon List)

Method 2:Method 2: Vertex ListVertex List Edge ListEdge List Face List (Polygon List)Face List (Polygon List)

Page 5: 1 Computer Graphics Chapter 7 3D Object Modeling.

55

01

2 3

45

6 7

Vertices and Faces - E.g. CubeVertices and Faces - E.g. Cube

0

1

23

4

5

Face Index

Vertex Index

Page 6: 1 Computer Graphics Chapter 7 3D Object Modeling.

66

Data representation using vertex, face and normal lists:

Vertex List Normal List Polygon List

30 30 30 0.0 0.0 1.0 0 1 2 3-30 30 30 0.0 0.0 -1.0 4 7 6 5-30 -30 30 0.0 1.0 0.0 0 4 5 1 30 -30 30 -1.0 0.0 0.0 1 5 6 2 30 30 -30 0.0 -1.0 0.0 2 6 7 3-30 30 -30 1.0 0.0 0.0 3 7 4 0-30 -30 -30 30 -30 -30

Page 7: 1 Computer Graphics Chapter 7 3D Object Modeling.

77

Vertex List Edge List Polygon Listx[i] y[i] z[i] L[j] M[j] P[k] Q[k] R[k] S[k]

30 30 30 0 1 0 1 2 3-30 30 30 1 2 4 7 6 5-30 -30 30 2 3 0 4 5 1 30 -30 30 3 0 1 5 6 2 30 30 -30 4 5 2 6 7 3-30 30 -30 5 6 3 7 4 0-30 -30 -30 6 7 30 -30 -30 7 4

0 41 52 63 7

Data representation using vertex, face and edge lists:

Page 8: 1 Computer Graphics Chapter 7 3D Object Modeling.

88

Normal Vectors (OpenGL)Normal Vectors (OpenGL)

Assigning a normal vector to a polygon:

glBegin(GL_POLYGON); glNormal3f(xn,yn,zn);

glVertex3f(x1,y1,z1);glVertex3f(x2,y2,z2);glVertex3f(x3,y3,z3);glVertex3f(x4,y4,z4);

glEnd();

Enabling automatic conversion of normal vectors to unit vectors:

glEnable(GL_NORMALIZE);

Page 9: 1 Computer Graphics Chapter 7 3D Object Modeling.

99

Regular Polyhedra (Regular Polyhedra (Platonic Solids)Platonic Solids) If all the faces of a polyhedron are If all the faces of a polyhedron are

identical, and each is a regular polygon, identical, and each is a regular polygon, then the object is called a then the object is called a platonic solidplatonic solid. .

Only five such objects exist.Only five such objects exist.

Page 10: 1 Computer Graphics Chapter 7 3D Object Modeling.

1010

Wire-Frame ModelsWire-Frame Models

If the object is defined only by a set of nodes If the object is defined only by a set of nodes (vertices), and a set of lines connecting the (vertices), and a set of lines connecting the nodes, then the resulting object nodes, then the resulting object representation is called a wire-frame model. representation is called a wire-frame model.

Very suitable for engineering Very suitable for engineering applications.applications.

Simplest 3D Model - easy to construct. Simplest 3D Model - easy to construct.

Easy to clip and manipulate. Easy to clip and manipulate.

Not suitable for building realistic models.Not suitable for building realistic models.

Page 11: 1 Computer Graphics Chapter 7 3D Object Modeling.

1111

Wire Frame Models - OpenGLWire Frame Models - OpenGL

Some Wireframe Models in OpenGL:Cube: glutWireCube(Gldouble size);Sphere: glutWireSphere(…);Torus: glutWireTorus(…);Teapot: glutWireTeapot(Gldouble size);Cone: glutWireCone(…);

(…) Refer text for list of arguments.

Page 12: 1 Computer Graphics Chapter 7 3D Object Modeling.

1212

Wire Frame Model - The Wire Frame Model - The TeapotTeapot

Page 13: 1 Computer Graphics Chapter 7 3D Object Modeling.

1313

Polygonal MeshPolygonal Mesh Three-dimensional surfaces and solids can be Three-dimensional surfaces and solids can be

approximated by a set of polygonal and line approximated by a set of polygonal and line elements. Such surfaces are called elements. Such surfaces are called polygonal polygonal meshes.meshes.

The set of polygons or faces, together form the The set of polygons or faces, together form the “skin” of the object. “skin” of the object.

This method can be used to represent a broad This method can be used to represent a broad class of solids/surfaces in graphics. class of solids/surfaces in graphics.

A polygonal mesh can be rendered using hidden A polygonal mesh can be rendered using hidden surface removal algorithms.surface removal algorithms.

Page 14: 1 Computer Graphics Chapter 7 3D Object Modeling.

1414

Polygonal Mesh - ExamplePolygonal Mesh - Example

Page 15: 1 Computer Graphics Chapter 7 3D Object Modeling.

1515

Solid ModelingSolid Modeling

Polygonal meshes can be used in solid Polygonal meshes can be used in solid modeling.modeling.

An object is considered An object is considered solidsolid if the if the polygons fit together to enclose a space.polygons fit together to enclose a space.

In solid models, it is necessary to In solid models, it is necessary to incorporate directional information on each incorporate directional information on each face by using the face by using the normal vectornormal vector to the to the plane of the face, and it is used in the plane of the face, and it is used in the shading process.shading process.

Page 16: 1 Computer Graphics Chapter 7 3D Object Modeling.

1616

Solid Modeling - ExampleSolid Modeling - Example

Page 17: 1 Computer Graphics Chapter 7 3D Object Modeling.

1717

Solid Modeling - OpenGLSolid Modeling - OpenGL

Some predefined Solid Models in OpenGL: Cube: glutSolidCube(Gldouble size); Sphere: glutSolidSphere(…); Torus: glutSolidTorus(…); Teapot: glutSolidTeapot(Gldouble size); Cone: glutSolidCone(…); (…) Arguments same as wire-frame models.

Page 18: 1 Computer Graphics Chapter 7 3D Object Modeling.

1818

Z

X

Y

y = f(x, z)

Surface ModelingSurface Modeling

Many surfaces can be represented by an explicit function of two independent variables, such as y = f(x, z).

Page 19: 1 Computer Graphics Chapter 7 3D Object Modeling.

1919

Surface Modeling - ExampleSurface Modeling - Example

Page 20: 1 Computer Graphics Chapter 7 3D Object Modeling.

2020

Sweep RepresentationsSweep Representations

Sweep representations are useful for both Sweep representations are useful for both surface modeling and solid modeling.surface modeling and solid modeling.

A large class of shapes (both surfaces and A large class of shapes (both surfaces and solid models) can be formed by solid models) can be formed by sweepingsweeping or or extrudingextruding a 2D shape through space. a 2D shape through space.

Sweep representations are useful for Sweep representations are useful for constructing 3-D objects that posses constructing 3-D objects that posses translational or rotational symmetries. translational or rotational symmetries.

Page 21: 1 Computer Graphics Chapter 7 3D Object Modeling.

2121

Extruded Shapes - ExamplesExtruded Shapes - Examples

A polyhedron obtained by sweeping (extruding) a polygon along a straight line is called a prism.

Page 22: 1 Computer Graphics Chapter 7 3D Object Modeling.

2222

Surface of RevolutionSurface of Revolution

A surface of revolution is obtained by A surface of revolution is obtained by revolving a curve (known as the revolving a curve (known as the base curvebase curve or or profile curveprofile curve) about an axis. ) about an axis.

In other words, a surface of revolution is In other words, a surface of revolution is generated by a generated by a rotational sweeprotational sweep of a 2D of a 2D curve. curve.

The symmetry of the surface of revolution The symmetry of the surface of revolution makes it a very useful object in makes it a very useful object in presentation graphics. presentation graphics.

Page 23: 1 Computer Graphics Chapter 7 3D Object Modeling.

2323

Z

X

Y

y = f(x)

r

y y

(x, z)

y = f(r)

x

22 zxr

Surface of RevolutionSurface of Revolution

Page 24: 1 Computer Graphics Chapter 7 3D Object Modeling.

2424

The three-dimensional surface obtained by

revolving the curve y = f(x) about the y-axis is

obtained by replacing x with sqrt(x*x + z*z).

The surface of revolution is thus given by

y f x z 2 2

Surface of RevolutionSurface of Revolution

Page 25: 1 Computer Graphics Chapter 7 3D Object Modeling.

2525

Surface of RevolutionSurface of Revolution

x

xy

)sin(

22

22sin

zx

zxy

Page 26: 1 Computer Graphics Chapter 7 3D Object Modeling.

2626

Quad treesQuad trees

Quad trees are generated by successively Quad trees are generated by successively dividing a 2-D region(usually a square) into dividing a 2-D region(usually a square) into quadrants. Each node in the quadtree has quadrants. Each node in the quadtree has 4 data elements, one for each of the 4 data elements, one for each of the quadrants in the region. If all the pixels quadrants in the region. If all the pixels within a quadrant have the same color (a within a quadrant have the same color (a homogeneous quadrant), the homogeneous quadrant), the corresponding data element in the node corresponding data element in the node stores that color. For a heterogeneous stores that color. For a heterogeneous region of space, the successive divisions region of space, the successive divisions into quadrants continues until all quadrants into quadrants continues until all quadrants are homogeneous. are homogeneous.

Page 27: 1 Computer Graphics Chapter 7 3D Object Modeling.

2727

OctreesOctrees An octree encoding scheme divide regions of An octree encoding scheme divide regions of

3-D space(usually a cube) in to octants and 3-D space(usually a cube) in to octants and stores 8 data elements in each node of the stores 8 data elements in each node of the tree.tree.

Individual elements of a 3-D space are called Individual elements of a 3-D space are called volume elements or voxels. volume elements or voxels.

When all voxels in an octant are of the same When all voxels in an octant are of the same type, this type value is stored in the type, this type value is stored in the corresponding data element of the node. Any corresponding data element of the node. Any heterogeneous octant is subdivided into heterogeneous octant is subdivided into octants and the corresponding data element octants and the corresponding data element in the node points to the next node in the in the node points to the next node in the octree. octree.

Page 28: 1 Computer Graphics Chapter 7 3D Object Modeling.

2828

OctreesOctrees

Page 29: 1 Computer Graphics Chapter 7 3D Object Modeling.

2929

Bezier CurvesBezier Curves

The Bezier curve only approximates the control pointsand doesn’t actually pass through all of them.

Page 30: 1 Computer Graphics Chapter 7 3D Object Modeling.

3030

Inputs: n control points (xi, yi), i = 0, 1,2, …n-1

,0

,0

,

( ) ( )

( ) ( )

0 1

!( ) (1 )

! !

m

b m i ii

m

b m i ii

i m im i

x u Bez u x

y u Bez u y

u

m m mBez u u u and

i i i m i

m = n1

Bezier CurvesBezier Curves

Page 31: 1 Computer Graphics Chapter 7 3D Object Modeling.

3131

Inputs: n control points (xi, yi), i = 0, 1,2, …m

0

( ) ( ) , 0 1

( ) ( ( ), ( ))

( , )

m

m i ii i

i i i

r u Bez u r u

where

r u x u y u

r x y

Bezier CurvesBezier Curves

Page 32: 1 Computer Graphics Chapter 7 3D Object Modeling.

3232

Properties of Bezier CurveProperties of Bezier Curve

Bezier curve is a polynomial of Bezier curve is a polynomial of degree one less than the degree one less than the number of control points number of control points

p0

p2

p1

p0

p2

p1

p3

Quadratic Curve Cubic Curve

Page 33: 1 Computer Graphics Chapter 7 3D Object Modeling.

3333

Properties of Bezier Curve (cont.)Properties of Bezier Curve (cont.)

Bezier curve always passes Bezier curve always passes through the first and last points; through the first and last points; i.e. i.e.

andand

0(0)x x

,

0(0)y y

(1) mx x (1) my y

Page 34: 1 Computer Graphics Chapter 7 3D Object Modeling.

3434

Properties of Bezier Curve Properties of Bezier Curve (cont)(cont) The slop at the beginning of the curve is The slop at the beginning of the curve is

along the line joining the first two control along the line joining the first two control points, and the slope at the end of the points, and the slope at the end of the curve is along the line joining the last two curve is along the line joining the last two points.points.

p0

p2

p1

p0

p2

p1

Page 35: 1 Computer Graphics Chapter 7 3D Object Modeling.

3535

Properties of Bezier Curve Properties of Bezier Curve (cont)(cont) Bezier blending functions are all positive Bezier blending functions are all positive

and the sum is always 1.and the sum is always 1.

This means that the curve is the weighted This means that the curve is the weighted sum of the control points.sum of the control points.

,0

( ) 1m

m ii

Bez u

Page 36: 1 Computer Graphics Chapter 7 3D Object Modeling.

3636

Design Technique using Bezier Design Technique using Bezier Curves:Curves:

A closed Bezier curve can be generated by A closed Bezier curve can be generated by specifying the first and last control points at specifying the first and last control points at the same locationthe same location

p4

p0=p5p1

p2

p3

Page 37: 1 Computer Graphics Chapter 7 3D Object Modeling.

3737

Design Technique (Cont)Design Technique (Cont)

A Bezier curve can be made to pass closer A Bezier curve can be made to pass closer to a given coordinate position by assigning to a given coordinate position by assigning multiple control points to that position.multiple control points to that position.

p0

p1 = p2 p3

p4

Page 38: 1 Computer Graphics Chapter 7 3D Object Modeling.

3838

Bezier curve can be form by piecing of Bezier curve can be form by piecing of several Bezier section with lower degree. several Bezier section with lower degree.

p0

p1

p2= p’0

p’2

p’3

p’1

Page 39: 1 Computer Graphics Chapter 7 3D Object Modeling.

3939

(Not Important!)

,0 0

( , ) ( ) ( ) ,

0 1, 0 1

( , ) ( ( , ), ( , ), ( , ))

( , , )

m l

m i l j i ji j

ij ij ij ij

r u v Bez u Bez v r

u v

where

r u v x u v y u v z u v

r x y z

Bezier SurfacesBezier Surfaces

Page 40: 1 Computer Graphics Chapter 7 3D Object Modeling.

4040

A set of 16 control points The Bezier Patch

Bezier PatchBezier Patch

Page 41: 1 Computer Graphics Chapter 7 3D Object Modeling.

4141

Utah Teapot Defined Using Control Points

Bezier PatchBezier Patch

Page 42: 1 Computer Graphics Chapter 7 3D Object Modeling.

4242

Utah Teapot Generated Using Bezier Patches

Bezier PatchBezier Patch