#include <MRCMesh/MRPointsLoad.h>
#include <MRCMesh/MRMeshSave.h>
#include <MRCMesh/MRPointCloudRadius.h>
#include <MRCMesh/MRPointCloud.h>
#include <MRCMesh/MRBox.h>
#include <MRCVoxels/MRPointsToMeshFusion.h>
#include <MRCMisc/expected_MR_Mesh_std_string.h>
#include <MRCMisc/expected_MR_PointCloud_std_string.h>
#include <MRCMisc/expected_void_std_string.h>
#include <MRCMisc/std_string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
{
int rc = EXIT_FAILURE;
MR_expected_MR_PointCloud_std_string* loadRes = MR_PointsLoad_fromAnySupportedFormat( "Points.ply", NULL, NULL );
MR_PointCloud* pc = MR_expected_MR_PointCloud_std_string_value_mut( loadRes );
if ( !pc )
{
fprintf( stderr, "Failed to load points: %s\n", MR_std_string_data( MR_expected_MR_PointCloud_std_string_error( loadRes ) ) );
goto fail_load;
}
MR_PointsToMeshParameters* params = MR_PointsToMeshParameters_DefaultConstruct();
MR_Box3f
box = MR_PointCloud_computeBoundingBox( pc, NULL );
MR_PointsToMeshParameters_Set_voxelSize( params,
voxelSize );
MR_PointsToMeshParameters_Set_sigma( params, fmaxf(
voxelSize, MR_findAvgPointsRadius( pc, 50, NULL ) ) );
MR_PointsToMeshParameters_Set_minWeight( params, 1.0f );
MR_expected_MR_Mesh_std_string* fusionRes = MR_pointsToMeshFusion( pc, params );
MR_Mesh*
mesh = MR_expected_MR_Mesh_std_string_value_mut( fusionRes );
{
fprintf( stderr, "Failed to fuse points: %s\n", MR_std_string_data( MR_expected_MR_Mesh_std_string_error( fusionRes ) ) );
goto fail_fuse;
}
MR_expected_void_std_string* saveEx = MR_MeshSave_toAnySupportedFormat(
mesh,
"Mesh.ctm", 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_fuse:
MR_expected_MR_Mesh_std_string_Destroy( fusionRes );
MR_PointsToMeshParameters_Destroy( params );
fail_load:
MR_expected_MR_PointCloud_std_string_Destroy( loadRes );
return rc;
}
const Vector3f & voxelSize() const
const BoxT & box(NodeId n) const
const std::shared_ptr< const Mesh > & mesh() const