Dr. Chih-Kuo Yeh 葉智國 Email: simpson.ycg@gmail.com Computer Graphics Dr. Chih-Kuo Yeh 葉智國 Email: simpson.ycg@gmail.com.

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.
Transformations Objectives Understand how transformations work in 2D and 3D Understand the concept of homogenous coordinate system Understand scene graphs.
Hierarchical Modeling II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Transformations III Week.
Graphical Objects and Scene Graphs CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
CSC 123 – Animating characters Hierarchical modeling Zoë Wood.
Hierarchical Transformations and Models CSE 3541 Matt Boggus.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology 3D Engines and Scene Graphs Spring 2012.
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.
COMP 175: Computer Graphics March 10, 2015
Objectives Review some advanced topics, including Review some advanced topics, including Chapter 8: Implementation Chapter 8: Implementation Chapter 9:
Computer Animation Rick Parent Computer Animation Algorithms and Techniques Kinematic Linkages.
Chapter 10 Bresenham’s Algorithm Data Structures and Graphics or Working with Models.
Transforms Hierarchical Modeling Scene Graphs Using hierarchical modeling techniques in 3D software design Transforms Local basis Matrix math review Matrices.
Demetriou/Loizidou – ACSC330 – Chapter 9 Hierarchical and Object-Oriented Modeling Dr. Giorgos A. Demetriou Dr. Stephania Loizidou Himona Computer Science.
Data Structures for Scenes, The Basics of Scene Graphs Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday,
Computer Animation Rick Parent Computer Animation Algorithms and Techniques Kinematic Linkages.
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 Scene Graphs ©Anthony Steed Scene Graph Overview n Building Scene Structures n Traversal n Examples n Instancing and Re-Use n More Transformations.
Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.
Kinematics Jehee Lee Seoul National University. Kinematics How to animate skeletons (articulated figures) Kinematics is the study of motion without regard.
1 Scene Graphs Week 4.2 ©Anthony Steed
Jul 25, 2014IAT 3551 Scene Graphs.  A data structure that stores information about a graphics scene –Each node has information that structures the interpretation.
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
1/50 CS148: Introduction to Computer Graphics and Imaging Transforms CS148: Introduction to Computer Graphics and Imaging Transforms.
Computer Graphics I, Fall 2008 Hierarchical Modeling II.
Scene Graph & Game Engines. 2 Limitations of Immediate Mode Graphics  When we define a geometric object in an application, upon execution of the code.
Computer Graphics Matrix Hierarchies / Animation
Models & Hierarchies CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2006.
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.
Hierarchical Modeling. 2 Objectives Build a tree-structured model of a humanoid figure. Examine various traversal strategies. Build a generalized tree-model.
CS559: Computer Graphics Lecture 13: Hierarchical Modeling and Curves Li Zhang Spring 2010.
Computer Graphics I, Fall 2008 Hierarchical Modeling I.
CSCE 441: Computer Graphics: Hierarchical Models Jinxiang Chai.
The Modelview Stack Lecture 9 Wed, Sep 12, The Modelview Stack OpenGL maintains a stack of matrices. The matrix on top of the stack is the current.
Hierarchical Models Chapter 9.
CSCE 210 Data Structures and Algorithms
IAT 355 Scene Graphs Feb 23, 2017 IAT 355.
Graphical Objects and Scene Graphs
Graphical Objects and Scene Graphs
Csc 2720 Instructor: Zhuojun Duan
Lecture Trees Chapter 9 of textbook 1. Concepts of trees
Using the basic-objects-IFS.js Utility
Modeling and Hierarchy
Hierarchical Modeling II
Hierarchical Transformations Hierarchical Models Scene Graphs
TREE DATA STRUCTURE Data Structure 21-Sep-18 Tree
Computer Graphics - Hierarchical Models-
Modeling and Hierarchy
Hierarchical and Object-Oriented Graphics
Introduction to Computer Graphics with WebGL
CSCE 441: Computer Graphics: Hierarchical Models
Graphs Chapter 11 Objectives Upon completion you will be able to:
Hierarchical and Object-Oriented Graphics
Transformations 4 University of British Columbia
Hierarchical Modeling I
Hierarchical Modeling & Constructive Solid Geometry
Transformations III Week 3, Mon Jan 21
Hierarchical Modeling
Computer Graphics Matrix Hierarchies / Animation
CSCE 441: Computer Graphics: Hierarchical Models
Trees.
Presentation transcript:

Dr. Chih-Kuo Yeh 葉智國 Email: simpson.ycg@gmail.com Computer Graphics Dr. Chih-Kuo Yeh 葉智國 Email: simpson.ycg@gmail.com

Hierarchical Models Hierarchical models used to represent complex objects explicit dependency between sub-parts of an object object-oriented approach to implementation e.g. Articulated objects (robot arm) Scene hierarchical uses to represent all objects in as a hierarchy shapes/lights/viewpoints/transforms/attributes ‘Scene Graph’ Scenes can be represented non-hierarchically leads to difficulties in scaling to large scale complex scenes all functions explicit in display() function inflexible Design of graphics systems with multiple objects hierarchical models object-oriented design scene graphs

Non-Hierarchical Modelling Treat object independently reference object by a unique symbol i.e. a,b,c…. Object initially defined in local object coordinates Transform each object instance from local to world coordinates: OpenGL display function: display(){ ….. Scalef(…); Rotatef(…); Translatef(...); draw_object(); };

Non-Hierarchical Modelling All objects are treated independently display() function transforms/draws each object explicitly No interrelations between objects Can represent objects by a table structure: each object has a symbol each object has corresponding translation/rotation/scale each object has set of attributes colour/material properties etc. render object by calling drawing each symbol in turn with specified transformation/attributes

Symbol-Instance Table

Hierarchical Models Consider a more complex model composed of several sub-objects car = chassis + 4 wheels Representation 1: Treat all parts independently (non-hierarchical) apply transformation to each part independently chassis: translate, draw chassis wheel 1: rotate, translate, draw wheel 1 wheel 2: rotate, translate, draw wheel 2 …. redundant, repeated computation of translate no explicit representation of dependence between chassis and wheels

Representation 2: Group parts hierarchically exploit relation between parts exploit similarity i.e. wheels are identical (just translated)

Graph Structures Graph Representation - nodes: objects + attributes? + transforms? - edges: dependency between objects parent-child relation between nodes ‘Directed-Graph’ edges have a direction associated with them Tree - directed graph with no closed-loops i.e. cannot return to the same point in the graph - ‘root node’: no entering edges - Intermediate nodes have one parent and one or more children - ‘leaf node’: no children Parameters such as location & attributes may be stored either in nodes or edges

Hierarchical Models We represent such models using transformations Each transformation represents a relative change from one scaling, position and orientation to another

Example: a small solar system A sun Two planets A moon around each planet

Example: a small solar system Every primitive is drawn as a sphere DrawSolidSphere(...); The use of PushMatrix() and PopMatrix() allow for Using the present model-view matrix to place objects preserving the model-view matrix for drawing other objects

Example: Solar system Relationships The sun stands still. Planets rotate around the sun and spin around their y-axis The moons rotate around their planet spin around their y-axis Rotate around the sun (together with their planet)

Just one planet and one moon void draw() { ... // set the projection and the camera here (see labs) // draw the scene DrawSolidSphere(...); // sun Rotate(angle_1p, 0, 1, 0); Translate(radius_1p); DrawSolidSphere(...); // first planet Rotate(angle_1m, 0, 1, 0); Translate(radius_1m); DrawSolidSphere(...); // moon around first planet }

Adding another planet with a moon void draw() { ... // set the projection and the camera here (see labs) // draw the scene DrawSolidSphere(...); // sun PushMatrix(); // save the model-view matrix into the transformation stack Rotate(angle_1p, 0, 0, 1); Translate(radius_1p); DrawSolidSphere(...); // first planet Rotate(angle_1m, 0, 0, 1); Translate(radius_1m); DrawSolidSphere(...); // moon around first planet PopMatrix(); // restore the model-view matrix (pop from stack) Rotate(angle_2p, 0, 0, 1); Translate(radius_2p); DrawSolidSphere(...); // second planet Rotate(angle_2m, 0, 0, 1); Translate(radius_2m); DrawSolidSphere(...); // moon around second planet }

Making one planet spin around its own axis void draw() { ... // set the projection and the camera here (see labs) // draw the scene DrawSolidSphere(...); // sun PushMatrix(); // save the model-view matrix into the transformation stack Rotate(angle_1p, 0, 0, 1); Translate(radius_1p); PushMatrix(); Rotate(angle_1rot, 0, 1, 0); // spin! DrawSolidSphere(...); // first planet PopMatrix(); Rotate(angle_1m, 0, 0, 1); Translate(radius_1m); SolidSphere(...); // moon around first planet PopMatrix(); // restore the model-view matrix (pop from stack) ... // draw the second planet here }

Example: Robot Arm Represented by a tree with a single chain Explicit hierarchical implementation (i) Base: Rotate about base R(θ1) M1 = R(θ1) (ii) Upper-arm: translate & rotate M2 = M1 T(l2 )R(θ2) (iii) lower-arm: translate & rotate M3 = M2 T(l3 )R(θ3) (iv) end-effector: translate & rotate M4 = M3 T(l4 )R(θ4) Base Upper-arm Lower-arm End-effector OpenGL: display(){ draw_base() Rotatef(θ1,0,0,1); draw_upperarm(); Translatef(0,l2 ,0); Rotatef(θ2,0,0,1); draw_lowerarm(); …… }

This example demonstrates an explicit hierarchy hard-coded in display function hierarchy cannot be changed (inflexible) Object-oriented hierarchical tree data structure Each node ‘object’ store (1) Transformation of object M (2) Pointer to function to draw object (3) Pointers to children

OpenGL pseudo code for single chain tree display(){ draw_arm(root); /* single call to recursive function */ } draw_arm(node){ Transform(node.M); /* apply model transform */ node.draw(); /* draw this part */ draw_arm(node.child); /* recursive call to children */

Example: Torso This figure consists of a torso and connected part, each arm and leg has two parts, but each arm and leg depend on the location & orientation of the torso, but not each other. Lets assume we can build the individual parts head(), torso(), left_upper_arm() etc. Each part can be located w.r.t its parent by a translation and one or more rotations.

Example: Torso The display callback must traverse the tree i.e. visit every node, drawing the object for that node, using the correct model-view matrix A standard pre-order traversal (that travels down the left of the tree, visiting each node) is used

Example: Torso

First draw torso. It only has one angle associated with it that allows it to rotate about y. Then we go to the head, however note we have to come back up to the torso to get to the arms and legs Any matrix that we apply to draw the head is not required for the arms or legs. Rather than recomputed the matrix that we apply to the torso node we can save it on the stack with a PushMatrix(). We can then go to the node for the head, changing the model-view matrix as necessary to draw the head. When we come back up to the torso node, we recover the model-view matrix with a PopMatrix() We have to come back up the torso after dealing with the left arm so we must go to a PushMatrix() immediately after the pop to keep a copy of the same model-view matrix

Simple! Although it appears convoluting, the rule is simple – every time we go to the left at a node with another unvisited right child we do a push; every time we return to the node we do a pop. Note we must do a pop at the end so the total number of pushes and pops is the same

PushMatrix(); //save current model-view matrix Rotatef(theta[0], 0.0, 1.0, 0.0); DrawTorso(); PushMatrix(); //save current model-view matrix Translatef(0.0, TORSO_HEIGHT+0.5*HEAD_HEIGHT, 0.0); Rotatef(theta[1], 1.0, 0.0, 0.0); Rotatef(theta[2], 0.0, 1.0, 0.0); Translatef(0.0, -0.5*HEAD_HEIGHT, 0.0); DrawHead(); PopMatrix(); //we have drawn the head so go back up to torso PushMatrix(); //but now want to draw left arm so save the torso matrix again Translatef(-(TORSO_RADIUS+UPPER_ARM_RADIUS), 0.9*TORSO_HEIGHT, 0.0); Rotatef(theta[3], 1.0, 0.0, 0.0); DrawLeft_upper_arm(); Translatef(0.0, UPPER_ARM_HEIGHT, 0.0); Rotatef(theta[4], 1.0, 0.0, 0.0); DrawLeft_lower_arm();

PopMatrix(); //left arm done, go back up to torso PushMatrix(); //but we are going to draw the right arm so save the torso matrix again Translatef(TORSO_RADIUS+UPPER_ARM_RADIUS, 0.9*TORSO_HEIGHT, 0.0); Rotatef(theta[5], 1.0, 0.0, 0.0); DrawRight_upper_arm(); Translatef(0.0, UPPER_ARM_HEIGHT, 0.0); Rotatef(theta[6], 1.0, 0.0, 0.0); DrawRight_lower_arm(); PopMatrix(); //back up to torso PushMatrix(); //save it we are going to draw the left leg Translatef(-(TORSO_RADIUS+UPPER_LEG_RADIUS), 0.1*UPPER_LEG_HEIGHT, 0.0); Rotatef(theta[7], 1.0, 0.0, 0.0); DrawLeft_upper_leg(); Translatef(0.0, UPPER_LEG_HEIGHT, 0.0); Rotatef(theta[8], 1.0, 0.0, 0.0); DrawLeft_lower_leg();

PopMatrix(); //back to torso PushMatrix(); //save it as we are going to draw right leg Translatef(TORSO_RADIUS+UPPER_LEG_RADIUS, 0.1*UPPER_LEG_HEIGHT, 0.0); Rotatef(theta[9], 1.0, 0.0, 0.0); DrawRight_upper_leg(); Translatef(0.0, UPPER_LEG_HEIGHT, 0.0); Rotatef(theta[10], 1.0, 0.0, 0.0); Right_lower_leg(); PopMatrix(); //pop so that the total number of pushes = total number of pops!

Example: Skeleton Represent transformation matrices between each parent and child each matrix is the transformation of the object in local coordinates into the parents coordinates How do we traverse the tree to draw the figure? Any order i.e. depth-first, breadth-first 2 methods to implement traversal: (1) Stack based - use matrix stack to store required matrices (2) Recursive - store matrix within nodes of data structure

(1) Stack-based tree traversal draw_figure(){ PushMatrix(); /* torso transform */ draw_torso(); Translatef(…); /* transform of head relative to torso */ Rotatef(...); draw_head(); PopMatrix(); /* restore torso transform */ PushMatrix(); Translate(); /* left_arm */ Rotate(); draw_upperarm(); Translate(); draw_lowerarm(); Translate(); /* right arm */ …... } use matrix stack to store intermediate matrices current ModelView matrix M determines position of figure in scene

Can also use Push/Pop values from attribute stack i.e. color etc. PushAttrib(); PopAttrib(); Limitation of stack-based approach: explicit representation of tree in single function relies on application programmer to push/pop matrices hard-coded/inflexible source code must be changed for different hierarchical structure no clear distinction between building a model and rendering it

(2) Recursive tree data-structures typedef struct treenode { Glfloat m[16]; void (*draw)(); int nchild; struct treenode *children; } treenode; void draw_tree(treenode *node){ PushMatrix(); /* save transform*/ MultMatrixf(node->m); node->draw(); for (i=0;i<node->nchild;i++) ….. draw_tree(node->children[i]); PopMatrix(); /* restore transform */ } each node is a recursive structure with pointers to children use a standard tree structure to represent hierarchy render via tree traversal algorithm (independent of model)