CS{1997-09
Binary Space Partitions for Fat Rectangles Pankaj K. Agarwal Edward F. Grove T. M. Murali Jerey Scott Vitter
Department of Computer Science Duke University Durham, North Carolina 27708{0129 April 1997
Binary Space Partitions for Fat Rectangles Pankaj K. Agarwal Edward F. Grovey T. M. Muraliz Jerey Scott Vitterx Abstract
We consider the practical problem of constructing binary space partitions (BSPs) for a set S of n orthogonal, non-intersecting, two-dimensional rectangles in R3 such that the aspect ratio of each rectangle in S is at most , for some constant 1. We present an n2O( log n ) -time algorithm to build a binary space partition of size n2O( log n ) for S . We also show that if m of thep n rectangles in S havepaspect ratios greater than , we can construct a BSP of size n m2O( log n ) for S in n m2O( log n ) time. The constants of proportionality in the big-oh terms are linear in log . We extend these results to cases in which the input contains non-orthogonal or intersecting objects. p
p
p
p
Support was provided by National Science Foundation research grant CCR{93{01259, by Army Research Oce MURI grant DAAH04{96{1{0013, by a Sloan fellowship, by a National Science Foundation NYI award and matching funds from Xerox Corp, and by a grant from the U.S.-Israeli Binational Science Foundation. Address: Box 90129, Department of Computer Science, Duke University, Durham, NC 27708{0129. Email:
[email protected] y Support was provided by Army Research Oce grant DAAH04{93{G{0076. This work was partially done when the author was at Duke University. Address: 946, Tamarack Lane #13, Sunnyvale, CA 94086. Email:
[email protected] z This author is aliated with Brown University. Support was provided in part by National Science Foundation research grant CCR{9522047 and by Army Research Oce MURI grant DAAH04{96{ 1{0013. Address: Box 90129, Department of Computer Science, Duke University, Durham, NC 27708{0129. Email:
[email protected] x Support was provided in part by National Science Foundation research grant CCR{9522047, by Army Research Oce grant DAAH04{93{G{0076, and by Army Research Oce MURI grant DAAH04{96{1{ 0013. Address: Box 90129, Department of Computer Science, Duke University, Durham, NC 27708{0129. Email:
[email protected]
1
1 Introduction How to render a set of opaque or partially transparent objects in R3 quickly and in a visually realistic way is a fundamental problem in computer graphics [15, 29]. A central component of this problem is hidden-surface removal : given a set of objects, a viewpoint, and an image plane, compute the scene visible from the viewpoint on the image plane. Because of its importance, the hidden-surface removal problem has been studied extensively in both the computer graphics and the computational geometry communities [14, 15]. One of the conceptually simplest solutions to this problem is the z -buer algorithm [8, 15]. This algorithm sequentially processes the objects; for each object, it updates the pixels of the image plane covered by the object, based on the distance information stored in the z -buer. A very fast hidden-surface removal algorithm can be obtained by implementing the z -buer in hardware. However, the cost of a hardware z -buer is very high. Only special-purpose and costly graphics engines contain fast z -buers, and z -buers implemented in software are generally inecient. Even when fast hardware z -buers are present, they are not fast enough to handle the huge models (containing hundreds of millions of polygons) that often have to be displayed in real time. As a result, other methods have to be developed either to \cull away" a large subset of invisible polygons so as to decrease the rendering load on the graphics pipeline (when models are large; e.g., see [30]) or to completely solve the hidden-surface removal problem (when there are very slow or no z -buers). One technique to handle both of these problems is the binary space partition (BSP), a data structure introduced by Fuchs et al. [16] that is based on work by Schumacker et al. [28]. Fuchs et al. use the BSP to implement the so-called \painter's algorithm" for hidden-surface removal; the painter's algorithm draws the objects to be displayed on the screen in a backto-front order (in which no object is occluded by any object earlier in the order). In general, it is not possible to nd a back-to-front order from a given viewpoint for an arbitrary set of objects. By fragmenting the objects, the BSP ensures that a back-to-front order from any viewpoint can be determined for the fragments. BSPs have subsequently proven to be versatile, with applications in many other problems|global illumination [6], shadow generation [10, 11], visibility problems [4, 30], solid modeling [23, 25, 31], geometric data repair [20], ray tracing [22], robotics [5], and approximation algorithms for network design [19] and surface simpli cation [3]. Algorithms have also been developed to construct BSPs for moving objects [1, 12, 24, 32]. Informally, a BSP B for a set of objects is a binary tree. Each node v of B is associated with a convex region R . The regions associated with the children of v are obtained by splitting R with a hyperplane. If v is a leaf of B , then the interior of R does not intersect any object. The regions associated with the leaves of the tree form a convex decomposition of space. The faces of the decomposition induced by the leaves intersect the objects and divide them into fragments; these fragments are stored at appropriate nodes of the BSP. The eciency of most algorithms that use BSPs depends on the number of nodes in the v
v
v
1
BSP. As a result, there has been a lot of eort to construct BSPs of small size. Although several simple heuristics have been developed for constructing BSPs of reasonable sizes [4, 7, 16, 21, 30, 31], provable bounds were rst obtained by Paterson and Yao. They show that a BSP of size O(n log n) can be constructed for n disjoint segments in R2 ; in R3 , they show that a BSP of size O(n2 ) can be constructed for n disjoint triangles in R3 , which is optimal in the worst case [26]. But in graphics-related applications, many common environments like buildings are composed largely of orthogonal rectangles, and non-orthogonal objects are approximated by their orthogonal bounding boxes [15]. Paterson and Yao [27] show that a BSP of sizepO(n) exists for n non-intersecting, orthogonal segments in R2 and that a BSP of size O(n n) exists for n non-intersecting, orthogonal rectangles in R3 . These bounds are optimal in the worst case.
(a)
(b)
Figure 1: (a) Lower bound for orthogonal rectangles. (b) Model of Soda Hall|85% of the rectangles have aspect ratio at most 25. In all known lower bound examples of orthogonal rectangles in R3 requiring BSPs p of size (n n), most of the rectangles are \thin." For example, Paterson and Yao's lower rectangles, arranged in p bound p pproof uses a con guration of (n) orthogonal p a n n n grid, for which any BSPphas size (n n) (see Figure 1(a)). All rectangles in their construction have aspect ratio ( n). Such con gurations of thin rectangles rarely occur in practice. Many real databases consist mainly of \fat" rectangles, i.e., the aspect ratios of these rectangles are bounded by a constant. An examination of four datasets|the Sitterson Hall, the Orange United Methodist Church Fellowship Hall, and the Sitterson Hall Lobby databases from the University of North Carolina at Chapel Hill and the model of Soda Hall from the University of California at Berkeley (shown in Figure 1(b))|shows that most of the rectangles in these models have aspect ratio less than 30. It is natural to ask whether BSPs of near-linear size can be constructed if most of the 2
rectangles are \fat." We call a rectangle fat if its aspect ratio (the ratio of the longer side to the shorter side) is at most , for a xed constant 1. A rectangle is said to be thin if its aspect ratio is greater than . In this paper, we consider the following problem: Given a set S of n non-intersecting, orthogonal, two-dimensional rectangles in R3 , of which m are thin and the remaining n ? m are fat, construct a BSP for S . p
in R3 (i.e., We rst show how to construct a BSP of size n2 ( log ) forpn fat rectangles p ( log ) when m = 0). We then show that if m > 0, a BSP can be built. p of size n m2 This bound comes close to the lower bound of (n m) on the size of such a BSP, which we prove later. We nally prove two important extensions to these results. If p of the n input objects are p non-orthogonal, we show that an np2 ( log ) -size BSP exists. Unlike in the case of orthogonal objects, fatness does not help in reducing the worst-case size of BSPs for non-orthogonal objects. In particular, we prove that there exists a set of n fat triangles in R3 for which any BSP has (n2 ) size. However, non-orthogonal objects can be approximated by orthogonal bounding boxes. The resulting bounding boxes might intersect each other. Motivated by this observation, we also consider the problem where n fat rectangles contain kpintersecting p pairs of rectangles, and we show that wepcan construct a BSP of size (n + k) k2 ( log ) . We also prove a lower bound of (n + k k) on the size of such a BSP. In all cases, the constant of proportionality in the big-oh terms is linear in log , where is the maximum aspect ratio of the fat rectangles. Our algorithms to construct these BSPs run in time proportional to the size of the BSPs they build. Experiments demonstrate that our algorithms work well in practice and construct BSPs of near-linear size when most of the rectangles are fat, and perform better than most known algorithms for constructing BSPs for orthogonal rectangles [2]. As far as we are aware, ours is the rst work to consider BSPs for the practical and common case of (two-dimensional) fat polygons in R3 . de Berg considers a weaker model, the case of (three-dimensional) fat polyhedra in R3 (a polyhedron is said to be fat if its volume is at least a constant fraction of the volume of the smallest sphere enclosing it), although his results extend to higher dimensions [13]. One of the main ingredients of our algorithm is the construction of an O(n log n)-size BSP for a set of n fat rectangles that are \long" with respect to a box B , i.e., none of the vertices of the rectangles lie in the interior of B . To prove this result, we crucially use the fatness of the rectangles. We use this procedure to construct a BSP of size O(n4 3 ) for fat rectangles. The algorithm repeatedly applies cuts that bisect the set of vertices of rectangles in S until all sub-problems have long rectangles and the total size of the subproblems is O(n4 3 ), at which pointpwe can invoke the algorithm for long rectangles. We improve the size of the BSP to n2 ( log ) by simultaneously simulating the algorithm for long rectangles and partitioning the vertices of rectangles in S in a clever manner. O
n
O
O
n
n
O
n
=
=
O
n
3
The rest of the paper is organized as follows: Section 2 gives some preliminary de nitions. In Section 3, we show how to build an O(n log n)-size BSP for n long rectangles. Then we show how to construct a BSP of size O(n4 3 ) in Section 4. Sections 5 and 6 present and p ( log ) . We extend this result analyze a better algorithm that constructs a BSP of size n2 in Section 7 to construct BSPs in cases when some objects in the input are (i) thin, (ii) non-orthogonal, or (iii) intersecting. We conclude in Section 8 with some open problems. =
n
O
2 Geometric Preliminaries A binary space partition B for a set S of pairwise-disjoint, (d ? 1)-dimensional, polyhedral objects in R is a tree de ned as follows: Each node v in B represents a convex region R and a set of objects S = fs \ R j s 2 S g that intersect R . The region associated with the root is R itself. If S is empty, then node v is a leaf of B Otherwise, we partition R into two convex regions by a cutting hyperplane H . At v, we store the equation of H and fs j s 2 S ; s H g, the subset of objects in S that lie in H . If we let H + be the positive halfspace and H ? the negative halfspace bounded by H , the regions associated with the left and right children of v are R \ H ? and R \ H + , respectively. The left subtree of v is a BSP for the set of objects S ? = fs \ H ? j s 2 S g and the right subtree of v is a BSP for the set of objects S + = fs \ H + j s 2 S g. The size of B is the sum of the number of nodes in B and the total number of faces of all dimensions of the objects stored at all the nodes in B. A back-to-front order for S with respect to a viewpoint p can be determined by traversing B in a speci c order: suppose we are at a node v of the BSP during the traversal. If v is a leaf, we simply return. Otherwise, if p lies in the positive halfspace de ned by H , we rst recursively visit the left child of v (which is associated with the negative halfspace), then report all the objects lying in H , and nally recursively visit the right child of v. The procedure is symmetric if p lies in the negative halfspace de ned by H . If p lies in H , the order in which we visit the children of v does not matter. In our case, S is a set of orthogonal rectangles in R3 and each cutting plane is normal to one of the axes. Therefore, the region R associated with each node v in B is a box (rectangular parallelepiped). We say that a rectangle r is long with respect to a box B if none of the vertices of r lie in the interior of B . Otherwise, r is said to be short. See Figure 2. A long rectangle is said to be free if none of its edges lies in the interior of B ; otherwise it is non-free. A free cut is a cutting plane that does not cross any rectangle in S and that either divides S into two non-empty sets or contains a rectangle in S Note that the plane containing a free rectangle is a free cut. Free cuts play a critical role in preventing excessive fragmentation of the rectangles in S . We will often focus on a box B and construct a BSP for the rectangles intersecting it. d
v
v
d
v
v
v
:
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
:
4
s
(a)
(b)
Figure 2: (a) Long and (b) short rectangles. Heavy dots indicate the vertices of these rectangles that lie on the boundary of the box. Rectangle s is a free rectangle. Given a set of rectangles R, let
R = fs \ B j s 2 Rg B
be the set of rectangles obtained by clipping the rectangles in R within B . For a set of points P , let P be the subset of P lying in the interior of B . Sometimes, we will abuse notation and use B to also refer to the corresponding node in the BSP. z -axis Top face B
y-axis Right face
x-axis Front face
Figure 3: Dierent classes of rectangles. The box B has six faces|top, bottom, front, back, right, and left. We assume, without loss of generality, that the back, bottom, left corner of B is the origin (i.e., the back face of B lies on the yz -plane). A rectangle s that is long with respect to to B belongs to the top class if two parallel edges of s \ B are contained in the top and bottom faces of B . We similarly de ne the front and right classes. A long rectangle belongs to at least one of these three classes; a non-free rectangle belongs to a unique class. See Figure 3 for examples of rectangles belonging to dierent classes. Although a BSP is a tree, we will often just discuss how to partition the box represented 5
by a node into two boxes. We will not explicitly detail the associated construction of the actual tree itself, since the construction is straightforward once we specify the cutting plane. In the rest of the paper, we assume that the vertices of the rectangles in S are sorted by x-, y-, and z -coordinate. The cost of this sort will not aect the asymptotic running times of our algorithms. We now state two preliminary lemmas that we will use below. The rst lemma characterizes a set of rectangles that are long with respect to a box and belong to one class. The second lemma applies to two classes of long rectangles. face g
(a)
(b)
Figure 4: (a) Long rectangles in the top class. (b) Projections of the rectangles in (a) onto the top face g; heavy dots indicate the vertices of these rectangles that lie in the interior of g. The dashed line is the cut satisfying (2.1).
Lemma 2.1 Let C be a box, P a set of points in the interior of C , R a set of rectangles long with respect to C , and w 1 a real number. If the rectangles in R belong to one class, then the following two conditions hold (see Figure 4): C
(i) There exists a face g of the box C that contains exactly one of the edges of each rectangle in R . Let V be the set of those vertices of the rectangles in R that lie in the interior of g. (ii) We can nd a plane that partitions C into two boxes C1 and C2 so that for i = 1; 2, (2.1) jV \ C j + wjP i j jV j +2wjP j : Proof : Part (i) follows from the de nition of a class. To prove Part (ii), let P be the set of projections of the points in P onto g. Assume g is the top face of C . If we associate a weight of 1 with each point in V and a weight w with each point in P , the total weight of C
C
i
C
6
the points in V [ P is jV j + wjP j. By sweeping g, we can nd a line l parallel to the x-axis lying in g that contains a point in V [ P and that divides V [ P into two sets, each with weight at most (jV j + wjP j)=2. We split C into two boxes C1 and C2 by drawing the plane containing l that is orthogonal to g. By construction, C1 and C2 satisfy (2.1).
Lemma 2.2 Let C be a box, P a set of points in the interior of C , R a set of rectangles long with respect to C , and w 1 a real number. If the rectangles in R belong to two classes, then one of the following two conditions holds (see Figure 5):
C
(i) We can nd one free cut that partitions C into two boxes C1 and C2 so that (2.2) jR i j + wjP i j 2 (jR j 3+ wjP j) for i = 1; 2. (ii) We can nd two parallel free cuts that divide C into three boxes C1 ; C2 ; and C3 such that all rectangles in R 2 belong to the same class and such that (2.3) jR 2 j + wjP 2 j jR j +3 wjP j : C
C
C
C
C
C
C
h2 z -axis
C3 y -axis C2
h1 y -axis
C2 x-axis
h C1
x-axis
z -axis
C1
(a)
(b)
Figure 5: Cuts made for two classes of rectangles: (a) One free cut and (b) Two parallel free cuts. Proof : Let r denote the projection of a rectangle r 2 R onto the x-axis: r is either a point or an interval. Similarly, let p denote the projection of a point p 2 P onto the x-axis. Set [ U = f([ 2 C r) ([ 2 p)g: C
r
R
p
P
U is a collection of disjoint intervals, some of which may be single points. Let r1 (resp., r2 ) be a rectangle in R belonging to the top (resp., right) class. Since the rectangles in R are C
C
7
disjoint, it is easily seen that r1 and r2 are also disjoint. Hence, each connected component of U contains the projections of rectangles belonging to at most one class (see Figure 5(b)). For any connected component I of U de ne,
(I ) = jfr 2 R j r I gj + wjfp 2 P j p I gj: C
Set W = jR j + wjP j. If U contains a connected component I = [ ; ] with (I ) > W=3, then the two free cuts are x = and x = . The cuts partition the box C into three boxes C1 ; C2 , and C3 , where C
C1 = fq j q 2 C and x(q) g; C2 = fq j q 2 C and x(q) g; and C3 = fq j q 2 C and x(q) g: By construction, all rectangles in R 2 belong to at most one class. Hence, condition (ii) holds.1 If there is no such connected component of U , then let I = [ ; ] be the leftmost conP 0 0 0 nected component of U with 0 (I ) > W=3 (we say that I I if I lies to the left of P I ). Since (I ) W=3 and 0 (I 0) < W=3, C
I
I
I 0: i
i
i
(g; d)
4 X
(g ; d ? 1); i
where
4 X
g 2g; i
i=1
i=1
because each edge of r is split into at most two edges by a phase of cuts (by the cutting plane orthogonal to the edge). We see that (g; 0) = 1 and (0; d) = 1, because a free 13
t
s
v
u
Figure 8: The shaded region is a rectangle r with one edge lying in the interior of B (r is shown projected onto a face of B that r is parallel to). A phase divides r into four pieces s; t; u; and v; s and t are free rectangles. rectangle at the beginning of a phase is removed by a free cut. It is easily checked that the solution to this recurrence is 3g(2 ? 1) + 1. d
We can now bound the size of the BSP constructed by the algorithm.
Theorem 4.2 A BSP of size O(n ) can be constructed for n fat orthogonal rectangles 4=3
in R . The constant of proportionality in the big-oh term is linear in 2 , where is the maximum aspect ratio of the input rectangles. 3
Proof : If a box B has k vertices in its interior, one phase of cuts partitions B into eight boxes each of which has at most bk=8c vertices in its interior. Since we start with n rectangles that have at most 4n vertices, the number of phases executed by the above algorithm is at most d(log n)=3 + 2=3e: Lemma 4.1 now implies that the total number of rectangles formed once all the phases are executed is O(n2(log ) 3 ) = O(n4 3 ). At this stage, all boxes have only long rectangles. Hence, Theorem 3.2 and the remark at the end of Section 3 imply that we can construct a linear-size BSP in each of these boxes, which increases the total size of the BSP only by a constant factor. This proves the theorem. n =
=
5 An Improved Algorithm We now describe an improved algorithm, in which we simultaneously simulate the algorithm for long fat rectangles of Section 3 and partition the vertices of the rectangles in S . The algorithm proceeds in rounds. Each round simulates a few steps of the algorithm for long rectangles and partitions the vertices of the rectangles in S into a small number of sets of approximately equal size. At the beginning of the ith round, for i > 0, the algorithm has a top subtree B of the BSP for S Let Q be the set of boxes associated with the leaves of B containing at least one rectangle. The initial tree B1 consists of one node and Q1 consists of one box that contains all the input rectangles. Our algorithm maintains the invariant that for each box B 2 Q , all long rectangles in S are non-free. If Q is empty, we are i
:
i
i
i
B
14
i
done. Otherwise, in the ith round, for each box B 2 Q , we construct a top subtree T of the BSP for the set S and attach it to the corresponding leaf of B . This gives us the new top subtree B +1 . Thus, it suces to describe how to build the tree T on a box B during a round. Let F S be the set of rectangles that are long with respect to B . Set f = jF j, and let k be the number of vertices of rectangles in S that lie in the interior of B (note that each such vertex is a vertex of an original rectangle in the input set S ). By assumption, all rectangles in F are non-free. We choose a parameter a, which remains xed throughout the round. We pick i
B
B
i
i
B
B
B
a=2
p
log(f +k )
to optimize the size of the BSP that the algorithm creates (see Theorem 6.5). We now describe the ith round in detail. If k = 0 (i.e., if all rectangles in S are long), we use Theorem 3.2 to construct a BSP for S . Otherwise, we perform a sequence of cuts in two stages that partition B as follows: B
B
We apply the -cuts, as described in Section 3.1. We make these cuts with respect to the rectangles in F , i.e., we consider only those rectangles of S that are long with respect to B . Let C be the set of boxes into which B is partitioned by the -cuts. Dividing Stage: We re ne each box C in C by applying cuts similar to the ones made in Section 3.2, as described below. Let k denote the number of vertices of rectangles in S that lie in the interior of C . Recall that F is the set of rectangles in F that are clipped within C . We recursively invoke the dividing stage until jF j + 2ak (f + ak)=a and S does not contain any free rectangles. 1. If C has any free rectangle, we use the free cut containing that rectangle to split C into two boxes. 2. If the rectangles in F belong to two classes, let P denote the set of vertices of the rectangles in S that lie in the interior of C . We apply at most two parallel free cuts that satisfy Lemma 2.2, with R = F; P = P , and w = 2a. 3. If the rectangles in F belong to just one class, we apply one cut using Lemma 2.1, with R = F; P = P , and w = 2a.
Separating Stage:
B
C
C
C
C
C
C
C
C
C
C
C
C
The cuts introduced during the dividing stage can be made in a tree-like fashion. At the end of the dividing stage, we have a set of boxes so that for each box D in this set, S does not contain any free rectangle and jF j + ak (f + ak )=a. Notice that as we apply cuts in C and in the resulting boxes, rectangles that are short with respect to C may become long with respect to the new boxes. We ignore these new long rectangles until the next round, unless they induce a free cut. D
D
D
15
6 Analysis of the Improved Algorithm We now analyze the size of the BSP constructed by the algorithm and the time complexity of the algorithm. In a round, the algorithm constructs a top subtree T of the BSP for the set of clipped rectangles S . Recall that F is the set of rectangles that are long with respect to B . For a node C in T , let T be the subtree of T rooted at C , the number of long rectangles in F , and the number of long rectangles in S n F . For a box D corresponding to a leaf of T , let f be the number of long rectangles in S . Note that f counts both the \old" long rectangles in F (pieces of rectangles that were long with respect to B ) and the \new" long rectangles in S n F (pieces of rectangles that were short with respect to B , but became long with respect to D due to the cuts made during the round); f = + . In a round, the separating stage rst splits B into a set of boxes C . For each box C in C , F has only two classes of long rectangles. The algorithm then executes the dividing stage on each such box C . As in the case of the algorithm for long rectangles (see Section 3), the subtree constructed in C has the following property: if Step 3 is executed at a node v, then Step 2 is not executed at any descendent of v. Let D be a node in T where Step 3 is invoked. In Lemma 6.1, we prove a bound on the total number of long rectangles at each leaf of T . We bound the number of long rectangles at the leaves of T in Lemmas 6.2 and 6.3. In Lemma 6.4, we prove a bound on the size of the tree T . In our main result (Theorem 6.5), we use the previous lemmas to establish bounds on the size of the BSP constructed by our algorithm and the running time of our algorithm. B
B
B
C
C
B
C
C
B
C
C
D
D
D
D
D
D
D
D
D
C
C
D
C
B
Lemma 6.1 For a box D associated with a leaf of T , B
f + 2ak f +a2ak : D
D
Proof : We know that is at most k (since a rectangle in S n F must be a piece of a rectangle short with respect to B , and there are at most k short rectangles in B ). Since f + 2ak + 2ak + and + 2ak (f + ak )=a (by construction), the lemma follows. D
D
D
D
D
D
D
D
D
D
For a box C in T , we use the notation L to denote the set of leaves in T . B
C
C
Lemma 6.2 Let C be a box associated with a node in T . If all rectangles in F belong to B
one class, then
X D
2 C L
f 2 + 2 max 2 ( + ak ) ; 1 + 4k C
D
C
C
C
where = (f + ak )=a.
16
+ ak C
C
C
C
;
Proof : Assume, without loss of generality, that all rectangles in F belong to the top class, and let g be the top face of C . By Lemma 2.1(i), g contains an edge of every rectangle in F . Let be the number of vertices of the non-free long rectangles in F that lie in the interior of g; obviously, 2 . Set C
C
C
C
C
C
C
X
( ; ; k ) = max C
C
C
D
2 C
f ; D
L
where the maximum is taken over all boxes C and over all sets S of rectangles with vertices of rectangles in S lying in the interior of the top face of C , long rectangles in S n F , and k vertices in the interior of C . We claim that (6.1) ( ; ; k ) + 2 max + 2ak ; 1 + 2k + 2ak ; C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
which implies the lemma, because 2 . Note that if S contains m 1 free rectangles, we apply the free cuts containing these rectangles to partition C (by repeatedly invoking Step 1 of the dividing stage) until the resulting boxes do not contain any free rectangles. The free cuts partition C into a set E of m + 1 boxes. Since we have created the boxes in E using free cuts, C
C
C
+ 2ak + 2ak ; for any box E in E ; X X X ; k k ; : E
E
E
2E
E
C
C
C
E
2E
E
C
E
2E
E
(6.2)
C
These inequalities imply that if (6.1) holds for each box in E , then (6.1) holds for C as well. Therefore, we prove (6.1) for all boxes C such that F contains only one class of rectangles and S does not contain any free rectangle. We proceed by induction on + 2ak . Base Case: 0 + 2ak . Since S does not contain any free rectangles, C is a leaf of T , i.e., L = fC g. We have C
C
C
C
B
C
C
C
C
( ; ; k ) = C
C
X
C
D
2 C
f = + + ; D
C
C
C
(6.3)
C
L
which implies (6.1).
Induction step: + 2P ak > . In this case, C is split into two sub-boxes C and C by P P C
C
2 C2 f , 2 C1 f + 2 Cf = ( ; ; k ) = ( 1 ; 1 ; k 1 ) + ( 2 ; 2 ; k 2 ) ;
a cutting plane h. Since
C
D
C
L
D
C
D
C
L
C
D
C
D
L
C
1
2
D
C
C
where k 1 + k 2 k and 1 + 2 . Note that h does not contain a free rectangle. For i = 1; 2, each long rectangle in S i nF i is contained either in a long rectangle in S n F or in a short rectangle in S . Since h C
C
C
C
C
C
C
C
17
C
C
C
intersects each rectangle in S at most once and a short rectangle intersected by h is divided into one short and one long rectangle, C
1 + 2 2 + k : C
C
C
(6.4)
C
By Lemma 2.1(ii), we have
i + 2ak i +22ak ; C
C
for i = 1; 2:
C
C
(6.5)
Let E1 (respectively, E2 ) be the set of boxes obtained by applying all the free cuts in S (respectively, S 2 ) in Step 1 of the dividing stage. Clearly,
C1
C
( ; ; k ) = C
C
X
C
E
2E1
X
( ; ; k ) + E
E
E
E
2E2
( ; ; k ): E
E
E
We consider two cases. Case (i): < + 2ak 2. For each i = 1; 2 i + 2ak i +22ak : As a result, all boxes in E1 and E2 are leaves of T . Using (6), and (6.3), we obtain C
C
C
C
C
C
B
( ; ; k ) C
C
X
C
E
2E1
X
f + E
E
2E2
X
f E
E
2E1
( + ) + E
E
1 + 1 + 2 + 2: C
C
C
X
E
2E2
( + ) E
E
C
By (6.4), we have ( ; ; k ) + 2 + k ; C
C
C
C
C
(6.6)
C
which implies (6.1), because + 2ak > . Case (ii): + 2ak > 2. For any box E in E1 [ E2, by (6) and (6.5), + 2 ak + 2ak : + 2 ak ; 1 max ; 1 = max 2 2 By (6) and the induction hypothesis, X + 2 ak + 2 ak + 2 ( ; ; k ) + 2k 2 2 2E1 X + 2 ak + 2 ak + 2 + + 2k 2 2 2E2 + 2 ak + 2ak + 2 ( k ( 1 + 2 ) + 2 ( 1 + 2 ) 1 + k 2) 2 2 C
C
C
C
E
C
E
C
C
C
E
C
C
C
C
C
E
C
C
E
E
C
E
C
C
E
C
E
E
C
C
C
C
C
C
C
C
18
C
C
:
Using (6.4), we obtain
( ; ; k ) + 2 (2 + k ) +22ak + 2 ak = + 2 + 2k C
C
C
C
C
C
C
C
+ 2k +22ak + 2ak ; C
C
C
C
C
C
C
C
C
C
which implies (6.1).
Lemma 6.3 Let C be a box associated with a node in T . If all rectangles in F belong to two classes, then B
X D
2 C
f 2 + 5 max D
C
(
+ 2ak C
C
L
3 C
C
)
; 1 + 6k
+ 2ak C
C
3 C
;
where = (f + ak )=a. Proof : Let
X
( ; ; k ) = max C
C
C
D
2 C
f ; D
L
where the maximum is taken over all boxes C and over all sets S of rectangles with long rectangles in F , long rectangles in S n F , and k vertices in the interior of C . The rectangles in F belong to at most two classes. We claim that C
C
C
C
C
C
C
( ; ; k ) 2 + 5 max C
C
C
C
C
(
+ 2ak C
3 C
)
; 1 + 6k
+ 2ak C
C
3 C
;
(6.7)
which proves the lemma. If S contains m 1 free rectangles, we apply the free cuts containing these rectangles to partition C (by repeatedly invoking Step 1 of the dividing stage) until the resulting boxes do not contain any free rectangles. Let E be the set of boxes into which C is so partitioned. Then + 2ak + 2ak ; for any box E in E ; X X X (6.8) k k : C
E
E
E
E
2E
C
C
C
E
2E
E
C
E
2E
E
C
These inequalities imply that if (6.7) holds for each box in E , then (6.7) holds for C as well. Therefore, we prove (6.7) for all boxes C such that F contains at most two classes of rectangles and S does not contain any free rectangle. We proceed by induction on + 2ak . C
C
C
C
19
Base case: + 2ak . Since S does not contain any free rectangles, C is a leaf of T . We have X ( ; ; k ) = f + ; (6.9) C
C
C
B
C
C
C
D
D
2 C
C
C
L
which implies (6.7).
Induction step: + 2ak > . The cuts made in Step 2 of the dividing stage fall into C
C
one of two categories (see Lemma 2.2). Note that none of these cuts contain a free rectangle. Case (i): We divide C into two boxes C1 and C2 using a plane h that does not intersect any rectangle in F . As a result, C
1 + 2 C
C
k 1 +k 2 k :
and
C
C
C
C
Since h intersects each rectangle in S at most once, (6.4) holds in this case too. Lemma 2.2 implies that for i = 1; 2: (6.10) i + 2ak i 2( +3 2ak ) C
C
C
C
C
Let E1 (resp., E2 ) be the set of boxes obtained by applying all the free cuts in S (resp., S 2 ) in Step 1 of the dividing stage. Clearly,
C1
C
( ; ; k ) C
C
X
C
E
2E1
( ; ; k ) + E
E
X
E
E
2E2
( ; ; k ): E
E
E
We consider two cases. (a) + 2ak 3=2. In this case, by (6.10), + 2ak 2( +3 2ak ) ; for each box E in E1 and E2 . Since E does not contain a free rectangle, E is a leaf of T . Using (6.8) and (6.9), we obtain C
C
C
E
C
E
B
( ; ; k ) C
C
C
X
2E1 X
E
E
2E1
f +
X
E
E
2E2
f
E
( + ) + E
X
E
E
2E2
1 + 1 + 2 + + 2 + k ; C
C
C
C
which implies (6.7,) because + 2ak > . C
C
20
C
C
C2
( + ) E
E
(b) + 2ak > 3=2. For a box E in E [ E , by (6.8) and (6.10), we have C
max
1
C
(
+ 2ak E
3 E
)
; 1 max
2
(
2 + 2ak 3 C
3 C
)
8 + 2ak ; 1 = 27 C
By the induction hypothesis, and by using (6.8) and (6.4), !
3 C
:
!!
8 + 2ak 3 + 6k 8 + 2ak 3 2 + 5 27 ( ; ; k ) 27 2E1 3 ! 3 !! X + 2 ak + 2 ak 8 8 + 6k 27 2 + 5 27 + 2E2 ! 3 + 2 ak 8 2 ( 1 + 2 ) + 5 ( 1 + 2 ) 27 3 ! 8 + 2ak + 6 (k 1 + k 2 ) 27 3 3 8 + 2 ak 8 + 2 ak 2 + 5 27 (2 + k ) + 6 27 k 3 3 2 + 5 + 2ak + 6k + 2ak ; X
C
C
C
E
C
C
C
E
C
E
E
C
E
C
C
C
E
E
E
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
which implies (6.7). Case (ii): We nd two parallel planes h1 and h2 that divide C into three boxes C1; C2 ; and C3 (in this order) so that all rectangles in F 2 belong to one class. Lemma 2.2 implies that the rectangles in F are partitioned among C1 ; C2 ; and C3 . Moreover, h1 and h2 partition the vertices in the interior of C . Thus, C
C
1 + 2 + 3 C
C
C
and
C
k 1 +k 2 +k 3 k : C
C
C
C
The planes h1 and h2 can intersect the rectangles in S n F . Each long rectangle in S n F is partitioned into at most three long rectangles. Each short rectangle in S is partitioned into at most three rectangles; if two of these rectangles are long, then one of the long rectangles must be in S 2 , since C2 is sandwiched between C1 and C3 (see the proof of Lemma 2.2). In other words, C
C
C
C
C
C
1 + 3 2 + k C
C
C
Lemma 2.2 also implies that i + 2ak i 2( +3 2ak ) ; C
C
C
C
and
C
for i = 1; 3; and 21
2 +k : C
C
(6.11)
C
2 + 2ak 2 + 2ak : C
C
C
C
(6.12)
Let E ; 1 i 3 be the set of boxes obtained by applying all the free cuts in S i in Step 1 of the dividing stage. Note that for each box E 2 E2 , F contains only one class of rectangles. It is clear that i
C
E
( ; ; k ) C
C
X
C
E
2E1
X
( ; ; k ) + E
E
E
E
2E2
X
(2 ; ; k ) + E
E
E
E
2E3
( ; ; k ); E
E
E
where ( ) is as de ned in the proof of Lemma 6.2. We again consider two cases. (a) < + 2ak 3=2. By (6.12), each box in E1 and E3 is a leaf of T . Therefore, by (6.9), C
C
B
( ; ; k ) C
C
C
X
2E1 X
E
E
2E1
X
f + E
E
2E2
E
X
( + ) + E
E
E
2E3
E
E
C
C
2EX 3
( + ) + E
E
X
C
E
f
E
E
( 1 + 3 ) + ( 1 + 3 ) + C
X
(2 ; ; k ) +
2E2
E
2E2
(2 ; ; k ) E
E
E
(2 ; ; k ) : E
E
E
For each box E 2 E2 , + 2ak 3=2: Hence, by (6.6), we have E
E
(2 ; ; k ) 2 + 2 + k : E
E
E
E
E
E
As a result, ( ; ; k ) ( 1 + 3 ) + ( 1 + 3 ) + C
C
C
C
C
C
X
C
E
2E2
(2 + 2 + k ) E
E
E
( 1 + 3 ) + ( 1 + 3 ) + (2 2 + 2 2 + k 2 ) 2 + 4 + 4k ; C
C
C
C
C
C
C
C
C
C
where the last inequality follows from (6.11). This inequality implies (6.7). (b) + 2ak > 3=2. For a box E 2 E1 [ E3 , C
max
C
(
+ 2ak E
3 E
)
; 1 max
(
2 + 2ak 3 C
Similarly, for a box E 2 E2 ,
max 2 + ak E
E
3 C
)
C
; 1 2 +2ak C
22
8 + 2ak ; 1 = 27 C
:
3 C
:
By the induction hypothesis and (6.1),
8 + 2ak 2 + 5 27 ( ; ; k ) 2E1 X 2 + 4 +2ak + C
C
3
!
+ 2ak 3 + 2 ak + 4k 2E2 3 X 8 + 2 ak 8 + 6 27 k +2ak 2 + 5 27 + 2E3
X
C
E
E
C
E
C
C
E
8k + 6 27
C
C
E
C
C
E
C
E
E
C
C
C
E
E
3 ! C
E
:
E
Since + 2ak > 3=2, C
C
+ 2ak 4 + 2ak 9 C
C
C
3 C
:
Therefore, using (6.11), we have
8 ( + ) + 2ak ( ; ; k ) 2 ( 1 + 2 + 3 ) + 5 27 1 3 C
C
C
C
C
C
C
C
C
3
3 C
+ 2ak + 6 8 (k + k ) + 2ak 2 3 27 1 3 + 2ak 2 3 3 + 2 ak + 2 ak 2 + 5 + 6k ; + 16 9 + 16 9k
C
C
C
C
C
C
3 C
C
C
C
C
C
C
C
C
C
C
which implies (6.7).
Lemma 6.4 The tree T constructed on box B in a round has the following properties: B
(i )
X D
(ii )
2 B
D
L
X D
k k,
2 B
f = O(f + a3 k), and D
L
(iii ) jT j = O((f + a3 k) log a). B
P
Proof : The bound on 2 B k follows, since each vertex in the interior of S lies in thePinterior of at most one box of L . Next, we will use Lemma 6.3 to prove a bound on 2 B f . A similar argument will prove the bound on jT j. D
L
D
B
B
D
L
D
B
23
B Separating Stage
C
}|
z
C
{
Dividing Stage
D } L C | {z } LB Figure 9: The tree T constructed in a round. |
{z
B
Let C be the set of boxes into which B is partitioned by the separating stage. See Figure 9. Let C be a box in C . Lemma 3.1(i) implies that all rectangles in F belong to at most two classes. Hence, by Lemma 6.3, ( 3 ) 3 X + 2 ak + 2 ak ; 1 + 6k ; (6.13) f = 2 + 5 max C
C
D
D
2 C
C
L
C
C
C
C
C
where = (f + ak )=a. The boxes in C correspond to the leaves of a top subtree of T . Therefore, the total number of long rectangles in the boxes associated with the leaves of T is X X X f = f ; B
B
D
By (6.13), this sum is X D
2 B
f
X
D
L
C
2C
2 + 5 C
2 B
D
L
C
2C 2 C D
+ 2ak C
C
3 ! C
D
L
+ 6k
+ 2ak C
C
3 ! C
:
Following the same argumentP as in the proof of Lemma 3.1(iii), weP can show P that We also know that 2C = O(f ) and 2C = O(k). 2C k k and = (f + ak )=a. Therefore, 3 ! X ? f + 2 ak f =O f +k = O f + a3 k : C
C
C
D
2 B L
D
C
C
C
We now present our main result regarding the performance of our improved algorithm:
Theorem 6.5 Given a set S of n rectangles in R such that the aspect ratio ofpeach rectangle in S is bounded by a constant 1, we can construct a BSP of size n2 for S in p 3
O(
time n2
O(
log n )
log n )
. The constants of proportionality in the big-oh terms are linear in log .
24
Proof : We rst bound the size of the BSP constructed by the algorithm. Let S (f; k) denote the maximum size of the BSP produced by the algorithm for a box B that contains f long rectangles and k vertices in its interior. If k = 0, Theorem 3.2 implies that S (f; k) = O(f log f ). For k > 0, by Lemma 6.4(iii), we construct the subtree T on B of size O((f + a3 k ) log a) in one round, and recursively construct subtrees for each box in the set of leaves L . Therefore, there exist constants c1 ; c2 ; c3 > 0 so that the size S (f; k) satis es the following recurrence: 8 c1 f log f for k = 0; > > < (6.14) S (f; k) > X 3 S ( f ; k ) + c ( f + a k ) log a for k > 0 ; 2 > : B
B
D
where
D
2 B
D
L
f + 2ak f +a2ak D
(6.15)
D
for every box D in L (by Lemma 6.1), and B
X
X
k k; D
f c3 (f + a3 k)
(6.16)
D
D
D
(by Lemma 6.4(i) and 6.4(ii)). We now prove that the solution to the above recurrence is p p S (f; k) = f2 log( +2 ) + k2 log( +2 ) ; where r and s are constants linear in log p, with s 2r. It is easy to show that the solution is correct for k = 0, since c1 f log f f 2 log for r log c1 : For k 0, we prove the claim by induction on f + 2ak. Base case:p f + 2ak = 5. In this case, it is easily seen that f = k = 1. Then a = 2 log( + ) = 2. The set S consists of one long rectangle and one short rectangle. In this case, it can be checked (by using Lemma p 2.1) pthat our algorithm constructs a BSP of size at most 10. Hence, S (1; 1) 10 2 log 5 + 2 log 5 , provided that r; s 2. Induction step: f + 2ak > 5. Since f + 2ak < f + 2ak, using the induction hypothesis, we obtain p p X X S (f; k) f 2 log( D +2 D ) + k 2 log( D +2 D ) + c2 (f + a3 k) log a: r
f
k
s
f
B
s
r
D
D
ak
f
r
f
ak
f
r
D
ak
D
D
f
s
ak
D
Using (6.15) and (6.16), ?
p
p
?
S (f; k) c3 f + a3k 2 log(( +2 ) ) + k2 log(( +2 ) ) + c2 f + a3 k log a plog(( +2 ) ) c2 log a c3 + plog(( f 2 +2 ) ) 2 p p 3 c 2 a log a 3 ( ? ) log(( +2 ) ) + c3 a 2 + 1 + plog(( +2 ) ) k2 log(( +2 r
f
ak =a
s
f
r
r
f
r
f
ak =a
ak =a
ak =a
s
f
ak =a
2
s
s
25
f
ak =a
f
ak )=a)
:
If r 9, then it can be checked that 2 choosing s 2r, we obtain
q
S (f; k) (c3 q + c2 )f 2 p = f 2 log( +2 )? log( r
r
f
?
log(f +2ak )
p
r
p
log((f +2ak )=a)
log(f +k )
3
2
+ k2
If r > 4 log (c3 + c2 ), then q
3
q + (c + 1 + c )k2 q p ?
f +k )+log(c2 +c3 )
ak
a . Since a = 2
p
r log(f + 2ak) ? log(f + k) + log (c2 + c3 ) r
log(f +2ak )
s
?
log(f +2ak )
s
p
p
log(f +k )
, by
log(f +k )
log(f +k )+log(1+c2 +c3 )
q
:
p log(f + 2ak ) ? log(f + k ) + 41
p
r log (f + 2ak): Similarly, since s 2r, q
p
p
s log(f + 2ak) ? log(f + k) + log (1 + c2 + c3 ) s log(f + 2ak): Hence,
S (f; k) f2
r
p
log(f +2ak )
+ k2
s
p
log(f +2ak )
;
(6.17)
as desired, provided that r maxflog c1 ; 4 log (c2 + c3 ) ; 9g and s 2r. Lemma 3.1 implies c2 262 and c3 18. As a result, both r and s are linear in log . Since pf n and k 4n at the beginning of the rst round, we get from (6.17) the bound n2 ( log ) on the size of the BSP constructed by the algorithm. We now bound the running time of our algorithm. Recall that we initially sorted the vertices of the rectangles in S by x-, y-, and z -coordinates. Suppose S does not contain a free rectangle. By Lemmas 2.1 and 2.2, the cuts to be made at B can be determined in O(jS j) time. Suppose C is a box obtained by partitioning B according to these cuts; we can easily obtain the sorted order of the vertices of the rectangles in S from the sorted order in B . Let E be the set of boxes obtained by applying C using all the free rectangles in S . Since the free rectangles in S are parallel to each other, we can partition the rectangles in S among the boxes in E in O(jS j) time. Therefore, we can construct the tree representing the ppartition of B into the set of boxes E in O(jS j) time. Hence, we obtain the same n2 ( log ) bound for the running time of the algorithm. O
n
B
B
C
C
C
C
C
B
O
n
Remark: We can modify our algorithm to prove that the height of the BSP constructed
is O(log n): if S contains free rectangles, we assign appropriate weights to the free rectangles, and partition B using the weighted median of the free rectangles. We leave the details to the reader. Paterson and Yao [26] use a similar idea to bound the height of BSP they construct for segments in the plane. B
26
7 Extensions In this section we extend the algorithm of Section 5 to the following three cases: (i) some of the input rectangles are thin, (ii) some of the input polygons are triangles, and (iii) some of the (fat) input rectangles intersect. 7.1
Fat and Thin Rectangles
Let us assume that the input S = F [ T has n rectangles, consisting of m thin rectangles in T and n ? m fat rectangles in F . We rst describe our algorithm and then construct a p set of rectangles for which any BSP has size (n m). The algorithm we use now is very similar to the algorithm for fat rectangles. Given a box B , let f be the number of long rectangles in F , k the number of vertices of rectangles in F that lie in the interior of B , plog( + ) and perform and t the number of rectangles in T . We x the parameter a = 2 the following steps: B
B
f
B
k
1. If S contains a free rectangle, we use the corresponding free cut to split B into two boxes. 2. If k = t = 0, we use the algorithm for long rectangles to construct a BSP for the set of clipped rectangles S . 3. If t (f + k), we use the algorithm by Paterson and Yao for orthogonal rectangles in R3 to construct a BSP for S [27]. 4. If (f + k) > t, we perform one round of the algorithm described in Section 5, with the dierence that we also use thin rectangles to make free cuts. B
B
B
This algorithm is recursively invoked on all the resulting sub-boxes. Let S (f; k; t) be the maximum size of the BSP produced by this algorithm for a box B with k vertices in its interior, f long rectangles in F , and t thin rectangles in T . Note that in Section 6, during the analysis of a round, we did not use the fact that the short rectangles were fat. As a result, Lemmas 6.2 and 6.3 hold for Step 4 above with + k + t replacing the term + k . We can similarly extend Lemma 6.4 to obtain the following recurrence for S (f; k; t). Here D ranges over all the boxes that B is divided into by a round of cuts, as de ned above in Step 4. B
B
C
C
C
C
C
8 > > > > > >
O(f log f );
for k = t = 0;
O(t t);
for t f + k;
p
> X > > > S (fD ; kD ; tD ) + O(f log a + a3 k + a3 t); > : D
27
for f + k > t;
P
P
P
where k k, f + 2ak (f + 2ak)=a, f = O(f + a3 k), and t = O(a3 t). We can analyze this recurrence as in Section 6 and show that its solution is p p p p p S (f; k; t) = f t2 log( + ) + k t2 log( + ) + O(t t); where p and q are positive constants depending on log with q 2p. The following theorem is immediate. D
D
D
D
D
p
f
D
q
k
D
f
D
k
Theorem set of n rectangles in Rp , of pwhich m are thin. A BSP of p 7.1p Let SforbeSa can size n m2 time. The constants of be constructed in n m2 3
O(
O(
log n )
log n )
proportionality in the big-oh terms are linear in log , where is the maximum aspect ratio of the fat rectangles.
Figure 10: Lower bound construction for thin and fat rectangles. We now show that Theorem 7.1 is near-optimal byp constructing a set of n rectangles of which m are thin for which any BSP has size (n m). Recall p that there exists a set of m thin rectangles in R3 for which any BSP has size (m m) [27]. To complete the proof of the lower bound, we now exhibit a set S = T [ F of n rectangles, where T is a set of m thin p rectangles and F is a set of n ? m fat rectangles, for which any BSP has size
((n ? m) m). We rst describe the rectangles in T and then the rectangles in F . We assume without loss of generality that m is an even perfect square and that n is a multiple of m. Consider a unit lattice of size pmp pm in the xz-plane. The points of the lattice have coordinates (i; 0; j ), where 0 i; j < m. On each such lattice point, we erect a segment of 28
p
length n ? m + 5(n ? m)=(2 m) + 1 (perpendicular to the xz -plane) in the +y-direction. p consisting These p m segments constitute T. pWe now construct (n ? m)=(2 m) sets, each by giving the of 2 m squares with side length m + 2 as follows (we specify each square p coordinates of two opposite p p corners of the square): Each set consists of m squares parallel to the xy-plane and m squares parallel to the yz -plane. For 0 k < (n ? m)=(2 m), the kth set contains the set of squares
f[(?1; (2pm + 5)k + 1 ? "; j ? "); (pm + 1; (2pm + 5)k + pm + 3 ? "; j ? ")] j 0 j < pmg
parallel to the xy-plane and the set of squares
f[(i?"; (2pm+5)k +pm+3+"; ?1); (i?"; (2pm+5)k +2pm+5+"; pm+1)] j 0 i < pmg
parallel to the yz -plane, for some suciently small " > 0. Note that in a set, each square parallel to the xy-plane is a distance of 2" from each square parallel to the yz -plane. Further, for any square, the closest square in a dierent set is at a distance of 1 ? 2" and the closest thin rectangle is at a distance of ". p We now prove that any BSP B for S has size ((n ? m) m). Recall that we have de ned the size of B to be the sum of the number of nodes in B and the total number of faces of all dimensions of the rectangles stored at the nodes in B . Thus, it suces to show that the number of proper intersection points between the cutting planes in B and edges of the rectangles p in S (i.e., the number of points at which a cutting plane crosses an edge) is ((n ? m) m). z -axis es er
et y -axis
x-axis
Figure 11: A cube and the rectangles in S it intersects. The edges e ; e and e are drawn in bold. r
s
t
p f(i; (2pm + 5)k + 4; j ) j 0 i; j < pm; 0 k < (n ? m)=(2pm)g:
Consider a cube of side 2" centered at each of the following (n ? m) m=2 points: These cubes do not intersect each other if " is chosen small enough. Each such cube intersects a thin rectangle t of T and two squares r and s of F (one of the squares, say r, is parallel to the xy-plane and the other, s, is parallel to the yz -plane). De ne e to be the edge of the rectangle e \ that lies in the interior of . De ne e and e similarly (since t is a segment, e is just the intersection of t with ). See Figure 11. We claim that at least r
s
t
29
t
one of e ; e , and e must be crossed by a cutting plane of B , which implies that the cutting p planes in B and the edges of the rectangles in S cross at ((n ? m) m) points. Recall that no rectangle in S intersects the interior of the region associated with a leaf of B . But e ; e , and e are contained in the region corresponding to the root of B. Hence, there must be a node v 2 B such that at least one of e ; e , and e is not contained in the interior of R and v has least height among all such nodes. Assume without loss of generality that e is not contained in R . Let u be v's parent. If the cutting plane H intersects e , we are done. Otherwise, e does not intersect the interior of R . If H intersects e , we are done. Otherwise, e lies in the interior of R or is contained in H , i.e., H separates e and e . Then H must intersect e , thus completing the proof. r
r
s
s
t
t
r
s
t
v
r
v
u
r
v
s
u
7.2
v
r
u
u
s
u
r
s
t
Fat rectangles and triangles
Suppose that p polygons in the input S are (non-orthogonal) triangles and that the rest are fat rectangles. To construct a BSP for S , we use non-orthogonal cutting planes; hence, each region is a convex polytope and the intersection of a triangle with a region is a polygon, possibly with more than three edges. We can extend the algorithm of Section 7.1 to this case as follows: In Step 1, we check whether we can make free cuts through the non-orthogonal polygons too. In Step 3, if the number of triangles at a node is greater than the number of fat rectangles, we use the algorithm of Agarwal et. al for triangles in R3 to construct a BSP of size quadratic in the number of triangles in near-quadratic time [1]. Proceeding as in the previous section, we can prove the following theorem:
Theorem 7.2 A BSP of size np2
plog
p
can be constructed in np2 ( log ) time for n 3 objects in R , of which p are non-orthogonal and the rest are fat rectangles. The constants of proportionality in the big-oh terms are linear in log , where is the maximum aspect ratio of the fat rectangles. O(
n)
O
n
Unlike the case of rectangles, the fatness assumption does not help in constructing BSPs of small size for triangles. More speci cally, we can show that there exists a set of n fat triangles in R3 such that any BSP for these triangles has (n2 ) size by modifying Chazelle's construction for proving a quadratic lower bound on the size of convex decompositions of polyhedra in R3 [9]. 7.3
Intersecting fat rectangles
?n
We now consider the case in which the n fat rectangles contain k 2 intersecting pairs. We construct the BSP using the following rather naive approach. For each intersecting pair of rectangles, we partition one of the rectangles in the pair into a constant number of rectangles such that the \smaller" rectangles do not intersect the other rectangle in the pair. This process creates a total of n + O(k) rectangles. Some or all of the \new" O(k) 30
rectangles may be thin. We then use the algorithm of Section 7.1 to construct a BSP for the rectangles. The theorem below follows.
p Theorem 7.3 A BSP of size (n + k) k2
plog
p
p
can be constructed in (n + k) k2 ( log ) time for n rectangles in R3 , which have k intersecting pairs of rectangles. The constants of proportionality in the big-oh terms are linear in log , where is the maximum aspect ratio of the fat rectangles. O(
n)
O
n
We can construct a set S of O(n) rectangles containing k intersecting pairs of rectangles p p so that any BSP for S haspsize (n + k k). Consider a set of 3k = O(n) squares divided into three families of size k=3 each as follows: the squares parallel to the xy-plane belong to the set p f[(0; 0; i); (n; n; i)] j 0 i < k=3g: The squares parallel to the yz - and xz -planes are de ned analogously. Each square in a family intersects all the squares in the other two families. The total number of intersecting pairs of rectangles is kp . Hence, the total number of vertices in the arrangement formed by the squares is (n + k k). By an argument similar to that used to prove the lower bound p in Section 7.1, we can show that any BSP for such a set of squares must contain (n + k k ) p leaves. Hence, any BSP for these squares has size (n + k k). Note that our upper bound is close to the lower bound when k is small.
8 Conclusions Since worst-case complexities of BSPs are very high ( (n3 2 ) for n orthogonal rectangles in R3 ) and all known examples that achieve the worst case use mainly thin rectangles, we have made the natural assumption that rectangles are fat and have shown that this assumption allows smaller worst-case size of BSPs. Note that our algorithm constructs a BSP for any set of orthogonal rectangles; it is only the analysis of the algorithm that depends on the fatness of the input rectangles. We have implemented a variant of our algorithm for fat rectangles and compared its performance to that of other known algorithms presented in the literature [2]. Our algorithm is indeed practical: it constructs a BSP of near-linear size on real data sets. Our algorithm performs better than not only Paterson and Yao's algorithm [27] but also most heuristics described in the literature [4, 17, 31]. p It seems very probable that BSPs of size smaller than n2 ( log ) can be built for n orthogonal rectangles of bounded aspect-ratio in R3 . The only lower bound we have is the trivial (n) bound. It would be interesting to see if it can be shown that simple heuristics (e.g., choose as the next splitting plane the plane that intersects the smallest number of rectangles) construct BSPs of (close to) optimal size. In fact, such heuristics perform =
O
31
n
reasonably well in practice, as our implementation shows [2]. Similar improvements can be envisioned for Theorems 7.1{7.3. We use fatness only at one point during the algorithm|while making -cuts (in Section 3). This fact raises the question of under what weaker models we can still construct BSPs of near-linear size. We showed in Section 7.2 that quadratic lower bounds hold on the size of BSPs for fat triangles. The edges of the triangles used in all such constructions have a linear number of distinct orientations. This observation leads to the question of whether sub-quadratic-size BSPs can be constructed for non-orthogonal objects if their edges have a small number of distinct orientations. In this paper, we have studied the eect of making reasonable assumption on the input on the worst-case size of the BSP, a data structure of primary importance in hidden-surface removal. An even more challenging open problem is determining the right assumptions that should be made about the input objects and the graphics display hardware so that provably fast and practically ecient algorithms can be developed for doing hidden-surface elimination of these objects. A preliminary investigation into an improved model for graphics hardware has been made by Grove et al. [18].
Acknowledgments We would like to thank Seth Teller for providing us with the Soda
Hall dataset created at the Department of Computer Science, University of California at Berkeley. We would also like to thank the Walkthrough Project, Department of Computer Science, University of North Carolina at Chapel Hill for providing us with the datasets for Sitterson Hall, the Orange United Methodist Church Fellowship Hall, and the Sitterson Hall Lobby.
References [1] P. K. Agarwal, L. J. Guibas, T. M. Murali, and J. S. Vitter, Cylindrical static and kinetic binary space partitions, To appear in the 13th Annual Symp. on Comp. Geom., 1997. [2] P. K. Agarwal, T. M. Murali, and J. S. Vitter, Practical methods for constructing binary space partitions for orthogonal objects, To appear in the 13th Annual Symp. on Comp. Geom., 1997. [3] P. K. Agarwal and S. Suri, Surface approximation and geometric partitions, Proc. 5th ACM-SIAM Sympos. Discrete Algorithms, 1994, pp. 24{33. [4] J. M. Airey, Increasing Update Rates in the Building Walkthrough System with Automatic Model-space Subdivision and Potentially Visible Set Calculations, Ph.D. Thesis, Dept. of Computer Science, University of North Carolina, Chapel Hill, 1990. 32
[5] C. Ballieux, Motion planning using binary space partitions, Tech. Rep. inf/src/93-25, Utrecht University, 1993. [6] A. T. Campbell, Modeling Global Diuse Illumination for Image Synthesis, Ph.D. Thesis, Dept. of Computer Sciences, University of Texas, Austin, 1991. [7] T. Cassen, K. R. Subramanian, and Z. Michalewicz, Near-optimal construction of partitioning trees by evolutionary techniques, Proc. of Graphics Interface '95, 1995, pp. 263{271. [8] E. Catmull, A Subdivision Algorithm for Computer Display of Curved Surfaces, Ph.D. Thesis, Computer Science Dept., University of Utah, Salt Lake City, 1974. [9] B. Chazelle, Convex partitions of polyhedra: a lower bound and worst-case optimal algorithm, SIAM J. Comput., 13 (1984), 488{507. [10] N. Chin and S. Feiner, Near real-time shadow generation using BSP trees, Proc. SIGGRAPH '89, Comput. Graph., Vol. 23, ACM SIGGRAPH, 1989, pp. 99{106. [11] N. Chin and S. Feiner, Fast object-precision shadow generation for areal light sources using BSP trees, Comput. Graph. (Proc. 1992 Symp. on Interactive 3D Graphics), Vol. 25, 1992, pp. 21{30. [12] Y. Chrysanthou, Shadow Computation for 3D Interaction and Animation, Ph.D. Thesis, Queen Mary and West eld College, University of London, 1996. [13] M. de Berg, Linear size binary space partitions for fat objects, Proc. Third Europ. Symp. on Algorithms, LNCS 979, Springer-Verlag, September 1995, pp. 252{263. [14] S. E. Dorward, A survey of object-space hidden surface removal, Internat. J. Comput. Geom. Appl., 4 (1994), 325{362. [15] J. D. Foley, A. van Dam, S. K. Feiner, and J. F. Hughes, Computer Graphics: Principles and Practice, Addison-Wesley, Reading, MA, 1990. [16] H. Fuchs, Z. M. Kedem, and B. Naylor, On visible surface generation by a priori tree structures, Proc. SIGGRAPH '80, Comput. Graph., Vol. 14, ACM SIGGRAPH, 1980, pp. 124{133. [17] H. Fuchs, Z. M. Kedem, and B. Naylor, On visible surface generation by a priori tree structures, Comput. Graph., 14 (1980), 124{133. Proc. SIGGRAPH '80. [18] E. F. Grove, T. M. Murali, and J. S. Vitter, The object complexity model for hiddensurface elimination, Proc. 7th Canad. Conf. Comput. Geom., 1995, pp. 273{278. [19] C. Mata and J. S. Mitchell, Approximation algorithms for geometric tour and network design problems, Proc. 11th Annu. ACM Sympos. Comput. Geom., 1995, pp. 360{369. 33
[20] T. M. Murali and T. A. Funkhouser, Consistent solid and boundary representations from arbitrary polygonal data, Proc. 1997 Symp. on Interactive 3D Graphics (to appear), 1997. [21] B. Naylor, Constructing good partitioning trees, Proc. Graphics Interface '93, 1993, pp. 181{191. [22] B. Naylor and W. Thibault, Application of BSP trees to ray-tracing and CSG evaluation, Technical Report GIT-ICS 86/03, Georgia Institute of Tech., School of Information and Computer Science, 1986. [23] B. F. Naylor, SCULPT: an interactive solid modeling tool, Proc. Graphics Interface '90, 1990, pp. 138{148. [24] B. F. Naylor, Interactive solid geometry via partitioning trees, Proc. Graphics Interface '92, 1992, pp. 11{18. [25] B. F. Naylor, J. Amanatides, and W. C. Thibault, Merging BSP trees yields polyhedral set operations, Proc. SIGGRAPH '90, Comput. Graph., Vol. 24, ACM SIGGRAPH, 1990, pp. 115{124. [26] M. S. Paterson and F. F. Yao, Ecient binary space partitions for hidden-surface removal and solid modeling, Discrete Comput. Geom., 5 (1990), 485{503. [27] M. S. Paterson and F. F. Yao, Optimal binary space partitions for orthogonal objects, J. Algorithms, 13 (1992), 99{113. [28] R. A. Schumacker, R. Brand, M. Gilliland, and W. Sharp, Study for applying computergenerated images to visual simulation, Tech. Rep. AFHRL{TR{69{14, U.S. Air Force Human Resources Laboratory, 1969. [29] I. E. Sutherland, R. F. Sproull, and R. A. Schumacker, A characterization of ten hidden-surface algorithms, ACM Comput. Surv., 6 (1974), 1{55. [30] S. J. Teller, Visibility Computations in Densely Occluded Polyhedral Environments, Ph.D. Thesis, Dept. of Computer Science, University of California, Berkeley, 1992. [31] W. C. Thibault and B. F. Naylor, Set operations on polyhedra using binary space partitioning trees, Proc. SIGGRAPH '87, Comput. Graph., Vol. 21, ACM SIGGRAPH, 1987, pp. 153{162. [32] E. Torres, Optimization of the binary space partition algorithm (BSP) for the visualization of dynamic scenes, Eurographics '90, North-Holland, 1990, pp. 507{518.
34