Mesh Oriented datABase  (version 5.6.0)
An array-based unstructured mesh library
DeleteEdges.cpp
Go to the documentation of this file.
1 /** @example DeleteEdges.cpp
2  * This example demonstrates edge deletion from a mesh.
3  * It shows how to load a mesh from a file,
4  * retrieve all edges (1D entities) from the mesh,
5  * delete all edges from the mesh,
6  * and write the modified mesh to a new file.
7  *
8  * The resulting mesh will have vertices and higher-dimensional entities
9  * (faces, volumes) but no edges, which can be useful for certain
10  * mesh processing workflows.
11  *
12  * To run: ./DeleteEdges [meshfile] [outfile]
13  */
14 
15 #include "moab/Core.hpp"
16 #include "moab/Range.hpp"
17 #include "moab/CN.hpp"
18 #include <iostream>
19 #include <memory>
20 
21 using namespace moab;
22 using namespace std;
23 
24 #ifndef MESH_DIR
25 #define MESH_DIR "."
26 #endif
27 
28 string test_file_name = string( MESH_DIR ) + string( "/hex01.vtk" );
29 string out_file = string( "outFile.h5m" );
30 
31 int main( int argc, char** argv )
32 {
33  if( argc == 1 )
34  {
35  std::cout << "Usage: " << argv[0] << " [meshfile] [outfile]\n";
36  return 0;
37  }
38  std::string mesh_file = ( argc > 1 ) ? argv[1] : std::string( MESH_DIR ) + "/hex01.vtk";
39  std::string out_file = ( argc > 2 ) ? argv[2] : "outFile.h5m";
40 
41  auto mb = std::make_unique< Core >();
42  if( !mb )
43  {
44  std::cerr << "Error: Could not allocate MOAB Core instance.\n";
45  return 1;
46  }
47  if( MB_SUCCESS != mb->load_mesh( mesh_file.c_str() ) )
48  {
49  std::cerr << "Error: Could not load mesh file '" << mesh_file << "'\n";
50  return 1;
51  }
52 
53  Range edges;
54  MB_CHK_ERR( mb->get_entities_by_dimension( 0, 1, edges ) );
55  MB_CHK_ERR( mb->delete_entities( edges ) );
56 
57  MB_CHK_SET_ERR( mb->write_file( out_file.c_str() ), "Error: Could not write output mesh file '" + out_file + "'" );
58  std::cout << "Deleted " << edges.size() << " edges. Output written to '" << out_file << "'.\n";
59  return 0;
60 }