16 template <
typename Result>
18 return result.worst_distance() <
epsilon;
32 template <
int N,
typename IndexTransform =
identity_transform>
35 static constexpr
size_t INVALID = std::numeric_limits<size_t>::max();
47 if constexpr (N > 0) {
48 if (num_neighbors >= 0) {
49 std::cerr <<
"warning: Specifying dynamic num_neighbors=" << num_neighbors <<
" for a static KNN result container (N=" << N <<
")" << std::endl;
53 if (num_neighbors <= 0) {
54 std::cerr <<
"error: Specifying invalid num_neighbors=" << num_neighbors <<
" for a dynamic KNN result container" << std::endl;
60 std::fill(this->distances, this->distances +
buffer_size(), std::numeric_limits<double>::max());
65 if constexpr (N > 0) {
80 void push(
size_t index,
double distance) {
85 if constexpr (N == 1) {
90 for (; insert_loc > 0 && distance <
distances[insert_loc - 1]; insert_loc--) {
Definition: flat_container.hpp:12
K-nearest neighbor search result container.
Definition: knn_result.hpp:33
double worst_distance() const
Worst distance in the result.
Definition: knn_result.hpp:76
size_t buffer_size() const
Buffer size (i.e., Maximum number of neighbors)
Definition: knn_result.hpp:64
const IndexTransform index_transform
Point index transformation (e.g., local point index to global point/voxel index)
Definition: knn_result.hpp:103
double * distances
Distances to neighbors.
Definition: knn_result.hpp:107
static constexpr size_t INVALID
Definition: knn_result.hpp:35
const int capacity
Maximum number of neighbors to search.
Definition: knn_result.hpp:104
void push(size_t index, double distance)
Push a pair of point index and distance to the result.
Definition: knn_result.hpp:80
size_t num_found() const
Number of found neighbors.
Definition: knn_result.hpp:73
KnnResult(size_t *indices, double *distances, int num_neighbors=-1, const IndexTransform &index_transform=identity_transform())
Constructor.
Definition: knn_result.hpp:41
size_t * indices
Indices of neighbors.
Definition: knn_result.hpp:106
int num_found_neighbors
Number of found neighbors.
Definition: knn_result.hpp:105
K-nearest neighbor search setting.
Definition: knn_result.hpp:13
double epsilon
Early termination threshold.
Definition: knn_result.hpp:22
bool fulfilled(const Result &result) const
Check if the result satisfies the early termination condition.
Definition: knn_result.hpp:17