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())
172 IntPatch_PrmPrmIntersection interpp;
173 interpp.Perform(S1,D1,TolTang,TolArc,myFleche,myUVMaxStep);
174 if (interpp.IsDone())
176 done = Standard_True;
177 tgte = Standard_False;
178 empt = interpp.IsEmpty();
179 const Standard_Integer nblm = interpp.NbLines();
180 for (Standard_Integer i=1; i<=nblm; i++) slin.Append(interpp.Line(i));
187 /////////////////////////////////////////////////////////////////////////////
188 // These several support functions provide methods which can help basic //
189 // algorithm to intersect infinite surfaces of the following types: //
191 // a.) SurfaceOfExtrusion; //
192 // b.) SurfaceOfRevolution; //
193 // c.) OffsetSurface. //
195 /////////////////////////////////////////////////////////////////////////////
196 #include <TColgp_Array1OfXYZ.hxx>
197 #include <TColgp_Array1OfPnt.hxx>
198 #include <TColgp_SequenceOfPnt.hxx>
199 #include <Extrema_ExtPS.hxx>
200 #include <Extrema_POnSurf.hxx>
201 #include <Geom2d_Curve.hxx>
202 #include <Geom2dAPI_InterCurveCurve.hxx>
203 #include <GeomAdaptor.hxx>
204 #include <GeomAdaptor_HCurve.hxx>
205 #include <GeomAdaptor_Curve.hxx>
206 #include <GeomAdaptor_Surface.hxx>
207 #include <GeomAdaptor_HSurface.hxx>
208 #include <Geom_Plane.hxx>
209 #include <ProjLib_ProjectOnPlane.hxx>
210 #include <GeomProjLib.hxx>
211 #include <ElCLib.hxx>
212 #include <Geom_TrimmedCurve.hxx>
213 #include <Geom_Surface.hxx>
214 #include <Geom_SurfaceOfLinearExtrusion.hxx>
215 #include <Geom_OffsetSurface.hxx>
216 #include <Geom_SurfaceOfRevolution.hxx>
217 #include <Geom_RectangularTrimmedSurface.hxx>
219 //===============================================================
220 //function: FUN_GetMinMaxXYZPnt
221 //===============================================================
222 static void FUN_GetMinMaxXYZPnt( const Handle(Adaptor3d_HSurface)& S,
223 gp_Pnt& pMin, gp_Pnt& pMax )
225 const Standard_Real DU = 0.25 * Abs(S->LastUParameter() - S->FirstUParameter());
226 const Standard_Real DV = 0.25 * Abs(S->LastVParameter() - S->FirstVParameter());
227 Standard_Real tMinXYZ = RealLast();
228 Standard_Real tMaxXYZ = -tMinXYZ;
229 gp_Pnt PUV, ptMax, ptMin;
230 for(Standard_Real U = S->FirstUParameter(); U <= S->LastUParameter(); U += DU)
232 for(Standard_Real V = S->FirstVParameter(); V <= S->LastVParameter(); V += DV)
235 const Standard_Real cXYZ = PUV.XYZ().Modulus();
236 if(cXYZ > tMaxXYZ) { tMaxXYZ = cXYZ; ptMax = PUV; }
237 if(cXYZ < tMinXYZ) { tMinXYZ = cXYZ; ptMin = PUV; }
243 //==========================================================================
244 //function: FUN_TrimInfSurf
245 //==========================================================================
246 static void FUN_TrimInfSurf(const gp_Pnt& Pmin,
248 const Handle(Adaptor3d_HSurface)& InfSurf,
249 const Standard_Real& AlternativeTrimPrm,
250 Handle(Adaptor3d_HSurface)& TrimS)
252 Standard_Real TP = AlternativeTrimPrm;
253 Extrema_ExtPS ext1(Pmin, InfSurf->Surface(), 1.e-7, 1.e-7);
254 Extrema_ExtPS ext2(Pmax, InfSurf->Surface(), 1.e-7, 1.e-7);
255 if(ext1.IsDone() || ext2.IsDone())
257 Standard_Real Umax = -1.e+100, Umin = 1.e+100, Vmax = -1.e+100, Vmin = 1.e+100, cU, cV;
260 for(Standard_Integer i = 1; i <= ext1.NbExt(); i++)
262 const Extrema_POnSurf & pons = ext1.Point(i);
263 pons.Parameter(cU,cV);
264 if(cU > Umax) Umax = cU;
265 if(cU < Umin) Umin = cU;
266 if(cV > Vmax) Vmax = cV;
267 if(cV < Vmin) Vmin = cV;
272 for(Standard_Integer i = 1; i <= ext2.NbExt(); i++)
274 const Extrema_POnSurf & pons = ext2.Point(i);
275 pons.Parameter(cU,cV);
276 if(cU > Umax) Umax = cU;
277 if(cU < Umin) Umin = cU;
278 if(cV > Vmax) Vmax = cV;
279 if(cV < Vmin) Vmin = cV;
282 TP = Max(Abs(Umin),Max(Abs(Umax),Max(Abs(Vmin),Abs(Vmax))));
284 if(TP == 0.) { TrimS = InfSurf; return; }
287 const Standard_Boolean Uinf = Precision::IsNegativeInfinite(InfSurf->FirstUParameter());
288 const Standard_Boolean Usup = Precision::IsPositiveInfinite(InfSurf->LastUParameter());
289 const Standard_Boolean Vinf = Precision::IsNegativeInfinite(InfSurf->FirstVParameter());
290 const Standard_Boolean Vsup = Precision::IsPositiveInfinite(InfSurf->LastVParameter());
291 Handle(Adaptor3d_HSurface) TmpSS;
292 Standard_Integer IsTrimed = 0;
293 const Standard_Real tp = 1000.0 * TP;
294 if(Vinf && Vsup) { TrimS = InfSurf->VTrim(-tp, tp, 1.0e-7); IsTrimed = 1; }
295 if(Vinf && !Vsup){ TrimS = InfSurf->VTrim(-tp, InfSurf->LastVParameter(), 1.0e-7); IsTrimed = 1; }
296 if(!Vinf && Vsup){ TrimS = InfSurf->VTrim(InfSurf->FirstVParameter(), tp, 1.0e-7); IsTrimed = 1; }
300 if(Uinf && Usup) TrimS = TmpSS->UTrim(-tp, tp, 1.0e-7);
301 if(Uinf && !Usup) TrimS = TmpSS->UTrim(-tp, InfSurf->LastUParameter(), 1.0e-7);
302 if(!Uinf && Usup) TrimS = TmpSS->UTrim(InfSurf->FirstUParameter(), tp, 1.0e-7);
306 if(Uinf && Usup) TrimS = InfSurf->UTrim(-tp, tp, 1.0e-7);
307 if(Uinf && !Usup) TrimS = InfSurf->UTrim(-tp, InfSurf->LastUParameter(), 1.0e-7);
308 if(!Uinf && Usup) TrimS = InfSurf->UTrim(InfSurf->FirstUParameter(), tp, 1.0e-7);
312 //================================================================================
313 //function: FUN_GetUiso
314 //================================================================================
315 static void FUN_GetUiso(const Handle(Geom_Surface)& GS,
316 const GeomAbs_SurfaceType& T,
317 const Standard_Real& FirstV,
318 const Standard_Real& LastV,
319 const Standard_Boolean& IsVC,
320 const Standard_Boolean& IsVP,
321 const Standard_Real& U,
322 Handle(Geom_Curve)& I)
324 if(T != GeomAbs_OffsetSurface)
326 Handle(Geom_Curve) gc = GS->UIso(U);
327 if(IsVP && (FirstV == 0.0 && LastV == (2.*M_PI))) I = gc;
330 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstV,LastV);
331 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
337 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (GS);
338 const Handle(Geom_Surface) bs = gos->BasisSurface();
339 Handle(Geom_Curve) gcbs = bs->UIso(U);
340 GeomAdaptor_Curve gac(gcbs);
341 const GeomAbs_CurveType GACT = gac.GetType();
342 if(IsVP || IsVC || GACT == GeomAbs_BSplineCurve || GACT == GeomAbs_BezierCurve || Abs(LastV - FirstV) < 1.e+5)
344 Handle(Geom_Curve) gc = gos->UIso(U);
345 if(IsVP && (FirstV == 0.0 && LastV == (2*M_PI))) I = gc;
348 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstV,LastV);
349 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
353 else//Offset Line, Parab, Hyperb
355 Standard_Real VmTr, VMTr;
356 if(GACT != GeomAbs_Hyperbola)
358 if(FirstV >= 0. && LastV >= 0.){ VmTr = FirstV; VMTr = ((LastV - FirstV) > 1.e+4) ? (FirstV + 1.e+4) : LastV; }
359 else if(FirstV < 0. && LastV < 0.){ VMTr = LastV; VmTr = ((FirstV - LastV) < -1.e+4) ? (LastV - 1.e+4) : FirstV; }
360 else { VmTr = (FirstV < -1.e+4) ? -1.e+4 : FirstV; VMTr = (LastV > 1.e+4) ? 1.e+4 : LastV; }
364 if(FirstV >= 0. && LastV >= 0.)
366 if(FirstV > 4.) return;
367 VmTr = FirstV; VMTr = (LastV > 4.) ? 4. : LastV;
369 else if(FirstV < 0. && LastV < 0.)
371 if(LastV < -4.) return;
372 VMTr = LastV; VmTr = (FirstV < -4.) ? -4. : FirstV;
374 else { VmTr = (FirstV < -4.) ? -4. : FirstV; VMTr = (LastV > 4.) ? 4. : LastV; }
376 //Make trimmed surface
377 Handle(Geom_RectangularTrimmedSurface) rts = new Geom_RectangularTrimmedSurface(gos,VmTr,VMTr,Standard_True);
382 //================================================================================
383 //function: FUN_GetViso
384 //================================================================================
385 static void FUN_GetViso(const Handle(Geom_Surface)& GS,
386 const GeomAbs_SurfaceType& T,
387 const Standard_Real& FirstU,
388 const Standard_Real& LastU,
389 const Standard_Boolean& IsUC,
390 const Standard_Boolean& IsUP,
391 const Standard_Real& V,
392 Handle(Geom_Curve)& I)
394 if(T != GeomAbs_OffsetSurface)
396 Handle(Geom_Curve) gc = GS->VIso(V);
397 if(IsUP && (FirstU == 0.0 && LastU == (2*M_PI))) I = gc;
400 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstU,LastU);
401 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
407 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (GS);
408 const Handle(Geom_Surface) bs = gos->BasisSurface();
409 Handle(Geom_Curve) gcbs = bs->VIso(V);
410 GeomAdaptor_Curve gac(gcbs);
411 const GeomAbs_CurveType GACT = gac.GetType();
412 if(IsUP || IsUC || GACT == GeomAbs_BSplineCurve || GACT == GeomAbs_BezierCurve || Abs(LastU - FirstU) < 1.e+5)
414 Handle(Geom_Curve) gc = gos->VIso(V);
415 if(IsUP && (FirstU == 0.0 && LastU == (2*M_PI))) I = gc;
418 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstU,LastU);
419 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
423 else//Offset Line, Parab, Hyperb
425 Standard_Real UmTr, UMTr;
426 if(GACT != GeomAbs_Hyperbola)
428 if(FirstU >= 0. && LastU >= 0.){ UmTr = FirstU; UMTr = ((LastU - FirstU) > 1.e+4) ? (FirstU + 1.e+4) : LastU; }
429 else if(FirstU < 0. && LastU < 0.){ UMTr = LastU; UmTr = ((FirstU - LastU) < -1.e+4) ? (LastU - 1.e+4) : FirstU; }
430 else { UmTr = (FirstU < -1.e+4) ? -1.e+4 : FirstU; UMTr = (LastU > 1.e+4) ? 1.e+4 : LastU; }
434 if(FirstU >= 0. && LastU >= 0.)
436 if(FirstU > 4.) return;
437 UmTr = FirstU; UMTr = (LastU > 4.) ? 4. : LastU;
439 else if(FirstU < 0. && LastU < 0.)
441 if(LastU < -4.) return;
442 UMTr = LastU; UmTr = (FirstU < -4.) ? -4. : FirstU;
444 else { UmTr = (FirstU < -4.) ? -4. : FirstU; UMTr = (LastU > 4.) ? 4. : LastU; }
446 //Make trimmed surface
447 Handle(Geom_RectangularTrimmedSurface) rts = new Geom_RectangularTrimmedSurface(gos,UmTr,UMTr,Standard_True);
452 //================================================================================
453 //function: FUN_PL_Intersection
454 //================================================================================
455 static void FUN_PL_Intersection(const Handle(Adaptor3d_HSurface)& S1,
456 const GeomAbs_SurfaceType& T1,
457 const Handle(Adaptor3d_HSurface)& S2,
458 const GeomAbs_SurfaceType& T2,
459 Standard_Boolean& IsOk,
460 TColgp_SequenceOfPnt& SP,
463 IsOk = Standard_False;
464 // 1. Check: both surfaces have U(V)isos - lines.
465 DV = gp_Vec(0.,0.,1.);
466 Standard_Boolean isoS1isLine[2] = {0, 0};
467 Standard_Boolean isoS2isLine[2] = {0, 0};
468 Handle(Geom_Curve) C1, C2;
469 const GeomAdaptor_Surface & gas1 = *(GeomAdaptor_Surface*)(&(S1->Surface()));
470 const GeomAdaptor_Surface & gas2 = *(GeomAdaptor_Surface*)(&(S2->Surface()));
471 const Handle(Geom_Surface) gs1 = gas1.Surface();
472 const Handle(Geom_Surface) gs2 = gas2.Surface();
473 Standard_Real MS1[2], MS2[2];
474 MS1[0] = 0.5 * (S1->LastUParameter() + S1->FirstUParameter());
475 MS1[1] = 0.5 * (S1->LastVParameter() + S1->FirstVParameter());
476 MS2[0] = 0.5 * (S2->LastUParameter() + S2->FirstUParameter());
477 MS2[1] = 0.5 * (S2->LastVParameter() + S2->FirstVParameter());
478 if(T1 == GeomAbs_SurfaceOfExtrusion) isoS1isLine[0] = Standard_True;
479 else if(!S1->IsVPeriodic() && !S1->IsVClosed()) {
480 if(T1 != GeomAbs_OffsetSurface) C1 = gs1->UIso(MS1[0]);
482 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs1);
483 const Handle(Geom_Surface) bs = gos->BasisSurface();
484 C1 = bs->UIso(MS1[0]);
486 GeomAdaptor_Curve gac(C1);
487 if(gac.GetType() == GeomAbs_Line) isoS1isLine[0] = Standard_True;
489 if(!S1->IsUPeriodic() && !S1->IsUClosed()) {
490 if(T1 != GeomAbs_OffsetSurface) C1 = gs1->VIso(MS1[1]);
492 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs1);
493 const Handle(Geom_Surface) bs = gos->BasisSurface();
494 C1 = bs->VIso(MS1[1]);
496 GeomAdaptor_Curve gac(C1);
497 if(gac.GetType() == GeomAbs_Line) isoS1isLine[1] = Standard_True;
499 if(T2 == GeomAbs_SurfaceOfExtrusion) isoS2isLine[0] = Standard_True;
500 else if(!S2->IsVPeriodic() && !S2->IsVClosed()) {
501 if(T2 != GeomAbs_OffsetSurface) C2 = gs2->UIso(MS2[0]);
503 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs2);
504 const Handle(Geom_Surface) bs = gos->BasisSurface();
505 C2 = bs->UIso(MS2[0]);
507 GeomAdaptor_Curve gac(C2);
508 if(gac.GetType() == GeomAbs_Line) isoS2isLine[0] = Standard_True;
510 if(!S2->IsUPeriodic() && !S2->IsUClosed()) {
511 if(T2 != GeomAbs_OffsetSurface) C2 = gs2->VIso(MS2[1]);
513 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs2);
514 const Handle(Geom_Surface) bs = gos->BasisSurface();
515 C2 = bs->VIso(MS2[1]);
517 GeomAdaptor_Curve gac(C2);
518 if(gac.GetType() == GeomAbs_Line) isoS2isLine[1] = Standard_True;
520 Standard_Boolean IsBothLines = ((isoS1isLine[0] || isoS1isLine[1]) &&
521 (isoS2isLine[0] || isoS2isLine[1]));
525 // 2. Check: Uiso lines of both surfaces are collinear.
527 gp_Vec derS1[2], derS2[2];
528 S1->D1(MS1[0], MS1[1], puvS1, derS1[0], derS1[1]);
529 S2->D1(MS2[0], MS2[1], puvS2, derS2[0], derS2[1]);
530 C1.Nullify(); C2.Nullify();
531 Standard_Integer iso = 0;
532 if(isoS1isLine[0] && isoS2isLine[0] &&
533 derS1[1].IsParallel(derS2[1],Precision::Angular())) {
535 FUN_GetViso(gs1,T1,S1->FirstUParameter(),S1->LastUParameter(),
536 S1->IsUClosed(),S1->IsUPeriodic(),MS1[1],C1);
537 FUN_GetViso(gs2,T2,S2->FirstUParameter(),S2->LastUParameter(),
538 S2->IsUClosed(),S2->IsUPeriodic(),MS2[1],C2);
540 else if(isoS1isLine[0] && isoS2isLine[1] &&
541 derS1[1].IsParallel(derS2[0],Precision::Angular())) {
543 FUN_GetViso(gs1,T1,S1->FirstUParameter(),S1->LastUParameter(),
544 S1->IsUClosed(),S1->IsUPeriodic(),MS1[1],C1);
545 FUN_GetUiso(gs2,T2,S2->FirstVParameter(),S2->LastVParameter(),
546 S2->IsVClosed(),S2->IsVPeriodic(),MS2[0],C2);
548 else if(isoS1isLine[1] && isoS2isLine[0] &&
549 derS1[0].IsParallel(derS2[1],Precision::Angular())) {
551 FUN_GetUiso(gs1,T1,S1->FirstVParameter(),S1->LastVParameter(),
552 S1->IsVClosed(),S1->IsVPeriodic(),MS1[0],C1);
553 FUN_GetViso(gs2,T2,S2->FirstUParameter(),S2->LastUParameter(),
554 S2->IsUClosed(),S2->IsUPeriodic(),MS2[1],C2);
556 else if(isoS1isLine[1] && isoS2isLine[1] &&
557 derS1[0].IsParallel(derS2[0],Precision::Angular())) {
559 FUN_GetUiso(gs1,T1,S1->FirstVParameter(),S1->LastVParameter(),
560 S1->IsVClosed(),S1->IsVPeriodic(),MS1[0],C1);
561 FUN_GetUiso(gs2,T2,S2->FirstVParameter(),S2->LastVParameter(),
562 S2->IsVClosed(),S2->IsVPeriodic(),MS2[0],C2);
565 IsOk = Standard_False;
568 IsOk = Standard_True;
569 // 3. Make intersections of V(U)isos
570 if(C1.IsNull() || C2.IsNull()) return;
572 Handle(Geom_Plane) GPln = new Geom_Plane(gp_Pln(puvS1,gp_Dir(DV)));
573 Handle(Geom_Curve) C1Prj =
574 GeomProjLib::ProjectOnPlane(C1,GPln,gp_Dir(DV),Standard_True);
575 Handle(Geom_Curve) C2Prj =
576 GeomProjLib::ProjectOnPlane(C2,GPln,gp_Dir(DV),Standard_True);
577 if(C1Prj.IsNull() || C2Prj.IsNull()) return;
578 Handle(Geom2d_Curve) C1Prj2d = GeomProjLib::Curve2d (C1Prj,GPln);
579 Handle(Geom2d_Curve) C2Prj2d = GeomProjLib::Curve2d (C2Prj,GPln);
580 Geom2dAPI_InterCurveCurve ICC(C1Prj2d,C2Prj2d,1.0e-7);
581 if(ICC.NbPoints() > 0 )
583 for(Standard_Integer ip = 1; ip <= ICC.NbPoints(); ip++)
585 gp_Pnt2d P = ICC.Point(ip);
586 gp_Pnt P3d = ElCLib::To3d(gp_Ax2(puvS1,gp_Dir(DV)),P);
591 //================================================================================
592 //function: FUN_NewFirstLast
593 //================================================================================
594 static void FUN_NewFirstLast(const GeomAbs_CurveType& ga_ct,
595 const Standard_Real& Fst,
596 const Standard_Real& Lst,
597 const Standard_Real& TrVal,
598 Standard_Real& NewFst,
599 Standard_Real& NewLst,
600 Standard_Boolean& NeedTr)
602 NewFst = Fst; NewLst = Lst; NeedTr = Standard_False;
606 case GeomAbs_Parabola:
608 if(Abs(Lst - Fst) > TrVal)
610 if(Fst >= 0. && Lst >= 0.)
613 NewLst = ((Fst + TrVal) < Lst) ? (Fst + TrVal) : Lst;
615 if(Fst < 0. && Lst < 0.)
618 NewFst = ((Lst - TrVal) > Fst) ? (Lst - TrVal) : Fst;
622 NewFst = (Fst < -TrVal) ? -TrVal : Fst;
623 NewLst = (Lst > TrVal) ? TrVal : Lst;
625 NeedTr = Standard_True;
629 case GeomAbs_Hyperbola:
631 if(Abs(Lst - Fst) > 10.)
633 if(Fst >= 0. && Lst >= 0.)
637 NewLst = (Lst > 4.) ? 4. : Lst;
639 if(Fst < 0. && Lst < 0.)
641 if(Lst < -4.) return;
643 NewFst = (Fst < -4.) ? -4. : Fst;
647 NewFst = (Fst < -4.) ? -4. : Fst;
648 NewLst = (Lst > 4.) ? 4. : Lst;
650 NeedTr = Standard_True;
658 //================================================================================
659 //function: FUN_TrimBothSurf
660 //================================================================================
661 static void FUN_TrimBothSurf(const Handle(Adaptor3d_HSurface)& S1,
662 const GeomAbs_SurfaceType& T1,
663 const Handle(Adaptor3d_HSurface)& S2,
664 const GeomAbs_SurfaceType& T2,
665 const Standard_Real& TV,
666 Handle(Adaptor3d_HSurface)& NS1,
667 Handle(Adaptor3d_HSurface)& NS2)
669 const GeomAdaptor_Surface & gas1 = *(GeomAdaptor_Surface*)(&(S1->Surface()));
670 const GeomAdaptor_Surface & gas2 = *(GeomAdaptor_Surface*)(&(S2->Surface()));
671 const Handle(Geom_Surface) gs1 = gas1.Surface();
672 const Handle(Geom_Surface) gs2 = gas2.Surface();
673 const Standard_Real UM1 = 0.5 * (S1->LastUParameter() + S1->FirstUParameter());
674 const Standard_Real UM2 = 0.5 * (S2->LastUParameter() + S2->FirstUParameter());
675 const Standard_Real VM1 = 0.5 * (S1->LastVParameter() + S1->FirstVParameter());
676 const Standard_Real VM2 = 0.5 * (S2->LastVParameter() + S2->FirstVParameter());
677 Handle(Geom_Curve) visoS1, visoS2, uisoS1, uisoS2;
678 if(T1 != GeomAbs_OffsetSurface){ visoS1 = gs1->VIso(VM1); uisoS1 = gs1->UIso(UM1); }
681 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs1);
682 const Handle(Geom_Surface) bs = gos->BasisSurface();
683 visoS1 = bs->VIso(VM1); uisoS1 = bs->UIso(UM1);
685 if(T2 != GeomAbs_OffsetSurface){ visoS2 = gs2->VIso(VM2); uisoS2 = gs2->UIso(UM2); }
688 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs2);
689 const Handle(Geom_Surface) bs = gos->BasisSurface();
690 visoS2 = bs->VIso(VM2); uisoS2 = bs->UIso(UM2);
692 if(uisoS1.IsNull() || uisoS2.IsNull() || visoS1.IsNull() || visoS2.IsNull()){ NS1 = S1; NS2 = S2; return; }
693 GeomAdaptor_Curve gau1(uisoS1);
694 GeomAdaptor_Curve gav1(visoS1);
695 GeomAdaptor_Curve gau2(uisoS2);
696 GeomAdaptor_Curve gav2(visoS2);
697 GeomAbs_CurveType GA_U1 = gau1.GetType();
698 GeomAbs_CurveType GA_V1 = gav1.GetType();
699 GeomAbs_CurveType GA_U2 = gau2.GetType();
700 GeomAbs_CurveType GA_V2 = gav2.GetType();
701 Standard_Boolean TrmU1 = Standard_False;
702 Standard_Boolean TrmV1 = Standard_False;
703 Standard_Boolean TrmU2 = Standard_False;
704 Standard_Boolean TrmV2 = Standard_False;
705 Standard_Real V1S1,V2S1,U1S1,U2S1, V1S2,V2S2,U1S2,U2S2;
706 FUN_NewFirstLast(GA_U1,S1->FirstVParameter(),S1->LastVParameter(),TV,V1S1,V2S1,TrmV1);
707 FUN_NewFirstLast(GA_V1,S1->FirstUParameter(),S1->LastUParameter(),TV,U1S1,U2S1,TrmU1);
708 FUN_NewFirstLast(GA_U2,S2->FirstVParameter(),S2->LastVParameter(),TV,V1S2,V2S2,TrmV2);
709 FUN_NewFirstLast(GA_V2,S2->FirstUParameter(),S2->LastUParameter(),TV,U1S2,U2S2,TrmU2);
710 if(TrmV1) NS1 = S1->VTrim(V1S1, V2S1, 1.0e-7);
711 if(TrmV2) NS2 = S2->VTrim(V1S2, V2S2, 1.0e-7);
716 Handle(Adaptor3d_HSurface) TS = NS1;
717 NS1 = TS->UTrim(U1S1, U2S1, 1.0e-7);
719 else NS1 = S1->UTrim(U1S1, U2S1, 1.0e-7);
725 Handle(Adaptor3d_HSurface) TS = NS2;
726 NS2 = TS->UTrim(U1S2, U2S2, 1.0e-7);
728 else NS2 = S2->UTrim(U1S2, U2S2, 1.0e-7);
732 //=======================================================================
735 //=======================================================================
736 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& theS1,
737 const Handle(Adaptor3d_TopolTool)& theD1,
738 const Handle(Adaptor3d_HSurface)& theS2,
739 const Handle(Adaptor3d_TopolTool)& theD2,
740 const Standard_Real TolArc,
741 const Standard_Real TolTang,
742 const Standard_Boolean isGeomInt,
743 const Standard_Boolean theIsReqToKeepRLine,
744 const Standard_Boolean theIsReqToPostWLProc)
748 if(myFleche <= Precision::PConfusion())
750 if(myUVMaxStep <= Precision::PConfusion())
753 done = Standard_False;
756 empt = Standard_True;
757 tgte = Standard_False;
758 oppo = Standard_False;
760 GeomAbs_SurfaceType typs1 = theS1->GetType();
761 GeomAbs_SurfaceType typs2 = theS2->GetType();
763 //treatment of the cases with cone or torus
764 Standard_Boolean TreatAsBiParametric = Standard_False;
765 Standard_Integer bGeomGeom = 0;
767 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone ||
768 typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
769 gp_Ax1 aCTAx, aGeomAx;
770 GeomAbs_SurfaceType aCTType;
771 Standard_Boolean bToCheck;
773 const Handle(Adaptor3d_HSurface)& aCTSurf =
774 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS1 : theS2;
775 const Handle(Adaptor3d_HSurface)& aGeomSurf =
776 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS2 : theS1;
778 aCTType = aCTSurf->GetType();
779 bToCheck = Standard_False;
781 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone) {
782 const gp_Cone aCon1 = (aCTType == GeomAbs_Cone) ?
783 aCTSurf->Cone() : aGeomSurf->Cone();
784 Standard_Real a1 = Abs(aCon1.SemiAngle());
785 bToCheck = (a1 < 0.02) || (a1 > 1.55);
787 if (typs1 == typs2) {
788 const gp_Cone aCon2 = aGeomSurf->Cone();
789 Standard_Real a2 = Abs(aCon2.SemiAngle());
790 bToCheck = bToCheck || (a2 < 0.02) || (a2 > 1.55);
792 if (a1 > 1.55 && a2 > 1.55) {//quasi-planes: if same domain, treat as canonic
793 const gp_Ax1 A1 = aCon1.Axis(), A2 = aCon2.Axis();
794 if (A1.IsParallel(A2,Precision::Angular())) {
795 const gp_Pnt Apex1 = aCon1.Apex(), Apex2 = aCon2.Apex();
796 const gp_Pln Plan1( Apex1, A1.Direction() );
797 if (Plan1.Distance( Apex2 ) <= Precision::Confusion()) {
798 bToCheck = Standard_False;
804 TreatAsBiParametric = bToCheck;
805 if (aCTType == GeomAbs_Cone) {
806 aCTAx = aCon1.Axis();
810 if (typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
811 const gp_Torus aTor1 = (aCTType == GeomAbs_Torus) ?
812 aCTSurf->Torus() : aGeomSurf->Torus();
813 bToCheck = aTor1.MajorRadius() > aTor1.MinorRadius();
814 if (typs1 == typs2) {
815 const gp_Torus aTor2 = aGeomSurf->Torus();
816 bToCheck = aTor2.MajorRadius() > aTor2.MinorRadius();
819 if (aCTType == GeomAbs_Torus) {
820 aCTAx = aTor1.Axis();
825 const gp_Lin aL1(aCTAx);
827 switch (aGeomSurf->GetType()) {
828 case GeomAbs_Plane: {
829 aGeomAx = aGeomSurf->Plane().Axis();
830 if (aCTType == GeomAbs_Cone) {
832 if (Abs(aCTSurf->Cone().SemiAngle()) < 0.02) {
833 Standard_Real ps = Abs(aCTAx.Direction().Dot(aGeomAx.Direction()));
840 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) ||
841 (aCTAx.IsNormal(aGeomAx, Precision::Angular()) &&
842 (aGeomSurf->Plane().Distance(aCTAx.Location()) < Precision::Confusion()))) {
846 bToCheck = Standard_False;
849 case GeomAbs_Sphere: {
850 if (aL1.Distance(aGeomSurf->Sphere().Location()) < Precision::Confusion()) {
853 bToCheck = Standard_False;
856 case GeomAbs_Cylinder:
857 aGeomAx = aGeomSurf->Cylinder().Axis();
860 aGeomAx = aGeomSurf->Cone().Axis();
863 aGeomAx = aGeomSurf->Torus().Axis();
866 bToCheck = Standard_False;
871 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) &&
872 (aL1.Distance(aGeomAx.Location()) <= Precision::Confusion())) {
877 if (bGeomGeom == 1) {
878 TreatAsBiParametric = Standard_False;
884 if(theD1->DomainIsInfinite() || theD2->DomainIsInfinite()) {
885 TreatAsBiParametric= Standard_False;
888 // Modified by skv - Mon Sep 26 14:58:30 2005 Begin
889 // if(TreatAsBiParametric) { typs1 = typs2 = GeomAbs_BezierSurface; }
890 if(TreatAsBiParametric)
892 if (typs1 == GeomAbs_Cone && typs2 == GeomAbs_Plane)
893 typs1 = GeomAbs_BezierSurface; // Using Imp-Prm Intersector
894 else if (typs1 == GeomAbs_Plane && typs2 == GeomAbs_Cone)
895 typs2 = GeomAbs_BezierSurface; // Using Imp-Prm Intersector
897 // Using Prm-Prm Intersector
898 typs1 = GeomAbs_BezierSurface;
899 typs2 = GeomAbs_BezierSurface;
902 // Modified by skv - Mon Sep 26 14:58:30 2005 End
904 // Surface type definition
905 Standard_Integer ts1 = 0;
909 case GeomAbs_Cylinder:
911 case GeomAbs_Cone: ts1 = 1; break;
912 case GeomAbs_Torus: ts1 = bGeomGeom; break;
916 Standard_Integer ts2 = 0;
920 case GeomAbs_Cylinder:
922 case GeomAbs_Cone: ts2 = 1; break;
923 case GeomAbs_Torus: ts2 = bGeomGeom; break;
927 // treatment of the cases with torus and any other geom surface
929 // Possible intersection types: 1. ts1 == ts2 == 1 <Geom-Geom>
930 // 2. ts1 != ts2 <Geom-Param>
931 // 3. ts1 == ts2 == 0 <Param-Param>
934 if(ts1 == ts2 && ts1 == 1)
936 IntSurf_ListOfPntOn2S ListOfPnts;
940 GeomGeomPerfom(theS1, theD1, theS2, theD2, TolArc, TolTang,
941 ListOfPnts, typs1, typs2, theIsReqToKeepRLine);
945 ParamParamPerfom(theS1, theD1, theS2, theD2,
946 TolArc, TolTang, ListOfPnts, typs1, typs2);
953 GeomParamPerfom(theS1, theD1, theS2, theD2, ts1 == 0, typs1, typs2);
957 if(ts1 == ts2 && ts1 == 0)
959 IntSurf_ListOfPntOn2S ListOfPnts;
962 ParamParamPerfom(theS1, theD1, theS2, theD2, TolArc,
963 TolTang, ListOfPnts, typs1, typs2);
966 if(!theIsReqToPostWLProc)
969 for(Standard_Integer i = slin.Lower(); i <= slin.Upper(); i++)
971 Handle(IntPatch_WLine) aWL = Handle(IntPatch_WLine)::DownCast(slin.Value(i));
976 if (!aWL->IsPurgingAllowed())
979 Handle(IntPatch_WLine) aRW =
980 IntPatch_WLineTool::ComputePurgedWLine(aWL, theS1, theS2, theD1, theD2);
985 slin.InsertAfter(i, aRW);
990 //=======================================================================
993 //=======================================================================
994 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& theS1,
995 const Handle(Adaptor3d_TopolTool)& theD1,
996 const Handle(Adaptor3d_HSurface)& theS2,
997 const Handle(Adaptor3d_TopolTool)& theD2,
998 const Standard_Real TolArc,
999 const Standard_Real TolTang,
1000 IntSurf_ListOfPntOn2S& ListOfPnts,
1001 const Standard_Boolean isGeomInt,
1002 const Standard_Boolean theIsReqToKeepRLine,
1003 const Standard_Boolean theIsReqToPostWLProc)
1006 myTolTang = TolTang;
1007 if(myFleche <= Precision::PConfusion())
1009 if(myUVMaxStep <= Precision::PConfusion())
1012 done = Standard_False;
1015 empt = Standard_True;
1016 tgte = Standard_False;
1017 oppo = Standard_False;
1019 GeomAbs_SurfaceType typs1 = theS1->GetType();
1020 GeomAbs_SurfaceType typs2 = theS2->GetType();
1022 //treatment of the cases with cone or torus
1023 Standard_Boolean TreatAsBiParametric = Standard_False;
1024 Standard_Integer bGeomGeom = 0;
1026 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone ||
1027 typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
1028 gp_Ax1 aCTAx, aGeomAx;
1029 GeomAbs_SurfaceType aCTType;
1030 Standard_Boolean bToCheck;
1032 const Handle(Adaptor3d_HSurface)& aCTSurf =
1033 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS1 : theS2;
1034 const Handle(Adaptor3d_HSurface)& aGeomSurf =
1035 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS2 : theS1;
1037 aCTType = aCTSurf->GetType();
1038 bToCheck = Standard_False;
1040 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone) {
1041 const gp_Cone aCon1 = (aCTType == GeomAbs_Cone) ?
1042 aCTSurf->Cone() : aGeomSurf->Cone();
1043 Standard_Real a1 = Abs(aCon1.SemiAngle());
1044 bToCheck = (a1 < 0.02) || (a1 > 1.55);
1046 if (typs1 == typs2) {
1047 const gp_Cone aCon2 = aGeomSurf->Cone();
1048 Standard_Real a2 = Abs(aCon2.SemiAngle());
1049 bToCheck = bToCheck || (a2 < 0.02) || (a2 > 1.55);
1051 if (a1 > 1.55 && a2 > 1.55) {//quasi-planes: if same domain, treat as canonic
1052 const gp_Ax1 A1 = aCon1.Axis(), A2 = aCon2.Axis();
1053 if (A1.IsParallel(A2,Precision::Angular())) {
1054 const gp_Pnt Apex1 = aCon1.Apex(), Apex2 = aCon2.Apex();
1055 const gp_Pln Plan1( Apex1, A1.Direction() );
1056 if (Plan1.Distance( Apex2 ) <= Precision::Confusion()) {
1057 bToCheck = Standard_False;
1063 TreatAsBiParametric = bToCheck;
1064 if (aCTType == GeomAbs_Cone) {
1065 aCTAx = aCon1.Axis();
1069 if (typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
1070 const gp_Torus aTor1 = (aCTType == GeomAbs_Torus) ?
1071 aCTSurf->Torus() : aGeomSurf->Torus();
1072 bToCheck = aTor1.MajorRadius() > aTor1.MinorRadius();
1073 if (typs1 == typs2) {
1074 const gp_Torus aTor2 = aGeomSurf->Torus();
1075 bToCheck = (bToCheck && (aTor2.MajorRadius() > aTor2.MinorRadius())) ||
1076 (Abs(aTor1.MajorRadius() - aTor2.MajorRadius()) < TolTang &&
1077 Abs(aTor1.MinorRadius() - aTor2.MinorRadius()) < TolTang);
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, typs1, typs2);
1190 GeomParamPerfom(theS1, theD1, theS2, theD2, ts1 == 0, typs1, typs2);
1194 ParamParamPerfom(theS1, theD1, theS2, theD2,
1195 TolArc, TolTang, ListOfPnts, typs1, typs2);
1199 GeomGeomPerfom(theS1, theD1, theS2, theD2, TolArc, TolTang,
1200 ListOfPnts, 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);
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 GeomAbs_SurfaceType typs1,
1239 const GeomAbs_SurfaceType typs2)
1241 IntPatch_PrmPrmIntersection interpp;
1242 if(!theD1->DomainIsInfinite() && !theD2->DomainIsInfinite())
1244 Standard_Boolean ClearFlag = Standard_True;
1245 if(!ListOfPnts.IsEmpty())
1247 interpp.Perform(theS1,theD1,theS2,theD2,TolTang,TolArc,myFleche,myUVMaxStep, ListOfPnts);
1248 ClearFlag = Standard_False;
1250 interpp.Perform(theS1,theD1,theS2,theD2,TolTang,TolArc,myFleche,myUVMaxStep,ClearFlag);
1252 else if((theD1->DomainIsInfinite()) ^ (theD2->DomainIsInfinite()))
1254 gp_Pnt pMaxXYZ, pMinXYZ;
1255 if(theD1->DomainIsInfinite())
1257 FUN_GetMinMaxXYZPnt( theS2, pMinXYZ, pMaxXYZ );
1258 const Standard_Real MU = Max(Abs(theS2->FirstUParameter()),Abs(theS2->LastUParameter()));
1259 const Standard_Real MV = Max(Abs(theS2->FirstVParameter()),Abs(theS2->LastVParameter()));
1260 const Standard_Real AP = Max(MU, MV);
1261 Handle(Adaptor3d_HSurface) SS;
1262 FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, theS1, AP, SS);
1263 interpp.Perform(SS,theD1,theS2,theD2,TolTang,TolArc,myFleche,myUVMaxStep);
1267 FUN_GetMinMaxXYZPnt( theS1, pMinXYZ, pMaxXYZ );
1268 const Standard_Real MU = Max(Abs(theS1->FirstUParameter()),Abs(theS1->LastUParameter()));
1269 const Standard_Real MV = Max(Abs(theS1->FirstVParameter()),Abs(theS1->LastVParameter()));
1270 const Standard_Real AP = Max(MU, MV);
1271 Handle(Adaptor3d_HSurface) SS;
1272 FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, theS2, AP, SS);
1273 interpp.Perform(theS1, theD1, SS, theD2,TolTang, TolArc,myFleche,myUVMaxStep);
1275 }//(theD1->DomainIsInfinite()) ^ (theD2->DomainIsInfinite())
1278 if(typs1 == GeomAbs_OtherSurface || typs2 == GeomAbs_OtherSurface)
1280 done = Standard_False;
1284 Standard_Boolean IsPLInt = Standard_False;
1285 TColgp_SequenceOfPnt sop;
1287 FUN_PL_Intersection(theS1,typs1,theS2,typs2,IsPLInt,sop,v);
1291 if(sop.Length() > 0)
1293 for(Standard_Integer ip = 1; ip <= sop.Length(); ip++)
1295 gp_Lin lin(sop.Value(ip),gp_Dir(v));
1296 Handle(IntPatch_Line) gl = new IntPatch_GLine(lin,Standard_False);
1300 done = Standard_True;
1303 done = Standard_False;
1306 }// 'COLLINEAR LINES'
1309 Handle(Adaptor3d_HSurface) nS1 = theS1;
1310 Handle(Adaptor3d_HSurface) nS2 = theS2;
1311 FUN_TrimBothSurf(theS1,typs1,theS2,typs2,1.e+8,nS1,nS2);
1312 interpp.Perform(nS1,theD1,nS2,theD2,TolTang,TolArc,myFleche,myUVMaxStep);
1313 }// 'NON - COLLINEAR LINES'
1314 }// both domains are infinite
1316 if (interpp.IsDone())
1318 done = Standard_True;
1319 tgte = Standard_False;
1320 empt = interpp.IsEmpty();
1322 for(Standard_Integer i = 1; i <= interpp.NbLines(); i++)
1324 if(interpp.Line(i)->ArcType() != IntPatch_Walking)
1325 slin.Append(interpp.Line(i));
1328 for (Standard_Integer i = 1; i <= interpp.NbLines(); i++)
1330 if(interpp.Line(i)->ArcType() == IntPatch_Walking)
1331 slin.Append(interpp.Line(i));
1336 //=======================================================================
1337 ////function : GeomGeomPerfom
1339 //=======================================================================
1340 void IntPatch_Intersection::GeomGeomPerfom(const Handle(Adaptor3d_HSurface)& theS1,
1341 const Handle(Adaptor3d_TopolTool)& theD1,
1342 const Handle(Adaptor3d_HSurface)& theS2,
1343 const Handle(Adaptor3d_TopolTool)& theD2,
1344 const Standard_Real TolArc,
1345 const Standard_Real TolTang,
1346 IntSurf_ListOfPntOn2S& ListOfPnts,
1347 const GeomAbs_SurfaceType theTyps1,
1348 const GeomAbs_SurfaceType theTyps2,
1349 const Standard_Boolean theIsReqToKeepRLine)
1351 IntPatch_ImpImpIntersection interii(theS1,theD1,theS2,theD2,
1352 myTolArc,myTolTang, theIsReqToKeepRLine);
1354 if (!interii.IsDone())
1356 done = Standard_False;
1357 ParamParamPerfom(theS1, theD1, theS2, theD2,
1358 TolArc, TolTang, ListOfPnts, theTyps1, theTyps2);
1362 done = (interii.GetStatus() == IntPatch_ImpImpIntersection::IntStatus_OK);
1363 empt = interii.IsEmpty();
1370 const Standard_Integer aNbPointsInALine = 200;
1372 tgte = interii.TangentFaces();
1374 oppo = interii.OppositeFaces();
1376 Standard_Boolean isWLExist = Standard_False;
1377 IntPatch_ALineToWLine AToW(theS1, theS2, aNbPointsInALine);
1379 for (Standard_Integer i = 1; i <= interii.NbLines(); i++)
1381 const Handle(IntPatch_Line)& line = interii.Line(i);
1382 if (line->ArcType() == IntPatch_Analytic)
1384 isWLExist = Standard_True;
1385 AToW.MakeWLine(Handle(IntPatch_ALine)::DownCast(line), slin);
1389 if (line->ArcType() == IntPatch_Walking)
1391 Handle(IntPatch_WLine)::DownCast(line)->EnablePurging(Standard_False);
1394 if((line->ArcType() != IntPatch_Restriction) || theIsReqToKeepRLine)
1399 for (Standard_Integer i = 1; i <= interii.NbPnts(); i++)
1401 spnt.Append(interii.Point(i));
1404 if((theTyps1 == GeomAbs_Cylinder) && (theTyps2 == GeomAbs_Cylinder))
1406 IntPatch_WLineTool::JoinWLines(slin, spnt, theS1, theS2, TolTang);
1411 Bnd_Box2d aBx1, aBx2;
1412 const Standard_Real aU1F = theS1->FirstUParameter(),
1413 aU1L = theS1->LastUParameter(),
1414 aV1F = theS1->FirstVParameter(),
1415 aV1L = theS1->LastVParameter(),
1416 aU2F = theS2->FirstUParameter(),
1417 aU2L = theS2->LastUParameter(),
1418 aV2F = theS2->FirstVParameter(),
1419 aV2L = theS2->LastVParameter();
1420 aBx1.Add(gp_Pnt2d(aU1F, aV1F));
1421 aBx1.Add(gp_Pnt2d(aU1L, aV1F));
1422 aBx1.Add(gp_Pnt2d(aU1L, aV1L));
1423 aBx1.Add(gp_Pnt2d(aU1F, aV1L));
1424 aBx2.Add(gp_Pnt2d(aU2F, aV2F));
1425 aBx2.Add(gp_Pnt2d(aU2L, aV2F));
1426 aBx2.Add(gp_Pnt2d(aU2L, aV2L));
1427 aBx2.Add(gp_Pnt2d(aU2F, aV2L));
1429 aBx1.Enlarge(Precision::PConfusion());
1430 aBx2.Enlarge(Precision::PConfusion());
1433 anArrOfPeriod[4] = {theS1->IsUPeriodic()? theS1->UPeriod() : 0.0,
1434 theS1->IsVPeriodic()? theS1->VPeriod() : 0.0,
1435 theS2->IsUPeriodic()? theS2->UPeriod() : 0.0,
1436 theS2->IsVPeriodic()? theS2->VPeriod() : 0.0};
1438 NCollection_List<gp_Pnt> aListOfCriticalPoints;
1440 if (theS1->GetType() == GeomAbs_Cone)
1442 aListOfCriticalPoints.Append(theS1->Cone().Apex());
1444 else if (theS1->GetType() == GeomAbs_Sphere)
1446 aListOfCriticalPoints.Append(theS1->Value(0.0, M_PI_2));
1447 aListOfCriticalPoints.Append(theS1->Value(0.0, -M_PI_2));
1450 if (theS2->GetType() == GeomAbs_Cone)
1452 aListOfCriticalPoints.Append(theS2->Cone().Apex());
1454 else if (theS2->GetType() == GeomAbs_Sphere)
1456 aListOfCriticalPoints.Append(theS2->Value(0.0, M_PI_2));
1457 aListOfCriticalPoints.Append(theS2->Value(0.0, -M_PI_2));
1460 IntPatch_WLineTool::ExtendTwoWLines(slin, theS1, theS2, TolTang,
1461 anArrOfPeriod, aBx1, aBx2,
1462 aListOfCriticalPoints);
1466 //=======================================================================
1467 //function : GeomParamPerfom
1469 //=======================================================================
1470 void IntPatch_Intersection::
1471 GeomParamPerfom(const Handle(Adaptor3d_HSurface)& theS1,
1472 const Handle(Adaptor3d_TopolTool)& theD1,
1473 const Handle(Adaptor3d_HSurface)& theS2,
1474 const Handle(Adaptor3d_TopolTool)& theD2,
1475 const Standard_Boolean isNotAnalitical,
1476 const GeomAbs_SurfaceType typs1,
1477 const GeomAbs_SurfaceType typs2)
1479 IntPatch_ImpPrmIntersection interip;
1482 if (isNotAnalitical/*ts1 == 0*/)
1483 interip.SetStartPoint(myU1Start,myV1Start);
1485 interip.SetStartPoint(myU2Start,myV2Start);
1488 if(theD1->DomainIsInfinite() && theD2->DomainIsInfinite())
1490 Standard_Boolean IsPLInt = Standard_False;
1491 TColgp_SequenceOfPnt sop;
1493 FUN_PL_Intersection(theS1,typs1,theS2,typs2,IsPLInt,sop,v);
1497 if(sop.Length() > 0)
1499 for(Standard_Integer ip = 1; ip <= sop.Length(); ip++)
1501 gp_Lin lin(sop.Value(ip),gp_Dir(v));
1502 Handle(IntPatch_Line) gl = new IntPatch_GLine(lin,Standard_False);
1506 done = Standard_True;
1509 done = Standard_False;
1515 Handle(Adaptor3d_HSurface) nS1 = theS1;
1516 Handle(Adaptor3d_HSurface) nS2 = theS2;
1517 FUN_TrimBothSurf(theS1,typs1,theS2,typs2,1.e+5,nS1,nS2);
1518 interip.Perform(nS1,theD1,nS2,theD2,myTolArc,myTolTang,myFleche,myUVMaxStep);
1522 interip.Perform(theS1,theD1,theS2,theD2,myTolArc,myTolTang,myFleche,myUVMaxStep);
1524 if (interip.IsDone())
1526 done = Standard_True;
1527 empt = interip.IsEmpty();
1531 const Standard_Integer aNbLines = interip.NbLines();
1532 for(Standard_Integer i = 1; i <= aNbLines; i++)
1534 if(interip.Line(i)->ArcType() != IntPatch_Walking)
1535 slin.Append(interip.Line(i));
1538 for(Standard_Integer i = 1; i <= aNbLines; i++)
1540 if(interip.Line(i)->ArcType() == IntPatch_Walking)
1541 slin.Append(interip.Line(i));
1544 for (Standard_Integer i = 1; i <= interip.NbPnts(); i++)
1545 spnt.Append(interip.Point(i));
1550 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& S1,
1551 const Handle(Adaptor3d_TopolTool)& D1,
1552 const Handle(Adaptor3d_HSurface)& S2,
1553 const Handle(Adaptor3d_TopolTool)& D2,
1554 const Standard_Real U1,
1555 const Standard_Real V1,
1556 const Standard_Real U2,
1557 const Standard_Real V2,
1558 const Standard_Real TolArc,
1559 const Standard_Real TolTang)
1562 myTolTang = TolTang;
1563 if(myFleche == 0.0) {
1565 //cout<<" -- IntPatch_Intersection::myFleche fixe par defaut a 0.01 --"<<endl;
1566 //cout<<" -- Utiliser la Methode SetTolerances( ... ) "<<endl;
1570 if(myUVMaxStep==0.0) {
1572 //cout<<" -- IntPatch_Intersection::myUVMaxStep fixe par defaut a 0.01 --"<<endl;
1573 //cout<<" -- Utiliser la Methode SetTolerances( ... ) "<<endl;
1578 done = Standard_False;
1582 empt = Standard_True;
1583 tgte = Standard_False;
1584 oppo = Standard_False;
1586 const GeomAbs_SurfaceType typs1 = S1->GetType();
1587 const GeomAbs_SurfaceType typs2 = S2->GetType();
1589 if( typs1==GeomAbs_Plane
1590 || typs1==GeomAbs_Cylinder
1591 || typs1==GeomAbs_Sphere
1592 || typs1==GeomAbs_Cone
1593 || typs2==GeomAbs_Plane
1594 || typs2==GeomAbs_Cylinder
1595 || typs2==GeomAbs_Sphere
1596 || typs2==GeomAbs_Cone)
1598 myIsStartPnt = Standard_True;
1599 myU1Start = U1; myV1Start = V1; myU2Start = U2; myV2Start = V2;
1600 Perform(S1,D1,S2,D2,TolArc,TolTang);
1601 myIsStartPnt = Standard_False;
1605 IntPatch_PrmPrmIntersection interpp;
1606 interpp.Perform(S1,D1,S2,D2,U1,V1,U2,V2,TolTang,TolArc,myFleche,myUVMaxStep);
1607 if (interpp.IsDone())
1609 done = Standard_True;
1610 tgte = Standard_False;
1611 empt = interpp.IsEmpty();
1612 const Standard_Integer nblm = interpp.NbLines();
1613 Standard_Integer i = 1;
1614 for (; i<=nblm; i++) slin.Append(interpp.Line(i));
1618 for(Standard_Integer i = slin.Lower(); i <= slin.Upper(); i++)
1620 Handle(IntPatch_WLine) aWL = Handle(IntPatch_WLine)::DownCast(slin.Value(i));
1625 if (!aWL->IsPurgingAllowed())
1628 Handle(IntPatch_WLine) aRW =
1629 IntPatch_WLineTool::ComputePurgedWLine(aWL, S1, S2, D1, D2);
1634 slin.InsertAfter(i, aRW);
1639 #ifdef DUMPOFIntPatch_Intersection
1641 void IntPatch_Intersection__MAJ_R(Handle(Adaptor2d_HCurve2d) *R1,
1642 Handle(Adaptor2d_HCurve2d) *,
1645 Standard_Integer nbR1,
1647 const IntPatch_Point& VTX)
1650 if(VTX.IsOnDomS1()) {
1652 //-- long unsigned ptr= *((long unsigned *)(((Handle(Standard_Transient) *)(&(VTX.ArcOnS1())))));
1653 for(Standard_Integer i=0; i<nbR1;i++) {
1654 if(VTX.ArcOnS1()==R1[i]) {
1656 printf("\n ******************************");
1660 printf("\n R Pas trouvee (IntPatch)\n");
1666 void IntPatch_Intersection::Dump(const Standard_Integer /*Mode*/,
1667 const Handle(Adaptor3d_HSurface)& /*S1*/,
1668 const Handle(Adaptor3d_TopolTool)& /*D1*/,
1669 const Handle(Adaptor3d_HSurface)& /*S2*/,
1670 const Handle(Adaptor3d_TopolTool)& /*D2*/) const
1672 #ifdef DUMPOFIntPatch_Intersection
1673 const int MAXR = 200;
1674 //-- ----------------------------------------------------------------------
1675 //-- construction de la liste des restrictions & vertex
1677 int NR1[MAXR],NR2[MAXR];
1678 Handle(Adaptor2d_HCurve2d) R1[MAXR],R2[MAXR];
1679 Standard_Integer nbR1=0,nbR2=0;
1680 for(D1->Init();D1->More() && nbR1<MAXR; D1->Next()) {
1681 R1[nbR1]=D1->Value();
1685 for(D2->Init();D2->More() && nbR2<MAXR; D2->Next()) {
1686 R2[nbR2]=D2->Value();
1691 printf("\nDUMP_INT: ----empt:%2ud tgte:%2ud oppo:%2ud ---------------------------------",empt,tgte,empt);
1692 Standard_Integer i,nbr1,nbr2,nbgl,nbgc,nbge,nbgp,nbgh,nbl,nbr,nbg,nbw,nba;
1693 nbl=nbr=nbg=nbw=nba=nbgl=nbge=nbr1=nbr2=nbgc=nbgp=nbgh=0;
1695 for(i=1;i<=nbl;i++) {
1696 const Handle(IntPatch_Line)& line=Line(i);
1697 const IntPatch_IType IType=line->ArcType();
1698 if(IType == IntPatch_Walking) nbw++;
1699 else if(IType == IntPatch_Restriction) {
1701 Handle(IntPatch_RLine) rlin (Handle(IntPatch_RLine)::DownCast (line));
1702 if(rlin->IsArcOnS1()) nbr1++;
1703 if(rlin->IsArcOnS2()) nbr2++;
1705 else if(IType == IntPatch_Analytic) nba++;
1708 if(IType == IntPatch_Lin) nbgl++;
1709 else if(IType == IntPatch_Circle) nbgc++;
1710 else if(IType == IntPatch_Parabola) nbgp++;
1711 else if(IType == IntPatch_Hyperbola) nbgh++;
1712 else if(IType == IntPatch_Ellipse) nbge++;
1717 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)",
1718 nbl,nbw,nbr,nbr1,nbr2,nba,nbg,nbgl,nbgc,nbge,nbgh,nbgp);
1720 IntPatch_LineConstructor LineConstructor(2);
1722 Standard_Integer nbllc=0;
1724 Standard_Integer nbva,nbvw,nbvr,nbvg;
1725 nbva=nbvr=nbvw=nbvg=0;
1726 for (j=1; j<=nbl; j++) {
1727 Standard_Integer v,nbvtx;
1728 const Handle(IntPatch_Line)& intersLinej = Line(j);
1729 Standard_Integer NbLines;
1730 LineConstructor.Perform(SequenceOfLine(),intersLinej,S1,D1,S2,D2,1e-7);
1731 NbLines = LineConstructor.NbLines();
1733 for(Standard_Integer k=1;k<=NbLines;k++) {
1735 const Handle(IntPatch_Line)& LineK = LineConstructor.Line(k);
1736 if (LineK->ArcType() == IntPatch_Analytic) {
1737 Handle(IntPatch_ALine) alin (Handle(IntPatch_ALine)::DownCast (LineK));
1738 nbvtx=alin->NbVertex();
1740 for(v=1;v<=nbvtx;v++) {
1741 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,alin->Vertex(v));
1744 else if (LineK->ArcType() == IntPatch_Restriction) {
1745 Handle(IntPatch_RLine) rlin (Handle(IntPatch_RLine)::DownCast (LineK));
1746 nbvtx=rlin->NbVertex();
1748 for(v=1;v<=nbvtx;v++) {
1749 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,rlin->Vertex(v));
1752 else if (LineK->ArcType() == IntPatch_Walking) {
1753 Handle(IntPatch_WLine) wlin (Handle(IntPatch_WLine)::DownCast (LineK));
1754 nbvtx=wlin->NbVertex();
1756 for(v=1;v<=nbvtx;v++) {
1757 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,wlin->Vertex(v));
1761 Handle(IntPatch_GLine) glin (Handle(IntPatch_GLine)::DownCast (LineK));
1762 nbvtx=glin->NbVertex();
1764 for(v=1;v<=nbvtx;v++) {
1765 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,glin->Vertex(v));
1770 printf("\nDUMP_LC :Lines:%2d WLin:%2d Restr:%2d Ana:%2d Geom:%2d",
1771 nbllc,nbw,nbr,nba,nbg);
1772 printf("\nDUMP_LC :vtx :%2d r:%2d :%2d :%2d",
1773 nbvw,nbvr,nbva,nbvg);