MeshLib
 
Loading...
Searching...
No Matches
Filling holes

Example of filling holes

#include "MRMeshC/MRMesh.h"
#include <stdio.h>
#include <stdlib.h>
#define MIN_HOLE_AREA 100.f
int main( int argc, char* argv[] )
{
int rc = EXIT_FAILURE;
if ( argc != 2 && argc != 3 )
{
fprintf( stderr, "Usage: %s INPUT [OUTPUT]", argv[0] );
goto out;
}
const char* input = argv[1];
const char* output = ( argc == 2 ) ? argv[1] : argv[2];
// error messages will be stored here
MRString* errorString = NULL;
MRMesh* mesh = mrMeshLoadFromAnySupportedFormat( input, &errorString );
if ( errorString )
{
fprintf( stderr, "Failed to load mesh: %s", mrStringData( errorString ) );
mrStringFree( errorString );
goto out;
}
// get list of existing holes; each hole is represented by a single edge lying on the hole's border
if ( mrEdgePathSize( holes ) == 0 )
{
printf( "Mesh doesn't have any holes" );
goto out_holes;
}
// you can set various parameters for the fill hole process; see the documentation for more info
// think of a metric as a method to fill holes in a preferred way
// you can define one or choose from one of predefined metrics from MRMeshMetrics.h
params.metric = metric;
// optionally get the bitset of created faces
params.outNewFaces = newFaces;
// you can either fill all holes at once or one by one
// in the second case don't forget to check the output fields of params (e.g. outNewFaces) after every iteration
size_t newFaceCount = 0;
#define FILL_ALL_HOLES 1
#if FILL_ALL_HOLES
mrFillHoles( mesh, mrEdgePathData( holes ), mrEdgePathSize( holes ), &params );
newFaceCount = mrBitSetCount( newFaces );
#else
for ( int i = 0; i < mrEdgePathSize( holes ); i++ )
{
MREdgeId e = mrEdgePathData( holes )[i];
MRVector3f holeDirArea = mrMeshHoleDirArea( mesh, e );
if ( mrVector3Length( &holeDirArea ) >= MIN_HOLE_AREA )
{
mrFillHole( mesh, e, &params );
newFaceCount += mrBitSetCount( newFaces );
}
}
#endif
printf( "Added new %zu faces", newFaceCount );
mrMeshSaveToAnySupportedFormat( mesh, output, &errorString );
if ( errorString )
{
fprintf( stderr, "Failed to save mesh: %s", mrStringData( errorString ) );
mrStringFree( errorString );
goto out_newFaces;
}
rc = EXIT_SUCCESS;
out_newFaces:
mrFaceBitSetFree( newFaces );
out_metric:
out_holes:
mrEdgePathFree( holes );
out_mesh:
mrMeshFree( mesh );
out:
return rc;
}
MRMESHC_API size_t mrBitSetCount(const MRBitSet *bs)
returns the number of bits in this bitset that are set
MRMESHC_API void mrFaceBitSetFree(MRFaceBitSet *fbs)
deallocates a FaceBitSet object
MRMESHC_API MRFaceBitSet * mrFaceBitSetNew(void)
creates a new FaceBitSet object
MRMESHC_API void mrFillHole(MRMesh *mesh, MREdgeId a, const MRFillHoleParams *params)
Fills hole in mesh .
MRMESHC_API void mrFillHoles(MRMesh *mesh, const MREdgeId *as, size_t asNum, const MRFillHoleParams *params)
fill all holes given by their representative edges in
MRMESHC_API MRFillHoleParams mrFillHoleParamsNew(void)
struct MRMesh MRMesh
Definition MRMeshC/MRMeshFwd.h:42
MRBitSet MRFaceBitSet
Definition MRMeshC/MRMeshFwd.h:36
typedefMR_EXTERN_C_BEGIN struct MRString MRString
Definition MRMeshC/MRMeshFwd.h:32
struct MREdgePath MREdgePath
Definition MRMeshC/MRMeshFwd.h:46
MRMESHC_API MRFillHoleMetric * mrGetUniversalMetric(const MRMesh *mesh)
MRMESHC_API void mrFillHoleMetricFree(MRFillHoleMetric *metric)
MRMESHC_API void mrEdgePathFree(MREdgePath *ep)
deallocates the EdgePath object
MRMESHC_API const MREdgeId * mrEdgePathData(const MREdgePath *ep)
gets read-only access to the edges of the edge path
MRMESHC_API size_t mrEdgePathSize(const MREdgePath *ep)
gets total count of the edges of the edge path
MRMESHC_API MRVector3f mrMeshHoleDirArea(const MRMesh *mesh, MREdgeId e)
MRMESHC_API MREdgePath * mrMeshFindHoleRepresentiveEdges(const MRMesh *mesh)
MRMESHC_API void mrMeshFree(MRMesh *mesh)
deallocates a Mesh object
MRMESHC_API void mrStringFree(MRString *str)
deallocates the string object
MR_EXTERN_C_BEGIN MRMESHC_API const char * mrStringData(const MRString *str)
gets read-only access to the string data
MRMESHC_API float mrVector3Length(const MRVector3f *v)
length of the vector
MRMESHC_API MRMesh * mrMeshLoadFromAnySupportedFormat(const char *file, MRString **errorStr)
MRMESHC_API void mrMeshSaveToAnySupportedFormat(const MRMesh *mesh, const char *file, MRString **errorStr)
edge index
Definition MRMeshC/MRId.h:8
Holds metrics for mrFillHole and mrBuildCylinderBetweenTwoHoles triangulation .
Parameters structure for mrFillHole Structure has some options to control mrFillHole.
Definition MRMeshC/MRMeshFillHole.h:23
MRFaceBitSet * outNewFaces
If not nullptr accumulate new faces.
Definition MRMeshC/MRMeshFillHole.h:31
const MRFillHoleMetric * metric
Definition MRMeshC/MRMeshFillHole.h:28
three-dimensional vector
Definition MRMeshC/MRVector3.h:9