cheshirekow  v0.1.0
KNearest.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_R2_S1_KNEAREST_H_
28 #define MPBLOCKS_KD_TREE_R2_S1_KNEAREST_H_
29 
30 #include <set>
31 
32 namespace mpblocks {
33 namespace kd_tree {
34 namespace r2_s1 {
35 
36 
37 template <class Traits,
38  template<class> class Allocator = std::allocator >
39 class KNearest :
40  public NearestSearchIface<Traits>
41 {
42  public:
43  typedef typename Traits::Format_t Format_t;
44  typedef typename Traits::Node Node_t;
45  typedef typename Traits::HyperRect HyperRect_t;
46 
48  typedef Key<Traits> Key_t;
49  typedef typename Key_t::Compare KeyCompare_t;
50  typedef Allocator<Key_t> Allocator_t;
51 
52  typedef Eigen::Matrix<Format_t,Traits::NDim,1> Point_t;
53  typedef std::set<Key_t,KeyCompare_t,Allocator_t> PQueue_t;
54 
55  protected:
56  unsigned int m_k;
59 
60  public:
61  KNearest( unsigned int k=1 );
62 
63  virtual ~KNearest(){};
64 
65  // expose the distance object
66  Distance_t& distFn(){ return m_dist2Fn; }
67 
68  // clear the queue
69  void reset();
70 
71  // clear the queue and change k
72  void reset( int k );
73 
74  // return the result
75  const PQueue_t& result();
76 
79  virtual void evaluate(const Point_t& q, const Point_t& p, Node_t* n);
80 
84  virtual bool shouldRecurse(const Point_t& q, const HyperRect_t& r );
85 };
86 
87 
88 
89 
90 
91 
92 } // namespace r2_s1
93 } // namespace kd_tree
94 } // namespace mpblocks
95 
96 
97 
98 
99 
100 
101 
102 
103 #endif // NEARESTNEIGHBOR_H_
Traits::HyperRect HyperRect_t
Definition: KNearest.h:45
virtual bool shouldRecurse(const Point_t &q, const HyperRect_t &r)
evaluate the Euclidean distance from q to it's closest point in r and if that distance is less than t...
Definition: KNearest.hpp:87
virtual void evaluate(const Point_t &q, const Point_t &p, Node_t *n)
calculates Euclidean distance from q to p, and if its less than the current best replaces the current...
Definition: KNearest.hpp:70
Allocator< Key_t > Allocator_t
Definition: KNearest.h:50
Interface for nearest node type searches.
Definition: NearestSearch.h:38
provides r2_s1 distance computation
Definition: Distance.h:38
Distance< Traits > Distance_t
Definition: KNearest.h:47
std::set< Key_t, KeyCompare_t, Allocator_t > PQueue_t
Definition: KNearest.h:53
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
Eigen::Matrix< Format_t, Traits::NDim, 1 > Point_t
Definition: KNearest.h:52
double Format_t
number format (i.e. double, float)
Definition: Traits.h:38
an NDim dimensional hyperrectangle, represented as a min and max extent
Definition: HyperRect.h:23