27 std::string
const& property_name,
28 int const old_value,
int const new_value,
29 bool replace_if_exists)
37 catch (std::runtime_error
const& e)
39 ERR(
"{:s}", e.what());
43 const std::size_t n_property_tuples(
46 if (!replace_if_exists)
48 for (std::size_t i = 0; i < n_property_tuples; ++i)
50 if ((*property_value_vec)[i] == new_value)
53 "ElementValueModification::replaceElementValue() - "
54 "Replacement value '{:d}' is already taken, no changes "
62 for (std::size_t i = 0; i < n_property_tuples; ++i)
64 if ((*property_value_vec)[i] == old_value)
66 (*property_value_vec)[i] = new_value;
75 bool replace_if_exists)
77 return replace(mesh,
"MaterialIDs", old_value, new_value,
89 catch (std::runtime_error
const& e)
91 ERR(
"{:s}", e.what());
95 std::vector<int> value_mapping(
98 std::vector<int> reverse_mapping(value_mapping.back() + 1, 0);
99 std::size_t
const nValues(value_mapping.size());
100 for (std::size_t i = 0; i < nValues; ++i)
102 reverse_mapping[value_mapping[i]] = i;
105 std::size_t
const n_property_values(property_value_vector->
size());
106 for (std::size_t i = 0; i < n_property_values; ++i)
108 (*property_value_vector)[i] =
109 reverse_mapping[(*property_value_vector)[i]];
125 catch (std::runtime_error
const& e)
127 ERR(
"{:s}", e.what());
131 std::vector<MeshLib::Element*>
const& elements(mesh.
getElements());
133 for (std::size_t k(0); k < elements.size(); k++)
135 if (elements[k]->getGeomType() != ele_type)
139 (*property_value_vector)[k] = new_value;
Definition of the ElementValueModification class.
Definition of the Element class.
void ERR(char const *fmt, Args const &... args)
void WARN(char const *fmt, Args const &... args)
Definition of the Mesh class.
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::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Properties & getProperties()
PropertyVector< T > const * getPropertyVector(std::string const &name) const
std::size_t getNumberOfTuples() const
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.