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