Salome HOME
Copyright update 2021
[modules/smesh.git] / src / StdMeshers / StdMeshers_Import_1D2D.cxx
index 949bd3a9073214bc786d6affa7d1840c79e433c3..727b1af8060d943e35d1acf096938c1ee916eed6 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  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
@@ -40,6 +40,7 @@
 #include "SMESH_Mesh.hxx"
 #include "SMESH_MesherHelper.hxx"
 #include "SMESH_OctreeNode.hxx"
+#include "SMESH_MeshEditor.hxx"
 #include "SMESH_subMesh.hxx"
 
 #include "Utils_SALOME_Exception.hxx"
@@ -48,6 +49,7 @@
 #include <BRepBndLib.hxx>
 #include <BRepClass_FaceClassifier.hxx>
 #include <BRepTools.hxx>
+#include <BRepTopAdaptor_FClass2d.hxx>
 #include <BRep_Builder.hxx>
 #include <BRep_Tool.hxx>
 #include <Bnd_B2d.hxx>
@@ -96,8 +98,8 @@ namespace
  */
 //=============================================================================
 
-StdMeshers_Import_1D2D::StdMeshers_Import_1D2D(int hypId, int studyId, SMESH_Gen * gen)
-  :SMESH_2D_Algo(hypId, studyId, gen), _sourceHyp(0)
+StdMeshers_Import_1D2D::StdMeshers_Import_1D2D(int hypId, SMESH_Gen * gen)
+  :SMESH_2D_Algo(hypId, gen), _sourceHyp(0)
 {
   _name = "Import_1D2D";
   _shapeType = (1 << TopAbs_FACE);
@@ -199,7 +201,8 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape &
   gp_Pnt p; gp_Vec du, dv;
 
   // BRepClass_FaceClassifier is most time consuming, so minimize its usage
-  BRepClass_FaceClassifier classifier;
+  const double clsfTol = 10 * BRep_Tool::Tolerance( geomFace );
+  BRepTopAdaptor_FClass2d classifier( geomFace, clsfTol ); //Brimless_FaceClassifier classifier;
   Bnd_B2d bndBox2d;
   Bnd_Box bndBox3d;
   {
@@ -306,10 +309,12 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape &
     const double groupTol = 0.5 * sqrt( getMinElemSize2( srcGroup ));
     minGroupTol = std::min( groupTol, minGroupTol );
 
+    // clsfTol is 2D tolerance of a probe line
     //GeomAdaptor_Surface S( surface );
     // const double clsfTol = Min( S.UResolution( 0.1 * groupTol ), -- issue 0023092
     //                             S.VResolution( 0.1 * groupTol ));
-    const double clsfTol = BRep_Tool::Tolerance( geomFace );
+    // another idea: try to use max tol of all edges
+    //const double clsfTol = 10 * BRep_Tool::Tolerance( geomFace ); // 0.1 * groupTol;
 
     if ( helper.HasSeam() )
       onEdgeClassifier.SetMesh( srcMesh->GetMeshDS() );
@@ -319,8 +324,7 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape &
     {
       const SMDS_MeshElement* face = srcElems->next();
 
-      SMDS_MeshElement::iterator node = face->begin_nodes();
-      if ( bndBox3d.IsOut( SMESH_TNodeXYZ( *node )))
+      if ( bndBox3d.IsOut( SMESH_NodeXYZ( face->GetNode(0) )))
         continue;
 
       // find or create nodes of a new face
@@ -329,13 +333,14 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape &
       newNodes.back() = 0;
       int nbCreatedNodes = 0;
       bool isOut = false, isIn = false; // if at least one node isIn - do not classify other nodes
-      for ( size_t i = 0; i < newNodes.size(); ++i, ++node )
+      for ( size_t i = 0; i < newNodes.size(); ++i )
       {
-        SMESH_TNodeXYZ nXYZ = *node;
+        const SMDS_MeshNode* node = face->GetNode( i );
+        SMESH_NodeXYZ nXYZ = node;
         nodeState[ i ] = TopAbs_UNKNOWN;
         newNodes [ i ] = 0;
 
-        it_isnew = n2n->insert( make_pair( *node, (SMDS_MeshNode*)0 ));
+        it_isnew = n2n->insert( make_pair( node, nullptr ));
         n2nIt    = it_isnew.first;
 
         const SMDS_MeshNode* & newNode = n2nIt->second;
@@ -349,7 +354,7 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape &
           if ( newNode->GetID() < (int) isNodeIn.size() &&
                isNodeIn[ newNode->GetID() ])
             isIn = true;
-          if ( !isIn && bndNodes.count( *node ))
+          if ( !isIn && bndNodes.count( node ))
             nodeState[ i ] = TopAbs_ON;
         }
         else
@@ -368,15 +373,15 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape &
         {
           // find out if node lies on the surface of theShape
           gp_XY uv( Precision::Infinite(), 0 );
-          isOut = ( !helper.CheckNodeUV( geomFace, *node, uv, groupTol, /*force=*/true ) ||
+          isOut = ( !helper.CheckNodeUV( geomFace, node, uv, groupTol, /*force=*/true ) ||
                     bndBox2d.IsOut( uv ));
           //int iCoo;
           if ( !isOut && !isIn ) // classify
           {
-            classifier.Perform( geomFace, uv, clsfTol );
-            nodeState[i] = classifier.State();
+            nodeState[i] = classifier.Perform( uv ); //classifier.Perform( geomFace, uv, clsfTol );
+            //nodeState[i] = classifier.State();
             isOut = ( nodeState[i] == TopAbs_OUT );
-            if ( isOut && helper.IsOnSeam( uv ) && onEdgeClassifier.IsSatisfy( (*node)->GetID() ))
+            if ( isOut && helper.IsOnSeam( uv ) && onEdgeClassifier.IsSatisfy( node->GetID() ))
             {
               // uv.SetCoord( iCoo, helper.GetOtherParam( uv.Coord( iCoo )));
               // classifier.Perform( geomFace, uv, clsfTol );
@@ -397,7 +402,7 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape &
               isNodeIn.resize( newNode->GetID() + 1, false );
             }
             if ( nodeState[i] == TopAbs_ON )
-              bndNodes.insert( *node );
+              bndNodes.insert( node );
             else if ( nodeState[i] != TopAbs_UNKNOWN )
               isNodeIn[ newNode->GetID() ] = isIn = true;
           }
@@ -417,8 +422,8 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape &
         {
           if ( nodeState[i] != TopAbs_UNKNOWN ) continue;
           gp_XY uv = helper.GetNodeUV( geomFace, newNodes[i] );
-          classifier.Perform( geomFace, uv, clsfTol );
-          nodeState[i] = classifier.State();
+          nodeState[i] = classifier.Perform( uv ); //geomFace, uv, clsfTol );
+          //nodeState[i] = classifier.State();
           isIn = ( nodeState[i] == TopAbs_IN );
         }
         if ( !isIn ) // classify face center
@@ -439,8 +444,9 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape &
           Standard_Real U,V;
           proj.LowerDistanceParameters(U,V);
           gp_XY uv( U,V );
-          classifier.Perform( geomFace, uv, clsfTol );
-          if ( classifier.State() != TopAbs_IN )
+          //classifier.Perform( geomFace, uv, clsfTol );
+          TopAbs_State state = classifier.Perform( uv );
+          if ( state != TopAbs_IN )
             continue;
         }
       }
@@ -581,7 +587,7 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape &
                 if ( Abs(u-f) < 2 * faceTol || Abs(u-l) < 2 * faceTol )
                   // duplicated node on vertex
                   return error("Source elements overlap one another");
-                tgtFaceSM->RemoveNode( n, /*isNodeDeleted=*/false );
+                tgtFaceSM->RemoveNode( n );
                 tgtMesh->SetNodeOnEdge( n, edges[iE], u );
                 break;
               }
@@ -634,7 +640,7 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape &
 
           TopoDS_Edge geomEdge = TopoDS::Edge(bndShapes.back());
           helper.CheckNodeU( geomEdge, link._medium, u, projTol, /*force=*/true );
-          tgtFaceSM->RemoveNode( link._medium, /*isNodeDeleted=*/false );
+          tgtFaceSM->RemoveNode( link._medium );
           tgtMesh->SetNodeOnEdge( (SMDS_MeshNode*)link._medium, geomEdge, u );
         }
         else
@@ -747,7 +753,7 @@ bool StdMeshers_Import_1D2D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape &
           seamHelper.AddEdge( node1, node2 );
           if ( node2->getshapeId() == helper.GetSubShapeID() )
           {
-            tgtFaceSM->RemoveNode( node2, /*isNodeDeleted=*/false );
+            tgtFaceSM->RemoveNode( node2 );
             tgtMesh->SetNodeOnEdge( const_cast<SMDS_MeshNode*>( node2 ), seamEdge, n2->first );
           }
         }