Hierarchical Modeling and Scene Graphs

Similar documents
Hierarchical Modeling and Scene Graphs

Hierarchical Modeling and scene graphs

Hierarchical Modelling

Hierarchy I. Guoying Zhao 1 / 40

Hierarchical Modeling II. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Graphical Objects and Scene Graphs

Hierarchical Modeling

Hierarchical Models Week 9, Lecture 19

Hierarchical Modeling. CS 432 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Hierarchical Modeling I. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Hierarchical Modeling. CS 432 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

CS354 Computer Graphics Character Animation and Skinning

Modeling Objects. Modeling. Symbol-Instance Table. Instance Transformation. Each appearance of the object in the model is an instance

Computer Graphics (CS 543) Lecture 6a: Hierarchical 3D Models. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

CSE Real Time Rendering Week 10

Hierarchical Modeling. University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell

Transformations. Rotation and Scaling

3.2 Hierarchical Modeling

Reading. Hierarchical Modeling. Symbols and instances. Required: Angel, sections , 9.8. Optional:

Vertex Buffer Objects and Transformations Week 4

Lecture 08: Hierarchical Modeling with Scene Graphs

Hierarchical Models. Roadmap. Importance of shadows. Importance of shadows. Importance of shadows. Importance of shadows

Two possible ways to specify transformations. Each part of the object is transformed independently relative to the origin

Using GLU/GLUT Objects

Computer graphics MN1

Where We Are: Static Models

Better Interactive Programs. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Transforms 1 Christian Miller CS Fall 2011

Scene Graphs. CS4620/5620: Lecture 7. Announcements. HW 1 out. PA 1 will be out on Wed

Hierarchical Modeling

Game Programming. Bing-Yu Chen National Taiwan University

Hierarchical Modeling: Tree of Transformations, Display Lists and Functions, Matrix and Attribute Stacks,

MODELING AND HIERARCHY

COMP 175 COMPUTER GRAPHICS. Lecture 07: Scene Graph. COMP 175: Computer Graphics March 10, Remco Chang 07 Scene Graph

CS4202: Test. 1. Write the letter corresponding to the library name next to the statement or statements that describe library.

6.837 Computer Graphics Hierarchical Modeling Wojciech Matusik, MIT EECS Some slides from BarbCutler & Jaakko Lehtinen

Graphics pipeline and transformations. Composition of transformations

Lecture 5b. Transformation

6.837 Introduction to Computer Graphics Assignment 5: OpenGL and Solid Textures Due Wednesday October 22, 2003 at 11:59pm

Lecture 5: Viewing. CSE Computer Graphics (Fall 2010)

Spring 2013, CS 112 Programming Assignment 2 Submission Due: April 26, 2013

Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

GL_MODELVIEW transformation

Modeling with Transformations

CHAPTER 1 Graphics Systems and Models 3

CS 352: Computer Graphics. Hierarchical Graphics, Modeling, And Animation

CS 4204 Computer Graphics

Graphics and Visualization

Computer Graphics Geometric Transformations

CS 428: Fall Introduction to. Transformations in OpenGL + hierarchical modeling. Andrew Nealen, Rutgers, /21/2009 1

TIEA311 Tietokonegrafiikan perusteet kevät 2018

3D Graphics Pipeline II Clipping. Instructor Stephen J. Guy

CS 465 Program 4: Modeller

Better Interactive Programs

Fachhochschule Regensburg, Germany, February 15, 2017

CSC 470 Computer Graphics

Computer Graphics. Chapter 7 2D Geometric Transformations

Chapter 20: Binary Trees

OpenGL: Setup 3D World

The Viewing Pipeline adaptation of Paul Bunn & Kerryn Hugo s notes

COMP3421. Week 2 - Transformations in 2D and Vector Geometry Revision

OpenGL Transformations

OpenGL. Toolkits.

Chapter 5 - The Scene Graph

GEOMETRIC OBJECTS AND TRANSFORMATIONS I

Scene Graphs. COMP 575/770 Fall 2010

Transformations IV. Week 3, Wed Jan 20

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

Using GLU/GLUT Objects. GLU/GLUT Objects. glucylinder() glutwirecone() GLU/GLUT provides very simple object primitives

2D/3D Geometric Transformations and Scene Graphs

Lecture 4 Advanced Computer Graphics (CS & SE )

Display Lists. Conceptually similar to a graphics file. In client-server environment, display list is placed on server

Affine Transformations in 3D

Modeling Transform. Chapter 4 Geometric Transformations. Overview. Instancing. Specify transformation for objects 李同益

COMP3421. Week 2 - Transformations in 2D and Vector Geometry Revision

CSE Intro to Computer Graphics. ANSWER KEY: Midterm Examination. November 18, Instructor: Sam Buss, UC San Diego

Rendering Pipeline and Coordinates Transforms

Introduction to 3D Graphics with OpenGL. Z-Buffer Hidden Surface Removal. Binghamton University. EngiNet. Thomas J. Watson

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

CS 591B Lecture 9: The OpenGL Rendering Pipeline

Outline. Introduction Surface of Revolution Hierarchical Modeling Blinn-Phong Shader Custom Shader(s)

CS 381 Computer Graphics, Fall 2012 Midterm Exam Solutions. The Midterm Exam was given in class on Tuesday, October 16, 2012.

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

Computer Graphics I Lecture 11

Viewing with Computers (OpenGL)

Transformation Hierarchies. CS 4620 Lecture 5

HIERARCHICAL TRANSFORMATIONS A Practical Introduction

Overview. By end of the week:

Transformations IV. Week 3, Mon Jan 22

CS451Real-time Rendering Pipeline

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

Computer Graphics. Prof. Feng Liu. Fall /21/2016

Cheating: In case of cheating, all parts involved (source(s) and receiver(s)) get zero.

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

High Level Graphics Programming & VR System Architecture

Hierarchical Models Josef Pelikán & Alexander Wilkie CGG MFF UK Praha

CS 381 Computer Graphics, Fall 2008 Midterm Exam Solutions. The Midterm Exam was given in class on Thursday, October 23, 2008.

Hidden Surface Removal. 3D Graphics with OpenGL. Back-Face Culling

Chapter 3: Modeling Transformation

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

Transcription:

Hierarchical Modeling and Scene Graphs Adapted from material prepared by Ed Angel Spring 2009

Objectives Examine the limitations of linear modeling Symbols and instances Introduce hierarchical models Articulated models Robots Introduce Tree and DAG models Examine various traversal strategies Generalize the notion of objects to include lights, cameras, attributes Introduce scene graphs

Instance Transformation Start with a prototype object (a symbol) Each appearance of the object in the model is an instance Must scale, orient, position Defines instance transformation

Relationships in Car Model Symbol-instance table does not show relationships between parts of model Consider model of car Chassis + 4 identical wheels Two symbols Rate of forward motion determined by rotational speed of wheels

Structure Through Function Calls car(speed){ chassis() wheel(right_front); wheel(left_front); wheel(right_rear); wheel(left_rear); } Fails to show relationships well Look at problem using a graph

Graphs Set of nodes and edges (links) Edge connects a pair of nodes Directed or undirected Cycle: directed path that is a loop loop

Tree Graph in which each node (except the root) has exactly one parent node May have multiple children Leaf or terminal node: no children root node leaf node

Tree Model of Car

DAG Model If we use the fact that all the wheels are identical, we get a directed acyclic graph Not much different than dealing with a tree

Modeling with Trees Must decide what information to place in nodes and what to put in edges Nodes What to draw Pointers to children Edges May have information on incremental changes to transformation matrices (can also store in nodes)

Robot Arm robot arm parts in their own coodinate systems

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

Relationships in Robot Arm Base rotates independently Single angle determines position Lower arm attached to base Its position depends on rotation of base Must also translate relative to base and rotate about connecting joint Upper arm attached to 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

Required Matrices Rotation of base: R b Apply M = R b to base Translate lower arm relative to base: T lu Rotate lower arm around joint: R lu Apply M = R b T lu R lu to lower arm Translate upper arm relative to upper arm: T uu Rotate upper arm around joint: R uu Apply M = R b T lu R lu T uu R uu to upper arm

OpenGL Code for Robot robot_arm(){ glrotate(theta, 0.0, 1.0, 0.0); base(); gltranslate(0.0, h1, 0.0); glrotate(phi, 0.0, 0.0, 1.0); lower_arm(); gltranslate(0.0, h2, 0.0); glrotate(psi, 0.0, 0.0, 1.0); upper_arm(); }

Tree Model of Robot Note code shows relationships between parts of model Can change look of parts easily without altering relationships Simple example of tree model Want a general node structure for nodes

Possible Node Structure Code for drawing part or pointer to drawing function linked list of pointers to children matrix relating node to parent

Generalizations Need to deal with multiple children How do we represent a more general tree? How do we traverse such a data structure? Animation How to use dynamically? Can we create and delete nodes during execution?

Humanoid Figure

Building the Model Can build a simple implementation using quadrics: ellipsoids and cylinders Access parts through functions torso() left_upper_arm() Matrices describe position of node with respect to its parent M lla positions left lower leg with respect to left upper arm

Tree with Matrices

Display and Traversal The position of the figure is determined by 11 joint angles (two for the head and one for each other part) Display of the tree requires a graph traversal Visit each node once Display function at each node that describes the part associated with the node, applying the correct transformation matrix for position and orientation

Transformation Matrices There are 10 relevant matrices M positions and orients entire figure through the torso which is the root node M h positions head with respect to torso M lua, M rua, M lul, M rul position arms and legs with respect to torso M lla, M rla, M lll, M rll position lower parts of limbs with respect to corresponding upper limbs

Stack-based Traversal Set model-view matrix to M and draw torso Set model-view matrix to MM h and draw head For left-upper arm need MM lua and so on Rather than recomputing MM lua from scratch or using an inverse matrix, we can use the matrix stack to store M and other matrices as we traverse the tree

Traversal Code figure() { glpushmatrix() torso(); glrotate3f( ); head(); glpopmatrix(); glpushmatrix(); gltranslate3f( ); glrotate3f( ); left_upper_arm(); glpopmatrix(); glpushmatrix(); save present model-view matrix update model-view matrix for head recover original model-view matrix save it again update model-view matrix for left upper arm recover and save original model-view matrix again rest of code

Analysis The code describes a particular tree and a particular traversal strategy Can we develop a more general approach? Note that the sample code does not include state changes, such as changes to colors May also want to use glpushattrib and glpopattrib to protect against unexpected state changes affecting later parts of the code

General Tree Data Structure Need a data structure to represent tree and an algorithm to traverse the tree We will use a left-child right sibling structure Uses linked lists Each node in data structure is two pointers Left: next node Right: linked list of children

Left-Child Right-Sibling Tree

Tree node Structure At each node we need to store Pointer to sibling Pointer to child Pointer to a function that draws the object represented by the node Homogeneous coordinate matrix to multiply on the right of the current model-view matrix Represents changes going from parent to node In OpenGL this matrix is a 1D array storing matrix by columns

C Definition of treenode typedef struct treenode { GLfloat m[16]; void (*f)(); struct treenode *sibling; struct treenode *child; } treenode;

Defining the torso node treenode torso_node, head_node, lua_node, ; /* use OpenGL functions to form matrix */ glloadidentity(); glrotatef(theta[0], 0.0, 1.0, 0.0); /* move model-view matrix to m */ glgetfloatv(gl_modelview_matrix, torso_node.m) torso_node.f = torso; /* torso() draws torso */ Torso_node.sibling = NULL; Torso_node.child = &head_node;

Notes The position of figure is determined by 11 joint angles stored in theta[11] Animate by changing the angles and redisplaying We form the required matrices using glrotate and gltranslate More efficient than software Because the matrix is formed in model-view matrix, we may want to first push original model-view matrix on matrix stack

Preorder Traversal void traverse(treenode *root){ if(root == NULL) return; glpushmatrix(); glmultmatrix(root->m); root->f(); if(root->child!= NULL) traverse(root->child); glpopmatrix(); if(root->sibling!= NULL) traverse(root->sibling); }

Notes We must save model-view matrix before multiplying it by node matrix Updated matrix applies to children of node but not to siblings which contain their own matrices The traversal program applies to any left-child right-sibling tree The particular tree is encoded in the definition of the individual nodes The order of traversal matters because of possible state changes in the functions

Dynamic Trees If we use pointers, the structure can be dynamic typedef treenode *tree_ptr; tree_ptr torso_ptr; torso_ptr = malloc(sizeof(treenode)); Definition of nodes and traversal are essentially the same as before but we can add and delete nodes during execution

Limitations of Immediate Mode Graphics 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 To redraw the object, either changed or the same, we must reexecute the code Display lists provide only a partial solution to this problem

OpenGL and Objects OpenGL lacks an object orientation Consider, for example, a green sphere 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 Defies our notion of a physical object We can try to build better objects in code using object-oriented languages/techniques

Imperative Model Example: rotate a cube cube data Application glrotate results The rotation function must know how the cube is represented Vertex list Edge list

Object-Oriented Model In this model, the representation is stored with the object Application message Cube Object The application sends a message to the object The object contains functions (methods) which allow it to transform itself

C/C++ Can try to use C structs to build objects C++ provides better support Use class construct Can hide implementation using public, private, and protected members in a class Can also use friend designation to allow classes to access each other

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]=

Cube Object Functions We would also like to have functions that act on the cube such as mycube.translate(1.0, 0.0,0.0); mycube.rotate(theta, 1.0, 0.0, 0.0); setcolor(mycube, 1.0, 0.0, 0.0); We also need a way of displaying the cube mycube.render();

Building the Cube Object class cube { public: float color[3]; float matrix[4][4]; // public methods } private: // implementation

The Implementation Can use any implementation in the private part such as a vertex list The private part has access to public members and the implementation of class methods can use any implementation without making it visible Render method is tricky but it will invoke the standard OpenGL drawing functions such as glvertex

Other Objects Other objects have geometric aspects Cameras Light sources But we should be able to have nongeometric objects too Materials Colors Transformations (matrices)

Application Code cube mycube; material plastic; mycube.setmaterial(plastic); camera frontview; frontview.position(x,y, z);

Light Object class light { // match Phong model public: boolean type; //ortho or perspective boolean near; float position[3]; float orientation[3]; float specular[3]; float diffuse[3]; float ambient[3]; }

Scene Descriptions If we recall figure model, we saw that We could describe model either by tree or by equivalent code 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 Render scene by traversing this tree

Scene Graph

Preorder Traversal glpushattrib glpushmatrix glcolor gltranslate glrotate Object1 gltranslate Object2 glpopmatrix glpopattrib

Separator Nodes Necessary to isolate state chages Equivalent to OpenGL Push/Pop Note that as with the figure model We can write a universal traversal algorithm The order of traversal can matter If we do not use the separator node, state changes can propagate

Inventor and Java3D Inventor and Java3D provide a scene graph API Scene graphs can also be described by a file (text or binary) Implementation independent way of transporting scenes Supported by scene graph APIs However, primitives supported should match capabilities of graphics systems Hence most scene graph APIs are built on top of OpenGL or DirectX (for PCs)

VRML Want to have a scene graph that can be used over the World Wide Web Need links to other sites to support distributed data bases Virtual Reality Markup Language Based on Inventor data base Implemented with OpenGL