Hierarchy I. Guoying Zhao 1 / 40

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

Hierarchical Modeling and Scene Graphs

Hierarchical Modeling and scene graphs

Hierarchical Models Week 9, Lecture 19

Hierarchical Modeling and Scene Graphs

Hierarchical Modelling

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

CS354 Computer Graphics Character Animation and Skinning

Hierarchical Modeling

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

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

Transformations. Rotation and Scaling

CSE Real Time Rendering Week 10

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

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

3.2 Hierarchical Modeling

Vertex Buffer Objects and Transformations Week 4

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

Lecture 08: Hierarchical Modeling with Scene Graphs

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

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

Hierarchical Modeling

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

Transforms 1 Christian Miller CS Fall 2011

Using GLU/GLUT Objects

Game Programming. Bing-Yu Chen National Taiwan University

Where We Are: Static Models

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

Lecture 5b. Transformation

Computer graphics MN1

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

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

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

TIEA311 Tietokonegrafiikan perusteet kevät 2018

MODELING AND HIERARCHY

Chapter 20: Binary Trees

Computer Graphics Geometric Transformations

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

BST Implementation. Data Structures. Lecture 4 Binary search trees (BST) Dr. Mahmoud Attia Sakr University of Ain Shams

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

Recursion, Trees and Tree Traversal. Module CE System Programming & Computer Control Systems

Transformations IV. Week 3, Wed Jan 20

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

Tree Structures. A hierarchical data structure whose point of entry is the root node

GL_MODELVIEW transformation

Binary Trees. Height 1

Modeling with Transformations

CE 221 Data Structures and Algorithms

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

Data Structure - Binary Tree 1 -

This week. CENG 732 Computer Animation. Warping an Object. Warping an Object. 2D Grid Deformation. Warping an Object.

LECTURE 11 TREE TRAVERSALS

CSE 214 Computer Science II Introduction to Tree

Graphical Objects and Scene Graphs

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010

Chapter 3: Modeling Transformation

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

Computer Graphics Hands-on

Programming II (CS300)

Graphics pipeline and transformations. Composition of transformations

CSE 230 Intermediate Programming in C and C++ Binary Tree

Scene Graphs. COMP 575/770 Fall 2010

OpenGL: Setup 3D World

CS 4204 Computer Graphics

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

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

CSI33 Data Structures

Why Do We Need Trees?

Binary Trees

Trees. CSE 373 Data Structures

Topic 18 Binary Trees "A tree may grow a thousand feet tall, but its leaves will return to its roots." -Chinese Proverb

Affine Transformations in 3D

Cpt S 122 Data Structures. Data Structures Trees

2D/3D Geometric Transformations and Scene Graphs

CSCI2100B Data Structures Trees

Better Interactive Programs

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

Binary Trees. Examples:

HIERARCHICAL TRANSFORMATIONS A Practical Introduction

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

Garbage Collection: recycling unused memory

lecture 9 Object hierarchies - call trees and GL_MODELVIEW stack - fractals - L systems

Applications. Human and animal motion Robotics control Hair Plants Molecular motion

Transformation Hierarchies. CS 4620 Lecture 5

DATA STRUCTURES AND ALGORITHMS

E.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.

CS/COE 1501 cs.pitt.edu/~bill/1501/ Graphs

Transformations IV. Week 3, Mon Jan 22

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop.

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

Notes. University of British Columbia

Fachhochschule Regensburg, Germany, February 15, 2017

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree.

Transformations III. Week 2, Fri Jan 19

CSC 470 Computer Graphics

Translation. 3D Transformations. Rotation about z axis. Scaling. CS 4620 Lecture 8. 3 Cornell CS4620 Fall 2009!Lecture 8

CS 231 Data Structures and Algorithms Fall Recursion and Binary Trees Lecture 21 October 24, Prof. Zadia Codabux

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

TREES. Trees - Introduction

Graphs & Digraphs Tuesday, November 06, 2007

Transcription:

Computer Graphics Hierarchy I Guoying Zhao 1 / 40

Hierarchical Modeling I Guoying Zhao 2 / 40

Objectives Examine the limitations of linear modeling Symbols and instances Introduce hierarchical models Articulated models Robots Introduce Tree and DAG (directed acyclic graph) models Guoying Zhao 3 / 40

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 Guoying Zhao 4 / 40

Symbol-Instance Table Can store a model by assigning a number to each symbol and storing the parameters for the instance transformation Guoying Zhao 5 / 40

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 Guoying Zhao 6 / 40

Structure Through Function Calls car(speed) { chassis() wheel(right_front); h wheel(left_front); wheel(right _ rear); wheel(left_rear); } Fails to show relationships well Look at problem using a graph Guoying Zhao 7 / 40

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

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 Guoying Zhao 9 / 40

Tree Model of Car Guoying Zhao 10 / 40

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 Guoying Zhao 11 / 40

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) Guoying Zhao 12 / 40

Robot Arm robot arm parts in their own coodinate systems Guoying Zhao 13 / 40

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 Guoying Zhao 14 / 40

Relationships in Robot Arm Base rotates t independently d Single angle determines position: Ry(θ) Lower arm attached to base Its position depends on rotation of base Must also translate t relative to base and rotate t about connecting joint: T(0,h1,0)Rz(φ) Ry(θ) T(0,h1,0)Rz(φ) 0)Rz(φ) 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: T(0,h2,0)Rz(ψ), (ψ) Ry(θ) T(0,h1,0)Rz(φ) T(0,h2,0)Rz(ψ) Guoying Zhao 15 / 40

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 lower 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 Guoying Zhao 16 / 40

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, 1.0, 0.0); lower_arm(); gltranslate(0.0, h2, 0.0); glrotate(psi, t 0.0, 0 1.0, 0.0); 0) upper_arm(); } Guoying Zhao 17 / 40

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 Guoying Zhao 18 / 40

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

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? Guoying Zhao 20 / 40

Hierarchical Modeling II Guoying Zhao 21 / 40

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 Guoying Zhao 22 / 40

Humanoid Figure Guoying Zhao 23 / 40

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 arm with respect to left upper arm Guoying Zhao 24 / 40

Tree with Matrices Guoying Zhao 25 / 40

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 Guoying Zhao 26 / 40

Tree traversal: depth-first, breadth-first. Depth first: start with the left branch, follow it to the left as deep as we can go, then go back up to the first right branch ---- pre-order traversal. Tree traversal function: explicitly itl (stacks) vs. implicitely (recursively) Guoying Zhao 27 / 40

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 especttotosoto torso M lla, M rla, M lll, M rll position lower parts of limbs with respect to corresponding upper limbs Guoying Zhao 28 / 40

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 Guoying Zhao 29 / 40

figure() { glpushmatrix() torso(); glrotate3f( ); head(); glpopmatrix(); glpushmatrix(); gltranslate3f( ); glrotate3f( ); left_upper_arm(); glpopmatrix(); glpushmatrix(); Guoying Zhao 30 / 40 Traversal Code 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 t against unexpected state changes affecting later parts of the code Guoying Zhao 31 / 40

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 t is two pointers Left: linked list of children (leftmost child) Right: pointer to the sibling node on the right Guoying Zhao 32 / 40

Left-Child Right-Sibling Tree Guoying Zhao 33 / 40

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 Guoying Zhao 34 / 40

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

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, t MATRIX torso_node.m) torso_node.f = torso; /* torso() draws torso */ Torso_node.sibling = NULL; // torso has no siblings Torso_node.child = &head_node; // its leftmost child is the head node. Guoying Zhao 36 / 40

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 ce than software Because the matrix is formed in model- view matrix, we may want to first push original model-view matrix on matrix stack Guoying Zhao 37 / 40

Preorder Traversal void traverse(treenode *root) { if(root == NULL) return; glpushmatrix(); // save the graphics state glmultmatrix(root->m); // modify model-view } root->f(); // draw the objects if(root->child!= NULL) traverse(root->child); glpopmatrix(); if(root->sibling!= NULL) traverse(root->sibling); Guoying Zhao 38 / 40

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 Guoying Zhao 39 / 40

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 Guoying Zhao 40 / 40