cheshirekow  v0.1.0
KNearestBall.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_BLOCKS_KNEARESTBALL_H_
28 #define MPBLOCKS_KD_TREE_EUCLIDEAN_BLOCKS_KNEARESTBALL_H_
29 
30 #include <set>
31 
32 namespace mpblocks {
33 namespace kd_tree {
34 namespace euclidean {
35 namespace blocks {
36 
37 template <class Traits,
38  template<class> class Allocator = std::allocator >
40 {
41  public:
42  typedef typename Traits::Format_t Format_t;
43  typedef typename Traits::Node Node_t;
44 
45  typedef Eigen::Matrix<Format_t,Traits::NDim,1> Point_t;
46 
50  typedef typename Search_t::PQueue_t PQueue_t;
51 
52  protected:
55 
56  public:
57  sigc::signal<void,Node_t*> sig_result;
58 
59  KNearestBall(Tree_t* tree=0):
60  m_tree(tree)
61  {}
62 
63  void setTree( Tree_t* tree )
64  { m_tree = tree; }
65 
66  void search( const Point_t& q, Format_t r, unsigned int k )
67  {
68  m_search.reset(r,k);
69  if(m_tree)
70  {
72  const PQueue_t& list = m_search.result();
73  typename PQueue_t::const_iterator iKey;
74  for( iKey = list.begin(); iKey != list.end(); ++iKey )
75  {
76  sig_result.emit(iKey->n);
77  }
78  }
79  }
80 
81  sigc::slot<void,const Point_t&,Format_t,unsigned int> slot_search()
82  { return sigc::mem_fun(this,&This_t::search); }
83 };
84 
85 
86 
87 
88 
89 } // namespace blocks
90 } // namespace euclidean
91 } // namespace kd_tree
92 } // namespace mpblocks
93 
94 
95 
96 
97 
98 
99 
100 
101 #endif // NEARESTNEIGHBOR_H_
a simple KDtree class
Definition: Tree.h:43
std::set< Key_t, KeyCompare_t, Allocator_t > PQueue_t
Definition: KNearestBall.h:53
void findNearest(const Point_t &q, NNIface_t &search)
generic NN search, specific search depends on the implementing class of the NNIface ...
Definition: Tree.hpp:91
euclidean::KNearestBall< Traits, Allocator > Search_t
Definition: KNearestBall.h:48
Eigen::Matrix< Format_t, Traits::NDim, 1 > Point_t
Definition: KNearestBall.h:45
KNearestBall< Traits, Allocator > This_t
Definition: KNearestBall.h:47
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
void search(const Point_t &q, Format_t r, unsigned int k)
Definition: KNearestBall.h:66
sigc::slot< void, const Point_t &, Format_t, unsigned int > slot_search()
Definition: KNearestBall.h:81
sigc::signal< void, Node_t * > sig_result
Definition: KNearestBall.h:57
double Format_t
number format (i.e. double, float)
Definition: Traits.h:38