A generic adaptor class for providing Approximate Nearest Neighbors (ANN) (via the nanoflann library) to MRPT classses.
This makes use of the CRTP design pattern.
Derived classes must be aware of the need to call "kdtree_mark_as_outdated()" when the data points change to mark the cached KD-tree (an "index") as invalid, and also implement the following interface (note that these are not virtual functions due to the usage of CRTP):
// Must return the number of data points inline size_t kdtree_get_point_count() const { ... } // Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class: inline float kdtree_distance(const float *p1, const size_t idx_p2,size_t size) const { ... } // Returns the dim'th component of the idx'th point in the class: inline num_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 = ...; // "x" limits return true; }
The KD-tree index will be built on demand only upon call of any of the query methods provided by this class.
Notice that there is only ONE internal cached KD-tree, so if a method to query a 2D point is called, then another method for 3D points, then again the 2D method, three KD-trees will be built. So, try to group all the calls for a given dimensionality together or build different class instances for queries of each dimensionality, etc.
#include <mrpt/math/KDTreeCapable.h>

Classes | |
| struct | TKDTreeDataHolder |
| Internal structure with the KD-tree representation (mainly used to avoid copying pointers with the = operator) More... | |
| struct | TKDTreeSearchParams |
Public Types | |
| typedef KDTreeCapable< Derived, num_t, metric_t > | self_t |
Public Member Functions | |
| KDTreeCapable () | |
| Constructor. | |
| ~KDTreeCapable () | |
| Destructor (nothing needed to do here) | |
| const Derived & | derived () const |
| CRTP helper method. | |
| Derived & | derived () |
| CRTP helper method. | |
Public utility methods to query the KD-tree | |
| size_t | kdTreeClosestPoint2D (float x0, float y0, float &out_x, float &out_y, float &out_dist_sqr) const |
| KD Tree-based search for the closest point (only ONE) to some given 2D coordinates. | |
| size_t | kdTreeClosestPoint2D (float x0, float y0, float &out_dist_sqr) const |
| size_t | kdTreeClosestPoint2D (const TPoint2D &p0, TPoint2D &pOut, float &outDistSqr) const |
| float | kdTreeClosestPoint2DsqrError (float x0, float y0) const |
| Like kdTreeClosestPoint2D, but just return the square error from some point to its closest neighbor. | |
| float | kdTreeClosestPoint2DsqrError (const TPoint2D &p0) const |
| void | kdTreeTwoClosestPoint2D (float x0, float y0, float &out_x1, float &out_y1, float &out_x2, float &out_y2, float &out_dist_sqr1, float &out_dist_sqr2) const |
| KD Tree-based search for the TWO closest point to some given 2D coordinates. | |
| void | kdTreeTwoClosestPoint2D (const TPoint2D &p0, TPoint2D &pOut1, TPoint2D &pOut2, float &outDistSqr1, float &outDistSqr2) const |
| std::vector< int > | kdTreeNClosestPoint2D (float x0, float y0, size_t knn, std::vector< float > &out_x, std::vector< float > &out_y, std::vector< float > &out_dist_sqr) const |
| KD Tree-based search for the N closest point to some given 2D coordinates. | |
| std::vector< int > | kdTreeNClosestPoint2D (const TPoint2D &p0, size_t N, std::vector< TPoint2D > &pOut, std::vector< float > &outDistSqr) const |
| void | kdTreeNClosestPoint2DIdx (float x0, float y0, size_t knn, std::vector< int > &out_idx, std::vector< float > &out_dist_sqr) const |
| KD Tree-based search for the N closest point to some given 2D coordinates and returns their indexes. | |
| void | kdTreeNClosestPoint2DIdx (const TPoint2D &p0, size_t N, std::vector< int > &outIdx, std::vector< float > &outDistSqr) const |
| size_t | kdTreeClosestPoint3D (float x0, float y0, float z0, float &out_x, float &out_y, float &out_z, float &out_dist_sqr) const |
| KD Tree-based search for the closest point (only ONE) to some given 3D coordinates. | |
| size_t | kdTreeClosestPoint3D (float x0, float y0, float z0, float &out_dist_sqr) const |
| size_t | kdTreeClosestPoint3D (const TPoint3D &p0, TPoint3D &pOut, float &outDistSqr) const |
| void | kdTreeNClosestPoint3D (float x0, float y0, float z0, size_t knn, std::vector< float > &out_x, std::vector< float > &out_y, std::vector< float > &out_z, std::vector< float > &out_dist_sqr) const |
| KD Tree-based search for the N closest points to some given 3D coordinates. | |
| void | kdTreeNClosestPoint3D (const TPoint3D &p0, size_t N, std::vector< TPoint3D > &pOut, std::vector< float > &outDistSqr) const |
| void | kdTreeNClosestPoint3DIdx (float x0, float y0, float z0, size_t knn, std::vector< int > &out_idx, std::vector< float > &out_dist_sqr) const |
| KD Tree-based search for the N closest point to some given 3D coordinates and returns their indexes. | |
| void | kdTreeNClosestPoint3DIdx (const TPoint3D &p0, size_t N, std::vector< int > &outIdx, std::vector< float > &outDistSqr) const |
Public Attributes | |
| TKDTreeSearchParams | kdtree_search_params |
| Parameters to tune the ANN searches. | |
Protected Member Functions | |
| void | kdtree_mark_as_outdated () const |
| To be called by child classes when KD tree data changes. | |
Private Member Functions | |
| void | rebuild_kdTree_2D () const |
| Rebuild, if needed the KD-tree for 2D (nDims=2), 3D (nDims=3), ... asking the child class for the data points. | |
| void | rebuild_kdTree_3D () const |
| Rebuild, if needed the KD-tree for 2D (nDims=2), 3D (nDims=3), ... asking the child class for the data points. | |
| void | rebuild_kdTree_Nd (const size_t nDims) const |
| Rebuild, if needed the KD-tree for 2D (nDims=2), 3D (nDims=3), ... asking the child class for the data points. | |
Private Attributes | |
| TKDTreeDataHolder< 2 > | m_kdtree2d_data |
| TKDTreeDataHolder< 3 > | m_kdtree3d_data |
| TKDTreeDataHolder | m_kdtreeNd_data |
| bool | m_kdtree_is_uptodate |
| whether the KD tree needs to be rebuilt or not. | |
| typedef KDTreeCapable<Derived,num_t,metric_t> mrpt::math::KDTreeCapable::self_t |
Definition at line 90 of file KDTreeCapable.h.
| mrpt::math::KDTreeCapable::KDTreeCapable | ( | ) | [inline] |
Constructor.
Definition at line 94 of file KDTreeCapable.h.
| mrpt::math::KDTreeCapable::~KDTreeCapable | ( | ) | [inline] |
Destructor (nothing needed to do here)
Definition at line 97 of file KDTreeCapable.h.
| const Derived& mrpt::math::KDTreeCapable::derived | ( | ) | const [inline] |
CRTP helper method.
Definition at line 100 of file KDTreeCapable.h.
Referenced by mrpt::math::KDTreeCapable< CFeatureList >::kdTreeClosestPoint2D(), mrpt::math::KDTreeCapable< CFeatureList >::kdTreeTwoClosestPoint2D(), mrpt::math::KDTreeCapable< CFeatureList >::kdTreeNClosestPoint2D(), mrpt::math::KDTreeCapable< CFeatureList >::kdTreeClosestPoint3D(), mrpt::math::KDTreeCapable< CFeatureList >::kdTreeNClosestPoint3D(), mrpt::math::KDTreeCapable< CFeatureList >::rebuild_kdTree_2D(), mrpt::math::KDTreeCapable< CFeatureList >::rebuild_kdTree_3D(), and mrpt::math::KDTreeCapable< CFeatureList >::rebuild_kdTree_Nd().
| Derived& mrpt::math::KDTreeCapable::derived | ( | ) | [inline] |
CRTP helper method.
Definition at line 102 of file KDTreeCapable.h.
| void mrpt::math::KDTreeCapable::kdtree_mark_as_outdated | ( | ) | const [inline, protected] |
To be called by child classes when KD tree data changes.
Definition at line 575 of file KDTreeCapable.h.
| size_t mrpt::math::KDTreeCapable::kdTreeClosestPoint2D | ( | float | x0, |
| float | y0, | ||
| float & | out_x, | ||
| float & | out_y, | ||
| float & | out_dist_sqr | ||
| ) | const [inline] |
KD Tree-based search for the closest point (only ONE) to some given 2D coordinates.
This method automatically build the "m_kdtree_data" structure when:
| x0 | The X coordinate of the query. |
| y0 | The Y coordinate of the query. |
| out_x | The X coordinate of the found closest correspondence. |
| out_y | The Y coordinate of the found closest correspondence. |
| out_dist_sqr | The square distance between the query and the returned point. |
Definition at line 136 of file KDTreeCapable.h.
Referenced by mrpt::math::KDTreeCapable< CFeatureList >::kdTreeClosestPoint2D(), and mrpt::math::KDTreeCapable< CFeatureList >::kdTreeClosestPoint2DsqrError().
| size_t mrpt::math::KDTreeCapable::kdTreeClosestPoint2D | ( | float | x0, |
| float | y0, | ||
| float & | out_dist_sqr | ||
| ) | const [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 166 of file KDTreeCapable.h.
| size_t mrpt::math::KDTreeCapable::kdTreeClosestPoint2D | ( | const TPoint2D & | p0, |
| TPoint2D & | pOut, | ||
| float & | outDistSqr | ||
| ) | const [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 189 of file KDTreeCapable.h.
| float mrpt::math::KDTreeCapable::kdTreeClosestPoint2DsqrError | ( | float | x0, |
| float | y0 | ||
| ) | const [inline] |
Like kdTreeClosestPoint2D, but just return the square error from some point to its closest neighbor.
Definition at line 199 of file KDTreeCapable.h.
Referenced by mrpt::math::KDTreeCapable< CFeatureList >::kdTreeClosestPoint2DsqrError().
| float mrpt::math::KDTreeCapable::kdTreeClosestPoint2DsqrError | ( | const TPoint2D & | p0 | ) | const [inline] |
Definition at line 208 of file KDTreeCapable.h.
| size_t mrpt::math::KDTreeCapable::kdTreeClosestPoint3D | ( | float | x0, |
| float | y0, | ||
| float | z0, | ||
| float & | out_x, | ||
| float & | out_y, | ||
| float & | out_z, | ||
| float & | out_dist_sqr | ||
| ) | const [inline] |
KD Tree-based search for the closest point (only ONE) to some given 3D coordinates.
This method automatically build the "m_kdtree_data" structure when:
| x0 | The X coordinate of the query. |
| y0 | The Y coordinate of the query. |
| z0 | The Z coordinate of the query. |
| out_x | The X coordinate of the found closest correspondence. |
| out_y | The Y coordinate of the found closest correspondence. |
| out_z | The Z coordinate of the found closest correspondence. |
| out_dist_sqr | The square distance between the query and the returned point. |
Definition at line 394 of file KDTreeCapable.h.
Referenced by mrpt::math::KDTreeCapable< CFeatureList >::kdTreeClosestPoint3D().
| size_t mrpt::math::KDTreeCapable::kdTreeClosestPoint3D | ( | float | x0, |
| float | y0, | ||
| float | z0, | ||
| float & | out_dist_sqr | ||
| ) | const [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 428 of file KDTreeCapable.h.
| size_t mrpt::math::KDTreeCapable::kdTreeClosestPoint3D | ( | const TPoint3D & | p0, |
| TPoint3D & | pOut, | ||
| float & | outDistSqr | ||
| ) | const [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 454 of file KDTreeCapable.h.
| std::vector<int> mrpt::math::KDTreeCapable::kdTreeNClosestPoint2D | ( | float | x0, |
| float | y0, | ||
| size_t | knn, | ||
| std::vector< float > & | out_x, | ||
| std::vector< float > & | out_y, | ||
| std::vector< float > & | out_dist_sqr | ||
| ) | const [inline] |
KD Tree-based search for the N closest point to some given 2D coordinates.
This method automatically build the "m_kdtree_data" structure when:
| x0 | The X coordinate of the query. |
| y0 | The Y coordinate of the query. |
| N | The number of closest points to search. |
| out_x | The vector containing the X coordinates of the correspondences. |
| out_y | The vector containing the Y coordinates of the correspondences. |
| out_dist_sqr | The vector containing the square distance between the query and the returned points. |
Definition at line 293 of file KDTreeCapable.h.
Referenced by mrpt::math::KDTreeCapable< CFeatureList >::kdTreeNClosestPoint2D().
| std::vector<int> mrpt::math::KDTreeCapable::kdTreeNClosestPoint2D | ( | const TPoint2D & | p0, |
| size_t | N, | ||
| std::vector< TPoint2D > & | pOut, | ||
| std::vector< float > & | outDistSqr | ||
| ) | const [inline] |
Definition at line 326 of file KDTreeCapable.h.
| void mrpt::math::KDTreeCapable::kdTreeNClosestPoint2DIdx | ( | float | x0, |
| float | y0, | ||
| size_t | knn, | ||
| std::vector< int > & | out_idx, | ||
| std::vector< float > & | out_dist_sqr | ||
| ) | const [inline] |
KD Tree-based search for the N closest point to some given 2D coordinates and returns their indexes.
This method automatically build the "m_kdtree_data" structure when:
| x0 | The X coordinate of the query. |
| y0 | The Y coordinate of the query. |
| N | The number of closest points to search. |
| out_idx | The indexes of the found closest correspondence. |
| out_dist_sqr | The square distance between the query and the returned point. |
Definition at line 351 of file KDTreeCapable.h.
Referenced by mrpt::math::KDTreeCapable< CFeatureList >::kdTreeNClosestPoint2DIdx().
| void mrpt::math::KDTreeCapable::kdTreeNClosestPoint2DIdx | ( | const TPoint2D & | p0, |
| size_t | N, | ||
| std::vector< int > & | outIdx, | ||
| std::vector< float > & | outDistSqr | ||
| ) | const [inline] |
Definition at line 373 of file KDTreeCapable.h.
| void mrpt::math::KDTreeCapable::kdTreeNClosestPoint3D | ( | float | x0, |
| float | y0, | ||
| float | z0, | ||
| size_t | knn, | ||
| std::vector< float > & | out_x, | ||
| std::vector< float > & | out_y, | ||
| std::vector< float > & | out_z, | ||
| std::vector< float > & | out_dist_sqr | ||
| ) | const [inline] |
KD Tree-based search for the N closest points to some given 3D coordinates.
This method automatically build the "m_kdtree_data" structure when:
| x0 | The X coordinate of the query. |
| y0 | The Y coordinate of the query. |
| z0 | The Z coordinate of the query. |
| N | The number of closest points to search. |
| out_x | The vector containing the X coordinates of the correspondences. |
| out_y | The vector containing the Y coordinates of the correspondences. |
| out_z | The vector containing the Z coordinates of the correspondences. |
| out_dist_sqr | The vector containing the square distance between the query and the returned points. |
Definition at line 480 of file KDTreeCapable.h.
Referenced by mrpt::math::KDTreeCapable< CFeatureList >::kdTreeNClosestPoint3D().
| void mrpt::math::KDTreeCapable::kdTreeNClosestPoint3D | ( | const TPoint3D & | p0, |
| size_t | N, | ||
| std::vector< TPoint3D > & | pOut, | ||
| std::vector< float > & | outDistSqr | ||
| ) | const [inline] |
Definition at line 517 of file KDTreeCapable.h.
| void mrpt::math::KDTreeCapable::kdTreeNClosestPoint3DIdx | ( | float | x0, |
| float | y0, | ||
| float | z0, | ||
| size_t | knn, | ||
| std::vector< int > & | out_idx, | ||
| std::vector< float > & | out_dist_sqr | ||
| ) | const [inline] |
KD Tree-based search for the N closest point to some given 3D coordinates and returns their indexes.
This method automatically build the "m_kdtree_data" structure when:
| x0 | The X coordinate of the query. |
| y0 | The Y coordinate of the query. |
| z0 | The Z coordinate of the query. |
| N | The number of closest points to search. |
| out_idx | The indexes of the found closest correspondence. |
| out_dist_sqr | The square distance between the query and the returned point. |
Definition at line 543 of file KDTreeCapable.h.
Referenced by mrpt::math::KDTreeCapable< CFeatureList >::kdTreeNClosestPoint3DIdx().
| void mrpt::math::KDTreeCapable::kdTreeNClosestPoint3DIdx | ( | const TPoint3D & | p0, |
| size_t | N, | ||
| std::vector< int > & | outIdx, | ||
| std::vector< float > & | outDistSqr | ||
| ) | const [inline] |
Definition at line 567 of file KDTreeCapable.h.
| void mrpt::math::KDTreeCapable::kdTreeTwoClosestPoint2D | ( | float | x0, |
| float | y0, | ||
| float & | out_x1, | ||
| float & | out_y1, | ||
| float & | out_x2, | ||
| float & | out_y2, | ||
| float & | out_dist_sqr1, | ||
| float & | out_dist_sqr2 | ||
| ) | const [inline] |
KD Tree-based search for the TWO closest point to some given 2D coordinates.
This method automatically build the "m_kdtree_data" structure when:
| x0 | The X coordinate of the query. |
| y0 | The Y coordinate of the query. |
| out_x1 | The X coordinate of the first correspondence. |
| out_y1 | The Y coordinate of the first correspondence. |
| out_x2 | The X coordinate of the second correspondence. |
| out_y2 | The Y coordinate of the second correspondence. |
| out_dist_sqr1 | The square distance between the query and the first returned point. |
| out_dist_sqr2 | The square distance between the query and the second returned point. |
Definition at line 229 of file KDTreeCapable.h.
Referenced by mrpt::math::KDTreeCapable< CFeatureList >::kdTreeTwoClosestPoint2D().
| void mrpt::math::KDTreeCapable::kdTreeTwoClosestPoint2D | ( | const TPoint2D & | p0, |
| TPoint2D & | pOut1, | ||
| TPoint2D & | pOut2, | ||
| float & | outDistSqr1, | ||
| float & | outDistSqr2 | ||
| ) | const [inline] |
Definition at line 266 of file KDTreeCapable.h.
| void mrpt::math::KDTreeCapable::rebuild_kdTree_2D | ( | ) | const [inline, private] |
Rebuild, if needed the KD-tree for 2D (nDims=2), 3D (nDims=3), ... asking the child class for the data points.
Definition at line 615 of file KDTreeCapable.h.
Referenced by mrpt::math::KDTreeCapable< CFeatureList >::kdTreeClosestPoint2D(), mrpt::math::KDTreeCapable< CFeatureList >::kdTreeTwoClosestPoint2D(), mrpt::math::KDTreeCapable< CFeatureList >::kdTreeNClosestPoint2D(), and mrpt::math::KDTreeCapable< CFeatureList >::kdTreeNClosestPoint2DIdx().
| void mrpt::math::KDTreeCapable::rebuild_kdTree_3D | ( | ) | const [inline, private] |
Rebuild, if needed the KD-tree for 2D (nDims=2), 3D (nDims=3), ... asking the child class for the data points.
Definition at line 640 of file KDTreeCapable.h.
Referenced by mrpt::math::KDTreeCapable< CFeatureList >::kdTreeClosestPoint3D(), mrpt::math::KDTreeCapable< CFeatureList >::kdTreeNClosestPoint3D(), and mrpt::math::KDTreeCapable< CFeatureList >::kdTreeNClosestPoint3DIdx().
| void mrpt::math::KDTreeCapable::rebuild_kdTree_Nd | ( | const size_t | nDims | ) | const [inline, private] |
Rebuild, if needed the KD-tree for 2D (nDims=2), 3D (nDims=3), ... asking the child class for the data points.
Definition at line 665 of file KDTreeCapable.h.
Parameters to tune the ANN searches.
Definition at line 116 of file KDTreeCapable.h.
Referenced by mrpt::math::KDTreeCapable< CFeatureList >::kdTreeClosestPoint2D(), mrpt::math::KDTreeCapable< CFeatureList >::kdTreeTwoClosestPoint2D(), mrpt::math::KDTreeCapable< CFeatureList >::kdTreeNClosestPoint2D(), mrpt::math::KDTreeCapable< CFeatureList >::kdTreeNClosestPoint2DIdx(), mrpt::math::KDTreeCapable< CFeatureList >::kdTreeClosestPoint3D(), mrpt::math::KDTreeCapable< CFeatureList >::kdTreeNClosestPoint3D(), mrpt::math::KDTreeCapable< CFeatureList >::kdTreeNClosestPoint3DIdx(), mrpt::math::KDTreeCapable< CFeatureList >::rebuild_kdTree_2D(), mrpt::math::KDTreeCapable< CFeatureList >::rebuild_kdTree_3D(), and mrpt::math::KDTreeCapable< CFeatureList >::rebuild_kdTree_Nd().
TKDTreeDataHolder<2> mrpt::math::KDTreeCapable::m_kdtree2d_data [mutable, private] |
Definition at line 609 of file KDTreeCapable.h.
Referenced by mrpt::math::KDTreeCapable< CFeatureList >::kdTreeClosestPoint2D(), mrpt::math::KDTreeCapable< CFeatureList >::kdTreeTwoClosestPoint2D(), mrpt::math::KDTreeCapable< CFeatureList >::kdTreeNClosestPoint2D(), mrpt::math::KDTreeCapable< CFeatureList >::kdTreeNClosestPoint2DIdx(), mrpt::math::KDTreeCapable< CFeatureList >::rebuild_kdTree_2D(), mrpt::math::KDTreeCapable< CFeatureList >::rebuild_kdTree_3D(), and mrpt::math::KDTreeCapable< CFeatureList >::rebuild_kdTree_Nd().
TKDTreeDataHolder<3> mrpt::math::KDTreeCapable::m_kdtree3d_data [mutable, private] |
Definition at line 610 of file KDTreeCapable.h.
Referenced by mrpt::math::KDTreeCapable< CFeatureList >::kdTreeClosestPoint3D(), mrpt::math::KDTreeCapable< CFeatureList >::kdTreeNClosestPoint3D(), mrpt::math::KDTreeCapable< CFeatureList >::kdTreeNClosestPoint3DIdx(), mrpt::math::KDTreeCapable< CFeatureList >::rebuild_kdTree_2D(), mrpt::math::KDTreeCapable< CFeatureList >::rebuild_kdTree_3D(), and mrpt::math::KDTreeCapable< CFeatureList >::rebuild_kdTree_Nd().
bool mrpt::math::KDTreeCapable::m_kdtree_is_uptodate [mutable, private] |
whether the KD tree needs to be rebuilt or not.
Definition at line 612 of file KDTreeCapable.h.
Referenced by mrpt::math::KDTreeCapable< CFeatureList >::kdtree_mark_as_outdated(), mrpt::math::KDTreeCapable< CFeatureList >::rebuild_kdTree_2D(), mrpt::math::KDTreeCapable< CFeatureList >::rebuild_kdTree_3D(), and mrpt::math::KDTreeCapable< CFeatureList >::rebuild_kdTree_Nd().
TKDTreeDataHolder mrpt::math::KDTreeCapable::m_kdtreeNd_data [mutable, private] |
Definition at line 611 of file KDTreeCapable.h.
Referenced by mrpt::math::KDTreeCapable< CFeatureList >::rebuild_kdTree_2D(), mrpt::math::KDTreeCapable< CFeatureList >::rebuild_kdTree_3D(), and mrpt::math::KDTreeCapable< CFeatureList >::rebuild_kdTree_Nd().
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |