8 #include <boost/shared_ptr.hpp> 9 #include <boost/type_traits.hpp> 24 template <
typename _TIndex >
27 inline std::size_t kdtreeDefaultValue<std::size_t>()
28 {
return std::size_t(-1); }
38 template <
typename T >
43 int dim()
const {
return m_dim; }
44 int & dim() {
return m_dim; }
46 T
const & value()
const {
return m_value; }
47 T & value() {
return m_value; }
49 const T & operator()() {
return m_value; }
51 operator T ()
const {
return m_value; }
63 template <
typename T >
64 inline std::ostream & operator<<(std::ostream & os, const KDNode<T> & n)
66 return os << n.value();
75 template <
typename TIndex,
typename TContainer >
77 :
public NaryTree< KDNode< TIndex >, 2 >
89 enum { LEFT = 0, RIGHT };
99 template <
typename T_Container >
112 template <
typename TKDTree >
132 void build(TKDTree & res);
137 class Coordinate_comparison
140 Coordinate_comparison(
const Self & parent) : m_parent(parent) {}
143 template <
class TVector >
144 inline bool operator()(
const TVector *v1,
const TVector *v2)
145 {
return (*v1)[m_parent.m_dim] < (*v2)[m_parent.m_dim]; }
148 inline bool operator()(std::size_t i1, std::size_t i2)
149 {
return m_parent.m_v[i1][m_parent.m_dim] < m_parent.m_v[i2][m_parent.m_dim];
152 const Self & m_parent;
168 typename std::vector<index_type>::iterator left,
169 typename std::vector<index_type>::iterator right,
170 typename TKDTree::iterator iRes,
176 void getIndex(
const typename Collection::const_iterator & iV, indexed_type * & vIndex)
177 { vIndex =
const_cast<indexed_type*
>(&*iV); }
182 void getIndex(
const typename Collection::const_iterator & iV, std::size_t & vIndex)
183 { vIndex = std::distance(m_v.begin(), iV); }
188 void makeIndexVector(
const Collection & v, std::vector<index_type> & vIndex);
193 const Collection & m_v;
194 Coordinate_comparison m_compare;
196 std::vector<index_type> m_vIndex;
209 template <
typename TPrecision,
typename TKDTree >
226 index_type operator()(
const indexed_type & vec);
233 void lookMax(
typename TKDTree::const_iterator iNode);
237 const TKDTree * m_pKdt;
240 index_type m_minIndex;
246 template <
typename T,
typename TIndex,
typename TContainer >
257 template <
typename TPrecision,
typename TKDTree >
259 typename TKDTree::index_type
260 find_closest(
const TKDTree & kdtree,
const typename TKDTree::indexed_type & vec)
KDTree< TIndex, TContainer > Self
int niter()
Return the number of iterations taken by the last search.
KDTree(const T_Container &c)
Belongs to package Box Do not include directly, include til/Box.h instead.
TKDTree::index_type find_closest(const TKDTree &kdtree, const typename TKDTree::indexed_type &vec)
Returns the closest point to vec in kdtree.
_TIndex kdtreeDefaultValue()
TKDTree::index_type index_type
TKDTree::indexed_type indexed_type
KDTreeFactory(const Collection &v)
Initialize the factory with the collection of which we want to compute the KDTree.
TKDTree::index_type index_type
void makeKDTree(const std::vector< T > &v, KDTree< TIndex, TContainer > &res)
Find_closest(const TKDTree &kdtree)
Provide input kdtree.
A class to find a KDTree point closest to an input point.
TKDTree::Collection Collection
boost::enable_if_c< boost::is_same< TIndex, std::size_t >::value &&!boost::is_same< TPointer, std::size_t >::value, TIndex >::type getIndex(const std::vector< T, TAlloc > &c, TPointer pElem)
A class to represent an N-ary tree.
TKDTree::indexed_type indexed_type
KDTreeFactory< TKDTree > Self