02c69bf3674deff052696d5a870a6a15922499e9
[occt.git] / src / IntPatch / IntPatch_Intersection.cxx
1 // Created by: Modelization
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and / or modify it
7 // under the terms of the GNU Lesser General Public version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <IntPatch_Intersection.ixx>
16
17 #include <IntPatch_ALineToWLine.hxx>
18 #include <IntPatch_GLine.hxx>
19 #include <IntPatch_ALine.hxx>
20 #include <IntPatch_WLine.hxx>
21 #include <IntPatch_RLine.hxx>
22 #include <IntPatch_PrmPrmIntersection.hxx>
23 #include <IntPatch_ImpPrmIntersection.hxx>
24 #include <IntPatch_ImpImpIntersection.hxx>
25 #include <IntSurf_Quadric.hxx>
26
27 #include <stdio.h>
28
29 #define DEBUG 0 
30 static const Standard_Integer aNbPointsInALine = 200;
31
32 //======================================================================
33 // function: SequenceOfLine
34 //======================================================================
35 const IntPatch_SequenceOfLine& IntPatch_Intersection::SequenceOfLine() const { return(slin); }
36
37 //======================================================================
38 // function: IntPatch_Intersection
39 //======================================================================
40 IntPatch_Intersection::IntPatch_Intersection ()
41  : done(Standard_False),
42    //empt, tgte, oppo,
43    myTolArc(0.0), myTolTang(0.0),
44    myUVMaxStep(0.0), myFleche(0.0),
45    myIsStartPnt(Standard_False)
46    //myU1Start, myV1Start, myU2Start, myV2Start
47 {
48 }
49
50 //======================================================================
51 // function: IntPatch_Intersection
52 //======================================================================
53 IntPatch_Intersection::IntPatch_Intersection(const Handle(Adaptor3d_HSurface)&  S1,
54                                              const Handle(Adaptor3d_TopolTool)& D1,
55                                              const Handle(Adaptor3d_HSurface)&  S2,
56                                              const Handle(Adaptor3d_TopolTool)& D2,
57                                              const Standard_Real TolArc,
58                                              const Standard_Real TolTang)
59  : done(Standard_False),
60    //empt, tgte, oppo,
61    myTolArc(TolArc), myTolTang(TolTang),
62    myUVMaxStep(0.0), myFleche(0.0),
63    myIsStartPnt(Standard_False)
64    //myU1Start, myV1Start, myU2Start, myV2Start
65 {
66   if(myTolArc<1e-8) myTolArc=1e-8;
67   if(myTolTang<1e-8) myTolTang=1e-8;
68   if(myTolArc>0.5) myTolArc=0.5;
69   if(myTolTang>0.5) myTolTang=0.5;
70   Perform(S1,D1,S2,D2,TolArc,TolTang);
71 }
72
73 //======================================================================
74 // function: IntPatch_Intersection
75 //======================================================================
76 IntPatch_Intersection::IntPatch_Intersection(const Handle(Adaptor3d_HSurface)&  S1,
77                                              const Handle(Adaptor3d_TopolTool)& D1,
78                                              const Standard_Real TolArc,
79                                              const Standard_Real TolTang)
80  : done(Standard_False),
81    //empt, tgte, oppo,
82    myTolArc(TolArc), myTolTang(TolTang),
83    myUVMaxStep(0.0), myFleche(0.0),
84    myIsStartPnt(Standard_False)
85    //myU1Start, myV1Start, myU2Start, myV2Start
86 {
87   Perform(S1,D1,TolArc,TolTang);
88 }
89
90 //======================================================================
91 // function: SetTolerances
92 //======================================================================
93 void IntPatch_Intersection::SetTolerances(const Standard_Real TolArc,
94                                           const Standard_Real TolTang,
95                                           const Standard_Real UVMaxStep,
96                                           const Standard_Real Fleche)
97
98   myTolArc     = TolArc;
99   myTolTang    = TolTang;
100   myUVMaxStep  = UVMaxStep;
101   myFleche     = Fleche;
102   if(myTolArc<1e-8) myTolArc=1e-8;
103   if(myTolTang<1e-8) myTolTang=1e-8;
104   if(myTolArc>0.5) myTolArc=0.5;
105   if(myTolTang>0.5) myTolTang=0.5;  
106   if(myFleche<1.0e-3) myFleche=1e-3;
107   if(myUVMaxStep<1.0e-3) myUVMaxStep=1e-3;
108   if(myFleche>10) myFleche=10;
109   if(myUVMaxStep>0.5) myUVMaxStep=0.5;
110 }
111
112 //======================================================================
113 // function: Perform
114 //======================================================================
115 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)&  S1,
116                                     const Handle(Adaptor3d_TopolTool)& D1,
117                                     const Standard_Real TolArc,
118                                     const Standard_Real TolTang)
119 {
120   myTolArc = TolArc;
121   myTolTang = TolTang;
122   if(myFleche == 0.0)  myFleche = 0.01;
123   if(myUVMaxStep==0.0) myUVMaxStep = 0.01;
124
125   done = Standard_True;
126   spnt.Clear();
127   slin.Clear();
128   
129   empt = Standard_True;
130   tgte = Standard_False;
131   oppo = Standard_False;
132
133   switch (S1->GetType())
134   { 
135     case GeomAbs_Plane:
136     case GeomAbs_Cylinder:
137     case GeomAbs_Sphere:
138     case GeomAbs_Cone:
139     case GeomAbs_Torus: break;
140     default:
141     {
142           IntPatch_PrmPrmIntersection interpp;
143           interpp.Perform(S1,D1,TolArc,TolTang,myFleche,myUVMaxStep);
144           if (interpp.IsDone())
145           {
146             done = Standard_True;
147             tgte = Standard_False;
148             empt = interpp.IsEmpty();
149             const Standard_Integer nblm = interpp.NbLines();
150             for (Standard_Integer i=1; i<=nblm; i++) slin.Append(interpp.Line(i));
151           }
152     }
153     break;
154   }
155 }
156
157 /////////////////////////////////////////////////////////////////////////////
158 //  These several support functions provide methods which can help basic   //
159 //  algorithm to intersect infinite surfaces of the following types:       //
160 //                                                                         //
161 //  a.) SurfaceOfExtrusion;                                                //
162 //  b.) SurfaceOfRevolution;                                               //
163 //  c.) OffsetSurface.                                                     //
164 //                                                                         //
165 /////////////////////////////////////////////////////////////////////////////
166 #include <TColgp_Array1OfXYZ.hxx>
167 #include <TColgp_Array1OfPnt.hxx>
168 #include <TColgp_SequenceOfPnt.hxx>
169 #include <Extrema_ExtPS.hxx>
170 #include <Extrema_POnSurf.hxx>
171 #include <Geom2d_Curve.hxx>
172 #include <Geom2dAPI_InterCurveCurve.hxx>
173 #include <GeomAdaptor.hxx>
174 #include <GeomAdaptor_HCurve.hxx>
175 #include <GeomAdaptor_Curve.hxx>
176 #include <GeomAdaptor_Surface.hxx>
177 #include <Handle_GeomAdaptor_HSurface.hxx>
178 #include <Geom_Plane.hxx>
179 #include <ProjLib_ProjectOnPlane.hxx>
180 #include <GeomProjLib.hxx>
181 #include <ElCLib.hxx>
182 #include <Geom_TrimmedCurve.hxx>
183 #include <Geom_Surface.hxx>
184 #include <Geom_SurfaceOfLinearExtrusion.hxx>
185 #include <Geom_OffsetSurface.hxx>
186 #include <Geom_SurfaceOfRevolution.hxx>
187 #include <Geom_RectangularTrimmedSurface.hxx>
188
189 //===============================================================
190 //function: FUN_GetMinMaxXYZPnt
191 //===============================================================
192 static void FUN_GetMinMaxXYZPnt( const Handle(Adaptor3d_HSurface)& S,
193                                  gp_Pnt& pMin, gp_Pnt& pMax )
194 {
195   const Standard_Real DU = 0.25 * Abs(S->LastUParameter() - S->FirstUParameter());
196   const Standard_Real DV = 0.25 * Abs(S->LastVParameter() - S->FirstVParameter());
197   Standard_Real tMinXYZ = RealLast();
198   Standard_Real tMaxXYZ = -tMinXYZ;
199   gp_Pnt PUV, ptMax, ptMin;
200   for(Standard_Real U = S->FirstUParameter(); U <= S->LastUParameter(); U += DU)
201   {
202     for(Standard_Real V = S->FirstVParameter(); V <= S->LastVParameter(); V += DV)
203         {
204           S->D0(U,V,PUV);
205       const Standard_Real cXYZ = PUV.XYZ().Modulus();
206           if(cXYZ > tMaxXYZ) { tMaxXYZ = cXYZ; ptMax = PUV; }
207           if(cXYZ < tMinXYZ) { tMinXYZ = cXYZ; ptMin = PUV; }
208         }
209   }
210   pMin = ptMin;
211   pMax = ptMax;
212 }
213 //==========================================================================
214 //function: FUN_TrimInfSurf
215 //==========================================================================
216 static void FUN_TrimInfSurf(const gp_Pnt& Pmin,
217                             const gp_Pnt& Pmax,
218                             const Handle(Adaptor3d_HSurface)& InfSurf,
219                             const Standard_Real& AlternativeTrimPrm,
220                             Handle(Adaptor3d_HSurface)& TrimS)
221 {
222   Standard_Real TP = AlternativeTrimPrm;
223   Extrema_ExtPS ext1(Pmin, InfSurf->Surface(), 1.e-7, 1.e-7);
224   Extrema_ExtPS ext2(Pmax, InfSurf->Surface(), 1.e-7, 1.e-7);
225   if(ext1.IsDone() || ext2.IsDone())
226   {
227     Standard_Real Umax = -1.e+100, Umin = 1.e+100, Vmax = -1.e+100, Vmin = 1.e+100, cU, cV;
228     if(ext1.IsDone())
229         {
230       for(Standard_Integer i = 1; i <= ext1.NbExt(); i++)
231       {
232             const Extrema_POnSurf & pons = ext1.Point(i);
233             pons.Parameter(cU,cV);
234             if(cU > Umax) Umax = cU;
235             if(cU < Umin) Umin = cU;
236             if(cV > Vmax) Vmax = cV;
237             if(cV < Vmin) Vmin = cV;
238       }
239         }
240     if(ext2.IsDone())
241         {
242       for(Standard_Integer i = 1; i <= ext2.NbExt(); i++)
243       {
244         const Extrema_POnSurf & pons = ext2.Point(i);
245         pons.Parameter(cU,cV);
246         if(cU > Umax) Umax = cU;
247         if(cU < Umin) Umin = cU;
248         if(cV > Vmax) Vmax = cV;
249         if(cV < Vmin) Vmin = cV;
250       }
251         }
252     TP = Max(Abs(Umin),Max(Abs(Umax),Max(Abs(Vmin),Abs(Vmax))));
253   }
254   if(TP == 0.) { TrimS = InfSurf; return; }
255   else
256   {
257     const Standard_Boolean Uinf = Precision::IsNegativeInfinite(InfSurf->FirstUParameter()); 
258     const Standard_Boolean Usup = Precision::IsPositiveInfinite(InfSurf->LastUParameter());
259     const Standard_Boolean Vinf = Precision::IsNegativeInfinite(InfSurf->FirstVParameter()); 
260     const Standard_Boolean Vsup = Precision::IsPositiveInfinite(InfSurf->LastVParameter());
261     Handle(Adaptor3d_HSurface) TmpSS;
262     Standard_Integer IsTrimed = 0;
263     const Standard_Real tp = 1000.0 * TP;
264     if(Vinf && Vsup) { TrimS = InfSurf->VTrim(-tp, tp, 1.0e-7); IsTrimed = 1; }
265     if(Vinf && !Vsup){ TrimS = InfSurf->VTrim(-tp, InfSurf->LastVParameter(), 1.0e-7); IsTrimed = 1; }
266     if(!Vinf && Vsup){ TrimS = InfSurf->VTrim(InfSurf->FirstVParameter(), tp, 1.0e-7); IsTrimed = 1; }
267     if(IsTrimed)
268         {
269           TmpSS = TrimS;
270           if(Uinf && Usup)  TrimS = TmpSS->UTrim(-tp, tp, 1.0e-7);
271           if(Uinf && !Usup) TrimS = TmpSS->UTrim(-tp, InfSurf->LastUParameter(), 1.0e-7);
272           if(!Uinf && Usup) TrimS = TmpSS->UTrim(InfSurf->FirstUParameter(), tp, 1.0e-7);
273         }
274     else
275         {
276           if(Uinf && Usup)  TrimS = InfSurf->UTrim(-tp, tp, 1.0e-7);
277           if(Uinf && !Usup) TrimS = InfSurf->UTrim(-tp, InfSurf->LastUParameter(), 1.0e-7);
278           if(!Uinf && Usup) TrimS = InfSurf->UTrim(InfSurf->FirstUParameter(), tp, 1.0e-7);
279         }
280   }
281 }
282 //================================================================================
283 //function: FUN_GetUiso
284 //================================================================================
285 static void FUN_GetUiso(const Handle(Geom_Surface)& GS,
286                         const GeomAbs_SurfaceType&  T,
287                         const Standard_Real&        FirstV,
288                         const Standard_Real&        LastV,
289                         const Standard_Boolean&     IsVC,
290                         const Standard_Boolean&     IsVP,
291                         const Standard_Real&        U,
292                         Handle(Geom_Curve)&         I)
293 {
294   if(T !=  GeomAbs_OffsetSurface)
295   {
296     Handle(Geom_Curve) gc = GS->UIso(U);
297     if(IsVP && (FirstV == 0.0 && LastV == (2.*M_PI))) I = gc;
298     else
299         {
300           Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstV,LastV);
301           //szv:I = Handle(Geom_Curve)::DownCast(gtc);
302           I = gtc;
303         }
304   }
305   else//OffsetSurface
306   {
307     const Handle(Geom_OffsetSurface) gos = *(Handle_Geom_OffsetSurface*)&GS;
308     const Handle(Geom_Surface) bs = gos->BasisSurface();
309     Handle(Geom_Curve) gcbs = bs->UIso(U);
310     GeomAdaptor_Curve gac(gcbs);
311     const GeomAbs_CurveType GACT = gac.GetType();
312     if(IsVP || IsVC || GACT == GeomAbs_BSplineCurve || GACT == GeomAbs_BezierCurve || Abs(LastV - FirstV) < 1.e+5)
313         {
314           Handle(Geom_Curve) gc = gos->UIso(U);
315           if(IsVP && (FirstV == 0.0 && LastV == (2*M_PI))) I = gc;
316           else
317       {
318             Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstV,LastV);
319             //szv:I = Handle(Geom_Curve)::DownCast(gtc);
320             I = gtc;
321           }
322         }
323     else//Offset Line, Parab, Hyperb
324         {
325           Standard_Real VmTr, VMTr;
326           if(GACT != GeomAbs_Hyperbola)
327       {
328             if(FirstV >= 0. && LastV >= 0.){ VmTr = FirstV; VMTr = ((LastV - FirstV) > 1.e+4) ? (FirstV + 1.e+4) : LastV; }
329             else if(FirstV < 0. && LastV < 0.){ VMTr = LastV; VmTr = ((FirstV - LastV) < -1.e+4) ? (LastV - 1.e+4) : FirstV; }
330             else { VmTr = (FirstV < -1.e+4) ? -1.e+4 : FirstV; VMTr = (LastV > 1.e+4) ? 1.e+4 : LastV; }
331           }
332           else//Hyperbola
333           {
334             if(FirstV >= 0. && LastV >= 0.)
335                 {
336                   if(FirstV > 4.) return;
337                   VmTr = FirstV; VMTr = (LastV > 4.) ? 4. : LastV;
338                 }
339             else if(FirstV < 0. && LastV < 0.)
340                 {
341                   if(LastV < -4.) return;
342                   VMTr = LastV; VmTr = (FirstV < -4.) ? -4. : FirstV;
343                 }
344             else { VmTr = (FirstV < -4.) ? -4. : FirstV; VMTr = (LastV > 4.) ? 4. : LastV; }
345           }
346           //Make trimmed surface
347           Handle(Geom_RectangularTrimmedSurface) rts = new Geom_RectangularTrimmedSurface(gos,VmTr,VMTr,Standard_True);
348           I = rts->UIso(U);
349         }
350   }
351 }
352 //================================================================================
353 //function: FUN_GetViso
354 //================================================================================
355 static void FUN_GetViso(const Handle(Geom_Surface)& GS,
356                         const GeomAbs_SurfaceType&  T,
357                         const Standard_Real&        FirstU,
358                         const Standard_Real&        LastU,
359                         const Standard_Boolean&     IsUC,
360                         const Standard_Boolean&     IsUP,
361                         const Standard_Real&        V,
362                         Handle(Geom_Curve)&         I)
363 {
364   if(T !=  GeomAbs_OffsetSurface)
365   {
366     Handle(Geom_Curve) gc = GS->VIso(V);
367     if(IsUP && (FirstU == 0.0 && LastU == (2*M_PI))) I = gc;
368     else
369         {
370           Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstU,LastU);
371           //szv:I = Handle(Geom_Curve)::DownCast(gtc);
372           I = gtc;
373         }
374   }
375   else//OffsetSurface
376   {
377     const Handle(Geom_OffsetSurface) gos = *(Handle_Geom_OffsetSurface*)&GS;
378     const Handle(Geom_Surface) bs = gos->BasisSurface();
379     Handle(Geom_Curve) gcbs = bs->VIso(V);
380     GeomAdaptor_Curve gac(gcbs);
381     const GeomAbs_CurveType GACT = gac.GetType();
382     if(IsUP || IsUC || GACT == GeomAbs_BSplineCurve || GACT == GeomAbs_BezierCurve || Abs(LastU - FirstU) < 1.e+5)
383         {
384           Handle(Geom_Curve) gc = gos->VIso(V);
385           if(IsUP && (FirstU == 0.0 && LastU == (2*M_PI))) I = gc;
386           else
387           {
388             Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstU,LastU);
389             //szv:I = Handle(Geom_Curve)::DownCast(gtc);
390             I = gtc;
391           }
392         }
393     else//Offset Line, Parab, Hyperb
394         {
395           Standard_Real UmTr, UMTr;
396           if(GACT != GeomAbs_Hyperbola)
397           {
398             if(FirstU >= 0. && LastU >= 0.){ UmTr = FirstU; UMTr = ((LastU - FirstU) > 1.e+4) ? (FirstU + 1.e+4) : LastU; }
399             else if(FirstU < 0. && LastU < 0.){ UMTr = LastU; UmTr = ((FirstU - LastU) < -1.e+4) ? (LastU - 1.e+4) : FirstU; }
400             else { UmTr = (FirstU < -1.e+4) ? -1.e+4 : FirstU; UMTr = (LastU > 1.e+4) ? 1.e+4 : LastU; }
401           }
402           else//Hyperbola
403           {
404             if(FirstU >= 0. && LastU >= 0.)
405                 {
406                   if(FirstU > 4.) return;
407                   UmTr = FirstU; UMTr = (LastU > 4.) ? 4. : LastU;
408                 }
409             else if(FirstU < 0. && LastU < 0.)
410                 {
411                   if(LastU < -4.) return;
412                   UMTr = LastU; UmTr = (FirstU < -4.) ? -4. : FirstU;
413                 }
414             else { UmTr = (FirstU < -4.) ? -4. : FirstU; UMTr = (LastU > 4.) ? 4. : LastU; }
415             }
416           //Make trimmed surface
417           Handle(Geom_RectangularTrimmedSurface) rts = new Geom_RectangularTrimmedSurface(gos,UmTr,UMTr,Standard_True);
418           I = rts->VIso(V);
419         }
420   }
421 }
422 //================================================================================
423 //function: FUN_PL_Intersection
424 //================================================================================
425 static void FUN_PL_Intersection(const Handle(Adaptor3d_HSurface)& S1,
426                                 const GeomAbs_SurfaceType&        T1,
427                                 const Handle(Adaptor3d_HSurface)& S2,
428                                 const GeomAbs_SurfaceType&        T2,
429                                 Standard_Boolean&                 IsOk,
430                                 TColgp_SequenceOfPnt&             SP,
431                                 gp_Vec&                           DV)
432 {
433   IsOk = Standard_False;
434   // 1. Check: both surfaces have U(V)isos - lines.
435   DV = gp_Vec(0.,0.,1.);
436   Standard_Boolean isoS1isLine[2] = {0, 0};
437   Standard_Boolean isoS2isLine[2] = {0, 0};
438   Handle(Geom_Curve) C1, C2;
439   const GeomAdaptor_Surface & gas1 = *(GeomAdaptor_Surface*)(&(S1->Surface()));
440   const GeomAdaptor_Surface & gas2 = *(GeomAdaptor_Surface*)(&(S2->Surface()));
441   const Handle(Geom_Surface) gs1 = gas1.Surface();
442   const Handle(Geom_Surface) gs2 = gas2.Surface();
443   Standard_Real MS1[2], MS2[2];
444   MS1[0] = 0.5 * (S1->LastUParameter() + S1->FirstUParameter());
445   MS1[1] = 0.5 * (S1->LastVParameter() + S1->FirstVParameter());
446   MS2[0] = 0.5 * (S2->LastUParameter() + S2->FirstUParameter());
447   MS2[1] = 0.5 * (S2->LastVParameter() + S2->FirstVParameter());
448   if(T1 == GeomAbs_SurfaceOfExtrusion) isoS1isLine[0] = Standard_True;
449   else if(!S1->IsVPeriodic() && !S1->IsVClosed()) {
450     if(T1 != GeomAbs_OffsetSurface) C1 = gs1->UIso(MS1[0]);
451     else {
452       const Handle(Geom_OffsetSurface) gos = *(Handle_Geom_OffsetSurface*)&gs1;
453       const Handle(Geom_Surface) bs = gos->BasisSurface();
454       C1 = bs->UIso(MS1[0]);
455     }
456     GeomAdaptor_Curve gac(C1);
457     if(gac.GetType() == GeomAbs_Line) isoS1isLine[0] = Standard_True;
458   }
459   if(!S1->IsUPeriodic() && !S1->IsUClosed()) {
460     if(T1 != GeomAbs_OffsetSurface) C1 = gs1->VIso(MS1[1]);
461     else {
462       const Handle(Geom_OffsetSurface) gos = *(Handle_Geom_OffsetSurface*)&gs1;
463       const Handle(Geom_Surface) bs = gos->BasisSurface();
464       C1 = bs->VIso(MS1[1]);
465     }
466     GeomAdaptor_Curve gac(C1);
467     if(gac.GetType() == GeomAbs_Line) isoS1isLine[1] = Standard_True;
468   }
469   if(T2 == GeomAbs_SurfaceOfExtrusion) isoS2isLine[0] = Standard_True;
470   else if(!S2->IsVPeriodic() && !S2->IsVClosed()) {
471     if(T2 != GeomAbs_OffsetSurface) C2 = gs2->UIso(MS2[0]);
472     else {
473       const Handle(Geom_OffsetSurface) gos = *(Handle_Geom_OffsetSurface*)&gs2;
474       const Handle(Geom_Surface) bs = gos->BasisSurface();
475       C2 = bs->UIso(MS2[0]);
476     }
477     GeomAdaptor_Curve gac(C2);
478     if(gac.GetType() == GeomAbs_Line) isoS2isLine[0] = Standard_True;
479   }
480   if(!S2->IsUPeriodic() && !S2->IsUClosed()) {
481     if(T2 != GeomAbs_OffsetSurface) C2 = gs2->VIso(MS2[1]);
482     else {
483       const Handle(Geom_OffsetSurface) gos = *(Handle_Geom_OffsetSurface*)&gs2;
484       const Handle(Geom_Surface) bs = gos->BasisSurface();
485       C2 = bs->VIso(MS2[1]);
486     }
487     GeomAdaptor_Curve gac(C2);
488     if(gac.GetType() == GeomAbs_Line) isoS2isLine[1] = Standard_True;
489   }
490   Standard_Boolean IsBothLines = ((isoS1isLine[0] || isoS1isLine[1]) &&
491                                   (isoS2isLine[0] || isoS2isLine[1]));
492   if(!IsBothLines){
493     return;
494   }
495   // 2. Check: Uiso lines of both surfaces are collinear.
496   gp_Pnt puvS1, puvS2;
497   gp_Vec derS1[2], derS2[2];
498   S1->D1(MS1[0], MS1[1], puvS1, derS1[0], derS1[1]);
499   S2->D1(MS2[0], MS2[1], puvS2, derS2[0], derS2[1]);
500   C1.Nullify(); C2.Nullify();
501   Standard_Integer iso = 0;
502   if(isoS1isLine[0] && isoS2isLine[0] &&
503      derS1[1].IsParallel(derS2[1],Precision::Angular())) {
504     iso = 1;
505     FUN_GetViso(gs1,T1,S1->FirstUParameter(),S1->LastUParameter(),
506                 S1->IsUClosed(),S1->IsUPeriodic(),MS1[1],C1);
507     FUN_GetViso(gs2,T2,S2->FirstUParameter(),S2->LastUParameter(),
508                 S2->IsUClosed(),S2->IsUPeriodic(),MS2[1],C2);
509   }
510   else if(isoS1isLine[0] && isoS2isLine[1] &&
511           derS1[1].IsParallel(derS2[0],Precision::Angular())) {
512     iso = 1;
513     FUN_GetViso(gs1,T1,S1->FirstUParameter(),S1->LastUParameter(),
514                 S1->IsUClosed(),S1->IsUPeriodic(),MS1[1],C1);
515     FUN_GetUiso(gs2,T2,S2->FirstVParameter(),S2->LastVParameter(),
516                 S2->IsVClosed(),S2->IsVPeriodic(),MS2[0],C2);
517   }
518   else if(isoS1isLine[1] && isoS2isLine[0] &&
519           derS1[0].IsParallel(derS2[1],Precision::Angular())) {
520     iso = 0;
521     FUN_GetUiso(gs1,T1,S1->FirstVParameter(),S1->LastVParameter(),
522                 S1->IsVClosed(),S1->IsVPeriodic(),MS1[0],C1);
523     FUN_GetViso(gs2,T2,S2->FirstUParameter(),S2->LastUParameter(),
524                 S2->IsUClosed(),S2->IsUPeriodic(),MS2[1],C2);
525   }
526   else if(isoS1isLine[1] && isoS2isLine[1] &&
527           derS1[0].IsParallel(derS2[0],Precision::Angular())) {
528     iso = 0;
529     FUN_GetUiso(gs1,T1,S1->FirstVParameter(),S1->LastVParameter(),
530                 S1->IsVClosed(),S1->IsVPeriodic(),MS1[0],C1);
531     FUN_GetUiso(gs2,T2,S2->FirstVParameter(),S2->LastVParameter(),
532                 S2->IsVClosed(),S2->IsVPeriodic(),MS2[0],C2);
533   }
534   else {
535     IsOk = Standard_False;
536     return;
537   }
538   IsOk = Standard_True;
539   // 3. Make intersections of V(U)isos
540   if(C1.IsNull() || C2.IsNull()) return;
541   DV = derS1[iso];
542   Handle(Geom_Plane) GPln = new Geom_Plane(gp_Pln(puvS1,gp_Dir(DV)));
543   Handle(Geom_Curve) C1Prj =
544     GeomProjLib::ProjectOnPlane(C1,GPln,gp_Dir(DV),Standard_True);
545   Handle(Geom_Curve) C2Prj =
546     GeomProjLib::ProjectOnPlane(C2,GPln,gp_Dir(DV),Standard_True);
547   if(C1Prj.IsNull() || C2Prj.IsNull()) return;
548   Handle(Geom2d_Curve) C1Prj2d =
549     GeomProjLib::Curve2d(C1Prj,*(Handle_Geom_Surface *)&GPln);
550   Handle(Geom2d_Curve) C2Prj2d =
551     GeomProjLib::Curve2d(C2Prj,*(Handle_Geom_Surface *)&GPln);
552   Geom2dAPI_InterCurveCurve ICC(C1Prj2d,C2Prj2d,1.0e-7);
553   if(ICC.NbPoints() > 0 )
554   {
555     for(Standard_Integer ip = 1; ip <= ICC.NbPoints(); ip++)
556         {
557           gp_Pnt2d P = ICC.Point(ip);
558           gp_Pnt P3d = ElCLib::To3d(gp_Ax2(puvS1,gp_Dir(DV)),P);
559           SP.Append(P3d);
560         }
561   }
562 }
563 //================================================================================
564 //function: FUN_NewFirstLast
565 //================================================================================
566 static void FUN_NewFirstLast(const GeomAbs_CurveType& ga_ct,
567                              const Standard_Real&     Fst,
568                              const Standard_Real&     Lst,
569                              const Standard_Real&     TrVal,
570                              Standard_Real&           NewFst,
571                              Standard_Real&           NewLst,
572                              Standard_Boolean&        NeedTr)
573 {
574   NewFst = Fst; NewLst = Lst; NeedTr = Standard_False;
575   switch (ga_ct)
576   {
577     case GeomAbs_Line:
578     case GeomAbs_Parabola:
579     {
580       if(Abs(Lst - Fst) > TrVal)
581           {
582             if(Fst >= 0. && Lst >= 0.)
583         {
584               NewFst = Fst;
585               NewLst = ((Fst + TrVal) < Lst) ? (Fst + TrVal) : Lst;
586             }
587             if(Fst < 0. && Lst < 0.)
588             {
589               NewLst = Lst;
590               NewFst = ((Lst - TrVal) > Fst) ? (Lst - TrVal) : Fst;
591             }
592             else
593             {
594               NewFst = (Fst < -TrVal) ? -TrVal : Fst;
595               NewLst = (Lst > TrVal) ? TrVal : Lst;
596             }
597             NeedTr = Standard_True;
598           }
599           break;
600     }
601         case GeomAbs_Hyperbola:
602     {
603       if(Abs(Lst - Fst) > 10.)
604           { 
605             if(Fst >= 0. && Lst >= 0.)
606             {
607               if(Fst > 4.) return;
608               NewFst = Fst;
609               NewLst = (Lst > 4.) ? 4. : Lst;
610             }
611             if(Fst < 0. && Lst < 0.)
612             {
613               if(Lst < -4.) return;
614               NewLst = Lst;
615               NewFst = (Fst < -4.) ? -4. : Fst;
616             }
617             else
618             {
619               NewFst = (Fst < -4.) ? -4. : Fst;
620               NewLst = (Lst > 4.) ? 4. : Lst;
621             }
622             NeedTr = Standard_True;
623           }
624       break;
625     }
626   default:
627     break;
628   }
629 }
630 //================================================================================
631 //function: FUN_TrimBothSurf
632 //================================================================================               
633 static void FUN_TrimBothSurf(const Handle(Adaptor3d_HSurface)& S1,
634                              const GeomAbs_SurfaceType&        T1,
635                              const Handle(Adaptor3d_HSurface)& S2,
636                              const GeomAbs_SurfaceType&        T2,
637                              const Standard_Real&              TV,
638                              Handle(Adaptor3d_HSurface)&       NS1,
639                              Handle(Adaptor3d_HSurface)&       NS2)
640 {
641   const GeomAdaptor_Surface & gas1 = *(GeomAdaptor_Surface*)(&(S1->Surface()));
642   const GeomAdaptor_Surface & gas2 = *(GeomAdaptor_Surface*)(&(S2->Surface()));
643   const Handle(Geom_Surface) gs1 = gas1.Surface();
644   const Handle(Geom_Surface) gs2 = gas2.Surface();
645   const Standard_Real UM1 = 0.5 * (S1->LastUParameter() + S1->FirstUParameter());
646   const Standard_Real UM2 = 0.5 * (S2->LastUParameter() + S2->FirstUParameter());
647   const Standard_Real VM1 = 0.5 * (S1->LastVParameter() + S1->FirstVParameter());
648   const Standard_Real VM2 = 0.5 * (S2->LastVParameter() + S2->FirstVParameter());
649   Handle(Geom_Curve) visoS1, visoS2, uisoS1, uisoS2;
650   if(T1 != GeomAbs_OffsetSurface){ visoS1 = gs1->VIso(VM1); uisoS1 = gs1->UIso(UM1); }
651   else
652   {
653     const Handle(Geom_OffsetSurface) gos = *(Handle_Geom_OffsetSurface*)&gs1;
654     const Handle(Geom_Surface) bs = gos->BasisSurface();
655     visoS1 = bs->VIso(VM1); uisoS1 = bs->UIso(UM1);
656   }
657   if(T2 != GeomAbs_OffsetSurface){ visoS2 = gs2->VIso(VM2); uisoS2 = gs2->UIso(UM2); }
658   else
659   {
660     const Handle(Geom_OffsetSurface) gos = *(Handle_Geom_OffsetSurface*)&gs2;
661     const Handle(Geom_Surface) bs = gos->BasisSurface();
662     visoS2 = bs->VIso(VM2); uisoS2 = bs->UIso(UM2);
663   }
664   if(uisoS1.IsNull() || uisoS2.IsNull() || visoS1.IsNull() || visoS2.IsNull()){ NS1 = S1; NS2 = S2; return; }
665   GeomAdaptor_Curve gau1(uisoS1);
666   GeomAdaptor_Curve gav1(visoS1);
667   GeomAdaptor_Curve gau2(uisoS2);
668   GeomAdaptor_Curve gav2(visoS2);
669   GeomAbs_CurveType GA_U1 = gau1.GetType();
670   GeomAbs_CurveType GA_V1 = gav1.GetType();
671   GeomAbs_CurveType GA_U2 = gau2.GetType();
672   GeomAbs_CurveType GA_V2 = gav2.GetType();
673   Standard_Boolean TrmU1 = Standard_False;
674   Standard_Boolean TrmV1 = Standard_False;
675   Standard_Boolean TrmU2 = Standard_False;
676   Standard_Boolean TrmV2 = Standard_False;
677   Standard_Real V1S1,V2S1,U1S1,U2S1, V1S2,V2S2,U1S2,U2S2;
678   FUN_NewFirstLast(GA_U1,S1->FirstVParameter(),S1->LastVParameter(),TV,V1S1,V2S1,TrmV1);
679   FUN_NewFirstLast(GA_V1,S1->FirstUParameter(),S1->LastUParameter(),TV,U1S1,U2S1,TrmU1);
680   FUN_NewFirstLast(GA_U2,S2->FirstVParameter(),S2->LastVParameter(),TV,V1S2,V2S2,TrmV2);
681   FUN_NewFirstLast(GA_V2,S2->FirstUParameter(),S2->LastUParameter(),TV,U1S2,U2S2,TrmU2);
682   if(TrmV1) NS1 = S1->VTrim(V1S1, V2S1, 1.0e-7);
683   if(TrmV2) NS2 = S2->VTrim(V1S2, V2S2, 1.0e-7);
684   if(TrmU1)
685   {
686     if(TrmV1)
687         {
688           Handle(Adaptor3d_HSurface) TS = NS1;
689           NS1 = TS->UTrim(U1S1, U2S1, 1.0e-7);
690         }
691     else NS1 = S1->UTrim(U1S1, U2S1, 1.0e-7);
692   }
693   if(TrmU2)
694   {
695     if(TrmV2)
696         {
697           Handle(Adaptor3d_HSurface) TS = NS2;
698           NS2 = TS->UTrim(U1S2, U2S2, 1.0e-7);
699         }
700     else NS2 = S2->UTrim(U1S2, U2S2, 1.0e-7);
701   }
702 }
703
704 //=======================================================================
705 //function : Perform
706 //purpose  : 
707 //=======================================================================
708 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)&  theS1,
709                                     const Handle(Adaptor3d_TopolTool)& theD1,
710                                     const Handle(Adaptor3d_HSurface)&  theS2,
711                                     const Handle(Adaptor3d_TopolTool)& theD2,
712                                     const Standard_Real TolArc,
713                                     const Standard_Real TolTang,
714                                     const Standard_Boolean isGeomInt)
715 {
716   myTolArc = TolArc;
717   myTolTang = TolTang;
718   if(myFleche <= Precision::PConfusion())
719     myFleche = 0.01;
720   if(myUVMaxStep <= Precision::PConfusion())
721     myUVMaxStep = 0.01;
722
723   done = Standard_False;
724   spnt.Clear();
725   slin.Clear();
726   empt = Standard_True;
727   tgte = Standard_False;
728   oppo = Standard_False;
729
730   GeomAbs_SurfaceType typs1 = theS1->GetType();
731   GeomAbs_SurfaceType typs2 = theS2->GetType();
732   
733   Standard_Boolean TreatAsBiParametric = Standard_False;
734   if(typs1 == GeomAbs_Cone)
735   {
736     const gp_Cone Con1 = theS1->Cone();
737     const Standard_Real a1 = Abs(Con1.SemiAngle());
738     if((a1 < 0.02) || (a1 > 1.55))
739     {
740       if(typs2==GeomAbs_Plane)
741       {
742         if(a1 < 0.02)
743         {
744           const gp_Pln Plan2 = theS2->Plane();
745           const gp_Dir axec = Con1.Axis().Direction();
746           const gp_Dir axep = Plan2.Axis().Direction();
747           const Standard_Real ps = Abs(axec.Dot(axep));
748           if(ps < 0.015)
749           {
750             TreatAsBiParametric = Standard_True;
751           }
752         }
753       }
754       else
755         TreatAsBiParametric = Standard_True;
756     }
757   }
758
759   if(typs2 == GeomAbs_Cone)
760   {
761     const gp_Cone Con2 = theS2->Cone();
762     const Standard_Real a2 = Abs(Con2.SemiAngle());
763     if((a2 < 0.02) || (a2 > 1.55))
764     {
765       if(typs1 == GeomAbs_Plane)
766       {
767         if(a2 < 0.02)
768         {
769           const gp_Pln Plan1 = theS1->Plane();
770           const gp_Dir axec = Con2.Axis().Direction();
771           const gp_Dir axep = Plan1.Axis().Direction();
772           const Standard_Real ps = Abs(axec.Dot(axep));
773           if(ps<0.015)
774           {
775             TreatAsBiParametric = Standard_True;
776           }
777         }
778       }
779       else
780         TreatAsBiParametric = Standard_True;
781     }
782
783     //// modified by jgv, 15.12.02 for OCC565 ////
784     if (typs1 == GeomAbs_Cone && TreatAsBiParametric)
785     {
786       const gp_Cone Con1 = theS1->Cone();
787       const Standard_Real a1 = Abs(Con1.SemiAngle());
788       //if collinear, treat as canonical
789       const gp_Ax1 A1 = Con1.Axis(), A2 = Con2.Axis();
790       const gp_Lin L1(A1);
791       if (A1.IsParallel(A2,Precision::Angular()) && 
792          (L1.Distance(A2.Location()) <= Precision::Confusion()))
793       {
794         TreatAsBiParametric = Standard_False;
795       }
796       else if (a1 > 1.55 && a2 > 1.55) //quasi-planes: if same domain, treat as canonic
797       {
798         const gp_Ax1 A1 = Con1.Axis(), A2 = Con2.Axis();
799         if (A1.IsParallel(A2,Precision::Angular()))
800         {
801           const gp_Pnt Apex1 = Con1.Apex(), Apex2 = Con2.Apex();
802           const gp_Pln Plan1( Apex1, A1.Direction() );
803           if (Plan1.Distance( Apex2 ) <= Precision::Confusion())
804           {
805             TreatAsBiParametric = Standard_False;
806           }
807         }
808       }
809     }// if (typs1 == GeomAbs_Cone)    {
810   }// if(typs2 == GeomAbs_Cone)  {
811
812   if(theD1->DomainIsInfinite() || theD2->DomainIsInfinite()) {
813     TreatAsBiParametric= Standard_False;
814   }
815
816 //  Modified by skv - Mon Sep 26 14:58:30 2005 Begin
817 //   if(TreatAsBiParametric) { typs1 = typs2 = GeomAbs_BezierSurface; }
818   if(TreatAsBiParametric)
819   {
820     if (typs1 == GeomAbs_Cone && typs2 == GeomAbs_Plane)
821       typs1 = GeomAbs_BezierSurface; // Using Imp-Prm Intersector
822     else if (typs1 == GeomAbs_Plane && typs2 == GeomAbs_Cone)
823       typs2 = GeomAbs_BezierSurface; // Using Imp-Prm Intersector
824     else {
825       // Using Prm-Prm Intersector
826       typs1 = GeomAbs_BezierSurface;
827       typs2 = GeomAbs_BezierSurface;
828     }
829   }
830 //  Modified by skv - Mon Sep 26 14:58:30 2005 End
831
832   // Surface type definition
833   Standard_Integer ts1 = 0;
834   switch (typs1)
835   {
836     case GeomAbs_Plane:
837     case GeomAbs_Cylinder:
838     case GeomAbs_Sphere:
839     case GeomAbs_Cone: ts1 = 1; break;
840     default: break;
841   }
842
843   Standard_Integer ts2 = 0;
844   switch (typs2)
845   {
846     case GeomAbs_Plane:
847     case GeomAbs_Cylinder:
848     case GeomAbs_Sphere:
849     case GeomAbs_Cone: ts2 = 1; break;
850     default: break;
851   }
852   //
853   // treatment of the cases with torus and any other geom surface
854   if ((typs1 == GeomAbs_Torus && ts2) ||
855       (typs2 == GeomAbs_Torus && ts1) ||
856       (typs1 == GeomAbs_Torus && typs2 == GeomAbs_Torus)) {
857     // check if axes collinear
858     //
859     const Handle(Adaptor3d_HSurface)& aTorSurf = 
860       (typs1 == GeomAbs_Torus) ? theS1 : theS2;
861     const Handle(Adaptor3d_HSurface)& aGeomSurf = 
862       (typs1 == GeomAbs_Torus) ? theS2 : theS1;
863     //
864     Standard_Boolean bValid = 
865       aTorSurf->Torus().MajorRadius() > aTorSurf->Torus().MinorRadius();
866     if (bValid && (typs1 == typs2)) {
867       bValid = aGeomSurf->Torus().MajorRadius() > aGeomSurf->Torus().MinorRadius();
868     }
869     //
870     if (bValid) {
871       Standard_Boolean bCheck, bImpImp;
872       const gp_Ax1 aTorAx = aTorSurf->Torus().Axis();
873       const gp_Lin aL1(aTorAx);
874       //
875       bCheck = Standard_True;
876       bImpImp = Standard_False;
877       //
878       gp_Ax1 aGeomAx;
879       switch (aGeomSurf->GetType()) {
880       case GeomAbs_Plane: {
881         aGeomAx = aGeomSurf->Plane().Axis();
882         if (aTorAx.IsParallel(aGeomAx, Precision::Angular()) ||
883             (aTorAx.IsNormal(aGeomAx, Precision::Angular()) && 
884              (aGeomSurf->Plane().Distance(aTorAx.Location()) < Precision::Confusion()))) {
885           bImpImp = Standard_True;
886         }
887         bCheck = Standard_False;
888         break;
889       }
890       case GeomAbs_Sphere: {
891         if (aL1.Distance(aGeomSurf->Sphere().Location()) < Precision::Confusion()) {
892           bImpImp = Standard_True;
893         }
894         bCheck = Standard_False;
895         break;
896       }
897       case GeomAbs_Cylinder:
898         aGeomAx = aGeomSurf->Cylinder().Axis();
899         break;
900       case GeomAbs_Cone: 
901         aGeomAx = aGeomSurf->Cone().Axis();
902         break;
903       case GeomAbs_Torus: 
904         aGeomAx = aGeomSurf->Torus().Axis();
905         break;
906       default: 
907         bCheck = Standard_False;
908         break;
909       }
910       //
911       if (bCheck) {
912         if (aTorAx.IsParallel(aGeomAx, Precision::Angular()) &&
913             (aL1.Distance(aGeomAx.Location()) <= Precision::Confusion())) {
914           bImpImp = Standard_True;
915         }
916       }
917       //
918       if (bImpImp) {
919         ts1 = 1;
920         ts2 = 1;
921       }
922     }
923   }
924   //
925   // Possible intersection types: 1. ts1 == ts2 == 1 <Geom-Geom>
926   //                              2. ts1 != ts2      <Geom-Param>
927   //                              3. ts1 == ts2 == 0 <Param-Param>
928
929   // Geom - Geom
930   if(ts1 == ts2 && ts1 == 1)
931   {
932     const Standard_Boolean RestrictLine = Standard_True;
933     IntSurf_ListOfPntOn2S ListOfPnts;
934     ListOfPnts.Clear();
935     if(isGeomInt)
936     {
937       GeomGeomPerfom(theS1, theD1, theS2, theD2, TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
938     }
939     else
940     {
941       ParamParamPerfom(theS1, theD1, theS2, theD2, TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
942     }
943   }
944
945   // Geom - Param
946   if(ts1 != ts2)
947   {
948     GeomParamPerfom(theS1, theD1, theS2, theD2, ts1 == 0, typs1, typs2);
949   }
950
951   // Param - Param 
952   if(ts1 == ts2 && ts1 == 0)
953   {
954     const Standard_Boolean RestrictLine = Standard_True;
955     IntSurf_ListOfPntOn2S ListOfPnts;
956     ListOfPnts.Clear();
957
958     ParamParamPerfom(theS1, theD1, theS2, theD2, TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
959   }
960 }
961                       
962 //=======================================================================
963 //function : Perform
964 //purpose  : 
965 //=======================================================================
966 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)&  theS1,
967                                     const Handle(Adaptor3d_TopolTool)& theD1,
968                                     const Handle(Adaptor3d_HSurface)&  theS2,
969                                     const Handle(Adaptor3d_TopolTool)& theD2,
970                                     const Standard_Real TolArc,
971                                     const Standard_Real TolTang,
972                                     IntSurf_ListOfPntOn2S& ListOfPnts,
973                                     const Standard_Boolean RestrictLine,
974                                     const Standard_Boolean isGeomInt)
975 {
976   myTolArc = TolArc;
977   myTolTang = TolTang;
978   if(myFleche <= Precision::PConfusion())
979     myFleche = 0.01;
980   if(myUVMaxStep <= Precision::PConfusion())
981     myUVMaxStep = 0.01;
982     
983   done = Standard_False;
984   spnt.Clear();
985   slin.Clear();
986   empt = Standard_True;
987   tgte = Standard_False;
988   oppo = Standard_False;
989
990   GeomAbs_SurfaceType typs1 = theS1->GetType();
991   GeomAbs_SurfaceType typs2 = theS2->GetType();
992   
993   Standard_Boolean TreatAsBiParametric = Standard_False;
994   if(typs1 == GeomAbs_Cone)
995   {
996     const gp_Cone Con1 = theS1->Cone();
997     const Standard_Real a1 = Abs(Con1.SemiAngle());
998     if((a1 < 0.02) || (a1 > 1.55))
999     {
1000       if(typs2==GeomAbs_Plane)
1001       {
1002         if(a1 < 0.02)
1003         {
1004           const gp_Pln Plan2 = theS2->Plane();
1005           const gp_Dir axec = Con1.Axis().Direction();
1006           const gp_Dir axep = Plan2.Axis().Direction();
1007           const Standard_Real ps = Abs(axec.Dot(axep));
1008           if(ps < 0.015)
1009           {
1010             TreatAsBiParametric = Standard_True;
1011           }
1012         }
1013       }
1014       else
1015         TreatAsBiParametric = Standard_True;
1016     }
1017   }
1018
1019   if(typs2 == GeomAbs_Cone)
1020   {
1021     const gp_Cone Con2 = theS2->Cone();
1022     const Standard_Real a2 = Abs(Con2.SemiAngle());
1023     if((a2 < 0.02) || (a2 > 1.55))
1024     {
1025       if(typs1 == GeomAbs_Plane)
1026       {
1027         if(a2 < 0.02)
1028         {
1029           const gp_Pln Plan1 = theS1->Plane();
1030           const gp_Dir axec = Con2.Axis().Direction();
1031           const gp_Dir axep = Plan1.Axis().Direction();
1032           const Standard_Real ps = Abs(axec.Dot(axep));
1033           if(ps<0.015)
1034           {
1035             TreatAsBiParametric = Standard_True;
1036           }
1037         }
1038       }
1039       else
1040         TreatAsBiParametric = Standard_True;
1041     }
1042
1043     //// modified by jgv, 15.12.02 for OCC565 ////
1044     if (typs1 == GeomAbs_Cone && TreatAsBiParametric)
1045     {
1046       const gp_Cone Con1 = theS1->Cone();
1047       const Standard_Real a1 = Abs(Con1.SemiAngle());
1048       //if collinear, treat as canonical
1049       const gp_Ax1 A1 = Con1.Axis(), A2 = Con2.Axis();
1050       const gp_Lin L1(A1);
1051       if (A1.IsParallel(A2,Precision::Angular()) &&
1052          (L1.Distance(A2.Location()) <= Precision::Confusion()))
1053       {
1054         TreatAsBiParametric = Standard_False;
1055       }
1056       else if (a1 > 1.55 && a2 > 1.55) //quasi-planes: if same domain, treat as canonic
1057       {
1058         const gp_Ax1 A1 = Con1.Axis(), A2 = Con2.Axis();
1059         if (A1.IsParallel(A2,Precision::Angular()))
1060         {
1061           const gp_Pnt Apex1 = Con1.Apex(), Apex2 = Con2.Apex();
1062           const gp_Pln Plan1( Apex1, A1.Direction() );
1063           if (Plan1.Distance( Apex2 ) <= Precision::Confusion())
1064           {
1065             TreatAsBiParametric = Standard_False;
1066           }
1067         }
1068       }
1069     }// if (typs1 == GeomAbs_Cone)    {
1070   }// if(typs2 == GeomAbs_Cone)  {
1071
1072   if(theD1->DomainIsInfinite() || theD2->DomainIsInfinite()) {
1073     TreatAsBiParametric= Standard_False;
1074   }
1075
1076   if(TreatAsBiParametric)
1077   {
1078     // Using Prm-Prm Intersector
1079     typs1 = GeomAbs_BezierSurface;
1080     typs2 = GeomAbs_BezierSurface;
1081   }
1082
1083   // Surface type definition
1084   Standard_Integer ts1 = 0;
1085   switch (typs1)
1086   {
1087     case GeomAbs_Plane:
1088     case GeomAbs_Cylinder:
1089     case GeomAbs_Sphere:
1090     case GeomAbs_Cone: ts1 = 1; break;
1091     default: break;
1092   }
1093
1094   Standard_Integer ts2 = 0;
1095   switch (typs2)
1096   {
1097     case GeomAbs_Plane:
1098     case GeomAbs_Cylinder:
1099     case GeomAbs_Sphere:
1100     case GeomAbs_Cone: ts2 = 1; break;
1101     default: break;
1102   }
1103   //
1104   // treatment of the cases with torus and any other geom surface
1105   if ((typs1 == GeomAbs_Torus && ts2) ||
1106       (typs2 == GeomAbs_Torus && ts1) ||
1107       (typs1 == GeomAbs_Torus && typs2 == GeomAbs_Torus)) {
1108     // check if axes collinear
1109     //
1110     const Handle(Adaptor3d_HSurface)& aTorSurf = 
1111       (typs1 == GeomAbs_Torus) ? theS1 : theS2;
1112     const Handle(Adaptor3d_HSurface)& aGeomSurf = 
1113       (typs1 == GeomAbs_Torus) ? theS2 : theS1;
1114     //
1115     Standard_Boolean bValid = 
1116       aTorSurf->Torus().MajorRadius() > aTorSurf->Torus().MinorRadius();
1117     if (bValid && (typs1 == typs2)) {
1118       bValid = aGeomSurf->Torus().MajorRadius() > aGeomSurf->Torus().MinorRadius();
1119     }
1120     //
1121     if (bValid) {
1122       Standard_Boolean bCheck, bImpImp;
1123       const gp_Ax1 aTorAx = aTorSurf->Torus().Axis();
1124       const gp_Lin aL1(aTorAx);
1125       //
1126       bCheck = Standard_True;
1127       bImpImp = Standard_False;
1128       //
1129       gp_Ax1 aGeomAx;
1130       switch (aGeomSurf->GetType()) {
1131       case GeomAbs_Plane: {
1132         aGeomAx = aGeomSurf->Plane().Axis();
1133         if (aTorAx.IsParallel(aGeomAx, Precision::Angular()) ||
1134             (aTorAx.IsNormal(aGeomAx, Precision::Angular()) && 
1135              (aGeomSurf->Plane().Distance(aTorAx.Location()) < Precision::Confusion()))) {
1136           bImpImp = Standard_True;
1137         }
1138         bCheck = Standard_False;
1139         break;
1140       }
1141       case GeomAbs_Sphere: {
1142         if (aL1.Distance(aGeomSurf->Sphere().Location()) < Precision::Confusion()) {
1143           bImpImp = Standard_True;
1144         }
1145         bCheck = Standard_False;
1146         break;
1147       }
1148       case GeomAbs_Cylinder:
1149         aGeomAx = aGeomSurf->Cylinder().Axis();
1150         break;
1151       case GeomAbs_Cone: 
1152         aGeomAx = aGeomSurf->Cone().Axis();
1153         break;
1154       case GeomAbs_Torus: 
1155         aGeomAx = aGeomSurf->Torus().Axis();
1156         break;
1157       default: 
1158         bCheck = Standard_False;
1159         break;
1160       }
1161       //
1162       if (bCheck) {
1163         if (aTorAx.IsParallel(aGeomAx, Precision::Angular()) &&
1164             (aL1.Distance(aGeomAx.Location()) <= Precision::Confusion())) {
1165           bImpImp = Standard_True;
1166         }
1167       }
1168       //
1169       if (bImpImp) {
1170         ts1 = 1;
1171         ts2 = 1;
1172       }
1173     }
1174   }
1175   //
1176   // Possible intersection types: 1. ts1 == ts2 == 1 <Geom-Geom>
1177   //                              2. ts1 != ts2      <Geom-Param>
1178   //                              3. ts1 == ts2 == 0 <Param-Param>
1179
1180   if(!isGeomInt)
1181   {
1182     ParamParamPerfom(theS1, theD1, theS2, theD2, TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
1183   }
1184   else if(ts1 != ts2)
1185   {
1186     GeomParamPerfom(theS1, theD1, theS2, theD2, ts1 == 0, typs1, typs2);
1187   }
1188   else if (ts1 == 0)
1189   {
1190     ParamParamPerfom(theS1, theD1, theS2, theD2, TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
1191   }
1192   else if(ts1 == 1)
1193   {
1194     GeomGeomPerfom(theS1, theD1, theS2, theD2, TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
1195   }
1196 }
1197
1198 //=======================================================================
1199 //function : ParamParamPerfom
1200 //purpose  : 
1201 //=======================================================================
1202 void IntPatch_Intersection::ParamParamPerfom(const Handle(Adaptor3d_HSurface)&  theS1,
1203                                              const Handle(Adaptor3d_TopolTool)& theD1,
1204                                              const Handle(Adaptor3d_HSurface)&  theS2,
1205                                              const Handle(Adaptor3d_TopolTool)& theD2,
1206                                              const Standard_Real TolArc,
1207                                              const Standard_Real TolTang,
1208                                              IntSurf_ListOfPntOn2S& ListOfPnts,
1209                                              const Standard_Boolean RestrictLine,
1210                                              const GeomAbs_SurfaceType typs1,
1211                                              const GeomAbs_SurfaceType typs2)
1212 {
1213   IntPatch_PrmPrmIntersection interpp;
1214   if(!theD1->DomainIsInfinite() && !theD2->DomainIsInfinite())
1215   {
1216     Standard_Boolean ClearFlag = Standard_True;
1217     if(!ListOfPnts.IsEmpty())
1218     {
1219       interpp.Perform(theS1,theD1,theS2,theD2,TolArc,TolTang,myFleche,myUVMaxStep, ListOfPnts, RestrictLine);
1220       ClearFlag = Standard_False;
1221     }
1222     interpp.Perform(theS1,theD1,theS2,theD2,TolArc,TolTang,myFleche,myUVMaxStep,ClearFlag);   //double call!!!!!!!
1223   }
1224   else if((theD1->DomainIsInfinite()) ^ (theD2->DomainIsInfinite()))
1225   {
1226     gp_Pnt pMaxXYZ, pMinXYZ;
1227     if(theD1->DomainIsInfinite())
1228     {
1229       FUN_GetMinMaxXYZPnt( theS2, pMinXYZ, pMaxXYZ );
1230       const Standard_Real MU = Max(Abs(theS2->FirstUParameter()),Abs(theS2->LastUParameter()));
1231       const Standard_Real MV = Max(Abs(theS2->FirstVParameter()),Abs(theS2->LastVParameter()));
1232       const Standard_Real AP = Max(MU, MV);
1233       Handle(Adaptor3d_HSurface) SS;
1234       FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, theS1, AP, SS);
1235       interpp.Perform(SS,theD1,theS2,theD2,TolArc,TolTang,myFleche,myUVMaxStep);
1236     }
1237     else
1238     {
1239       FUN_GetMinMaxXYZPnt( theS1, pMinXYZ, pMaxXYZ );
1240       const Standard_Real MU = Max(Abs(theS1->FirstUParameter()),Abs(theS1->LastUParameter()));
1241       const Standard_Real MV = Max(Abs(theS1->FirstVParameter()),Abs(theS1->LastVParameter()));
1242       const Standard_Real AP = Max(MU, MV);
1243       Handle(Adaptor3d_HSurface) SS;
1244       FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, theS2, AP, SS);
1245       interpp.Perform(theS1, theD1, SS, theD2,TolArc,TolTang,myFleche,myUVMaxStep);
1246     }
1247   }//(theD1->DomainIsInfinite()) ^ (theD2->DomainIsInfinite())
1248   else
1249   {
1250     if(typs1 == GeomAbs_OtherSurface || typs2 == GeomAbs_OtherSurface)
1251     {
1252       done = Standard_False;
1253       return;
1254     }
1255
1256     Standard_Boolean IsPLInt = Standard_False;
1257     TColgp_SequenceOfPnt sop;
1258     gp_Vec v;
1259     FUN_PL_Intersection(theS1,typs1,theS2,typs2,IsPLInt,sop,v);
1260
1261     if(IsPLInt)
1262     {
1263       if(sop.Length() > 0)
1264       {
1265         for(Standard_Integer ip = 1; ip <= sop.Length(); ip++)
1266         {
1267           gp_Lin lin(sop.Value(ip),gp_Dir(v));
1268           Handle(IntPatch_GLine) gl = new IntPatch_GLine(lin,Standard_False);
1269           slin.Append(*(Handle_IntPatch_Line *)&gl);
1270         }
1271
1272         done = Standard_True;
1273       }
1274       else
1275         done = Standard_False;
1276
1277       return;
1278     }// 'COLLINEAR LINES'
1279     else
1280     {
1281       Handle(Adaptor3d_HSurface) nS1 = theS1;
1282       Handle(Adaptor3d_HSurface) nS2 = theS2;
1283       FUN_TrimBothSurf(theS1,typs1,theS2,typs2,1.e+8,nS1,nS2);
1284       interpp.Perform(nS1,theD1,nS2,theD2,TolArc,TolTang,myFleche,myUVMaxStep);
1285     }// 'NON - COLLINEAR LINES'
1286   }// both domains are infinite
1287
1288   if (interpp.IsDone())
1289   {
1290     done = Standard_True;
1291     tgte = Standard_False;
1292     empt = interpp.IsEmpty();
1293
1294     for(Standard_Integer i = 1; i <= interpp.NbLines(); i++)
1295     {
1296       if(interpp.Line(i)->ArcType() != IntPatch_Walking)
1297         slin.Append(interpp.Line(i));
1298     }
1299
1300     for (Standard_Integer i = 1; i <= interpp.NbLines(); i++)
1301     {
1302       if(interpp.Line(i)->ArcType() == IntPatch_Walking)
1303         slin.Append(interpp.Line(i));
1304     }
1305   }
1306 }
1307
1308 //=======================================================================
1309 ////function : GeomGeomPerfom
1310 //purpose  : 
1311 //=======================================================================
1312 void IntPatch_Intersection::GeomGeomPerfom(const Handle(Adaptor3d_HSurface)& theS1,
1313                                            const Handle(Adaptor3d_TopolTool)& theD1,
1314                                            const Handle(Adaptor3d_HSurface)& theS2,
1315                                            const Handle(Adaptor3d_TopolTool)& theD2,
1316                                            const Standard_Real TolArc,
1317                                            const Standard_Real TolTang,
1318                                            IntSurf_ListOfPntOn2S& ListOfPnts,
1319                                            const Standard_Boolean RestrictLine,
1320                                            const GeomAbs_SurfaceType typs1,
1321                                            const GeomAbs_SurfaceType typs2)
1322 {
1323   IntPatch_ImpImpIntersection interii(theS1,theD1,theS2,theD2,myTolArc,myTolTang);
1324   const Standard_Boolean anIS = interii.IsDone();
1325   if (anIS)
1326   {
1327     done = anIS;
1328     empt = interii.IsEmpty();
1329     if (!empt)
1330     {
1331       tgte = interii.TangentFaces();
1332       if (tgte)
1333         oppo = interii.OppositeFaces();
1334
1335       for (Standard_Integer i = 1; i <= interii.NbLines(); i++)
1336       {
1337         const Handle_IntPatch_Line& line = interii.Line(i);
1338         if (line->ArcType() == IntPatch_Analytic)
1339         {
1340           const GeomAbs_SurfaceType typs1 = theS1->GetType();
1341           const GeomAbs_SurfaceType typs2 = theS2->GetType();
1342           IntSurf_Quadric Quad1,Quad2;
1343           
1344           switch(typs1)
1345           {
1346           case GeomAbs_Plane:
1347             Quad1.SetValue(theS1->Plane());
1348             break;
1349
1350           case GeomAbs_Cylinder:
1351             Quad1.SetValue(theS1->Cylinder());
1352             break;
1353
1354           case GeomAbs_Sphere:
1355             Quad1.SetValue(theS1->Sphere());
1356             break;
1357
1358           case GeomAbs_Cone:
1359             Quad1.SetValue(theS1->Cone());
1360             break;
1361
1362           case GeomAbs_Torus:
1363             Quad1.SetValue(theS1->Torus());
1364             break;
1365
1366           default:
1367             break;
1368           }
1369
1370           switch(typs2)
1371           {
1372           case GeomAbs_Plane:
1373             Quad2.SetValue(theS2->Plane());
1374             break;
1375           case GeomAbs_Cylinder:
1376             Quad2.SetValue(theS2->Cylinder());
1377             break;
1378
1379           case GeomAbs_Sphere:
1380             Quad2.SetValue(theS2->Sphere());
1381             break;
1382
1383           case GeomAbs_Cone:
1384             Quad2.SetValue(theS2->Cone());
1385             break;
1386
1387           case GeomAbs_Torus:
1388             Quad2.SetValue(theS2->Torus());
1389             break;
1390
1391           default:
1392             break;
1393           }
1394
1395           IntPatch_ALineToWLine AToW(Quad1,Quad2,0.01,0.05,aNbPointsInALine);
1396           Handle(IntPatch_Line) wlin=AToW.MakeWLine((*((Handle_IntPatch_ALine *)(&line))));
1397           slin.Append(wlin);
1398         }
1399         else
1400           slin.Append(interii.Line(i));
1401       }
1402
1403       for (Standard_Integer i = 1; i <= interii.NbPnts(); i++)
1404       {
1405         spnt.Append(interii.Point(i));
1406       }
1407     }
1408   }
1409   else
1410     ParamParamPerfom(theS1, theD1, theS2, theD2, TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
1411 }
1412
1413 //=======================================================================
1414 ////function : GeomParamPerfom
1415 //purpose  : 
1416 //=======================================================================
1417 void IntPatch_Intersection::GeomParamPerfom(const Handle(Adaptor3d_HSurface)&  theS1,
1418                                             const Handle(Adaptor3d_TopolTool)& theD1,
1419                                             const Handle(Adaptor3d_HSurface)&  theS2,
1420                                             const Handle(Adaptor3d_TopolTool)& theD2,
1421                                             const Standard_Boolean isNotAnalitical,
1422                                             const GeomAbs_SurfaceType typs1,
1423                                             const GeomAbs_SurfaceType typs2)
1424 {
1425   IntPatch_ImpPrmIntersection interip;
1426   if (myIsStartPnt)
1427   {
1428     if (isNotAnalitical/*ts1 == 0*/)
1429       interip.SetStartPoint(myU1Start,myV1Start);
1430     else
1431       interip.SetStartPoint(myU2Start,myV2Start);
1432   }
1433
1434   if(theD1->DomainIsInfinite() && theD2->DomainIsInfinite())
1435   {
1436     Standard_Boolean IsPLInt = Standard_False;
1437     TColgp_SequenceOfPnt sop;
1438     gp_Vec v;
1439     FUN_PL_Intersection(theS1,typs1,theS2,typs2,IsPLInt,sop,v);
1440     
1441     if(IsPLInt)
1442     {
1443       if(sop.Length() > 0)
1444       {
1445         for(Standard_Integer ip = 1; ip <= sop.Length(); ip++)
1446         {
1447           gp_Lin lin(sop.Value(ip),gp_Dir(v));
1448           Handle(IntPatch_GLine) gl = new IntPatch_GLine(lin,Standard_False);
1449           slin.Append(*(Handle_IntPatch_Line *)&gl);
1450         }
1451
1452         done = Standard_True;
1453       }
1454       else
1455         done = Standard_False;
1456
1457       return;
1458     }
1459     else
1460     {
1461       Handle(Adaptor3d_HSurface) nS1 = theS1;
1462       Handle(Adaptor3d_HSurface) nS2 = theS2;
1463       FUN_TrimBothSurf(theS1,typs1,theS2,typs2,1.e+5,nS1,nS2);
1464       interip.Perform(nS1,theD1,nS2,theD2,myTolArc,myTolTang,myFleche,myUVMaxStep);
1465     }
1466   }
1467   else
1468     interip.Perform(theS1,theD1,theS2,theD2,myTolArc,myTolTang,myFleche,myUVMaxStep);
1469
1470   if (interip.IsDone()) 
1471   {
1472     done = Standard_True;
1473     empt = interip.IsEmpty();
1474
1475     if (!empt)
1476     {
1477       for(Standard_Integer i = 1; i <= interip.NbLines(); i++)
1478       {
1479         if(interip.Line(i)->ArcType() != IntPatch_Walking)
1480           slin.Append(interip.Line(i));
1481       }
1482
1483       for(Standard_Integer i = 1; i <= interip.NbLines(); i++)
1484       {
1485         if(interip.Line(i)->ArcType() == IntPatch_Walking)
1486           slin.Append(interip.Line(i));
1487       }
1488
1489       for (Standard_Integer i = 1; i <= interip.NbPnts(); i++)
1490         spnt.Append(interip.Point(i));
1491     }
1492   }
1493 }
1494
1495
1496 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)&  S1,
1497                                     const Handle(Adaptor3d_TopolTool)& D1,
1498                                     const Handle(Adaptor3d_HSurface)&  S2,
1499                                     const Handle(Adaptor3d_TopolTool)& D2,
1500                                     const Standard_Real U1,
1501                                     const Standard_Real V1,
1502                                     const Standard_Real U2,
1503                                     const Standard_Real V2,
1504                                     const Standard_Real TolArc,
1505                                     const Standard_Real TolTang)
1506 {
1507   myTolArc = TolArc;
1508   myTolTang = TolTang;
1509   if(myFleche == 0.0) {
1510 #if DEBUG
1511     //cout<<" -- IntPatch_Intersection::myFleche fixe par defaut a 0.01 --"<<endl;
1512     //cout<<" -- Utiliser la Methode SetTolerances( ... ) "<<endl;
1513 #endif
1514     myFleche = 0.01;
1515   }
1516   if(myUVMaxStep==0.0) {
1517 #if DEBUG
1518     //cout<<" -- IntPatch_Intersection::myUVMaxStep fixe par defaut a 0.01 --"<<endl;
1519     //cout<<" -- Utiliser la Methode SetTolerances( ... ) "<<endl;
1520 #endif
1521     myUVMaxStep = 0.01;
1522   }
1523
1524   done = Standard_False;
1525   spnt.Clear();
1526   slin.Clear();
1527
1528   empt = Standard_True;
1529   tgte = Standard_False;
1530   oppo = Standard_False;
1531
1532   const GeomAbs_SurfaceType typs1 = S1->GetType();
1533   const GeomAbs_SurfaceType typs2 = S2->GetType();
1534   
1535   if(   typs1==GeomAbs_Plane 
1536      || typs1==GeomAbs_Cylinder
1537      || typs1==GeomAbs_Sphere
1538      || typs1==GeomAbs_Cone
1539      || typs2==GeomAbs_Plane 
1540      || typs2==GeomAbs_Cylinder
1541      || typs2==GeomAbs_Sphere
1542      || typs2==GeomAbs_Cone)
1543   {
1544     myIsStartPnt = Standard_True;
1545     myU1Start = U1; myV1Start = V1; myU2Start = U2; myV2Start = V2;
1546     Perform(S1,D1,S2,D2,TolArc,TolTang);
1547     myIsStartPnt = Standard_False;
1548   }
1549   else
1550   {
1551     IntPatch_PrmPrmIntersection interpp;
1552     interpp.Perform(S1,D1,S2,D2,U1,V1,U2,V2,TolArc,TolTang,myFleche,myUVMaxStep);
1553     if (interpp.IsDone())
1554         {
1555       done = Standard_True;
1556       tgte = Standard_False;
1557       empt = interpp.IsEmpty();
1558       const Standard_Integer nblm = interpp.NbLines();
1559       Standard_Integer i = 1;
1560       for (; i<=nblm; i++) slin.Append(interpp.Line(i));
1561     }
1562   }
1563 }
1564 //======================================================================
1565 #include <IntPatch_IType.hxx>
1566 #include <IntPatch_LineConstructor.hxx>
1567 #include <Handle_Adaptor2d_HCurve2d.hxx>
1568 #define MAXR 200
1569
1570
1571 //void IntPatch_Intersection__MAJ_R(Handle_Adaptor2d_HCurve2d *R1,
1572 //                                   Handle_Adaptor2d_HCurve2d *R2,
1573 //                                   int *NR1,
1574 //                                   int *NR2,
1575 //                                   Standard_Integer nbR1,
1576 //                                   Standard_Integer nbR2,
1577 //                                   const IntPatch_Point& VTX)
1578 void IntPatch_Intersection__MAJ_R(Handle_Adaptor2d_HCurve2d *,
1579                                      Handle_Adaptor2d_HCurve2d *,
1580                                      int *,
1581                                      int *,
1582                                      Standard_Integer ,
1583                                      Standard_Integer ,
1584                                      const IntPatch_Point& )
1585
1586   /*
1587   if(VTX.IsOnDomS1()) { 
1588     
1589     //-- long unsigned ptr= *((long unsigned *)(((Handle_Standard_Transient *)(&(VTX.ArcOnS1())))));
1590     for(Standard_Integer i=0; i<nbR1;i++) { 
1591       if(VTX.ArcOnS1()==R1[i]) { 
1592         NR1[i]++;
1593         printf("\n ******************************");
1594         return;
1595       }
1596     }
1597     printf("\n R Pas trouvee  (IntPatch)\n");
1598     
1599   }
1600   */
1601 }
1602
1603
1604 //void IntPatch_Intersection::Dump(const Standard_Integer Mode,
1605 void IntPatch_Intersection::Dump(const Standard_Integer ,
1606                                     const Handle(Adaptor3d_HSurface)&  S1,
1607                                     const Handle(Adaptor3d_TopolTool)& D1,
1608                                     const Handle(Adaptor3d_HSurface)&  S2,
1609                                     const Handle(Adaptor3d_TopolTool)& D2) const 
1610
1611   
1612   //-- ----------------------------------------------------------------------
1613   //--  construction de la liste des restrictions & vertex 
1614   //--
1615   int NR1[MAXR],NR2[MAXR];
1616   Handle_Adaptor2d_HCurve2d R1[MAXR],R2[MAXR];
1617   Standard_Integer nbR1=0,nbR2=0;
1618   for(D1->Init();D1->More() && nbR1<MAXR; D1->Next()) { 
1619     R1[nbR1]=D1->Value(); 
1620     NR1[nbR1]=0;
1621     nbR1++;
1622   }
1623   for(D2->Init();D2->More() && nbR2<MAXR; D2->Next()) { 
1624     R2[nbR2]=D2->Value();
1625     NR2[nbR2]=0;
1626     nbR2++;
1627   }
1628   
1629   printf("\nDUMP_INT:  ----empt:%2ud  tgte:%2ud  oppo:%2ud ---------------------------------",empt,tgte,empt);
1630   Standard_Integer i,j,nbr1,nbr2,nbgl,nbgc,nbge,nbgp,nbgh,nbl,nbr,nbg,nbw,nba;
1631   nbl=nbr=nbg=nbw=nba=nbgl=nbge=nbr1=nbr2=nbgc=nbgp=nbgh=0;
1632   nbl=NbLines();
1633   for(i=1;i<=nbl;i++) { 
1634     const Handle(IntPatch_Line)& line=Line(i);
1635     const IntPatch_IType IType=line->ArcType();
1636     if(IType == IntPatch_Walking) nbw++;
1637     else     if(IType == IntPatch_Restriction) { 
1638       nbr++;
1639       Handle(IntPatch_RLine)& rlin =
1640         *((Handle(IntPatch_RLine) *)&line);
1641       if(rlin->IsArcOnS1()) nbr1++;
1642       if(rlin->IsArcOnS2()) nbr2++;
1643     }
1644     else     if(IType == IntPatch_Analytic) nba++;
1645     else     { nbg++; 
1646                if(IType == IntPatch_Lin) nbgl++;
1647                else if(IType == IntPatch_Circle) nbgc++;
1648                else if(IType == IntPatch_Parabola) nbgp++;
1649                else if(IType == IntPatch_Hyperbola) nbgh++;
1650                else if(IType == IntPatch_Ellipse) nbge++;
1651              }
1652   }
1653   
1654   
1655   printf("\nDUMP_INT:Lines:%2d Wlin:%2d Restr:%2d(On1:%2d On2:%2d) Ana:%2d Geom:%2d(L:%2d C:%2d E:%2d H:%2d P:%2d)",
1656          nbl,nbw,nbr,nbr1,nbr2,nba,nbg,nbgl,nbgc,nbge,nbgh,nbgp);
1657   
1658   IntPatch_LineConstructor LineConstructor(2);
1659   
1660   Standard_Integer nbllc=0;
1661   nbw=nbr=nbg=nba=0;
1662   Standard_Integer nbva,nbvw,nbvr,nbvg;
1663   nbva=nbvr=nbvw=nbvg=0;
1664   for (j=1; j<=nbl; j++) {
1665     Standard_Integer v,nbvtx;
1666     const Handle(IntPatch_Line)& intersLinej = Line(j);
1667     Standard_Integer NbLines;
1668     LineConstructor.Perform(SequenceOfLine(),intersLinej,S1,D1,S2,D2,1e-7);
1669     NbLines = LineConstructor.NbLines();
1670     
1671     for(Standard_Integer k=1;k<=NbLines;k++) { 
1672       nbllc++;
1673       const Handle(IntPatch_Line)& LineK = LineConstructor.Line(k);
1674       if (LineK->ArcType() == IntPatch_Analytic) { 
1675         Handle(IntPatch_ALine)& alin =
1676           *((Handle(IntPatch_ALine) *)&LineK);
1677         nbvtx=alin->NbVertex();
1678         nbva+=nbvtx;    nba++;
1679         for(v=1;v<=nbvtx;v++) { 
1680           IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,alin->Vertex(v));
1681         }
1682       }
1683       else if (LineK->ArcType() == IntPatch_Restriction) {
1684         Handle(IntPatch_RLine)& rlin =
1685           *((Handle(IntPatch_RLine) *)&LineK);
1686         nbvtx=rlin->NbVertex();
1687         nbvr+=nbvtx;    nbr++;
1688         for(v=1;v<=nbvtx;v++) { 
1689           IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,rlin->Vertex(v));
1690         }
1691       }
1692       else if (LineK->ArcType() == IntPatch_Walking) {
1693         Handle(IntPatch_WLine)& wlin =
1694           *((Handle(IntPatch_WLine) *)&LineK);
1695         nbvtx=wlin->NbVertex();
1696         nbvw+=nbvtx;    nbw++;
1697         for(v=1;v<=nbvtx;v++) { 
1698           IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,wlin->Vertex(v));
1699         }
1700       }
1701       else { 
1702         Handle(IntPatch_GLine)& glin =
1703           *((Handle(IntPatch_GLine) *)&LineK);
1704         nbvtx=glin->NbVertex();
1705         nbvg+=nbvtx;    nbg++;
1706         for(v=1;v<=nbvtx;v++) { 
1707           IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,glin->Vertex(v));
1708         }
1709       }
1710     }
1711   }
1712   printf("\nDUMP_LC :Lines:%2d WLin:%2d Restr:%2d Ana:%2d Geom:%2d",
1713          nbllc,nbw,nbr,nba,nbg);
1714   printf("\nDUMP_LC :vtx          :%2d     r:%2d    :%2d     :%2d",
1715          nbvw,nbvr,nbva,nbvg);
1716
1717
1718
1719    printf("\n");
1720 }