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 "MRMeshTriPoint.h"
7#include "MREnums.h"
8
9namespace MR
10{
13
14
24{
25public:
26 MR_BIND_OVERLOAD_SUFFIX() MRMESH_API explicit Laplacian( Mesh & mesh );
27 MR_BIND_OVERLOAD_SUFFIX(topology) MRMESH_API Laplacian( const MeshTopology & topology, VertCoords & points );
30
33 void init( const VertBitSet & freeVerts, EdgeWeights weights, VertexMass vmass = VertexMass::Unit, RememberShape rem = RememberShape::Yes )
34 { initFromPoints( points_, freeVerts, weights, vmass, rem ); }
35
37 MRMESH_API void initFromPoints( const VertCoords & points, const VertBitSet & freeVerts, EdgeWeights weights,
39
42 MR_BIND_OVERLOAD_SUFFIX() MRMESH_API void fixVertex( VertId v, bool smooth = true );
43
46 MR_BIND_OVERLOAD_SUFFIX(pos) MRMESH_API void fixVertex( VertId v, const Vector3f & fixedPos, bool smooth = true );
47
49 MRMESH_API void multVertexWeight( VertId v, double factor );
50
53
56 MRMESH_API void applyToVector( VertCoords & points );
57
60 void apply() { applyToVector( points_ ); }
61
64 MRMESH_API void applyToScalar( VertScalars & scalarField );
65
67 [[nodiscard]] const VertBitSet & region() const { return region_; }
68
70 [[nodiscard]] const VertBitSet & freeVerts() const { return freeVerts_; }
71
73 [[nodiscard]] const VertBitSet & firstLayerFixedVerts() const { assert( solver_ ); return firstLayerFixedVerts_; }
74
76 [[nodiscard]] const MeshTopology & topology() const { return topology_; }
77
79 [[nodiscard]] VertCoords & points() const { return points_; }
80
82 struct Attractor
83 {
85 Vector3d target;
90 double weight = 1;
91 };
92
95
98
99private:
100 template <typename I, typename G, typename S, typename P>
101 void prepareRhs_( I && iniRhs, G && g, S && s, P && p ) const;
102
103 const MeshTopology & topology_;
104 VertCoords & points_;
105
107 VertBitSet region_;
108
110 VertBitSet freeVerts_;
111
113 VertBitSet fixedSharpVertices_;
114
116 VertBitSet firstLayerFixedVerts_;
117
119 struct Equation
120 {
121 Vector3d rhs;
122 double centerCoeff = 0;
123 int firstElem = 0;
124 };
125 std::vector<Equation> equations_;
126
127 std::vector<Attractor> attractors_;
128
129 struct Element
130 {
131 double coeff = 0;
132 VertId neiVert;
133 };
134 std::vector<Element> nonZeroElements_;
135
137 Vector< int, VertId > regionVert2id_;
138 Vector< int, VertId > freeVert2id_;
139
140 class Solver;
141 std::unique_ptr<Solver> solver_;
142};
143
144}
#define MRMESH_API
Definition MRMeshFwd.h:85
Definition MRMeshTopology.h:31
void addAttractor(const Attractor &a)
adds one more attractor to the stored list
void apply()
Definition MRLaplacian.h:60
void applyToScalar(VertScalars &scalarField)
const VertBitSet & freeVerts() const
return currently free vertices
Definition MRLaplacian.h:70
const VertBitSet & firstLayerFixedVerts() const
return fixed vertices from the first layer around free vertices
Definition MRLaplacian.h:73
int firstElem
coefficient on matrix diagonal
Definition MRLaplacian.h:123
MeshTriPoint
Definition MRMeshFwd.h:515
double weight
Definition MRLaplacian.h:90
void init(const VertBitSet &freeVerts, EdgeWeights weights, VertexMass vmass=VertexMass::Unit, RememberShape rem=RememberShape::Yes)
Definition MRLaplacian.h:33
MeshTriPoint p
Definition MRLaplacian.h:84
EdgeWeights
determines the weight of each edge in applications like Laplacian
Definition MREnums.h:44
void applyToVector(VertCoords &points)
Laplacian(Mesh &mesh)
double centerCoeff
equation right hand side
Definition MRLaplacian.h:122
void fixVertex(VertId v, bool smooth=true)
const VertBitSet & region() const
return all initially free vertices and the first layer of vertices around them
Definition MRLaplacian.h:67
Vector3d target
Definition MRLaplacian.h:85
RememberShape
Definition MREnums.h:56
void multVertexWeight(VertId v, double factor)
multiplies vertex equation's weight on the given factor
Vector3d rhs
Definition MRLaplacian.h:121
const MeshTopology & topology() const
return the topology for which Laplacian was constructed
Definition MRLaplacian.h:76
void removeAllAttractors()
forgets all attractors added previously
double coeff
Definition MRLaplacian.h:131
VertId neiVert
Definition MRLaplacian.h:132
VertexMass
determines the weight or mass of each vertex in applications like Laplacian
Definition MREnums.h:34
VertCoords & points() const
return the vector of coordinates for which Laplacian was constructed
Definition MRLaplacian.h:79
void updateSolver()
if you manually call this method after initialization and fixing vertices then next apply call will b...
void initFromPoints(const VertCoords &points, const VertBitSet &freeVerts, EdgeWeights weights, VertexMass vmass=VertexMass::Unit, RememberShape rem=RememberShape::Yes)
same as init() but uses the given points instead of ones passed to a constructor for weights computat...
@ factor
Definition MRUnitInfo.h:51
@ Yes
true Laplacian mode when initial mesh shape is remembered and copied in apply
Definition MREnums.h:57
@ Unit
all vertices have same mass=1
Definition MREnums.h:36
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
attracts the given point inside some mesh's triangle to the given target with the given weight
Definition MRLaplacian.h:83
Definition MRMesh.h:24