28{
29 TCLAP::CmdLine cmd(
30 "Reads a list of 2D unstructured mesh layers and samples them onto a "
31 "structured grid of the same extent. Note, that a large cube size may "
32 "result in an undersampling of the original structure.\nCube sizes are "
33 "defines by x/y/z-parameters. For equilateral cubes, only the "
34 "x-parameter needs to be set.\n\n"
35 "OpenGeoSys-6 software, version " +
37 ".\n"
38 "Copyright (c) 2012-2025, OpenGeoSys Community "
39 "(http://www.opengeosys.org)",
41 TCLAP::SwitchArg dilate_arg(
42 "d", "dilate",
43 "assign mat IDs based on single nodes instead of a majority of nodes, "
44 "which can result in a slightly increased voxel grid extent",
45 false);
46 cmd.add(dilate_arg);
47
48 TCLAP::ValueArg<double> z_arg(
49 "z", "cellsize-z",
50 "edge length of cubes in z-direction (depth), "
51 "(min = 0)",
52 false, 1000, "CELLSIZE-Z");
53 cmd.add(z_arg);
54
55 TCLAP::ValueArg<double> y_arg(
56 "y", "cellsize-y",
57 "edge length of cubes in y-direction (latitude), "
58 "(min = 0)",
59 false, 1000, "CELLSIZE-Y");
60 cmd.add(y_arg);
61
62 TCLAP::ValueArg<double> x_arg(
63 "x", "cellsize-x",
64 "edge length of cubes in x-direction (longitude) or all directions, if "
65 "y and z are not set, (min = 0)",
66 true, 1000, "CELLSIZE-X");
67 cmd.add(x_arg);
68
69 TCLAP::ValueArg<std::string> output_arg(
70 "o", "output", "Output (.vtu). Name of output mesh file", true, "",
71 "OUTPUT_FILE");
72 cmd.add(output_arg);
73
74 TCLAP::ValueArg<std::string> input_arg(
75 "i", "input",
76 "Input (.vtu). Name of the input file list containing the paths the "
77 "all input layers "
78 "in correct order from top to bottom",
79 true, "", "INPUT_FILE_LIST");
80 cmd.add(input_arg);
81 cmd.parse(argc, argv);
82
84
85 if ((y_arg.isSet() && !z_arg.isSet()) ||
86 ((!y_arg.isSet() && z_arg.isSet())))
87 {
88 ERR(
"For equilateral cubes, only x needs to be set. For unequal "
89 "cuboids, all three edge lengths (x/y/z) need to be specified.");
90 return EXIT_FAILURE;
91 }
92
93 double const x_size = x_arg.getValue();
94 double const y_size = (y_arg.isSet()) ? y_arg.getValue() : x_arg.getValue();
95 double const z_size = (z_arg.isSet()) ? z_arg.getValue() : x_arg.getValue();
96 std::array<double, 3> const cellsize = {x_size, y_size, z_size};
97
98 std::string const input_name = input_arg.getValue();
99 std::string const output_name = output_arg.getValue();
101 if (layer_names.size() < 2)
102 {
103 ERR(
"At least two layers are required to create a 3D Mesh");
104 return EXIT_FAILURE;
105 }
106
107 std::vector<std::unique_ptr<MeshLib::Mesh>> layers;
108 layers.reserve(layer_names.size());
109 constexpr double minval = std::numeric_limits<double>::max();
110 constexpr double maxval = std::numeric_limits<double>::lowest();
111 std::pair<MathLib::Point3d, MathLib::Point3d> extent(
114
115 for (auto const& layer : layer_names)
116 {
118 if (mesh == nullptr)
119 {
120 ERR(
"Input layer '{:s}' not found. Aborting...", layer);
121 return EXIT_FAILURE;
122 }
123 layers.emplace_back(mesh);
124 }
125 std::vector<MeshLib::Mesh const*> layers_ptr;
126 std::transform(std::begin(layers), std::end(layers),
127 std::back_inserter(layers_ptr),
128 [](auto const& layer) { return layer.get(); });
129 bool const dilate = dilate_arg.getValue();
132 if (mesh == nullptr)
133 {
134 ERR(
"The VoxelGrid could not be created.");
135 return EXIT_FAILURE;
136 }
138 vtu.writeToFile(output_name);
139 return EXIT_SUCCESS;
140}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
std::vector< std::string > readStringListFromFile(std::string const &filename)
Reads non-empty lines from a list of strings from a file into a vector.
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)