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_EUCLIDEAN_KNEAREST_H_
28 #define MPBLOCKS_KD_TREE_EUCLIDEAN_KNEAREST_H_
29 
30 #include <set>
31 
32 namespace mpblocks {
33 namespace kd_tree {
34 namespace euclidean {
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 
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  // clear the queue
66  void reset();
67 
68  // clear the queue and change k
69  void reset( int k );
70 
71  // return the result
72  const PQueue_t& result();
73 
76  virtual void evaluate(const Point_t& q, const Point_t& p, Node_t* n);
77 
81  virtual bool shouldRecurse(const Point_t& q, const HyperRect_t& r );
82 };
83 
84 
85 
86 
87 
88 
89 } // namespace euclidean
90 } // namespace kd_tree
91 } // namespace mpblocks
92 
93 
94 
95 
96 
97 
98 
99 
100 #endif // NEARESTNEIGHBOR_H_
HyperRect< Traits > HyperRect_t
Definition: KNearest.h:47
provides euclidean distance computation
Definition: Distance.h:38
Interface for nearest node type searches.
Definition: NearestSearch.h:38
std::set< Key_t, KeyCompare_t, Allocator_t > PQueue_t
Definition: KNearest.h:53
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
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
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
double Format_t
number format (i.e. double, float)
Definition: Traits.h:38
Eigen::Matrix< Format_t, Traits::NDim, 1 > Point_t
Definition: KNearest.h:52
an NDim dimensional hyperrectangle, represented as a min and max extent
Definition: HyperRect.h:23