ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance > Class Template Reference

#include <knncpp.h>

Public Types

typedef _Scalar Scalar
 
typedef _Distance Distance
 
typedef Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > Matrix
 
typedef Eigen::Matrix< Scalar, _Dimension, Eigen::Dynamic > DataMatrix
 
typedef Eigen::Matrix< Scalar, _Dimension, 1 > DataVector
 
typedef knncpp::Matrixi Matrixi
 

Public Member Functions

 KDTreeMinkowski ()
 
 KDTreeMinkowski (const DataMatrix &data, const bool copy=false)
 
void setBucketSize (const Index bucketSize)
 
void setSorted (const bool sorted)
 
void setBalanced (const bool balanced)
 
void setTakeRoot (const bool takeRoot)
 
void setCompact (const bool compact)
 
void setThreads (const unsigned int threads)
 
void setMaxDistance (const Scalar maxDist)
 
void setData (const DataMatrix &data, const bool copy=false)
 
void setDistance (const Distance &distance)
 
void build ()
 
template<typename Derived >
void query (const Eigen::MatrixBase< Derived > &queryPoints, const size_t knn, Matrixi &indices, Matrix &distances) const
 
void clear ()
 
Index size () const
 
Index dimension () const
 
Index depth () const
 

Detailed Description

template<typename _Scalar, int _Dimension, typename _Distance>
class knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >

Class for performing k nearest neighbour searches with minkowski distances. This kdtree only works reliably with the minkowski distance and its special cases like manhatten or euclidean distance.

See also
ManhattenDistance, EuclideanDistance, ChebyshevDistance, MinkowskiDistance

Definition at line 499 of file knncpp.h.

Member Typedef Documentation

◆ DataMatrix

template<typename _Scalar , int _Dimension, typename _Distance >
typedef Eigen::Matrix<Scalar, _Dimension, Eigen::Dynamic> knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::DataMatrix

Definition at line 504 of file knncpp.h.

◆ DataVector

template<typename _Scalar , int _Dimension, typename _Distance >
typedef Eigen::Matrix<Scalar, _Dimension, 1> knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::DataVector

Definition at line 505 of file knncpp.h.

◆ Distance

template<typename _Scalar , int _Dimension, typename _Distance >
typedef _Distance knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::Distance

Definition at line 502 of file knncpp.h.

◆ Matrix

template<typename _Scalar , int _Dimension, typename _Distance >
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::Matrix

Definition at line 503 of file knncpp.h.

◆ Matrixi

template<typename _Scalar , int _Dimension, typename _Distance >
typedef knncpp::Matrixi knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::Matrixi

Definition at line 506 of file knncpp.h.

◆ Scalar

template<typename _Scalar , int _Dimension, typename _Distance >
typedef _Scalar knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::Scalar

Definition at line 501 of file knncpp.h.

Constructor & Destructor Documentation

◆ KDTreeMinkowski() [1/2]

template<typename _Scalar , int _Dimension, typename _Distance >
knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::KDTreeMinkowski ( )
inline

Constructs an empty KDTree.

Definition at line 920 of file knncpp.h.

◆ KDTreeMinkowski() [2/2]

template<typename _Scalar , int _Dimension, typename _Distance >
knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::KDTreeMinkowski ( const DataMatrix data,
const bool  copy = false 
)
inline

Constructs KDTree with the given data. This does not build the the index of the tree.

Parameters
dataNxM matrix, M points of dimension N
copyif true copies the data, otherwise assumes static data

Definition at line 926 of file knncpp.h.

References copy, and knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::setData().

Member Function Documentation

◆ build()

template<typename _Scalar , int _Dimension, typename _Distance >
void knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::build ( )
inline

Builds the search index of the tree. Data has to be set and must be non-empty.

Definition at line 988 of file knncpp.h.

References knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::clear(), and length().

Referenced by knn_cpp_nearest_neighbors().

◆ clear()

template<typename _Scalar , int _Dimension, typename _Distance >
void knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::clear ( void  )
inline

◆ depth()

template<typename _Scalar , int _Dimension, typename _Distance >
Index knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::depth ( void  ) const
inline

Returns the maxximum depth of the tree.

Returns
maximum depth of the tree

Definition at line 1100 of file knncpp.h.

◆ dimension()

template<typename _Scalar , int _Dimension, typename _Distance >
Index knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::dimension ( ) const
inline

Returns the dimension of the data points in the search index.

Returns
dimension of data points

Definition at line 1096 of file knncpp.h.

Referenced by knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::query().

◆ query()

template<typename _Scalar , int _Dimension, typename _Distance >
template<typename Derived >
void knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::query ( const Eigen::MatrixBase< Derived > &  queryPoints,
const size_t  knn,
Matrixi indices,
Matrix distances 
) const
inline

Queries the tree for the nearest neighbours of the given query points.

The tree has to be built before it can be queried.

The query points have to have the same dimension as the data points of the tree.

The result matrices will be resized appropriatley. Indices and distances will be set to -1 if less than knn neighbours were found.

Parameters
queryPointsNxM matrix, M points of dimension N
knnamount of neighbours to be found
indicesKNNxM matrix, indices of neighbours in the data set
distancesKNNxM matrix, distance between query points and neighbours

Definition at line 1029 of file knncpp.h.

References knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::dimension(), and knncpp::QueryHeap< Scalar >::sort().

Referenced by knn_cpp_nearest_neighbors().

◆ setBalanced()

template<typename _Scalar , int _Dimension, typename _Distance >
void knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::setBalanced ( const bool  balanced)
inline

Set if the tree should be built as balanced as possible. This increases build time, but decreases search time.

Parameters
balancedset true to build a balanced tree

Definition at line 943 of file knncpp.h.

◆ setBucketSize()

template<typename _Scalar , int _Dimension, typename _Distance >
void knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::setBucketSize ( const Index  bucketSize)
inline

Set the maximum amount of data points per leaf in the tree (aka bucket size).

Parameters
bucketSizeamount of points per leaf.

Definition at line 933 of file knncpp.h.

Referenced by knn_cpp_nearest_neighbors().

◆ setCompact()

template<typename _Scalar , int _Dimension, typename _Distance >
void knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::setCompact ( const bool  compact)
inline

Set if the tree should be built with compact leaf nodes. This increases build time, but makes leaf nodes denser (more) points. Thus less visits are necessary.

Parameters
compactset true ti build a tree with compact leafs

Definition at line 956 of file knncpp.h.

◆ setData()

template<typename _Scalar , int _Dimension, typename _Distance >
void knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::setData ( const DataMatrix data,
const bool  copy = false 
)
inline

Set the data points used for this tree. This does not build the tree.

Parameters
dataNxM matrix, M points of dimension N
copyif true data is copied, assumes static data otherwise

Definition at line 974 of file knncpp.h.

References knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::clear(), and copy.

Referenced by knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::KDTreeMinkowski().

◆ setDistance()

template<typename _Scalar , int _Dimension, typename _Distance >
void knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::setDistance ( const Distance distance)
inline

Definition at line 984 of file knncpp.h.

◆ setMaxDistance()

template<typename _Scalar , int _Dimension, typename _Distance >
void knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::setMaxDistance ( const Scalar  maxDist)
inline

Set the maximum distance for querying the tree. The search will be pruned if the maximum distance is set to any positive number.

Parameters
maxDistmaximum distance, <= 0 for no limit

Definition at line 968 of file knncpp.h.

◆ setSorted()

template<typename _Scalar , int _Dimension, typename _Distance >
void knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::setSorted ( const bool  sorted)
inline

Set if the points returned by the queries should be sorted according to their distance to the query points.

Parameters
sortedsort query results

Definition at line 938 of file knncpp.h.

Referenced by knn_cpp_nearest_neighbors().

◆ setTakeRoot()

template<typename _Scalar , int _Dimension, typename _Distance >
void knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::setTakeRoot ( const bool  takeRoot)
inline

Set if the distances after the query should be rooted or not. Taking the root of the distances increases query time, but the function will return true distances instead of their powered versions.

Parameters
takeRootset true if root should be taken else false

Definition at line 950 of file knncpp.h.

◆ setThreads()

template<typename _Scalar , int _Dimension, typename _Distance >
void knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::setThreads ( const unsigned int  threads)
inline

Set the amount of threads that should be used for building and querying the tree. OpenMP has to be enabled for this to work.

Parameters
threadsamount of threads, 0 for optimal choice

Definition at line 962 of file knncpp.h.

Referenced by knn_cpp_nearest_neighbors().

◆ size()

template<typename _Scalar , int _Dimension, typename _Distance >
Index knncpp::KDTreeMinkowski< _Scalar, _Dimension, _Distance >::size ( void  ) const
inline

Returns the amount of data points stored in the search index.

Returns
number of data points

Definition at line 1092 of file knncpp.h.


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