Main MRPT website > C++ reference for MRPT 1.4.0
List of all members | Classes | Public Types | Public Member Functions | Public Attributes | Protected Types | Protected Attributes | Private Member Functions
nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType > Class Template Reference

Detailed Description

template<typename Distance, class DatasetAdaptor, int DIM = -1, typename IndexType = size_t>
class nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >

kd-tree index

Contains the k-d trees and other information for indexing a set of points for nearest-neighbor matching.

The class "DatasetAdaptor" must provide the following interface (can be non-virtual, inlined methods):

// Must return the number of data points
inline size_t kdtree_get_point_count() const { ... }
// [Only if using the metric_L2_Simple type] Must return the Euclidean (L2) distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class:
inline DistanceType kdtree_distance(const T *p1, const size_t idx_p2,size_t size) const { ... }
// Must return the dim'th component of the idx'th point in the class:
inline T kdtree_get_pt(const size_t idx, int dim) const { ... }
// Optional bounding-box computation: return false to default to a standard bbox computation loop.
// Return true if the BBOX was already computed by the class and returned in "bb" so it can be avoided to redo it again.
// Look at bb.size() to find out the expected dimensionality (e.g. 2 or 3 for point clouds)
template <class BBOX>
bool kdtree_get_bbox(BBOX &bb) const
{
bb[0].low = ...; bb[0].high = ...; // 0th dimension limits
bb[1].low = ...; bb[1].high = ...; // 1st dimension limits
...
return true;
}
size_t size() const
Returns size of index.
Definition: nanoflann.hpp:898
int dim
Dimensionality of each data point.
Definition: nanoflann.hpp:761
Distance::DistanceType DistanceType
Definition: nanoflann.hpp:742
Template Parameters
DatasetAdaptorThe user-provided adaptor (see comments above).
DistanceThe distance metric to use: nanoflann::metric_L1, nanoflann::metric_L2, nanoflann::metric_L2_Simple, etc.
IndexTypeWill be typically size_t or int

Definition at line 735 of file nanoflann.hpp.

#include <mrpt/otherlibs/nanoflann/nanoflann.hpp>

Classes

struct  BranchStruct
 This record represents a branch point when finding neighbors in the tree. More...
 
struct  Interval
 
struct  Node
 

Public Types

typedef Distance::ElementType ElementType
 
typedef Distance::DistanceType DistanceType
 

Public Member Functions

 KDTreeSingleIndexAdaptor (const int dimensionality, const DatasetAdaptor &inputData, const KDTreeSingleIndexAdaptorParams &params=KDTreeSingleIndexAdaptorParams())
 KDTree constructor. More...
 
 ~KDTreeSingleIndexAdaptor ()
 Standard destructor. More...
 
void freeIndex ()
 Frees the previously-built index. More...
 
void buildIndex ()
 Builds the index. More...
 
size_t size () const
 Returns size of index. More...
 
size_t veclen () const
 Returns the length of an index feature. More...
 
size_t usedMemory () const
 Computes the inde memory usage Returns: memory used by the index. More...
 
void saveIndex (FILE *stream)
 Stores the index in a binary file. More...
 
void loadIndex (FILE *stream)
 Loads a previous index from a binary file. More...
 
Query methods
template<typename RESULTSET >
void findNeighbors (RESULTSET &result, const ElementType *vec, const SearchParams &searchParams) const
 Find set of nearest neighbors to vec[0:dim-1]. More...
 
void knnSearch (const ElementType *query_point, const size_t num_closest, IndexType *out_indices, DistanceType *out_distances_sq, const int=10) const
 Find the "num_closest" nearest neighbors to the query_point[0:dim-1]. More...
 
size_t radiusSearch (const ElementType *query_point, const DistanceType radius, std::vector< std::pair< IndexType, DistanceType > > &IndicesDists, const SearchParams &searchParams) const
 Find all the neighbors to query_point[0:dim-1] within a maximum radius. More...
 

Public Attributes

Distance distance
 

Protected Types

typedef NodeNodePtr
 
typedef array_or_vector_selector< DIM, Interval >::container_t BoundingBox
 Define "BoundingBox" as a fixed-size or variable-size container depending on "DIM". More...
 
typedef array_or_vector_selector< DIM, DistanceType >::container_t distance_vector_t
 Define "distance_vector_t" as a fixed-size or variable-size container depending on "DIM". More...
 
typedef BranchStruct< NodePtr, DistanceTypeBranchSt
 
typedef BranchStBranch
 

Protected Attributes

std::vector< IndexType > vind
 Array of indices to vectors in the dataset. More...
 
size_t m_leaf_max_size
 
const DatasetAdaptor & dataset
 The dataset used by this index. More...
 
const KDTreeSingleIndexAdaptorParams index_params
 
size_t m_size
 
int dim
 Dimensionality of each data point. More...
 
NodePtr root_node
 Array of k-d trees used to find neighbours. More...
 
BoundingBox root_bbox
 
PooledAllocator pool
 Pooled memory allocator. More...
 

Private Member Functions

 KDTreeSingleIndexAdaptor (const KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType > &)
 Hidden copy constructor, to disallow copying indices (Not implemented) More...
 
void init_vind ()
 Make sure the auxiliary list vind has the same size than the current dataset, and re-generate if size has changed. More...
 
ElementType dataset_get (size_t idx, int component) const
 Helper accessor to the dataset points: More...
 
void save_tree (FILE *stream, NodePtr tree)
 
void load_tree (FILE *stream, NodePtr &tree)
 
void computeBoundingBox (BoundingBox &bbox)
 
NodePtr divideTree (const IndexType left, const IndexType right, BoundingBox &bbox)
 Create a tree node that subdivides the list of vecs from vind[first] to vind[last]. More...
 
void computeMinMax (IndexType *ind, IndexType count, int element, ElementType &min_elem, ElementType &max_elem)
 
void middleSplit_ (IndexType *ind, IndexType count, IndexType &index, int &cutfeat, DistanceType &cutval, const BoundingBox &bbox)
 
void planeSplit (IndexType *ind, const IndexType count, int cutfeat, DistanceType cutval, IndexType &lim1, IndexType &lim2)
 Subdivide the list of points by a plane perpendicular on axe corresponding to the 'cutfeat' dimension at 'cutval' position. More...
 
DistanceType computeInitialDistances (const ElementType *vec, distance_vector_t &dists) const
 
template<class RESULTSET >
void searchLevel (RESULTSET &result_set, const ElementType *vec, const NodePtr node, DistanceType mindistsq, distance_vector_t &dists, const float epsError) const
 Performs an exact search in the tree starting from a node. More...
 

Member Typedef Documentation

◆ BoundingBox

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
typedef array_or_vector_selector<DIM,Interval>::container_t nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::BoundingBox
protected

Define "BoundingBox" as a fixed-size or variable-size container depending on "DIM".

Definition at line 801 of file nanoflann.hpp.

◆ Branch

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
typedef BranchSt* nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::Branch
protected

Definition at line 830 of file nanoflann.hpp.

◆ BranchSt

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
typedef BranchStruct<NodePtr, DistanceType> nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::BranchSt
protected

Definition at line 829 of file nanoflann.hpp.

◆ distance_vector_t

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
typedef array_or_vector_selector<DIM,DistanceType>::container_t nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::distance_vector_t
protected

Define "distance_vector_t" as a fixed-size or variable-size container depending on "DIM".

Definition at line 804 of file nanoflann.hpp.

◆ DistanceType

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
typedef Distance::DistanceType nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::DistanceType

Definition at line 742 of file nanoflann.hpp.

◆ ElementType

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
typedef Distance::ElementType nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::ElementType

Definition at line 741 of file nanoflann.hpp.

◆ NodePtr

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
typedef Node* nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::NodePtr
protected

Definition at line 792 of file nanoflann.hpp.

Constructor & Destructor Documentation

◆ KDTreeSingleIndexAdaptor() [1/2]

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::KDTreeSingleIndexAdaptor ( const KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType > &  )
private

Hidden copy constructor, to disallow copying indices (Not implemented)

◆ KDTreeSingleIndexAdaptor() [2/2]

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::KDTreeSingleIndexAdaptor ( const int  dimensionality,
const DatasetAdaptor &  inputData,
const KDTreeSingleIndexAdaptorParams params = KDTreeSingleIndexAdaptorParams() 
)
inline

KDTree constructor.

Params: inputData = dataset with the input features params = parameters passed to the kdtree algorithm (see http://code.google.com/p/nanoflann/ for help choosing the parameters)

Definition at line 854 of file nanoflann.hpp.

◆ ~KDTreeSingleIndexAdaptor()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::~KDTreeSingleIndexAdaptor ( )
inline

Standard destructor.

Definition at line 872 of file nanoflann.hpp.

Member Function Documentation

◆ buildIndex()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
void nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::buildIndex ( )
inline

◆ computeBoundingBox()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
void nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::computeBoundingBox ( BoundingBox bbox)
inlineprivate

Definition at line 1026 of file nanoflann.hpp.

References nanoflann::CArray< T, N >::resize().

◆ computeInitialDistances()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
DistanceType nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::computeInitialDistances ( const ElementType vec,
distance_vector_t dists 
) const
inlineprivate

Definition at line 1201 of file nanoflann.hpp.

◆ computeMinMax()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
void nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::computeMinMax ( IndexType *  ind,
IndexType  count,
int  element,
ElementType min_elem,
ElementType max_elem 
)
inlineprivate

Definition at line 1110 of file nanoflann.hpp.

◆ dataset_get()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
ElementType nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::dataset_get ( size_t  idx,
int  component 
) const
inlineprivate

Helper accessor to the dataset points:

Definition at line 996 of file nanoflann.hpp.

◆ divideTree()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
NodePtr nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::divideTree ( const IndexType  left,
const IndexType  right,
BoundingBox bbox 
)
inlineprivate

◆ findNeighbors()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
template<typename RESULTSET >
void nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::findNeighbors ( RESULTSET &  result,
const ElementType vec,
const SearchParams searchParams 
) const
inline

◆ freeIndex()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
void nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::freeIndex ( )
inline

Frees the previously-built index.

Automatically called within buildIndex().

Definition at line 877 of file nanoflann.hpp.

References nanoflann::PooledAllocator::free_all().

◆ init_vind()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
void nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::init_vind ( )
inlineprivate

Make sure the auxiliary list vind has the same size than the current dataset, and re-generate if size has changed.

Definition at line 987 of file nanoflann.hpp.

◆ knnSearch()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
void nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::knnSearch ( const ElementType query_point,
const size_t  num_closest,
IndexType *  out_indices,
DistanceType out_distances_sq,
const int  = 10 
) const
inline

Find the "num_closest" nearest neighbors to the query_point[0:dim-1].

Their indices are stored inside the result object.

See also
radiusSearch, findNeighbors
Note
nChecks_IGNORED is ignored but kept for compatibility with the original FLANN interface.

Definition at line 953 of file nanoflann.hpp.

References nanoflann::KNNResultSet< DistanceType, IndexType, CountType >::init().

◆ load_tree()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
void nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::load_tree ( FILE *  stream,
NodePtr tree 
)
inlineprivate

◆ loadIndex()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
void nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::loadIndex ( FILE *  stream)
inline

Loads a previous index from a binary file.

IMPORTANT NOTE: The set of data points is NOT stored in the file, so the index object must be constructed associated to the same source of data points used while building the index. See the example: examples/saveload_example.cpp

See also
loadIndex

Definition at line 1293 of file nanoflann.hpp.

References nanoflann::load_value().

◆ middleSplit_()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
void nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::middleSplit_ ( IndexType *  ind,
IndexType  count,
IndexType &  index,
int &  cutfeat,
DistanceType cutval,
const BoundingBox bbox 
)
inlineprivate

Definition at line 1121 of file nanoflann.hpp.

◆ planeSplit()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
void nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::planeSplit ( IndexType *  ind,
const IndexType  count,
int  cutfeat,
DistanceType  cutval,
IndexType &  lim1,
IndexType &  lim2 
)
inlineprivate

Subdivide the list of points by a plane perpendicular on axe corresponding to the 'cutfeat' dimension at 'cutval' position.

On return: dataset[ind[0..lim1-1]][cutfeat]<cutval dataset[ind[lim1..lim2-1]][cutfeat]==cutval dataset[ind[lim2..count]][cutfeat]>cutval

Definition at line 1172 of file nanoflann.hpp.

◆ radiusSearch()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
size_t nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::radiusSearch ( const ElementType query_point,
const DistanceType  radius,
std::vector< std::pair< IndexType, DistanceType > > &  IndicesDists,
const SearchParams searchParams 
) const
inline

Find all the neighbors to query_point[0:dim-1] within a maximum radius.

The output is given as a vector of pairs, of which the first element is a point index and the second the corresponding distance. Previous contents of IndicesDists are cleared.

If searchParams.sorted==true, the output list is sorted by ascending distances.

For a better performance, it is advisable to do a .reserve() on the vector if you have any wild guess about the number of expected matches.

See also
knnSearch, findNeighbors
Returns
The number of points within the given radius (i.e. indices.size() or dists.size() )

Definition at line 972 of file nanoflann.hpp.

References nanoflann::RadiusResultSet< DistanceType, IndexType >::size(), and nanoflann::SearchParams::sorted.

Referenced by mrpt::math::KDTreeCapable< Derived, num_t, metric_t >::kdTreeRadiusSearch2D(), and mrpt::math::KDTreeCapable< Derived, num_t, metric_t >::kdTreeRadiusSearch3D().

◆ save_tree()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
void nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::save_tree ( FILE *  stream,
NodePtr  tree 
)
inlineprivate

◆ saveIndex()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
void nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::saveIndex ( FILE *  stream)
inline

Stores the index in a binary file.

IMPORTANT NOTE: The set of data points is NOT stored in the file, so when loading the index object it must be constructed associated to the same source of data points used while building it. See the example: examples/saveload_example.cpp

See also
loadIndex

Definition at line 1279 of file nanoflann.hpp.

References nanoflann::save_value().

◆ searchLevel()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
template<class RESULTSET >
void nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::searchLevel ( RESULTSET &  result_set,
const ElementType vec,
const NodePtr  node,
DistanceType  mindistsq,
distance_vector_t dists,
const float  epsError 
) const
inlineprivate

◆ size()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
size_t nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::size ( ) const
inline

Returns size of index.

Definition at line 898 of file nanoflann.hpp.

◆ usedMemory()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
size_t nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::usedMemory ( ) const
inline

Computes the inde memory usage Returns: memory used by the index.

Definition at line 915 of file nanoflann.hpp.

References nanoflann::PooledAllocator::usedMemory, and nanoflann::PooledAllocator::wastedMemory.

◆ veclen()

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
size_t nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::veclen ( ) const
inline

Returns the length of an index feature.

Definition at line 906 of file nanoflann.hpp.

Member Data Documentation

◆ dataset

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
const DatasetAdaptor& nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::dataset
protected

The dataset used by this index.

The source of our data

Definition at line 756 of file nanoflann.hpp.

◆ dim

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
int nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::dim
protected

Dimensionality of each data point.

Definition at line 761 of file nanoflann.hpp.

◆ distance

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
Distance nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::distance

Definition at line 845 of file nanoflann.hpp.

◆ index_params

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
const KDTreeSingleIndexAdaptorParams nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::index_params
protected

Definition at line 758 of file nanoflann.hpp.

◆ m_leaf_max_size

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
size_t nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::m_leaf_max_size
protected

Definition at line 750 of file nanoflann.hpp.

◆ m_size

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
size_t nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::m_size
protected

Definition at line 760 of file nanoflann.hpp.

◆ pool

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
PooledAllocator nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::pool
protected

Pooled memory allocator.

Using a pooled memory allocator is more efficient than allocating memory directly when there is a large number small of memory allocations.

Definition at line 841 of file nanoflann.hpp.

◆ root_bbox

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
BoundingBox nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::root_bbox
protected

Definition at line 832 of file nanoflann.hpp.

◆ root_node

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
NodePtr nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::root_node
protected

Array of k-d trees used to find neighbours.

Definition at line 828 of file nanoflann.hpp.

◆ vind

template<typename Distance , class DatasetAdaptor , int DIM = -1, typename IndexType = size_t>
std::vector<IndexType> nanoflann::KDTreeSingleIndexAdaptor< Distance, DatasetAdaptor, DIM, IndexType >::vind
protected

Array of indices to vectors in the dataset.

Definition at line 748 of file nanoflann.hpp.




Page generated by Doxygen 1.9.5 for MRPT 1.4.0 SVN: at Tue Dec 27 00:53:09 UTC 2022