diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index c6ad48039eddcf6d89fe8babdbadb048a456cbae..64326f4fb0dddbfa3e6eb4d61b1439a4dae8ec6f 100644 --- a/Geo/GModel.cpp +++ b/Geo/GModel.cpp @@ -625,13 +625,13 @@ int GModel::getNumMeshElements(unsigned c[5]) return 0; } -MElement *GModel::getMeshElementByCoord(SPoint3 &p) +MElement *GModel::getMeshElementByCoord(SPoint3 &p, int dim) { if(!_octree){ Msg::Debug("Rebuilding mesh element octree"); _octree = new MElementOctree(this); } - return _octree->find(p.x(), p.y(), p.z()); + return _octree->find(p.x(), p.y(), p.z(), dim); } MVertex *GModel::getMeshVertexByTag(int n) diff --git a/Geo/GModel.h b/Geo/GModel.h index e9babea4541088281bc9fb6231d75c3d077e95db..fffd49eec139dc73bb076aae0874cde27b2d4e48 100644 --- a/Geo/GModel.h +++ b/Geo/GModel.h @@ -296,7 +296,7 @@ class GModel int getNumMeshElements(unsigned c[5]); // access a mesh element by coordinates (using an octree search) - MElement *getMeshElementByCoord(SPoint3 &p); + MElement *getMeshElementByCoord(SPoint3 &p, int dim = -1); // access a mesh element by tag, using the element cache MElement *getMeshElementByTag(int n); diff --git a/Geo/MElementOctree.cpp b/Geo/MElementOctree.cpp index a1dd5a13da624cd9c068553f5aeaa84daa64e98b..c74568b7133cb6264e1337e4d4e87e1ece2b934e 100644 --- a/Geo/MElementOctree.cpp +++ b/Geo/MElementOctree.cpp @@ -110,9 +110,19 @@ MElementOctree::~MElementOctree() Octree_Delete(_octree); } -MElement *MElementOctree::find(double x, double y, double z) +MElement *MElementOctree::find(double x, double y, double z, int dim) { double P[3] = {x, y, z}; - return (MElement*)Octree_Search(P, _octree); + MElement *e = (MElement*)Octree_Search(P, _octree); + if (dim == -1 || !e || e->getDim() == dim) + return e; + std::list<void*> l; + Octree_SearchAll (P, _octree, &l); + for (std::list<void*>::iterator it = l.begin(); it != l.end(); it++) { + MElement *el = (MElement*) *it; + if (el->getDim() == dim) + return el; + } + return NULL; } diff --git a/Geo/MElementOctree.h b/Geo/MElementOctree.h index 262fef6fa3933743deb1fba4b9bad7abefb9cbee..112589611f847ed215e9393cc04e10c16d65b3a5 100644 --- a/Geo/MElementOctree.h +++ b/Geo/MElementOctree.h @@ -19,7 +19,7 @@ class MElementOctree{ MElementOctree(GModel *); MElementOctree(std::vector<MElement*> &); ~MElementOctree(); - MElement *find(double x, double y, double z); + MElement *find(double x, double y, double z, int dim = -1); Octree *getInternalOctree(){ return _octree; } };