#include <iostream>
#include <random>
#include <Ponca/SpatialPartitioning>
#include <Ponca/src/Common/pointTypes.h>
#include <Eigen/Core>
int main()
{
constexpr int N {100000};
std::vector<DataPoint> points(N);
std::generate(points.begin(), points.end(), [](){
return DataPoint{100 * DataPoint::VectorType::Random()};
});
int seed = 0;
std::vector<int> indices(N);
std::vector<int> sampling(N / 2);
std::iota(indices.begin(), indices.end(), 0);
std::sample(indices.begin(), indices.end(), sampling.begin(), N / 2, std::mt19937(seed));
kdtree = &kdtreeSparse;
kdtree = &kdtreeDense;
const int query_idx = 10;
const DataPoint::VectorType query_pt{-10.0, 0.5, 75.0};
const int k = 10;
std::cout << "The nearest neighbor of the point at index " << query_idx << " is at index "
<< *kdtree->nearestNeighbor(query_idx).begin() << std::endl;
std::cout << "The nearest neighbor of the point (" << query_pt.transpose() << ") is at index "
<< *kdtree->nearestNeighbor(query_pt).begin() << std::endl;
std::cout << "The " << k << "-nearest neighbors of the point at index " << query_idx << " are at indices: ";
for(int neighbor_idx : kdtreeDense.kNearestNeighbors(query_idx, k)) {
std::cout << neighbor_idx << ", ";
}
std::cout << std::endl;
std::cout << "The " << k << "-nearest neighbors of the point (" << query_pt.transpose() << ") are at indices: ";
for(auto neighbor_idx : kdtreeDense.kNearestNeighbors(query_pt, k)) {
std::cout << neighbor_idx << ", ";
}
std::cout << std::endl;
std::cout << "The nearest neighbors of the point at index " << query_idx << " are at indices: ";
for(int neighbor_idx : knnGraph.kNearestNeighbors(query_idx)) {
std::cout << neighbor_idx << ", ";
}
std::cout << std::endl;
const int second_query_idx = 5;
constexpr DataPoint::Scalar radius = 5.25;
auto rangeNeighbors = kdtreeDense.rangeNeighbors(query_idx, radius);
std::cout << "The neighbors of the point at index " << second_query_idx << " at a distance " << radius << " are at indices: ";
for(int neighbor_idx : rangeNeighbors(second_query_idx, radius)) {
std::cout << neighbor_idx << ", ";
}
std::cout << std::endl;
auto posRangeNeighbors = kdtreeDense.rangeNeighborsQuery();
std::cout << "The neighbors of the point (" << query_pt.transpose() << ") at a distance " << radius << " are at indices: ";
for(auto neighbor_idx : posRangeNeighbors(query_pt, radius)) {
std::cout << neighbor_idx << ", ";
}
std::cout << std::endl;
auto knnRangeNeighbors = knnGraph.rangeNeighborsIndexQuery();
std::cout << "The neighbors of the point (" << query_pt.transpose() << ") at a distance " << radius << " are at indices: ";
for(auto neighbor_idx : knnRangeNeighbors(query_idx, radius)) {
std::cout << neighbor_idx << ", ";
}
std::cout << std::endl;
return 1;
}
Customizable base class for KnnGraph datastructure.
Point data type containing only containing the position vector.
Public interface for dense KdTree datastructure.
Public interface for sparse KdTree datastructure.
Abstract KdTree type with KdTreeDefaultTraits.