0027830: Infinite HLR looping
authormsv <msv@opencascade.com>
Thu, 8 Sep 2016 19:57:50 +0000 (22:57 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 15 Sep 2016 09:19:52 +0000 (12:19 +0300)
Make protection of HLR algo against garbage data in faces. In particular case, there are faces built on a periodical surfaces, which U bounds exceed period thousands times. Such faces are excluded from the process of edges hiding.

In addition, while fitting the intersection point in period for periodical faces, replace looping with the single call to AdjustPeriodic method.

- Add new test case.
- Update tests of HLR according to new numbers of subshapes.

Update of test cases according to the new behavior

13 files changed:
src/HLRBRep/HLRBRep_Data.cxx
src/HLRBRep/HLRBRep_Data.hxx
src/HLRBRep/HLRBRep_Hider.cxx
tests/bugs/modalg_6/bug27341_301
tests/bugs/modalg_6/bug27341_306
tests/bugs/modalg_6/bug27341_307
tests/bugs/modalg_6/bug27341_308
tests/bugs/modalg_6/bug27341_313
tests/bugs/modalg_6/bug27341_317
tests/bugs/modalg_6/bug27341_320
tests/bugs/modalg_6/bug27341_324
tests/bugs/modalg_6/bug27341_328
tests/bugs/modalg_6/bug27830 [new file with mode: 0644]

index 63e7ee0..0167524 100644 (file)
@@ -20,6 +20,7 @@
 #include <BRepTopAdaptor_TopolTool.hxx>
 #include <ElCLib.hxx>
 #include <Geom2d_Curve.hxx>
+#include <GeomInt.hxx>
 #include <gp.hxx>
 #include <gp_Dir.hxx>
 #include <gp_Dir2d.hxx>
@@ -2093,39 +2094,24 @@ HLRBRep_Data::Classify (const Standard_Integer E,
       IntCurveSurface_TransitionOnCurve Tr;
       
       for (i = 1; i <= nbPoints; i++) {
-       Standard_Boolean InsideRestriction = Standard_False;
        myIntersector.CSPoint(i).Values(PInter,u,v,w,Tr);
        if (w < wLim) {
-         if (PeriodU)
-           while (u > UMin) 
-             u -= PeriodU;
-         if (PeriodV)
-           while (v > VMin)
-             v -= PeriodV;
-//       Standard_Real UInit = u;
-         Standard_Real VInit = v;
+          Standard_Real aDummyShift;
+          if (PeriodU > 0.)
+            GeomInt::AdjustPeriodic(u, UMin, UMax, PeriodU, u, aDummyShift);
+          if (PeriodV > 0.)
+            GeomInt::AdjustPeriodic(v, VMin, VMax, PeriodV, v, aDummyShift);
          
-         do {
-           v = VInit;
-           
-           do {
-             gp_Pnt2d pnt2d(u,v);
-             if (myClassifier->Classify(pnt2d,Precision::PConfusion())
-                  != TopAbs_OUT)
-              {
-               InsideRestriction = Standard_True;
-               state = TopAbs_IN;
-               Level++;
-               if (!LevelFlag) {
-                 return state;
-               }
-             }
-             v += PeriodV;
-           }
-           while (PeriodV && v < VMax && !InsideRestriction);
-           u += PeriodU;
-         }
-         while (PeriodU && u < UMax && !InsideRestriction);
+          gp_Pnt2d pnt2d(u, v);
+          if (myClassifier->Classify(pnt2d, Precision::PConfusion())
+            != TopAbs_OUT)
+          {
+            state = TopAbs_IN;
+            Level++;
+            if (!LevelFlag) {
+              return state;
+            }
+          }
        }
       }
     }
@@ -2444,3 +2430,34 @@ HLRBRep_Data::SameVertex (const Standard_Boolean h1,
   }
   return SameV;
 }
+
+//=======================================================================
+//function : IsBadFace
+//purpose  : 
+//=======================================================================
+
+Standard_Boolean HLRBRep_Data::IsBadFace() const
+{
+  if (iFaceGeom)
+  {
+    // check for garbage data - if periodic then bounds must not exceed period
+    HLRBRep_Surface *pGeom = (HLRBRep_Surface*)iFaceGeom;
+    if (pGeom->IsUPeriodic())
+    {
+      Standard_Real aPeriod = pGeom->UPeriod();
+      Standard_Real aMin = pGeom->FirstUParameter();
+      Standard_Real aMax = pGeom->LastUParameter();
+      if (aPeriod * 2 < aMax - aMin)
+        return Standard_True;
+    }
+    if (pGeom->IsVPeriodic())
+    {
+      Standard_Real aPeriod = pGeom->VPeriod();
+      Standard_Real aMin = pGeom->FirstVParameter();
+      Standard_Real aMax = pGeom->LastVParameter();
+      if (aPeriod * 2 < aMax - aMin)
+        return Standard_True;
+    }
+  }
+  return Standard_False;
+}
index 72ee999..f537114 100644 (file)
@@ -173,7 +173,10 @@ public:
   
   //! Classification of an edge.
   Standard_EXPORT TopAbs_State Classify (const Standard_Integer E, const HLRBRep_EdgeData& ED, const Standard_Boolean LevelFlag, Standard_Integer& Level, const Standard_Real param);
-  
+
+  //! Returns true if the current face is bad.
+  Standard_EXPORT Standard_Boolean IsBadFace() const;
+
   Standard_EXPORT void Destroy();
 ~HLRBRep_Data()
 {
index 86b7513..6162996 100644 (file)
@@ -103,6 +103,8 @@ void HLRBRep_Hider::Hide(const Standard_Integer FI,
   myDS->InitEdge(FI,MST);
   if (!myDS->MoreEdge())                        // there is nothing to do
      return;                                    // **********************
+  if (myDS->IsBadFace())
+    return;
   HLRBRep_EdgeInterferenceTool EIT(myDS); // List of Intersections
   HLRBRep_Array1OfEData& myEData = myDS->EDataArray();
 
index a278496..e1634e7 100644 (file)
@@ -23,6 +23,6 @@ build3d result
 fit
 
 checkprops result -l 1030.62
-checknbshapes result -vertex 258 -edge 130
+checknbshapes result -vertex 256 -edge 129
 
 checkview -screenshot -2d -path ${imagedir}/${test_image}.png
index 7698f2a..f673547 100644 (file)
@@ -23,6 +23,6 @@ build3d result
 fit
 
 checkprops result -l 2893.98
-checknbshapes result -vertex 705 -edge 353
+checknbshapes result -vertex 699 -edge 350
 
 checkview -screenshot -2d -path ${imagedir}/${test_image}.png
index 1ca4fed..7cb2f09 100644 (file)
@@ -23,6 +23,6 @@ build3d result
 fit
 
 checkprops result -l 2282.11
-checknbshapes result -vertex 947 -edge 476
+checknbshapes result -vertex 945 -edge 475
 
 checkview -screenshot -2d -path ${imagedir}/${test_image}.png
index b8e0622..3bff8b8 100644 (file)
@@ -22,7 +22,7 @@ build3d result
 
 fit
 
-checkprops result -l 1249.94
-checknbshapes result -vertex 490 -edge 245
+checkprops result -l 1170.46
+checknbshapes result -vertex 486 -edge 243
 
 checkview -screenshot -2d -path ${imagedir}/${test_image}.png
index a947ba4..69f4eed 100644 (file)
@@ -23,6 +23,6 @@ build3d result
 fit
 
 checkprops result -l 9662.5
-checknbshapes result -vertex 4429 -edge 2221
+checknbshapes result -vertex 4423 -edge 2218
 
 checkview -screenshot -2d -path ${imagedir}/${test_image}.png
index cfa5701..95e54f9 100644 (file)
@@ -22,7 +22,7 @@ build3d result
 
 fit
 
-checkprops result -l 2774.53
-checknbshapes result -vertex 614 -edge 307
+checkprops result -l 2704.1
+checknbshapes result -vertex 594 -edge 297
 
 checkview -screenshot -2d -path ${imagedir}/${test_image}.png
index 01beedd..ca1b112 100644 (file)
@@ -23,6 +23,6 @@ build3d result
 fit
 
 checkprops result -l 1726.77
-checknbshapes result -vertex 811 -edge 406
+checknbshapes result -vertex 803 -edge 402
 
 checkview -screenshot -2d -path ${imagedir}/${test_image}.png
index cfd3304..dad9044 100644 (file)
@@ -23,6 +23,6 @@ build3d result
 fit
 
 checkprops result -l 211.007
-checknbshapes result -vertex 106 -edge 53
+checknbshapes result -vertex 102 -edge 51
 
 checkview -screenshot -2d -path ${imagedir}/${test_image}.png
index 383ea1a..4aef177 100644 (file)
@@ -23,6 +23,6 @@ build3d result
 fit
 
 checkprops result -l 40.3211
-checknbshapes result -vertex 62 -edge 31
+checknbshapes result -vertex 60 -edge 30
 
 checkview -screenshot -2d -path ${imagedir}/${test_image}.png
diff --git a/tests/bugs/modalg_6/bug27830 b/tests/bugs/modalg_6/bug27830
new file mode 100644 (file)
index 0000000..66b2398
--- /dev/null
@@ -0,0 +1,17 @@
+puts "============"
+puts "OCC27830"
+puts "============"
+puts ""
+######################################################
+# Infinite HLR looping
+######################################################
+
+restore [locate_data_file bug27830_body1.brep] result
+
+vinit
+vdisplay result
+vfit
+vhlr on
+vhlrtype algo result
+
+# no screenshot since the shape is a garbage, the test is just to check performance