12#include <range/v3/algorithm/fill.hpp>
23void adjustExtent(std::pair<MathLib::Point3d, MathLib::Point3d>& extent,
28 for (std::size_t i = 0; i < 3; ++i)
30 extent.first[i] = std::min(extent.first[i], aabb.
getMinPoint()[i]);
31 extent.second[i] = std::max(extent.second[i], aabb.
getMaxPoint()[i]);
23void adjustExtent(std::pair<MathLib::Point3d, MathLib::Point3d>& extent, {
…}
37 std::pair<MathLib::Point3d, MathLib::Point3d>& extent,
38 std::array<double, 3>
const& res)
40 INFO(
"Creating initial mesh...");
41 std::array<double, 3> mesh_range{{extent.second[0] - extent.first[0],
42 extent.second[1] - extent.first[1],
43 extent.second[2] - extent.first[2]}};
44 std::array<std::size_t, 3>
const n_cells{
45 {
static_cast<std::size_t
>(std::ceil(mesh_range[0] / res[0])),
46 static_cast<std::size_t
>(std::ceil(mesh_range[1] / res[1])),
47 static_cast<std::size_t
>(std::ceil(mesh_range[2] / res[2]))}};
48 for (std::size_t i = 0; i < 3; ++i)
50 double const ext_range = n_cells[i] * res[i];
51 double const offset = (ext_range - mesh_range[i]) / 2.0;
52 mesh_range[i] = ext_range;
53 extent.first[i] -= offset;
54 extent.second[i] += offset;
56 std::unique_ptr<MeshLib::Mesh> mesh(
58 mesh_range[0], mesh_range[1], mesh_range[2], n_cells[0], n_cells[1],
59 n_cells[2], extent.first));
60 auto mat_id = mesh->getProperties().createNewPropertyVector<
int>(
66 ranges::fill(*mat_id, -1);
74 double const max_edge)
76 constexpr double max_val = std::numeric_limits<double>::max();
78 {node[0] - max_edge, node[1] - max_edge, -max_val}};
80 {node[0] + max_edge, node[1] + max_edge, max_val}};
81 auto const& intersection_candidates =
84 intersection_candidates, node);
91 double const max_edge,
92 std::size_t& nullptr_cnt,
93 std::size_t& upper_layer_cnt,
94 std::size_t& lower_layer_cnt)
97 if (proj_elem ==
nullptr)
114 std::vector<MeshLib::Mesh const*>
const& layers,
117 INFO(
"Setting material properties...");
118 std::size_t
const n_layers = layers.size();
122 std::vector<bool> is_set(n_elems,
false);
123 for (
int i = n_layers - 1; i >= 0; --i)
125 INFO(
"-> Layer {:d}", n_layers - i - 1);
127 auto const edgeLengths = minMaxEdgeLength(layers[i]->getElements());
128 double const max_edge = edgeLengths.second;
129 for (std::size_t j = 0; j < n_elems; ++j)
136 std::size_t nullptr_cnt(0);
137 std::size_t upper_layer_cnt(0);
138 std::size_t lower_layer_cnt(0);
141 voteMatId(node, grid, max_edge, nullptr_cnt, upper_layer_cnt,
146 for (std::size_t k = 0; k < 8; ++k)
149 voteMatId(n, grid, max_edge, nullptr_cnt, upper_layer_cnt,
157 if ((upper_layer_cnt == 0 && lower_layer_cnt == 0) ||
158 (!dilate && nullptr_cnt >= upper_layer_cnt &&
159 nullptr_cnt >= lower_layer_cnt))
163 if (upper_layer_cnt > lower_layer_cnt)
165 (*mat_ids)[j] = n_layers - i - 1;
175 (*mat_ids)[j] = n_layers - i - 1;
185 std::replace(mat_ids->begin(), mat_ids->end(),
186 static_cast<int>(n_layers - 1), -1);
194 std::vector<std::size_t> marked_elems;
196 std::size_t
const n_elems = mat_ids.size();
197 for (std::size_t i = 0; i < n_elems; ++i)
199 if (mat_ids[i] == mat_id)
201 marked_elems.push_back(i);
210 std::pair<MathLib::Point3d, MathLib::Point3d>& extent,
211 std::vector<MeshLib::Mesh const*>
const& layers,
212 std::array<double, 3>
const cellsize,
215 for (
auto const& layer : layers)
227 if (marked_elements.size() == mesh->getNumberOfElements())
231 std::unique_ptr<MeshLib::Mesh> new_mesh(
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the Mesh class.
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.