OGS
getMeshElementsForMaterialIDs.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
5
6#include <range/v3/algorithm/contains.hpp>
7
9#include "MeshLib/Mesh.h"
10
11namespace MeshLib
12{
13std::vector<MeshLib::Element*> getMeshElementsForMaterialIDs(
14 MeshLib::Mesh const& mesh, std::vector<int> const& selected_material_ids)
15{
16 auto const material_ids = *materialIDs(mesh);
17 auto const& elements = mesh.getElements();
18 std::vector<MeshLib::Element*> selected_elements;
19
20 for (std::size_t i = 0; i < material_ids.size(); ++i)
21 {
22 if (ranges::contains(selected_material_ids, material_ids[i]))
23 {
24 selected_elements.push_back(elements[i]);
25 }
26 }
27 return selected_elements;
28}
29} // namespace MeshLib
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:100
std::vector< MeshLib::Element * > getMeshElementsForMaterialIDs(MeshLib::Mesh const &mesh, std::vector< int > const &selected_material_ids)
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition Mesh.cpp:258