cheshirekow  v0.1.0
KNearestBallCenter.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_KNEARESTBALLCENTER_H_
28 #define MPBLOCKS_KD_TREE_EUCLIDEAN_BLOCKS_KNEARESTBALLCENTER_H_
29 
30 #include <set>
31 
32 namespace mpblocks {
33 namespace kd_tree {
34 namespace euclidean {
35 namespace blocks {
36 
38 template <class Traits,
39  template<class> class Allocator = std::allocator >
41 {
42  public:
43  typedef typename Traits::Format_t Format_t;
44  typedef typename Traits::Node Node_t;
45 
46  typedef Eigen::Matrix<Format_t,Traits::NDim,1> Point_t;
47 
51  typedef typename Search_t::PQueue_t PQueue_t;
52 
53  protected:
56 
57  public:
58  sigc::signal<void,Node_t*> sig_result;
59 
61  m_tree(tree)
62  {}
63 
64  void setTree( Tree_t* tree )
65  { m_tree = tree; }
66 
67  void search( const Point_t& q, const Point_t& c,
68  Format_t r, unsigned int k )
69  {
70  m_search.reset(c,r,k);
71  if(m_tree)
72  {
74  const PQueue_t& list = m_search.result();
75  typename PQueue_t::const_iterator iKey;
76  for( iKey = list.begin(); iKey != list.end(); ++iKey )
77  {
78  sig_result.emit(iKey->n);
79  }
80  }
81  }
82 
83  sigc::slot<void,const Point_t&,const Point_t&,Format_t,unsigned int>
85  { return sigc::mem_fun(this,&This_t::search); }
86 };
87 
88 
89 } // namespace blocks
90 } // namespace euclidean
91 } // namespace kd_tree
92 } // namespace mpblocks
93 
94 #endif
performs search for k-NN within a ball at a specified center and radius
a simple KDtree class
Definition: Tree.h:43
void reset(const Point_t &center, Format_t radius, unsigned int k)
resets the search for the specified point
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::KNearestBallCenter< Traits, Allocator > Search_t
performs search for k-NN within a ball at a specified center and radius
Eigen::Matrix< Format_t, Traits::NDim, 1 > Point_t
void search(const Point_t &q, const Point_t &c, Format_t r, unsigned int k)
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
std::set< Key_t, KeyCompare_t, Allocator_t > PQueue_t
KNearestBallCenter< Traits, Allocator > This_t
double Format_t
number format (i.e. double, float)
Definition: Traits.h:38
sigc::slot< void, const Point_t &, const Point_t &, Format_t, unsigned int > slot_search()