18int main(
int argc,
char* argv[])
21 "Reads a 3D unstructured mesh and samples it onto a structured grid of "
22 "the same extent. Cell properties are mapped onto the grid (sampled at "
23 "the centre-points of each cube), node properties are ignored. Note, "
24 "that a large cube size may result in an undersampling of the original "
25 "mesh structure.\nCube sizes are defines by x/y/z-parameters. For "
26 "equilateral cubes, only the x-parameter needs to be set.\n\n"
27 "OpenGeoSys-6 software, version " +
30 "Copyright (c) 2012-2026, OpenGeoSys Community "
31 "(http://www.opengeosys.org)",
34 TCLAP::ValueArg<double> z_arg(
"z",
"cellsize-z",
35 "edge length of cubes in z-direction "
37 false, 1000,
"CELLSIZE_Z");
40 TCLAP::ValueArg<double> y_arg(
"y",
"cellsize-y",
41 "edge length of cubes in y-direction "
42 "(latitude), (min = 0)",
43 false, 1000,
"CELLSIZE_Y");
46 TCLAP::ValueArg<double> x_arg(
48 "edge length of cubes in x-direction (longitude) or all directions, if "
49 "y and z are not set, (min = 0)",
50 true, 1000,
"CELLSIZE_X");
53 TCLAP::ValueArg<std::string> output_arg(
54 "o",
"output",
"Output (.vtu). The output grid file",
true,
"",
58 TCLAP::ValueArg<std::string> input_arg(
59 "i",
"input",
"Input (.vtu | .msh). The 3D input mesh file",
true,
"",
63 cmd.add(log_level_arg);
64 cmd.parse(argc, argv);
69 if ((y_arg.isSet() && !z_arg.isSet()) ||
70 ((!y_arg.isSet() && z_arg.isSet())))
72 ERR(
"For equilateral cubes, only x needs to be set. For unequal "
73 "cuboids, all three edge lengths (x/y/z) need to be specified.");
78 double const x_size = x_arg.getValue();
79 double const y_size = (y_arg.isSet()) ? y_arg.getValue() : x_arg.getValue();
80 double const z_size = (z_arg.isSet()) ? z_arg.getValue() : x_arg.getValue();
82 if (x_size <= 0 || y_size <= 0 || z_size <= 0)
84 ERR(
"A cellsize ({},{},{}) is not allowed to be <= 0", x_size, y_size,
89 std::array<double, 3>
const cellsize = {x_size, y_size, z_size};
91 vtkSmartPointer<vtkUnstructuredGrid> mesh =
93 input_arg.getValue());
99 double*
const bounds = mesh->GetBounds();
101 std::array<double, 3>{bounds[0], bounds[2], bounds[4]});
103 std::array<double, 3>{bounds[1], bounds[3], bounds[5]});
104 std::array<double, 3> ranges = {max[0] - min[0], max[1] - min[1],
106 if (ranges[0] < 0 || ranges[1] < 0 || ranges[2] < 0)
108 ERR(
"The range ({},{},{}) is not allowed to be < 0", ranges[0],
109 ranges[1], ranges[2]);
112 std::array<std::size_t, 3>
const dims =
114 std::unique_ptr<MeshLib::Mesh> grid(
116 dims[0], dims[1], dims[2], cellsize[0], cellsize[1], cellsize[2],
119 std::vector<int>
const tmp_ids =
121 auto*
const cell_ids = grid->getProperties().createNewPropertyVector<
int>(
124 cell_ids->assign(tmp_ids);