spatial data structuresfp/courses/02-graphics/pdf-color/17...• idea use tree data structure –...
TRANSCRIPT
![Page 1: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/1.jpg)
March 28, 2002Frank PfenningCarnegie Mellon University
http://www.cs.cmu.edu/~fp/courses/graphics/
Hierarchical Bounding VolumesRegular GridsOctreesBSP TreesConstructive Solid Geometry (CSG)
[Angel 8.9]
Hierarchical Bounding VolumesRegular GridsOctreesBSP TreesConstructive Solid Geometry (CSG)
[Angel 8.9]
Spatial Data StructuresSpatial Data Structures
15-462 Computer Graphics ILecture 17
![Page 2: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/2.jpg)
03/28/2002 15-462 Graphics I 2
Ray Tracing AccelerationRay 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)
![Page 3: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/3.jpg)
03/28/2002 15-462 Graphics I 3
Spatial Data StructuresSpatial Data Structures
• 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: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/4.jpg)
03/28/2002 15-462 Graphics I 4
Bounding VolumesBounding Volumes
• 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– Boxes, axis-aligned– Boxes, oriented– Spheres– Finite intersections or unions of above
![Page 5: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/5.jpg)
03/28/2002 15-462 Graphics I 5
Selection of Bounding VolumesSelection of Bounding Volumes
• 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: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/6.jpg)
03/28/2002 15-462 Graphics I 6
Hierarchical Bounding VolumesHierarchical Bounding Volumes
• With simple bounding volumes, ray casting still has 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: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/7.jpg)
03/28/2002 15-462 Graphics I 7
Ray Intersection AlgorithmRay Intersection Algorithm
• 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: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/8.jpg)
03/28/2002 15-462 Graphics I 8
Spatial SubdivisionSpatial Subdivision
• Bounding volumes enclose objects, recursively• Alternatively, divide space• For each segment of space keep list of
intersecting surfaces or objects• Basic techniques
– Regular grids– Octrees (axis-aligned, non-uniform partition)– BSP trees (recursive Binary Space Partition, planes)
![Page 9: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/9.jpg)
03/28/2002 15-462 Graphics I 9
GridsGrids
• 3D array of cells (voxels) that tile space• Each cell points to all intersecting surfaces• Intersection alg
steps from cellto cell
![Page 10: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/10.jpg)
03/28/2002 15-462 Graphics I 10
Caching Intersection pointsCaching Intersection points
• Objects can span multiple cells• For A need to test intersection only once• For B need to cache intersection and check
next cell for closer one• If not, C could be missed
(yellow ray) AB
C
![Page 11: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/11.jpg)
03/28/2002 15-462 Graphics I 11
Assessment of GridsAssessment of Grids
• Poor choice when world is non-homogeneous• Size of grid
– Too small: too many surfaces per cell– Too large: too many empty cells to traverse– Can use alg like Bresenham’s for efficient traversal
• Non-uniform spatial subdivision more flexible– Can adjust to objects that are present
![Page 12: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/12.jpg)
03/28/2002 15-462 Graphics I 12
OutlineOutline
• Hierarchical Bounding Volumes• Regular Grids• Octrees• BSP Trees• Constructive Solid Geometry (CSG)
![Page 13: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/13.jpg)
03/28/2002 15-462 Graphics I 13
QuadtreesQuadtrees
• 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
![Page 14: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/14.jpg)
03/28/2002 15-462 Graphics I 14
OctreesOctrees
• 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
![Page 15: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/15.jpg)
03/28/2002 15-462 Graphics I 15
Assessment for Ray TracingAssessment for Ray Tracing
• Grids– Easy to implement– Require a lot of memory– Poor results for non-homogeneous scense
• 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: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/16.jpg)
03/28/2002 15-462 Graphics I 16
Other Spatial Subdivision TechniquesOther Spatial Subdivision Techniques
• 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 [see handout]
![Page 17: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/17.jpg)
03/28/2002 15-462 Graphics I 17
OutlineOutline
• Hierarchical Bounding Volumes• Regular Grids• Octrees• BSP Trees• Constructive Solid Geometry (CSG)
![Page 18: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/18.jpg)
03/28/2002 15-462 Graphics I 18
BSP TreesBSP Trees
• 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 – Balance tree
• For details, see http://reality.sgi.com/bspfaq/
![Page 19: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/19.jpg)
03/28/2002 15-462 Graphics I 19
Building a BSP TreeBuilding a BSP Tree
• Use hidden surface removal as intuition• Using line 1 or line 2 as root is easy
Line 2Line 3
Line 1
Viewpoint
11
2
3
B A C D
a BSP treeusing 2 as root
A
B
D
C
3 2
the subdivisionof space it implies
![Page 20: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/20.jpg)
03/28/2002 15-462 Graphics I 20
Splitting of surfacesSplitting of surfaces
• Using line 3 as root requires splitting
Line 2a
Line 3
Line 1
Viewpoint
1
2a2b
Line 2b
3
![Page 21: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/21.jpg)
03/28/2002 15-462 Graphics I 21
Building a Good TreeBuilding a Good Tree
• 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: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/22.jpg)
03/28/2002 15-462 Graphics I 22
Painter’s Algorithm with BSP TreesPainter’s Algorithm with BSP Trees
• 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: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/23.jpg)
03/28/2002 15-462 Graphics I 23
Details of Painter’s AlgorithmDetails of Painter’s Algorithm
• 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)
[Guest Lecture: John Ketchpaw]
![Page 24: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/24.jpg)
03/28/2002 15-462 Graphics I 24
Clipping With Spatial Data StructuresClipping With Spatial Data Structures
• Accelerate clipping– Goal: accept or rejects whole sets of objects– Can use an spatial data structures
• Scene should be mostly fixed– Terrain fly-through– Gaming
Hierarchical bounding volumes Octrees
![Page 25: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/25.jpg)
03/28/2002 15-462 Graphics I 25
Data Structure DemosData Structure Demos
• BSP Tree construction http://symbolcraft.com/pjl/graphics/bsp/
• KD Tree construction http://www.rolemaker.dk/nonRoleMaker/uni/algogem/kdtree.htm
![Page 26: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/26.jpg)
03/28/2002 15-462 Graphics I 26
Real-Time and Interactive Ray TracingReal-Time and Interactive Ray Tracing
• Interactive ray tracing via space subdivision http://www.cs.utah.edu/~reinhard/egwr/
• Interactive ray tracing with good hardware http://www.cs.utah.edu/vissim/projects/raytracing/
![Page 27: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/27.jpg)
03/28/2002 15-462 Graphics I 27
OutlineOutline
• Hierarchical Bounding Volumes• Regular Grids• Octrees• BSP Trees• Constructive Solid Geometry (CSG)
![Page 28: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/28.jpg)
03/28/2002 15-462 Graphics I 28
Constructive Solid Geometry (CSG)Constructive Solid Geometry (CSG)
• Generate complex shapes with simple building blocks (boxes, spheres, cylinders, cones, ...)
• Particularly applicable for machined objects• Efficient with ray tracing
![Page 29: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/29.jpg)
03/28/2002 15-462 Graphics I 29
Example: A CSG TrainExample: A CSG Train
Brian Wyvill et al., U. of Calgary
![Page 30: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/30.jpg)
03/28/2002 15-462 Graphics I 30
Boolean OperationsBoolean Operations
• Intersection and union• Subtraction
– Example: drilling a hole
Subtract From
To get
![Page 31: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/31.jpg)
03/28/2002 15-462 Graphics I 31
CSG TreesCSG Trees
• Set operations yield tree-based representation
• Use these trees for ray/objects intersections• Think about how!
![Page 32: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/32.jpg)
03/28/2002 15-462 Graphics I 32
Implicit Functions for BooleansImplicit Functions for Booleans
• Solid as implicit function, F(x,y,z)– F(x, y, z) < 0 interior– F(x, y, z) = 0 surface– F(x, y, z) > 0 exterior
• For CSG, use F(x, y, z) 2 {-1, 0, 1}• FA Å B (p) = max (FA(p), FB(p))• FA [ B (p) = min (FA(p), FB(p))• FA – B (p) = max (FA(p), - FB(p))
![Page 33: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/33.jpg)
03/28/2002 15-462 Graphics I 33
SummarySummary
• Hierarchical Bounding Volumes• Regular Grids• Octrees• BSP Trees• Constructive Solid Geometry (CSG)
![Page 34: Spatial Data Structuresfp/courses/02-graphics/pdf-color/17...• Idea use tree data structure – Larger bounding volumes contain smaller ones etc. – Sometimes naturally available](https://reader033.vdocuments.mx/reader033/viewer/2022060522/6051be799adebe697374727f/html5/thumbnails/34.jpg)
03/28/2002 15-462 Graphics I 34
PreviewPreview
• Radiosity• Image Processing• Assignment 6 due today• Assignment 7 (ray tracing) out late today