i
i
i
i
i
i
i
i
14.1. Spatial Data Structures 649
height, h, of a balanced tree is log
k
n,wheren is the total number of
nodes (internal and leaves) in the tree.
A full tree is one where all leaf nodes are at the same height, h.Some
properties of (only) full trees follow. The total number of nodes can be
computed as a geometric sum:
n = k
0
+ k
1
+ ...k
h−1
+ k
h
=
k
h+1
− 1
k − 1
. (14.1)
Thus, the number of leaf nodes, l,isl = k
h
, and the number of internal
nodes, i,isi = n−l =
k
h
−1
k−1
. Assuming that only the number of leaf nodes,
l, is known, then the total number of nodes is n = i + l =
kl−1
k−1
.Fora
binary tree, where k =2,thisgivesn =2l −1. Note that a higher k gives a
tree with a lower height, which means that it takes fewer steps to traverse
the tree, but it also requires more work at each node. The binary tree is
often the simplest choice, and one that gives good performance. However,
there is evidence that a higher k (e.g., k =4ork = 8) gives slightly better
performance for some applications [731]. Using k =2,k =4,ork =8
makes it simple to construct trees; just subdivide along the longest axis for
k = 2, and for the two longest axes for k = 4, and for all axes for k =8. It
is much more difficult to form optimal trees for other values of k.
BVHs are also excellent for performing various queries. For example,
assume that a ray should be intersected with a scene, and the first inter-
section found should be returned. To use a BVH for this, testing starts at
the root. If the ray misses its BV, then the ray misses all geometry con-
tained in the BVH. Otherwise, testing continues recursively, that is, the
BVs of the children of the root are tested. As soon as a BV is missed by
the ray, testing can terminate on that subtree of the BVH. If the ray hits
a leaf node’s BV, the ray is tested against the geometry at this node. The
performance gains come partly from the fact that testing the ray with the
BV is fast. This is why simple objects such as spheres and boxes are used
as BVs. The other reason is the nesting of BVs, which allows us to avoid
testing large regions of space due to early termination in the tree.
Often the closest intersection, not the first found, is what is desired.
The only additional data needed are the distance and identity of the closest
object found while traversing the tree. The current closest distance is also
used to cull the tree during traversal. If a BV is intersected, but its distance
is beyond the closest distance found so far, then the BV can be discarded.
Normally we do not know which child of a BV is closest without testing,
so we must test all children in arbitrary order. As will be seen, a BSP
tree has an advantage over normal BVHs in that it can guarantee front-
to-back ordering. However, binary BVHs can also achieve this advantage
by keeping track of the axis used to split the set of objects into the two
children [132].