OGS
ElementValueModification.h
Go to the documentation of this file.
1 
15 #pragma once
16 
17 #include <vector>
18 
19 #include "MeshLib/MeshEnums.h"
20 #include "MeshLib/Mesh.h"
21 
22 namespace MeshLib {
23 // forward declarations
24 class Mesh;
25 template <typename T>
26 class PropertyVector;
27 
32 {
33 public:
36  static std::size_t condense(MeshLib::Mesh &mesh);
37 
40  static bool replace(MeshLib::Mesh &mesh, int const old_value, int const new_value, bool replace_if_exists = false);
41 
42  static bool replace(MeshLib::Mesh &mesh, std::string const& property_name,
43  int const old_value, int const new_value, bool replace_if_exists = false);
44 
47  static std::size_t setByElementType(MeshLib::Mesh &mesh, MeshElemType ele_type, int const new_value);
48 
49 private:
52  template <typename T>
53  static std::vector<T> getSortedPropertyValues(
54  MeshLib::PropertyVector<T> const& property_vector)
55  {
56  std::vector<T> value_mapping;
57  const std::size_t n_property_values(property_vector.size());
58  for (std::size_t i=0; i<n_property_values; ++i) {
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  if (value == value_mapping[j]) {
64  exists = true;
65  break;
66  }
67  }
68  if (!exists)
69  {
70  value_mapping.push_back(value);
71  }
72  }
73 
74  std::sort(value_mapping.begin(), value_mapping.end());
75  return value_mapping;
76  }
77 
78 };
79 
80 } // end namespace MeshLib
Definition of mesh-related Enumerations.
Definition of the Mesh class.
A set of methods for manipulating mesh element values.
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)
static std::size_t setByElementType(MeshLib::Mesh &mesh, MeshElemType ele_type, int const new_value)
static std::vector< T > getSortedPropertyValues(MeshLib::PropertyVector< T > const &property_vector)
std::size_t size() const
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition: MeshEnums.h:27