Unions

This example is given in Examples/EBGeometry_Union/main.cpp and shows the following steps:

  1. The creation of scene composed of an array of spheres.

  2. Instantiation of a standard union for the signed distance (see Unions).

  3. Instantiation of a BVH-enabled union for the signed distance (see Unions).

We focus on the following parts of the code:

Creating the spheres

In the first block of code we are defining one million spheres that lie on a three-dimensional lattice, where each sphere has a radius of one:

Creating standard union

In the second block of code we are simply creating a standard signed distance function union:

For implementation details regarding the standard union, see Unions.

Creating BVH-enabled union

In the third block of code we create a BVH-enabled union. To do so, we must first provide a function which can create bounding volumes around each object:

Here, we use axis-aligned boxes but we could also have used other types of bounding volumes.

Typical output

The above example shows two methods of creating unions. When running the example the typical output is something like:

Partitioning spheres
Computing distance with slow union
Computing distance with fast union
Distance and time using standard union = -1, which took 26.7353 ms
Distance and time using optimize union = -1, which took 0.003527 ms
Speedup = 7580.19

where we note that the optimized union was about 7500 times faster than the “standard” union.