MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMesh/MRFreeFormDeformer.h
Go to the documentation of this file.
1#pragma once
2#include "MRMeshFwd.h"
3#include "MRVector3.h"
4#include "MRBox.h"
5#include "MRVector.h"
6#include "MRMeshEigen.h"
7
8namespace MR
9{
13{
14public:
15 // Only set mesh ref
16 MRMESH_API FreeFormDeformer( VertCoords& coords, const VertBitSet& valid );
17 MRMESH_API FreeFormDeformer( Mesh& mesh, const VertBitSet* region = nullptr );
18 // Calculates all points' normalized positions in parallel
19 // sets ref grid by initialBox, if initialBox is invalid uses mesh bounding box instead
20 MRMESH_API void init( const Vector3i& resolution = Vector3i::diagonal( 2 ), const Box3f& initialBox = Box3f() );
21 // Updates ref grid point position
22 MRMESH_API void setRefGridPointPosition( const Vector3i& coordOfPointInGrid, const Vector3f& newPos );
23 // Gets ref grid point position
24 MRMESH_API const Vector3f& getRefGridPointPosition( const Vector3i& coordOfPointInGrid ) const;
25 // Apply updated grid to all mesh points in parallel
26 // ensure updating render object after using it
27 MRMESH_API void apply() const;
28 // Apply updated grid to given point
29 MRMESH_API Vector3f applySinglePoint( const Vector3f& point ) const;
30 // Get one dimension index by grid coord
31 MRMESH_API int getIndex( const Vector3i& coordOfPointInGrid ) const;
32 // Get grid coord by index
33 MRMESH_API Vector3i getCoord( int index ) const;
34
35 const std::vector<Vector3f>& getAllRefGridPositions() const { return refPointsGrid_; }
36 void setAllRefGridPositions( const std::vector<Vector3f>& refPoints ) { refPointsGrid_ = refPoints; }
37 const Vector3i& getResolution() const { return resolution_; }
38private:
39 VertCoords& coords_;
40 const VertBitSet& validPoints_;
41 std::vector<Vector3f> refPointsGrid_;
42 Box3f initialBox_;
43 VertCoords normedCoords_;
44 Vector3i resolution_;
45
46 Vector3f applyToNormedPoint_( const Vector3f& normedPoint, std::vector<Vector3f>& xPlaneCache, std::vector<Vector3f>& yLineCache, std::vector<Vector3f>& tempPoints ) const;
47};
48
53{
54public:
56 MRMESH_API FreeFormBestFit( const Box3d& box, const Vector3i& resolution = Vector3i::diagonal( 2 ) );
57
59 MRMESH_API void addPair( const Vector3d& src, const Vector3d& tgt, double w = 1.0 );
60 void addPair( const Vector3f& src, const Vector3f& tgt, float w = 1.0f ) { addPair( Vector3d( src ), Vector3d( tgt ), double( w ) ); }
61
63 MRMESH_API void addOther( const FreeFormBestFit& other );
64
67 void setStabilizer( double stabilizer ) { stabilizer_ = stabilizer; }
68 double getStabilizer() const { return stabilizer_; }
69
71 [[nodiscard]] MRMESH_API std::vector<Vector3f> findBestDeformationReferenceGrid();
72private:
73 Box3d box_;
74 Vector3i resolution_;
75 size_t resXY_{ 0 };
76 size_t size_{ 0 };
77 double sumWeight_{ 0.0 };
78
79 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> accumA_;
80 Eigen::Matrix<double, Eigen::Dynamic, 3> accumB_;
81
82 std::vector<int> pascalLineX_;
83 std::vector<int> pascalLineY_;
84 std::vector<int> pascalLineZ_;
85
86 Vector3d reverseDiagonal_;
87
88 double stabilizer_{ 0.1 };
89 void stabilize_();
90};
91
93MRMESH_API std::vector<Vector3f> makeFreeFormOriginGrid( const Box3f& box, const Vector3i& resolution );
94
95// Calculates best Free Form transform to fit given source->target deformation
96// origin ref grid as box corners ( resolution parameter specifies how to divide box )
97// samplesToBox - if set used to transform source and target points to box space
98// returns new positions of ref grid
99MRMESH_API std::vector<Vector3f> findBestFreeformDeformation( const Box3f& box, const std::vector<Vector3f>& source, const std::vector<Vector3f>& target,
100 const Vector3i& resolution = Vector3i::diagonal( 2 ), const AffineXf3f* samplesToBox = nullptr );
101
102}
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:79
#define MRMESH_CLASS
Definition MRMesh/MRMeshFwd.h:83
Definition MRMesh/MRFreeFormDeformer.h:53
MRMESH_API void addPair(const Vector3d &src, const Vector3d &tgt, double w=1.0)
add pair of source and target point to accumulator
void addPair(const Vector3f &src, const Vector3f &tgt, float w=1.0f)
Definition MRMesh/MRFreeFormDeformer.h:60
double getStabilizer() const
Definition MRMesh/MRFreeFormDeformer.h:68
void setStabilizer(double stabilizer)
Definition MRMesh/MRFreeFormDeformer.h:67
MRMESH_API std::vector< Vector3f > findBestDeformationReferenceGrid()
finds best grid points positions to align source points to target points
MRMESH_API void addOther(const FreeFormBestFit &other)
adds other instance of FreeFormBestFit if it has same ref grid
MRMESH_API FreeFormBestFit(const Box3d &box, const Vector3i &resolution=Vector3i::diagonal(2))
initialize the class, compute cached values and reserve space for matrices
Class for deforming mesh using Bernstein interpolation.
Definition MRMesh/MRFreeFormDeformer.h:13
MRMESH_API void setRefGridPointPosition(const Vector3i &coordOfPointInGrid, const Vector3f &newPos)
MRMESH_API FreeFormDeformer(VertCoords &coords, const VertBitSet &valid)
MRMESH_API FreeFormDeformer(Mesh &mesh, const VertBitSet *region=nullptr)
const Vector3i & getResolution() const
Definition MRMesh/MRFreeFormDeformer.h:37
MRMESH_API const Vector3f & getRefGridPointPosition(const Vector3i &coordOfPointInGrid) const
MRMESH_API Vector3i getCoord(int index) const
MRMESH_API int getIndex(const Vector3i &coordOfPointInGrid) const
MRMESH_API Vector3f applySinglePoint(const Vector3f &point) const
MRMESH_API void init(const Vector3i &resolution=Vector3i::diagonal(2), const Box3f &initialBox=Box3f())
void setAllRefGridPositions(const std::vector< Vector3f > &refPoints)
Definition MRMesh/MRFreeFormDeformer.h:36
MRMESH_API void apply() const
const std::vector< Vector3f > & getAllRefGridPositions() const
Definition MRMesh/MRFreeFormDeformer.h:35
Definition MRCameraOrientationPlugin.h:8
MRMESH_API std::vector< Vector3f > findBestFreeformDeformation(const Box3f &box, const std::vector< Vector3f > &source, const std::vector< Vector3f > &target, const Vector3i &resolution=Vector3i::diagonal(2), const AffineXf3f *samplesToBox=nullptr)
MRMESH_API std::vector< Vector3f > makeFreeFormOriginGrid(const Box3f &box, const Vector3i &resolution)
Returns positions of grid points in given box with given resolution.
Definition MRMesh/MRMesh.h:22