OGS
ElementValueModification.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <vector>
7
8#include "MeshLib/Mesh.h"
9#include "MeshLib/MeshEnums.h"
10
11namespace MeshLib
12{
13// forward declarations
14class Mesh;
15template <typename T>
16class PropertyVector;
17} // namespace MeshLib
18
19namespace MeshToolsLib
20{
21
26{
27public:
30 static std::size_t condense(MeshLib::Mesh& mesh);
31
35 static bool replace(MeshLib::Mesh& mesh, int const old_value,
36 int const new_value, bool replace_if_exists = false);
37
38 static bool replace(MeshLib::Mesh& mesh, std::string const& property_name,
39 int const old_value, int const new_value,
40 bool replace_if_exists = false);
41
44 static std::size_t setByElementType(MeshLib::Mesh& mesh,
45 MeshLib::MeshElemType ele_type,
46 int const new_value);
47
48private:
51 template <typename T>
52 static std::vector<T> getSortedPropertyValues(
53 MeshLib::PropertyVector<T> const& property_vector)
54 {
55 std::vector<T> value_mapping;
56 const std::size_t n_property_values(property_vector.size());
57 for (std::size_t i = 0; i < n_property_values; ++i)
58 {
59 bool exists(false);
60 T const& value(property_vector[i]);
61 std::size_t const size(value_mapping.size());
62 for (std::size_t j = 0; j < size; ++j)
63 {
64 if (value == value_mapping[j])
65 {
66 exists = true;
67 break;
68 }
69 }
70 if (!exists)
71 {
72 value_mapping.push_back(value);
73 }
74 }
75
76 std::sort(value_mapping.begin(), value_mapping.end());
77 return value_mapping;
78 }
79};
80
81} // namespace MeshToolsLib
constexpr std::size_t size() const
A set of methods for manipulating mesh element values.
static std::vector< T > getSortedPropertyValues(MeshLib::PropertyVector< T > const &property_vector)
static std::size_t setByElementType(MeshLib::Mesh &mesh, MeshLib::MeshElemType ele_type, int const new_value)
static bool replace(MeshLib::Mesh &mesh, int const old_value, int const new_value, bool replace_if_exists=false)
static std::size_t condense(MeshLib::Mesh &mesh)
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition MeshEnums.h:37