xc
region.hpp
Go to the documentation of this file.
1 
7 #ifndef INCLUDE_KDTREE_REGION_HPP
8 #define INCLUDE_KDTREE_REGION_HPP
9 
10 #include <cstddef>
11 
12 #include "utility/kdtree++/node.hpp" //Modificado LCPT.
13 
14 namespace kd_tree
15 {
16 
17  template <size_t const __K, typename _Val, typename _SubVal,
18  typename _Acc, typename _Cmp>
19  struct _Region
20  {
21  typedef _Val value_type;
22  typedef _SubVal subvalue_type;
23 
24  // special typedef for checking against a fuzzy point (for find_nearest)
25  // Note the region (first) component is not supposed to have an area, its
26  // bounds should all be set to a specific point.
27  typedef std::pair<_Region,_SubVal> _CenterPt;
28 
29  _Region(_Acc const& __acc=_Acc(), const _Cmp& __cmp=_Cmp())
30  : _M_cmp(__acc), _M_acc(__cmp) {}
31 
32  template <typename Val>
33  _Region(Val const& __V,
34  _Acc const& __acc=_Acc(), const _Cmp& __cmp=_Cmp())
35  : _M_acc(__acc), _M_cmp(__cmp)
36  {
37  for (size_t __i = 0; __i != __K; ++__i)
38  {
39  _M_low_bounds[__i] = _M_high_bounds[__i] = _M_acc(__V,__i);
40  }
41  }
42 
43  template <typename Val>
44  _Region(Val const& __V, subvalue_type const& __R,
45  _Acc const& __acc=_Acc(), const _Cmp& __cmp=_Cmp())
46  : _M_acc(__acc), _M_cmp(__cmp)
47  {
48  for (size_t __i = 0; __i != __K; ++__i)
49  {
50  _M_low_bounds[__i] = _M_acc(__V,__i) - __R;
51  _M_high_bounds[__i] = _M_acc(__V,__i) + __R;
52  }
53  }
54 
55  bool
56  intersects_with(_CenterPt const& __THAT) const
57  {
58  for (size_t __i = 0; __i != __K; ++__i)
59  {
60  // does it fall outside the bounds?
61  // ! low-tolerance <= x <= high+tolerance
62  // ! (low-tol <= x and x <= high+tol)
63  // !low-tol<=x or !x<=high+tol
64  // low-tol>x or x>high+tol
65  // x<low-tol or high+tol<x
66  if (_M_cmp(__THAT.first._M_low_bounds[__i], _M_low_bounds[__i] - __THAT.second)
67  || _M_cmp(_M_high_bounds[__i] + __THAT.second, __THAT.first._M_low_bounds[__i]))
68  return false;
69  }
70  return true;
71  }
72 
73  bool
74  intersects_with(_Region const& __THAT) const
75  {
76  for (size_t __i = 0; __i != __K; ++__i)
77  {
78  if (_M_cmp(__THAT._M_high_bounds[__i], _M_low_bounds[__i])
79  || _M_cmp(_M_high_bounds[__i], __THAT._M_low_bounds[__i]))
80  return false;
81  }
82  return true;
83  }
84 
85  bool
86  encloses(value_type const& __V) const
87  {
88  for (size_t __i = 0; __i != __K; ++__i)
89  {
90  if (_M_cmp(_M_acc(__V, __i), _M_low_bounds[__i])
91  || _M_cmp(_M_high_bounds[__i], _M_acc(__V, __i)))
92  return false;
93  }
94  return true;
95  }
96 
97  _Region&
98  set_high_bound(value_type const& __V, size_t const __L)
99  {
100  _M_high_bounds[__L % __K] = _M_acc(__V, __L % __K);
101  return *this;
102  }
103 
104  _Region&
105  set_low_bound(value_type const& __V, size_t const __L)
106  {
107  _M_low_bounds[__L % __K] = _M_acc(__V, __L % __K);
108  return *this;
109  }
110 
111  subvalue_type _M_low_bounds[__K], _M_high_bounds[__K];
112  _Acc _M_acc;
113  _Cmp _M_cmp;
114  };
115 
116 } // namespace kd_tree
117 
118 #endif // include guard
119 
120 /* COPYRIGHT --
121  *
122  * This file is part of libkdtree++, a C++ template KD-Tree sorting container.
123  * libkdtree++ is (c) 2004-2007 Martin F. Krafft <libkdtree@pobox.madduck.net>
124  * and Sylvain Bougerel <sylvain.bougerel.devel@gmail.com> distributed under the
125  * terms of the Artistic License 2.0. See the ./COPYING file in the source tree
126  * root for more information.
127  *
128  * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
129  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES
130  * OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
131  */
Definition: region.hpp:19
Defines interfaces for nodes as used by the KDTree class.
Definition: allocator.hpp:14