Salome HOME
Try to use length of edges for association in case of a 2-edges wire
authoreap <eap@opencascade.com>
Wed, 10 Oct 2012 10:48:10 +0000 (10:48 +0000)
committereap <eap@opencascade.com>
Wed, 10 Oct 2012 10:48:10 +0000 (10:48 +0000)
src/StdMeshers/StdMeshers_ProjectionUtils.cxx

index d0f29a54bb66dbc9ddebdcd549e4a62baa39bbd4..8d198fe6955d095eab59464a1c4a7757004a94f6 100644 (file)
@@ -1237,6 +1237,7 @@ int StdMeshers_ProjectionUtils::FindFaceAssociation(const TopoDS_Face&    face1,
 {
   bool OK = false;
   list< int > nbEInW1, nbEInW2;
+  list< TopoDS_Edge >::iterator edgeIt;
   int i_ok_wire_algo = -1;
   for ( int outer_wire_algo = 0; outer_wire_algo < 2 && !OK; ++outer_wire_algo )
   {
@@ -1257,7 +1258,6 @@ int StdMeshers_ProjectionUtils::FindFaceAssociation(const TopoDS_Face&    face1,
 
     bool reverse = false;
 
-    list< TopoDS_Edge >::iterator edgeIt;
     if ( !VV1[1].IsSame( TopExp::LastVertex( edges1.front(), true ))) {
       reverse = true;
       edgeIt = --edges1.end();
@@ -1367,6 +1367,27 @@ int StdMeshers_ProjectionUtils::FindFaceAssociation(const TopoDS_Face&    face1,
     }
   }
 
+  const int nbEdges = nbEInW1.front();
+  if ( OK && nbEdges == 2 )
+  {
+    // if a wire includes 2 edges, it's impossible to associate them using
+    // topological information only. Try to use length of edges for association.
+    double l1[2], l2[2];
+    edgeIt = edges1.begin();
+    l1[0] = SMESH_Algo::EdgeLength( *edgeIt++ );
+    l1[1] = SMESH_Algo::EdgeLength( *edgeIt++ );
+    if ( Abs( l1[0] - l1[1] ) > 0.1 * Max( l1[0], l1[1] ) )
+    {
+      edgeIt = edges2.begin();
+      l2[0] = SMESH_Algo::EdgeLength( *edgeIt++ );
+      l2[1] = SMESH_Algo::EdgeLength( *edgeIt++ );
+      if (( l1[0] < l1[1] ) != ( l2[0] < l2[1] ))
+      {
+        Reverse( edges2, nbEdges );
+      }
+    }
+  }
+
   return OK ? nbEInW1.front() : 0;
 }