0% found this document useful (0 votes)
107 views31 pages

CG12 BSP

This document discusses binary space partitions (BSP) which are a data structure used to efficiently perform visibility calculations and rendering for 3D scenes. BSPs recursively subdivide space into convex regions by hyperplanes formed from object boundaries. This allows using a "painter's algorithm" approach to render scenes from any viewpoint in logarithmic time after preprocessing. The document describes algorithms for constructing optimal BSPs from sets of line segments in 2D and proves their expected size is O(n log n) with expected construction time of O(n^2 log n).

Uploaded by

Brinda Pujara
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views31 pages

CG12 BSP

This document discusses binary space partitions (BSP) which are a data structure used to efficiently perform visibility calculations and rendering for 3D scenes. BSPs recursively subdivide space into convex regions by hyperplanes formed from object boundaries. This allows using a "painter's algorithm" approach to render scenes from any viewpoint in logarithmic time after preprocessing. The document describes algorithms for constructing optimal BSPs from sets of line segments in 2D and proves their expected size is O(n log n) with expected construction time of O(n^2 log n).

Uploaded by

Brinda Pujara
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 31

COSC 6114

Prof. Andy Mirzaian


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. Tth [2001], A note on binary plane partitions, SoCG, 151-156.
Csaba D. Tth [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, painters algorithm
Painters Algorithm
Depth Order: 1, 2, 3
1
2
3
Snap-shot of Painters Algorithm
1
2
3
Painters 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.
Problem: This has to be recomputed each time the view point changes. Expensive.
Solution: Preprocess the scene first: Binary Space Partition (BSP)
Problem: in-front-of relation may contain cycles. Hence, no such ordering possible.
Solution: Split some objects to break these cycles. Which? Where?
A 2D scene and its BSP
O4
O5
L1
O3
O1
O2
L2
L3
L4
L5
L6
L7
L
1
L
2
L
3
L
5
L
4
L
7
L
6
O5 O4 O3 O4 O2 O1 O1 O1
BSP
d-dimensional BSP :
S a set of objects in 9
d
.
Node v partition hyper-plane H(v) : a
1
x
1
+ a
2
x
2
+ + a
d
x
d
+ a
d+1
= 0


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

(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
)
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
+ =

+ +
=
+ + +
=

extensions of u(1) u(k) cut


segment v from left to right.
. ] v cuts Line(u(i)) Pr[
1 k
1
2 i k
1
1 i
1
+ + +
+ s
2DNONRANDOMBSP with free-cuts
THEOREM: For any n disjoint line segments in 9
2
, an auto-partition BSP
tree of size O(n log n) can be computed in O(n
2
) time.
PROOF:
De-randomize the previous result by obtaining a permutation t- (with free-cuts) that
results in a BSP of size O(n log n).
Construct t backwards: t(n), t(n-1), , t(2), t(1).
Pick t(n) arbitrarily.
Suppose t(n), t(n-1), , t(k+1) are picked. What should be t(k)?
Consider where the remaining k segment extensions intersect u
t(n)
, , u
t(k+1)
.
There are s 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 u
j
, that contributes no more
than the average extreme intersection count 2(n-k)/k.
Set t(k) j.


( ) ( ) ). n log n ( O n nH 2 n ) S ( * BSP size
n
n
1 k
k
) k n ( 2
= s + s

This construction can be carried out in O(n


2
) time. [How? Can it be improved?]
Non-auto-partition
THEOREM [Paterson-Yao 1990]:
There is an algorithm that, given n disjoint line segments in 9
2
, constructs
a BSP tree of size O(n log n) & depth O(log n) in O(n log n) time.
Non-auto-partition
THEOREM [Paterson-Yao 1990]:
There is an algorithm that, given n disjoint line segments in 9
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.
y median
H
max
H
min
H
o
o(0) o(1)
o(2)
o(3)
|(0) |(1) |(2)
B1
B2
A1
A2 A3
o(0) o(1) o(2) o(3) |(0) |(1) |(2)
A1, A2, A3 B1, B2
H
o
multi-way tree BSP with free cuts
Now convert to binary tree:
choose order of free-cuts Ais and Bis
in a balanced way, by weights of each
(sub-tree) o(i) and |(i).

Each segment will be cut in s 2 log n fragments.

May consider Segment Trees in the y-direction.
3D BSP Algorithms
ALGORITHM 3D Auto-Partition BSP(S)
ALGORITHM 3DBSP(S)
Input: a set S = { t
1
, t
2
, , t
n
} of triangles in 9
3
.
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 triangle t e S
4. S
+
{ t H(t)
+
| te S }; T
+
3DBSP(S
+
)
5. 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

You might also like