hierarchical models
DESCRIPTION
Hierarchical Models. Chapter 9. Introduction: In this chapter we explore multiple approaches to developing and working with models of geometric objects. We extend the use of transformations from Chapter 4 to include hierarchical relationships among the objects. - PowerPoint PPT PresentationTRANSCRIPT
Hierarchical Hierarchical ModelsModels
Chapter 9Chapter 9
CS 480/680 2Chapter 9 -- Hierarchical Models
Introduction:Introduction: In this chapter we explore multiple In this chapter we explore multiple
approaches to developing and working approaches to developing and working with models of geometric objects.with models of geometric objects.
We extend the use of transformations We extend the use of transformations from Chapter 4 to include hierarchical from Chapter 4 to include hierarchical relationships among the objects.relationships among the objects.
The techniques that we develop are The techniques that we develop are appropriate for applications, such as appropriate for applications, such as robotics and figure animation, where the robotics and figure animation, where the dynamic behavior of the objects is dynamic behavior of the objects is characterized by relationships among the characterized by relationships among the parts of the model.parts of the model.
CS 480/680 3Chapter 9 -- Hierarchical Models
The notion of hierarchy is a powerful one The notion of hierarchy is a powerful one and is an integral part of object oriented and is an integral part of object oriented methodologies.methodologies.
We extend our hierarchical model of We extend our hierarchical model of objects to hierarchical models of whole objects to hierarchical models of whole scenes, including cameras, lights, and scenes, including cameras, lights, and material properties.material properties.
Such models allow us to extend our Such models allow us to extend our graphics APIs to more objet-oriented graphics APIs to more objet-oriented systems and gives us insight in how to use systems and gives us insight in how to use graphics over networks and distributed graphics over networks and distributed environments, such as the Web.environments, such as the Web.
CS 480/680 4Chapter 9 -- Hierarchical Models
1. Symbols and Instances1. Symbols and Instances
Our first concern is how to store a model that Our first concern is how to store a model that may include many sophisticated objects.may include many sophisticated objects.
There are two immediate issues:There are two immediate issues: How do we define a complex objectHow do we define a complex object How do we represent a collection of these objects.How do we represent a collection of these objects.
We can take a non hierarchical approach to We can take a non hierarchical approach to modeling regarding these objects as modeling regarding these objects as symbolssymbols, and modeling our world as a , and modeling our world as a collection of symbolscollection of symbols
CS 480/680 5Chapter 9 -- Hierarchical Models
Symbols are usually represented at a Symbols are usually represented at a convenient size and orientation.convenient size and orientation. For example: a cylinderFor example: a cylinder
In OpenGL we have to set up the In OpenGL we have to set up the appropriate transformation from the frame appropriate transformation from the frame of the symbol to the world coordinate of the symbol to the world coordinate frame to apply it to the model-view matrix frame to apply it to the model-view matrix before we execute the code for the symbol.before we execute the code for the symbol.
CS 480/680 6Chapter 9 -- Hierarchical Models
For example: the instance transformationFor example: the instance transformation M = TRS M = TRS is a concatenation of a translation, a rotation, and a is a concatenation of a translation, a rotation, and a
scalescale
And the OpenGL program often contains this code:And the OpenGL program often contains this code: glMatrixMode(GL_MODELVIEW);glMatrixMode(GL_MODELVIEW); glLaodIdentity();glLaodIdentity(); glTranslatef(...);glTranslatef(...); glRotatef(...);glRotatef(...); glScalef(...);glScalef(...); glutSolidCylinder(...)’glutSolidCylinder(...)’
CS 480/680 7Chapter 9 -- Hierarchical Models
We can also think of such a model in We can also think of such a model in the form of a tablethe form of a table
The table shows no relationship among The table shows no relationship among the objects. However, it does contain the objects. However, it does contain everything we need to draw the objects.everything we need to draw the objects.
We could do a lot of things with this data We could do a lot of things with this data structure, but its flatness limits us.structure, but its flatness limits us.
CS 480/680 8Chapter 9 -- Hierarchical Models
2. Hierarchical Models2. Hierarchical Models
Suppose we wish to build an automobile Suppose we wish to build an automobile that we can animatethat we can animate
We can build it from the chassis, and 4 We can build it from the chassis, and 4 wheelswheels
CS 480/680 9Chapter 9 -- Hierarchical Models
Two frames of our animation could Two frames of our animation could look like this:look like this:
We could calculate how far the wheel We could calculate how far the wheel moved, and have code that looks likemoved, and have code that looks like
calculate(speed, distance);calculate(speed, distance); draw_right_front_wheel(speed, dist);draw_right_front_wheel(speed, dist); draw_left_front_wheel(speed, dist);draw_left_front_wheel(speed, dist); draw_right_rear_wheel(speed, dist);draw_right_rear_wheel(speed, dist); draw_left_rear_wheel(speed, dist);draw_left_rear_wheel(speed, dist); draw_chassis(speed, dist);draw_chassis(speed, dist);
CS 480/680 10Chapter 9 -- Hierarchical Models
BUT this is the kind of code we do NOT BUT this is the kind of code we do NOT want....want....
It is linear, and it shows none of the It is linear, and it shows none of the relationships between the 5 objects.relationships between the 5 objects.
There are two types of relationships we There are two types of relationships we wish to conveywish to convey
First, we cannot separate the movement of the First, we cannot separate the movement of the car from the movement of the wheelscar from the movement of the wheels
If the car moves forward, the wheels must If the car moves forward, the wheels must turn.turn.
Second, we would like to note that all the Second, we would like to note that all the wheels are identical and just located and wheels are identical and just located and oriented differently.oriented differently.
We typically do this with a graph.We typically do this with a graph. Def: node, edge, root, leaf, ...Def: node, edge, root, leaf, ...
CS 480/680 11Chapter 9 -- Hierarchical Models
GraphGraph 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 loop: directed path that is a loop
loop
CS 480/680 12Chapter 9 -- Hierarchical Models
TreeTree Graph in which each node (except the Graph in which each node (except the
root) has exactly one parent noderoot) has exactly one parent node May have multiple childrenMay have multiple children Leaf or terminal node: no childrenLeaf or terminal node: no children
root node
leaf node
CS 480/680 13Chapter 9 -- Hierarchical Models
Tree Model of a carTree Model of a car
CS 480/680 14Chapter 9 -- Hierarchical Models
DAG ModelDAG Model If we use the fact that all the wheels are If we use the fact that all the wheels are
identical, we get a identical, we get a directed acyclic graphdirected acyclic graph Not much different than dealing with a treeNot much different than dealing with a tree
CS 480/680 15Chapter 9 -- Hierarchical Models
Modeling with treesModeling with trees Must decide what information to place in Must decide what information to place in
nodes and what to put in edgesnodes and what to put in edges NodesNodes
What to drawWhat to draw Pointers to childrenPointers to children
EdgesEdges May have information on incremental May have information on incremental
changes to transformation matrices (can also changes to transformation matrices (can also store in nodes)store in nodes)
CS 480/680 16Chapter 9 -- Hierarchical Models
3. A Robot Arm3. A Robot Arm
Robotics provides many opportunities Robotics provides many opportunities for developing hierarchical models. for developing hierarchical models. Consider this armConsider this arm
It consists of 3 partsIt consists of 3 parts
CS 480/680 17Chapter 9 -- Hierarchical Models
The mechanism has 3 degrees of The mechanism has 3 degrees of freedom, each of which can be described freedom, each of which can be described by a joint angle between the componentsby a joint angle between the components
In our model, each joint angle In our model, each joint angle determines how to position a component determines how to position a component with respect to the component to which with respect to the component to which it is attachedit is attached
CS 480/680 18Chapter 9 -- Hierarchical Models
Articulated ModelsArticulated Models 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 Can specify state of model by giving all joint
anglesangles
CS 480/680 19Chapter 9 -- Hierarchical Models
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 Must also translate relative to base and
rotate about connecting jointrotate about connecting joint Upper arm attached to lower armUpper arm attached to lower arm
Its position depends on both base and Its position depends on both base and lower armlower arm
Must translate relative to lower arm and Must translate relative to lower arm and rotate about joint connecting to lower rotate about joint connecting to lower armarm
CS 480/680 20Chapter 9 -- Hierarchical Models
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 arm: to upper 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
CS 480/680 21Chapter 9 -- Hierarchical Models
OpenGL Code for RobotOpenGL Code for Robotrobot_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();}}
CS 480/680 22Chapter 9 -- Hierarchical Models
Tree Model of RobotTree Model of Robot Note code shows Note code shows
relationships between parts relationships between parts of modelof model Can change “look” of parts Can change “look” of parts
easily without altering easily without altering relationshipsrelationships
Simple example of tree Simple example of tree modelmodel
Want a general node Want a general node structure for nodesstructure for nodes
CS 480/680 23Chapter 9 -- Hierarchical Models
Possible Node StructurePossible Node Structure
Code for drawing part orpointer to drawing function
linked list of pointers to children
matrix relating node to parent
CS 480/680 24Chapter 9 -- Hierarchical Models
GeneralizationsGeneralizations Need to deal with multiple childrenNeed to deal with multiple children
How do we represent a more general How do we represent a more general tree?tree?
How do we traverse such a data How do we traverse such a data structure?structure?
AnimationAnimation How to use dynamically?How to use dynamically? Can we create and delete nodes during Can we create and delete nodes during
execution?execution?
CS 480/680 25Chapter 9 -- Hierarchical Models
4. Trees and Traversals4. Trees and Traversals
Here we have a box-like Here we have a box-like representation of a human figure representation of a human figure and a tree representation.and a tree representation.
CS 480/680 26Chapter 9 -- Hierarchical Models
Building the ModelBuilding the Model Can build a simple implementation Can build a simple implementation
using quadrics: ellipsoids and using quadrics: ellipsoids and cylinderscylinders
Access parts through functionsAccess parts through functions torso()torso() left_upper_arm()left_upper_arm()
Matrices describe position of node Matrices describe position of node with respect to its parentwith respect to its parent MMllalla positions left lower arm with respect positions left lower arm with respect
to left upper armto left upper arm
CS 480/680 27Chapter 9 -- Hierarchical Models
Tree with MatricesTree with Matrices
CS 480/680 28Chapter 9 -- Hierarchical Models
Display and TraversalDisplay and Traversal The position of the figure is The position of the figure is
determined by 11 joint angles (two determined by 11 joint angles (two for the head and one for each other for the head and one for each other part)part)
Display of the tree requires a Display of the tree requires a graph graph traversaltraversal Visit each node onceVisit each node once Display function at each node that Display function at each node that
describes the part associated with the describes the part associated with the node, applying the correct node, applying the correct transformation matrix for position and transformation matrix for position and orientationorientation
CS 480/680 29Chapter 9 -- Hierarchical Models
Transformation MatricesTransformation Matrices There are 10 relevant matricesThere are 10 relevant matrices
MM positions and orients entire figure positions and orients entire figure through the torso which is the root nodethrough the torso which is the root node
MMhh positions head with respect to torso positions head with respect to torso
MMlualua, , MMruarua, , MMlullul, , MMrulrul position arms and legs position arms and legs with respect to torsowith respect to torso
MMllalla, , MMrlarla, , MMllllll, , MMrllrll position lower parts of position lower parts of limbs with respect to corresponding limbs with respect to corresponding upper limbsupper limbs
CS 480/680 30Chapter 9 -- Hierarchical Models
4.1 A Stack-Based 4.1 A Stack-Based TraversalTraversal
Set model-view matrix to Set model-view matrix to MM and draw and draw torsotorso
Set model-view matrix to Set model-view matrix to MMMMhh and draw and draw headhead
For left-upper arm need For left-upper arm need MMMMlua lua and so onand so on
Rather than recomputing Rather than recomputing MMMMlualua from from scratch or using an inverse matrix, we scratch or using an inverse matrix, we can use the matrix stack to store can use the matrix stack to store M M and and other matrices as we traverse the treeother matrices as we traverse the tree
CS 480/680 31Chapter 9 -- Hierarchical Models
Traversal CodeTraversal Codefigure() {figure() { glPushMatrix() glPushMatrix() // // save present model-view matrixsave present model-view matrix
torso();torso(); glRotate3f(…); glRotate3f(…); // // update model-view matrix for headupdate model-view matrix for head
head();head(); glPopMatrix(); glPopMatrix(); // // recover original model-view matrix recover original model-view matrix
glPushMatrix(); glPushMatrix(); // // save it againsave it again
glTranslate3f(…); glTranslate3f(…); // // update model-view matrix update model-view matrix
glRotate3f(…); glRotate3f(…); // // for left upper armfor left upper arm
left_upper_arm();left_upper_arm(); glPopMatrix(); glPopMatrix(); // // recover and save original recover and save original
glPushMatrix(); // glPushMatrix(); // model-view matrix againmodel-view matrix again
......
CS 480/680 32Chapter 9 -- Hierarchical Models
AnalysisAnalysis The code describes a particular tree The code describes a particular tree
and a particular traversal strategyand a particular traversal strategy Can we develop a more general Can we develop a more general
approach?approach? Note that the sample code does not Note that the sample code does not
include state changes, such as include state changes, such as changes to colorschanges to colors May also want to use May also want to use glPushAttribglPushAttrib and and glPopAttribglPopAttrib to protect against to protect against unexpected state changes affecting later unexpected state changes affecting later parts of the codeparts of the code
CS 480/680 33Chapter 9 -- Hierarchical Models
5. Use of Tree Data 5. Use of Tree Data StructuresStructures
Need a data structure to represent tree Need a data structure to represent tree and an algorithm to traverse the treeand an algorithm to traverse the tree
We will use a We will use a left-child right siblingleft-child right sibling structurestructure Uses linked listsUses linked lists Each node in data structure is two Each node in data structure is two
pointerspointers Left: next nodeLeft: next node Right: linked list of childrenRight: linked list of children
CS 480/680 34Chapter 9 -- Hierarchical Models
Left-Child Right-Sibling TreeLeft-Child Right-Sibling Tree
CS 480/680 35Chapter 9 -- Hierarchical Models
Tree node StructureTree node Structure At each node we need to store At each node we need to store
Pointer to siblingPointer to sibling Pointer to childPointer to child Pointer to a function that draws the Pointer to a function that draws the
object represented by the nodeobject represented by the node Homogeneous coordinate matrix to Homogeneous coordinate matrix to
multiply on the right of the current multiply on the right of the current model-view matrixmodel-view matrix
Represents changes going from Represents changes going from parent to nodeparent to node
In OpenGL this matrix is a 1D array In OpenGL this matrix is a 1D array storing matrix by columns storing matrix by columns
CS 480/680 36Chapter 9 -- Hierarchical Models
C Definition of treenodeC Definition of treenode
typedef struct treenodetypedef struct treenode
{{
Glfloat m[16];Glfloat m[16];
void (*f)();void (*f)();
struct treenode *sibling;struct treenode *sibling;
struct treenode *child;struct treenode *child;
} treenode;} treenode;
CS 480/680 37Chapter 9 -- Hierarchical Models
Defining the torso nodeDefining the torso nodetreenode torso_node, head_node, lua_node,treenode torso_node, head_node, lua_node, … ;… ;
/* use OpenGL functions to form matrix *//* use OpenGL functions to form matrix */glLoadIdentity();glLoadIdentity();glRotatef(theta[0], 0.0, 1.0, 0.0);glRotatef(theta[0], 0.0, 1.0, 0.0); /* move model-view matrix to m *//* move model-view matrix to m */glGetFloatv(GL_MODELVIEW_MATRIX, glGetFloatv(GL_MODELVIEW_MATRIX, torso_node.m)torso_node.m)
torso_node.f = torso; /* torso() draws torso torso_node.f = torso; /* torso() draws torso */*/
Torso_node.sibling = NULL;Torso_node.sibling = NULL;Torso_node.child = &head_node;Torso_node.child = &head_node;
CS 480/680 38Chapter 9 -- Hierarchical Models
NotesNotes The position of figure is determined by 11 The position of figure is determined by 11
joint angles stored injoint angles stored in theta[11]theta[11] Animate by changing the angles and Animate by changing the angles and
redisplayingredisplaying We form the required matrices usingWe form the required matrices using glRotateglRotate andand glTranslateglTranslate
More efficient than softwareMore efficient than software Because the matrix is formed in model-Because the matrix is formed in model-
view matrix, we may want to first push view matrix, we may want to first push original model-view matrix on matrix original model-view matrix on matrix stackstack
CS 480/680 39Chapter 9 -- Hierarchical Models
Preorder TraversalPreorder Traversalvoid traverse(treenode *root)void traverse(treenode *root){{ if(root == NULL) return;if(root == NULL) return; glPushMatrix();glPushMatrix(); glMultMatrix(root->m);glMultMatrix(root->m); root->f();root->f(); if(root->child != NULL) if(root->child != NULL) traverse(root->child);traverse(root->child); glPopMatrix();glPopMatrix(); if(root->sibling != NULL) if(root->sibling != NULL) traverse(root->sibling);traverse(root->sibling);}}
CS 480/680 40Chapter 9 -- Hierarchical Models
NotesNotes We must save model view matrix We must save model view matrix
before multiplying it by node matrix before multiplying it by node matrix Updated matrix applies to children of Updated matrix applies to children of
node but not to siblings which contain node but not to siblings which contain their own matricestheir own matrices
The traversal program applies to any The traversal program applies to any left-child right-sibling treeleft-child right-sibling tree The particular tree is encoded in the The particular tree is encoded in the
definition of the individual nodesdefinition of the individual nodes The order of traversal matters The order of traversal matters
because of possible state changes in because of possible state changes in the functionsthe functions
CS 480/680 41Chapter 9 -- Hierarchical Models
Dynamic TreesDynamic Trees If we use pointers, the structure can be If we use pointers, the structure can be
dynamicdynamic
typedef treenode *tree_ptr;typedef treenode *tree_ptr;
tree_ptr torso_ptr;tree_ptr torso_ptr;
torso_ptr = malloc(sizeof(treenode));torso_ptr = malloc(sizeof(treenode));
Definition of nodes and traversal are Definition of nodes and traversal are essentially the same as before but we can essentially the same as before but we can add and delete nodes during executionadd and delete nodes during execution
CS 480/680 42Chapter 9 -- Hierarchical Models
6. Animation6. Animation
This section discusses basic This section discusses basic animation animation
It then introduces kinematics and It then introduces kinematics and inverse kinematics.inverse kinematics.
CS 480/680 43Chapter 9 -- Hierarchical Models
7. Graphical Objects7. Graphical Objects
Limitations of Immediate Mode GraphicsLimitations of Immediate Mode Graphics When we define a geometric object in an When we define a geometric object in an
application, upon execution of the code the application, upon execution of the code the object is passed through the pipeline object is passed through the pipeline
It then disappears from the graphical It then disappears from the graphical systemsystem
To redraw the object, either changed or the To redraw the object, either changed or the same, we must reexecute the codesame, we must reexecute the code
Display lists provide only a partial solution Display lists provide only a partial solution to this problemto this problem
CS 480/680 44Chapter 9 -- Hierarchical Models
7.1 Methods, Attributes, 7.1 Methods, Attributes, and Messagesand Messages
OpenGL and ObjectsOpenGL and Objects 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 We can model the sphere with polygons or use OpenGL quadricsOpenGL quadrics
Its color is determined by the OpenGL state and Its color is determined by the OpenGL state and is not a property of the objectis not a property of the object
Defies our notion of a physical objectDefies our notion of a physical object We can try to build better objects in code We can try to build better objects in code
using object-oriented languages/techniquesusing object-oriented languages/techniques
CS 480/680 45Chapter 9 -- Hierarchical Models
Imperative Programming ModelImperative Programming Model Example: rotate a cubeExample: rotate a cube
The rotation function must know how The rotation function must know how the cube is representedthe cube is represented Vertex listVertex list Edge listEdge list
Application glRotate
cube data
results
CS 480/680 46Chapter 9 -- Hierarchical Models
Object-Oriented Programming Object-Oriented Programming ModelModel In this model, the representation is stored In this model, the representation is stored
with the object with the object
The application sends a The application sends a messagemessage to the to the object object
The object contains functions (The object contains functions (methodsmethods) ) which allow it to transform itselfwhich allow it to transform itself
Application Cube Objectmessage
CS 480/680 47Chapter 9 -- Hierarchical Models
C/C++C/C++ Can try to use C structs to build Can try to use C structs to build
objects objects C++ provides better supportC++ provides better support
Use class constructUse class construct Can hide implementation using public, Can hide implementation using public,
private, and protected members in a private, and protected members in a classclass
Can also use friend designation to allow Can also use friend designation to allow classes to access each otherclasses to access each other
CS 480/680 48Chapter 9 -- Hierarchical Models
7.2 A Cube Object7.2 A Cube Object
Suppose that we want to create a Suppose that we want to create a simple cube object that we can simple cube object that we can scale, orient, position and set its scale, orient, position and set its color directly through code such ascolor directly through code such ascube 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]=………
CS 480/680 49Chapter 9 -- Hierarchical Models
Cube Object FunctionsCube Object Functions We would also like to have functions that We would also like to have functions that
act on the cube such as act on the cube such as 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); setcolor(mycube, 1.0, 0.0, 0.0);setcolor(mycube, 1.0, 0.0, 0.0);
We also need a way of displaying the We also need a way of displaying the cubecube mycube.render();mycube.render();
CS 480/680 50Chapter 9 -- Hierarchical Models
Building the Cube ObjectBuilding the Cube Objectclass cube {class cube {
public:public:
float color[3];float color[3];
float matrix[4][4];float matrix[4][4];
// public methods// public methods
private:private:
// implementation// implementation
}}
CS 480/680 51Chapter 9 -- Hierarchical Models
7.3 Implementing the 7.3 Implementing the Cube ObjectCube Object
Can use any implementation in the Can use any implementation in the private part such as a vertex listprivate part such as a vertex list
The private part has access to public The private part has access to public members and the implementation of members and the implementation of class methods can use any class methods can use any implementation without making it implementation without making it visiblevisible
Render method is tricky but it will Render method is tricky but it will invoke the standard OpenGL drawing invoke the standard OpenGL drawing functions such as functions such as glVertexglVertex
CS 480/680 52Chapter 9 -- Hierarchical Models
7.5 Geometric Objects7.5 Geometric Objects
Suppose that we now want to build Suppose that we now want to build an object-oriented graphics systems.an object-oriented graphics systems. What objects should we include?What objects should we include? Points, vectors, polygons, rectangles, Points, vectors, polygons, rectangles,
and trianglesand triangles
CS 480/680 53Chapter 9 -- Hierarchical Models
Other objects have geometric Other objects have geometric aspectsaspects CamerasCameras Light sourcesLight sources
But we should be able to have But we should be able to have non-geometric objects toonon-geometric objects too MaterialsMaterials ColorsColors Transformations (matrices)Transformations (matrices)
CS 480/680 54Chapter 9 -- Hierarchical Models
Application CodeApplication Code
cube mycube;cube mycube;
material plastic;material plastic;
mycube.setMaterial(plastic);mycube.setMaterial(plastic);
camera frontView;camera frontView;
frontView.position(x ,y, z);frontView.position(x ,y, z);
CS 480/680 55Chapter 9 -- Hierarchical Models
Light ObjectLight Object
class light { // match Phong modelclass light { // match Phong model public:public: boolean type; //ortho or perspectiveboolean type; //ortho or perspective boolean near;boolean near; float position[3];float position[3]; float orientation[3];float orientation[3]; float specular[3];float specular[3]; float diffuse[3];float diffuse[3]; float ambient[3];float ambient[3];}}
CS 480/680 56Chapter 9 -- Hierarchical Models
8. Scene Graphs8. Scene Graphs
If we recall figure model, we saw that If we recall figure model, we saw that We could describe model either by tree or We could describe model either by tree or
by equivalent codeby equivalent code We could write a generic traversal to We could write a generic traversal to
displaydisplay If we can represent all the elements of a If we can represent all the elements of a
scene (cameras, lights,materials, scene (cameras, lights,materials, geometry) as C++ objects, we should geometry) as C++ objects, we should be able to show them in a treebe able to show them in a tree Render scene by traversing this treeRender scene by traversing this tree
CS 480/680 57Chapter 9 -- Hierarchical Models
CS 480/680 58Chapter 9 -- Hierarchical Models
Preorder TraversalPreorder TraversalglPushAttribglPushAttrib
glPushMatrix glPushMatrix
glColorglColor
glTranslateglTranslate
glRotateglRotate
Object1Object1
glTranslateglTranslate
Object2Object2
glPopMatrixglPopMatrix
glPopAttribglPopAttrib
……
CS 480/680 59Chapter 9 -- Hierarchical Models
Separator NodesSeparator Nodes Necessary to isolate state changesNecessary to isolate state changes
Equivalent to OpenGL Push/PopEquivalent to OpenGL Push/Pop Note that as with the figure modelNote that as with the figure model
We can write a universal traversal We can write a universal traversal algorithmalgorithm
The order of traversal can matter The order of traversal can matter If we do not use the separator node, If we do not use the separator node,
state changes can propagatestate changes can propagate
CS 480/680 60Chapter 9 -- Hierarchical Models
Inventor and Java3DInventor and Java3D Inventor and Java3D provide a scene graph Inventor and Java3D provide a scene graph
API API Scene graphs can also be described by a Scene graphs can also be described by a
file (text or binary)file (text or binary) Implementation independent way of Implementation independent way of
transporting scenestransporting scenes Supported by scene graph APIsSupported by scene graph APIs
However, primitives supported should However, primitives supported should match capabilities of graphics systemsmatch capabilities of graphics systems
Hence most scene graph APIs are built Hence most scene graph APIs are built on top of OpenGL or DirectX (for PCs)on top of OpenGL or DirectX (for PCs)
CS 480/680 61Chapter 9 -- Hierarchical Models
VRMLVRML Want to have a scene graph that can Want to have a scene graph that can
be used over the World Wide Webbe used over the World Wide Web Need links to other sites to support Need links to other sites to support
distributed data basesdistributed data bases VVirtual irtual RReality eality MMarkup arkup LLanguageanguage
Based on Inventor data baseBased on Inventor data base Implemented with OpenGLImplemented with OpenGL
CS 480/680 62Chapter 9 -- Hierarchical Models
9. A Simple Scene Graph 9. A Simple Scene Graph APIAPI
In this section the author develops a In this section the author develops a scene graph APIscene graph API Geometry NodesGeometry Nodes CamerasCameras Lights and MaterialsLights and Materials TransformationsTransformations
CS 480/680 63Chapter 9 -- Hierarchical Models
10. Other Tree 10. Other Tree StructuresStructures
The polygonal representations of objects The polygonal representations of objects that we have used has many strengths that we have used has many strengths and a few weaknesses.and a few weaknesses.
This section covers other representations This section covers other representations that attempt to deal with those that attempt to deal with those weaknessesweaknesses CSG TreesCSG Trees Shade TreesShade Trees BSP TreesBSP Trees Quadtrees and OctreesQuadtrees and Octrees
CS 480/680 64Chapter 9 -- Hierarchical Models
11. Graphics and the 11. Graphics and the WebWeb
The world wide web has had an The world wide web has had an enormous effect on virtually all enormous effect on virtually all communications and computer communications and computer applications.applications.
This section takes a graphics-oriented This section takes a graphics-oriented approach to see what extensions are approach to see what extensions are needed to develop web applications.needed to develop web applications. Protocols, HTML, VRML, Java and Protocols, HTML, VRML, Java and
applets are discussed.applets are discussed.
CS 480/680 65Chapter 9 -- Hierarchical Models
12. Summary and Notes12. Summary and Notes
The speed at which modern hardware The speed at which modern hardware can render geometric objects has can render geometric objects has opened up the possibilities of a variety opened up the possibilities of a variety of modeling systems.of modeling systems.
As users of computer graphics, we need As users of computer graphics, we need a large arsenal of techniques f we are to a large arsenal of techniques f we are to make full use of our graphics systems.make full use of our graphics systems.
CS 480/680 66Chapter 9 -- Hierarchical Models
We have presented the basic themes We have presented the basic themes that apply to most approaches to that apply to most approaches to modeling.modeling. One is the use of hierarchy to One is the use of hierarchy to
incorporate relationships among objects incorporate relationships among objects in a scene.in a scene.
We have seen that we can use We have seen that we can use fundamental data structures, such as fundamental data structures, such as trees and DAGs, to represent such trees and DAGs, to represent such relationshipsrelationships
And traversing these data structures And traversing these data structures becomes part of the rendering process.becomes part of the rendering process.
CS 480/680 67Chapter 9 -- Hierarchical Models
13. Suggested Readings13. Suggested Readings
Hierarchical transformations through Hierarchical transformations through the use of a matrix stack were described the use of a matrix stack were described in the graphics literature almost 30 in the graphics literature almost 30 years ago [New83].years ago [New83].
The PHIGS API [ANSI88] was the first to The PHIGS API [ANSI88] was the first to incorporate them as part of a standard incorporate them as part of a standard package.package.
Scene graphs are the heart of Open Scene graphs are the heart of Open Inventor [Wer94].Inventor [Wer94].
The Open Inventor database format was The Open Inventor database format was the basis for VRML [Har96]the basis for VRML [Har96]
CS 480/680 68Chapter 9 -- Hierarchical Models
Exercises -- Due next Exercises -- Due next classclass