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"
31#ifdef IMP_ALGEBRA_USE_ANN
32#define IMP_KNN_DATA internal::ANNData
33#elif defined(IMP_ALGEBRA_USE_IMP_CGAL)
34#define IMP_KNN_DATA IMP::cgal::internal::KNNData
36#define IMP_KNN_DATA internal::LinearKNNData<D>
39IMPALGEBRA_BEGIN_NAMESPACE
58#if IMP_HAS_CHECKS >= IMP_INTERNAL
59 mutable std::ofstream query_log_;
62 void instantiate(It b, It e) {
66 internal::LinearKNNData<D> linear(b, e);
67 linear.fill_nearest_neighbors(*b, 3U, eps_, ret);
73 NearestNeighborD(It b, It e,
double epsilon = 0)
74 :
Object(
"NearestNeighbor%1%"), 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);
135 ret.resize(std::min(k + 1, data_.get_number_of_points()));
138 Ints::iterator it = std::find(ret.begin(), ret.end(),
static_cast<int>(i));
139 if (it != ret.end()) {
141 }
else if (ret.size() > k) {
147 unsigned int k)
const {
150#if IMP_HAS_CHECKS >= IMP_INTERNAL
152 query_log_ << v <<
" " << k << std::endl;
156 data_.fill_nearest_neighbors(v, k, eps_, ret);
158 ret.resize(std::min(k, data_.get_number_of_points()));
166 data_.fill_nearest_neighbors(data_.get_point(i), distance, eps_, ret);
168 ret.erase(std::remove(ret.begin(), ret.end(),
static_cast<int>(i)),
177 data_.fill_nearest_neighbors(pt, distance, eps_, ret);
201class IMPALGEBRAEXPORT DynamicNearestNeighbor3D :
public Object {
205 typedef Grid::Index Index;
206 typedef Grid::ExtendedIndex EIndex;
210 void set_coordinates_internal(
int id,
Vector3D nc);
213 DynamicNearestNeighbor3D(
const Vector3Ds &vs,
double query_estimate = 1);
214 Ints get_in_ball(
int id,
double distance)
const;
215 void set_coordinates(
int id,
Vector3D nc);
218IMPALGEBRA_END_NAMESPACE
A class to represent a voxel grid.
A shared base class to help in debugging and things.
Checking and error reporting support.
#define IMP_INTERNAL_CHECK_VARIABLE(variable)
Common base class for heavy weight IMP objects.
Object(std::string name)
Construct an object with the given name.
void set_was_used(bool tf) const
A Cartesian vector in D-dimensions.
A more IMP-like version of the std::vector.
Embed a grid as an evenly spaced axis aligned grid.
A voxel grid in d-dimensional space.
Build a structure for finding nearest neighbors.
Ints get_in_ball(const VectorD< D > &pt, double distance) const
Find all points within the provided distance.
unsigned int get_nearest_neighbor(unsigned int i) const
Search using the ith point in the input set.
Ints get_nearest_neighbors(unsigned int i, unsigned int k) const
Search using the ith point in the input set.
Ints get_in_ball(unsigned int i, double distance) const
Find all points within the provided distance.
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.
Dense and sparse storage of the voxel data in a grid.
Logging and error reporting support.
Logging and error reporting support.
#define IMP_OBJECT_LOG
Set the log level to the object's log level.
Vector< VectorD< 3 > > Vector3Ds
IMP::Vector< Int > Ints
Standard way to pass a bunch of Int values.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.