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