diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index 9a5f5b50fe03bf80cfb18ce2a1934391deb42344..3861232d2c7e72d8f0e9cf81b9bf53704a57d613 100644 --- a/Geo/GModel.cpp +++ b/Geo/GModel.cpp @@ -909,7 +909,7 @@ void GModel::removeInvisibleElements() destroyMeshCaches(); } -int GModel::indexMeshVertices(bool all, int singlePartition) +int GModel::indexMeshVertices(bool all, int singlePartition, bool renumber) { std::vector<GEntity*> entities; getEntities(entities); @@ -940,15 +940,21 @@ int GModel::indexMeshVertices(bool all, int singlePartition) // renumber all the mesh vertices tagged with 0 int numVertices = 0, index = 0; - for(unsigned int i = 0; i < entities.size(); i++) - for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) - if(!entities[i]->mesh_vertices[j]->getIndex()){ + for(unsigned int i = 0; i < entities.size(); i++){ + for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++){ + MVertex *v = entities[i]->mesh_vertices[j]; + if(!v->getIndex()){ index++; numVertices++; - entities[i]->mesh_vertices[j]->setIndex(index); + if(renumber) + v->setIndex(index); + else + v->setIndex(v->getNum()); } - else if(entities[i]->mesh_vertices[j]->getIndex() == -2) + else if(v->getIndex() == -2) index++; + } + } return numVertices; } diff --git a/Geo/GModel.h b/Geo/GModel.h index 969d7bb1d29214f618cfc95ca51c123ac5920842..495677bfc0fc7e2671af098620aef38c1f3cab6b 100644 --- a/Geo/GModel.h +++ b/Geo/GModel.h @@ -342,7 +342,7 @@ class GModel // index all the (used) mesh vertices in a continuous sequence, // starting at 1 - int indexMeshVertices(bool all, int singlePartition=0); + int indexMeshVertices(bool all, int singlePartition=0, bool renumber=true); // scale the mesh by the given factor void scaleMesh(double factor); diff --git a/Geo/GModelIO_MSH.cpp b/Geo/GModelIO_MSH.cpp index b3ca1d9d1d811010b950ed8fcee8e2f945185df4..f3cbf318ffff30da469f5b6ac34260e6752e21fd 100644 --- a/Geo/GModelIO_MSH.cpp +++ b/Geo/GModelIO_MSH.cpp @@ -400,12 +400,16 @@ int GModel::writeMSH(const std::string &name, double version, bool binary, return 0; } + // FIXME: should make this available to users, and should allow to renumber + // elements, too. Renumbering should be disabled by default. + bool renumber = false; + // if there are no physicals we save all the elements if(noPhysicalGroups()) saveAll = true; // get the number of vertices and index the vertices in a continuous // sequence - int numVertices = indexMeshVertices(saveAll, saveSinglePartition); + int numVertices = indexMeshVertices(saveAll, saveSinglePartition, renumber); // get the number of elements we need to save std::vector<GEntity*> entities;