Salome HOME
23080: [CEA 1497] Do not merge a middle node in quadratic with the extreme nodes...
[modules/smesh.git] / src / SMESHUtils / SMESH_OctreeNode.cxx
index 31c6ba660cebe8d1a4ab9de08c3bf82e74f16b23..772a50f99f1a2504c640beaf9039ed2950a0cbdf 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -30,6 +30,7 @@
 #include "SMESH_OctreeNode.hxx"
 
 #include "SMDS_SetIterator.hxx"
+#include "SMESH_TypeDefs.hxx"
 #include <gp_Pnt.hxx>
 
 using namespace std;
@@ -167,7 +168,7 @@ void SMESH_OctreeNode::NodesAround (const SMDS_MeshNode * Node,
                                     list<const SMDS_MeshNode*>* Result,
                                     const double precision)
 {
-  gp_XYZ p(Node->X(), Node->Y(), Node->Z());
+  SMESH_TNodeXYZ p(Node);
   if (isInside(p, precision))
   {
     if (isLeaf())
@@ -191,7 +192,7 @@ void SMESH_OctreeNode::NodesAround (const SMDS_MeshNode * Node,
  *  \param node - node to find nodes closest to
  *  \param dist2Nodes - map of found nodes and their distances
  *  \param precision - radius of a sphere to check nodes inside
- *  \retval bool - true if an exact overlapping found
+ *  \retval bool - true if an exact overlapping found !!!
  */
 //================================================================================
 
@@ -204,7 +205,6 @@ bool SMESH_OctreeNode::NodesAround(const gp_XYZ &node,
   else if ( precision == 0. )
     precision = maxSize() / 2;
 
-  //gp_XYZ p(node->X(), node->Y(), node->Z());
   if (isInside(node, precision))
   {
     if (!isLeaf())
@@ -223,19 +223,19 @@ bool SMESH_OctreeNode::NodesAround(const gp_XYZ &node,
     else if ( NbNodes() > 0 )
     {
       double minDist = precision * precision;
-      gp_Pnt p1 ( node.X(), node.Y(), node.Z() );
       TIDSortedNodeSet::iterator nIt = myNodes.begin();
       for ( ; nIt != myNodes.end(); ++nIt )
       {
-        gp_Pnt p2 ( (*nIt)->X(), (*nIt)->Y(), (*nIt)->Z() );
-        double dist2 = p1.SquareDistance( p2 );
+        SMESH_TNodeXYZ p2( *nIt );
+        double dist2 = ( node - p2 ).SquareModulus();
         if ( dist2 < minDist )
-          dist2Nodes.insert( make_pair( minDist = dist2, *nIt ));
+          dist2Nodes.insert( make_pair( minDist = dist2, p2._node ));
       }
 //       if ( dist2Nodes.size() > 1 ) // leave only closest node in dist2Nodes
 //         dist2Nodes.erase( ++dist2Nodes.begin(), dist2Nodes.end());
 
-      return ( sqrt( minDist) <= precision * ( 1 + 1e-12 ));
+      // true if an exact overlapping found
+      return ( sqrt( minDist ) <= precision * 1e-12 );
     }
   }
   return false;
@@ -275,42 +275,33 @@ void SMESH_OctreeNode::FindCoincidentNodes (TIDSortedNodeSet& theSetOfNodes,
  * \param theGroupsOfNodes - list of nodes closed to each other returned
  */
 //=============================
-void SMESH_OctreeNode::FindCoincidentNodes ( TIDSortedNodeSet* theSetOfNodes,
-                                             const double               theTolerance,
+void SMESH_OctreeNode::FindCoincidentNodes ( TIDSortedNodeSet*                    theSetOfNodes,
+                                             const double                         theTolerance,
                                              list< list< const SMDS_MeshNode*> >* theGroupsOfNodes)
 {
   TIDSortedNodeSet::iterator it1 = theSetOfNodes->begin();
   list<const SMDS_MeshNode*>::iterator it2;
 
+  list<const SMDS_MeshNode*> ListOfCoincidentNodes;
+  TIDCompare idLess;
+
   while (it1 != theSetOfNodes->end())
   {
     const SMDS_MeshNode * n1 = *it1;
 
-    list<const SMDS_MeshNode*> ListOfCoincidentNodes;// Initialize the lists via a declaration, it's enough
-
-    list<const SMDS_MeshNode*> * groupPtr = 0;
-
     // Searching for Nodes around n1 and put them in ListofCoincidentNodes.
     // Found nodes are also erased from theSetOfNodes
     FindCoincidentNodes(n1, theSetOfNodes, &ListOfCoincidentNodes, theTolerance);
 
-    // We build a list {n1 + his neigbours} and add this list in theGroupsOfNodes
-    for (it2 = ListOfCoincidentNodes.begin(); it2 != ListOfCoincidentNodes.end(); it2++)
+    if ( !ListOfCoincidentNodes.empty() )
     {
-      const SMDS_MeshNode* n2 = *it2;
-      if ( !groupPtr )
-      {
-        theGroupsOfNodes->push_back( list<const SMDS_MeshNode*>() );
-        groupPtr = & theGroupsOfNodes->back();
-        groupPtr->push_back( n1 );
-      }
-      if (groupPtr->front() > n2)
-        groupPtr->push_front( n2 );
-      else
-        groupPtr->push_back( n2 );
+      // We build a list {n1 + his neigbours} and add this list in theGroupsOfNodes
+      if ( idLess( n1, ListOfCoincidentNodes.front() )) ListOfCoincidentNodes.push_front( n1 );
+      else                                              ListOfCoincidentNodes.push_back ( n1 );
+      ListOfCoincidentNodes.sort( idLess );
+      theGroupsOfNodes->push_back( list<const SMDS_MeshNode*>() );
+      theGroupsOfNodes->back().splice( theGroupsOfNodes->back().end(), ListOfCoincidentNodes );
     }
-    if (groupPtr != 0)
-      groupPtr->sort();
 
     theSetOfNodes->erase(it1);
     it1 = theSetOfNodes->begin();