Skip to content

Reduce dependency on FLANN, move towards nanoflann as default - #6332

Merged
mvieth merged 2 commits into
PointCloudLibrary:masterfrom
mvieth:nanoflann_default
Sep 15, 2025
Merged

mvieth merged 2 commits into
PointCloudLibrary:masterfrom
mvieth:nanoflann_default

Conversation

@mvieth

@mvieth mvieth commented Aug 30, 2025 •

Copy link
Copy Markdown
Member

Current behaviour

FLANN is the default search method for unorganized point clouds. If FLANN is not available, many PCL modules will not be built.

Desired new behaviour (work in progress):

  • Both FLANN and nanoflann are installed: use nanoflann as default search method for unorganized clouds (faster than FLANN)
  • Only FLANN is installed: use FLANN as default (same as before)
  • Only nanoflann is installed: use nanoflann as default (different than before, all PCL modules should be built, all classes should be available)
  • Neither FLANN nor nanoflann is installed: to discuss, maybe use PCL's octree as default search method for unorganized clouds?

What this PR does

  • Introduce a new function autoSelectMethod to ... well, automatically select the best search method based on the cloud and whether FLANN and/or nanoflann are installed. Use the new function in some classes (more to follow in future PRs)
  • Add missing includes for KdTree and OrganizedNeighbor because the transitive includes from feature.hpp are not available any more
  • Fix RSD estimation: the first search result is used as a reference, so the results must be sorted. Previously, the search results (of radiusSearch) have been unsorted, and switching from KdTree to KdTreeNanoflann gave differently ordered search results and thus also different results in the GRSD test (meaning a failing test). Requiring sorted results and adjusting the expected values in the GRSD test fixes the issue and should also lead to more useful RSD and GRSD descriptors
  • In some cases (mostly in tools), delete calls to setSearchMethod with KdTree and instead let the class decide which search method to use (via autoSelectMethod)

I am planning to do one or more follow-up PRs.

@mvieth mvieth added changelog: enhancement Meta-information for changelog generation module: search labels Aug 30, 2025
@mvieth
mvieth force-pushed the nanoflann_default branch 10 times, most recently from dfb69ee to a031e8c Compare September 4, 2025 09:33
Current behaviour: FLANN is the default search method for unorganized point clouds. If FLANN is not available, many PCL modules will not be built.
Desired new behaviour (work in progress):
  Both FLANN and nanoflann are installed: use nanoflann as default search method for unorganized clouds (faster than FLANN)
  Only FLANN is installed: use FLANN as default (same as before)
  Only nanoflann is installed: use nanoflann as default (different than before, all PCL modules should be built, all classes should be available)
  Neither FLANN nor nanoflann is installed: to discuss, maybe use PCL's octree as default search method for unorganized clouds?
@mvieth
mvieth force-pushed the nanoflann_default branch 4 times, most recently from 4997298 to e46775a Compare September 7, 2025 08:32
@mvieth
mvieth marked this pull request as ready for review September 10, 2025 18:48
Comment thread kdtree/CMakeLists.txt
set(srcs
src/kdtree_flann.cpp
)
if(FLANN_FOUND)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't kdtree_flann.h also be added conditionally? Else this header gets installed, but FLANN is not really supported?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Currently this condition does not make any difference because flann is still a required external dependency of the kdtree module (if flann is not avalable, the module will not be built, so FLANN_FOUND is currently always true here if the module is built). I added this condition when I was experimenting with making flann an optional dependency of this module, but kdtree_flann.h still had to be available to make KdTreeNanoflann work (as the parent class of KdTreeNanoflann, KdTree, has KdTreeFLANN as the default template parameter).
If you like, I could also remove all if(FLANN_FOUND)-statements in this file, and then check again in a future PR, which files should be included/excluded.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lets just merge this one then and adjust accordingly when possible.

@mvieth
mvieth merged commit 2cd2d87 into PointCloudLibrary:master Sep 15, 2025
13 checks passed
@mvieth
mvieth deleted the nanoflann_default branch September 15, 2025 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: enhancement Meta-information for changelog generation module: search

2 participants