iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nrt::Search Class Reference

#include <nrt/PointCloud2/Search/Search.H>

A class for searching point clouds.

Provides functionality to search through a point cloud based upon an approximate KDTree implementation powered by FLANN.

Examples:
tests/test-PointCloud2Search.C.

Definition at line 51 of file Search.H.

Inheritance diagram for nrt::Search:
nrt::SourceCloud

Public Types

typedef PointCloud2::Geometry Geometry
 
typedef PointCloud2::BaseType BaseType
 

Public Member Functions

 Search (double epsilon=0.0)
 Create an empty search. More...
 
 Search (PointCloud2 const input, double epsilon=0.0)
 Create a new search based upon a point cloud. More...
 
 Search (PointCloud2 const input, Indices const indices, double epsilon=0.0)
 Create a new search based upon a point cloud subset. More...
 
std::vector< std::pair< size_t,
BaseType > > 
knn (Geometry const &query, int k)
 Perform a k-nearest neighbor search on the geometry. More...
 
template<class Field >
std::vector< std::pair< size_t,
BaseType > > 
knn (Field const &query, int k)
 Perform a k-nearest neighbor search on a specific field. More...
 
template<class Field , class Distance >
std::vector< std::pair< size_t,
BaseType > > 
knn (Field const &query, int k, Distance const &dist)
 Perform a k-nearest neighbor search on a specific field using a non-standard Distance functor. More...
 
std::vector< std::pair< size_t,
BaseType > > 
radius (Geometry const &query, double const radius, size_t maxResults=0, bool sort=false)
 Perform a fixed radius search on the geometry. More...
 
template<class Field >
std::vector< std::pair< size_t,
BaseType > > 
radius (Field const &query, double const radius, size_t maxResults=0, bool sort=false)
 Perform a fixed radius search on a specific field. More...
 
void rebuild (PointCloud2 const cloud)
 Forces a rebuild on the next search to match an updated point cloud. More...
 
void rebuild (PointCloud2 const cloud, Indices const indices)
 Forces a rebuild on the next search to match an updated point cloud. More...
 
template<class Field >
auto knn (Field const &query, int k) -> std::vector< std::pair< size_t, BaseType >>
 
template<class Field , class Distance >
auto knn (Field const &query, int k, Distance const &dist) -> std::vector< std::pair< size_t, BaseType >>
 
template<class Field , class Distance >
auto knnImpl (Field const &query, int k, Distance const &dist, std::unique_ptr< flann::Index< Distance >> &indexPtr) -> std::vector< std::pair< size_t, BaseType >>
 
template<class Field >
auto radius (Field const &query, double const radius, size_t maxResults, bool sort) -> std::vector< std::pair< size_t, BaseType >>
 
- Public Member Functions inherited from nrt::SourceCloud
 SourceCloud ()
 Initializes with no data.
 
 SourceCloud (PointCloud2 const cloud)
 Initializes with a point cloud and no subset.
 
 SourceCloud (PointCloud2 const cloud, Indices const indices)
 Initializes with a point cloud and a specific subset.
 
size_t getWorkingSize () const
 Returns the current working size of the Source. More...
 

Static Public Member Functions

static Indices extractIndices (std::vector< std::pair< size_t, BaseType >> const &results)
 Convenience function to extract the results of a search as a set of indices.
 

Protected Member Functions

template<class Field , class Distance >
std::vector< std::pair< size_t,
BaseType > > 
knnImpl (Field const &query, int k, Distance const &dist, std::unique_ptr< flann::Index< Distance >> &indexPtr)
 Does the actual work for a specific field knn search. More...
 
bool rebuildFLANNIndex ()
 Rebuilds FLANN index if necessary. More...
 
template<class Field >
bool rebuildFLANNIndex ()
 Rebuilds FLANN index if necessary. More...
 
template<class Field , class Distance >
bool rebuildFLANNIndex (Distance const &dist, std::unique_ptr< flann::Index< Distance >> &indexPtr)
 Rebuilds FLANN index if necessary. More...
 
- Protected Member Functions inherited from nrt::SourceCloud
void setCloud (PointCloud2 const cloud)
 Sets to use a specific cloud.
 
void setCloud (PointCloud2 const cloud, Indices const indices)
 Sets to sue a specific subset of a cloud.
 

Additional Inherited Members

- Public Attributes inherited from nrt::SourceCloud
PointCloud2 cloud
 The source point cloud.
 
Indices indices
 The optional indices.
 
bool useSubset
 Whether we use a subset or not.
 

Constructor & Destructor Documentation

nrt::Search::Search ( double  epsilon = 0.0)

Create an empty search.

For this search to work, you will need to explicitly call rebuild before performing a search.

Parameters
epsilonThe minimum required accuracy of the search
nrt::Search::Search ( PointCloud2 const  input,
double  epsilon = 0.0 
)

Create a new search based upon a point cloud.

The cloud will be indexed as soon as the first search is conducted. If the search type changes, the index will be rebuilt to the latest search field type

Parameters
inputThe point cloud to search
epsilonThe minimum required accuracy of the search
nrt::Search::Search ( PointCloud2 const  input,
Indices const  indices,
double  epsilon = 0.0 
)

Create a new search based upon a point cloud subset.

The cloud will be indexed as soon as the first search is conducted. If the search type changes, the index will be rebuilt to the latest search field type

Parameters
inputThe point cloud to search
indicesThe subset of the cloud to search through
epsilonThe minimum required accuracy of the search

Member Function Documentation

std::vector<std::pair<size_t, BaseType> > nrt::Search::knn ( Geometry const &  query,
int  k 
)

Perform a k-nearest neighbor search on the geometry.

Will rebuild the search index if the previous search type was not geometry.

If this search is operating upon a subset, the returned indices will refer to the original cloud and not the subset (e.g. instead of 0 referring to the first subset index, it will refer to the real index of whatever subset[0] represents).

Parameters
queryThe geometrical query
kThe maximum number of neighbors to find
Returns
The indices of the neighbors and their squared distances
Examples:
tests/test-PointCloud2Search.C.

Referenced by nrt::CorrespondenceEstimationNearestNeighbor::findReciprocalCorrespondence().

template<class Field >
std::vector<std::pair<size_t, BaseType> > nrt::Search::knn ( Field const &  query,
int  k 
)

Perform a k-nearest neighbor search on a specific field.

Will rebuild the search index if the previous search type was not Field.

If this search is operating upon a subset, the returned indices will refer to the original cloud and not the subset (e.g. instead of 0 referring to the first subset index, it will refer to the real index of whatever subset[0] represents).

Parameters
queryThe specific field query
kThe maximum number of neighbors to find
Returns
The indices of the neighbors and their squared distances
template<class Field , class Distance >
std::vector<std::pair<size_t, BaseType> > nrt::Search::knn ( Field const &  query,
int  k,
Distance const &  dist 
)

Perform a k-nearest neighbor search on a specific field using a non-standard Distance functor.

Will rebuild the search index if the previous search type was not Field or the distance functor changed.

If this search is operating upon a subset, the returned indices will refer to the original cloud and not the subset (e.g. instead of 0 referring to the first subset index, it will refer to the real index of whatever subset[0] represents).

Note
This function is not thread safe
Todo:
revisit and make thread safe
Template Parameters
FieldThe field to query. Can be the geometry as well.
DistanceThe distance functor type
Parameters
queryThe specific field query
kThe maximum number of neighbors to find
distThe distance functor (see flann documentation for examples)
Returns
The indices of the neighbors and their squared distances
std::vector<std::pair<size_t, BaseType> > nrt::Search::radius ( Geometry const &  query,
double const  radius,
size_t  maxResults = 0,
bool  sort = false 
)

Perform a fixed radius search on the geometry.

Will rebuild the search index if the previous search type was not geometry.

If this search is operating upon a subset, the returned indices will refer to the original cloud and not the subset (e.g. instead of 0 referring to the first subset index, it will refer to the real index of whatever subset[0] represents).

Parameters
queryThe geometrical query
radiusThe radius within query to find neighbors
maxResultsThe maximum number of neighbors to find. Zero or > cloud size to return maximum.
sortWhether to sort results by distance (will slow down computation)
Returns
The indices of the neighbors and their squared distances
Examples:
tests/test-PointCloud2Search.C.
template<class Field >
std::vector<std::pair<size_t, BaseType> > nrt::Search::radius ( Field const &  query,
double const  radius,
size_t  maxResults = 0,
bool  sort = false 
)

Perform a fixed radius search on a specific field.

Will rebuild the search index if the previous search type was not Field.

If this search is operating upon a subset, the returned indices will refer to the original cloud and not the subset (e.g. instead of 0 referring to the first subset index, it will refer to the real index of whatever subset[0] represents).

Parameters
queryThe specific field query
radiusThe radius within query to find neighbors
maxResultsThe maximum number of neighbors to find. Zero or > cloud size to return maximum.
sortWhether to sort results by distance (will slow down computation)
Returns
The indices of the neighbors and their squared distances
void nrt::Search::rebuild ( PointCloud2 const  cloud)

Forces a rebuild on the next search to match an updated point cloud.

Since the cloud we reference may be changed externally, which would cause the external cloud to create its own copy of the data, it may be necessary to update the cloud that search is referencing

Examples:
tests/test-PointCloud2Search.C.
void nrt::Search::rebuild ( PointCloud2 const  cloud,
Indices const  indices 
)

Forces a rebuild on the next search to match an updated point cloud.

Since the cloud we reference may be changed externally, which would cause the external cloud to create its own copy of the data, it may be necessary to update the cloud that search is referencing

template<class Field , class Distance >
std::vector<std::pair<size_t, BaseType> > nrt::Search::knnImpl ( Field const &  query,
int  k,
Distance const &  dist,
std::unique_ptr< flann::Index< Distance >> &  indexPtr 
)
protected

Does the actual work for a specific field knn search.

Will rebuild the search index if the previous search type was not Field or the distance functor changed.

If this search is operating upon a subset, the returned indices will refer to the original cloud and not the subset (e.g. instead of 0 referring to the first subset index, it will refer to the real index of whatever subset[0] represents).

Template Parameters
FieldThe field to query. Can be the geometry as well.
DistanceThe distance functor type
Parameters
queryThe specific field query
kThe maximum number of neighbors to find
distThe distance functor (see flann documentation for examples)
indexPtra unique_ptr that is the sole owner of the FLANN index to use
Returns
The indices of the neighbors and their squared distances
bool nrt::Search::rebuildFLANNIndex ( )
inlineprotected

Rebuilds FLANN index if necessary.

Returns
true if the flann index is valid

Definition at line 176 of file SearchImpl.H.

template<class Field >
bool nrt::Search::rebuildFLANNIndex ( )
protected

Rebuilds FLANN index if necessary.

Returns
true if the flann index is valid
template<class Field , class Distance >
bool nrt::Search::rebuildFLANNIndex ( Distance const &  dist,
std::unique_ptr< flann::Index< Distance >> &  indexPtr 
)
inlineprotected

Rebuilds FLANN index if necessary.

Returns
true if the flann index is valid

Definition at line 182 of file SearchImpl.H.

References nrt::SourceCloud::cloud, nrt::SourceCloud::indices, and nrt::SourceCloud::useSubset.


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