Salome HOME
Fix MinDistance for node-group (SALOME_TESTS/Grids/smesh/imps_09/K0)
[modules/smesh.git] / src / SMESHUtils / SMESH_MeshAlgos.cxx
index 55c5f50253bed26288668235f25414c9e26e4549..a2c9c10368fe357f5ee0c6011b6ac255774f8ff5 100644 (file)
@@ -238,6 +238,7 @@ namespace // Utils used in SMESH_ElementSearcherImpl::FindElementsByPoint()
     void getElementsInBox    ( const Bnd_B3d& box,  TElemSeq& foundElems );
     void getElementsInSphere ( const gp_XYZ& center, const double radius, TElemSeq& foundElems );
     ElementBndBoxTree* getLeafAtPoint( const gp_XYZ& point );
     void getElementsInBox    ( const Bnd_B3d& box,  TElemSeq& foundElems );
     void getElementsInSphere ( const gp_XYZ& center, const double radius, TElemSeq& foundElems );
     ElementBndBoxTree* getLeafAtPoint( const gp_XYZ& point );
+    int  getNbElements();
 
   protected:
     ElementBndBoxTree() {}
 
   protected:
     ElementBndBoxTree() {}
@@ -466,6 +467,27 @@ namespace // Utils used in SMESH_ElementSearcherImpl::FindElementsByPoint()
     return 0;
   }
 
     return 0;
   }
 
+  //================================================================================
+  /*!
+   * \brief Return number of elements
+   */
+  //================================================================================
+
+  int ElementBndBoxTree::getNbElements()
+  {
+    int nb = 0;
+    if ( isLeaf() )
+    {
+      nb = _elements.size();
+    }
+    else
+    {
+      for (int i = 0; i < 8; i++)
+        nb += ((ElementBndBoxTree*) myChildren[i])->getNbElements();
+    }
+    return nb;
+  }
+
   //================================================================================
   /*!
    * \brief Construct the element box
   //================================================================================
   /*!
    * \brief Construct the element box
@@ -1302,6 +1324,23 @@ gp_XYZ SMESH_ElementSearcherImpl::Project(const gp_Pnt&            point,
       minDist = d;
     }
   }
       minDist = d;
     }
   }
+  if ( minDist > radius )
+  {
+    ElementBndBoxTree::TElemSeq elems2;
+    ebbTree->getElementsInSphere( p, minDist, elems2 );
+    for ( e = elems2.begin(); e != elems2.end(); ++e )
+    {
+      if ( elems.count( *e ))
+        continue;
+      double d = SMESH_MeshAlgos::GetDistance( *e, point, &proj );
+      if ( d < minDist )
+      {
+        bestProj = proj;
+        elem = *e;
+        minDist = d;
+      }
+    }
+  }
   if ( closestElem ) *closestElem = elem;
 
   return bestProj;
   if ( closestElem ) *closestElem = elem;
 
   return bestProj;