Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.

Slides:



Advertisements
Similar presentations
2.6. B OUNDING V OLUME H IERARCHIES Overview of different forms of bounding volume hierarchy.
Advertisements

Heuristic Search techniques
Introduction to Algorithms Quicksort
AI Pathfinding Representing the Search Space
Christian Lauterbach COMP 770, 2/16/2009. Overview  Acceleration structures  Spatial hierarchies  Object hierarchies  Interactive Ray Tracing techniques.
Restart Trail for Stackless BVH Traversal Samuli Laine NVIDIA Research.
Binary Trees CSC 220. Your Observations (so far data structures) Array –Unordered Add, delete, search –Ordered Linked List –??
AVL Trees1 Part-F2 AVL Trees v z. AVL Trees2 AVL Tree Definition (§ 9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that.
Chapter 4: Trees Part II - AVL Tree
Types of Algorithms.
Quick Review of Apr 10 material B+-Tree File Organization –similar to B+-tree index –leaf nodes store records, not pointers to records stored in an original.
Searching on Multi-Dimensional Data
Part2 AI as Representation and Search
2-dimensional indexing structure
CPSC 231 B-Trees (D.H.)1 LEARNING OBJECTIVES Problems with simple indexing. Multilevel indexing: B-Tree. –B-Tree creation: insertion and deletion of nodes.
Quicksort.
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Part B Part A:  Index Definition in SQL  Ordered Indices  Index Sequential.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
Blind Search-Part 2 Ref: Chapter 2. Search Trees The search for a solution can be described by a tree - each node represents one state. The path from.
B + -Trees (Part 1). Motivation AVL tree with N nodes is an excellent data structure for searching, indexing, etc. –The Big-Oh analysis shows most operations.
Bounding Volume Hierarchies and Spatial Partitioning Kenneth E. Hoff III COMP-236 lecture Spring 2000.
Chapter 12 Trees. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Define trees as data structures Define the terms.
R-Trees 2-dimensional indexing structure. R-trees 2-dimensional version of the B-tree: B-tree of maximum degree 8; degree between 3 and 8 Internal nodes.
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Trees.
Homework #3 Due Thursday, April 17 Problems: –Chapter 11: 11.6, –Chapter 12: 12.1, 12.2, 12.3, 12.4, 12.5, 12.7.
Backtracking.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 20: Binary Trees.
Binary Trees Chapter 6.
Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering.
B-Tree. B-Trees a specialized multi-way tree designed especially for use on disk In a B-tree each node may contain a large number of keys. The number.
ICS 220 – Data Structures and Algorithms Week 7 Dr. Ken Cosh.
CHAPTER 71 TREE. Binary Tree A binary tree T is a finite set of one or more nodes such that: (a) T is empty or (b) There is a specially designated node.
Chapter Tow Search Trees BY HUSSEIN SALIM QASIM WESAM HRBI FADHEEL CS 6310 ADVANCE DATA STRUCTURE AND ALGORITHM DR. ELISE DE DONCKER 1.
1 Trees Tree nomenclature Implementation strategies Traversals –Depth-first –Breadth-first Implementing binary search trees.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
March 7 & 9, Csci 2111: Data and File Structures Week 8, Lectures 1 & 2 Multi-Level Indexing and B-Trees.
Chapter 6 Binary Trees. 6.1 Trees, Binary Trees, and Binary Search Trees Linked lists usually are more flexible than arrays, but it is difficult to use.
12.1 Chapter 12: Indexing and Hashing Spring 2009 Sections , , Problems , 12.7, 12.8, 12.13, 12.15,
PRESENTED BY – GAURANGI TILAK SHASHANK AGARWAL Collision Detection.
Lecture 3: Uninformed Search
Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Algorithms April-May 2013 Dr. Youn-Hee Han The Project for the Establishing the Korea ㅡ Vietnam College of Technology in Bac Giang.
Basic Problem Solving Search strategy  Problem can be solved by searching for a solution. An attempt is to transform initial state of a problem into some.
1 Multi-Level Indexing and B-Trees. 2 Statement of the Problem When indexes grow too large they have to be stored on secondary storage. However, there.
Types of Algorithms. 2 Algorithm classification Algorithms that use a similar problem-solving approach can be grouped together We’ll talk about a classification.
M180: Data Structures & Algorithms in Java Trees & Binary Trees Arab Open University 1.
R-Trees: A Dynamic Index Structure For Spatial Searching Antonin Guttman.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
Trees Chapter 23 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Rooted Tree a b d ef i j g h c k root parent node (self) child descendent leaf (no children) e, i, k, g, h are leaves internal node (not a leaf) sibling.
B-TREE. Motivation for B-Trees So far we have assumed that we can store an entire data structure in main memory What if we have so much data that it won’t.
Indexing Database Management Systems. Chapter 12: Indexing and Hashing Basic Concepts Ordered Indices B + -Tree Index Files File Organization 2.
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.
Ray Tracing Optimizations
Ray Tracing Acceleration (5). Ray Tracing Acceleration Techniques Too Slow! Uniform grids Spatial hierarchies K-D Octtree BSP Hierarchical grids Hierarchical.
Data Structures and Algorithms Instructor: Tesfaye Guta [M.Sc.] Haramaya University.
Trees CSIT 402 Data Structures II 1. 2 Why Do We Need Trees? Lists, Stacks, and Queues are linear relationships Information often contains hierarchical.
8/3/2007CMSC 341 BTrees1 CMSC 341 B- Trees D. Frey with apologies to Tom Anastasio.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
Navigation Piles with Applications to Sorting, Priority Queues, and Priority Deques Jyrki Katajainen and Fabio Vitale Department of Computing, University.
Bounding Volume Hierarchies and Spatial Partitioning
Multiway Search Trees Data may not fit into main memory
Bounding Volume Hierarchies and Spatial Partitioning
B+ Tree.
Types of Algorithms.
CS202 - Fundamental Structures of Computer Science II
Types of Algorithms.
CMSC 202 Trees.
Types of Algorithms.
Presentation transcript:

Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology

2 Bounding Volume Hierarchies Wrapping objects in bounding volumes and performing tests on the bounding volumes before testing the object geometry itself can result in significant performance improvement. By arranging the bounding volumes into a tree hierarchy called a bounding volume hierarchy (BVH), the time complexity can be reduced to logarithmic in the number of tests performed.  With a hierarchy in place, during collision testing children do not have to be examined if their parent volume is not intersected.  Scene graphs, ray tracing, view-frustum culling.

3 Bounding Volume Hierarchies Comparison between bounding volume hierarchies and spatial partitioning schemes  The main differences are that two or more volumes in a BVH can cover the same space and objects are generally only inserted in a single volume.  In contrast, in a spatial partitioning scheme the partitions are disjoint and objects contained in the spatial partitioning are typically allowed to be represented in two or more partitions.

4 Bounding Volume Hierarchies Manual creation of hierarchies  Designers tend to think functionally rather than spatially. A grouping may not be suitable for collision detection.  The hierarchy is also likely to be either too shallow or too deep in the wrong places. A better solution is to automate the generation of hierarchies from the provided models.

5 Bounding Volume Hierarchies Hierarchy Design Issues  The nodes contained in any given subtree should be near each other.  Each node in the hierarchy should be of minimal volume.  The sum of all bounding volumes should be minimal.  Greater attention should be paid to nodes near the root of the hierarchy.  The volume of overlap of sibling nodes should be minimal.  The hierarchy should be balanced with respect to both its node structure and its content.

6 Bounding Volume Hierarchies For real-time applications, an important addition to the previous list is the requirement that the worst-case time for queries not be much worse than the average-case query time. It is also desired that the hierarchy can be automatically generated without user intervention. A very important factor often glossed over in treatments of collision detection is the total memory requirement for the data structures used to represent the bounding volume hierarchy.

7 Bounding Volume Hierarchies Cost function: The expected cost of bounding volume hierarchy queries  Example: T = N V C V + N P C P +N U C U + C O  T is the total cost of intersecting the two hierarchies  N V is the number of BV pairs tested for overlap  C V is the cost of testing a pair of BVs for overlap  N P is the number of primitive pairs tested.  C P is the cost of testing a primitive pair.  N U is the number of nodes that need to be updated.  C U is the cost of updating each such node  C O is the cost of a one-time processing.

8 Bounding Volume Hierarchies N V and N P are minimized by making the bounding volume fit the object as tightly as possible. By making the overlap tests as fast as possible, C V and C P are minimized. In general the values are so intrinsically linked that minimizing one value often causes another to increase.  Finding a compromise among existing requirements is a challenge in all collision detection systems.

9 Bounding Volume Hierarchies Degree of tree? What degree or branching factor should be use in the tree representing the bounding volume hierarchy?  A tree of a higher degree will be of smaller height, minimizing root-to- leaf traversal time.  More work has to be expended at each visited node to check its children for overlap.  The opposite holds for a low-degree tree. Then what degree should be used?  It is a difficult one and no definitive answer has been forthcoming.  It appears that binary trees are by far the most common hierarchical representation. It is easier to build, to represent and traverse than any other trees.

10 Building Strategies for Hierarchy Construction As the number of possible trees grows exponentially in terms of the number of elements in the input set, an exhaustive search for the best tree is infeasible.  This rules out finding an optimal tree.  Instead, heuristic rules are used to guide the construction, examining a few alternatives at each decision – making step, picking the best alternative. There are three primary categories of tree construction methods: top-down, bottom-up and insertion methods.

11 Building Strategies for Hierarchy Construction Top-down method  It proceeds by partitioning the input set into two subsets, bounding them in the chosen bounding volume, then recursing over the bounded subsets.  It is by far the most popular due to its ease of implementation.  However, they do not generally result in the best possible trees.

12 Top-down Construction A top-down method can be described in terms of a recursive procedure.  It starts out by bounding the input set of primitives in a bounding volume.  These primitives are then partitioned into two subsets.  The procedure is now called recursively to form sub- hierarchies for the two subsets, which are then connected as children to the parent volume.  The recursion stops when the input set consists of a single primitive, at which point the procedure just returns after creating the bounding volume for the primitive.

13 Top-down Construction The choice of how the input set is partitioned into two subsets.  Apart from the selection of what bounding volume to use, only a single guiding criterion controls the structure of the resulting tree  A set of n elements can be partitioned into two nonempty subsets in 2 n-1 -1 ways Only a small subset of all partitions can reasonably be considered.

14 Top-down Construction Partitioning Strategies  Median-cut algorithm The set is divided in two equal-size parts with respect to their projection along the selected axis, resulting in a balanced tree.  Minimize the sum of the volumes (or surface areas) of the child volumes  Minimize the maximum volume (surface area) of the child volumes  Minimize the volume (surface area) of the intersection of the child volumes  Maximize the separation of child volumes  Divide primitives equally between the child volumes  Combinations of the previous strategies.

15 Top-down Construction Stopping criteria  The node contains just a single primitive, or less than some k primitives  The volume of the bounding volume has fallen below a set cut-off limit  The depth of the node has reached a predefined cut-off depth. Partitioning can fail when  All primitives fall on one side of the split plane.  One or both child volumes end up with as many primitives as the parent volume.  Both child volumes are as large as the parent volume. When partitioning fails, it is reasonable to try other partitioning criteria before stopping.

16 Top-down Construction Choice of Partitioning Axis  A single axis must be selected as the partitioning axis.  An iterative optimization can locate the best possible axis but it is too expensive. Consequently, the search must be limited to a small number of axes from which the best one is picked.

17 Top-down Construction Choice of Partitioning Axis  Common choices of axes Local x, y, and z coordinate axes Axes from the intended aligned bounding volume Axes of the parent bounding volume Axis through the two most distant points Axis along which variance is greatest  We may apply a small number of hill-climbing steps to improve on the axis.

18 Top-down Construction Choice of Split Point  As there are infinitely many splitting points along the axis, the selection must be restricted to a small set of choices Median of the centroid coordinates (object median) Mean of the centroid coordinates (object mean) Median of the bounding volume projection extents (spatial median) Splitting at k evenly spaced points along the bounding volume projection extents Splitting between (random subset of) the centroid coordinates Figure 6.3 here

19 Top-down Construction The advantages include ease of implementation and fast tree construction. The disadvantage is that as critical decisions are made early in the algorithm at a point where all information is not available the trees are typically not as good as possible.

20 Building Strategies for Hierarchy Construction Bottom-up method  It starts with the input set as the leaves of the tree and then group two or more of them to form a new node, proceeding in the same manner until everything has been grouped under a single node.  Although bottom-up methods are likely to produce better trees than the other methods, they are also more difficult to implement and slow in construction.

21 Building Strategies for Hierarchy Construction Bottom-up Construction  The first step is to enclose each primitive within a bounding volume. These volumes form the leaf nodes of the tree.  From the resulting set of volumes, two (or more) leaf nodes are selected based on some merging criterion. – a clustering rule.  These nodes are then bound within a bounding volume, which replaces the original nodes in the set.  This pairing procedure repeats until the set consists of a single bounding volume representing the root node of the constructed tree.

22 Building Strategies for Hierarchy Construction Bottom-up Construction  One of the more meaningful merging criteria is to select the pair so that the volume of their bounding volume is minimized. A brute-force approach for finding which two nodes to merge : O(n 2 ) Repeated n-1 times to form a full tree, the total construction time becomes O(n 3 ) There exists more sophisticated methods which outperform the brute force method.

23 Building Strategies for Hierarchy Construction Insertion method  It builds the hierarchy incrementally by inserting objects one at a time into the tree.  The insertion position is chosen so as to minimize some cost measurement for the resulting tree.  It is considered an on-line method in that it requires all primitives to be available before construction starts. It allows updates to be performed at runtime.

24 Building Strategies for Hierarchy Construction Insertion method

25 Building Strategies for Hierarchy Construction Insertion method  The tree is built by inserting one object at a time, starting from an empty tree.  Objects are inserted by finding the insertion location in the tree that causes the tree to grow as little as possible according to a cost metric. Normally the cost associated with inserting an object at a given position is taken to be the cost of its bounding volume plus the increase in volume its insertion causes in all ancestor volumes above it in the tree.  If the object being inserted is large compared to the existing nodes, it will tend to end up near the top of the hierarchy.

26 Building Strategies for Hierarchy Construction Insertion method  Smaller objects are more likely to lie within existing bounding volumes and will instead end up near the bottom.  When the new object is far away from existing objects it will also end up near the top.  Overall the resulting tree will therefore tend to reflect the actual clustering in the original set of objects.

27 Building Strategies for Hierarchy Construction Insertion method  Because the structure of a tree is dependent on the objects inserted into it and because insertion decisions are made based on the current structure, it follows that the order in which objects are inserted is significant. The best approach seems to be to randomly shuffle the objects before insertion.  A simple insertion method implementation would be to perform a single root-leaf traversal by consistently descending the child for which the insertion into would be cheaper. Then the insertion node would be selected from the visited nodes along the traced path such that the total tree volume would be minimized. -> O(nlog n)

28 Building Strategies for Hierarchy Construction Insertion method  Insertion strategies can be as fast as or even faster than top-down methods and could produce better results.  They are considered on-line methods in the sense that not all objects need be present when the process starts.  The Goldsmith-Salmon Incremental Construction Method  for constructing bounding volume hierarchies for use in ray tracing.

29 Hierarchy Traversal To determine the overlap status of two bounding volume hierarchies, some rule must be established for how to descend the trees when their top-level volumes overlap.  If the one hierarchy fully descended before the other one is?  Are they both descended? The two most fundamental tree-traversing methods are breadth- first search and depth-first search.

30 Hierarchy Traversal Breadth-first search (BFS) explores nodes at a given depth before proceeding deeper into the tree.  It suffers from the fact that stacking all nodes during traversal requires a substantial amount of memory. Depth-first search (DFS) proceeds into the tree, searching deeper rather than wider, backtracking up the tree when it reaches the leaves.  It seems to be the most popular choice for collision detection systems.  It often enhanced by a simple heuristic to guide the search along, improving on the basic blind DFS approach without the overhead of a full best-first search.

31 Hierarchy Traversal Uninformed or blind search methods  BFS and DFS methods  They do not examine and make traversal decisions based on the data contained in the traversed structure.  They only look at the structure itself to determine what nodes to visit next. Informed search methods  These attempts to utilize known information about the domain being searched through heuristic rules. Best-first search, a greedy algorithm that always moves to the node that scores best on some search criterion.

32 Hierarchy Traversal Descent Rules  Given two hierarchies A and B there are several possible traversal alternatives. Descend A before B is descended. Descend B before A is descended. Descend the larger volume. Descend A and B simultaneously. Descend A and B alternatingly. Descend based on overlap. Combinations of the previous or other complex rules based on traversal history.  Which type of traversal is most effective depends entirely on the structure of the data. For a very large data sets, hybrid approaches are likely to be more effective than a single tree hierarchy.

33 Collision Detection System First, using a pruning algorithm, all pairs of objects whose fixed cubes overlap are detected and stored in the pair list. Second, the object pairs are sent to exact collision detection algorithms. Finally, the results from collision detection are forwarded and taken care of by the application, so that action can be taken.

34 Collision Detection System

35 Efficient Tree Representation and Traversal It is important to optimize both the traversal code and the tree representation for an industrial-strength implementation. As memory accesses and branch prediction misses tend to cause large penalties in modern architectures, two obvious optimizations are  to minimize the size of the data structures involved  to arrange the data in a more cache-friendly way so that relevant information is encountered as soon as possible. It is difficult to predict cache behaviors. So some of more advanced techniques might not always provide the expected speedups.  Keep the traversal code as short and straightforward as possible might in fact be a simple way of making it faster.

36 Efficient Tree Representation and Traversal Array Representation  Assume a complete binary tree of n nodes is given as a collision hierarchy.  This tree can be stored into an array of n elements by mapping its nodes in a breadth-first level-by-level manner. Being at the node stored at array[i] the corresponding left child to the node will be found at array[2*i+1] and its right child at array[2*i+2].  Instead of representing the tree using nodes containing left and right pointers to the node’s children it is possible to completely remove all pointers and store the pointerless nodes in an array in the manner.

37 Efficient Tree Representation and Traversal A perfectly balanced tree saves memory space and pointer reads during tree traversal. But for a nonbalanced tree, space will be wasted.  Space still has to be allocated as if the tree were complemented with extra nodes to make it fully balanced.

38 Efficient Tree Representation and Traversal This representation is most useful when the actual node data (“payload”) is small compared to the combined size of the child pointers or when the tree really is fully balanced.

39 Efficient Tree Representation and Traversal Preorder Traversal Order  Even when no guarantees can be made about the balance of the tree hierarchy, it is still possible to output the data in a more effective representation.  If the tree nodes are output in preorder traversal order, the left child when present will always immediately follow its parent. This way, although a link is still needed to point at the right child only a single bit is needed to indicate whether there is a left child.

40 Efficient Tree Representation and Traversal Preorder Traversal Order  In addition to reducing the needed number of child pointers by half, this representation also has the benefit of being quite cache friendly. The left child is very likely already in cache, having been fetched at the same time as its parent, making traversal more efficient.

41 Efficient Tree Representation and Traversal Offsets Instead of Pointers  A typical tree implementation uses (32-bit) pointers to represent node child links. For most trees a pointer representation is overkill.  More often than not, allocating the tree nodes from within an array a 16-bit index value from the start of the array can be used instead. This will work for both static and dynamic trees.

42 Efficient Tree Representation and Traversal Cache-friendlier Structures (Nonbinary Trees)  Execution time in modern architectures is often more limited by cache issues related to fetching data from memory than the number of instructions executed.  It can pay off to use nonconventional structures that although more complicated to traverse take up less memory and have a more cache-friendly access pattern.

43 Efficient Tree Representation and Traversal One possible representation method  Merging sets of three binary tree nodes (parent, left and right child) into a “tri-node”, a fused node containing all three nodes.

44 Efficient Tree Representation and Traversal Drawbacks  The drawback is the additional processing required to traverse the tree.  In addition, when a tree is not complete nodes go empty in the tri-node, wasting memory.  A flag is also needed to indicate whether the node is used or empty. Tri-node trees are better suited for dense trees.