85 std::string
const& name,
bool on_top,
86 bool copy_material_ids)
88 INFO(
"Extracting top surface of mesh '{:s}' ... ", mesh.
getName());
89 double const flag = on_top ? -1.0 : 1.0;
90 Eigen::Vector3d
const dir({0, 0, flag});
91 double const angle(90);
92 std::unique_ptr<MeshLib::Mesh> sfc_mesh(
nullptr);
94 auto const prop_name =
100 mesh, dir, angle, prop_name));
104 sfc_mesh = (on_top) ? std::make_unique<MeshLib::Mesh>(mesh)
105 : std::unique_ptr<MeshLib::Mesh>(
109 sfc_mesh->getProperties().createNewPropertyVector<std::size_t>(
113 pv->resize(sfc_mesh->getNumberOfNodes());
114 std::iota(pv->begin(), pv->end(), 0);
118 ERR(
"Could not create and initialize property '{}'.", prop_name);
125 std::vector<MeshLib::Node*> subsfc_nodes =
127 std::vector<MeshLib::Element*> subsfc_elements =
130 std::size_t
const n_subsfc_nodes(subsfc_nodes.size());
132 std::vector<MeshLib::Node*>
const& sfc_nodes(sfc_mesh->getNodes());
133 std::size_t
const n_sfc_nodes(sfc_nodes.size());
135 if (!sfc_mesh->getProperties().existsPropertyVector<std::size_t>(prop_name))
137 ERR(
"Need subsurface node ids, but the property '{:s}' is not "
143 auto const*
const node_id_pv =
144 sfc_mesh->getProperties().getPropertyVector<std::size_t>(prop_name);
147 std::map<std::size_t, std::size_t> subsfc_sfc_id_map;
148 for (std::size_t k(0); k < n_sfc_nodes; ++k)
150 std::size_t
const subsfc_id((*node_id_pv)[k]);
151 std::size_t
const sfc_id(k + n_subsfc_nodes);
152 subsfc_sfc_id_map.insert(std::make_pair(subsfc_id, sfc_id));
155 node[0], node[1], node[2] - (flag * thickness), sfc_id));
159 std::vector<MeshLib::Element*>
const& sfc_elements(sfc_mesh->getElements());
160 std::size_t
const n_sfc_elements(sfc_elements.size());
161 for (std::size_t k(0); k < n_sfc_elements; ++k)
164 subsfc_nodes, *sfc_elements[k], *node_id_pv, subsfc_sfc_id_map));
167 auto new_mesh =
new MeshLib::Mesh(name, subsfc_nodes, subsfc_elements,
172 ERR(
"Could not copy the property 'MaterialIDs' since the original mesh "
173 "does not contain such a property.");
176 auto const*
const materials =
179 auto*
const new_materials =
180 new_mesh->getProperties().createNewPropertyVector<
int>(
184 ERR(
"Can not set material properties for new layer");
188 new_materials->reserve(subsfc_elements.size());
189 std::copy(materials->cbegin(), materials->cend(),
190 std::back_inserter(*new_materials));
192 if (copy_material_ids &&
193 sfc_mesh->getProperties().existsPropertyVector<
int>(
"MaterialIDs"))
195 auto const& sfc_material_ids =
196 *sfc_mesh->getProperties().getPropertyVector<
int>(
"MaterialIDs");
197 std::copy(sfc_material_ids.cbegin(), sfc_material_ids.cend(),
198 std::back_inserter(*new_materials));
202 int const new_layer_id(
203 *(std::max_element(materials->cbegin(), materials->cend())) + 1);
204 auto const n_new_props(subsfc_elements.size() -
206 std::fill_n(std::back_inserter(*new_materials), n_new_props,