6#include <range/v3/algorithm/fill.hpp>
17void adjustExtent(std::pair<MathLib::Point3d, MathLib::Point3d>& extent,
22 for (std::size_t i = 0; i < 3; ++i)
24 extent.first[i] = std::min(extent.first[i], aabb.
getMinPoint()[i]);
25 extent.second[i] = std::max(extent.second[i], aabb.
getMaxPoint()[i]);
31 std::pair<MathLib::Point3d, MathLib::Point3d>& extent,
32 std::array<double, 3>
const& res)
34 INFO(
"Creating initial mesh...");
35 std::array<double, 3> mesh_range{{extent.second[0] - extent.first[0],
36 extent.second[1] - extent.first[1],
37 extent.second[2] - extent.first[2]}};
38 std::array<std::size_t, 3>
const n_cells{
39 {
static_cast<std::size_t
>(std::ceil(mesh_range[0] / res[0])),
40 static_cast<std::size_t
>(std::ceil(mesh_range[1] / res[1])),
41 static_cast<std::size_t
>(std::ceil(mesh_range[2] / res[2]))}};
42 for (std::size_t i = 0; i < 3; ++i)
44 double const ext_range = n_cells[i] * res[i];
45 double const offset = (ext_range - mesh_range[i]) / 2.0;
46 mesh_range[i] = ext_range;
47 extent.first[i] -= offset;
48 extent.second[i] += offset;
50 std::unique_ptr<MeshLib::Mesh> mesh(
52 mesh_range[0], mesh_range[1], mesh_range[2], n_cells[0], n_cells[1],
53 n_cells[2], extent.first));
54 auto mat_id = mesh->getProperties().createNewPropertyVector<
int>(
60 ranges::fill(*mat_id, -1);
68 double const max_edge)
70 constexpr double max_val = std::numeric_limits<double>::max();
72 {node[0] - max_edge, node[1] - max_edge, -max_val}};
74 {node[0] + max_edge, node[1] + max_edge, max_val}};
75 auto const& intersection_candidates =
78 intersection_candidates, node);
85 double const max_edge,
86 std::size_t& nullptr_cnt,
87 std::size_t& upper_layer_cnt,
88 std::size_t& lower_layer_cnt)
91 if (proj_elem ==
nullptr)
108 std::vector<MeshLib::Mesh const*>
const& layers,
111 INFO(
"Setting material properties...");
112 std::size_t
const n_layers = layers.size();
116 std::vector<bool> is_set(n_elems,
false);
117 for (
int i = n_layers - 1; i >= 0; --i)
119 INFO(
"-> Layer {:d}", n_layers - i - 1);
121 auto const edgeLengths = minMaxEdgeLength(layers[i]->getElements());
122 double const max_edge = edgeLengths.second;
123 for (std::size_t j = 0; j < n_elems; ++j)
130 std::size_t nullptr_cnt(0);
131 std::size_t upper_layer_cnt(0);
132 std::size_t lower_layer_cnt(0);
135 voteMatId(node, grid, max_edge, nullptr_cnt, upper_layer_cnt,
140 for (std::size_t k = 0; k < 8; ++k)
143 voteMatId(n, grid, max_edge, nullptr_cnt, upper_layer_cnt,
151 if ((upper_layer_cnt == 0 && lower_layer_cnt == 0) ||
152 (!dilate && nullptr_cnt >= upper_layer_cnt &&
153 nullptr_cnt >= lower_layer_cnt))
157 if (upper_layer_cnt > lower_layer_cnt)
159 (*mat_ids)[j] = n_layers - i - 1;
169 (*mat_ids)[j] = n_layers - i - 1;
179 std::replace(mat_ids->begin(), mat_ids->end(),
180 static_cast<int>(n_layers - 1), -1);
188 std::vector<std::size_t> marked_elems;
190 std::size_t
const n_elems = mat_ids.size();
191 for (std::size_t i = 0; i < n_elems; ++i)
193 if (mat_ids[i] == mat_id)
195 marked_elems.push_back(i);
204 std::pair<MathLib::Point3d, MathLib::Point3d>& extent,
205 std::vector<MeshLib::Mesh const*>
const& layers,
206 std::array<double, 3>
const cellsize,
209 for (
auto const& layer : layers)
221 if (marked_elements.size() == mesh->getNumberOfElements())
225 std::unique_ptr<MeshLib::Mesh> new_mesh(
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
static std::string mat_name
std::vector< std::size_t > markSpecificElements(MeshLib::Mesh const &mesh, int const mat_id)
void voteMatId(MathLib::Point3d 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)
MeshLib::Element const * getProjectedElement(MeshLib::MeshElementGrid const &grid, MathLib::Point3d const &node, double const max_edge)
void setMaterialIDs(MeshLib::Mesh &mesh, std::vector< MeshLib::Mesh const * > const &layers, bool const dilate)
std::unique_ptr< MeshLib::Mesh > generateInitialMesh(std::pair< MathLib::Point3d, MathLib::Point3d > &extent, std::array< double, 3 > const &res)
void adjustExtent(std::pair< MathLib::Point3d, MathLib::Point3d > &extent, MeshLib::Mesh const &mesh)
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Eigen::Vector3d const & getMaxPoint() const
Eigen::Vector3d const & getMinPoint() const
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_view name) const
PropertyVector< int > const * materialIDs(Mesh const &mesh)
MathLib::Point3d getCenterOfGravity(Element const &element)
Calculates the center of gravity for the mesh element.