|
CGAL 6.3-dev - Sphere Packing
|
Sphere packings have a wide range of applications in scientific and engineering disciplines. While the computation of optimal sphere packings, e.g., filling the largest number of fixed size spheres into a volume or occupying the largest volume with a fixed number of spheres, has NP complexity and is generally known as the "Packing problem". The Protosphere method, see [2] and [1], instead calculates a greedy packing, i.e., it iteratively inserts the largest non-overlapping spheres inside the volume.
The Protosphere algorithm calculates a sphere packing on GPU in a massively parallel manner. It uses two voxel grids, one to insert sphere candidates and one to speed up the calculation of the closest point on the enclosing volume. A sphere candidate is generated in each cell of the grid and moved away from the closest point on the boundary and other already inserted spheres in an iterative manner. The largest candidates are then inserted into the sphere packing and new sphere candidates are generated. Grid cells that are outside of the object or completely inside spheres are excluded from following iterations. Two different grids are used as the initialization cost and memory requirements differ for the two tasks. The grid for sphere placement is initialized with a coarse resolution as during the first steps typically a few very large spheres are placed that cover large parts of the volume. The grid is refined after some placement iterations to allow for a broader search while limiting the memory usage as a larger number of grid cells is already covered by spheres. The grid to identify the closest point on the enclosing volume is expensive in initialization, but doesn't add to the computation cost for each iteration. It is thus initialized with a higher resolution and a split is often not required.
The method has three parameters which are used to terminate the packing:
In addition the following parameters can be provided, but have useful default values:
The method is demonstrated at the dino model as it possesses some compact and some fine parts, see Figure 112.1. Choosing a lower number of spheres, e.g., 100 or 1000 spheres, leads to a sparse coverage in legs and arms. A coverage of at least 98% is achieved with 58.3k spheres.
Figure 112.1 Packing with a 98% target coverage.
From left to right: 1. dino input mesh, 2. 100 spheres, 3. 1kspheres, 4. 10k spheres, 5. 58.3k spheres
The following table shows the coverage and performance when using standard parameters and 98% target coverage with the dino model. A NVidia RTX A2000 laptop GPU with 4 Gb of memory was used.
| Dino | 100 Spheres | 1k Spheres | 10k Spheres | 58.3k Spheres |
|---|---|---|---|---|
| Time | 0.77s | 4.8s | 34.7s | 368s |
| Coverage | 59.3% | 72.0% | 83.3% | 98.1% |
The following example demonstrates the sphere packing of the dino model with 1.000 spheres. The result is exported into a ".spheres" file which can be displayed in CGAL Lab.
Example: Sphere_packing/sphere_packing.cpp