27 #ifndef MPBLOCKS_KD_TREE_NODE_HPP_
28 #define MPBLOCKS_KD_TREE_NODE_HPP_
37 template <
class Traits>
46 template <
class Traits>
48 Node_t* parent,
unsigned int i )
54 m_this =
static_cast<Node_t*
>(
this);
57 template <
class Traits>
63 template <
class Traits>
70 template <
class Traits>
77 if(static_cast<This_t*>(node)->m_point[m_i] <= m_point[m_i])
78 ptrChild = &m_smallerChild;
80 ptrChild = &m_greaterChild;
83 Node_t*& child = *ptrChild;
92 static_cast<This_t*
>(node)->
construct( m_this,(m_i+1) % m_point.rows());
98 template <
class Traits>
111 Format_t diff = q[m_i] - m_point[m_i];
114 nearerNode = m_smallerChild;
115 fartherNode = m_greaterChild;
117 nearerHyperCoord = &(rect.
maxExt[m_i]);
118 fartherHyperCoord = &(rect.
minExt[m_i]);
123 nearerNode = m_greaterChild;
124 fartherNode = m_smallerChild;
126 nearerHyperCoord = &(rect.
minExt[m_i]);
127 fartherHyperCoord = &(rect.
maxExt[m_i]);
136 Format_t oldHyperVal = *nearerHyperCoord;
140 *nearerHyperCoord = m_point[m_i];
147 *nearerHyperCoord = oldHyperVal;
158 Format_t oldHyperVal = *fartherHyperCoord;
159 *fartherHyperCoord = m_point[m_i];
163 static_cast<This_t*>(fartherNode)->findNearest(q,rect,search);
166 *fartherHyperCoord = oldHyperVal;
176 template <
class Traits>
186 Node_t* child = m_smallerChild;
192 *hyperCoord = m_point[m_i];
196 static_cast<This_t*>(child)->
findRange(search,rect);
200 *hyperCoord = oldHyperVal;
205 Node_t* child = m_greaterChild;
211 *hyperCoord = m_point[m_i];
215 static_cast<This_t*>(child)->
findRange(search,rect);
219 *hyperCoord = oldHyperVal;
224 template <
class Traits>
225 template <
typename BackInserter >
234 pair->
node = m_greaterChild;
243 pair->
node = m_smallerChild;
void insert(Node_t *)
recursively inserts point as a new node in the tree
void construct(Node_t *parent, unsigned int i)
construct a new node
__host__ __device__ __forceinline__ void construct(SturmSequence2< Scalar, Spec > &sturm, const Exp &exp)
construct a sturm sequence
virtual bool shouldRecurse(const HyperRect_t &h)=0
return true if the hyper rectangle intersects the range
void enumerate(HyperRect_t &container, BackInserter bs)
Point_t maxExt
maximum extent of hyper-rectangle
pairs nodes of the Kd tree along with a hyperrectangle that is the bounding volume for the subtree ro...
virtual bool shouldRecurse(const Point_t &q, const HyperRect_t &h)=0
evaluate the hyper rectangle and return true if it is possible that we must recurse into it ...
const Point_t & getPoint()
returns a Point_t of the point stored at this node
Interface for nearest node type searches.
void findNearest(const Point &query, int k, SearchQueue &q, ResultSet &r, const QueueMinKeyFn &minKey, const QueuePopMinFn &popMin, const QueueInsertFn &enqueue, const QueueSizeFn &queueSize, const SetMaxKeyFn &maxKey, const SetPopMaxFn &popMax, const SetInsertFn &insert, const SetSizeFn &size, const PointDistanceFn &pointDist, const CellDistanceFn &cellDist, const IsLeafFn &isLeaf, const ChildrenFn &children, const SitesFn &sites, const CellFn &getCell, const NodeFn &getNode)
Node()
does nothing, see construct
Traits::Format_t Format_t
virtual void evaluate(const Point_t &q, const Point_t &p, Node_t *n)=0
evaluate the current point, and add the corresponding node to the result set if necessary ...
void setPoint(const Point_t &p)
fill point data (convenience method)
the node class must be defined in traits since it uses the CTRP, it must derive from kd_tree::Node<Tr...
virtual void evaluate(const Point_t &q, Node_t *n)=0
evalute if p is inside the range, and add n to the result set if it is
Base class for nodes in the kd tree.
void insert(NodeRef node, PointRef point, const IsLeafFn &isLeaf, const LeafInsertFn &leafInsert, const IdxFn &idx, const ValueFn &value, const ChildFn &child, const PointGetFn &pointGet)
Point_t minExt
minimum extent of hyper-rectangle
void findRange(RangeIface_t &search, HyperRect_t &rect)
find all nodes in the tree that lie inside the specified range ( can be arbitrary volume...
void findNearest(const Point_t &q, HyperRect_t &rect, NNIface_t &search)
perform a generic Nearest Neighbor query, different queries provide different implementations of the ...
an NDim dimensional hyperrectangle, represented as a min and max extent