dlr::computerVision::QuadMap< Type > Class Template Reference

This class implements a QuadMap data structure that tessellates 2D space into square regions, and stores an approximately uniform distribution of 2D points in such a way that finding points within the space has complexity approximately logarithmic in the number of points. More...

#include <quadMap.h>

Collaboration diagram for dlr::computerVision::QuadMap< Type >:
[legend]

List of all members.

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
QuadMapm_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


Detailed Description

template<class Type>
class dlr::computerVision::QuadMap< Type >

This class implements a QuadMap data structure that tessellates 2D space into square regions, and stores an approximately uniform distribution of 2D points in such a way that finding points within the space has complexity approximately logarithmic in the number of points.

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.


Constructor & Destructor Documentation

template<class Type >
dlr::computerVision::QuadMap< Type >::QuadMap ( double  minCoord0,
double  minCoord1,
double  maxCoord0,
double  maxCoord1,
unsigned int  maxDepth 
) [inline]

The default constructor creates an empty map.

Definition at line 418 of file quadMap.h.

template<class Type >
dlr::computerVision::QuadMap< Type >::~QuadMap (  )  [inline, virtual]

The destructor cleans up any system resources during destruction.

Definition at line 437 of file quadMap.h.


Member Function Documentation

template<class Type >
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.

Parameters:
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().

template<class Type >
template<class Iter >
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.

Parameters:
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().

template<class Type>
bool dlr::computerVision::QuadMap< Type >::empty (  )  [inline]

This member function returns true if the map contains no elements, false otherwise.

Returns:
The return value is true of *this is empty.

Definition at line 300 of file quadMap.h.

template<class Type >
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.

Parameters:
element This argument is the Type instance to search for. It will be compared to elements in the map using QuadMapComparator<Type>::isEqual().
Returns:
The return value is true if a matching element is found in the map, false otherwise.

Definition at line 491 of file quadMap.h.

References dlr::computerVision::QuadMap< Type >::find().

Referenced by dlr::computerVision::QuadMap< Type >::find().

template<class Type >
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.

Parameters:
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&).
Returns:
The return value is a const reference to the closest element in the map.

Definition at line 555 of file quadMap.h.

template<class Type>
bool dlr::computerVision::QuadMap< Type >::isEmpty (  )  [inline]

This member function returns true if the map contains no elements, false otherwise.

Returns:
The return value is true of *this is empty.

Definition at line 351 of file quadMap.h.


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

Generated on Wed Nov 25 12:15:09 2009 for dlrComputerVision Utility Library by  doxygen 1.5.8