OGS
TIN2VTK.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include <tclap/CmdLine.h>
5
7
8// STL
9#include <memory>
10#include <string>
11#include <vector>
12
13#include "BaseLib/FileTools.h"
14#include "BaseLib/MPI.h"
15#include "InfoLib/GitInfo.h"
16
17// GeoLib
19#include "GeoLib/Point.h"
20#include "GeoLib/PointVec.h"
21#include "GeoLib/Surface.h"
23
24// MeshLib
25#include "BaseLib/Logging.h"
26#include "MeshLib/Mesh.h"
28
29int main(int argc, char* argv[])
30{
31 TCLAP::CmdLine cmd(
32 "Converts TIN file into VTU file.\n\n"
33 "OpenGeoSys-6 software, version " +
35 ".\n"
36 "Copyright (c) 2012-2026, OpenGeoSys Community "
37 "(http://www.opengeosys.org)",
39 TCLAP::ValueArg<std::string> inArg("i", "input-tin-file",
40 "Input (.tin). The name "
41 "of the input file "
42 "containing the input TIN ",
43 true, "", "INPUT_FILE");
44 cmd.add(inArg);
45 TCLAP::ValueArg<std::string> outArg(
46 "o", "output-vtu-file",
47 "Output (.vtu). The name of the output file "
48 "the mesh will be written to",
49 true, "", "OUTPUT_FILE");
50 cmd.add(outArg);
51 auto log_level_arg = BaseLib::makeLogLevelArg();
52 cmd.add(log_level_arg);
53 cmd.parse(argc, argv);
54
55 BaseLib::MPI::Setup mpi_setup(argc, argv);
56 BaseLib::initOGSLogger(log_level_arg.getValue());
57
58 INFO("reading the TIN file...");
59 const std::string tinFileName(inArg.getValue());
60 std::string point_vec_name{"SurfacePoints"};
61 GeoLib::PointVec point_vec{point_vec_name, std::vector<GeoLib::Point*>{},
63 std::unique_ptr<GeoLib::Surface> sfc(
64 GeoLib::IO::TINInterface::readTIN(tinFileName, point_vec));
65 if (!sfc)
66 {
67 return EXIT_FAILURE;
68 }
69 INFO("TIN read: {:d} points, {:d} triangles", point_vec.size(),
70 sfc->getNumberOfTriangles());
71
72 INFO("converting to mesh data");
73 std::unique_ptr<MeshLib::Mesh> mesh(MeshToolsLib::convertSurfaceToMesh(
75 std::numeric_limits<double>::epsilon()));
76 INFO("Mesh created: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
77 mesh->getNumberOfElements());
78
79 INFO("Write it into VTU");
80 MeshLib::IO::VtuInterface writer(mesh.get());
81 writer.writeToFile(outArg.getValue());
82
83 return EXIT_SUCCESS;
84}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
int main(int argc, char *argv[])
Definition TIN2VTK.cpp:29
static GeoLib::Surface * readTIN(std::string const &fname, GeoLib::PointVec &pnt_vec, std::vector< std::string > *errors=nullptr)
This class manages pointers to Points in a std::vector along with a name. It also handles the deletio...
Definition PointVec.h:25
std::map< std::string, std::size_t > NameIdMap
Definition TemplateVec.h:30
std::size_t size() const
Definition TemplateVec.h:88
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:56
std::string extractBaseNameWithoutExtension(std::string const &pathname)
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * convertSurfaceToMesh(const GeoLib::Surface &sfc, const std::string &mesh_name, double eps)