Salome HOME
bos #20144 [CEA 20142] Import1D - Error: Algorithm failed
[modules/smesh.git] / src / SMESHUtils / SMESH_MAT2d.cxx
index f37334a160308c8759f28b9568fdf5c1ec023b76..fbbb0553f1579c2303c3382d092c9480857885f9 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2020  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
@@ -469,7 +469,7 @@ namespace
     }
     text << "\n";
     file.write( text.c_str(), text.size() );
-    cout << "execfile( '" << fileName << "')" << endl;
+    cout << fileName << endl;
 #endif
   }
 
@@ -648,10 +648,18 @@ namespace
     for ( size_t iE = 0; iE < edges.size(); ++iE )
     {
       size_t iE2 = (iE+1) % edges.size();
-      if ( !TopExp::CommonVertex( edges[iE], edges[iE2], vShared ))
-        continue;
+      if ( !TopExp::CommonVertex( edges[iE], edges[iE2], vShared )) // FACE with several WIREs?
+        for ( size_t i = 1; i < edges.size(); ++i )
+        {
+          iE2 = (iE2+1) % edges.size();
+          if ( iE != iE2 &&
+               TopExp::CommonVertex( edges[iE], edges[iE2], vShared ) &&
+               vShared.IsSame( TopExp::LastVertex( edges[iE], true )))
+            break;
+        }
       if ( !vShared.IsSame( TopExp::LastVertex( edges[iE], true )))
-        return false;
+        continue;
+        //return false;
       vector< UVU > & points1 = uvuVec[ iE ];
       vector< UVU > & points2 = uvuVec[ iE2 ];
       gp_Pnt2d & uv1 = points1.back() ._uv;
@@ -665,14 +673,12 @@ namespace
     // make 'scale' such that to have coordinates precise enough when converted to int
 
     gp_XY uvMin = uvBox.CornerMin(), uvMax = uvBox.CornerMax();
-    uvMin.ChangeCoord(1) = uvMin.X() * scale[0];
-    uvMin.ChangeCoord(2) = uvMin.Y() * scale[1];
-    uvMax.ChangeCoord(1) = uvMax.X() * scale[0];
-    uvMax.ChangeCoord(2) = uvMax.Y() * scale[1];
+    uvMin *= gp_XY( scale[0], scale[1] );
+    uvMax *= gp_XY( scale[0], scale[1] );
     double vMax[2] = { Max( Abs( uvMin.X() ), Abs( uvMax.X() )),
                        Max( Abs( uvMin.Y() ), Abs( uvMax.Y() )) };
     int iMax = ( vMax[0] > vMax[1] ) ? 0 : 1;
-    const double precision = Min( 1e-5, minSegLen * 1e-2 );
+    const double precision = Min( 1e-5, Min( minSegLen * 1e-2, vMax[iMax] * 1e-5 ));
     double preciScale = Min( vMax[iMax] / precision,
                              std::numeric_limits<int>::max() / vMax[iMax] );
     preciScale /= scale[iMax];
@@ -798,6 +804,12 @@ namespace
     for (TVD::const_cell_iterator it = vd.cells().begin(); it != vd.cells().end(); ++it)
     {
       const TVDCell* cell = &(*it);
+      if ( cell->is_degenerate() )
+      {
+        std::cerr << "SMESH_MAT2d: encounter degenerate voronoi_cell. Invalid input data?"
+                  << std::endl;
+        return;
+      }
       if ( cell->contains_segment() )
       {
         InSegment& seg = inSegments[ cell->source_index() ];
@@ -1065,6 +1077,11 @@ namespace
           }
         }
 
+        else // 2D_mesh_QuadranglePreference_00/A1, bos20144.brep
+        {
+          continue; // bndSegs.size() == 1
+        }
+
         bndSegs[i].setBranch( branchID, bndSegsPerEdge ); // set to i-th and to the opposite bndSeg
         if ( bndSegs[i].hasOppositeEdge() )
           branchEdges[ bndSegs[i].branchID() ].push_back( bndSegs[i]._edge );