Point Cloud Library (PCL)  1.14.0-dev
List of all members | Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
pcl::search::FlannSearch< PointT, FlannDistance > Class Template Reference

search::FlannSearch is a generic FLANN wrapper class for the new search interface. More...

#include <pcl/search/flann_search.h>

+ Inheritance diagram for pcl::search::FlannSearch< PointT, FlannDistance >:
+ Collaboration diagram for pcl::search::FlannSearch< PointT, FlannDistance >:

Classes

class  FlannIndexCreator
 Helper class that creates a FLANN index from a given FLANN matrix. More...
 
class  KdTreeIndexCreator
 Creates a FLANN KdTreeSingleIndex from the given input data. More...
 
class  KdTreeMultiIndexCreator
 Creates a FLANN KdTreeIndex of multiple randomized trees from the given input data, suitable for feature matching. More...
 
class  KMeansIndexCreator
 Creates a FLANN KdTreeSingleIndex from the given input data. More...
 

Public Types

using Ptr = shared_ptr< FlannSearch< PointT, FlannDistance > >
 
using ConstPtr = shared_ptr< const FlannSearch< PointT, FlannDistance > >
 
using PointCloud = typename Search< PointT >::PointCloud
 
using PointCloudConstPtr = typename Search< PointT >::PointCloudConstPtr
 
using MatrixPtr = shared_ptr< flann::Matrix< float > >
 
using MatrixConstPtr = shared_ptr< const flann::Matrix< float > >
 
using Index = flann::NNIndex< FlannDistance >
 
using IndexPtr = shared_ptr< flann::NNIndex< FlannDistance > >
 
using PointRepresentation = pcl::PointRepresentation< PointT >
 
using PointRepresentationPtr = typename PointRepresentation::Ptr
 
using PointRepresentationConstPtr = typename PointRepresentation::ConstPtr
 
using FlannIndexCreatorPtr = shared_ptr< FlannIndexCreator >
 

Public Member Functions

 FlannSearch (bool sorted=true, FlannIndexCreatorPtr creator=FlannIndexCreatorPtr(new KdTreeIndexCreator()))
 
 ~FlannSearch () override
 Destructor for FlannSearch. More...
 
void setEpsilon (double eps)
 Set the search epsilon precision (error bound) for nearest neighbors searches. More...
 
double getEpsilon ()
 Get the search epsilon precision (error bound) for nearest neighbors searches. More...
 
void setChecks (int checks)
 Set the number of checks to perform during approximate searches in multiple randomized trees. More...
 
int getChecks ()
 Get the number of checks to perform during approximate searches in multiple randomized trees. More...
 
bool setInputCloud (const PointCloudConstPtr &cloud, const IndicesConstPtr &indices=IndicesConstPtr()) override
 Provide a pointer to the input dataset. More...
 
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. More...
 
void nearestKSearch (const PointCloud &cloud, const Indices &indices, int k, std::vector< Indices > &k_indices, std::vector< std::vector< float > > &k_sqr_distances) const override
 Search for the k-nearest neighbors for the given query point. More...
 
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. More...
 
void radiusSearch (const PointCloud &cloud, const Indices &indices, double radius, std::vector< Indices > &k_indices, std::vector< std::vector< float > > &k_sqr_distances, unsigned int max_nn=0) const override
 Search for the k-nearest neighbors for the given query point. More...
 
void setPointRepresentation (const PointRepresentationConstPtr &point_representation)
 Provide a pointer to the point representation to use to convert points into k-D vectors. More...
 
PointRepresentationConstPtr const getPointRepresentation ()
 Get a pointer to the point representation used when converting points into k-D vectors. More...
 

Protected Member Functions

void convertInputToFlannMatrix ()
 converts the input data to a format usable by FLANN More...
 

Protected Attributes

IndexPtr index_
 The FLANN index. More...
 
FlannIndexCreatorPtr creator_
 The index creator, used to (re-) create the index when the search data is passed. More...
 
MatrixPtr input_flann_
 Input data in FLANN format. More...
 
float eps_ {0.0f}
 Epsilon for approximate NN search. More...
 
int checks_ {32}
 Number of checks to perform for approximate NN search using the multiple randomized tree index. More...
 
bool input_copied_for_flann_ {false}
 
PointRepresentationConstPtr point_representation_ {nullptr}
 
int dim_ {0}
 
Indices index_mapping_
 
bool identity_mapping_ {false}
 
std::size_t total_nr_points_ {0}
 

Detailed Description

template<typename PointT, typename FlannDistance = flann::L2_Simple <float>>
class pcl::search::FlannSearch< PointT, FlannDistance >

search::FlannSearch is a generic FLANN wrapper class for the new search interface.

It is able to wrap any FLANN index type, e.g. the kd tree as well as indices for high-dimensional searches and intended as a more powerful and cleaner successor to KdTreeFlann.

By default, this class creates a single kd tree for indexing the input data. However, for high dimensions (> 10), it is often better to use the multiple randomized kd tree index provided by FLANN in combination with the flann::L2 distance functor. During search in this type of index, the number of checks to perform before terminating the search can be controlled. Here is a code example if a high-dimensional 2-NN search:

// Feature and distance type
using FeatureT = SHOT352;
using DistanceT = flann::L2<float>;
// Search and index types
using SearchT = search::FlannSearch<FeatureT, DistanceT>;
using CreatorPtrT = typename SearchT::FlannIndexCreatorPtr;
using IndexT = typename SearchT::KdTreeMultiIndexCreator;
using RepresentationPtrT = typename SearchT::PointRepresentationPtr;
// Features
// Fill query and target with calculated features...
// Instantiate search object with 4 randomized trees and 256 checks
SearchT search (true, CreatorPtrT (new IndexT (4)));
search.setPointRepresentation (RepresentationPtrT (new DefaultFeatureRepresentation<FeatureT>));
search.setChecks (256);
search.setInputCloud (target);
// Do search
std::vector<Indices> k_indices;
std::vector<std::vector<float> > k_sqr_distances;
search.nearestKSearch (*query, Indices (), 2, k_indices, k_sqr_distances);
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
Author
Andreas Muetzel
Anders Glent Buch (multiple randomized kd tree interface)

Definition at line 100 of file flann_search.h.

Member Typedef Documentation

◆ ConstPtr

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
using pcl::search::FlannSearch< PointT, FlannDistance >::ConstPtr = shared_ptr<const FlannSearch<PointT, FlannDistance> >

Definition at line 108 of file flann_search.h.

◆ FlannIndexCreatorPtr

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
using pcl::search::FlannSearch< PointT, FlannDistance >::FlannIndexCreatorPtr = shared_ptr<FlannIndexCreator>

Definition at line 141 of file flann_search.h.

◆ Index

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
using pcl::search::FlannSearch< PointT, FlannDistance >::Index = flann::NNIndex<FlannDistance>

Definition at line 116 of file flann_search.h.

◆ IndexPtr

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
using pcl::search::FlannSearch< PointT, FlannDistance >::IndexPtr = shared_ptr<flann::NNIndex<FlannDistance> >

Definition at line 117 of file flann_search.h.

◆ MatrixConstPtr

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
using pcl::search::FlannSearch< PointT, FlannDistance >::MatrixConstPtr = shared_ptr<const flann::Matrix<float> >

Definition at line 114 of file flann_search.h.

◆ MatrixPtr

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
using pcl::search::FlannSearch< PointT, FlannDistance >::MatrixPtr = shared_ptr<flann::Matrix<float> >

Definition at line 113 of file flann_search.h.

◆ PointCloud

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
using pcl::search::FlannSearch< PointT, FlannDistance >::PointCloud = typename Search<PointT>::PointCloud

Definition at line 110 of file flann_search.h.

◆ PointCloudConstPtr

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
using pcl::search::FlannSearch< PointT, FlannDistance >::PointCloudConstPtr = typename Search<PointT>::PointCloudConstPtr

Definition at line 111 of file flann_search.h.

◆ PointRepresentation

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
using pcl::search::FlannSearch< PointT, FlannDistance >::PointRepresentation = pcl::PointRepresentation<PointT>

Definition at line 119 of file flann_search.h.

◆ PointRepresentationConstPtr

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
using pcl::search::FlannSearch< PointT, FlannDistance >::PointRepresentationConstPtr = typename PointRepresentation::ConstPtr

Definition at line 121 of file flann_search.h.

◆ PointRepresentationPtr

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
using pcl::search::FlannSearch< PointT, FlannDistance >::PointRepresentationPtr = typename PointRepresentation::Ptr

Definition at line 120 of file flann_search.h.

◆ Ptr

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
using pcl::search::FlannSearch< PointT, FlannDistance >::Ptr = shared_ptr<FlannSearch<PointT, FlannDistance> >

Definition at line 107 of file flann_search.h.

Constructor & Destructor Documentation

◆ FlannSearch()

template<typename PointT , typename FlannDistance >
pcl::search::FlannSearch< PointT, FlannDistance >::FlannSearch ( bool  sorted = true,
FlannIndexCreatorPtr  creator = FlannIndexCreatorPtr (new KdTreeIndexCreator ()) 
)

◆ ~FlannSearch()

template<typename PointT , typename FlannDistance >
pcl::search::FlannSearch< PointT, FlannDistance >::~FlannSearch
override

Destructor for FlannSearch.

Definition at line 86 of file flann_search.hpp.

Member Function Documentation

◆ convertInputToFlannMatrix()

template<typename PointT , typename FlannDistance >
void pcl::search::FlannSearch< PointT, FlannDistance >::convertInputToFlannMatrix
protected

converts the input data to a format usable by FLANN

Definition at line 372 of file flann_search.hpp.

◆ getChecks()

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
int pcl::search::FlannSearch< PointT, FlannDistance >::getChecks ( )
inline

Get the number of checks to perform during approximate searches in multiple randomized trees.

Definition at line 248 of file flann_search.h.

References pcl::search::FlannSearch< PointT, FlannDistance >::checks_.

◆ getEpsilon()

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
double pcl::search::FlannSearch< PointT, FlannDistance >::getEpsilon ( )
inline

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

Definition at line 232 of file flann_search.h.

References pcl::search::FlannSearch< PointT, FlannDistance >::eps_.

◆ getPointRepresentation()

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
PointRepresentationConstPtr const pcl::search::FlannSearch< PointT, FlannDistance >::getPointRepresentation ( )
inline

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

Definition at line 326 of file flann_search.h.

References pcl::search::FlannSearch< PointT, FlannDistance >::point_representation_.

◆ nearestKSearch() [1/2]

template<typename PointT , typename FlannDistance >
void pcl::search::FlannSearch< PointT, FlannDistance >::nearestKSearch ( const PointCloud cloud,
const Indices indices,
int  k,
std::vector< Indices > &  k_indices,
std::vector< std::vector< float > > &  k_sqr_distances 
) const
overridevirtual

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

Parameters
[in]cloudthe point cloud data
[in]indicesa vector of point cloud indices to query for nearest neighbors
[in]kthe number of neighbors to search for
[out]k_indicesthe resultant indices of the neighboring points, k_indices[i] corresponds to the neighbors of the query point i
[out]k_sqr_distancesthe resultant squared distances to the neighboring points, k_sqr_distances[i] corresponds to the neighbors of the query point i

Reimplemented from pcl::search::Search< PointT >.

Definition at line 150 of file flann_search.hpp.

References pcl::knn_search().

◆ nearestKSearch() [2/2]

template<typename PointT , typename FlannDistance >
int pcl::search::FlannSearch< PointT, FlannDistance >::nearestKSearch ( const PointT point,
int  k,
Indices k_indices,
std::vector< float > &  k_sqr_distances 
) const
overridevirtual

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

Implements pcl::search::Search< PointT >.

Definition at line 106 of file flann_search.hpp.

References pcl::knn_search().

◆ radiusSearch() [1/2]

template<typename PointT , typename FlannDistance >
void pcl::search::FlannSearch< PointT, FlannDistance >::radiusSearch ( const PointCloud cloud,
const Indices indices,
double  radius,
std::vector< Indices > &  k_indices,
std::vector< std::vector< float > > &  k_sqr_distances,
unsigned int  max_nn = 0 
) const
overridevirtual

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

Parameters
[in]cloudthe point cloud data
[in]indicesa vector of point cloud indices to query for nearest neighbors
[in]radiusthe radius of the sphere bounding all of p_q's neighbors
[out]k_indicesthe resultant indices of the neighboring points, k_indices[i] corresponds to the neighbors of the query point i
[out]k_sqr_distancesthe resultant squared distances to the neighboring points, k_sqr_distances[i] corresponds to the neighbors of the query point i
[in]max_nnif given, bounds the maximum returned neighbors to this value

Reimplemented from pcl::search::Search< PointT >.

Definition at line 282 of file flann_search.hpp.

References pcl::radius_search().

◆ radiusSearch() [2/2]

template<typename PointT , typename FlannDistance >
int pcl::search::FlannSearch< PointT, FlannDistance >::radiusSearch ( const PointT point,
double  radius,
Indices k_indices,
std::vector< float > &  k_sqr_distances,
unsigned int  max_nn = 0 
) const
overridevirtual

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

Implements pcl::search::Search< PointT >.

Definition at line 240 of file flann_search.hpp.

References pcl::radius_search().

◆ setChecks()

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
void pcl::search::FlannSearch< PointT, FlannDistance >::setChecks ( int  checks)
inline

Set the number of checks to perform during approximate searches in multiple randomized trees.

Parameters
[in]checksnumber of checks to perform during approximate searches in multiple randomized trees.

Definition at line 241 of file flann_search.h.

References pcl::search::FlannSearch< PointT, FlannDistance >::checks_.

◆ setEpsilon()

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
void pcl::search::FlannSearch< PointT, FlannDistance >::setEpsilon ( double  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 225 of file flann_search.h.

References pcl::search::FlannSearch< PointT, FlannDistance >::eps_.

◆ setInputCloud()

template<typename PointT , typename FlannDistance >
bool pcl::search::FlannSearch< PointT, FlannDistance >::setInputCloud ( const PointCloudConstPtr cloud,
const IndicesConstPtr indices = IndicesConstPtr () 
)
overridevirtual

Provide a pointer to the input dataset.

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

Reimplemented from pcl::search::Search< PointT >.

Definition at line 94 of file flann_search.hpp.

Referenced by pcl::search::FlannSearch< PointT, FlannDistance >::setPointRepresentation().

◆ setPointRepresentation()

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
void pcl::search::FlannSearch< PointT, FlannDistance >::setPointRepresentation ( const PointRepresentationConstPtr point_representation)
inline

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

Parameters
[in]point_representationthe const boost shared pointer to a PointRepresentation

Definition at line 316 of file flann_search.h.

References pcl::search::FlannSearch< PointT, FlannDistance >::dim_, pcl::search::Search< PointT >::indices_, pcl::search::Search< PointT >::input_, pcl::search::FlannSearch< PointT, FlannDistance >::point_representation_, and pcl::search::FlannSearch< PointT, FlannDistance >::setInputCloud().

Member Data Documentation

◆ checks_

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
int pcl::search::FlannSearch< PointT, FlannDistance >::checks_ {32}
protected

Number of checks to perform for approximate NN search using the multiple randomized tree index.

Definition at line 355 of file flann_search.h.

Referenced by pcl::search::FlannSearch< PointT, FlannDistance >::getChecks(), and pcl::search::FlannSearch< PointT, FlannDistance >::setChecks().

◆ creator_

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
FlannIndexCreatorPtr pcl::search::FlannSearch< PointT, FlannDistance >::creator_
protected

The index creator, used to (re-) create the index when the search data is passed.

Definition at line 343 of file flann_search.h.

◆ dim_

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
int pcl::search::FlannSearch< PointT, FlannDistance >::dim_ {0}
protected

◆ eps_

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
float pcl::search::FlannSearch< PointT, FlannDistance >::eps_ {0.0f}
protected

◆ identity_mapping_

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
bool pcl::search::FlannSearch< PointT, FlannDistance >::identity_mapping_ {false}
protected

Definition at line 364 of file flann_search.h.

◆ index_

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
IndexPtr pcl::search::FlannSearch< PointT, FlannDistance >::index_
protected

The FLANN index.

Definition at line 339 of file flann_search.h.

◆ index_mapping_

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
Indices pcl::search::FlannSearch< PointT, FlannDistance >::index_mapping_
protected

Definition at line 363 of file flann_search.h.

◆ input_copied_for_flann_

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
bool pcl::search::FlannSearch< PointT, FlannDistance >::input_copied_for_flann_ {false}
protected

Definition at line 357 of file flann_search.h.

◆ input_flann_

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
MatrixPtr pcl::search::FlannSearch< PointT, FlannDistance >::input_flann_
protected

Input data in FLANN format.

Definition at line 347 of file flann_search.h.

◆ point_representation_

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
PointRepresentationConstPtr pcl::search::FlannSearch< PointT, FlannDistance >::point_representation_ {nullptr}
protected

◆ total_nr_points_

template<typename PointT , typename FlannDistance = flann::L2_Simple <float>>
std::size_t pcl::search::FlannSearch< PointT, FlannDistance >::total_nr_points_ {0}
protected

Definition at line 366 of file flann_search.h.


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