#include <kdTree.h>
Public Member Functions | |
| KDTree () | |
| The default constructor creates an empty tree. | |
| template<class Iter > | |
| KDTree (Iter beginIter, Iter endIter) | |
| This constructor creates a tree and populates it with the specified sample points. | |
| virtual | ~KDTree () |
| The destructor cleans up any system resources during destruction. | |
| bool | find (Type const &point) const |
| This member function returns true if the specified Type instance has already been inserted into the tree. | |
| Type const & | findNearest (Type const &point, double &distance) const |
| This member function returns a const reference to the tree element that is closest (Euclidean distance) to the specified point. | |
Protected Member Functions | |
| template<class Iter > | |
| KDTree (Iter beginIter, Iter endIter, size_t vectorSize, size_t level) | |
| template<class Iter > | |
| void | construct (Iter beginIter, Iter endIter, size_t vectorSize, size_t level) |
| void | findNearestIterative (Type const &point, Type const *&bestPointPtr, double &bestDistance) const |
| void | findNearestRecursive (Type const &point, Type const *&bestPointPtr, double &bestDistance) const |
Protected Attributes | |
| KDComparator< Dimension, Type > | m_comparator |
| Type | m_point |
| KDTree * | m_leftChild |
| KDTree * | m_rightChild |
Template argument Dimension specifies how many dimensions the tree will span. Template argument Type specifies what kind of element will be contained in the tree. Logically, Type represents a point in multi-dimensional space. It must support default construction, copying and assignment. It must also fulfill the requirements of the KDComparator class template. Note that if you need to use a Type that doesn't support the KDComparator requirements, you can always specialize KDComparator for your specific Type. This class currently does not support adding points after construction or rebalancing.
Here's an example of how to use the KDTree class template:
namespce cv = dlr::computerVision; namespce num = dlr::numeric; std::vector<num::Vector3D> myPoints; myPoints.push_back(num::Vector3D(2.1, 3.5, 2.0)); myPoints.push_back(num::Vector3D(5.0, 3.2, 2.5)); myPoints.push_back(num::Vector3D(2.4, 1.6, 1.3)); myPoints.push_back(num::Vector3D(7.7, 4.7, 1.1)); myPoints.push_back(num::Vector3D(-2.0, 6.3, 5.0)); myPoints.push_back(num::Vector3D(0.0, 0.0, 0.0)); myPoints.push_back(num::Vector3D(3.1, 4.7, 5.4)); cv::KDTree<3, num::Vector3D> kdTree(myPoints.begin(), myPoints.end()); double distance; num::Vector3D testPoint(3.5, 6.9, 4.4); num::Vector3D nearestPoint = kdTree.findNearest(testPoint, distance); std::cout << "The closest point was " << nearestPoint << ", " << "which was " << distance << " distance from " << testPoint << std::endl;
Definition at line 231 of file kdTree.h.
| dlr::computerVision::KDTree< Dimension, Type >::KDTree | ( | ) | [inline] |
| dlr::computerVision::KDTree< Dimension, Type >::KDTree | ( | Iter | beginIter, | |
| Iter | endIter | |||
| ) | [inline] |
This constructor creates a tree and populates it with the specified sample points.
It has complexity O(N*log(N)), where N is the number of elements to be inserted into the tree.
| beginIter | This argument is an iterator pointing to the beginning of a sequence of Type instances that is to be inserted into the tree. | |
| endIter | This argument is an interator pointing one element past the last Type instance in the sequence that is to be inserted into the tree. |
| dlr::computerVision::KDTree< Dimension, Type >::~KDTree | ( | ) | [inline, virtual] |
| bool dlr::computerVision::KDTree< Dimension, Type >::find | ( | Type const & | point | ) | const [inline] |
This member function returns true if the specified Type instance has already been inserted into the tree.
It has complexity O(log(N), where N is the number of points contained in the tree.
| point | This argument is the Type instance to search for. It will be compared to elements in the tree using KDComparator<Dimension, Type>::isEqual(). |
Definition at line 404 of file kdTree.h.
References dlr::computerVision::KDTree< Dimension, Type >::find().
Referenced by dlr::computerVision::KDTree< Dimension, Type >::find().
| Type const & dlr::computerVision::KDTree< Dimension, Type >::findNearest | ( | Type const & | point, | |
| double & | distance | |||
| ) | const [inline] |
This member function returns a const reference to the tree element that is closest (Euclidean distance) to the specified point.
It has complexity O(log(N), where N is the number of points contained in the tree.
| point | This argument is the Type instance to search for. It will be compared to elements in the tree using KDComparator<Dimension, Type>::computeDistance(Type const&, Type const&). | |
| distance | This argument is used to return the distance between the point for which we're searching and the closest point in the tree. It will be computed using KDComparator<Dimension, Type>::computeDistance(Type const&, Type const&). |
1.5.8