0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / IntCurvesFace / IntCurvesFace_Intersector.cxx
index 02417ea..f2c974b 100644 (file)
@@ -42,7 +42,7 @@
 #include <TopoDS_Face.hxx>
 #include <BRep_Tool.hxx>
 #include <TopoDS.hxx>
-#include <Geom2dAPI_ProjectPointOnCurve.hxx>
+#include <GeomAPI_ProjectPointOnCurve.hxx>
 //
 static void ComputeSamplePars(const Handle(Adaptor3d_HSurface)& Hsurface, 
                               const Standard_Integer nbsu,
@@ -132,10 +132,12 @@ IntCurvesFace_Intersector::IntCurvesFace_Intersector(const TopoDS_Face& Face,
 : 
   Tol(aTol),
   done(Standard_False),
+  myReady(Standard_False),
   nbpnt(0),
   PtrOnPolyhedron(NULL),
   PtrOnBndBounding(NULL),
-  myUseBoundTol (UseBToler)
+  myUseBoundTol (UseBToler),
+  myIsParallel(Standard_False)
 { 
   BRepAdaptor_Surface surface;
   face = Face;
@@ -174,18 +176,23 @@ IntCurvesFace_Intersector::IntCurvesFace_Intersector(const TopoDS_Face& Face,
     if (nbsu > aMaxSamples) nbsu = aMaxSamples;
     if (nbsv > aMaxSamples) nbsv = aMaxSamples;
 
-    if (Max(dU, dV) > Min(dU, dV) * aTresh)
-    {
-      aMinSamples = 10;
-      nbsu = (Standard_Integer)(Sqrt(dU / dV) * aMaxSamples);
-      if (nbsu < aMinSamples) nbsu = aMinSamples;
-      nbsv = aMaxSamples2 / nbsu;
-      if (nbsv < aMinSamples)
+    if (dU > Precision::Confusion() && dV > Precision::Confusion()) {
+      if (Max(dU, dV) > Min(dU, dV) * aTresh)
       {
-        nbsv = aMinSamples;
-        nbsu = aMaxSamples2 / aMinSamples;
+        aMinSamples = 10;
+        nbsu = (Standard_Integer)(Sqrt(dU / dV) * aMaxSamples);
+        if (nbsu < aMinSamples) nbsu = aMinSamples;
+        nbsv = aMaxSamples2 / nbsu;
+        if (nbsv < aMinSamples)
+        {
+          nbsv = aMinSamples;
+          nbsu = aMaxSamples2 / aMinSamples;
+        }
       }
     }
+    else {
+      return; // surface has no extension along one of directions
+    }
 
     Standard_Integer NbUOnS = Hsurface->NbUIntervals(GeomAbs_C2);
     Standard_Integer NbVOnS = Hsurface->NbVIntervals(GeomAbs_C2);
@@ -204,6 +211,7 @@ IntCurvesFace_Intersector::IntCurvesFace_Intersector(const TopoDS_Face& Face,
         new IntCurveSurface_ThePolyhedronOfHInter(Hsurface,nbsu,nbsv,U0,V0,U1,V1);
     }
   }
+  myReady = Standard_True;
 }
 //=======================================================================
 //function : InternalCall
@@ -251,16 +259,12 @@ void IntCurvesFace_Intersector::InternalCall(const IntCurveSurface_HInter &HICS,
           for(; anExp.More(); anExp.Next())
           {
             TopoDS_Edge anE = TopoDS::Edge(anExp.Current());
-            Standard_Real curtol = BRep_Tool::Tolerance(anE);
-            Standard_Real tol2d = Max(Hsurface->UResolution(curtol), Hsurface->VResolution(curtol));
-            tol2d = Max(tol2d, Tol);
             Standard_Real f, l;
-            Handle(Geom2d_Curve) aPC = BRep_Tool::CurveOnSurface(anE, face, f, l);
-            Geom2dAPI_ProjectPointOnCurve aProj(Puv, aPC, f, l);
-            if(aProj.NbPoints() > 0)
+            Handle(Geom_Curve) aPC = BRep_Tool::Curve (anE, f, l);
+            GeomAPI_ProjectPointOnCurve aProj (HICSPointindex.Pnt(), aPC, f, l);
+            if (aProj.NbPoints() > 0)
             {
-              Standard_Real d = aProj.LowerDistance();
-              if(d <= tol2d)
+              if (aProj.LowerDistance() <= maxtol3d)
               {
                 //Nearest edge is found, state is really ON
                 currentstate = TopAbs_ON;
@@ -326,6 +330,10 @@ void IntCurvesFace_Intersector::InternalCall(const IntCurveSurface_HInter &HICS,
       } //-- classifier state is IN or ON
     } //-- Loop on Intersection points.
   } //-- HICS.IsDone()
+  else if (HICS.IsDone())
+  {
+    myIsParallel = HICS.IsParallel();
+  }
 }
 //=======================================================================
 //function : Perform
@@ -335,6 +343,11 @@ void IntCurvesFace_Intersector::Perform(const gp_Lin& L,
                                        const Standard_Real ParMin,
                                        const Standard_Real ParMax)
 { 
+  done = Standard_False;
+  if (!myReady)
+  {
+    return;
+  }
   done = Standard_True;
   SeqPnt.Clear();
   mySeqState.Clear();
@@ -413,6 +426,11 @@ void IntCurvesFace_Intersector::Perform(const Handle(Adaptor3d_HCurve)& HCu,
                                        const Standard_Real ParMin,
                                        const Standard_Real ParMax) 
 { 
+  done = Standard_False;
+  if (!myReady)
+  {
+    return;
+  }
   done = Standard_True;
   SeqPnt.Clear();
   //  Modified by skv - Wed Sep  3 16:14:10 2003 OCC578 Begin