MeshLib Documentation
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
63 bool optimizeVertexPos = true;
64
66 int maxDeletedVertices = INT_MAX;
67
69 int maxDeletedFaces = INT_MAX;
70
72 FaceBitSet * region = nullptr;
73
75 UndirectedEdgeBitSet* notFlippable = nullptr;
76
80
83 UndirectedEdgeBitSet * edgesToCollapse = nullptr;
84
88
90 bool touchNearBdEdges = true;
91
95 bool touchBdVerts = true;
96
99 const VertBitSet * bdVerts = nullptr;
100
103 float maxAngleChange = -1;
104
112
121 std::function<void( UndirectedEdgeId ue, float & collapseErrorSq, Vector3f & collapsePos )> adjustCollapse;
122
125 std::function<void( EdgeId del, EdgeId rem )> onEdgeDel;
126
133
135 bool packMesh = false;
136
139
143
147
151 std::vector<FaceBitSet> * partFaces = nullptr;
152
155};
156
166struct DecimateResult
167{
168 int vertsDeleted = 0;
169 int facesDeleted = 0;
176 bool cancelled = true;
177};
178
191
196[[nodiscard]] MRMESH_API QuadraticForm3f computeFormAtVertex( const MeshPart & mp, VertId v, float stabilizer, const UndirectedEdgeBitSet * creases = nullptr );
197
202[[nodiscard]] MRMESH_API Vector<QuadraticForm3f, VertId> computeFormsAtVertices( const MeshPart & mp, float stabilizer, const UndirectedEdgeBitSet * creases = nullptr );
203
209[[nodiscard]] MRMESH_API FaceBitSet getSubdividePart( const FaceBitSet & valids, size_t subdivideParts, size_t myPart );
210
212{
213 [[deprecated]]
214 int maxIters = 1;
216 float maxDeviation = 0;
218 float tinyEdgeLength = 0;
220 float maxAngleChange = PI_F / 3;
223 float criticalAspectRatio = 10000;
226 float stabilizer = 1e-6f;
228 FaceBitSet * region = nullptr;
229};
230
240[[deprecated(" use the version with parameter struct instead" )]]
241MRMESH_API bool resolveMeshDegenerations( Mesh& mesh, int maxIters, float maxDeviation = 0, float maxAngleChange = PI_F / 3, float criticalAspectRatio = 10000 );
242
243
245{
248 float targetEdgeLen = 0.001f;
250 int maxEdgeSplits = 10'000'000;
252 float maxAngleChangeAfterFlip = 30 * PI_F / 180.0f;
254 float maxBdShift = FLT_MAX;
257 bool useCurvature = false;
264 FaceBitSet * region = nullptr;
267 UndirectedEdgeBitSet* notFlippable = nullptr;
269 bool packMesh = false;
274 std::function<void(EdgeId e1, EdgeId e)> onEdgeSplit;
276 std::function<void(EdgeId e, EdgeId e1)> onEdgeDel;
283 std::function<bool( EdgeId edgeToCollapse, const Vector3f& newEdgeOrgPos )> preCollapse;
286};
287// Splits too long and eliminates too short edges from the mesh
288MRMESH_API bool remesh( Mesh& mesh, const RemeshSettings & settings );
289
290} //namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
std::vector<T>-like container that requires specific indexing type,
Definition MRMesh/MRVector.h:20
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:576
MRMESH_API DecimateResult decimateMesh(Mesh &mesh, const DecimateSettings &settings={})
Collapse edges in mesh region according to the settings.
MRMESH_API QuadraticForm3f computeFormAtVertex(const MeshPart &mp, VertId v, float stabilizer, const UndirectedEdgeBitSet *creases=nullptr)
Computes quadratic form at given vertex of the initial surface before decimation.
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 Vector< QuadraticForm3f, VertId > computeFormsAtVertices(const MeshPart &mp, float stabilizer, const UndirectedEdgeBitSet *creases=nullptr)
Computes quadratic forms at every vertex of mesh part before decimation.
MRMESH_API bool resolveMeshDegenerations(Mesh &mesh, const ResolveMeshDegenSettings &settings={})
Resolves degenerate triangles in given mesh.
Definition MRCameraOrientationPlugin.h:8
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:427
HashMap< UndirectedEdgeId, UndirectedEdgeId > UndirectedEdgeHashMap
Definition MRMesh/MRMeshFwd.h:467
Results of MR::decimateMesh.
int vertsDeleted
Number deleted verts. Same as the number of performed collapses.
Definition MRMesh/MRMeshDecimate.h:168
int facesDeleted
Definition MRMesh/MRMeshDecimate.h:169
float errorIntroduced
Definition MRMesh/MRMeshDecimate.h:174
bool cancelled
whether the algorithm was cancelled by the callback
Definition MRMesh/MRMeshDecimate.h:176
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:75
bool collapseNearNotFlippable
Definition MRMesh/MRMeshDecimate.h:79
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:121
bool packMesh
whether to pack mesh at the end
Definition MRMesh/MRMeshDecimate.h:135
int maxDeletedFaces
Limit on the number of deleted faces.
Definition MRMesh/MRMeshDecimate.h:69
PreCollapseCallback preCollapse
The user can provide this optional callback that is invoked immediately before edge collapse;.
Definition MRMesh/MRMeshDecimate.h:111
UndirectedEdgeHashMap * twinMap
Definition MRMesh/MRMeshDecimate.h:87
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:146
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:154
std::vector< FaceBitSet > * partFaces
Definition MRMesh/MRMeshDecimate.h:151
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:132
int subdivideParts
Definition MRMesh/MRMeshDecimate.h:142
FaceBitSet * region
Region on mesh to be decimated, it is updated during the operation.
Definition MRMesh/MRMeshDecimate.h:72
const VertBitSet * bdVerts
Definition MRMesh/MRMeshDecimate.h:99
ProgressCallback progressCallback
callback to report algorithm progress and cancel it by user request
Definition MRMesh/MRMeshDecimate.h:138
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:66
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:63
float maxEdgeLen
Maximal possible edge length created during decimation.
Definition MRMesh/MRMeshDecimate.h:42
UndirectedEdgeBitSet * edgesToCollapse
Definition MRMesh/MRMeshDecimate.h:83
bool touchNearBdEdges
Whether to allow collapsing or flipping edges having at least one vertex on (region) boundary.
Definition MRMesh/MRMeshDecimate.h:90
float maxAngleChange
Definition MRMesh/MRMeshDecimate.h:103
bool touchBdVerts
Definition MRMesh/MRMeshDecimate.h:95
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:125
Definition MRMesh/MRMesh.h:23
Definition MRMesh/MRMeshDecimate.h:245
bool finalRelaxNoShrinkage
if true prevents the surface from shrinkage after many iterations
Definition MRMesh/MRMeshDecimate.h:262
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:276
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:274
float targetEdgeLen
Definition MRMesh/MRMeshDecimate.h:248
int maxEdgeSplits
Maximum number of edge splits allowed during subdivision.
Definition MRMesh/MRMeshDecimate.h:250
bool useCurvature
Definition MRMesh/MRMeshDecimate.h:257
bool projectOnOriginalMesh
Definition MRMesh/MRMeshDecimate.h:272
float maxAngleChangeAfterFlip
Improves local mesh triangulation by doing edge flips if it does not change dihedral angle more than ...
Definition MRMesh/MRMeshDecimate.h:252
FaceBitSet * region
Region on mesh to be changed, it is updated during the operation.
Definition MRMesh/MRMeshDecimate.h:264
float maxBdShift
Maximal shift of a boundary during one edge collapse.
Definition MRMesh/MRMeshDecimate.h:254
ProgressCallback progressCallback
callback to report algorithm progress and cancel it by user request
Definition MRMesh/MRMeshDecimate.h:285
int finalRelaxIters
Definition MRMesh/MRMeshDecimate.h:260
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:283
bool packMesh
whether to pack mesh at the end
Definition MRMesh/MRMeshDecimate.h:269
UndirectedEdgeBitSet * notFlippable
Definition MRMesh/MRMeshDecimate.h:267
Definition MRMesh/MRMeshDecimate.h:212
float maxAngleChange
Permit edge flips if it does not change dihedral angle more than on this value.
Definition MRMesh/MRMeshDecimate.h:220
float maxDeviation
maximum permitted deviation from the original surface
Definition MRMesh/MRMeshDecimate.h:216
FaceBitSet * region
degenerations will be fixed only in given region, which is updated during the processing
Definition MRMesh/MRMeshDecimate.h:228
float criticalAspectRatio
Definition MRMesh/MRMeshDecimate.h:223
float tinyEdgeLength
edges not longer than this value will be collapsed ignoring normals and aspect ratio checks
Definition MRMesh/MRMeshDecimate.h:218
int maxIters
Definition MRMesh/MRMeshDecimate.h:214
float stabilizer
Definition MRMesh/MRMeshDecimate.h:226