BSP Trees Binary space partitioning trees.

Slides:



Advertisements
Similar presentations
Computer Graphics - Rasterization -
Advertisements

Visible-Surface Detection(identification)
1 Binary Space Partition Trees ©Anthony Steed, Yiorgos Chrysanthou
Two Segments Intersect?
Collisions and Intersections When objects move, test for collision. When projecting surfaces, check for intersections. (Many slides adapted from Amitabh.

Brute-Force Triangulation
03/12/02 (c) 2002 University of Wisconsin, CS559 Last Time Some Visibility (Hidden Surface Removal) algorithms –Painter’s Draw in some order Things drawn.
Hidden Surface Removal Why make the effort?  Realistic models.  Wasted time drawing. OpenGL and HSR  OpenGL does handle HSR using the depth buffer.
CSE 381 – Advanced Game Programming Scene Management
BSP Trees Binary space partitioning trees. Used to store a collection of objects in n- dimensional space. Tree recursively divides n-dimensional space.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Clipping II, Hidden Surfaces.
Chapter 6: Vertices to Fragments Part 2 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
1 Dr. Scott Schaefer Hidden Surfaces. 2/62 Hidden Surfaces.
Computer Graphics 14: Surface Detection Methods
A lion in the desert How do you find a lion in the desert? How about when you have a predicate that tells you if the lion is in front or behind a separating.
Hidden Surface Elimination Wen-Chieh (Steve) Lin Institute of Multimedia Engineering I-Chen Lin’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals.
1 CSCE 441: Computer Graphics Hidden Surface Removal (Cont.) Jinxiang Chai.
UNC Chapel Hill M. C. Lin Overview of Last Lecture About Final Course Project –presentation, demo, write-up More geometric data structures –Binary Space.
A lion in the desert How do you find a lion in the desert? How about when you have a predicate that tells you if the lion is in front or behind a separating.
Vertices and Fragments III Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
Spatial Data Structure: Quadtree, Octree,and BSP tree Mengxia Zhu Fall 2007.
10/11/2001CS 638, Fall 2001 Today Kd-trees BSP Trees.
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
Hidden Surface Removal
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
10/29/02 (c) 2002 University of Wisconsin, CS559 Today Hidden Surface Removal Exact Visibility.
Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering.
10/09/2001CS 638, Fall 2001 Today Spatial Data Structures –Why care? –Octrees/Quadtrees –Kd-trees.
The Visibility Problem In many environments, most of the primitives (triangles) are not visible most of the time –Architectural walkthroughs, Urban environments.
CSC418 Computer Graphics n BSP tree n Z-Buffer n A-buffer n Scanline.
The BSP-tree from Prof. Seth MIT.. Motivation for BSP Trees: The Visibility Problem We have a set of objects (either 2d or 3d) in space. We have.
Visible-Surface Detection Jehee Lee Seoul National University.
PRESENTED BY – GAURANGI TILAK SHASHANK AGARWAL Collision Detection.
Using BSP for CD Ref: BSP in deBerg et al ’ s book (url)url.
3/23/04© University of Wisconsin, CS559 Spring 2004 Last Time Antialiasing –Area-weighted sampling Visibility –Painters algorithm –Depth buffer (Z-buffer)
Implementation II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Implementation II.
Where We Stand At this point we know how to: –Convert points from local to window coordinates –Clip polygons and lines to the view volume –Determine which.
Computer Graphics I, Fall 2010 Implementation II.
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
01/28/09Dinesh Manocha, COMP770 Visibility Computations Visible Surface Determination Visibility Culling.
BSP Tree Supplement Jyun-Ming Chen. Fall Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.
Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 5 Hidden Surface Removal and Rasterization Taku Komura.
Visible-Surface Detection Methods. To identify those parts of a scene that are visible from a chosen viewing position. Surfaces which are obscured by.
Visibility Determination – List Priority Methods Chapter 11.
UNC Chapel Hill M. C. Lin Geometric Data Structures Reading: Chapter 10 of the Textbook Driving Applications –Windowing Queries Related Application –Query.
CS552: Computer Graphics Lecture 28: Solid Modeling.

Computer Graphics Implementation II
Solid Area Scan Conversion or Visible Surface Detection
© University of Wisconsin, CS559 Fall 2004
Hidden Surfaces Dr. Scott Schaefer.
Modeliranje kompleksnih modelov
Query Processing in Databases Dr. M. Gavrilova
KD Tree A binary search tree where every node is a
Orthogonal Range Searching and Kd-Trees
CSCE 441: Computer Graphics Hidden Surface Removal
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
Implementation II Ed Angel Professor Emeritus of Computer Science
Quadtrees 1.
© University of Wisconsin, CS559 Fall 2004
Hidden Surface Removal
CSCE 441: Computer Graphics Hidden Surface Removal (Cont.)
CS679 - Fall Copyright Univ. of Wisconsin
Introduction to Computer Graphics with WebGL
Modeliranje kompleksnih modelov
Implementation II Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

BSP Trees Binary space partitioning trees. Used to store a collection of objects in n-dimensional space. Tree recursively divides n-dimensional space using (n-1)-dimensional hyperplanes. An (n-1)-dimensional hyperplane is anything defined by a single linear equation as in ax + by + c = 0 (line, n = 2), ax + by + cz +d = 0 (plane, n = 3) that partitions an n-dimensional subspace into 2. Recursive partitioning stops when a region has a single object or when a region is homogeneous (all inside or outside an object). Could represent all objects in a 3d room and draw the view from different angles or identify which object is hit when you walk in a particular direction.

Space Partitioning n-dimensional space splitting hyperplane a1x1 + a2x2 + … anxn + an+1 = 0 ax + by + c = 0 (2D) ax+by+cz+d = 0 (3D)

Space Partitioning +ve half space n-dimensional space ax + by + c > 0 ax+by+cz+d > 0 n-dimensional space coincident ax + by + c = 0 ax+by+cz+d = 0 Note that +ve and –ve may be inverted by changing sign of coefficients: -ax – by –c = 0 -ve half space ax + by + c < 0 ax+by+cz+d < 0

Classifying Object z In 2D, ph is the line ax + by + c = 0. Compute ax + by + c for all vertices of z. If all values are = 0; z is coincident to ph. If all values are <= 0; z is left of ph. If all values are >= 0; z is right of ph. Otherwise, z spans ph and is to be split by finding intersection points with ph.

2D a g e b h c f d Equation of ph is x – 6 = 0 6

2D a g e b h c f 2 d Equation of ph is y –x –2 = 0

3D Equation of ph is z –2 = 0 General: ax + by + cz + d = 0 y z x

Space Partitioning n-dimensional space coincident list +ve -ve +ve -ve Objects that cross partitioning plane get split. -ve

Objects in 2D a g e b h 2D space will be partitioned using lines. c f d

Objects in 2D a g e b h First cut by a line. c f d

Objects in 2D a g a-d e-h e b h c f d First cut by a hyperplane (in this case a line), (say) x = 6 or x-6 = 0. Classify polygons as to left, coincident, to right, or cut by the hyperplane. For this purpose, look at the end points of each boundary edge of the polygon and see if both points lie on the same side of x-6 (I.e., does x-6 have the same sign for both end points). If both don’t, then x-6 = 0 cuts the edge (and hence the polygon). Note that a line may be coincident with the cut line. A polygon that has an edge coincident with the cut line isn’t coincident with the cut line; instead the polygon lies to one side of the cut line. c f d

Objects in 2D a g a-d e-h e b h c f d Cut each subspace by a blue line. c f d

Objects in 2D a-b e-f c-d g-h a g e b h c f d Cut each subspace by a blue line. c f d

Objects in 2D a g e b h c f a b c d g h f d e Cut each subspace by a green line. Although we don’t have homogeneous regions, each region has a single object and this may be enough for certain applications. We can continue the partitioning until each leaf represents a homogeneous region if we wish. If our object set included lines, we could have a line that is colinear with a partitioning hyperplane; this line would be stored in an internal node. c f a b c d g h f d e

Collision Detection a g e b h c f a b c d g h f d e If I move in my current direction, which object will I hit first? In right part of red cut. So if I hit someone in right part, don’t need to search left part. In right part of blue cut. In bottom part of green cut. Reach h but no intersect with object in h. Don’t need to check left subtree as motion line has no intersection with that subspace. Check left subtree of blue cut. Line cuts into subtree f first, search f. Collision detected! c f a b c d g h f d e

Visibility Ordering a g e b h c f a b c d g h f d e Which objects are in front and which behind from current view point? Determine which half plane eye is in. Root is x-6 = 0. Eye is at x = 7, 7-6 >0; so, eye is in right half plane. Objects in right half plane are in front of those in left half plane. In other words, objects in half plane that contains viewer (eye) cannot be occluded by objects in other half plane. Recursively order those in right half plane; then those in left half plane. Can use for painting to give view as seen by person; paint objects in near subtree; then those in far subtree but do not paint over regions already painted. Create tree once; draw view from any position many times. Good for a static scene as well as insert/delete of objects. Not good for moving objects. Z-buffer algorithm for drawing maintains 2 buffers—frame and z. The frame buffer keeps the intensity of every pixel and the z buffer has the z coordinate of the object that defined the current intensity for the pixel. The scene to be drawn is transformed so that increasing z-coordinates means increasing distance from viewer. Compute frame-buffer intensities by scanning objects in scene. If the z-value of current object is smaller than that stored in z-buffer for the pixel, update intensity in frame buffer and z-value in z-buffer. c f a b c d g h f d e

BSP Tree Construction Select partitioning hyperplanes. Partition objects. Repeat on partitions.

Partitioning Hyperplane Selection b h Good for intra object visibility ordering; which faces are closer to viewer? c f d Face of an object.

Partitioning Hyperplane Selection b h Good for intra object visibility ordering; which faces are closer to viewer? c f d Face of an object.

Autopartition Only object faces are used as splitting hyperplanes a g

Partitioning Hyperplane Selection b h c f Axis-aligned orthogonal hyperplanes d

Partitioning Hyperplane Selection b h c f Axis-aligned orthogonal hyperplanes d

Partitioning Hyperplane Selection b h The example cut increases number of objects/pieces by 3 as b, e, and h each get split into 2. Balance # objects (pieces) on each side of hyperplane Minimize increase in number of objects/pieces. c f d

3D Example

3D Example

3D Example

3D Example

Another 3D Example Yellow object is in front of green one as well as behind it. Painter’s algorithm—draw objects from back to front—fails.

Another 3D Example Hyperplane defined by back of green object splits yellow object into 3 pieces. Middle piece goes to one subtree of BSP; remaining 2 pieces plus green object goes to other subtree.

BSP Tree of an Object Each leaf represents a region that is either wholly inside or outside the object. Object surface is considered inside object. Surface planes are used as partitioning planes. Orient partitioning hyperplanes so that interior is to left. a a Box is a leaf.

BSP Tree of an Object Each leaf represents a region that is either wholly inside or outside the object. Object surface is considered inside object. Surface planes are used as partitioning planes. Orient partitioning hyperplanes so that interior is to left. a b a Box is a leaf. b

BSP Tree of an Object Each leaf represents a region that is either wholly inside or outside the object. Object surface is considered inside object. Surface planes are used as partitioning planes. Orient partitioning hyperplanes so that interior is to left. a b a c Box is a leaf. c b

BSP Tree of an Object Each leaf represents a region that is either wholly inside or outside the object. Object surface is considered inside object. Surface planes are used as partitioning planes. Orient partitioning hyperplanes so that interior is to left. a b a c Box is a leaf. d c d b

BSP Tree of an Object Each leaf represents a region that is either wholly inside or outside the object. Object surface is considered inside object. Surface planes are used as partitioning planes. Orient partitioning hyperplanes so that interior is to left. a b a c Note with chosen orientation of partitioning hyperplanes, left leaves are in and right are out. Different hyperplane orderings result in different bsp trees. Heuristics to select ordering that results in a good bsp tree. d c d e e b

BSP Tree of an Object Each leaf represents a region that is either wholly inside or outside the object. Object surface is considered inside object. Surface planes are used as partitioning planes. Orient partitioning hyperplanes so that interior is to left. a b a c Box is a leaf. f d c d e e f b

BSP Tree of an Object Orient partitioning hyperplanes so that interior is to left. With this orientation, left leaves are interior and right leaves are exterior. a b a c Note with chosen orientation of partitioning hyperplanes, left leaves are in and right are out. Different hyperplane orderings result in different bsp trees. Heuristics to select ordering that results in a good bsp tree. f d c d e e f b

BSP Tree Construction Node structure: ph = equation of partitioning hyperplane cList = list of objects coincident with ph leftChild rightChild

BSP Tree Construction BSPtree(O) // O is object set if O is empty, return null; Create a new node N; N.ph = partitioning hyperplane for O; lList = rList = N.cList = null; for each object z in O do if z is coincident to ph or |O| = 1, add z to N.cList; if z is left of ph, add z to lList; if z is right of ph, add z to rList; if z spans ph, split z and add pieces to lList and rList; N.leftChild = BSPTree(lList); N.rightChild = BSPTree(rList); return N; Construct BSP tree for object set O. Leaves represent (possibly) non-homogeneous regions with a single object. May be modified to get homogeneous region leaves.

Basic Draw Back to Front draw(N) if eye left of N.ph // eye in –ve half plane {draw(N.rightChild); draw N.cList; draw(N.leftChild)}; else if eye right of N.ph {draw(N.leftChild); draw N.cList; draw(N.rightChild)}; else // eye coincident to N.ph {draw(N.leftChild); draw(N.rightChild)}; Note: when eye is coincident to N.ph objects in N.clist are not visible to the viewer. Also, drawing order should depend on viewing direction. Draw() should take into account viewing direction and angle of sight to eliminate subtrees and objects that are behind the viewer or outside the field of view. The method overdraws pixels drawn earlier; because of back to front order, proper view is drawn. Could eliminate drawing of occluded pixels. Drawing a pixel is expensive when complex lighting model in use. When eye is coincident to partitioning hyperplane, objects coincident with this hyperplane are not visible. Eg, in 2D, if you look along the ph you’ll see only the end of the first line but not the line itself.

Basic Draw Front to Back draw(N) if eye left of N.ph // eye in –ve half plane {draw(N.leftChild); draw N.cList; draw(N.rightChild)}; else if eye right of N.ph {draw(N.rightChild); draw N.cList; draw(N.leftChild)}; else // eye coincident to N.ph {draw(N.rightChild); draw(N.leftChild)}; Draw must not draw a previously drawn pixel. Need to keep list of not-drawn or drawn pixels to ensure no redraw.

Randomization Autopartition. Splitting hyperplane is randomly selected to be one of the object faces. Lines in 2D; planes in 3D. Autopartition requires selection of next face to use as ph. Greedy selection to minimize number of cut pieces and balance subtrees is time consuming and doesn’t always work well. So select ph at random. a g e b h

Randomization—2D Analysis Start with n (nonintersecting) line segments. Total number of line segments in autopartition bsp is expected to be <= n + 2n ln n. If this bound is exceeded; rerun construction. Expected number of construction rounds before this bound is not exceeded is 2. a is approximated by 8 lines (say). Each partitioning line is expected to cut at most 2ln n other lines. 8 8 n = 29 4 3 6

Randomization —2D Analysis So, number of nodes in bsp is O(n log n). Construction time at each node is O(n) as at each node O(n) segments need to be partitioned. Time is O(n2log n) per construction round. 2 rounds expected. Expected complexity is O(n2log n). a is approximated by 8 lines (say). Each partitioning line is expected to cut at most 2ln n other lines. So, number of leaves (and hence total number of nodes) is O(n log n). Alternatively, each cut is a different segment and so there are O(nlog n) nodes. Note, using segment tree ideas we can construct, in O(n log n) time, a bsp tree of n line segments. The resulting bsp tree has O(n log n) nodes (and hence, number of (sub) segments is O(n log n)). For this, use divide-and-conquer, use free splits whenever possible and vertical splitting lines otherwise. This, of course, is not an autopartition. The resulting BSP is slightly larger than autopartition BSP in practice. 8 8 n = 29 4 3 6

Randomization—3D Analysis Start with n (nonintersecting) triangles. Total number of triangles in autopartition bsp is O(n2). There exist n-triangle examples for which every autopartition has W(n2) triangles. n = 24 Triangularize the faces—green = 12; yellow = 12. The autopartition is done slightly differently, a given ph is used to split every cell where the split is useful (I.e., the ph partitions the objects in the cell into non-null partitions).

Free Partitions One that does not split an object. Do a free partition whenever possible; otherwise, randomly select a segment/face as partitioning hyperplane. 8 8 4 3 6

Free Partitions Using an object face, that crosses a BSP region, results in a free partition of that BSP region. Portion of black segment bounded by red (previous) splitting lines may be used to partition blue region. No segments in blue region can be split as line segments are non-intersecting. Freeno faces are cut by the ph.

Free Partitions Using an object face, that crosses a BSP region, results in a free partition of that BSP region. When green segment is used to partition blue region, segments in blue region may be split. Extend green segment to region boundaries to get splitting hyperplane. The 2 black segments are cut.