Skip to content
Snippets Groups Projects
Commit b836603f authored by Tom Fischer's avatar Tom Fischer
Browse files

[MeL/ME] AddLayerToMesh: Copy MaterialIDs property.

parent 317657b1
No related branches found
No related tags found
No related merge requests found
...@@ -107,7 +107,6 @@ MeshLib::Mesh* addLayerToMesh(MeshLib::Mesh const& mesh, double thickness, ...@@ -107,7 +107,6 @@ MeshLib::Mesh* addLayerToMesh(MeshLib::Mesh const& mesh, double thickness,
} }
// *** insert new top layer elements into subsfc_mesh // *** insert new top layer elements into subsfc_mesh
std::size_t orig_size(subsfc_elements.size());
std::vector<MeshLib::Element*> const& sfc_elements(sfc_mesh->getElements()); std::vector<MeshLib::Element*> const& sfc_elements(sfc_mesh->getElements());
std::size_t const n_sfc_elements(sfc_elements.size()); std::size_t const n_sfc_elements(sfc_elements.size());
for (std::size_t k(0); k<n_sfc_elements; ++k) for (std::size_t k(0); k<n_sfc_elements; ++k)
...@@ -115,23 +114,33 @@ MeshLib::Mesh* addLayerToMesh(MeshLib::Mesh const& mesh, double thickness, ...@@ -115,23 +114,33 @@ MeshLib::Mesh* addLayerToMesh(MeshLib::Mesh const& mesh, double thickness,
extrudeElement(subsfc_nodes, *sfc_elements[k], subsfc_sfc_id_map) extrudeElement(subsfc_nodes, *sfc_elements[k], subsfc_sfc_id_map)
); );
MeshLib::Properties subsfc_props (mesh.getProperties()); auto new_mesh = new MeshLib::Mesh(name, subsfc_nodes, subsfc_elements);
boost::optional<MeshLib::PropertyVector<int> &> opt_materials(
subsfc_props.getPropertyVector<int>("MaterialIDs") boost::optional<MeshLib::PropertyVector<int> const&> opt_materials(
mesh.getProperties().getPropertyVector<int>("MaterialIDs")
); );
if (!opt_materials) {
ERR("Can not set material properties for new layer"); if (opt_materials) {
} else { boost::optional<PropertyVector<int> &> new_opt_materials(
MeshLib::PropertyVector<int> & materials(opt_materials.get()); new_mesh->getProperties().createNewPropertyVector<int>("MaterialIDs",
unsigned layer_id(*(std::max_element( MeshLib::MeshItemType::Cell, 1));
materials.cbegin(), materials.cend()))+1); if (!new_opt_materials) {
while (orig_size<subsfc_elements.size()) { ERR("Can not set material properties for new layer");
materials.push_back(layer_id); } else {
orig_size++; unsigned new_layer_id(*(std::max_element(
opt_materials->cbegin(), opt_materials->cend()))+1);
std::copy(opt_materials->cbegin(), opt_materials->cend(),
new_opt_materials->begin());
auto const n_new_props(subsfc_elements.size()-mesh.getNElements());
std::fill_n(new_opt_materials->end(), n_new_props, new_layer_id);
} }
} else {
ERR(
"Could not copy the property \"MaterialIDs\" since the original "
"mesh does not contain such a property.");
} }
return new MeshLib::Mesh(name, subsfc_nodes, subsfc_elements, subsfc_props); return new_mesh;
} }
} // namespace MeshLib } // namespace MeshLib
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment