1 // Created by: Modelization
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License 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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <IntPatch_Intersection.hxx>
18 #include <Adaptor3d_HSurface.hxx>
19 #include <Adaptor3d_TopolTool.hxx>
20 #include <IntPatch_ALine.hxx>
21 #include <IntPatch_ALineToWLine.hxx>
22 #include <IntPatch_GLine.hxx>
23 #include <IntPatch_ImpImpIntersection.hxx>
24 #include <IntPatch_ImpPrmIntersection.hxx>
25 #include <IntPatch_PrmPrmIntersection.hxx>
26 #include <IntPatch_WLine.hxx>
27 #include <IntPatch_WLineTool.hxx>
29 #include <ProjLib_ProjectOnPlane.hxx>
30 #include <Geom_Plane.hxx>
31 #include <GeomAdaptor_HSurface.hxx>
32 #include <GeomAdaptor_HCurve.hxx>
33 #include <ProjLib_ProjectedCurve.hxx>
34 #include <Geom2dInt_GInter.hxx>
35 #include <Geom2dAdaptor_Curve.hxx>
36 #include <ProjLib.hxx>
38 //======================================================================
39 // function: SequenceOfLine
40 //======================================================================
41 const IntPatch_SequenceOfLine& IntPatch_Intersection::SequenceOfLine() const { return(slin); }
43 //======================================================================
44 // function: IntPatch_Intersection
45 //======================================================================
46 IntPatch_Intersection::IntPatch_Intersection ()
47 : done(Standard_False),
49 myTolArc(0.0), myTolTang(0.0),
50 myUVMaxStep(0.0), myFleche(0.0),
51 myIsStartPnt(Standard_False)
52 //myU1Start, myV1Start, myU2Start, myV2Start
56 //======================================================================
57 // function: IntPatch_Intersection
58 //======================================================================
59 IntPatch_Intersection::IntPatch_Intersection(const Handle(Adaptor3d_HSurface)& S1,
60 const Handle(Adaptor3d_TopolTool)& D1,
61 const Handle(Adaptor3d_HSurface)& S2,
62 const Handle(Adaptor3d_TopolTool)& D2,
63 const Standard_Real TolArc,
64 const Standard_Real TolTang)
65 : done(Standard_False),
67 myTolArc(TolArc), myTolTang(TolTang),
68 myUVMaxStep(0.0), myFleche(0.0),
69 myIsStartPnt(Standard_False)
70 //myU1Start, myV1Start, myU2Start, myV2Start
72 if(myTolArc<1e-8) myTolArc=1e-8;
73 if(myTolTang<1e-8) myTolTang=1e-8;
74 if(myTolArc>0.5) myTolArc=0.5;
75 if(myTolTang>0.5) myTolTang=0.5;
76 Perform(S1,D1,S2,D2,TolArc,TolTang);
79 //======================================================================
80 // function: IntPatch_Intersection
81 //======================================================================
82 IntPatch_Intersection::IntPatch_Intersection(const Handle(Adaptor3d_HSurface)& S1,
83 const Handle(Adaptor3d_TopolTool)& D1,
84 const Standard_Real TolArc,
85 const Standard_Real TolTang)
86 : done(Standard_False),
88 myTolArc(TolArc), myTolTang(TolTang),
89 myUVMaxStep(0.0), myFleche(0.0),
90 myIsStartPnt(Standard_False)
91 //myU1Start, myV1Start, myU2Start, myV2Start
93 Perform(S1,D1,TolArc,TolTang);
96 //======================================================================
97 // function: SetTolerances
98 //======================================================================
99 void IntPatch_Intersection::SetTolerances(const Standard_Real TolArc,
100 const Standard_Real TolTang,
101 const Standard_Real UVMaxStep,
102 const Standard_Real Fleche)
106 myUVMaxStep = UVMaxStep;
108 if(myTolArc<1e-8) myTolArc=1e-8;
109 if(myTolTang<1e-8) myTolTang=1e-8;
110 if(myTolArc>0.5) myTolArc=0.5;
111 if(myTolTang>0.5) myTolTang=0.5;
112 if(myFleche<1.0e-3) myFleche=1e-3;
113 if(myUVMaxStep<1.0e-3) myUVMaxStep=1e-3;
114 if(myFleche>10) myFleche=10;
115 if(myUVMaxStep>0.5) myUVMaxStep=0.5;
118 //======================================================================
120 //======================================================================
121 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& S1,
122 const Handle(Adaptor3d_TopolTool)& D1,
123 const Standard_Real TolArc,
124 const Standard_Real TolTang)
128 if(myFleche == 0.0) myFleche = 0.01;
129 if(myUVMaxStep==0.0) myUVMaxStep = 0.01;
131 done = Standard_True;
135 empt = Standard_True;
136 tgte = Standard_False;
137 oppo = Standard_False;
139 switch (S1->GetType())
142 case GeomAbs_Cylinder:
147 case GeomAbs_SurfaceOfExtrusion:
149 gp_Dir aDirection = S1->Direction();
150 gp_Ax3 anAxis(gp::Origin(), aDirection);
151 Handle(Adaptor3d_HCurve) aBasisCurve = S1->BasisCurve();
152 ProjLib_ProjectOnPlane Projector(anAxis);
153 Projector.Load(aBasisCurve, Precision::Confusion());
154 Handle(GeomAdaptor_HCurve) aProjCurve = Projector.GetResult();
155 Handle(Geom_Plane) aPlane = new Geom_Plane(anAxis);
156 Handle(GeomAdaptor_HSurface) aGAHsurf = new GeomAdaptor_HSurface(aPlane);
157 ProjLib_ProjectedCurve aProjectedCurve(aGAHsurf, aProjCurve);
158 Handle(Geom2d_Curve) aPCurve;
159 ProjLib::MakePCurveOfType(aProjectedCurve, aPCurve);
160 Geom2dAdaptor_Curve AC(aPCurve,
161 aProjectedCurve.FirstParameter(),
162 aProjectedCurve.LastParameter());
163 Geom2dInt_GInter Intersector(AC,
164 Precision::Confusion(),
165 Precision::Confusion());
166 if (Intersector.IsDone() && Intersector.IsEmpty())
171 IntPatch_PrmPrmIntersection interpp;
172 interpp.Perform(S1,D1,TolTang,TolArc,myFleche,myUVMaxStep);
173 if (interpp.IsDone())
175 done = Standard_True;
176 tgte = Standard_False;
177 empt = interpp.IsEmpty();
178 const Standard_Integer nblm = interpp.NbLines();
179 for (Standard_Integer i=1; i<=nblm; i++) slin.Append(interpp.Line(i));
186 /////////////////////////////////////////////////////////////////////////////
187 // These several support functions provide methods which can help basic //
188 // algorithm to intersect infinite surfaces of the following types: //
190 // a.) SurfaceOfExtrusion; //
191 // b.) SurfaceOfRevolution; //
192 // c.) OffsetSurface. //
194 /////////////////////////////////////////////////////////////////////////////
195 #include <TColgp_Array1OfXYZ.hxx>
196 #include <TColgp_Array1OfPnt.hxx>
197 #include <TColgp_SequenceOfPnt.hxx>
198 #include <Extrema_ExtPS.hxx>
199 #include <Extrema_POnSurf.hxx>
200 #include <Geom2d_Curve.hxx>
201 #include <Geom2dAPI_InterCurveCurve.hxx>
202 #include <GeomAdaptor.hxx>
203 #include <GeomAdaptor_HCurve.hxx>
204 #include <GeomAdaptor_Curve.hxx>
205 #include <GeomAdaptor_Surface.hxx>
206 #include <GeomAdaptor_HSurface.hxx>
207 #include <Geom_Plane.hxx>
208 #include <ProjLib_ProjectOnPlane.hxx>
209 #include <GeomProjLib.hxx>
210 #include <ElCLib.hxx>
211 #include <Geom_TrimmedCurve.hxx>
212 #include <Geom_Surface.hxx>
213 #include <Geom_SurfaceOfLinearExtrusion.hxx>
214 #include <Geom_OffsetSurface.hxx>
215 #include <Geom_SurfaceOfRevolution.hxx>
216 #include <Geom_RectangularTrimmedSurface.hxx>
218 //===============================================================
219 //function: FUN_GetMinMaxXYZPnt
220 //===============================================================
221 static void FUN_GetMinMaxXYZPnt( const Handle(Adaptor3d_HSurface)& S,
222 gp_Pnt& pMin, gp_Pnt& pMax )
224 const Standard_Real DU = 0.25 * Abs(S->LastUParameter() - S->FirstUParameter());
225 const Standard_Real DV = 0.25 * Abs(S->LastVParameter() - S->FirstVParameter());
226 Standard_Real tMinXYZ = RealLast();
227 Standard_Real tMaxXYZ = -tMinXYZ;
228 gp_Pnt PUV, ptMax, ptMin;
229 for(Standard_Real U = S->FirstUParameter(); U <= S->LastUParameter(); U += DU)
231 for(Standard_Real V = S->FirstVParameter(); V <= S->LastVParameter(); V += DV)
234 const Standard_Real cXYZ = PUV.XYZ().Modulus();
235 if(cXYZ > tMaxXYZ) { tMaxXYZ = cXYZ; ptMax = PUV; }
236 if(cXYZ < tMinXYZ) { tMinXYZ = cXYZ; ptMin = PUV; }
242 //==========================================================================
243 //function: FUN_TrimInfSurf
244 //==========================================================================
245 static void FUN_TrimInfSurf(const gp_Pnt& Pmin,
247 const Handle(Adaptor3d_HSurface)& InfSurf,
248 const Standard_Real& AlternativeTrimPrm,
249 Handle(Adaptor3d_HSurface)& TrimS)
251 Standard_Real TP = AlternativeTrimPrm;
252 Extrema_ExtPS ext1(Pmin, InfSurf->Surface(), 1.e-7, 1.e-7);
253 Extrema_ExtPS ext2(Pmax, InfSurf->Surface(), 1.e-7, 1.e-7);
254 if(ext1.IsDone() || ext2.IsDone())
256 Standard_Real Umax = -1.e+100, Umin = 1.e+100, Vmax = -1.e+100, Vmin = 1.e+100, cU, cV;
259 for(Standard_Integer i = 1; i <= ext1.NbExt(); i++)
261 const Extrema_POnSurf & pons = ext1.Point(i);
262 pons.Parameter(cU,cV);
263 if(cU > Umax) Umax = cU;
264 if(cU < Umin) Umin = cU;
265 if(cV > Vmax) Vmax = cV;
266 if(cV < Vmin) Vmin = cV;
271 for(Standard_Integer i = 1; i <= ext2.NbExt(); i++)
273 const Extrema_POnSurf & pons = ext2.Point(i);
274 pons.Parameter(cU,cV);
275 if(cU > Umax) Umax = cU;
276 if(cU < Umin) Umin = cU;
277 if(cV > Vmax) Vmax = cV;
278 if(cV < Vmin) Vmin = cV;
281 TP = Max(Abs(Umin),Max(Abs(Umax),Max(Abs(Vmin),Abs(Vmax))));
283 if(TP == 0.) { TrimS = InfSurf; return; }
286 const Standard_Boolean Uinf = Precision::IsNegativeInfinite(InfSurf->FirstUParameter());
287 const Standard_Boolean Usup = Precision::IsPositiveInfinite(InfSurf->LastUParameter());
288 const Standard_Boolean Vinf = Precision::IsNegativeInfinite(InfSurf->FirstVParameter());
289 const Standard_Boolean Vsup = Precision::IsPositiveInfinite(InfSurf->LastVParameter());
290 Handle(Adaptor3d_HSurface) TmpSS;
291 Standard_Integer IsTrimed = 0;
292 const Standard_Real tp = 1000.0 * TP;
293 if(Vinf && Vsup) { TrimS = InfSurf->VTrim(-tp, tp, 1.0e-7); IsTrimed = 1; }
294 if(Vinf && !Vsup){ TrimS = InfSurf->VTrim(-tp, InfSurf->LastVParameter(), 1.0e-7); IsTrimed = 1; }
295 if(!Vinf && Vsup){ TrimS = InfSurf->VTrim(InfSurf->FirstVParameter(), tp, 1.0e-7); IsTrimed = 1; }
299 if(Uinf && Usup) TrimS = TmpSS->UTrim(-tp, tp, 1.0e-7);
300 if(Uinf && !Usup) TrimS = TmpSS->UTrim(-tp, InfSurf->LastUParameter(), 1.0e-7);
301 if(!Uinf && Usup) TrimS = TmpSS->UTrim(InfSurf->FirstUParameter(), tp, 1.0e-7);
305 if(Uinf && Usup) TrimS = InfSurf->UTrim(-tp, tp, 1.0e-7);
306 if(Uinf && !Usup) TrimS = InfSurf->UTrim(-tp, InfSurf->LastUParameter(), 1.0e-7);
307 if(!Uinf && Usup) TrimS = InfSurf->UTrim(InfSurf->FirstUParameter(), tp, 1.0e-7);
311 //================================================================================
312 //function: FUN_GetUiso
313 //================================================================================
314 static void FUN_GetUiso(const Handle(Geom_Surface)& GS,
315 const GeomAbs_SurfaceType& T,
316 const Standard_Real& FirstV,
317 const Standard_Real& LastV,
318 const Standard_Boolean& IsVC,
319 const Standard_Boolean& IsVP,
320 const Standard_Real& U,
321 Handle(Geom_Curve)& I)
323 if(T != GeomAbs_OffsetSurface)
325 Handle(Geom_Curve) gc = GS->UIso(U);
326 if(IsVP && (FirstV == 0.0 && LastV == (2.*M_PI))) I = gc;
329 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstV,LastV);
330 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
336 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (GS);
337 const Handle(Geom_Surface) bs = gos->BasisSurface();
338 Handle(Geom_Curve) gcbs = bs->UIso(U);
339 GeomAdaptor_Curve gac(gcbs);
340 const GeomAbs_CurveType GACT = gac.GetType();
341 if(IsVP || IsVC || GACT == GeomAbs_BSplineCurve || GACT == GeomAbs_BezierCurve || Abs(LastV - FirstV) < 1.e+5)
343 Handle(Geom_Curve) gc = gos->UIso(U);
344 if(IsVP && (FirstV == 0.0 && LastV == (2*M_PI))) I = gc;
347 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstV,LastV);
348 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
352 else//Offset Line, Parab, Hyperb
354 Standard_Real VmTr, VMTr;
355 if(GACT != GeomAbs_Hyperbola)
357 if(FirstV >= 0. && LastV >= 0.){ VmTr = FirstV; VMTr = ((LastV - FirstV) > 1.e+4) ? (FirstV + 1.e+4) : LastV; }
358 else if(FirstV < 0. && LastV < 0.){ VMTr = LastV; VmTr = ((FirstV - LastV) < -1.e+4) ? (LastV - 1.e+4) : FirstV; }
359 else { VmTr = (FirstV < -1.e+4) ? -1.e+4 : FirstV; VMTr = (LastV > 1.e+4) ? 1.e+4 : LastV; }
363 if(FirstV >= 0. && LastV >= 0.)
365 if(FirstV > 4.) return;
366 VmTr = FirstV; VMTr = (LastV > 4.) ? 4. : LastV;
368 else if(FirstV < 0. && LastV < 0.)
370 if(LastV < -4.) return;
371 VMTr = LastV; VmTr = (FirstV < -4.) ? -4. : FirstV;
373 else { VmTr = (FirstV < -4.) ? -4. : FirstV; VMTr = (LastV > 4.) ? 4. : LastV; }
375 //Make trimmed surface
376 Handle(Geom_RectangularTrimmedSurface) rts = new Geom_RectangularTrimmedSurface(gos,VmTr,VMTr,Standard_True);
381 //================================================================================
382 //function: FUN_GetViso
383 //================================================================================
384 static void FUN_GetViso(const Handle(Geom_Surface)& GS,
385 const GeomAbs_SurfaceType& T,
386 const Standard_Real& FirstU,
387 const Standard_Real& LastU,
388 const Standard_Boolean& IsUC,
389 const Standard_Boolean& IsUP,
390 const Standard_Real& V,
391 Handle(Geom_Curve)& I)
393 if(T != GeomAbs_OffsetSurface)
395 Handle(Geom_Curve) gc = GS->VIso(V);
396 if(IsUP && (FirstU == 0.0 && LastU == (2*M_PI))) I = gc;
399 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstU,LastU);
400 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
406 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (GS);
407 const Handle(Geom_Surface) bs = gos->BasisSurface();
408 Handle(Geom_Curve) gcbs = bs->VIso(V);
409 GeomAdaptor_Curve gac(gcbs);
410 const GeomAbs_CurveType GACT = gac.GetType();
411 if(IsUP || IsUC || GACT == GeomAbs_BSplineCurve || GACT == GeomAbs_BezierCurve || Abs(LastU - FirstU) < 1.e+5)
413 Handle(Geom_Curve) gc = gos->VIso(V);
414 if(IsUP && (FirstU == 0.0 && LastU == (2*M_PI))) I = gc;
417 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstU,LastU);
418 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
422 else//Offset Line, Parab, Hyperb
424 Standard_Real UmTr, UMTr;
425 if(GACT != GeomAbs_Hyperbola)
427 if(FirstU >= 0. && LastU >= 0.){ UmTr = FirstU; UMTr = ((LastU - FirstU) > 1.e+4) ? (FirstU + 1.e+4) : LastU; }
428 else if(FirstU < 0. && LastU < 0.){ UMTr = LastU; UmTr = ((FirstU - LastU) < -1.e+4) ? (LastU - 1.e+4) : FirstU; }
429 else { UmTr = (FirstU < -1.e+4) ? -1.e+4 : FirstU; UMTr = (LastU > 1.e+4) ? 1.e+4 : LastU; }
433 if(FirstU >= 0. && LastU >= 0.)
435 if(FirstU > 4.) return;
436 UmTr = FirstU; UMTr = (LastU > 4.) ? 4. : LastU;
438 else if(FirstU < 0. && LastU < 0.)
440 if(LastU < -4.) return;
441 UMTr = LastU; UmTr = (FirstU < -4.) ? -4. : FirstU;
443 else { UmTr = (FirstU < -4.) ? -4. : FirstU; UMTr = (LastU > 4.) ? 4. : LastU; }
445 //Make trimmed surface
446 Handle(Geom_RectangularTrimmedSurface) rts = new Geom_RectangularTrimmedSurface(gos,UmTr,UMTr,Standard_True);
451 //================================================================================
452 //function: FUN_PL_Intersection
453 //================================================================================
454 static void FUN_PL_Intersection(const Handle(Adaptor3d_HSurface)& S1,
455 const GeomAbs_SurfaceType& T1,
456 const Handle(Adaptor3d_HSurface)& S2,
457 const GeomAbs_SurfaceType& T2,
458 Standard_Boolean& IsOk,
459 TColgp_SequenceOfPnt& SP,
462 IsOk = Standard_False;
463 // 1. Check: both surfaces have U(V)isos - lines.
464 DV = gp_Vec(0.,0.,1.);
465 Standard_Boolean isoS1isLine[2] = {0, 0};
466 Standard_Boolean isoS2isLine[2] = {0, 0};
467 Handle(Geom_Curve) C1, C2;
468 const GeomAdaptor_Surface & gas1 = *(GeomAdaptor_Surface*)(&(S1->Surface()));
469 const GeomAdaptor_Surface & gas2 = *(GeomAdaptor_Surface*)(&(S2->Surface()));
470 const Handle(Geom_Surface) gs1 = gas1.Surface();
471 const Handle(Geom_Surface) gs2 = gas2.Surface();
472 Standard_Real MS1[2], MS2[2];
473 MS1[0] = 0.5 * (S1->LastUParameter() + S1->FirstUParameter());
474 MS1[1] = 0.5 * (S1->LastVParameter() + S1->FirstVParameter());
475 MS2[0] = 0.5 * (S2->LastUParameter() + S2->FirstUParameter());
476 MS2[1] = 0.5 * (S2->LastVParameter() + S2->FirstVParameter());
477 if(T1 == GeomAbs_SurfaceOfExtrusion) isoS1isLine[0] = Standard_True;
478 else if(!S1->IsVPeriodic() && !S1->IsVClosed()) {
479 if(T1 != GeomAbs_OffsetSurface) C1 = gs1->UIso(MS1[0]);
481 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs1);
482 const Handle(Geom_Surface) bs = gos->BasisSurface();
483 C1 = bs->UIso(MS1[0]);
485 GeomAdaptor_Curve gac(C1);
486 if(gac.GetType() == GeomAbs_Line) isoS1isLine[0] = Standard_True;
488 if(!S1->IsUPeriodic() && !S1->IsUClosed()) {
489 if(T1 != GeomAbs_OffsetSurface) C1 = gs1->VIso(MS1[1]);
491 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs1);
492 const Handle(Geom_Surface) bs = gos->BasisSurface();
493 C1 = bs->VIso(MS1[1]);
495 GeomAdaptor_Curve gac(C1);
496 if(gac.GetType() == GeomAbs_Line) isoS1isLine[1] = Standard_True;
498 if(T2 == GeomAbs_SurfaceOfExtrusion) isoS2isLine[0] = Standard_True;
499 else if(!S2->IsVPeriodic() && !S2->IsVClosed()) {
500 if(T2 != GeomAbs_OffsetSurface) C2 = gs2->UIso(MS2[0]);
502 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs2);
503 const Handle(Geom_Surface) bs = gos->BasisSurface();
504 C2 = bs->UIso(MS2[0]);
506 GeomAdaptor_Curve gac(C2);
507 if(gac.GetType() == GeomAbs_Line) isoS2isLine[0] = Standard_True;
509 if(!S2->IsUPeriodic() && !S2->IsUClosed()) {
510 if(T2 != GeomAbs_OffsetSurface) C2 = gs2->VIso(MS2[1]);
512 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs2);
513 const Handle(Geom_Surface) bs = gos->BasisSurface();
514 C2 = bs->VIso(MS2[1]);
516 GeomAdaptor_Curve gac(C2);
517 if(gac.GetType() == GeomAbs_Line) isoS2isLine[1] = Standard_True;
519 Standard_Boolean IsBothLines = ((isoS1isLine[0] || isoS1isLine[1]) &&
520 (isoS2isLine[0] || isoS2isLine[1]));
524 // 2. Check: Uiso lines of both surfaces are collinear.
526 gp_Vec derS1[2], derS2[2];
527 S1->D1(MS1[0], MS1[1], puvS1, derS1[0], derS1[1]);
528 S2->D1(MS2[0], MS2[1], puvS2, derS2[0], derS2[1]);
529 C1.Nullify(); C2.Nullify();
530 Standard_Integer iso = 0;
531 if(isoS1isLine[0] && isoS2isLine[0] &&
532 derS1[1].IsParallel(derS2[1],Precision::Angular())) {
534 FUN_GetViso(gs1,T1,S1->FirstUParameter(),S1->LastUParameter(),
535 S1->IsUClosed(),S1->IsUPeriodic(),MS1[1],C1);
536 FUN_GetViso(gs2,T2,S2->FirstUParameter(),S2->LastUParameter(),
537 S2->IsUClosed(),S2->IsUPeriodic(),MS2[1],C2);
539 else if(isoS1isLine[0] && isoS2isLine[1] &&
540 derS1[1].IsParallel(derS2[0],Precision::Angular())) {
542 FUN_GetViso(gs1,T1,S1->FirstUParameter(),S1->LastUParameter(),
543 S1->IsUClosed(),S1->IsUPeriodic(),MS1[1],C1);
544 FUN_GetUiso(gs2,T2,S2->FirstVParameter(),S2->LastVParameter(),
545 S2->IsVClosed(),S2->IsVPeriodic(),MS2[0],C2);
547 else if(isoS1isLine[1] && isoS2isLine[0] &&
548 derS1[0].IsParallel(derS2[1],Precision::Angular())) {
550 FUN_GetUiso(gs1,T1,S1->FirstVParameter(),S1->LastVParameter(),
551 S1->IsVClosed(),S1->IsVPeriodic(),MS1[0],C1);
552 FUN_GetViso(gs2,T2,S2->FirstUParameter(),S2->LastUParameter(),
553 S2->IsUClosed(),S2->IsUPeriodic(),MS2[1],C2);
555 else if(isoS1isLine[1] && isoS2isLine[1] &&
556 derS1[0].IsParallel(derS2[0],Precision::Angular())) {
558 FUN_GetUiso(gs1,T1,S1->FirstVParameter(),S1->LastVParameter(),
559 S1->IsVClosed(),S1->IsVPeriodic(),MS1[0],C1);
560 FUN_GetUiso(gs2,T2,S2->FirstVParameter(),S2->LastVParameter(),
561 S2->IsVClosed(),S2->IsVPeriodic(),MS2[0],C2);
564 IsOk = Standard_False;
567 IsOk = Standard_True;
568 // 3. Make intersections of V(U)isos
569 if(C1.IsNull() || C2.IsNull()) return;
571 Handle(Geom_Plane) GPln = new Geom_Plane(gp_Pln(puvS1,gp_Dir(DV)));
572 Handle(Geom_Curve) C1Prj =
573 GeomProjLib::ProjectOnPlane(C1,GPln,gp_Dir(DV),Standard_True);
574 Handle(Geom_Curve) C2Prj =
575 GeomProjLib::ProjectOnPlane(C2,GPln,gp_Dir(DV),Standard_True);
576 if(C1Prj.IsNull() || C2Prj.IsNull()) return;
577 Handle(Geom2d_Curve) C1Prj2d = GeomProjLib::Curve2d (C1Prj,GPln);
578 Handle(Geom2d_Curve) C2Prj2d = GeomProjLib::Curve2d (C2Prj,GPln);
579 Geom2dAPI_InterCurveCurve ICC(C1Prj2d,C2Prj2d,1.0e-7);
580 if(ICC.NbPoints() > 0 )
582 for(Standard_Integer ip = 1; ip <= ICC.NbPoints(); ip++)
584 gp_Pnt2d P = ICC.Point(ip);
585 gp_Pnt P3d = ElCLib::To3d(gp_Ax2(puvS1,gp_Dir(DV)),P);
590 //================================================================================
591 //function: FUN_NewFirstLast
592 //================================================================================
593 static void FUN_NewFirstLast(const GeomAbs_CurveType& ga_ct,
594 const Standard_Real& Fst,
595 const Standard_Real& Lst,
596 const Standard_Real& TrVal,
597 Standard_Real& NewFst,
598 Standard_Real& NewLst,
599 Standard_Boolean& NeedTr)
601 NewFst = Fst; NewLst = Lst; NeedTr = Standard_False;
605 case GeomAbs_Parabola:
607 if(Abs(Lst - Fst) > TrVal)
609 if(Fst >= 0. && Lst >= 0.)
612 NewLst = ((Fst + TrVal) < Lst) ? (Fst + TrVal) : Lst;
614 if(Fst < 0. && Lst < 0.)
617 NewFst = ((Lst - TrVal) > Fst) ? (Lst - TrVal) : Fst;
621 NewFst = (Fst < -TrVal) ? -TrVal : Fst;
622 NewLst = (Lst > TrVal) ? TrVal : Lst;
624 NeedTr = Standard_True;
628 case GeomAbs_Hyperbola:
630 if(Abs(Lst - Fst) > 10.)
632 if(Fst >= 0. && Lst >= 0.)
636 NewLst = (Lst > 4.) ? 4. : Lst;
638 if(Fst < 0. && Lst < 0.)
640 if(Lst < -4.) return;
642 NewFst = (Fst < -4.) ? -4. : Fst;
646 NewFst = (Fst < -4.) ? -4. : Fst;
647 NewLst = (Lst > 4.) ? 4. : Lst;
649 NeedTr = Standard_True;
657 //================================================================================
658 //function: FUN_TrimBothSurf
659 //================================================================================
660 static void FUN_TrimBothSurf(const Handle(Adaptor3d_HSurface)& S1,
661 const GeomAbs_SurfaceType& T1,
662 const Handle(Adaptor3d_HSurface)& S2,
663 const GeomAbs_SurfaceType& T2,
664 const Standard_Real& TV,
665 Handle(Adaptor3d_HSurface)& NS1,
666 Handle(Adaptor3d_HSurface)& NS2)
668 const GeomAdaptor_Surface & gas1 = *(GeomAdaptor_Surface*)(&(S1->Surface()));
669 const GeomAdaptor_Surface & gas2 = *(GeomAdaptor_Surface*)(&(S2->Surface()));
670 const Handle(Geom_Surface) gs1 = gas1.Surface();
671 const Handle(Geom_Surface) gs2 = gas2.Surface();
672 const Standard_Real UM1 = 0.5 * (S1->LastUParameter() + S1->FirstUParameter());
673 const Standard_Real UM2 = 0.5 * (S2->LastUParameter() + S2->FirstUParameter());
674 const Standard_Real VM1 = 0.5 * (S1->LastVParameter() + S1->FirstVParameter());
675 const Standard_Real VM2 = 0.5 * (S2->LastVParameter() + S2->FirstVParameter());
676 Handle(Geom_Curve) visoS1, visoS2, uisoS1, uisoS2;
677 if(T1 != GeomAbs_OffsetSurface){ visoS1 = gs1->VIso(VM1); uisoS1 = gs1->UIso(UM1); }
680 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs1);
681 const Handle(Geom_Surface) bs = gos->BasisSurface();
682 visoS1 = bs->VIso(VM1); uisoS1 = bs->UIso(UM1);
684 if(T2 != GeomAbs_OffsetSurface){ visoS2 = gs2->VIso(VM2); uisoS2 = gs2->UIso(UM2); }
687 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs2);
688 const Handle(Geom_Surface) bs = gos->BasisSurface();
689 visoS2 = bs->VIso(VM2); uisoS2 = bs->UIso(UM2);
691 if(uisoS1.IsNull() || uisoS2.IsNull() || visoS1.IsNull() || visoS2.IsNull()){ NS1 = S1; NS2 = S2; return; }
692 GeomAdaptor_Curve gau1(uisoS1);
693 GeomAdaptor_Curve gav1(visoS1);
694 GeomAdaptor_Curve gau2(uisoS2);
695 GeomAdaptor_Curve gav2(visoS2);
696 GeomAbs_CurveType GA_U1 = gau1.GetType();
697 GeomAbs_CurveType GA_V1 = gav1.GetType();
698 GeomAbs_CurveType GA_U2 = gau2.GetType();
699 GeomAbs_CurveType GA_V2 = gav2.GetType();
700 Standard_Boolean TrmU1 = Standard_False;
701 Standard_Boolean TrmV1 = Standard_False;
702 Standard_Boolean TrmU2 = Standard_False;
703 Standard_Boolean TrmV2 = Standard_False;
704 Standard_Real V1S1,V2S1,U1S1,U2S1, V1S2,V2S2,U1S2,U2S2;
705 FUN_NewFirstLast(GA_U1,S1->FirstVParameter(),S1->LastVParameter(),TV,V1S1,V2S1,TrmV1);
706 FUN_NewFirstLast(GA_V1,S1->FirstUParameter(),S1->LastUParameter(),TV,U1S1,U2S1,TrmU1);
707 FUN_NewFirstLast(GA_U2,S2->FirstVParameter(),S2->LastVParameter(),TV,V1S2,V2S2,TrmV2);
708 FUN_NewFirstLast(GA_V2,S2->FirstUParameter(),S2->LastUParameter(),TV,U1S2,U2S2,TrmU2);
709 if(TrmV1) NS1 = S1->VTrim(V1S1, V2S1, 1.0e-7);
710 if(TrmV2) NS2 = S2->VTrim(V1S2, V2S2, 1.0e-7);
715 Handle(Adaptor3d_HSurface) TS = NS1;
716 NS1 = TS->UTrim(U1S1, U2S1, 1.0e-7);
718 else NS1 = S1->UTrim(U1S1, U2S1, 1.0e-7);
724 Handle(Adaptor3d_HSurface) TS = NS2;
725 NS2 = TS->UTrim(U1S2, U2S2, 1.0e-7);
727 else NS2 = S2->UTrim(U1S2, U2S2, 1.0e-7);
731 //=======================================================================
734 //=======================================================================
735 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& theS1,
736 const Handle(Adaptor3d_TopolTool)& theD1,
737 const Handle(Adaptor3d_HSurface)& theS2,
738 const Handle(Adaptor3d_TopolTool)& theD2,
739 const Standard_Real TolArc,
740 const Standard_Real TolTang,
741 const Standard_Boolean isGeomInt,
742 const Standard_Boolean theIsReqToKeepRLine,
743 const Standard_Boolean theIsReqToPostWLProc)
747 if(myFleche <= Precision::PConfusion())
749 if(myUVMaxStep <= Precision::PConfusion())
752 done = Standard_False;
755 empt = Standard_True;
756 tgte = Standard_False;
757 oppo = Standard_False;
759 GeomAbs_SurfaceType typs1 = theS1->GetType();
760 GeomAbs_SurfaceType typs2 = theS2->GetType();
762 //treatment of the cases with cone or torus
763 Standard_Boolean TreatAsBiParametric = Standard_False;
764 Standard_Integer bGeomGeom = 0;
766 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone ||
767 typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
768 gp_Ax1 aCTAx, aGeomAx;
769 GeomAbs_SurfaceType aCTType;
770 Standard_Boolean bToCheck;
772 const Handle(Adaptor3d_HSurface)& aCTSurf =
773 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS1 : theS2;
774 const Handle(Adaptor3d_HSurface)& aGeomSurf =
775 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS2 : theS1;
777 aCTType = aCTSurf->GetType();
778 bToCheck = Standard_False;
780 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone) {
781 const gp_Cone aCon1 = (aCTType == GeomAbs_Cone) ?
782 aCTSurf->Cone() : aGeomSurf->Cone();
783 Standard_Real a1 = Abs(aCon1.SemiAngle());
784 bToCheck = (a1 < 0.02) || (a1 > 1.55);
786 if (typs1 == typs2) {
787 const gp_Cone aCon2 = aGeomSurf->Cone();
788 Standard_Real a2 = Abs(aCon2.SemiAngle());
789 bToCheck = bToCheck || (a2 < 0.02) || (a2 > 1.55);
791 if (a1 > 1.55 && a2 > 1.55) {//quasi-planes: if same domain, treat as canonic
792 const gp_Ax1 A1 = aCon1.Axis(), A2 = aCon2.Axis();
793 if (A1.IsParallel(A2,Precision::Angular())) {
794 const gp_Pnt Apex1 = aCon1.Apex(), Apex2 = aCon2.Apex();
795 const gp_Pln Plan1( Apex1, A1.Direction() );
796 if (Plan1.Distance( Apex2 ) <= Precision::Confusion()) {
797 bToCheck = Standard_False;
803 TreatAsBiParametric = bToCheck;
804 if (aCTType == GeomAbs_Cone) {
805 aCTAx = aCon1.Axis();
809 if (typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
810 const gp_Torus aTor1 = (aCTType == GeomAbs_Torus) ?
811 aCTSurf->Torus() : aGeomSurf->Torus();
812 bToCheck = aTor1.MajorRadius() > aTor1.MinorRadius();
813 if (typs1 == typs2) {
814 const gp_Torus aTor2 = aGeomSurf->Torus();
815 bToCheck = aTor2.MajorRadius() > aTor2.MinorRadius();
818 if (aCTType == GeomAbs_Torus) {
819 aCTAx = aTor1.Axis();
824 const gp_Lin aL1(aCTAx);
826 switch (aGeomSurf->GetType()) {
827 case GeomAbs_Plane: {
828 aGeomAx = aGeomSurf->Plane().Axis();
829 if (aCTType == GeomAbs_Cone) {
831 if (Abs(aCTSurf->Cone().SemiAngle()) < 0.02) {
832 Standard_Real ps = Abs(aCTAx.Direction().Dot(aGeomAx.Direction()));
839 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) ||
840 (aCTAx.IsNormal(aGeomAx, Precision::Angular()) &&
841 (aGeomSurf->Plane().Distance(aCTAx.Location()) < Precision::Confusion()))) {
845 bToCheck = Standard_False;
848 case GeomAbs_Sphere: {
849 if (aL1.Distance(aGeomSurf->Sphere().Location()) < Precision::Confusion()) {
852 bToCheck = Standard_False;
855 case GeomAbs_Cylinder:
856 aGeomAx = aGeomSurf->Cylinder().Axis();
859 aGeomAx = aGeomSurf->Cone().Axis();
862 aGeomAx = aGeomSurf->Torus().Axis();
865 bToCheck = Standard_False;
870 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) &&
871 (aL1.Distance(aGeomAx.Location()) <= Precision::Confusion())) {
876 if (bGeomGeom == 1) {
877 TreatAsBiParametric = Standard_False;
883 if(theD1->DomainIsInfinite() || theD2->DomainIsInfinite()) {
884 TreatAsBiParametric= Standard_False;
887 // Modified by skv - Mon Sep 26 14:58:30 2005 Begin
888 // if(TreatAsBiParametric) { typs1 = typs2 = GeomAbs_BezierSurface; }
889 if(TreatAsBiParametric)
891 if (typs1 == GeomAbs_Cone && typs2 == GeomAbs_Plane)
892 typs1 = GeomAbs_BezierSurface; // Using Imp-Prm Intersector
893 else if (typs1 == GeomAbs_Plane && typs2 == GeomAbs_Cone)
894 typs2 = GeomAbs_BezierSurface; // Using Imp-Prm Intersector
896 // Using Prm-Prm Intersector
897 typs1 = GeomAbs_BezierSurface;
898 typs2 = GeomAbs_BezierSurface;
901 // Modified by skv - Mon Sep 26 14:58:30 2005 End
903 // Surface type definition
904 Standard_Integer ts1 = 0;
908 case GeomAbs_Cylinder:
910 case GeomAbs_Cone: ts1 = 1; break;
911 case GeomAbs_Torus: ts1 = bGeomGeom; break;
915 Standard_Integer ts2 = 0;
919 case GeomAbs_Cylinder:
921 case GeomAbs_Cone: ts2 = 1; break;
922 case GeomAbs_Torus: ts2 = bGeomGeom; break;
926 // treatment of the cases with torus and any other geom surface
928 // Possible intersection types: 1. ts1 == ts2 == 1 <Geom-Geom>
929 // 2. ts1 != ts2 <Geom-Param>
930 // 3. ts1 == ts2 == 0 <Param-Param>
933 const Standard_Boolean RestrictLine = Standard_True;
934 if(ts1 == ts2 && ts1 == 1)
936 IntSurf_ListOfPntOn2S ListOfPnts;
940 GeomGeomPerfom( theS1, theD1, theS2, theD2, TolArc,
941 TolTang, ListOfPnts, RestrictLine,
942 typs1, typs2, theIsReqToKeepRLine);
946 ParamParamPerfom(theS1, theD1, theS2, theD2,
947 TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
954 GeomParamPerfom(theS1, theD1, theS2, theD2, ts1 == 0, typs1, typs2);
958 if(ts1 == ts2 && ts1 == 0)
960 IntSurf_ListOfPntOn2S ListOfPnts;
963 ParamParamPerfom(theS1, theD1, theS2, theD2, TolArc,
964 TolTang, ListOfPnts, RestrictLine, typs1, typs2);
967 if(!theIsReqToPostWLProc)
970 for(Standard_Integer i = slin.Lower(); i <= slin.Upper(); i++)
972 Handle(IntPatch_WLine) aWL = Handle(IntPatch_WLine)::DownCast(slin.Value(i));
977 if (!aWL->IsPurgingAllowed())
980 Handle(IntPatch_WLine) aRW =
981 IntPatch_WLineTool::ComputePurgedWLine(aWL, theS1, theS2, theD1, theD2, RestrictLine);
986 slin.InsertAfter(i, aRW);
991 //=======================================================================
994 //=======================================================================
995 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& theS1,
996 const Handle(Adaptor3d_TopolTool)& theD1,
997 const Handle(Adaptor3d_HSurface)& theS2,
998 const Handle(Adaptor3d_TopolTool)& theD2,
999 const Standard_Real TolArc,
1000 const Standard_Real TolTang,
1001 IntSurf_ListOfPntOn2S& ListOfPnts,
1002 const Standard_Boolean RestrictLine,
1003 const Standard_Boolean isGeomInt,
1004 const Standard_Boolean theIsReqToKeepRLine,
1005 const Standard_Boolean theIsReqToPostWLProc)
1008 myTolTang = TolTang;
1009 if(myFleche <= Precision::PConfusion())
1011 if(myUVMaxStep <= Precision::PConfusion())
1014 done = Standard_False;
1017 empt = Standard_True;
1018 tgte = Standard_False;
1019 oppo = Standard_False;
1021 GeomAbs_SurfaceType typs1 = theS1->GetType();
1022 GeomAbs_SurfaceType typs2 = theS2->GetType();
1024 //treatment of the cases with cone or torus
1025 Standard_Boolean TreatAsBiParametric = Standard_False;
1026 Standard_Integer bGeomGeom = 0;
1028 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone ||
1029 typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
1030 gp_Ax1 aCTAx, aGeomAx;
1031 GeomAbs_SurfaceType aCTType;
1032 Standard_Boolean bToCheck;
1034 const Handle(Adaptor3d_HSurface)& aCTSurf =
1035 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS1 : theS2;
1036 const Handle(Adaptor3d_HSurface)& aGeomSurf =
1037 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS2 : theS1;
1039 aCTType = aCTSurf->GetType();
1040 bToCheck = Standard_False;
1042 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone) {
1043 const gp_Cone aCon1 = (aCTType == GeomAbs_Cone) ?
1044 aCTSurf->Cone() : aGeomSurf->Cone();
1045 Standard_Real a1 = Abs(aCon1.SemiAngle());
1046 bToCheck = (a1 < 0.02) || (a1 > 1.55);
1048 if (typs1 == typs2) {
1049 const gp_Cone aCon2 = aGeomSurf->Cone();
1050 Standard_Real a2 = Abs(aCon2.SemiAngle());
1051 bToCheck = bToCheck || (a2 < 0.02) || (a2 > 1.55);
1053 if (a1 > 1.55 && a2 > 1.55) {//quasi-planes: if same domain, treat as canonic
1054 const gp_Ax1 A1 = aCon1.Axis(), A2 = aCon2.Axis();
1055 if (A1.IsParallel(A2,Precision::Angular())) {
1056 const gp_Pnt Apex1 = aCon1.Apex(), Apex2 = aCon2.Apex();
1057 const gp_Pln Plan1( Apex1, A1.Direction() );
1058 if (Plan1.Distance( Apex2 ) <= Precision::Confusion()) {
1059 bToCheck = Standard_False;
1065 TreatAsBiParametric = bToCheck;
1066 if (aCTType == GeomAbs_Cone) {
1067 aCTAx = aCon1.Axis();
1071 if (typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
1072 const gp_Torus aTor1 = (aCTType == GeomAbs_Torus) ?
1073 aCTSurf->Torus() : aGeomSurf->Torus();
1074 bToCheck = aTor1.MajorRadius() > aTor1.MinorRadius();
1075 if (typs1 == typs2) {
1076 const gp_Torus aTor2 = aGeomSurf->Torus();
1077 bToCheck = aTor2.MajorRadius() > aTor2.MinorRadius();
1080 if (aCTType == GeomAbs_Torus) {
1081 aCTAx = aTor1.Axis();
1086 const gp_Lin aL1(aCTAx);
1088 switch (aGeomSurf->GetType()) {
1089 case GeomAbs_Plane: {
1090 aGeomAx = aGeomSurf->Plane().Axis();
1091 if (aCTType == GeomAbs_Cone) {
1093 if (Abs(aCTSurf->Cone().SemiAngle()) < 0.02) {
1094 Standard_Real ps = Abs(aCTAx.Direction().Dot(aGeomAx.Direction()));
1101 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) ||
1102 (aCTAx.IsNormal(aGeomAx, Precision::Angular()) &&
1103 (aGeomSurf->Plane().Distance(aCTAx.Location()) < Precision::Confusion()))) {
1107 bToCheck = Standard_False;
1110 case GeomAbs_Sphere: {
1111 if (aL1.Distance(aGeomSurf->Sphere().Location()) < Precision::Confusion()) {
1114 bToCheck = Standard_False;
1117 case GeomAbs_Cylinder:
1118 aGeomAx = aGeomSurf->Cylinder().Axis();
1121 aGeomAx = aGeomSurf->Cone().Axis();
1124 aGeomAx = aGeomSurf->Torus().Axis();
1127 bToCheck = Standard_False;
1132 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) &&
1133 (aL1.Distance(aGeomAx.Location()) <= Precision::Confusion())) {
1138 if (bGeomGeom == 1) {
1139 TreatAsBiParametric = Standard_False;
1145 if(theD1->DomainIsInfinite() || theD2->DomainIsInfinite()) {
1146 TreatAsBiParametric= Standard_False;
1149 if(TreatAsBiParametric)
1151 // Using Prm-Prm Intersector
1152 typs1 = GeomAbs_BezierSurface;
1153 typs2 = GeomAbs_BezierSurface;
1156 // Surface type definition
1157 Standard_Integer ts1 = 0;
1161 case GeomAbs_Cylinder:
1162 case GeomAbs_Sphere:
1163 case GeomAbs_Cone: ts1 = 1; break;
1164 case GeomAbs_Torus: ts1 = bGeomGeom; break;
1168 Standard_Integer ts2 = 0;
1172 case GeomAbs_Cylinder:
1173 case GeomAbs_Sphere:
1174 case GeomAbs_Cone: ts2 = 1; break;
1175 case GeomAbs_Torus: ts2 = bGeomGeom; break;
1179 // Possible intersection types: 1. ts1 == ts2 == 1 <Geom-Geom>
1180 // 2. ts1 != ts2 <Geom-Param>
1181 // 3. ts1 == ts2 == 0 <Param-Param>
1185 ParamParamPerfom(theS1, theD1, theS2, theD2,
1186 TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
1190 GeomParamPerfom(theS1, theD1, theS2, theD2, ts1 == 0, typs1, typs2);
1194 ParamParamPerfom(theS1, theD1, theS2, theD2,
1195 TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
1199 GeomGeomPerfom(theS1, theD1, theS2, theD2, TolArc,
1200 TolTang, ListOfPnts, RestrictLine, typs1, typs2, theIsReqToKeepRLine);
1203 if(!theIsReqToPostWLProc)
1206 for(Standard_Integer i = slin.Lower(); i <= slin.Upper(); i++)
1208 Handle(IntPatch_WLine) aWL = Handle(IntPatch_WLine)::DownCast(slin.Value(i));
1213 if(!aWL->IsPurgingAllowed())
1216 Handle(IntPatch_WLine) aRW =
1217 IntPatch_WLineTool::ComputePurgedWLine(aWL, theS1, theS2, theD1, theD2, RestrictLine);
1222 slin.InsertAfter(i, aRW);
1227 //=======================================================================
1228 //function : ParamParamPerfom
1230 //=======================================================================
1231 void IntPatch_Intersection::ParamParamPerfom(const Handle(Adaptor3d_HSurface)& theS1,
1232 const Handle(Adaptor3d_TopolTool)& theD1,
1233 const Handle(Adaptor3d_HSurface)& theS2,
1234 const Handle(Adaptor3d_TopolTool)& theD2,
1235 const Standard_Real TolArc,
1236 const Standard_Real TolTang,
1237 IntSurf_ListOfPntOn2S& ListOfPnts,
1238 const Standard_Boolean RestrictLine,
1239 const GeomAbs_SurfaceType typs1,
1240 const GeomAbs_SurfaceType typs2)
1242 IntPatch_PrmPrmIntersection interpp;
1243 if(!theD1->DomainIsInfinite() && !theD2->DomainIsInfinite())
1245 Standard_Boolean ClearFlag = Standard_True;
1246 if(!ListOfPnts.IsEmpty())
1248 interpp.Perform(theS1,theD1,theS2,theD2,TolTang,TolArc,myFleche,myUVMaxStep, ListOfPnts, RestrictLine);
1249 ClearFlag = Standard_False;
1251 interpp.Perform(theS1,theD1,theS2,theD2,TolTang,TolArc,myFleche,myUVMaxStep,ClearFlag); //double call!!!!!!!
1253 else if((theD1->DomainIsInfinite()) ^ (theD2->DomainIsInfinite()))
1255 gp_Pnt pMaxXYZ, pMinXYZ;
1256 if(theD1->DomainIsInfinite())
1258 FUN_GetMinMaxXYZPnt( theS2, pMinXYZ, pMaxXYZ );
1259 const Standard_Real MU = Max(Abs(theS2->FirstUParameter()),Abs(theS2->LastUParameter()));
1260 const Standard_Real MV = Max(Abs(theS2->FirstVParameter()),Abs(theS2->LastVParameter()));
1261 const Standard_Real AP = Max(MU, MV);
1262 Handle(Adaptor3d_HSurface) SS;
1263 FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, theS1, AP, SS);
1264 interpp.Perform(SS,theD1,theS2,theD2,TolTang,TolArc,myFleche,myUVMaxStep);
1268 FUN_GetMinMaxXYZPnt( theS1, pMinXYZ, pMaxXYZ );
1269 const Standard_Real MU = Max(Abs(theS1->FirstUParameter()),Abs(theS1->LastUParameter()));
1270 const Standard_Real MV = Max(Abs(theS1->FirstVParameter()),Abs(theS1->LastVParameter()));
1271 const Standard_Real AP = Max(MU, MV);
1272 Handle(Adaptor3d_HSurface) SS;
1273 FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, theS2, AP, SS);
1274 interpp.Perform(theS1, theD1, SS, theD2,TolTang, TolArc,myFleche,myUVMaxStep);
1276 }//(theD1->DomainIsInfinite()) ^ (theD2->DomainIsInfinite())
1279 if(typs1 == GeomAbs_OtherSurface || typs2 == GeomAbs_OtherSurface)
1281 done = Standard_False;
1285 Standard_Boolean IsPLInt = Standard_False;
1286 TColgp_SequenceOfPnt sop;
1288 FUN_PL_Intersection(theS1,typs1,theS2,typs2,IsPLInt,sop,v);
1292 if(sop.Length() > 0)
1294 for(Standard_Integer ip = 1; ip <= sop.Length(); ip++)
1296 gp_Lin lin(sop.Value(ip),gp_Dir(v));
1297 Handle(IntPatch_Line) gl = new IntPatch_GLine(lin,Standard_False);
1301 done = Standard_True;
1304 done = Standard_False;
1307 }// 'COLLINEAR LINES'
1310 Handle(Adaptor3d_HSurface) nS1 = theS1;
1311 Handle(Adaptor3d_HSurface) nS2 = theS2;
1312 FUN_TrimBothSurf(theS1,typs1,theS2,typs2,1.e+8,nS1,nS2);
1313 interpp.Perform(nS1,theD1,nS2,theD2,TolTang,TolArc,myFleche,myUVMaxStep);
1314 }// 'NON - COLLINEAR LINES'
1315 }// both domains are infinite
1317 if (interpp.IsDone())
1319 done = Standard_True;
1320 tgte = Standard_False;
1321 empt = interpp.IsEmpty();
1323 for(Standard_Integer i = 1; i <= interpp.NbLines(); i++)
1325 if(interpp.Line(i)->ArcType() != IntPatch_Walking)
1326 slin.Append(interpp.Line(i));
1329 for (Standard_Integer i = 1; i <= interpp.NbLines(); i++)
1331 if(interpp.Line(i)->ArcType() == IntPatch_Walking)
1332 slin.Append(interpp.Line(i));
1337 //=======================================================================
1338 ////function : GeomGeomPerfom
1340 //=======================================================================
1341 void IntPatch_Intersection::GeomGeomPerfom(const Handle(Adaptor3d_HSurface)& theS1,
1342 const Handle(Adaptor3d_TopolTool)& theD1,
1343 const Handle(Adaptor3d_HSurface)& theS2,
1344 const Handle(Adaptor3d_TopolTool)& theD2,
1345 const Standard_Real TolArc,
1346 const Standard_Real TolTang,
1347 IntSurf_ListOfPntOn2S& ListOfPnts,
1348 const Standard_Boolean RestrictLine,
1349 const GeomAbs_SurfaceType theTyps1,
1350 const GeomAbs_SurfaceType theTyps2,
1351 const Standard_Boolean theIsReqToKeepRLine)
1353 IntPatch_ImpImpIntersection interii(theS1,theD1,theS2,theD2,
1354 myTolArc,myTolTang, theIsReqToKeepRLine);
1356 if (!interii.IsDone())
1358 done = Standard_False;
1359 ParamParamPerfom(theS1, theD1, theS2, theD2,
1360 TolArc, TolTang, ListOfPnts, RestrictLine, theTyps1, theTyps2);
1364 done = (interii.GetStatus() == IntPatch_ImpImpIntersection::IntStatus_OK);
1365 empt = interii.IsEmpty();
1372 const Standard_Integer aNbPointsInALine = 200;
1374 tgte = interii.TangentFaces();
1376 oppo = interii.OppositeFaces();
1378 Standard_Boolean isWLExist = Standard_False;
1379 IntPatch_ALineToWLine AToW(theS1, theS2, aNbPointsInALine);
1381 for (Standard_Integer i = 1; i <= interii.NbLines(); i++)
1383 const Handle(IntPatch_Line)& line = interii.Line(i);
1384 if (line->ArcType() == IntPatch_Analytic)
1386 isWLExist = Standard_True;
1387 AToW.MakeWLine(Handle(IntPatch_ALine)::DownCast(line), slin);
1391 if (line->ArcType() == IntPatch_Walking)
1393 Handle(IntPatch_WLine)::DownCast(line)->EnablePurging(Standard_False);
1396 if((line->ArcType() != IntPatch_Restriction) || theIsReqToKeepRLine)
1401 for (Standard_Integer i = 1; i <= interii.NbPnts(); i++)
1403 spnt.Append(interii.Point(i));
1406 if((theTyps1 == GeomAbs_Cylinder) && (theTyps2 == GeomAbs_Cylinder))
1408 IntPatch_WLineTool::JoinWLines(slin, spnt, theS1, theS2, TolTang);
1413 Bnd_Box2d aBx1, aBx2;
1414 const Standard_Real aU1F = theS1->FirstUParameter(),
1415 aU1L = theS1->LastUParameter(),
1416 aV1F = theS1->FirstVParameter(),
1417 aV1L = theS1->LastVParameter(),
1418 aU2F = theS2->FirstUParameter(),
1419 aU2L = theS2->LastUParameter(),
1420 aV2F = theS2->FirstVParameter(),
1421 aV2L = theS2->LastVParameter();
1422 aBx1.Add(gp_Pnt2d(aU1F, aV1F));
1423 aBx1.Add(gp_Pnt2d(aU1L, aV1F));
1424 aBx1.Add(gp_Pnt2d(aU1L, aV1L));
1425 aBx1.Add(gp_Pnt2d(aU1F, aV1L));
1426 aBx2.Add(gp_Pnt2d(aU2F, aV2F));
1427 aBx2.Add(gp_Pnt2d(aU2L, aV2F));
1428 aBx2.Add(gp_Pnt2d(aU2L, aV2L));
1429 aBx2.Add(gp_Pnt2d(aU2F, aV2L));
1431 aBx1.Enlarge(Precision::PConfusion());
1432 aBx2.Enlarge(Precision::PConfusion());
1435 anArrOfPeriod[4] = {theS1->IsUPeriodic()? theS1->UPeriod() : 0.0,
1436 theS1->IsVPeriodic()? theS1->VPeriod() : 0.0,
1437 theS2->IsUPeriodic()? theS2->UPeriod() : 0.0,
1438 theS2->IsVPeriodic()? theS2->VPeriod() : 0.0};
1439 IntPatch_WLineTool::ExtendTwoWLines(slin, theS1, theS2, TolTang,
1440 anArrOfPeriod, aBx1, aBx2);
1444 //=======================================================================
1445 //function : GeomParamPerfom
1447 //=======================================================================
1448 void IntPatch_Intersection::
1449 GeomParamPerfom(const Handle(Adaptor3d_HSurface)& theS1,
1450 const Handle(Adaptor3d_TopolTool)& theD1,
1451 const Handle(Adaptor3d_HSurface)& theS2,
1452 const Handle(Adaptor3d_TopolTool)& theD2,
1453 const Standard_Boolean isNotAnalitical,
1454 const GeomAbs_SurfaceType typs1,
1455 const GeomAbs_SurfaceType typs2)
1457 IntPatch_ImpPrmIntersection interip;
1460 if (isNotAnalitical/*ts1 == 0*/)
1461 interip.SetStartPoint(myU1Start,myV1Start);
1463 interip.SetStartPoint(myU2Start,myV2Start);
1466 if(theD1->DomainIsInfinite() && theD2->DomainIsInfinite())
1468 Standard_Boolean IsPLInt = Standard_False;
1469 TColgp_SequenceOfPnt sop;
1471 FUN_PL_Intersection(theS1,typs1,theS2,typs2,IsPLInt,sop,v);
1475 if(sop.Length() > 0)
1477 for(Standard_Integer ip = 1; ip <= sop.Length(); ip++)
1479 gp_Lin lin(sop.Value(ip),gp_Dir(v));
1480 Handle(IntPatch_Line) gl = new IntPatch_GLine(lin,Standard_False);
1484 done = Standard_True;
1487 done = Standard_False;
1493 Handle(Adaptor3d_HSurface) nS1 = theS1;
1494 Handle(Adaptor3d_HSurface) nS2 = theS2;
1495 FUN_TrimBothSurf(theS1,typs1,theS2,typs2,1.e+5,nS1,nS2);
1496 interip.Perform(nS1,theD1,nS2,theD2,myTolArc,myTolTang,myFleche,myUVMaxStep);
1500 interip.Perform(theS1,theD1,theS2,theD2,myTolArc,myTolTang,myFleche,myUVMaxStep);
1502 if (interip.IsDone())
1504 done = Standard_True;
1505 empt = interip.IsEmpty();
1509 const Standard_Integer aNbLines = interip.NbLines();
1510 for(Standard_Integer i = 1; i <= aNbLines; i++)
1512 if(interip.Line(i)->ArcType() != IntPatch_Walking)
1513 slin.Append(interip.Line(i));
1516 for(Standard_Integer i = 1; i <= aNbLines; i++)
1518 if(interip.Line(i)->ArcType() == IntPatch_Walking)
1519 slin.Append(interip.Line(i));
1522 for (Standard_Integer i = 1; i <= interip.NbPnts(); i++)
1523 spnt.Append(interip.Point(i));
1528 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& S1,
1529 const Handle(Adaptor3d_TopolTool)& D1,
1530 const Handle(Adaptor3d_HSurface)& S2,
1531 const Handle(Adaptor3d_TopolTool)& D2,
1532 const Standard_Real U1,
1533 const Standard_Real V1,
1534 const Standard_Real U2,
1535 const Standard_Real V2,
1536 const Standard_Real TolArc,
1537 const Standard_Real TolTang)
1540 myTolTang = TolTang;
1541 if(myFleche == 0.0) {
1543 //cout<<" -- IntPatch_Intersection::myFleche fixe par defaut a 0.01 --"<<endl;
1544 //cout<<" -- Utiliser la Methode SetTolerances( ... ) "<<endl;
1548 if(myUVMaxStep==0.0) {
1550 //cout<<" -- IntPatch_Intersection::myUVMaxStep fixe par defaut a 0.01 --"<<endl;
1551 //cout<<" -- Utiliser la Methode SetTolerances( ... ) "<<endl;
1556 done = Standard_False;
1560 empt = Standard_True;
1561 tgte = Standard_False;
1562 oppo = Standard_False;
1564 const GeomAbs_SurfaceType typs1 = S1->GetType();
1565 const GeomAbs_SurfaceType typs2 = S2->GetType();
1567 if( typs1==GeomAbs_Plane
1568 || typs1==GeomAbs_Cylinder
1569 || typs1==GeomAbs_Sphere
1570 || typs1==GeomAbs_Cone
1571 || typs2==GeomAbs_Plane
1572 || typs2==GeomAbs_Cylinder
1573 || typs2==GeomAbs_Sphere
1574 || typs2==GeomAbs_Cone)
1576 myIsStartPnt = Standard_True;
1577 myU1Start = U1; myV1Start = V1; myU2Start = U2; myV2Start = V2;
1578 Perform(S1,D1,S2,D2,TolArc,TolTang);
1579 myIsStartPnt = Standard_False;
1583 IntPatch_PrmPrmIntersection interpp;
1584 interpp.Perform(S1,D1,S2,D2,U1,V1,U2,V2,TolTang,TolArc,myFleche,myUVMaxStep);
1585 if (interpp.IsDone())
1587 done = Standard_True;
1588 tgte = Standard_False;
1589 empt = interpp.IsEmpty();
1590 const Standard_Integer nblm = interpp.NbLines();
1591 Standard_Integer i = 1;
1592 for (; i<=nblm; i++) slin.Append(interpp.Line(i));
1596 for(Standard_Integer i = slin.Lower(); i <= slin.Upper(); i++)
1598 Handle(IntPatch_WLine) aWL = Handle(IntPatch_WLine)::DownCast(slin.Value(i));
1603 if (!aWL->IsPurgingAllowed())
1606 Handle(IntPatch_WLine) aRW =
1607 IntPatch_WLineTool::ComputePurgedWLine(aWL, S1, S2, D1, D2, Standard_True);
1612 slin.InsertAfter(i, aRW);
1617 #ifdef DUMPOFIntPatch_Intersection
1619 void IntPatch_Intersection__MAJ_R(Handle(Adaptor2d_HCurve2d) *R1,
1620 Handle(Adaptor2d_HCurve2d) *,
1623 Standard_Integer nbR1,
1625 const IntPatch_Point& VTX)
1628 if(VTX.IsOnDomS1()) {
1630 //-- long unsigned ptr= *((long unsigned *)(((Handle(Standard_Transient) *)(&(VTX.ArcOnS1())))));
1631 for(Standard_Integer i=0; i<nbR1;i++) {
1632 if(VTX.ArcOnS1()==R1[i]) {
1634 printf("\n ******************************");
1638 printf("\n R Pas trouvee (IntPatch)\n");
1644 void IntPatch_Intersection::Dump(const Standard_Integer /*Mode*/,
1645 const Handle(Adaptor3d_HSurface)& /*S1*/,
1646 const Handle(Adaptor3d_TopolTool)& /*D1*/,
1647 const Handle(Adaptor3d_HSurface)& /*S2*/,
1648 const Handle(Adaptor3d_TopolTool)& /*D2*/) const
1650 #ifdef DUMPOFIntPatch_Intersection
1651 const int MAXR = 200;
1652 //-- ----------------------------------------------------------------------
1653 //-- construction de la liste des restrictions & vertex
1655 int NR1[MAXR],NR2[MAXR];
1656 Handle(Adaptor2d_HCurve2d) R1[MAXR],R2[MAXR];
1657 Standard_Integer nbR1=0,nbR2=0;
1658 for(D1->Init();D1->More() && nbR1<MAXR; D1->Next()) {
1659 R1[nbR1]=D1->Value();
1663 for(D2->Init();D2->More() && nbR2<MAXR; D2->Next()) {
1664 R2[nbR2]=D2->Value();
1669 printf("\nDUMP_INT: ----empt:%2ud tgte:%2ud oppo:%2ud ---------------------------------",empt,tgte,empt);
1670 Standard_Integer i,nbr1,nbr2,nbgl,nbgc,nbge,nbgp,nbgh,nbl,nbr,nbg,nbw,nba;
1671 nbl=nbr=nbg=nbw=nba=nbgl=nbge=nbr1=nbr2=nbgc=nbgp=nbgh=0;
1673 for(i=1;i<=nbl;i++) {
1674 const Handle(IntPatch_Line)& line=Line(i);
1675 const IntPatch_IType IType=line->ArcType();
1676 if(IType == IntPatch_Walking) nbw++;
1677 else if(IType == IntPatch_Restriction) {
1679 Handle(IntPatch_RLine) rlin (Handle(IntPatch_RLine)::DownCast (line));
1680 if(rlin->IsArcOnS1()) nbr1++;
1681 if(rlin->IsArcOnS2()) nbr2++;
1683 else if(IType == IntPatch_Analytic) nba++;
1686 if(IType == IntPatch_Lin) nbgl++;
1687 else if(IType == IntPatch_Circle) nbgc++;
1688 else if(IType == IntPatch_Parabola) nbgp++;
1689 else if(IType == IntPatch_Hyperbola) nbgh++;
1690 else if(IType == IntPatch_Ellipse) nbge++;
1695 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)",
1696 nbl,nbw,nbr,nbr1,nbr2,nba,nbg,nbgl,nbgc,nbge,nbgh,nbgp);
1698 IntPatch_LineConstructor LineConstructor(2);
1700 Standard_Integer nbllc=0;
1702 Standard_Integer nbva,nbvw,nbvr,nbvg;
1703 nbva=nbvr=nbvw=nbvg=0;
1704 for (j=1; j<=nbl; j++) {
1705 Standard_Integer v,nbvtx;
1706 const Handle(IntPatch_Line)& intersLinej = Line(j);
1707 Standard_Integer NbLines;
1708 LineConstructor.Perform(SequenceOfLine(),intersLinej,S1,D1,S2,D2,1e-7);
1709 NbLines = LineConstructor.NbLines();
1711 for(Standard_Integer k=1;k<=NbLines;k++) {
1713 const Handle(IntPatch_Line)& LineK = LineConstructor.Line(k);
1714 if (LineK->ArcType() == IntPatch_Analytic) {
1715 Handle(IntPatch_ALine) alin (Handle(IntPatch_ALine)::DownCast (LineK));
1716 nbvtx=alin->NbVertex();
1718 for(v=1;v<=nbvtx;v++) {
1719 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,alin->Vertex(v));
1722 else if (LineK->ArcType() == IntPatch_Restriction) {
1723 Handle(IntPatch_RLine) rlin (Handle(IntPatch_RLine)::DownCast (LineK));
1724 nbvtx=rlin->NbVertex();
1726 for(v=1;v<=nbvtx;v++) {
1727 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,rlin->Vertex(v));
1730 else if (LineK->ArcType() == IntPatch_Walking) {
1731 Handle(IntPatch_WLine) wlin (Handle(IntPatch_WLine)::DownCast (LineK));
1732 nbvtx=wlin->NbVertex();
1734 for(v=1;v<=nbvtx;v++) {
1735 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,wlin->Vertex(v));
1739 Handle(IntPatch_GLine) glin (Handle(IntPatch_GLine)::DownCast (LineK));
1740 nbvtx=glin->NbVertex();
1742 for(v=1;v<=nbvtx;v++) {
1743 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,glin->Vertex(v));
1748 printf("\nDUMP_LC :Lines:%2d WLin:%2d Restr:%2d Ana:%2d Geom:%2d",
1749 nbllc,nbw,nbr,nba,nbg);
1750 printf("\nDUMP_LC :vtx :%2d r:%2d :%2d :%2d",
1751 nbvw,nbvr,nbva,nbvg);