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-2024, 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 element normal",
52 false, 90, "floating point value");
53 cmd.add(angle_arg);
54 TCLAP::ValueArg<double> z("z", "z-component", "z component of the normal",
55 false, -1.0, "floating point value");
56 cmd.add(z);
57 TCLAP::ValueArg<double> y("y", "y-component", "y component of the normal",
58 false, 0, "floating point value");
59 cmd.add(y);
60 TCLAP::ValueArg<double> x("x", "x-component", "x component of the normal",
61 false, 0, "floating point value");
62 cmd.add(x);
63 TCLAP::ValueArg<std::string> mesh_out(
64 "o", "mesh-output-file",
65 "the name of the file the surface mesh should be written to", false, "",
66 "file name of output mesh");
67 cmd.add(mesh_out);
68 TCLAP::ValueArg<std::string> mesh_in(
69 "i", "mesh-input-file",
70 "the name of the file containing the input mesh", true, "",
71 "file name of input mesh");
72 cmd.add(mesh_in);
73 cmd.parse(argc, argv);
74
75 BaseLib::MPI::Setup mpi_setup(argc, argv);
76
77 std::unique_ptr<MeshLib::Mesh const> mesh(MeshLib::IO::readMeshFromFile(
78 mesh_in.getValue(), true /* compute_element_neighbors */));
79
80 if (!mesh)
81 {
82 ERR("Error reading mesh file.");
83 return EXIT_FAILURE;
84 }
85
86 if (mesh->getDimension() != 3)
87 {
88 ERR("Surfaces can currently only be extracted from 3D meshes.");
89 return EXIT_FAILURE;
90 }
91
92 INFO("Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
93 mesh->getNumberOfElements());
94
95 // extract surface
96 Eigen::Vector3d const dir({x.getValue(), y.getValue(), z.getValue()});
97 double const angle(angle_arg.getValue());
98 std::unique_ptr<MeshLib::Mesh> surface_mesh(
103
104 std::string out_fname(mesh_out.getValue());
105 if (out_fname.empty())
106 {
107 out_fname = BaseLib::dropFileExtension(mesh_in.getValue()) + "_sfc.vtu";
108 }
109
110 auto const data_mode =
111 use_ascii_arg.getValue() ? vtkXMLWriter::Ascii : vtkXMLWriter::Binary;
112 MeshLib::IO::writeVtu(*surface_mesh, out_fname, data_mode);
113
114 return EXIT_SUCCESS;
115}
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:188

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().