MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMesh/MRMeshDecimate.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRPch/MRBindingMacros.h"
4#include "MRMeshFwd.h"
6#include "MRConstants.h"
7#include <cfloat>
8#include <climits>
9#include <functional>
10#include <optional>
11
12namespace MR
13{
21{
22 MinimizeError, // the next edge to collapse will be the one that introduced minimal error to the surface
23 ShortestEdgeFirst // the next edge to collapse will be the shortest one
24};
25
33struct DecimateSettings
34{
36
41 float maxError = FLT_MAX;
42
44 float maxEdgeLen = FLT_MAX;
45
47 float maxBdShift = FLT_MAX;
48
51
54 float criticalTriAspectRatio = FLT_MAX;
55
57 float tinyEdgeLength = -1;
58
61 float stabilizer = 0.001f;
62
66
69 bool optimizeVertexPos = true;
70
72 int maxDeletedVertices = INT_MAX;
73
75 int maxDeletedFaces = INT_MAX;
76
78 FaceBitSet * region = nullptr;
79
81 UndirectedEdgeBitSet* notFlippable = nullptr;
82
86
89 UndirectedEdgeBitSet * edgesToCollapse = nullptr;
90
94
96 bool touchNearBdEdges = true;
97
101 bool touchBdVerts = true;
102
106 VertBitSet * bdVerts = nullptr;
107
110 float maxAngleChange = -1;
111
119
128 std::function<void( UndirectedEdgeId ue, float & collapseErrorSq, Vector3f & collapsePos )> adjustCollapse;
129
132 std::function<void( EdgeId del, EdgeId rem )> onEdgeDel;
133
140
142 bool packMesh = false;
143
146
150
154
158 std::vector<FaceBitSet> * partFaces = nullptr;
159
162};
163
173struct DecimateResult
174{
175 int vertsDeleted = 0;
176 int facesDeleted = 0;
183 bool cancelled = true;
184};
185
195
199
201[[nodiscard]] MRMESH_API std::optional<ObjectMeshData> makeDecimatedObjectMeshData( const ObjectMesh & obj, const DecimateSettings & settings,
202 DecimateResult * outRes = nullptr );
203
204
209[[nodiscard]] MRMESH_API QuadraticForm3f computeFormAtVertex( const MeshPart & mp, VertId v, float stabilizer, bool angleWeigted, const UndirectedEdgeBitSet * creases = nullptr );
210
215[[nodiscard]] MRMESH_API Vector<QuadraticForm3f, VertId> computeFormsAtVertices( const MeshPart & mp, float stabilizer, bool angleWeigted, const UndirectedEdgeBitSet * creases = nullptr );
216
222[[nodiscard]] MRMESH_API FaceBitSet getSubdividePart( const FaceBitSet & valids, size_t subdivideParts, size_t myPart );
223
225{
227 float maxDeviation = 0;
228
230 float tinyEdgeLength = 0;
231
233 float maxAngleChange = PI_F / 3;
234
237 float criticalAspectRatio = 10000;
238
241 float stabilizer = 1e-6f;
242
244 FaceBitSet * region = nullptr;
245};
246
256
257
259{
262 float targetEdgeLen = 0.001f;
264 int maxEdgeSplits = 10'000'000;
266 float maxAngleChangeAfterFlip = 30 * PI_F / 180.0f;
268 float maxBdShift = FLT_MAX;
271 bool useCurvature = false;
278 FaceBitSet * region = nullptr;
281 UndirectedEdgeBitSet* notFlippable = nullptr;
283 bool packMesh = false;
288 std::function<void(EdgeId e1, EdgeId e)> onEdgeSplit;
290 std::function<void(EdgeId e, EdgeId e1)> onEdgeDel;
297 std::function<bool( EdgeId edgeToCollapse, const Vector3f& newEdgeOrgPos )> preCollapse;
300};
301// Splits too long and eliminates too short edges from the mesh
302MRMESH_API bool remesh( Mesh& mesh, const RemeshSettings & settings );
303
304} //namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:80
Definition MRObjectMesh.h:11
std::vector<T>-like container that requires specific indexing type,
Definition MRMesh/MRVector.h:19
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:729
MRMESH_API DecimateResult decimateMesh(Mesh &mesh, const DecimateSettings &settings={})
Performs mesh simplification 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={})
Removes degenerate triangles in a mesh by calling decimateMesh function with appropriate settings.
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.
Definition MRCameraOrientationPlugin.h:8
MRMESH_API bool remesh(Mesh &mesh, const RemeshSettings &settings)
MRMESH_API DecimateResult decimateObjectMeshData(ObjectMeshData &data, const DecimateSettings &settings)
DecimateStrategy
Defines the order of edge collapses inside Decimate algorithm.
Definition MRMesh/MRMeshDecimate.h:21
@ MinimizeError
Definition MRMesh/MRMeshDecimate.h:22
@ ShortestEdgeFirst
Definition MRMesh/MRMeshDecimate.h:23
std::function< bool(EdgeId edgeToCollapse, const Vector3f &newEdgeOrgPos)> PreCollapseCallback
Definition MRMesh/MRMeshFwd.h:559
MRMESH_API std::optional< ObjectMeshData > makeDecimatedObjectMeshData(const ObjectMesh &obj, const DecimateSettings &settings, DecimateResult *outRes=nullptr)
returns the data of decimated mesh given ObjectMesh (which remains unchanged) and decimation paramete...
HashMap< UndirectedEdgeId, UndirectedEdgeId > UndirectedEdgeHashMap
Definition MRMesh/MRMeshFwd.h:599
Results of MR::decimateMesh.
int vertsDeleted
Number deleted verts. Same as the number of performed collapses.
Definition MRMesh/MRMeshDecimate.h:175
int facesDeleted
Definition MRMesh/MRMeshDecimate.h:176
float errorIntroduced
Definition MRMesh/MRMeshDecimate.h:181
bool cancelled
whether the algorithm was cancelled by the callback
Definition MRMesh/MRMeshDecimate.h:183
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:81
bool collapseNearNotFlippable
Definition MRMesh/MRMeshDecimate.h:85
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:128
bool angleWeightedDistToPlane
Definition MRMesh/MRMeshDecimate.h:65
bool packMesh
whether to pack mesh at the end
Definition MRMesh/MRMeshDecimate.h:142
int maxDeletedFaces
Limit on the number of deleted faces.
Definition MRMesh/MRMeshDecimate.h:75
PreCollapseCallback preCollapse
The user can provide this optional callback that is invoked immediately before edge collapse;.
Definition MRMesh/MRMeshDecimate.h:118
UndirectedEdgeHashMap * twinMap
Definition MRMesh/MRMeshDecimate.h:93
float maxBdShift
Maximal shift of a boundary during one edge collapse.
Definition MRMesh/MRMeshDecimate.h:47
float criticalTriAspectRatio
Definition MRMesh/MRMeshDecimate.h:54
bool decimateBetweenParts
Definition MRMesh/MRMeshDecimate.h:153
DecimateStrategy strategy
Definition MRMesh/MRMeshDecimate.h:35
int minFacesInPart
minimum number of faces in one subdivision part for ( subdivideParts > 1 ) mode
Definition MRMesh/MRMeshDecimate.h:161
std::vector< FaceBitSet > * partFaces
Definition MRMesh/MRMeshDecimate.h:158
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:139
int subdivideParts
Definition MRMesh/MRMeshDecimate.h:149
FaceBitSet * region
Region on mesh to be decimated, it is updated during the operation.
Definition MRMesh/MRMeshDecimate.h:78
ProgressCallback progressCallback
callback to report algorithm progress and cancel it by user request
Definition MRMesh/MRMeshDecimate.h:145
float stabilizer
Definition MRMesh/MRMeshDecimate.h:61
float maxError
Definition MRMesh/MRMeshDecimate.h:41
int maxDeletedVertices
Limit on the number of deleted vertices.
Definition MRMesh/MRMeshDecimate.h:72
VertBitSet * bdVerts
Definition MRMesh/MRMeshDecimate.h:106
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:57
bool optimizeVertexPos
Definition MRMesh/MRMeshDecimate.h:69
float maxEdgeLen
Maximal possible edge length created during decimation.
Definition MRMesh/MRMeshDecimate.h:44
UndirectedEdgeBitSet * edgesToCollapse
Definition MRMesh/MRMeshDecimate.h:89
bool touchNearBdEdges
Whether to allow collapsing or flipping edges having at least one vertex on (region) boundary.
Definition MRMesh/MRMeshDecimate.h:96
float maxAngleChange
Definition MRMesh/MRMeshDecimate.h:110
bool touchBdVerts
Definition MRMesh/MRMeshDecimate.h:101
float maxTriangleAspectRatio
Maximal possible aspect ratio of a triangle introduced during decimation.
Definition MRMesh/MRMeshDecimate.h:50
std::function< void(EdgeId del, EdgeId rem)> onEdgeDel
Definition MRMesh/MRMeshDecimate.h:132
Definition MRMesh/MRMesh.h:23
mesh and its per-element attributes for ObjectMeshHolder
Definition MRObjectMeshData.h:14
Definition MRMesh/MRMeshDecimate.h:259
bool finalRelaxNoShrinkage
if true prevents the surface from shrinkage after many iterations
Definition MRMesh/MRMeshDecimate.h:276
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:290
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:288
float targetEdgeLen
Definition MRMesh/MRMeshDecimate.h:262
int maxEdgeSplits
Maximum number of edge splits allowed during subdivision.
Definition MRMesh/MRMeshDecimate.h:264
bool useCurvature
Definition MRMesh/MRMeshDecimate.h:271
bool projectOnOriginalMesh
Definition MRMesh/MRMeshDecimate.h:286
float maxAngleChangeAfterFlip
Improves local mesh triangulation by doing edge flips if it does not change dihedral angle more than ...
Definition MRMesh/MRMeshDecimate.h:266
FaceBitSet * region
Region on mesh to be changed, it is updated during the operation.
Definition MRMesh/MRMeshDecimate.h:278
float maxBdShift
Maximal shift of a boundary during one edge collapse.
Definition MRMesh/MRMeshDecimate.h:268
ProgressCallback progressCallback
callback to report algorithm progress and cancel it by user request
Definition MRMesh/MRMeshDecimate.h:299
int finalRelaxIters
Definition MRMesh/MRMeshDecimate.h:274
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:297
bool packMesh
whether to pack mesh at the end
Definition MRMesh/MRMeshDecimate.h:283
UndirectedEdgeBitSet * notFlippable
Definition MRMesh/MRMeshDecimate.h:281
Definition MRMesh/MRMeshDecimate.h:225
float maxAngleChange
Permit edge flips if it does not change dihedral angle more than on this value.
Definition MRMesh/MRMeshDecimate.h:233
float maxDeviation
maximum permitted deviation from the original surface
Definition MRMesh/MRMeshDecimate.h:227
FaceBitSet * region
degenerations will be fixed only in given region, which is updated during the processing
Definition MRMesh/MRMeshDecimate.h:244
float criticalAspectRatio
Definition MRMesh/MRMeshDecimate.h:237
float tinyEdgeLength
edges not longer than this value will be collapsed ignoring normals and aspect ratio checks
Definition MRMesh/MRMeshDecimate.h:230
float stabilizer
Definition MRMesh/MRMeshDecimate.h:241