MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / main

Function main

examples/cpp-examples/NoiseDenoise.dox.cpp:10–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#include <iostream>
9
10int main()
11{
12 // Load mesh
13 auto loadRes = MR::MeshLoad::fromAnySupportedFormat( "mesh.stl" );
14 if ( !loadRes.has_value() )
15 {
16 std::cerr << loadRes.error() << std::endl;
17 return 1;
18 }
19 MR::Mesh& mesh = *loadRes;
20
21 // Add noise to the mesh
22 std::ignore = MR::addNoise( mesh.points, mesh.topology.getValidVerts(), {
23 .sigma = mesh.computeBoundingBox().diagonal() * 0.0001f,
24 } );
25
26 // Invalidate the mesh because of the external vertex changes
27 mesh.invalidateCaches();
28
29 // Save the noised mesh
30 if ( auto saveRes = MR::MeshSave::toAnySupportedFormat( mesh, "noised_mesh.stl" ); !saveRes )
31 {
32 std::cerr << saveRes.error() << std::endl;
33 return 1;
34 }
35
36 // Denoise the mesh with sharpening for sharp edges
37 // see the article "Mesh Denoising via a Novel Mumford-Shah Framework"
38 std::ignore = MR::meshDenoiseViaNormals( mesh );
39
40 // Save the denoised mesh
41 if ( auto saveRes = MR::MeshSave::toAnySupportedFormat( mesh, "denoised_mesh.stl" ); !saveRes )
42 {
43 std::cerr << saveRes.error() << std::endl;
44 return 1;
45 }
46}

Callers

nothing calls this directly

Calls 8

addNoiseFunction · 0.85
meshDenoiseViaNormalsFunction · 0.85
errorMethod · 0.80
fromAnySupportedFormatFunction · 0.50
toAnySupportedFormatFunction · 0.50
diagonalMethod · 0.45
computeBoundingBoxMethod · 0.45
invalidateCachesMethod · 0.45

Tested by

no test coverage detected