Skip to content

Fix offset by one in RadiusOutlierRemoval<PCLPointCloud2> and speed up radius search - #6488

Merged
mvieth merged 2 commits into
PointCloudLibrary:masterfrom
Sree0211:fix-radius-outlier-removal-pclpointcloud2
Oct 17, 2026
Merged

mvieth merged 2 commits into
PointCloudLibrary:masterfrom
Sree0211:fix-radius-outlier-removal-pclpointcloud2

Conversation

@Sree0211

@Sree0211 Sree0211 commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

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.

@mvieth

mvieth commented Oct 10, 2026

Copy link
Copy Markdown
Member

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)

Please don't comment it out, update the test to use 14 like you said.

@Sree0211

Copy link
Copy Markdown
Contributor Author

Thanks for letting me know. I’ve restored the PCLPointCloud2 sections and updated both to setMinNeighborsInRadius(14).

[----------] 1 test from RadiusOutlierRemoval
[ RUN      ] RadiusOutlierRemoval.Filters
[       OK ] RadiusOutlierRemoval.Filters (4968 ms)
[----------] 1 test from RadiusOutlierRemoval (4969 ms total)

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

Pushed in the latest commit.

@mvieth mvieth changed the title Fix offset by one in RadiusOutlierRemoval<PCLPointCloud> and speed up radius search. Fixes #2816 Fix offset by one in RadiusOutlierRemoval<PCLPointCloud2> and speed up radius search Oct 17, 2026
@mvieth mvieth added changelog: behavior change Meta-information for changelog generation changelog: fix Meta-information for changelog generation labels Oct 17, 2026

@mvieth mvieth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mvieth
mvieth merged commit b054e75 into PointCloudLibrary:master Oct 17, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: behavior change Meta-information for changelog generation changelog: fix Meta-information for changelog generation module: filters

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RadiusOutlierRemoval<PCLPointCloud2> implementation is slow and confusing

2 participants