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_DUBINS_KD_TREE_KNEAREST_H_
28 #define MPBLOCKS_DUBINS_KD_TREE_KNEAREST_H_
29 
30 #include <vector>
31 #include <queue>
32 
33 namespace mpblocks {
34 namespace dubins {
35 namespace kd_tree {
36 
37 
38 template <typename Scalar>
39 class KNearest :
40  public mpblocks::kd_tree::NearestSearchIface<Traits<Scalar> >
41 {
42  public:
43  typedef typename Traits<Scalar>::Node Node_t;
45 
47  typedef Key<Scalar> Key_t;
48  typedef typename Key_t::LessThan KeyCompare;
49  typedef std::vector<Key_t> KeyVec;
50 
51  typedef Eigen::Matrix<Scalar,3,1> Point;
52  typedef std::priority_queue<Key_t,KeyVec,KeyCompare> PQueue_t;
53 
54  unsigned int m_nodesEvaluated;
55  unsigned int m_boxesEvaluated;
56 
57  protected:
58  unsigned int m_k;
60  Scalar m_radius;
61 
62  public:
63  KNearest( unsigned int k=1, Scalar radius=1 );
64 
65  virtual ~KNearest(){};
66 
67  // clear the queue
68  void reset();
69 
70  // clear the queue and change k
71  void reset( int k, Scalar radius );
72 
73  // return the result
74  PQueue_t& result();
75 
78  virtual void evaluate(const Point& q, const Point& p, Node_t* n);
79 
83  virtual bool shouldRecurse(const Point& q, const HyperRect_t& r );
84 };
85 
86 
87 } // namespace kd_tree
88 } // namespace dubins
89 } // namespace mpblocks
90 
91 
92 #endif // NEARESTNEIGHBOR_H_
Traits< Scalar >::Node Node_t
Definition: KNearest.h:43
virtual bool shouldRecurse(const Point &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:99
key for priority queue
Definition: Key.h:39
Interface for nearest node type searches.
Definition: NearestSearch.h:38
KNearest(unsigned int k=1, Scalar radius=1)
Definition: KNearest.hpp:37
std::priority_queue< Key_t, KeyVec, KeyCompare > PQueue_t
Definition: KNearest.h:52
std::vector< Key_t > KeyVec
Definition: KNearest.h:49
Traits< Scalar >::HyperRect HyperRect_t
Definition: KNearest.h:44
virtual void evaluate(const Point &q, const Point &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:76
Distance< Scalar > Distance_t
Definition: KNearest.h:46
Eigen::Matrix< Scalar, 3, 1 > Point
Definition: KNearest.h:51