1 / 42

Advanced Computer Graphics Spring 2014

Advanced Computer Graphics Spring 2014. K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology. Efficient Tree Representation and Traversal. Tree Node and Primitive Ordering

lilka
Download Presentation

Advanced Computer Graphics Spring 2014

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Efficient Tree Representation and Traversal • Tree Node and Primitive Ordering • When a simultaneous traversal is used, four recursive calls are generated in the node-node part of the traversal algorithm. • The order in which these recursive calls were issued is completely determined by the relative ordering of the nodes within the two trees. • The performance of the program is governed by such an order of those recursive calls. • How can we determine the best order?

  3. Efficient Tree Representation and Traversal • Tree Node and Primitive Ordering • One possibility would be to attempt to figure out at runtime the best order in which to issue the recursive calls. • It is not easy, as nothing is known about the structure further down the hierarchies at this point. • A more feasible alternative (with no runtime overhead) is to rearrange the children of a parent node heuristically during construction. • The child more likely to lead to an early intersection comes first.

  4. Efficient Tree Representation and Traversal • Tree Node and Primitive Ordering • A few possible ways to order the nodes include • Arrange children so that leaves come before nodes • Put the smallest subtrees first • Sort children by their hits-to-tests ratio • Sort children from near to far along predominant query direction.

  5. Efficient Tree Representation and Traversal • On Recursion • Recursion is not the most effective form in which to express the code. • Exiting the recursion and immediately returning a value is not directly supported in most languages • Using a flag variable to tell the code to exit is not just an complicated solution but requires the recursion to “unwind” all the way to the top. • The ideal solution is to rewrite any recursive code using explicit stacking. • As the code is no longer recursive, it is possible to exit the function at any time. • It also provides the ability to interrupt and resume the code at any point by simply saving away a few variable values. • Having an explicit stack pointer makes it easy to limit traversals to a specified maximum depth if so desired. • Not using recursion also avoids the overhead of recursive function calls.

  6. Improved Queries Through Caching • Caching serves as a very important means of optimizing collision queries. • By keeping track of various information about the last collision query an object was involved in, that information can often be used in a subsequent query to speed it up by “jump-starting” the calculations, thanks to the spatial and temporal coherence objects tend to exhibit. • The information cashed can be classified in two types: positive and negative.

  7. Improved Queries Through Caching • The information cashed can be classified in two types: positive and negative. • Positive: it helps in more quickly detecting that the two objects are colliding. • Negative: It aids in determining the separation of the two objects. • Specific pieces of information that can help quickly answer decision problems are referred to as witnesses.

  8. Improved Queries Through Caching • Surface Caching: Caching Intersecting Primitives • The most obvious caching scheme is to store one or more overlapping primitives from each object when the objects are found colliding. • These primitives serve as witnesses of the collision. • The next time the same two objects are tested for overlap these cached primitives can be tested first to see if they are still in collision. • If so, a test query can immediately return without having to examine the full hierarchies, worst case. • The drawback is that this type of caching method only works for test queries.

  9. Improved Queries Through Caching • Two possible cache organizations for holding the stored primitives: a shared or a distributed cache. • A shared cache: a global cache that contains any number of pair entries • Typically implemented as a hash table wherein the colliding primitives are registered under a key constructed from the two object IDs. • The benefit is that the system easily handles an object being involved in any number of collisions. • Drawbacks include the cost of performing a hash table lookup and having to remove the pair when the objects are no longer in collision.

  10. Improved Queries Through Caching • Two possible cache organizations for holding the stored primitives: a shared or a distributed cache. • A distributed cache: a local cache wherein the primitives are stored within the objects themselves. • The benefit is that cached primitives are instantly available. • However, if only a single primitive is cached per object the contact with multiple objects will cause the cache to be prematurely flushed, rendering it useless.

  11. Improved Queries Through Caching • Front Tracking • It is an advanced type of caching mechanism that uses temporal coherence for speeding up collision queries. • It can be applied to any CD system that uses hierarchies of bounding volumes.

  12. Improved Queries Through Caching • Front Tracking • Two bounding volumes hierarchies are tested against each other. • Ones with three and seven nodes. BV test tree

  13. Improved Queries Through Caching • Front Tracking • Each node in the BV test tree is a test between a node in each tree. • Not all nodes overlap when testing two BVs against each other, and so the dashed line illustrates where the overlapping borders the nonoverlapping pairs. • That is, above this line each pair of nodes overlap, and below it they are disjoint. • Node “C” overlaps b, so that the node “Cb” is above the line. • Node “C” does not overlap “c”, so that node “Cc” is below.

  14. Improved Queries Through Caching • Front Tracking • The algorithm keeps track of a front, and this front is the dashed line in the figure.

  15. Improved Queries Through Caching • Front Tracking • By storing this front for the next frame, testing can start just above the front, thereby saving traversal time at the upper parts of the trees. • The effect is the same as starting from the root of the BV test tree. • The BV test tree will not be the same from frame to frame. • If more nodes are found to overlap, then the BV test tree grows, and the front is lowered. • If a node is not overlapping any longer, then the front has to be raised.

  16. Improved Queries Through Caching • Front Tracking • From tests on sphere tree, it is reported that an average speedup of 40% for the basic front-updating method. • With deferred updating, an average speedup of 84% could be possible.

  17. Spatial Partitioning • Spatial partitioning techniques provide broad-phase processing by dividing space into regions and testing if objects overlap the same region of space. • Because objects can only intersect if they overlap the same region of space, the number of pair-wise tests is drastically reduced.

  18. Spatial Partitioning • Uniform Grids • A very effective space subdivision scheme. • Overlay space with a regular grid. • It divides space into a number of regions, or grid cells of equal size. • Each object is then associated with the cells it overlays. • As only objects overlapping a common cell could possibly be in contact, in-depth tests are only performed against those objects found sharing cells with the object tested for collision. • The farther apart two objects are the less likely they overlap the same cells.

  19. Spatial Partitioning • Uniform Grids • Uniformity of the grid – simple and fast accessing to a cell. • Given a specific cell, computing neighboring cells are trivial to locate. • It is a good and popular choice for space subdivision. • Grids are known by many names: regions, buckets, sectors and zones.

  20. Spatial Partitioning • Cell Size Issues • The grid is too fine. • The grid is too coarse (with respect to object size) • The grid is too coarse (with respect to object complexity) • The grid is both too find and too coarse.

  21. Spatial Partitioning • Cell Size Issues • Having objects overlap only a small number of cells is important. • It limits the amount of work required to insert and update objects in the grid, and to perform the actual overlap tests.

  22. Spatial Partitioning • Storing objects in a grid. • Grids as Arrays of Linked Lists • Allocate an array of corresponding dimension, mapping grid cells to array elements one-to-one. • To handle the case of multiple objects ending up in a given cell, each array element would point to a linked list of objects, or be NULL if empty. • The easiest way of maintaining these linked lists is to embed the links within the objects themselves. • A drawback with using a dense array of this type is that for large grids just storing the list headers in each grid cell becomes prohibitive in terms of memory requirements.

  23. Spatial Partitioning • Storing objects in a grid. • Hashed Storage • The most effective alternative to using a dense array to store the grid is to map each cell into a hash table of a fixed set of n buckets. The buckets contain the linked lists of objects. The grid itself is conceptual and does not use any memory.

  24. Spatial Partitioning • Storing objects in a grid. • Hashed Storage • The most effective alternative to using a dense array to store the grid is to map each cell into a hash table of a fixed set of n buckets. • Storing Static Data • When grid data is static (when it represents world polygon data instead of dynamic objects), the need for a linked list can be removed altogether. • Store all cells data in a single contiguous array.

  25. Spatial Partitioning • Storing objects in a grid. • Implicit Grids • An alternative to storing a grid explicitly is to store it implicitly as the Cartesian product of two or more arrays. • The grid is now represented by two arrays (three in 3D), wherein one array corresponds to the grid rows and the other to the grid columns. • Each array element points to a linked list of objects. • An object is inserted into the grid by adding it to the lists of the grid cells it overlaps for both the row and column array. • This scheme can result in either fewer or more list insertions compared to the dense array representation.

  26. Spatial Partitioning • Storing objects in a grid. • Implicit Grids A 4 by 5 grid implicitly defined as the intersection of 9(4+5) linked lists. Five objects have been inserted into the lists and their implied positions in the grid are indicated.

  27. Spatial Partitioning • Hierarchical Grids • The most significant problem with uniform grids is their inability to deal with objects of greatly varying sizes in a graceful way. • When objects are much larger than the grid cell size and end up overlapping many cells, updating the position of a moving object becomes very expensive. • If the cell size is adjusted to hold the larger objects, the grid becomes less spatially discriminatory as more small objects now end up in the same cell, with loss of performance as a result. • Such a size problem can effectively be addressed by the use of hierarchical grids, a grid structure particularly well suited to holding dynamically moving objects.

  28. Spatial Partitioning • The hierarchical grid consists of a number of grids of varying cell sizes, all overlapping to cover the same space. • Given a hierarchy containing n levels of grids and letting rk represent the size of the grid cells at level k in the hierarchy, the grids are arranged in increasing cell size order, with r1 < r2 < .. < rn. • Level 1 is the lowest level, and level n is the highest level.

  29. Spatial Partitioning

  30. Spatial Partitioning • The grid cells can assume any relative size and should ideally be selected with respect to existing object sizes. • A simple procedure for setting up the hierarchy • Let the cells at level 1 just encompass the smallest objects. • Then successively double the cell size so that cells of level k+1 are twice as wide as cells of level k. • Repeat the doubling process until the highest level cells are large enough to encompass the largest objects.

  31. Spatial Partitioning • Octree (and Quadtrees) • It is an axis-aligned hierarchical partitioning of a volume of 3D world space. • Each parent node in the octree has eight children. • Each node also has a finite volume associated with it. • The root node volume is generally taken to be the smallest axis-aligned cube fully enclosing the world. • The volume is then subdivided into eight smaller equal-size subcubes by simultaneously dividing the cube in half along each of the x,y, and z axes. • These subcubes form the child nodes of the root node.

  32. Spatial Partitioning • Octree (and Quadtrees) • Typical criteria for stopping the recursive creation of the octree include the tree reaching a maximum depth or the cubes getting smaller than some preset minimum size. • Initially, all primitives in the world are associated with the root volume. • As the root volume is split, the set of primitives is reassigned to the child cells it overlaps, duplicating the primitives when they overlap more than one cell. • The procedure is repeated recursively.

  33. Spatial Partitioning • Octree (and Quadtrees)

  34. Spatial Partitioning • k-d Trees • A generalization of octrees and quadtrees can be found in the k-dimensional tree, or k-d tree. • k represents the number of dimensions subdivided, which does not have to match the dimensionality of the space used. • The k-d tree divides space along one dimension at a time. • Traditionally, k-d trees are split along x, then y, then z, then x again, and so on, in a cyclic fashion. • Often the splitting axis is freely selected among the k dimensions. • One level of an octree can be seen as a three-level k-d tree split along x, then y, then z (all splits selected to divide the space in half).

  35. Spatial Partitioning • k-d Trees

  36. Spatial Partitioning • Hybrid Schemes • The grid serves as a fast way of locating the appropriate trees. • Grids can also be used as “acceleration structures” into a single tree hierarchy.

  37. Spatial Partitioning • Sweep-and-Prune • It exploits the temporal coherence most often found in virtual environments. • Temporal coherence means that objects undergo small changes in their position and orientation from frame to frame. • This can be used to check if two AABBs overlap. • The three-dimensional problem for AABBs is solved by using the one-dimensional algorithm for each of the three main axes.

  38. Spatial Partitioning • Sweep-and-Prune

  39. Collision Response • Collision response is the action that should be taken to avoid interpenetration of objects. • The simplest technique is introduced here. • What happens to a sphere’s motion at the time of collision? • Assume that a sphere is moving towards a plane. • v: the velocity vector of the sphere • nᆞx + d = 0.

  40. Collision Response

  41. Collision Response • The velocity vector • v = vn + vp • vn = (vᆞn)n • vp = v – vn. • After the collision, the velocity vector is • v’ = vp– nv • Here we have assumed that the response was totally elastic.

  42. Collision Response • If some energy is lost at collision, then • v’ = vp– kvn • As k gets smaller, more and more energy is lost, and the collision appears less and less bouncy. • More sophisticated collision response is based on physics, and involves creating a system of ODEs.

More Related