#include <iostream>
#include <Ponca/SpatialPartitioning>
#include <Eigen/Core>
struct DataPoint
{
enum {Dim = 3};
using Scalar = float;
using VectorType = Eigen::Vector<Scalar,Dim>;
inline const auto& pos() const {return m_pos;}
VectorType m_pos;
};
int main()
{
constexpr int N = 1e5;
std::vector<DataPoint> points(N);
std::generate(points.begin(), points.end(), [](){
return DataPoint{100 * DataPoint::VectorType::Random()};});
const int query_idx = 10;
const DataPoint::VectorType query_pt{-10.0, 0.5, 75.0};
std::cout << "the nearest neighbor of the point at index " << query_idx << " is at index "
<< *kdtree.nearest_neighbor(query_idx).begin() << std::endl;
std::cout << "the nearest neighbor of the point (" << query_pt.transpose() << ") is at index "
<< *kdtree.nearest_neighbor(query_pt).begin() << std::endl;
constexpr int k = 10;
std::cout << "the " << k << "-nearest neighbors of the point at index " << query_idx << " are at indices: ";
for(int neighbor_idx : kdtree.k_nearest_neighbors(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 : kdtree.k_nearest_neighbors(query_pt, k)) {
std::cout << neighbor_idx << ", ";
}
std::cout << std::endl;
constexpr DataPoint::Scalar radius = 5.25;
std::cout << "the neighbors of the point at index " << query_idx << " at a distance " << radius << " are at indices: ";
for(int neighbor_idx : kdtree.range_neighbors(query_idx, radius)) {
std::cout << neighbor_idx << ", ";
}
std::cout << std::endl;
std::cout << "the neighbors of the point (" << query_pt.transpose() << ") at a distance " << radius << " are at indices: ";
for(auto neighbor_idx : kdtree.range_neighbors(query_pt, radius)) {
std::cout << neighbor_idx << ", ";
}
std::cout << std::endl;
return 1;
}