21void adjustExtent(std::pair<MathLib::Point3d, MathLib::Point3d>& extent,
26 for (std::size_t i = 0; i < 3; ++i)
28 extent.first[i] = std::min(extent.first[i], aabb.
getMinPoint()[i]);
29 extent.second[i] = std::max(extent.second[i], aabb.
getMaxPoint()[i]);
35 std::pair<MathLib::Point3d, MathLib::Point3d>& extent,
36 std::array<double, 3>
const& res)
38 INFO(
"Creating initial mesh...");
39 std::array<double, 3> mesh_range{{extent.second[0] - extent.first[0],
40 extent.second[1] - extent.first[1],
41 extent.second[2] - extent.first[2]}};
42 std::array<std::size_t, 3>
const n_cells{
43 {
static_cast<std::size_t
>(std::ceil(mesh_range[0] / res[0])),
44 static_cast<std::size_t
>(std::ceil(mesh_range[1] / res[1])),
45 static_cast<std::size_t
>(std::ceil(mesh_range[2] / res[2]))}};
46 for (std::size_t i = 0; i < 3; ++i)
48 double const ext_range = n_cells[i] * res[i];
49 double const offset = (ext_range - mesh_range[i]) / 2.0;
50 mesh_range[i] = ext_range;
51 extent.first[i] -= offset;
52 extent.second[i] += offset;
54 std::unique_ptr<MeshLib::Mesh> mesh(
56 mesh_range[0], mesh_range[1], mesh_range[2], n_cells[0], n_cells[1],
57 n_cells[2], extent.first));
58 auto mat_id = mesh->getProperties().createNewPropertyVector<
int>(
64 mat_id->insert(mat_id->end(), mesh->getNumberOfElements(), -1);
72 double const max_edge)
74 constexpr double max_val = std::numeric_limits<double>::max();
76 {node[0] - max_edge, node[1] - max_edge, -max_val}};
78 {node[0] + max_edge, node[1] + max_edge, max_val}};
79 auto const& intersection_candidates =
82 intersection_candidates, node);
89 double const max_edge,
90 std::size_t& nullptr_cnt,
91 std::size_t& upper_layer_cnt,
92 std::size_t& lower_layer_cnt)
95 if (proj_elem ==
nullptr)
112 std::vector<MeshLib::Mesh const*>
const& layers,
115 INFO(
"Setting material properties...");
116 std::size_t
const n_layers = layers.size();
120 std::vector<bool> is_set(n_elems,
false);
121 for (
int i = n_layers - 1; i >= 0; --i)
123 INFO(
"-> Layer {:d}", n_layers - i - 1);
125 auto const edgeLengths = minMaxEdgeLength(layers[i]->getElements());
126 double const max_edge = edgeLengths.second;
127 for (std::size_t j = 0; j < n_elems; ++j)
134 std::size_t nullptr_cnt(0);
135 std::size_t upper_layer_cnt(0);
136 std::size_t lower_layer_cnt(0);
139 voteMatId(node, grid, max_edge, nullptr_cnt, upper_layer_cnt,
144 for (std::size_t k = 0; k < 8; ++k)
147 voteMatId(n, grid, max_edge, nullptr_cnt, upper_layer_cnt,
155 if ((upper_layer_cnt == 0 && lower_layer_cnt == 0) ||
156 (!dilate && nullptr_cnt >= upper_layer_cnt &&
157 nullptr_cnt >= lower_layer_cnt))
161 if (upper_layer_cnt > lower_layer_cnt)
163 (*mat_ids)[j] = n_layers - i - 1;
173 (*mat_ids)[j] = n_layers - i - 1;
183 std::replace(mat_ids->begin(), mat_ids->end(),
184 static_cast<int>(n_layers - 1), -1);
192 std::vector<std::size_t> marked_elems;
194 std::size_t
const n_elems = mat_ids.size();
195 for (std::size_t i = 0; i < n_elems; ++i)
197 if (mat_ids[i] == mat_id)
199 marked_elems.push_back(i);
208 std::pair<MathLib::Point3d, MathLib::Point3d>& extent,
209 std::vector<MeshLib::Mesh const*>
const& layers,
210 std::array<double, 3>
const cellsize,
213 for (
auto const& layer : layers)
225 if (marked_elements.size() == mesh->getNumberOfElements())
229 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.