From e05104f52184cd1559d297fc255168e6d4ad6093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mirko=20W=C3=A4chter?= <mirko.waechter@kit.edu> Date: Mon, 12 Aug 2019 12:11:14 +0200 Subject: [PATCH] restored wrong code cleanup --- VirtualRobot/Visualization/TriMeshModel.cpp | 28 ++++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/VirtualRobot/Visualization/TriMeshModel.cpp b/VirtualRobot/Visualization/TriMeshModel.cpp index 1762dde0c..4492d57b0 100644 --- a/VirtualRobot/Visualization/TriMeshModel.cpp +++ b/VirtualRobot/Visualization/TriMeshModel.cpp @@ -276,11 +276,26 @@ namespace VirtualRobot return static_cast<unsigned int>(counter); } - unsigned int TriMeshModel::addMissingColors(const VisualizationFactory::Color& /*color*/) + unsigned int TriMeshModel::addMissingColors(const VisualizationFactory::Color& color) { mergeVertices(); int counter = 0; + auto getAndAddColorId = [&](unsigned int vertexId) + { + for(auto& face : faces) + { + if(face.id1 == vertexId && face.idColor1 != UINT_MAX) + return face.idColor1; + if(face.id2 == vertexId && face.idColor2 != UINT_MAX) + return face.idColor2; + if(face.id3 == vertexId && face.idColor3 != UINT_MAX) + return face.idColor3; + } + return addColor(color); + }; + + for (auto& face : faces) { if (face.idColor1 != UINT_MAX && face.idColor2 != UINT_MAX && face.idColor3 != UINT_MAX) @@ -288,18 +303,23 @@ namespace VirtualRobot continue; } - if (face.idColor1 == UINT_MAX) + auto colorId = UINT_MAX; + if(face.idColor1 == UINT_MAX) { + colorId = face.idColor1 = getAndAddColorId(face.id1); counter++; } - if (face.idColor2 == UINT_MAX) + if(face.idColor2 == UINT_MAX) { + colorId = face.idColor2 = getAndAddColorId(face.id2); counter++; } - if (face.idColor3 == UINT_MAX) + if(face.idColor3 == UINT_MAX) { + colorId = face.idColor3 = getAndAddColorId(face.id3); counter++; } + } return static_cast<unsigned int>(counter); } -- GitLab