From 2df9acc444db05836aff600878bdfb5191a3223a Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Fri, 16 Dec 2016 20:44:51 +0000 Subject: [PATCH] re-index mesh vertices before removing duplicates: this allows to cleanup meshes that have nodes with identical ids ("getNum()") --- Geo/GModel.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index efda18dc84..62fd2b14c3 100644 --- a/Geo/GModel.cpp +++ b/Geo/GModel.cpp @@ -1738,6 +1738,18 @@ int GModel::removeDuplicateMeshVertices(double tolerance) std::vector<GEntity*> entities; getEntities(entities); + // re-index all vertices (don't use MVertex::getNum(), as we want to be able + // to remove diplicate vertices from "incorrect" meshes, where vertices with + // the same number are duplicated) + int n = 0; + for(unsigned int i = 0; i < entities.size(); i++){ + GEntity* ge = entities[i]; + for(unsigned int j = 0; j < ge->mesh_vertices.size(); j++){ + MVertex *v = ge->mesh_vertices[j]; + v->setIndex(++n); + } + } + MVertexRTree pos(eps); std::map<int, MVertex*> vertices; std::map<MVertex*,MVertex*> duplicates; @@ -1749,7 +1761,7 @@ int GModel::removeDuplicateMeshVertices(double tolerance) if(v2) duplicates[v] = v2; // v should be removed else - vertices[v->getNum()] = v; + vertices[v->getIndex()] = v; } } -- GitLab