OGS
GocadTSurfaceReader.cpp
Go to the documentation of this file.
1
10#include <tclap/CmdLine.h>
11
13#include "BaseLib/MPI.h"
14#include "InfoLib/GitInfo.h"
16#include "MeshLib/Mesh.h"
17
18std::string getDelim(std::string const& str)
19{
20 std::size_t const bslash = str.find_first_of('\\');
21 char const delim = (bslash == std::string::npos) ? '/' : '\\';
22 return (str.back() == delim) ? "" : std::string(1, delim);
23}
24
25int main(int argc, char* argv[])
26{
27 TCLAP::CmdLine cmd(
28 "Reads Gocad ascii files (*.ts, *.pl, *.mx) and writes TSurf- and PLine"
29 "data into one or more VTU unstructured grids.\n\n"
30 "OpenGeoSys-6 software, version " +
32 ".\n"
33 "Copyright (c) 2012-2024, OpenGeoSys Community "
34 "(http://www.opengeosys.org)",
36
37 TCLAP::SwitchArg write_binary_arg(
38 "b", "write-binary",
39 "if set, OGS-Meshes will be written in binary format");
40 cmd.add(write_binary_arg);
41
42 TCLAP::SwitchArg export_surfaces_arg(
43 "s", "surfaces-only",
44 "if set, only TSurf datasets will be parsed from the input file");
45 cmd.add(export_surfaces_arg);
46
47 TCLAP::SwitchArg export_lines_arg(
48 "l", "lines-only",
49 "if set, only PLine datasets will be parsed from the input file");
50 cmd.add(export_lines_arg);
51
52 TCLAP::ValueArg<std::string> output_arg(
53 "o", "output-dir", "output directory", true, "", "output dir");
54 cmd.add(output_arg);
55
56 TCLAP::ValueArg<std::string> input_arg(
57 "i", "input-file",
58 "Gocad triangular surfaces file (*.ts). Provide a file with unix file "
59 "endings under unix. Use dos2unix to convert. ",
60 true, "", "filename.ts");
61 cmd.add(input_arg);
62
63 cmd.parse(argc, argv);
64
65 BaseLib::MPI::Setup mpi_setup(argc, argv);
66
67 if (export_lines_arg.isSet() && export_surfaces_arg.isSet())
68 {
69 ERR("Both the 'lines-only'-flag and 'surfaces-only'-flag are set. Only "
70 "one is allowed at a time.");
71 return 2;
72 }
73
74 std::string const file_name(input_arg.getValue());
75
77 if (export_lines_arg.isSet())
78 {
80 }
81 if (export_surfaces_arg.isSet())
82 {
84 }
85 std::vector<std::unique_ptr<MeshLib::Mesh>> meshes;
86 if (!FileIO::Gocad::GocadAsciiReader::readFile(file_name, meshes, t))
87 {
88 ERR("Error reading file.");
89 return 1;
90 }
91 INFO("{:d} meshes found.", meshes.size());
92 std::string const dir = output_arg.getValue();
93 bool const write_binary = write_binary_arg.getValue();
94 std::string const delim = getDelim(dir);
95 for (auto& mesh : meshes)
96 {
97 if (mesh == nullptr)
98 {
99 continue;
100 }
101 INFO("Writing mesh \"{:s}\"", mesh->getName());
102 int data_mode = (write_binary) ? 2 : 0;
103 bool compressed = (write_binary);
104 MeshLib::IO::VtuInterface vtu(mesh.get(), data_mode, compressed);
105 vtu.writeToFile(dir + delim + mesh->getName() + ".vtu");
106 }
107 return 0;
108}
Git information.
int main(int argc, char *argv[])
std::string getDelim(std::string const &str)
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
Definition of the Mesh class.
Implementation of the VtuInterface class.
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
bool writeToFile(std::filesystem::path const &file_path)
bool readFile(std::string const &file_name, std::vector< std::unique_ptr< MeshLib::Mesh > > &meshes, DataType const export_type)
Reads the specified file and writes data into internal mesh vector.
GITINFOLIB_EXPORT const std::string ogs_version