MeshLib C++ Docs
Loading...
Searching...
No Matches
MRLaplacian.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRBitSet.h"
4#include "MRVector.h"
5#include "MRVector3.h"
6#include "MREnums.h"
7#include <MRPch/MREigenSparseCore.h>
8
9namespace MR
10{
13
14
24{
25public:
26 enum class RememberShape
27 {
28 Yes,
29 No
30 };
31
32 MRMESH_API explicit Laplacian( Mesh & mesh );
33 Laplacian( const MeshTopology & topology, VertCoords & points ) : topology_( topology ), points_( points ) { }
34
37 MRMESH_API void init( const VertBitSet & freeVerts, EdgeWeights weights, VertexMass vmass = VertexMass::Unit,
39
42 MRMESH_API void fixVertex( VertId v, bool smooth = true );
43
46 MRMESH_API void fixVertex( VertId v, const Vector3f & fixedPos, bool smooth = true );
47
49 MRMESH_API void updateSolver();
50
52 MRMESH_API void apply();
53
55 MRMESH_API void applyToScalar( VertScalars & scalarField );
56
58 [[nodiscard]] const VertBitSet & region() const { return region_; }
59
61 [[nodiscard]] const VertBitSet & freeVerts() const { return freeVerts_; }
62
64 [[nodiscard]] const VertBitSet & firstLayerFixedVerts() const { assert( solverValid_ ); return firstLayerFixedVerts_; }
65
66private:
68 void updateSolver_();
69
71 void updateRhs_();
72
73 template <typename I, typename G, typename S>
74 void prepareRhs_( I && iniRhs, G && g, S && s );
75
76 const MeshTopology & topology_;
77 VertCoords & points_;
78
80 VertBitSet region_;
81
83 VertBitSet freeVerts_;
84
86 VertBitSet fixedSharpVertices_;
87
89 VertBitSet firstLayerFixedVerts_;
90
92 struct Equation
93 {
94 Vector3d rhs;
95 double centerCoeff = 0;
96 int firstElem = 0;
97 };
98 std::vector<Equation> equations_;
99
100 struct Element
101 {
102 double coeff = 0;
103 VertId neiVert;
104 };
105 std::vector<Element> nonZeroElements_;
106
108 Vector< int, VertId > regionVert2id_;
109 Vector< int, VertId > freeVert2id_;
110
111 using SparseMatrix = Eigen::SparseMatrix<double,Eigen::RowMajor>;
112 SparseMatrix M_;
113
115 bool solverValid_ = false;
116 using SparseMatrixColMajor = Eigen::SparseMatrix<double,Eigen::ColMajor>;
117
119 class Solver
120 {
121 public:
122 virtual ~Solver() = default;
123 virtual void compute( const SparseMatrixColMajor& A ) = 0;
124 virtual Eigen::VectorXd solve( const Eigen::VectorXd& rhs ) = 0;
125 };
126 std::unique_ptr<Solver> solver_;
127
129 bool rhsValid_ = false;
130 Eigen::VectorXd rhs_[3];
131};
132
133}
Definition MRLaplacian.h:24
Definition MRMeshTopology.h:22
const VertBitSet & freeVerts() const
return currently free vertices
Definition MRLaplacian.h:61
MRMESH_API void apply()
given fixed vertices, computes positions of remaining region vertices
const VertBitSet & firstLayerFixedVerts() const
return fixed vertices from the first layer around free vertices
Definition MRLaplacian.h:64
MRMESH_API void fixVertex(VertId v, const Vector3f &fixedPos, bool smooth=true)
int firstElem
coefficient on matrix diagonal
Definition MRLaplacian.h:96
virtual void compute(const SparseMatrixColMajor &A)=0
MRMESH_API void updateSolver()
if you manually call this method after initialization and fixing vertices then next apply call will b...
virtual Eigen::VectorXd solve(const Eigen::VectorXd &rhs)=0
EdgeWeights
determines the weight of each edge in applications like Laplacian
Definition MREnums.h:44
RememberShape
Definition MRLaplacian.h:27
MRMESH_API Laplacian(Mesh &mesh)
virtual ~Solver()=default
Laplacian(const MeshTopology &topology, VertCoords &points)
Definition MRLaplacian.h:33
double centerCoeff
equation right hand side
Definition MRLaplacian.h:95
MRMESH_API void init(const VertBitSet &freeVerts, EdgeWeights weights, VertexMass vmass=VertexMass::Unit, RememberShape rem=Laplacian::RememberShape::Yes)
const VertBitSet & region() const
return all initially free vertices and the first layer of vertices around them
Definition MRLaplacian.h:58
MRMESH_API void fixVertex(VertId v, bool smooth=true)
Vector3d rhs
Definition MRLaplacian.h:94
double coeff
Definition MRLaplacian.h:102
VertId neiVert
Definition MRLaplacian.h:103
VertexMass
determines the weight or mass of each vertex in applications like Laplacian
Definition MREnums.h:34
MRMESH_API void applyToScalar(VertScalars &scalarField)
given a pre-resized scalar field with set values in fixed vertices, computes the values in free verti...
@ No
true Laplacian mode when initial mesh shape is remembered and copied in apply
@ Unit
all vertices have same mass=1
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRMesh.h:23