Graphics Reference
In-Depth Information
Figure 7.11 A quadtree node with the first level of subdivision shown in black dotted lines,
and the following level of subdivision in gray dashed lines. Dark gray objects overlap the first-
level dividing planes and become stuck at the current level. Medium gray objects propagate
one level down before becoming stuck. Here, only the white objects descend two levels.
To avoid duplication of geometry between multiple octree nodes, the original set of
primitives is stored in an array beforehand and a duplicate set of primitives is passed
to the construction function. Each of the duplicate primitives is given a reference to
the original primitive. When primitives are split, both parts retain the reference to the
original primitive. As tree leaf nodes are generated, rather than storing the split-up
duplicate geometry the references to the original set of primitives are stored. As the
tree is static, this work is best done in a preprocessing step.
Duplicating the primitives across overlapped octants works great for a static envi-
ronment. However, this approach is inefficient when the octree holds dynamic objects
because the tree must be updated as objects move. For the dynamic scenario, a better
approach is to restrict placement of objects to the lowest octree cell that contains
the object in its interior. By associating the object with a single cell only, a minimum
amount of pointer information must be updated when the object moves. A drawback
of restricting objects to lie within a single octree cell is that objects may be higher in
the tree than their size justifies. Specifically, any object straddling a partitioning plane
will become“stuck”at that level, regardless of the relative size between the object and
the node volume (Figure 7.11). This problem is addressed later. From here on, it is
assumed the octree is of the dynamic variety.
The octree can begin as an empty tree grown on demand as objects are inserted.
It can also be preallocated to alleviate the cost of dynamically growing it. Given
the previous octree node definition, preallocating a pointer-based octree down to a
specified depth can be done as:
// Preallocates an octree down to a specific depth
Node *BuildOctree(Point center, float halfWidth, int stopDepth)
{
if (stopDepth < 0) return NULL;
 
Search WWH ::




Custom Search