ImFusion SDK 4.3
NearestNeighborSearch Class Reference

#include <ImFusion/Base/NearestNeighborSearch.h>

Nearest neighbor search for points. More...

Detailed Description

Nearest neighbor search for points.

Author
Alexander Ladikos

All returned distances are squared Euclidean distances, all returned indices correspond to the point set used for building the index. The number of results per search point may be less than requested if there were no other points available. Templates are provived for vec3, vec2, vec3f, vec2f and Eigen::VectorXd. This class is not thread-safe. If you want to use the search in multiple threads, construct the index and then use the copy constructor to create an independent copy of the index for each thread.

Classes

class  OutputWrapper
 Helper class for optional distance output, implicitly created from output type T. Do not use directly. More...
 

Public Member Functions

 NearestNeighborSearch (const NearestNeighborSearch &other)
 

Build index of points to search in

template<typename Scalar, int Dim>
bool buildIndex (const std::vector< Eigen::Matrix< Scalar, Dim, 1, 0, Dim, 1 > > &points, const Eigen::Matrix< Scalar, Dim+1, Dim+1, 0, Dim+1, Dim+1 > &matrix=Eigen::Matrix< Scalar, Dim+1, Dim+1 >::Identity())
 Set points and optional matrix to apply to them.
 
bool buildIndex (const std::vector< vecX > &points, std::optional< matX > matrix=std::nullopt)
 Set points of arbitrary dimension, which must be equal over all points and match the given matrix (if any)
 
bool buildIndex (const PointCloud *pc, bool useMatrix=true)
 Set points from point cloud.
 
bool buildIndex (const Mesh *m, bool useMatrix=true)
 Set points from mesh vertices.
 

Multiple search points

template<typename vecT>
bool findNearestNeighbors (const std::vector< vecT > &points, int k, std::vector< std::vector< int > > &indicesOut, OutputWrapper< std::vector< std::vector< double > > > distsSquaredOut={}) const
 Finds the k closest other points for each point.
 
template<typename vecT>
bool findNearestNeighbors (const std::vector< vecT > &points, std::vector< int > &indicesOut, OutputWrapper< std::vector< double > > distsSquaredOut={}) const
 Finds the closest other point to each point.
 
template<typename vecT>
bool findNearestNeighborsRadius (const std::vector< vecT > &points, double radius, std::vector< std::vector< int > > &indicesOut, OutputWrapper< std::vector< std::vector< double > > > distsSquaredOut={}) const
 For each point, finds all other points within the given radius.
 
template<typename vecT>
bool findNearestNeighborsCombined (const std::vector< vecT > &points, int k, double radius, std::vector< std::vector< int > > &indicesOut, OutputWrapper< std::vector< std::vector< double > > > distsSquaredOut={}) const
 Finds the k closest other points for each point within the given radius.
 
template<typename vecT>
bool findNearestNeighborsCombined (const std::vector< vecT > &points, double radius, std::vector< int > &indicesOut, OutputWrapper< std::vector< double > > distsSquaredOut={}) const
 Finds the closest other point to each point within the given radius.
 

Single search point

template<typename vecT>
bool findNearestNeighbors (const vecT &point, int k, std::vector< int > &indicesOut, OutputWrapper< std::vector< double > > distsSquaredOut={}) const
 Finds the k other points closest to point.
 
template<typename vecT>
bool findNearestNeighbors (const vecT &point, int &indexOut, OutputWrapper< double > distSquaredOut={}) const
 Finds the other point closest to point.
 
template<typename vecT>
bool findNearestNeighborsRadius (const vecT &point, double radius, std::vector< int > &indicesOut, OutputWrapper< std::vector< double > > distsSquaredOut={}) const
 Finds all other points within the given radius of point.
 
template<typename vecT>
bool findNearestNeighborsCombined (const vecT &point, int k, double radius, std::vector< int > &indicesOut, OutputWrapper< std::vector< double > > distsSquaredOut={}) const
 Finds the k closest other points within the given radius of point.
 
template<typename vecT>
bool findNearestNeighborsCombined (const vecT &point, double radius, int &indexOut, OutputWrapper< double > distSquaredOut={}) const
 Finds the closest other point within the given radius of point.
 

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close