Point Cloud Library (PCL) 1.15.1
Loading...
Searching...
No Matches
pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree > Class Template Reference

pcl::search::KdTreeNanoflann is a faster and flexible alternative to pcl::search::KdTree. More...

#include <pcl/search/kdtree_nanoflann.h>

Inheritance diagram for pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >:

Public Types

using PointCloud = typename Search<PointT>::PointCloud
using PointCloudConstPtr = typename pcl::PointCloud<PointT>::ConstPtr
using Ptr = shared_ptr<KdTreeNanoflann<PointT, Dim, Distance, Tree>>
using ConstPtr = shared_ptr<const KdTreeNanoflann<PointT, Dim, Distance, Tree>>
using KdTreePtr = shared_ptr<Tree>
using KdTreeConstPtr = shared_ptr<const Tree>
using PointRepresentationConstPtr = shared_ptr<const PointRepresentation<PointT>>
Public Types inherited from pcl::search::KdTree< PointT, Tree >
using PointCloud = typename Search<PointT>::PointCloud
using PointCloudConstPtr = typename Search<PointT>::PointCloudConstPtr
using Ptr = shared_ptr<KdTree<PointT, Tree> >
using ConstPtr = shared_ptr<const KdTree<PointT, Tree> >
using KdTreePtr = typename Tree::Ptr
using KdTreeConstPtr = typename Tree::ConstPtr
using PointRepresentationConstPtr = typename PointRepresentation<PointT>::ConstPtr

Public Member Functions

 KdTreeNanoflann (bool sorted, std::size_t leaf_max_size, unsigned int n_thread_build=1)
 Constructor for KdTreeNanoflann.
 KdTreeNanoflann (bool sorted=false)
 Constructor for KdTreeNanoflann.
 ~KdTreeNanoflann () override=default
 Destructor for KdTreeNanoflann.
void setPointRepresentation (const PointRepresentationConstPtr &point_representation)
 Provide a pointer to the point representation to use to convert points into k-D vectors.
PointRepresentationConstPtr getPointRepresentation () const
 Get a pointer to the point representation used when converting points into k-D vectors.
void setSortedResults (bool sorted_results) override
 Sets whether the results have to be sorted or not.
void setEpsilon (float eps)
 Set the search epsilon precision (error bound) for nearest neighbors searches.
float getEpsilon () const
 Get the search epsilon precision (error bound) for nearest neighbors searches.
void setUseRKNN (bool use_rknn)
 Influences the results of radiusSearch when max_nn is not set to zero.
bool setInputCloud (const PointCloudConstPtr &cloud, const IndicesConstPtr &indices=IndicesConstPtr()) override
 Provide a pointer to the input dataset, this will build the kd-tree.
KdTreePtr getNanoflannTree ()
 Get pointer to internal nanoflann tree.
int nearestKSearch (const PointT &point, int k, Indices &k_indices, std::vector< float > &k_sqr_distances) const override
 Search for the k-nearest neighbors for the given query point.
int radiusSearch (const PointT &point, double radius, Indices &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const override
 Search for all the nearest neighbors of the query point in a given radius.
Public Member Functions inherited from pcl::search::KdTree< PointT, Tree >
 KdTree (bool sorted=true)
 Constructor for KdTree.
 ~KdTree () override=default
 Destructor for KdTree.
void setPointRepresentation (const PointRepresentationConstPtr &point_representation)
 Provide a pointer to the point representation to use to convert points into k-D vectors.
PointRepresentationConstPtr getPointRepresentation () const
 Get a pointer to the point representation used when converting points into k-D vectors.
void setEpsilon (float eps)
 Set the search epsilon precision (error bound) for nearest neighbors searches.
float getEpsilon () const
 Get the search epsilon precision (error bound) for nearest neighbors searches.

Additional Inherited Members

Protected Member Functions inherited from pcl::search::KdTree< PointT, Tree >
 KdTree (const std::string &name, bool sorted)
 This leaves the internal tree_ object uninitialized!
Protected Attributes inherited from pcl::search::KdTree< PointT, Tree >
KdTreePtr tree_
 A pointer to the internal KdTree object.

Detailed Description

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
class pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >

pcl::search::KdTreeNanoflann is a faster and flexible alternative to pcl::search::KdTree.

It is based on the nanoflann library by Jose Luis Blanco-Claraco ( https://github.com/jlblancoc/nanoflann ). Since nanoflann is treated as an optional dependency to PCL, you must test the preprocessor symbol PCL_HAS_NANOFLANN after including pcl/search/kdtree_nanoflann.h.

// Example 1: using KdTreeNanoflann in NormalEstimation:
ne.setSearchMethod (tree);
// rest as usual
// Example 2: using KdTreeNanoflannn in ICP:
// rest as usual
// Example 3: using a L1 distance norm:
kdtree_nanoflann.setInputCloud (my_cloud);
// now ready to use kdtree_nanoflann.nearestKSearch(...) and
// kdtree_nanoflann.radiusSearch(...);
// Example 4: using KdTreeNanoflann with features instead of 3D points:
kdtree_nanoflann_feat.setInputCloud(my_features_cloud);
// now ready for searching
void setSearchMethod(const KdTreePtr &tree)
Provide a pointer to the search object.
Definition feature.h:164
IterativeClosestPoint provides a base implementation of the Iterative Closest Point algorithm.
Definition icp.h:98
NormalEstimation estimates local surface properties (surface normals and curvatures)at each 3D point.
Definition normal_3d.h:244
void setSearchMethodSource(const KdTreeReciprocalPtr &tree, bool force_no_recompute=false)
Provide a pointer to the search object used to find correspondences in the source cloud (usually used...
void setSearchMethodTarget(const KdTreePtr &tree, bool force_no_recompute=false)
Provide a pointer to the search object used to find correspondences in the target cloud.
pcl::search::KdTreeNanoflann is a faster and flexible alternative to pcl::search::KdTree.
bool setInputCloud(const PointCloudConstPtr &cloud, const IndicesConstPtr &indices=IndicesConstPtr()) override
Provide a pointer to the input dataset, this will build the kd-tree.
shared_ptr< T > make_shared(Args &&... args)
Returns a pcl::shared_ptr compliant with type T's allocation policy.
Template Parameters
PointTCan be a point like pcl::PointXYZ or a feature like pcl::SHOT352
DimDimension of the KdTree to build. If set to -1, it will infer the dimension at runtime from the given point representation, but with a performance penalty. Default is 3, appropriate for all xyz point types.
DistanceThe distance to use. Possible values include pcl::L1_Adaptor (taxicab/manhattan distance), pcl::L2_Simple_Adaptor (euclidean distance, optimized for few dimensions), pcl::L2_Adaptor (euclidean distance, optimized for many dimensions), pcl::SO2_Adaptor, pcl::SO3_Adaptor. Default is pcl::L2_Simple_Adaptor
Author
Markus Vieth

Definition at line 186 of file kdtree_nanoflann.h.

Member Typedef Documentation

◆ ConstPtr

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
using pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::ConstPtr = shared_ptr<const KdTreeNanoflann<PointT, Dim, Distance, Tree>>

Definition at line 292 of file kdtree_nanoflann.h.

◆ KdTreeConstPtr

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
using pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::KdTreeConstPtr = shared_ptr<const Tree>

Definition at line 295 of file kdtree_nanoflann.h.

◆ KdTreePtr

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
using pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::KdTreePtr = shared_ptr<Tree>

Definition at line 294 of file kdtree_nanoflann.h.

◆ PointCloud

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
using pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::PointCloud = typename Search<PointT>::PointCloud

Definition at line 279 of file kdtree_nanoflann.h.

◆ PointCloudConstPtr

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
using pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::PointCloudConstPtr = typename pcl::PointCloud<PointT>::ConstPtr

Definition at line 280 of file kdtree_nanoflann.h.

◆ PointRepresentationConstPtr

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
using pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::PointRepresentationConstPtr = shared_ptr<const PointRepresentation<PointT>>

Definition at line 296 of file kdtree_nanoflann.h.

◆ Ptr

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
using pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::Ptr = shared_ptr<KdTreeNanoflann<PointT, Dim, Distance, Tree>>

Definition at line 291 of file kdtree_nanoflann.h.

Constructor & Destructor Documentation

◆ KdTreeNanoflann() [1/2]

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::KdTreeNanoflann ( bool sorted,
std::size_t leaf_max_size,
unsigned int n_thread_build = 1 )
inline

Constructor for KdTreeNanoflann.

Parameters
[in]sortedSet to true if the nearest neighbor search results need to be sorted in ascending order based on their distance to the query point (default is false, which is faster)
[in]leaf_max_sizeMax number of points/samples in a leaf, can be tuned to achieve best performance. When using this for 1nn search (e.g. correspondence estimation in icp/registration), then leaf_max_size=10 is usually fastest. Otherwise, leaf_max_size=20 is a good choice.
[in]n_thread_buildNumber of threads for concurrent tree build (default is 1, meaning no concurrent build)

Definition at line 310 of file kdtree_nanoflann.h.

References pcl::search::KdTree< PointT, Tree >::KdTree().

Referenced by KdTreeNanoflann().

◆ KdTreeNanoflann() [2/2]

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::KdTreeNanoflann ( bool sorted = false)
inline

Constructor for KdTreeNanoflann.

Parameters
[in]sortedset to true if the nearest neighbor search results need to be sorted in ascending order based on their distance to the query point

Definition at line 325 of file kdtree_nanoflann.h.

References KdTreeNanoflann().

◆ ~KdTreeNanoflann()

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::~KdTreeNanoflann ( )
overridedefault

Destructor for KdTreeNanoflann.

Member Function Documentation

◆ getEpsilon()

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
float pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::getEpsilon ( ) const
inline

Get the search epsilon precision (error bound) for nearest neighbors searches.

Definition at line 386 of file kdtree_nanoflann.h.

◆ getNanoflannTree()

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
KdTreePtr pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::getNanoflannTree ( )
inline

Get pointer to internal nanoflann tree.

Use with caution.

Definition at line 420 of file kdtree_nanoflann.h.

◆ getPointRepresentation()

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
PointRepresentationConstPtr pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::getPointRepresentation ( ) const
inline

Get a pointer to the point representation used when converting points into k-D vectors.

Definition at line 359 of file kdtree_nanoflann.h.

◆ nearestKSearch()

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
int pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::nearestKSearch ( const PointT & point,
int k,
Indices & k_indices,
std::vector< float > & k_sqr_distances ) const
inlineoverridevirtual

Search for the k-nearest neighbors for the given query point.

Parameters
[in]pointthe given query point
[in]kthe number of neighbors to search for
[out]k_indicesthe resultant indices of the neighboring points (must be resized to k a priori!)
[out]k_sqr_distancesthe resultant squared distances to the neighboring points (must be resized to k a priori!)
Returns
number of neighbors found

Reimplemented from pcl::search::KdTree< PointT, Tree >.

Definition at line 435 of file kdtree_nanoflann.h.

◆ radiusSearch()

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
int pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::radiusSearch ( const PointT & point,
double radius,
Indices & k_indices,
std::vector< float > & k_sqr_distances,
unsigned int max_nn = 0 ) const
inlineoverridevirtual

Search for all the nearest neighbors of the query point in a given radius.

Parameters
[in]pointthe given query point
[in]radiusthe radius of the sphere bounding all of p_q's neighbors
[out]k_indicesthe resultant indices of the neighboring points
[out]k_sqr_distancesthe resultant squared distances to the neighboring points
[in]max_nnif given, bounds the maximum returned neighbors to this value. If max_nn is set to 0 or to a number higher than the number of points in the input cloud, all neighbors in radius will be returned.
Returns
number of neighbors found in radius

Reimplemented from pcl::search::KdTree< PointT, Tree >.

Definition at line 486 of file kdtree_nanoflann.h.

References pcl::search::Search< PointT >::sorted_results_, pcl::search::Search< PointT >::sortResults(), and pcl::search::internal::square_if_l2().

◆ setEpsilon()

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
void pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::setEpsilon ( float eps)
inline

Set the search epsilon precision (error bound) for nearest neighbors searches.

Parameters
[in]epsprecision (error bound) for nearest neighbors searches

Definition at line 378 of file kdtree_nanoflann.h.

◆ setInputCloud()

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
bool pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::setInputCloud ( const PointCloudConstPtr & cloud,
const IndicesConstPtr & indices = IndicesConstPtr() )
inlineoverridevirtual

Provide a pointer to the input dataset, this will build the kd-tree.

Parameters
[in]cloudthe const shared pointer to a PointCloud
[in]indicesthe point indices subset that is to be used from cloud

Reimplemented from pcl::search::KdTree< PointT, Tree >.

Definition at line 408 of file kdtree_nanoflann.h.

References pcl::search::Search< PointT >::indices_, and pcl::search::Search< PointT >::input_.

◆ setPointRepresentation()

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
void pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::setPointRepresentation ( const PointRepresentationConstPtr & point_representation)
inline

Provide a pointer to the point representation to use to convert points into k-D vectors.

If you want to use this function, it is recommended to do so before calling setInputCloud, to avoid setting up the kd-tree twice.

Parameters
[in]point_representationthe const shared pointer to a PointRepresentation

Definition at line 336 of file kdtree_nanoflann.h.

◆ setSortedResults()

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
void pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::setSortedResults ( bool sorted_results)
inlineoverridevirtual

Sets whether the results have to be sorted or not.

Parameters
[in]sorted_resultsset to true if the radius search results should be sorted

Reimplemented from pcl::search::KdTree< PointT, Tree >.

Definition at line 368 of file kdtree_nanoflann.h.

References pcl::search::Search< PointT >::sorted_results_.

◆ setUseRKNN()

template<typename PointT, std::int32_t Dim = 3, typename Distance = std::conditional_t<Dim >= 4, L2_Adaptor, L2_Simple_Adaptor, typename Tree = nanoflann::KDTreeSingleIndexAdaptor< Distance, pcl::search::internal::PointCloudAdaptor<float>, Dim, pcl::index_t>>
void pcl::search::KdTreeNanoflann< PointT, Dim, Distance, L2_Adaptor, L2_Simple_Adaptor, Tree >::setUseRKNN ( bool use_rknn)
inline

Influences the results of radiusSearch when max_nn is not set to zero.

If the parameter max_nn of radiusSearch is set to a value greater than zero, it will return at most that many points. If you set use_rknn=true, it will always return the points closest to the query point. If you set use_rknn=false, it may return any points within the radius, which can be faster.

Definition at line 398 of file kdtree_nanoflann.h.


The documentation for this class was generated from the following file: