This is an example of how to use Ponca to fit a Line on random 3D samples.
#include <numeric>
#include <algorithm>
#include <iostream>
#include <vector>
#include <Ponca/Fitting>
#include <Ponca/src/Common/pointTypes.h>
using namespace Eigen;
using namespace std;
using Scalar = MyPoint::Scalar;
using VectorType = MyPoint::VectorType;
{
constexpr int n = 10000;
VectorType
dir = VectorType::Random().normalized();
std::generate(points.begin(), points.end(),
[&
dir]() { return (dir * Eigen::internal::random<Scalar>(0.1, 2)).eval(); });
const VectorType&
p = points.at(0).pos();
std::cout << "====================\nLeastSquareLineFit:\n";
cout <<
"Direction of the generated line: " <<
dir.transpose() <<
endl;
_fit.setNeighborFilter({
p, 1});
{
cout <<
"Direction of the fitted 3D line: " <<
_fit.direction().transpose() <<
endl;
cout <<
"Origin of the fitted line: " <<
_fit.origin().transpose() <<
endl;
cout <<
"Projection of the basis center on the fitted line: " <<
_fit.project(
p).transpose() <<
endl;
std::transform_reduce(points.cbegin(), points.cend(), Scalar(0), std::plus<>(),
cout <<
"Mean error between samples and fitted line: " <<
dist / Scalar(n) <<
endl;
}
cerr <<
"Fit is not stable: " <<
_fit.getCurrentState() <<
endl;
}
Aggregator class used to declare specialized structures using CRTP.
This Source Code Form is subject to the terms of the Mozilla Public License, v.
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...