MeshLib C++ Docs
Loading...
Searching...
No Matches
Decimate overview

This chapter represents documentation about mesh decimation. More...

Classes

struct  MR::DecimateSettings
 Parameters structure for MR::decimateMesh. More...
struct  MR::DecimateResult
 Results of MR::decimateMesh. More...
struct  MR::ResolveMeshDegenSettings
struct  MR::RemeshSettings
struct  MR::DecimatePolylineSettings< V >
 Parameters structure for MR::decimatePolyline. More...

Enumerations

enum  MR::DecimateStrategy { MR::MinimizeError , MR::ShortestEdgeFirst }
 Defines the order of edge collapses inside Decimate algorithm. More...
enum class  MR::DecimatePartsMode { MR::DecimatePartsMode::PackedMesh , MR::DecimatePartsMode::AABBTree }
 Defines how decimation finds the parts of the mesh for parallel processing (DecimateSettings::subdivideParts > 1) More...

Functions

DecimateResult MR::decimateMesh (Mesh &mesh, const DecimateSettings &settings={})
 Performs mesh simplification in mesh region according to the settings.
DecimateResult MR::decimateObjectMeshData (ObjectMeshData &data, const DecimateSettings &settings)
std::optional< ObjectMeshData > MR::makeDecimatedObjectMeshData (const ObjectMesh &obj, const DecimateSettings &settings, DecimateResult *outRes=nullptr)
 returns the data of decimated mesh given ObjectMesh (which remains unchanged) and decimation parameters
QuadraticForm3f MR::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.
Vector< QuadraticForm3f, VertId > MR::computeFormsAtVertices (const MeshPart &mp, float stabilizer, bool angleWeigted, const UndirectedEdgeBitSet *creases=nullptr)
 Computes quadratic forms at every vertex of mesh part before decimation.
FaceBitSet MR::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 these bits because they do not share any block with other parts
bool MR::resolveMeshDegenerations (Mesh &mesh, const ResolveMeshDegenSettings &settings={})
 Removes degenerate triangles in a mesh by calling decimateMesh function with appropriate settings.
bool MR::remesh (Mesh &mesh, const RemeshSettings &settings)
 Splits too long and eliminates too short edges from the mesh.
DecimatePolylineResult MR::decimatePolyline (Polyline2 &polyline, const DecimatePolylineSettings2 &settings={})
 Collapse edges in the polyline according to the settings.
DecimatePolylineResult MR::decimateContour (Contour2f &contour, const DecimatePolylineSettings2 &settings={})
 Collapse edges in the contour according to the settings.

Detailed Description

This chapter represents documentation about mesh decimation.

Enumeration Type Documentation

◆ DecimatePartsMode

enum class MR::DecimatePartsMode
strong

#include <MRMesh/MRMeshDecimate.h>

Defines how decimation finds the parts of the mesh for parallel processing (DecimateSettings::subdivideParts > 1)

Enumerator
PackedMesh 

the mesh is already packed optimally (e.g. by mesh.packOptimally()), and the parts are ranges of face ids

AABBTree 

the parts are subtrees of mesh's AABB tree (taken from the mesh if present, otherwise constructed), no packing is needed; the number of parts is rounded up to a power of two

◆ DecimateStrategy

#include <MRMesh/MRMeshDecimate.h>

Defines the order of edge collapses inside Decimate algorithm.

Enumerator
MinimizeError 

the next edge to collapse will be the one that introduced minimal error to the surface

ShortestEdgeFirst 

the next edge to collapse will be the shortest one

Function Documentation

◆ computeFormAtVertex()

QuadraticForm3f MR::computeFormAtVertex ( const MeshPart & mp,
VertId v,
float stabilizer,
bool angleWeigted,
const UndirectedEdgeBitSet * creases = nullptr )
nodiscard

#include <MRMesh/MRMeshDecimate.h>

Computes quadratic form at given vertex of the initial surface before decimation.

◆ computeFormsAtVertices()

Vector< QuadraticForm3f, VertId > MR::computeFormsAtVertices ( const MeshPart & mp,
float stabilizer,
bool angleWeigted,
const UndirectedEdgeBitSet * creases = nullptr )
nodiscard

#include <MRMesh/MRMeshDecimate.h>

Computes quadratic forms at every vertex of mesh part before decimation.

◆ decimateContour()

DecimatePolylineResult MR::decimateContour ( Contour2f & contour,
const DecimatePolylineSettings2 & settings = {} )

#include <MRMesh/MRPolylineDecimate.h>

Collapse edges in the contour according to the settings.

◆ decimateMesh()

DecimateResult MR::decimateMesh ( Mesh & mesh,
const DecimateSettings & settings = {} )

#include <MRMesh/MRMeshDecimate.h>

Performs mesh simplification in mesh region according to the settings.

A closed tetrahedron is never collapsed in two triangles lying on each other: it is removed completely if its four vertices can be collapsed in one point within maxError (for ShortestEdgeFirst: none of its edges is longer than maxError), and preCollapse, the limits on deleted faces and vertices, region, fixed boundary vertices, notFlippable and edgesToCollapse permit it; otherwise it is kept whole.

// Repack mesh optimally without building an AABB tree, which decimation invalidates anyway.
// It's not necessary but highly recommended to achieve the best performance in parallel processing
mesh.packOptimally( false );
// Setup decimate parameters
// Decimation stop thresholds, you may specify one or both
settings.maxDeletedFaces = 1000; // Number of faces to be deleted
settings.maxError = 0.05f; // Maximum error when decimation stops
// Number of parts for parallel processing, greatly improves performance at the cost of minor quality loss.
// 16 is a good choice even with fewer CPU cores, since smaller parts are processed faster; much larger values add per-part overhead
settings.subdivideParts = 16;
// Decimate mesh
MR::decimateMesh( mesh, settings );
Before
After

◆ decimateObjectMeshData()

DecimateResult MR::decimateObjectMeshData ( ObjectMeshData & data,
const DecimateSettings & settings )

#include <MRMesh/MRMeshDecimate.h>

Performs mesh simplification with per-element attributes according to given settings;

settings.region limits the simplification like in decimateMesh (whole mesh if null), and face selection is not used as a region; the attributes without values for some mesh elements are padded with default values (see resizeAttributesToMesh)

◆ decimatePolyline()

DecimatePolylineResult MR::decimatePolyline ( Polyline2 & polyline,
const DecimatePolylineSettings2 & settings = {} )

#include <MRMesh/MRPolylineDecimate.h>

Collapse edges in the polyline according to the settings.

◆ getSubdividePart()

FaceBitSet MR::getSubdividePart ( const FaceBitSet & valids,
size_t subdivideParts,
size_t myPart )
nodiscard

#include <MRMesh/MRMeshDecimate.h>

returns given subdivision part of all valid faces; parallel threads shall be able to safely modify these bits because they do not share any block with other parts

◆ makeDecimatedObjectMeshData()

std::optional< ObjectMeshData > MR::makeDecimatedObjectMeshData ( const ObjectMesh & obj,
const DecimateSettings & settings,
DecimateResult * outRes = nullptr )
nodiscard

#include <MRMesh/MRMeshDecimate.h>

returns the data of decimated mesh given ObjectMesh (which remains unchanged) and decimation parameters

◆ remesh()

bool MR::remesh ( Mesh & mesh,
const RemeshSettings & settings )

#include <MRMesh/MRMeshDecimate.h>

Splits too long and eliminates too short edges from the mesh.

◆ resolveMeshDegenerations()

bool MR::resolveMeshDegenerations ( Mesh & mesh,
const ResolveMeshDegenSettings & settings = {} )

#include <MRMesh/MRMeshDecimate.h>

Removes degenerate triangles in a mesh by calling decimateMesh function with appropriate settings.

consider using fixMeshDegeneracies for more complex cases

Returns
true if the mesh has been changed
See also
decimateMesh