0026431: Can't cut a sphere from a cylinder
[occt.git] / src / TopOpeBRep / TopOpeBRep_FacesIntersector.cxx
index 12713c6..6c72812 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#include <TopOpeBRep_FacesIntersector.ixx>
+
+#include <Bnd_Box.hxx>
+#include <BRepAdaptor_HSurface.hxx>
+#include <BRepTopAdaptor_TopolTool.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopOpeBRep_FacesIntersector.hxx>
+#include <TopOpeBRep_LineInter.hxx>
 
 #ifdef DRAW
 #include <TopOpeBRep_DRAW.hxx>
@@ -180,8 +186,10 @@ void TopOpeBRep_FacesIntersector::Perform(const TopoDS_Shape& F1,const TopoDS_Sh
   BRepAdaptor_Surface& S2 = mySurface2->ChangeSurface(); S2.Initialize(myFace2);
   mySurfaceType1 = S1.GetType();
   mySurfaceType2 = S2.GetType();
-  myDomain1->Initialize(mySurface1);
-  myDomain2->Initialize(mySurface2);
+  const Handle(Adaptor3d_HSurface)& aSurf1 = mySurface1; // to avoid ambiguity
+  myDomain1->Initialize(aSurf1);
+  const Handle(Adaptor3d_HSurface)& aSurf2 = mySurface2; // to avoid ambiguity
+  myDomain2->Initialize(aSurf2);
 
 #ifdef OCCT_DEBUG
   if (TopOpeBRepTool_GettraceKRO()) KRO_DSFILLER_INTFF.Start();
@@ -208,7 +216,9 @@ void TopOpeBRep_FacesIntersector::Perform(const TopoDS_Shape& F1,const TopoDS_Sh
 #endif
 
   myIntersector.SetTolerances(myTol1,myTol2,MaxUV,Deflection); 
-  myIntersector.Perform(mySurface1,myDomain1,mySurface2,myDomain2,myTol1,myTol2);
+  myIntersector.Perform(mySurface1,myDomain1,mySurface2,myDomain2,
+                        myTol1,myTol2,Standard_True,Standard_True,
+                        Standard_False);
 
 #ifdef OCCT_DEBUG
   if (TopOpeBRepTool_GettraceKRO()) KRO_DSFILLER_INTFF.Stop();
@@ -1167,38 +1177,25 @@ static void MergeWLinesIfAllSegmentsAlongRestriction(IntPatch_SequenceOfLine&
   Standard_Real Fp = 0., Lp = 0.;
 
 
-  if( WLineRank == 1 )
-    {
-      Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
-      Standard_Integer arcnumber = GetArc(theSlin,WLineRank,theSurface1,theDomain1,theSurface2,testPoint,TolVrtx,aLineOn2S,Fp,Lp);
-
-      if( arcnumber == 0 )
-       return;
-     
-      Handle(IntPatch_WLine) anWLine = NULL;
-      anWLine = GetMergedWLineOnRestriction(theSlin,TolVrtx,aLineOn2S);
-#ifdef OCCT_DEBUG
-         cout << "*** TopOpeBRep_FaceIntersector: Merge WLines on Restriction S1 to WLine ***" << endl;
-#endif
-      theSlin.Clear();
-      theSlin.Append(anWLine);
-    }
-  else
-    {
-      Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
-      Standard_Integer arcnumber = GetArc(theSlin,WLineRank,theSurface2,theDomain2,theSurface1,testPoint,TolVrtx,aLineOn2S,Fp,Lp);
-      
-      if( arcnumber == 0 )
-       return;
-
-      Handle(IntPatch_WLine) anWLine = NULL;
-      anWLine = GetMergedWLineOnRestriction(theSlin,TolVrtx,aLineOn2S);
+  Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
+  //
+  Standard_Integer arcnumber = (WLineRank == 1) ?
+      GetArc(theSlin,WLineRank,theSurface1,theDomain1,theSurface2,testPoint,TolVrtx,aLineOn2S,Fp,Lp) :
+      GetArc(theSlin,WLineRank,theSurface2,theDomain2,theSurface1,testPoint,TolVrtx,aLineOn2S,Fp,Lp);
+  //    
+  if (arcnumber == 0) {
+    return;
+  }
+  //
+  Handle(IntPatch_WLine) anWLine = GetMergedWLineOnRestriction(theSlin,TolVrtx,aLineOn2S);
+  if (!anWLine.IsNull()) {
+    theSlin.Clear();
+    theSlin.Append(anWLine);
 #ifdef OCCT_DEBUG
-         cout << "*** TopOpeBRep_FaceIntersector: Merge WLines on Restriction S2 to WLine***" << endl;
+    cout << "*** TopOpeBRep_FaceIntersector: Merge WLines on Restriction " 
+         << ((WLineRank == 1) ? "S1" : "S2") << " to WLine***" << endl;
 #endif
-      theSlin.Clear();
-      theSlin.Append(anWLine);
-    }
+  }
 }
 
 //=========================================================================================
@@ -1498,6 +1495,11 @@ static Handle(IntPatch_WLine) GetMergedWLineOnRestriction(IntPatch_SequenceOfLin
                                                                           const Standard_Real&               theVrtxTol,
                                                                           const Handle(IntSurf_LineOn2S)&    theLineOn2S)
 {
+  Handle(IntPatch_WLine) mWLine;
+  if (theLineOn2S->NbPoints() == 0) {
+    return mWLine;
+  }
+  //
   IntSurf_TypeTrans trans1 = IntSurf_Undecided;
   IntSurf_TypeTrans trans2 = IntSurf_Undecided;
   Standard_Integer i = 0;
@@ -1515,7 +1517,7 @@ static Handle(IntPatch_WLine) GetMergedWLineOnRestriction(IntPatch_SequenceOfLin
        trans2 = aWLine->TransitionOnS2();
     }
 
-  Handle(IntPatch_WLine) mWLine = new IntPatch_WLine(theLineOn2S, Standard_False, trans1, trans2);
+  mWLine = new IntPatch_WLine(theLineOn2S, Standard_False, trans1, trans2);
 
   Standard_Integer NbPnts = mWLine->NbPnts();
   IntPatch_Point aFirstVertex, aLastVertex;