From a5dcf0fb45ec0dca60e78788939602b8ad9498ac Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Mon, 10 Dec 2012 15:51:44 +0000 Subject: [PATCH] don't renumber vertices in MSH3 (should provide an option to control this) --- Geo/GModel.cpp | 18 ++++++++++++------ Geo/GModel.h | 2 +- Geo/GModelIO_MSH.cpp | 6 +++++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index 9a5f5b50fe..3861232d2c 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 969d7bb1d2..495677bfc0 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 b3ca1d9d1d..f3cbf318ff 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; -- GitLab