OGS
VoxelGridFromLayeredMeshes.cpp File Reference

Detailed Description

Definition in file VoxelGridFromLayeredMeshes.cpp.

Include dependency graph for VoxelGridFromLayeredMeshes.cpp:

Go to the source code of this file.

Functions

void adjustExtent (std::pair< MathLib::Point3d, MathLib::Point3d > &extent, MeshLib::Mesh const &mesh)
 
std::unique_ptr< MeshLib::MeshgenerateInitialMesh (std::pair< MathLib::Point3d, MathLib::Point3d > &extent, std::array< double, 3 > const &res)
 
MeshLib::Element const * getProjectedElement (MeshLib::MeshElementGrid const &grid, MathLib::Point3d const &node, double const max_edge)
 
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)
 
void setMaterialIDs (MeshLib::Mesh &mesh, std::vector< MeshLib::Mesh const * > const &layers, bool const dilate)
 
std::vector< std::size_t > markSpecificElements (MeshLib::Mesh const &mesh, int const mat_id)
 

Variables

static std::string mat_name = "MaterialIDs"
 

Function Documentation

◆ adjustExtent()

void adjustExtent ( std::pair< MathLib::Point3d, MathLib::Point3d > & extent,
MeshLib::Mesh const & mesh )

Definition at line 21 of file VoxelGridFromLayeredMeshes.cpp.

23{
24 auto const& nodes = mesh.getNodes();
25 GeoLib::AABB aabb(nodes.cbegin(), nodes.cend());
26 for (std::size_t i = 0; i < 3; ++i)
27 {
28 extent.first[i] = std::min(extent.first[i], aabb.getMinPoint()[i]);
29 extent.second[i] = std::max(extent.second[i], aabb.getMaxPoint()[i]);
30 }
31}
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition AABB.h:56

References GeoLib::AABB::getMaxPoint(), GeoLib::AABB::getMinPoint(), and MeshLib::Mesh::getNodes().

Referenced by MeshToolsLib::MeshGenerators::VoxelFromLayeredMeshes::createVoxelFromLayeredMesh().

◆ generateInitialMesh()

std::unique_ptr< MeshLib::Mesh > generateInitialMesh ( std::pair< MathLib::Point3d, MathLib::Point3d > & extent,
std::array< double, 3 > const & res )

Definition at line 34 of file VoxelGridFromLayeredMeshes.cpp.

37{
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)
47 {
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;
53 }
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>(
60 if (!mat_id)
61 {
62 return nullptr;
63 }
64 mat_id->insert(mat_id->end(), mesh->getNumberOfElements(), -1);
65 return mesh;
66}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
static std::string mat_name
MeshLib::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")

References MeshLib::Cell, MeshToolsLib::MeshGenerator::generateRegularHexMesh(), INFO(), and mat_name.

Referenced by MeshToolsLib::MeshGenerators::VoxelFromLayeredMeshes::createVoxelFromLayeredMesh().

◆ getProjectedElement()

MeshLib::Element const * getProjectedElement ( MeshLib::MeshElementGrid const & grid,
MathLib::Point3d const & node,
double const max_edge )

Definition at line 69 of file VoxelGridFromLayeredMeshes.cpp.

73{
74 constexpr double max_val = std::numeric_limits<double>::max();
75 MathLib::Point3d const min_vol{
76 {node[0] - max_edge, node[1] - max_edge, -max_val}};
77 MathLib::Point3d const max_vol{
78 {node[0] + max_edge, node[1] + max_edge, max_val}};
79 auto const& intersection_candidates =
80 grid.getElementsInVolume(min_vol, max_vol);
82 intersection_candidates, node);
83}
MeshLib::Element const * getProjectedElement(std::vector< const MeshLib::Element * > const &elements, MathLib::Point3d const &node)

References MeshLib::MeshElementGrid::getElementsInVolume(), and MeshToolsLib::ProjectPointOnMesh::getProjectedElement().

Referenced by voteMatId().

◆ markSpecificElements()

std::vector< std::size_t > markSpecificElements ( MeshLib::Mesh const & mesh,
int const mat_id )

Definition at line 189 of file VoxelGridFromLayeredMeshes.cpp.

191{
192 std::vector<std::size_t> marked_elems;
193 auto const mat_ids = *MeshLib::materialIDs(mesh);
194 std::size_t const n_elems = mat_ids.size();
195 for (std::size_t i = 0; i < n_elems; ++i)
196 {
197 if (mat_ids[i] == mat_id)
198 {
199 marked_elems.push_back(i);
200 }
201 }
202 return marked_elems;
203}
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition Mesh.cpp:268

References MeshLib::materialIDs().

Referenced by MeshToolsLib::MeshGenerators::VoxelFromLayeredMeshes::createVoxelFromLayeredMesh().

◆ setMaterialIDs()

void setMaterialIDs ( MeshLib::Mesh & mesh,
std::vector< MeshLib::Mesh const * > const & layers,
bool const dilate )

Definition at line 111 of file VoxelGridFromLayeredMeshes.cpp.

114{
115 INFO("Setting material properties...");
116 std::size_t const n_layers = layers.size();
117 auto const& elems = mesh.getElements();
118 std::size_t const n_elems = mesh.getNumberOfElements();
119 auto mat_ids = mesh.getProperties().getPropertyVector<int>(mat_name);
120 std::vector<bool> is_set(n_elems, false);
121 for (int i = n_layers - 1; i >= 0; --i)
122 {
123 INFO("-> Layer {:d}", n_layers - i - 1);
124 MeshLib::MeshElementGrid const grid(*layers[i]);
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)
128 {
129 if (is_set[j])
130 {
131 continue;
132 }
133
134 std::size_t nullptr_cnt(0);
135 std::size_t upper_layer_cnt(0);
136 std::size_t lower_layer_cnt(0);
137
138 auto const& node = MeshLib::getCenterOfGravity(*elems[j]);
139 voteMatId(node, grid, max_edge, nullptr_cnt, upper_layer_cnt,
140 lower_layer_cnt);
141 if (nullptr_cnt)
142 {
143 // if no element was found at centre point, vote via corners
144 for (std::size_t k = 0; k < 8; ++k)
145 {
146 MeshLib::Node const& n = *elems[j]->getNode(k);
147 voteMatId(n, grid, max_edge, nullptr_cnt, upper_layer_cnt,
148 lower_layer_cnt);
149 }
150
151 // If the "dilate"-param is set, a mat ID will be assigned if at
152 // least one node was voting for a specific layer. Without the
153 // "dilate"-param, an absolute majority is needed. In case of a
154 // tie, the lower layer will be favoured.
155 if ((upper_layer_cnt == 0 && lower_layer_cnt == 0) ||
156 (!dilate && nullptr_cnt >= upper_layer_cnt &&
157 nullptr_cnt >= lower_layer_cnt))
158 {
159 continue;
160 }
161 if (upper_layer_cnt > lower_layer_cnt)
162 {
163 (*mat_ids)[j] = n_layers - i - 1;
164 }
165 else
166 {
167 is_set[j] = true;
168 }
169 continue;
170 }
171 if (upper_layer_cnt)
172 {
173 (*mat_ids)[j] = n_layers - i - 1;
174 }
175 else
176 {
177 is_set[j] = true;
178 }
179 }
180 }
181 // set all elements above uppermost layer back to -1 so they are
182 // subsequently cut
183 std::replace(mat_ids->begin(), mat_ids->end(),
184 static_cast<int>(n_layers - 1), -1);
185}
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)
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:109
Properties & getProperties()
Definition Mesh.h:134
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:97
PropertyVector< T > const * getPropertyVector(std::string_view name) const
std::pair< double, double > minMaxEdgeLength(std::vector< Element * > const &elements)
Returns the minimum and maximum edge length for given elements.
Definition Mesh.cpp:189
MathLib::Point3d getCenterOfGravity(Element const &element)
Calculates the center of gravity for the mesh element.
Definition Element.cpp:124

References MeshLib::getCenterOfGravity(), MeshLib::Mesh::getElements(), MeshLib::Mesh::getNumberOfElements(), MeshLib::Mesh::getProperties(), MeshLib::Properties::getPropertyVector(), INFO(), mat_name, and voteMatId().

Referenced by MeshToolsLib::MeshGenerators::VoxelFromLayeredMeshes::createVoxelFromLayeredMesh().

◆ voteMatId()

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 )

Definition at line 87 of file VoxelGridFromLayeredMeshes.cpp.

93{
94 auto const& proj_elem = getProjectedElement(grid, node, max_edge);
95 if (proj_elem == nullptr)
96 {
97 nullptr_cnt++;
98 return;
99 }
100 if (node[2] >
102 {
103 upper_layer_cnt++;
104 return;
105 }
106 lower_layer_cnt++;
107}
MeshLib::Element const * getProjectedElement(MeshLib::MeshElementGrid const &grid, MathLib::Point3d const &node, double const max_edge)
double getElevation(MeshLib::Element const &element, MathLib::Point3d const &node)

References MeshToolsLib::ProjectPointOnMesh::getElevation(), and getProjectedElement().

Referenced by setMaterialIDs().

Variable Documentation

◆ mat_name

std::string mat_name = "MaterialIDs"
static

Definition at line 18 of file VoxelGridFromLayeredMeshes.cpp.

Referenced by generateInitialMesh(), and setMaterialIDs().