COMPUTER TECHNOLOGY INSTITUTE
1999
________________________________________________________________________________
____________________________________________________________________________________
TECHNICAL REPORT No. TR.
99/09/04
1
Abstract
We consider the following problem as defined by Grove et al. [GMV99]: Given a set of n
isothetic rectangles in 3D space determine the subset of rectangles that are not completely
hidden. We present optimal algorithm
s for this problem that run in
O(nlogn)
time and
O(n)
space. Our results are improvements over the one of Grove et al. by a logarithmic factor in
storage and one of them is achieved by using a different approach. An analogous approach
gives non

trivial sol
utions for other kinds of objects too.
Keywords:
Computational geometry, computer graphics, object complexity, hidden surface
removal, segment tree.
TECHNICAL REPORT No. TR.99/09/04
“ Optimal Algorithms for reporting visible rectangles ”
N. Kitsios, C. Makris, S. Sioutas, A. Tsakalidis, J. Tsaknakis and B. Vassiliadis
14/10/99
COMPUTER TECHNOLOGY INSTITUTE
1999
________________________________________________________________________________
____________________________________________________________________________________
TECHNICAL REPORT No. TR.
99/09/04
2
1. Introduction
A ubiquitous task in computer graphics is that of rendering scenes of obje
cts in 3D space. Part of
this task is, given a viewing position, to determine the portions of the objects that are visible from
the viewing position, in order only these to be displayed on the screen. This problem is commonly
known as hidden surface remova
l or hidden line elimination depending on whether the displayed
parts are surface patches or line segments. There are two main approaches to the problem: image
space and object space. In the first approach, which do computer graphics algorithms implement,
the projections of the objects on the screen are treated as raster images (i.e. images composed by
pixels). As a consequence their output is a raster image too, and their running times depend on the
raster size (screen resolution). On the other hand, algor
ithms in computational geometry treat the
projections of the objects as vector images. Their output is a graph, called the visibility map,
whose edges are visible segments of object’s edges and whose vertices are visible vertices or cross
points of visible
edges. Their running times depend on the size of the visibility map.
Although there are certain advantages in using object space solutions like precise scaling of
images without loss in detail, in practice image space algorithms have proved to be more
suc
cessful because they can be efficiently implemented in hardware. An attempt to combine the
two approaches is the object complexity model, introduced by Grove et al. in [GMV99]. In this
model the hidden surface removal problem is solved in two steps. In the
first step the subset of
objects that are not completely obscured by other objects is determined using object space
methods. The size of this subset is called the object complexity of the scene, denoted q. In the
second step an image space algorithm (like
the z

buffer) is applied on this subset of objects only.
Because of the first step, a significant speed up is expected in the execution of the image space
algorithm. The challenge in this approach is to develop algorithms for the first step whose time
can
be bounded by a function of the object complexity q and the input size n. Standard object

space algorithms are inefficient for this purpose because their running times are lower bounded by
the visibility map size k, which can be
Θ
(q
2
).
This approach can be efficiently realised for the window

rendering problem as shown in
[GMV99]. This is the problem of displaying on a screen the contents (text, images) of a set of n
rectilinear windows which may partially overlap and for which a p
recedence order is known. It is
easy to rephrase this as a hidden surface removal problem in which the objects are rectangles with
sides parallel to the x

,y

axes. For the standard hidden surface problem the best solutions [B90,
GAO90, MNU90] run in
O((n
+ k)logn)
time and
O(nlogn)
storage. The storage can be reduced to
O(n)
by a simple technique as shown in [KT96]. By modifying appropriately the algorithm of
Bern [B90], Grove et al. showed that the object complexity version of the problem can be solved
in
optimal
O(nlogn)
time and
O(nlogn)
storage.
In this paper we present two new space and time optimal algorithm for the problem. The fist
solution abstracts the base features of the plane sweep algorithm of Grove et al. and using an idea
similar to [KT96] a
chieves optimal space and time performance. The proposed algorithm although
following initially the partitioning trick
of [KT96], is different and works independently of the
specific query process. The result is based on an interesting observation for fas
t preprocessing of a
segment tree. We believe that this observation and its generalization can find applications in other
problems too. The second solution is based on the approach of [GAO90], is entirely different from
the algorithm of [GMV99], and it can
be extended to handle other kinds of objects too. The
proposed algorithm appears to be conceptually more appealing from the first solution, and it is
easy to implement. An advantage of this algorithm compared with the first solution is that it
requires a
much simpler version of the linear time Union

Find algorithm of [GT84].
COMPUTER TECHNOLOGY INSTITUTE
1999
________________________________________________________________________________
____________________________________________________________________________________
TECHNICAL REPORT No. TR.
99/09/04
3
2. The first algorithm
The first subsection provides a description of the algorithm in [GMV99]. The description is a
little abstract in order to emphasize the generality of our
technique. Then under this abstract
description we describe our linear time and space solution. The final subsection generalizes our
approach.
2.1. The algorithm of [GMV99]
Let S be a set of n horizontal rectangles in three dimensional space with sides p
arallel to the x

and y

axes and assume that the observer is at the point z=+
⸠Weca汬瑨攠e摧e猠瑨a琠are灡ra汬e氠
瑯t瑨攠y

a楳i癥牴楣a氠an搠瑨攠e摧猠瑨慴ta牥 灡ra汬e氠瑯t瑨攠

a楳i桯物z潮瑡氮oWe ca渠灵琠瑨t
[䝍G㤹9汧潲楴桭⁵
湤n爠瑨r潬汯睩ga浥mo牫r
Step 1.
Construct an initial empty segment tree T where the leaves correspond to the distinct y

coordinates of the projections of the rectangles on the y

axis.
Step 2.
Perform a space sweep by moving a plane parallel to the y
z plane along the x

axis. The
stations of the sweep are the distinct x

coordinates of the vertical edges of the rectangles in S.
Whenever a point

station is met, a query algorithm is performed on the segment tree and the y

projection of the corresponding v
ertical edge is inserted (deleted) from the segment tree, if it is the
left (right) vertical edge of a rectangle. Let v be a node of T and let S
v
be the set of the segments
stored in v. S
v
is organized in a heap data structure based on the order of the rec
tangles along the
z

axis, such that the topmost segment in S
v
can be accessed in constant time. Designate this
segment by top(S
v
). Along with v the values of a constant number of functions f
i
(v), i=1,..c, are
stored. Each such function is completely define
d by top(S
v
), top(S
u
), top(S
w
), f
i
(u), f
i
(w), where
u,w are the left and right sons of v respectively. These functions are used for the query algorithm
and their values are recomputed if necessary during each insertion and deletion. We should remark
here t
hat from the restrictions on f
i
() and the definition of the segment tree the recomputation of
the function values for each sweep station, during an insertion or deletion, costs O(logn), since the
nodes whose function values may be affected are nodes or son
s of nodes that belong to two paths
of T (these paths are the paths in T to the y

coordinates of the points that delimit the segment to
be inserted or deleted).
It is clear from the above description that at any sweep station we only need to know the valu
es
of the top(S
v
) lists, since with these values in hand we can compute the valued of the associated
functions and so perform correctly the query process. This observation leads to the following
modified framework (see also [B90, MNU90]):
Step 1
. Compute
for each node v of the segment tree T a list of values of top(S
v
). Each entry in
the list is accociated with a list of sweep stations for which is valid.
Step 2.
This step is an exact simulation of the initial algorithm except that no insertions and
delet
ions of segments are made and whenever the value at the top of a heap is needed (for the
query algorithm or for the recomputation of the auxiliary functions), the correct value is taken
from the corresponding list.
Examining the modified algorithm (in the
light of [B90,MNU90,GMV99]) it follows that step 1
runs in O(nlogn) time and since each rectangle can be stored at O(logn) nodes needs O(nlogn)
space. Consider now step 2. As it was argued before, the computation of the changed function
values for each sw
eep station costs O(logn). So, if we let Q(i) be the query time for the i

th
sweep station we have that the time cost of step 2 is O(nlogn)+
n
i
i
Q
2
1
)
(
while the space is
COMPUTER TECHNOLOGY INSTITUTE
1999
________________________________________________________________________________
____________________________________________________________________________________
TECHNICAL REPORT No. TR.
99/09/04
4
O(nlogn). So we have an overall running time of O(nlogn)+
n
i
i
Q
2
1
)
(
time and a space usage of
O(nlogn).
2.2. The improved algorithm.
The new algorithm, following the [KT96] partitioning, divides the stations of the sweep in
O(logn) slabs and processes each slab sequentially. At any sweep station the segment tree
stores
information only for the current slab.
The algorithm can be described as follows:
Stage 1.
Sort the rectangles in S according to their z

coordinate and sort the x

, y

coordinates of
the projection of the rectangles on the x

and y

axes. Construct
an initially empty segment tree T
where the leaves correspond to the distinct y

coordinates of the projections of the rectangles on the
y

axis.
Stage 2.
Divide the O(n) stations of the sweep into O(logn) groups G
i
, i=1...,k. Each group
consists of O(n/
logn) consecutive sweep stations. Let x
i
f
, x
i
l
the x

coordinates of the first and last
sweep station belonging to G
i
. Then we can consider that the group G
i
defines a slab Ð
i
in space
delimited by the planes x=(x
i

1
l
+x
i
f
)/2 and x=(x
i
l
+x
i+1
f
)/2.
Stage 3.
F
or i=1,...,k
begin
Process 1
. Compute for each node v of the segment tree T a list of values of top(S
v
). Each entry in
the list has a list of sweep stations in G
i
for which is valid
Process 2.
Sweep along the sweep stations
in Ð
i
and apply the query algorithm for each station.
Whenever the value of Top(S
v
) is needed take it from the corresponding list
Process 3
. Empty all the information from T
end.
Before proceeding to the time and space
analysis we prove a lemma that is crucial for our
computations:
Lemma 1:
Let S be a set of O(n) non

intersecting segments in the yz

plane, parallel to the y

axis
and with y

coordinates taken from the universe U={y
1
,y
2
,...,y
n
} and let T be an initially
empty
segment tree build on the universe U. Assume that S is given in ordered z

order and for each
endpoint of a segment in S we have a pointer to the leaf in T where the search for the y

coordinate
of this point would end. Then in O(n) time and space we
can find for each node v of T the topmost
segment in S that would be stored in v.
Proof:
Using the terminology of [BJM94] call a node v of T the upper left relative of a node w of
T, if v is the left child of some node z and w lies on the left spine of
the subtree rooted at the right
child of z. If the symmetric situation holds (that is v is the right child of some node z and w lies on
the right spine of the subtree rooted at the left child of z), then call it the upper right relative of w.
We will als
o simply say that the nodes v and w are related.
First, connect each node v of T by two double pointer with its upper right and left relatives. This
task can be easily performed done in O(n) time by two traversals of T.
COMPUTER TECHNOLOGY INSTITUTE
1999
________________________________________________________________________________
____________________________________________________________________________________
TECHNICAL REPORT No. TR.
99/09/04
5
The basic observation is that since each node has a unique upper right and a unique upper left
relative then, by following the pointers connecting the relative nodes, we can in
O(n) time and
space extract from T two forests F
l
, F
r
of vertex disjoint trees (see figure 1). The nodes in the trees
of F
r
are connected by upper right relative pointer and the nodes in the trees in F
l
are connected by
upper left relative pointers. F
l
an
d F
r
can be converted to two trees L, R by connecting the roots of
their components with a dummy node l, r respectively. In [BJM94] it was noted that each segment
s is stored in T in two sequence of nodes such that neighboring nodes in both sequences are
r
elated. The first sequence S
1
is consisting from upper right related nodes beginning from the leaf
storing the left endpoint of S and the second sequence S
2
is consisting from upper left related
nodes beginning from the leaf storing the right endpoint of S
. In other words the nodes in which s
is stored constitute two subpaths one in R (sequence S
1
) and one in L (sequence S
2
). Since for each
s in S we know the leaves in T to which its endpoints correspond, the first node on each subpath
can be found in O(1)
time. The last node in the two subpaths is the first node whose parent has
range that is not contained in the range of s (according to the segment tree definition).
Then the algorithm is the following:
Process the segments in S in decreasing z

order. Let
S'
S扥瑨攠獥琠潦o獥杭敮瑳g灲潣e獳敤s獯sar
a湤n汥琠猠扥瑨攠c畲e湴n獥gme湴⸠F潬o潷o瑨攠瑷漠獵扰s瑨猠楮iLa湤nR瑨慴tc潲oe獰潮搠瑯t瑨攠n潤os
of T in which s would be stored and if any node is found which doesn’t store any segmen
t of S'
then mark it and store s to v. Since all these operations can be simulated by a sequence of O(n)
unions and finds in which the structure of the unions is given (L and R are the union trees) it
follows that the whole process can be done in O(n) time
.
We elaborate more at this point, in order to establish the correctness of our argument. Consider
without loss of generality the tree L. Initially every node v of L is a singleton set {v} named v.
The parent of v in L is denoted by p(v). On the sets ind
uced by the nodes of L we will perform a
sequence of operations:
find(x)
= return the name of the set containing x, and
v
1
v
2
v
1
v
2
(a)
T
he initial tree, the dotted edges are
upward related pointers
(b) The forest F
r
, if we connect v
1
,v
2
with a dummy
node we get tree R.
figure 1
COMPUTER TECHNOLOGY INSTITUTE
1999
________________________________________________________________________________
____________________________________________________________________________________
TECHNICAL REPORT No. TR.
99/09/04
6
link(x)=
create a new set that will be the union of the sets containing p(x) and x, with the name
of the new set being the name of the
old set containing p(x).
In [GT85] it was shown that an intermixed sequence of m find and link operations on n elements
structured in this way can be performed in O(m+n) time and O(n) space.
Suppose now that the segment s[s
l
,s
r
] is to be processed. Then
the operations we need to perform
are given by the following piece of code:
1.
Let x be the node in L corresponding to the leaf of T storing the elementary interval [
s
l
,s
l
]
2.
stop:=false;
3.
while not stop do
4.
x:=find(x);
5.
if range(x)
[s
l
,s
r
] then stop:=true;
6.
else {top(S
x
):=s; link(x);}
7.
od.
It is easily seen that: (1)links
nodes of L; and (2) finds
S+links.
From (1), (2) m=O(n), and the whole processing of the segments in S takes O(n) time. Finally,
the space is O
(n), since each node v stores only one segment which clearly is the topmost of the
segments that would be stored in v.
˜
Proceeding now to the analysis of the algorithm Stages 1,2 can be clearly performed in O(nlogn)
time and O(n) s
pace. Consider now stage 3, and assume that we are in the for loop and we want to
perform processes 1,2,3 for the slab Ð
i
Lemma 2:
Process 1 can be performed in O(n) time and O(n) space
.
Proof:
Let S
i
be the set of rectangles that belong to S and affect t
he visibility in the slab Ð
i
. The
set S
i
is the union of two disjoint sets S
f
i
, S
c
i
where S
f
i
is the set of rectangles that span Ð
i
, and S
c
i
are the set of rectangles who have at least one vertical edge in Ð
i
. It is clear that the x

coordinates
of the edg
es of the rectangles of S
c
i
that are in Ð
i
are the point stations belonging to G
i
. Note also
that S
f
i
=O(n) and S
c
i
=O(n/logn). We proceed in two phases, the first phase takes care of the
rectangles in S
r
i and the second phase takes care of the rectangles i
n S
c
i
.
Phase 1:
Suppose that we ignore the S
c
i
set. Then since (i) the rectangles of S
f
i
span Ð
i
, (ii) they
are given in z

order from stage 1 of the algorithm and (iii) stage 1 provides for each segment s
S
f
i
a pointer to the leaf
in T where the search for the y

coordinate of this point would end, then the
problem is equivalent to that described in Lemma 1 and can be solved in O(n) time and space. For
each node v of T denote by seg(v) the topmost rectangle of S
f
i
that is stored in
it.
Phase 2:
Suppose now that only the S
c
i
set of rectangles is present in the slab. Since
S
c
i
=O(n/logn) we can apply the initial algorithm in O((n/logn)logn)=O(n) space and time and
produce for each node v of T a list of top(S'
v
) values, where S'
v
denotes
the list of segments in v.
After the above steps it is clear that for each sweep station in G
i
the topmost rectangle in S
v
is
given by max(top(S'
v
),seg(v)). So process 1 can be completed in O(n) space and time.
Lemma 3:
Let f, l be the first and last sw
eep station lying in slab Ð
i
then Process 2 can be
performed in O(n+
l
i
f
i
i
Q
)
(
) time
Proof:
We have O(n/logn) point stations. The recomputation of the values of the functions can be
done in O(logn) time for each such sweep station and the query
processes produce correct results
COMPUTER TECHNOLOGY INSTITUTE
1999
________________________________________________________________________________
____________________________________________________________________________________
TECHNICAL REPORT No. TR.
99/09/04
7
according to Lemma 2.
˜
Lemma 4
.
The modified algorithm needs O(n) space and runs in time
O(nlogn)+
n
i
i
Q
2
1
)
(
Proof:
Since each call of the for loop destroys the information in T, and
there are O(logn) calls of
the loop the result comes easily from lemmas 1,2,3.
˜
2.3. Generalization
In Lemma 1 we proved the validity of a statement describing the time needed to store in the
nodes of a segment tree T information regard
ing the segments in the node lists of the nodes. This
Lemma can be extended to handle the case where
the tree T is not binary but t

ary with t a parameter 1<t
n,
the number of segments S is not O(n), and
the tree T is a hereditary segment tree (see [C
EGS94]), that is each node v of T has associated
with it two node lists S
v
and S'
v
. S
v
consists of the segments that would be stored in v in the
traditional segment tree sense and S'
v
consists of the segments stored in S
u
for all proper
descendants u of v.
In other words whenever a segment s is to be stored is some S
v
list then it is
stored in the S'
w
lists for each proper ancestor w of v. It is easy to see that each segment s is stored
in the S
v
lists of O(ht) nodes and in the S'
v
lists of h nodes where h
=log
t
n the height of T.
The generalization of Lemma 1 is the next lemma:
Lemma 5
:
Let S be a set of m non

intersecting segments in the xz

plane, parallel to the x

axis,
with x

coordinates taken from the universe U={x
1
,x
2
,...,x
n
) and let T be an initially
empty t

ary
hereditary segment tree T build on the universe U. Assume that S is given in ordered z

order and
for each endpoint of a segment in S we have a pointer to the leaf in T, where the search for the x

coordinate of this point would end. Then in O(n
+m) time and space we can find for each node v
of T, the topmost segment s
1
(v) in S that would be stored in S
v
and the topmost segment s
2
(v) in S
that would be stored in S'
v
. Also in the same time and space bounds we can compute for each
segment s in S two
lists L
1
(s) and L
2
(s), where L
1
(s) contains the nodes v of T for which s is the
topmost segment in S
v
and L
2
(s) the nodes v of T for which s is the topmost segment in S'
v
.
Proof:
Consider first the computation of the s
2
(v) values. From the discussion abov
e the nodes in
whose S'() lists a segment s[s
l
,s
r
] is stored, constitute two paths in T beginning from the leaves
where the search for s
l
, s
r
would end in T and end up at the root. Then the algorithm is the
following:
Process the segments in S in decreasi
ng z

order. Let S
1
be the set of segments processed so far and
let s be the current segment. Follow the two paths in T corresponding to the nodes in T where s
would be stored and if any node is found which does not store any segment of S
1
then mark it and
set s
2
(v) to s. Since it was shown that all these operations can be simulated by a sequence of O(m)
union and finds, on O(n) elements in which the structure of the union is given (T is the union tree)
then the whole process of computing the s
2
values can
be performed in O(n+m) time and O(n+m)
space.
Consider now the computation of the s
1

values. Let v
1
,v
2
,...,v
t
be the t sons of a node v in T with
v
1
,v
2
,..,v
t
sorted according to their appearances in T from left to right (that is the range of v
i
is left
to
the range of v
i+1
), and let p(v) be the parent of v.
We give the following definitions which are generalisations of the definitions given in the proof of
lemma 1:
If v is the i

th child of p(v), with 1<i
t. then the upper left relative of v is the (i

1)

t
h child of
p(v)
COMPUTER TECHNOLOGY INSTITUTE
1999
________________________________________________________________________________
____________________________________________________________________________________
TECHNICAL REPORT No. TR.
99/09/04
8
If v is the first child of p(v), then the upper left relative of v is the node w, such that v lies on
the left spine of the subtree rooted at the immediate right neighbouring sibling of w.
If v is the i

th child of p(v) with 1<i
t then the
upper right relative of v is the (i+1)

th child of
p(v).
If v is the last child of p(v) then the upper right relative of v is the node w such that v lies on the
right spine of the subtree at the immediate left neighbouring sibling of w.
Again each node has
a unique upper right and a unique upper left relative and so by following
the same approach as in lemma 1 we can in O(n) time and space extract from T the two forests
F
l
, F
r
and then convert them to two trees L,R. Then following exactly the same steps as
those
given in lemma 1 we can prove that the s
1

values for each node v of T can be computed in
O(n+m) time and space. For the second part of the lemma it is easy to see that given the s
1
, s
2
values stored in T the computation of the L
1
,L
2
lists for each s
egment in S can be performed in
O(n+m) time and space by a simple traversal of T.
˜
The above lemma can be used to reduce to linear the space cost of the algorithms presented in
[GAO90].
3. The second algorithm
In this section w
e provide a description of our second algorithm. In the fist subsection we
describe a solution that matches the performance of [GMV99] i.e. runs in O(nlogn) time and
space. Our solution is based on the approach of [GAO90] which we have modified appropriate
ly.
Then in the second subsection we show how to reduce the storage to O(n) by using a partitioning
trick.
3.1. The Incremental Approach
We will use the notation R.x
1
, R.x
2
, R.y
1
, R.y
2
, R.z for the x

, y

and z

coordinates of rectangle
R, i.e. R = [R.x1,
R.y2]
[R.y1, R.y2]
R.z.
We will use an incremental approach analogous to the one of [GAO90]. This approach to hidden
line elimination problems was introduced by Guting and Ottman in [GO87] and was also used in
[KOS92, SO91, SO92]. The rectangles will
be processed in descending z

order starting from the
one nearest to the viewer, and a structure storing the union of the projections of all rectangles
encountered so far, will be maintained. Following the terminology of [GAO90] we call this union
the shado
w of the rectangles. Each time a new rectangle is encountered we will query the structure
storing the shadow to determine if there are parts of the rectangle not covered by the shadow. If
there are such parts then we add the rectangle to the set V of visib
le rectangles (initially this set is
empty). Then the structure storing the shadow is updated to reflect the addition of the new
rectangle, and the algorithm continues with the next rectangle.
By the above brief description it is clear that the algorithm c
orrectly computes the subset of
visible rectangles (which will be the set V after completion of the algorithm). We implement the
structure for shadow maintenance as a simplified version of the Hive Tree of [GAO90]. As shown
in lemma 6 this structure can b
e built in O(nlogn) time using O(nlogn) storage. Furthermore in
lemma 7 and corollary 1 it is shown that all queries and updates performed by the algorithm take
O(nlogn) time after an initial O(nlogn) time preprocessing phase. Therefore, we obtain the main
result of this subsection stated in the following theorem:
Theorem 1
The rectangles visible from z =
, in a set of n iso

oriented rectangles in 3D space,
can be determined in O(nlogn) space and time.
3.1.1. The Data Structure
As already mentioned the da
ta structure is a simple version of the Hive Tree which was introduced
in [GAO90]. The Hive Tree is a segment tree augmented with auxiliary structures in its nodes to
COMPUTER TECHNOLOGY INSTITUTE
1999
________________________________________________________________________________
____________________________________________________________________________________
TECHNICAL REPORT No. TR.
99/09/04
9
facilitate shadow maintenance. We will give an overview of this structure as needed for o
ur
purposes.
Let x
1
, x
2
, x
3
,…, x
2n
be the x

coordinates of the rectangles in ascending order (without loss of
generality we assume that the x

coordinates are distinct). The skeleton of the structure is a
segment tree T. T is a static binary balanced tree w
hose leaves are associated with the elementary
x

ranges [x
1
, x
2
), [x
2
, x
3
), .. , [x
2n

1
, x
2n
] in this order. Each node u of the tree has an associated
xrange(u) equal to the union of the xranges of its two children. Known properties of this
representation
are:
at each level of the tree the xranges of the nodes constitute a partition of [x
1
, x
2n
]
the nodes whose xranges contain a value x lie in a root to leaf path, and
any interval [x
i
, x
j
] can be associated to O(logn) nodes u such that xrange(u)
學
i
, x
j
] and
xrange(parent(u))
學
l
, x
j
].
It is clear from the above properties that any interval can be partitioned to O(logn) maximal
subintervals (xranges). In two dimensions each xrange [x
i
, x
j
]
defines a slab delimited by the two
vertical lines x = x
i
, x = x
j
. Every rectangle R can be associated to O(logn) nodes according to
[R.x
1
, R.x
2
]. For each node u we denote by S(u) the set of rectangles associated to u or to
descendants of u. Note that rec
tangles in S(u) either intersect both boundaries of the slab of u, or
have at least one vertical side inside the slab. Let y
1
, y
2
, . ., y
p
be the y

coordinates of rectangles of
S(u). We draw horizontal lines y = y
1
, y = y
2
, . . . , y = y
p
partitioning the
slab into p

1 horizontal
strips. These strips are stored as a sorted list denoted as Strip(u). For each strip h in Strip(u) we
store two lists Up(h), Down(h). Up(h) contains all strips in Strip(parent(u)) that intersect h, while
Down(h) contains all strips
in Strip(left_child(u))
Strip(right_child(u)) that intersect h. Note
that strips in Down(h) form a partition of strip h. There is also an equivalence between Up and
Down lists, specifically h
Up(h') if h'
䑯D渨n⤮)䅬獯A湯瑥n瑨慴t䑯D渨n⤠c潮瑡楮猠eac瑬y瑷o
獴物灳⡯湥楮ieac栠c桩h搩⸠周T啰Ua湤n䑯D渠汩獴sa牥業灬敭p湴敤na猠摯畢y汩湫n搠汩獴s⸠周T
景汬潷楮敭浡潵湤⁴桥楺e湤潮獴牵r瑩潮⁴o浥m⁴桥瑲畣瑵牥.
Lemma 6
The Hive Tree for a
collection of n rectangles in the plane can be constructed in
O(nlogn) time and space
.
Proof
. The proof follows from lemma 2.2 of [GAO90] for the special case in which the skeleton
of the structure is a binary tree. In brief the arguments go as follows: F
or the space notice that the
size of all lists Up(h) is the same with the total size of lists Down(h) because of the equivalence
property. The total size of Down(h) lists can be bounded by twice the number of all strips since
each list has size 2. For the
number of strips observe that each rectangle contributes two strip
boundaries to each one of its associated nodes and their ancestors. Since there are O(logn)
associated nodes whose ancestors lie in a forked path, each rectangle contributes O(logn) strip
b
oundaries. Therefore the number of strips and the size of the structure is O(nlogn). The lists for
the strips can be constructed recursively, in time bounded by their size by constructing first the
lists of the root and then using these lists to compute th
e lists of its children.
˜
3.1.2 Determining Visible Rectangles
We process the rectangles in descending depth order. Let R
1
, R
2
, . . ., R
i

1
be an order of the
rectangles in decreasing z

coordinate. At the time we process rectangle
R
i
rectangles R
1
, R
2
,..., R
i

1
will have been inserted in the Hive Tree. The Hive Tree will be used to store a representation of
the union of the processed rectangles. We denote this union by U
i
. Initially U
1
=
. Processing of
R
i
involves two steps: First w
e have to query the Hive Tree to determine if R
i
U
i
= U
i
. If so,
then the rectangle is completely obscured by the rectangles R
1
, R
2
, . . ., R
i

1
, else there is a part of
R
i
which is not hidden, in which case rectangle R
i
is
reported as visible. Secondly, we have to
COMPUTER TECHNOLOGY INSTITUTE
1999
________________________________________________________________________________
____________________________________________________________________________________
TECHNICAL REPORT No. TR.
99/09/04
10
update the Hive Tree in order to represent the union U
i+1
= U
i
R
i
, that is insert R
i
in the Hive
Tree. We will show how to perform both steps in a single access of the Hive Tree.
A
strip can be in one of two states full, or open. A strip is full if it is inside U
i
and it is open, if it
is outside U
i
or it partially overlaps U
i
. It follows from the definitions that if a strip h is full then
all strips belonging in Down(h) are full to
o. Note that initially all strips are open while upon
termination of the algorithm all strips have become full.
As in [AGO90] we will use some additional lists for each strip h. These are:
OU(h) which stores the strips in Up(h) that are open and
OD(h) wh
ich stores the strips in Down(h) that are open.
Initially OU(h) = Up(h) and OD(h) = Down(h).
Now consider querying the structure with rectangle R
i
. Rectangle R
i
can be associated to
O(logn) nodes of the Hive Tree. The slabs of these nodes are disjoint and
partition rectangle R
i
to
O(logn) pieces. Each strip of these nodes, is either completely contained in R
i
or lies outside R
i
.
So the rectangle can be decomposed into a number of strips. The query algorithm must be able to
determine if there is one such st
rip that is not full. If so, then there exists a part of R
i
not covered
by U
i
. This can be performed efficiently by using the notion of principal rectangles. For each strip
h that belongs to node u the principal rectangle is the highest rectangle (the one
with biggest z

coordinate) among the rectangles of S(u) that contain strip h. Note that each strip has at most one
principal rectangle. Principal rectangles are computed in a preprocessing step. After having
determined the principal rectangles it is easy t
o compute for each rectangle R a list P(R) of all
strips for which R is a principal rectangle. Given the list P(R
i
) it is trivial to perform the query: we
visit all strips in P(R
i
) and check if there exists one which is not full. The correctness follows fr
om
the fact that all

remaining strips which are covered by R
i
and are not in P(R
i
) need not be
examined because they are full (otherwise R
i
would be the principal rectangle for them).
It remains to show how to update the Hive Tree. Consider again the strip
s in P(R
i
). If all of them
are full then nothing needs to be done (indeed adding R
i
does not change the union U
i
). Otherwise,
let h is a strip in P(R), which is not full. First we mark this strip as full. Then for each strip h' in
OD(h) we remove h from OU
(h'). If this results to OU(h') =
then we also mark h' as full, we
remove h' from OD(h) and continue in the same way with strips in OD(h'). We act analogously for
strips in OU(h). That is, for each strip h' in OU(h) we remove h from OD(h'). If this result
s to an
empty list then we mark strip h' as full, we remove h' from OU(h) and continue in the same way
for strips in OU(h').
This completes the description of the algorithm. A bound for the total time of queries and updates
is provided by the following le
mma.
Lemma 7
The time spent for al1 queries and updates in the Hive Tree is bounded by the size of
the Hive Tree.
Proof
. Each query processes the strips in P(R
i
) for each rectangle R
i
. Because each strip has a
unique principal rectangle it follows that eac
h strip is processed once. So the query time is
bounded by the total size of lists Strip(u). Updates also process strips in OU(h) and OD(h) for each
visited strip h. This kind of processing may cascade to several ancestors and descendants of each
associate
d node u. However, notice that for each visited strip h' a deletion is made from either
OU(h') or OD(h'). Since the total number of deletions during all updates can not exceed the total
size of the lists OU and OD, the claimed bound follows.
˜
Consider now the time of the preprocessing phase. In the preprocessing phase we have to
compute for each strip h its principal rectangle. First we need the following remark:
Lemma 8
We can compute in O(nlogn) time for each node u, the set S(u)
of its associated
rectangles, the depth order of rectangles in S(u) and the y

order of their horizontal boundaries.
Proof.
In a preliminary step we sort the y

and z

coordinates of the rectangles. For each rectangle
we compute in O(logn) time a list of a
ssociated nodes in the Hive Tree. For each node in the tree
COMPUTER TECHNOLOGY INSTITUTE
1999
________________________________________________________________________________
____________________________________________________________________________________
TECHNICAL REPORT No. TR.
99/09/04
11
we create two empty lists the z

list and the y

list. Then we process all rectangles in descending
depth order and add each rectangle to the z

lists of its associated nodes. This produces in O(nlog
n)
time for each node a list of its associated rectangles in descending depth order. In the same way
we can compute for each node its y

list containing the y

order of the boundaries of its associated
rectangles.
˜
Given the information computed in the prev
ious lemma we can solve the principal rectangle
problem for the strips of each node of the Hive Tree. The solution is described in the following
lemma:
Lemma 9
Given the z

and the y

order of the boundaries of rectangles in S(u) the principal
rectangle fo
r each strip in Strip(u) can be computed in time O(Strip(u)).
Proof
. First we restrict our attention to the strips defined by the boundaries of rectangles in S(u)
The strips in Strip(u) are contained in these strips, so their principal rectangles can be
derived
easily from the principal rectangles of the latter. Then the problem can be rephrased as a 2

dimensional interval visibility problem, specifically: given a set of horizontal segments in the y

z
plane determine the visible parts of the segments from
a point at z = +
. This problem can be
solved using the linear time Union

Find algorithm of Gabow and Tarjan [GT85] in O(S(u)) time.
Then in O(Strip(u)) time we can determine in a single pass of the list Strip(u) the principal
re
ctangles for its strips.
˜
As a consequence of the previous observations the preprocessing time can be bounded by the
total size of the lists Strip(u) i.e.
Corollary 1
The preprocessing time is bounded by the size of the Hive Tree
.
3.2. Space Reduct
ion
To reduce the storage of the algorithm we will partition the scene into O(logn) vertical slabs and
we will solve the problem independently in each slab in O(n) time and space. It is interesting to
note that in our approach this simple partitioning sche
me directly reduces the space to O(n)
without further modifications of the previous approach.
Initially we sort the x

y

and z

coordinates of all rectangles in all slabs and we call the resulting
orderings O
x
, O
y
, O
z
respectively. We define the slabs by
drawing vertical lines in the x

y plane,
so that in each slab there are no more than [n/logn] vertices of rectangles. In this way we have
O(logn) slabs each containing O(n/logn) vertices. In each slab we distinguish two sets of
rectangles denoted S
c
and S
f
. The rectangles of S
f
span the x

range of the slab while the ones of S
c
have one or both of their vertical edges inside the slab. For both sets of rectangles we consider
only the portions of rectangles inside the slab. Note that S
c
 = O(n/logn) and S
f

= O(n). For each
slab we apply the algorithm of the previous section with input the rectangles of S
c
S
f
. The
following lemma bounds the time and storage of this solution.
Lemma 10
The visible rectangles in a single slab can be reported in O(n) space and
time
.
Proof
. First we will show that the hive tree has size O(n). The storage for the rectangles of S
c
clearly is O(n) since there are O(n/logn) such rectangles. The rectangles of S
f
are all associated to
a single node in the Hive Tree, its root, since th
ey span the x

range of the slab. So the storage
needed for them is also O(n). By using the same algorithm as in lemma 6 the Hive Tree can be
constructed in time bounded by its size, if the y

order of rectangles of S
f
is known. This order can
be derived in
O(n) time from the ordering O
y
of all rectangles. So the Hive Tree can be built in
O(n) time and storage. By lemma 7 the time of all queries and updates will be bounded by O(n).
However we still need a way to bound the time of the preprocessing. The prepro
cessing time will
be O(n) if the time of lemma 8 is reduced to O(n). The sets S(u) clearly can be computed in O(n)
time. For all nodes except for the root the computations take O(n) time because there are
O(n/logn) rectangles. For the root the y

and z

or
der of rectangles of S
f
can be derived in O(n)
time by the O
y
and O
z
orders of all rectangles. Now it is easy to bound the time of the whole
algorithm as stated in the following theorem:
COMPUTER TECHNOLOGY INSTITUTE
1999
________________________________________________________________________________
____________________________________________________________________________________
TECHNICAL REPORT No. TR.
99/09/04
12
Theorem 2
The visible rectangles in a set of n iso

oriented rectangle
s can be determined in
O(nlogn) time and O(n) storage.
Proof
. The total time for all slabs is O(nlogn). The time to compute the orders O
x
, O
y
and O
z
is
O(nlogn) for sorting. The storage used during the process is always O(n) by the previous lemma.
˜
The a
lgorithm described above reports multiple times the rectangles that are visible in more than
one slab. This can be avoided by using a table of size n to mark the reported rectangles. The
rectangles are numbered from 1 to n and rectangle number indexes the
table.
4. Extensions and Future Work
In this paper we have presented two algorithms for determining visible rectangles in optimal
time and storage. Naturally the question is raised whether other known algorithms for hidden
surface removal can be appropria
tely modified to solve the object

complexity version of the
problem for more general objects. There seems to be an inherent difficulty for most algorithms
because their time complexities strongly depend on the size k of the visibility map. However the
incr
emental approach upon which our second algorithm was based, apart from being more
appealing than the plane sweep approach of [GMV99] it may also be more promising for other
kinds of objects too.
Consider for example the case in which the objects of the sce
ne have small union size. We can
use the approach of [KOS92], which is as follows: The objects are processed in descending depth
order and the shadow (union) of processed objects is explicitly computed. However instead of
processing one object in each step
in that approach the visibility map of the next f objects is
computed in O(c) time, where c is the current size of the shadow. Then, in a merging step which
takes O(clogc+k') time, the visibility map is compared against the shadow to find the k' arts not
obscured by the shadow. As shown in [KOS92] this approach takes O(n
C汯ln+欩k瑩浥睨w牥C
楳⁴桥慸業洠獨慤潷楺e.
呯T獯汶攠瑨攠潢橥o琠co浰me楴y 癥牳楯渠潦o瑨t 灲潢汥洠睥 ca渠業灬敭p湴n瑨攠浥mg楮i 獴数
a灰牯p物r瑥tyⰠ獯s
瑨慴t楴牵湳r楮i伨c汯gc⤠瑩浥man搠灲潤pce猠a猠潵瑰畴瑨t楤敮瑩iy潦o瑨攠癩獩扬攠
潢橥o瑳t⡴桥e瑡楬猠areeasya湤na牥汥l琠瑯t瑨t牥a摥爩.周T渠by瑨ea湡ly獩s潦o[S伹㉝瑨攠瑩浥m楳
扯畮摥搠by伨n
C logn). Now consider the classes of objects studied in [K
OS92]. For the case in
which the objects are discs or convex homothetic objects C can be bounded by q [KLPS86], for
the case of fat triangles C is bounded by O(qloglogq) [MPSSW94], while for the case of
polyhedral terrain C is bounded by q
α
(q), where q is
the object complexity and
α
denotes the
inverse of Ackerman's function.
So this approach yields output sensitive algorithms with time:
O(n
q logn) for discs and convex homothetic objects,
O(n
qloglogq logn) for fat triangles and
O(n
q
α
(q) logn) for terr
ains.
The above time bounds are optimal when q is constant and in the worst case (q = n) they are much
more efficient than computing a visibility map of size O(n
2
).
It is interesting to investigate whether this approach can solve the object complexity ve
rsion of
hidden surface removal for other kinds of objects as well. It is also interesting to look for more
efficient algorithms for the case of fat triangles and the case of objects of small union size.
References
[B90]
M. Bern, “Hidden surface removal
for rectangles”,
J. Comp. Syst. Sci.
,
40
(1990), 49

69.
[BJM94]Baumgarten H., Jung H., Mehlhorn K., “Dynamic Point Location in General
Subdivisions”,
Journal of Algorithms
,
17
(1994), 342

380.
COMPUTER TECHNOLOGY INSTITUTE
1999
________________________________________________________________________________
____________________________________________________________________________________
TECHNICAL REPORT No. TR.
99/09/04
13
[CEGS94]B. Chazelle, H. Edelsbrunner, L. Guibas, and M. Sharir
, “Algorithms for Bichromatic
Line

Segment Problems and Polyhedral Terrains”, Algorithmica
11
(1994), 116

122.
[CS89]
R. Cole and M. Sharir, “Visibility problems for polyhedral terrains”,
J. Symbolic
Comput.
(1989), 11

30.
[GAO90] M. T. Goodrich, M.J. Att
alah and M.H. Overmars, “An input size output size trade

off
in the time complexity of rectilinear hidden surface removal”,
Proc. ICALP'90, Lecture
Notes in
Comp. Sci. 443, SpringerVerlang Berlin
(1990), 689

702.
[GO87] Guting R., Ottmann T. New algorith
ms for special cases of the hidden line elimination
problem, Computer Vision,
Graphics and Image Processing
40
(1987).
[GT85]
H.N. Gabow and R.E. Tarjan, “A linear time algorithm for a special case of disjoint
set union”,
J. Comp. Syst. Sci.
, (1985), 209

221.
[GMV99] E.F. Grove, T.M. Murali and J.S. Vitter, “The object complexity model for hidden line
elimination”,
International Journal of Computational Geometry and Applications
,
9
(1999), 207

217
[GO87]
R.H. Guting and T. Ottman, “New algorithms for spe
cial cases of the hidden line
elimination, problem”,
Comp. Vision, Graphics Image Proc.
40
( 1987), 188

204.
[KLPS86] K. Kedem, R. Livne, J. Pach and M. Sharir, “On the union of Jordan, regions and
collision

free translational motion amidst polygonal obsta
cles”,
Discrete Comput.
Geom.
1
(1986),
59

71.
[KOS92] M. J. Katz, M. H. Overmars and M. Sharir, “Efficient hidden, surface removal for
objects of small union size”,
Computational Geometry Theory and Applications
2
(1992), 223

234.
[MNU90] K. Mehlhorn, St.
Naeher and C. Uhrig, “Hidden line elimination for iso

oriented
rectangles”,
Information Processing Letters
35
(1990), 137

143.
[MPSSW94] J. Matousek, J. Pach, M. Sharir, S. Sifrony· and E. Welzl, “Fat triangles determine
linearly many holes”,
SIAM J. Comp
ut.
, (1994), 154

199.
[SO91]
H. Schipper and M.H. Overmars, “Dynamic partition trees”,
BIT
31
(1991), 421

436.
[SO92]
M. Sharir, and M.H. Overmars, “A simple output

sensitive algorithm for hidden
surface removal,
ACM Transactions on graphics
”,
11
(1992),
1

11.
Enter the password to open this PDF file:
File name:

File size:

Title:

Author:

Subject:

Keywords:

Creation Date:

Modification Date:

Creator:

PDF Producer:

PDF Version:

Page Count:

Preparing document for printing…
0%
Comments 0
Log in to post a comment