Point Cloud Library (PCL)  1.14.1-dev
List of all members | Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
pcl::search::Search< PointT > Class Template Referenceabstract

Generic search class. More...

#include <pcl/search/search.h>

+ Inheritance diagram for pcl::search::Search< PointT >:
+ Collaboration diagram for pcl::search::Search< PointT >:

Public Types

using PointCloud = pcl::PointCloud< PointT >
 
using PointCloudPtr = typename PointCloud::Ptr
 
using PointCloudConstPtr = typename PointCloud::ConstPtr
 
using Ptr = shared_ptr< pcl::search::Search< PointT > >
 
using ConstPtr = shared_ptr< const pcl::search::Search< PointT > >
 
using IndicesPtr = pcl::IndicesPtr
 
using IndicesConstPtr = pcl::IndicesConstPtr
 

Public Member Functions

 Search (const std::string &name="", bool sorted=false)
 Constructor. More...
 
virtual ~Search ()=default
 Destructor. More...
 
virtual const std::string & getName () const
 Returns the search method name. More...
 
virtual void setSortedResults (bool sorted)
 sets whether the results should be sorted (ascending in the distance) or not More...
 
virtual bool getSortedResults ()
 Gets whether the results should be sorted (ascending in the distance) or not Otherwise the results may be returned in any order. More...
 
virtual bool setInputCloud (const PointCloudConstPtr &cloud, const IndicesConstPtr &indices=IndicesConstPtr())
 Pass the input dataset that the search will be performed on. More...
 
virtual PointCloudConstPtr getInputCloud () const
 Get a pointer to the input point cloud dataset. More...
 
virtual IndicesConstPtr getIndices () const
 Get a pointer to the vector of indices used. More...
 
virtual int nearestKSearch (const PointT &point, int k, Indices &k_indices, std::vector< float > &k_sqr_distances) const =0
 Search for the k-nearest neighbors for the given query point. More...
 
template<typename PointTDiff >
int nearestKSearchT (const PointTDiff &point, int k, Indices &k_indices, std::vector< float > &k_sqr_distances) const
 Search for k-nearest neighbors for the given query point. More...
 
virtual int nearestKSearch (const PointCloud &cloud, index_t index, int k, Indices &k_indices, std::vector< float > &k_sqr_distances) const
 Search for k-nearest neighbors for the given query point. More...
 
virtual int nearestKSearch (index_t index, int k, Indices &k_indices, std::vector< float > &k_sqr_distances) const
 Search for k-nearest neighbors for the given query point (zero-copy). More...
 
virtual void nearestKSearch (const PointCloud &cloud, const Indices &indices, int k, std::vector< Indices > &k_indices, std::vector< std::vector< float > > &k_sqr_distances) const
 Search for the k-nearest neighbors for the given query point. More...
 
template<typename PointTDiff >
void nearestKSearchT (const pcl::PointCloud< PointTDiff > &cloud, const Indices &indices, int k, std::vector< Indices > &k_indices, std::vector< std::vector< float > > &k_sqr_distances) const
 Search for the k-nearest neighbors for the given query point. More...
 
virtual int radiusSearch (const PointT &point, double radius, Indices &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const =0
 Search for all the nearest neighbors of the query point in a given radius. More...
 
template<typename PointTDiff >
int radiusSearchT (const PointTDiff &point, double radius, Indices &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const
 Search for all the nearest neighbors of the query point in a given radius. More...
 
virtual int radiusSearch (const PointCloud &cloud, index_t index, double radius, Indices &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const
 Search for all the nearest neighbors of the query point in a given radius. More...
 
virtual int radiusSearch (index_t index, double radius, Indices &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const
 Search for all the nearest neighbors of the query point in a given radius (zero-copy). More...
 
virtual 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
 Search for all the nearest neighbors of the query point in a given radius. More...
 
template<typename PointTDiff >
void radiusSearchT (const pcl::PointCloud< PointTDiff > &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
 Search for all the nearest neighbors of the query points in a given radius. More...
 

Protected Member Functions

void sortResults (Indices &indices, std::vector< float > &distances) const
 

Protected Attributes

PointCloudConstPtr input_
 
IndicesConstPtr indices_
 
bool sorted_results_
 
std::string name_
 

Detailed Description

template<typename PointT>
class pcl::search::Search< PointT >

Generic search class.

All search wrappers must inherit from this.

Each search method must implement 2 different types of search:

The input to each search method can be given in 3 different ways:

For the latter option, it is assumed that the user specified the input via a setInputCloud () method first.

Note
In case of an error, all methods are supposed to return 0 as the number of neighbors found.
libpcl_search deals with three-dimensional search problems. For higher level dimensional search, please refer to the libpcl_kdtree module.
Author
Radu B. Rusu

Definition at line 74 of file search.h.

Member Typedef Documentation

◆ ConstPtr

template<typename PointT >
using pcl::search::Search< PointT >::ConstPtr = shared_ptr<const pcl::search::Search<PointT> >

Definition at line 82 of file search.h.

◆ IndicesConstPtr

template<typename PointT >
using pcl::search::Search< PointT >::IndicesConstPtr = pcl::IndicesConstPtr

Definition at line 85 of file search.h.

◆ IndicesPtr

template<typename PointT >
using pcl::search::Search< PointT >::IndicesPtr = pcl::IndicesPtr

Definition at line 84 of file search.h.

◆ PointCloud

template<typename PointT >
using pcl::search::Search< PointT >::PointCloud = pcl::PointCloud<PointT>

Definition at line 77 of file search.h.

◆ PointCloudConstPtr

template<typename PointT >
using pcl::search::Search< PointT >::PointCloudConstPtr = typename PointCloud::ConstPtr

Definition at line 79 of file search.h.

◆ PointCloudPtr

template<typename PointT >
using pcl::search::Search< PointT >::PointCloudPtr = typename PointCloud::Ptr

Definition at line 78 of file search.h.

◆ Ptr

template<typename PointT >
using pcl::search::Search< PointT >::Ptr = shared_ptr<pcl::search::Search<PointT> >

Definition at line 81 of file search.h.

Constructor & Destructor Documentation

◆ Search()

template<typename PointT >
pcl::search::Search< PointT >::Search ( const std::string &  name = "",
bool  sorted = false 
)

Constructor.

Definition at line 45 of file search.hpp.

◆ ~Search()

template<typename PointT >
virtual pcl::search::Search< PointT >::~Search ( )
virtualdefault

Destructor.

Member Function Documentation

◆ getIndices()

template<typename PointT >
virtual IndicesConstPtr pcl::search::Search< PointT >::getIndices ( ) const
inlinevirtual

Get a pointer to the vector of indices used.

Definition at line 131 of file search.h.

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

Referenced by pcl::extractEuclideanClusters().

◆ getInputCloud()

template<typename PointT >
virtual PointCloudConstPtr pcl::search::Search< PointT >::getInputCloud ( ) const
inlinevirtual

Get a pointer to the input point cloud dataset.

Definition at line 124 of file search.h.

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

Referenced by pcl::extractEuclideanClusters(), pcl::extractLabeledEuclideanClusters(), and pcl::seededHueSegmentation().

◆ getName()

template<typename PointT >
const std::string & pcl::search::Search< PointT >::getName
virtual

Returns the search method name.

Definition at line 54 of file search.hpp.

◆ getSortedResults()

template<typename PointT >
bool pcl::search::Search< PointT >::getSortedResults
virtual

Gets whether the results should be sorted (ascending in the distance) or not Otherwise the results may be returned in any order.

Definition at line 68 of file search.hpp.

Referenced by pcl::extractEuclideanClusters(), pcl::extractLabeledEuclideanClusters(), and pcl::seededHueSegmentation().

◆ nearestKSearch() [1/4]

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

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 in pcl::search::FlannSearch< PointT, FlannDistance >.

Definition at line 114 of file search.hpp.

◆ nearestKSearch() [2/4]

template<typename PointT >
int pcl::search::Search< PointT >::nearestKSearch ( const PointCloud cloud,
index_t  index,
int  k,
Indices k_indices,
std::vector< float > &  k_sqr_distances 
) const
virtual

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

Attention
This method does not do any bounds checking for the input index (i.e., index >= cloud.size () || index < 0), and assumes valid (i.e., finite) data.
Parameters
[in]cloudthe point cloud data
[in]indexa valid index in cloud representing a valid (i.e., finite) 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
Exceptions
assertsin debug mode if the index is not between 0 and the maximum number of points

Reimplemented in pcl::search::Octree< PointT, LeafTWrap, BranchTWrap, OctreeT >.

Definition at line 86 of file search.hpp.

◆ nearestKSearch() [3/4]

template<typename PointT >
virtual int pcl::search::Search< PointT >::nearestKSearch ( const PointT point,
int  k,
Indices k_indices,
std::vector< float > &  k_sqr_distances 
) const
pure virtual

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

Implemented in pcl::search::KdTree< SceneT >, pcl::search::Octree< PointT, LeafTWrap, BranchTWrap, OctreeT >, pcl::search::KdTree< PointT, Tree >, pcl::search::FlannSearch< PointT, FlannDistance >, pcl::search::BruteForce< PointT >, pcl::search::OrganizedNeighbor< PointT >, pcl::search::Octree< PointInT >, and pcl::search::KdTree< pcl::PointXYZRGB >.

Referenced by pcl::getPointCloudDifference(), and pcl::search::Search< PointT >::nearestKSearchT().

◆ nearestKSearch() [4/4]

template<typename PointT >
int pcl::search::Search< PointT >::nearestKSearch ( index_t  index,
int  k,
Indices k_indices,
std::vector< float > &  k_sqr_distances 
) const
virtual

Search for k-nearest neighbors for the given query point (zero-copy).

Attention
This method does not do any bounds checking for the input index (i.e., index >= cloud.size () || index < 0), and assumes valid (i.e., finite) data.
Parameters
[in]indexa valid index representing a valid query point in the dataset given by setInputCloud. If indices were given in setInputCloud, index will be the position in the indices vector.
[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
Exceptions
assertsin debug mode if the index is not between 0 and the maximum number of points

Reimplemented in pcl::search::Octree< PointT, LeafTWrap, BranchTWrap, OctreeT >, and pcl::search::Octree< PointInT >.

Definition at line 96 of file search.hpp.

◆ nearestKSearchT() [1/2]

template<typename PointT >
template<typename PointTDiff >
void pcl::search::Search< PointT >::nearestKSearchT ( const pcl::PointCloud< PointTDiff > &  cloud,
const Indices indices,
int  k,
std::vector< Indices > &  k_indices,
std::vector< std::vector< float > > &  k_sqr_distances 
) const
inline

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

Use this method if the query points are of a different type than the points in the data set (e.g. PointXYZRGBA instead of PointXYZ).

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
Note
This method copies the input point cloud of type PointTDiff to a temporary cloud of type PointT and performs the batch search on the new cloud. You should prefer the single-point search if you don't use a search algorithm that accelerates batch NN search.

Definition at line 230 of file search.h.

References pcl::search::Search< PointT >::nearestKSearch(), pcl::PointCloud< PointT >::resize(), and pcl::PointCloud< PointT >::size().

◆ nearestKSearchT() [2/2]

template<typename PointT >
template<typename PointTDiff >
int pcl::search::Search< PointT >::nearestKSearchT ( const PointTDiff &  point,
int  k,
Indices k_indices,
std::vector< float > &  k_sqr_distances 
) const
inline

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

This method accepts a different template parameter for the point type.

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

Definition at line 158 of file search.h.

References pcl::copyPoint(), and pcl::search::Search< PointT >::nearestKSearch().

◆ radiusSearch() [1/4]

template<typename PointT >
void pcl::search::Search< PointT >::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
virtual

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

Parameters
[in]cloudthe point cloud data
[in]indicesthe indices in cloud. If indices is empty, neighbors will be searched for all points.
[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. 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.

Reimplemented in pcl::search::FlannSearch< PointT, FlannDistance >.

Definition at line 163 of file search.hpp.

References pcl::PointCloud< PointT >::size().

◆ radiusSearch() [2/4]

template<typename PointT >
int pcl::search::Search< PointT >::radiusSearch ( const PointCloud cloud,
index_t  index,
double  radius,
Indices k_indices,
std::vector< float > &  k_sqr_distances,
unsigned int  max_nn = 0 
) const
virtual

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

Attention
This method does not do any bounds checking for the input index (i.e., index >= cloud.size () || index < 0), and assumes valid (i.e., finite) data.
Parameters
[in]cloudthe point cloud data
[in]indexa valid index in cloud representing a valid (i.e., finite) 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
Exceptions
assertsin debug mode if the index is not between 0 and the maximum number of points

Reimplemented in pcl::search::Octree< PointT, LeafTWrap, BranchTWrap, OctreeT >.

Definition at line 137 of file search.hpp.

References pcl::PointCloud< PointT >::size().

◆ radiusSearch() [3/4]

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

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

Implemented in pcl::search::KdTree< SceneT >, pcl::search::KdTree< PointT, Tree >, pcl::search::FlannSearch< PointT, FlannDistance >, pcl::search::BruteForce< PointT >, pcl::search::OrganizedNeighbor< PointT >, pcl::search::Octree< PointT, LeafTWrap, BranchTWrap, OctreeT >, pcl::search::Octree< PointInT >, and pcl::search::KdTree< pcl::PointXYZRGB >.

Referenced by pcl::SmoothedSurfacesKeypoint< PointT, PointNT >::detectKeypoints(), pcl::extractEuclideanClusters(), pcl::extractLabeledEuclideanClusters(), pcl::search::Search< PointT >::radiusSearchT(), and pcl::seededHueSegmentation().

◆ radiusSearch() [4/4]

template<typename PointT >
int pcl::search::Search< PointT >::radiusSearch ( index_t  index,
double  radius,
Indices k_indices,
std::vector< float > &  k_sqr_distances,
unsigned int  max_nn = 0 
) const
virtual

Search for all the nearest neighbors of the query point in a given radius (zero-copy).

Attention
This method does not do any bounds checking for the input index (i.e., index >= cloud.size () || index < 0), and assumes valid (i.e., finite) data.
Parameters
[in]indexa valid index representing a valid query point in the dataset given by setInputCloud. If indices were given in setInputCloud, index will be the position in the indices vector.
[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
Exceptions
assertsin debug mode if the index is not between 0 and the maximum number of points

Reimplemented in pcl::search::Octree< PointT, LeafTWrap, BranchTWrap, OctreeT >, and pcl::search::Octree< PointInT >.

Definition at line 148 of file search.hpp.

◆ radiusSearchT() [1/2]

template<typename PointT >
template<typename PointTDiff >
void pcl::search::Search< PointT >::radiusSearchT ( const pcl::PointCloud< PointTDiff > &  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
inline

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

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. 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.
Note
This method copies the input point cloud of type PointTDiff to a temporary cloud of type PointT and performs the batch search on the new cloud. You should prefer the single-point search if you don't use a search algorithm that accelerates batch NN search.

Definition at line 369 of file search.h.

References pcl::search::Search< PointT >::radiusSearch(), pcl::PointCloud< PointT >::resize(), and pcl::PointCloud< PointT >::size().

◆ radiusSearchT() [2/2]

template<typename PointT >
template<typename PointTDiff >
int pcl::search::Search< PointT >::radiusSearchT ( const PointTDiff &  point,
double  radius,
Indices k_indices,
std::vector< float > &  k_sqr_distances,
unsigned int  max_nn = 0 
) const
inline

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

Definition at line 286 of file search.h.

References pcl::copyPoint(), and pcl::search::Search< PointT >::radiusSearch().

◆ setInputCloud()

template<typename PointT >
bool pcl::search::Search< PointT >::setInputCloud ( const PointCloudConstPtr cloud,
const IndicesConstPtr indices = IndicesConstPtr () 
)
virtual

Pass the input dataset that the search will be performed on.

Parameters
[in]clouda const pointer to the PointCloud data
[in]indicesthe point indices subset that is to be used from the cloud
Returns
True if successful, false if an error occurred, for example because the point cloud is unsuited for the search method.

Reimplemented in pcl::search::OrganizedNeighbor< PointT >, pcl::search::KdTree< PointT, Tree >, pcl::search::KdTree< pcl::PointXYZRGB >, pcl::search::KdTree< SceneT >, pcl::search::FlannSearch< PointT, FlannDistance >, and pcl::search::Octree< PointT, LeafTWrap, BranchTWrap, OctreeT >.

Definition at line 75 of file search.hpp.

◆ setSortedResults()

template<typename PointT >
void pcl::search::Search< PointT >::setSortedResults ( bool  sorted)
virtual

sets whether the results should be sorted (ascending in the distance) or not

Parameters
[in]sortedshould be true if the results should be sorted by the distance in ascending order. Otherwise the results may be returned in any order.

Reimplemented in pcl::search::KdTree< PointT, Tree >, pcl::search::KdTree< pcl::PointXYZRGB >, and pcl::search::KdTree< SceneT >.

Definition at line 61 of file search.hpp.

◆ sortResults()

template<typename PointT >
void pcl::search::Search< PointT >::sortResults ( Indices indices,
std::vector< float > &  distances 
) const
protected

Member Data Documentation

◆ indices_

template<typename PointT >
IndicesConstPtr pcl::search::Search< PointT >::indices_
protected

◆ input_

template<typename PointT >
PointCloudConstPtr pcl::search::Search< PointT >::input_
protected

◆ name_

template<typename PointT >
std::string pcl::search::Search< PointT >::name_
protected

Definition at line 405 of file search.h.

◆ sorted_results_

template<typename PointT >
bool pcl::search::Search< PointT >::sorted_results_
protected

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