*Spatial coherence*, *spatial division* or *space tracing* refer to the
subdivision of 3-space to take advantage of spatial structure of the objects. The
technique, rather than checking rays against all objects in the scene or against *bounded
volume* approximations to the objects in the scene, "poses" the question: *"Is the
3-space region through which the ray is currently passing occupied by any objects?"*.

Bounding volume schemes associate a volume with an object, whereas the subdivision
schemes addressed here *represent* the objects as volumes by labelling the 3D space.

Major disadvantages of the bounding volume approach are:

- The efficiency is dependent on how well an object fills the space of a bounding volume.
- Its search time is a function of scene complexity.
- Depending on the nature and disposition of objects, a hierarchical description may be difficult or impossible.

- Computation time should be relatively independent of the scene complexity.
- Computation time per ray should be relatively constant and not be dependent on the origin or direction of the ray.
- Computational time should be `rational' (
*aka*reasonable - say, within an hour) and should (in the future) be `interactive' (within a few minutes - though ideally at frame rates). - The algorithm should not require the user to supply any additional information, such as object clustering information.
- The algorithm should deal with a wide variety of primitive geometric types and should be easily extensible to new types.
- The algorithm should be amenable to implementation on parallel or other advanced architectures.

In spatial sub-division methods we build up (in a pre-processing stage) additional structure to the objects to constrain the search.

A general protocol for spatial coherence schemes is:

- The space occupied by the scene is subdivided into labelled regions.
- A ray is first checked against these regions. Regions not containing objects can be pruned.
- Otherwise, the ray is tested against the objects in the current region.

- Octrees.
- SEADS.
- Binary Space Partitioning.

An *octree* is a hierarchical data structure that specifies the
occupancy of cubic regions (which vary in size) of object space.

A large region is either

- empty, or
- fully contained by a single object.

and the corresponding quadtree is

To construct the quadtree,

- The root of the tree represents the entire region.
- We then divide this region into four subregions, represented by four child nodes.
- Any subregion that is partially occupied by an object is further subdivided.
- This process continues until the subdivision reaches some predetermined limit.

For constructing an octree, we need only a trivial modification of the above procedure by

- using a cube to replace a square, and
- using 8-subdivision to replace a 4-subdivision.

The *basic idea* is to trace a ray from subregion to subregion.
We need as *input* an octree and a ray together with its start point, *P*.
The *output* is either an intersection point or the indication of
empty intersection.

**Step 1:**Detect the region containing*P*.**Step 2:**The ray is tested for intersection with any objects that lie in the region.*Intersections exist.*The first one encountered is the required intersection point for the ray. STOP.*No intersection.*- Calculate the point where the ray leaves the region - the intersection with the boundary of the region.
- A point on the ray a short distance away from the current region is assigned as
*P*. Go to Step 1.

A 2D example is given in *Watt and Watt*, page 224 (Figure 9.13). The spatial
subdivision in that example is terminated when each sub-region contains on one object.

**Step 1** above can be implemented by a typical tree search algorithm.
The maximum number of nodes that can be traversed is equal to the maximum depth of the tree.

In practice, the depth is small for even subdivision as fine as 1024 x 1024 x 1024 where
the result octree depth will have a maximum of
*log*_{8}(1024x1024x1024) = 10.

When building the octree data structure there are certain *trade-offs* that you can
consider. Firstly you can limit the depth of the tree so the search is faster, but this means
that in the smallest subdivision there may be several (more than one anyway) candidates
for the intersection calculation. *Alternatively* we can continue the subdivision
until each cell contains a single object, making the intersection calculation faster, but
which may make the maximum length of any branch very long.

One of the disadvantages of octrees is that the volumes that contain a
single object may be large. This is equivalent to a bounding volume which has a large
"void" area - *ie.* the bounding shape is inappropriate for the object shape.
This results in unnecessary intersection calculations.

**S**patially **E**numerated **A**uxiliary **D**ata
**S**tructure

The name SEADS suggests dividing all of the space of interest into equally sized cells regardless of their occupancy by objects, as shown in the example below;

Since here the sub-division occurs regardless of whether the cell is
occupied by an object or not, SEADS will generate more cells than the
octree. This therefore results in unnecessary demand for storage and
this is the primary *disadvantage* of this method - it has heavy space
overheads.

This data structure is analogous to the 2D sub-division of the screen
into pixels. It is this fact that gives rise to the major
*advantage* of this technique - fast tracking algorithms are possible.
The fast tree search algorithm in question is referred to as the 3D-DDA
(Digital Differential Analyser). It is an extension of the DDA, which is
used to determine the set of pixels passed through by a line. It is
extended to track a ray through the 3D SEADS grid. The speed of the
algorithm arises from the fact that floating point multiplication and
division are avoided, requiring only addition, subtraction and
comparison - predominantly *integer* addition on the cell
coordinates. (*recall the advantages of
using* **structured** *grids*).

The BSP tree is essentially the same as the octree, with changes to the data structure representation used to index into the tree. In a general scene, objects will often be unevenly distributed throughout the occupied space.

Binary space partitioning scheme is used to provide a balanced tree
according to the scene. When a BSP is used to represent sub-division of
space into *cubic* cells, it has no advantage over an octree.
However, the divisions need not be even.

- Instead of 8-subdivision by cubes, each time we divide the occupied space into two by a plane.
- Each nonterminal node in a BSP tree represents a single partitioning plane.
- A terminal node represents a region that is not further subdivided.

Octree, SEADS, and Binary Space Partitioning all have two potential problems.

- Some objects may be tested twice for intersection; see (a) below.
This problem can be resolved if we add a unique tag for each object. The result of intersection tests for each object with respect to the ray are then made available.

- Some intersection with objects may be incorrect if the
tracking process is incorrectly terminated, as shown in (b) below.
If the circle is tested first the intersection test will flag
the object. Thus, the intersection point will be incorrectly recorded
and the
*first*(and*true*) intersection point will be completely missed.This problem can be avoided by adopting a more effective termination condition. That is, we terminate the ray tracing when the

*nearest*intersection point is contained in the current box.

- Octree.
- Good for scenes whose occupancy density varies widely. Sub-division will be finer for high density regions and coarser for low density regions.
- It is possible to have small objects in large regions.
- Stepping from region to region is slower than the other two methods because the trees tend to be unbalanced.

- SEADS.
- Stepping is faster than an octree, but
- massive memory costs are incurred.

- BSP.
- The depth of the tree is (usually) smaller than an octree.
- Void areas will tend to be smaller.

- Expensive.
- Only possible to trace specular reflection and transmission, since
rays are treated infinitely thin.
- This excludes major light transport mechanisms such as the interaction of diffuse surfaces.
- Consequently, this results in images that exhibit a distinctive ray-traced signature.
- Modeling diffuse interaction by extending the simple ray tracing method is computationally impossible.