koide3 / small_gicp

Efficient and parallel algorithms for point cloud registration [C++, Python]
MIT License
318 stars 40 forks source link

voxelgrid_sampling_omp twice reduces point count #74

Closed grischi closed 1 month ago

grischi commented 1 month ago

Describe the bug When voxelgrid_samping_omp is first run with cloud A as input and cloud B as output, a second run with cloud B as input and cloud C as output results in cloud C having a lower point count than cloud B, even though leaf_size has the same value at both executions.

To Reproduce Steps to reproduce the behavior:

  1. add the following lines below line 16 in src/example/02_basic_registration_pcl.cpp
    std::cout << raw_target->size() << std::endl;
    std::cout << target->size() << std::endl;
    target = voxelgrid_sampling_omp(*target, 0.25);
    std::cout << target->size() << std::endl;
    target = voxelgrid_sampling_omp(*target, 0.25);
    std::cout << target->size() << std::endl;
  2. Build the package
  3. Run '02_basic_registration_pcl'. The output is:
    69088
    6206
    6147
    6147
    ...

    The first number is the size of the raw cloud, the second one after the first filter application and so on. Expected behaviour is that the last three numbers are the same.

Expected behavior Cloud C shall have the same size (point count) as cloud B.

Environment (please complete the following information):

koide3 commented 1 month ago

voxelgrid_sampling_omp uses a slight approximation for parallel processing efficiency that causes minor run-by-run non-determinism. If it is important that the method returns exactly the same number of points every time, we can consider changing the scheduling method at the following line from (guided, 4) to (static) (that may cause very slight performance degradation for a large point cloud).

https://github.com/koide3/small_gicp/blob/f48faf079051a92bfdb201bb08a67d35179fbd67/include/small_gicp/util/downsampling_omp.hpp#L63

grischi commented 1 month ago

Thank you @koide3 for your response. This approximation is perfectly fine for me, I just was not aware of it. Those use-cases where I want the filter to return exactly the same number of points every time are not so time-critical, I can use a different method in these cases.