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/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 "MeshLib/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 28 of file ExtractSurface.cpp.

29 {
30  TCLAP::CmdLine cmd(
31  "Extracts a 2D surface from a 3D input mesh by specifying a normal "
32  "vector and an angle. (The surface normal (0, 0, 0) will extract the "
33  "complete outer boundary of the 3D mesh.)\n"
34  "An extensive documentation can be found at "
35  "https://docs.opengeosys.org/docs/tools/meshing-submeshes/"
36  "extract-surface\n"
37  "OpenGeoSys-6 software, version " +
39  ".\n"
40  "Copyright (c) 2012-2021, OpenGeoSys Community "
41  "(http://www.opengeosys.org)",
43  TCLAP::SwitchArg use_ascii_arg("", "ascii-output",
44  "If the switch is set use ascii instead of "
45  "binary format for data in the vtu output.",
46  false);
47  cmd.add(use_ascii_arg);
48  TCLAP::ValueArg<std::string> face_prop_name(
49  "f", "face-property-name",
50  "the name of the data array the surface face id of the subsurface/bulk "
51  "element will be stored to",
52  false, "bulk_face_ids", "string");
53  cmd.add(face_prop_name);
54  TCLAP::ValueArg<std::string> element_prop_name(
55  "e", "element-property-name",
56  "the name of the data array the subsurface/bulk element id will be "
57  "stored to",
58  false, "bulk_element_ids", "string");
59  cmd.add(element_prop_name);
60  TCLAP::ValueArg<std::string> node_prop_name(
61  "n", "node-property-name",
62  "the name of the data array the subsurface/bulk node id will be stored "
63  "to",
64  false, "bulk_node_ids", "string");
65  cmd.add(node_prop_name);
66  TCLAP::ValueArg<double> angle_arg(
67  "a", "angle",
68  "tolerated angle (in degrees) between given normal and element normal",
69  false, 90, "floating point value");
70  cmd.add(angle_arg);
71  TCLAP::ValueArg<double> z("z", "z-component", "z component of the normal",
72  false, -1.0, "floating point value");
73  cmd.add(z);
74  TCLAP::ValueArg<double> y("y", "y-component", "y component of the normal",
75  false, 0, "floating point value");
76  cmd.add(y);
77  TCLAP::ValueArg<double> x("x", "x-component", "x component of the normal",
78  false, 0, "floating point value");
79  cmd.add(x);
80  TCLAP::ValueArg<std::string> mesh_out(
81  "o", "mesh-output-file",
82  "the name of the file the surface mesh should be written to", false, "",
83  "file name of output mesh");
84  cmd.add(mesh_out);
85  TCLAP::ValueArg<std::string> mesh_in(
86  "i", "mesh-input-file",
87  "the name of the file containing the input mesh", true, "",
88  "file name of input mesh");
89  cmd.add(mesh_in);
90  cmd.parse(argc, argv);
91 
92  std::unique_ptr<MeshLib::Mesh const> mesh(
93  MeshLib::IO::readMeshFromFile(mesh_in.getValue()));
94 
95  if (!mesh)
96  {
97  ERR("Error reading mesh file.");
98  return EXIT_FAILURE;
99  }
100 
101  if (mesh->getDimension() != 3)
102  {
103  ERR("Surfaces can currently only be extracted from 3D meshes.");
104  return EXIT_FAILURE;
105  }
106 
107  INFO("Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
108  mesh->getNumberOfElements());
109 
110  // extract surface
111  Eigen::Vector3d const dir({x.getValue(), y.getValue(), z.getValue()});
112  double const angle(angle_arg.getValue());
113  std::unique_ptr<MeshLib::Mesh> surface_mesh(
115  *mesh, dir, angle, node_prop_name.getValue(),
116  element_prop_name.getValue(), face_prop_name.getValue()));
117 
118  std::string out_fname(mesh_out.getValue());
119  if (out_fname.empty())
120  {
121  out_fname = BaseLib::dropFileExtension(mesh_in.getValue()) + "_sfc.vtu";
122  }
123 
124  auto const data_mode =
125  use_ascii_arg.getValue() ? vtkXMLWriter::Ascii : vtkXMLWriter::Binary;
126  MeshLib::IO::writeVtu(*surface_mesh, out_fname, data_mode);
127 
128  return EXIT_SUCCESS;
129 }
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
static MeshLib::Mesh * getMeshSurface(const MeshLib::Mesh &subsfc_mesh, Eigen::Vector3d const &dir, double angle, std::string const &subsfc_node_id_prop_name="", std::string const &subsfc_element_id_prop_name="", std::string const &face_id_prop_name="")
std::string dropFileExtension(std::string const &filename)
Definition: FileTools.cpp:169
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)

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