34{
35 TCLAP::CmdLine cmd(
36 "Creates a boundary representation for a layered 3D mesh in "
37 "*.smesh-format. This boundary representation can be used with the "
38 "TetGen Tetrahedral Mesh Generator to create 3D meshes of the given "
39 "geometry at arbitrary resolutions and with varying properties. "
40 "Details on command line switches and possible parametrisation can be "
41 "found in the TetGen User's Manual. Supported raster formats are "
42 "ArcGIS ascii rasters (*.asc), Surfer Grids (*.grd) and XYZ raster "
43 "files (*.xyz)."
44 "Only input meshes consisting of line and triangle elements are "
45 "currently supported as mapping of quads might result in invalid mesh "
46 "elements.\n\n"
47 "OpenGeoSys-6 software, version " +
49 ".\n"
50 "Copyright (c) 2012-2024, OpenGeoSys Community "
51 "(http://www.opengeosys.org)",
53
54 TCLAP::SwitchArg use_ascii_arg("", "ascii_output",
55 "Write VTU output in ASCII format.");
56 cmd.add(use_ascii_arg);
57
58 double min_thickness(std::numeric_limits<double>::epsilon());
59 TCLAP::ValueArg<double> min_thickness_arg(
60 "t", "thickness",
61 "The minimum thickness of a layer to be integrated at any given "
62 "location.",
63 false, min_thickness, "floating point number");
64 cmd.add(min_thickness_arg);
65
66 TCLAP::ValueArg<std::string> raster_path_arg(
67 "r", "raster-list",
68 "An ascii-file containing a list of raster files, starting from top "
69 "(DEM) to bottom.",
70 true, "", "file name");
71 cmd.add(raster_path_arg);
72
73 TCLAP::ValueArg<std::string> mesh_out_arg(
74 "o", "output-mesh-file", "The file name of the resulting 3D mesh.",
75 true, "", "file name");
76 cmd.add(mesh_out_arg);
77
78 TCLAP::ValueArg<std::string> mesh_arg("i", "input-mesh-file",
79 "The file name of the 2D input mesh.",
80 true, "", "file name");
81 cmd.add(mesh_arg);
82
83 cmd.parse(argc, argv);
84
86
87 if (min_thickness_arg.isSet())
88 {
89 min_thickness = min_thickness_arg.getValue();
90 if (min_thickness < 0)
91 {
92 ERR(
"Minimum layer thickness must be non-negative value.");
93 return EXIT_FAILURE;
94 }
95 }
96
97 INFO(
"Reading mesh '{:s}' ... ", mesh_arg.getValue());
99 mesh_arg.getValue(), true ));
100 if (!sfc_mesh)
101 {
102 ERR(
"Error reading mesh '{:s}'.", mesh_arg.getValue());
103 return EXIT_FAILURE;
104 }
105 if (sfc_mesh->getDimension() != 2)
106 {
107 ERR(
"Input mesh must be a 2D mesh.");
108 return EXIT_FAILURE;
109 }
111
112 std::vector<std::string> raster_paths =
114 if (raster_paths.size() < 2)
115 {
116 ERR(
"At least two raster files needed to create 3D mesh.");
117 return EXIT_FAILURE;
118 }
119 std::reverse(raster_paths.begin(), raster_paths.end());
120
121 std::string output_name(mesh_out_arg.getValue());
123 {
124 output_name.append(".smesh");
125 }
126
129 if (rasters)
130 {
131 if (!lv.
createLayers(*sfc_mesh, *rasters, min_thickness))
132 {
133 ERR(
"Creating the layers was erroneous.");
134 return EXIT_FAILURE;
135 }
136 }
137 else
138 {
139 ERR(
"The raster files are not accessible.");
140 return EXIT_FAILURE;
141 }
142 std::unique_ptr<MeshLib::Mesh> tg_mesh =
143 lv.
getMesh(
"BoundaryRepresentation");
144 if (tg_mesh != nullptr)
145 {
149 INFO(
"Smesh was successfully written.");
150 }
151 else
152 {
153 ERR(
"The tetgen-smesh could not be created.");
154 return EXIT_FAILURE;
155 }
156
157 return EXIT_SUCCESS;
158}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
static bool writeTetGenSmesh(const std::string &file_name, const GeoLib::GEOObjects &geo_objects, const std::string &geo_name, const std::vector< GeoLib::Point > &attribute_points)
virtual bool createLayers(MeshLib::Mesh const &mesh, std::vector< GeoLib::Raster const * > const &rasters, double minimum_thickness, double noDataReplacementValue=0.0) final
std::unique_ptr< MeshLib::Mesh > getMesh(std::string const &mesh_name) const
Returns a mesh of the subsurface representation.
Creates a volume geometry from 2D mesh layers based on raster data.
std::vector< MeshLib::Node > getAttributePoints() const
std::vector< std::string > readStringListFromFile(std::string const &filename)
Reads non-empty lines from a list of strings from a file into a vector.
bool hasFileExtension(std::string const &extension, std::string const &filename)
std::optional< std::vector< GeoLib::Raster const * > > readRasters(std::vector< std::string > const &raster_paths)
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)