OGS
GocadTSurfaceReader.cpp File Reference

Detailed Description

Definition in file GocadTSurfaceReader.cpp.

#include <tclap/CmdLine.h>
#include "Applications/FileIO/GocadIO/GocadAsciiReader.h"
#include "InfoLib/GitInfo.h"
#include "MeshLib/IO/VtkIO/VtuInterface.h"
#include "MeshLib/Mesh.h"
Include dependency graph for GocadTSurfaceReader.cpp:

Go to the source code of this file.

Functions

std::string getDelim (std::string const &str)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ getDelim()

std::string getDelim ( std::string const &  str)

Definition at line 17 of file GocadTSurfaceReader.cpp.

18 {
19  std::size_t const bslash = str.find_first_of('\\');
20  char const delim = (bslash == std::string::npos) ? '/' : '\\';
21  return (str.back() == delim) ? "" : std::string(1, delim);
22 }

Referenced by main().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 24 of file GocadTSurfaceReader.cpp.

25 {
26  TCLAP::CmdLine cmd(
27  "Reads Gocad ascii files (*.ts, *.pl, *.mx) and writes TSurf- and PLine"
28  "data into one or more VTU unstructured grids.\n\n"
29  "OpenGeoSys-6 software, version " +
31  ".\n"
32  "Copyright (c) 2012-2021, OpenGeoSys Community "
33  "(http://www.opengeosys.org)",
35 
36  TCLAP::SwitchArg write_binary_arg(
37  "b", "write-binary",
38  "if set, OGS-Meshes will be written in binary format");
39  cmd.add(write_binary_arg);
40 
41  TCLAP::SwitchArg export_surfaces_arg(
42  "s", "surfaces-only",
43  "if set, only TSurf datasets will be parsed from the input file");
44  cmd.add(export_surfaces_arg);
45 
46  TCLAP::SwitchArg export_lines_arg(
47  "l", "lines-only",
48  "if set, only PLine datasets will be parsed from the input file");
49  cmd.add(export_lines_arg);
50 
51  TCLAP::ValueArg<std::string> output_arg(
52  "o", "output-dir", "output directory", true, "", "output dir");
53  cmd.add(output_arg);
54 
55  TCLAP::ValueArg<std::string> input_arg(
56  "i", "input-file",
57  "Gocad triangular surfaces file (*.ts). Provide a file with unix file "
58  "endings under unix. Use dos2unix to convert. ",
59  true, "", "filename.ts");
60  cmd.add(input_arg);
61 
62  cmd.parse(argc, argv);
63 
64  if (export_lines_arg.isSet() && export_surfaces_arg.isSet())
65  {
66  ERR("Both the 'lines-only'-flag and 'surfaces-only'-flag are set. Only "
67  "one is allowed at a time.");
68  return 2;
69  }
70 
71  std::string const file_name(input_arg.getValue());
72 
74  if (export_lines_arg.isSet())
75  {
77  }
78  if (export_surfaces_arg.isSet())
79  {
81  }
82  std::vector<std::unique_ptr<MeshLib::Mesh>> meshes;
83  if (!FileIO::Gocad::GocadAsciiReader::readFile(file_name, meshes, t))
84  {
85  ERR("Error reading file.");
86  return 1;
87  }
88  INFO("{:d} meshes found.", meshes.size());
89  std::string const dir = output_arg.getValue();
90  bool const write_binary = write_binary_arg.getValue();
91  std::string const delim = getDelim(dir);
92  for (auto& mesh : meshes)
93  {
94  if (mesh == nullptr)
95  {
96  continue;
97  }
98  INFO("Writing mesh \"{:s}\"", mesh->getName());
99  int data_mode = (write_binary) ? 2 : 0;
100  bool compressed = (write_binary);
101  MeshLib::IO::VtuInterface vtu(mesh.get(), data_mode, compressed);
102  vtu.writeToFile(dir + delim + mesh->getName() + ".vtu");
103  }
104  return 0;
105 }
std::string getDelim(std::string const &str)
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
Definition: VtuInterface.h:38
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

References FileIO::Gocad::ALL, ERR(), getDelim(), INFO(), GitInfoLib::GitInfo::ogs_version, FileIO::Gocad::PLINE, FileIO::Gocad::GocadAsciiReader::readFile(), FileIO::Gocad::TSURF, and MeshLib::IO::VtuInterface::writeToFile().