Skip to content

Fix offset by one in RadiusOutlierRemoval<PCLPointCloud> and speed up radius search. Fixes #2816 - #6488

Open
Sree0211 wants to merge 1 commit into
PointCloudLibrary:masterfrom
Sree0211:fix-radius-outlier-removal-pclpointcloud2
Open

Sree0211 wants to merge 1 commit into
PointCloudLibrary:masterfrom
Sree0211:fix-radius-outlier-removal-pclpointcloud2

Conversation

@Sree0211

@Sree0211 Sree0211 commented Oct 8, 2026

Copy link
Copy Markdown

Changes:

  • In applyFilter(PCLPointCloud2&): use k <= min_pts_radius_ instead of k < min_pts_radius_. The radius search result includes the query point itself, so this makes the PCLPointCloud2 specialisation consistent with the templated implementation and with the documentation of setMinNeighborsInRadius.
  • Pass min_pts_radius_ + 1 as max_nn to both radiusSearch calls, so the search stops once enough nieghbors are found.
  • Added the unit test from the issue as a test (RadiusOutlierRemovalPCLPointCloud2).
  • Updated the existing RadiusOutlierRemoval test case as the PCLPointCloud2 section used setMinNeightborsInradius(15) to get the same 307 points as the templated part with 14. Both now use 14. (Commented out this current test section)

Testing:

  • Built and ran test_filters locally in Windows (MSVC). Before updating the unit test setup tests fail, after the fix all filter tests pass.
    command: test_filters.exe test\bun0.pcd test\milk_cartoon_all_small_colorx.pcd --gtest_filter=RadiusOutlierRemoval*
Note: Google Test filter = RadiusOutlierRemoval*
[==========] Running 2 tests from 2 test suites.
[----------] Global test environment set-up.
[----------] 1 test from RadiusOutlierRemoval
[ RUN      ] RadiusOutlierRemoval.Filters
..\test\filters\test_filters.cpp(1592): error: Expected equality of these values:
  cloud_out.size ()
    Which is: 274
  307
..\test\filters\test_filters.cpp(1593): error: Expected equality of these values:
  cloud_out.width
    Which is: 274
  307
..\test\filters\test_filters.cpp(1595): error: The difference between cloud_out[cloud_out.size () - 1].x and -0.077893 is 0.011893000357627873, which exceeds 1e-4, where
cloud_out[cloud_out.size () - 1].x evaluates to -0.065999999642372131,
-0.077893 evaluates to -0.077893000000000004, and
1e-4 evaluates to 0.0001.
..\test\filters\test_filters.cpp(1596): error: The difference between cloud_out[cloud_out.size () - 1].y and 0.16039 is 0.0076900020694732618, which exceeds 1e-4, where
cloud_out[cloud_out.size () - 1].y evaluates to 0.16808000206947327,
0.16039 evaluates to 0.16039, and
1e-4 evaluates to 0.0001.
..\test\filters\test_filters.cpp(1597): error: The difference between cloud_out[cloud_out.size () - 1].z and -0.021299 is 0.0096169997850656525, which exceeds 1e-4, where
cloud_out[cloud_out.size () - 1].z evaluates to -0.030915999785065651,
-0.021299 evaluates to -0.021298999999999998, and
1e-4 evaluates to 0.0001.
[  FAILED  ] RadiusOutlierRemoval.Filters (135 ms)
[----------] 1 test from RadiusOutlierRemoval (136 ms total)

[----------] 1 test from RadiusOutlierRemovalPCLPointCloud2
[ RUN      ] RadiusOutlierRemovalPCLPointCloud2.Filters
[       OK ] RadiusOutlierRemovalPCLPointCloud2.Filters (0 ms)
[----------] 1 test from RadiusOutlierRemovalPCLPointCloud2 (0 ms total)

[----------] Global test environment tear-down
[==========] 2 tests from 2 test suites ran. (139 ms total)
[  PASSED  ] 1 test.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] RadiusOutlierRemoval.Filters

 1 FAILED TEST

After Fix:

Note: Google Test filter = RadiusOutlierRemoval*
[==========] Running 2 tests from 2 test suites.
[----------] Global test environment set-up.
[----------] 1 test from RadiusOutlierRemoval
[ RUN      ] RadiusOutlierRemoval.Filters
[       OK ] RadiusOutlierRemoval.Filters (126 ms)
[----------] 1 test from RadiusOutlierRemoval (126 ms total)

[----------] 1 test from RadiusOutlierRemovalPCLPointCloud2
[ RUN      ] RadiusOutlierRemovalPCLPointCloud2.Filters
[       OK ] RadiusOutlierRemovalPCLPointCloud2.Filters (0 ms)
[----------] 1 test from RadiusOutlierRemovalPCLPointCloud2 (0 ms total)

[----------] Global test environment tear-down
[==========] 2 tests from 2 test suites ran. (129 ms total)
[  PASSED  ] 2 tests.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant