0026619: Tolerances of operands are modified using bop
[occt.git] / src / BOPAlgo / BOPAlgo_Builder_2.cxx
index 57248f9..b17734d 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#include <BOPAlgo_Builder.ixx>
-//
-#include <NCollection_IncAllocator.hxx>
-//
-#include <TopoDS_Shape.hxx>
-#include <TopoDS_Face.hxx>
-#include <TopoDS_Edge.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <TopoDS_Compound.hxx>
-//
-#include <BRep_Tool.hxx>
-#include <BRep_Builder.hxx>
-//
-#include <TopExp_Explorer.hxx>
-//
-#include <BOPCol_ListOfShape.hxx>
-#include <BOPCol_ListOfInteger.hxx>
-#include <BOPCol_MapOfInteger.hxx>
+
+#include <BOPAlgo_Builder.hxx>
+#include <BOPAlgo_BuilderFace.hxx>
+#include <BOPAlgo_PaveFiller.hxx>
 #include <BOPCol_DataMapOfIntegerListOfShape.hxx>
 #include <BOPCol_DataMapOfShapeShape.hxx>
+#include <BOPCol_ListOfInteger.hxx>
+#include <BOPCol_ListOfShape.hxx>
+#include <BOPCol_MapOfInteger.hxx>
 #include <BOPCol_NCVector.hxx>
-#include <BOPCol_TBB.hxx>
-//
-#include <BOPInt_Context.hxx>
-//
-#include <BOPDS_PaveBlock.hxx>
-#include <BOPDS_ShapeInfo.hxx>
+#include <BOPCol_Parallel.hxx>
 #include <BOPDS_DS.hxx>
 #include <BOPDS_FaceInfo.hxx>
-#include <BOPDS_MapOfPaveBlock.hxx>
-#include <BOPDS_VectorOfInterfFF.hxx>
 #include <BOPDS_Interf.hxx>
+#include <BOPDS_MapOfPaveBlock.hxx>
+#include <BOPDS_PaveBlock.hxx>
+#include <BOPDS_ShapeInfo.hxx>
 #include <BOPDS_VectorOfCurve.hxx>
+#include <BOPDS_VectorOfInterfFF.hxx>
 #include <BOPDS_VectorOfPoint.hxx>
-//
 #include <BOPTools.hxx>
 #include <BOPTools_AlgoTools.hxx>
 #include <BOPTools_AlgoTools2D.hxx>
 #include <BOPTools_AlgoTools3D.hxx>
-#include <BOPAlgo_BuilderFace.hxx>
 #include <BOPTools_CoupleOfShape.hxx>
+#include <BOPTools_DataMapOfShapeSet.hxx>
 #include <BOPTools_ListOfCoupleOfShape.hxx>
 #include <BOPTools_MapOfSet.hxx>
-#include <BOPTools_DataMapOfShapeSet.hxx>
-
+#include <BRep_Builder.hxx>
+#include <BRep_Tool.hxx>
+#include <IntTools_Context.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS_Compound.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Vertex.hxx>
 
+//
+//
+//
+//
+//
+//
+//
+//
 static
   Standard_Boolean HasPaveBlocksOnIn(const BOPDS_FaceInfo& aFI1,
                                      const BOPDS_FaceInfo& aFI2);
@@ -68,11 +68,11 @@ static
   void FillMap(const TopoDS_Shape& aS1,
                const TopoDS_Shape& aS2,
                BOPCol_IndexedDataMapOfShapeListOfShape& aDMSLS,
-               Handle(NCollection_IncAllocator)& aAllocator);
+               Handle(NCollection_BaseAllocator)& aAllocator);
 static
   void MakeBlocksCnx(const BOPCol_IndexedDataMapOfShapeListOfShape& aMILI,
                      BOPCol_DataMapOfIntegerListOfShape& aMBlocks,
-                     Handle(NCollection_IncAllocator)& aAllocator);
+                     Handle(NCollection_BaseAllocator)& aAllocator);
 //
 typedef BOPCol_NCVector<TopoDS_Shape> BOPAlgo_VectorOfShape;
 //
@@ -87,10 +87,17 @@ typedef NCollection_IndexedDataMap\
 //class    : BOPAlgo_PairOfShapeBoolean
 //purpose  : 
 //=======================================================================
-class BOPAlgo_PairOfShapeBoolean {
+class BOPAlgo_PairOfShapeBoolean : public BOPAlgo_Algo {
+
  public:
-  BOPAlgo_PairOfShapeBoolean()
-    : myFlag(Standard_False) {
+  DEFINE_STANDARD_ALLOC
+
+  BOPAlgo_PairOfShapeBoolean() : 
+    BOPAlgo_Algo(),
+    myFlag(Standard_False) {
+  }
+  //
+  virtual ~BOPAlgo_PairOfShapeBoolean() {
   }
   //
   TopoDS_Shape& Shape1() {
@@ -105,88 +112,53 @@ class BOPAlgo_PairOfShapeBoolean {
     return myFlag;
   }
   //
+  void SetContext(const Handle(IntTools_Context)& aContext) {
+    myContext=aContext;
+  }
+  //
+  const Handle(IntTools_Context)& Context()const {
+    return myContext;
+  }
+  //
+  virtual void Perform() {
+    BOPAlgo_Algo::UserBreak();
+    //  
+    const TopoDS_Face& aFj=*((TopoDS_Face*)&myShape1);
+    const TopoDS_Face& aFk=*((TopoDS_Face*)&myShape2);
+    myFlag=BOPTools_AlgoTools::AreFacesSameDomain(aFj, aFk, myContext);
+  }
+  //
  protected: 
   Standard_Boolean myFlag;
   TopoDS_Shape myShape1;
   TopoDS_Shape myShape2;
+  Handle(IntTools_Context) myContext;
 };
 //
 typedef BOPCol_NCVector<BOPAlgo_PairOfShapeBoolean> \
   BOPAlgo_VectorOfPairOfShapeBoolean;
 //
-//=======================================================================
-//function : BOPAlgo_BuilderSDFaceFunctor
-//purpose  : The class provides the interface and implementation 
-//           of the parallel computations
-//=======================================================================
-class BOPAlgo_BuilderSDFaceFunctor {
- protected:
-  BOPAlgo_VectorOfPairOfShapeBoolean* myPVPSB;
-  
- public:
-  //
-  BOPAlgo_BuilderSDFaceFunctor(BOPAlgo_VectorOfPairOfShapeBoolean& aVPSB)
-    : myPVPSB(&aVPSB){
-  }
-  //
-  void operator()( const flexible_range<Standard_Integer>& aBR ) const {
-    Standard_Boolean bFlag;
-    Standard_Integer i, iBeg, iEnd;
-    Handle(BOPInt_Context) aContext;
-    //
-    aContext=new BOPInt_Context;
-    //
-    BOPAlgo_VectorOfPairOfShapeBoolean& aVPSB=*myPVPSB;
-    //
-    iBeg=aBR.begin();
-    iEnd=aBR.end();
-    for(i=iBeg; i!=iEnd; ++i) {
-      BOPAlgo_PairOfShapeBoolean& aPSB=aVPSB(i);
-      const TopoDS_Face& aFj=(*(TopoDS_Face*)(&aPSB.Shape1()));
-      const TopoDS_Face& aFk=(*(TopoDS_Face*)(&aPSB.Shape2()));
-      bFlag=BOPTools_AlgoTools::AreFacesSameDomain(aFj, aFk, aContext);
-      if (bFlag) {
-        aPSB.Flag()=bFlag;
-      }
-    }
-  }
-};
+typedef BOPCol_ContextFunctor 
+  <BOPAlgo_PairOfShapeBoolean,
+  BOPAlgo_VectorOfPairOfShapeBoolean,
+  Handle(IntTools_Context), 
+  IntTools_Context> BOPCol_BuilderSDFaceFunctor;
+//
+typedef BOPCol_ContextCnt 
+  <BOPCol_BuilderSDFaceFunctor,
+  BOPAlgo_VectorOfPairOfShapeBoolean,
+  Handle(IntTools_Context)> BOPAlgo_BuilderSDFaceCnt;
 //
-//=======================================================================
-//function : BOPAlgo_BuilderSDFaceCnt
-//purpose  : The class provides the interface and implementation 
-//           of the parallel computations
-//=======================================================================
-class BOPAlgo_BuilderSDFaceCnt {
- public:
-  //-------------------------------
-  // Perform
-  Standard_EXPORT static 
-    void Perform(const Standard_Boolean bRunParallel,
-                 BOPAlgo_VectorOfPairOfShapeBoolean& aVPSB) {
-      Standard_Integer aNbVPSB;
-      //
-      aNbVPSB=aVPSB.Extent();
-      BOPAlgo_BuilderSDFaceFunctor aBFF(aVPSB);
-      //
-      if (bRunParallel) {
-        flexible_for(flexible_range<Standard_Integer>(0,aNbVPSB), aBFF);
-      }
-      else {
-        aBFF.operator()(flexible_range<Standard_Integer>(0,aNbVPSB));
-      }
-    }
-};
 //=======================================================================
 // BuilderFace
 //
 typedef BOPCol_NCVector<BOPAlgo_BuilderFace> BOPAlgo_VectorOfBuilderFace;
 //
-typedef BOPCol_TBBFunctor 
+typedef BOPCol_Functor 
   <BOPAlgo_BuilderFace,
   BOPAlgo_VectorOfBuilderFace> BOPAlgo_BuilderFaceFunctor;
 //
-typedef BOPCol_TBBCnt 
+typedef BOPCol_Cnt 
   <BOPAlgo_BuilderFaceFunctor,
   BOPAlgo_VectorOfBuilderFace> BOPAlgo_BuilderFaceCnt;
 //
@@ -194,13 +166,17 @@ typedef BOPCol_TBBCnt
 //class    : BOPAlgo_VFI
 //purpose  : 
 //=======================================================================
-class BOPAlgo_VFI {
+class BOPAlgo_VFI : public BOPAlgo_Algo {
+
  public:
-  BOPAlgo_VFI() 
-   : myFlag(-1) {
+  DEFINE_STANDARD_ALLOC
+  
+  BOPAlgo_VFI() :
+    BOPAlgo_Algo(),
+    myFlag(-1) {
   }
   //
-  ~BOPAlgo_VFI(){
+  virtual ~BOPAlgo_VFI(){
   }
   //
   void SetVertex(const TopoDS_Vertex& aV) {
@@ -223,39 +199,40 @@ class BOPAlgo_VFI {
     return myFlag;
   }
   //
-  void SetContext(const Handle(BOPInt_Context)& aContext) {
+  void SetContext(const Handle(IntTools_Context)& aContext) {
     myContext=aContext;
   }
   //
-  const Handle(BOPInt_Context)& Context()const {
+  const Handle(IntTools_Context)& Context()const {
     return myContext;
   }
   //
-  void Perform() {
-    Standard_Real aT1, aT2;
+  virtual void Perform() {
+    Standard_Real aT1, aT2, dummy;
     //
-    myFlag=myContext->ComputeVF(myV, myF, aT1, aT2);
+    BOPAlgo_Algo::UserBreak();
+    myFlag = myContext->ComputeVF(myV, myF, aT1, aT2, dummy);
   }
   //
  protected:
   Standard_Integer myFlag;
   TopoDS_Vertex myV;
   TopoDS_Face myF;
-  Handle(BOPInt_Context) myContext;
+  Handle(IntTools_Context) myContext;
 };
 //
 typedef BOPCol_NCVector<BOPAlgo_VFI> BOPAlgo_VectorOfVFI; 
 //
-typedef BOPCol_TBBContextFunctor 
+typedef BOPCol_ContextFunctor 
   <BOPAlgo_VFI,
   BOPAlgo_VectorOfVFI,
-  Handle(BOPInt_Context), 
-  BOPInt_Context> BOPAlgo_VFIFunctor;
+  Handle(IntTools_Context), 
+  IntTools_Context> BOPAlgo_VFIFunctor;
 //
-typedef BOPCol_TBBContextCnt 
+typedef BOPCol_ContextCnt 
   <BOPAlgo_VFIFunctor,
   BOPAlgo_VectorOfVFI,
-  Handle(BOPInt_Context)> BOPAlgo_VFICnt;
+  Handle(IntTools_Context)> BOPAlgo_VFICnt;
 //
 //=======================================================================
 //function : FillImagesFaces
@@ -287,13 +264,13 @@ void BOPAlgo_Builder::BuildSplitFaces()
   BOPCol_MapOfShape aMFence;
   Handle(NCollection_BaseAllocator) aAllocator;
   BOPCol_ListOfShape aLFIm(myAllocator);
-  BOPCol_MapIteratorOfMapOfShape aItMS;
   BOPAlgo_VectorOfBuilderFace aVBF;
   //
   myErrorStatus=0;
   //
   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~scope f
-  aAllocator=new NCollection_IncAllocator();
+  aAllocator=
+    NCollection_BaseAllocator::CommonBaseAllocator();
   //
   BOPCol_ListOfShape aLE(aAllocator);
   BOPCol_MapOfShape aMDE(100, aAllocator);
@@ -428,13 +405,16 @@ void BOPAlgo_Builder::BuildSplitFaces()
       aLE.Append(aSp);
     }
     //
-    BOPTools_AlgoTools2D::BuildPCurveForEdgesOnPlane (aLE, aFF);
-    //
+    if (!myPaveFiller->NonDestructive()) {
+      // speed up for planar faces
+      BOPTools_AlgoTools2D::BuildPCurveForEdgesOnPlane (aLE, aFF);
+    }
     // 3 Build split faces
     BOPAlgo_BuilderFace& aBF=aVBF.Append1();
     aBF.SetFace(aF);
     aBF.SetShapes(aLE);
     aBF.SetRunParallel(myRunParallel);
+    aBF.SetProgressIndicator(myProgressIndicator);
     //
   }// for (i=0; i<aNbS; ++i) {
   //
@@ -466,7 +446,6 @@ void BOPAlgo_Builder::BuildSplitFaces()
     mySplits.Bind(aF, aLFIm); 
   }// for (k=0; k<aNbBF; ++k) {
   //
-  aAllocator.Nullify();
   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~scope t
 }
 //=======================================================================
@@ -477,7 +456,7 @@ void BOPAlgo_Builder::FillSameDomainFaces()
 {
   Standard_Boolean bFlag;
   Standard_Integer i, j, k, aNbFFs, aNbCurves, aNbPoints, nF1, nF2, aNbS;
-  Handle(NCollection_IncAllocator) aAllocator;
+  Handle(NCollection_BaseAllocator) aAllocator;
   BOPCol_ListIteratorOfListOfShape aItF;
   BOPCol_MapOfShape aMFence;
   BOPAlgo_IndexedDataMapOfSetInteger aIDMSS;
@@ -619,13 +598,15 @@ void BOPAlgo_Builder::FillSameDomainFaces()
         BOPAlgo_PairOfShapeBoolean& aPSB=aVPSB.Append1();
         aPSB.Shape1()=aFj;
         aPSB.Shape2()=aFk;
+        aPSB.SetProgressIndicator(myProgressIndicator);
       }
     }
   }
-  //====================================================
-  BOPAlgo_BuilderSDFaceCnt::Perform(myRunParallel, aVPSB);
-  //====================================================
-  aAllocator=new NCollection_IncAllocator();
+  //================================================================
+  BOPAlgo_BuilderSDFaceCnt::Perform(myRunParallel, aVPSB, myContext);
+  //================================================================
+  aAllocator=
+    NCollection_BaseAllocator::CommonBaseAllocator();
   BOPCol_IndexedDataMapOfShapeListOfShape aDMSLS(100, aAllocator);
   BOPCol_DataMapOfIntegerListOfShape aMBlocks(100, aAllocator);
   //
@@ -669,7 +650,6 @@ void BOPAlgo_Builder::FillSameDomainFaces()
   }
   aMBlocks.Clear();
   aDMSLS.Clear();
-  aAllocator.Nullify();
 }
 //=======================================================================
 // function: FillImagesFaces1
@@ -747,6 +727,7 @@ void BOPAlgo_Builder::FillImagesFaces1()
         BOPAlgo_VFI& aVFI=aVVFI.Append1();
         aVFI.SetVertex(aVx);
         aVFI.SetFace(aFy);
+        aVFI.SetProgressIndicator(myProgressIndicator);
       }
     }
   }// for (i=0; i<aNbS; ++i) {
@@ -762,9 +743,9 @@ void BOPAlgo_Builder::FillImagesFaces1()
     //
     iFlag=aVFI.Flag();
     if (!iFlag) {
-      TopoDS_Vertex& aVx=aVFI.Vertex();
+      TopoDS_Vertex& aVertex=aVFI.Vertex();
       TopoDS_Face& aFy=aVFI.Face(); 
-      aBB.Add(aFy, aVx);
+      aBB.Add(aFy, aVertex);
     }
   }
 }
@@ -774,7 +755,7 @@ void BOPAlgo_Builder::FillImagesFaces1()
 //=======================================================================
 void MakeBlocksCnx(const BOPCol_IndexedDataMapOfShapeListOfShape& aMILI,
                    BOPCol_DataMapOfIntegerListOfShape& aMBlocks,
-                   Handle(NCollection_IncAllocator)& aAllocator)
+                   Handle(NCollection_BaseAllocator)& aAllocator)
 {
   Standard_Integer aNbV, aNbVS, aNbVP, aNbEC, k, i, j;
   BOPCol_ListIteratorOfListOfShape aItLI;
@@ -856,7 +837,7 @@ void MakeBlocksCnx(const BOPCol_IndexedDataMapOfShapeListOfShape& aMILI,
 void FillMap(const TopoDS_Shape& aS1,
              const TopoDS_Shape& aS2,
              BOPCol_IndexedDataMapOfShapeListOfShape& aDMSLS,
-             Handle(NCollection_IncAllocator)& aAllocator)
+             Handle(NCollection_BaseAllocator)& aAllocator)
 {
   if (aDMSLS.Contains(aS1)) {
     BOPCol_ListOfShape& aLS=aDMSLS.ChangeFromKey(aS1);
@@ -886,27 +867,27 @@ Standard_Boolean HasPaveBlocksOnIn(const BOPDS_FaceInfo& aFI1,
                                    const BOPDS_FaceInfo& aFI2)
 {
   Standard_Boolean bRet;
-  BOPDS_MapIteratorOfMapOfPaveBlock aItMPB;
+  Standard_Integer i, aNbPB;
   //
   bRet=Standard_False;
-  const BOPDS_IndexedMapOfPaveBlock& aMPBOn1=aFI1.PaveBlocksOn();
-  const BOPDS_IndexedMapOfPaveBlock& aMPBIn1=aFI1.PaveBlocksIn();
-  //
-  const BOPDS_IndexedMapOfPaveBlock& aMPBOn2=aFI2.PaveBlocksOn();
-  aItMPB.Initialize(aMPBOn2);
-  for (; aItMPB.More(); aItMPB.Next()) {
-    const Handle(BOPDS_PaveBlock)& aPB=aItMPB.Value();
-    bRet=aMPBOn1.Contains(aPB) || aMPBIn1.Contains(aPB);
+  const BOPDS_IndexedMapOfPaveBlock& aMPBOn1 = aFI1.PaveBlocksOn();
+  const BOPDS_IndexedMapOfPaveBlock& aMPBIn1 = aFI1.PaveBlocksIn();
+  //
+  const BOPDS_IndexedMapOfPaveBlock& aMPBOn2 = aFI2.PaveBlocksOn();
+  aNbPB = aMPBOn2.Extent();
+  for (i = 1; i <= aNbPB; ++i) {
+    const Handle(BOPDS_PaveBlock)& aPB = aMPBOn2(i);
+    bRet = aMPBOn1.Contains(aPB) || aMPBIn1.Contains(aPB);
     if (bRet) {
       return bRet;
     }
   }
   //
-  const BOPDS_IndexedMapOfPaveBlock& aMPBIn2=aFI2.PaveBlocksIn();
-  aItMPB.Initialize(aMPBIn2);
-  for (; aItMPB.More(); aItMPB.Next()) {
-    const Handle(BOPDS_PaveBlock)& aPB=aItMPB.Value();
-    bRet=aMPBOn1.Contains(aPB) || aMPBIn1.Contains(aPB);
+  const BOPDS_IndexedMapOfPaveBlock& aMPBIn2 = aFI2.PaveBlocksIn();
+  aNbPB = aMPBIn2.Extent();
+  for (i = 1; i <= aNbPB; ++i) {
+    const Handle(BOPDS_PaveBlock)& aPB = aMPBIn2(i);
+    bRet = aMPBOn1.Contains(aPB) || aMPBIn1.Contains(aPB);
     if (bRet) {
       return bRet;
     }