Geometric Data Structures For Computer Graphics: Gabriel Zachmann & Elmar Langetepe
Geometric Data Structures For Computer Graphics: Gabriel Zachmann & Elmar Langetepe
Geometric Data Structures For Computer Graphics: Gabriel Zachmann & Elmar Langetepe
Course Description
In recent years, methods from computational geometry have been widely adopted by the computer
graphics community yielding elegant and efficient algorithms. This course aims at familiarizing practi-
tioners in the computer graphics field with a wide range of data structures from computational geometry.
It will enable attendees to recognize geometrical problems and select the most suitable data structure
when developing computer graphics algorithms.
The course will focus on algorithms and data structures that have proven to be versatile, efficient,
fundamental and easy to implement. Thus practitioners and researchers will benefit immediately from
this course for their everyday work.
∗ You can find the slides and the multimedia material for this tu-
torial at http://cg.cs.uni-bonn.de/course/
2 Zachmann/Langetepe: Geometric Data Structures for CG
Prerequisites
Participants of this course should be familiar with the basic principles of computer graphics and the type
of problems in the area. Familiarity with computer programming is not required.
The intended audience are practitioners working in 3D computer graphics (VR, CAD/CAM, entertain-
ment, animation, etc.) and students from both computer graphics and computational geometry, possibly
working on a master or PhD thesis.
Syllabus
Our goal is to familiarize practitioners and researchers in computer graphics with some very versatile and
ubiquitous geometric data structures, enable them to readily recognize geometric problems during their
work, modify the algorithms to their needs, and hopefully make them curious about further powerful
treasures to be discovered in the area of computational geometry.
In order to achieve these goals in an engaging yet sound manner, the general concept throughout the
course is to present each geometric data structure in the following way: first, the data strucure will be
defined and described in detail; then, some of its fundamental properties will be highlighted; after that,
one or more computational geometry algorithms based on the data structure will be presented; and finally,
a number of recent, representative and practically relevant algorithms from computer graphics will be
described in detail, showing the utilization of the data structure in a creative and enlightening way.
We have arranged the topics in roughly increasing degree of difficulty. The hierarchical data structures
are ordered by increasing flexibility, while the non-hierarchical topics build on each other. Finally, the last
topic presents a generic technique for dynamizing geometric data structures.
Detailed informations about the topics discussed and the corresponding presenters are given in the
schedule below.
Component 1. Introduction
Introduction – Zachmann/Langetepe.
Component 2. Quadtree/Octree
Construction, complexity, balancing, navigation – Langetepe.
Terrain visualization, iso-surface generation – Zachmann.
Component 3. Bounding volume hierarchies
Definition, construction, hierarchical collision detection – Zachmann.
Component 4. Voronoi diagrams / Delaunay triangulations
Definition, construction, generalizations, applications – Langetepe.
NURBS tesselation, texture synthesis – Zachmann.
Component 5. Distance fields
Definition, modelling, morphing – Zachmann.
Component 6. Dynamization of geometric data structures
Definition, amortized Insert and Delete – Langetepe.
Contents
1 Introduction 5
3 BSP Trees 15
3.1 Rendering Without a Z-Buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2 Representing Objects with BSPs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3 Boolean Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.4 Construction Heuristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.4.1 Convex objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.4.2 Cost driven heuristic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.4.3 Non-uniform queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.4.4 Deferred, self-organizing BSPs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5 Voronoi Diagrams 28
5.1 Definitions and Elementary Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
5.1.1 Voronoi Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
5.1.2 Delaunay Triangulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5.2 Computation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
5.3 Generalization of the Voronoi Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.3.1 Voronoi Diagram and Delaunay Triangulation in 3D . . . . . . . . . . . . . . . . . 32
5.3.2 Constrained Voronoi diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.3.3 Other Types of Generalizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.4 Applications of the Voronoi Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.4.1 Nearest Neighbor or Post Office Problem . . . . . . . . . . . . . . . . . . . . . . . 34
5.4.2 Motion planning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5.4.3 Other Applications of the Voronoi Diagram in 2D . . . . . . . . . . . . . . . . . . . 36
5.5 Texture Synthesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
5.6 Shape Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
6 Distance Fields 39
6.1 Computation and representation of DFs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
6.1.1 Propagation method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
6.1.2 Projection of distance functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
6.2 Applications of DFs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
6.2.1 Morphing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
6.2.2 Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Y
i can be computed efficiently. We simply have to
g
compute all nodes v with:
d
k
5
b
R(v) ∩ Q 6= ∅.
c
f
Additionally we have to test whether the points
inside the subtree of v are inside Q.
j The efficiency of the k-d-tree with respect to
e
a
h
range queries depends on the depth of the tree. A
X
balanced k-d-tree can be easily constructed. We
5 10
sort the X- and Y-coordinates. With this order
we recursively split the set into subsets of equal
x=5
size in time O(log n). The construction runs in
x<5 5<x time O(n log n). Altogether the following theorem
holds:
y=4 y=5
y<4 4<y y<5 5<y
Theorem 4 A balanced k-d-tree for n points in
x=2 x<3 x=3 3<x x=8 x=7 the plane can be constructed in O(n log n) and
x<2 2<x x<7
x<8 8<x 7<x
needs O(n) space. A range query with an √ axis-
a b d j g
parallel rectangle can be answered in time O( n +
y=3 y=2 y=6
y<3 3<y y<2 2<y y<6 6<y a), where a denotes the size of the answer.
e c h f k i
Figure 4: A height field approximated by a grid.15 Figure 5: The same height field approximated by
a TIN.
T-vertices!
4 8
Figure 6: In order to use quadtrees for defining a Figure 7: A quadtree defines a recursive subdivi-
height field mesh, it should be balanced. sion scheme yielding a 4-8 mesh. The dots denote
the newly added vertices. Some vertices have de-
gree 4, some 8 (hence the name).
with very little detail in order to maintain a high depicted in Figure 6. If we render that as-is, then
frame rate. there will be a gap (a.k.a. crack ) between the top
In order to solve this problem, a data structure is left square and the fine detail squares inside the top
needed that allows to quickly determine the desired right square. The vertices causing this problem are
level of detail in each part of the terrain. Quadtrees called T-vertices. Triangulating them would help in
are such a data structure, in particular, since they theory, but in practice this leads to long and thin
seem to be a good compromise between the sim- triangles which have problems on their own. The
plicity of non-hierarchical grids and the good adap- solution is, of course, to triangulate each node.
tivity of TINs. The general idea is to construct Thus, a quadtree offers a recursive subdivision
a quadtree over the grid, and then traverse this scheme to define a triangulated regular grid (see
quadtree top-down in order to render it. At each Figure 7): start with a square subdivided into two
node, we decide whether the detail offered by ren- right-angle triangles; with each recursion step, sub-
dering it is enough, or if we have to go down fur- divide the longest side of all triangles (the hy-
ther. pothenuse) yielding two new right-angle triangles
One problem with quadtrees (and quadrangle- each (hence this scheme is sometimes referred to
based data structures in general) is that nodes are as “longest edge bisection”).65 This yields a mesh
not quite independent of each other. Assume we where all vertices have degree 4 or 8 (except the
have constructed a quadtree over some terrain as
red
red
blue
level 0 1 2 3 4
blue
Figure 8: The 4-8 subdivision can be generated Figure 9: The red quadtree can be stored in the
by two interleaved quadtrees. The solid lines con- unused “ghost” nodes of the blue quadtree.
nect siblings that share a common father.
border vertices), which is why such a mesh is often if error(i) < τ then
called a 4-8 mesh. return
This subdivision scheme induces a directed acyclic end if
graph (DAG) on the set of vertices: vertex j is a if Bi outside viewing frustum then
child of i if it is created by a split of a right angle return
end if
at vertex i. This will be denoted by an edge (i, j).
submesh( j, cl )
Note that almost all vertices are created twice (see V += pi
Figure 7), so all nodes in the graph have 4 children submesh( j, cr )
and 2 parents (except the border vertices).
During rendering, we will choose cells of the sub- where error(i) is some error measure for vertex i,
division at different levels. Let M0 be the fully and Bi is the sphere around vertex i that completely
subdivided mesh (which corresponds to the origi- encloses all descendant triangles.
nal grid) and M be the current, incompletely subdi- Note that this algorithm can produce the same
vided mesh. M corresponds to a subset of the DAG vertex multiple times consecutively; this is easy
of M0 . The condition of being crack-free can be re- to check, of course. In order to produce one strip,
formulated in terms of the DAGs associated with the algorithm has to copy older vertices to the cur-
M0 and M: rent front of the list at places where it makes a
“turn”; again, this is easy to detect, and the inter-
M is crack-free ⇔ ested reader is referred to.65
M does not have any T-vertices ⇔ One can speed up the culling a bit by noticing
that if Bi is completely inside the frustum, then we
∀(i, j) ∈ M : (i0 , j) ∈ M, where parent(j) = {i, i0 }
do not need to test the child vertices any more.
(1)
We still need to think about the way we store our
In other words: you cannot subdivide one trian- terrain subdivision mesh. Eventually, we will want
gle alone, you also have to subdivide the one on to store it as a single linear array for two reasons:
the other side. During rendering, this means that if 1. The tree is complete, so it really would not make
you render a vertex, then you also have to render sense to store it using pointers.
all its ancestors (remember: a vertex has 2 parents).
Rendering such a mesh generates (conceptually) 2. We want to map the file that holds the tree into
a single, long list of vertices that are then fed into memory as-is (for instance, with Unix’ mmap
the graphics pipeline as a single triangle strip. The function), so pointers would not work at all.
pseudo-code for the algorithm looks like this (sim-
plified): We should keep in mind, however, that with cur-
rent architectures, every memory access that can
submesh(i,j)
physical
space ª ⊕
ª ⊕ ⊕ ⊕
node cell
⊕ ª
?
ª ⊕
ª ⊕ ª ⊕
computational
space
⊕ ª
Figure 10: A scalar field is often given in the form Figure 11: Cells straddling the isosurface are tri-
of a curvilinear grid. By doing all calculations in angulated according to a lookup table. In some
computational space, we can usually save a lot of cases, several triangulations are possible, which
computational effort. must be resolved by heuristics.
not be satisfied by the cache is extremely expensive During rendering we need to calculate the indices
(this is even more so with disk accesses, of course). of the child vertices, given the three vertices of a
The simplest way to organize the terrain vertices triangle. It turns out that by cleverly choosing the
is a matrix layout. The disadvantage is that there indices of the top-level vertices this can be done as
is no cache locality at all across the major index. efficiently as with a matrix layout.
In order to improve this, people often introduce The interested reader can find more about this
some kind of blocking, where each block is stored topic in Lindstrom et al.,64 Lindstrom and Pas-
in matrix and all blocks are arranged in matrix or- cucci,65 Balmelli et al.,8 Balmelli et al.,7 and many
der, too. Unfortunately, Lindstrom and Pascucci65 others.
report that this is, at least for terrain visualization,
worse than the simple matrix layout by a factor 10! 2.4 Isosurface Generation
Enter quadtrees. They offer the advantage that
vertices on the same level are stored fairly close One technique (among many others) of visualizing
in memory. The 4-8 subdivision scheme can be a 3-dimenional volume is to extract isosurfaces and
viewed as two quadtrees which are interleaved (see render those as a regular polygonal surface. It can
Figure 8): we start with the first level of the “red” be used to extract the surfaces of bones or organs in
quadtree that contains just the one vertex in the medical scans, such as MRI or CT.
middle of the grid, which is the one that is gen- Assume for the moment that we are given a
erated by the 4-8 subdivision with the first step. scalar field f : R3 → R. Then the task of finding
Next comes the first level of the “blue” quadtree an isosurface would “just” be to find all solutions
that contains 4 vertices, which are the vertices gen- (i.e., all roots) of the equation f (~x ) = t.
erated by the second step of the 4-8 subdivision Since we live in a discrete world (at least in com-
scheme. This process repeats logically. Note that puter graphics), the scalar field is usually given in
the blue quadtree is exactly like the red one, except the form of a curvilinear grid : the vertices of the
it is rotated by 45°. When you overlay the red and cells are called nodes, and we have one scalar and a
the blue quadtree you get exactly the 4-8 mesh. 3D point stored at each node (see Figure 10). Such
Notice that the blue quadtree contains nodes that a curvilinear grid is usually stored as a 3D array,
are outside the terrain grid; we will call these nodes which can be conceived as a regular 3D grid (here,
“ghost nodes”. The nice thing about them is that the cells are often called voxels ).
we can store the red quadtree in place of these ghost The task of finding an isosurface for a given value
nodes (see Figure 9). This reduces the number t in a curvilinear grid amounts to finding all cells of
of unused elements in the final linear array down which at least one node (i.e., corner) has a value
to 33%. less than t and one node has a value greater than
y
x=0 m0 m0
y=0 1
Figure 12: Octrees offer a simple way to compute Figure 13: Volume data layout should match the
isosurfaces efficiently. order of traversal of the octree.
t. Such cells are then triangulated according to a edge will be visited exactly four times during the
lookup table (see Figure 11). So, a simple algorithm complete procedure. Therefore, when we visit an
works as follows:66 compute the sign for all nodes edge for the first time, we compute the vertex of the
(⊕ , > t , ª , < t); then consider each cell in isosurface on that edge, and store the edge together
turn, use the eight signs as an index into the lookup with the vertex in a hash table. So whenever we
table, and triangulate it (if at all). need a vertex on an edge, we first try to look up
Notice that in this algorithm we have only used that edge in the hash table. Our observation also
the 3D array — we have not made use at all of the allows us to keep the size of the hash table fairly
information exactly where in space the nodes are low: when an edge has been visited for the fourth
(except when actually producing the triangles). We time, then we know that it cannot be visited any
have, in fact, made a transition from computational more; therefore, we remove it from the hash table.
space (i.e., the curvilinear grid) to computational
space (i.e., the 3D array). So in the following, we 2.5 Ray Shooting
can, without loss of generality, restrict ourselves to
consider only regular grids, that is, 3D arrays. Ray shooting is an elementary task that frequently
The question is, how can we improve the exhaus- arises in ray tracing, volume visualization, and in
tive algorithm. One problem is that we must not games for collision detection or terrain following.
miss any little part of the isosurface. So we need a The task is, basically, to find the earliest hit of a
data structure that allows us to discard large parts given ray when following that ray through a scene
of the volume where the isosurface is guaranteed to composed of polygons or other objects.
not be. This calls for octrees. A simple idea to avoid checking the ray against
The idea is to construct a complete octree over the all objects is to partition the universe into a regular
cells of the grid96 (for the sake of simplicity, we will grid (see Figure 14). With each cell we store a list
assume that the grid’s size is a power of two). The of objects that occupy that cell (at least partially).
leaves point to the lower left node of their associ- Then, we just walk along the ray from cell to cell,
ated cell (see Figure 12). Each leaf ν stores the min- and check the ray against all those objects that are
imum νmin and the maximum νmax of the 8 nodes stored with that cell.
of the cell. Similarly, each inner node of the octree In this scheme (and others), we need a technique
stores the min/max of its 8 children. called mailboxes that prevents us from checking the
Observe that an isosurface intersects the volume ray twice against the same object:38 every ray gets
associated with a node ν (inner or leaf node) if and a unique ID (we just increment a global variable
only if νmin ≤ t ≤ νmax . This already suggests holding that ID whenever we start with a new ray);
how the algorithm works: start with the root and during traversal, we store the ray’s ID with the ob-
visit recursively all the children where the condi- ject whenever we have performed an intersection
tion holds. At the leaves, construct the triangles as test with it. But before doing an intersection test
usual. with an object, we look into its mailbox whether or
This can be accelerated further by noticing that not the current ray’s ID is already there; if so, then
if the isosurface crosses an edge of a cell, then that
Figure 14: Ray shooting can be implemented ef- Figure 15: The same scenario utilizing an octree.
ficiently with an octree.
we know that we have already performed the inter- those nodes and leaves that are stabbed by the
section test in an earlier cell. ray.
In the following, we will present two methods
Here, we will describe a top-down method.79 The
that both utilize octrees to further reduce the num-
idea is to work only with the ray parameter in order
ber of objects considered.
to decide which children of a node must be visited.
Let the ray be given by
2.5.1 3D Octree
A canonical way to improve any grid-based method ~x = ~p + td~
is to construct an octree (see Figure 15). Here, the and a voxel v by
octree leaves store lists of objects (or, rather, point-
ers to objects). Since we are dealing now with poly- [xl , xh ] × [yl , yh ] × [zl , zh ]
gons and other graphical objects, the leaf rule for
In the following, we will describe the algorithm as-
the octree construction process must be changed
suming that all di > 0; later, we will show that the
slightly:
algorithm works also for all other cases.
1. maximum depth reached; or, First of all, observe that if we already have the
2. only one polygon/object occupies the cell. line parameters of the intersection of the ray with
the borders of a cell, then it is trivial to compute the
We can try to better approximate the geometry of
line intervals half-way in between (see Figure 16):
the scene by changing the rule to stop only when
there are no objects in the cell (or the maximum 1 l
depth is reached). tm
α = (t + tαh ) , α ∈ {x, y, z} (2)
2 α
How do we traverse an octree along a given ray?
Like in the case of a grid, we have to make “hori- So, for 8 children of a cell, we need to compute only
zontal” steps, which actually advance along the ray. three new line parameters. Clearly, the line inter-
With octrees, though, we also need to make “verti- sects a cell if and only if max{til } < min{thj }.
cal” steps, which traverse the octree up or down. The algorithm can be outlined as follows:
All algorithms for ray shooting with octrees can traverse( v, tl , th )
be classified into two classes: compute tm
determine order in which sub-cells are hit by the ray
• Bottom-up: this method starts at that leaf in the
for all sub-cells vi that are hit do
octree that contains the origin of the ray; from traverse( vi , tl |tm , tm |th )
there it tries to find that neighbor cell that is end for
stabbed next by the ray, etc.
where tl |tm means that we construct the lower bound-
• Top-down: this method starts at the root of the ary for the respective cell by passing the appropri-
octree, and tries to recurse down into exactly ate components from tl and tm .
tyh
thx
tm l
tm
y
y > tx
tm
x
tlx
tly
tm l
y < tx
Figure 16: Line parameters are trivial to compute Figure 17: The sub-cell that must be traversed first
for children of a node. can be found by simple comparisons. Here, only
the case tlx > tly is depicted.
2.5.2 5D Octree S2 ↔ [−1, +1]2 × {+x, −x, +y, −y, +z, −z}
In the previous, simple algorithm, we still walk We will denote the coordinates on the cube’s side
along a ray every time we shoot it into the scene. by u and v.
However, rays are essentially static objects, just like
the geometry of the scene! This is the basic obser-
vation behind the following algorithm.3,6 Again, it
Table 1: Determines the enter- Table 2: Determines the first Table 3: Determines the traver-
ing side. sub-cell. sal order of the sub-cells.
d~
u u
v + =
v
Figure 19: With the direction cube, we can dis- Figure 20: A uv interval on the direction cube
cretize directions, and organize them with any hi- plus a xyz interval in 3-space yield a beam.
erarchical partitioning scheme.
Within a given universe B = [0, 1]3 (we assume the remaining two uv-intervals define a cone in 3-
it is a box), we can represent all possibly occurring space. Together (more precisely, their Minkowski
rays by points in sum) they define a beam in 3-space that starts at
the cell’s box and extends in the general direction
R = B × [−1, +1]2 of the cone (see Figure 20).
(3)
× {+x, −x, +y, −y, +z, −z} Since we have now defined what a 5D cell of
the octree represents, it is almost trivial to define
which can be implemented conveniently by 6 copies how objects are assigned to sub-cells: we just com-
of 5-dimenional boxes. pare the bounding volume of each object against the
Returning to our goal, we now build six 5-dimen- sub-cells 3D beam. Note that an object can be as-
sional octrees as follows. Associate (conceptually) signed to several sub-cells (just like in regular 3D
all objects with the root. Partition a node in the octrees). The test whether or not an object inter-
octree, if sects a beam could be simplified further by enclos-
ing a beam with a cone, and then checking the ob-
1. there are too many objects associated with it; jects bounding sphere against that cone. This just
and increases the number of false positives a little bit.
2. the node’s cell is too large. Having computed the six 5D octrees for a given
If a node is partitioned, we must also partition its scene, ray tracing through that octree is almost
set of objects and assign each subset to one of the trivial: map the ray onto a 5D point via the direc-
children. tion cube; start with the root of that octree which
Observe that each node in the 5D octree defines a is associated to the side of the direction cube onto
beam in 3-space: the xyz-interval of the first three which the ray was mapped; find the leaf in that oc-
coordinates of the cell define a box in 3-space, and
tree that contains the 5D point (i.e., the ray); check orientation and position of a splitting plane can be
the ray against all objects associated with that leaf. chosen arbitrarily. To get a feeling for a BSP tree,
By locating a leaf in one of the six 5D octrees, Figure 23 shows an example for a set of objects.
we have discarded all objects that do not lie in the The definition of a BSP (short for BSP tree) is
general direction of the ray. But we can optimize fairly straight-forward. Here, we will present a re-
the algorithm even further. cursive definition. Let h denote a plane in Rd , h+
First of all, we sort all objects associated with a and h− denote the positive and negative half-space,
leaf along the dominant axis of the beam by their resp.
minimum (see Figure 21). If the minimum coordi-
nate of an object along the dominant axis is greater Definition 1 (BSP tree)
than the current intersection point, then we can Let S be a set of objects (points, polygons, groups
stop — all other possible intersection points are far- of polygons, or other spatial objects), and let S(ν)
ther away. denote the set of objects associated with a node ν.
Second, we can utilize ray coherence as follows. Then the BSP T(S) is defined by
We maintain a cache for each level in the ray tree
1. If |S| ≤ 1, then T is a leaf ν which stores S(ν) :=
that stores the leaves of the 5D octrees that were
S.
visited last time. When following a new ray, we
first look into the octree leaf in the cache whether 2. If |S| > 1, then the root of T is a node ν; ν stores
it is contained therein, before we start searching for a plane hν and a set S(ν) := {x ∈ S|x ⊆ hν }
it from the root. (this is the set of objects that lie completely
Another trick (that works with other ray acceler- inside hν ; in 3D, these can only be polygons,
ation schemes as well) is to exploit the fact that we edges, or points). ν also has two children T −
do not need to know the first occluder between a and T + ; T − is the BSP for the set of objects
point on a surface and a light source. Any occluder S− := {x ∩ h− +
ν |x ∈ S}, and T is the BSP for
suffices to assert that the point is in shadow. So + +
the set of objects S := {x ∩ hν |x ∈ S}.
we also keep a cache with each light source which
stores that object (or a small set) which has been an This can readily be turned into a general algorithm
occluder last time. for constructing BSPs. Note that a splitting step
Finally, we would like to mention a memory op- (i.e., the construction of an inner node) requires us
timization technique for 5D octrees, because they to split each object into two disjoint fragments if it
can occupy a lot of memory. It is based on the ob- straddles the splitting plane of that node. In some
servation that within a beam defined by a leaf of the applications though (such as ray shooting), this is
octree the objects at the back (almost) never inter- not really necessary; instead, we can just put those
sect with a ray emanating from that cell (see Fig- objects into both subsets.
ure 22). So we store objects with a cell only if they Note that with each node of the BSP a convex
are within a certain distance. Should a ray not hit cell is associated (which is possibly unbounded): the
any object, then we start a new intersection query “cell” associated with the root is the whole space,
with another ray that has the same direction and a which is convex; splitting a convex region into two
starting point just behind that maximum distance. parts yields two convex regions. In Figure 23, the
Obviously, we have to make a trade-off between convex region of one of the leaves has been high-
space and speed here, but when chosen properly, lighted as an example.
the cut-off distance should not reduce performance With BSPs, we have much more freedom to place
too much while still saving a significant amount of the splitting planes than with k-d trees. However,
memory. this also makes that decision much harder (as al-
most always in life). If our input is a set of poly-
gons, then a very common approach is to choose
3 BSP Trees one of the polygons from the input set and use
this as the splitting plane. This is called an auto-
BSP trees (short for binary space partitioning trees ) partition (see Figure 24).
can be viewed as a generalization of k-d trees. like While an auto-partition can have Ω(n2 ) frag-
k-d trees, BSP trees are binary trees, but now the ments, it is possible to show the following in 2D.23,75
1 2 3 4
Figure 21: By sorting objects with in each 5D leaf, Figure 22: By truncating the beam (or rather, the
we can often stop checking ray intersection quite list of objects) we can save a lot of memory usage
early. of a 5D octree, while reducing performance only
insignificantly.
h1 near
polygons
h3 h3 h2
h4 far
h2 h4 polygons
h1
3
enable efficient enumeration of all polygons in vis- 1
ibility order from any point in any direction.1 out out
6 in 1 2 3
A simple algorithm to render a set of polygons 6 out
in 5 4
with correct hidden-surface removal, and without out
in
5
out
in out out in out
a z-buffer, is the painter’s algorithm : render the 7 7
out 2 in out
scene from back to front as seen from the current 4
viewpoint. Front polygons will just overwrite the Figure 26: Each leaf cell of BSP representation
contents of the frame buffer, thus effectively hid- of an object is completely inside or completely
ing the polygons in the back. There are polygon outside.
configurations where this kind of sorting is not al-
ways possible, but we will deal with that later.
How can we efficiently obtain such a visibility or- A B
combine
Figure 31: A graphical depiction of the merge step in the algorithm for boolean operations on objects
represented by BSP trees.
of tree Ti where L j are all the leaves. Then the Operation T1 Result
merge of T1 , T2 yields a new BSP tree T3 such that
C3 = {c1 ∩ c2 |c1 ∈ C1 , c2 ∈ C2 , c1 ∩ c2 6= ∅} (see in T1
∪
Figure 30). out T2
The merge operation consists of two cases. The in T2
∩
first, almost trivial, case occurs when one of the two out T1
operands is a leaf: then at least one of the two re-
in T2c
gions is homogenous, i.e., completely inside or out- \
out T1
side. In the other case, both trees are inhomoge-
nous over the same region of space: then, we just in T2c
ª
split one of the two with the splitting plane from out T2
the root of the other, and we obtain two pairs of
BPSs, that are smaller, and still cover the same re- Furthermore, we would like to point out that the
gions in space; those two pairs can be merged recur- merge function is symmetric: it does not matter
sively (see Figure 31). The following pseudo-code whether we partition T2 with H1 or, the other way
describes this recursive procedure more formally: round, T1 with H2 — the result will be the same.
merge( T1 , T2 ) → T3
if T1 or T2 is a leaf then 3.4 Construction Heuristics
perform the cell-op as required by the boolean op-
eration to be constructed (see below) One can prove that in general, auto-partitions have
else the same complexity as other partitionings.23,75 In
(T2ª , T2⊕ ) ← split-tree(T2 , H1 , . . .) addition, it has been proven that “fat” objects (i.e.,
T3− ← merge(T1− , T2ª ) objects with bounded aspect ration) and “unclut-
tered” scenes admit a BSP with linear size.21,22
T3+ ← merge(T1+ , T2⊕ ) However, for practical applications, the “hidden”
T3 ← (H1 , T3− , T3+ ) constants do matter. So, the construction strategy
end if should produce “good” BSPs. Depending on the ap-
The function cell-op is the only place where the plication itself, however, the definition of exactly
semantic of the general merge operation is special- what a “good” BSP tree is can be quite different.
ized. When we have reached that point, then we Basically, there are two kinds of applications:
know that one of the two cells is homogeneous, so
• Classification: These are applications where the
we can just replace it by the other node’s sub-tree
BSP is used to determine the inside/outside sta-
suitably modified according to the boolean opera-
tus of a point, or whether or not a line intersects
tion. The following table lists the details of this
with an object.
function (assuming that T1 is the leaf):
In this case, we try to optimize the balancedness T has been visited (dito for P(T + )). This probabil-
of the BSP. ity depends, of course, on the application the BSP
is going to be used for. For instance, in the case of
• Visibility: These are applications where the BSP inside/outside queries
is used to sort the polygons in “visibility order”
such as rendering without z-buffer. Vol(T − )
P(T − ) =
Consequently, we try to minimize the number Vol(T)
of splits, i.e., the size of the BSP.
Obviously, trying to optimize Equation 4 globally
is prohibitively expensive. Therefore, a local heuris-
3.4.1 Convex objects
tic must be employed to guide the splitting process.
As an example, consider an convex object. In that A simple heuristic is the following:69 estimate the
caese, an auto-partition has size O(n), takes time cost of the subtrees by the number of polygons, and
O(n2 ) to construct, and is a linear tree. This does add a penalty for polygons that are split by the cur-
not seem to be a very smart BSP (although it is per- rent node, so that
fectly suitable for visibility ordering).
If we allow arbitrary splitting planes, then we C(T) = 1 + |S− |α + |S+ |α + βs (5)
can balance the BSP much better. The construction
time will be where S is the set of polygons associated with a
node, s the set of polygons split by a node, and
T(n) = n + 2T( n2 + αn) ∈ O(n1+δ ) , 0 < α < n α, β are two parameters that can be used to make
2
the BSP more balanced or smaller. (69 reports that
where α is the fraction of polygons that are split α = 0.8, . . . , 0.95 and β = 41 , . . . , 43 are usually
at each node. The following table shows the actual good values to start from.) Again, this is yields an
complexities for some values of α: optimization process, but now it only a local pro-
cess.
α 0.05 0.2 0.4 If the BSP is to be an auto-partition, then a very
quick approximization of the local optimum yields
n1.15 n2 n7
very good results: just sort the polygons according
to their size and evaluate Equation 5 for the first k
As mentioned above, the question now is how to
polygons. Then, choose the one that produces the
choose the splitting planes. We propose the fol-
least costly BSP (subtree), the rationale being that
lowing simple heuristic:2 Compute a representative
the probability that a polygon gets split is propor-
vertex for each polygon (barycenter, bbox center,
tional to its size, so we try to get rid of them as
etc.). Determine a plane, such that on both sides
early as possible.
are about the same number of points, and such that
An even simpler heuristic was proposed by.36
all points are far away from the plane (obviously,
Randomly choose k polygons from S and select the
this is an optimization).
one that produces the least number of splits. They
report that k = 5 yielded near-optimal BSPs (for
3.4.2 Cost driven heuristic visibility ordering).
In order to derive construction criteria, obviously,
one needs to define the quality of a BSP. An abstract 3.4.3 Non-uniform queries
measure is the cost of a BSP T
In the previous section, we assumed that all queries
C(T) = 1 + P(T − )C(T − ) + P(T + )C(T + ) (4) are uniformly distributed over a certain domain.
This is a valid assumption if nothing is known
where P(T − ) is the probability that the left subtree about the distribution. On the other hand, if we
T − will be visited under the condition that the tree know more about it, then we should make use
of this and construct the BSP such that frequent
queries can be answered most quickly.3
2 For the case of convex objects, a heuristic has already been pro-
posed by.87 However, we believe that their heuristic has some
flaws. 3 The same principle is underlying the Huffman encoding scheme.
Indeed, quite often we know more about the queries. 3.4.4 Deferred, self-organizing BSPs
For instance, in ray tracing, the starting points are
Now, what should we do if we just don’t know the
usually not uniformly distributed in space; for in-
query distribution, or if it is too expensive to mea-
stance, they usually do not emanate from the inte-
sure it by experiments? The answer is, of course,
rior of objects. Also, the prominent polygons of an
to defer the complete construction of the BSP, in
object are hit more frequently than those that are
other words, we only build as much of the BSP that
within cavities or completely inside.
is absolutely necessary. In addition, we keep a his-
According to,1 we can estimate the costs of a
tory (in some form) of all the queries we have seen
query by
so far, so whenever we have to build a new part of
C(query) = # nodes visited the BSP we base the construction on that history
≤ depth(BSP) · # stabbed leaf cells (as a best guess of the probability distribution of all
queries to come).2
So, according to this, we should minimize the num- As an example, let us consider the problem of de-
ber of stabbed leaf cells before a polygon hit occurs. tecting intersections between a 3-dim. line segment
The factors influencing the probability that a ray and a set of polygons.4
hits a polygon are Since a BSP is now no longer completely con-
structed before we use it, the nodes must store ad-
1. If the angle between a ray and a polygon is large, ditional information:
then the probability is large.
1. the polygon P defining the splitting plane; or, if
2. If the polygon is large (relative to the total size
it is a preliminary leaf,
of the object/universe), then the probability is
large. 2. a list L ⊆ S of polygons associated with it, for
which the subtree has not been built yet.
3. . . .
Let ω(l) denote the density of all rays l over some The algorithm for answering queries with a ray R
domain D; this could be measured, or it could be now also triggers the construction of the BSP:
derived from the geometry. Let S be the set of poly- testray(R,ν)
gons over which the BSP is to be built. Assign to if ν is a leaf then
each polygon p a score for all P ∈ Lν do
Z if R intersects P then
return hit
score(p) = w(S, p, l)ω(l)dl end if
D
end for
where the weight w is defined as else
ν1 ← child of ν that contains startpoint of R
Area(p) ν2 ← other child
w(S, p, l) = sin2 (n p , rl )
Area(S) testray(R,ν1 )
if no hit in ν1 then
and n p is the normal of p and rl is the direction of testray(R,ν2 )
l. end if
So the algorithm for constructing a BSP adapted end if
to a given distribution is the following random-
Since the line segment is finite (in particular, if it is
ized greedy strategy: sort all polygons according to
short), this algorithm can usually stop much earlier,
score(p); choose randomly one out of the “top k“
but the details have been omitted here.
and split the set S. Thus, polygons with a higher
The initial BPS is just one node (the root) with
probability of getting hit by the ray tend to end up
L = S, i.e., all polygons of the object or scene.
higher in the tree.
Now we need to fill in the open issues, namely:
The BSP thus constructed has been named cus-
tomized BSP by.1 The authors report that it usu- 4 Sometimes, this is also called “collision detection”, in particular
ally has about 2× as many polygons as its “obliv- in the game programming industry, because we are only inter-
ious” version, but the queries have to visit only ested in a yes/no answer, while in ray tracing we want to deter-
2 − −10× less polygons. mine the earliest intersection.
(which is exhaustive), and a maximally recursive d is any metric, very often just the Euclidean dis-
algorithm. tance.) Let
There are more design choices possible according
to theSdefinition. For inner nodes, it only requires diam(G) = max d(g, f )
g, f ∈G
that Oi = O; this means, that the same object
o ∈ O could be associated with several children. be the diameter of G.
Depending on the application, the type of BVs, and Then we can define tightness
the construction process, this may not always be
avoidable. But if possible, you should always split h(B, G)
τ := .
the set of objects into disjoint subsets. diam(G)
Finally, there is, at least, one more design choice:
the type of BV used at each node. Again, this See Figure 33 for an illustration.
does not necessarily mean that each node uses the Since the Hausdorff distance is very sensitive to
same type of BV. Figure 32 shows a number of the outliers, one could also think of other definitions
most commonly used BVs. The difference between such as the following one:
OBBs6 and AABBs is that OBBs can be oriented ar-
bitrarily (hence “oriented bounding boxes”). Definition 4 (Tightness by volume)
DOPs53,57,99 are a generalization of AABBs: basi- Let C(ν) b the set of children of a node ν of the
cally, they are the intersection of k slabs. Prisms BV hierarchy. Let Vol(ν) be the volume of the BV
and cylinders have been proposed by Barequet et stored with ν.
al.9 and Weghorst et al.,94 but they seem to be too Then, we can define the tightness as
expensive computationally. A spherical shell is the
intersection of a shell and a cone (the cone’s apex Vol(ν)
τ := .
coincides with the sphere’s center), and a shell is ∑ν0 ∈C(ν) Vol(ν0 )
the space between two concentric spheres. Finally,
one can always take the intersection of two or more Alternatively, we can define it as
different types of BVs.52
There are three characteristic properties of BVs: Vol(ν)
τ := ,
∑ν0 ∈L(ν) Vol(ν0 )
• tightness,
• memory usage, where L(ν) is the set of leaves beneath ν.
• number of operations needed to test the query
object against a BV. Getting back to the tightness definition based on
the Hausdorff distance, we observe a fundamental
Often, one has to make a trade-off between these difference between AABBs and OBBs:40
properties: generally, the type of BV that offers
• The tightness of AABBs depends on the orien-
better tightness also requires more operations per
tation of the enclosed geometry. What is worse
query and more memory.
is that the tightness of the children of an AABB
Regarding the tightness, one can establish a the-
enclosing a surface of small curvature is almost
oretical advantage of OBBs. But first, we need to
the same as that of the father.
define tightness.40
The worst case is depicted in Figure 34. The
Definition 3 (Tightness by Hausdorff distance) tightness of the father is τ = h/d, while the
Let B be a BV, G some geometry bounded by B, i.e., h0 h/2
tightness of a child is τ 0 = d/2 = d/2 = τ.
g ⊂ B. Let
• The tightness of OBBs does not depend on the
h(B, G) = max min d(b, g) orientation of the enclosed geometry. Instead,
b∈B g∈G
it depends on its curvature, and it decreases ap-
be the directed Hausdorff distance, i.e., the maxi- proximately linearly with the depth in the hier-
mum distance of B to the nearest point in G. (Here, archy.
Figure 35 depicts the situation for a sphere. The
Hausdorff distance from an OBB to an enclosed
h φ Œ/2
h(B, G) d
diam(G) h
d
G
h0
Figure 33: One way to de- Figure 34: The tightness of an Figure 35: The tightness of an
fine tightness is via the directed AABB remains more or less OBB decreases for deeper lev-
Hausdorff distance. constant throughout the levels els in a OBB hierarchy for small
of a AABB hierarchy for surfaces curvature surfaces.
of small curvature.
spherical arc is h = r(1 − cos φ), while the di- simplification is to just approximate each object by
ameter of the arc is d = 2r sin φ. Thus, the its center (baryenter or bounding box center), and
tightness for an OBB bounding a spherical arc then deal only with sets of points during the con-
1−cos φ struction. Of course, when the BVs are finally com-
of degree φ is τ = 2 sin φ , which approaches 0
linearly as φ → 0. puted for the nodes, then the true extents of the
objects must be considered.
This makes OBBs seem much more attractive In the following we will describe algorithms for
than AABBs. The price of the much improved each construction strategy.
tightness is, of course, the higher computational ef-
fort needed for most queries per node when travers- 4.1.1 Bottom-up
ing an OBB tree with a query.
In this class, we will actually describe two algo-
rithms.
4.1 Construction of BV Hierarchies
Let B be the set of BVs on the top-most level of
Essentially, there are 3 strategies to build BV trees: the BV hierarchy that has been constructed so far.80
For each bi ∈ B find the nearest neighbor bi0 ∈ B;
• bottom-up,
let di be the distance between bi and bi0 . Sort B with
• top-down,
respect to di . Then, combine the first k nodes in B
• insertion
under a common father; do the same with the next
From a theoretical point of view, one could pursue k elements from B, etc. This yields a new set B0 ,
a simple top-down strategy, which just splits the and the process is repeated.
set of objects into two equally sized parts, where Note that this strategy does not necessarily pro-
the objects are assigned randomly to either subset. duce BVs with a small “dead space”: in Figure 36,
Asymptotically, this usually yields the same query the strategy would choose to combine the left pair
time as any other strategy. However, in practice, (distance = 0), while choosing the right pair would
the query times offered by such a BV hierarchy are result in much less dead space.
by a large factor worse. The second strategy is less greedy in that it com-
During construction of a BV hierarchy, it is con- putes a tiling for each level. We will describe it
venient to forget about the graphical objects or first in 2D.62 Again, let B be the set of BVs on the
primitives, and instead deal with their BVs and top-most level so far constructed, with |B| = n.
consider those as the atoms. Sometimes, another
Figure 36: A simple greedy strategy can produce Figure 37: A less greedy strategy combines BVs
much “dead space”. by computing a “tiling”.
The algorithm first computes the center ci for each to be performed on the BV tree. See below for a few
bi ∈ B. Then, it sorts B along the x-axis √ with re- criteria.
spect to c x . Now, the set B is split into n/k vertical
i Usually, algorithms in this class have complexity
“slices” (again with respect to cix ). Now, each slice O(n log n).
is sorted according to ciy and subsequently split into
√
n/k “tiles”, so that we end up with k tiles (see 4.1.3 Top-down
Figure 37). Finally, all nodes in a tile are combined This scheme is the most popular one. It seems to
under one common father, its BV is combined, and produce very good hierarchies while still being very
the process repeats with a new set B0 . efficient, and usually it can be implemented easily.
In Rd it works quite
√ similarly: we just split each The general idea is to start with the complete set
d
slice repeatedly by n/k along all coordinate axes. of elementary BVs, split that into k parts, and cre-
ate a BV tree for each part recursively. The splitting
4.1.2 Insertion is guided by some heuristic or criterion that (hope-
fully) produces good hierarchies.
This construction scheme starts with an empty tree.
Let B be the set of elementary BVs. The following
pseudo-code describes the general procedure: 4.1.4 Construction criteria
1: while |B| > 0 do In the literature, there is a vast number of crite-
2: choose next b ∈ B ria for guiding the splitting, insertion, or merging,
3: ν := root during BV tree construction. (Often, the authors
4: while ν 6= leaf do endow the thus constructed BV hierarchy with a
5: choose child ν0 , new name, even though the BVs utilized are well
so that insertion of b into ν0 causes minimal known.) Obviously, the criterion depends on the
increase in the costs of the total tree
application for which the BV tree is to be used. In
6: ν := ν0
7: end while
the following, we will present a few of these crite-
8: end while ria.
For ray tracing, if we can estimate the probabil-
All insertion algorithms only vary step 2 and/or 5. ity that a ray will hit a child box when it has hit the
Step 2 is important because a “bad” choice in the father box, then we know how likely it is, that we
beginning can probably never be made right after- need to visit the child node when we have visited
wards. Step 5 depends on the type of query that is the father node. Let us assume that all rays em-
anate from the same origin (see Figure 38). Then,
θν for α = x, y, z do
θ ν0 sort B along axis α with respect to the BV centers
find
ν0 ½
Area(b1 , . . . , b j )
kα = min j+
j=0...n Area(B)
ν
¾
Area(b j+1 , . . . , bn )
(n − j)
Area(B)
Figure 38: The probability of a ray hitting a child
end for
box can be extimated by the surface area. choose the best kα
where Area(b1 , . . . , b j ) denotes the surface area of
we can observe that the probability that a ray s hits the BV enclosing b1 , . . . , b j .
a child box ν0 under the condition that it has hit the If the query is a point location query (e.g., is a
father box ν is given point inside or outside the object), then the
volume instead of the surface area should be used.
θ ν0 Area(ν0 ) This is because the probability that a point is con-
P(s hits ν0 |s hits ν) = ≈ (6)
θν Area(ν) tained in a child BV, under the condition that it is
contained in the father BV, is proportional to the
where Area denotes the surface area of the BV, and
ratio of the two volumes.
θ denotes the solid angle subtended by the BV. This
For range queries, and for collision detection, the
is because for a convex object, the solid angle sub-
volume seems to be a good probability estimation,
tended by it, when seen from large distances, is ap-
too.
proximately proportional to its surface area.39 So, a
A quite different splitting algorithm does not
simple strategy is to just minimize the surface area
(explicitely) try to estimate any probabilities. It
of the BVs of the children that are produced by a
just approximates each elementary BV/object by
split.6
its center point. It then proceeds as follows. For
A more elaborate criterion tries to establish a cost
a given set B of such points, compute its princi-
function for a split and minimize that. For ray trac-
pal components (the Eigenvectors of the covariance
ing, this cost function can be approximated by
matrix); choose the largest of them (i.e., the one ex-
Area(ν1 ) Area(ν2 ) hibiting the largest variance); place a plane orthog-
C(ν1 , ν2 ) = C(ν1 ) + C(ν2 ) onal to that principal axis and through the barycen-
Area(ν) Area(ν)
(7) ter of all points in B; finally, split B into two sub-
where ν1 , ν2 are the children of ν. The optimal split sets according to the side on which the point lies.
B = B1 ∪ B2 minimizes this cost function: (This description is a slightly modified version of
Gottschalk et al.40 ) Alternatively, one can place the
C(B1 , B2 ) = min C(B0 , B \ B0 ) splitting plane through the median of all points, in-
B0 ∈P (B) stead of the barycenter. This would lead to balanced
trees, but not necessarily better ones.
where B1 , B2 are the subsets of elementary BVs (or
objects) assigned to the children. Here, we have as-
sumed a binary tree, but this can be extended to 4.1.5 The criterion for collision detection
other arities analogously. In the following, we will describe a general cri-
Of course, such a minimization is too expensive terion that can guide the splitting process of top-
in practice, in particular, because of the recursive down BV hierarchy construction algorithms, such
definition of the cost function. So, Fussell and Sub- that the hierarchy produced is good in the sense of
ramanian,37 Müller et al.,67 and Beckmann et al.10 fast collision detection100 (see Section 4.2).
have proposed the following approximation algo- Let C(A, B) be the expected costs of a node pair
rithm: (A, B) under the condition that we have already de-
termined during collision detection that we need to
6 For the insertion scheme, the strategy is to choose that child traverse the hierarchies further down. Assuming
node whose area is increased least.39
axes, and then selecting the best one. Along each sphere,46,74 OBBs,40 DOPs,57,99 AABBs,58,88,98 and
axis, we consider three cases: both subsets form convex hulls,31 to name but a few.
lower boxes with respect to its parent, both are up- Given two hierarchical BV volume data struc-
per boxes, or one upper and one lower box. tures for two objects A and B, almost all hierar-
In each case, we first try to find a good “seed” chical collision detection algorithms implement the
polygon for each of the two subsets, which is as following general algorithm scheme:
close as possible to the outer border that is perpen- traverse(A,B)
dicular to the splitting axis. Then, in a second pass, if A and B do not overlap then
we consider each polygon in turn, and assign it to return
that subset whose volume is increased least. In or- end if
der to prevent “creeping greediness”,8 we run alter- if A and B are leaves then
natingly through the array of polygons. After good return intersection of primitives
splitting candidates have been obtained for all three enclosed by A and B
axes, we just pick the one with least total volume of else
the subsets. for all children A[i] and B[j] do
traverse(A[i],B[j])
The algorithm and criterion we propose here could
end for
also be applied to construct hierarchies utilizing end if
other kinds of BVs, such as OBBs, DOPs, and even
convex hulls. We suspect that the volume of AABBs This algorithm quickly “zooms in” on pairs of close
would work fairly well as an estimate of the volume polygons. The characteristics of different hierarchi-
of the respective BVs. cal collision detection algorithms lie in the type of
This algorithm has proven to be geometrically BV used, the overlap test for a pair of nodes, and
robust, since there is no error propagation. There- the algorithm for construction of the BV trees.
fore, a simple epsilon guard for all comparisons suf- The algorithm outlined above is essentially a si-
fices. multaneous traversal of two hierarchies, which in-
It can be shown that this algorithm is, under cer- duces a so-called recursion tree (see Figure 40).
tain assumptions,9 in O(n), where n is the number Each node in this tree denotes a BV overlap test.
of polygons.100 Leaves in the recursion tree denote an intersection
test of the enclosed primitives (polygons); whether
or not a BV test is done at the leaves depends on
4.2 Collision Detection how expensive it is, compared to the intersection
Fast and exact collision detection of polygonal ob- test of primitives.
jects undergoing rigid motions is at the core of During collision detection, the simultaneous traver-
many simulation algorithms in computer graphics. sal will stop at some nodes in the recursion tree. Let
In particular, all kinds of highly interactive appli- us call the set of nodes, of which some children are
cations such as virtual prototyping need exact col- not visited (because their BVs do not overlap), the
lision detection at interactive speed for very com- “bottom slice” through the recursion tree (see the
plex, arbitrary “polygon soups”. It is a fundamen- dashed lines in Figure 40).
tal problem of dynamic simulation of rigid bodies, One idea is to save this set for a given pair of ob-
simulation of natural interaction with objects, and jects.63 When this pair is to be checked next time,
haptic rendering. we can start from this set, going either up or down.
Bounding volume trees seem to be a very effi- Hopefully, if the objects have moved only a little
cient data structure to tackle the problem of colli- relative to each other, the number of nodes that
sion detection for rigid bodies. All kinds of differ- need to be added or removed from the bottom slice
ent types of BVs have been explored in the past: is small. This scheme is called incremental hierar-
chical collision detection.
8 This happens, for instance, when the sequence of polygons hap-
pens to be ordered such that each polygon increases one subset’s 5 Voronoi Diagrams
volume just a little bit, so that the other subset never gets a
polygon assigned to.
9 These assumption have been valid in all practical cases we have For a given set of sites inside an area the Voronoi
encountered so far. diagram is a partition of the area into regions of
A A1 1
B C B2 B3 C2 C3 2 3
D E F G D4 D5 E4 E5 F6 F7 G6 G7 4 5 6 7
D6 D7 E6 E7 F4 F5 G4 G5
Figure 40: The recursion tree is induced by the simultaneous traversal of two BV trees.
t
5.3 Generalization of the Voronoi
Diagram
q
5.3.1 Voronoi Diagram and Delaunay
r Triangulation in 3D
q q
q
t t
t
pi pi pi
F T
s s
s r SF r
SF r
Figure 45: Updating DTi−1 after inserting the new site pi . In (ii) the new
Delaunay edges connecting pi to q, r, s have been added, and
edge qr has already been flipped. Two more flips are neces-
sary before the final state shown in (iii) is reached.
5.3.2 Constrained Voronoi diagrams nay triangulation DT(S, L) have been proposed in
Lee and Lin,61 Chew,16 Wang and Schubert92 and
For many applications it is not useful to consider
Wang.91 In Seidel81 and Kao and Mount51 one
neighborship relations without any constraints. For
will find good implementation schemes. An appli-
example, a small distance between two cities may
cation of DT(S, L) to quality mesh generation can
become unimportant if there is a (natural or artifi-
be found in Chew.17
cial) border line between them and the border line
itself should not serve as a new site. To overcome
such problems the concept of constrained Voronoi 5.3.3 Other Types of Generalizations
diagrams was introduced.61 We simply list some of the generalization schemes
Let S be a set of n points in the plane, and let and show examples of some intuitive ones.
L be a set of non-crossing line segments spanned
by S, thus we have |L| ≤ 3n − 6. The segments • Different metrics
in L may be considered as obstacles. The bounded – L1 , a comparison of L1 and L2 is shown in
distance between two points x and y in the plane is Figure 46
defined as follows: – L∞
½
d(x, y) if xy ∩ L = ∅ – Convex distance functions
b(x, y) =
∞ otherwise • Different space
where d stands for the Euclidean distance. In the – On trees and graphs
resulting constrained Voronoi diagram VD(S, L), – Higher dimensions
regions of sites that are close but not visible from
• Weights
each other are separated by segments in L, an ex-
• More general sites
ample is shown in Figure 49.
The exact dual of VD(S, L) may be no longer a – Line segments (see Figure 47).
full triangulation of S (even if S is included) but – Polygonal chains
we can modify VD(S, L) in order to dualize it into • Farthest point Voronoi diagram
a "near to Delaunay" triangulation DT(S, L) that • K-th order Voronoi digram
also includes L. • Colored objects
For every line segment l we proceed as follows:
All sites of the clipped regions to the left of a seg-
5.4 Applications of the Voronoi
ment l build a special Voronoi diagram to the right
and vice versa. The neighborship within these spe- Diagram
cial diagrams lead to additional edges inserted into 5.4.1 Nearest Neighbor or Post Office Problem
the dual of VD(S, L). Note that the endpoints of
the line segments are always neighbors in the new We consider the well-known post office problem.
diagrams and therefore the line segments itself are For a set S of sites in the plane and an arbitrary
inserted (see Figure 49). query point x we want to compute the point of S
Algorithms for computing the constrained Voro- closest to x efficiently.
noi diagram VD(S, L) and the constrained Delau-
Figure 49: The constrained Voronoi diagram VD(S, L) and its dual.
In the field of computational geometry there is a Theorem 8 Given a set S of n point sites in the
general technique for solving such query problems. plane, one can, within O(n2 ) time and storage,
One tries to decompose the query set into classes construct a data structure that supports nearest
so that every class has the same answer. Now for a neighbor queries: for an arbitrary query point x,
single answer we only have to determine its class. its nearest neighbor in S can be found in time
This technique is called locus approach. O(log n).
The Voronoi diagram represents the locus ap-
proach for the post office problem. The classes cor- The simple technique can be easily extended to
respond to the regions of the sites. For a query 3D. There are also more efficient approaches, i.e.,
point x we want to determine its class/region and Edelsbrunner29 constructs a O(log n) search struc-
return its owner. ture for the Voronoi diagram in linear time and
To solve this task a simple technique can be ap- with linear space.
plied. We draw a horizontal line through every ver-
tex of the diagram and sort the lines in O(n log n) 5.4.2 Motion planning
time, see Figure 50. The lines decompose the di- We present a simple application of Voronoi dia-
agram into slabs. For every slab we sort the set grams for computing collision-free paths in polyg-
of crossing edges of the Voronoi diagram in linear onal environments. Let us assume that a two di-
time. Altogether we need O(n2 ) time for the sim- mensional environment with polygonal obstacles
ple construction. is given. For simplicity we assume that a circle-
shaped robot is given and a collision-free path from
s to t should be computed (see Figure 51).
We can solve this problem by computing the
Voronoi diagram VD(S) of the corresponding line
segments. This gives rise to a reasonable solu-
tion. Let us assume that the robot moves between
x
t' t
yt
s' s ys
l
• Consider the closest point s0 ∈ VD(S) to s, re- • Minimum Spanning Tree and
spectively t0 ∈ VD(S) to s. TSP-Heuristic, O(n log n)
• Delete the segments of VD(S) where the robot • Largest empty circle, O(n)
does not fit between the obstacles. • Smallest enclosing circle (square with fixed ori-
• Consider the graph G of the remaining diagram entation), O(n)
together with s0 and t0 . • Smallest color spanning circle (square with fixed
• Compute a path from s0 to t0 in G by standard orientation), O(nk), where k is the number of
graph algorithms. colors
N(p)
|| · ||
|| · ||
Td Id
p
|| · ||
T I N(p) N(pi )
p pi
random border T0 I0
Figure 52: The texture synthesis algorithm pro- Figure 53: Using an image pyramid, the texture
ceeds in scan line order through the texture and synthesis process becomes fairly robust against
considers only the neighborhood around the cur- different scales of detail in the sample images.
rent pixel as shown.
Figure 54: Some results of the texture synthesis algorithm.95 In each pair, the image on the left is the
original one, the one on the right is the (partly) synthesized one.
real-world objects have texture, so it is extremely Of course, images not satisfying these criteria can
important to render them in synthetic worlds, too. be used as textures as well (such as façades), but if
Texture synthesis generally tries to synthesize you want to synthesize such images, then a statis-
new textures, either from given images, from a tical or stochastic approach is probably not feasible.
mathematical description, or from a physical model. In the following, we will describe a stochastic
Mathematical descriptions can be as simple as a algorithm that is very simple, very efficient, and
number of sine waves to generate water ripples, works remarkably well.95 Given a sample image, it
while physical models try to describe the physi- does not, like most other methods, try to compute
cal or biological effects and phenomena that lead to explicitly the stochastic model. Instead, it uses the
some texture (such as patina or fur). In all of these sample image itself, which implicitly contains that
“model-based” methods, the knowledge about the model already.
texture is in the model and the algorithm. The We will use the following terminology:
other class of methods starts with one or more
images; then they try to find some statistical or I = Original (sample) image
stochastic description (explicitely or implicitely) of T = New texture image
these, and finally it generates a new texture from pi = Pixel from I
the statistic.
Basically, textures are images with the following p = Pixel from T to be generated next
properties: N(p) = Neighborhood of p (see Figure 52)
1. Stationary: if a window with the proper size is Initially, T is cleared to black. The algorithm
moved about the image, the portion inside the starts by adding a suitably sized border at the left
window always appears the same. and the top, filled with random pixels (this will be
thrown away again at the end). Then, it performs
2. Local: each pixel’s color in the image depends the following simple loop in scan line order (see
only on a relatively small neighborhood. Figure 52):
Figure 56: Example of a distance field in the plane Figure 57: The vector distance field for the same
for a simple polygon (thick black lines). The dis- polygon as shown on the left. Only a few vectors
tance field inside the polygon is not shown. The are shown, although (in theory) every point of the
dashed lines show the Voronoi diagram for the field has a vector.
same polygon. The thin lines show isosurfaces
for various isovalues.
Figure 58: A network of roads described in the Figure 59: The distance map of these roads. The
plane by a set of edges. distance of each point in the plane from a road
is color coded. It could be used, for example,
to determine the areas where new houses can be
built.
we will describe algorithms for them in the follow- terpolation. Other interpolation methods could, of
ing. More sophisticated representations try to store course, be used as well.
more information at each voxel in order to be able The simplest discrete representation of a DF is
to extract distances quickly from the field.45 the 3D voxel grid. However, for most applications
Since each cell in a discrete distance field stores this is too costly not only in memory utilization but
one signed distance to the surface for only one also in computational efforts. So, usually DFs are
“representative”, the distance of other points must represented using octrees (see Figure 60), because
be interpolated from these values. One simple they are simple to construct and offer fairly good
method is to store exact distances for the nodes (i.e., adaptivity and allow for easy algorithms.35 This
the corners of the voxels), and generate all other representation is called an adaptively sampled dis-
distances in the interior of voxels by trilinear in- tance field (ADF). Actually, the kind of hierarchical
√ √ √ √ √ √
part of matrix 10 3 8 3 10 3 6 5 6 3
√ √ √ √ √ √ √ √
for backward scan 3 6 5 6 3 6 3 2 3 6
√ √ √ √ √ √ √ √
6 5 2 5 6 5 2 1 2 5
√ √ √ √ √ √ √ √
3 6 5 6 3 6 3 2 3 6
√ √ √ √ √ √ √ √
layer 10 10 8 10 10 3 6 5 6 3
-2 -1
-2 0
√ √ √ √
8 5 2 5 4
-1 √ √ √ √
8 2 1 2 5
0
2 1 0 1 2
√ √ √ √
1 5 2 1 2 8
√ √ √ √
5 5 2 5 8
2
1 2
√ √ √ √ √ √
3 6 5 6 3 10 3 8 3 10
Figure 60: Representing distance fields by octrees √ √
6 3
√ √
2 3
√
6 3
√ √
6 5
√
6 3
√ √ √ √ √ √ √ √
has both memory and computational advantages. part of matrix
5 2
√ √
6 3
1
√ √
2 3
2
√
5
6 3
6 5 2
√ √
6 5
√
5 6
6 3
√ √ √ √ √ √ √ √
for forward scan 3 6 5 6 3 10 10 8 10 10
space partitioning is a design parameter of the al- Figure 61: By convoluting a “distance matrix”
gorithm; for instance, BSPs (see Section 3) proba- with an initially binary distance field (0 or ∞ ),
bly offer much more efficient storage at the price of one gets an approximate distance field. Here a
more complex interpolation. 5 × 5 × 5 example of such a matrix is shown.
Constructing ADFs works much like construct-
ing regular octrees for surfaces, except that here, More formally speaking, since we want to com-
we subdivide a cell if the distance field is not well pute the DF only for a discrete set of points in space,
approximated by the interpolation function defined we can reformulate Equation 14 as follows
so far by the cell corners. ©
The following two algorithms for computing DFs D̃S (x, y, z) = min D(x + i, y + j, z + k)
i,j,k∈Z3
produce only flat representations (i.e., grids), but ª (15)
they can be turned into an ADF by coalescing cells +d M (i, j, k)
in a bottom-up manner if the resulting cell still de- where d M is the distance of a node (i, j, k) from
scribes the DF well enough.12 the center node (0, 0, 0). Actually, this is already
a slight approximation of the exact DF.
6.1.1 Propagation method We can now further approximate this by not con-
sidering the infinite “neighborhood” (i, j, k) ∈ Z3 ,
This method bears some resemblance to region grow-
but instead only a local one I ⊂ Z. Since a prac-
ing and flood filling algorithms and is also called
tical computation of D̃S would compute each node
chamfer method. It can produce only approxima-
in some kind of scan order, we choose I such that
tions of the exact DF.
it contains only nodes that have already been com-
The idea is to start with a binary DF, where all
puted by the respective scan. Thus, d M can be pre-
voxels intersecting the surface are assigned a dis-
computed and stored conveniently in a 3-dimen-
tance of 0, and all others are assigned a distance of
sional matrix (see Figure 61).
∞ . Then, we somehow “propagate” these known
This process looks very similar to conventional
values to voxels in the neighborhood, taking advan-
convolution, except that here we perform a mini-
tage of the fact that we already know the distances
mum operation over a number of sums, while the
between neighboring voxels.13 Note that these dis-
conventional convolution performs a sum over a
tances only depend on the local neighborhood con-
number of products.
stellation, no matter where the “propagation front”
Obviously, a single scan will not assign meaning-
currently is.
ful distance values to all nodes, no matter what or-
der the scan preforms. Therefore, we need at least
two scans: for instance, first, a 3D scanline order
from top to bottom (“forward”), and second, back-
wards from bottom to top. In each pass, only one
half of the 3D matrix d M needs to be considered
12Usually, it is faster to compute an ADF top-down, though. (see Figure 61). It could still happen, of course, that
13This idea has been proposed as early as 1984,13 and maybe even there are still nodes with distance ∞ in the respec-
earlier. tive part of the chamfer matrix.
Figure 62: The distance func- Figure 63: More complex sites Figure 64: The distance func-
tion of a point site in the plane have a bit more complex dis- tion of sites in 3D is different
is a cone.44 tance functions. for the different slices of the
volume.
The time complexity of this method is in O(m), The key technique applied in this approach is to
m = number of voxels. However, the result is only embed the problem into more dimensions than are
an approximation of the distance field; in fact, the inherent in the input/output itself. This is a very
accuracy of the distance values can be pretty low.14 general technique that often helps to get a better
In order to further improve accuracy, one can and simpler view on a complex problem.
make a few more passes, not only from top to bot- The method described in the following was pre-
tom and back, but also from left to right, etc. An- sented by Hoff et al.,44 and, from a different point
other option is to increase the size of d M . of view, by Sethian.83
Analogously, an approximate vector distance field Let us consider the distance field of a single point
can be computed.50 In that case, the matrix d M con- in 2D. If we consider this a surface in 3D, then we
tains vectors instead of scalars. In order to improve get a cone with the apex in that point. In other
the accuracy, we can proceed in two steps: first, for words, the distance field of a point in a plane is just
each voxel in the neighborhood of the surface (usu- the orthogonal projection of suitable cone onto the
ally just the 33 -neighborhood) we compute vec- plane z = 0.
tors to the exact closest point on the surface; then, Now, if there are n point sites in the plane, we
this shell is propagated by several passes with the get n cones, so each point in the plane will be “hit”
vector-valued matrix d M . The time for computing by n distance values from the projection (see Fig-
the exact distance shell can be optimized by utiliz- ure 62). Obviously, only the smallest one wins
ing an octree or BV hierarchy for closest point com- and gets “stored” with that point — and this is ex-
putation, and initializing each search with the dis- actly what the z-buffer of graphics hardware was
tance (and vector) to the closest point of a nieghbor designed for.
voxel. These cones are called the distance function for
a point. The distance function for other features
6.1.2 Projection of distance functions (line segments, polygons, curves) is a little bit more
complicated (see Figure 63).
The previous method can be applied to all kinds of So, computing a discrete DF for a set of sites in
surfaces S. However, it can produce only very gross the plane can be done by rendering all the asso-
approximations. In the following, we describe a ciated distance functions (represented as polygonal
method that can produce much better approxima- meshes) and reading out the z-buffer (and possibly
tions. However, it can be applied only to polygonal the frame buffer if we also want the site IDs, i.e.,
surfaces S. discretized Voronoi regions). If we want to com-
pute a three-dimenional DF, then we proceed slice-
by-slice. One noteworthy catch, though, is that the
14Furthermore, the distance values are not even an upper bound
distance functions of the sites changes from slice to
on the real distance. slice. For instance, the distance function for a point
6.2.1 Morphing
Figure 65: By specifying correspondences, the
One interesting application of DFs is morphing, i.e.,
user can identify feature points that should transi-
the problem of finding a “smooth” transition from
tion into each other during the morph.20
a shape S ⊂ Rd to a shape T ⊂ Rd , i.e., we are
looking for a shape transformation M(t, Rd ), t ∈
[0, 1], such that M(0, S) = S, M(1, S) = T. to each other, there will be in-between models that
Sometimes, there is a bit of confusion about terms: almost vanish.
sometimes, morphing refers to any smooth transi- Therefore, in addition to the DF interpolation, we
tion, sometimes it refers only to those transitions usually want to split the morphing into two steps
that are bijective, continuous, and have a continu- (for each t): first, S is warped by some function
ous inverse. In the latter case, the term morphing W(t, x) into S0 , then DS0 and DT are interpolated,
is equivalent to the notion of homeomorphism in i.e., M(t, S) = tDW(t,S) + (1 − t)DT .
the area of topology, and the term metamorpho- The idea of the warp is that it encodes the ex-
sis is used to refer to the broader definition. The pertise of the user who usually wants a number of
difference between a homeomorphism and a meta- prominent feature points from S to transition onto
morphosis is that the former does not allow to cut other feature points on T. For instance, she wants
or glue the shape during the transition (this would the corresponding tips of nose, fingers, and feet of
change the topology). two different characters transition into each other.
In the following, we will describe a simple method Therefore, the user has to specify a small number
for metamorphosis of two shapes given as volumet- of correspondences (p0,i , p1,i ), where p0,i ∈ S, and
ric models; it was presented by Cohen-Or et al.20 p1,i ∈ T (see Figure 65). Then, we determine a
The nice thing about a volumetric representation is warp function W(t, x) such that W(1, p0,i ) = p1,i .
that it can naturally handle genus changes (i.e., the Since the warp function should distort S as little
number of “holes” in S and T is different). as possible (just “align” them), we can assemble it
In the simplest form, we can just interpolate lin- from a rotation, then a translation, and finally an
early between the two DFs of S and T yielding a elastic part that is not a linear transformation:
new DF ¡ ¢¡ ¢
W(t, x) = (1 − t)I + tE R(a, tθ)x + tc (17)
M(t, S) = J(t, S, T) = tDS + (1 − t)DT . (16)
where E is the elastic transformation, R(a, θ) is a
In order to obtain a polygonal representation, we rotation about axis a and angle θ, and c is the trans-
can compute the isosurface for the value 0. lation.
This works quite well, if S and T are “aligned” The rotation and translation of the warp function
with each other (in an intuitive sense). However, can be determined by least-squares fitting, while
when morphing two sticks that are perpendicular the elastic transformation can be formulated as a
2 2
1 1
0 0
-1 -1
-2 2 -2
1
0
-1
-2
Figure 66: Example of differ- Figure 67: Example of a 3D dif- Figure 68: Close-up view show-
ence of two DFs. On the left, ference operation.14 ing the adaptivity.
the two DFs for tool and ob-
ject are shown superimposed;
on the right, the result is shown.
scattered data interpolation problem. One method Figure 66 shows an example of the difference oper-
that has proven quite robust is the approach using ation.
radial basis functions. The interested reader will If ADFs are used for representation of the DFs,
find the details in Cohen-Or et al.20 then a recursive procedure has to be applied to
the object’s ADF in order to compute the resulting
6.2.2 Modeling ADF. It is similar to the generation of ADFs (see
above), except that here the subdivision is governed
A frequently used modeling paradigm in CAD is by the compliance of new object ADF with the tool
volumetric modeling, which means that objects are, ADF: a cell is further subdivided if it contains cells
conceptually, defined by specifying for each point from the tool ADF that are smaller, and if the tri-
whether or not it is a member of the object. the ad- linear interpolation inside the cell does not approx-
vantage is that it is fairly simple to define Boolean imate well enough the ADF of the tool.
operations on such a representation, such as union,
subtraction, and intersection. Examples of vol-
umetric modeling is constructive solid geometry 7 Dynamization of Geometric
(CSG) and voxel-based modeling. The advantage
of using distance fields for volumetric modeling is
Data Structures
that they are much easier to implement than CSG,
We present a generic approach for the dynamiza-
but provide much better quality than simple voxel-
tion of an arbitrary static geometric data structure.
based approaches.
Often a simple static data structure is sufficient if
Computing the Boolean operation on two DFs
the set of represented geometric objects will have
basically amounts to evaluating the appropriate op-
few changes over time. Once created, the static
erator on the two fields. The following tables gives
structure mostly has to cope with data queries due
these operators for a field DO (for the object) and a
to its geometric intention. If the set of objects
field DT (for the tool):
varies very much over time, there is need for more
complex dynamic structures which allow efficient
Boolean op. operator on DF insertion and deletion of objects.
¡ ¢
Union DO∪T = min DO , DT For example a one dimensional sorted array of
¡ ¢ a fixed set M is sufficient for x is Element of M
Intersection DO∩T = max DO , DT
¡ ¢ queries. But if the set M has many changes over
Difference DO−T = max DO , −DT
time, a dynamic AVL-tree would be more likely.
The AVL-tree implementation is more complex
since rotations of the tree has to be considered for The dynamization module should export a dy-
insertion and deletion of objects. Additionally, the namic abstract (geometric) data type TDyn with
AVL-tree dynamization was invented for the spe- the following operations:
cial case of the one-dimenional search. We want
to show that it is possible to dynamize a simple Build(W, D): Build the structure W of type
static data structure indirectly but also efficiently TDyn with data objects in
in a general setting. Once this generic approach the set D.
is implemented it can be used for many static data Query(W, q): Gives the answer (objects of D) to
structures. a query to W with query object q.
The generic approaches presented here are not
Extract(W, D): Collects all data objects D of W
optimal against a dynamization adapted directly to
in a single set and returns a
a single data structure, but they are easy to imple-
pointer this set.
ment and efficient for many applications.
In Section 7.1 we formalize the given problem Erase(W): Delete the complete data
and define some requirements. In Section 7.2 we structure W from the storage.
present methods allowing insertion and deletion in Insert(W, d): Insert object d into W.
amortized efficient time. For many applications this
Delete(W, d): Delete d out of W.
is already efficient enough. Within this section
the dynamization technique is explained in detail Note, that the new operations Delete and Insert
and the amortized cost of the new operations are are necessary since we have a dynamic data type
shown. Similar ideas for the worst-case sensitive now.
approach are sketched in Section 7.3. The effort Additionally, we introduce some cost functions
of the dynamization itself is amortized over time. for the operations of the abstract dynamic and the
For details see Klein55 or the work of Overmars72 abstract static data type. For example let BV (n) de-
and van Kreveld.89 We present a simple example in notes the time function for the operation Build(V, D)
Section 7.4. of TStat. The notations are fully presented in Fig-
ure 69. The cost functions depend on the imple-
7.1 Model of the Dynamization mentation of TStat. Note, that the cost function of
TDyn will depend on the cost functions of TStat
Let us assume that TStat is a static abstract (geo-
together with the efficiency of the our general dy-
metric) data type. Since we have a geometric data
namization.
structure, we assume that the essential motivation
of TStat is a query operation on the set of stored
Modul
objects D. i.e., for a query object q the answer is Dynamize
always a subset of D which might be empty.
We want to define the generic dynamization by a
module that imports the following operations from K
Export Import
TStat: ®
Comp.: ADT TDyn
build(V, D): Build the structure V of type
ADT TStat Comp.:
TStat with all data objects in the
BW (n) Build(W, D)
set D.
QW (n) Query(W, q) build(V, D) BV (n)
query(V, q): Gives the answer (objects of D) to EW (n) Extract(W, D) query(V, q) QV (n)
a query to V with query object q. IW (n) Insert(W, d) extract(V, D) EV (n)
extract(V, D): Collects all data objects D of V in DW (n) Delete(W, d)
a single set an returns a pointer to Space.: SW (n) Space: SV (n)
this set.
erase(V): Delete the complete data structure Figure 69: Dynamization in the generic sense.
V from the storage.
In order to guarantee some bounds for the corre-
sponding cost functions of TDyn the cost functions
Insert(W, d) : Extract(W, D); Build(W, D ∪ {d}) BW (n) ∈ O(n + BV (n)) = O(BV (n))
Delete(W, d) : Extract(W, D); Build(W, D \ {d}). since BV (n) is at least linear.
Similar results hold for some other operations.
This throw-away implementation is not very ef-
We can prove
ficient. Therefore we distribute the n data objects of
the static structure V among several structures Vi . EW (n) ≤ log n EV (n)
If a new element has to be inserted we hope that
only a single structure Vi may be concerned. Let the results of extraxt(Vi ) for at most log n struc-
tures Vi .
Additionally,
n = al 2l + al−1 2l−1 + . . . + a1 2 + a0 mit ai ∈ {0, 1}.
QW (n) ≤ log n Qv (n)
Then al al−1 . . . a1 a0 is the binary representation
of n. For every ai = 1 we build a structure Vi which holds if we assume that the query can be decompose
has 2i elements. The collection of these structures as well, see the requirements.
is a representation of Wn which is called binary It is also easy to see that
structure (see Figure 70). To build up the binary
blog nc
structure Wn we proceed as follows:
SW (n) ≤ ∑ SV (2i ) ∈ O(SV (n)).
i=0
V4 V4
4
2
V3
23
V2
22
V1
21
V0
20
W23 W24
Figure 70: The binary structure Wn contains the structure Vi if ai = 1 holds for the
binary representation of n. For examples see n = 23 (left) and n = 24
(right).
Therefore it remains to analyse IW (n). Note, that this is not an expected value and that
As we have seen from Figure 70 sometimes the W is a function of s, i.e., the length of the operation
whole structure of Wn is destroyed when Wn+1 was sequence. The current data set may have a number
build up. In this example we had to perform the of elements n ≤ s.
following tasks: For the Insert(W, d) operation one can prove
µ ¶
extract(V0 , D0 ); extract(V1 , D1 ); extract(V2 , D2 ); log s
I W (s) ∈ O BV (s) .
D := D0 ∪ D1 ∪ D2 ∪ {d}; s
build(V3 , D);
Note, that except insertions there are only queries
In general we have to build up Vj and extract and in s. Queries do not change the size of the data set
erase Vj−1 , Vj−2 , . . ., V0 only if ai = 1 holds for and so we can also replace s by the number of in-
i = 0, 1 . . . , j − 1 and a j = 0 holds (in the binary sertions here.
representation of the current n). Altogether, the results are presented in the fol-
In this special case we have lowing theorem.
à !
j−1
Theorem 11 A static abstract data type as pre-
IW (n) ≤ ∑ EV (2i ) + Cj + BV (2 j )
sented in Figure 69 can be dynamized by means
i=0
of the binary structure in a dynamic abstract data
≤ EV (2 j ) + Cj + BV (2 j ) type TDyn so that the operation Insert(W, d) is
³ ´
∈ O BV (2 ) .j performed in amortized time
µ ¶
log s
For a long sequence of insertions many of them I W (s) ∈ O BV (s) .
are performed without extreme reconstructions. Thus s
the effort for all Insert(W, d) is amortized over Let n be the size of the current data set. We have
time.
Generally, let Work be an arbitrary operation SW (n) ∈ log n Sv (n)
with cost function W. For a sequence of s differ- BW (n) ∈ BV (n))
ent operations let Work be applied k times. If
QW (n) ∈ log n Qv (n).
total cost of k Work operationen
≤ W(s)
k 7.2.2 Amortized Delete: Occasional
Reconstruction
holds for a monotonically increasing cost function
W, we say that the operation Work is performed in Assume that we did not have implemented the Insert
amortized time W(s). operation, yet.
If we have to delete an object we can not choose the binary structure for the insertion. The opera-
its location beforehand. Therefore the deletion of tion weak.delete is only available for the structures
an objects is much more difficult than the insertion. Vi and we have to extend it to W in order to apply
Deletion may cause fundamental reconstruction. the result of Section 7.2.2. If Weak.Delete(W, d) is
For many data structures it is easier to simply applied, d should be marked as deleted in W. But
mark an object as deleted. Physically the object re- we do not know in which of the structures Vi the
mains in the structure but does no longer belong to element d lies. Therefore in addition to the binary
the data set D. These objects have bad influence on structure we construct a balanced searchtree T that
the running time of all operations although they stores this information. For every d ∈ W there is a
are no longer necessary. Therefore from time to pointer to the structure Vi with d ∈ Vi , an example
time we have to reconstruct the data structure for is shown in Figure 71.
the actual data set. The additional cost of the search tree T is covered
First of all, for TStat we introduce an addi- as follows. Query operations are not involved. For
tional operation weak.delete(V, d) with cost func- Weak.Delete(W, d) there is an additional O(log n)
tion WDV (n). We simply want to construct a for searching the corresponding Vi and for marking
strong delete function with an acceptable amortized d as deleted in Vi .
time bound for TDyn. If an object d has to be inserted we have to up-
Therefore we use weak.delete(V, d) until D has date T. The object d gets an entry for its struc-
only the half size of V. Then we erase V and build ture Vj in T, this is done in time O(log n) and it
a new structure V out of D. The cost of the oc- will not affect the time bound for the insertion.
casional reconstruction is amortized over the pre- But furthermore if V0 , . . . , Vj−1 has to be erased
ceeding delete-operations. This gives the following the corresponding objects should point to Vj after-
result. wards. This can be efficiently realized by collecting
the pointers of T to Vi in a list for every Vi . We
Theorem 12 A static abstract data type as pre- collect the pointers and change them to "‘Vj "’. This
sented in Figure 69 with an additional operation operation is already covered by time O(BV (2 j )) for
weak.delete(V, d) and with additional cost func- constructing Vj .
tion WDV (n) can be dynamized by means of oc- Altogether we conclude:
casional reconstruction in a dynamic abstract data
type TDyn so that Theorem 13 A static abstract data type as pre-
sented in Figure 69 with an additional operation
BW (r) = BV (r) weak.delete(V, d) and with additional cost function
EW (r) ∈ O (EV (r)) WDV (n) can be dynamized by means of binary
QW (r) ∈ O (QV (r)) structure, searchtree T and occasional reconstruc-
tion in a dynamic abstract data type TDyn so that
SW (r) ∈ O (SV (r))
µ ¶ the amortized time for insertion reads
B (s)
DW (s) ∈ O WDV (s) + V , µ
B (s)
¶
s I W (s) ∈ O log s V ,
s
holds. The size of the current actual data set is de-
noted with r and s denotes the length of the opera- and the amortized time for deletion reads
tion sequence. µ ¶
B (s)
DW (s) ∈ O log s + WDV (s) + V .
We omit the proof here. s
For the rest of the operations we have
7.2.3 Amortized Insert and Amortized Delete
BW (r) = BV (r)
In the preceeding sections we have discussed Insert
and Delete separately. Now we want to show how EW (r) ∈ O (log r EV (r))
to combine the two approaches. QW (r) ∈ O (log r QV (r))
A static abstract data type with a weak delete im- SW (r) ∈ O (SV (r)) .
plementation is given. As in Section 7.2.1 we use
1 2 3 4 5 6 7 8 V3
9 10 11 12 V2
T
13 14 V1
15 V0
Figure 71: A structure W15 with a searchtree T storing pointers to Vi for every d ∈ Vi .
The size of the current actual data set is denoted 7.4 A Simple Example
with r and s denotes the length of the operation
For convenience, we take a simple example from
sequence.
Section 2 and apply Theorem 14, thus implement-
ing worst-case sensitive insertion and deletion.
7.3 Worst-Case sensitive Insert and In Section 2.2 an easy implementation of the
Delete static k-d-tree was presented with
√ Sk-d (n) = O(n)
and query time Qk-d (n) = O( n + a), where a
In the last section we have seen that it is easy to
represents the size of the answer (see Theorem 4).
amortize the cost of Insert and Delete analytically
Obviously, weak.delete(k-d, x) can be implemented
over time. The main idea for the construction of
in O(log n) time, thus we obtain WDk-d (n) =
the dynamic data structure was given by the binary
O(log n). Additionally we have Bk-d (n) = O(n log n).
structure of Wn which has fundamental changes
Let Dyn(k-d) denote the dynamic variant based
from time to time but the corresponding costs were
upon the statically implemented k-d-tree.
amortized. Now we are looking for the worst-
Application of Theorem 14 results in:
case cost of Insert and Delete. The idea is to dis-
tribute the construction of Vj itself over time, i.e., Build(Dyn(k-d), D) ∈ O(n
the structure Vj should be finished if Vj−1 , Vj−2 , . . . √log n)
Query(Dyn(k-d), q) ∈ O(³ n log´n + a)
V0 has to be erased.
We only refer to the result of this approach. The Insert(Dyn(k-d), d) ∈ O log2 n
ideas are very similar to the ideas of the preceed- Delete(Dyn(k-d), d) ∈ O (log n)
ing sections. Technically, a modified binary repre- Space O(n).
sentation is used in order to distribute the effort
of the reconstruction over time. For the interested
reader we refer to Klein55 or van Kreveld89 and
References
Overmars.72
[1] S. Ar, B. Chazelle, and A. Tal, Self-
Customized BSP Trees for Collision Detection,
Theorem 14 A static abstract data type as pre- Computational Geometry: Theory and Applica-
sented in Figure 69 with an additional operation tions, 15 (2000), pp. 91–102.
weak.delete(V, d) and with additional cost function
[2] S. Ar, G. Montag, and A. Tal, Deferred,
WDV (n) can be dynamized in a dynamic abstract
Self-Organizing BSP Trees, in Eurographics, Sept.
data type TDyn so that 2002, pp. 269–278. http://www.ee.technion.
ac.il/~ayellet/papers.html.
Build(W, D) ∈ O(BV (n))
Query(W, q) ∈ O(log [3] J. Arvo and D. B. Kirk, Fast Ray Trac-
³ n · QV (n))
´ ing by Ray Classification, in Computer Graphics
log n
Insert(W, d) ∈ O n BV (n) (SIGGRAPH ’87 Proceedings), M. C. Stone, ed.,
³ ´
BV (n) vol. 21, July 1987, pp. 55–64.
Delete(W, d) ∈ O log n + WDV (n) + n
Space O(SV (n)). [4] F. Aurenhammer, Voronoi diagrams: A sur-
vey of a fundamental geometric data structure,
ACM Comput. Surv., 23 (1991), pp. 345–405.
Here n denotes the number of relevant, stored
data objects.
[52] N. Katayama and S. Satoh, The SR-tree: Detail Rendering of Height Fields, in SIGGRAPH
An Index Structure for High-Dimensional Near- 96 Conference Proceedings, H. Rushmeier, ed.,
est Neighbor Queries, in Proc. ACM SIGMOD ACM SIGGRAPH, Aug. 1996, pp. 109–118. held
Conf. on Management of Data, 1997, pp. 369–380. in New Orleans, Louisiana, 04-09 August 1996.
[53] T. L. Kay and J. T. Kajiya, Ray Trac- [65] P. Lindstrom and V. Pascucci, Visual-
ing Complex Scenes, in Computer Graphics (SIG- ization of Large Terrains Made Easy, in Proc. IEEE
GRAPH ’86 Proceedings), D. C. Evans and R. J. Visualization, San Diego, 2001.
Athay, eds., vol. 20, Aug. 1986, pp. 269–278. [66] W. E. Lorensen and H. E. Cline,
[54] R. Kimmel, N. Kiryati, and A. M. Marching Cubes: A High Resolution 3D Surface
Bruckstein, Multi-Valued Distance Maps for Construction Algorithm, in Computer Graphics
Motion Planning on Surfaces with Moving Obsta- (SIGGRAPH ’87 Proceedings), M. C. Stone, ed.,
cles, IEEE Transactions on Robotics and Automa- vol. 21, July 1987, pp. 163–169.
tion, 14 (1998), pp. 427–436. [67] G. Mller, S. Schfer, and W. D. Fell-
[55] R. Klein, Algorithmische Geometrie, Addison- ner, Automatic Creation of Object Hierarchies
Wesley, Bonn, 1997. http://www.oldenbourg. for Radiosity Clustering, Computer Graphics Fo-
de/cgi-bin/rotitel?T=24382. rum, 19 (2000). ISSN 0167-7055.
[56] R. Klein, A. Schilling, and [68] B. Naylor, J. Amanatides, and
W. Straer, Reconstruction and simplification W. Thibault, Merging BSP Trees Yields Poly-
of surfaces from contours, in Pacific Graphics, hedral Set Operations, in Computer Graphics
1999, pp. 198–207. http://cg.cs.uni-bonn. (SIGGRAPH ’90 Proceedings), F. Baskett, ed.,
de/publications/publication.asp?id=31. vol. 24, Aug. 1990, pp. 115–124.
[57] J. T. Klosowski, M. Held, J. S. B. [69] B. F. Naylor, A Tutorial on Binary Space
Mitchell, H. Sowrizal, and K. Zikan, Partitioning Trees, ACM SIGGRAPH ’96 Course
Efficient Collision Detection Using Bounding Vol- Notes 29, (1996).
ume Hierarchies of k-DOPs, IEEE Transactions on
[70] M. Novotni and R. Klein, A Geometric
Visualization and Computer Graphics, 4 (1998),
Approach to 3D Object Comparison, in Interna-
pp. 21–36.
tional Conference on Shape Modeling and Appli-
[58] T. Larsson and T. Akenine-Mller, cations, May 2001, pp. 167–175.
Collision Detection for Continuously Deforming
[71] R. Osada, T. Funkhouser,
Bodies, in Eurographics, 2001, pp. 325–333. short
B. Chazelle, and D. Dobkin, Matching
presentation.
3D models with shape distributions, in Pro-
[59] J.-C. Latombe, Robot Motion Planning, ceedings of the International Conference on
Kluwer Academic Publishers, Boston, 1991. Shape Modeling and Applications (SMI-01),
[60] C. L. Lawson, Software for C1 surface inter- B. Werner, ed., Los Alamitos, CA, May 7–11 2001,
polation, in Math. Software III, J. R. Rice, ed., Aca- pp. 154–166.
demic Press, New York, NY, 1977, pp. 161–194. [72] M. H. Overmars, The Design of Dynamic
[61] D. T. Lee and A. K. Lin, Generalized De- Data Structures, vol. 156 of Lecture Notes Com-
launay Triangulation for Planar Graphs, Discrete put. Sci., Springer-Verlag, Heidelberg, West Ger-
Comput. Geom., 1 (1986), pp. 201–217. many, 1983.
[62] S. Leutenegger, J. Edgington, and [73] D. W. Paglieroni, Distance Transforms:
M. Lopez, STR : A Simple and Efficient Algo- Properties and Machine Vision Applications,
rithm for R-Tree Packing, in Proceedings of the CVGIP: Graphical Models and Image Processing,
13th International Conference on Data Engineer- 54 (1992), pp. 56–74.
ing (ICDE’97), Washington - Brussels - Tokyo, [74] I. J. Palmer and R. L. Grimsdale, Colli-
Apr. 1997, pp. 497–507. ISBN 0-8186-7807-0. sion Detection for Animation using Sphere-Trees,
[63] T.-Y. Li and J.-S. Chen, Incremental 3D Computer Graphics Forum, 14 (1995), pp. 105–
Collision Detection with Hierarchical Data Struc- 116. ISSN 0167-7055.
tures, in Proc. VRST ’98, Taipei, Taiwan, Nov. [75] M. S. Paterson and F. F. Yao, Effi-
1998, ACM, pp. 139–144. cient binary space partitions for hidden-surface
[64] P. Lindstrom, D. Koller, W. Rib- removal and solid modeling, Discrete Comput.
arsky, L. F. Hughes, N. Faust, and Geom., 5 (1990), pp. 485–503.
G. Turner, Real-Time, Continuous Level of
[76] B. A. Payne and A. W. Toga, Dis- [88] G. van den Bergen, Efficient Collision
tance field manipulation of surface models, IEEE Detection of Complex Deformable Models using
Computer Graphics and Applications, 12 (1992), AABB Trees, Journal of Graphics Tools, 2 (1997),
pp. 65–71. pp. 1–14.
[77] F. P. Preparata and M. I. Shamos, [89] M. J. van Kreveld, New Results on Data
Computational Geometry: An Introduction, Structures in Computational Geometry, ph.D.
Springer-Verlag, New York, NY, 1985. dissertation, Dept. Comput. Sci., Utrecht Univ.,
Utrecht, Netherlands, 1992.
[78] V. T. Rajan, Optimality of the Delaunay tri-
angulation in Rd , in Proc. 7th Annu. ACM Sym- [90] M. Wan, F. Dachille, and A. Kauf-
pos. Comput. Geom., 1991, pp. 357–363. man, Distance-field based skeletons for virtual
navigation, in Proceedings of the conference on
[79] J. Revelles, C. Urena, and M. Las- Visualization 2001, 2001, pp. 239–246. ISBN 0-
tra, An Efficient Parametric Algorithm for Oc- 7803-7200-X.
tree Traversal, in WSCG 2000 Conference Pro-
ceedings, University of West Bohemia, Plzen,
[91] C. A. Wang, Efficiently updating the con-
strained Delaunay triangulations, BIT, 33 (1993),
Czech Republic, 2000. http://visinfo.zib.de/
pp. 238–252.
EVlib/Show?EVL-2000-307.
[92] C. A. Wang and L. Schubert, An optimal
[80] N. Roussopoulos and D. Leifker, algorithm for constructing the Delaunay triangu-
Direct spatial search on pictorial databases using
lation of a set of line segments, in Proc. 3rd Annu.
packed R-trees, in Proceedings of ACM-SIGMOD
ACM Sympos. Comput. Geom., 1987, pp. 223–
1985 International Conference on Management of
232.
Data, May 28–31, 1985, LaMansion Hotel, Austin,
Texas, S. Navathe, ed., New York, NY 10036, USA, [93] D. F. Watson, Computing the n-Dimensional
1985, pp. 17–31. ISBN 0-89791-160-1. http:// Delaunay Tesselation with Applications to
www.acm.org/pubs/articles/proceedings/ Voronoi Polytopes, Comput. J., 24 (1981),
mod/318898/p17-roussopoulos/ pp. 167–172.
p17-roussopoulos.pdf;http://www.acm. [94] H. Weghorst, G. Hooper, and D. P.
org/pubs/citations/proceedings/mod/ Greenberg, Improved Computational Meth-
318898/p17-roussopoulos/. ods for Ray Tracing, ACM Transactions on Graph-
ics, 3 (1984), pp. 52–69.
[81] R. Seidel, Constrained Delaunay triangula-
tions and Voronoi diagrams with obstacles, Tech- [95] L.-Y. Wei and M. Levoy, Fast Texture
nical Report 260, IIG-TU Graz, Austria, 1988. Synthesis Using Tree-Structured Vector Quanti-
zation, in Siggraph 2000, Computer Graphics Pro-
[82] J. A. Sethian, An Analysis of Flame Propaga- ceedings, K. Akeley, ed., Annual Conference Se-
tion, PhD thesis, Dept. of Mathematics, University ries, 2000, pp. 479–488. http://visinfo.zib.
of California, Berkeley, 1982. http://visinfo. de/EVlib/Show?EVL-2000-87.
zib.de/EVlib/Show?EVL-1982-2.
[96] J. Wilhelms and A. V. Gelder, Octrees
[83] , Level Set Methods, Cambridge University for Faster Isosurface Generation Extended Ab-
Press, 1996. http://visinfo.zib.de/EVlib/ stract, in Computer Graphics (San Diego Work-
Show?EVL-1996-149. shop on Volume Visualization), vol. 24, Nov. 1990,
[84] , Level set methods and fast marching pp. 57–62.
methods, Cambridge University Press, 1999. [97] C. Youngblut, R. E. Johnson,
[85] M. I. Shamos, Computational Geometry, S. H. Nash, R. A. Wienclaw, and
ph.D. thesis, Dept. Comput. Sci., Yale Univ., New C. A. Will, Different Applications of
Haven, CT, 1978. Two-Dimensional Potential Fields for Vol-
ume Modeling, Tech. Rep. UCAM-CL-TR-
[86] M. Tanemura, T. Ogawa, and 541, University of Cambridge, Computer
W. Ogita, A New Algorithm for Three- Laboratory, 15 JJ Thomson Avenue, Cam-
Dimensional Voronoi Tesselation, J. Comput. bridge CB3 0FD, United Kingdom, Aug. 2002.
Phys., 51 (1983), pp. 191–207. http://www.cl.cam.ac.uk/users/nad/pubs/.
[87] E. Torres, Optimization of the Binary Space [98] G. Zachmann, Real-time and Exact Collision
Partition Algorithm (BSP) for the Visualization of Detection for Interactive Virtual Prototyping, in
Dynamic Scenes, in Eurographics ’90, C. E. Van- Proc. of the 1997 ASME Design Engineering Tech-
doni and D. A. Duce, eds., Sept. 1990, pp. 507–518. nical Conferences, Sacramento, California, Sept.
1997. Paper no. CIE-4306.
[99] , Rapid Collision Detection by Dynamically China, Nov.11–13 2002, pp. 121–128. http://
Aligned DOP-Trees, in Proc. of IEEE Virtual Real- www.gabrielzachmann.org/.
ity Annual International Symposium; VRAIS ’98, [101] B. Zhu and A. Mirzaian, Sorting does not
Atlanta, Georgia, Mar. 1998, pp. 90–97. always help in computational geometry, in Proc.
3rd Canad. Conf. Comput. Geom., Aug. 1991,
[100] , Minimal Hierarchical Collision Detection, pp. 239–242.
in Proc. ACM Symposium on Virtual Reality
Software and Technology (VRST), Hong Kong,