Approximate range searching using binary space partitions
Full text
Approximate Range Searhing Using Binary Spae Partitions Mark de Berg a and Miha Strepp el a ; 1 , a Department of Computer Siene, TU Eindhoven, P.O.Box 513, 5600 MB Eindhoven, the Netherlands. 1. Intro dution Multi-funtional data strutures and BSP trees. In omputational geometry, eÆient data stru- tures have been develop ed for a variety of geometri query problems: range searhing, p oint lo ation, nearest-neighb or searhing, et. The theoretial performane of these strutures is often lose to the theoretial lower bounds. In order to ahieve lose to optimal performane, most strutures are dediated to very spei settings. It would be preferable, however, to have a single multi-funtional geometri data struture : a data struture that an store dierent typ es of data and answer various typ es of queries. Indeed, this is what is often done in pratie. Another p otential problem with the strutures develop ed in omputational geometry is that they are sometimes rather involved, and that it is un- lear how large the onstant fators in the query time and storage osts are. Moreover, they may fail to take advantage of the ases where the input ob jets and/or the query have some nie prop erties. Hene, the ideal would b e to have a multifuntional data struture that is simple and takes advantage of any favorable prop erties of the input and/or query. A binary spae partition tree , or BSP tree , is a spae-partitioning struture where the sub division of the underlying spae is done in a hierarhial fashion using hyp erplanes (that is, lines in ase the spae is 2D, planes in 3D, et.) The hierarhi- al sub division pro ess usually ontinues until eah ell ontains at most one (or mayb e a small number of ) input ob jet(s). BSP trees are used for many purp oses; among these are range searhing [1℄ and Email addresses: m.t.d.bergtue.nl (Mark de Berg), m.w.a.streppeltue.nl (Miha Strepp el). 1 MS is supp orted by the Netherlands Organisation for Sienti Researh (N.W.O.) under pro jet no. 612.065.203. hidden surfae removal with the painter's algorithm [11℄. In some appliations|hidden-surfae removal is a typial example|the eÆieny is determined by the size of the BSP tree. Hene, several researhers have prop osed algorithms to onstrut small BSP trees in various dierent settings [2,5,13,15℄. In this pap er we fo us on the query omplexity of BSP trees. Approximate range searhing. Developing a multi-funtional geometri data struture|one that an store any typ e of ob jet and an do range searhing with any typ e of query range|that provably has goo d p erformane seems quite hard, if not impossible. As it turns out, however, suh results an b e ahieved if one is willing to settle for " -approximate range searhing , as intro dued by Arya and Mount [3℄. Here one onsiders, for a parameter " > 0, the " - extended query range Q " , whih is the set of p oints lying at distane at most · diam( Q ) from Q , where diam( Q ) is the diameter of Q . Ob jets interseting Q must b e rep orted, while ob jets interseting Q " (but not Q ) may or may not be rep orted; ob jets outside Q " are not allowed to b e rep orted. In pra- tie, one would expet that for small values of " , not to o many extra ob jets are rep orted. Our results. In this pap er we show that it is p ossible to onstrut BSP trees for sets of disjoint segments in the plane, and for low-density senes in any dimension, whose query time for approximate range searhing is as go o d, or almost as go o d, as the best known b ounds for p oint data [3,8,9℄. More preisely, our results are as follows. In Setion 3 we study BSP trees for a set S of n disjoint line segments in the plane. We give a general tehnique to onvert a BSP tree T p for a set of p oints to a BSP tree T S for S , suh that the size of T S is O ( n · depth( T p )), and the time for range searhing remains almost the same. In Setion 4 we then onsider low-density senes. 20th EWCG Seville, Spain (2004)
20th Europ ean Workshop on Computational Geometry We prove that any sene of onstant density in R d admits a BSP of linear size, suh that rangesearhing queries with arbitrary onvex ranges an b e answered in O (log n + min "> 0 { (1 =" d − 1 ) + k " } ), where k " is the numb er of ob jets interseting Q " . 2. Preliminaries In this setion we briey intro due some terminology and notation that we will use throughout the pap er. A BSP tree for a set S of n ob jets in R d is a binary tree T with the following properties. { Every (internal or leaf ) node orresp onds to a subset region( ) of R d , whih we all the region of . These regions are not stored with the no des. When is a leaf node, we sometimes refer to region( ) as a el l . The ro ot no de ro ot( T ) orresp onds to R d . { Every internal no de stores a hyperplane h ( ). The left hild of then orresp onds to region( ) ∩ h ( ) − , where h ( ) − denotes the half-spae b elow h ( ), and the right hild orresp onds to region( ) ∩ h ( ) + , where h ( ) + is the half-spae ab ove h ( ). A no de stores, b esides the splitting hyperplane h ( ), a list L ( ) with all ob jets ontained in h ( ) that interset region( ). { Every leaf no de stores a list L ( ) of all ob jets in S interseting the interior of region( ). In our ase the lists have a onstant length. The size of a BSP tree is dened as the total numb er of nodes plus the total size of the lists L ( ) over all no des in T . Finally, for a no de in a tree T , we use T ( ) to denote the subtree of T ro oted at , and we use depth( T ) to denote the depth of T . 3. BSPs for segments in the plane Let S b e a set of n disjoint line segments in the plane. In this setion we desribe a general tehnique to onstrut a BSP for S , based on a BSP on the endp oints of S . The tehnique uses a segmenttree like approah similar to, but more general than, the deterministi BSP onstrution of Paterson and Yao [13℄. The range-searhing struture of Overmars et al.[12℄ uses similar ideas, exept that they store so-alled long segments|see b elow|in h(ν)h(ν) a) b) h(µ) Figure 1. Illustration of the pruning strategy. The blak squares indiate input segments. a) There is a T-juntion on h ( ): a splitting line in the subtree ends on h ( ). Pruning h ( ) would partition the empty part of the region, whih might have a negative eet on the query time. b) There is no T-juntion on h ( ) and h ( ) an be pruned. an asso iated struture, so they do not onstrut a BSP for the segments. The main extra ompliation we fae is that we must ensure that we only work with the relevant p ortions of the given tree during the reursive onstrution, and prune away irrelevant p ortions. The pruning has to b e done arefully, however, beause to o muh pruning an have a negative eet on the query time. Next we desrib e the onstrution in more detail. Let P b e the set of 2 n endp oints of the segments in S , and let T P b e a BSP tree for P . We assume that T P has size O ( n ), and that the leaves of T P store at most one point from P . Below we desrib e the global onstrution of the BSP tree for S . Some details of the onstrution will be omitted here. The BSP tree T S for S is onstruted reursively from T P , as follows. Let b e a no de in T P . We all a segment s ∈ S short at if region( ) ontains an endp oint of s . A segment s is alled long at if (i) s intersets the interior of region( ), and (ii) s is short at parent( ) but not at . In a reursive all there are two parameters: a no de ∈ T P and a subset S ∗⊂ S , lipp ed to lie within region( ). The reursive all will onstrut a BSP tree T S ∗ for S ∗ based on T P ( ). Initially, = root( T P ) and S ∗ = S . The reursion stops when S ∗ is empty, in whih ase T S ∗ is a single leaf. Let L ⊂ S ∗ b e the set of segments from S ∗ that are long at . The reursive all is handled as follows. (i) If L is empty, we ompute S l = S ∗∩ h ( ) − and S r = S ∗∩ h ( ) + . If both S l and S r are non-empty, we reate a ro ot no de for T S ∗ whih stores h ( ) as
Marh 25-26, 2004 Seville (Spain) its splitting line. We then reurse on the left hild of with S l and on the right hild of with S r to onstrut resp etively the left and the right subtree of the root. If one of S l and S r is empty, it seems the splitting line h ( ) is useless in T S ∗ . We have to b e areful, however, that we do not in- rease the query time: the removal of h ( ) an ause other splitting lines, whih used to end on h ( ), to extend further. Hene, we pro- eed as follows. Dene a T-juntion , see Fig. 1, to be a vertex of the original BSP subdivision indued by T P . To deide whether or not to use h ( ), we hek if h ( ) ∩ R ontains a T-juntion in its interior, where R is the region that orresp onds to the root of T S ∗ . If this is the ase, we do not prune. (ii) The seond ase is when L is not empty. Now the long segments partition r eg ion ( ) into m := | L | + 1 regions, R 1 ;:::;R m . We take the following steps. (i) We split S ∗\ L into m subsets S ∗ 1 ;:::;S ∗ m , where S ∗ i ontains the segments from S ∗ lying inside R i . (ii) We onstrut a binary tree T with m − 1 internal no des whose splitting lines are the lines ontaining the long segments. The leaves of T orresp ond to the regions R i , and will b eome the ro ots of the subtrees to b e reated for the sets S ∗ i . T is balaned by the sizes of the sets S ∗ i , as in the trap ezoid metho d for p oint lo ation [14℄. The tree T S ∗ then onsists of the tree T , with, for every 1 ⩽ i ⩽ m , the leaf of T orresp onding to R i replaed by a subtree for S ∗ i . More preisely, eah subtree T i is onstruted using a reursive all with node and S ∗ i as parameters. The following theorem states the p erformane of the BSP. Its pro of is omitted in this extended abstrat. Theorem 1 Let R be a family of onstant- omplexity query ranges in R 2 . Suppose that for any set P of n points in R 2 , there is a BSP tree T P of linear size, where eah leaf stores at most one point from P , with the fol lowing property: any query with a range from R intersets at most v ( n; k ) el ls in the BSP subdivision, where k is the number of points in the query range. Then for any set S of n disjoint segments in R 2 , there is a BSP tree T S suh that (i) the depth of T S is O ( depth ( T P )) (ii) the size of T S is O ( n · depth ( T P )) (iii) any query with a range from R visits at most O (( v ( n; k ) + k ) · depth ( T P )) nodes from T S , where k is the number of segments interseting the range. The BSP tree T S an be onstruted in O ( n · ( depth ( T P )) 2 ) time. Several of the known data strutures for range searhing in p oint sets are atually BSP trees. Examples are ham-sandwih trees [10℄, kd-trees [7℄, and BAR-trees [8,9℄. Here we fo us on the appliation using BAR-trees, as it gives goo d b ounds for approximate range searhing for line segments in the plane. One an onstrut BAR-trees with logarithmi depth, suh that the numb er of leaves visited by a query with a onvex query range Q is b ounded by O ((1 =" ) + k " ), where k " is the numb er of p oints inside the extended query range Q " . Combining this with theorem 1 (and a sp eialized onstrution algorithm that speeds up the onstrution time by a logarithmi fator) we get the following results. Corollary 2 Let S be a set of n disjoint segments in R 2 . In O ( n log n ) time one an onstrut a BSP tree for S of size O ( n log n ) and depth O (log n ) suh that a range query with a onstant- omplexity onvex range an be answered in time O (min "> 0 { (1 =" ) log n + k " log n } ) , where k " is the number of segments interseting Q " . 4. BSPs for low-density senes Let S b e a set of n ob jets R d . For an ob jet o , we use ( o ) to denote the radius of the smallest enlosing ball of o . The density of a set S is the smallest numb er suh that the following holds: any ball B is interseted by at most ob jets o ∈ S with ( o ) ⩾ ( B ) [6℄. If S has density , we all S a -low-density sene. In this setion we show how to onstrut a BSP tree for S that has linear size and very goo d p erformane for approximate range searhing if the density of S is onstant. Our metho d ombines ideas from de Berg [5℄ with the BAR-tree of Dunan et al.[9℄ Our overall strategy, also used by de Berg [5℄, is to ompute a suitable
20th Europ ean Workshop on Computational Geometry set of p oints that will guide the onstrution of the BSP tree. Unlike in [5℄, however, we annot use the b ounding-b ox verties of the ob jets in S for this, b eause that does not work in ombination with a BAR-tree. What we need is a set G of p oints with the following property: any ell in a BAR-tree that do es not ontain a p oint from G in its interior is interseted by at most ob jets from S , for some onstant . We all suh a set G a -guarding set [4℄ against BAR-tree ells, and we all the p oints in G guards . The algorithm is as follows. (i) Construt a -guarding set G for S , as explained b elow. The onstrution of the guarding set is done by generating O (1) guards for eah ob jet o ∈ S , so that the guards reated for any subset of the ob jets will form a -guarding set for that subset. Using the results of [4℄ it an be shown that there exists a guarding set for -low-density senes against BAR-tree ells. Using sp eial prop erties of (orner-ut) BAR-tree ells a guarding set of size 12 n an b e given for the planar ase. We will use ob jet( g ) to denote the ob jet for whih a guard g ∈ G was reated. (ii) Create a BAR-tree T on the set G using the algorithm of Dunan et al.[9℄, with the following adaptation: whenever a reursively all is made with a subset G ∗⊂ G in a region R , we delete all guards g from G ∗ for whih ob jet( g ) do es not interset R . This pruning step, whih was not needed in [5℄, is essential to guarantee a b ound on the query time. This leads to a BSP tree whose ells an only ontain guards whose orresp onding ob jets do not interset the ell. (iii) Searh with eah ob jet o ∈ S in T to determine whih leaf ells are interseted by o . Store with eah leaf the set of all interseted ob jets. Let T S b e the resulting BSP tree. The following theorem states the p erformane of the BSP. Its pro of is omitted in this extended abstrat. Theorem 3 Let S be a -low-density sene onsisting of n objets in R d . There exists a BSP tree T S for S suh that (i) the depth of T S is O (log n ) (ii) the size is O ( n ) (iii) a query range with a onvex range Q visits takes O (log n + · min "> 0 { (1 =" ) + k " } ) time, where k " is the number of objets interseting the extended query range Q " . The BSP tree an be onstruted in O ( n log n ) time. Referenes [1℄ P.K. Agarwal and J. Erikson. Geometri range searhing and its relatives. In: B. Chazelle, J. Go o dman, and R. Pollak (Eds.), Advanes in Disrete and Computational Geometry , Vol. 223 of Contemporary Mathematis , pages 1{56, Amerian Mathematial So iety, 1998. [2℄ P.K. Agarwal, E. Grove, T.M. Murali and J.S. Vitter. Binary spae partitions for fat retangles. SIAM J. Comput. 29:1422-1448, 2000. [3℄ A. Arya, D. Mount, Approximate range searhing, Comput. Geom. Theory Appl. 17 (2000) 135{152. [4℄ M. de Berg, H. David, M. J. Katz, M. Overmars, A. F. van der Stapp en, and J. Vleugels. Guarding senes against invasive hyperub es. Comput. Geom. , 26:99{ 117, 2003. [5℄ M. de Berg. Linear size binary spae partitions for unluttered senes. Algorithmia 28:353{366, 2000. [6℄ M. de Berg, M.J. Katz, A. F. van der Stapp en, and J. Vleugels. Realisti input mo dels for geometri algorithms. In Pro. 13th Annu. ACM Sympos. Comput. Geom. , pages 294{303, 1997. [7℄ M. de Berg, M. van Kreveld, M. Overmars, and O. Cheong. Computational Geometry: Algorithms and Appliations . Springer-Verlag, 1997. [8℄ C.A. Dunan, Balaned Aspet Ratio Trees, Ph.D. Thesis, John Hopkins University, 1999. [9℄ C.A. Dunan, M.T. Go o drih, S.G. Kob ourov, Balaned asp et ratio trees: Combining the advantages of k-d trees and o trees, In Pro. 10th Ann. ACMSIAM Sympos. Disrete Algorithms , pages 300{309, 1999. [10℄ H. Edelsbrunner. Algorithms in Combinatorial Geometry . Springer-Verlag, 1987. [11℄ H. Fuhs, Z. M. Kedem, and B. Naylor. On visible surfae generation by a priori tree strutures. Comput. Graph. , 14(3):124{133, 1980. Pro . SIGGRAPH '80. [12℄ M.H. Overmars, H. Shipp er, and M. Sharir. Storing line segments in partition trees. BIT , 30:385{403, 1990 [13℄ M. S. Paterson and F. F. Yao. EÆient binary spae partitions for hidden-surfae removal and solid mo deling. Disrete Comput. Geom. , 5:485{503, 1990. [14℄ F.P. Preparata and M.I. Shamos. Computational Geometry: An Introdution. Springer-Verlag, 1985. [15℄ C.D. Toth. Binary Spae Partitions for Line Segments with a Limited Number of Diretions. SIAM J. Comput. 32:307{325, 2003.