0024772: Modeling Algorithms - Intersection of cylinder and cone produces incorrect...
[occt.git] / src / GeomInt / GeomInt_IntSS.cxx
index ce061d2..600fb45 100644 (file)
@@ -77,38 +77,78 @@ void GeomInt_IntSS::Perform(const Handle(Geom_Surface)& S1,
   myTolReached2d = myTolReached3d = 0.0;
   myNbrestr = 0;
   sline.Clear();
-  Handle(Adaptor3d_TopolTool) dom1 = new Adaptor3d_TopolTool(myHS1);
-  Handle(Adaptor3d_TopolTool) dom2 = new Adaptor3d_TopolTool(myHS2);
-  myLConstruct.Load(dom1,dom2,myHS1,myHS2);
   
   Standard_Real TolArc = Tol;
   Standard_Real TolTang = Tol;
-  Standard_Real UVMaxStep = IntPatch_Intersection::DefineUVMaxStep(myHS1, dom1, myHS2, dom2);
   Standard_Real Deflection = 0.1;
   if (myHS1->GetType() == GeomAbs_BSplineSurface && myHS2->GetType() == GeomAbs_BSplineSurface)
   {
     Deflection /= 10.;
   }
 
+  Handle(Adaptor3d_TopolTool) dom1 = new Adaptor3d_TopolTool (myHS1);
+  Handle(Adaptor3d_TopolTool) dom2 = new Adaptor3d_TopolTool (myHS2);
 
-  myIntersector.SetTolerances(TolArc,TolTang,UVMaxStep,Deflection);
+  NCollection_Vector< Handle(Adaptor3d_Surface)> aVecHS1;
+  NCollection_Vector< Handle(Adaptor3d_Surface)> aVecHS2;
 
-  if(myHS1 == myHS2) {
-    myIntersector.Perform(myHS1,dom1,TolArc,TolTang);
-  }
-  else if (!useStart) {
-    myIntersector.Perform(myHS1,dom1,myHS2,dom2,TolArc,TolTang);
+  if (myHS1 == myHS2)
+  {
+    aVecHS1.Append (myHS1);
+    aVecHS2.Append (myHS2);
   }
-  else {
-    myIntersector.Perform(myHS1,dom1,myHS2,dom2,U1,V1,U2,V2,TolArc,TolTang);
+  else
+  {
+    myIntersector.PrepareSurfaces (myHS1, dom1, myHS2, dom2, Tol, aVecHS1, aVecHS2);
   }
 
-  // ============================================================
-  if (myIntersector.IsDone()) {
-    const Standard_Integer nblin = myIntersector.NbLines();
-    for (Standard_Integer i=1; i<= nblin; i++)
+  for (Standard_Integer aNumOfHS1 = 0; aNumOfHS1 < aVecHS1.Length(); aNumOfHS1++)
+  {
+    const Handle(Adaptor3d_Surface)& aHS1 = aVecHS1.Value (aNumOfHS1);
+
+    for (Standard_Integer aNumOfHS2 = 0; aNumOfHS2 < aVecHS2.Length(); aNumOfHS2++)
     {
-      MakeCurve(i,dom1,dom2,Tol,Approx,ApproxS1,ApproxS2);
+      const Handle(Adaptor3d_Surface)& aHS2 = aVecHS2.Value (aNumOfHS2);
+
+      Handle(Adaptor3d_TopolTool) aDom1 = new Adaptor3d_TopolTool (aHS1);
+      Handle(Adaptor3d_TopolTool) aDom2 = new Adaptor3d_TopolTool (aHS2);
+
+      myLConstruct.Load (aDom1 ,aDom2,
+                         Handle(GeomAdaptor_Surface)::DownCast (aHS1),
+                         Handle(GeomAdaptor_Surface)::DownCast (aHS2));
+
+      Standard_Real UVMaxStep = IntPatch_Intersection::DefineUVMaxStep (aHS1, aDom1, aHS2, aDom2);
+
+      myIntersector.SetTolerances (TolArc, TolTang, UVMaxStep, Deflection);
+
+      if (aHS1 == aHS2)
+      {
+        myIntersector.Perform (aHS1, aDom1, TolArc, TolTang);
+      }
+      else if (!useStart)
+      {
+        myIntersector.Perform (aHS1, aDom1, aHS2, aDom2, TolArc, TolTang);
+      }
+      else
+      {
+        TopAbs_State aState1 = aDom1->Classify (gp_Pnt2d (U1, V1), Tol);
+        TopAbs_State aState2 = aDom2->Classify (gp_Pnt2d (U2, V2), Tol);
+
+        if ((aState1 == TopAbs_IN || aState1 == TopAbs_ON) &&
+            (aState2 == TopAbs_IN || aState2 == TopAbs_ON))
+        {
+          myIntersector.Perform (aHS1, aDom1, aHS2, aDom2, U1, V1, U2, V2, TolArc, TolTang);
+        }
+      }
+
+      // ============================================================
+      if (myIntersector.IsDone()) {
+        const Standard_Integer nblin = myIntersector.NbLines();
+        for (Standard_Integer i = 1; i <= nblin; i++)
+        {
+          MakeCurve (i, aDom1, aDom2, Tol, Approx, ApproxS1, ApproxS2);
+        }
+      }
     }
   }
 }