#include <quadMap.h>
Public Member Functions | |
| QuadMap (double minCoord0, double minCoord1, double maxCoord0, double maxCoord1, unsigned int maxDepth) | |
| The default constructor creates an empty map. | |
| virtual | ~QuadMap () |
| The destructor cleans up any system resources during destruction. | |
| Type & | addElement (Type const &element) |
| This member function adds a single Type instance to the map. | |
| template<class Iter > | |
| void | addElements (Iter beginIter, Iter endIter) |
| This member function populates a map with Type instances. | |
| bool | empty () |
| This member function returns true if the map contains no elements, false otherwise. | |
| bool | find (Type const &element) const |
| This member function returns true if the specified Type instance has already been inserted into the map. | |
| Type const & | findNearest (Type const &element, double &distance) const |
| This member function returns a const reference to the map element that is closest (Euclidean distance) to the specified element. | |
| bool | isEmpty () |
| This member function returns true if the map contains no elements, false otherwise. | |
Protected Member Functions | |
| Type & | addElement (Type *elementPtr) |
| void | findNearestIterative (Type const &element, Type const *&bestElementPtr, double &bestDistanceSquared) const |
| void | findNearestRecursive (Type const &element, Type const *&bestElementPtr, double &bestDistanceSquared) const |
| void | setBounds (double minCoord0, double minCoord1, double maxCoord0, double maxCoord1, unsigned int maxDepth) |
Protected Attributes | |
| double | m_border0 |
| double | m_border1 |
| QuadMap * | m_childrenPtr |
| QuadMapComparator< Type > | m_comparator |
| std::vector< Type * > | m_localStore |
| double | m_maxCoord0 |
| double | m_maxCoord1 |
| unsigned int | m_maxDepth |
| double | m_minCoord0 |
| double | m_minCoord1 |
QuadMap differs from QuadTree in that the boundaries between regions are statically determined, rather than depending on the data. The total extent of the map is declared up-front. As points are added to the map, the total region is divided into four quarters, each of which can be subdivided into quarters, ands so on. A region is subdivided only if it contains more than a preset number of points.
The advantage of this approach (vs. QuadTree) is that (for well behaved point sets) there are fewer rebalancing issues. As long as you declare the total area upfront, you can add new points to the map at any time without rebalancing concerns.
The disadvantage is that QuadMap is vulnerable to poorly-behaved point sets. If a large number of points have nearly the same position, then the logarithmic search becomes more nearly linear.
Template argument Type specifies what kind of element will be contained in the map. Logically, Type represents a point in two-dimensional space. It must support default construction, copying and assignment. It must also fulfill the requirements of the QuadMapComparator class template. Note that if you need to use a Type that doesn't support the QuadMapComparator requirements, you can always specialize QuadMapComparator for your specific Type.
Here's an example of how to use the QuadMap class template:
namespce cv = dlr::computerVision; namespce num = dlr::numeric; std::vector<num::Vector2D> myPoints; myPoints.push_back(num::Vector2D(2.1, 3.5)); myPoints.push_back(num::Vector2D(5.0, 3.2)); myPoints.push_back(num::Vector2D(2.4, 1.6)); myPoints.push_back(num::Vector2D(7.7, 4.7)); myPoints.push_back(num::Vector2D(-2.0, 6.3)); myPoints.push_back(num::Vector2D(0.0, 0.0)); myPoints.push_back(num::Vector2D(3.1, 4.7)); cv::QuadMap<num::Vector2D> quadMap(-7.0, -7.0, 7.0, 7.0, 10); quadMap.addElements(myPoints.begin(), myPoints.end()); double distanceSquared; num::Vector2D testPoint(3.5, 6.9); num::Vector2D nearestPoint = quadMap.findNearest(testPoint, distanceSquared); std::cout << "The closest point was " << nearestPoint << ", " << "which was " << std:::sqrt(distanceSquared) << " distance from " << testPoint << std::endl;
Definition at line 245 of file quadMap.h.
| dlr::computerVision::QuadMap< Type >::QuadMap | ( | double | minCoord0, | |
| double | minCoord1, | |||
| double | maxCoord0, | |||
| double | maxCoord1, | |||
| unsigned int | maxDepth | |||
| ) | [inline] |
| dlr::computerVision::QuadMap< Type >::~QuadMap | ( | ) | [inline, virtual] |
| Type & dlr::computerVision::QuadMap< Type >::addElement | ( | Type const & | element | ) | [inline] |
This member function adds a single Type instance to the map.
It has complexity O(logN), where N is the number of elements in the map.
| element | This is the element to be copied into the map. |
Definition at line 450 of file quadMap.h.
Referenced by dlr::computerVision::QuadMap< Type >::addElements().
| void dlr::computerVision::QuadMap< Type >::addElements | ( | Iter | beginIter, | |
| Iter | endIter | |||
| ) | [inline] |
This member function populates a map with Type instances.
It has complexity O(N*logN), where N is the number of elements to be inserted into the map.
| beginIter | This argument is an iterator pointing to the beginning of a sequence of Type instances that is to be copied into the map. | |
| endIter | This argument is an interator pointing one element past the last Type instance in the sequence that is to be copied into the map. |
Definition at line 462 of file quadMap.h.
References dlr::computerVision::QuadMap< Type >::addElement().
| bool dlr::computerVision::QuadMap< Type >::empty | ( | ) | [inline] |
| bool dlr::computerVision::QuadMap< Type >::find | ( | Type const & | element | ) | const [inline] |
This member function returns true if the specified Type instance has already been inserted into the map.
It has complexity O(log(N), where N is the number of elements contained in the map.
| element | This argument is the Type instance to search for. It will be compared to elements in the map using QuadMapComparator<Type>::isEqual(). |
Definition at line 491 of file quadMap.h.
References dlr::computerVision::QuadMap< Type >::find().
Referenced by dlr::computerVision::QuadMap< Type >::find().
| Type const & dlr::computerVision::QuadMap< Type >::findNearest | ( | Type const & | element, | |
| double & | distance | |||
| ) | const [inline] |
This member function returns a const reference to the map element that is closest (Euclidean distance) to the specified element.
It has complexity O(log(N), where N is the number of elements contained in the map.
| element | This argument is the Type instance to search for. It will be compared to elements in the map using QuadMapComparator<Dimension, Type>::computeDistanceSquared(Type const&, Type const&). | |
| distanceSquared | This argument is used to return the squared distance between the element for which we're searching and the closest element in the map. It will be computed using QuadMapComparator<Dimension, Type>computeDistanceSquared(Type const&, Type const&). |
| bool dlr::computerVision::QuadMap< Type >::isEmpty | ( | ) | [inline] |
1.5.8