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
35{
37
42 float maxError = FLT_MAX;
43
45 float maxEdgeLen = FLT_MAX;
46
48 float maxBdShift = FLT_MAX;
49
52
55 float criticalTriAspectRatio = FLT_MAX;
56
58 float tinyEdgeLength = -1;
59
62 float stabilizer = 0.001f;
63
67
70 bool optimizeVertexPos = true;
71
73 int maxDeletedVertices = INT_MAX;
74
76 int maxDeletedFaces = INT_MAX;
77
79 FaceBitSet * region = nullptr;
80
82 UndirectedEdgeBitSet* notFlippable = nullptr;
83
87
90 UndirectedEdgeBitSet * edgesToCollapse = nullptr;
91
95
97 bool touchNearBdEdges = true;
98
102 bool touchBdVerts = true;
103
107 VertBitSet * bdVerts = nullptr;
108
111 float maxAngleChange = -1;
112
120
129 std::function<void( UndirectedEdgeId ue, float & collapseErrorSq, Vector3f & collapsePos )> adjustCollapse;
130
133 std::function<void( EdgeId del, EdgeId rem )> onEdgeDel;
134
141
143 bool packMesh = false;
144
147
151
155
159 std::vector<FaceBitSet> * partFaces = nullptr;
160
163};
164
175{
176 int vertsDeleted = 0;
177 int facesDeleted = 0;
184 bool cancelled = true;
185};
186
196
200
202[[nodiscard]] MRMESH_API std::optional<ObjectMeshData> makeDecimatedObjectMeshData( const ObjectMesh & obj, const DecimateSettings & settings,
203 DecimateResult * outRes = nullptr );
204
205
210[[nodiscard]] MRMESH_API QuadraticForm3f computeFormAtVertex( const MeshPart & mp, VertId v, float stabilizer, bool angleWeigted, const UndirectedEdgeBitSet * creases = nullptr );
211
216[[nodiscard]] MRMESH_API Vector<QuadraticForm3f, VertId> computeFormsAtVertices( const MeshPart & mp, float stabilizer, bool angleWeigted, const UndirectedEdgeBitSet * creases = nullptr );
217
223[[nodiscard]] MRMESH_API FaceBitSet getSubdividePart( const FaceBitSet & valids, size_t subdivideParts, size_t myPart );
224
226{
228 float maxDeviation = 0;
229
231 float tinyEdgeLength = 0;
232
234 float maxAngleChange = PI_F / 3;
235
238 float criticalAspectRatio = 10000;
239
242 float stabilizer = 1e-6f;
243
245 FaceBitSet * region = nullptr;
246};
247
257
258
260{
263 float targetEdgeLen = 0.001f;
265 int maxEdgeSplits = 10'000'000;
267 float maxAngleChangeAfterFlip = 30 * PI_F / 180.0f;
270 bool frozenBoundary = false;
273 float maxBdShift = FLT_MAX;
276 bool useCurvature = false;
287 FaceBitSet * region = nullptr;
290 UndirectedEdgeBitSet* notFlippable = nullptr;
292 bool packMesh = false;
297 std::function<void(EdgeId e1, EdgeId e)> onEdgeSplit;
299 std::function<void(EdgeId e, EdgeId e1)> onEdgeDel;
306 std::function<bool( EdgeId edgeToCollapse, const Vector3f& newEdgeOrgPos )> preCollapse;
309};
310
311MRMESH_API bool remesh( Mesh& mesh, const RemeshSettings & settings );
312
314
315}
#define MRMESH_API
Definition MRMeshFwd.h:80
Definition MRObjectMesh.h:14
std::vector<T>-like container that requires specific indexing type,
Definition MRVector.h:23
std::function< bool(float)> ProgressCallback
Definition MRMeshFwd.h:753
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.
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
std::function< bool(EdgeId edgeToCollapse, const Vector3f &newEdgeOrgPos)> PreCollapseCallback
Definition MRMeshFwd.h:573
HashMap< UndirectedEdgeId, UndirectedEdgeId > UndirectedEdgeHashMap
Definition MRMeshFwd.h:613
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Results of MR::decimateMesh.
Definition MRMeshDecimate.h:175
int vertsDeleted
Number deleted verts. Same as the number of performed collapses.
Definition MRMeshDecimate.h:176
int facesDeleted
Definition MRMeshDecimate.h:177
float errorIntroduced
Definition MRMeshDecimate.h:182
bool cancelled
whether the algorithm was cancelled by the callback
Definition MRMeshDecimate.h:184
Parameters structure for MR::decimateMesh.
Definition MRMeshDecimate.h:35
UndirectedEdgeBitSet * notFlippable
Edges specified by this bit-set will never be flipped, but they can be collapsed or replaced during c...
Definition MRMeshDecimate.h:82
bool collapseNearNotFlippable
Definition MRMeshDecimate.h:86
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:129
bool angleWeightedDistToPlane
Definition MRMeshDecimate.h:66
bool packMesh
whether to pack mesh at the end
Definition MRMeshDecimate.h:143
int maxDeletedFaces
Limit on the number of deleted faces.
Definition MRMeshDecimate.h:76
PreCollapseCallback preCollapse
The user can provide this optional callback that is invoked immediately before edge collapse;.
Definition MRMeshDecimate.h:119
UndirectedEdgeHashMap * twinMap
Definition MRMeshDecimate.h:94
float maxBdShift
Maximal shift of a boundary during one edge collapse.
Definition MRMeshDecimate.h:48
float criticalTriAspectRatio
Definition MRMeshDecimate.h:55
bool decimateBetweenParts
Definition MRMeshDecimate.h:154
DecimateStrategy strategy
Definition MRMeshDecimate.h:36
int minFacesInPart
minimum number of faces in one subdivision part for ( subdivideParts > 1 ) mode
Definition MRMeshDecimate.h:162
std::vector< FaceBitSet > * partFaces
Definition MRMeshDecimate.h:159
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:140
int subdivideParts
Definition MRMeshDecimate.h:150
FaceBitSet * region
Region on mesh to be decimated, it is updated during the operation.
Definition MRMeshDecimate.h:79
ProgressCallback progressCallback
callback to report algorithm progress and cancel it by user request
Definition MRMeshDecimate.h:146
float stabilizer
Definition MRMeshDecimate.h:62
float maxError
Definition MRMeshDecimate.h:42
int maxDeletedVertices
Limit on the number of deleted vertices.
Definition MRMeshDecimate.h:73
VertBitSet * bdVerts
Definition MRMeshDecimate.h:107
float tinyEdgeLength
edges not longer than this value will be collapsed even if it results in appearance of a triangle wit...
Definition MRMeshDecimate.h:58
bool optimizeVertexPos
Definition MRMeshDecimate.h:70
float maxEdgeLen
Maximal possible edge length created during decimation.
Definition MRMeshDecimate.h:45
UndirectedEdgeBitSet * edgesToCollapse
Definition MRMeshDecimate.h:90
bool touchNearBdEdges
Whether to allow collapsing or flipping edges having at least one vertex on (region) boundary.
Definition MRMeshDecimate.h:97
float maxAngleChange
Definition MRMeshDecimate.h:111
bool touchBdVerts
Definition MRMeshDecimate.h:102
float maxTriangleAspectRatio
Maximal possible aspect ratio of a triangle introduced during decimation.
Definition MRMeshDecimate.h:51
std::function< void(EdgeId del, EdgeId rem)> onEdgeDel
Definition MRMeshDecimate.h:133
Definition MRMesh.h:23
mesh and its per-element attributes for ObjectMeshHolder
Definition MRObjectMeshData.h:17
Definition MRMeshDecimate.h:260
bool finalRelaxNoShrinkage
if true prevents the surface from shrinkage after many iterations
Definition MRMeshDecimate.h:285
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:299
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:297
float targetEdgeLen
Definition MRMeshDecimate.h:263
int maxEdgeSplits
Maximum number of edge splits allowed during subdivision.
Definition MRMeshDecimate.h:265
bool useCurvature
Definition MRMeshDecimate.h:276
bool projectOnOriginalMesh
Definition MRMeshDecimate.h:295
float maxAngleChangeAfterFlip
Improves local mesh triangulation by doing edge flips if it does not change dihedral angle more than ...
Definition MRMeshDecimate.h:267
FaceBitSet * region
Region on mesh to be changed, it is updated during the operation.
Definition MRMeshDecimate.h:287
float maxBdShift
Definition MRMeshDecimate.h:273
ProgressCallback progressCallback
callback to report algorithm progress and cancel it by user request
Definition MRMeshDecimate.h:308
bool frozenBoundary
Definition MRMeshDecimate.h:270
int finalRelaxIters
Definition MRMeshDecimate.h:283
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:306
bool packMesh
whether to pack mesh at the end
Definition MRMeshDecimate.h:292
UndirectedEdgeBitSet * notFlippable
Definition MRMeshDecimate.h:290
float maxSplittableTriAspectRatio
Definition MRMeshDecimate.h:280
Definition MRMeshDecimate.h:226
float maxAngleChange
Permit edge flips if it does not change dihedral angle more than on this value.
Definition MRMeshDecimate.h:234
float maxDeviation
maximum permitted deviation from the original surface
Definition MRMeshDecimate.h:228
FaceBitSet * region
degenerations will be fixed only in given region, which is updated during the processing
Definition MRMeshDecimate.h:245
float criticalAspectRatio
Definition MRMeshDecimate.h:238
float tinyEdgeLength
edges not longer than this value will be collapsed ignoring normals and aspect ratio checks
Definition MRMeshDecimate.h:231
float stabilizer
Definition MRMeshDecimate.h:242