OGS
TIN2VTK.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
16// STL
17#include <memory>
18#include <string>
19#include <vector>
20
21// BaseLib
22#include "BaseLib/FileTools.h"
23#include "InfoLib/GitInfo.h"
24
25// GeoLib
27#include "GeoLib/Point.h"
28#include "GeoLib/PointVec.h"
29#include "GeoLib/Surface.h"
31
32// MeshLib
33#include "MeshLib/Mesh.h"
35
36int main(int argc, char* argv[])
37{
38 TCLAP::CmdLine cmd(
39 "Converts TIN file into VTU file.\n\n"
40 "OpenGeoSys-6 software, version " +
42 ".\n"
43 "Copyright (c) 2012-2024, OpenGeoSys Community "
44 "(http://www.opengeosys.org)",
46 TCLAP::ValueArg<std::string> inArg(
47 "i", "input-tin-file", "the name of the file containing the input TIN",
48 true, "", "string");
49 cmd.add(inArg);
50 TCLAP::ValueArg<std::string> outArg(
51 "o", "output-vtu-file",
52 "the name of the file the mesh will be written to", true, "", "string");
53 cmd.add(outArg);
54 cmd.parse(argc, argv);
55
56#ifdef USE_PETSC
57 MPI_Init(&argc, &argv);
58#endif
59
60 INFO("reading the TIN file...");
61 const std::string tinFileName(inArg.getValue());
62 std::string point_vec_name{"SurfacePoints"};
63 GeoLib::PointVec point_vec{point_vec_name, std::vector<GeoLib::Point*>{},
65 std::unique_ptr<GeoLib::Surface> sfc(
66 GeoLib::IO::TINInterface::readTIN(tinFileName, point_vec));
67 if (!sfc)
68 {
69#ifdef USE_PETSC
70 MPI_Finalize();
71#endif
72 return EXIT_FAILURE;
73 }
74 INFO("TIN read: {:d} points, {:d} triangles", point_vec.size(),
75 sfc->getNumberOfTriangles());
76
77 INFO("converting to mesh data");
78 std::unique_ptr<MeshLib::Mesh> mesh(MeshToolsLib::convertSurfaceToMesh(
80 std::numeric_limits<double>::epsilon()));
81 INFO("Mesh created: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
82 mesh->getNumberOfElements());
83
84 INFO("Write it into VTU");
85 MeshLib::IO::VtuInterface writer(mesh.get());
86 writer.writeToFile(outArg.getValue());
87
88#ifdef USE_PETSC
89 MPI_Finalize();
90#endif
91 return EXIT_SUCCESS;
92}
Filename manipulation routines.
Definition of the Point class.
Git information.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
Definition of the Mesh class.
Definition of the PointVec class.
int main(int argc, char *argv[])
Definition TIN2VTK.cpp:36
Implementation of the VtuInterface class.
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:36
std::map< std::string, std::size_t > NameIdMap
Definition TemplateVec.h:41
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
bool writeToFile(std::filesystem::path const &file_path)
Definition of mesh to geometry conversion.
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)