Saving an MMG mesh
Write and reload geometry together with MMG feature metadata.
Geometry and remeshing features
MMG::Mesh extends the local geometry mesh with corner, ridge and required entity sets. These labels carry remeshing constraints in addition to the mesh's ordinary region and boundary attributes.
Construct and mark the mesh
The example scales an eight-by-eight vertex grid to the unit square and marks its four corners. Vertex zero is also marked as required. Boundary incidence is prepared before any facet queries.
constexpr size_t nodes = 8; MMG::Mesh mesh; mesh = Mesh().UniformGrid(Polytope::Type::Triangle, {nodes, nodes}); mesh.scale(1.0 / (nodes - 1)); mesh.getConnectivity().compute(1, 2); mesh.setCorner(0); mesh.setCorner(nodes - 1); mesh.setCorner(nodes * (nodes - 1)); mesh.setCorner(nodes * nodes - 1); mesh.setRequiredVertex(0);
Save the metadata
MEDIT represents MMG features through dedicated sections. Required vertices, edges, triangles and tetrahedra are written as their corresponding RequiredVertices, RequiredEdges, RequiredTriangles and RequiredTetrahedra sections when those sets are populated.
Reload and compare
The format argument selects the MEDIT reader explicitly. A second write makes the loaded representation available for inspection.
mesh.save("MMG.medit.mesh", IO::FileFormat::MEDIT); MMG::Mesh loaded; loaded.load("MMG.medit.mesh", IO::FileFormat::MEDIT); loaded.save("MMG.copy.medit.mesh", IO::FileFormat::MEDIT);
The program compares mesh counts and the marked corner/required-vertex metadata. Preservation during a subsequent remeshing or level-set cut is covered separately by MMG behavior and guarantees.
Build and run
Build MeshIO and run it from a scratch directory. It writes MMG.medit.mesh and MMG.copy.medit.mesh; the expected mesh has 64 vertices and 98 triangles.
The complete program is available in MeshIO.cpp.