35 #ifndef IE_CORE_KDTREE_H
36 #define IE_CORE_KDTREE_H
41 #include "OpenEXR/ImathVec.h"
43 #include "IECore/VectorTraits.h"
52 template<
class Po
intIterator>
57 typedef PointIterator Iterator;
58 typedef typename std::iterator_traits<PointIterator>::value_type Point;
61 typedef std::vector<Node> NodeVector;
62 typedef typename NodeVector::size_type NodeIndex;
72 KDTree( PointIterator first, PointIterator last,
int maxLeafSize=4 );
79 void init( PointIterator first, PointIterator last,
int maxLeafSize=4 );
91 PointIterator
nearestNeighbour(
const Point &p, BaseType &distSquared )
const;
97 unsigned int nearestNeighbours(
const Point &p, BaseType r, std::vector<PointIterator> &nearNeighbours )
const;
102 unsigned int nearestNNeighbours(
const Point &p,
unsigned int numNeighbours, std::vector<Neighbour> &nearNeighbours )
const;
106 template<
typename Box,
typename OutputIterator>
114 inline const Node &
node( NodeIndex index )
const;
119 inline NodeIndex
lowChildIndex( NodeIndex parentIndex )
const;
126 typedef std::vector<PointIterator> Permutation;
127 typedef typename Permutation::iterator PermutationIterator;
128 typedef typename Permutation::const_iterator PermutationConstIterator;
132 unsigned char majorAxis( PermutationConstIterator permFirst, PermutationConstIterator permLast );
133 void build( NodeIndex nodeIndex, PermutationIterator permFirst, PermutationIterator permLast );
135 void nearestNeighbourWalk( NodeIndex nodeIndex,
const Point &p, PointIterator &closestPoint, BaseType &distSquared )
const;
137 void nearestNeighboursWalk( NodeIndex nodeIndex,
const Point &p, BaseType r2, std::vector<PointIterator> &nearNeighbours )
const;
139 template<
typename Box,
typename OutputIterator>
140 void enclosedPointsWalk( NodeIndex nodeIndex,
const Box &bound, OutputIterator it )
const;
142 void nearestNNeighboursWalk( NodeIndex nodeIndex,
const Point &p,
unsigned int numNeighbours, std::vector<Neighbour> &nearNeighbours, BaseType &maxDistSquared )
const;
147 PointIterator m_lastPoint;
152 template<
class Po
intIterator>
158 inline bool isLeaf()
const;
161 inline PointIterator *permFirst()
const;
164 inline PointIterator *permLast()
const;
166 inline bool isBranch()
const;
169 inline unsigned char cutAxis()
const;
172 inline BaseType cutValue()
const;
176 friend class KDTree<PointIterator>;
178 inline void makeLeaf( PermutationIterator permFirst, PermutationIterator permLast );
179 inline void makeBranch(
unsigned char cutAxis, BaseType cutValue );
181 unsigned char m_cutAxisAndLeaf;
185 PointIterator *first;
195 template<
class Po
intIterator>
201 : point( p ), distSquared( d2 )
206 BaseType distSquared;
208 bool operator < (
const Neighbour &other )
const
210 return distSquared < other.distSquared;
222 #include "KDTree.inl"
224 #endif // IE_CORE_KDTREE_H
The Node class which is used to implement the branching structure in the KDTree.
Definition: KDTree.h:153
NodeIndex rootIndex() const
Returns the index for the root node.
NodeIndex highChildIndex(NodeIndex parentIndex) const
void init(PointIterator first, PointIterator last, int maxLeafSize=4)
void enclosedPoints(const Box &bound, OutputIterator it) const
unsigned int nearestNeighbours(const Point &p, BaseType r, std::vector< PointIterator > &nearNeighbours) const
The Neighbour class is used to return information from the KDTree::nearestNNeighbours() query...
Definition: KDTree.h:196
unsigned int nearestNNeighbours(const Point &p, unsigned int numNeighbours, std::vector< Neighbour > &nearNeighbours) const
Definition: VectorTraits.h:48
const Node & node(NodeIndex index) const
PointIterator nearestNeighbour(const Point &p) const
NodeIndex lowChildIndex(NodeIndex parentIndex) const
This namespace contains all components of the core library.
Definition: AddSmoothSkinningInfluencesOp.h:43
NodeIndex numNodes() const
Returns the number of nodes in the tree.