cheshirekow  v0.1.0
Nearest.hpp
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_R2_S1_NEAREST_HPP_
28 #define MPBLOCKS_KD_TREE_R2_S1_NEAREST_HPP_
29 
30 
31 namespace mpblocks {
32 namespace kd_tree {
33 namespace r2_s1 {
34 
35 
36 
37 
38 template <class Traits>
40 {
41  m_d2Best = inf;
42  m_nBest = 0;
43 }
44 
45 
46 
47 template <class Traits>
49 {
50  return m_nBest;
51 }
52 
53 
54 
55 
56 template <class Traits>
58  const Point_t& q, const Point_t& p, Node_t* n)
59 {
60  Format_t d2 = m_dist2Fn(q,p);
61  if( d2 < m_d2Best )
62  {
63  m_d2Best = d2;
64  m_nBest = n;
65  }
66 }
67 
68 
69 
70 
71 template <class Traits>
73  const Point_t& q, const HyperRect_t& r )
74 {
75  Format_t d2 = m_dist2Fn(q,r);
76  return (d2 < m_d2Best);
77 }
78 
79 
80 
81 
82 
83 
84 } // namespace r2_s1
85 } // namespace kd_tree
86 } // namespace mpblocks
87 
88 
89 
90 
91 
92 
93 
94 
95 #endif // NEARESTNEIGHBOR_H_
void reset(Format_t inf=std::numeric_limits< Format_t >::max())
Definition: Nearest.hpp:39
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: Nearest.hpp:57
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 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: Nearest.hpp:72
an NDim dimensional hyperrectangle, represented as a min and max extent
Definition: HyperRect.h:23