cheshirekow  v0.1.0
Node.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
27 #ifndef MPBLOCKS_KD_TREE_NODE_H_
28 #define MPBLOCKS_KD_TREE_NODE_H_
29 
30 
31 namespace mpblocks {
32 namespace kd_tree {
33 
35 
57 template <class Traits>
58 class Node
59 {
60  public:
61  // these just shorten up some of the templated classes into smaller
62  // names
63  typedef typename Traits::Format_t Format_t;
64  typedef typename Traits::Node Node_t;
65  typedef typename Traits::HyperRect HyperRect_t;
66 
67 
68  typedef Eigen::Matrix<Format_t,Traits::NDim,1> Vector_t;
69  typedef Vector_t Point_t;
70 
73 
76 
77  protected:
78  unsigned int m_i;
85 
86  public:
88  Node();
89 
91 
96  void construct( Node_t* parent, unsigned int i );
97 
99  void setPoint( const Point_t& p );
100 
102  const Point_t& getPoint();
103 
105  Node_t* getParent(){ return m_parent; }
106 
108  void insert( Node_t* );
109 
112 
117  void findNearest( const Point_t& q,
118  HyperRect_t& rect,
119  NNIface_t& search );
120 
124  void findRange( RangeIface_t& search, HyperRect_t& rect );
125 
126  template <typename BackInserter >
127  void enumerate( HyperRect_t& container, BackInserter bs );
128 
129 };
130 
131 
132 } // namespace kd_tree
133 } // mpblocks
134 
135 #endif
void insert(Node_t *)
recursively inserts point as a new node in the tree
Definition: Node.hpp:71
void construct(Node_t *parent, unsigned int i)
construct a new node
Definition: Node.hpp:47
Point_t m_point
the point that this node contains
Definition: Node.h:80
Node_t * getParent()
return the parent node
Definition: Node.h:105
unsigned int m_i
dimension that this node splits on, also index of hyperplane's constant component ...
Definition: Node.h:78
Vector_t Point_t
Definition: Node.h:69
void enumerate(HyperRect_t &container, BackInserter bs)
Definition: Node.hpp:226
Node_t * m_greaterChild
child node who's i'th value is larger
Definition: Node.h:83
RangeSearchIface< Traits > RangeIface_t
Definition: Node.h:75
Node_t * m_this
Definition: Node.h:84
pairs nodes of the Kd tree along with a hyperrectangle that is the bounding volume for the subtree ro...
Definition: ListPair.h:37
ListPair< Traits > Pair_t
Definition: Node.h:72
const Point_t & getPoint()
returns a Point_t of the point stored at this node
Definition: Node.hpp:65
Interface for nearest node type searches.
Definition: NearestSearch.h:38
Traits::HyperRect HyperRect_t
Definition: Node.h:65
Node()
does nothing, see construct
Definition: Node.hpp:38
Traits::Format_t Format_t
Definition: Node.h:63
void setPoint(const Point_t &p)
fill point data (convenience method)
Definition: Node.hpp:58
NearestSearchIface< Traits > NNIface_t
Definition: Node.h:74
Eigen::Matrix< Format_t, Traits::NDim, 1 > Vector_t
Definition: Node.h:68
Traits::Node Node_t
Definition: Node.h:64
the node class must be defined in traits since it uses the CTRP, it must derive from kd_tree::Node<Tr...
Definition: Traits.h:49
Base class for nodes in the kd tree.
Definition: Node.h:58
Node_t * m_parent
parent node
Definition: Node.h:81
Node_t * m_smallerChild
child node who's i'th value is smaller
Definition: Node.h:82
double Format_t
number format (i.e. double, float)
Definition: Traits.h:38
void findRange(RangeIface_t &search, HyperRect_t &rect)
find all nodes in the tree that lie inside the specified range ( can be arbitrary volume...
Definition: Node.hpp:177
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 ...
Definition: Node.hpp:99
Node< Traits > This_t
Definition: Node.h:71
an NDim dimensional hyperrectangle, represented as a min and max extent
Definition: HyperRect.h:23