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
11namespace MR
12{
20{
21 MinimizeError, // the next edge to collapse will be the one that introduced minimal error to the surface
22 ShortestEdgeFirst // the next edge to collapse will be the shortest one
23};
24
32struct DecimateSettings
33{
35
40 float maxError = FLT_MAX;
41
43 float maxEdgeLen = FLT_MAX;
44
46 float maxBdShift = FLT_MAX;
47
50
53 float criticalTriAspectRatio = FLT_MAX;
54
56 float tinyEdgeLength = -1;
57
60 float stabilizer = 0.001f;
61
65
68 bool optimizeVertexPos = true;
69
71 int maxDeletedVertices = INT_MAX;
72
74 int maxDeletedFaces = INT_MAX;
75
77 FaceBitSet * region = nullptr;
78
80 UndirectedEdgeBitSet* notFlippable = nullptr;
81
85
88 UndirectedEdgeBitSet * edgesToCollapse = nullptr;
89
93
95 bool touchNearBdEdges = true;
96
100 bool touchBdVerts = true;
101
105 VertBitSet * bdVerts = nullptr;
106
109 float maxAngleChange = -1;
110
118
127 std::function<void( UndirectedEdgeId ue, float & collapseErrorSq, Vector3f & collapsePos )> adjustCollapse;
128
131 std::function<void( EdgeId del, EdgeId rem )> onEdgeDel;
132
139
141 bool packMesh = false;
142
145
149
153
157 std::vector<FaceBitSet> * partFaces = nullptr;
158
161};
162
172struct DecimateResult
173{
174 int vertsDeleted = 0;
175 int facesDeleted = 0;
182 bool cancelled = true;
183};
184
194
199[[nodiscard]] MRMESH_API QuadraticForm3f computeFormAtVertex( const MeshPart & mp, VertId v, float stabilizer, bool angleWeigted, const UndirectedEdgeBitSet * creases = nullptr );
200
205[[nodiscard]] MRMESH_API Vector<QuadraticForm3f, VertId> computeFormsAtVertices( const MeshPart & mp, float stabilizer, bool angleWeigted, const UndirectedEdgeBitSet * creases = nullptr );
206
212[[nodiscard]] MRMESH_API FaceBitSet getSubdividePart( const FaceBitSet & valids, size_t subdivideParts, size_t myPart );
213
215{
217 float maxDeviation = 0;
218
220 float tinyEdgeLength = 0;
221
223 float maxAngleChange = PI_F / 3;
224
227 float criticalAspectRatio = 10000;
228
231 float stabilizer = 1e-6f;
232
234 FaceBitSet * region = nullptr;
235};
236
246
247
249{
252 float targetEdgeLen = 0.001f;
254 int maxEdgeSplits = 10'000'000;
256 float maxAngleChangeAfterFlip = 30 * PI_F / 180.0f;
258 float maxBdShift = FLT_MAX;
261 bool useCurvature = false;
268 FaceBitSet * region = nullptr;
271 UndirectedEdgeBitSet* notFlippable = nullptr;
273 bool packMesh = false;
278 std::function<void(EdgeId e1, EdgeId e)> onEdgeSplit;
280 std::function<void(EdgeId e, EdgeId e1)> onEdgeDel;
287 std::function<bool( EdgeId edgeToCollapse, const Vector3f& newEdgeOrgPos )> preCollapse;
290};
291// Splits too long and eliminates too short edges from the mesh
292MRMESH_API bool remesh( Mesh& mesh, const RemeshSettings & settings );
293
294} //namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:80
std::vector<T>-like container that requires specific indexing type,
Definition MRMesh/MRVector.h:19
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:728
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={})
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)
DecimateStrategy
Defines the order of edge collapses inside Decimate algorithm.
Definition MRMesh/MRMeshDecimate.h:20
@ MinimizeError
Definition MRMesh/MRMeshDecimate.h:21
@ ShortestEdgeFirst
Definition MRMesh/MRMeshDecimate.h:22
std::function< bool(EdgeId edgeToCollapse, const Vector3f &newEdgeOrgPos)> PreCollapseCallback
Definition MRMesh/MRMeshFwd.h:559
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:174
int facesDeleted
Definition MRMesh/MRMeshDecimate.h:175
float errorIntroduced
Definition MRMesh/MRMeshDecimate.h:180
bool cancelled
whether the algorithm was cancelled by the callback
Definition MRMesh/MRMeshDecimate.h:182
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:80
bool collapseNearNotFlippable
Definition MRMesh/MRMeshDecimate.h:84
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:127
bool angleWeightedDistToPlane
Definition MRMesh/MRMeshDecimate.h:64
bool packMesh
whether to pack mesh at the end
Definition MRMesh/MRMeshDecimate.h:141
int maxDeletedFaces
Limit on the number of deleted faces.
Definition MRMesh/MRMeshDecimate.h:74
PreCollapseCallback preCollapse
The user can provide this optional callback that is invoked immediately before edge collapse;.
Definition MRMesh/MRMeshDecimate.h:117
UndirectedEdgeHashMap * twinMap
Definition MRMesh/MRMeshDecimate.h:92
float maxBdShift
Maximal shift of a boundary during one edge collapse.
Definition MRMesh/MRMeshDecimate.h:46
float criticalTriAspectRatio
Definition MRMesh/MRMeshDecimate.h:53
bool decimateBetweenParts
Definition MRMesh/MRMeshDecimate.h:152
DecimateStrategy strategy
Definition MRMesh/MRMeshDecimate.h:34
int minFacesInPart
minimum number of faces in one subdivision part for ( subdivideParts > 1 ) mode
Definition MRMesh/MRMeshDecimate.h:160
std::vector< FaceBitSet > * partFaces
Definition MRMesh/MRMeshDecimate.h:157
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:138
int subdivideParts
Definition MRMesh/MRMeshDecimate.h:148
FaceBitSet * region
Region on mesh to be decimated, it is updated during the operation.
Definition MRMesh/MRMeshDecimate.h:77
ProgressCallback progressCallback
callback to report algorithm progress and cancel it by user request
Definition MRMesh/MRMeshDecimate.h:144
float stabilizer
Definition MRMesh/MRMeshDecimate.h:60
float maxError
Definition MRMesh/MRMeshDecimate.h:40
int maxDeletedVertices
Limit on the number of deleted vertices.
Definition MRMesh/MRMeshDecimate.h:71
VertBitSet * bdVerts
Definition MRMesh/MRMeshDecimate.h:105
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:56
bool optimizeVertexPos
Definition MRMesh/MRMeshDecimate.h:68
float maxEdgeLen
Maximal possible edge length created during decimation.
Definition MRMesh/MRMeshDecimate.h:43
UndirectedEdgeBitSet * edgesToCollapse
Definition MRMesh/MRMeshDecimate.h:88
bool touchNearBdEdges
Whether to allow collapsing or flipping edges having at least one vertex on (region) boundary.
Definition MRMesh/MRMeshDecimate.h:95
float maxAngleChange
Definition MRMesh/MRMeshDecimate.h:109
bool touchBdVerts
Definition MRMesh/MRMeshDecimate.h:100
float maxTriangleAspectRatio
Maximal possible aspect ratio of a triangle introduced during decimation.
Definition MRMesh/MRMeshDecimate.h:49
std::function< void(EdgeId del, EdgeId rem)> onEdgeDel
Definition MRMesh/MRMeshDecimate.h:131
Definition MRMesh/MRMesh.h:23
Definition MRMesh/MRMeshDecimate.h:249
bool finalRelaxNoShrinkage
if true prevents the surface from shrinkage after many iterations
Definition MRMesh/MRMeshDecimate.h:266
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:280
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:278
float targetEdgeLen
Definition MRMesh/MRMeshDecimate.h:252
int maxEdgeSplits
Maximum number of edge splits allowed during subdivision.
Definition MRMesh/MRMeshDecimate.h:254
bool useCurvature
Definition MRMesh/MRMeshDecimate.h:261
bool projectOnOriginalMesh
Definition MRMesh/MRMeshDecimate.h:276
float maxAngleChangeAfterFlip
Improves local mesh triangulation by doing edge flips if it does not change dihedral angle more than ...
Definition MRMesh/MRMeshDecimate.h:256
FaceBitSet * region
Region on mesh to be changed, it is updated during the operation.
Definition MRMesh/MRMeshDecimate.h:268
float maxBdShift
Maximal shift of a boundary during one edge collapse.
Definition MRMesh/MRMeshDecimate.h:258
ProgressCallback progressCallback
callback to report algorithm progress and cancel it by user request
Definition MRMesh/MRMeshDecimate.h:289
int finalRelaxIters
Definition MRMesh/MRMeshDecimate.h:264
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:287
bool packMesh
whether to pack mesh at the end
Definition MRMesh/MRMeshDecimate.h:273
UndirectedEdgeBitSet * notFlippable
Definition MRMesh/MRMeshDecimate.h:271
Definition MRMesh/MRMeshDecimate.h:215
float maxAngleChange
Permit edge flips if it does not change dihedral angle more than on this value.
Definition MRMesh/MRMeshDecimate.h:223
float maxDeviation
maximum permitted deviation from the original surface
Definition MRMesh/MRMeshDecimate.h:217
FaceBitSet * region
degenerations will be fixed only in given region, which is updated during the processing
Definition MRMesh/MRMeshDecimate.h:234
float criticalAspectRatio
Definition MRMesh/MRMeshDecimate.h:227
float tinyEdgeLength
edges not longer than this value will be collapsed ignoring normals and aspect ratio checks
Definition MRMesh/MRMeshDecimate.h:220
float stabilizer
Definition MRMesh/MRMeshDecimate.h:231