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

Function main

examples/cpp-examples/FreeFormDeformation.dox.cpp:8–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6#include <iostream>
7
8int main()
9{
10 // Load mesh
11 auto mesh = MR::MeshLoad::fromAnySupportedFormat( "mesh.stl" );
12 if ( !mesh.has_value() )
13 {
14 std::cerr << mesh.error() << std::endl;
15 return 1;
16 }
17
18//! [0]
19 // Construct deformer on mesh vertices
20 MR::FreeFormDeformer ffDeformer( mesh->points, mesh->topology.getValidVerts() );
21
22 // Compute mesh bounding box
23 const auto box = mesh->computeBoundingBox();
24
25 // Init deformer with 3x3 grid on mesh box
26 ffDeformer.init( MR::Vector3i::diagonal( 3 ), box );
27
28 // Move some control points of the grid to the center
29 ffDeformer.setRefGridPointPosition( { 1, 1, 0 }, box.center() );
30 ffDeformer.setRefGridPointPosition( { 1, 1, 2 }, box.center() );
31 ffDeformer.setRefGridPointPosition( { 0, 1, 1 }, box.center() );
32 ffDeformer.setRefGridPointPosition( { 2, 1, 1 }, box.center() );
33 ffDeformer.setRefGridPointPosition( { 1, 0, 1 }, box.center() );
34 ffDeformer.setRefGridPointPosition( { 1, 2, 1 }, box.center() );
35
36 // Apply the deformation to the mesh vertices
37 ffDeformer.apply();
38
39 // Invalidate the mesh because of external vertex changes
40 mesh->invalidateCaches();
41//! [0]
42
43 // Save deformed mesh
44 if ( auto saveRes = MR::MeshSave::toAnySupportedFormat( *mesh, "deformed_mesh.stl" ); !saveRes )
45 {
46 std::cerr << saveRes.error() << std::endl;
47 return 1;
48 }
49}

Callers

nothing calls this directly

Calls 10

diagonalFunction · 0.85
errorMethod · 0.80
fromAnySupportedFormatFunction · 0.50
toAnySupportedFormatFunction · 0.50
computeBoundingBoxMethod · 0.45
initMethod · 0.45
centerMethod · 0.45
applyMethod · 0.45
invalidateCachesMethod · 0.45

Tested by

no test coverage detected