Cortex  10.0.0-a4
Classes | Public Types | Public Member Functions | List of all members
IECore::KDTree< PointIterator > Class Template Reference

#include <KDTree.h>

Classes

class  Neighbour
 The Neighbour class is used to return information from the KDTree::nearestNNeighbours() query. More...
 
class  Node
 The Node class which is used to implement the branching structure in the KDTree. More...
 

Public Types

typedef PointIterator Iterator
 
typedef std::iterator_traits< PointIterator >::value_type Point
 
typedef VectorTraits< Point >::BaseType BaseType
 
typedef std::vector< NodeNodeVector
 
typedef NodeVector::size_type NodeIndex
 

Public Member Functions

 KDTree ()
 
 KDTree (PointIterator first, PointIterator last, int maxLeafSize=4)
 
void init (PointIterator first, PointIterator last, int maxLeafSize=4)
 
PointIterator nearestNeighbour (const Point &p) const
 
PointIterator nearestNeighbour (const Point &p, BaseType &distSquared) const
 
unsigned int nearestNeighbours (const Point &p, BaseType r, std::vector< PointIterator > &nearNeighbours) const
 
unsigned int nearestNNeighbours (const Point &p, unsigned int numNeighbours, std::vector< Neighbour > &nearNeighbours) const
 
template<typename Box , typename OutputIterator >
void enclosedPoints (const Box &bound, OutputIterator it) const
 
NodeIndex numNodes () const
 Returns the number of nodes in the tree.
 
const Nodenode (NodeIndex index) const
 
NodeIndex rootIndex () const
 Returns the index for the root node.
 
NodeIndex lowChildIndex (NodeIndex parentIndex) const
 
NodeIndex highChildIndex (NodeIndex parentIndex) const
 

Detailed Description

template<class PointIterator>
class IECore::KDTree< PointIterator >

The KDTree class provides accelerated searching of pointsets. It is templated so that it can operate on a wide variety of datatypes, and uses the VectorTraits.h and VectorOps.h functionality to assist in this.

Constructor & Destructor Documentation

template<class PointIterator>
IECore::KDTree< PointIterator >::KDTree ( )

Constructs an unititialised tree - you must call init() before using it.

template<class PointIterator>
IECore::KDTree< PointIterator >::KDTree ( PointIterator  first,
PointIterator  last,
int  maxLeafSize = 4 
)

Creates a tree for the fast searching of points. Note that the tree does not own the passed points - it is up to you to ensure that they remain valid and unchanged as long as the KDTree is in use.

Member Function Documentation

template<class PointIterator>
template<typename Box , typename OutputIterator >
void IECore::KDTree< PointIterator >::enclosedPoints ( const Box &  bound,
OutputIterator  it 
) const

Finds all the points contained by the specified bound, outputting them to the specified iterator.

Threading:
May be called by multiple concurrent threads.
template<class PointIterator>
NodeIndex IECore::KDTree< PointIterator >::highChildIndex ( NodeIndex  parentIndex) const
inline

Returns the index for the "high" child of the specified Node. This will only be valid if parent.isBranch() is true.

template<class PointIterator>
void IECore::KDTree< PointIterator >::init ( PointIterator  first,
PointIterator  last,
int  maxLeafSize = 4 
)

Builds the tree for the specified points - the iterator range must remain valid and unchanged as long as the tree is in use. This method can be called again to rebuild the tree at any time.

Threading:
This can't be called while other threads are making queries.
template<class PointIterator>
NodeIndex IECore::KDTree< PointIterator >::lowChildIndex ( NodeIndex  parentIndex) const
inline

Returns the index for the "low" child of the specified Node. This will only be valid if parent.isBranch() is true.

template<class PointIterator>
PointIterator IECore::KDTree< PointIterator >::nearestNeighbour ( const Point &  p) const

Returns an iterator to the nearest neighbour to the point p.

Threading:
May be called by multiple concurrent threads.
template<class PointIterator>
PointIterator IECore::KDTree< PointIterator >::nearestNeighbour ( const Point &  p,
BaseType &  distSquared 
) const

Returns an iterator to the nearest neighbour to the point p, and places the squared distance between these two points in distSquared. The initial value of distSquared constrains the search to return only points which are closer than sqrt(distSquared) to p. In the event of no such point being found, an iterator to the end of the points is returned (the "last" parameter which was passed to the constructor).

Threading:
May be called by multiple concurrent threads.
template<class PointIterator>
unsigned int IECore::KDTree< PointIterator >::nearestNeighbours ( const Point &  p,
BaseType  r,
std::vector< PointIterator > &  nearNeighbours 
) const

Populates the passed vector of iterators with the neighbours of point p which are closer than radius r. Returns the number of points found.

Todo:
There should be a form where nearNeighbours is an output iterator, to allow any container to be filled. See enclosedPoints for an example of this form.
Threading:
May be called by multiple concurrent threads provided they are each using a different vector for the result.
template<class PointIterator>
unsigned int IECore::KDTree< PointIterator >::nearestNNeighbours ( const Point &  p,
unsigned int  numNeighbours,
std::vector< Neighbour > &  nearNeighbours 
) const

Populates the passed vector with the N closest neighbours to p, sorted with the closest first. Returns the number found.

Threading:
May be called by multiple concurrent threads provided they are each using a different vector for the result.
template<class PointIterator>
const Node& IECore::KDTree< PointIterator >::node ( NodeIndex  index) const
inline

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