* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Fundamentals of Computer Graphics
General-purpose computing on graphics processing units wikipedia , lookup
BSAVE (bitmap format) wikipedia , lookup
Free and open-source graphics device driver wikipedia , lookup
Computer vision wikipedia , lookup
Apple II graphics wikipedia , lookup
Framebuffer wikipedia , lookup
Graphics processing unit wikipedia , lookup
Tektronix 4010 wikipedia , lookup
Fundamentals of Computer Graphics Part 8 Hierarchical&Object oriented Graphics prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared with Angel,E.: Interactive Computer Graphics – A Top Down Approach with OpenGL, Addison Wesley, 2001 Symbols&Instances Extension to transformations – Chapter 4 GLU&GLUT provide objects built on the top of OpenGL basic primitives NONHIERARCHICAL APPROACH • primitives or objects -> SYMBOLS • world is a collection of symbols APIs distinguish • model frame or model coordinates – where the model is defined • world frame Transformation from model frame to world frame is needed Fundamentals of Computer Graphics 2 Symbols&Instances M=TRS In OpenGL • appropriate transformation set up from the model frame (frame of symbols) to the world frame • apply it to the MODEL-VIEW matrix BEFORE EXECUTING the code Fundamentals of Computer Graphics 3 Symbols&Instances glMatrixMode(GL_MODELVIEW); /* M = T R S */ glLoadIdentity ( ); glTranslatef (....); glRotatef (...); glScalef(..); glutSolidCylinder (.....) /* or other symbol */ Fundamentals of Computer Graphics 4 Symbols&Instances • • equivalent of a model in the form of the table contains flat information – no information on the actual structure • how to represent complex structures? • each part has its own model frame coordinate system • how to manipulate with substructures Fundamentals of Computer Graphics 5 Hierarchical Models A car chassis & 4 wheels main ( ); { float s = ...;/*speed*/ float d[3]= {...}; /* direction */ draw_right_front_wheel (s,d); draw_left_front_wheel (s,d); draw_right_rear_wheel (s,d); draw_left_rear_wheel (s,d); draw_chassis (s,d); }/* WE DO NOT WANT THIS*/ two frames of animation Fundamentals of Computer Graphics 6 Hierarchical Models Description - as a graph • nodes & edges Tree – a directed graph • root node tree structure of a car • parent node • child nodes • terminal nodes – leafs Direct Acyclic Graph (DAG) • store a position of each wheel Trees & DAGs – hierarchical methods expressing the relational-ships Fundamentals of Computer Graphics 7 A Robot Arm A robot arm – three parts • each has 3 degrees of freedom – described by joint angle between components display ( ) { glRotatef(theta, 0.0., 1.0., 0.0); base( ); glTranslatef(0.0, h1, 0.0); glRotatef(phi, 0.0., 0.0., 1.0); lower_arm ( ); glTranslatef(0.0, h2, 0.0); glRotatef(psi, 0.0., 0.0., 1.0); upper_arm( ); }/* arm positioning independent to individual parts details */ Fundamentals of Computer Graphics 8 A Robot Arm If information stored in nodes (not in edges) – each node must store at least: • pointer to a function that draws the object represented by the node • matrix that positions, scales and orients this node relative to the node’s parent (including children) • pointer to children of the node Fundamentals of Computer Graphics 9 Trees and Traversal All matrices are incremental and any traversal algorithm can be used (depth-first or breadth-first); - we will traverse left to right & depth first Explicit traversal explicitly in the code, using stacks to store required matrices and attributes Recursive – code is simpler, storage of matrices&attributes done implicitly Fundamentals of Computer Graphics 10 Trees and Traversal All matrices are incremental and any traversal algorithm can be used (depth-first or breadth-first); - we will traverse left to right & depth first Explicit traversal explicitly in the code, using stacks to store required matrices and attributes Recursive – code is simpler, storage of matrices&attributes done implicitly Fundamentals of Computer Graphics 11 Stack Based Traversal figure( ) { glPushMatrix( ); torso ( ); glTranslatef (..); glRotate3 (..); head ( ); glPopMatrix ( ); /* restore state for the torso */ glPushMatrix( ); /* save the state for torso*/ glTranslatef (..); glRotate3 (..); left_upper_leg ( ); glTranslatef (..); glRotate3 (..); left_lower_leg ( ); /* incremental change */ glPopMatrix ( ); /* recent state recovery */ /* ----*/ glPushMatrix( ); .......... } Fundamentals of Computer Graphics 12 Tree Data Structures typedef struct treenode { GLfloat m[16]; void (*f) ( ); struct treenode *sibling; struct treenode *child; } treenode; .... treenode torso_node, head_node, ....; Fundamentals of Computer Graphics 13 Tree Data Structures glLoadIdentity ( ); glRotatef(theta[0],0.0, 1.0, 0.0); glGetFloatv(GL_MODELVIEW_MATRIX, torso_node.m); /* matrix elements copied to the m of the node */ /* the torso node has no sibling; leftmost child is the head node */ /* rest of the code for the torso node*/ torso_node.f = torso; torso_node.sibling = NULL; torso_node.child = &head_node; Fundamentals of Computer Graphics 14 Tree Data Structures /* for the upper-arm node */ glLoadIdentity ( ); glTranslatef(-(TORSO_RADIUS+UPPER_ARM_RADIUS), 0.9*TORSO_HEIGHT, 0.0) glRotatef(theta[3], 1.0, 0.0, 0.0); glGetFloatv(GL_MODELVIEW_MATRIX, lua_node.m); /* matrix elements copied to the m of the node */ lua_node.f = left_upper_arm; lua_node.sibling = &rua_node; lua_node.child = &lla_node; Fundamentals of Computer Graphics 15 Tree Data Structures – Recursive Solution /* assumption MODEL-VIEW state */ void traverse (treenode* root); { if (root==NULL) return; glPushMatrix( ); glMultMatrixf(root->m); root->f( ); if (root->child!=NULL) traverse(root->child); glPopMatrix ( ); if (root->sibling!=NULL) traverse(root->sibling); } /* traversal method is independent from the particular tree !! */ Fundamentals of Computer Graphics 16 Tree Data Structures – Recursive Solution generic display callback function void display (void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity ( ); traverse ( &torso_node); glutSwapBuffers( ); } Read p.346-347 to analyze the whole program including the interaction, read chapters 8.6 – 8.8 on your own Fundamentals of Computer Graphics 17 Other Tree Structures DAG structures provide tools for describing scenes • Constructive Solid Geometry – CSG trees uses solids objects to create the required object how to make an object with a hole? • BSP trees – work wit surface • Quadtrees & Octrees – discrete technique & space subdivision Fundamentals of Computer Graphics 18 Constructive Solid Geometry CSG – set operations • union • intersection • difference • complement AB AB A-B -B Describe intersection of 3 orthogonal cylinders • • simple symbolic manipulations difficult to evaluate and render Fundamentals of Computer Graphics 19 Constructive Solid Geometry plane A separates polygons to two groups => BINARY SPATIAL-PARTITIONING TREE • standard tree techniques can be used • useful for visibility solution Fundamentals of Computer Graphics 20 Quadtrees & Octrees BSP trees do not have “a orientation” in space – application can be costly Quadtrees – hierarchical space subdivision technique - often used for image data compression - pixels Octree – extension to 3D applications volume representation - voxels Fundamentals of Computer Graphics 21 Hierarchical & Object oriented Graphics In this chapter you have learnt: • fundamentals how very complex structures can be created and manipulated • how the hierarchical structures can be used for real applications • what could be a structure of database for geometric objects Have a look at: • the SPIDER project at http://herakles.zcu.cz - hierarchical modeling & animation • F-rep project – HyperFun language for implicit modeling – practical use of CSG trees Fundamentals of Computer Graphics 22