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
19class PointAccumulator
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 MRMeshFwd.h:80
Definition MRBestFit.h:75
unsafe void addPlane(MR.Const_Plane3d pl)
Definition MRBestFit.h:20
unsafe void addPoint(in MR.Vector3d pt)
Definition MRPointCloudPart.h:10
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