CG12 BSP
CG12 BSP
Positive open half-space H
+
(v) : a
1
x
1
+ a
2
x
2
+ + a
d
x
d
+ a
d+1
> 0
Negative open half-space H
(v) : a
1
x
1
+ a
2
x
2
+ + a
d
x
d
+ a
d+1
< 0
S(v) = S H(v)
S
+
(v) = S H
+
(v)
S
(v) = S H
(v)
H
+
(v)
H
(v)
H(v)
BSP of S:
BSP(S
(v))
BSP(S
+
(v))
H(v), S(v)
node v
Node regions in BSP tree
BSP partitions 9
d
into convex polyhedra:
region(v) = the region corresponding to node v in the BSP tree.
region(root) = 9
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) = C internal nodes v,
then # nodes of the BSP tree is in the order of its size.
L1
L2
L3
L4
L5
v
L1
L3
L4
L5
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:
1. For S = a set of line-segments in 9
2
.
BSP partition lines are extensions of the line-segments in S.
Line(s) = line extension of segment seS.
2. For S = a set of polygons in 9
3
,
each BSP partition plane is the plane that contain some polygon in S.
Painters Algorithm (PA) using BSP tree
S = a set of polygons in 9
3
T = a BSP of S
p
view
= the view point in 9
3
T
T
+
root v
T :
ALGORITHM PA( T , p
view
)
v root of T
if v is a leaf then scan-convert object fragment in S(v)
if p
view
e H
, p
view
)
if p
view
e H
+
(v) then PA(T
, p
view
)
scan-convert object fragment in S(v)
PA(T
+
, p
view
)
if p
view
e H(v) then PA(T
+
, p
view
)
PA(T
, p
view
)
end
H
(v)
H
+
(v)
H
(v)
Painters Algorithm using BSP tree
Once the BSP tree is constructed, the efficiency of painters 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.
2D BSP Algorithms
Auto-Partition
ALGORITHM 2DBSP(S)
Input: a set S = { s
1
, s
2
, , s
n
} of pairwise disjoint segments in 9
2
.
Output: an auto-partition BSP T of S.
1. if |S| s 1 then T a leaf containing S
2. else do
3. choose a segment s e S
4. S
+
{ s Line(s)
+
| se S }; T
+
2DBSP(S
+
)
5. S
{ s Line(s)
| se S }; T
2DBSP(S
)
6. Create a BSP tree T with root node v,
left sub-tree T
, right sub-tree T
+
7. S(v) {se S | s c Line(s) }
8. end-else
9. return T
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
Arbitrary choice of segment seS on line 3
BSP(t(S)) = BSP if segments in S are inserted in order of permutation t.
Also try the following example:
s
1
s
2
s
3
s
n/2
s
n
O(n
2
) worst-case BSP size
with t = 1,2, , n.
In this instance the best choice
is to pick segment s
n/2+1
first.
Random choice of segment seS on line 3
RANDOM CHOICE: 2DRANDOMBSP(S)
t = a random permutation of S, obtained in O(n) time first.
Then insert segment in order according to t.
Improvement: Free cuts.
If a segment s completely crosses the current region, then pick s first.
This choice wont create any fragments.
t- = permutation t 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 O(n
2
) [even with free cuts].
Expected BSP size improves [even without free cuts]. Analyzed next.
2DRANDOMBSP without free-cuts
Suppose we next pick segment s
j
.
What is the probability that Line(s
j
) will CUT another given segment s
k
?
Define (the asymmetric distance):
=
+ otherwise
s intersects ) Line(s if
s & s between in
) Line(s ng intersecti
segments of #
k j
k j
j
) s , dist(s
k j
Line(s
j
)
s
j
0
0 1
1
2
There are up to 2 segments for each distance
2DRANDOMBSP without free-cuts
CLAIM: Suppose we next pick segment s
j
.
The probability that Line(s
j
) will CUT segment s
k
is
| |
) s , dist(s 2
k j
+
s
1
s cuts ) Line(s Pr
k j
PROOF:
Suppose segments between s
j
& s
k
on Line(s
j
) are s
i1
, s
i2
, , s
id
; d = dist(s
j
, s
k
).
Line(s
j
) will cut s
k
only if
among the d+2 segments {s
j
, s
k
, s
i1
, s
i2
, , s
id
}, s
j
is picked first.
This choice occurs with probability 1/(d+2).
However, some segments that dont cross Line(s
j
) (e.g., segment on previous page)
might be picked and separate s
j
from s
k
.
Thus, prob s 1/(d+2).
2DRANDOMBSP without free-cuts
THEOREM: 2DRANDOMBSP constructs BSP of expected size O(n log n).
( ) ( ) | |
| |
). n log n ( O
n nH 2
1
2 n
s cuts ) Line(s Pr n
] cuts # E[ n (S) BSP size E
n
n
1 j
2 n
0 d
n
1 j
n
j k
1 k
k j
=
=
|
|
.
|
\
|
+
+ s
+ =
+ =
=
=
=
=
=
d 2
PROOF:
by linearity of
expectation
2DRANDOMBSP without free-cuts
THEOREM: 2DRANDOMBSP expected time = O(n
2
log n).
PROOF:
Markov inequality: at least half the auto-partition BSPs have size s 2(2n H
n
2n) + n.
Try independent runs of 2DRANDOMBSP until you get a BSP of size s 2(2n H
n
2n) + n.
E[ # runs ] = 2.
THEOREM: A BSP of size at most O(n log n)
can be constructed in expected time O(n
2
log n).
COROLLARY:
After this preprocessing (done once and off-line on the static scene),
Painters Algorithm takes O(n log n) time for any view point.
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).
2DRANDOMBSP with free-cuts
THEOREM: 2DRANDOMBSP with free-splits: expected size = O(n log n).
PROOF: t- = random permutation of the input segments, with free-cuts,
used by the algorithm.
u(1)
u(2)
u(3)
u(4)
v
t-: 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) }.]
( ) | |
( ) ( ) ( )
). n log n ( O H n 2 n
2 n n
] v cuts Line(u(i)) Pr[ n (S)) * BSP( size E
n
v
1 k
k
1 k
1
2
1
v
k
1 i
1 k
1
2 i k
1
1 i
1
v
k
1 i
= + s
+ + + s + + s
+ =
+ +
=
+ + +
=
{ t H(t)
| te S }; T
3DBSP(S
)
6. Create a BSP tree T with root node v,
left sub-tree T
, right sub-tree T
+
S(v) {te S | t c H(t) }
7. end-else
8. return T
end
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.
Assume the faces in 3D have been triangulated.
H(t)
t
ALGORITHM 3D Auto-Partition BSP(S)
t
free cut
current region
s1
s2
s3
Line(s1)
Line(s2)
Line(s3)
Line(s3)
3D:
2D:
ALGORITHM 3D Auto-Partition BSP(S)
LEMMA: 3DRANDOMBSP expected size O(n
2
).
PROOF:
Random permutation t
1
, t
2
, , t
n
.
Consider how H(t
j
), j=1,,k-1, cuts H(t
k
).
(Some wont cut t
k
.)
Just before s
k-1
= H(t
k-1
) H(t
k
) is introduced,
the shaded regions in the subdivision of t
k
are free cuts. Thus, they will be done before
t
k-1
. Hence, they wont be cut by s
k-1
.
The unshaded region is (at most) the union
of the zones of the 3 edges e
1
, e
2
, e
3
of t
k
in the arrangement of s
1
, s
2
, , s
k-1
in H(t
k
).
Hence, it has total size O(k).
So, E[ # fragments on H(t
k
) ] = O(k).
Therefore,
E[# fragments on all triangles] = O(E
k
k) = O(n
2
).
H(t
k
)
t
k
e
1
e
2
e
3
s
k-1
= H(t
k-1
) H(t
k
)
t
k
e
1
e
2
e
3
FACT: There is a set of n non-crossing triangles in 9
3
for which
any auto-partition has size O(n
2
).
Is O(n
2
) expected size good?
FACT: There is a set of n non-crossing triangles in 9
3
for which
even any non-auto-partition has size O(n
2
).
Consider a grid formation of lines (long & skinny triangles) perturbed as follows:
The 4 tiny openings
forming the 4 corners
of the grid cell are NOT
co-planar.
The line equations are: { y=i, z = ix | i = 1 .. n/2 } { x=i, z = iy + c | i = 1 .. n/2 }
(The n/2 lines parallel to the yz-plane are slightly raised by an c 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 cant go in between the tiny openings).
Hence, O(n
2
) cuts.
x
y
z
What about non-auto-partitions?
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 9
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. Tth: SODA 2002].
O(n log n / log log n) general worst-case optimal BSP size in 9
2
[Csaba D. Tth: SoCG 2009].
3D BSP:
Orthogonal rectangles in 9
3
admit O(n
1.5
) BSP size,
and this bound is tight [Paterson-Yao 1992].
Exercises
1. 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).
2. 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.
3. 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 O(n).
4. 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?
5. 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.
6. 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).
7. Open Problem: Resolve the O(n log n) vs O(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.
END