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

Function main

examples/cpp-examples/Triangulation.dox.cpp:10–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#include <iostream>
9
10int main()
11{
12 // Generate point cloud
13 MR::PointCloud pc;
14 pc.points.reserve( 10000 );
15 for ( auto i = 0; i < 100; ++i )
16 {
17 const auto u = MR::PI2_F * float( i ) / ( 100.f - 1.f );
18 for ( auto j = 0; j < 100; ++j )
19 {
20 const auto v = MR::PI_F * float( j ) / ( 100.f - 1.f );
21
22 pc.points.emplace_back(
23 std::cos( u ) * std::sin( v ),
24 std::sin( u ) * std::sin( v ),
25 std::cos( v )
26 );
27 }
28 }
29 // Remove duplicate points
30 auto vs = MR::pointUniformSampling( pc, {
31 .distance = 1e-3f,
32 } );
33 assert( vs );
34 pc.validPoints = std::move( *vs );
35 pc.invalidateCaches();
36
37 // Triangulate it
38 auto triangulated = MR::triangulatePointCloud( pc );
39 assert( triangulated );
40
41 // Fix possible issues
42 auto mesh = MR::offsetMesh( *triangulated, 0.f, { {
43 .voxelSize = MR::suggestVoxelSize( *triangulated, 5e+6f ),
44 } } );
45 assert( mesh );
46
47 // Save result
48 if ( auto saveRes = MR::MeshSave::toAnySupportedFormat( *mesh, "result.stl" ); !saveRes )
49 {
50 std::cerr << saveRes.error() << std::endl;
51 return 1;
52 }
53
54 return 0;
55}

Callers

nothing calls this directly

Calls 8

pointUniformSamplingFunction · 0.85
triangulatePointCloudFunction · 0.85
offsetMeshFunction · 0.85
suggestVoxelSizeFunction · 0.85
errorMethod · 0.80
toAnySupportedFormatFunction · 0.50
reserveMethod · 0.45
invalidateCachesMethod · 0.45

Tested by

no test coverage detected