16 #include <tclap/CmdLine.h>
35 void adjustExtent(std::pair<MathLib::Point3d, MathLib::Point3d>& extent,
40 for (std::size_t i = 0; i < 3; ++i)
42 extent.first[i] = std::min(extent.first[i], aabb.
getMinPoint()[i]);
43 extent.second[i] = std::max(extent.second[i], aabb.
getMaxPoint()[i]);
49 std::pair<MathLib::Point3d, MathLib::Point3d>& extent,
50 std::array<double, 3>
const& res)
52 INFO(
"Creating initial mesh...");
53 std::array<double, 3> mesh_range{{extent.second[0] - extent.first[0],
54 extent.second[1] - extent.first[1],
55 extent.second[2] - extent.first[2]}};
56 std::array<std::size_t, 3>
const n_cells{
57 {
static_cast<std::size_t
>(std::ceil(mesh_range[0] / res[0])),
58 static_cast<std::size_t
>(std::ceil(mesh_range[1] / res[1])),
59 static_cast<std::size_t
>(std::ceil(mesh_range[2] / res[2]))}};
60 for (std::size_t i = 0; i < 3; ++i)
62 double const ext_range = n_cells[i] * res[i];
63 double const offset = (ext_range - mesh_range[i]) / 2.0;
64 mesh_range[i] = ext_range;
65 extent.first[i] -= offset;
66 extent.second[i] += offset;
68 std::unique_ptr<MeshLib::Mesh> mesh(
70 mesh_range[0], mesh_range[1], mesh_range[2], n_cells[0], n_cells[1],
71 n_cells[2], extent.first));
72 auto mat_id = mesh->getProperties().createNewPropertyVector<
int>(
78 mat_id->insert(mat_id->end(), mesh->getNumberOfElements(), -1);
86 double const max_edge)
88 constexpr
double max_val = std::numeric_limits<double>::max();
90 {node[0] - max_edge, node[1] - max_edge, -max_val}};
92 {node[0] + max_edge, node[1] + max_edge, max_val}};
93 auto const& intersection_candidates =
96 intersection_candidates, node);
102 double const max_edge, std::size_t& nullptr_cnt,
103 std::size_t& upper_layer_cnt, std::size_t& lower_layer_cnt)
106 if (proj_elem ==
nullptr)
122 std::vector<std::unique_ptr<MeshLib::Mesh>>
const& layers,
125 INFO(
"Setting material properties...");
126 std::size_t
const n_layers = layers.size();
130 std::vector<bool> is_set(n_elems,
false);
131 for (
int i = n_layers - 1; i >= 0; --i)
133 INFO(
"-> Layer {:d}", n_layers - i - 1);
135 double const max_edge(layers[i]->getMaxEdgeLength());
136 for (std::size_t j = 0; j < n_elems; ++j)
143 std::size_t nullptr_cnt(0);
144 std::size_t upper_layer_cnt(0);
145 std::size_t lower_layer_cnt(0);
148 voteMatId(node, grid, max_edge, nullptr_cnt, upper_layer_cnt,
153 for (std::size_t k = 0; k < 8; ++k)
156 voteMatId(n, grid, max_edge, nullptr_cnt, upper_layer_cnt,
164 if ((upper_layer_cnt == 0 && lower_layer_cnt == 0) ||
165 (!dilate && nullptr_cnt >= upper_layer_cnt &&
166 nullptr_cnt >= lower_layer_cnt))
170 if (upper_layer_cnt > lower_layer_cnt)
172 (*mat_ids)[j] = n_layers - i - 1;
182 (*mat_ids)[j] = n_layers - i - 1;
192 std::replace(mat_ids->begin(), mat_ids->end(),
193 static_cast<int>(n_layers - 1), -1);
200 std::vector<std::size_t> marked_elems;
202 std::size_t
const n_elems = mat_ids.size();
203 for (std::size_t i = 0; i < n_elems; ++i)
205 if (mat_ids[i] == -1)
207 marked_elems.push_back(i);
218 int main(
int argc,
char* argv[])
221 "Reads a list of 2D unstructured mesh layers and samples them onto a "
222 "structured grid of the same extent. Note, that a large cube size may "
223 "result in an undersampling of the original structure.\nCube sizes are "
224 "defines by x/y/z-parameters. For equilateral cubes, only the "
225 "x-parameter needs to be set.\n\n"
226 "OpenGeoSys-6 software, version " +
229 "Copyright (c) 2012-2021, OpenGeoSys Community "
230 "(http://www.opengeosys.org)",
232 TCLAP::SwitchArg dilate_arg(
234 "assign mat IDs based on single nodes instead of a majority of nodes, "
235 "which can result in a slightly increased voxel grid extent",
239 TCLAP::ValueArg<double> z_arg(
"z",
"cellsize-z",
240 "edge length of cubes in z-direction (depth)",
241 false, 1000,
"floating point number");
244 TCLAP::ValueArg<double> y_arg(
245 "y",
"cellsize-y",
"edge length of cubes in y-direction (latitude)",
246 false, 1000,
"floating point number");
249 TCLAP::ValueArg<double> x_arg(
251 "edge length of cubes in x-direction (longitude) or all directions, if "
252 "y and z are not set",
253 true, 1000,
"floating point number");
256 TCLAP::ValueArg<std::string> output_arg(
257 "o",
"output",
"name of output mesh (*.vtu)",
true,
"",
"string");
260 TCLAP::ValueArg<std::string> input_arg(
262 "name of the input file list containing the paths the all input layers "
263 "in correct order from top to bottom",
266 cmd.parse(argc, argv);
268 if ((y_arg.isSet() && !z_arg.isSet()) ||
269 ((!y_arg.isSet() && z_arg.isSet())))
271 ERR(
"For equilateral cubes, only x needs to be set. For unequal "
272 "cuboids, all three edge lengths (x/y/z) need to be specified.");
276 double const x_size = x_arg.getValue();
277 double const y_size = (y_arg.isSet()) ? y_arg.getValue() : x_arg.getValue();
278 double const z_size = (z_arg.isSet()) ? z_arg.getValue() : x_arg.getValue();
279 std::array<double, 3>
const cellsize = {x_size, y_size, z_size};
281 std::string
const input_name = input_arg.getValue();
282 std::string
const output_name = output_arg.getValue();
284 if (layer_names.size() < 2)
286 ERR(
"At least two layers are required to create a 3D Mesh");
290 std::vector<std::unique_ptr<MeshLib::Mesh>> layers;
291 layers.reserve(layer_names.size());
292 constexpr
double minval = std::numeric_limits<double>::max();
293 constexpr
double maxval = std::numeric_limits<double>::lowest();
294 std::pair<MathLib::Point3d, MathLib::Point3d> extent(
297 for (
auto const& layer : layer_names)
299 std::unique_ptr<MeshLib::Mesh> mesh(
303 ERR(
"Input layer '{:s}' not found. Aborting...", layer);
307 layers.emplace_back(std::move(mesh));
313 ERR(
"Error creating mesh...");
319 if (new_mesh ==
nullptr)
321 ERR(
"Error generating mesh...");
Definition of the AABB class.
Definition of the Element class.
int main(int argc, char *argv[])
static std::string mat_name
MeshLib::Element const * getProjectedElement(MeshLib::MeshElementGrid const &grid, MeshLib::Node const &node, double const max_edge)
void voteMatId(MeshLib::Node const &node, MeshLib::MeshElementGrid const &grid, double const max_edge, std::size_t &nullptr_cnt, std::size_t &upper_layer_cnt, std::size_t &lower_layer_cnt)
void setMaterialIDs(MeshLib::Mesh &mesh, std::vector< std::unique_ptr< MeshLib::Mesh >> const &layers, bool const dilate)
std::unique_ptr< MeshLib::Mesh > generateInitialMesh(std::pair< MathLib::Point3d, MathLib::Point3d > &extent, std::array< double, 3 > const &res)
MeshLib::Mesh * removeUnusedElements(MeshLib::Mesh const &mesh)
void adjustExtent(std::pair< MathLib::Point3d, MathLib::Point3d > &extent, MeshLib::Mesh const &mesh)
void INFO(char const *fmt, Args const &... args)
void ERR(char const *fmt, Args const &... args)
Definition of the Mesh class.
Definition of the Node class.
Definition of the Point3d class.
Implementation of the VtuInterface class.
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Eigen::Vector3d const & getMinPoint() const
Eigen::Vector3d const & getMaxPoint() const
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
bool writeToFile(std::filesystem::path const &file_path)
std::vector< MeshLib::Element const * > getElementsInVolume(POINT const &min, POINT const &max) const
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Properties & getProperties()
std::size_t getNumberOfElements() const
Get the number of elements.
PropertyVector< T > const * getPropertyVector(std::string const &name) 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.
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name)
Mesh * generateRegularHexMesh(const BaseLib::ISubdivision &div_x, const BaseLib::ISubdivision &div_y, const BaseLib::ISubdivision &div_z, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")
double getElevation(Element const &element, Node const &node)
Element const * getProjectedElement(std::vector< const Element * > const &elements, Node const &node)
MeshLib::Mesh * removeElements(const MeshLib::Mesh &mesh, const std::vector< std::size_t > &removed_element_ids, const std::string &new_mesh_name)
PropertyVector< int > const * materialIDs(Mesh const &mesh)
MeshLib::Node getCenterOfGravity(Element const &element)
Calculates the center of gravity for the mesh element.
Definition of readMeshFromFile function.