Ponca  292d8d7132745e0d4242ff9a01e93697fc96b204
Point Cloud Analysis library
Loading...
Searching...
No Matches
Ponca basic plane fit

This is an example of how to use Ponca to compute surface variation on random data with plane fitting.

/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <Ponca/Ponca>
using namespace std;
using namespace Ponca;
using Scalar = MyPoint::Scalar;
using VectorType = MyPoint::VectorType;
// Define related structure
template <typename Fit>
void test_fit(Fit& _fit, vector<MyPoint>& _vecs, const VectorType& _p)
{
Scalar tmax = 100.0;
// Set a weighting function instance
_fit.setNeighborFilter({_p, tmax});
// Fit plane (method compute handles multipass fitting
if (_fit.compute(_vecs.begin(), _vecs.end()) == STABLE)
{
cout << "Value of the scalar field at the initial point: " << _p.transpose() << " is equal to "
<< _fit.potential(_p) << endl;
cout << "It's gradient at this place is equal to: " << _fit.primitiveGradient(_p).transpose() << endl;
cout << "The initial point " << _p.transpose() << endl
<< "Is projected at " << _fit.project(_p).transpose() << endl;
cout << "Value of the surface variation: " << _fit.surfaceVariation() << endl;
}
}
int main()
{
// init random point cloud
int n = 10000;
vector<MyPoint> vecs(n);
std::generate(vecs.begin(), vecs.end(), getRandomPoint<MyPoint>);
std::cout << "====================\nCovariancePlaneFit:\n";
CovPlaneFit fit;
test_fit(fit, vecs, vecs.at(0).pos());
}
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:294
Weight neighbors according to the Euclidean distance between a query and a reference position.
Point data type containing the position and normal vectors.
Definition pointTypes.h:23
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11
DataPoint getRandomPoint()
Generate a random points.
@ STABLE
The fitting is stable and ready to use.
Definition enums.h:17