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 MRMESH_API explicit Laplacian( Mesh & mesh );
30
34 void init( const VertBitSet & freeVerts, EdgeWeights weights, VertexMass vmass = VertexMass::Unit, RememberShape rem = RememberShape::Yes )
35 { initFromPoints( points_, freeVerts, weights, vmass, rem ); }
36
38 MRMESH_API void initFromPoints( const VertCoords & points, const VertBitSet & freeVerts, EdgeWeights weights,
40
43 MRMESH_API void fixVertex( VertId v, bool smooth = true );
44
47 MRMESH_API void fixVertex( VertId v, const Vector3f & fixedPos, bool smooth = true );
48
50 MRMESH_API void multVertexWeight( VertId v, double factor );
51
54
57 MRMESH_API void applyToVector( VertCoords & points );
58
61 void apply() { applyToVector( points_ ); }
62
65 MRMESH_API void applyToScalar( VertScalars & scalarField );
66
68 [[nodiscard]] const VertBitSet & region() const { return region_; }
69
71 [[nodiscard]] const VertBitSet & freeVerts() const { return freeVerts_; }
72
74 [[nodiscard]] const VertBitSet & firstLayerFixedVerts() const { assert( solver_ ); return firstLayerFixedVerts_; }
75
77 [[nodiscard]] const MeshTopology & topology() const { return topology_; }
78
80 [[nodiscard]] VertCoords & points() const { return points_; }
81
83 struct Attractor
84 {
86 Vector3d target;
91 double weight = 1;
92 };
93
96
99
100private:
101 template <typename I, typename G, typename S, typename P>
102 void prepareRhs_( I && iniRhs, G && g, S && s, P && p ) const;
103
104 const MeshTopology & topology_;
105 VertCoords & points_;
106
108 VertBitSet region_;
109
111 VertBitSet freeVerts_;
112
114 VertBitSet fixedSharpVertices_;
115
117 VertBitSet firstLayerFixedVerts_;
118
120 struct Equation
121 {
122 Vector3d rhs;
123 double centerCoeff = 0;
124 int firstElem = 0;
125 };
126 std::vector<Equation> equations_;
127
128 std::vector<Attractor> attractors_;
129
130 struct Element
131 {
132 double coeff = 0;
133 VertId neiVert;
134 };
135 std::vector<Element> nonZeroElements_;
136
138 Vector< int, VertId > regionVert2id_;
139 Vector< int, VertId > freeVert2id_;
140
141 class Solver;
142 std::unique_ptr<Solver> solver_;
143};
144
145}
#define MRMESH_API
Definition MRMeshFwd.h:80
Definition MRMeshTopology.h:23
void addAttractor(const Attractor &a)
adds one more attractor to the stored list
void apply()
Definition MRLaplacian.h:61
void applyToScalar(VertScalars &scalarField)
const VertBitSet & freeVerts() const
return currently free vertices
Definition MRLaplacian.h:71
const VertBitSet & firstLayerFixedVerts() const
return fixed vertices from the first layer around free vertices
Definition MRLaplacian.h:74
int firstElem
coefficient on matrix diagonal
Definition MRLaplacian.h:124
double weight
Definition MRLaplacian.h:91
void init(const VertBitSet &freeVerts, EdgeWeights weights, VertexMass vmass=VertexMass::Unit, RememberShape rem=RememberShape::Yes)
Definition MRLaplacian.h:34
MeshTriPoint p
Definition MRLaplacian.h:85
EdgeWeights
determines the weight of each edge in applications like Laplacian
Definition MREnums.h:44
Laplacian(Laplacian &&) noexcept
void applyToVector(VertCoords &points)
Laplacian(Mesh &mesh)
Laplacian(const MeshTopology &topology, VertCoords &points)
class MRMESH_CLASS I
Definition MRMeshFwd.h:137
double centerCoeff
equation right hand side
Definition MRLaplacian.h:123
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:68
Vector3d target
Definition MRLaplacian.h:86
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:122
const MeshTopology & topology() const
return the topology for which Laplacian was constructed
Definition MRLaplacian.h:77
void removeAllAttractors()
forgets all attractors added previously
double coeff
Definition MRLaplacian.h:132
VertId neiVert
Definition MRLaplacian.h:133
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:80
void fixVertex(VertId v, const Vector3f &fixedPos, bool smooth=true)
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 for bindings generation
Definition MRCameraOrientationPlugin.h:8
attracts the given point inside some mesh's triangle to the given target with the given weight
Definition MRLaplacian.h:84
Definition MRMeshTriPoint.h:26
Definition MRMesh.h:23