0026619: Tolerances of operands are modified using bop
[occt.git] / src / BOPAlgo / BOPAlgo_PaveFiller_2.cxx
index 51c3ace..3658d3d 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#include <BOPAlgo_PaveFiller.ixx>
-
-#include <TopoDS_Vertex.hxx>
-#include <TopoDS_Edge.hxx>
-#include <BRep_Tool.hxx>
 
+#include <BOPAlgo_PaveFiller.hxx>
+#include <BOPAlgo_SectionAttribute.hxx>
 #include <BOPCol_NCVector.hxx>
-#include <BOPCol_TBB.hxx>
-
-#include <IntTools_Context.hxx>
-
-#include <BOPDS_Iterator.hxx>
-#include <BOPDS_VectorOfInterfVE.hxx>
+#include <BOPCol_Parallel.hxx>
+#include <BOPDS_Curve.hxx>
+#include <BOPDS_DS.hxx>
 #include <BOPDS_Interf.hxx>
-#include <BOPDS_PassKey.hxx>
+#include <BOPDS_Iterator.hxx>
 #include <BOPDS_MapOfPassKey.hxx>
-#include <BRepBndLib.hxx>
+#include <BOPDS_PassKey.hxx>
+#include <BOPDS_PaveBlock.hxx>
+#include <BOPDS_VectorOfInterfVE.hxx>
+#include <BOPTools_AlgoTools.hxx>
 #include <BRep_Builder.hxx>
+#include <BRep_Tool.hxx>
+#include <BRepBndLib.hxx>
+#include <gp_Pnt.hxx>
+#include <IntTools_Context.hxx>
+#include <IntTools_Tools.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <Precision.hxx>
 
 //=======================================================================
 //class    : BOPAlgo_VertexEdgeEdge
@@ -45,7 +51,7 @@ class BOPAlgo_VertexEdge : public BOPAlgo_Algo {
 
   BOPAlgo_VertexEdge() : 
     BOPAlgo_Algo(),
-    myIV(-1), myIE(-1), myIVx(-1), myFlag(-1), myT(-1.) {
+    myIV(-1), myIE(-1), myIVx(-1), myFlag(-1), myT(-1.), myTolVNew(-1.) {
   };
   //
   virtual ~BOPAlgo_VertexEdge(){
@@ -71,15 +77,15 @@ class BOPAlgo_VertexEdge : public BOPAlgo_Algo {
     myV=aV;
   }
   //
-  const TopoDS_Vertex& Vertex()const {
-    return myV;
-  }
-  //
   void SetEdge(const TopoDS_Edge& aE) {
     myE=aE;
   }
   //
-  const TopoDS_Edge& Edge()const {
+  const TopoDS_Vertex& Vertex() const {
+    return myV;
+  }
+  //
+  const TopoDS_Edge& Edge() const {
     return myE;
   }
   //
@@ -91,6 +97,10 @@ class BOPAlgo_VertexEdge : public BOPAlgo_Algo {
     return myT;
   }
   //
+  Standard_Real VertexNewTolerance()const {
+    return myTolVNew;
+  }
+  //
   void SetContext(const Handle(IntTools_Context)& aContext) {
     myContext=aContext;
   }
@@ -101,7 +111,7 @@ class BOPAlgo_VertexEdge : public BOPAlgo_Algo {
   //
   virtual void Perform() {
     BOPAlgo_Algo::UserBreak();
-    myFlag=myContext->ComputeVE (myV, myE, myT);
+    myFlag=myContext->ComputeVE (myV, myE, myT, myTolVNew);
   };
   //
  protected:
@@ -110,6 +120,7 @@ class BOPAlgo_VertexEdge : public BOPAlgo_Algo {
   Standard_Integer myIVx;
   Standard_Integer myFlag;
   Standard_Real myT;
+  Standard_Real myTolVNew;
   TopoDS_Vertex myV;
   TopoDS_Edge myE;
   Handle(IntTools_Context) myContext;
@@ -118,13 +129,13 @@ class BOPAlgo_VertexEdge : public BOPAlgo_Algo {
 typedef BOPCol_NCVector
   <BOPAlgo_VertexEdge> BOPAlgo_VectorOfVertexEdge; 
 //
-typedef BOPCol_TBBContextFunctor 
+typedef BOPCol_ContextFunctor 
   <BOPAlgo_VertexEdge,
   BOPAlgo_VectorOfVertexEdge,
   Handle(IntTools_Context), 
   IntTools_Context> BOPAlgo_VertexEdgeFunctor;
 //
-typedef BOPCol_TBBContextCnt 
+typedef BOPCol_ContextCnt 
   <BOPAlgo_VertexEdgeFunctor,
   BOPAlgo_VectorOfVertexEdge,
   Handle(IntTools_Context)> BOPAlgo_VertexEdgeCnt;
@@ -136,16 +147,17 @@ typedef BOPCol_TBBContextCnt
 void BOPAlgo_PaveFiller::PerformVE()
 {
   Standard_Boolean bJustAdd;
-  Standard_Integer iSize, nV, nE, nVSD, iFlag, nVx, i, k, aNbVE;;
-  Standard_Real aT, aTolE, aTolV;
+  Standard_Integer iSize, nV, nE, nVSD, iFlag, nVx,  k, aNbVE;
+  Standard_Real aT, aT1, aT2, aTS1, aTS2;
   BOPDS_Pave aPave;
   BOPDS_PassKey aPK;
   BOPDS_MapOfPassKey aMPK;
-  BRep_Builder aBB;
   BOPAlgo_VectorOfVertexEdge aVVE;
   //
   myErrorStatus=0;
   //
+  FillShrunkData(TopAbs_VERTEX, TopAbs_EDGE);
+  //
   myIterator->Initialize(TopAbs_VERTEX, TopAbs_EDGE);
   iSize=myIterator->ExpectedLength();
   if (!iSize) {
@@ -153,9 +165,7 @@ void BOPAlgo_PaveFiller::PerformVE()
   }
   //
   BOPDS_VectorOfInterfVE& aVEs=myDS->InterfVE();
-  aVEs.SetStartSize(iSize);
   aVEs.SetIncrement(iSize);
-  aVEs.Init();
   //
   for (; myIterator->More(); myIterator->Next()) {
     myIterator->Value(nV, nE, bJustAdd);
@@ -187,6 +197,12 @@ void BOPAlgo_PaveFiller::PerformVE()
       continue;
     }
     //
+    const BOPDS_ListOfPaveBlock& aLPB = myDS->PaveBlocks(nE);
+    if (aLPB.IsEmpty() || !aLPB.First()->HasShrunkData()) {
+      // this is a micro edge, ignore it
+      continue;
+    }
+    //
     const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aSIE.Shape())); 
     const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nVx))); 
     //
@@ -210,30 +226,50 @@ void BOPAlgo_PaveFiller::PerformVE()
     if (!iFlag) {
       aVESolver.Indices(nV, nE, nVx);
       aT=aVESolver.Parameter();
-      const TopoDS_Vertex& aV=aVESolver.Vertex();
-      const TopoDS_Edge& aE=aVESolver.Edge();
+      // 
+      // check if vertex hits beyond shrunk range, in such case create V-V interf
+      const BOPDS_ListOfPaveBlock& aLPB = myDS->PaveBlocks(nE);
+      const Handle(BOPDS_PaveBlock)& aPB = aLPB.First();
+      Bnd_Box aBox;
+      aPB->Range(aT1, aT2);
+      aPB->ShrunkData(aTS1, aTS2, aBox);
+      IntTools_Range aPaveR[2] = { IntTools_Range(aT1, aTS1), IntTools_Range(aTS2, aT2) };
+      Standard_Real aTol = Precision::Confusion();
+      Standard_Boolean isOnPave = Standard_False;
+      for (Standard_Integer i = 0; i < 2; i++) {
+        if (IntTools_Tools::IsOnPave1(aT, aPaveR[i], aTol)) {
+          Standard_Integer nV1 = (i == 0 ? aPB->Pave1().Index() : aPB->Pave2().Index());
+          if (!myDS->HasInterf(nV, nV1)) {
+            BOPCol_ListOfInteger aLI;
+            aLI.Append(nV);
+            aLI.Append(nV1);
+            MakeSDVertices(aLI);
+          }
+          isOnPave = Standard_True;
+          break;
+        }
+      }
+      if (isOnPave)
+        continue;
+      //
       // 1
-      i=aVEs.Append()-1;
-      BOPDS_InterfVE& aVE=aVEs(i);
+      BOPDS_InterfVE& aVE=aVEs.Append1();
       aVE.SetIndices(nV, nE);
       aVE.SetParameter(aT);
       // 2
       myDS->AddInterf(nV, nE);
-      // 3
-      BOPDS_ListOfPaveBlock& aLPB=myDS->ChangePaveBlocks(nE);
-      Handle(BOPDS_PaveBlock)& aPB=*((Handle(BOPDS_PaveBlock)*)&aLPB.First());
-      // 
+      //
+      // 3 update vertex V/E if necessary
+      Standard_Real aTolVNew = aVESolver.VertexNewTolerance();
+      nVx=UpdateVertex(nV, aTolVNew);
+      //4
+      if (myDS->IsNewShape(nVx)) {
+        aVE.SetIndexNew(nVx);
+      }
+      //5 append ext pave to pave block
       aPave.SetIndex(nVx);
       aPave.SetParameter(aT);
       aPB->AppendExtPave(aPave);
-      aTolV = BRep_Tool::Tolerance(aV);
-      aTolE = BRep_Tool::Tolerance(aE);
-      if ( aTolV < aTolE) {
-        aBB.UpdateVertex(aV, aTolE);
-        BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nVx);
-        Bnd_Box& aBoxDS=aSIDS.ChangeBox();
-        BRepBndLib::Add(aV, aBoxDS);
-      }
     }
   }//for (k=0; k < aNbVE; ++k) {
 }