0025470: Wrong result of COMMON operation
authoremv <emv@opencascade.com>
Fri, 28 Nov 2014 10:25:00 +0000 (13:25 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 28 Nov 2014 10:49:46 +0000 (13:49 +0300)
Fix for correct splitting of infinite faces.

Test cases for issue CR25470

src/BOPAlgo/BOPAlgo_BuilderFace.cxx
tests/bugs/modalg_5/bug25470 [new file with mode: 0644]

index bc78246..d9104c9 100644 (file)
 #include <BRep_Tool.hxx>
 #include <BRepTools.hxx>
 //
+#include <Bnd_Box.hxx>
+//
+#include <BRepBndLib.hxx>
+//
 #include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
 
@@ -451,7 +455,7 @@ void BOPAlgo_BuilderFace::PerformLoops()
 void BOPAlgo_BuilderFace::PerformAreas()
 {
   Standard_Boolean bIsGrowth, bIsHole;
-  Standard_Integer k, aNbHoles, aNbDMISB, m, aNbMSH, aNbInOutMap;;
+  Standard_Integer k, aNbS, aNbHoles, aNbDMISB, m, aNbMSH, aNbInOutMap;
   Standard_Real aTol;
   TopLoc_Location aLoc;
   Handle(Geom_Surface) aS;
@@ -469,6 +473,7 @@ void BOPAlgo_BuilderFace::PerformAreas()
   NCollection_UBTreeFiller <Standard_Integer, Bnd_Box2d> aTreeFiller(aBBTree);
   //
   myErrorStatus=0;
+  aNbHoles=0;
   //
   aTol=BRep_Tool::Tolerance(myFace);
   aS=BRep_Tool::Surface(myFace, aLoc);
@@ -498,8 +503,8 @@ void BOPAlgo_BuilderFace::PerformAreas()
       bIsHole=aClsf.IsHole();
       if (bIsHole) {
         BOPTools::MapShapes(aWire, TopAbs_EDGE, aMHE);
-          //
-          bIsHole=Standard_True;
+        //
+        bIsHole=Standard_True;
       }
       else {
         bIsHole=Standard_False;
@@ -525,6 +530,7 @@ void BOPAlgo_BuilderFace::PerformAreas()
     if (bIsHole) {
       const Bnd_Box2d& aBox2D=aSB2D.Box2D();
       aTreeFiller.Add(k, aBox2D);
+      ++aNbHoles;
     }
   }
   //
@@ -546,7 +552,10 @@ void BOPAlgo_BuilderFace::PerformAreas()
     aSelector.Clear();
     aSelector.SetBox(aBox2DF);
     //
-    aNbHoles=aBBTree.Select(aSelector);
+    aNbS = aBBTree.Select(aSelector);
+    if (!aNbS) {
+      continue;
+    }
     //
     const BOPCol_ListOfInteger& aLI=aSelector.Indices();
     //
@@ -572,7 +581,7 @@ void BOPAlgo_BuilderFace::PerformAreas()
     }
   }// for (m=1; m<=aNbDMISB; ++m)
   //
-  // 5. Map [Face/Holes] -> aMSH 
+  // 5.1 Map [Face/Holes] -> aMSH 
   aNbInOutMap=aInOutMap.Extent();
   for (m=1; m<=aNbInOutMap; ++m) {
     const TopoDS_Shape& aHole=aInOutMap.FindKey(m);
@@ -589,6 +598,41 @@ void BOPAlgo_BuilderFace::PerformAreas()
     }
   }
   //
+  // 5.2. Add unused holes to the original face
+  if (aNbHoles != aNbInOutMap) {
+    Bnd_Box aBoxF;
+    BRepBndLib::Add(myFace, aBoxF);
+    if (aBoxF.IsOpenXmin() || aBoxF.IsOpenXmax() ||
+        aBoxF.IsOpenYmin() || aBoxF.IsOpenYmax() ||
+        aBoxF.IsOpenZmin() || aBoxF.IsOpenZmax()) {
+      //
+      BOPCol_ListOfShape anUnUsedHoles;
+      for (m = 1; m <= aNbDMISB; ++m) {
+        const BOPAlgo_ShapeBox2D& aSB2D=aDMISB.FindFromIndex(m);
+        if (aSB2D.IsHole()) {
+          const TopoDS_Shape& aHole = aSB2D.Shape();
+          if (!aInOutMap.Contains(aHole)) {
+            anUnUsedHoles.Append(aHole);
+          }
+        }
+      }
+      //
+      if (anUnUsedHoles.Extent()) {
+        TopoDS_Face aFace;
+        aBB.MakeFace(aFace, aS, aLoc, aTol);
+        aMSH.Add(aFace, anUnUsedHoles);
+        //
+        BOPAlgo_ShapeBox2D aSB2D;
+        //
+        aSB2D.SetShape(aFace);
+        aSB2D.SetIsHole(Standard_False);
+        //
+        aDMISB.Add(aNbDMISB, aSB2D);
+        ++aNbDMISB;
+      }
+    }
+  }
+  //
   // 6. Add aHoles to Faces
   aNbMSH=aMSH.Extent();
   for (m=1; m<=aNbMSH; ++m) {
diff --git a/tests/bugs/modalg_5/bug25470 b/tests/bugs/modalg_5/bug25470
new file mode 100644 (file)
index 0000000..c6ce679
--- /dev/null
@@ -0,0 +1,31 @@
+puts "=========="
+puts "OCC25470"
+puts "==========" 
+puts ""
+####################################################
+# Wrong result of COMMON operation
+####################################################
+
+restore [locate_data_file bug25470_s.brep] b1
+restore [locate_data_file bug25470_t.brep] b2
+
+bclearobjects
+bcleartools
+baddobjects b1
+baddtools b2
+bfillds -s
+bbop result 0
+
+set square 893.011
+
+set nb_v_good 45
+set nb_e_good 77
+set nb_w_good 32
+set nb_f_good 32
+set nb_sh_good 1
+set nb_sol_good 1
+set nb_compsol_good 0
+set nb_compound_good  1
+set nb_shape_good 189
+
+set 2dviewer 1