diff --git a/MeshLib/MeshGenerators/LayeredMeshGenerator.cpp b/MeshLib/MeshGenerators/LayeredMeshGenerator.cpp index 00f74050169e58962c83577e57bad51c3544dc9b..4a7caea00d432300b7d715172e3aea6c69eaa67c 100644 --- a/MeshLib/MeshGenerators/LayeredMeshGenerator.cpp +++ b/MeshLib/MeshGenerators/LayeredMeshGenerator.cpp @@ -17,6 +17,8 @@ #include <vector> #include <fstream> +#include <logog/include/logog.hpp> + #include "FileIO/AsciiRasterInterface.h" #include "GeoLib/Raster.h" @@ -24,6 +26,8 @@ #include "MeshLib/Mesh.h" #include "MeshLib/Node.h" #include "MeshLib/Elements/Element.h" +#include "MeshLib/PropertyVector.h" +#include "MeshLib/Properties.h" #include "MeshLib/MeshQuality/MeshValidation.h" #include "MeshLib/MeshSearch/NodeSearch.h" #include "MeshLib/MeshEditing/RemoveMeshComponents.h" @@ -53,17 +57,28 @@ bool LayeredMeshGenerator::createLayers(MeshLib::Mesh const& mesh, MeshLib::Mesh* LayeredMeshGenerator::getMesh(std::string const& mesh_name) const { - if (_nodes.empty() || _elements.empty()) - return nullptr; - - MeshLib::Mesh* result (new MeshLib::Mesh(mesh_name, _nodes, _elements)); - MeshLib::NodeSearch ns(*result); - if (ns.searchUnused() > 0) { - auto new_mesh = MeshLib::removeNodes(*result, ns.getSearchedNodeIDs(), mesh_name); - delete result; - return new_mesh; - } - return result; + if (_nodes.empty() || _elements.empty()) + return nullptr; + + MeshLib::Properties properties; + if (_materials.size() == _elements.size()) + { + boost::optional<MeshLib::PropertyVector<int> &> materials = + properties.createNewPropertyVector<int>("MaterialIDs", MeshLib::MeshItemType::Cell); + materials->resize(_materials.size()); + std::copy(_materials.cbegin(), _materials.cend(), materials->begin()); + } + else + WARN ("Skipping MaterialID information, number of entries does not match element number"); + + MeshLib::Mesh* result (new MeshLib::Mesh(mesh_name, _nodes, _elements, properties)); + MeshLib::NodeSearch ns(*result); + if (ns.searchUnused() > 0) { + auto new_mesh = MeshLib::removeNodes(*result, ns.getSearchedNodeIDs(), mesh_name); + delete result; + return new_mesh; + } + return result; } double LayeredMeshGenerator::calcEpsilon(GeoLib::Raster const& low, GeoLib::Raster const& high) diff --git a/MeshLib/MeshGenerators/LayeredMeshGenerator.h b/MeshLib/MeshGenerators/LayeredMeshGenerator.h index ec832bc47462029d2bc1185a5c9c84bb7a8e7ecf..958d598d1022c29c138dc63ce0396c5780dd49fe 100644 --- a/MeshLib/MeshGenerators/LayeredMeshGenerator.h +++ b/MeshLib/MeshGenerators/LayeredMeshGenerator.h @@ -97,6 +97,7 @@ protected: double _elevation_epsilon; double _minimum_thickness; + std::vector<int> _materials; std::vector<MeshLib::Node*> _nodes; std::vector<MeshLib::Element*> _elements; };