0026431: Can't cut a sphere from a cylinder
[occt.git] / src / TopOpeBRep / TopOpeBRep_FacesIntersector.cxx
old mode 100755 (executable)
new mode 100644 (file)
index c4cc742..6c72812
@@ -1,25 +1,26 @@
 // Created on: 1993-11-18
 // Created by: Jean Yves LEBEY
 // Copyright (c) 1993-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
 //
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
 //
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
 //
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
+// 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>
 
 Standard_EXPORT Standard_Real GLOBAL_tolFF = 1.e-7;
 
-#ifdef DEB
+#ifdef OCCT_DEBUG
 #include <TopAbs.hxx>
-Standard_EXPORT Standard_Boolean TopOpeBRep_GettraceFI();
-Standard_EXPORT Standard_Boolean TopOpeBRep_GettraceFITOL();
-Standard_EXPORT Standard_Boolean TopOpeBRep_GettraceSAVFF();
+extern Standard_Boolean TopOpeBRep_GettraceFI();
+extern Standard_Boolean TopOpeBRep_GettraceFITOL();
+extern Standard_Boolean TopOpeBRep_GettraceSAVFF();
 
-Standard_EXPORT Standard_Integer SAVFFi1 = 0;
-Standard_EXPORT Standard_Integer SAVFFi2 = 0;
+Standard_Integer SAVFFi1 = 0;
+Standard_Integer SAVFFi2 = 0;
 static void SAVFF(const TopoDS_Face& F1,const TopoDS_Face& F2)
 {
   TCollection_AsciiString an1("SAVA");if (SAVFFi1) an1=an1+SAVFFi1;
@@ -62,7 +63,7 @@ static void SAVFF(const TopoDS_Face& F1,const TopoDS_Face& F2)
   cout<<"FaceIntersector : write "<<n1<<","<<n2<<endl;BRepTools::Write(F1,n1);BRepTools::Write(F2,n2); 
 }
 
-Standard_EXPORT Standard_Boolean TopOpeBRepTool_GettraceKRO();
+extern Standard_Boolean TopOpeBRepTool_GettraceKRO();
 #include <TopOpeBRepTool_KRO.hxx>
 Standard_EXPORT TOPKRO KRO_DSFILLER_INTFF("intersection face/face");
 
@@ -172,7 +173,7 @@ TopOpeBRep_FacesIntersector::TopOpeBRep_FacesIntersector ()
 void TopOpeBRep_FacesIntersector::Perform(const TopoDS_Shape& F1,const TopoDS_Shape& F2,
                                          const Bnd_Box& B1,const Bnd_Box& B2)
 {
-#ifdef DEB
+#ifdef OCCT_DEBUG
   if (TopOpeBRep_GettraceSAVFF()) SAVFF(TopoDS::Face(F1),TopoDS::Face(F2));
 #endif
   
@@ -185,10 +186,12 @@ 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 DEB
+#ifdef OCCT_DEBUG
   if (TopOpeBRepTool_GettraceKRO()) KRO_DSFILLER_INTFF.Start();
 #endif
 
@@ -204,7 +207,7 @@ void TopOpeBRep_FacesIntersector::Perform(const TopoDS_Shape& F1,const TopoDS_Sh
   Standard_Real tol2 = myTol2;
   GLOBAL_tolFF = Max(tol1,tol2);
 
-#ifdef DEB
+#ifdef OCCT_DEBUG
   if (TopOpeBRep_GettraceFITOL()) {
     cout<<"FacesIntersector : Perform tol1 = "<<tol1<<endl;
     cout<<"                           tol2 = "<<tol2<<endl;
@@ -213,9 +216,11 @@ 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 DEB
+#ifdef OCCT_DEBUG
   if (TopOpeBRepTool_GettraceKRO()) KRO_DSFILLER_INTFF.Stop();
 #endif
 
@@ -240,7 +245,7 @@ void TopOpeBRep_FacesIntersector::Perform(const TopoDS_Shape& F1,const TopoDS_Sh
     }
   }
   
-#ifdef DEB
+#ifdef OCCT_DEBUG
   if (TopOpeBRep_GettraceFI()) cout<<"Perform : isempty "<<IsEmpty()<<endl;
 #endif
 }
@@ -590,7 +595,7 @@ void TopOpeBRep_FacesIntersector::ForceTolerances(const Standard_Real Tol1,
   myTol1 = Tol1;
   myTol2 = Tol2;  
   myForceTolerances = Standard_True;
-#ifdef DEB
+#ifdef OCCT_DEBUG
   if (TopOpeBRep_GettraceFITOL())
     cout<<"ForceTolerances : myTol1,myTol2 = "<<myTol1<<","<<myTol2<<endl;
 #endif
@@ -613,7 +618,7 @@ void TopOpeBRep_FacesIntersector::GetTolerances(Standard_Real& Tol1,
 //purpose  : (private)
 //=======================================================================
 
-#ifdef DEB
+#ifdef OCCT_DEBUG
 void TopOpeBRep_FacesIntersector::ShapeTolerances(const TopoDS_Shape& S1,
                                                  const TopoDS_Shape& S2)
 #else
@@ -625,7 +630,7 @@ void TopOpeBRep_FacesIntersector::ShapeTolerances(const TopoDS_Shape& ,
   myTol1 = Precision::Confusion();
   myTol2 = myTol1;  
   myForceTolerances = Standard_False;
-#ifdef DEB
+#ifdef OCCT_DEBUG
   if (TopOpeBRep_GettraceFITOL()) {
     cout<<"ShapeTolerances on S1 = ";TopAbs::Print(S1.ShapeType(),cout);
     cout<<" S2 = ";TopAbs::Print(S2.ShapeType(),cout);
@@ -1172,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 DEB
-         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);
-#ifdef DEB
-         cout << "*** TopOpeBRep_FaceIntersector: Merge WLines on Restriction S2 to WLine***" << endl;
+  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 " 
+         << ((WLineRank == 1) ? "S1" : "S2") << " to WLine***" << endl;
 #endif
-      theSlin.Clear();
-      theSlin.Append(anWLine);
-    }
+  }
 }
 
 //=========================================================================================
@@ -1366,7 +1358,7 @@ static Standard_Integer GetArc(IntPatch_SequenceOfLine&           theSlin,
            }
        }
       //  c. all middle gaps
-      Standard_Integer NbChkPnts = theSlin.Length() - 1;
+      Standard_Integer NbChkPnts = WLVertexParameters.Length() / 2 - 1;
       for(i = 1; i <= NbChkPnts; i++)
        {
          if( Abs(WLVertexParameters.Value(i*2+1) - WLVertexParameters.Value(i*2)) > arc->Resolution(MaxVertexTol))
@@ -1444,13 +1436,12 @@ static Standard_Boolean IsPointOK(const gp_Pnt&            theTestPnt,
   Extrema_ExtPS extPS(theTestPnt,theTestSurface,ExtTol,ExtTol);
   if( extPS.IsDone() && extPS.NbExt() > 0 )
     {
-      Standard_Integer i = 0, minext = 1;
+      Standard_Integer i = 0;
       Standard_Real MinDist2 = 1.e+200;
       for(i = 1; i <= extPS.NbExt(); i++)
        {
          if( extPS.SquareDistance(i) < MinDist2 )
            {
-             minext = i;
              MinDist2 = extPS.SquareDistance(i);
            }
        }
@@ -1504,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;
@@ -1521,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;