#include <MRCMesh/MRMesh.h>
#include <MRCMesh/MRMeshFillHole.h>
#include <MRCMesh/MRMeshLoad.h>
#include <MRCMesh/MRMeshMetrics.h>
#include <MRCMesh/MRMeshSave.h>
#include <MRCMesh/MRMeshTopology.h>
#include <MRCMisc/expected_MR_Mesh_std_string.h>
#include <MRCMisc/expected_void_std_string.h>
#include <MRCMisc/std_string.h>
#include <MRCMisc/std_vector_MR_EdgeId.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
{
int rc = EXIT_FAILURE;
MR_expected_MR_Mesh_std_string* meshEx = MR_MeshLoad_fromAnySupportedFormat_2( "meshA.stl", NULL, NULL );
MR_Mesh* mesh = MR_expected_MR_Mesh_std_string_value_mut( meshEx );
if ( !mesh )
{
fprintf( stderr, "Failed to load mesh A: %s\n", MR_std_string_data( MR_expected_MR_Mesh_std_string_error( meshEx ) ) );
goto fail_mesh_loading_a;
}
MR_expected_MR_Mesh_std_string* mesh2Ex = MR_MeshLoad_fromAnySupportedFormat_2( "meshB.stl", NULL, NULL );
MR_Mesh* mesh2 = MR_expected_MR_Mesh_std_string_value_mut( mesh2Ex );
if ( !mesh2 )
{
fprintf( stderr, "Failed to load mesh B: %s\n", MR_std_string_data( MR_expected_MR_Mesh_std_string_error( mesh2Ex ) ) );
goto fail_mesh_loading_b;
}
MR_Mesh_addMesh_3( mesh, mesh2, NULL, NULL );
MR_std_vector_MR_EdgeId* edges = MR_MeshTopology_findHoleRepresentiveEdges( MR_Mesh_Get_topology( mesh ), NULL );
if ( MR_std_vector_MR_EdgeId_size( edges ) != 2 )
{
fprintf( stderr, "Expected exactly 2 holes to stitch, but found %" PRIu64 "\n", MR_std_vector_MR_EdgeId_size( edges ) );
goto fail_not_two_holes;
}
MR_StitchHolesParams* params = MR_StitchHolesParams_DefaultConstruct();
MR_FillHoleMetric* metric = MR_getUniversalMetric( mesh );
MR_StitchHolesParams_Set_metric( params, MR_PassBy_Move, metric );
MR_FillHoleMetric_Destroy( metric );
MR_buildCylinderBetweenTwoHoles_4( mesh, *MR_std_vector_MR_EdgeId_at( edges, 0 ), *MR_std_vector_MR_EdgeId_at( edges, 1 ), params );
MR_StitchHolesParams_Destroy( params );
MR_expected_void_std_string* saveEx = MR_MeshSave_toAnySupportedFormat_3( mesh, "MeshStitched.stl", NULL, NULL);
if ( MR_expected_void_std_string_error( saveEx ) )
{
fprintf( stderr, "Failed to save mesh: %s\n", MR_std_string_data( MR_expected_void_std_string_error( saveEx ) ) );
goto fail_save;
}
rc = EXIT_SUCCESS;
fail_save:
MR_expected_void_std_string_Destroy( saveEx );
fail_not_two_holes:
MR_std_vector_MR_EdgeId_Destroy( edges );
fail_mesh_loading_b:
MR_expected_MR_Mesh_std_string_Destroy( mesh2Ex );
fail_mesh_loading_a:
MR_expected_MR_Mesh_std_string_Destroy( meshEx );
return rc;
}