From 2bcea05710624027763f010c4ac39a8fcf5272c7 Mon Sep 17 00:00:00 2001 From: Van Dung Nguyen <vandung.nguyen@ulg.ac.be> Date: Wed, 12 Feb 2014 10:30:35 +0000 Subject: [PATCH] add a function --- Geo/GModel.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ Geo/GModel.h | 5 ++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index f74a2f55ef..948394586f 100644 --- a/Geo/GModel.cpp +++ b/Geo/GModel.cpp @@ -815,6 +815,50 @@ MVertex *GModel::getMeshVertexByTag(int n) return _vertexMapCache[n]; } +MVertex* GModel::getMeshVertexByCoordinates(double x, double y, double z, double tol){ + if(_vertexVectorCache.empty() && _vertexMapCache.empty()){ + Msg::Debug("Rebuilding mesh vertex cache"); + _vertexVectorCache.clear(); + _vertexMapCache.clear(); + bool dense = (getNumMeshVertices() == _maxVertexNum); + std::vector<GEntity*> entities; + getEntities(entities); + if(dense){ + Msg::Debug("Good: we have a dense vertex numbering in the cache"); + // numbering starts at 1 + _vertexVectorCache.resize(_maxVertexNum + 1); + for(unsigned int i = 0; i < entities.size(); i++) + for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) + _vertexVectorCache[entities[i]->mesh_vertices[j]->getNum()] = + entities[i]->mesh_vertices[j]; + } + else{ + for(unsigned int i = 0; i < entities.size(); i++) + for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++) + _vertexMapCache[entities[i]->mesh_vertices[j]->getNum()] = + entities[i]->mesh_vertices[j]; + } + } + + for (int i=1; i< _vertexVectorCache.size(); i++){ + MVertex* v = _vertexVectorCache[i]; + double l = sqrt((v->x() -x)*(v->x()-x)+ (v->y()-y)*(v->y()-y)+ (v->z()-z)*(v->z()-z)); + if (l<tol) return v; + }; + + for (std::map<int,MVertex*>::iterator it = _vertexMapCache.begin(); it!= _vertexMapCache.end(); it++){ + MVertex* v = it->second; + double l = sqrt((v->x() -x)*(v->x()-x)+ (v->y()-y)*(v->y()-y)+ (v->z()-z)*(v->z()-z)); + if (l<tol) return v; + }; + + MVertex* v = new MVertex(x,y,z); + _vertexVectorCache.push_back(v); + _vertexMapCache[v->getNum()] = v; + + return v; +}; + void GModel::getMeshVerticesForPhysicalGroup(int dim, int num, std::vector<MVertex*> &v) { v.clear(); diff --git a/Geo/GModel.h b/Geo/GModel.h index 6bbd50bbea..6b1f52917f 100644 --- a/Geo/GModel.h +++ b/Geo/GModel.h @@ -371,7 +371,10 @@ class GModel // access a mesh vertex by tag, using the vertex cache MVertex *getMeshVertexByTag(int n); - + + // get a mesh vertex by coordinate, using the vertex cache + MVertex *getMeshVertexByCoordinates(double x, double y, double z, double tol); + // get all the mesh vertices associated with the physical group // of dimension "dim" and id number "num" void getMeshVerticesForPhysicalGroup(int dim, int num, std::vector<MVertex*> &); -- GitLab