13
Objectives Objectives Review some advanced topics, Review some advanced topics, including including Chapter 8: Implementation Chapter 8: Implementation Chapter 9: Hierarchical Modeling Chapter 9: Hierarchical Modeling CSC461: Lecture 26 CSC461: Lecture 26 Advanced Topics on Computer Advanced Topics on Computer Graphics Graphics

Objectives Review some advanced topics, including Review some advanced topics, including Chapter 8: Implementation Chapter 8: Implementation Chapter 9:

Embed Size (px)

Citation preview

Objectives Objectives

Review some advanced topics, includingReview some advanced topics, including Chapter 8: ImplementationChapter 8: Implementation Chapter 9: Hierarchical ModelingChapter 9: Hierarchical Modeling

CSC461: Lecture 26CSC461: Lecture 26Advanced Topics on Computer Advanced Topics on Computer

GraphicsGraphics

Implementation -- Meta AlgorithmsImplementation -- Meta Algorithms Consider two approaches to rendering a scene Consider two approaches to rendering a scene

with opaque objectswith opaque objects For every pixel, determine which object that For every pixel, determine which object that

projects on the pixel is closest to the viewer projects on the pixel is closest to the viewer and compute the shade of this pixeland compute the shade of this pixel Ray tracing paradigmRay tracing paradigm

For every object, determine which pixels it For every object, determine which pixels it covers and shade these pixelscovers and shade these pixels Pipeline approachPipeline approach Must keep track of depthsMust keep track of depths

Implementation -- Common TasksImplementation -- Common Tasks

ClippingClipping Rasterization or scan conversionRasterization or scan conversion AntialiasingAntialiasing TransformationsTransformations Hidden surface removalHidden surface removal

Implementation – Line ClippingImplementation – Line Clipping 2D against clipping window2D against clipping window 3D against clipping volume3D against clipping volume Easy for line segments polygonsEasy for line segments polygons Hard for curves and textHard for curves and text

Convert to lines and polygons firstConvert to lines and polygons first Brute force approach: compute intersections with all Brute force approach: compute intersections with all

sides of clipping windowsides of clipping window Inefficient: one division per intersectionInefficient: one division per intersection

Cohen-Sutherland Algorithm Cohen-Sutherland Algorithm Idea: eliminate as many cases as possible without Idea: eliminate as many cases as possible without

computing intersectionscomputing intersections Start with four lines that determine the sides of the clipping Start with four lines that determine the sides of the clipping

windowwindow

Implementation – Polygon ClippingImplementation – Polygon Clipping Not as simple as line segment Not as simple as line segment

clippingclipping Clipping a line segment yields at Clipping a line segment yields at

most one line segmentmost one line segment Clipping a polygon can yield Clipping a polygon can yield

multiple polygonsmultiple polygons

However, clipping a convex polygon can yield at most one other However, clipping a convex polygon can yield at most one other polygonpolygon

Clipping as a Black BoxClipping as a Black Box Can consider line segment clipping as a process that takes in two vertices Can consider line segment clipping as a process that takes in two vertices

and produces either no vertices or the vertices of a clipped line segmentand produces either no vertices or the vertices of a clipped line segment

Implementation – Pipeline ClippingImplementation – Pipeline Clipping Line SegmentsLine Segments

Clipping against each side of window is independent of other sidesClipping against each side of window is independent of other sides Can use four independent clippers in a pipelineCan use four independent clippers in a pipeline

PolygonsPolygons Three dimensions: add front and back clippersThree dimensions: add front and back clippers Strategy used in SGI Geometry EngineStrategy used in SGI Geometry Engine Small increase in latencySmall increase in latency

Hierarchical ModelingHierarchical Modeling Start with a prototype object (a Start with a prototype object (a symbolsymbol)) Each appearance of the object in the model is an Each appearance of the object in the model is an instanceinstance

Must scale, orient, positionMust scale, orient, position Defines instance transformationDefines instance transformation

Symbol-Instance TableSymbol-Instance Table: : Can store a model by assigning a number to each Can store a model by assigning a number to each symbol and storing the parameters for the instance transformationsymbol and storing the parameters for the instance transformation

Car ModelingCar Modeling Symbol-instance table does not show relationships between Symbol-instance table does not show relationships between

parts of modelparts of model Consider model of carConsider model of car

Chassis + 4 identical wheelsChassis + 4 identical wheels Two symbolsTwo symbols

Rate of forward motion determined by rotational speed of wheelsRate of forward motion determined by rotational speed of wheels

Hierarchical ModelsHierarchical Models Graph ModelsGraph Models

Set of Set of nodesnodes and and edges (links)edges (links) Edge connects a pair of nodesEdge connects a pair of nodes

Directed or undirectedDirected or undirected CycleCycle: directed path that is a : directed path that is a

looploop

Tree ModelsTree Models Graph in which each node Graph in which each node

(except the root) has exactly (except the root) has exactly one parent nodeone parent node

May have multiple childrenMay have multiple children Leaf or terminal node: no Leaf or terminal node: no

childrenchildren A Tree Model for CarA Tree Model for Car

looproot node

leaf node

Hierarchical Models -- Robot ArmHierarchical Models -- Robot Arm

Robot arm is an example of an Robot arm is an example of an articulated modelarticulated model Parts connected at jointsParts connected at joints Can specify state of model by giving all joint anglesCan specify state of model by giving all joint angles

Relationships in Robot ArmRelationships in Robot Arm Base rotates independentlyBase rotates independently

Single angle determines positionSingle angle determines position Lower arm attached to baseLower arm attached to base

Its position depends on rotation of baseIts position depends on rotation of base Must also translate relative to base and rotate about connecting jointMust also translate relative to base and rotate about connecting joint

Upper arm attached to lower armUpper arm attached to lower arm Its position depends on both base and lower armIts position depends on both base and lower arm Must translate relative to lower arm and rotate about joint connecting to lower Must translate relative to lower arm and rotate about joint connecting to lower

armarm

robot armparts in their own coodinate systems

Hierarchical Models -- Robot ArmHierarchical Models -- Robot Arm Required MatricesRequired Matrices

Rotation of base: Rotation of base: RRbb Apply Apply MM = = RRb b to baseto base

Translate lower arm Translate lower arm relativerelative to base: to base: TTlulu Rotate lower arm around joint: Rotate lower arm around joint: RRlulu

Apply Apply MM = = RRb b TTlu lu RRlu lu to lower armto lower arm Translate upper arm Translate upper arm relativerelative to upper to upper

arm: arm: TTuuuu Rotate upper arm around joint: Rotate upper arm around joint: RRuuuu

Apply Apply MM = = RRb b TTlu lu RRlu lu TTuu uu RRuu uu to upper armto upper arm Tree Model of RobotTree Model of Robot

Note code shows relationships between parts Note code shows relationships between parts of modelof model

Can change “look” of parts easily without Can change “look” of parts easily without altering relationshipsaltering relationships

Simple example of tree modelSimple example of tree model Want a general node structure for nodesWant a general node structure for nodes

OpenGL Code for Robot ArmOpenGL Code for Robot Arm

robot_arm()robot_arm(){{ glRotate(theta,0.0,1.0,0.0);glRotate(theta,0.0,1.0,0.0); base();base(); glTranslate(0.0, h1, 0.0);glTranslate(0.0, h1, 0.0); glRotate(phi, 0.0, 1.0, 0.0);glRotate(phi, 0.0, 1.0, 0.0); lower_arm();lower_arm(); glTranslate(0.0, h2, 0.0);glTranslate(0.0, h2, 0.0); glRotate(psi, 0.0, 1.0, 0.0);glRotate(psi, 0.0, 1.0, 0.0); upper_arm();upper_arm();}}

Limitations of Immediate Mode Limitations of Immediate Mode Graphics and ObjectsGraphics and Objects

When we define a geometric object in an application, upon When we define a geometric object in an application, upon execution of the code the object is passed through the pipeline execution of the code the object is passed through the pipeline

It then disappears from the graphical systemIt then disappears from the graphical system To redraw the object, either changed or the same, we must To redraw the object, either changed or the same, we must

reexecute the codereexecute the code Display lists provide only a partial solution to this problemDisplay lists provide only a partial solution to this problem OpenGL lacks an object orientationOpenGL lacks an object orientation Consider, for example, a green sphereConsider, for example, a green sphere

We can model the sphere with polygons or use OpenGL quadricsWe can model the sphere with polygons or use OpenGL quadrics Its color is determined by the OpenGL state and is not a property of the Its color is determined by the OpenGL state and is not a property of the

objectobject Defies our notion of a physical objectDefies our notion of a physical object We can try to build better objects in code using object-oriented We can try to build better objects in code using object-oriented

languages/techniqueslanguages/techniques

Objects and ImplementationObjects and Implementation Imperative Programming Model – rotate a cubeImperative Programming Model – rotate a cube

The rotation function must know how the cube is The rotation function must know how the cube is represented: Vertex list or Edge listrepresented: Vertex list or Edge list

Object-Oriented Programming ModelObject-Oriented Programming Model The application sends a The application sends a messagemessage to the object to the object The object contains functions (The object contains functions (methodsmethods) which allow it to ) which allow it to

transform itselftransform itself

Cube Object :Cube Object : Suppose that we want to create a simple cube Suppose that we want to create a simple cube object that we can scale, orient, position and set its color directly object that we can scale, orient, position and set its color directly through code such asthrough code such as

cube mycube;cube mycube;mycube.color[0]=1.0;mycube.color[0]=1.0;mycube.color[1]=mycube.color[2]=0.0;mycube.color[1]=mycube.color[2]=0.0;mycube.matrix[0][0]=………mycube.matrix[0][0]=………mycube.translate(1.0, 0.0,0.0);mycube.translate(1.0, 0.0,0.0);mycube.rotate(theta, 1.0, 0.0, 0.0);mycube.rotate(theta, 1.0, 0.0, 0.0);

Application glRotatecube data

results

Application Cube Objectmessage

Scene GraphsScene Graphs Scene DescriptionsScene Descriptions

If we recall figure model, we saw that If we recall figure model, we saw that We could describe model either by tree or by equivalent codeWe could describe model either by tree or by equivalent code We could write a generic traversal to displayWe could write a generic traversal to display

If we can represent all the elements of a scene (cameras, If we can represent all the elements of a scene (cameras, lights,materials, geometry) as C++ objects, we should be lights,materials, geometry) as C++ objects, we should be able to show them in a treeable to show them in a tree

Render scene by traversing this treeRender scene by traversing this tree

Scene GraphScene Graph