From 52c96e0d3124ecf7617ab27cb2ca475f11b15308 Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Mon, 13 Apr 2015 14:02:54 +0200
Subject: [PATCH] [MeL/ME] ElemValMod: condense() using PropertyVector().

---
 .../MeshEditing/ElementValueModification.cpp  | 26 ++++++++++++++-----
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/MeshLib/MeshEditing/ElementValueModification.cpp b/MeshLib/MeshEditing/ElementValueModification.cpp
index 6f54233b804..acefe0d011c 100644
--- a/MeshLib/MeshEditing/ElementValueModification.cpp
+++ b/MeshLib/MeshEditing/ElementValueModification.cpp
@@ -77,16 +77,30 @@ bool ElementValueModification::replace(MeshLib::Mesh &mesh, unsigned old_value,
 
 unsigned ElementValueModification::condense(MeshLib::Mesh &mesh)
 {
-	std::vector<unsigned> value_mapping (ElementValueModification::getMeshValues(mesh));
-	std::vector<unsigned> reverse_mapping(value_mapping.back()+1, 0);
+	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);
 	const unsigned nValues (value_mapping.size());
 	for (unsigned i=0; i<nValues; ++i)
 		reverse_mapping[value_mapping[i]] = i;
 
-	const std::size_t nElements (mesh.getNElements());
-	std::vector<MeshLib::Element*> &elements (const_cast<std::vector<MeshLib::Element*>&>(mesh.getElements()));
-	for (unsigned i=0; i<nElements; ++i)
-		elements[i]->setValue(reverse_mapping[elements[i]->getValue()]);
+	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;
 }
-- 
GitLab