Download presentation
Presentation is loading. Please wait.
Published byWinifred Corey Howard Modified over 9 years ago
1
Objectives Review some advanced topics, including Review some advanced topics, including Chapter 8: Implementation Chapter 8: Implementation Chapter 9: Hierarchical Modeling Chapter 9: Hierarchical Modeling CSC461: Lecture 26 Advanced Topics on Computer Graphics
2
Implementation -- Meta Algorithms Consider two approaches to rendering a scene with opaque objects Consider two approaches to rendering a scene with opaque objects For every pixel, determine which object that projects on the pixel is closest to the viewer and compute the shade of this pixel For every pixel, determine which object that projects on the pixel is closest to the viewer and compute the shade of this pixel Ray tracing paradigm Ray tracing paradigm For every object, determine which pixels it covers and shade these pixels For every object, determine which pixels it covers and shade these pixels Pipeline approach Pipeline approach Must keep track of depths Must keep track of depths
3
Implementation -- Common Tasks Clipping Clipping Rasterization or scan conversion Rasterization or scan conversion Antialiasing Antialiasing Transformations Transformations Hidden surface removal Hidden surface removal
4
Implementation – Line Clipping 2D against clipping window 2D against clipping window 3D against clipping volume 3D against clipping volume Easy for line segments polygons Easy for line segments polygons Hard for curves and text Hard for curves and text Convert to lines and polygons first Convert to lines and polygons first Brute force approach: compute intersections with all sides of clipping window Brute force approach: compute intersections with all sides of clipping window Inefficient: one division per intersection Inefficient: one division per intersection Cohen-Sutherland Algorithm Cohen-Sutherland Algorithm Idea: eliminate as many cases as possible without computing intersections Idea: eliminate as many cases as possible without computing intersections Start with four lines that determine the sides of the clipping window Start with four lines that determine the sides of the clipping window
5
Implementation – Polygon Clipping Not as simple as line segment clipping Not as simple as line segment clipping Clipping a line segment yields at most one line segment Clipping a line segment yields at most one line segment Clipping a polygon can yield multiple polygons Clipping a polygon can yield multiple polygons However, clipping a convex polygon can yield at most one other polygon However, clipping a convex polygon can yield at most one other polygon Clipping as a Black Box Clipping as a Black Box 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 segment 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 segment
6
Implementation – Pipeline Clipping Line Segments Line Segments Clipping against each side of window is independent of other sides Clipping against each side of window is independent of other sides Can use four independent clippers in a pipeline Can use four independent clippers in a pipeline Polygons Polygons Three dimensions: add front and back clippers Three dimensions: add front and back clippers Strategy used in SGI Geometry Engine Strategy used in SGI Geometry Engine Small increase in latency Small increase in latency
7
Hierarchical Modeling Start with a prototype object (a symbol) Start with a prototype object (a symbol) Each appearance of the object in the model is an instance Each appearance of the object in the model is an instance Must scale, orient, position Must scale, orient, position Defines instance transformation Defines instance transformation Symbol-Instance Table : Can store a model by assigning a number to each symbol and storing the parameters for the instance transformation Symbol-Instance Table : Can store a model by assigning a number to each symbol and storing the parameters for the instance transformation Car Modeling Car Modeling Symbol-instance table does not show relationships between parts of model Symbol-instance table does not show relationships between parts of model Consider model of car Consider model of car Chassis + 4 identical wheels Chassis + 4 identical wheels Two symbols Two symbols Rate of forward motion determined by rotational speed of wheels Rate of forward motion determined by rotational speed of wheels
8
Hierarchical Models Graph Models Graph Models Set of nodes and edges (links) Set of nodes and edges (links) Edge connects a pair of nodes Edge connects a pair of nodes Directed or undirected Directed or undirected Cycle: directed path that is a loop Cycle: directed path that is a loop Tree Models Tree Models Graph in which each node (except the root) has exactly one parent node Graph in which each node (except the root) has exactly one parent node May have multiple children May have multiple children Leaf or terminal node: no children Leaf or terminal node: no children A Tree Model for Car A Tree Model for Car loop root node leaf node
9
Hierarchical Models -- Robot Arm Robot arm is an example of an articulated model Robot arm is an example of an articulated model Parts connected at joints Parts connected at joints Can specify state of model by giving all joint angles Can specify state of model by giving all joint angles Relationships in Robot Arm Relationships in Robot Arm Base rotates independently Base rotates independently Single angle determines position Single angle determines position Lower arm attached to base Lower arm attached to base Its position depends on rotation of base Its position depends on rotation of base Must also translate relative to base and rotate about connecting joint Must also translate relative to base and rotate about connecting joint Upper arm attached to lower arm Upper arm attached to lower arm Its position depends on both base and lower arm Its position depends on both base and lower arm Must translate relative to lower arm and rotate about joint connecting to lower arm Must translate relative to lower arm and rotate about joint connecting to lower arm robot arm parts in their own coodinate systems
10
Hierarchical Models -- Robot Arm Required Matrices Required Matrices Rotation of base: R b Rotation of base: R b Apply M = R b to base Apply M = R b to base Translate lower arm relative to base: T lu Translate lower arm relative to base: T lu Rotate lower arm around joint: R lu Rotate lower arm around joint: R lu Apply M = R b T lu R lu to lower arm Apply M = R b T lu R lu to lower arm Translate upper arm relative to upper arm: T uu Translate upper arm relative to upper arm: T uu Rotate upper arm around joint: R uu Rotate upper arm around joint: R uu Apply M = R b T lu R lu T uu R uu to upper arm Apply M = R b T lu R lu T uu R uu to upper arm Tree Model of Robot Tree Model of Robot Note code shows relationships between parts of model Note code shows relationships between parts of model Can change “look” of parts easily without altering relationships Can change “look” of parts easily without altering relationships Simple example of tree model Simple example of tree model Want a general node structure for nodes Want a general node structure for nodes OpenGL Code for 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();}
11
Limitations of Immediate Mode Graphics and Objects When we define a geometric object in an application, upon execution of the code the object is passed through the pipeline When we define a geometric object in an application, upon execution of the code the object is passed through the pipeline It then disappears from the graphical system It then disappears from the graphical system To redraw the object, either changed or the same, we must reexecute the code To redraw the object, either changed or the same, we must reexecute the code Display lists provide only a partial solution to this problem Display lists provide only a partial solution to this problem OpenGL lacks an object orientation OpenGL lacks an object orientation Consider, for example, a green sphere Consider, for example, a green sphere We can model the sphere with polygons or use OpenGL quadrics We 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 object Its color is determined by the OpenGL state and is not a property of the object Defies our notion of a physical object Defies our notion of a physical object We can try to build better objects in code using object-oriented languages/techniques We can try to build better objects in code using object-oriented languages/techniques
12
Objects and Implementation Imperative Programming Model – rotate a cube Imperative Programming Model – rotate a cube The rotation function must know how the cube is represented: Vertex list or Edge list The rotation function must know how the cube is represented: Vertex list or Edge list Object-Oriented Programming Model Object-Oriented Programming Model The application sends a message to the object The application sends a message to the object The object contains functions (methods) which allow it to transform itself The object contains functions (methods) which allow it to transform itself Cube Object : Suppose that we want to create a simple cube object that we can scale, orient, position and set its color directly through code such as Cube Object : Suppose that we want to create a simple cube object that we can scale, orient, position and set its color directly through code such as cube mycube; mycube.color[0]=1.0;mycube.color[1]=mycube.color[2]=0.0;mycube.matrix[0][0]=……… mycube.translate(1.0, 0.0,0.0); mycube.rotate(theta, 1.0, 0.0, 0.0); Application glRotate cube data results ApplicationCube Object message
13
Scene Graphs Scene Descriptions Scene 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 code We could describe model either by tree or by equivalent code We could write a generic traversal to display We could write a generic traversal to display If we can represent all the elements of a scene (cameras, lights,materials, geometry) as C++ objects, we should be able to show them in a tree If we can represent all the elements of a scene (cameras, lights,materials, geometry) as C++ objects, we should be able to show them in a tree Render scene by traversing this tree Render scene by traversing this tree Scene Graph Scene Graph
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.