pub fn voxel_downsample(
cloud: &PointCloud,
voxel_size: f64,
) -> Result<PointCloud, CloudError>Expand description
Downsamples a cloud onto a grid of cells with edge voxel_size,
replacing the points of each occupied cell by their centroid.
§Determinism
The result is bit-for-bit identical at any thread count, both in values and in point order. This is a requirement, not a side effect: further up the stack these points assemble the Jacobian, and a floating order of summation would make the smallest singular value float — that is, the degeneracy detector itself.
Three decisions achieve it:
- points are sorted by the key
(cell, original index), which is a total order, so the sorted sequence is unique regardless of the sorting algorithm; - within a cell, accumulation runs sequentially in increasing original index, so the order of summation is fixed;
- parallelism happens only between cells, which are independent.
A hash table instead of the sort would be faster, but neither its traversal order nor its order of merging partial sums is defined.
§Attributes
Attributes are not carried over: averaging depends on what the column means — colour averages, a class label does not. The returned cloud has coordinates only.