85 std::string
const& name,
bool const on_top,
86 bool const copy_material_ids,
87 std::optional<int>
const layer_id)
89 INFO(
"Extracting top surface of mesh '{:s}' ... ", mesh.
getName());
90 double const flag = on_top ? -1.0 : 1.0;
91 Eigen::Vector3d
const dir({0, 0, flag});
92 double const angle(90);
93 std::unique_ptr<MeshLib::Mesh> sfc_mesh(
nullptr);
95 auto const prop_name =
101 mesh, dir, angle, prop_name));
105 sfc_mesh = (on_top) ? std::make_unique<MeshLib::Mesh>(mesh)
106 : std::unique_ptr<MeshLib::Mesh>(
110 sfc_mesh->getProperties().createNewPropertyVector<std::size_t>(
114 pv->resize(sfc_mesh->getNumberOfNodes());
115 std::iota(pv->begin(), pv->end(), 0);
119 ERR(
"Could not create and initialize property '{}'.", prop_name);
126 std::vector<MeshLib::Node*> subsfc_nodes =
128 std::vector<MeshLib::Element*> subsfc_elements =
131 std::size_t
const n_subsfc_nodes(subsfc_nodes.size());
133 std::vector<MeshLib::Node*>
const& sfc_nodes(sfc_mesh->getNodes());
134 std::size_t
const n_sfc_nodes(sfc_nodes.size());
136 if (!sfc_mesh->getProperties().existsPropertyVector<std::size_t>(prop_name))
138 ERR(
"Need subsurface node ids, but the property '{:s}' is not "
144 auto const*
const node_id_pv =
145 sfc_mesh->getProperties().getPropertyVector<std::size_t>(prop_name);
148 std::map<std::size_t, std::size_t> subsfc_sfc_id_map;
149 for (std::size_t k(0); k < n_sfc_nodes; ++k)
151 std::size_t
const subsfc_id((*node_id_pv)[k]);
152 std::size_t
const sfc_id(k + n_subsfc_nodes);
153 subsfc_sfc_id_map.insert(std::make_pair(subsfc_id, sfc_id));
156 node[0], node[1], node[2] - (flag * thickness), sfc_id));
160 std::vector<MeshLib::Element*>
const& sfc_elements(sfc_mesh->getElements());
161 std::size_t
const n_sfc_elements(sfc_elements.size());
162 for (std::size_t k(0); k < n_sfc_elements; ++k)
165 subsfc_nodes, *sfc_elements[k], *node_id_pv, subsfc_sfc_id_map));
168 auto new_mesh =
new MeshLib::Mesh(name, subsfc_nodes, subsfc_elements,
173 ERR(
"Could not copy the property 'MaterialIDs' since the original mesh "
174 "does not contain such a property.");
177 auto const*
const materials =
180 auto*
const new_materials =
181 new_mesh->getProperties().createNewPropertyVector<
int>(
185 ERR(
"Can not set material properties for new layer");
189 new_materials->reserve(subsfc_elements.size());
190 std::copy(materials->cbegin(), materials->cend(),
191 std::back_inserter(*new_materials));
193 if (copy_material_ids &&
194 sfc_mesh->getProperties().existsPropertyVector<
int>(
"MaterialIDs"))
196 auto const& sfc_material_ids =
197 *sfc_mesh->getProperties().getPropertyVector<
int>(
"MaterialIDs");
198 std::copy(sfc_material_ids.cbegin(), sfc_material_ids.cend(),
199 std::back_inserter(*new_materials));
203 int const new_layer_id =
206 : *(std::max_element(materials->cbegin(), materials->cend())) +
208 auto const n_new_props(subsfc_elements.size() -
210 std::fill_n(std::back_inserter(*new_materials), n_new_props,