Salome HOME
Copyright update 2022
[modules/smesh.git] / src / SMESHUtils / SMESH_Delaunay.cxx
index e2a4a99b6eedbddc9f205e4b2823178d1ee8d421..70890775ca0c570653625cec326ac07526e567be 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  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
@@ -225,11 +225,8 @@ const BRepMesh_Triangle* SMESH_Delaunay::FindTriangle( const gp_XY&
     gp_XY seg = uv - gc;
 
     tria->Edges( linkIDs, ori );
-#if OCC_VERSION_LARGE <= 0x07030000
-    int triaID = _triaDS->IndexOf( *tria );
-#else
-    int triaID = tria - & ( _triaDS->GetElement( 0 ));
-#endif
+
+    const BRepMesh_Triangle* prevTria = tria;
     tria = 0;
 
     for ( int i = 0; i < 3; ++i )
@@ -252,7 +249,9 @@ const BRepMesh_Triangle* SMESH_Delaunay::FindTriangle( const gp_XY&
       double uSeg = ( uv1 - gc ) ^ lin / crossSegLin;
       if ( 0. <= uSeg && uSeg <= 1. )
       {
-        tria = & _triaDS->GetElement( triIDs.Index( 1 + ( triIDs.Index(1) == triaID )));
+        tria = & _triaDS->GetElement( triIDs.Index( 1 ));
+        if ( tria == prevTria )
+          tria = & _triaDS->GetElement( triIDs.Index( 2 ));
         if ( tria->Movability() != BRepMesh_Deleted )
           break;
       }
@@ -274,7 +273,7 @@ const BRepMesh_Triangle* SMESH_Delaunay::GetTriangleNear( int iBndNode )
   if ( iBndNode >= _triaDS->NbNodes() )
     return 0;
   int nodeIDs[3];
-  int nbNbNodes = _bndNodes.size();
+  int nbBndNodes = _bndNodes.size();
 #if OCC_VERSION_LARGE <= 0x07030000
   typedef BRepMesh::ListOfInteger TLinkList;
 #else
@@ -290,9 +289,9 @@ const BRepMesh_Triangle* SMESH_Delaunay::GetTriangleNear( int iBndNode )
       if ( tria.Movability() != BRepMesh_Deleted )
       {
         _triaDS->ElementNodes( tria, nodeIDs );
-        if ( nodeIDs[0]-1 < nbNbNodes &&
-             nodeIDs[1]-1 < nbNbNodes &&
-             nodeIDs[2]-1 < nbNbNodes )
+        if ( nodeIDs[0]-1 < nbBndNodes &&
+             nodeIDs[1]-1 < nbBndNodes &&
+             nodeIDs[2]-1 < nbBndNodes )
           return &tria;
       }
     }
@@ -302,9 +301,9 @@ const BRepMesh_Triangle* SMESH_Delaunay::GetTriangleNear( int iBndNode )
       if ( tria.Movability() != BRepMesh_Deleted )
       {
         _triaDS->ElementNodes( tria, nodeIDs );
-        if ( nodeIDs[0]-1 < nbNbNodes &&
-             nodeIDs[1]-1 < nbNbNodes &&
-             nodeIDs[2]-1 < nbNbNodes )
+        if ( nodeIDs[0]-1 < nbBndNodes &&
+             nodeIDs[1]-1 < nbBndNodes &&
+             nodeIDs[2]-1 < nbBndNodes )
           return &tria;
       }
     }
@@ -374,19 +373,34 @@ void SMESH_Delaunay::ToPython() const
   }
 
   int nodeIDs[3];
+  const char* dofName[] = { "Free",
+                            "InVolume",
+                            "OnSurface",
+                            "OnCurve",
+                            "Fixed",
+                            "Frontier",
+                            "Deleted" };
+  text << "# nb elements = " << _triaDS->NbElements() << endl;
+  std::vector< int > deletedElems;
   for ( int i = 0; i < _triaDS->NbElements(); ++i )
   {
     const BRepMesh_Triangle& t = _triaDS->GetElement( i+1 );
     if ( t.Movability() == BRepMesh_Deleted )
-      continue;
+      deletedElems.push_back( i+1 );
+    //   continue;
     _triaDS->ElementNodes( t, nodeIDs );
-    text << "mesh.AddFace([ " << nodeIDs[0] << ", " << nodeIDs[1] << ", " << nodeIDs[2] << " ])" << endl;
+    text << "mesh.AddFace([ " << nodeIDs[0] << ", " << nodeIDs[1] << ", " << nodeIDs[2] << " ]) # "
+         <<  dofName[ t.Movability() ] << endl;
   }
+  text << "mesh.MakeGroupByIds( 'deleted elements', SMESH.FACE, [";
+  for ( int id : deletedElems )
+    text << id << ",";
+  text << "])" << endl;
 
   const char* fileName = "/tmp/Delaunay.py";
   SMESH_File file( fileName, false );
   file.remove();
   file.openForWriting();
   file.write( text.c_str(), text.size() );
-  cout << "exec(open('" << fileName << "', 'rb').read())";
+  std::cout << "exec(open('" << fileName << "', 'rb').read())";
 }