std::size_t ElementValueModification::condense(MeshLib::Mesh &mesh)
{
    boost::optional<MeshLib::PropertyVector<int> &>
        optional_property_value_vec(
            mesh.getProperties().getPropertyVector<int>("MaterialIDs")
        );

    if (!optional_property_value_vec) {
        return 0;
    }

    MeshLib::PropertyVector<int> & property_value_vector(
        optional_property_value_vec.get()
    );
    std::vector<int> value_mapping(
        getSortedPropertyValues(property_value_vector)
    );

    std::vector<int> reverse_mapping(value_mapping.back()+1, 0);
    std::size_t const nValues (value_mapping.size());
    for (std::size_t i=0; i<nValues; ++i)
        reverse_mapping[value_mapping[i]] = i;

    std::size_t const n_property_values(property_value_vector.size());
    for (std::size_t i=0; i<n_property_values; ++i)
        property_value_vector[i] = reverse_mapping[property_value_vector[i]];

    return nValues;
}
std::size_t ElementValueModification::condense(MeshLib::Mesh &mesh)
{
    auto* property_value_vector =
        mesh.getProperties().getPropertyVector<int>("MaterialIDs");

    if (!property_value_vector)
    {
        return 0;
    }

    std::vector<int> value_mapping(
        getSortedPropertyValues(*property_value_vector));

    std::vector<int> reverse_mapping(value_mapping.back()+1, 0);
    std::size_t const nValues (value_mapping.size());
    for (std::size_t i=0; i<nValues; ++i)
        reverse_mapping[value_mapping[i]] = i;

    std::size_t const n_property_values(property_value_vector->size());
    for (std::size_t i = 0; i < n_property_values; ++i)
        (*property_value_vector)[i] =
            reverse_mapping[(*property_value_vector)[i]];

    return nValues;
}
std::size_t ElementValueModification::condense(MeshLib::Mesh &mesh)
{
    MeshLib::PropertyVector<int>* property_value_vector = nullptr;
    try
    {
        property_value_vector = mesh.getProperties().getPropertyVector<int>(
            "MaterialIDs", MeshLib::MeshItemType::Cell, 1);
    }
    catch (std::runtime_error const& e)
    {
        ERR("%s", e.what());
        return 0;
    }

    std::vector<int> value_mapping(
        getSortedPropertyValues(*property_value_vector));

    std::vector<int> reverse_mapping(value_mapping.back() + 1, 0);
    std::size_t const nValues(value_mapping.size());
    for (std::size_t i = 0; i < nValues; ++i)
    {
        reverse_mapping[value_mapping[i]] = i;
    }

    std::size_t const n_property_values(property_value_vector->size());
    for (std::size_t i = 0; i < n_property_values; ++i)
    {
        (*property_value_vector)[i] =
            reverse_mapping[(*property_value_vector)[i]];
    }

    return nValues;
}