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.
15 #include <IntPatch_Intersection.hxx>
17 #include <Adaptor3d_HSurface.hxx>
18 #include <Adaptor3d_TopolTool.hxx>
19 #include <IntPatch_ALine.hxx>
20 #include <IntPatch_ALineToWLine.hxx>
21 #include <IntPatch_GLine.hxx>
22 #include <IntPatch_ImpImpIntersection.hxx>
23 #include <IntPatch_ImpPrmIntersection.hxx>
24 #include <IntPatch_Line.hxx>
25 #include <IntPatch_Point.hxx>
26 #include <IntPatch_PrmPrmIntersection.hxx>
27 #include <IntPatch_RLine.hxx>
28 #include <IntPatch_WLine.hxx>
29 #include <IntPatch_WLineTool.hxx>
30 #include <IntSurf_Quadric.hxx>
31 #include <Standard_ConstructionError.hxx>
32 #include <Standard_DomainError.hxx>
33 #include <Standard_OutOfRange.hxx>
34 #include <StdFail_NotDone.hxx>
35 #include <IntPatch_LineConstructor.hxx>
39 static const Standard_Integer aNbPointsInALine = 200;
41 //======================================================================
42 // function: SequenceOfLine
43 //======================================================================
44 const IntPatch_SequenceOfLine& IntPatch_Intersection::SequenceOfLine() const { return(slin); }
46 //======================================================================
47 // function: IntPatch_Intersection
48 //======================================================================
49 IntPatch_Intersection::IntPatch_Intersection ()
50 : done(Standard_False),
52 myTolArc(0.0), myTolTang(0.0),
53 myUVMaxStep(0.0), myFleche(0.0),
54 myIsStartPnt(Standard_False)
55 //myU1Start, myV1Start, myU2Start, myV2Start
59 //======================================================================
60 // function: IntPatch_Intersection
61 //======================================================================
62 IntPatch_Intersection::IntPatch_Intersection(const Handle(Adaptor3d_HSurface)& S1,
63 const Handle(Adaptor3d_TopolTool)& D1,
64 const Handle(Adaptor3d_HSurface)& S2,
65 const Handle(Adaptor3d_TopolTool)& D2,
66 const Standard_Real TolArc,
67 const Standard_Real TolTang)
68 : done(Standard_False),
70 myTolArc(TolArc), myTolTang(TolTang),
71 myUVMaxStep(0.0), myFleche(0.0),
72 myIsStartPnt(Standard_False)
73 //myU1Start, myV1Start, myU2Start, myV2Start
75 if(myTolArc<1e-8) myTolArc=1e-8;
76 if(myTolTang<1e-8) myTolTang=1e-8;
77 if(myTolArc>0.5) myTolArc=0.5;
78 if(myTolTang>0.5) myTolTang=0.5;
79 Perform(S1,D1,S2,D2,TolArc,TolTang);
82 //======================================================================
83 // function: IntPatch_Intersection
84 //======================================================================
85 IntPatch_Intersection::IntPatch_Intersection(const Handle(Adaptor3d_HSurface)& S1,
86 const Handle(Adaptor3d_TopolTool)& D1,
87 const Standard_Real TolArc,
88 const Standard_Real TolTang)
89 : done(Standard_False),
91 myTolArc(TolArc), myTolTang(TolTang),
92 myUVMaxStep(0.0), myFleche(0.0),
93 myIsStartPnt(Standard_False)
94 //myU1Start, myV1Start, myU2Start, myV2Start
96 Perform(S1,D1,TolArc,TolTang);
99 //======================================================================
100 // function: SetTolerances
101 //======================================================================
102 void IntPatch_Intersection::SetTolerances(const Standard_Real TolArc,
103 const Standard_Real TolTang,
104 const Standard_Real UVMaxStep,
105 const Standard_Real Fleche)
109 myUVMaxStep = UVMaxStep;
111 if(myTolArc<1e-8) myTolArc=1e-8;
112 if(myTolTang<1e-8) myTolTang=1e-8;
113 if(myTolArc>0.5) myTolArc=0.5;
114 if(myTolTang>0.5) myTolTang=0.5;
115 if(myFleche<1.0e-3) myFleche=1e-3;
116 if(myUVMaxStep<1.0e-3) myUVMaxStep=1e-3;
117 if(myFleche>10) myFleche=10;
118 if(myUVMaxStep>0.5) myUVMaxStep=0.5;
121 //======================================================================
123 //======================================================================
124 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& S1,
125 const Handle(Adaptor3d_TopolTool)& D1,
126 const Standard_Real TolArc,
127 const Standard_Real TolTang)
131 if(myFleche == 0.0) myFleche = 0.01;
132 if(myUVMaxStep==0.0) myUVMaxStep = 0.01;
134 done = Standard_True;
138 empt = Standard_True;
139 tgte = Standard_False;
140 oppo = Standard_False;
142 switch (S1->GetType())
145 case GeomAbs_Cylinder:
148 case GeomAbs_Torus: break;
151 IntPatch_PrmPrmIntersection interpp;
152 interpp.Perform(S1,D1,TolTang,TolArc,myFleche,myUVMaxStep);
153 if (interpp.IsDone())
155 done = Standard_True;
156 tgte = Standard_False;
157 empt = interpp.IsEmpty();
158 const Standard_Integer nblm = interpp.NbLines();
159 for (Standard_Integer i=1; i<=nblm; i++) slin.Append(interpp.Line(i));
166 /////////////////////////////////////////////////////////////////////////////
167 // These several support functions provide methods which can help basic //
168 // algorithm to intersect infinite surfaces of the following types: //
170 // a.) SurfaceOfExtrusion; //
171 // b.) SurfaceOfRevolution; //
172 // c.) OffsetSurface. //
174 /////////////////////////////////////////////////////////////////////////////
175 #include <TColgp_Array1OfXYZ.hxx>
176 #include <TColgp_Array1OfPnt.hxx>
177 #include <TColgp_SequenceOfPnt.hxx>
178 #include <Extrema_ExtPS.hxx>
179 #include <Extrema_POnSurf.hxx>
180 #include <Geom2d_Curve.hxx>
181 #include <Geom2dAPI_InterCurveCurve.hxx>
182 #include <GeomAdaptor.hxx>
183 #include <GeomAdaptor_HCurve.hxx>
184 #include <GeomAdaptor_Curve.hxx>
185 #include <GeomAdaptor_Surface.hxx>
186 #include <GeomAdaptor_HSurface.hxx>
187 #include <Geom_Plane.hxx>
188 #include <ProjLib_ProjectOnPlane.hxx>
189 #include <GeomProjLib.hxx>
190 #include <ElCLib.hxx>
191 #include <Geom_TrimmedCurve.hxx>
192 #include <Geom_Surface.hxx>
193 #include <Geom_SurfaceOfLinearExtrusion.hxx>
194 #include <Geom_OffsetSurface.hxx>
195 #include <Geom_SurfaceOfRevolution.hxx>
196 #include <Geom_RectangularTrimmedSurface.hxx>
198 //===============================================================
199 //function: FUN_GetMinMaxXYZPnt
200 //===============================================================
201 static void FUN_GetMinMaxXYZPnt( const Handle(Adaptor3d_HSurface)& S,
202 gp_Pnt& pMin, gp_Pnt& pMax )
204 const Standard_Real DU = 0.25 * Abs(S->LastUParameter() - S->FirstUParameter());
205 const Standard_Real DV = 0.25 * Abs(S->LastVParameter() - S->FirstVParameter());
206 Standard_Real tMinXYZ = RealLast();
207 Standard_Real tMaxXYZ = -tMinXYZ;
208 gp_Pnt PUV, ptMax, ptMin;
209 for(Standard_Real U = S->FirstUParameter(); U <= S->LastUParameter(); U += DU)
211 for(Standard_Real V = S->FirstVParameter(); V <= S->LastVParameter(); V += DV)
214 const Standard_Real cXYZ = PUV.XYZ().Modulus();
215 if(cXYZ > tMaxXYZ) { tMaxXYZ = cXYZ; ptMax = PUV; }
216 if(cXYZ < tMinXYZ) { tMinXYZ = cXYZ; ptMin = PUV; }
222 //==========================================================================
223 //function: FUN_TrimInfSurf
224 //==========================================================================
225 static void FUN_TrimInfSurf(const gp_Pnt& Pmin,
227 const Handle(Adaptor3d_HSurface)& InfSurf,
228 const Standard_Real& AlternativeTrimPrm,
229 Handle(Adaptor3d_HSurface)& TrimS)
231 Standard_Real TP = AlternativeTrimPrm;
232 Extrema_ExtPS ext1(Pmin, InfSurf->Surface(), 1.e-7, 1.e-7);
233 Extrema_ExtPS ext2(Pmax, InfSurf->Surface(), 1.e-7, 1.e-7);
234 if(ext1.IsDone() || ext2.IsDone())
236 Standard_Real Umax = -1.e+100, Umin = 1.e+100, Vmax = -1.e+100, Vmin = 1.e+100, cU, cV;
239 for(Standard_Integer i = 1; i <= ext1.NbExt(); i++)
241 const Extrema_POnSurf & pons = ext1.Point(i);
242 pons.Parameter(cU,cV);
243 if(cU > Umax) Umax = cU;
244 if(cU < Umin) Umin = cU;
245 if(cV > Vmax) Vmax = cV;
246 if(cV < Vmin) Vmin = cV;
251 for(Standard_Integer i = 1; i <= ext2.NbExt(); i++)
253 const Extrema_POnSurf & pons = ext2.Point(i);
254 pons.Parameter(cU,cV);
255 if(cU > Umax) Umax = cU;
256 if(cU < Umin) Umin = cU;
257 if(cV > Vmax) Vmax = cV;
258 if(cV < Vmin) Vmin = cV;
261 TP = Max(Abs(Umin),Max(Abs(Umax),Max(Abs(Vmin),Abs(Vmax))));
263 if(TP == 0.) { TrimS = InfSurf; return; }
266 const Standard_Boolean Uinf = Precision::IsNegativeInfinite(InfSurf->FirstUParameter());
267 const Standard_Boolean Usup = Precision::IsPositiveInfinite(InfSurf->LastUParameter());
268 const Standard_Boolean Vinf = Precision::IsNegativeInfinite(InfSurf->FirstVParameter());
269 const Standard_Boolean Vsup = Precision::IsPositiveInfinite(InfSurf->LastVParameter());
270 Handle(Adaptor3d_HSurface) TmpSS;
271 Standard_Integer IsTrimed = 0;
272 const Standard_Real tp = 1000.0 * TP;
273 if(Vinf && Vsup) { TrimS = InfSurf->VTrim(-tp, tp, 1.0e-7); IsTrimed = 1; }
274 if(Vinf && !Vsup){ TrimS = InfSurf->VTrim(-tp, InfSurf->LastVParameter(), 1.0e-7); IsTrimed = 1; }
275 if(!Vinf && Vsup){ TrimS = InfSurf->VTrim(InfSurf->FirstVParameter(), tp, 1.0e-7); IsTrimed = 1; }
279 if(Uinf && Usup) TrimS = TmpSS->UTrim(-tp, tp, 1.0e-7);
280 if(Uinf && !Usup) TrimS = TmpSS->UTrim(-tp, InfSurf->LastUParameter(), 1.0e-7);
281 if(!Uinf && Usup) TrimS = TmpSS->UTrim(InfSurf->FirstUParameter(), tp, 1.0e-7);
285 if(Uinf && Usup) TrimS = InfSurf->UTrim(-tp, tp, 1.0e-7);
286 if(Uinf && !Usup) TrimS = InfSurf->UTrim(-tp, InfSurf->LastUParameter(), 1.0e-7);
287 if(!Uinf && Usup) TrimS = InfSurf->UTrim(InfSurf->FirstUParameter(), tp, 1.0e-7);
291 //================================================================================
292 //function: FUN_GetUiso
293 //================================================================================
294 static void FUN_GetUiso(const Handle(Geom_Surface)& GS,
295 const GeomAbs_SurfaceType& T,
296 const Standard_Real& FirstV,
297 const Standard_Real& LastV,
298 const Standard_Boolean& IsVC,
299 const Standard_Boolean& IsVP,
300 const Standard_Real& U,
301 Handle(Geom_Curve)& I)
303 if(T != GeomAbs_OffsetSurface)
305 Handle(Geom_Curve) gc = GS->UIso(U);
306 if(IsVP && (FirstV == 0.0 && LastV == (2.*M_PI))) I = gc;
309 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstV,LastV);
310 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
316 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (GS);
317 const Handle(Geom_Surface) bs = gos->BasisSurface();
318 Handle(Geom_Curve) gcbs = bs->UIso(U);
319 GeomAdaptor_Curve gac(gcbs);
320 const GeomAbs_CurveType GACT = gac.GetType();
321 if(IsVP || IsVC || GACT == GeomAbs_BSplineCurve || GACT == GeomAbs_BezierCurve || Abs(LastV - FirstV) < 1.e+5)
323 Handle(Geom_Curve) gc = gos->UIso(U);
324 if(IsVP && (FirstV == 0.0 && LastV == (2*M_PI))) I = gc;
327 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstV,LastV);
328 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
332 else//Offset Line, Parab, Hyperb
334 Standard_Real VmTr, VMTr;
335 if(GACT != GeomAbs_Hyperbola)
337 if(FirstV >= 0. && LastV >= 0.){ VmTr = FirstV; VMTr = ((LastV - FirstV) > 1.e+4) ? (FirstV + 1.e+4) : LastV; }
338 else if(FirstV < 0. && LastV < 0.){ VMTr = LastV; VmTr = ((FirstV - LastV) < -1.e+4) ? (LastV - 1.e+4) : FirstV; }
339 else { VmTr = (FirstV < -1.e+4) ? -1.e+4 : FirstV; VMTr = (LastV > 1.e+4) ? 1.e+4 : LastV; }
343 if(FirstV >= 0. && LastV >= 0.)
345 if(FirstV > 4.) return;
346 VmTr = FirstV; VMTr = (LastV > 4.) ? 4. : LastV;
348 else if(FirstV < 0. && LastV < 0.)
350 if(LastV < -4.) return;
351 VMTr = LastV; VmTr = (FirstV < -4.) ? -4. : FirstV;
353 else { VmTr = (FirstV < -4.) ? -4. : FirstV; VMTr = (LastV > 4.) ? 4. : LastV; }
355 //Make trimmed surface
356 Handle(Geom_RectangularTrimmedSurface) rts = new Geom_RectangularTrimmedSurface(gos,VmTr,VMTr,Standard_True);
361 //================================================================================
362 //function: FUN_GetViso
363 //================================================================================
364 static void FUN_GetViso(const Handle(Geom_Surface)& GS,
365 const GeomAbs_SurfaceType& T,
366 const Standard_Real& FirstU,
367 const Standard_Real& LastU,
368 const Standard_Boolean& IsUC,
369 const Standard_Boolean& IsUP,
370 const Standard_Real& V,
371 Handle(Geom_Curve)& I)
373 if(T != GeomAbs_OffsetSurface)
375 Handle(Geom_Curve) gc = GS->VIso(V);
376 if(IsUP && (FirstU == 0.0 && LastU == (2*M_PI))) I = gc;
379 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstU,LastU);
380 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
386 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (GS);
387 const Handle(Geom_Surface) bs = gos->BasisSurface();
388 Handle(Geom_Curve) gcbs = bs->VIso(V);
389 GeomAdaptor_Curve gac(gcbs);
390 const GeomAbs_CurveType GACT = gac.GetType();
391 if(IsUP || IsUC || GACT == GeomAbs_BSplineCurve || GACT == GeomAbs_BezierCurve || Abs(LastU - FirstU) < 1.e+5)
393 Handle(Geom_Curve) gc = gos->VIso(V);
394 if(IsUP && (FirstU == 0.0 && LastU == (2*M_PI))) I = gc;
397 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstU,LastU);
398 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
402 else//Offset Line, Parab, Hyperb
404 Standard_Real UmTr, UMTr;
405 if(GACT != GeomAbs_Hyperbola)
407 if(FirstU >= 0. && LastU >= 0.){ UmTr = FirstU; UMTr = ((LastU - FirstU) > 1.e+4) ? (FirstU + 1.e+4) : LastU; }
408 else if(FirstU < 0. && LastU < 0.){ UMTr = LastU; UmTr = ((FirstU - LastU) < -1.e+4) ? (LastU - 1.e+4) : FirstU; }
409 else { UmTr = (FirstU < -1.e+4) ? -1.e+4 : FirstU; UMTr = (LastU > 1.e+4) ? 1.e+4 : LastU; }
413 if(FirstU >= 0. && LastU >= 0.)
415 if(FirstU > 4.) return;
416 UmTr = FirstU; UMTr = (LastU > 4.) ? 4. : LastU;
418 else if(FirstU < 0. && LastU < 0.)
420 if(LastU < -4.) return;
421 UMTr = LastU; UmTr = (FirstU < -4.) ? -4. : FirstU;
423 else { UmTr = (FirstU < -4.) ? -4. : FirstU; UMTr = (LastU > 4.) ? 4. : LastU; }
425 //Make trimmed surface
426 Handle(Geom_RectangularTrimmedSurface) rts = new Geom_RectangularTrimmedSurface(gos,UmTr,UMTr,Standard_True);
431 //================================================================================
432 //function: FUN_PL_Intersection
433 //================================================================================
434 static void FUN_PL_Intersection(const Handle(Adaptor3d_HSurface)& S1,
435 const GeomAbs_SurfaceType& T1,
436 const Handle(Adaptor3d_HSurface)& S2,
437 const GeomAbs_SurfaceType& T2,
438 Standard_Boolean& IsOk,
439 TColgp_SequenceOfPnt& SP,
442 IsOk = Standard_False;
443 // 1. Check: both surfaces have U(V)isos - lines.
444 DV = gp_Vec(0.,0.,1.);
445 Standard_Boolean isoS1isLine[2] = {0, 0};
446 Standard_Boolean isoS2isLine[2] = {0, 0};
447 Handle(Geom_Curve) C1, C2;
448 const GeomAdaptor_Surface & gas1 = *(GeomAdaptor_Surface*)(&(S1->Surface()));
449 const GeomAdaptor_Surface & gas2 = *(GeomAdaptor_Surface*)(&(S2->Surface()));
450 const Handle(Geom_Surface) gs1 = gas1.Surface();
451 const Handle(Geom_Surface) gs2 = gas2.Surface();
452 Standard_Real MS1[2], MS2[2];
453 MS1[0] = 0.5 * (S1->LastUParameter() + S1->FirstUParameter());
454 MS1[1] = 0.5 * (S1->LastVParameter() + S1->FirstVParameter());
455 MS2[0] = 0.5 * (S2->LastUParameter() + S2->FirstUParameter());
456 MS2[1] = 0.5 * (S2->LastVParameter() + S2->FirstVParameter());
457 if(T1 == GeomAbs_SurfaceOfExtrusion) isoS1isLine[0] = Standard_True;
458 else if(!S1->IsVPeriodic() && !S1->IsVClosed()) {
459 if(T1 != GeomAbs_OffsetSurface) C1 = gs1->UIso(MS1[0]);
461 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs1);
462 const Handle(Geom_Surface) bs = gos->BasisSurface();
463 C1 = bs->UIso(MS1[0]);
465 GeomAdaptor_Curve gac(C1);
466 if(gac.GetType() == GeomAbs_Line) isoS1isLine[0] = Standard_True;
468 if(!S1->IsUPeriodic() && !S1->IsUClosed()) {
469 if(T1 != GeomAbs_OffsetSurface) C1 = gs1->VIso(MS1[1]);
471 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs1);
472 const Handle(Geom_Surface) bs = gos->BasisSurface();
473 C1 = bs->VIso(MS1[1]);
475 GeomAdaptor_Curve gac(C1);
476 if(gac.GetType() == GeomAbs_Line) isoS1isLine[1] = Standard_True;
478 if(T2 == GeomAbs_SurfaceOfExtrusion) isoS2isLine[0] = Standard_True;
479 else if(!S2->IsVPeriodic() && !S2->IsVClosed()) {
480 if(T2 != GeomAbs_OffsetSurface) C2 = gs2->UIso(MS2[0]);
482 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs2);
483 const Handle(Geom_Surface) bs = gos->BasisSurface();
484 C2 = bs->UIso(MS2[0]);
486 GeomAdaptor_Curve gac(C2);
487 if(gac.GetType() == GeomAbs_Line) isoS2isLine[0] = Standard_True;
489 if(!S2->IsUPeriodic() && !S2->IsUClosed()) {
490 if(T2 != GeomAbs_OffsetSurface) C2 = gs2->VIso(MS2[1]);
492 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs2);
493 const Handle(Geom_Surface) bs = gos->BasisSurface();
494 C2 = bs->VIso(MS2[1]);
496 GeomAdaptor_Curve gac(C2);
497 if(gac.GetType() == GeomAbs_Line) isoS2isLine[1] = Standard_True;
499 Standard_Boolean IsBothLines = ((isoS1isLine[0] || isoS1isLine[1]) &&
500 (isoS2isLine[0] || isoS2isLine[1]));
504 // 2. Check: Uiso lines of both surfaces are collinear.
506 gp_Vec derS1[2], derS2[2];
507 S1->D1(MS1[0], MS1[1], puvS1, derS1[0], derS1[1]);
508 S2->D1(MS2[0], MS2[1], puvS2, derS2[0], derS2[1]);
509 C1.Nullify(); C2.Nullify();
510 Standard_Integer iso = 0;
511 if(isoS1isLine[0] && isoS2isLine[0] &&
512 derS1[1].IsParallel(derS2[1],Precision::Angular())) {
514 FUN_GetViso(gs1,T1,S1->FirstUParameter(),S1->LastUParameter(),
515 S1->IsUClosed(),S1->IsUPeriodic(),MS1[1],C1);
516 FUN_GetViso(gs2,T2,S2->FirstUParameter(),S2->LastUParameter(),
517 S2->IsUClosed(),S2->IsUPeriodic(),MS2[1],C2);
519 else if(isoS1isLine[0] && isoS2isLine[1] &&
520 derS1[1].IsParallel(derS2[0],Precision::Angular())) {
522 FUN_GetViso(gs1,T1,S1->FirstUParameter(),S1->LastUParameter(),
523 S1->IsUClosed(),S1->IsUPeriodic(),MS1[1],C1);
524 FUN_GetUiso(gs2,T2,S2->FirstVParameter(),S2->LastVParameter(),
525 S2->IsVClosed(),S2->IsVPeriodic(),MS2[0],C2);
527 else if(isoS1isLine[1] && isoS2isLine[0] &&
528 derS1[0].IsParallel(derS2[1],Precision::Angular())) {
530 FUN_GetUiso(gs1,T1,S1->FirstVParameter(),S1->LastVParameter(),
531 S1->IsVClosed(),S1->IsVPeriodic(),MS1[0],C1);
532 FUN_GetViso(gs2,T2,S2->FirstUParameter(),S2->LastUParameter(),
533 S2->IsUClosed(),S2->IsUPeriodic(),MS2[1],C2);
535 else if(isoS1isLine[1] && isoS2isLine[1] &&
536 derS1[0].IsParallel(derS2[0],Precision::Angular())) {
538 FUN_GetUiso(gs1,T1,S1->FirstVParameter(),S1->LastVParameter(),
539 S1->IsVClosed(),S1->IsVPeriodic(),MS1[0],C1);
540 FUN_GetUiso(gs2,T2,S2->FirstVParameter(),S2->LastVParameter(),
541 S2->IsVClosed(),S2->IsVPeriodic(),MS2[0],C2);
544 IsOk = Standard_False;
547 IsOk = Standard_True;
548 // 3. Make intersections of V(U)isos
549 if(C1.IsNull() || C2.IsNull()) return;
551 Handle(Geom_Plane) GPln = new Geom_Plane(gp_Pln(puvS1,gp_Dir(DV)));
552 Handle(Geom_Curve) C1Prj =
553 GeomProjLib::ProjectOnPlane(C1,GPln,gp_Dir(DV),Standard_True);
554 Handle(Geom_Curve) C2Prj =
555 GeomProjLib::ProjectOnPlane(C2,GPln,gp_Dir(DV),Standard_True);
556 if(C1Prj.IsNull() || C2Prj.IsNull()) return;
557 Handle(Geom2d_Curve) C1Prj2d = GeomProjLib::Curve2d (C1Prj,GPln);
558 Handle(Geom2d_Curve) C2Prj2d = GeomProjLib::Curve2d (C2Prj,GPln);
559 Geom2dAPI_InterCurveCurve ICC(C1Prj2d,C2Prj2d,1.0e-7);
560 if(ICC.NbPoints() > 0 )
562 for(Standard_Integer ip = 1; ip <= ICC.NbPoints(); ip++)
564 gp_Pnt2d P = ICC.Point(ip);
565 gp_Pnt P3d = ElCLib::To3d(gp_Ax2(puvS1,gp_Dir(DV)),P);
570 //================================================================================
571 //function: FUN_NewFirstLast
572 //================================================================================
573 static void FUN_NewFirstLast(const GeomAbs_CurveType& ga_ct,
574 const Standard_Real& Fst,
575 const Standard_Real& Lst,
576 const Standard_Real& TrVal,
577 Standard_Real& NewFst,
578 Standard_Real& NewLst,
579 Standard_Boolean& NeedTr)
581 NewFst = Fst; NewLst = Lst; NeedTr = Standard_False;
585 case GeomAbs_Parabola:
587 if(Abs(Lst - Fst) > TrVal)
589 if(Fst >= 0. && Lst >= 0.)
592 NewLst = ((Fst + TrVal) < Lst) ? (Fst + TrVal) : Lst;
594 if(Fst < 0. && Lst < 0.)
597 NewFst = ((Lst - TrVal) > Fst) ? (Lst - TrVal) : Fst;
601 NewFst = (Fst < -TrVal) ? -TrVal : Fst;
602 NewLst = (Lst > TrVal) ? TrVal : Lst;
604 NeedTr = Standard_True;
608 case GeomAbs_Hyperbola:
610 if(Abs(Lst - Fst) > 10.)
612 if(Fst >= 0. && Lst >= 0.)
616 NewLst = (Lst > 4.) ? 4. : Lst;
618 if(Fst < 0. && Lst < 0.)
620 if(Lst < -4.) return;
622 NewFst = (Fst < -4.) ? -4. : Fst;
626 NewFst = (Fst < -4.) ? -4. : Fst;
627 NewLst = (Lst > 4.) ? 4. : Lst;
629 NeedTr = Standard_True;
637 //================================================================================
638 //function: FUN_TrimBothSurf
639 //================================================================================
640 static void FUN_TrimBothSurf(const Handle(Adaptor3d_HSurface)& S1,
641 const GeomAbs_SurfaceType& T1,
642 const Handle(Adaptor3d_HSurface)& S2,
643 const GeomAbs_SurfaceType& T2,
644 const Standard_Real& TV,
645 Handle(Adaptor3d_HSurface)& NS1,
646 Handle(Adaptor3d_HSurface)& NS2)
648 const GeomAdaptor_Surface & gas1 = *(GeomAdaptor_Surface*)(&(S1->Surface()));
649 const GeomAdaptor_Surface & gas2 = *(GeomAdaptor_Surface*)(&(S2->Surface()));
650 const Handle(Geom_Surface) gs1 = gas1.Surface();
651 const Handle(Geom_Surface) gs2 = gas2.Surface();
652 const Standard_Real UM1 = 0.5 * (S1->LastUParameter() + S1->FirstUParameter());
653 const Standard_Real UM2 = 0.5 * (S2->LastUParameter() + S2->FirstUParameter());
654 const Standard_Real VM1 = 0.5 * (S1->LastVParameter() + S1->FirstVParameter());
655 const Standard_Real VM2 = 0.5 * (S2->LastVParameter() + S2->FirstVParameter());
656 Handle(Geom_Curve) visoS1, visoS2, uisoS1, uisoS2;
657 if(T1 != GeomAbs_OffsetSurface){ visoS1 = gs1->VIso(VM1); uisoS1 = gs1->UIso(UM1); }
660 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs1);
661 const Handle(Geom_Surface) bs = gos->BasisSurface();
662 visoS1 = bs->VIso(VM1); uisoS1 = bs->UIso(UM1);
664 if(T2 != GeomAbs_OffsetSurface){ visoS2 = gs2->VIso(VM2); uisoS2 = gs2->UIso(UM2); }
667 const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs2);
668 const Handle(Geom_Surface) bs = gos->BasisSurface();
669 visoS2 = bs->VIso(VM2); uisoS2 = bs->UIso(UM2);
671 if(uisoS1.IsNull() || uisoS2.IsNull() || visoS1.IsNull() || visoS2.IsNull()){ NS1 = S1; NS2 = S2; return; }
672 GeomAdaptor_Curve gau1(uisoS1);
673 GeomAdaptor_Curve gav1(visoS1);
674 GeomAdaptor_Curve gau2(uisoS2);
675 GeomAdaptor_Curve gav2(visoS2);
676 GeomAbs_CurveType GA_U1 = gau1.GetType();
677 GeomAbs_CurveType GA_V1 = gav1.GetType();
678 GeomAbs_CurveType GA_U2 = gau2.GetType();
679 GeomAbs_CurveType GA_V2 = gav2.GetType();
680 Standard_Boolean TrmU1 = Standard_False;
681 Standard_Boolean TrmV1 = Standard_False;
682 Standard_Boolean TrmU2 = Standard_False;
683 Standard_Boolean TrmV2 = Standard_False;
684 Standard_Real V1S1,V2S1,U1S1,U2S1, V1S2,V2S2,U1S2,U2S2;
685 FUN_NewFirstLast(GA_U1,S1->FirstVParameter(),S1->LastVParameter(),TV,V1S1,V2S1,TrmV1);
686 FUN_NewFirstLast(GA_V1,S1->FirstUParameter(),S1->LastUParameter(),TV,U1S1,U2S1,TrmU1);
687 FUN_NewFirstLast(GA_U2,S2->FirstVParameter(),S2->LastVParameter(),TV,V1S2,V2S2,TrmV2);
688 FUN_NewFirstLast(GA_V2,S2->FirstUParameter(),S2->LastUParameter(),TV,U1S2,U2S2,TrmU2);
689 if(TrmV1) NS1 = S1->VTrim(V1S1, V2S1, 1.0e-7);
690 if(TrmV2) NS2 = S2->VTrim(V1S2, V2S2, 1.0e-7);
695 Handle(Adaptor3d_HSurface) TS = NS1;
696 NS1 = TS->UTrim(U1S1, U2S1, 1.0e-7);
698 else NS1 = S1->UTrim(U1S1, U2S1, 1.0e-7);
704 Handle(Adaptor3d_HSurface) TS = NS2;
705 NS2 = TS->UTrim(U1S2, U2S2, 1.0e-7);
707 else NS2 = S2->UTrim(U1S2, U2S2, 1.0e-7);
711 //=======================================================================
714 //=======================================================================
715 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& theS1,
716 const Handle(Adaptor3d_TopolTool)& theD1,
717 const Handle(Adaptor3d_HSurface)& theS2,
718 const Handle(Adaptor3d_TopolTool)& theD2,
719 const Standard_Real TolArc,
720 const Standard_Real TolTang,
721 const Standard_Boolean isGeomInt,
722 const Standard_Boolean theIsReqToKeepRLine,
723 const Standard_Boolean theIsReqToPostWLProc)
727 if(myFleche <= Precision::PConfusion())
729 if(myUVMaxStep <= Precision::PConfusion())
732 done = Standard_False;
735 empt = Standard_True;
736 tgte = Standard_False;
737 oppo = Standard_False;
739 GeomAbs_SurfaceType typs1 = theS1->GetType();
740 GeomAbs_SurfaceType typs2 = theS2->GetType();
742 //treatment of the cases with cone or torus
743 Standard_Boolean TreatAsBiParametric = Standard_False;
744 Standard_Integer bGeomGeom = 0;
746 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone ||
747 typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
748 gp_Ax1 aCTAx, aGeomAx;
749 GeomAbs_SurfaceType aCTType;
750 Standard_Boolean bToCheck;
752 const Handle(Adaptor3d_HSurface)& aCTSurf =
753 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS1 : theS2;
754 const Handle(Adaptor3d_HSurface)& aGeomSurf =
755 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS2 : theS1;
757 aCTType = aCTSurf->GetType();
758 bToCheck = Standard_False;
760 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone) {
761 const gp_Cone aCon1 = (aCTType == GeomAbs_Cone) ?
762 aCTSurf->Cone() : aGeomSurf->Cone();
763 Standard_Real a1 = Abs(aCon1.SemiAngle());
764 bToCheck = (a1 < 0.02) || (a1 > 1.55);
766 if (typs1 == typs2) {
767 const gp_Cone aCon2 = aGeomSurf->Cone();
768 Standard_Real a2 = Abs(aCon2.SemiAngle());
769 bToCheck = bToCheck || (a2 < 0.02) || (a2 > 1.55);
771 if (a1 > 1.55 && a2 > 1.55) {//quasi-planes: if same domain, treat as canonic
772 const gp_Ax1 A1 = aCon1.Axis(), A2 = aCon2.Axis();
773 if (A1.IsParallel(A2,Precision::Angular())) {
774 const gp_Pnt Apex1 = aCon1.Apex(), Apex2 = aCon2.Apex();
775 const gp_Pln Plan1( Apex1, A1.Direction() );
776 if (Plan1.Distance( Apex2 ) <= Precision::Confusion()) {
777 bToCheck = Standard_False;
783 TreatAsBiParametric = bToCheck;
784 if (aCTType == GeomAbs_Cone) {
785 aCTAx = aCon1.Axis();
789 if (typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
790 const gp_Torus aTor1 = (aCTType == GeomAbs_Torus) ?
791 aCTSurf->Torus() : aGeomSurf->Torus();
792 bToCheck = aTor1.MajorRadius() > aTor1.MinorRadius();
793 if (typs1 == typs2) {
794 const gp_Torus aTor2 = aGeomSurf->Torus();
795 bToCheck = aTor2.MajorRadius() > aTor2.MinorRadius();
798 if (aCTType == GeomAbs_Torus) {
799 aCTAx = aTor1.Axis();
804 const gp_Lin aL1(aCTAx);
806 switch (aGeomSurf->GetType()) {
807 case GeomAbs_Plane: {
808 aGeomAx = aGeomSurf->Plane().Axis();
809 if (aCTType == GeomAbs_Cone) {
811 if (Abs(aCTSurf->Cone().SemiAngle()) < 0.02) {
812 Standard_Real ps = Abs(aCTAx.Direction().Dot(aGeomAx.Direction()));
819 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) ||
820 (aCTAx.IsNormal(aGeomAx, Precision::Angular()) &&
821 (aGeomSurf->Plane().Distance(aCTAx.Location()) < Precision::Confusion()))) {
825 bToCheck = Standard_False;
828 case GeomAbs_Sphere: {
829 if (aL1.Distance(aGeomSurf->Sphere().Location()) < Precision::Confusion()) {
832 bToCheck = Standard_False;
835 case GeomAbs_Cylinder:
836 aGeomAx = aGeomSurf->Cylinder().Axis();
839 aGeomAx = aGeomSurf->Cone().Axis();
842 aGeomAx = aGeomSurf->Torus().Axis();
845 bToCheck = Standard_False;
850 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) &&
851 (aL1.Distance(aGeomAx.Location()) <= Precision::Confusion())) {
856 if (bGeomGeom == 1) {
857 TreatAsBiParametric = Standard_False;
863 if(theD1->DomainIsInfinite() || theD2->DomainIsInfinite()) {
864 TreatAsBiParametric= Standard_False;
867 // Modified by skv - Mon Sep 26 14:58:30 2005 Begin
868 // if(TreatAsBiParametric) { typs1 = typs2 = GeomAbs_BezierSurface; }
869 if(TreatAsBiParametric)
871 if (typs1 == GeomAbs_Cone && typs2 == GeomAbs_Plane)
872 typs1 = GeomAbs_BezierSurface; // Using Imp-Prm Intersector
873 else if (typs1 == GeomAbs_Plane && typs2 == GeomAbs_Cone)
874 typs2 = GeomAbs_BezierSurface; // Using Imp-Prm Intersector
876 // Using Prm-Prm Intersector
877 typs1 = GeomAbs_BezierSurface;
878 typs2 = GeomAbs_BezierSurface;
881 // Modified by skv - Mon Sep 26 14:58:30 2005 End
883 // Surface type definition
884 Standard_Integer ts1 = 0;
888 case GeomAbs_Cylinder:
890 case GeomAbs_Cone: ts1 = 1; break;
891 case GeomAbs_Torus: ts1 = bGeomGeom; break;
895 Standard_Integer ts2 = 0;
899 case GeomAbs_Cylinder:
901 case GeomAbs_Cone: ts2 = 1; break;
902 case GeomAbs_Torus: ts2 = bGeomGeom; break;
906 // treatment of the cases with torus and any other geom surface
908 // Possible intersection types: 1. ts1 == ts2 == 1 <Geom-Geom>
909 // 2. ts1 != ts2 <Geom-Param>
910 // 3. ts1 == ts2 == 0 <Param-Param>
913 const Standard_Boolean RestrictLine = Standard_True;
914 if(ts1 == ts2 && ts1 == 1)
916 IntSurf_ListOfPntOn2S ListOfPnts;
920 GeomGeomPerfom( theS1, theD1, theS2, theD2, TolArc,
921 TolTang, ListOfPnts, RestrictLine,
922 typs1, typs2, theIsReqToKeepRLine);
926 ParamParamPerfom(theS1, theD1, theS2, theD2,
927 TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
934 GeomParamPerfom(theS1, theD1, theS2, theD2, ts1 == 0, typs1, typs2);
938 if(ts1 == ts2 && ts1 == 0)
940 IntSurf_ListOfPntOn2S ListOfPnts;
943 ParamParamPerfom(theS1, theD1, theS2, theD2, TolArc,
944 TolTang, ListOfPnts, RestrictLine, typs1, typs2);
947 if(!theIsReqToPostWLProc)
950 for(Standard_Integer i = slin.Lower(); i <= slin.Upper(); i++)
952 Handle(IntPatch_WLine) aWL = Handle(IntPatch_WLine)::DownCast(slin.Value(i));
957 Handle(IntPatch_WLine) aRW =
958 IntPatch_WLineTool::ComputePurgedWLine(aWL, theS1, theS2, theD1, theD2, RestrictLine);
963 slin.InsertAfter(i, aRW);
968 //=======================================================================
971 //=======================================================================
972 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& theS1,
973 const Handle(Adaptor3d_TopolTool)& theD1,
974 const Handle(Adaptor3d_HSurface)& theS2,
975 const Handle(Adaptor3d_TopolTool)& theD2,
976 const Standard_Real TolArc,
977 const Standard_Real TolTang,
978 IntSurf_ListOfPntOn2S& ListOfPnts,
979 const Standard_Boolean RestrictLine,
980 const Standard_Boolean isGeomInt,
981 const Standard_Boolean theIsReqToKeepRLine,
982 const Standard_Boolean theIsReqToPostWLProc)
986 if(myFleche <= Precision::PConfusion())
988 if(myUVMaxStep <= Precision::PConfusion())
991 done = Standard_False;
994 empt = Standard_True;
995 tgte = Standard_False;
996 oppo = Standard_False;
998 GeomAbs_SurfaceType typs1 = theS1->GetType();
999 GeomAbs_SurfaceType typs2 = theS2->GetType();
1001 //treatment of the cases with cone or torus
1002 Standard_Boolean TreatAsBiParametric = Standard_False;
1003 Standard_Integer bGeomGeom = 0;
1005 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone ||
1006 typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
1007 gp_Ax1 aCTAx, aGeomAx;
1008 GeomAbs_SurfaceType aCTType;
1009 Standard_Boolean bToCheck;
1011 const Handle(Adaptor3d_HSurface)& aCTSurf =
1012 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS1 : theS2;
1013 const Handle(Adaptor3d_HSurface)& aGeomSurf =
1014 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS2 : theS1;
1016 aCTType = aCTSurf->GetType();
1017 bToCheck = Standard_False;
1019 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone) {
1020 const gp_Cone aCon1 = (aCTType == GeomAbs_Cone) ?
1021 aCTSurf->Cone() : aGeomSurf->Cone();
1022 Standard_Real a1 = Abs(aCon1.SemiAngle());
1023 bToCheck = (a1 < 0.02) || (a1 > 1.55);
1025 if (typs1 == typs2) {
1026 const gp_Cone aCon2 = aGeomSurf->Cone();
1027 Standard_Real a2 = Abs(aCon2.SemiAngle());
1028 bToCheck = bToCheck || (a2 < 0.02) || (a2 > 1.55);
1030 if (a1 > 1.55 && a2 > 1.55) {//quasi-planes: if same domain, treat as canonic
1031 const gp_Ax1 A1 = aCon1.Axis(), A2 = aCon2.Axis();
1032 if (A1.IsParallel(A2,Precision::Angular())) {
1033 const gp_Pnt Apex1 = aCon1.Apex(), Apex2 = aCon2.Apex();
1034 const gp_Pln Plan1( Apex1, A1.Direction() );
1035 if (Plan1.Distance( Apex2 ) <= Precision::Confusion()) {
1036 bToCheck = Standard_False;
1042 TreatAsBiParametric = bToCheck;
1043 if (aCTType == GeomAbs_Cone) {
1044 aCTAx = aCon1.Axis();
1048 if (typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
1049 const gp_Torus aTor1 = (aCTType == GeomAbs_Torus) ?
1050 aCTSurf->Torus() : aGeomSurf->Torus();
1051 bToCheck = aTor1.MajorRadius() > aTor1.MinorRadius();
1052 if (typs1 == typs2) {
1053 const gp_Torus aTor2 = aGeomSurf->Torus();
1054 bToCheck = aTor2.MajorRadius() > aTor2.MinorRadius();
1057 if (aCTType == GeomAbs_Torus) {
1058 aCTAx = aTor1.Axis();
1063 const gp_Lin aL1(aCTAx);
1065 switch (aGeomSurf->GetType()) {
1066 case GeomAbs_Plane: {
1067 aGeomAx = aGeomSurf->Plane().Axis();
1068 if (aCTType == GeomAbs_Cone) {
1070 if (Abs(aCTSurf->Cone().SemiAngle()) < 0.02) {
1071 Standard_Real ps = Abs(aCTAx.Direction().Dot(aGeomAx.Direction()));
1078 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) ||
1079 (aCTAx.IsNormal(aGeomAx, Precision::Angular()) &&
1080 (aGeomSurf->Plane().Distance(aCTAx.Location()) < Precision::Confusion()))) {
1084 bToCheck = Standard_False;
1087 case GeomAbs_Sphere: {
1088 if (aL1.Distance(aGeomSurf->Sphere().Location()) < Precision::Confusion()) {
1091 bToCheck = Standard_False;
1094 case GeomAbs_Cylinder:
1095 aGeomAx = aGeomSurf->Cylinder().Axis();
1098 aGeomAx = aGeomSurf->Cone().Axis();
1101 aGeomAx = aGeomSurf->Torus().Axis();
1104 bToCheck = Standard_False;
1109 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) &&
1110 (aL1.Distance(aGeomAx.Location()) <= Precision::Confusion())) {
1115 if (bGeomGeom == 1) {
1116 TreatAsBiParametric = Standard_False;
1122 if(theD1->DomainIsInfinite() || theD2->DomainIsInfinite()) {
1123 TreatAsBiParametric= Standard_False;
1126 if(TreatAsBiParametric)
1128 // Using Prm-Prm Intersector
1129 typs1 = GeomAbs_BezierSurface;
1130 typs2 = GeomAbs_BezierSurface;
1133 // Surface type definition
1134 Standard_Integer ts1 = 0;
1138 case GeomAbs_Cylinder:
1139 case GeomAbs_Sphere:
1140 case GeomAbs_Cone: ts1 = 1; break;
1141 case GeomAbs_Torus: ts1 = bGeomGeom; break;
1145 Standard_Integer ts2 = 0;
1149 case GeomAbs_Cylinder:
1150 case GeomAbs_Sphere:
1151 case GeomAbs_Cone: ts2 = 1; break;
1152 case GeomAbs_Torus: ts2 = bGeomGeom; break;
1156 // Possible intersection types: 1. ts1 == ts2 == 1 <Geom-Geom>
1157 // 2. ts1 != ts2 <Geom-Param>
1158 // 3. ts1 == ts2 == 0 <Param-Param>
1162 ParamParamPerfom(theS1, theD1, theS2, theD2,
1163 TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
1167 GeomParamPerfom(theS1, theD1, theS2, theD2, ts1 == 0, typs1, typs2);
1171 ParamParamPerfom(theS1, theD1, theS2, theD2,
1172 TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
1176 GeomGeomPerfom(theS1, theD1, theS2, theD2, TolArc,
1177 TolTang, ListOfPnts, RestrictLine, typs1, typs2, theIsReqToKeepRLine);
1180 if(!theIsReqToPostWLProc)
1183 for(Standard_Integer i = slin.Lower(); i <= slin.Upper(); i++)
1185 Handle(IntPatch_WLine) aWL = Handle(IntPatch_WLine)::DownCast(slin.Value(i));
1190 if(!aWL->IsPurgingAllowed())
1193 Handle(IntPatch_WLine) aRW =
1194 IntPatch_WLineTool::ComputePurgedWLine(aWL, theS1, theS2, theD1, theD2, RestrictLine);
1199 slin.InsertAfter(i, aRW);
1204 //=======================================================================
1205 //function : ParamParamPerfom
1207 //=======================================================================
1208 void IntPatch_Intersection::ParamParamPerfom(const Handle(Adaptor3d_HSurface)& theS1,
1209 const Handle(Adaptor3d_TopolTool)& theD1,
1210 const Handle(Adaptor3d_HSurface)& theS2,
1211 const Handle(Adaptor3d_TopolTool)& theD2,
1212 const Standard_Real TolArc,
1213 const Standard_Real TolTang,
1214 IntSurf_ListOfPntOn2S& ListOfPnts,
1215 const Standard_Boolean RestrictLine,
1216 const GeomAbs_SurfaceType typs1,
1217 const GeomAbs_SurfaceType typs2)
1219 IntPatch_PrmPrmIntersection interpp;
1220 if(!theD1->DomainIsInfinite() && !theD2->DomainIsInfinite())
1222 Standard_Boolean ClearFlag = Standard_True;
1223 if(!ListOfPnts.IsEmpty())
1225 interpp.Perform(theS1,theD1,theS2,theD2,TolTang,TolArc,myFleche,myUVMaxStep, ListOfPnts, RestrictLine);
1226 ClearFlag = Standard_False;
1228 interpp.Perform(theS1,theD1,theS2,theD2,TolTang,TolArc,myFleche,myUVMaxStep,ClearFlag); //double call!!!!!!!
1230 else if((theD1->DomainIsInfinite()) ^ (theD2->DomainIsInfinite()))
1232 gp_Pnt pMaxXYZ, pMinXYZ;
1233 if(theD1->DomainIsInfinite())
1235 FUN_GetMinMaxXYZPnt( theS2, pMinXYZ, pMaxXYZ );
1236 const Standard_Real MU = Max(Abs(theS2->FirstUParameter()),Abs(theS2->LastUParameter()));
1237 const Standard_Real MV = Max(Abs(theS2->FirstVParameter()),Abs(theS2->LastVParameter()));
1238 const Standard_Real AP = Max(MU, MV);
1239 Handle(Adaptor3d_HSurface) SS;
1240 FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, theS1, AP, SS);
1241 interpp.Perform(SS,theD1,theS2,theD2,TolTang,TolArc,myFleche,myUVMaxStep);
1245 FUN_GetMinMaxXYZPnt( theS1, pMinXYZ, pMaxXYZ );
1246 const Standard_Real MU = Max(Abs(theS1->FirstUParameter()),Abs(theS1->LastUParameter()));
1247 const Standard_Real MV = Max(Abs(theS1->FirstVParameter()),Abs(theS1->LastVParameter()));
1248 const Standard_Real AP = Max(MU, MV);
1249 Handle(Adaptor3d_HSurface) SS;
1250 FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, theS2, AP, SS);
1251 interpp.Perform(theS1, theD1, SS, theD2,TolTang, TolArc,myFleche,myUVMaxStep);
1253 }//(theD1->DomainIsInfinite()) ^ (theD2->DomainIsInfinite())
1256 if(typs1 == GeomAbs_OtherSurface || typs2 == GeomAbs_OtherSurface)
1258 done = Standard_False;
1262 Standard_Boolean IsPLInt = Standard_False;
1263 TColgp_SequenceOfPnt sop;
1265 FUN_PL_Intersection(theS1,typs1,theS2,typs2,IsPLInt,sop,v);
1269 if(sop.Length() > 0)
1271 for(Standard_Integer ip = 1; ip <= sop.Length(); ip++)
1273 gp_Lin lin(sop.Value(ip),gp_Dir(v));
1274 Handle(IntPatch_Line) gl = new IntPatch_GLine(lin,Standard_False);
1278 done = Standard_True;
1281 done = Standard_False;
1284 }// 'COLLINEAR LINES'
1287 Handle(Adaptor3d_HSurface) nS1 = theS1;
1288 Handle(Adaptor3d_HSurface) nS2 = theS2;
1289 FUN_TrimBothSurf(theS1,typs1,theS2,typs2,1.e+8,nS1,nS2);
1290 interpp.Perform(nS1,theD1,nS2,theD2,TolTang,TolArc,myFleche,myUVMaxStep);
1291 }// 'NON - COLLINEAR LINES'
1292 }// both domains are infinite
1294 if (interpp.IsDone())
1296 done = Standard_True;
1297 tgte = Standard_False;
1298 empt = interpp.IsEmpty();
1300 for(Standard_Integer i = 1; i <= interpp.NbLines(); i++)
1302 if(interpp.Line(i)->ArcType() != IntPatch_Walking)
1303 slin.Append(interpp.Line(i));
1306 for (Standard_Integer i = 1; i <= interpp.NbLines(); i++)
1308 if(interpp.Line(i)->ArcType() == IntPatch_Walking)
1309 slin.Append(interpp.Line(i));
1314 //=======================================================================
1315 ////function : GeomGeomPerfom
1317 //=======================================================================
1318 void IntPatch_Intersection::GeomGeomPerfom(const Handle(Adaptor3d_HSurface)& theS1,
1319 const Handle(Adaptor3d_TopolTool)& theD1,
1320 const Handle(Adaptor3d_HSurface)& theS2,
1321 const Handle(Adaptor3d_TopolTool)& theD2,
1322 const Standard_Real TolArc,
1323 const Standard_Real TolTang,
1324 IntSurf_ListOfPntOn2S& ListOfPnts,
1325 const Standard_Boolean RestrictLine,
1326 const GeomAbs_SurfaceType theTyps1,
1327 const GeomAbs_SurfaceType theTyps2,
1328 const Standard_Boolean theIsReqToKeepRLine)
1330 IntPatch_ImpImpIntersection interii(theS1,theD1,theS2,theD2,
1331 myTolArc,myTolTang, theIsReqToKeepRLine);
1332 const Standard_Boolean anIS = interii.IsDone();
1336 empt = interii.IsEmpty();
1339 tgte = interii.TangentFaces();
1341 oppo = interii.OppositeFaces();
1343 Standard_Boolean isQuadSet = Standard_False;
1344 IntSurf_Quadric Quad1,Quad2;
1346 for (Standard_Integer i = 1; i <= interii.NbLines(); i++)
1348 const Handle(IntPatch_Line)& line = interii.Line(i);
1349 if (line->ArcType() == IntPatch_Analytic)
1353 isQuadSet = Standard_True;
1355 const GeomAbs_SurfaceType aTyps1 = theS1->GetType();
1356 const GeomAbs_SurfaceType aTyps2 = theS2->GetType();
1361 Quad1.SetValue(theS1->Plane());
1364 case GeomAbs_Cylinder:
1365 Quad1.SetValue(theS1->Cylinder());
1368 case GeomAbs_Sphere:
1369 Quad1.SetValue(theS1->Sphere());
1373 Quad1.SetValue(theS1->Cone());
1377 Quad1.SetValue(theS1->Torus());
1381 isQuadSet = Standard_False;
1388 Quad2.SetValue(theS2->Plane());
1390 case GeomAbs_Cylinder:
1391 Quad2.SetValue(theS2->Cylinder());
1394 case GeomAbs_Sphere:
1395 Quad2.SetValue(theS2->Sphere());
1399 Quad2.SetValue(theS2->Cone());
1403 Quad2.SetValue(theS2->Torus());
1407 isQuadSet = Standard_False;
1417 IntPatch_ALineToWLine AToW(Quad1,Quad2,0.01,0.05,aNbPointsInALine);
1418 Handle(IntPatch_WLine) wlin =
1419 AToW.MakeWLine(Handle(IntPatch_ALine)::DownCast(line));
1420 wlin->EnablePurging(Standard_False);
1425 if(line->ArcType() == IntPatch_Walking)
1427 Handle(IntPatch_WLine)::DownCast(line)->EnablePurging(Standard_False);
1434 for (Standard_Integer i = 1; i <= interii.NbPnts(); i++)
1436 spnt.Append(interii.Point(i));
1439 if((theTyps1 == GeomAbs_Cylinder) && (theTyps2 == GeomAbs_Cylinder))
1441 IntPatch_WLineTool::JoinWLines( slin, spnt, TolTang,
1442 theS1->IsUPeriodic()? theS1->UPeriod() : 0.0,
1443 theS2->IsUPeriodic()? theS2->UPeriod() : 0.0,
1444 theS1->IsVPeriodic()? theS1->VPeriod() : 0.0,
1445 theS2->IsVPeriodic()? theS2->VPeriod() : 0.0,
1446 theS1->FirstUParameter(),
1447 theS1->LastUParameter(),
1448 theS1->FirstVParameter(),
1449 theS1->LastVParameter(),
1450 theS2->FirstUParameter(),
1451 theS2->LastUParameter(),
1452 theS2->FirstVParameter(),
1453 theS2->LastVParameter());
1458 Bnd_Box2d aBx1, aBx2;
1459 const Standard_Real aU1F = theS1->FirstUParameter(),
1460 aU1L = theS1->LastUParameter(),
1461 aV1F = theS1->FirstVParameter(),
1462 aV1L = theS1->LastVParameter(),
1463 aU2F = theS2->FirstUParameter(),
1464 aU2L = theS2->LastUParameter(),
1465 aV2F = theS2->FirstVParameter(),
1466 aV2L = theS2->LastVParameter();
1467 aBx1.Add(gp_Pnt2d(aU1F, aV1F));
1468 aBx1.Add(gp_Pnt2d(aU1L, aV1F));
1469 aBx1.Add(gp_Pnt2d(aU1L, aV1L));
1470 aBx1.Add(gp_Pnt2d(aU1F, aV1L));
1471 aBx2.Add(gp_Pnt2d(aU2F, aV2F));
1472 aBx2.Add(gp_Pnt2d(aU2L, aV2F));
1473 aBx2.Add(gp_Pnt2d(aU2L, aV2L));
1474 aBx2.Add(gp_Pnt2d(aU2F, aV2L));
1476 aBx1.Enlarge(Precision::PConfusion());
1477 aBx2.Enlarge(Precision::PConfusion());
1479 IntPatch_WLineTool::
1480 ExtendTwoWlinesToEachOther(slin, Quad1, Quad2, TolTang,
1481 theS1->IsUPeriodic()? theS1->UPeriod() : 0.0,
1482 theS2->IsUPeriodic()? theS2->UPeriod() : 0.0,
1483 theS1->IsVPeriodic()? theS1->VPeriod() : 0.0,
1484 theS2->IsVPeriodic()? theS2->VPeriod() : 0.0,
1490 ParamParamPerfom(theS1, theD1, theS2, theD2,
1491 TolArc, TolTang, ListOfPnts, RestrictLine, theTyps1, theTyps2);
1494 //=======================================================================
1495 //function : GeomParamPerfom
1497 //=======================================================================
1498 void IntPatch_Intersection::
1499 GeomParamPerfom(const Handle(Adaptor3d_HSurface)& theS1,
1500 const Handle(Adaptor3d_TopolTool)& theD1,
1501 const Handle(Adaptor3d_HSurface)& theS2,
1502 const Handle(Adaptor3d_TopolTool)& theD2,
1503 const Standard_Boolean isNotAnalitical,
1504 const GeomAbs_SurfaceType typs1,
1505 const GeomAbs_SurfaceType typs2)
1507 IntPatch_ImpPrmIntersection interip;
1510 if (isNotAnalitical/*ts1 == 0*/)
1511 interip.SetStartPoint(myU1Start,myV1Start);
1513 interip.SetStartPoint(myU2Start,myV2Start);
1516 if(theD1->DomainIsInfinite() && theD2->DomainIsInfinite())
1518 Standard_Boolean IsPLInt = Standard_False;
1519 TColgp_SequenceOfPnt sop;
1521 FUN_PL_Intersection(theS1,typs1,theS2,typs2,IsPLInt,sop,v);
1525 if(sop.Length() > 0)
1527 for(Standard_Integer ip = 1; ip <= sop.Length(); ip++)
1529 gp_Lin lin(sop.Value(ip),gp_Dir(v));
1530 Handle(IntPatch_Line) gl = new IntPatch_GLine(lin,Standard_False);
1534 done = Standard_True;
1537 done = Standard_False;
1543 Handle(Adaptor3d_HSurface) nS1 = theS1;
1544 Handle(Adaptor3d_HSurface) nS2 = theS2;
1545 FUN_TrimBothSurf(theS1,typs1,theS2,typs2,1.e+5,nS1,nS2);
1546 interip.Perform(nS1,theD1,nS2,theD2,myTolArc,myTolTang,myFleche,myUVMaxStep);
1550 interip.Perform(theS1,theD1,theS2,theD2,myTolArc,myTolTang,myFleche,myUVMaxStep);
1552 if (interip.IsDone())
1554 done = Standard_True;
1555 empt = interip.IsEmpty();
1559 const Standard_Integer aNbLines = interip.NbLines();
1560 for(Standard_Integer i = 1; i <= aNbLines; i++)
1562 if(interip.Line(i)->ArcType() != IntPatch_Walking)
1563 slin.Append(interip.Line(i));
1566 for(Standard_Integer i = 1; i <= aNbLines; i++)
1568 if(interip.Line(i)->ArcType() == IntPatch_Walking)
1569 slin.Append(interip.Line(i));
1572 for (Standard_Integer i = 1; i <= interip.NbPnts(); i++)
1573 spnt.Append(interip.Point(i));
1578 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& S1,
1579 const Handle(Adaptor3d_TopolTool)& D1,
1580 const Handle(Adaptor3d_HSurface)& S2,
1581 const Handle(Adaptor3d_TopolTool)& D2,
1582 const Standard_Real U1,
1583 const Standard_Real V1,
1584 const Standard_Real U2,
1585 const Standard_Real V2,
1586 const Standard_Real TolArc,
1587 const Standard_Real TolTang)
1590 myTolTang = TolTang;
1591 if(myFleche == 0.0) {
1593 //cout<<" -- IntPatch_Intersection::myFleche fixe par defaut a 0.01 --"<<endl;
1594 //cout<<" -- Utiliser la Methode SetTolerances( ... ) "<<endl;
1598 if(myUVMaxStep==0.0) {
1600 //cout<<" -- IntPatch_Intersection::myUVMaxStep fixe par defaut a 0.01 --"<<endl;
1601 //cout<<" -- Utiliser la Methode SetTolerances( ... ) "<<endl;
1606 done = Standard_False;
1610 empt = Standard_True;
1611 tgte = Standard_False;
1612 oppo = Standard_False;
1614 const GeomAbs_SurfaceType typs1 = S1->GetType();
1615 const GeomAbs_SurfaceType typs2 = S2->GetType();
1617 if( typs1==GeomAbs_Plane
1618 || typs1==GeomAbs_Cylinder
1619 || typs1==GeomAbs_Sphere
1620 || typs1==GeomAbs_Cone
1621 || typs2==GeomAbs_Plane
1622 || typs2==GeomAbs_Cylinder
1623 || typs2==GeomAbs_Sphere
1624 || typs2==GeomAbs_Cone)
1626 myIsStartPnt = Standard_True;
1627 myU1Start = U1; myV1Start = V1; myU2Start = U2; myV2Start = V2;
1628 Perform(S1,D1,S2,D2,TolArc,TolTang);
1629 myIsStartPnt = Standard_False;
1633 IntPatch_PrmPrmIntersection interpp;
1634 interpp.Perform(S1,D1,S2,D2,U1,V1,U2,V2,TolTang,TolArc,myFleche,myUVMaxStep);
1635 if (interpp.IsDone())
1637 done = Standard_True;
1638 tgte = Standard_False;
1639 empt = interpp.IsEmpty();
1640 const Standard_Integer nblm = interpp.NbLines();
1641 Standard_Integer i = 1;
1642 for (; i<=nblm; i++) slin.Append(interpp.Line(i));
1646 for(Standard_Integer i = slin.Lower(); i <= slin.Upper(); i++)
1648 Handle(IntPatch_WLine) aWL = Handle(IntPatch_WLine)::DownCast(slin.Value(i));
1653 Handle(IntPatch_WLine) aRW =
1654 IntPatch_WLineTool::ComputePurgedWLine(aWL, S1, S2, D1, D2, Standard_True);
1659 slin.InsertAfter(i, aRW);
1664 #ifdef DUMPOFIntPatch_Intersection
1666 void IntPatch_Intersection__MAJ_R(Handle(Adaptor2d_HCurve2d) *R1,
1667 Handle(Adaptor2d_HCurve2d) *,
1670 Standard_Integer nbR1,
1672 const IntPatch_Point& VTX)
1675 if(VTX.IsOnDomS1()) {
1677 //-- long unsigned ptr= *((long unsigned *)(((Handle(Standard_Transient) *)(&(VTX.ArcOnS1())))));
1678 for(Standard_Integer i=0; i<nbR1;i++) {
1679 if(VTX.ArcOnS1()==R1[i]) {
1681 printf("\n ******************************");
1685 printf("\n R Pas trouvee (IntPatch)\n");
1691 void IntPatch_Intersection::Dump(const Standard_Integer /*Mode*/,
1692 const Handle(Adaptor3d_HSurface)& /*S1*/,
1693 const Handle(Adaptor3d_TopolTool)& /*D1*/,
1694 const Handle(Adaptor3d_HSurface)& /*S2*/,
1695 const Handle(Adaptor3d_TopolTool)& /*D2*/) const
1697 #ifdef DUMPOFIntPatch_Intersection
1698 const int MAXR = 200;
1699 //-- ----------------------------------------------------------------------
1700 //-- construction de la liste des restrictions & vertex
1702 int NR1[MAXR],NR2[MAXR];
1703 Handle(Adaptor2d_HCurve2d) R1[MAXR],R2[MAXR];
1704 Standard_Integer nbR1=0,nbR2=0;
1705 for(D1->Init();D1->More() && nbR1<MAXR; D1->Next()) {
1706 R1[nbR1]=D1->Value();
1710 for(D2->Init();D2->More() && nbR2<MAXR; D2->Next()) {
1711 R2[nbR2]=D2->Value();
1716 printf("\nDUMP_INT: ----empt:%2ud tgte:%2ud oppo:%2ud ---------------------------------",empt,tgte,empt);
1717 Standard_Integer i,nbr1,nbr2,nbgl,nbgc,nbge,nbgp,nbgh,nbl,nbr,nbg,nbw,nba;
1718 nbl=nbr=nbg=nbw=nba=nbgl=nbge=nbr1=nbr2=nbgc=nbgp=nbgh=0;
1720 for(i=1;i<=nbl;i++) {
1721 const Handle(IntPatch_Line)& line=Line(i);
1722 const IntPatch_IType IType=line->ArcType();
1723 if(IType == IntPatch_Walking) nbw++;
1724 else if(IType == IntPatch_Restriction) {
1726 Handle(IntPatch_RLine) rlin (Handle(IntPatch_RLine)::DownCast (line));
1727 if(rlin->IsArcOnS1()) nbr1++;
1728 if(rlin->IsArcOnS2()) nbr2++;
1730 else if(IType == IntPatch_Analytic) nba++;
1733 if(IType == IntPatch_Lin) nbgl++;
1734 else if(IType == IntPatch_Circle) nbgc++;
1735 else if(IType == IntPatch_Parabola) nbgp++;
1736 else if(IType == IntPatch_Hyperbola) nbgh++;
1737 else if(IType == IntPatch_Ellipse) nbge++;
1742 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)",
1743 nbl,nbw,nbr,nbr1,nbr2,nba,nbg,nbgl,nbgc,nbge,nbgh,nbgp);
1745 IntPatch_LineConstructor LineConstructor(2);
1747 Standard_Integer nbllc=0;
1749 Standard_Integer nbva,nbvw,nbvr,nbvg;
1750 nbva=nbvr=nbvw=nbvg=0;
1751 for (j=1; j<=nbl; j++) {
1752 Standard_Integer v,nbvtx;
1753 const Handle(IntPatch_Line)& intersLinej = Line(j);
1754 Standard_Integer NbLines;
1755 LineConstructor.Perform(SequenceOfLine(),intersLinej,S1,D1,S2,D2,1e-7);
1756 NbLines = LineConstructor.NbLines();
1758 for(Standard_Integer k=1;k<=NbLines;k++) {
1760 const Handle(IntPatch_Line)& LineK = LineConstructor.Line(k);
1761 if (LineK->ArcType() == IntPatch_Analytic) {
1762 Handle(IntPatch_ALine) alin (Handle(IntPatch_ALine)::DownCast (LineK));
1763 nbvtx=alin->NbVertex();
1765 for(v=1;v<=nbvtx;v++) {
1766 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,alin->Vertex(v));
1769 else if (LineK->ArcType() == IntPatch_Restriction) {
1770 Handle(IntPatch_RLine) rlin (Handle(IntPatch_RLine)::DownCast (LineK));
1771 nbvtx=rlin->NbVertex();
1773 for(v=1;v<=nbvtx;v++) {
1774 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,rlin->Vertex(v));
1777 else if (LineK->ArcType() == IntPatch_Walking) {
1778 Handle(IntPatch_WLine) wlin (Handle(IntPatch_WLine)::DownCast (LineK));
1779 nbvtx=wlin->NbVertex();
1781 for(v=1;v<=nbvtx;v++) {
1782 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,wlin->Vertex(v));
1786 Handle(IntPatch_GLine) glin (Handle(IntPatch_GLine)::DownCast (LineK));
1787 nbvtx=glin->NbVertex();
1789 for(v=1;v<=nbvtx;v++) {
1790 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,glin->Vertex(v));
1795 printf("\nDUMP_LC :Lines:%2d WLin:%2d Restr:%2d Ana:%2d Geom:%2d",
1796 nbllc,nbw,nbr,nba,nbg);
1797 printf("\nDUMP_LC :vtx :%2d r:%2d :%2d :%2d",
1798 nbvw,nbvr,nbva,nbvg);