MeshLib C++ Docs
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 "MRPointCloudPart.h"
9#include <array>
10
11namespace MR
12{
13
17
20{
21public:
22 MRMESH_API void addPoint( const Vector3d & pt );
23 MRMESH_API void addPoint( const Vector3d & pt, double weight );
24 void addPoint( const Vector3f& pt ) { addPoint( Vector3d( pt ) ); }
25 void addPoint( const Vector3f& pt, float weight ) { addPoint( Vector3d( pt ), weight ); }
26
28 MRMESH_API Plane3d getBestPlane() const;
29 Plane3f getBestPlanef() const { return Plane3f( getBestPlane() ); }
31 MRMESH_API Line3d getBestLine() const;
32 Line3f getBestLinef() const { return Line3f( getBestLine() ); }
33
35 MRMESH_API bool getCenteredCovarianceEigen( Vector3d & centroid, Matrix3d & eigenvectors, Vector3d & eigenvalues ) const;
36 MRMESH_API bool getCenteredCovarianceEigen( Vector3f& centroid, Matrix3f& eigenvectors, Vector3f& eigenvalues ) const;
37
40 MRMESH_API AffineXf3d getBasicXf() const;
41 AffineXf3f getBasicXf3f() const { return AffineXf3f( getBasicXf() ); }
42
45 MRMESH_API std::array<AffineXf3d, 4> get4BasicXfs() const;
46 MRMESH_API std::array<AffineXf3f, 4> get4BasicXfs3f() const;
47
48 bool valid() const { return sumWeight_ > 0; };
49
50private:
51 double sumWeight_ = 0;
52 Vector3d momentum1_;
53 SymMatrix3d momentum2_;
54};
55
57MRMESH_API void accumulatePoints( PointAccumulator& accum, const std::vector<Vector3f>& points, const AffineXf3f* xf = nullptr );
58
60MRMESH_API void accumulateWeighedPoints( PointAccumulator& accum, const std::vector<Vector3f>& points, const std::vector<float>& weights, const AffineXf3f* xf = nullptr );
61
63MRMESH_API void accumulateFaceCenters( PointAccumulator& accum, const MeshPart& mp, const AffineXf3f* xf = nullptr );
64
66MRMESH_API void accumulateLineCenters( PointAccumulator& accum, const Polyline3& pl, const AffineXf3f* xf = nullptr );
67
69MRMESH_API void accumulatePoints( PointAccumulator& accum, const PointCloudPart& pcp, const AffineXf3f* xf = nullptr );
70
72
75{
76public:
77 MRMESH_API void addPlane( const Plane3d & pl );
78 void addPlane( const Plane3f& pl ) { addPlane( Plane3d( pl ) ); }
79
85 MRMESH_API Vector3d findBestCrossPoint( const Vector3d & p0, double tol, int * rank = nullptr, Vector3d * space = nullptr ) const;
86 MRMESH_API Vector3f findBestCrossPoint( const Vector3f & p0, float tol, int * rank = nullptr, Vector3f * space = nullptr ) const;
87
88private:
89 SymMatrix3d mat_;
90 Vector3d rhs_;
91};
92
93} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:80
Class to accumulate planes to find then their crossing point.
Definition MRBestFit.h:75
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:78
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:20
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:25
AffineXf3f getBasicXf3f() const
Definition MRBestFit.h:41
void addPoint(const Vector3f &pt)
Definition MRBestFit.h:24
bool valid() const
Definition MRBestFit.h:48
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:29
MRMESH_API std::array< AffineXf3f, 4 > get4BasicXfs3f() const
Line3f getBestLinef() const
Definition MRBestFit.h:32
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
represents full point cloud (if region is nullptr) or some portion of point cloud (if region pointer ...
Definition MRPointCloudPart.h:10