8 #ifndef IMPALGEBRA_VECTOR_SEARCH_H
9 #define IMPALGEBRA_VECTOR_SEARCH_H
21 #ifdef IMP_ALGEBRA_USE_IMP_CGAL
22 #include <IMP/cgal/internal/knn.h>
24 #ifdef IMP_ALGEBRA_USE_ANN
25 #include "internal/ann.h"
27 #include "internal/linear_knn.h"
30 #ifdef IMP_ALGEBRA_USE_ANN
31 #define IMP_KNN_DATA internal::ANNData
32 #elif defined(IMP_ALGEBRA_USE_IMP_CGAL)
33 #define IMP_KNN_DATA IMP::cgal::internal::KNNData
35 #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);
73 : Object(
"NearestNeighbor%1%"), data_(b, e), eps_(epsilon) {
77 : Object(
"NearestNeighbor%1%"),
78 data_(vs.begin(), vs.end()),
80 instantiate(vs.begin(), vs.end());
87 #if IMP_HAS_CHECKS >= IMP_INTERNAL
88 query_log_.open(fname.c_str());
89 for (
unsigned int i = 0; i < data_.get_number_of_points(); ++i) {
90 query_log_ << spaces_io(data_.get_point(i)) << std::endl;
92 query_log_ << std::endl;
96 unsigned int get_nearest_neighbor(
const VectorD<D> &q)
const {
99 #if IMP_HAS_CHECKS >= IMP_INTERNAL
101 query_log_ << spaces_io(q) <<
" " << 1 << std::endl;
105 data_.fill_nearest_neighbors(q, 1U, eps_, ret);
112 #if IMP_HAS_CHECKS >= IMP_INTERNAL
114 query_log_ << i <<
" " << 1 << std::endl;
118 data_.fill_nearest_neighbors(data_.get_point(i), 2U, eps_, ret);
126 #if IMP_HAS_CHECKS >= IMP_INTERNAL
128 query_log_ << i <<
" " << k << std::endl;
132 data_.fill_nearest_neighbors(data_.get_point(i), k + 1, eps_, ret);
133 return Ints(++ret.begin(), ret.end());
136 unsigned int k)
const {
139 #if IMP_HAS_CHECKS >= IMP_INTERNAL
141 query_log_ << v <<
" " << k << std::endl;
145 data_.fill_nearest_neighbors(v, k, eps_, ret);
146 return Ints(++ret.begin(), ret.end());
153 data_.fill_nearest_neighbors(data_.get_point(i), distance, eps_, ret);
154 return Ints(++ret.begin(), ret.end());
161 data_.fill_nearest_neighbors(pt, distance, eps_, ret);
194 void set_coordinates_internal(
int id,
Vector3D nc);
198 Ints get_in_ball(
int id,
double distance)
const;
199 void set_coordinates(
int id,
Vector3D nc);
202 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)
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
#define IMP_OBJECT_LOG
Set the log level to the object's log level.
#define IMP_INTERNAL_CHECK_VARIABLE(variable)
An index in an infinite grid on space.
A voxel grid in d-dimensional space space.
A Cartesian vector in D-dimensions.
Logging and error reporting support.
A class to represent a voxel grid.
Ints get_in_ball(const VectorD< D > &pt, double distance) const
Common base class for heavy weight IMP objects.
Checking and error reporting support.
Ints get_nearest_neighbors(unsigned int i, unsigned int k) const
Search using the ith point in the input set.
A shared base class to help in debugging and things.
A class to represent a voxel grid.
Ints get_in_ball(unsigned int i, double distance) const
Logging and error reporting support.
IMP::base::Vector< Int > Ints
Standard way to pass a bunch of Int values.