cheshirekow  v0.1.0
Ball.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_BALL_H_
28 #define MPBLOCKS_KD_TREE_EUCLIDEAN_BLOCKS_BALL_H_
29 
30 namespace mpblocks {
31 namespace kd_tree {
32 namespace euclidean {
33 namespace blocks {
34 
35 template <class Traits,
36  template<class> class Allocator = std::allocator >
37 class Ball
38 {
39  public:
40  typedef typename Traits::Format_t Format_t;
41  typedef typename Traits::Node Node_t;
42 
43  typedef Eigen::Matrix<Format_t,Traits::NDim,1> Point_t;
44 
48 
49  protected:
52 
53  public:
54  sigc::signal<void,Node_t*> sig_result;
55 
56  Ball(Tree_t* tree=0):
57  m_tree(tree)
58  {}
59 
60  void setTree( Tree_t* tree )
61  { m_tree = tree; }
62 
63  void search( const Point_t& center, Format_t radius )
64  {
65  m_search.reset(center,radius);
66  if(m_tree)
67  {
69  const typename Search_t::List_t& list = m_search.result();
70  typename Search_t::List_t::const_iterator ipNode;
71  for( ipNode = list.begin(); ipNode != list.end(); ++ipNode )
72  {
73  sig_result.emit(*ipNode);
74  }
75  }
76  }
77 
78  sigc::slot<void,const Point_t&,Format_t> slot_search()
79  { return sigc::mem_fun(this,This_t::search); }
80 
81 };
82 
83 
84 
85 
86 
87 } // namespace blocks
88 } // namespace euclidean
89 } // namespace kd_tree
90 } // namespace mpblocks
91 
92 
93 
94 
95 
96 
97 
98 
99 #endif // NEARESTNEIGHBOR_H_
euclidean::Ball< Traits, Allocator > Search_t
Definition: Ball.h:46
void findRange(RangeIface_t &search)
generic range search, specific search depends on the implementing class of the RangeIface ...
Definition: Tree.hpp:102
a simple KDtree class
Definition: Tree.h:43
Eigen::Matrix< Format_t, Traits::NDim, 1 > Point_t
Definition: Ball.h:43
sigc::slot< void, const Point_t &, Format_t > slot_search()
Definition: Ball.h:78
void search(const Point_t &center, Format_t radius)
Definition: Ball.h:63
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
Ball< Traits, Allocator > This_t
Definition: Ball.h:45
std::vector< Node_t *, Allocator_t > List_t
Definition: Ball.h:52
example traits class, can also be used as a default if you're lazy and your problem happens to be 2d ...
Definition: Traits.h:36
double Format_t
number format (i.e. double, float)
Definition: Traits.h:38
sigc::signal< void, Node_t * > sig_result
Definition: Ball.h:54