00001
00007 #ifndef INCLUDE_KDTREE_REGION_HPP
00008 #define INCLUDE_KDTREE_REGION_HPP
00009
00010 #include <cstddef>
00011
00012 #include <kdtree++/node.hpp>
00013
00014 namespace KDTree
00015 {
00016
00017 template <size_t const __K, typename _Val, typename _SubVal,
00018 typename _Acc, typename _Cmp>
00019 struct _Region
00020 {
00021 typedef _Val value_type;
00022 typedef _SubVal subvalue_type;
00023
00024
00025
00026
00027 typedef std::pair<_Region,_SubVal> _CenterPt;
00028
00029 _Region(_Acc const& __acc=_Acc(), const _Cmp& __cmp=_Cmp())
00030 : _M_cmp(__acc), _M_acc(__cmp) {}
00031
00032 template <typename Val>
00033 _Region(Val const& __V,
00034 _Acc const& __acc=_Acc(), const _Cmp& __cmp=_Cmp())
00035 : _M_acc(__acc), _M_cmp(__cmp)
00036 {
00037 for (size_t __i = 0; __i != __K; ++__i)
00038 {
00039 _M_low_bounds[__i] = _M_high_bounds[__i] = _M_acc(__V,__i);
00040 }
00041 }
00042
00043 template <typename Val>
00044 _Region(Val const& __V, subvalue_type const& __R,
00045 _Acc const& __acc=_Acc(), const _Cmp& __cmp=_Cmp())
00046 : _M_acc(__acc), _M_cmp(__cmp)
00047 {
00048 for (size_t __i = 0; __i != __K; ++__i)
00049 {
00050 _M_low_bounds[__i] = _M_acc(__V,__i) - __R;
00051 _M_high_bounds[__i] = _M_acc(__V,__i) + __R;
00052 }
00053 }
00054
00055 bool
00056 intersects_with(_CenterPt const& __THAT) const
00057 {
00058 for (size_t __i = 0; __i != __K; ++__i)
00059 {
00060
00061
00062
00063
00064
00065
00066 if (_M_cmp(__THAT.first._M_low_bounds[__i], _M_low_bounds[__i] - __THAT.second)
00067 || _M_cmp(_M_high_bounds[__i] + __THAT.second, __THAT.first._M_low_bounds[__i]))
00068 return false;
00069 }
00070 return true;
00071 }
00072
00073 bool
00074 intersects_with(_Region const& __THAT) const
00075 {
00076 for (size_t __i = 0; __i != __K; ++__i)
00077 {
00078 if (_M_cmp(__THAT._M_high_bounds[__i], _M_low_bounds[__i])
00079 || _M_cmp(_M_high_bounds[__i], __THAT._M_low_bounds[__i]))
00080 return false;
00081 }
00082 return true;
00083 }
00084
00085 bool
00086 encloses(value_type const& __V) const
00087 {
00088 for (size_t __i = 0; __i != __K; ++__i)
00089 {
00090 if (_M_cmp(_M_acc(__V, __i), _M_low_bounds[__i])
00091 || _M_cmp(_M_high_bounds[__i], _M_acc(__V, __i)))
00092 return false;
00093 }
00094 return true;
00095 }
00096
00097 _Region&
00098 set_high_bound(value_type const& __V, size_t const __L)
00099 {
00100 _M_high_bounds[__L % __K] = _M_acc(__V, __L % __K);
00101 return *this;
00102 }
00103
00104 _Region&
00105 set_low_bound(value_type const& __V, size_t const __L)
00106 {
00107 _M_low_bounds[__L % __K] = _M_acc(__V, __L % __K);
00108 return *this;
00109 }
00110
00111 subvalue_type _M_low_bounds[__K], _M_high_bounds[__K];
00112 _Acc _M_acc;
00113 _Cmp _M_cmp;
00114 };
00115
00116 }
00117
00118 #endif // include guard
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131