MeshLib Documentation
Loading...
Searching...
No Matches
MRBestFit.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRSymMatrix3.h"
4#include "MRPlane3.h"
5#include "MRLine3.h"
6#include "MRPolyline.h"
7#include "MRAffineXf3.h"
8#include <array>
9
10namespace MR
11{
12
16
19{
20public:
21 MRMESH_API void addPoint( const Vector3d & pt );
22 MRMESH_API void addPoint( const Vector3d & pt, double weight );
23 void addPoint( const Vector3f& pt ) { addPoint( Vector3d( pt ) ); }
24 void addPoint( const Vector3f& pt, float weight ) { addPoint( Vector3d( pt ), weight ); }
25
27 MRMESH_API Plane3d getBestPlane() const;
28 Plane3f getBestPlanef() const { return Plane3f( getBestPlane() ); }
30 MRMESH_API Line3d getBestLine() const;
31 Line3f getBestLinef() const { return Line3f( getBestLine() ); }
32
34 MRMESH_API bool getCenteredCovarianceEigen( Vector3d & centroid, Matrix3d & eigenvectors, Vector3d & eigenvalues ) const;
35 MRMESH_API bool getCenteredCovarianceEigen( Vector3f& centroid, Matrix3f& eigenvectors, Vector3f& eigenvalues ) const;
36
39 MRMESH_API AffineXf3d getBasicXf() const;
40 AffineXf3f getBasicXf3f() const { return AffineXf3f( getBasicXf() ); }
41
44 MRMESH_API std::array<AffineXf3d, 4> get4BasicXfs() const;
45 MRMESH_API std::array<AffineXf3f, 4> get4BasicXfs3f() const;
46
47 bool valid() const { return sumWeight_ > 0; };
48
49private:
50 double sumWeight_ = 0;
51 Vector3d momentum1_;
52 SymMatrix3d momentum2_;
53};
54
56MRMESH_API void accumulatePoints( PointAccumulator& accum, const std::vector<Vector3f>& points, const AffineXf3f* xf = nullptr );
57
59MRMESH_API void accumulateWeighedPoints( PointAccumulator& accum, const std::vector<Vector3f>& points, const std::vector<float>& weights, const AffineXf3f* xf = nullptr );
60
62MRMESH_API void accumulateFaceCenters( PointAccumulator& accum, const MeshPart& mp, const AffineXf3f* xf = nullptr );
63
65MRMESH_API void accumulateLineCenters( PointAccumulator& accum, const Polyline3& pl, const AffineXf3f* xf = nullptr );
66
68MRMESH_API void accumulatePoints( PointAccumulator& accum, const PointCloud& pc, const AffineXf3f* xf = nullptr );
69
71
74{
75public:
76 MRMESH_API void addPlane( const Plane3d & pl );
77 void addPlane( const Plane3f& pl ) { addPlane( Plane3d( pl ) ); }
78
84 MRMESH_API Vector3d findBestCrossPoint( const Vector3d & p0, double tol, int * rank = nullptr, Vector3d * space = nullptr ) const;
85 MRMESH_API Vector3f findBestCrossPoint( const Vector3f & p0, float tol, int * rank = nullptr, Vector3f * space = nullptr ) const;
86
87private:
88 SymMatrix3d mat_;
89 Vector3d rhs_;
90};
91
92} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
Class to accumulate planes to find then their crossing point.
Definition MRBestFit.h:74
MRMESH_API Vector3f findBestCrossPoint(const Vector3f &p0, float tol, int *rank=nullptr, Vector3f *space=nullptr) const
MRMESH_API void addPlane(const Plane3d &pl)
void addPlane(const Plane3f &pl)
Definition MRBestFit.h:77
MRMESH_API Vector3d findBestCrossPoint(const Vector3d &p0, double tol, int *rank=nullptr, Vector3d *space=nullptr) const
Class to accumulate points and make best line / plane approximation.
Definition MRBestFit.h:19
MRMESH_API void addPoint(const Vector3d &pt, double weight)
MRMESH_API Line3d getBestLine() const
computes the best approximating line from the accumulated points
MRMESH_API Plane3d getBestPlane() const
computes the best approximating plane from the accumulated points
void addPoint(const Vector3f &pt, float weight)
Definition MRBestFit.h:24
AffineXf3f getBasicXf3f() const
Definition MRBestFit.h:40
void addPoint(const Vector3f &pt)
Definition MRBestFit.h:23
bool valid() const
Definition MRBestFit.h:47
MRMESH_API std::array< AffineXf3d, 4 > get4BasicXfs() const
MRMESH_API bool getCenteredCovarianceEigen(Vector3d &centroid, Matrix3d &eigenvectors, Vector3d &eigenvalues) const
computes centroid and eigenvectors/eigenvalues of the covariance matrix of the accumulated points
MRMESH_API AffineXf3d getBasicXf() const
Plane3f getBestPlanef() const
Definition MRBestFit.h:28
MRMESH_API std::array< AffineXf3f, 4 > get4BasicXfs3f() const
Line3f getBestLinef() const
Definition MRBestFit.h:31
MRMESH_API void addPoint(const Vector3d &pt)
MRMESH_API bool getCenteredCovarianceEigen(Vector3f &centroid, Matrix3f &eigenvectors, Vector3f &eigenvalues) const
MRMESH_API void accumulateWeighedPoints(PointAccumulator &accum, const std::vector< Vector3f > &points, const std::vector< float > &weights, const AffineXf3f *xf=nullptr)
Adds in existing PointAccumulator all given weighed points.
MRMESH_API void accumulateLineCenters(PointAccumulator &accum, const Polyline3 &pl, const AffineXf3f *xf=nullptr)
Adds in existing PointAccumulator all line centers with the weight equal to the length line.
MRMESH_API void accumulateFaceCenters(PointAccumulator &accum, const MeshPart &mp, const AffineXf3f *xf=nullptr)
Adds in existing PointAccumulator all mesh face centers with the weight equal to face area.
MRMESH_API void accumulatePoints(PointAccumulator &accum, const std::vector< Vector3f > &points, const AffineXf3f *xf=nullptr)
Adds in existing PointAccumulator all given points.
Definition MRCameraOrientationPlugin.h:8
Definition MRMesh/MRPointCloud.h:16