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>
37 IMPALGEBRA_BEGIN_NAMESPACE
56 #if IMP_HAS_CHECKS >= IMP_INTERNAL
57 mutable std::ofstream query_log_;
60 void instantiate(It b, It e) {
64 internal::LinearKNNData<D> linear(b, e);
65 linear.fill_nearest_neighbors(*b, 3U, eps_, ret);
72 : Object(
"NearestNeighbor%1%"), data_(b, e), eps_(epsilon) {
76 : Object(
"NearestNeighbor%1%"),
77 data_(vs.begin(), vs.end()),
79 instantiate(vs.begin(), vs.end());
86 #if IMP_HAS_CHECKS >= IMP_INTERNAL
87 query_log_.open(fname.c_str());
88 for (
unsigned int i = 0; i < data_.get_number_of_points(); ++i) {
89 query_log_ << spaces_io(data_.get_point(i)) << std::endl;
91 query_log_ << std::endl;
95 unsigned int get_nearest_neighbor(
const VectorD<D> &q)
const {
98 #if IMP_HAS_CHECKS >= IMP_INTERNAL
100 query_log_ << spaces_io(q) <<
" " << 1 << std::endl;
104 data_.fill_nearest_neighbors(q, 1U, eps_, ret);
111 #if IMP_HAS_CHECKS >= IMP_INTERNAL
113 query_log_ << i <<
" " << 1 << std::endl;
117 data_.fill_nearest_neighbors(data_.get_point(i), 2U, eps_, ret);
125 #if IMP_HAS_CHECKS >= IMP_INTERNAL
127 query_log_ << i <<
" " << k << std::endl;
131 data_.fill_nearest_neighbors(data_.get_point(i), k + 1, eps_, ret);
132 return Ints(++ret.begin(), ret.end());
135 unsigned int k)
const {
138 #if IMP_HAS_CHECKS >= IMP_INTERNAL
140 query_log_ << v <<
" " << k << std::endl;
144 data_.fill_nearest_neighbors(v, k, eps_, ret);
145 return Ints(++ret.begin(), ret.end());
152 data_.fill_nearest_neighbors(data_.get_point(i), distance, eps_, ret);
153 return Ints(++ret.begin(), ret.end());
160 data_.fill_nearest_neighbors(pt, distance, eps_, ret);
193 void set_coordinates_internal(
int id,
Vector3D nc);
197 Ints get_in_ball(
int id,
double distance)
const;
198 void set_coordinates(
int id,
Vector3D nc);
201 IMPALGEBRA_END_NAMESPACE
unsigned int get_nearest_neighbor(unsigned int i) const
void set_query_log(std::string fname)
Log the points and queries to a file for performance studies.
A class to represent a voxel grid.
Represent a real cell in a grid (one within the bounding box)
An index in an infinite grid on space.
A voxel grid in d-dimensional space space.
#define IMP_INTERNAL_CHECK_VARIABLE(variable)
A Cartesian vector in D-dimensions.
Checkging and error reporting support.
A class to represent a voxel grid.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Ints get_in_ball(const VectorD< D > &pt, double distance) const
Common base class for heavy weight IMP objects.
#define IMP_OBJECT_LOG
Set the log level to the object's log level.
Ints get_nearest_neighbors(unsigned int i, unsigned int k) const
Logging and error reporting support.
A class to represent a voxel grid.
Ints get_in_ball(unsigned int i, double distance) const
A shared base class to help in debugging and things.
IMP::base::Vector< Int > Ints
Standard way to pass a bunch of Int values.