The example output the time required to collect the neighbors, and the number of neighbors collected:
#include <iostream>
#include <chrono>
#include <vector>
#include "./nanoflann.hpp"
#include <Ponca/Fitting>
#include <Ponca/SpatialPartitioning>
{
public:
enum
{
Dim = 3
};
using VectorType = Eigen::Matrix<Scalar, Dim, 1>;
using MatrixType = Eigen::Matrix<Scalar, Dim, Dim>;
PONCA_MULTIARCH
inline MyPoint(
const VectorType&
_pos = VectorType::Zero()) : m_pos(
_pos) {}
PONCA_MULTIARCH inline const VectorType& pos() const { return m_pos; }
PONCA_MULTIARCH inline VectorType& pos() { return m_pos; }
{
return {VectorType::Random().normalized() * Eigen::internal::random<Scalar>(0.9, 1.1)};
}
private:
VectorType m_pos;
};
using Scalar = MyPoint::Scalar;
using VectorType = MyPoint::VectorType;
{
using coord_t =
typename MyPoint::Scalar;
const std::vector<MyPoint>&
pts;
{
else
}
template <class BBOX>
{
return false;
}
};
nanoflann::KDTreeSingleIndexAdaptor<nanoflann::L2_Simple_Adaptor<Scalar, NFPointCloud>,
NFPointCloud, 3>;
{
std::cerr << "[raw] Something weird happened" << std::endl;
return f.getNumNeighbors();
}
{
if (!(
== STABLE))
std::cerr << "[ponca_kdtree] Something weird happened" << std::endl;
return f.getNumNeighbors();
}
{
std::vector<nanoflann::ResultItem<size_t, Scalar>>
indices_dists;
f.init();
do
{
f.startNewPass();
{
}
}
while (
res == NEED_OTHER_PASS);
std::cerr << "[nanoflann_kdtree] Something weird happened" << std::endl;
return f.getNumNeighbors();
}
{
using Scalar = typename MyPoint::Scalar;
constexpr int n = 100000;
std::vector<MyPoint>
vecs(n);
std::generate(
vecs.begin(),
vecs.end(), []() { return MyPoint::Random(); });
constexpr int nbrun = 1000;
std::generate(
queries.begin(),
queries.end(), []() { return MyPoint::Random().pos(); });
auto start = std::chrono::system_clock::now();
{
}
auto end = std::chrono::system_clock::now();
std::chrono::duration<double>
rawDiff = (end - start);
start = std::chrono::system_clock::now();
{
}
end = std::chrono::system_clock::now();
const std::chrono::duration<double>
poncaDiff = (end - start);
start = std::chrono::system_clock::now();
{
}
end = std::chrono::system_clock::now();
const std::chrono::duration<double>
nanoflannDiff = (end - start);
std::cout << "Timings: "
<< "\n"
<<
"Raw : " <<
rawDiff.count() <<
"\n"
std::cout << "Number of neighbors: "
<< "\n"
}
Aggregator class used to declare specialized structures using CRTP.
bool addNeighbor(const DataPoint &_nei)
Add a neighbor to perform the fit.
FIT_RESULT computeWithIds(IndexRange ids, const PointContainer &points)
Convenience function to iterate over a subset of samples in a PointContainer Add neighbors stored in ...
FIT_RESULT compute(const IteratorBegin &begin, const IteratorEnd &end)
Convenience function for STL-like iterators Add neighbors stored in a container using STL-like iterat...