Hierarchical Modeling II

Slides:



Advertisements
Similar presentations
Using GLU/GLUT Objects GLU/GLUT provides very simple object primitives glutWireCube glutWireCone gluCylinder glutWireTeapot.
Advertisements

Hierarchical Modeling I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Hierarchical Modeling II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
CSC 123 – Animating characters Hierarchical modeling Zoë Wood.
Hierarchical Transformations and Models CSE 3541 Matt Boggus.
Hierarchical Transformations Hierarchical Models Scene Graphs
Hierarchy, Modeling, and Scene Graphs Angel: Chapter 10 OpenGL Programming and Reference Guides, other sources. ppt from Angel, AW, etc. CSCI 6360/4360.
CSE Real Time Rendering
Chapter 10 Bresenham’s Algorithm Data Structures and Graphics or Working with Models.
Demetriou/Loizidou – ACSC330 – Chapter 9 Hierarchical and Object-Oriented Modeling Dr. Giorgos A. Demetriou Dr. Stephania Loizidou Himona Computer Science.
Computer Animation Rick Parent Computer Animation Algorithms and Techniques Kinematic Linkages.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Week 4 Lecture 1: Hierarchical Modeling Part 1 Based on Interactive Computer Graphics (Angel) - Chapter 10 1 Angel: Interactive Computer Graphics 5E ©
Hierarchical Modeling. Instance Transformation Start with a prototype object (a symbol) Each appearance of the object in the model is an instance – Must.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 40 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 40 Computer Graphics Hierarchy I.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Hierarchical and Object-Oriented Graphics Construct complex models from a set of simple geometric objects Extend the use of transformations to include.
Transformations Tutorial
Computer Graphics I, Fall 2008 Hierarchical Modeling II.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 9.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell Hierarchical Modeling.
University of New Mexico
Hierarchical Modeling. 2 Objectives Build a tree-structured model of a humanoid figure. Examine various traversal strategies. Build a generalized tree-model.
Copyright © 2012 Pearson Education, Inc. Chapter 20: Binary Trees.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 20: Binary Trees.
Computer Graphics I, Fall 2008 Hierarchical Modeling I.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 20: Binary Trees.
CSCE 441: Computer Graphics: Hierarchical Models Jinxiang Chai.
Hierarchical Models Chapter 9.
Introduction to Computer Graphics with WebGL
OpenGL Transformations
Graphical Objects and Scene Graphs
Representation Ed Angel Professor Emeritus of Computer Science,
Using the basic-objects-IFS.js Utility
Modeling and Hierarchy
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Chapter 20: Binary Trees.
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Computer Graphics - Hierarchical Models-
Modeling and Hierarchy
Chapter 21: Binary Trees.
Hierarchical and Object-Oriented Graphics
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
CSCE 441: Computer Graphics: Hierarchical Models
Introduction to Computer Graphics with WebGL
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
Building Models Ed Angel Professor Emeritus of Computer Science
Hierarchical and Object-Oriented Graphics
Introduction to Computer Graphics with WebGL
Hierarchical Modeling I
Introduction to Computer Graphics with WebGL
Hierarchical Modeling & Constructive Solid Geometry
Introduction to Computer Graphics with WebGL
Transformations Ed Angel Professor Emeritus of Computer Science
Representation Ed Angel Professor Emeritus of Computer Science,
Programming with OpenGL Part 3: Shaders
Chapter 20: Binary Trees.
Computer Viewing Ed Angel Professor Emeritus of Computer Science
Dr. Chih-Kuo Yeh 葉智國 Computer Graphics Dr. Chih-Kuo Yeh 葉智國
Hierarchical Modeling
Introduction to Computer Graphics with WebGL
Computer Graphics Matrix Hierarchies / Animation
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
CSCE 441: Computer Graphics: Hierarchical Models
Presentation transcript:

Hierarchical Modeling II Ed Angel Professor Emeritus of Computer Science University of New Mexico E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

Objectives Build a tree-structured model of a humanoid figure Examine various traversal strategies Build a generalized tree-model structure that is independent of the particular model E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

Humanoid Figure E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

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 Mlla positions left lower leg with respect to left upper arm E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

Tree with Matrices E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

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 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

Transformation Matrices There are 10 relevant matrices M positions and orients entire figure through the torso which is the root node Mh positions head with respect to torso Mlua, Mrua, Mlul, Mrul position arms and legs with respect to torso Mlla, Mrla, Mlll, Mrll position lower parts of limbs with respect to corresponding upper limbs E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

Stack-based Traversal Set model-view matrix to M and draw torso Set model-view matrix to MMh and draw head For left-upper arm need MMlua and so on Rather than recomputing MMlua from scratch or using an inverse matrix, we can use the matrix stack to store M and other matrices as we traverse the tree E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

Traversal Code save present model-view matrix figure() { PushMatrix() torso(); Rotate (…); head(); PopMatrix(); PushMatrix(); Translate(…); Rotate(…); left_upper_arm(); 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 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

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 a PushAttrib and PopAttrib to protect against unexpected state changes affecting later parts of the code E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

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 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

Left-Child Right-Sibling Tree E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

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 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

C Definition of treenode typedef struct treenode { mat4 m; void (*f)(); struct treenode *sibling; struct treenode *child; } treenode; E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

torso and head nodes treenode torso_node, head_node, lua_node, … ; torso_node.m = RotateY(theta[0]); torso_node.f = torso; torso_node.sibling = NULL; torso_node.child = &head_node; head_node.m = translate(0.0, TORSO_HEIGHT+0.5*HEAD_HEIGHT, 0.0)*RotateX(theta[1])*RotateY(theta[2]); head_node.f = head; head_node.sibling = &lua_node; head_node.child = NULL; E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

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 Rotate and Translate More efficient than software Because the matrix is formed using the model-view matrix, we may want to first push original model-view matrix on matrix stack E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

Preorder Traversal void traverse(treenode* root) { if(root==NULL) return; mvstack.push(model_view); model_view = model_view*root->m; root->f(); if(root->child!=NULL) traverse(root->child); model_view = mvstack.pop(); if(root->sibling!=NULL) traverse(root->sibling); } E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

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 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

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 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012