OGS
ExtractSurface.cpp File Reference

Detailed Description

Extracts the surface from the given mesh.

Definition in file ExtractSurface.cpp.

#include <tclap/CmdLine.h>
#include <algorithm>
#include <memory>
#include <string>
#include <vector>
#include "BaseLib/FileTools.h"
#include "BaseLib/MPI.h"
#include "BaseLib/StringTools.h"
#include "InfoLib/GitInfo.h"
#include "MeshLib/IO/VtkIO/VtuInterface.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h"
#include "MeshToolsLib/MeshSurfaceExtraction.h"
Include dependency graph for ExtractSurface.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 29 of file ExtractSurface.cpp.

30{
31 TCLAP::CmdLine cmd(
32 "Extracts a 2D surface from a 3D input mesh by specifying a normal "
33 "vector and an angle. (The surface normal (0, 0, 0) will extract the "
34 "complete outer boundary of the 3D mesh.)\n"
35 "An extensive documentation can be found at "
36 "https://docs.opengeosys.org/docs/tools/meshing-submeshes/"
37 "extract-surface\n"
38 "OpenGeoSys-6 software, version " +
40 ".\n"
41 "Copyright (c) 2012-2025, OpenGeoSys Community "
42 "(http://www.opengeosys.org)",
44 TCLAP::SwitchArg use_ascii_arg("", "ascii-output",
45 "If the switch is set use ascii instead of "
46 "binary format for data in the vtu output.",
47 false);
48 cmd.add(use_ascii_arg);
49 TCLAP::ValueArg<double> angle_arg(
50 "a", "angle",
51 "tolerated angle (in degrees) between given normal and "
52 "element normal, (min = 0), (max = 360)",
53 false, 90, "ANGLE");
54 cmd.add(angle_arg);
55 TCLAP::ValueArg<double> z("z", "z-component", "z component of the normal",
56 false, -1.0, "Z-COMPONENT");
57 cmd.add(z);
58 TCLAP::ValueArg<double> y("y", "y-component", "y component of the normal",
59 false, 0, "Y-COMPONENT");
60 cmd.add(y);
61 TCLAP::ValueArg<double> x("x", "x-component", "x component of the normal",
62 false, 0, "X-COMPONENT");
63 cmd.add(x);
64 TCLAP::ValueArg<std::string> mesh_out(
65 "o", "mesh-output-file",
66 "Output (.vtu). The name of the file the surface mesh should be "
67 "written to",
68 false, "", "OUTPUT_FILE");
69 cmd.add(mesh_out);
70 TCLAP::ValueArg<std::string> mesh_in(
71 "i", "mesh-input-file",
72 "Input (.vtu). The name of the file containing the input mesh", true,
73 "", "INPUT_FILE");
74 cmd.add(mesh_in);
75 cmd.parse(argc, argv);
76
77 BaseLib::MPI::Setup mpi_setup(argc, argv);
78
79 std::unique_ptr<MeshLib::Mesh const> mesh(MeshLib::IO::readMeshFromFile(
80 mesh_in.getValue(), true /* compute_element_neighbors */));
81
82 if (!mesh)
83 {
84 ERR("Error reading mesh file.");
85 return EXIT_FAILURE;
86 }
87
88 if (mesh->getDimension() != 3)
89 {
90 ERR("Surfaces can currently only be extracted from 3D meshes.");
91 return EXIT_FAILURE;
92 }
93
94 INFO("Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
95 mesh->getNumberOfElements());
96
97 // extract surface
98 Eigen::Vector3d const dir({x.getValue(), y.getValue(), z.getValue()});
99 double const angle(angle_arg.getValue());
100 std::unique_ptr<MeshLib::Mesh> surface_mesh(
105
106 std::string out_fname(mesh_out.getValue());
107 if (out_fname.empty())
108 {
109 out_fname = BaseLib::dropFileExtension(mesh_in.getValue()) + "_sfc.vtu";
110 }
111
112 auto const data_mode =
113 use_ascii_arg.getValue() ? vtkXMLWriter::Ascii : vtkXMLWriter::Binary;
114 MeshLib::IO::writeVtu(*surface_mesh, out_fname, data_mode);
115
116 return EXIT_SUCCESS;
117}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
static MeshLib::Mesh * getMeshSurface(const MeshLib::Mesh &subsfc_mesh, Eigen::Vector3d const &dir, double angle, std::string_view subsfc_node_id_prop_name="", std::string_view subsfc_element_id_prop_name="", std::string_view face_id_prop_name="")
std::string dropFileExtension(std::string const &filename)
GITINFOLIB_EXPORT const std::string ogs_version
int writeVtu(MeshLib::Mesh const &mesh, std::string const &file_name, int const data_mode)
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
Definition Properties.h:191

References MeshLib::Cell, BaseLib::dropFileExtension(), ERR(), MeshLib::Face, MeshToolsLib::MeshSurfaceExtraction::getMeshSurface(), INFO(), MeshLib::Node, GitInfoLib::GitInfo::ogs_version, MeshLib::IO::readMeshFromFile(), and MeshLib::IO::writeVtu().