library of assembled shared sources |
http://lass.cocamware.com |
#include <kd_tree.h>
Data Structures | |
class | LessDim |
class | Neighbour |
class | Node |
Public Types | |
enum | { dimension = TObjectTraits::dimension } |
typedef KdTree< ObjectType, ObjectTraits > | TSelf |
typedef ObjectType | TObject |
typedef ObjectTraits | TObjectTraits |
typedef TObjectTraits::TObjectIterator | TObjectIterator |
typedef TObjectTraits::TObjectReference | TObjectReference |
typedef TObjectTraits::TPoint | TPoint |
typedef TObjectTraits::TValue | TValue |
typedef TObjectTraits::TParam | TParam |
typedef TObjectTraits::TParam | TReference |
typedef TObjectTraits::TParam | TConstReference |
typedef std::vector< Neighbour > | TNeighbourhood |
Public Member Functions | |
KdTree () | |
Constructs an empty k-d tree. | |
KdTree (TObjectIterator first, TObjectIterator last) | |
Constructs a k-d tree from objects in range [first, last). | |
void | reset () |
Resets to an empty tree. | |
void | reset (TObjectIterator first, TObjectIterator last) |
Resets to a new k-d tree of objects in range [first, last). | |
Neighbour | nearestNeighbour (const TPoint &target) const |
Locates the object that's nearest to a target position. | |
TValue | rangeSearch (const TPoint &target, TParam maxRadius, size_t maxCount, TNeighbourhood &neighbourhood) const |
Locates objects within a spherical range around a target position. | |
template<typename OutputIterator > | |
OutputIterator | rangeSearch (const TPoint &target, TParam maxRadius, OutputIterator first) const |
Find all objects in a radius of maxRadius of target. | |
template<typename RandomIterator > | |
RandomIterator | rangeSearch (const TPoint &target, TParam maxRadius, size_t maxCount, RandomIterator first) const |
void | swap (TSelf &other) |
Swap the representation of two k-d trees. | |
const bool | isEmpty () const |
returns true if there are no objects in the k-d tree | |
void | clear () |
resest the k-d tree to an empty one. | |
const TObjectIterator | end () const |
template<typename RandomAccessIterator > | |
RandomAccessIterator | rangeSearch (const TPoint &target, TParam maxRadius, size_t maxCount, RandomAccessIterator first) const |
Find up to a fixed number of objects in a radius of maxRadius of target. | |
Private Types | |
enum | { dummyAxis_ = TAxis(-1) } |
typedef std::vector < TObjectIterator > | TObjectIterators |
typedef TObjectIterators::iterator | TIteratorIterator |
typedef unsigned char | TAxis |
typedef std::vector< TAxis > | TAxes |
typedef std::vector< Node > | TNodes |
Private Member Functions | |
void | buildHeap () |
void | balance (size_t index, TIteratorIterator first, TIteratorIterator last) |
TAxis | findSplitAxis (TIteratorIterator first, TIteratorIterator last) const |
void | assignNode (size_t index, TObjectIterator object, TAxis splitAxis) |
size_t | findNode (size_t index, const TPoint &target) const |
void | doNearestNeighbour (size_t index, const TPoint &target, Neighbour &best) const |
template<typename OutputIterator > | |
OutputIterator | doRangeSearch (size_t index, const TPoint &target, TParam squaredRadius, OutputIterator output) const |
template<typename RandomIterator > | |
RandomIterator | doRangeSearch (size_t index, const TPoint &target, TReference squaredRadius, size_t maxCount, RandomIterator first, RandomIterator last) const |
Static Private Member Functions | |
static TValue | squaredDistance (const TPoint &a, const TPoint &b) |
Private Attributes | |
TNodes | heap_ |
TObjectIterator | begin_ |
TObjectIterator | end_ |
size_t | size_ |
the KD tree does NOT own the objects. You must keep them yourself!
Definition at line 86 of file kd_tree.h.
typedef KdTree<ObjectType, ObjectTraits> lass::spat::KdTree< ObjectType, ObjectTraits >::TSelf |
typedef ObjectType lass::spat::KdTree< ObjectType, ObjectTraits >::TObject |
typedef ObjectTraits lass::spat::KdTree< ObjectType, ObjectTraits >::TObjectTraits |
typedef TObjectTraits::TObjectIterator lass::spat::KdTree< ObjectType, ObjectTraits >::TObjectIterator |
typedef TObjectTraits::TObjectReference lass::spat::KdTree< ObjectType, ObjectTraits >::TObjectReference |
typedef TObjectTraits::TPoint lass::spat::KdTree< ObjectType, ObjectTraits >::TPoint |
typedef TObjectTraits::TValue lass::spat::KdTree< ObjectType, ObjectTraits >::TValue |
typedef TObjectTraits::TParam lass::spat::KdTree< ObjectType, ObjectTraits >::TParam |
typedef TObjectTraits::TParam lass::spat::KdTree< ObjectType, ObjectTraits >::TReference |
typedef TObjectTraits::TParam lass::spat::KdTree< ObjectType, ObjectTraits >::TConstReference |
typedef std::vector<Neighbour> lass::spat::KdTree< ObjectType, ObjectTraits >::TNeighbourhood |
typedef std::vector<TObjectIterator> lass::spat::KdTree< ObjectType, ObjectTraits >::TObjectIterators [private] |
typedef TObjectIterators::iterator lass::spat::KdTree< ObjectType, ObjectTraits >::TIteratorIterator [private] |
typedef unsigned char lass::spat::KdTree< ObjectType, ObjectTraits >::TAxis [private] |
typedef std::vector<TAxis> lass::spat::KdTree< ObjectType, ObjectTraits >::TAxes [private] |
typedef std::vector<Node> lass::spat::KdTree< ObjectType, ObjectTraits >::TNodes [private] |
anonymous enum |
anonymous enum [private] |
lass::spat::KdTree< O, OT >::KdTree | ( | ) | [inline] |
lass::spat::KdTree< O, OT >::KdTree | ( | TObjectIterator | first, | |
TObjectIterator | last | |||
) | [inline] |
Constructs a k-d tree from objects in range [first, last).
Definition at line 80 of file kd_tree.inl.
References lass::spat::KdTree< ObjectType, ObjectTraits >::balance(), lass::spat::KdTree< ObjectType, ObjectTraits >::begin_, lass::prim::distance(), lass::spat::KdTree< ObjectType, ObjectTraits >::end_, lass::spat::KdTree< ObjectType, ObjectTraits >::heap_, and lass::spat::KdTree< ObjectType, ObjectTraits >::size_.
void lass::spat::KdTree< O, OT >::reset | ( | ) | [inline] |
Resets to an empty tree.
Definition at line 101 of file kd_tree.inl.
References lass::spat::KdTree< ObjectType, ObjectTraits >::swap().
void lass::spat::KdTree< O, OT >::reset | ( | TObjectIterator | first, | |
TObjectIterator | last | |||
) | [inline] |
Resets to a new k-d tree of objects in range [first, last).
Definition at line 113 of file kd_tree.inl.
References lass::spat::KdTree< ObjectType, ObjectTraits >::swap().
KdTree< O, OT >::Neighbour lass::spat::KdTree< O, OT >::nearestNeighbour | ( | const TPoint & | target | ) | const [inline] |
Locates the object that's nearest to a target position.
Definition at line 125 of file kd_tree.inl.
References lass::spat::KdTree< ObjectType, ObjectTraits >::doNearestNeighbour(), lass::spat::KdTree< ObjectType, ObjectTraits >::end_, lass::spat::KdTree< ObjectType, ObjectTraits >::isEmpty(), and LASS_THROW.
KdTree< O, OT >::TValue lass::spat::KdTree< O, OT >::rangeSearch | ( | const TPoint & | target, | |
TParam | maxRadius, | |||
size_t | maxCount, | |||
TNeighbourhood & | neighbourhood | |||
) | const [inline] |
Locates objects within a spherical range around a target position.
target | [in] the center of the spherical range | |
maxRadius | [in] the radius of the range | |
maxCount | [in] the maximum number of objects to be returned.
| |
neighbourhood | [out] a std::vector that will be filled with the found objects. The vector will be cleared before use. |
Definition at line 158 of file kd_tree.inl.
References lass::spat::KdTree< ObjectType, ObjectTraits >::end(), lass::spat::KdTree< ObjectType, ObjectTraits >::isEmpty(), LASS_THROW, and lass::spat::KdTree< ObjectType, ObjectTraits >::size_.
OutputIterator lass::spat::KdTree< O, OT >::rangeSearch | ( | const TPoint & | target, | |
TParam | maxRadius, | |||
OutputIterator | first | |||
) | const [inline] |
Find all objects in a radius of maxRadius of target.
target | [in] center of range. | |
maxRadius | [in] radius of range | |
first | [in] output iterator dereferencable to Neighbour. |
If you wish to use a fixed sized range, you best use the other rangeSearch overload taking a random access iterator and an extra parameter maxCount.
Definition at line 216 of file kd_tree.inl.
References lass::spat::KdTree< ObjectType, ObjectTraits >::doRangeSearch(), and lass::spat::KdTree< ObjectType, ObjectTraits >::isEmpty().
RandomIterator lass::spat::KdTree< ObjectType, ObjectTraits >::rangeSearch | ( | const TPoint & | target, | |
TParam | maxRadius, | |||
size_t | maxCount, | |||
RandomIterator | first | |||
) | const [inline] |
void lass::spat::KdTree< O, OT >::swap | ( | TSelf & | other | ) | [inline] |
Swap the representation of two k-d trees.
Definition at line 269 of file kd_tree.inl.
References lass::spat::KdTree< ObjectType, ObjectTraits >::begin_, lass::spat::KdTree< ObjectType, ObjectTraits >::end_, lass::spat::KdTree< ObjectType, ObjectTraits >::heap_, and lass::spat::KdTree< ObjectType, ObjectTraits >::size_.
Referenced by lass::spat::KdTree< ObjectType, ObjectTraits >::clear(), and lass::spat::KdTree< ObjectType, ObjectTraits >::reset().
const bool lass::spat::KdTree< O, OT >::isEmpty | ( | ) | const [inline] |
returns true if there are no objects in the k-d tree
Definition at line 282 of file kd_tree.inl.
References lass::spat::KdTree< ObjectType, ObjectTraits >::heap_.
Referenced by lass::spat::KdTree< ObjectType, ObjectTraits >::nearestNeighbour(), and lass::spat::KdTree< ObjectType, ObjectTraits >::rangeSearch().
void lass::spat::KdTree< O, OT >::clear | ( | ) | [inline] |
resest the k-d tree to an empty one.
Definition at line 292 of file kd_tree.inl.
References lass::spat::KdTree< ObjectType, ObjectTraits >::swap().
const KdTree< O, OT >::TObjectIterator lass::spat::KdTree< O, OT >::end | ( | ) | const [inline] |
Definition at line 302 of file kd_tree.inl.
References lass::spat::KdTree< ObjectType, ObjectTraits >::end_.
Referenced by lass::spat::KdTree< ObjectType, ObjectTraits >::rangeSearch().
void lass::spat::KdTree< ObjectType, ObjectTraits >::buildHeap | ( | ) | [private] |
void lass::spat::KdTree< O, OT >::balance | ( | size_t | index, | |
TIteratorIterator | first, | |||
TIteratorIterator | last | |||
) | [inline, private] |
Definition at line 390 of file kd_tree.inl.
References lass::spat::KdTree< ObjectType, ObjectTraits >::assignNode(), lass::spat::KdTree< ObjectType, ObjectTraits >::dummyAxis_, lass::spat::KdTree< ObjectType, ObjectTraits >::findSplitAxis(), and lass::stde::split().
Referenced by lass::spat::KdTree< ObjectType, ObjectTraits >::KdTree().
KdTree< O, OT >::TAxis lass::spat::KdTree< O, OT >::findSplitAxis | ( | TIteratorIterator | first, | |
TIteratorIterator | last | |||
) | const [inline, private] |
Definition at line 420 of file kd_tree.inl.
References lass::spat::KdTree< ObjectType, ObjectTraits >::dimension, and lass::prim::distance().
Referenced by lass::spat::KdTree< ObjectType, ObjectTraits >::balance().
void lass::spat::KdTree< O, OT >::assignNode | ( | size_t | index, | |
TObjectIterator | object, | |||
TAxis | splitAxis | |||
) | [inline, private] |
Definition at line 453 of file kd_tree.inl.
References lass::spat::KdTree< ObjectType, ObjectTraits >::end_, and lass::spat::KdTree< ObjectType, ObjectTraits >::heap_.
Referenced by lass::spat::KdTree< ObjectType, ObjectTraits >::balance().
size_t lass::spat::KdTree< O, OT >::findNode | ( | size_t | index, | |
const TPoint & | target | |||
) | const [inline, private] |
Definition at line 465 of file kd_tree.inl.
References lass::spat::KdTree< ObjectType, ObjectTraits >::Node::axis(), lass::spat::KdTree< ObjectType, ObjectTraits >::dummyAxis_, lass::spat::KdTree< ObjectType, ObjectTraits >::end_, lass::spat::KdTree< ObjectType, ObjectTraits >::heap_, lass::spat::KdTree< ObjectType, ObjectTraits >::Node::position(), and lass::stde::split().
void lass::spat::KdTree< O, OT >::doNearestNeighbour | ( | size_t | index, | |
const TPoint & | target, | |||
Neighbour & | best | |||
) | const [inline, private] |
Definition at line 490 of file kd_tree.inl.
References lass::spat::KdTree< ObjectType, ObjectTraits >::Node::axis(), lass::spat::KdTree< ObjectType, ObjectTraits >::dummyAxis_, lass::spat::KdTree< ObjectType, ObjectTraits >::end_, lass::spat::KdTree< ObjectType, ObjectTraits >::heap_, lass::spat::KdTree< ObjectType, ObjectTraits >::Node::object(), lass::spat::KdTree< ObjectType, ObjectTraits >::Node::position(), lass::stde::split(), lass::num::sqr(), lass::spat::KdTree< ObjectType, ObjectTraits >::squaredDistance(), and lass::spat::KdTree< ObjectType, ObjectTraits >::Neighbour::squaredDistance().
Referenced by lass::spat::KdTree< ObjectType, ObjectTraits >::nearestNeighbour().
OutputIterator lass::spat::KdTree< O, OT >::doRangeSearch | ( | size_t | index, | |
const TPoint & | target, | |||
TParam | squaredRadius, | |||
OutputIterator | output | |||
) | const [inline, private] |
Definition at line 534 of file kd_tree.inl.
References lass::spat::KdTree< ObjectType, ObjectTraits >::Node::axis(), lass::spat::KdTree< ObjectType, ObjectTraits >::dummyAxis_, lass::spat::KdTree< ObjectType, ObjectTraits >::end_, lass::spat::KdTree< ObjectType, ObjectTraits >::heap_, lass::spat::KdTree< ObjectType, ObjectTraits >::Node::object(), lass::spat::KdTree< ObjectType, ObjectTraits >::Node::position(), lass::stde::split(), lass::num::sqr(), and lass::spat::KdTree< ObjectType, ObjectTraits >::squaredDistance().
Referenced by lass::spat::KdTree< ObjectType, ObjectTraits >::doRangeSearch(), and lass::spat::KdTree< ObjectType, ObjectTraits >::rangeSearch().
RandomIterator lass::spat::KdTree< O, OT >::doRangeSearch | ( | size_t | index, | |
const TPoint & | target, | |||
TReference | squaredRadius, | |||
size_t | maxCount, | |||
RandomIterator | first, | |||
RandomIterator | last | |||
) | const [inline, private] |
Definition at line 581 of file kd_tree.inl.
References lass::spat::KdTree< ObjectType, ObjectTraits >::Node::axis(), lass::spat::KdTree< ObjectType, ObjectTraits >::doRangeSearch(), lass::spat::KdTree< ObjectType, ObjectTraits >::dummyAxis_, lass::spat::KdTree< ObjectType, ObjectTraits >::end_, lass::spat::KdTree< ObjectType, ObjectTraits >::heap_, LASS_ASSERT, lass::spat::KdTree< ObjectType, ObjectTraits >::Node::object(), lass::spat::KdTree< ObjectType, ObjectTraits >::Node::position(), lass::stde::split(), lass::num::sqr(), and lass::spat::KdTree< ObjectType, ObjectTraits >::squaredDistance().
KdTree< O, OT >::TValue lass::spat::KdTree< O, OT >::squaredDistance | ( | const TPoint & | a, | |
const TPoint & | b | |||
) | [inline, static, private] |
Definition at line 640 of file kd_tree.inl.
References lass::spat::KdTree< ObjectType, ObjectTraits >::dimension, and sqr().
Referenced by lass::spat::KdTree< ObjectType, ObjectTraits >::doNearestNeighbour(), and lass::spat::KdTree< ObjectType, ObjectTraits >::doRangeSearch().
RandomAccessIterator lass::spat::KdTree< ObjectType, ObjectTraits >::rangeSearch | ( | const TPoint & | target, | |
TParam | maxRadius, | |||
size_t | maxCount, | |||
RandomAccessIterator | first | |||
) | const [inline] |
Find up to a fixed number of objects in a radius of maxRadius of target.
target | [in] center of range. | |
maxRadius | [in] radius of range | |
maxCount | [in] maximum number of objects to be found. | |
first | [in] random access iterator dereferencable to Neighbour, [first, first + maxCount + 1) must be a valid range. |
If you wish to find all points within the range of maxRadius, you better use the overload with the regular output iterator and without maxCount.
Definition at line 253 of file kd_tree.inl.
References lass::spat::KdTree< ObjectType, ObjectTraits >::doRangeSearch(), and lass::spat::KdTree< ObjectType, ObjectTraits >::isEmpty().
TNodes lass::spat::KdTree< ObjectType, ObjectTraits >::heap_ [private] |
Definition at line 204 of file kd_tree.h.
Referenced by lass::spat::KdTree< ObjectType, ObjectTraits >::assignNode(), lass::spat::KdTree< ObjectType, ObjectTraits >::doNearestNeighbour(), lass::spat::KdTree< ObjectType, ObjectTraits >::doRangeSearch(), lass::spat::KdTree< ObjectType, ObjectTraits >::findNode(), lass::spat::KdTree< ObjectType, ObjectTraits >::isEmpty(), lass::spat::KdTree< ObjectType, ObjectTraits >::KdTree(), and lass::spat::KdTree< ObjectType, ObjectTraits >::swap().
TObjectIterator lass::spat::KdTree< ObjectType, ObjectTraits >::begin_ [private] |
Definition at line 205 of file kd_tree.h.
Referenced by lass::spat::KdTree< ObjectType, ObjectTraits >::KdTree(), and lass::spat::KdTree< ObjectType, ObjectTraits >::swap().
TObjectIterator lass::spat::KdTree< ObjectType, ObjectTraits >::end_ [private] |
Definition at line 206 of file kd_tree.h.
Referenced by lass::spat::KdTree< ObjectType, ObjectTraits >::assignNode(), lass::spat::KdTree< ObjectType, ObjectTraits >::doNearestNeighbour(), lass::spat::KdTree< ObjectType, ObjectTraits >::doRangeSearch(), lass::spat::KdTree< ObjectType, ObjectTraits >::end(), lass::spat::KdTree< ObjectType, ObjectTraits >::findNode(), lass::spat::KdTree< ObjectType, ObjectTraits >::KdTree(), lass::spat::KdTree< ObjectType, ObjectTraits >::nearestNeighbour(), and lass::spat::KdTree< ObjectType, ObjectTraits >::swap().
size_t lass::spat::KdTree< ObjectType, ObjectTraits >::size_ [private] |
Definition at line 207 of file kd_tree.h.
Referenced by lass::spat::KdTree< ObjectType, ObjectTraits >::KdTree(), lass::spat::KdTree< ObjectType, ObjectTraits >::rangeSearch(), and lass::spat::KdTree< ObjectType, ObjectTraits >::swap().
Generated on Mon Nov 10 14:22:15 2008 for Library of Assembled Shared Sources by 1.5.7.1 |