Skip to content

Commit 51648d0

Browse files
authored
Doc: Add code snippets from examples (#4497)
1 parent 11e0914 commit 51648d0

14 files changed

+29
-9
lines changed

examples/cpp-examples/FreeFormDeformation.dox.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ int main()
99
auto mesh = MR::MeshLoad::fromAnySupportedFormat( "mesh.stl" );
1010
assert( mesh );
1111

12-
// Compute mesh bounding box
13-
const auto box = mesh->computeBoundingBox();
14-
12+
//! [0]
1513
// Construct deformer on mesh vertices
1614
MR::FreeFormDeformer ffDeformer( mesh->points, mesh->topology.getValidVerts() );
1715

16+
// Compute mesh bounding box
17+
const auto box = mesh->computeBoundingBox();
18+
1819
// Init deformer with 3x3 grid on mesh box
1920
ffDeformer.init( MR::Vector3i::diagonal( 3 ), box );
2021

@@ -31,6 +32,7 @@ int main()
3132

3233
// Invalidate the mesh because of external vertex changes
3334
mesh->invalidateCaches();
35+
//! [0]
3436

3537
// Save deformed mesh
3638
MR::MeshSave::toAnySupportedFormat( *mesh, "deformed_mesh.stl" );

examples/cpp-examples/MeshBoolean.dox.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
int main()
99
{
10+
//! [0]
1011
// create first sphere with radius of 1 unit
1112
MR::Mesh sphere1 = MR::makeUVSphere( 1.0f, 64, 64 );
1213

@@ -17,10 +18,12 @@ int main()
1718

1819
// perform boolean operation
1920
MR::BooleanResult result = MR::boolean( sphere1, sphere2, MR::BooleanOperation::Intersection );
20-
MR::Mesh resultMesh = *result;
2121
if ( !result.valid() )
2222
std::cerr << result.errorString << std::endl;
2323

24+
MR::Mesh resultMesh = *result;
25+
//! [0]
26+
2427
// save result to STL file
2528
MR::MeshSave::toAnySupportedFormat( resultMesh, "out_boolean.stl" );
2629

examples/cpp-examples/MeshDecimate.dox.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ int main()
1010
// Load mesh
1111
MR::Mesh mesh = *MR::MeshLoad::fromAnySupportedFormat( "mesh.stl" );
1212

13+
//! [0]
1314
// Repack mesh optimally.
1415
// It's not necessary but highly recommended to achieve the best performance in parallel processing
1516
mesh.packOptimally();
@@ -27,6 +28,7 @@ int main()
2728

2829
// Decimate mesh
2930
MR::decimateMesh( mesh, settings );
31+
//! [0]
3032

3133
// Save result
3234
MR::MeshSave::toAnySupportedFormat( mesh, "decimated_mesh.stl" );

examples/cpp-examples/MeshICP.dox.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ int main()
1212
MR::Mesh meshFloating = *MR::MeshLoad::fromAnySupportedFormat( "meshA.stl" );
1313
MR::Mesh meshFixed = *MR::MeshLoad::fromAnySupportedFormat( "meshB.stl" );
1414

15+
//! [0]
1516
// Prepare ICP parameters
1617
float diagonal = meshFixed.getBoundingBox().diagonal();
1718
float icpSamplingVoxelSize = diagonal * 0.01f; // To sample points from object
@@ -30,6 +31,7 @@ int main()
3031

3132
// Transform floating mesh
3233
meshFloating.transform( xf );
34+
//! [0]
3335

3436
// Output information string
3537
std::string info = icp.getStatusInfo();

examples/cpp-examples/MeshModification.dox.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ int main()
1616
props.maxDeviationAfterFlip = 0.5f;
1717
MR::subdivideMesh( mesh, props );
1818

19+
//! [MeshTransform]
1920
// Rotate mesh
2021
MR::AffineXf3f rotationXf = MR::AffineXf3f::linear( MR::Matrix3f::rotation( MR::Vector3f::plusZ(), MR::PI_F * 0.5f ) );
2122
mesh.transform( rotationXf );
23+
//! [MeshTransform]
2224

2325
return 0;
2426
}

examples/cpp-examples/MeshOffset.dox.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ int main()
1212
// Create mesh
1313
MR::Mesh mesh = MR::makeCube();
1414

15+
//! [0]
1516
// Setup parameters
1617
MR::GeneralOffsetParameters params;
1718
// calculate voxel size depending on desired accuracy and/or memory consumption
@@ -22,6 +23,7 @@ int main()
2223
// Make offset mesh
2324
float offset = mesh.computeBoundingBox().diagonal() * 0.1f;
2425
auto meshRes = MR::generalOffsetMesh( mesh, offset, params );
26+
//! [0]
2527
if ( !meshRes.has_value() )
2628
{
2729
std::cerr << meshRes.error() << std::endl;

examples/cpp-examples/MeshStitchHole.dox.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ int main()
1313
MR::Mesh mesh = std::move( meshARes.value() );
1414
mesh.addMesh( meshBRes.value() );
1515

16+
//! [0]
1617
// Find holes (expect that there are exactly 2 holes)
1718
std::vector<MR::EdgeId> edges = mesh.topology.findHoleRepresentiveEdges();
1819
if ( edges.size() != 2 )
@@ -22,6 +23,7 @@ int main()
2223
MR::StitchHolesParams params;
2324
params.metric = MR::getUniversalMetric( mesh );
2425
MR::buildCylinderBetweenTwoHoles( mesh, edges.front(), edges.back(), params );
26+
//! [0]
2527

2628
// Save result
2729
auto saveRes = MR::MeshSave::toAnySupportedFormat( mesh, "stitchedMesh.stl" );

source/MRMesh/MRFreeFormDeformer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
namespace MR
99
{
10-
// Class for deforming mesh using Bernstein interpolation
10+
/// \brief Class for deforming mesh using Bernstein interpolation
11+
/// \snippet cpp-examples/FreeFormDeformation.dox.cpp 0
1112
class FreeFormDeformer
1213
{
1314
public:

source/MRMesh/MRICP.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ MRMESH_API void updatePointPairs( PointPairs& pairs,
167167

168168
/// This class allows you to register two object with similar shape using
169169
/// Iterative Closest Points (ICP) point-to-point or point-to-plane algorithms
170+
/// \snippet cpp-examples/MeshICP.dox.cpp 0
170171
class [[nodiscard]] ICP
171172
{
172173
public:

source/MRMesh/MRMesh.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ struct [[nodiscard]] Mesh
340340

341341
/// applies given transformation to specified vertices
342342
/// if region is nullptr, all valid mesh vertices are used
343+
/// \snippet cpp-examples/MeshModification.dox.cpp MeshTransform
343344
MRMESH_API void transform( const AffineXf3f& xf, const VertBitSet* region = nullptr );
344345

345346
/// creates new point and assigns given position to it

0 commit comments

Comments
 (0)