1 / 31

COSC 6114

COSC 6114. Prof. Andy Mirzaian. Binary Space Partition. References :. [M. de Berge et al] chapter 12 [Mulmuley ’94] chapter 9 Paterson, Yao [1990], “Binary partitions with applications to hidden-surface removal and solid modeling,” Discrete & Comp. Geometry 5, 485-504.

avi
Download Presentation

COSC 6114

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. COSC 6114 Prof. Andy Mirzaian Binary Space Partition

  2. References: • [M. de Berge et al] chapter 12 • [Mulmuley ’94] chapter 9 • Paterson, Yao [1990], “Binary partitions with applications to hidden-surface removal and solid modeling,” Discrete & Comp. Geometry 5, 485-504. • Paterson, Yao [1992], “Optimal binary partitions for orthogonal objects,” J. Algorithms 13, 99-113. • de Berg, de Groot, Overmars [1994], “New results on binary space partitions in the plane,” Scand. Workshop Algorithm Theory (SWAT), 61-72. • de Berg [1995], “Linear size binary space partitions for fat objects,” European Sympos. Algorithms (ESA), 252-263. • Csaba D. Tóth [2001], “A note on binary plane partitions,” SoCG, 151-156. • Csaba D. Tóth [2002], “Binary space partitions for line segments with a limited number of directions,” SODA, 465-471. • Applications: • 2D image of a 3D scene • flight simulator , real-time applications with changing view point • visibility calculations, hidden surface removal • shading calculations (light intensity) • scene modeling and rendering, painter’s algorithm

  3. Painter’s Algorithm • Painter’s algorithm uses only the intensity buffer, not the z-buffer. • It first computes a sorting of objects in order of their closeness to the view point. • Then paints objects in that order back-to-front. 3 3 2 2 1 1 Depth Order: 1, 2, 3 Snap-shot of Painter’s Algorithm • Problem:“in-front-of” relation may contain cycles. Hence, no such ordering possible. • Solution:Split some objects to break these cycles. Which? Where? • Problem: This has to be recomputed each time the view point changes. Expensive. • Solution: Preprocess the scene first: Binary Space Partition (BSP)

  4. A 2D scene and its BSP L2 L1 L1 L4 L2 L3 O4 O1 L6 O3 L5 L5 L4 L7 L6 O5 L3 L7 O5 O4 O3 O4 O2 O1 O1 O1 O2

  5. BSP • d-dimensional BSP : • S a set of objects in d. • Node v partition hyper-plane H(v) : a1x1 + a2x2 + … + adxd+ ad+1 = 0 • Positive open half-space H+(v) : a1x1 + a2x2 + … + adxd+ ad+1> 0 • Negative open half-space H-(v) : a1x1 + a2x2 + … + adxd+ ad+1 < 0 • S(v) = S  H(v) • S+(v) = S  H+(v) • S-(v) = S  H-(v) node v H(v), S(v) BSP of S: H(v) H+(v) H-(v) BSP(S-(v)) BSP(S+(v))

  6. Node regions in BSP tree • BSP partitionsd into convex polyhedra: • region(v) = the region corresponding to node v in the BSP tree. • region(root) = d • node v: region(v) • region(left-child(v)) = region(v)  H-(v) • region(right-child(v)) = region(v)  H+(v) • Size of BSP tree = # object fragments = # leaves. • If S  region(v)    internal nodes v, • then # nodes of the BSP tree is in the order of its size. L1 L2 L3 L1 L4 L4 L5 region(v) L5 v L3

  7. Auto-Partition BSP A special class of BSP when the set of objects have “flat” faces,and each BSP partition hyper-plane is affine hull of some object facet. • Examples: • For S = a set of line-segments in 2.BSP partition lines are extensions of the line-segments in S.Line(s) = line extension of segment sS. • For S = a set of polygons in 3, each BSP partition plane is the plane that contain some polygon in S.

  8. Painter’s Algorithm (PA) using BSP tree root v T : S = a set of polygons in 3 T = a BSP of S pview = the view point in 3 T- T+ ALGORITHM PA( T , pview) v  root of T if v is a leaf then scan-convert object fragment in S(v) if pview H-(v)then PA(T+, pview) scan-convert object fragment in S(v) PA(T-, pview) if pview H+(v)then PA(T-, pview) scan-convert object fragment in S(v) PA(T+, pview) if pview H(v)then PA(T+, pview) PA(T-, pview) end H+(v) H-(v) H(v)

  9. Painter’s Algorithm using BSP tree Once the BSP tree is constructed, the efficiency of painter’s algorithm depends on the size of the BSP tree.To increase efficiency, we need small size BSP. That is, as few object fragments as possible.

  10. 2D BSP Algorithms

  11. Auto-Partition ALGORITHM 2DBSP(S) Input: a set S = { s1, s2, … , sn} of pairwise disjoint segments in 2. Output: an auto-partition BSP T of S. if |S|  1 thenT a leaf containing S else do choose a segment s  S S+ { s’ Line(s)+ | s’ S }; T+ 2DBSP(S+) S- { s’ Line(s)- | s’ S }; T- 2DBSP(S-) Create a BSP tree T with root node v, left sub-tree T- , right sub-tree T+ S(v)  {s’ S | s’  Line(s) } end-else returnT end • BSP size depends on the choice of s on line 3: • arbitrary choice : e.g., pick first one • random choice : first do random permutation of S • greedy choice : pick one that cuts fewest segments in its region • …

  12. Arbitrary choice of segment sS on line 3 BSP(p(S)) = BSP if segments in S are inserted in order of permutation p. s1 Q(n2) worst-case BSP size with p= 1,2, …, n. In this instance the best choice is to pick segment sn/2+1 first. s2 s3 sn/2 sn sn/2 +1 sn/2 +2 sn/2 +3 Also try the following example:

  13. Random choice of segment sS on line 3 • RANDOM CHOICE:2DRANDOMBSP(S) p = a random permutation of S, obtained in O(n) time first. Then insert segment in order according to p. • Improvement: Free cuts. If a segment s completely crosses the current region, then pick s first. This choice won’t create any fragments.p* = permutation p with free-cuts having precedence. free cut • To keep track of free cuts corresponding to each BSP node, keep a boolean flag for each segment fragment that indicates whether that fragment contains any end-point of its original segment. • Worst case BSP size is still Q(n2) [even with free cuts]. • Expected BSP size improves [even without free cuts]. Analyzed next.

  14. 2DRANDOMBSP without free-cuts Suppose we next pick segment sj. What is the probability that Line(sj) will CUT another given segment sk? Define (the asymmetric distance): § sj Line(sj) 1 0 0 1 2 There are up to 2 segments for each distance

  15. 2DRANDOMBSP without free-cuts CLAIM: Suppose we next pick segment sj. The probability that Line(sj) will CUT segment sk is PROOF: Suppose segments between sj& skon Line(sj) are si1 , si2 , … , sid ; d = dist(sj, sk). Line(sj) will cut sk only if among the d+2 segments {sj , sk , si1 , si2 , … , sid }, sj is picked first.This choice occurs with probability 1/(d+2). However, some segments that don’t cross Line(sj) (e.g., segment § on previous page) might be picked and separate sj from sk. Thus, prob  1/(d+2).

  16. 2DRANDOMBSP without free-cuts THEOREM: 2DRANDOMBSP constructs BSP of expectedsize O(n log n). PROOF: by linearity of expectation

  17. 2DRANDOMBSP without free-cuts THEOREM: 2DRANDOMBSP expected time = O(n2 log n). PROOF: Each call to 2DRANDOMBSP, excluding its recursive calls, takes at most O(n) time. Expected # of recursive calls is the expected # of nodes in BSP tree = O(n log n). THEOREM: A BSP of size at most O(n log n) can be constructed in expected time O(n2 log n). • PROOF: • Markov inequality: at least half the auto-partition BSP’s have size  2(2n Hn –2n) + n. • Try independent runs of 2DRANDOMBSP until you get a BSP of size  2(2n Hn –2n) + n. • E[ # runs ] = 2. COROLLARY: After this preprocessing (done once and off-line on the static scene),Painter’s Algorithm takes O(n log n) time for any view point.

  18. 2DRANDOMBSP with free-cuts THEOREM: 2DRANDOMBSP with free-splits: expected size = O(n log n). PROOF: p* = random permutation of the input segments, with free-cuts, used by the algorithm. u(2) u(3) extensions of u(1) … u(k) cut segment v from left to right. v u(4) u(1) p*: Line(u(i)) makes a non-free cut of segment v only if: either u(i) precedes all of {v, u(1), u(2), … , u(i-1) }, or u(i) precedes all of {v, u(i+1), u(i+2), … , u(k) }. [Note: both conditions hold if u(i) precedes all of { v, u(1), … , u(k) }.]

  19. 2DNONRANDOMBSP with free-cuts THEOREM: For any n disjoint line segments in 2, an auto-partition BSP tree of size O(n log n) can be computed in O(n2) time. • PROOF: • De-randomize the previous result by obtaining a permutation p* (with free-cuts) that results in a BSP of size O(n log n). • Construct p backwards:p(n), p(n-1), … , p(2), p(1). • Pick p(n) arbitrarily. • Suppose p(n), p(n-1), … , p(k+1) are picked. What should be p(k)? • Consider where the remaining k segment extensions intersect up(n) , … , up(k+1) . • There are  2(n-k) “extreme” fragments on these (n-k) segments. • The remaining “inner” fragments of these (n-k) segments are free-cuts. • Among the remaining k segments there is one, say uj, that contributes no more than the average “extreme” intersection count 2(n-k)/k. • Set p(k) j. • This construction can be carried out in O(n2) time. [How? Can it be improved?]

  20. Non-auto-partition THEOREM [Paterson-Yao 1990]: There is an algorithm that, given n disjoint line segments in 2, constructs a BSP tree of size O(n log n) & depth O(log n) in O(n log n) time.

  21. Non-auto-partition THEOREM [Paterson-Yao 1990]: There is an algorithm that, given n disjoint line segments in 2, constructs a BSP tree of size O(n log n) & depth O(log n) in O(n log n) time. PROOF: Balanced horizontal cuts and free-splits. Hmax a(0) a(1) a(3) a(2) A1 A2 A3 y median Ho B1 B2 b(0) b(1) b(2) Hmin multi-way tree BSP with free cuts • Now convert to binary tree: • choose order of free-cuts Ai’s and Bi’s • in a balanced way, by “weights” of each (sub-tree) a(i) and b(i). • Each segment will be cut in  2 log n fragments. • May consider Segment Trees in the y-direction. Ho A1, A2, A3 B1, B2 a(0) a(1) a(2) a(3) b(0) b(1) b(2)

  22. 3D BSP Algorithms

  23. ALGORITHM 3D Auto-Partition BSP(S) Assume the faces in 3D have been triangulated. ALGORITHM 3DBSP(S) Input: a set S = { t1, t2, … , tn} of triangles in 3. Output: an auto-partition BSP T of S. if |S|  1 thenT a leaf containing S else do choose a triangle t  S S+ { t’ H(t)+ | t’ S }; T+ 3DBSP(S+) S- { t’ H(t)- | t’ S }; T- 3DBSP(S-) Create a BSP tree T with root node v, left sub-tree T- , right sub-tree T+ S(v)  {t’ S | t’  H(t) } end-else returnT end H(t) t Choose triangles randomly, but always give preference to free-splits. Furthermore, once we select a triangle t (to simplify the analysis) we cut all regions intersected by H(t), except those that would create empty regions.

  24. ALGORITHM 3D Auto-Partition BSP(S) current region 3D: t free cut 2D: Line(s2) Line(s1) s1 s2 Line(s3) s3 Line(s3)

  25. ALGORITHM 3D Auto-Partition BSP(S) LEMMA: 3DRANDOMBSP expected size O(n2). PROOF: Random permutation t1, t2, … , tn.Consider how H(tj), j=1,…,k-1, cuts H(tk). (Some won’t cut tk.) Just before sk-1 = H(tk-1)  H(tk) is introduced, the shaded regions in the subdivision of tk are free cuts. Thus, they will be done before tk-1. Hence, they won’t be cut by sk-1. The unshaded region is (at most) the union of the zones of the 3 edges e1, e2, e3 of tk in the arrangement of s1 , s2 , … , sk-1 in H(tk). Hence, it has total size O(k). So, E[ # fragments on H(tk) ] = O(k). Therefore, E[# fragments on all triangles] = O(Sk k) = O(n2). H(tk) e3 tk e1 e2 tk e2 e1 e3 sk-1 = H(tk-1)  H(tk)

  26. Is O(n2) expected size good? FACT: There is a set of n non-crossing triangles in 3 for which any auto-partition has size Q(n2).

  27. What about non-auto-partitions? FACT: There is a set of n non-crossing triangles in 3 for which even any non-auto-partition has size Q(n2). Consider a grid formation of lines (long & skinny triangles) perturbed as follows: z The 4 tiny “openings” forming the 4 “corners” of the grid cell are NOT co-planar. y x • The line equations are: { y=i, z = ix | i = 1 .. n/2 }  { x=i, z = iy + e | i = 1 .. n/2 } • (The n/2 lines parallel to the yz-plane are slightly raised by an e along z.) • For any grid cell, at least one cut has to separate its 4 lines in the immediate neighborhood of the cell. • But any such cut plane has to cut at least one “edge” of the grid cell (since it can’t go in between the tiny openings). • Hence, W(n2) cuts.

  28. Optimal size BSP (?) • 2D BSP:O(n) size is possible for the following classes: • Orthogonal Partitions: n horizontal/vertical segments [Paterson-Yao 1990]. • n “fat” objects (bounded aspect ratio) in 2[de Berg 1994]. • n arbitrary slope segments where the length ratio of the longest vs. shortest segment is bounded by a constant [de Berg 1994]. O(Kn) BSP size if the n segments are restricted to K distinct slopes [Csaba D. Tóth: SODA 2002]. Q(n log n / log log n) general worst-case optimal BSP size in 2[Csaba D. Tóth: SoCG 2009]. 3D BSP: • Orthogonal rectangles in 3 admit O(n1.5) BSP size, and this bound is tight [Paterson-Yao 1992].

  29. Exercises

  30. Let S be a set of m simple polygons in the plane with n vertices in total. Let T be a BSP tree for S of size k. Prove that the total complexity of the fragments generated by the BSP is O(n+k). • Give an example of a set S of n non-intersecting line segments in the plane where the greedy method of constructing an auto-partition (where the splitting line Line(s) is taken that induces the least number of cuts) results in a BSP of quadratic size. • 2D Binary Space Partitioning of a set S of n disjoint line segments in the plane:(a) Give an example of such a set S for which a BSP tree of size n exists, whereas any auto- partition of S has size at least 4n/3.(b) Give an example of such a set S such that any auto-partition tree for S has depth (n). • Suppose we apply 2DRANDOMBSP to a set of intersecting line segments in the plane. What can you say about the expected size of the resulting BSP tree? • Work out the details of 3DRANDOMBSP. More specifically, how can we find the cells that must be cut when a partitioning plane is added, and how do we perform such a cut efficiently? Analyze the running time of the resulting algorithm. • 2D-tree (and kD-trees in general discussed earlier) are special case of 2D BSP trees, where the partitioning lines are restricted to be alternating horizontal/vertical at even/odd depths.(a) Discuss advantages and disadvantages of BSP trees over kD-trees.(b) Consider an arbitrary pair S of non-intersecting line segments in the plane. Show that S admits a BSP of size 2, but it does not admit any 2D-tree of size O(1). • Open Problem: Resolve the O(n log n) vs W(n log n / log log n) gap on the best BSP size for worst-case set of n non-intersecting line segments in the plane.

  31. END

More Related