Skip to content
Snippets Groups Projects
Commit 63f6dd3e authored by Matti Pellika's avatar Matti Pellika
Browse files

Strict switch for getMeshElementsByCoord -function. Added an indication of the...

Strict switch for getMeshElementsByCoord -function. Added an indication of the origin in the figure of MLine.

parent 251dd10f
No related branches found
No related tags found
No related merge requests found
......@@ -743,13 +743,13 @@ MElement *GModel::getMeshElementByCoord(SPoint3 &p, int dim, bool strict)
return _octree->find(p.x(), p.y(), p.z(), dim, strict);
}
std::vector<MElement*> GModel::getMeshElementsByCoord(SPoint3 &p, int dim)
std::vector<MElement*> GModel::getMeshElementsByCoord(SPoint3 &p, int dim, bool strict)
{
if(!_octree){
Msg::Debug("Rebuilding mesh element octree");
_octree = new MElementOctree(this);
}
return _octree->findAll(p.x(), p.y(), p.z(), dim);
return _octree->findAll(p.x(), p.y(), p.z(), dim, strict);
}
MVertex *GModel::getMeshVertexByTag(int n)
......
......@@ -313,7 +313,7 @@ class GModel
// access a mesh element by coordinates (using an octree search)
MElement *getMeshElementByCoord(SPoint3 &p, int dim=-1, bool strict=true);
std::vector<MElement*> getMeshElementsByCoord(SPoint3 &p, int dim=-1);
std::vector<MElement*> getMeshElementsByCoord(SPoint3 &p, int dim=-1, bool strict=true);
// access a mesh element by tag, using the element cache
MElement *getMeshElementByTag(int n);
......
......@@ -123,8 +123,11 @@ MElementOctree::~MElementOctree()
}
std::vector<MElement *> MElementOctree::findAll(double x, double y, double z, int dim)
std::vector<MElement *> MElementOctree::findAll(double x, double y, double z, int dim, bool strict)
{
double maxTol = 1.;
double tolIncr = 10.;
double P[3] = {x, y, z};
std::vector<void*> v;
std::vector<MElement*> e;
......@@ -134,6 +137,53 @@ std::vector<MElement *> MElementOctree::findAll(double x, double y, double z, in
MElement *el = (MElement*) *it;
if (dim == -1 || el->getDim() == dim)e.push_back(el);
}
if (e.empty() && !strict && _gm) {
double initialTol = MElement::getTolerance();
double tol = initialTol;
while (tol < maxTol){
tol *= tolIncr;
MElement::setTolerance(tol);
std::vector<GEntity*> entities;
_gm->getEntities(entities);
for(unsigned int i = 0; i < entities.size(); i++){
for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){
MElement* el = entities[i]->getMeshElement(j);
if (dim == -1 || el->getDim() == dim){
if (MElementInEle(el, P)){
e.push_back(el);
}
}
}
}
if(!e.empty()) {
MElement::setTolerance(initialTol);
return e;
}
}
MElement::setTolerance(initialTol);
}
else if (e.empty() && !strict && !_gm){
double initialTol = MElement::getTolerance();
double tol = initialTol;
while (tol < maxTol){
tol *= tolIncr;
MElement::setTolerance(tol);
for(unsigned int i = 0; i < _elems.size(); i++){
MElement* el = _elems[i];
if (dim == -1 || el->getDim() == dim){
if (MElementInEle(el, P)){
e.push_back(el);
}
}
}
if(!e.empty()) {
MElement::setTolerance(initialTol);
return e;
}
}
MElement::setTolerance(initialTol);
//Msg::Warning("Point %g %g %g not found",x,y,z);
}
return e;
}
......
......@@ -23,7 +23,7 @@ class MElementOctree{
~MElementOctree();
MElement *find(double x, double y, double z, int dim = -1, bool strict = false);
Octree *getInternalOctree(){ return _octree; }
std::vector<MElement *> findAll(double x, double y, double z, int dim);
std::vector<MElement *> findAll(double x, double y, double z, int dim, bool strict = false);
};
#endif
......@@ -11,7 +11,7 @@
/*
* MLine
*
* 0----------1 --> u
* 0-----+-----1 --> u
*
*/
class MLine : public MElement {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment