Presentation is loading. Please wait.

Presentation is loading. Please wait.

BSP Trees Binary space partitioning trees.

Similar presentations


Presentation on theme: "BSP Trees Binary space partitioning trees."— Presentation transcript:

1 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.

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

3 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

4 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.

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

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

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

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

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

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

11 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

12 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

13 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

14 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

15 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

16 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

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

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

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

20 Autopartition Only object faces are used as splitting hyperplanes a g

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

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

23 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

24 3D Example

25 3D Example

26 3D Example

27 3D Example

28 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.

29 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.

30 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.

31 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

32 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

33 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

34 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

35 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

36 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

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

38 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.

39 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.

40 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.

41 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

42 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

43 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

44 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).

45 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

46 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.

47 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.


Download ppt "BSP Trees Binary space partitioning trees."

Similar presentations


Ads by Google