Report

2.6. BOUNDING VOLUME HIERARCHIES Overview of different forms of bounding volume hierarchy Exploration of different types of bounding volume hierarchy Bounding Volume Hierarchies Given a total of n objects, a simple brute force approach towards producing a list of intersecting objects is to consider all object pairings (i.e. n2/2 comparisons). Assuming each object can be described in terms of one of more bounding volumes, by arranging the object’s bounding volumes into a tree-based hierarchy (known as a bounding volume hierarchy), a logarithmic order time complexity can be obtained. BVH Design Issues: Desirable Characteristics Desirable characteristics of a game-oriented BVH are likely to include: • The nodes contained in any given sub-tree should be spatially ‘close’ to each other. • Each node in the hierarchy should be of minimal volume. • Pruning a node near the root of the tree should remove more objects from further consideration than removal of a deeper node. • The volume of overlap between sibling nodes should be minimal. • The hierarchy should be balanced with respect to both its node structure and its content. • The worst-case time for queries should not be much worse than the average-case query time. BVH Building Strategies As the number of possible BVH trees grows exponentially as the number of objects increase it is not possible to use an exhaustive (optimal) search. Instead, heuristic rules are used to direct the BVH construction (selecting the best option from a small number of hopefully near optimal options at each step). There are three main categories of tree construction methods: • top-down • bottom-up • insertion BVH Building Strategies • Top-down: partitioning input set into two (or more) subsets, introduce bounds, and recursing over bounded subsets (typically does not produce best trees, but is easy to implement and hence popular). • Bottom-up: start with leaves of the tree, group two (or more) to form a bounding node, progressively grouping bounded volumes until a single node is reached (typically produces best quality BVH, but more difficult to implement). • Insertion: incrementally insert an object into the tree so as to minimize some insertion cost measurement Forms of BVH Construction Consult the recommended course text for full details of the following approaches: • • • Top-down Construction Bottom-up Construction Incremental (Insertion) Construction Top-down construction is explored next by way of an example. Top-down construction of a bounding volume hierarchy Top-down Construction of a BVH The process of top-down construction can be algorithmically described as: void BuildTopDownBVH(BVHNode treeNode, ArrayList objects) { Node newNode = new Node(); Create an empty node and add to the tree treeNode.add(newNode); Build a suitable bounding volume around the specified object list newNode.BoundingVolume = ComputeBoundingVolume(objects); if( objects.Count <= MIN_OBJECTS_PER_LEAF ) { If needed, simply newNode.Type = LEAF; store the object list within this node newNode. Objects = objects; } else { newNode.Type = NODE; Sort and split the objects into two partitions int splitIdx = RearrangeAndPartitionObjects(objects); BuildTopDownBVH( Recursively build the BVH along the defined left and right sub-trees newNode.LeftTree, objects.Subset(0,splitIdx)); BuildTopDownBVH( newNode.RightTree, objects.Subset(splitIdx,objects.Count); } } Top-down partitioning strategy Other than selecting which bounding volume to use, the top-down strategy need only define how an input set of objects can be partitioned into two subsets. Typically the input set is divided using a splitting hyperplane. Any primitives intersected by the splitting plane are commonly assigned to the subset within which its centroid belongs, alongside extending subset bounding volume by half the width of the primitive (thereby fully enclosing the primitive and minimising overlap between sibling bounding volumes). Top-down partitioning strategy A number of different partitioning strategies might be adopted (depending upon the performance/memory needs, etc. of the application), including: • Minimize the sum of the volumes (or surface areas) of the child volumes. • Minimize the volume (surface area) of the Assuming spherical bounding volumes Minimal child volume, but high overlap volume intersection of the child volumes. • Maximize the separation of child volumes. • Divide primitives equally between the child volumes (known as a median-cut algorithm, and tends to produced balanced trees) • Combinations of above strategies. Larger child volume, but smaller overlap volume Top-down partitioning: Halting recursion The recursive partitioning stops (thereby forming a leaf node) when some termination condition is reached. This can include: • The node contains less than some k primitives. • The volume of the bounding volume falls below a cut-off limit. • The depth of the node has reached a predefined cut-off depth. Partitioning might also fail because: • All primitives fall on one side of the split plane. • One or both child volumes end up with as many (or nearly as many) primitives as the parent volume. • Both child volumes are (almost) as large as the parent volume. In these cases, it is reasonable to try other partitioning criteria before terminating the recursion. Top-down partitioning: Choice of axis The choice of which separating axis to use is often restricted to the following: • Local x, y, and z coordinate axes (easy to use, also form orthogonal set, i.e. good coverage). • Axes from some aligned bounding volume (e.g. from a reference k-DOP). • Axes of the parent bounding volume • Axis along which variance is greatest (using the dimension with largest spread serves to minimise the size of the child volumes). Top-down partitioning: Choice of split point The choice of which split point to use is (also) often restricted to the following: • Object median: splitting at the middle object (thereby evenly distributing the primitives and providing a balanced tree). • Object mean: splitting at the mean object offset (e.g. along the axis with greatest variance). • Bounding volume median: splitting at the middle of the bounding volume (thereby splitting into two equal parts). (a) Splits at object median, (b) splits at object mean, (c) splits at spatial median Approaches to traversing bounding volumes hierarchies Hierarchy Traversal Given two BVHs a descent rule is used to determine overlap status when the top-level volumes overlap. Approaches include breadth-first (BFS) and depthfirst (DFS) searches. BFS explores all nodes at a given depth before descending. DFS descends down into the tree, backtracking up once a leaf is hit. A decent method is blind (or uninformed) if it only uses the tree structure to select the next node. Informed methods examine node data (e.g. using heuristics) to select the next node (e.g. a best-first search maintains a list of best-scoring moves). For collision detection systems, DFS (possibly a simple heuristic – i.e. basically a best-first approach) is typically favoured over BFS. Descent Rules Given two BVHs the following descent strategies might be adopted: 1.Descend A before B (or vice versa). Fully descend into the leaves of A before starting to descend into B. This will be very expensive if B’s root bound fully contains A and/or if A contains lots of nodes. 2.Descend the larger volume. Dynamically determine which BVH node is currently larger and descend into (avoiding the problems of Approach 1). 3.Descend A and B simultaneously. Similar to Approach 2 but without any cost evaluation overhead (but it may not prune space as efficiently). 4.Descend based on overlap. Similar to Approach 2, priortise descent on degree of overlap between BVH regions. Generic Informed Depth-first traversal An example informed depth-first traversal algorithm is: CollisionResult is assumed to store relevant collision detection/contact information void BVHInformedDFS(CollisionResult r, BVHNode a, BVHNode b) { If the bounding volumes do not overlap then simply return if (!BVOverlap(a, b)) return; } if (IsLeaf(a) && IsLeaf(b)) { If two leaf nodes are found, then perform CollidePrimitives(r, a, b); collision detection on the primitives } else { Descent rule to determine which BVH to follow if (DescendA(a, b)) { BVHInformedDFS (r, a->left, b); BVHInformedDFS (r, a->right, b); } else { BVHInformedDFS (r, a, b->left); BVHInformedDFS (r, ,a, b->right); } bool DescendA(BVHNode a, BVHNode b) } { return IsLeaf(b) || Descend into the larger volume (!IsLeaf(a) && (SizeOfBV(a) >= SizeOfBV(b))); } Descent Rules See the source text book for: • A non-recursive, faster, implementation of the generic informed depth-first traversal • Simultaneous depth-first traversal algorithm • Optimised leaf-directed depth-first traversal Directed mathematical reading Directed reading • Read Chapter 6 of Real Time Collision Detection (pp235-284) • Related papers can be found from: http://realtimecollisiondetection.net/books/rtcd/references/ Summary Today we explored: Bounding volume hierarchies Overview of top-down construction approaches