Savarese Software Research
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size > Class Template Reference

#include <KDTree.h>

List of all members.


Detailed Description

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
class sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >

A k-d tree divides a k-dimensional space relative to the points it contains by storing them in a binary tree, discriminating by a different dimension at each level of the tree.

It allows efficient point data retrieval (O(lg(n))) and range searching.

KDTree tries to conform to the map interface from the STL where it makes sense. Therefore, you will find it can be used with some STL algorithms.

Author:
Daniel F. Savarese

Definition at line 94 of file KDTree.h.

Public Types

typedef KDTreeTraits< KDTreetraits
typedef KDTreeConstTraits<
KDTree
const_traits
typedef Point key_type
typedef Value mapped_type
typedef std::pair< const key_type,
mapped_type
value_type
typedef value_typepointer
typedef pointer const const_pointer
typedef value_typereference
typedef const reference const_reference
typedef Discriminator discriminator_type
typedef detail::KDTreeRangeSearchIterator<
traits
iterator
typedef detail::KDTreeRangeSearchIterator<
const_traits
const_iterator
typedef PointTraits< key_typepoint_traits
typedef Size size_type
typedef detail::KDTreeNode<
traits
node_type
typedef node_type::child_type child_type

Public Member Functions

 KDTree ()
 Constructs an empty KDTree.
 KDTree (const KDTree &tree)
 Constructs a copy of a KDTree.
virtual ~KDTree ()
 Deallocates the memory allocated by the KDTree.
void clear ()
 Removes all elements from the container, leaving it empty.
const size_type size () const
 Returns the number of point-value mappings in the KDTree.
const size_type max_size () const
 Returns the maximum number of elements that can be contained.
bool empty () const
 Returns true if the container has no elements, false if it contains one or more elements.
iterator begin ()
 Returns an iterator pointing to the leftmost bottommost point in the container.
const_iterator begin () const
 Returns a const iterator pointing to the leftmost bottommost point in the container.
iteratorend ()
 Returns an iterator denoting the end of a range.
const const_iteratorend () const
 Returns a const iterator denoting the end of a range.
bool insert (const key_type &point, const mapped_type &value, mapped_type *replaced=0)
 Inserts a key value pair, replacing any existing value that may be present, and optionally retrieving the replaced value.
std::pair< iterator, bool > insert (const value_type &mapping)
 Inserts a key value pair, but--in conformance with the STL container interface--doesn't replace any existing value that may be present.
mapped_typeoperator[] (const key_type &point)
 Retrieves the value at the given location.
bool remove (const key_type &point, mapped_type *erased=0)
 Removes the point-value mapping corresponding to the given point key.
size_type erase (const key_type &point)
 Removes the point-value mapping corresponding to the given point key.
void erase (iterator pos)
 Removes the point-value mapping at the specified position.
iterator begin (const key_type &lower, const key_type &upper)
 Returns an iterator for mappings that are contained in the rectangle defined by the given lower left-hand and upper right-hand corners.
const_iterator begin (const key_type &lower, const key_type &upper) const
 Returns a const iterator for mappings that are contained in the rectangle defined by the given lower left-hand and upper right-hand corners.
bool get (const key_type &point, mapped_type *value=0) const
 Returns true if the KDTree contains a point-value mapping for the specified point, false if not.
iterator find (const key_type &point)
 Returns the location of the point-value mapping for the specified point (slower than get()).
const_iterator find (const key_type &point) const
 Returns the location of the point-value mapping for the specified point (slower than get()).
void optimize ()
 Optimizes the performance of future search operations by balancing the KDTree.

Static Public Member Functions

static const unsigned int dimensions ()

Classes

struct  NodeComparator


Member Typedef Documentation

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
typedef node_type::child_type sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::child_type
 

Definition at line 119 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
typedef detail::KDTreeRangeSearchIterator<const_traits> sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::const_iterator
 

Definition at line 109 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
typedef pointer const sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::const_pointer
 

Definition at line 104 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
typedef const reference sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::const_reference
 

Definition at line 106 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
typedef KDTreeConstTraits<KDTree> sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::const_traits
 

Definition at line 99 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
typedef Discriminator sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::discriminator_type
 

Definition at line 107 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
typedef detail::KDTreeRangeSearchIterator<traits> sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::iterator
 

Definition at line 108 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
typedef Point sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::key_type
 

Definition at line 100 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
typedef Value sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::mapped_type
 

Definition at line 101 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
typedef detail::KDTreeNode<traits> sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::node_type
 

Definition at line 118 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
typedef PointTraits<key_type> sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::point_traits
 

Definition at line 110 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
typedef value_type* sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::pointer
 

Definition at line 103 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
typedef value_type& sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::reference
 

Definition at line 105 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
typedef Size sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::size_type
 

Definition at line 112 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
typedef KDTreeTraits<KDTree> sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::traits
 

Definition at line 98 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
typedef std::pair<const key_type, mapped_type> sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::value_type
 

Definition at line 102 of file KDTree.h.


Constructor & Destructor Documentation

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::KDTree  )  [inline, explicit]
 

Constructs an empty KDTree.

Definition at line 386 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::KDTree const KDTree< Point, Value, Dimensions, Discriminator, Size > &  tree  )  [inline]
 

Constructs a copy of a KDTree.

Parameters:
tree The KDTree to copy.

Definition at line 394 of file KDTree.h.

References sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::begin().

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
virtual sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::~KDTree  )  [inline, virtual]
 

Deallocates the memory allocated by the KDTree.

Definition at line 404 of file KDTree.h.


Member Function Documentation

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
const_iterator sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::begin const key_type lower,
const key_type upper
const [inline]
 

Returns a const iterator for mappings that are contained in the rectangle defined by the given lower left-hand and upper right-hand corners.

The mappings returned include those occuring at points on the bounding rectangle, not just those inside.

Parameters:
lower The lower left-hand corner of the bounding rectangle.
upper The upper right-hand corner of the bounding rectangle.
Returns:
A KDTree::const_iterator for mappings that are contained in the specified rectangle.

Definition at line 642 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
iterator sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::begin const key_type lower,
const key_type upper
[inline]
 

Returns an iterator for mappings that are contained in the rectangle defined by the given lower left-hand and upper right-hand corners.

The mappings returned include those occuring at points on the bounding rectangle, not just those inside.

Parameters:
lower The lower left-hand corner of the bounding rectangle.
upper The upper right-hand corner of the bounding rectangle.
Returns:
A KDTree::iterator for mappings that are contained in the specified rectangle.

Definition at line 625 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
const_iterator sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::begin  )  const [inline]
 

Returns a const iterator pointing to the leftmost bottommost point in the container.

If empty, it equals end().

Returns:
A const iterator pointing to the leftmost bottommost point in the container. If empty, it equals end().

Definition at line 462 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
iterator sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::begin  )  [inline]
 

Returns an iterator pointing to the leftmost bottommost point in the container.

If empty, it equals end().

Returns:
An iterator pointing to the leftmost bottommost point in the container. If empty, it equals end().

Definition at line 451 of file KDTree.h.

Referenced by sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::KDTree().

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
void sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::clear  )  [inline]
 

Removes all elements from the container, leaving it empty.

Definition at line 409 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
static const unsigned int sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::dimensions  )  [inline, static]
 

Definition at line 114 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
bool sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::empty  )  const [inline]
 

Returns true if the container has no elements, false if it contains one or more elements.

Returns:
true if the container has no elements, false if it contains one or more elements.

Definition at line 440 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
const const_iterator& sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::end  )  const [inline]
 

Returns a const iterator denoting the end of a range.

Returns:
A const iterator denoting the end of a range.

Definition at line 480 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
iterator& sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::end  )  [inline]
 

Returns an iterator denoting the end of a range.

Returns:
An iterator denoting the end of a range.

Definition at line 471 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
void sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::erase iterator  pos  )  [inline]
 

Removes the point-value mapping at the specified position.

Parameters:
pos The KDTree::iterator denoting the location of the mapping.

Definition at line 608 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
size_type sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::erase const key_type point  )  [inline]
 

Removes the point-value mapping corresponding to the given point key.

Parameters:
point The point key of the mapping to remove.
Returns:
The number of mappings erased (0 or 1).

Definition at line 599 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
const_iterator sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::find const key_type point  )  const [inline]
 

Returns the location of the point-value mapping for the specified point (slower than get()).

If there is no mapping present, the iiterator is equivalent to end().

Parameters:
point The key of the poinit-value mapping to find.
Returns:
true A KDTree::const_iterator for the location of the point-value mapping matching the specified point. end() if there is no mapping.

Definition at line 694 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
iterator sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::find const key_type point  )  [inline]
 

Returns the location of the point-value mapping for the specified point (slower than get()).

If there is no mapping present, the iiterator is equivalent to end().

Parameters:
point The key of the poinit-value mapping to find.
Returns:
true A KDTree::iterator for the location of the point-value mapping matching the specified point. end() if there is no mapping.

Definition at line 680 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
bool sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::get const key_type point,
mapped_type value = 0
const [inline]
 

Returns true if the KDTree contains a point-value mapping for the specified point, false if not.

Optionally, retrieves the value at the given location (faster than find()).

Parameters:
point The location from which to retrieve the value.
value A pointer to a KDTree::mapped_type in which to store the retrieved value. This pointer may be null if you do not want to retrieve the value and only want to see if the point is present in the KDTree.
Returns:
true if the KDTree contains a point-value mapping for the specified point, false if not.

Definition at line 659 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
std::pair<iterator,bool> sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::insert const value_type mapping  )  [inline]
 

Inserts a key value pair, but--in conformance with the STL container interface--doesn't replace any existing value that may be present.

Note, this method is slower than bool insert(const key_type &, const mapped_type, mapped_type*)

Returns:
A pair containing the iterator pointing to the inserted value and true if the mapping is inserted. If the value is not inserted, a pair containing the iterator pointing to the existing value and false.

Definition at line 516 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
bool sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::insert const key_type point,
const mapped_type value,
mapped_type replaced = 0
[inline]
 

Inserts a key value pair, replacing any existing value that may be present, and optionally retrieving the replaced value.

Parameters:
point The key corresponding to the value to be inserted
value The value to be inserted.
replaced If you want to retrieve a value that was replaced, have this parameter point to a valid object to store the value. If not, its default value of zero will prevent it from being retrieved.
Returns:
true if value is replaced, false if not.

Definition at line 496 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
const size_type sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::max_size  )  const [inline]
 

Returns the maximum number of elements that can be contained.

Returns:
The maximum number of elements that can be contained.

Definition at line 429 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
mapped_type& sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::operator[] const key_type point  )  [inline]
 

Retrieves the value at the given location.

In conformance with the STL map interface, if the point key does not occur in the KDTree, a new value is inserted and returned using the default constructor for KDTree::mapped_type.

Parameters:
point The location from which to retrieve the value.
Returns:
The value at the given location.

Definition at line 542 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
void sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::optimize  )  [inline]
 

Optimizes the performance of future search operations by balancing the KDTree.

The balancing operation is relatively expensive, but can significantly improve the performance of searches. Usually, you don't have to optimize a tree which contains random key values inserted in a random order.

Definition at line 706 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
bool sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::remove const key_type point,
mapped_type erased = 0
[inline]
 

Removes the point-value mapping corresponding to the given point key.

Optionally, retrieves the removed value if a mapping was present.

Parameters:
point The point key of the mapping to remove.
erased A pointer to a mapped_type in which to store the erased value. This pointer may be null if you do not want to retrieve the removed value and only want to remove the mapping.
Returns:
true if a mapping was present and removed, false if not.

Definition at line 562 of file KDTree.h.

template<typename Point, typename Value, unsigned int Dimensions = 2, typename Discriminator = unsigned char, typename Size = unsigned int>
const size_type sava::spatial::KDTree< Point, Value, Dimensions, Discriminator, Size >::size  )  const [inline]
 

Returns the number of point-value mappings in the KDTree.

Returns:
The number of point-value mappings in the KDTree.

Definition at line 420 of file KDTree.h.


The documentation for this class was generated from the following file:
Savarese Software Research
Copyright © 2003-2005 Savarese Software Research and Daniel F. Savarese. All rights reserved.