OGS
TIN2VTK.cpp
Go to the documentation of this file.
1
10#include <tclap/CmdLine.h>
11
12// STL
13#include <memory>
14#include <string>
15#include <vector>
16
17#include "BaseLib/FileTools.h"
18#include "BaseLib/MPI.h"
19#include "InfoLib/GitInfo.h"
20
21// GeoLib
23#include "GeoLib/Point.h"
24#include "GeoLib/PointVec.h"
25#include "GeoLib/Surface.h"
27
28// MeshLib
29#include "MeshLib/Mesh.h"
31
32int main(int argc, char* argv[])
33{
34 TCLAP::CmdLine cmd(
35 "Converts TIN file into VTU file.\n\n"
36 "OpenGeoSys-6 software, version " +
38 ".\n"
39 "Copyright (c) 2012-2024, OpenGeoSys Community "
40 "(http://www.opengeosys.org)",
42 TCLAP::ValueArg<std::string> inArg(
43 "i", "input-tin-file", "the name of the file containing the input TIN",
44 true, "", "string");
45 cmd.add(inArg);
46 TCLAP::ValueArg<std::string> outArg(
47 "o", "output-vtu-file",
48 "the name of the file the mesh will be written to", true, "", "string");
49 cmd.add(outArg);
50 cmd.parse(argc, argv);
51
52 BaseLib::MPI::Setup mpi_setup(argc, argv);
53
54 INFO("reading the TIN file...");
55 const std::string tinFileName(inArg.getValue());
56 std::string point_vec_name{"SurfacePoints"};
57 GeoLib::PointVec point_vec{point_vec_name, std::vector<GeoLib::Point*>{},
59 std::unique_ptr<GeoLib::Surface> sfc(
60 GeoLib::IO::TINInterface::readTIN(tinFileName, point_vec));
61 if (!sfc)
62 {
63 return EXIT_FAILURE;
64 }
65 INFO("TIN read: {:d} points, {:d} triangles", point_vec.size(),
66 sfc->getNumberOfTriangles());
67
68 INFO("converting to mesh data");
69 std::unique_ptr<MeshLib::Mesh> mesh(MeshToolsLib::convertSurfaceToMesh(
71 std::numeric_limits<double>::epsilon()));
72 INFO("Mesh created: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
73 mesh->getNumberOfElements());
74
75 INFO("Write it into VTU");
76 MeshLib::IO::VtuInterface writer(mesh.get());
77 writer.writeToFile(outArg.getValue());
78
79 return EXIT_SUCCESS;
80}
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:32
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)