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

[MeL/ME/AddLayer] Switch to copy MaterialIDs.

parent 354b5b3c
No related branches found
No related tags found
No related merge requests found
...@@ -84,14 +84,16 @@ MeshLib::Element* extrudeElement(std::vector<MeshLib::Node*> const& subsfc_nodes ...@@ -84,14 +84,16 @@ MeshLib::Element* extrudeElement(std::vector<MeshLib::Node*> const& subsfc_nodes
} }
MeshLib::Mesh* addTopLayerToMesh(MeshLib::Mesh const& mesh, MeshLib::Mesh* addTopLayerToMesh(MeshLib::Mesh const& mesh,
double thickness, double thickness,
std::string const& name) std::string const& name,
bool copy_material_ids)
{ {
return addLayerToMesh(mesh, thickness, name, true); return addLayerToMesh(mesh, thickness, name, true, copy_material_ids);
} }
MeshLib::Mesh* addLayerToMesh(MeshLib::Mesh const& mesh, double thickness, MeshLib::Mesh* addLayerToMesh(MeshLib::Mesh const& mesh, double thickness,
std::string const& name, bool on_top) std::string const& name, bool on_top,
bool copy_material_ids)
{ {
INFO("Extracting top surface of mesh '{:s}' ... ", mesh.getName()); INFO("Extracting top surface of mesh '{:s}' ... ", mesh.getName());
int const flag = (on_top) ? -1 : 1; int const flag = (on_top) ? -1 : 1;
...@@ -192,12 +194,26 @@ MeshLib::Mesh* addLayerToMesh(MeshLib::Mesh const& mesh, double thickness, ...@@ -192,12 +194,26 @@ MeshLib::Mesh* addLayerToMesh(MeshLib::Mesh const& mesh, double thickness,
} }
new_materials->reserve(subsfc_elements.size()); new_materials->reserve(subsfc_elements.size());
int new_layer_id(
*(std::max_element(materials->cbegin(), materials->cend())) + 1);
std::copy(materials->cbegin(), materials->cend(), std::copy(materials->cbegin(), materials->cend(),
std::back_inserter(*new_materials)); std::back_inserter(*new_materials));
auto const n_new_props(subsfc_elements.size() - mesh.getNumberOfElements());
std::fill_n(std::back_inserter(*new_materials), n_new_props, new_layer_id); if (copy_material_ids &&
sfc_mesh->getProperties().existsPropertyVector<int>("MaterialIDs"))
{
auto const& sfc_material_ids =
*sfc_mesh->getProperties().getPropertyVector<int>("MaterialIDs");
std::copy(sfc_material_ids.cbegin(), sfc_material_ids.cend(),
std::back_inserter(*new_materials));
}
else
{
int const new_layer_id(
*(std::max_element(materials->cbegin(), materials->cend())) + 1);
auto const n_new_props(subsfc_elements.size() -
mesh.getNumberOfElements());
std::fill_n(std::back_inserter(*new_materials), n_new_props,
new_layer_id);
}
return new_mesh; return new_mesh;
} }
......
...@@ -26,14 +26,14 @@ class Element; ...@@ -26,14 +26,14 @@ class Element;
/// Adds a layer on top of the mesh /// Adds a layer on top of the mesh
MeshLib::Mesh* addTopLayerToMesh(MeshLib::Mesh const& mesh, MeshLib::Mesh* addTopLayerToMesh(MeshLib::Mesh const& mesh,
double thickness, double thickness,
std::string const& name); std::string const& name,
bool copy_material_ids);
/// Adds a layer to the mesh. If on_top is true, the layer is added on top, /// Adds a layer to the mesh. If on_top is true, the layer is added on top,
/// if it is false, the layer is added at the bottom. /// if it is false, the layer is added at the bottom.
MeshLib::Mesh* addLayerToMesh(MeshLib::Mesh const& mesh, MeshLib::Mesh* addLayerToMesh(MeshLib::Mesh const& mesh, double thickness,
double thickness, std::string const& name, bool on_top,
std::string const& name, bool copy_material_ids);
bool on_top);
} // end namespace MeshLib } // end 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