MeshLib C++ Docs
Loading...
Searching...
No Matches
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{
19
26
36
45{
47
52 float maxError = FLT_MAX;
53
55 float maxEdgeLen = FLT_MAX;
56
58 float maxBdShift = FLT_MAX;
59
62
65 float criticalTriAspectRatio = FLT_MAX;
66
69 bool preventNormalFlips = true;
70
72 float tinyEdgeLength = -1;
73
76 float stabilizer = 0.001f;
77
81
84 bool optimizeVertexPos = true;
85
87 int maxDeletedVertices = INT_MAX;
88
90 int maxDeletedFaces = INT_MAX;
91
93 FaceBitSet * region = nullptr;
94
96 UndirectedEdgeBitSet* notFlippable = nullptr;
97
101
104 UndirectedEdgeBitSet * edgesToCollapse = nullptr;
105
109
111 bool touchNearBdEdges = true;
112
116 bool touchBdVerts = true;
117
121 VertBitSet * bdVerts = nullptr;
122
125 const UndirectedEdgeBitSet * regionEdges = nullptr;
126
129 float maxAngleChange = -1;
130
138
147 std::function<void( UndirectedEdgeId ue, float & collapseErrorSq, Vector3f & collapsePos )> adjustCollapse;
148
151 std::function<void( EdgeId del, EdgeId rem )> onEdgeDel;
152
159
161 bool packMesh = false;
162
165
169
172
177
181 std::vector<FaceBitSet> * partFaces = nullptr;
182
185};
186
196{
197 int vertsDeleted = 0;
198 int facesDeleted = 0;
205 bool cancelled = true;
206};
207
221
226
228[[nodiscard]] MRMESH_API std::optional<ObjectMeshData> makeDecimatedObjectMeshData( const ObjectMesh & obj, const DecimateSettings & settings,
229 DecimateResult * outRes = nullptr );
230
231
236[[nodiscard]] MRMESH_API QuadraticForm3f computeFormAtVertex( const MeshPart & mp, VertId v, float stabilizer, bool angleWeigted, const UndirectedEdgeBitSet * creases = nullptr );
237
242[[nodiscard]] MRMESH_API Vector<QuadraticForm3f, VertId> computeFormsAtVertices( const MeshPart & mp, float stabilizer, bool angleWeigted, const UndirectedEdgeBitSet * creases = nullptr );
243
249[[nodiscard]] MRMESH_API FaceBitSet getSubdividePart( const FaceBitSet & valids, size_t subdivideParts, size_t myPart );
250
252{
254 float maxDeviation = 0;
255
257 float tinyEdgeLength = 0;
258
260 float maxAngleChange = PI_F / 3;
261
264 float criticalAspectRatio = 10000;
265
268 float stabilizer = 1e-6f;
269
271 FaceBitSet * region = nullptr;
272};
273
283
284
286{
289 float targetEdgeLen = 0.001f;
291 int maxEdgeSplits = 10'000'000;
293 float maxAngleChangeAfterFlip = 30 * PI_F / 180.0f;
296 bool frozenBoundary = false;
299 float maxBdShift = FLT_MAX;
302 bool useCurvature = false;
313 FaceBitSet * region = nullptr;
316 UndirectedEdgeBitSet* notFlippable = nullptr;
318 bool packMesh = false;
323 std::function<void(EdgeId e1, EdgeId e)> onEdgeSplit;
325 std::function<void(EdgeId e, EdgeId e1)> onEdgeDel;
332 std::function<bool( EdgeId edgeToCollapse, const Vector3f& newEdgeOrgPos )> preCollapse;
335};
336
337MRMESH_API bool remesh( Mesh& mesh, const RemeshSettings & settings );
338
340
341}
#define MRMESH_API
Definition MRMeshFwd.h:85
Definition MRAABBTree.h:41
Definition MRObjectMesh.h:14
Vector<T> is indexed by size_t.
Definition MRVector.h:24
std::function< bool(float)> ProgressCallback
Definition MRMeshFwd.h:790
DecimateStrategy
Defines the order of edge collapses inside Decimate algorithm.
Definition MRMeshDecimate.h:22
bool remesh(Mesh &mesh, const RemeshSettings &settings)
Splits too long and eliminates too short edges from the mesh.
DecimateResult decimateObjectMeshData(ObjectMeshData &data, const DecimateSettings &settings)
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.
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.
bool resolveMeshDegenerations(Mesh &mesh, const ResolveMeshDegenSettings &settings={})
Removes degenerate triangles in a mesh by calling decimateMesh function with appropriate settings.
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...
DecimateResult decimateMesh(Mesh &mesh, const DecimateSettings &settings={})
Performs mesh simplification in mesh region according to the settings.
DecimatePartsMode
Defines how decimation finds the parts of the mesh for parallel processing (DecimateSettings::subdivi...
Definition MRMeshDecimate.h:29
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...
@ MinimizeError
the next edge to collapse will be the one that introduced minimal error to the surface
Definition MRMeshDecimate.h:23
@ ShortestEdgeFirst
the next edge to collapse will be the shortest one
Definition MRMeshDecimate.h:24
@ PackedMesh
the mesh is already packed optimally (e.g. by mesh.packOptimally()), and the parts are ranges of face...
Definition MRMeshDecimate.h:31
std::function< bool(EdgeId edgeToCollapse, const Vector3f &newEdgeOrgPos)> PreCollapseCallback
Definition MRMeshFwd.h:596
HashMap< UndirectedEdgeId, UndirectedEdgeId > UndirectedEdgeHashMap
Definition MRMeshFwd.h:638
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
Results of MR::decimateMesh.
Definition MRMeshDecimate.h:196
int vertsDeleted
Number deleted verts. Same as the number of performed collapses.
Definition MRMeshDecimate.h:197
int facesDeleted
Definition MRMeshDecimate.h:198
float errorIntroduced
Definition MRMeshDecimate.h:203
bool cancelled
whether the algorithm was cancelled by the callback
Definition MRMeshDecimate.h:205
Parameters structure for MR::decimateMesh.
Definition MRMeshDecimate.h:45
UndirectedEdgeBitSet * notFlippable
Edges specified by this bit-set will never be flipped, but they can be collapsed or replaced during c...
Definition MRMeshDecimate.h:96
bool collapseNearNotFlippable
Definition MRMeshDecimate.h:100
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 MRMeshDecimate.h:147
bool angleWeightedDistToPlane
Definition MRMeshDecimate.h:80
bool packMesh
whether to pack mesh at the end
Definition MRMeshDecimate.h:161
int maxDeletedFaces
Limit on the number of deleted faces.
Definition MRMeshDecimate.h:90
PreCollapseCallback preCollapse
The user can provide this optional callback that is invoked immediately before edge collapse;.
Definition MRMeshDecimate.h:137
UndirectedEdgeHashMap * twinMap
Definition MRMeshDecimate.h:108
DecimatePartsMode partsMode
how the parts are found for subdivideParts > 1; ignored if partFaces is given
Definition MRMeshDecimate.h:171
float maxBdShift
Maximal shift of a boundary during one edge collapse.
Definition MRMeshDecimate.h:58
float criticalTriAspectRatio
Definition MRMeshDecimate.h:65
const UndirectedEdgeBitSet * regionEdges
Definition MRMeshDecimate.h:125
bool decimateBetweenParts
Definition MRMeshDecimate.h:176
DecimateStrategy strategy
Definition MRMeshDecimate.h:46
int minFacesInPart
minimum number of faces in one subdivision part for ( subdivideParts > 1 ) mode
Definition MRMeshDecimate.h:184
std::vector< FaceBitSet > * partFaces
Definition MRMeshDecimate.h:181
bool preventNormalFlips
Definition MRMeshDecimate.h:69
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 MRMeshDecimate.h:158
int subdivideParts
Definition MRMeshDecimate.h:168
FaceBitSet * region
Region on mesh to be decimated, it is updated during the operation.
Definition MRMeshDecimate.h:93
ProgressCallback progressCallback
callback to report algorithm progress and cancel it by user request
Definition MRMeshDecimate.h:164
float stabilizer
Definition MRMeshDecimate.h:76
float maxError
Definition MRMeshDecimate.h:52
int maxDeletedVertices
Limit on the number of deleted vertices.
Definition MRMeshDecimate.h:87
VertBitSet * bdVerts
Definition MRMeshDecimate.h:121
float tinyEdgeLength
edges not longer than this value will be collapsed even if it results in appearance of a triangle wit...
Definition MRMeshDecimate.h:72
bool optimizeVertexPos
Definition MRMeshDecimate.h:84
float maxEdgeLen
Maximal possible edge length created during decimation.
Definition MRMeshDecimate.h:55
UndirectedEdgeBitSet * edgesToCollapse
Definition MRMeshDecimate.h:104
bool touchNearBdEdges
Whether to allow collapsing or flipping edges having at least one vertex on (region) boundary.
Definition MRMeshDecimate.h:111
float maxAngleChange
Definition MRMeshDecimate.h:129
bool touchBdVerts
Definition MRMeshDecimate.h:116
float maxTriangleAspectRatio
Maximal possible aspect ratio of a triangle introduced during decimation.
Definition MRMeshDecimate.h:61
std::function< void(EdgeId del, EdgeId rem)> onEdgeDel
Definition MRMeshDecimate.h:151
Definition MRMesh.h:24
mesh and its per-element attributes for ObjectMeshHolder
Definition MRObjectMeshData.h:17
Definition MRMeshDecimate.h:286
bool finalRelaxNoShrinkage
if true prevents the surface from shrinkage after many iterations
Definition MRMeshDecimate.h:311
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 MRMeshDecimate.h:325
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 MRMeshDecimate.h:323
float targetEdgeLen
Definition MRMeshDecimate.h:289
int maxEdgeSplits
Maximum number of edge splits allowed during subdivision.
Definition MRMeshDecimate.h:291
bool useCurvature
Definition MRMeshDecimate.h:302
bool projectOnOriginalMesh
Definition MRMeshDecimate.h:321
float maxAngleChangeAfterFlip
Improves local mesh triangulation by doing edge flips if it does not change dihedral angle more than ...
Definition MRMeshDecimate.h:293
FaceBitSet * region
Region on mesh to be changed, it is updated during the operation.
Definition MRMeshDecimate.h:313
float maxBdShift
Definition MRMeshDecimate.h:299
ProgressCallback progressCallback
callback to report algorithm progress and cancel it by user request
Definition MRMeshDecimate.h:334
bool frozenBoundary
Definition MRMeshDecimate.h:296
int finalRelaxIters
Definition MRMeshDecimate.h:309
std::function< bool(EdgeId edgeToCollapse, const Vector3f &newEdgeOrgPos)> preCollapse
The user can provide this optional callback that is invoked immediately before edge collapse;.
Definition MRMeshDecimate.h:332
bool packMesh
whether to pack mesh at the end
Definition MRMeshDecimate.h:318
UndirectedEdgeBitSet * notFlippable
Definition MRMeshDecimate.h:316
float maxSplittableTriAspectRatio
Definition MRMeshDecimate.h:306
Definition MRMeshDecimate.h:252
float maxAngleChange
Permit edge flips if it does not change dihedral angle more than on this value.
Definition MRMeshDecimate.h:260
float maxDeviation
maximum permitted deviation from the original surface
Definition MRMeshDecimate.h:254
FaceBitSet * region
degenerations will be fixed only in given region, which is updated during the processing
Definition MRMeshDecimate.h:271
float criticalAspectRatio
Definition MRMeshDecimate.h:264
float tinyEdgeLength
edges not longer than this value will be collapsed ignoring normals and aspect ratio checks
Definition MRMeshDecimate.h:257
float stabilizer
Definition MRMeshDecimate.h:268