MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMesh/MRMeshDecimate.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
5#include "MRConstants.h"
6#include <cfloat>
7#include <climits>
8#include <functional>
9
10namespace MR
11{
19{
20 MinimizeError, // the next edge to collapse will be the one that introduced minimal error to the surface
21 ShortestEdgeFirst // the next edge to collapse will be the shortest one
22};
23
31struct DecimateSettings
32{
34
39 float maxError = FLT_MAX;
40
42 float maxEdgeLen = FLT_MAX;
43
45 float maxBdShift = FLT_MAX;
46
49
52 float criticalTriAspectRatio = FLT_MAX;
53
55 float tinyEdgeLength = -1;
56
59 float stabilizer = 0.001f;
60
64
67 bool optimizeVertexPos = true;
68
70 int maxDeletedVertices = INT_MAX;
71
73 int maxDeletedFaces = INT_MAX;
74
76 FaceBitSet * region = nullptr;
77
79 UndirectedEdgeBitSet* notFlippable = nullptr;
80
84
87 UndirectedEdgeBitSet * edgesToCollapse = nullptr;
88
92
94 bool touchNearBdEdges = true;
95
99 bool touchBdVerts = true;
100
104 VertBitSet * bdVerts = nullptr;
105
108 float maxAngleChange = -1;
109
117
126 std::function<void( UndirectedEdgeId ue, float & collapseErrorSq, Vector3f & collapsePos )> adjustCollapse;
127
130 std::function<void( EdgeId del, EdgeId rem )> onEdgeDel;
131
138
140 bool packMesh = false;
141
144
148
152
156 std::vector<FaceBitSet> * partFaces = nullptr;
157
160};
161
171struct DecimateResult
172{
173 int vertsDeleted = 0;
174 int facesDeleted = 0;
181 bool cancelled = true;
182};
183
196
201[[nodiscard]] MRMESH_API QuadraticForm3f computeFormAtVertex( const MeshPart & mp, VertId v, float stabilizer, bool angleWeigted, const UndirectedEdgeBitSet * creases = nullptr );
202
207[[nodiscard]] MRMESH_API Vector<QuadraticForm3f, VertId> computeFormsAtVertices( const MeshPart & mp, float stabilizer, bool angleWeigted, const UndirectedEdgeBitSet * creases = nullptr );
208
214[[nodiscard]] MRMESH_API FaceBitSet getSubdividePart( const FaceBitSet & valids, size_t subdivideParts, size_t myPart );
215
217{
218 [[deprecated]]
219 int maxIters = 1;
221 float maxDeviation = 0;
223 float tinyEdgeLength = 0;
225 float maxAngleChange = PI_F / 3;
228 float criticalAspectRatio = 10000;
231 float stabilizer = 1e-6f;
233 FaceBitSet * region = nullptr;
234};
235
245[[deprecated(" use the version with parameter struct instead" )]]
246MRMESH_API bool resolveMeshDegenerations( Mesh& mesh, int maxIters, float maxDeviation = 0, float maxAngleChange = PI_F / 3, float criticalAspectRatio = 10000 );
247
248
250{
253 float targetEdgeLen = 0.001f;
255 int maxEdgeSplits = 10'000'000;
257 float maxAngleChangeAfterFlip = 30 * PI_F / 180.0f;
259 float maxBdShift = FLT_MAX;
262 bool useCurvature = false;
269 FaceBitSet * region = nullptr;
272 UndirectedEdgeBitSet* notFlippable = nullptr;
274 bool packMesh = false;
279 std::function<void(EdgeId e1, EdgeId e)> onEdgeSplit;
281 std::function<void(EdgeId e, EdgeId e1)> onEdgeDel;
288 std::function<bool( EdgeId edgeToCollapse, const Vector3f& newEdgeOrgPos )> preCollapse;
291};
292// Splits too long and eliminates too short edges from the mesh
293MRMESH_API bool remesh( Mesh& mesh, const RemeshSettings & settings );
294
295} //namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:79
std::vector<T>-like container that requires specific indexing type,
Definition MRMesh/MRVector.h:20
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:626
MRMESH_API DecimateResult decimateMesh(Mesh &mesh, const DecimateSettings &settings={})
Collapse edges in mesh region according to the settings.
MRMESH_API FaceBitSet getSubdividePart(const FaceBitSet &valids, size_t subdivideParts, size_t myPart)
returns given subdivision part of all valid faces; parallel threads shall be able to safely modify th...
MRMESH_API bool resolveMeshDegenerations(Mesh &mesh, const ResolveMeshDegenSettings &settings={})
Resolves degenerate triangles in given mesh.
MRMESH_API QuadraticForm3f computeFormAtVertex(const MeshPart &mp, VertId v, float stabilizer, bool angleWeigted, const UndirectedEdgeBitSet *creases=nullptr)
Computes quadratic form at given vertex of the initial surface before decimation.
MRMESH_API Vector< QuadraticForm3f, VertId > computeFormsAtVertices(const MeshPart &mp, float stabilizer, bool angleWeigted, const UndirectedEdgeBitSet *creases=nullptr)
Computes quadratic forms at every vertex of mesh part before decimation.
MRMESH_API bool remesh(Mesh &mesh, const RemeshSettings &settings)
DecimateStrategy
Defines the order of edge collapses inside Decimate algorithm.
Definition MRMesh/MRMeshDecimate.h:19
@ MinimizeError
Definition MRMesh/MRMeshDecimate.h:20
@ ShortestEdgeFirst
Definition MRMesh/MRMeshDecimate.h:21
std::function< bool(EdgeId edgeToCollapse, const Vector3f &newEdgeOrgPos)> PreCollapseCallback
Definition MRMesh/MRMeshFwd.h:472
HashMap< UndirectedEdgeId, UndirectedEdgeId > UndirectedEdgeHashMap
Definition MRMesh/MRMeshFwd.h:512
Results of MR::decimateMesh.
int vertsDeleted
Number deleted verts. Same as the number of performed collapses.
Definition MRMesh/MRMeshDecimate.h:173
int facesDeleted
Definition MRMesh/MRMeshDecimate.h:174
float errorIntroduced
Definition MRMesh/MRMeshDecimate.h:179
bool cancelled
whether the algorithm was cancelled by the callback
Definition MRMesh/MRMeshDecimate.h:181
Parameters structure for MR::decimateMesh.
UndirectedEdgeBitSet * notFlippable
Edges specified by this bit-set will never be flipped, but they can be collapsed or replaced during c...
Definition MRMesh/MRMeshDecimate.h:79
bool collapseNearNotFlippable
Definition MRMesh/MRMeshDecimate.h:83
std::function< void(UndirectedEdgeId ue, float &collapseErrorSq, Vector3f &collapsePos)> adjustCollapse
The user can provide this optional callback for adjusting error introduced by this edge collapse and ...
Definition MRMesh/MRMeshDecimate.h:126
bool angleWeightedDistToPlane
Definition MRMesh/MRMeshDecimate.h:63
bool packMesh
whether to pack mesh at the end
Definition MRMesh/MRMeshDecimate.h:140
int maxDeletedFaces
Limit on the number of deleted faces.
Definition MRMesh/MRMeshDecimate.h:73
PreCollapseCallback preCollapse
The user can provide this optional callback that is invoked immediately before edge collapse;.
Definition MRMesh/MRMeshDecimate.h:116
UndirectedEdgeHashMap * twinMap
Definition MRMesh/MRMeshDecimate.h:91
float maxBdShift
Maximal shift of a boundary during one edge collapse.
Definition MRMesh/MRMeshDecimate.h:45
float criticalTriAspectRatio
Definition MRMesh/MRMeshDecimate.h:52
bool decimateBetweenParts
Definition MRMesh/MRMeshDecimate.h:151
DecimateStrategy strategy
Definition MRMesh/MRMeshDecimate.h:33
int minFacesInPart
minimum number of faces in one subdivision part for ( subdivideParts > 1 ) mode
Definition MRMesh/MRMeshDecimate.h:159
std::vector< FaceBitSet > * partFaces
Definition MRMesh/MRMeshDecimate.h:156
Vector< QuadraticForm3f, VertId > * vertForms
If not null, then vertex quadratic forms are stored there; if on input the vector is not empty then i...
Definition MRMesh/MRMeshDecimate.h:137
int subdivideParts
Definition MRMesh/MRMeshDecimate.h:147
FaceBitSet * region
Region on mesh to be decimated, it is updated during the operation.
Definition MRMesh/MRMeshDecimate.h:76
ProgressCallback progressCallback
callback to report algorithm progress and cancel it by user request
Definition MRMesh/MRMeshDecimate.h:143
float stabilizer
Definition MRMesh/MRMeshDecimate.h:59
float maxError
Definition MRMesh/MRMeshDecimate.h:39
int maxDeletedVertices
Limit on the number of deleted vertices.
Definition MRMesh/MRMeshDecimate.h:70
VertBitSet * bdVerts
Definition MRMesh/MRMeshDecimate.h:104
float tinyEdgeLength
edges not longer than this value will be collapsed even if it results in appearance of a triangle wit...
Definition MRMesh/MRMeshDecimate.h:55
bool optimizeVertexPos
Definition MRMesh/MRMeshDecimate.h:67
float maxEdgeLen
Maximal possible edge length created during decimation.
Definition MRMesh/MRMeshDecimate.h:42
UndirectedEdgeBitSet * edgesToCollapse
Definition MRMesh/MRMeshDecimate.h:87
bool touchNearBdEdges
Whether to allow collapsing or flipping edges having at least one vertex on (region) boundary.
Definition MRMesh/MRMeshDecimate.h:94
float maxAngleChange
Definition MRMesh/MRMeshDecimate.h:108
bool touchBdVerts
Definition MRMesh/MRMeshDecimate.h:99
float maxTriangleAspectRatio
Maximal possible aspect ratio of a triangle introduced during decimation.
Definition MRMesh/MRMeshDecimate.h:48
std::function< void(EdgeId del, EdgeId rem)> onEdgeDel
Definition MRMesh/MRMeshDecimate.h:130
Definition MRMesh/MRMesh.h:23
Definition MRMesh/MRMeshDecimate.h:250
bool finalRelaxNoShrinkage
if true prevents the surface from shrinkage after many iterations
Definition MRMesh/MRMeshDecimate.h:267
std::function< void(EdgeId e, EdgeId e1)> onEdgeDel
if valid (e1) is given then dest(e) = dest(e1) and their origins are in different ends of collapsing ...
Definition MRMesh/MRMeshDecimate.h:281
std::function< void(EdgeId e1, EdgeId e)> onEdgeSplit
this function is called each time edge (e) is split into (e1->e), but before the ring is made Delone
Definition MRMesh/MRMeshDecimate.h:279
float targetEdgeLen
Definition MRMesh/MRMeshDecimate.h:253
int maxEdgeSplits
Maximum number of edge splits allowed during subdivision.
Definition MRMesh/MRMeshDecimate.h:255
bool useCurvature
Definition MRMesh/MRMeshDecimate.h:262
bool projectOnOriginalMesh
Definition MRMesh/MRMeshDecimate.h:277
float maxAngleChangeAfterFlip
Improves local mesh triangulation by doing edge flips if it does not change dihedral angle more than ...
Definition MRMesh/MRMeshDecimate.h:257
FaceBitSet * region
Region on mesh to be changed, it is updated during the operation.
Definition MRMesh/MRMeshDecimate.h:269
float maxBdShift
Maximal shift of a boundary during one edge collapse.
Definition MRMesh/MRMeshDecimate.h:259
ProgressCallback progressCallback
callback to report algorithm progress and cancel it by user request
Definition MRMesh/MRMeshDecimate.h:290
int finalRelaxIters
Definition MRMesh/MRMeshDecimate.h:265
std::function< bool(EdgeId edgeToCollapse, const Vector3f &newEdgeOrgPos)> preCollapse
The user can provide this optional callback that is invoked immediately before edge collapse;.
Definition MRMesh/MRMeshDecimate.h:288
bool packMesh
whether to pack mesh at the end
Definition MRMesh/MRMeshDecimate.h:274
UndirectedEdgeBitSet * notFlippable
Definition MRMesh/MRMeshDecimate.h:272
Definition MRMesh/MRMeshDecimate.h:217
float maxAngleChange
Permit edge flips if it does not change dihedral angle more than on this value.
Definition MRMesh/MRMeshDecimate.h:225
float maxDeviation
maximum permitted deviation from the original surface
Definition MRMesh/MRMeshDecimate.h:221
FaceBitSet * region
degenerations will be fixed only in given region, which is updated during the processing
Definition MRMesh/MRMeshDecimate.h:233
float criticalAspectRatio
Definition MRMesh/MRMeshDecimate.h:228
float tinyEdgeLength
edges not longer than this value will be collapsed ignoring normals and aspect ratio checks
Definition MRMesh/MRMeshDecimate.h:223
int maxIters
Definition MRMesh/MRMeshDecimate.h:219
float stabilizer
Definition MRMesh/MRMeshDecimate.h:231