Implementing Scene Graphs, CSG Trees Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, January 26, 2004.

Slides:



Advertisements
Similar presentations
CSG and Raytracing CPSC 407.
Advertisements

Christian Lauterbach COMP 770, 2/16/2009. Overview  Acceleration structures  Spatial hierarchies  Object hierarchies  Interactive Ray Tracing techniques.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part R4. Disjoint Sets.
Binary Trees CSC 220. Your Observations (so far data structures) Array –Unordered Add, delete, search –Ordered Linked List –??
CSE 381 – Advanced Game Programming Scene Management
CS447/ Realistic Rendering -- Solids Modeling -- Introduction to 2D and 3D Computer Graphics.
Multiple-key indexes Index on one attribute provides pointer to an index on the other. If V is a value of the first attribute, then the index we reach.
Tomas Mőller © 2000 Speeding up your game The scene graph Culling techniques Level-of-detail rendering (LODs) Collision detection Resources and pointers.
18.1 Si31_2001 SI31 Advanced Computer Graphics AGR Lecture 18 Image-based Rendering Light Maps What We Did Not Cover Learning More...
A lion in the desert How do you find a lion in the desert? How about when you have a predicate that tells you if the lion is in front or behind a separating.
B + -Trees (Part 1) Lecture 20 COMP171 Fall 2006.
A lion in the desert How do you find a lion in the desert? How about when you have a predicate that tells you if the lion is in front or behind a separating.
CS 206 Introduction to Computer Science II 02 / 11 / 2009 Instructor: Michael Eckmann.
Chapter 12 Trees. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Define trees as data structures Define the terms.
B + -Trees COMP171 Fall AVL Trees / Slide 2 Dictionary for Secondary storage * The AVL tree is an excellent dictionary structure when the entire.
10/11/2001CS 638, Fall 2001 Today Kd-trees BSP Trees.
10/02/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Octrees.
Hidden Surface Removal
BSP Trees, Quadtrees & Octrees Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, January 28, 2004.
Computing & Information Sciences Kansas State University CIS 536/636 Introduction to Computer Graphics Lecture 25 of 41 William H. Hsu Department of Computing.
Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering.
Managing Your Objects Paul Taylor 2009 Assignment Due Fri 5/6/2009.
Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009.
Kansas State University Department of Computing and Information Sciences CIS 736: Computer Graphics Wednesday, February 23, 2000 William H. Hsu Department.
AITI Lecture 20 Trees, Binary Search Trees Adapted from MIT Course 1.00 Spring 2003 Lecture 28 and Tutorial Note 10 (Teachers: Please do not erase the.
Data Structures for Scenes, The Basics of Scene Graphs Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday,
CS 1031 Tree Traversal Techniques; Heaps Tree Traversal Concept Tree Traversal Techniques: Preorder, Inorder, Postorder Full Trees Almost Complete Trees.
INTRODUCTION TO BINARY TREES P SORTING  Review of Linear Search: –again, begin with first element and search through list until finding element,
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
PRESENTED BY – GAURANGI TILAK SHASHANK AGARWAL Collision Detection.
Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url.
More on Advanced Interfaces, Image Basics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, November 21, 2003.
1 Chapter 10 Trees. 2 Definition of Tree A tree is a set of linked nodes, such that there is one and only one path from a unique node (called the root.
More on Drawable Objects, Hierarchical Objects Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, January.
Advanced HSR Methods Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday, January 30, 2004.
Jul 25, 2014IAT 3551 Scene Graphs.  A data structure that stores information about a graphics scene –Each node has information that structures the interpretation.
Intro. to Advanced Lighting, Basic Ray Tracing Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, April.
Binary Space Partitioning Trees Ray Casting Depth Buffering
Review 1 Queue Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
Lecture - 10 on Data Structures. 6:05:57 PM Prepared by, Jesmin Akhter, Lecturer, IIT,JU.
CS 206 Introduction to Computer Science II 10 / 02 / 2009 Instructor: Michael Eckmann.
Constructive Solid Geometry Ray Tracing CSG Models
Maths & Technologies for Games Spatial Partitioning 2
Data Structures Using C++ 2E Chapter 11 Binary Trees.
CS 367 Introduction to Data Structures Lecture 8.
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
CMSC 202, Version 5/02 1 Trees. CMSC 202, Version 5/02 2 Tree Basics 1.A tree is a set of nodes. 2.A tree may be empty (i.e., contain no nodes). 3.If.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
More on Ray Tracing Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, April 14, 2004.
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Solid Modeling Dr. Scott Schaefer.
(c) University of Washington20-1 CSC 143 Java Trees.
CS552: Computer Graphics Lecture 28: Solid Modeling.

Scene Manager Creates and places movable objects like lights and cameras so as to access them efficiently, e.g. for rendering. Loads and assembles world.
Bounding Volume Hierarchies and Spatial Partitioning
Bounding Volume Hierarchies and Spatial Partitioning
Trees Lecture 12 CS2110 – Fall 2017.
Binary Trees Lecture 36 Wed, Apr 21, /21/2018 Binary Trees.
Chapter 20: Binary Trees.
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Chapter 21: Binary Trees.
Hierarchical and Object-Oriented Graphics
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
Quadtrees 1.
Trees.
Trees Lecture 9 CS2110 – Fall 2009.
Trees CMSC 202, Version 5/02.
Hierarchical and Object-Oriented Graphics
Chapter 20: Binary Trees.
Presentation transcript:

Implementing Scene Graphs, CSG Trees Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, January 26, 2004

26 Jan 2004CS 481/6812 Review: Data Structures for Scenes We will discuss four types of trees for holding scenes: Scene Graphs Organized by how the scene is constructed. Nodes hold objects. CSG Trees Organized by how the scene is constructed. Leaves hold 3-D primitives. Internal nodes hold set operations. BSP Trees Organized by spatial relationships in the scene. Nodes hold facets (in 3-D, polygons). Quadtrees & Octrees Organized spatially. Nodes represent regions in space. Leaves hold objects.

26 Jan 2004CS 481/6813 Review: The Basics of Scene Graphs [1/2] Structure of a (simple) scene graph: Each node corresponds to a drawable object. The children of a given node correspond to “parts” of the object; these may be movable. Thus, each node has a transformation. It, and all of its descendants, are drawn with this transformation. The descendants have, in addition, their own transformations. Data needed in each node: Drawable object (pointer to this?). Transformation (a matrix? a pointer to a matrix? a pointer to a function that returns a matrix?). Pointers to child nodes.

26 Jan 2004CS 481/6814 Review: The Basics of Scene Graphs [2/2] In face.cpp, if we stored the face in a scene graph, it might look like this: We can add functionality to scene graphs by putting other things in them. In particular: Light sources. Other things like light sources (e.g., environment maps). Head EyeEar NoseMouth Iris Pupil Eye Iris Pupil L.R. Hair

26 Jan 2004CS 481/6815 Implementing Scene Graphs: Overview Now we look at how to implement a scene graph. What type of tree to use. The node data structure. Drawing via a simple recursive traversal. Deallocation issues. Lastly, we look briefly at a “DAG” variation, in which we do not use a tree.

26 Jan 2004CS 481/6816 Implementing Scene Graphs: Using B-Trees We often implement an arbitrary tree as a binary tree. We distinguish between the logical tree and the physical tree. The latter is the internal representation, which may be entirely hidden. Each node has a “down” pointer to its first (logical) child and a “right” pointer to the next (logical) child of its (logical) parent. Either or both of these may be null. A pre-order traversal of the physical tree gives a reasonable (pre- order, roughly speaking) traversal of the logical tree. Logical TreePhysical Tree

26 Jan 2004CS 481/6817 Implementing Scene Graphs: Node Implementation Say a node is an object of class SGNode. Each node needs: An object: (Drawable *). A transformation. I will use an array of 16 GLdouble ’s. You may want to do this differently. Down pointer & right pointer: (SGNode *). class SGNode { public: // Lots of stuff here: constructor(s), etc. void drawtree() const; // Draw objects in my subtree. private: Drawable * object; // Must be valid. GLdouble transform[16]; // Handle differently?? SGNode * downp; // Each of downp, rightp is SGNode * rightp; // either valid or null. };

26 Jan 2004CS 481/6818 Implementing Scene Graphs: Drawing Via Tree Traversal Now writing drawtree is easy: recursively traverse the tree. Stuff hanging off of downp uses this node’s transformation, but stuff hanging off of rightp does not. void SGNode::drawtree() const { glPushMatrix(); glMultMatrixd(transform); // Handle differently?? object->draw(); // virtual function call if (downp) downp->drawtree(); glPopMatrix(); if (rightp) rightp->drawtree(); } Draw the scene by calling drawtree for the root node.

26 Jan 2004CS 481/6819 Implementing Scene Graphs: The Node Destructor Everything needs to be deallocated. Generally, in a tree, each node is responsible for freeing its children. SGNode::~SGNode() { // Is the node responsible for delete'ing its object? // If not, then you don't want the line below. delete object; // transform is just an array member; we can ignore // it here. But if your transformation uses dynamic // allocation, you should probably deallocate it now. if (downp) delete downp; if (rightp) delete rightp; }

26 Jan 2004CS 481/68110 Implementing Scene Graphs: DAG Variation A Directed Acyclic Graph (DAG) is a generalization of a tree. Different nodes can share children. Thus, a node may not have a unique parent. We do not allow “cycles”: a node cannot be its own descendant. The 2-child-pointer idea does not work for a DAG. (Why not?) DAG’s are particularly appropriate for scene graphs, since identical objects can appear more than once in a scene. This means that an object cannot store its own transformation. Instead, it stores the transformations of its children. Deallocation gets interesting; a parent no longer “owns” its children. Solution 1: Each node keeps a reference count. When it hits 0, deallocate. Solution 2: Nodes do not manage each other at all. Keep all nodes in a list.

26 Jan 2004CS 481/68111 CSG Trees: Introduction to CSG We have constructed scenes with polygons (and points & lines). Another method is Constructive Solid Geometry (CSG). In CSG, primitives are solid 3-D objects. For example, Sphere Cube Cylinder Cone Etc. … We create new objects from existing ones using three set operations: Union Intersection Set difference CSG does not work well with pipeline-based rendering, so we will say little about it right now. CSG scenes are typically rendered using some type of ray tracing. The movie Tron (Disney, 1982) used CSG-style techniques. CSG is less mainstream than it used to be. I am told it is still used in CAD.

26 Jan 2004CS 481/68112 CSG Trees: Scene Representation In CSG, we represent a scene as a binary tree. Leaves hold primitives. Internal nodes, which always have two children, hold set operations. The order in which children are given matters (for the set-difference operation). CSG trees are useful for things other than rendering. Intersection tests (collision detection, etc.) are not too hard. (Thus: ray tracing.) A DAG may be appropriate here as well. U UU ∩ – sphere cubeconespherecube

26 Jan 2004CS 481/68113 A Brief Introduction to BSP Trees A very different way of storing a scene is a Binary Space Partition tree (BSP tree). BSP trees are useful for visibility-related issues, HSR, etc. Nodes hold polygons. In 3-D nodes hold polygons. In 2-D they would hold line segments. Thus, a BSP tree provides a relatively low-level description of a scene. Data about the arrangement of the scene is encoded in the structure of the tree. Details on the board …