00001 00008 #ifndef INCLUDE_KDTREE_ACCESSOR_HPP 00009 #define INCLUDE_KDTREE_ACCESSOR_HPP 00010 00011 #include <cstddef> 00012 00013 namespace KDTree 00014 { 00015 template <typename _Val> 00016 struct _Bracket_accessor 00017 { 00018 typedef typename _Val::value_type result_type; 00019 00020 result_type 00021 operator()(_Val const& V, size_t const N) const 00022 { 00023 return V[N]; 00024 } 00025 }; 00026 00027 template <typename _Tp> 00028 struct always_true 00029 { 00030 bool operator() (const _Tp& ) const { return true; } 00031 }; 00032 00033 template <typename _Tp, typename _Dist> 00034 struct squared_difference 00035 { 00036 typedef _Dist distance_type; 00037 00038 distance_type 00039 operator() (const _Tp& __a, const _Tp& __b) const 00040 { 00041 distance_type d=__a - __b; 00042 return d*d; 00043 } 00044 }; 00045 00046 template <typename _Tp, typename _Dist> 00047 struct squared_difference_counted 00048 { 00049 typedef _Dist distance_type; 00050 00051 squared_difference_counted() 00052 : _M_count(0) 00053 { } 00054 00055 void reset () 00056 { _M_count = 0; } 00057 00058 long& 00059 count () const 00060 { return _M_count; } 00061 00062 distance_type 00063 operator() (const _Tp& __a, const _Tp& __b) const 00064 { 00065 distance_type d=__a - __b; 00066 ++_M_count; 00067 return d*d; 00068 } 00069 00070 private: 00071 mutable long _M_count; 00072 }; 00073 00074 } // namespace KDTree 00075 00076 #endif // include guard 00077 00078 /* COPYRIGHT -- 00079 * 00080 * This file is part of libkdtree++, a C++ template KD-Tree sorting container. 00081 * libkdtree++ is (c) 2004-2007 Martin F. Krafft <libkdtree@pobox.madduck.net> 00082 * and Sylvain Bougerel <sylvain.bougerel.devel@gmail.com> distributed under the 00083 * terms of the Artistic License 2.0. See the ./COPYING file in the source tree 00084 * root for more information. 00085 * 00086 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED 00087 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES 00088 * OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00089 */