8 #ifndef IMPALGEBRA_VECTOR_SEARCH_H
9 #define IMPALGEBRA_VECTOR_SEARCH_H
20 #ifdef IMP_ALGEBRA_USE_IMP_CGAL
21 #include <IMP/cgal/internal/knn.h>
23 #ifdef IMP_ALGEBRA_USE_ANN
24 #include "internal/ann.h"
26 #include "internal/linear_knn.h"
29 #ifdef IMP_ALGEBRA_USE_ANN
30 #define IMP_KNN_DATA internal::ANNData
31 #elif defined(IMP_ALGEBRA_USE_IMP_CGAL)
32 #define IMP_KNN_DATA IMP::cgal::internal::KNNData
34 #define IMP_KNN_DATA internal::LinearKNNData<D>
38 IMPALGEBRA_BEGIN_NAMESPACE
57 #if IMP_HAS_CHECKS >= IMP_INTERNAL
58 mutable std::ofstream query_log_;
61 void instantiate(It b, It e) {
65 internal::LinearKNNData<D> linear(b,e);
66 linear.fill_nearest_neighbors(*b, 3U, eps_, ret);
72 Object(
"NearestNeighbor%1%"),
73 data_(b,e), eps_(epsilon){
78 Object(
"NearestNeighbor%1%"),
79 data_(vs.begin(), vs.end()),
81 instantiate(vs.begin(), vs.end());
88 #if IMP_HAS_CHECKS >= IMP_INTERNAL
89 query_log_.open(fname.c_str());
90 for (
unsigned int i=0; i< data_.get_number_of_points(); ++i) {
91 query_log_ << spaces_io(data_.get_point(i)) << std::endl;
93 query_log_ << std::endl;
97 unsigned int get_nearest_neighbor(
const VectorD<D> &q)
const {
100 #if IMP_HAS_CHECKS >= IMP_INTERNAL
102 query_log_ << spaces_io(q) <<
" " << 1 << std::endl;
106 data_.fill_nearest_neighbors(q, 1U, eps_, ret);
113 #if IMP_HAS_CHECKS >= IMP_INTERNAL
115 query_log_ << i <<
" " << 1 << std::endl;
119 data_.fill_nearest_neighbors(data_.get_point(i), 2U, eps_, ret);
127 #if IMP_HAS_CHECKS >= IMP_INTERNAL
129 query_log_ << i <<
" " << k << std::endl;
133 data_.fill_nearest_neighbors(data_.get_point(i), k+1, eps_, ret);
134 return Ints(++ret.begin(), ret.end());
137 unsigned int k)
const {
140 #if IMP_HAS_CHECKS >= IMP_INTERNAL
142 query_log_ << v <<
" " << k << std::endl;
146 data_.fill_nearest_neighbors(v, k, eps_, ret);
147 return Ints(++ret.begin(), ret.end());
154 data_.fill_nearest_neighbors(data_.get_point(i), distance, eps_, ret);
155 return Ints(++ret.begin(), ret.end());
162 data_.fill_nearest_neighbors(pt, distance, eps_, ret);
171 typedef NearestNeighborD<1> NearestNeighbor1D;
172 typedef NearestNeighborD<2> NearestNeighbor2D;
173 typedef NearestNeighborD<3> NearestNeighbor3D;
174 typedef NearestNeighborD<4> NearestNeighbor4D;
175 typedef NearestNeighborD<5> NearestNeighbor5D;
176 typedef NearestNeighborD<6> NearestNeighbor6D;
177 typedef NearestNeighborD<-1> NearestNeighborKD;
198 void set_coordinates_internal(
int id,
Vector3D nc);
201 double query_estimate=1);
202 Ints get_in_ball(
int id,
double distance)
const;
203 void set_coordinates(
int id,
Vector3D nc);
206 IMPALGEBRA_END_NAMESPACE