/** * \file * \author Karsten Rink * \date 2013-04-04 * \brief Definition of the ElementValueModification class * * \copyright * Copyright (c) 2012-2023, OpenGeoSys Community (http://www.opengeosys.org) * Distributed under a Modified BSD License. * See accompanying file LICENSE.txt or * http://www.opengeosys.org/project/license * */ #pragma once #include #include "MeshLib/MeshEnums.h" #include "MeshLib/Mesh.h" namespace MeshLib { // forward declarations class Mesh; template class PropertyVector; /** * \brief A set of methods for manipulating mesh element values */ class ElementValueModification { public: /// Reduces the values assigned the elements of mesh to the smallest possible range. /// Returns the number of different values. static std::size_t condense(MeshLib::Mesh &mesh); /// Replaces for all elements of mesh with the value old_value with new_value if possible. /// Returns true if successful or false if the value is already taken. static bool replace(MeshLib::Mesh &mesh, int const old_value, int const new_value, bool replace_if_exists = false); static bool replace(MeshLib::Mesh &mesh, std::string const& property_name, int const old_value, int const new_value, bool replace_if_exists = false); /// Sets new value for all elements having the given element type /// Returns the number of elements having the given element type static std::size_t setByElementType(MeshLib::Mesh &mesh, MeshElemType ele_type, int const new_value); private: /// Returns sorted values of properties within the PropertyVector /// These values are stored in a vector. template static std::vector getSortedPropertyValues( MeshLib::PropertyVector const& property_vector) { std::vector value_mapping; const std::size_t n_property_values(property_vector.size()); for (std::size_t i=0; i