/** * \file cgal/internal/knn.h * \brief manipulation of text, and Interconversion between text and numbers * Copyright 2007-2010 IMP Inventors. All rights reserved. */ #ifndef IMPCGAL_INTERNAL_KNN_H #define IMPCGAL_INTERNAL_KNN_H #include "../cgal_config.h" #include #include #include #include #include IMPCGAL_BEGIN_INTERNAL_NAMESPACE template struct VectorWithIndex: public algebra::VectorD { int index; VectorWithIndex(unsigned int i, const algebra::VectorD& p): algebra::VectorD(p), index(i){} VectorWithIndex(): index(-1){} operator unsigned int() const {return index;} unsigned int dimension() const { return D; } }; template std::vector > create_vectors_with_index(It b, It e) { std::vector > v(std::distance(b,e)); It c=b; for (unsigned int i=0; i< v.size(); ++i) { v[i]= VectorWithIndex(i, get_vector_d_geometry(*c)); ++c; } return v; } struct IMPCGALEXPORT RCTree: public RefCounted { virtual ~RCTree(); }; template struct KNNData{}; #define IMP_CGAL_KNN_D(D) \ struct IMPCGALEXPORT KNNData##D { \ mutable Pointer tree_; \ std::vector > vsi_; \ KNNData##D(const std::vector > &v); \ void fill_nearest_neighbors_v(const algebra::VectorD &g, \ unsigned int k, \ double eps, Ints &ret) const; \ void fill_nearest_neighbors_v(const algebra::VectorD &g, \ double dist, \ double eps, Ints &ret) const; \ template \ void fill_nearest_neighbors(const G &g, unsigned int k, \ double eps, Ints &ret) const { \ fill_nearest_neighbors_v(get_vector_d_geometry(g), \ k, eps, ret); \ } \ template \ void fill_nearest_neighbors(const G &g, double distance, \ double eps, Ints &ret) const { \ fill_nearest_neighbors_v(get_vector_d_geometry(g), \ distance, eps, ret); \ } \ const algebra::VectorD &get_point(unsigned int i) const { \ return vsi_[i]; \ } \ unsigned int get_number_of_points() const { \ return vsi_.size(); \ } \ }; \ template <> \ struct KNNData: public KNNData##D { \ template \ KNNData(It b, It e): KNNData##D(create_vectors_with_index(b,e)) { \ } \ } \ IMP_CGAL_KNN_D(2); IMP_CGAL_KNN_D(3); IMP_CGAL_KNN_D(4); IMPCGAL_END_INTERNAL_NAMESPACE #endif /* IMPCGAL_INTERNAL_KNN_H */