![Page 1: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/1.jpg)
CSCI 420: Computer Graphics
Hao Lihttp://cs420.hao-li.com
Fall 2017
8.2 Spatial Data Structures
1
![Page 2: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/2.jpg)
Ray Tracing Acceleration
• Faster intersections - Faster ray-object intersections
• Object bounding volume • Efficient intersectors
- Fewer ray-object intersections • Hierarchical bounding volumes (boxes, spheres) • Spatial data structures • Directional techniques
• Fewer rays - Adaptive tree-depth control - Stochastic sampling
• Generalized rays (beams, cones)
2
![Page 3: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/3.jpg)
Spatial Data Structures
3
• Data structures to store geometric information • Sample applications
- Collision detection - Location queries - Chemical simulations - Rendering
• Spatial data structures for ray tracing - Object-centric data structures (bounding volumes) - Space subdivision (grids, octrees, BSP trees) - Speed-up of 10x, 100x, or more
![Page 4: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/4.jpg)
Intersection of Rays and Implicit Surfaces
4
• Wrap complex objects in simple ones • Does ray intersect bounding box?
- No: does not intersect enclosed objects - Yes: calculate intersection with enclosed objects
• Common types:
Axis-aligned Bounding
Box (AABB)
Oriented Bounding Box (OBB)
Sphere Convex Hull 6-dop
![Page 5: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/5.jpg)
Selection of Bounding Volumes
5
• Effectiveness depends on: - Probability that ray hits bounding volume, but not
enclosed objects (tight fit is better) - Expense to calculate intersections with bounding
volume and enclosed objects • Amortize calculation of bounding volumes • Use heuristics
good
bad
![Page 6: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/6.jpg)
Hierarchical Bounding Volumes
6
• With simple bounding volumes, ray casting still requires O(n) intersection tests
• Idea: use tree data structure - Larger bounding volumes contain smaller ones etc. - Sometimes naturally available (e.g. human figure) - Sometimes difficult to compute
• Often reduces complexity to O(log(n))
![Page 7: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/7.jpg)
Ray Intersection Algorithm
7
• Recursively descend tree • If ray misses bounding volume, no intersection • If ray intersects bounding volume, recurse with enclosed
volumes and objects • Maintain near and far bounds to prune further • Overall effectiveness depends on model and constructed
hierarchy
![Page 8: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/8.jpg)
Uniform Spatial Sub
Quadtree/Octree kd-tree BSP-tree
Spatial Subdivision
8
• Bounding volumes enclose objects, recursively • Alternatively, divide space (as opposed to objects) • For each segment of space, keep a list of intersecting
surfaces or objects • Basic techniques:
![Page 9: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/9.jpg)
Grids
9
• 3D array of cells (voxels) that tile space • Each cell points to all intersecting surfaces • Intersection algorithm steps from cell to cell
![Page 10: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/10.jpg)
Caching Intersection Points
10
• Objects can span multiple cells • For A need to test intersection only once • For B need to cache intersection and check next cell
for any closer intersection with other objects • If not, C could be missed (yellow ray)
A B
C
![Page 11: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/11.jpg)
Assessment of Grids
11
• Poor choice when world is non-homogeneous • Grid resolution:
- Too small: too many surfaces per cell - Too large: too many empty cells to traverse - Can use algorithms like Bresenham’s
for efficient traversal • Non-uniform spatial subdivision more flexible - Can adjust to objects that are present
![Page 12: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/12.jpg)
Outline
12
• Hierarchical Bounding Volumes • Regular Grids • Octrees • BSP Trees
![Page 13: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/13.jpg)
Quadtrees
• Generalization of binary trees in 2D - Node (cell) is a square - Recursively split into 4 equal sub-squares - Stop subdivision based on number of objects
• Ray intersection has to traverse quadtree • More difficult to step to next cell
13
![Page 14: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/14.jpg)
Octrees
• Generalization of quadtree in 3D • Each cell may be split into 8 equal sub-cells • Internal nodes store pointers to children • Leaf nodes store list of surfaces • Adapts well to non-homogeneous scenes
14
![Page 15: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/15.jpg)
Assessment for Ray Tracing
15
• Grids - Easy to implement - Require a lot of memory - Poor results for non-homogeneous scenes
• Octrees - Better on most scenes (more adaptive)
• Alternative: nested grids • Spatial subdivision expensive for animations • Hierarchical bounding volumes
- Natural for hierarchical objects - Better for dynamic scenes
![Page 16: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/16.jpg)
Other Spatial Subdivision Techniques
16
• Relax rules for quadtrees and octrees • k-dimensional tree (k-d tree)
- Split at arbitrary interior point - Split one dimension at a time
• Binary space partitioning tree (BSP tree) - In 2 dimensions, split with any line - In k dims. split with k-1 dimensional hyperplane - Particularly useful for painter’s algorithm - Can also be used for ray tracing
![Page 17: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/17.jpg)
Outline
17
• Hierarchical Bounding Volumes • Regular Grids • Octrees • BSP Trees
![Page 18: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/18.jpg)
BSP Trees
18
• Split space with any line (2D) or plane (3D) • Applications
- Painters algorithm for hidden surface removal - Ray casting
• Inherent spatial ordering given viewpoint - Left subtree: in front, right subtree: behind
• Problem: finding good space partitions - Proper ordering for any viewpoint - How to balance the tree
![Page 19: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/19.jpg)
Building a BSP Tree
19
• Use hidden surface removal as intuition • Using line 1 or line 2 as root is easy
Line 2 Line 3
Line 1
Viewpoint
1 1
2
3
B A C D
a BSP tree using 2 as root
A
B
D
C
3 2
the subdivision of space it implies
![Page 20: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/20.jpg)
Splitting of Surfaces
20
• Using line 3 as root requires splitting
![Page 21: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/21.jpg)
Building a Good Tree
21
• Naive partitioning of n polygons yields O(n3) polygons (in 3D) • Algorithms with O(n2) increase exist
- Try all, use polygon with fewest splits - Do not need to split exactly along polygon planes
• Should balance tree - More splits allow easier balancing - Rebalancing?
![Page 22: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/22.jpg)
Painter’s Algorithm with BSP Trees
22
• Building the tree - May need to split some polygons - Slow, but done only once
• Traverse back-to-front or front-to-back - Order is viewer-direction dependent - What is front and what is back of each line changes - Determine order on the fly
![Page 23: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/23.jpg)
Details of Painter’s Algorithm
23
• Each face has form Ax + By + Cz + D • Plug in coordinates and determine
- Positive: front side - Zero: on plane - Negative: back side
• Back-to-front: inorder traversal, farther child first • Front-to-back: inorder traversal, near child first • Do backface culling with same sign test • Clip against visible portion of space (portals)
![Page 24: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/24.jpg)
Clipping With Spatial Data Structures
24
• Accelerate clipping - Goal: accept or reject whole sets of objects - Can use an spatial data structures
• Scene should be mostly fixed - Terrain fly-through - Gaming
![Page 25: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/25.jpg)
Data Structure Demos
25
• BSP Tree construction http://symbolcraft.com/graphics/bsp/index.html
• KD Tree construction http://donar.umiacs.umd.edu/quadtree/points/kdtree.html
![Page 26: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/26.jpg)
Real-Time and Interactive Ray Tracing
26
• Interactive ray tracing via space subdivision http://www.cs.utah.edu/~reinhard/egwr/• State of the art in interactive ray tracing http://www.cs.utah.edu/~shirley/irt/
![Page 27: 8.2 Spatial Data Structures - Hao Li · Spatial Data Structures 3 • Data structures to store geometric information • Sample applications - Collision detection - Location queries](https://reader036.vdocument.in/reader036/viewer/2022062414/5ec73aa5c01d1a639020c4b6/html5/thumbnails/27.jpg)
Summary
27
• Hierarchical Bounding Volumes • Regular Grids • Octrees • BSP Trees