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 const Standard_Boolean RestrictLine = Standard_True;
935 if(ts1 == ts2 && ts1 == 1)
937 IntSurf_ListOfPntOn2S ListOfPnts;
941 GeomGeomPerfom( theS1, theD1, theS2, theD2, TolArc,
942 TolTang, ListOfPnts, RestrictLine,
943 typs1, typs2, theIsReqToKeepRLine);
947 ParamParamPerfom(theS1, theD1, theS2, theD2,
948 TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
955 GeomParamPerfom(theS1, theD1, theS2, theD2, ts1 == 0, typs1, typs2);
959 if(ts1 == ts2 && ts1 == 0)
961 IntSurf_ListOfPntOn2S ListOfPnts;
964 ParamParamPerfom(theS1, theD1, theS2, theD2, TolArc,
965 TolTang, ListOfPnts, RestrictLine, typs1, typs2);
968 if(!theIsReqToPostWLProc)
971 for(Standard_Integer i = slin.Lower(); i <= slin.Upper(); i++)
973 Handle(IntPatch_WLine) aWL = Handle(IntPatch_WLine)::DownCast(slin.Value(i));
978 if (!aWL->IsPurgingAllowed())
981 Handle(IntPatch_WLine) aRW =
982 IntPatch_WLineTool::ComputePurgedWLine(aWL, theS1, theS2, theD1, theD2, RestrictLine);
987 slin.InsertAfter(i, aRW);
992 //=======================================================================
995 //=======================================================================
996 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& theS1,
997 const Handle(Adaptor3d_TopolTool)& theD1,
998 const Handle(Adaptor3d_HSurface)& theS2,
999 const Handle(Adaptor3d_TopolTool)& theD2,
1000 const Standard_Real TolArc,
1001 const Standard_Real TolTang,
1002 IntSurf_ListOfPntOn2S& ListOfPnts,
1003 const Standard_Boolean RestrictLine,
1004 const Standard_Boolean isGeomInt,
1005 const Standard_Boolean theIsReqToKeepRLine,
1006 const Standard_Boolean theIsReqToPostWLProc)
1009 myTolTang = TolTang;
1010 if(myFleche <= Precision::PConfusion())
1012 if(myUVMaxStep <= Precision::PConfusion())
1015 done = Standard_False;
1018 empt = Standard_True;
1019 tgte = Standard_False;
1020 oppo = Standard_False;
1022 GeomAbs_SurfaceType typs1 = theS1->GetType();
1023 GeomAbs_SurfaceType typs2 = theS2->GetType();
1025 //treatment of the cases with cone or torus
1026 Standard_Boolean TreatAsBiParametric = Standard_False;
1027 Standard_Integer bGeomGeom = 0;
1029 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone ||
1030 typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
1031 gp_Ax1 aCTAx, aGeomAx;
1032 GeomAbs_SurfaceType aCTType;
1033 Standard_Boolean bToCheck;
1035 const Handle(Adaptor3d_HSurface)& aCTSurf =
1036 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS1 : theS2;
1037 const Handle(Adaptor3d_HSurface)& aGeomSurf =
1038 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS2 : theS1;
1040 aCTType = aCTSurf->GetType();
1041 bToCheck = Standard_False;
1043 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone) {
1044 const gp_Cone aCon1 = (aCTType == GeomAbs_Cone) ?
1045 aCTSurf->Cone() : aGeomSurf->Cone();
1046 Standard_Real a1 = Abs(aCon1.SemiAngle());
1047 bToCheck = (a1 < 0.02) || (a1 > 1.55);
1049 if (typs1 == typs2) {
1050 const gp_Cone aCon2 = aGeomSurf->Cone();
1051 Standard_Real a2 = Abs(aCon2.SemiAngle());
1052 bToCheck = bToCheck || (a2 < 0.02) || (a2 > 1.55);
1054 if (a1 > 1.55 && a2 > 1.55) {//quasi-planes: if same domain, treat as canonic
1055 const gp_Ax1 A1 = aCon1.Axis(), A2 = aCon2.Axis();
1056 if (A1.IsParallel(A2,Precision::Angular())) {
1057 const gp_Pnt Apex1 = aCon1.Apex(), Apex2 = aCon2.Apex();
1058 const gp_Pln Plan1( Apex1, A1.Direction() );
1059 if (Plan1.Distance( Apex2 ) <= Precision::Confusion()) {
1060 bToCheck = Standard_False;
1066 TreatAsBiParametric = bToCheck;
1067 if (aCTType == GeomAbs_Cone) {
1068 aCTAx = aCon1.Axis();
1072 if (typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
1073 const gp_Torus aTor1 = (aCTType == GeomAbs_Torus) ?
1074 aCTSurf->Torus() : aGeomSurf->Torus();
1075 bToCheck = aTor1.MajorRadius() > aTor1.MinorRadius();
1076 if (typs1 == typs2) {
1077 const gp_Torus aTor2 = aGeomSurf->Torus();
1078 bToCheck = aTor2.MajorRadius() > aTor2.MinorRadius();
1081 if (aCTType == GeomAbs_Torus) {
1082 aCTAx = aTor1.Axis();
1087 const gp_Lin aL1(aCTAx);
1089 switch (aGeomSurf->GetType()) {
1090 case GeomAbs_Plane: {
1091 aGeomAx = aGeomSurf->Plane().Axis();
1092 if (aCTType == GeomAbs_Cone) {
1094 if (Abs(aCTSurf->Cone().SemiAngle()) < 0.02) {
1095 Standard_Real ps = Abs(aCTAx.Direction().Dot(aGeomAx.Direction()));
1102 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) ||
1103 (aCTAx.IsNormal(aGeomAx, Precision::Angular()) &&
1104 (aGeomSurf->Plane().Distance(aCTAx.Location()) < Precision::Confusion()))) {
1108 bToCheck = Standard_False;
1111 case GeomAbs_Sphere: {
1112 if (aL1.Distance(aGeomSurf->Sphere().Location()) < Precision::Confusion()) {
1115 bToCheck = Standard_False;
1118 case GeomAbs_Cylinder:
1119 aGeomAx = aGeomSurf->Cylinder().Axis();
1122 aGeomAx = aGeomSurf->Cone().Axis();
1125 aGeomAx = aGeomSurf->Torus().Axis();
1128 bToCheck = Standard_False;
1133 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) &&
1134 (aL1.Distance(aGeomAx.Location()) <= Precision::Confusion())) {
1139 if (bGeomGeom == 1) {
1140 TreatAsBiParametric = Standard_False;
1146 if(theD1->DomainIsInfinite() || theD2->DomainIsInfinite()) {
1147 TreatAsBiParametric= Standard_False;
1150 if(TreatAsBiParametric)
1152 // Using Prm-Prm Intersector
1153 typs1 = GeomAbs_BezierSurface;
1154 typs2 = GeomAbs_BezierSurface;
1157 // Surface type definition
1158 Standard_Integer ts1 = 0;
1162 case GeomAbs_Cylinder:
1163 case GeomAbs_Sphere:
1164 case GeomAbs_Cone: ts1 = 1; break;
1165 case GeomAbs_Torus: ts1 = bGeomGeom; break;
1169 Standard_Integer ts2 = 0;
1173 case GeomAbs_Cylinder:
1174 case GeomAbs_Sphere:
1175 case GeomAbs_Cone: ts2 = 1; break;
1176 case GeomAbs_Torus: ts2 = bGeomGeom; break;
1180 // Possible intersection types: 1. ts1 == ts2 == 1 <Geom-Geom>
1181 // 2. ts1 != ts2 <Geom-Param>
1182 // 3. ts1 == ts2 == 0 <Param-Param>
1186 ParamParamPerfom(theS1, theD1, theS2, theD2,
1187 TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
1191 GeomParamPerfom(theS1, theD1, theS2, theD2, ts1 == 0, typs1, typs2);
1195 ParamParamPerfom(theS1, theD1, theS2, theD2,
1196 TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
1200 GeomGeomPerfom(theS1, theD1, theS2, theD2, TolArc,
1201 TolTang, ListOfPnts, RestrictLine, typs1, typs2, theIsReqToKeepRLine);
1204 if(!theIsReqToPostWLProc)
1207 for(Standard_Integer i = slin.Lower(); i <= slin.Upper(); i++)
1209 Handle(IntPatch_WLine) aWL = Handle(IntPatch_WLine)::DownCast(slin.Value(i));
1214 if(!aWL->IsPurgingAllowed())
1217 Handle(IntPatch_WLine) aRW =
1218 IntPatch_WLineTool::ComputePurgedWLine(aWL, theS1, theS2, theD1, theD2, RestrictLine);
1223 slin.InsertAfter(i, aRW);
1228 //=======================================================================
1229 //function : ParamParamPerfom
1231 //=======================================================================
1232 void IntPatch_Intersection::ParamParamPerfom(const Handle(Adaptor3d_HSurface)& theS1,
1233 const Handle(Adaptor3d_TopolTool)& theD1,
1234 const Handle(Adaptor3d_HSurface)& theS2,
1235 const Handle(Adaptor3d_TopolTool)& theD2,
1236 const Standard_Real TolArc,
1237 const Standard_Real TolTang,
1238 IntSurf_ListOfPntOn2S& ListOfPnts,
1239 const Standard_Boolean RestrictLine,
1240 const GeomAbs_SurfaceType typs1,
1241 const GeomAbs_SurfaceType typs2)
1243 IntPatch_PrmPrmIntersection interpp;
1244 if(!theD1->DomainIsInfinite() && !theD2->DomainIsInfinite())
1246 Standard_Boolean ClearFlag = Standard_True;
1247 if(!ListOfPnts.IsEmpty())
1249 interpp.Perform(theS1,theD1,theS2,theD2,TolTang,TolArc,myFleche,myUVMaxStep, ListOfPnts, RestrictLine);
1250 ClearFlag = Standard_False;
1252 interpp.Perform(theS1,theD1,theS2,theD2,TolTang,TolArc,myFleche,myUVMaxStep,ClearFlag); //double call!!!!!!!
1254 else if((theD1->DomainIsInfinite()) ^ (theD2->DomainIsInfinite()))
1256 gp_Pnt pMaxXYZ, pMinXYZ;
1257 if(theD1->DomainIsInfinite())
1259 FUN_GetMinMaxXYZPnt( theS2, pMinXYZ, pMaxXYZ );
1260 const Standard_Real MU = Max(Abs(theS2->FirstUParameter()),Abs(theS2->LastUParameter()));
1261 const Standard_Real MV = Max(Abs(theS2->FirstVParameter()),Abs(theS2->LastVParameter()));
1262 const Standard_Real AP = Max(MU, MV);
1263 Handle(Adaptor3d_HSurface) SS;
1264 FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, theS1, AP, SS);
1265 interpp.Perform(SS,theD1,theS2,theD2,TolTang,TolArc,myFleche,myUVMaxStep);
1269 FUN_GetMinMaxXYZPnt( theS1, pMinXYZ, pMaxXYZ );
1270 const Standard_Real MU = Max(Abs(theS1->FirstUParameter()),Abs(theS1->LastUParameter()));
1271 const Standard_Real MV = Max(Abs(theS1->FirstVParameter()),Abs(theS1->LastVParameter()));
1272 const Standard_Real AP = Max(MU, MV);
1273 Handle(Adaptor3d_HSurface) SS;
1274 FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, theS2, AP, SS);
1275 interpp.Perform(theS1, theD1, SS, theD2,TolTang, TolArc,myFleche,myUVMaxStep);
1277 }//(theD1->DomainIsInfinite()) ^ (theD2->DomainIsInfinite())
1280 if(typs1 == GeomAbs_OtherSurface || typs2 == GeomAbs_OtherSurface)
1282 done = Standard_False;
1286 Standard_Boolean IsPLInt = Standard_False;
1287 TColgp_SequenceOfPnt sop;
1289 FUN_PL_Intersection(theS1,typs1,theS2,typs2,IsPLInt,sop,v);
1293 if(sop.Length() > 0)
1295 for(Standard_Integer ip = 1; ip <= sop.Length(); ip++)
1297 gp_Lin lin(sop.Value(ip),gp_Dir(v));
1298 Handle(IntPatch_Line) gl = new IntPatch_GLine(lin,Standard_False);
1302 done = Standard_True;
1305 done = Standard_False;
1308 }// 'COLLINEAR LINES'
1311 Handle(Adaptor3d_HSurface) nS1 = theS1;
1312 Handle(Adaptor3d_HSurface) nS2 = theS2;
1313 FUN_TrimBothSurf(theS1,typs1,theS2,typs2,1.e+8,nS1,nS2);
1314 interpp.Perform(nS1,theD1,nS2,theD2,TolTang,TolArc,myFleche,myUVMaxStep);
1315 }// 'NON - COLLINEAR LINES'
1316 }// both domains are infinite
1318 if (interpp.IsDone())
1320 done = Standard_True;
1321 tgte = Standard_False;
1322 empt = interpp.IsEmpty();
1324 for(Standard_Integer i = 1; i <= interpp.NbLines(); i++)
1326 if(interpp.Line(i)->ArcType() != IntPatch_Walking)
1327 slin.Append(interpp.Line(i));
1330 for (Standard_Integer i = 1; i <= interpp.NbLines(); i++)
1332 if(interpp.Line(i)->ArcType() == IntPatch_Walking)
1333 slin.Append(interpp.Line(i));
1338 //=======================================================================
1339 ////function : GeomGeomPerfom
1341 //=======================================================================
1342 void IntPatch_Intersection::GeomGeomPerfom(const Handle(Adaptor3d_HSurface)& theS1,
1343 const Handle(Adaptor3d_TopolTool)& theD1,
1344 const Handle(Adaptor3d_HSurface)& theS2,
1345 const Handle(Adaptor3d_TopolTool)& theD2,
1346 const Standard_Real TolArc,
1347 const Standard_Real TolTang,
1348 IntSurf_ListOfPntOn2S& ListOfPnts,
1349 const Standard_Boolean RestrictLine,
1350 const GeomAbs_SurfaceType theTyps1,
1351 const GeomAbs_SurfaceType theTyps2,
1352 const Standard_Boolean theIsReqToKeepRLine)
1354 IntPatch_ImpImpIntersection interii(theS1,theD1,theS2,theD2,
1355 myTolArc,myTolTang, theIsReqToKeepRLine);
1357 if (!interii.IsDone())
1359 done = Standard_False;
1360 ParamParamPerfom(theS1, theD1, theS2, theD2,
1361 TolArc, TolTang, ListOfPnts, RestrictLine, theTyps1, theTyps2);
1365 done = (interii.GetStatus() == IntPatch_ImpImpIntersection::IntStatus_OK);
1366 empt = interii.IsEmpty();
1373 const Standard_Integer aNbPointsInALine = 200;
1375 tgte = interii.TangentFaces();
1377 oppo = interii.OppositeFaces();
1379 Standard_Boolean isWLExist = Standard_False;
1380 IntPatch_ALineToWLine AToW(theS1, theS2, aNbPointsInALine);
1382 for (Standard_Integer i = 1; i <= interii.NbLines(); i++)
1384 const Handle(IntPatch_Line)& line = interii.Line(i);
1385 if (line->ArcType() == IntPatch_Analytic)
1387 isWLExist = Standard_True;
1388 AToW.MakeWLine(Handle(IntPatch_ALine)::DownCast(line), slin);
1392 if (line->ArcType() == IntPatch_Walking)
1394 Handle(IntPatch_WLine)::DownCast(line)->EnablePurging(Standard_False);
1397 if((line->ArcType() != IntPatch_Restriction) || theIsReqToKeepRLine)
1402 for (Standard_Integer i = 1; i <= interii.NbPnts(); i++)
1404 spnt.Append(interii.Point(i));
1407 if((theTyps1 == GeomAbs_Cylinder) && (theTyps2 == GeomAbs_Cylinder))
1409 IntPatch_WLineTool::JoinWLines(slin, spnt, theS1, theS2, TolTang);
1414 Bnd_Box2d aBx1, aBx2;
1415 const Standard_Real aU1F = theS1->FirstUParameter(),
1416 aU1L = theS1->LastUParameter(),
1417 aV1F = theS1->FirstVParameter(),
1418 aV1L = theS1->LastVParameter(),
1419 aU2F = theS2->FirstUParameter(),
1420 aU2L = theS2->LastUParameter(),
1421 aV2F = theS2->FirstVParameter(),
1422 aV2L = theS2->LastVParameter();
1423 aBx1.Add(gp_Pnt2d(aU1F, aV1F));
1424 aBx1.Add(gp_Pnt2d(aU1L, aV1F));
1425 aBx1.Add(gp_Pnt2d(aU1L, aV1L));
1426 aBx1.Add(gp_Pnt2d(aU1F, aV1L));
1427 aBx2.Add(gp_Pnt2d(aU2F, aV2F));
1428 aBx2.Add(gp_Pnt2d(aU2L, aV2F));
1429 aBx2.Add(gp_Pnt2d(aU2L, aV2L));
1430 aBx2.Add(gp_Pnt2d(aU2F, aV2L));
1432 aBx1.Enlarge(Precision::PConfusion());
1433 aBx2.Enlarge(Precision::PConfusion());
1436 anArrOfPeriod[4] = {theS1->IsUPeriodic()? theS1->UPeriod() : 0.0,
1437 theS1->IsVPeriodic()? theS1->VPeriod() : 0.0,
1438 theS2->IsUPeriodic()? theS2->UPeriod() : 0.0,
1439 theS2->IsVPeriodic()? theS2->VPeriod() : 0.0};
1440 IntPatch_WLineTool::ExtendTwoWLines(slin, theS1, theS2, TolTang,
1441 anArrOfPeriod, aBx1, aBx2);
1445 //=======================================================================
1446 //function : GeomParamPerfom
1448 //=======================================================================
1449 void IntPatch_Intersection::
1450 GeomParamPerfom(const Handle(Adaptor3d_HSurface)& theS1,
1451 const Handle(Adaptor3d_TopolTool)& theD1,
1452 const Handle(Adaptor3d_HSurface)& theS2,
1453 const Handle(Adaptor3d_TopolTool)& theD2,
1454 const Standard_Boolean isNotAnalitical,
1455 const GeomAbs_SurfaceType typs1,
1456 const GeomAbs_SurfaceType typs2)
1458 IntPatch_ImpPrmIntersection interip;
1461 if (isNotAnalitical/*ts1 == 0*/)
1462 interip.SetStartPoint(myU1Start,myV1Start);
1464 interip.SetStartPoint(myU2Start,myV2Start);
1467 if(theD1->DomainIsInfinite() && theD2->DomainIsInfinite())
1469 Standard_Boolean IsPLInt = Standard_False;
1470 TColgp_SequenceOfPnt sop;
1472 FUN_PL_Intersection(theS1,typs1,theS2,typs2,IsPLInt,sop,v);
1476 if(sop.Length() > 0)
1478 for(Standard_Integer ip = 1; ip <= sop.Length(); ip++)
1480 gp_Lin lin(sop.Value(ip),gp_Dir(v));
1481 Handle(IntPatch_Line) gl = new IntPatch_GLine(lin,Standard_False);
1485 done = Standard_True;
1488 done = Standard_False;
1494 Handle(Adaptor3d_HSurface) nS1 = theS1;
1495 Handle(Adaptor3d_HSurface) nS2 = theS2;
1496 FUN_TrimBothSurf(theS1,typs1,theS2,typs2,1.e+5,nS1,nS2);
1497 interip.Perform(nS1,theD1,nS2,theD2,myTolArc,myTolTang,myFleche,myUVMaxStep);
1501 interip.Perform(theS1,theD1,theS2,theD2,myTolArc,myTolTang,myFleche,myUVMaxStep);
1503 if (interip.IsDone())
1505 done = Standard_True;
1506 empt = interip.IsEmpty();
1510 const Standard_Integer aNbLines = interip.NbLines();
1511 for(Standard_Integer i = 1; i <= aNbLines; i++)
1513 if(interip.Line(i)->ArcType() != IntPatch_Walking)
1514 slin.Append(interip.Line(i));
1517 for(Standard_Integer i = 1; i <= aNbLines; i++)
1519 if(interip.Line(i)->ArcType() == IntPatch_Walking)
1520 slin.Append(interip.Line(i));
1523 for (Standard_Integer i = 1; i <= interip.NbPnts(); i++)
1524 spnt.Append(interip.Point(i));
1529 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& S1,
1530 const Handle(Adaptor3d_TopolTool)& D1,
1531 const Handle(Adaptor3d_HSurface)& S2,
1532 const Handle(Adaptor3d_TopolTool)& D2,
1533 const Standard_Real U1,
1534 const Standard_Real V1,
1535 const Standard_Real U2,
1536 const Standard_Real V2,
1537 const Standard_Real TolArc,
1538 const Standard_Real TolTang)
1541 myTolTang = TolTang;
1542 if(myFleche == 0.0) {
1544 //cout<<" -- IntPatch_Intersection::myFleche fixe par defaut a 0.01 --"<<endl;
1545 //cout<<" -- Utiliser la Methode SetTolerances( ... ) "<<endl;
1549 if(myUVMaxStep==0.0) {
1551 //cout<<" -- IntPatch_Intersection::myUVMaxStep fixe par defaut a 0.01 --"<<endl;
1552 //cout<<" -- Utiliser la Methode SetTolerances( ... ) "<<endl;
1557 done = Standard_False;
1561 empt = Standard_True;
1562 tgte = Standard_False;
1563 oppo = Standard_False;
1565 const GeomAbs_SurfaceType typs1 = S1->GetType();
1566 const GeomAbs_SurfaceType typs2 = S2->GetType();
1568 if( typs1==GeomAbs_Plane
1569 || typs1==GeomAbs_Cylinder
1570 || typs1==GeomAbs_Sphere
1571 || typs1==GeomAbs_Cone
1572 || typs2==GeomAbs_Plane
1573 || typs2==GeomAbs_Cylinder
1574 || typs2==GeomAbs_Sphere
1575 || typs2==GeomAbs_Cone)
1577 myIsStartPnt = Standard_True;
1578 myU1Start = U1; myV1Start = V1; myU2Start = U2; myV2Start = V2;
1579 Perform(S1,D1,S2,D2,TolArc,TolTang);
1580 myIsStartPnt = Standard_False;
1584 IntPatch_PrmPrmIntersection interpp;
1585 interpp.Perform(S1,D1,S2,D2,U1,V1,U2,V2,TolTang,TolArc,myFleche,myUVMaxStep);
1586 if (interpp.IsDone())
1588 done = Standard_True;
1589 tgte = Standard_False;
1590 empt = interpp.IsEmpty();
1591 const Standard_Integer nblm = interpp.NbLines();
1592 Standard_Integer i = 1;
1593 for (; i<=nblm; i++) slin.Append(interpp.Line(i));
1597 for(Standard_Integer i = slin.Lower(); i <= slin.Upper(); i++)
1599 Handle(IntPatch_WLine) aWL = Handle(IntPatch_WLine)::DownCast(slin.Value(i));
1604 if (!aWL->IsPurgingAllowed())
1607 Handle(IntPatch_WLine) aRW =
1608 IntPatch_WLineTool::ComputePurgedWLine(aWL, S1, S2, D1, D2, Standard_True);
1613 slin.InsertAfter(i, aRW);
1618 #ifdef DUMPOFIntPatch_Intersection
1620 void IntPatch_Intersection__MAJ_R(Handle(Adaptor2d_HCurve2d) *R1,
1621 Handle(Adaptor2d_HCurve2d) *,
1624 Standard_Integer nbR1,
1626 const IntPatch_Point& VTX)
1629 if(VTX.IsOnDomS1()) {
1631 //-- long unsigned ptr= *((long unsigned *)(((Handle(Standard_Transient) *)(&(VTX.ArcOnS1())))));
1632 for(Standard_Integer i=0; i<nbR1;i++) {
1633 if(VTX.ArcOnS1()==R1[i]) {
1635 printf("\n ******************************");
1639 printf("\n R Pas trouvee (IntPatch)\n");
1645 void IntPatch_Intersection::Dump(const Standard_Integer /*Mode*/,
1646 const Handle(Adaptor3d_HSurface)& /*S1*/,
1647 const Handle(Adaptor3d_TopolTool)& /*D1*/,
1648 const Handle(Adaptor3d_HSurface)& /*S2*/,
1649 const Handle(Adaptor3d_TopolTool)& /*D2*/) const
1651 #ifdef DUMPOFIntPatch_Intersection
1652 const int MAXR = 200;
1653 //-- ----------------------------------------------------------------------
1654 //-- construction de la liste des restrictions & vertex
1656 int NR1[MAXR],NR2[MAXR];
1657 Handle(Adaptor2d_HCurve2d) R1[MAXR],R2[MAXR];
1658 Standard_Integer nbR1=0,nbR2=0;
1659 for(D1->Init();D1->More() && nbR1<MAXR; D1->Next()) {
1660 R1[nbR1]=D1->Value();
1664 for(D2->Init();D2->More() && nbR2<MAXR; D2->Next()) {
1665 R2[nbR2]=D2->Value();
1670 printf("\nDUMP_INT: ----empt:%2ud tgte:%2ud oppo:%2ud ---------------------------------",empt,tgte,empt);
1671 Standard_Integer i,nbr1,nbr2,nbgl,nbgc,nbge,nbgp,nbgh,nbl,nbr,nbg,nbw,nba;
1672 nbl=nbr=nbg=nbw=nba=nbgl=nbge=nbr1=nbr2=nbgc=nbgp=nbgh=0;
1674 for(i=1;i<=nbl;i++) {
1675 const Handle(IntPatch_Line)& line=Line(i);
1676 const IntPatch_IType IType=line->ArcType();
1677 if(IType == IntPatch_Walking) nbw++;
1678 else if(IType == IntPatch_Restriction) {
1680 Handle(IntPatch_RLine) rlin (Handle(IntPatch_RLine)::DownCast (line));
1681 if(rlin->IsArcOnS1()) nbr1++;
1682 if(rlin->IsArcOnS2()) nbr2++;
1684 else if(IType == IntPatch_Analytic) nba++;
1687 if(IType == IntPatch_Lin) nbgl++;
1688 else if(IType == IntPatch_Circle) nbgc++;
1689 else if(IType == IntPatch_Parabola) nbgp++;
1690 else if(IType == IntPatch_Hyperbola) nbgh++;
1691 else if(IType == IntPatch_Ellipse) nbge++;
1696 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)",
1697 nbl,nbw,nbr,nbr1,nbr2,nba,nbg,nbgl,nbgc,nbge,nbgh,nbgp);
1699 IntPatch_LineConstructor LineConstructor(2);
1701 Standard_Integer nbllc=0;
1703 Standard_Integer nbva,nbvw,nbvr,nbvg;
1704 nbva=nbvr=nbvw=nbvg=0;
1705 for (j=1; j<=nbl; j++) {
1706 Standard_Integer v,nbvtx;
1707 const Handle(IntPatch_Line)& intersLinej = Line(j);
1708 Standard_Integer NbLines;
1709 LineConstructor.Perform(SequenceOfLine(),intersLinej,S1,D1,S2,D2,1e-7);
1710 NbLines = LineConstructor.NbLines();
1712 for(Standard_Integer k=1;k<=NbLines;k++) {
1714 const Handle(IntPatch_Line)& LineK = LineConstructor.Line(k);
1715 if (LineK->ArcType() == IntPatch_Analytic) {
1716 Handle(IntPatch_ALine) alin (Handle(IntPatch_ALine)::DownCast (LineK));
1717 nbvtx=alin->NbVertex();
1719 for(v=1;v<=nbvtx;v++) {
1720 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,alin->Vertex(v));
1723 else if (LineK->ArcType() == IntPatch_Restriction) {
1724 Handle(IntPatch_RLine) rlin (Handle(IntPatch_RLine)::DownCast (LineK));
1725 nbvtx=rlin->NbVertex();
1727 for(v=1;v<=nbvtx;v++) {
1728 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,rlin->Vertex(v));
1731 else if (LineK->ArcType() == IntPatch_Walking) {
1732 Handle(IntPatch_WLine) wlin (Handle(IntPatch_WLine)::DownCast (LineK));
1733 nbvtx=wlin->NbVertex();
1735 for(v=1;v<=nbvtx;v++) {
1736 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,wlin->Vertex(v));
1740 Handle(IntPatch_GLine) glin (Handle(IntPatch_GLine)::DownCast (LineK));
1741 nbvtx=glin->NbVertex();
1743 for(v=1;v<=nbvtx;v++) {
1744 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,glin->Vertex(v));
1749 printf("\nDUMP_LC :Lines:%2d WLin:%2d Restr:%2d Ana:%2d Geom:%2d",
1750 nbllc,nbw,nbr,nba,nbg);
1751 printf("\nDUMP_LC :vtx :%2d r:%2d :%2d :%2d",
1752 nbvw,nbvr,nbva,nbvg);