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.ixx>
17 #include <IntPatch_ALineToWLine.hxx>
18 #include <IntPatch_GLine.hxx>
19 #include <IntPatch_ALine.hxx>
20 #include <IntPatch_WLine.hxx>
21 #include <IntPatch_RLine.hxx>
22 #include <IntPatch_PrmPrmIntersection.hxx>
23 #include <IntPatch_ImpPrmIntersection.hxx>
24 #include <IntPatch_ImpImpIntersection.hxx>
25 #include <IntSurf_Quadric.hxx>
30 static const Standard_Integer aNbPointsInALine = 200;
32 //======================================================================
33 // function: SequenceOfLine
34 //======================================================================
35 const IntPatch_SequenceOfLine& IntPatch_Intersection::SequenceOfLine() const { return(slin); }
37 //======================================================================
38 // function: IntPatch_Intersection
39 //======================================================================
40 IntPatch_Intersection::IntPatch_Intersection ()
41 : done(Standard_False),
43 myTolArc(0.0), myTolTang(0.0),
44 myUVMaxStep(0.0), myFleche(0.0),
45 myIsStartPnt(Standard_False)
46 //myU1Start, myV1Start, myU2Start, myV2Start
50 //======================================================================
51 // function: IntPatch_Intersection
52 //======================================================================
53 IntPatch_Intersection::IntPatch_Intersection(const Handle(Adaptor3d_HSurface)& S1,
54 const Handle(Adaptor3d_TopolTool)& D1,
55 const Handle(Adaptor3d_HSurface)& S2,
56 const Handle(Adaptor3d_TopolTool)& D2,
57 const Standard_Real TolArc,
58 const Standard_Real TolTang)
59 : done(Standard_False),
61 myTolArc(TolArc), myTolTang(TolTang),
62 myUVMaxStep(0.0), myFleche(0.0),
63 myIsStartPnt(Standard_False)
64 //myU1Start, myV1Start, myU2Start, myV2Start
66 if(myTolArc<1e-8) myTolArc=1e-8;
67 if(myTolTang<1e-8) myTolTang=1e-8;
68 if(myTolArc>0.5) myTolArc=0.5;
69 if(myTolTang>0.5) myTolTang=0.5;
70 Perform(S1,D1,S2,D2,TolArc,TolTang);
73 //======================================================================
74 // function: IntPatch_Intersection
75 //======================================================================
76 IntPatch_Intersection::IntPatch_Intersection(const Handle(Adaptor3d_HSurface)& S1,
77 const Handle(Adaptor3d_TopolTool)& D1,
78 const Standard_Real TolArc,
79 const Standard_Real TolTang)
80 : done(Standard_False),
82 myTolArc(TolArc), myTolTang(TolTang),
83 myUVMaxStep(0.0), myFleche(0.0),
84 myIsStartPnt(Standard_False)
85 //myU1Start, myV1Start, myU2Start, myV2Start
87 Perform(S1,D1,TolArc,TolTang);
90 //======================================================================
91 // function: SetTolerances
92 //======================================================================
93 void IntPatch_Intersection::SetTolerances(const Standard_Real TolArc,
94 const Standard_Real TolTang,
95 const Standard_Real UVMaxStep,
96 const Standard_Real Fleche)
100 myUVMaxStep = UVMaxStep;
102 if(myTolArc<1e-8) myTolArc=1e-8;
103 if(myTolTang<1e-8) myTolTang=1e-8;
104 if(myTolArc>0.5) myTolArc=0.5;
105 if(myTolTang>0.5) myTolTang=0.5;
106 if(myFleche<1.0e-3) myFleche=1e-3;
107 if(myUVMaxStep<1.0e-3) myUVMaxStep=1e-3;
108 if(myFleche>10) myFleche=10;
109 if(myUVMaxStep>0.5) myUVMaxStep=0.5;
112 //======================================================================
114 //======================================================================
115 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& S1,
116 const Handle(Adaptor3d_TopolTool)& D1,
117 const Standard_Real TolArc,
118 const Standard_Real TolTang)
122 if(myFleche == 0.0) myFleche = 0.01;
123 if(myUVMaxStep==0.0) myUVMaxStep = 0.01;
125 done = Standard_True;
129 empt = Standard_True;
130 tgte = Standard_False;
131 oppo = Standard_False;
133 switch (S1->GetType())
136 case GeomAbs_Cylinder:
139 case GeomAbs_Torus: break;
142 IntPatch_PrmPrmIntersection interpp;
143 interpp.Perform(S1,D1,TolArc,TolTang,myFleche,myUVMaxStep);
144 if (interpp.IsDone())
146 done = Standard_True;
147 tgte = Standard_False;
148 empt = interpp.IsEmpty();
149 const Standard_Integer nblm = interpp.NbLines();
150 for (Standard_Integer i=1; i<=nblm; i++) slin.Append(interpp.Line(i));
157 /////////////////////////////////////////////////////////////////////////////
158 // These several support functions provide methods which can help basic //
159 // algorithm to intersect infinite surfaces of the following types: //
161 // a.) SurfaceOfExtrusion; //
162 // b.) SurfaceOfRevolution; //
163 // c.) OffsetSurface. //
165 /////////////////////////////////////////////////////////////////////////////
166 #include <TColgp_Array1OfXYZ.hxx>
167 #include <TColgp_Array1OfPnt.hxx>
168 #include <TColgp_SequenceOfPnt.hxx>
169 #include <Extrema_ExtPS.hxx>
170 #include <Extrema_POnSurf.hxx>
171 #include <Geom2d_Curve.hxx>
172 #include <Geom2dAPI_InterCurveCurve.hxx>
173 #include <GeomAdaptor.hxx>
174 #include <GeomAdaptor_HCurve.hxx>
175 #include <GeomAdaptor_Curve.hxx>
176 #include <GeomAdaptor_Surface.hxx>
177 #include <GeomAdaptor_HSurface.hxx>
178 #include <Geom_Plane.hxx>
179 #include <ProjLib_ProjectOnPlane.hxx>
180 #include <GeomProjLib.hxx>
181 #include <ElCLib.hxx>
182 #include <Geom_TrimmedCurve.hxx>
183 #include <Geom_Surface.hxx>
184 #include <Geom_SurfaceOfLinearExtrusion.hxx>
185 #include <Geom_OffsetSurface.hxx>
186 #include <Geom_SurfaceOfRevolution.hxx>
187 #include <Geom_RectangularTrimmedSurface.hxx>
189 //===============================================================
190 //function: FUN_GetMinMaxXYZPnt
191 //===============================================================
192 static void FUN_GetMinMaxXYZPnt( const Handle(Adaptor3d_HSurface)& S,
193 gp_Pnt& pMin, gp_Pnt& pMax )
195 const Standard_Real DU = 0.25 * Abs(S->LastUParameter() - S->FirstUParameter());
196 const Standard_Real DV = 0.25 * Abs(S->LastVParameter() - S->FirstVParameter());
197 Standard_Real tMinXYZ = RealLast();
198 Standard_Real tMaxXYZ = -tMinXYZ;
199 gp_Pnt PUV, ptMax, ptMin;
200 for(Standard_Real U = S->FirstUParameter(); U <= S->LastUParameter(); U += DU)
202 for(Standard_Real V = S->FirstVParameter(); V <= S->LastVParameter(); V += DV)
205 const Standard_Real cXYZ = PUV.XYZ().Modulus();
206 if(cXYZ > tMaxXYZ) { tMaxXYZ = cXYZ; ptMax = PUV; }
207 if(cXYZ < tMinXYZ) { tMinXYZ = cXYZ; ptMin = PUV; }
213 //==========================================================================
214 //function: FUN_TrimInfSurf
215 //==========================================================================
216 static void FUN_TrimInfSurf(const gp_Pnt& Pmin,
218 const Handle(Adaptor3d_HSurface)& InfSurf,
219 const Standard_Real& AlternativeTrimPrm,
220 Handle(Adaptor3d_HSurface)& TrimS)
222 Standard_Real TP = AlternativeTrimPrm;
223 Extrema_ExtPS ext1(Pmin, InfSurf->Surface(), 1.e-7, 1.e-7);
224 Extrema_ExtPS ext2(Pmax, InfSurf->Surface(), 1.e-7, 1.e-7);
225 if(ext1.IsDone() || ext2.IsDone())
227 Standard_Real Umax = -1.e+100, Umin = 1.e+100, Vmax = -1.e+100, Vmin = 1.e+100, cU, cV;
230 for(Standard_Integer i = 1; i <= ext1.NbExt(); i++)
232 const Extrema_POnSurf & pons = ext1.Point(i);
233 pons.Parameter(cU,cV);
234 if(cU > Umax) Umax = cU;
235 if(cU < Umin) Umin = cU;
236 if(cV > Vmax) Vmax = cV;
237 if(cV < Vmin) Vmin = cV;
242 for(Standard_Integer i = 1; i <= ext2.NbExt(); i++)
244 const Extrema_POnSurf & pons = ext2.Point(i);
245 pons.Parameter(cU,cV);
246 if(cU > Umax) Umax = cU;
247 if(cU < Umin) Umin = cU;
248 if(cV > Vmax) Vmax = cV;
249 if(cV < Vmin) Vmin = cV;
252 TP = Max(Abs(Umin),Max(Abs(Umax),Max(Abs(Vmin),Abs(Vmax))));
254 if(TP == 0.) { TrimS = InfSurf; return; }
257 const Standard_Boolean Uinf = Precision::IsNegativeInfinite(InfSurf->FirstUParameter());
258 const Standard_Boolean Usup = Precision::IsPositiveInfinite(InfSurf->LastUParameter());
259 const Standard_Boolean Vinf = Precision::IsNegativeInfinite(InfSurf->FirstVParameter());
260 const Standard_Boolean Vsup = Precision::IsPositiveInfinite(InfSurf->LastVParameter());
261 Handle(Adaptor3d_HSurface) TmpSS;
262 Standard_Integer IsTrimed = 0;
263 const Standard_Real tp = 1000.0 * TP;
264 if(Vinf && Vsup) { TrimS = InfSurf->VTrim(-tp, tp, 1.0e-7); IsTrimed = 1; }
265 if(Vinf && !Vsup){ TrimS = InfSurf->VTrim(-tp, InfSurf->LastVParameter(), 1.0e-7); IsTrimed = 1; }
266 if(!Vinf && Vsup){ TrimS = InfSurf->VTrim(InfSurf->FirstVParameter(), tp, 1.0e-7); IsTrimed = 1; }
270 if(Uinf && Usup) TrimS = TmpSS->UTrim(-tp, tp, 1.0e-7);
271 if(Uinf && !Usup) TrimS = TmpSS->UTrim(-tp, InfSurf->LastUParameter(), 1.0e-7);
272 if(!Uinf && Usup) TrimS = TmpSS->UTrim(InfSurf->FirstUParameter(), tp, 1.0e-7);
276 if(Uinf && Usup) TrimS = InfSurf->UTrim(-tp, tp, 1.0e-7);
277 if(Uinf && !Usup) TrimS = InfSurf->UTrim(-tp, InfSurf->LastUParameter(), 1.0e-7);
278 if(!Uinf && Usup) TrimS = InfSurf->UTrim(InfSurf->FirstUParameter(), tp, 1.0e-7);
282 //================================================================================
283 //function: FUN_GetUiso
284 //================================================================================
285 static void FUN_GetUiso(const Handle(Geom_Surface)& GS,
286 const GeomAbs_SurfaceType& T,
287 const Standard_Real& FirstV,
288 const Standard_Real& LastV,
289 const Standard_Boolean& IsVC,
290 const Standard_Boolean& IsVP,
291 const Standard_Real& U,
292 Handle(Geom_Curve)& I)
294 if(T != GeomAbs_OffsetSurface)
296 Handle(Geom_Curve) gc = GS->UIso(U);
297 if(IsVP && (FirstV == 0.0 && LastV == (2.*M_PI))) I = gc;
300 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstV,LastV);
301 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
307 const Handle(Geom_OffsetSurface) gos = *(Handle(Geom_OffsetSurface)*)&GS;
308 const Handle(Geom_Surface) bs = gos->BasisSurface();
309 Handle(Geom_Curve) gcbs = bs->UIso(U);
310 GeomAdaptor_Curve gac(gcbs);
311 const GeomAbs_CurveType GACT = gac.GetType();
312 if(IsVP || IsVC || GACT == GeomAbs_BSplineCurve || GACT == GeomAbs_BezierCurve || Abs(LastV - FirstV) < 1.e+5)
314 Handle(Geom_Curve) gc = gos->UIso(U);
315 if(IsVP && (FirstV == 0.0 && LastV == (2*M_PI))) I = gc;
318 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstV,LastV);
319 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
323 else//Offset Line, Parab, Hyperb
325 Standard_Real VmTr, VMTr;
326 if(GACT != GeomAbs_Hyperbola)
328 if(FirstV >= 0. && LastV >= 0.){ VmTr = FirstV; VMTr = ((LastV - FirstV) > 1.e+4) ? (FirstV + 1.e+4) : LastV; }
329 else if(FirstV < 0. && LastV < 0.){ VMTr = LastV; VmTr = ((FirstV - LastV) < -1.e+4) ? (LastV - 1.e+4) : FirstV; }
330 else { VmTr = (FirstV < -1.e+4) ? -1.e+4 : FirstV; VMTr = (LastV > 1.e+4) ? 1.e+4 : LastV; }
334 if(FirstV >= 0. && LastV >= 0.)
336 if(FirstV > 4.) return;
337 VmTr = FirstV; VMTr = (LastV > 4.) ? 4. : LastV;
339 else if(FirstV < 0. && LastV < 0.)
341 if(LastV < -4.) return;
342 VMTr = LastV; VmTr = (FirstV < -4.) ? -4. : FirstV;
344 else { VmTr = (FirstV < -4.) ? -4. : FirstV; VMTr = (LastV > 4.) ? 4. : LastV; }
346 //Make trimmed surface
347 Handle(Geom_RectangularTrimmedSurface) rts = new Geom_RectangularTrimmedSurface(gos,VmTr,VMTr,Standard_True);
352 //================================================================================
353 //function: FUN_GetViso
354 //================================================================================
355 static void FUN_GetViso(const Handle(Geom_Surface)& GS,
356 const GeomAbs_SurfaceType& T,
357 const Standard_Real& FirstU,
358 const Standard_Real& LastU,
359 const Standard_Boolean& IsUC,
360 const Standard_Boolean& IsUP,
361 const Standard_Real& V,
362 Handle(Geom_Curve)& I)
364 if(T != GeomAbs_OffsetSurface)
366 Handle(Geom_Curve) gc = GS->VIso(V);
367 if(IsUP && (FirstU == 0.0 && LastU == (2*M_PI))) I = gc;
370 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstU,LastU);
371 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
377 const Handle(Geom_OffsetSurface) gos = *(Handle(Geom_OffsetSurface)*)&GS;
378 const Handle(Geom_Surface) bs = gos->BasisSurface();
379 Handle(Geom_Curve) gcbs = bs->VIso(V);
380 GeomAdaptor_Curve gac(gcbs);
381 const GeomAbs_CurveType GACT = gac.GetType();
382 if(IsUP || IsUC || GACT == GeomAbs_BSplineCurve || GACT == GeomAbs_BezierCurve || Abs(LastU - FirstU) < 1.e+5)
384 Handle(Geom_Curve) gc = gos->VIso(V);
385 if(IsUP && (FirstU == 0.0 && LastU == (2*M_PI))) I = gc;
388 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstU,LastU);
389 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
393 else//Offset Line, Parab, Hyperb
395 Standard_Real UmTr, UMTr;
396 if(GACT != GeomAbs_Hyperbola)
398 if(FirstU >= 0. && LastU >= 0.){ UmTr = FirstU; UMTr = ((LastU - FirstU) > 1.e+4) ? (FirstU + 1.e+4) : LastU; }
399 else if(FirstU < 0. && LastU < 0.){ UMTr = LastU; UmTr = ((FirstU - LastU) < -1.e+4) ? (LastU - 1.e+4) : FirstU; }
400 else { UmTr = (FirstU < -1.e+4) ? -1.e+4 : FirstU; UMTr = (LastU > 1.e+4) ? 1.e+4 : LastU; }
404 if(FirstU >= 0. && LastU >= 0.)
406 if(FirstU > 4.) return;
407 UmTr = FirstU; UMTr = (LastU > 4.) ? 4. : LastU;
409 else if(FirstU < 0. && LastU < 0.)
411 if(LastU < -4.) return;
412 UMTr = LastU; UmTr = (FirstU < -4.) ? -4. : FirstU;
414 else { UmTr = (FirstU < -4.) ? -4. : FirstU; UMTr = (LastU > 4.) ? 4. : LastU; }
416 //Make trimmed surface
417 Handle(Geom_RectangularTrimmedSurface) rts = new Geom_RectangularTrimmedSurface(gos,UmTr,UMTr,Standard_True);
422 //================================================================================
423 //function: FUN_PL_Intersection
424 //================================================================================
425 static void FUN_PL_Intersection(const Handle(Adaptor3d_HSurface)& S1,
426 const GeomAbs_SurfaceType& T1,
427 const Handle(Adaptor3d_HSurface)& S2,
428 const GeomAbs_SurfaceType& T2,
429 Standard_Boolean& IsOk,
430 TColgp_SequenceOfPnt& SP,
433 IsOk = Standard_False;
434 // 1. Check: both surfaces have U(V)isos - lines.
435 DV = gp_Vec(0.,0.,1.);
436 Standard_Boolean isoS1isLine[2] = {0, 0};
437 Standard_Boolean isoS2isLine[2] = {0, 0};
438 Handle(Geom_Curve) C1, C2;
439 const GeomAdaptor_Surface & gas1 = *(GeomAdaptor_Surface*)(&(S1->Surface()));
440 const GeomAdaptor_Surface & gas2 = *(GeomAdaptor_Surface*)(&(S2->Surface()));
441 const Handle(Geom_Surface) gs1 = gas1.Surface();
442 const Handle(Geom_Surface) gs2 = gas2.Surface();
443 Standard_Real MS1[2], MS2[2];
444 MS1[0] = 0.5 * (S1->LastUParameter() + S1->FirstUParameter());
445 MS1[1] = 0.5 * (S1->LastVParameter() + S1->FirstVParameter());
446 MS2[0] = 0.5 * (S2->LastUParameter() + S2->FirstUParameter());
447 MS2[1] = 0.5 * (S2->LastVParameter() + S2->FirstVParameter());
448 if(T1 == GeomAbs_SurfaceOfExtrusion) isoS1isLine[0] = Standard_True;
449 else if(!S1->IsVPeriodic() && !S1->IsVClosed()) {
450 if(T1 != GeomAbs_OffsetSurface) C1 = gs1->UIso(MS1[0]);
452 const Handle(Geom_OffsetSurface) gos = *(Handle(Geom_OffsetSurface)*)&gs1;
453 const Handle(Geom_Surface) bs = gos->BasisSurface();
454 C1 = bs->UIso(MS1[0]);
456 GeomAdaptor_Curve gac(C1);
457 if(gac.GetType() == GeomAbs_Line) isoS1isLine[0] = Standard_True;
459 if(!S1->IsUPeriodic() && !S1->IsUClosed()) {
460 if(T1 != GeomAbs_OffsetSurface) C1 = gs1->VIso(MS1[1]);
462 const Handle(Geom_OffsetSurface) gos = *(Handle(Geom_OffsetSurface)*)&gs1;
463 const Handle(Geom_Surface) bs = gos->BasisSurface();
464 C1 = bs->VIso(MS1[1]);
466 GeomAdaptor_Curve gac(C1);
467 if(gac.GetType() == GeomAbs_Line) isoS1isLine[1] = Standard_True;
469 if(T2 == GeomAbs_SurfaceOfExtrusion) isoS2isLine[0] = Standard_True;
470 else if(!S2->IsVPeriodic() && !S2->IsVClosed()) {
471 if(T2 != GeomAbs_OffsetSurface) C2 = gs2->UIso(MS2[0]);
473 const Handle(Geom_OffsetSurface) gos = *(Handle(Geom_OffsetSurface)*)&gs2;
474 const Handle(Geom_Surface) bs = gos->BasisSurface();
475 C2 = bs->UIso(MS2[0]);
477 GeomAdaptor_Curve gac(C2);
478 if(gac.GetType() == GeomAbs_Line) isoS2isLine[0] = Standard_True;
480 if(!S2->IsUPeriodic() && !S2->IsUClosed()) {
481 if(T2 != GeomAbs_OffsetSurface) C2 = gs2->VIso(MS2[1]);
483 const Handle(Geom_OffsetSurface) gos = *(Handle(Geom_OffsetSurface)*)&gs2;
484 const Handle(Geom_Surface) bs = gos->BasisSurface();
485 C2 = bs->VIso(MS2[1]);
487 GeomAdaptor_Curve gac(C2);
488 if(gac.GetType() == GeomAbs_Line) isoS2isLine[1] = Standard_True;
490 Standard_Boolean IsBothLines = ((isoS1isLine[0] || isoS1isLine[1]) &&
491 (isoS2isLine[0] || isoS2isLine[1]));
495 // 2. Check: Uiso lines of both surfaces are collinear.
497 gp_Vec derS1[2], derS2[2];
498 S1->D1(MS1[0], MS1[1], puvS1, derS1[0], derS1[1]);
499 S2->D1(MS2[0], MS2[1], puvS2, derS2[0], derS2[1]);
500 C1.Nullify(); C2.Nullify();
501 Standard_Integer iso = 0;
502 if(isoS1isLine[0] && isoS2isLine[0] &&
503 derS1[1].IsParallel(derS2[1],Precision::Angular())) {
505 FUN_GetViso(gs1,T1,S1->FirstUParameter(),S1->LastUParameter(),
506 S1->IsUClosed(),S1->IsUPeriodic(),MS1[1],C1);
507 FUN_GetViso(gs2,T2,S2->FirstUParameter(),S2->LastUParameter(),
508 S2->IsUClosed(),S2->IsUPeriodic(),MS2[1],C2);
510 else if(isoS1isLine[0] && isoS2isLine[1] &&
511 derS1[1].IsParallel(derS2[0],Precision::Angular())) {
513 FUN_GetViso(gs1,T1,S1->FirstUParameter(),S1->LastUParameter(),
514 S1->IsUClosed(),S1->IsUPeriodic(),MS1[1],C1);
515 FUN_GetUiso(gs2,T2,S2->FirstVParameter(),S2->LastVParameter(),
516 S2->IsVClosed(),S2->IsVPeriodic(),MS2[0],C2);
518 else if(isoS1isLine[1] && isoS2isLine[0] &&
519 derS1[0].IsParallel(derS2[1],Precision::Angular())) {
521 FUN_GetUiso(gs1,T1,S1->FirstVParameter(),S1->LastVParameter(),
522 S1->IsVClosed(),S1->IsVPeriodic(),MS1[0],C1);
523 FUN_GetViso(gs2,T2,S2->FirstUParameter(),S2->LastUParameter(),
524 S2->IsUClosed(),S2->IsUPeriodic(),MS2[1],C2);
526 else if(isoS1isLine[1] && isoS2isLine[1] &&
527 derS1[0].IsParallel(derS2[0],Precision::Angular())) {
529 FUN_GetUiso(gs1,T1,S1->FirstVParameter(),S1->LastVParameter(),
530 S1->IsVClosed(),S1->IsVPeriodic(),MS1[0],C1);
531 FUN_GetUiso(gs2,T2,S2->FirstVParameter(),S2->LastVParameter(),
532 S2->IsVClosed(),S2->IsVPeriodic(),MS2[0],C2);
535 IsOk = Standard_False;
538 IsOk = Standard_True;
539 // 3. Make intersections of V(U)isos
540 if(C1.IsNull() || C2.IsNull()) return;
542 Handle(Geom_Plane) GPln = new Geom_Plane(gp_Pln(puvS1,gp_Dir(DV)));
543 Handle(Geom_Curve) C1Prj =
544 GeomProjLib::ProjectOnPlane(C1,GPln,gp_Dir(DV),Standard_True);
545 Handle(Geom_Curve) C2Prj =
546 GeomProjLib::ProjectOnPlane(C2,GPln,gp_Dir(DV),Standard_True);
547 if(C1Prj.IsNull() || C2Prj.IsNull()) return;
548 Handle(Geom2d_Curve) C1Prj2d =
549 GeomProjLib::Curve2d(C1Prj,*(Handle(Geom_Surface) *)&GPln);
550 Handle(Geom2d_Curve) C2Prj2d =
551 GeomProjLib::Curve2d(C2Prj,*(Handle(Geom_Surface) *)&GPln);
552 Geom2dAPI_InterCurveCurve ICC(C1Prj2d,C2Prj2d,1.0e-7);
553 if(ICC.NbPoints() > 0 )
555 for(Standard_Integer ip = 1; ip <= ICC.NbPoints(); ip++)
557 gp_Pnt2d P = ICC.Point(ip);
558 gp_Pnt P3d = ElCLib::To3d(gp_Ax2(puvS1,gp_Dir(DV)),P);
563 //================================================================================
564 //function: FUN_NewFirstLast
565 //================================================================================
566 static void FUN_NewFirstLast(const GeomAbs_CurveType& ga_ct,
567 const Standard_Real& Fst,
568 const Standard_Real& Lst,
569 const Standard_Real& TrVal,
570 Standard_Real& NewFst,
571 Standard_Real& NewLst,
572 Standard_Boolean& NeedTr)
574 NewFst = Fst; NewLst = Lst; NeedTr = Standard_False;
578 case GeomAbs_Parabola:
580 if(Abs(Lst - Fst) > TrVal)
582 if(Fst >= 0. && Lst >= 0.)
585 NewLst = ((Fst + TrVal) < Lst) ? (Fst + TrVal) : Lst;
587 if(Fst < 0. && Lst < 0.)
590 NewFst = ((Lst - TrVal) > Fst) ? (Lst - TrVal) : Fst;
594 NewFst = (Fst < -TrVal) ? -TrVal : Fst;
595 NewLst = (Lst > TrVal) ? TrVal : Lst;
597 NeedTr = Standard_True;
601 case GeomAbs_Hyperbola:
603 if(Abs(Lst - Fst) > 10.)
605 if(Fst >= 0. && Lst >= 0.)
609 NewLst = (Lst > 4.) ? 4. : Lst;
611 if(Fst < 0. && Lst < 0.)
613 if(Lst < -4.) return;
615 NewFst = (Fst < -4.) ? -4. : Fst;
619 NewFst = (Fst < -4.) ? -4. : Fst;
620 NewLst = (Lst > 4.) ? 4. : Lst;
622 NeedTr = Standard_True;
630 //================================================================================
631 //function: FUN_TrimBothSurf
632 //================================================================================
633 static void FUN_TrimBothSurf(const Handle(Adaptor3d_HSurface)& S1,
634 const GeomAbs_SurfaceType& T1,
635 const Handle(Adaptor3d_HSurface)& S2,
636 const GeomAbs_SurfaceType& T2,
637 const Standard_Real& TV,
638 Handle(Adaptor3d_HSurface)& NS1,
639 Handle(Adaptor3d_HSurface)& NS2)
641 const GeomAdaptor_Surface & gas1 = *(GeomAdaptor_Surface*)(&(S1->Surface()));
642 const GeomAdaptor_Surface & gas2 = *(GeomAdaptor_Surface*)(&(S2->Surface()));
643 const Handle(Geom_Surface) gs1 = gas1.Surface();
644 const Handle(Geom_Surface) gs2 = gas2.Surface();
645 const Standard_Real UM1 = 0.5 * (S1->LastUParameter() + S1->FirstUParameter());
646 const Standard_Real UM2 = 0.5 * (S2->LastUParameter() + S2->FirstUParameter());
647 const Standard_Real VM1 = 0.5 * (S1->LastVParameter() + S1->FirstVParameter());
648 const Standard_Real VM2 = 0.5 * (S2->LastVParameter() + S2->FirstVParameter());
649 Handle(Geom_Curve) visoS1, visoS2, uisoS1, uisoS2;
650 if(T1 != GeomAbs_OffsetSurface){ visoS1 = gs1->VIso(VM1); uisoS1 = gs1->UIso(UM1); }
653 const Handle(Geom_OffsetSurface) gos = *(Handle(Geom_OffsetSurface)*)&gs1;
654 const Handle(Geom_Surface) bs = gos->BasisSurface();
655 visoS1 = bs->VIso(VM1); uisoS1 = bs->UIso(UM1);
657 if(T2 != GeomAbs_OffsetSurface){ visoS2 = gs2->VIso(VM2); uisoS2 = gs2->UIso(UM2); }
660 const Handle(Geom_OffsetSurface) gos = *(Handle(Geom_OffsetSurface)*)&gs2;
661 const Handle(Geom_Surface) bs = gos->BasisSurface();
662 visoS2 = bs->VIso(VM2); uisoS2 = bs->UIso(UM2);
664 if(uisoS1.IsNull() || uisoS2.IsNull() || visoS1.IsNull() || visoS2.IsNull()){ NS1 = S1; NS2 = S2; return; }
665 GeomAdaptor_Curve gau1(uisoS1);
666 GeomAdaptor_Curve gav1(visoS1);
667 GeomAdaptor_Curve gau2(uisoS2);
668 GeomAdaptor_Curve gav2(visoS2);
669 GeomAbs_CurveType GA_U1 = gau1.GetType();
670 GeomAbs_CurveType GA_V1 = gav1.GetType();
671 GeomAbs_CurveType GA_U2 = gau2.GetType();
672 GeomAbs_CurveType GA_V2 = gav2.GetType();
673 Standard_Boolean TrmU1 = Standard_False;
674 Standard_Boolean TrmV1 = Standard_False;
675 Standard_Boolean TrmU2 = Standard_False;
676 Standard_Boolean TrmV2 = Standard_False;
677 Standard_Real V1S1,V2S1,U1S1,U2S1, V1S2,V2S2,U1S2,U2S2;
678 FUN_NewFirstLast(GA_U1,S1->FirstVParameter(),S1->LastVParameter(),TV,V1S1,V2S1,TrmV1);
679 FUN_NewFirstLast(GA_V1,S1->FirstUParameter(),S1->LastUParameter(),TV,U1S1,U2S1,TrmU1);
680 FUN_NewFirstLast(GA_U2,S2->FirstVParameter(),S2->LastVParameter(),TV,V1S2,V2S2,TrmV2);
681 FUN_NewFirstLast(GA_V2,S2->FirstUParameter(),S2->LastUParameter(),TV,U1S2,U2S2,TrmU2);
682 if(TrmV1) NS1 = S1->VTrim(V1S1, V2S1, 1.0e-7);
683 if(TrmV2) NS2 = S2->VTrim(V1S2, V2S2, 1.0e-7);
688 Handle(Adaptor3d_HSurface) TS = NS1;
689 NS1 = TS->UTrim(U1S1, U2S1, 1.0e-7);
691 else NS1 = S1->UTrim(U1S1, U2S1, 1.0e-7);
697 Handle(Adaptor3d_HSurface) TS = NS2;
698 NS2 = TS->UTrim(U1S2, U2S2, 1.0e-7);
700 else NS2 = S2->UTrim(U1S2, U2S2, 1.0e-7);
704 //=======================================================================
707 //=======================================================================
708 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& theS1,
709 const Handle(Adaptor3d_TopolTool)& theD1,
710 const Handle(Adaptor3d_HSurface)& theS2,
711 const Handle(Adaptor3d_TopolTool)& theD2,
712 const Standard_Real TolArc,
713 const Standard_Real TolTang,
714 const Standard_Boolean isGeomInt)
718 if(myFleche <= Precision::PConfusion())
720 if(myUVMaxStep <= Precision::PConfusion())
723 done = Standard_False;
726 empt = Standard_True;
727 tgte = Standard_False;
728 oppo = Standard_False;
730 GeomAbs_SurfaceType typs1 = theS1->GetType();
731 GeomAbs_SurfaceType typs2 = theS2->GetType();
733 //treatment of the cases with cone or torus
734 Standard_Boolean TreatAsBiParametric = Standard_False;
735 Standard_Integer bGeomGeom = 0;
737 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone ||
738 typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
739 gp_Ax1 aCTAx, aGeomAx;
740 GeomAbs_SurfaceType aCTType;
741 Standard_Boolean bToCheck;
743 const Handle(Adaptor3d_HSurface)& aCTSurf =
744 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS1 : theS2;
745 const Handle(Adaptor3d_HSurface)& aGeomSurf =
746 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS2 : theS1;
748 aCTType = aCTSurf->GetType();
749 bToCheck = Standard_False;
751 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone) {
752 const gp_Cone aCon1 = (aCTType == GeomAbs_Cone) ?
753 aCTSurf->Cone() : aGeomSurf->Cone();
754 Standard_Real a1 = Abs(aCon1.SemiAngle());
755 bToCheck = (a1 < 0.02) || (a1 > 1.55);
757 if (typs1 == typs2) {
758 const gp_Cone aCon2 = aGeomSurf->Cone();
759 Standard_Real a2 = Abs(aCon2.SemiAngle());
760 bToCheck = bToCheck || (a2 < 0.02) || (a2 > 1.55);
762 if (a1 > 1.55 && a2 > 1.55) {//quasi-planes: if same domain, treat as canonic
763 const gp_Ax1 A1 = aCon1.Axis(), A2 = aCon2.Axis();
764 if (A1.IsParallel(A2,Precision::Angular())) {
765 const gp_Pnt Apex1 = aCon1.Apex(), Apex2 = aCon2.Apex();
766 const gp_Pln Plan1( Apex1, A1.Direction() );
767 if (Plan1.Distance( Apex2 ) <= Precision::Confusion()) {
768 bToCheck = Standard_False;
774 TreatAsBiParametric = bToCheck;
775 if (aCTType == GeomAbs_Cone) {
776 aCTAx = aCon1.Axis();
780 if (typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
781 const gp_Torus aTor1 = (aCTType == GeomAbs_Torus) ?
782 aCTSurf->Torus() : aGeomSurf->Torus();
783 bToCheck = aTor1.MajorRadius() > aTor1.MinorRadius();
784 if (typs1 == typs2) {
785 const gp_Torus aTor2 = aGeomSurf->Torus();
786 bToCheck = aTor2.MajorRadius() > aTor2.MinorRadius();
789 if (aCTType == GeomAbs_Torus) {
790 aCTAx = aTor1.Axis();
795 const gp_Lin aL1(aCTAx);
797 switch (aGeomSurf->GetType()) {
798 case GeomAbs_Plane: {
799 aGeomAx = aGeomSurf->Plane().Axis();
800 if (aCTType == GeomAbs_Cone) {
802 if (Abs(aCTSurf->Cone().SemiAngle()) < 0.02) {
803 Standard_Real ps = Abs(aCTAx.Direction().Dot(aGeomAx.Direction()));
810 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) ||
811 (aCTAx.IsNormal(aGeomAx, Precision::Angular()) &&
812 (aGeomSurf->Plane().Distance(aCTAx.Location()) < Precision::Confusion()))) {
816 bToCheck = Standard_False;
819 case GeomAbs_Sphere: {
820 if (aL1.Distance(aGeomSurf->Sphere().Location()) < Precision::Confusion()) {
823 bToCheck = Standard_False;
826 case GeomAbs_Cylinder:
827 aGeomAx = aGeomSurf->Cylinder().Axis();
830 aGeomAx = aGeomSurf->Cone().Axis();
833 aGeomAx = aGeomSurf->Torus().Axis();
836 bToCheck = Standard_False;
841 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) &&
842 (aL1.Distance(aGeomAx.Location()) <= Precision::Confusion())) {
847 if (bGeomGeom == 1) {
848 TreatAsBiParametric = Standard_False;
854 if(theD1->DomainIsInfinite() || theD2->DomainIsInfinite()) {
855 TreatAsBiParametric= Standard_False;
858 // Modified by skv - Mon Sep 26 14:58:30 2005 Begin
859 // if(TreatAsBiParametric) { typs1 = typs2 = GeomAbs_BezierSurface; }
860 if(TreatAsBiParametric)
862 if (typs1 == GeomAbs_Cone && typs2 == GeomAbs_Plane)
863 typs1 = GeomAbs_BezierSurface; // Using Imp-Prm Intersector
864 else if (typs1 == GeomAbs_Plane && typs2 == GeomAbs_Cone)
865 typs2 = GeomAbs_BezierSurface; // Using Imp-Prm Intersector
867 // Using Prm-Prm Intersector
868 typs1 = GeomAbs_BezierSurface;
869 typs2 = GeomAbs_BezierSurface;
872 // Modified by skv - Mon Sep 26 14:58:30 2005 End
874 // Surface type definition
875 Standard_Integer ts1 = 0;
879 case GeomAbs_Cylinder:
881 case GeomAbs_Cone: ts1 = 1; break;
882 case GeomAbs_Torus: ts1 = bGeomGeom; break;
886 Standard_Integer ts2 = 0;
890 case GeomAbs_Cylinder:
892 case GeomAbs_Cone: ts2 = 1; break;
893 case GeomAbs_Torus: ts2 = bGeomGeom; break;
897 // treatment of the cases with torus and any other geom surface
899 // Possible intersection types: 1. ts1 == ts2 == 1 <Geom-Geom>
900 // 2. ts1 != ts2 <Geom-Param>
901 // 3. ts1 == ts2 == 0 <Param-Param>
904 if(ts1 == ts2 && ts1 == 1)
906 const Standard_Boolean RestrictLine = Standard_True;
907 IntSurf_ListOfPntOn2S ListOfPnts;
911 GeomGeomPerfom(theS1, theD1, theS2, theD2, TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
915 ParamParamPerfom(theS1, theD1, theS2, theD2, TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
922 GeomParamPerfom(theS1, theD1, theS2, theD2, ts1 == 0, typs1, typs2);
926 if(ts1 == ts2 && ts1 == 0)
928 const Standard_Boolean RestrictLine = Standard_True;
929 IntSurf_ListOfPntOn2S ListOfPnts;
932 ParamParamPerfom(theS1, theD1, theS2, theD2, TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
936 //=======================================================================
939 //=======================================================================
940 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& theS1,
941 const Handle(Adaptor3d_TopolTool)& theD1,
942 const Handle(Adaptor3d_HSurface)& theS2,
943 const Handle(Adaptor3d_TopolTool)& theD2,
944 const Standard_Real TolArc,
945 const Standard_Real TolTang,
946 IntSurf_ListOfPntOn2S& ListOfPnts,
947 const Standard_Boolean RestrictLine,
948 const Standard_Boolean isGeomInt)
952 if(myFleche <= Precision::PConfusion())
954 if(myUVMaxStep <= Precision::PConfusion())
957 done = Standard_False;
960 empt = Standard_True;
961 tgte = Standard_False;
962 oppo = Standard_False;
964 GeomAbs_SurfaceType typs1 = theS1->GetType();
965 GeomAbs_SurfaceType typs2 = theS2->GetType();
967 //treatment of the cases with cone or torus
968 Standard_Boolean TreatAsBiParametric = Standard_False;
969 Standard_Integer bGeomGeom = 0;
971 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone ||
972 typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
973 gp_Ax1 aCTAx, aGeomAx;
974 GeomAbs_SurfaceType aCTType;
975 Standard_Boolean bToCheck;
977 const Handle(Adaptor3d_HSurface)& aCTSurf =
978 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS1 : theS2;
979 const Handle(Adaptor3d_HSurface)& aGeomSurf =
980 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS2 : theS1;
982 aCTType = aCTSurf->GetType();
983 bToCheck = Standard_False;
985 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone) {
986 const gp_Cone aCon1 = (aCTType == GeomAbs_Cone) ?
987 aCTSurf->Cone() : aGeomSurf->Cone();
988 Standard_Real a1 = Abs(aCon1.SemiAngle());
989 bToCheck = (a1 < 0.02) || (a1 > 1.55);
991 if (typs1 == typs2) {
992 const gp_Cone aCon2 = aGeomSurf->Cone();
993 Standard_Real a2 = Abs(aCon2.SemiAngle());
994 bToCheck = bToCheck || (a2 < 0.02) || (a2 > 1.55);
996 if (a1 > 1.55 && a2 > 1.55) {//quasi-planes: if same domain, treat as canonic
997 const gp_Ax1 A1 = aCon1.Axis(), A2 = aCon2.Axis();
998 if (A1.IsParallel(A2,Precision::Angular())) {
999 const gp_Pnt Apex1 = aCon1.Apex(), Apex2 = aCon2.Apex();
1000 const gp_Pln Plan1( Apex1, A1.Direction() );
1001 if (Plan1.Distance( Apex2 ) <= Precision::Confusion()) {
1002 bToCheck = Standard_False;
1008 TreatAsBiParametric = bToCheck;
1009 if (aCTType == GeomAbs_Cone) {
1010 aCTAx = aCon1.Axis();
1014 if (typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
1015 const gp_Torus aTor1 = (aCTType == GeomAbs_Torus) ?
1016 aCTSurf->Torus() : aGeomSurf->Torus();
1017 bToCheck = aTor1.MajorRadius() > aTor1.MinorRadius();
1018 if (typs1 == typs2) {
1019 const gp_Torus aTor2 = aGeomSurf->Torus();
1020 bToCheck = aTor2.MajorRadius() > aTor2.MinorRadius();
1023 if (aCTType == GeomAbs_Torus) {
1024 aCTAx = aTor1.Axis();
1029 const gp_Lin aL1(aCTAx);
1031 switch (aGeomSurf->GetType()) {
1032 case GeomAbs_Plane: {
1033 aGeomAx = aGeomSurf->Plane().Axis();
1034 if (aCTType == GeomAbs_Cone) {
1036 if (Abs(aCTSurf->Cone().SemiAngle()) < 0.02) {
1037 Standard_Real ps = Abs(aCTAx.Direction().Dot(aGeomAx.Direction()));
1044 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) ||
1045 (aCTAx.IsNormal(aGeomAx, Precision::Angular()) &&
1046 (aGeomSurf->Plane().Distance(aCTAx.Location()) < Precision::Confusion()))) {
1050 bToCheck = Standard_False;
1053 case GeomAbs_Sphere: {
1054 if (aL1.Distance(aGeomSurf->Sphere().Location()) < Precision::Confusion()) {
1057 bToCheck = Standard_False;
1060 case GeomAbs_Cylinder:
1061 aGeomAx = aGeomSurf->Cylinder().Axis();
1064 aGeomAx = aGeomSurf->Cone().Axis();
1067 aGeomAx = aGeomSurf->Torus().Axis();
1070 bToCheck = Standard_False;
1075 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) &&
1076 (aL1.Distance(aGeomAx.Location()) <= Precision::Confusion())) {
1081 if (bGeomGeom == 1) {
1082 TreatAsBiParametric = Standard_False;
1088 if(theD1->DomainIsInfinite() || theD2->DomainIsInfinite()) {
1089 TreatAsBiParametric= Standard_False;
1092 if(TreatAsBiParametric)
1094 // Using Prm-Prm Intersector
1095 typs1 = GeomAbs_BezierSurface;
1096 typs2 = GeomAbs_BezierSurface;
1099 // Surface type definition
1100 Standard_Integer ts1 = 0;
1104 case GeomAbs_Cylinder:
1105 case GeomAbs_Sphere:
1106 case GeomAbs_Cone: ts1 = 1; break;
1107 case GeomAbs_Torus: ts1 = bGeomGeom; break;
1111 Standard_Integer ts2 = 0;
1115 case GeomAbs_Cylinder:
1116 case GeomAbs_Sphere:
1117 case GeomAbs_Cone: ts2 = 1; break;
1118 case GeomAbs_Torus: ts2 = bGeomGeom; break;
1122 // Possible intersection types: 1. ts1 == ts2 == 1 <Geom-Geom>
1123 // 2. ts1 != ts2 <Geom-Param>
1124 // 3. ts1 == ts2 == 0 <Param-Param>
1128 ParamParamPerfom(theS1, theD1, theS2, theD2, TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
1132 GeomParamPerfom(theS1, theD1, theS2, theD2, ts1 == 0, typs1, typs2);
1136 ParamParamPerfom(theS1, theD1, theS2, theD2, TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
1140 if(theD1->DomainIsInfinite() || theD2->DomainIsInfinite())
1142 GeomGeomPerfom(theS1, theD1, theS2, theD2, TolArc,
1143 TolTang, ListOfPnts, RestrictLine, typs1, typs2);
1147 GeomGeomPerfomTrimSurf(theS1, theD1, theS2, theD2,
1148 TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
1153 //=======================================================================
1154 //function : ParamParamPerfom
1156 //=======================================================================
1157 void IntPatch_Intersection::ParamParamPerfom(const Handle(Adaptor3d_HSurface)& theS1,
1158 const Handle(Adaptor3d_TopolTool)& theD1,
1159 const Handle(Adaptor3d_HSurface)& theS2,
1160 const Handle(Adaptor3d_TopolTool)& theD2,
1161 const Standard_Real TolArc,
1162 const Standard_Real TolTang,
1163 IntSurf_ListOfPntOn2S& ListOfPnts,
1164 const Standard_Boolean RestrictLine,
1165 const GeomAbs_SurfaceType typs1,
1166 const GeomAbs_SurfaceType typs2)
1168 IntPatch_PrmPrmIntersection interpp;
1169 if(!theD1->DomainIsInfinite() && !theD2->DomainIsInfinite())
1171 Standard_Boolean ClearFlag = Standard_True;
1172 if(!ListOfPnts.IsEmpty())
1174 interpp.Perform(theS1,theD1,theS2,theD2,TolArc,TolTang,myFleche,myUVMaxStep, ListOfPnts, RestrictLine);
1175 ClearFlag = Standard_False;
1177 interpp.Perform(theS1,theD1,theS2,theD2,TolArc,TolTang,myFleche,myUVMaxStep,ClearFlag); //double call!!!!!!!
1179 else if((theD1->DomainIsInfinite()) ^ (theD2->DomainIsInfinite()))
1181 gp_Pnt pMaxXYZ, pMinXYZ;
1182 if(theD1->DomainIsInfinite())
1184 FUN_GetMinMaxXYZPnt( theS2, pMinXYZ, pMaxXYZ );
1185 const Standard_Real MU = Max(Abs(theS2->FirstUParameter()),Abs(theS2->LastUParameter()));
1186 const Standard_Real MV = Max(Abs(theS2->FirstVParameter()),Abs(theS2->LastVParameter()));
1187 const Standard_Real AP = Max(MU, MV);
1188 Handle(Adaptor3d_HSurface) SS;
1189 FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, theS1, AP, SS);
1190 interpp.Perform(SS,theD1,theS2,theD2,TolArc,TolTang,myFleche,myUVMaxStep);
1194 FUN_GetMinMaxXYZPnt( theS1, pMinXYZ, pMaxXYZ );
1195 const Standard_Real MU = Max(Abs(theS1->FirstUParameter()),Abs(theS1->LastUParameter()));
1196 const Standard_Real MV = Max(Abs(theS1->FirstVParameter()),Abs(theS1->LastVParameter()));
1197 const Standard_Real AP = Max(MU, MV);
1198 Handle(Adaptor3d_HSurface) SS;
1199 FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, theS2, AP, SS);
1200 interpp.Perform(theS1, theD1, SS, theD2,TolArc,TolTang,myFleche,myUVMaxStep);
1202 }//(theD1->DomainIsInfinite()) ^ (theD2->DomainIsInfinite())
1205 if(typs1 == GeomAbs_OtherSurface || typs2 == GeomAbs_OtherSurface)
1207 done = Standard_False;
1211 Standard_Boolean IsPLInt = Standard_False;
1212 TColgp_SequenceOfPnt sop;
1214 FUN_PL_Intersection(theS1,typs1,theS2,typs2,IsPLInt,sop,v);
1218 if(sop.Length() > 0)
1220 for(Standard_Integer ip = 1; ip <= sop.Length(); ip++)
1222 gp_Lin lin(sop.Value(ip),gp_Dir(v));
1223 Handle(IntPatch_GLine) gl = new IntPatch_GLine(lin,Standard_False);
1224 slin.Append(*(Handle(IntPatch_Line) *)&gl);
1227 done = Standard_True;
1230 done = Standard_False;
1233 }// 'COLLINEAR LINES'
1236 Handle(Adaptor3d_HSurface) nS1 = theS1;
1237 Handle(Adaptor3d_HSurface) nS2 = theS2;
1238 FUN_TrimBothSurf(theS1,typs1,theS2,typs2,1.e+8,nS1,nS2);
1239 interpp.Perform(nS1,theD1,nS2,theD2,TolArc,TolTang,myFleche,myUVMaxStep);
1240 }// 'NON - COLLINEAR LINES'
1241 }// both domains are infinite
1243 if (interpp.IsDone())
1245 done = Standard_True;
1246 tgte = Standard_False;
1247 empt = interpp.IsEmpty();
1249 for(Standard_Integer i = 1; i <= interpp.NbLines(); i++)
1251 if(interpp.Line(i)->ArcType() != IntPatch_Walking)
1252 slin.Append(interpp.Line(i));
1255 for (Standard_Integer i = 1; i <= interpp.NbLines(); i++)
1257 if(interpp.Line(i)->ArcType() == IntPatch_Walking)
1258 slin.Append(interpp.Line(i));
1263 //=======================================================================
1264 ////function : GeomGeomPerfom
1266 //=======================================================================
1267 void IntPatch_Intersection::GeomGeomPerfom(const Handle(Adaptor3d_HSurface)& theS1,
1268 const Handle(Adaptor3d_TopolTool)& theD1,
1269 const Handle(Adaptor3d_HSurface)& theS2,
1270 const Handle(Adaptor3d_TopolTool)& theD2,
1271 const Standard_Real TolArc,
1272 const Standard_Real TolTang,
1273 IntSurf_ListOfPntOn2S& ListOfPnts,
1274 const Standard_Boolean RestrictLine,
1275 const GeomAbs_SurfaceType typs1,
1276 const GeomAbs_SurfaceType typs2)
1278 IntPatch_ImpImpIntersection interii(theS1,theD1,theS2,theD2,myTolArc,myTolTang);
1279 const Standard_Boolean anIS = interii.IsDone();
1283 empt = interii.IsEmpty();
1286 tgte = interii.TangentFaces();
1288 oppo = interii.OppositeFaces();
1290 for (Standard_Integer i = 1; i <= interii.NbLines(); i++)
1292 const Handle(IntPatch_Line)& line = interii.Line(i);
1293 if (line->ArcType() == IntPatch_Analytic)
1295 const GeomAbs_SurfaceType typs1 = theS1->GetType();
1296 const GeomAbs_SurfaceType typs2 = theS2->GetType();
1297 IntSurf_Quadric Quad1,Quad2;
1302 Quad1.SetValue(theS1->Plane());
1305 case GeomAbs_Cylinder:
1306 Quad1.SetValue(theS1->Cylinder());
1309 case GeomAbs_Sphere:
1310 Quad1.SetValue(theS1->Sphere());
1314 Quad1.SetValue(theS1->Cone());
1318 Quad1.SetValue(theS1->Torus());
1328 Quad2.SetValue(theS2->Plane());
1330 case GeomAbs_Cylinder:
1331 Quad2.SetValue(theS2->Cylinder());
1334 case GeomAbs_Sphere:
1335 Quad2.SetValue(theS2->Sphere());
1339 Quad2.SetValue(theS2->Cone());
1343 Quad2.SetValue(theS2->Torus());
1350 IntPatch_ALineToWLine AToW(Quad1,Quad2,0.01,0.05,aNbPointsInALine);
1351 Handle(IntPatch_Line) wlin=AToW.MakeWLine((*((Handle(IntPatch_ALine) *)(&line))));
1355 slin.Append(interii.Line(i));
1358 for (Standard_Integer i = 1; i <= interii.NbPnts(); i++)
1360 spnt.Append(interii.Point(i));
1365 ParamParamPerfom(theS1, theD1, theS2, theD2, TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
1368 //=======================================================================
1369 //function : GeomParamPerfom
1371 //=======================================================================
1372 void IntPatch_Intersection::
1373 GeomParamPerfom(const Handle(Adaptor3d_HSurface)& theS1,
1374 const Handle(Adaptor3d_TopolTool)& theD1,
1375 const Handle(Adaptor3d_HSurface)& theS2,
1376 const Handle(Adaptor3d_TopolTool)& theD2,
1377 const Standard_Boolean isNotAnalitical,
1378 const GeomAbs_SurfaceType typs1,
1379 const GeomAbs_SurfaceType typs2)
1381 IntPatch_ImpPrmIntersection interip;
1384 if (isNotAnalitical/*ts1 == 0*/)
1385 interip.SetStartPoint(myU1Start,myV1Start);
1387 interip.SetStartPoint(myU2Start,myV2Start);
1390 if(theD1->DomainIsInfinite() && theD2->DomainIsInfinite())
1392 Standard_Boolean IsPLInt = Standard_False;
1393 TColgp_SequenceOfPnt sop;
1395 FUN_PL_Intersection(theS1,typs1,theS2,typs2,IsPLInt,sop,v);
1399 if(sop.Length() > 0)
1401 for(Standard_Integer ip = 1; ip <= sop.Length(); ip++)
1403 gp_Lin lin(sop.Value(ip),gp_Dir(v));
1404 Handle(IntPatch_GLine) gl = new IntPatch_GLine(lin,Standard_False);
1405 slin.Append(*(Handle(IntPatch_Line) *)&gl);
1408 done = Standard_True;
1411 done = Standard_False;
1417 Handle(Adaptor3d_HSurface) nS1 = theS1;
1418 Handle(Adaptor3d_HSurface) nS2 = theS2;
1419 FUN_TrimBothSurf(theS1,typs1,theS2,typs2,1.e+5,nS1,nS2);
1420 interip.Perform(nS1,theD1,nS2,theD2,myTolArc,myTolTang,myFleche,myUVMaxStep);
1424 interip.Perform(theS1,theD1,theS2,theD2,myTolArc,myTolTang,myFleche,myUVMaxStep);
1426 if (interip.IsDone())
1428 done = Standard_True;
1429 empt = interip.IsEmpty();
1433 const Standard_Integer aNbLines = interip.NbLines();
1434 for(Standard_Integer i = 1; i <= aNbLines; i++)
1436 if(interip.Line(i)->ArcType() != IntPatch_Walking)
1437 slin.Append(interip.Line(i));
1440 for(Standard_Integer i = 1; i <= aNbLines; i++)
1442 if(interip.Line(i)->ArcType() == IntPatch_Walking)
1443 slin.Append(interip.Line(i));
1446 for (Standard_Integer i = 1; i <= interip.NbPnts(); i++)
1447 spnt.Append(interip.Point(i));
1452 //=======================================================================
1453 //function : GeomGeomPerfomTrimSurf
1454 //purpose : This function returns ready walking-line (which is not need
1455 // in convertation) as an intersection line between two
1456 // trimmed surfaces.
1457 //=======================================================================
1458 void IntPatch_Intersection::
1459 GeomGeomPerfomTrimSurf( const Handle(Adaptor3d_HSurface)& theS1,
1460 const Handle(Adaptor3d_TopolTool)& theD1,
1461 const Handle(Adaptor3d_HSurface)& theS2,
1462 const Handle(Adaptor3d_TopolTool)& theD2,
1463 const Standard_Real theTolArc,
1464 const Standard_Real theTolTang,
1465 IntSurf_ListOfPntOn2S& theListOfPnts,
1466 const Standard_Boolean RestrictLine,
1467 const GeomAbs_SurfaceType theTyps1,
1468 const GeomAbs_SurfaceType theTyps2)
1470 IntSurf_Quadric Quad1,Quad2;
1472 if((theTyps1 == GeomAbs_Cylinder) && (theTyps2 == GeomAbs_Cylinder))
1474 IntPatch_ImpImpIntersection anInt;
1475 anInt.Perform(theS1, theD1, theS2, theD2, theTolArc, theTolTang, Standard_True);
1477 done = anInt.IsDone();
1479 const Standard_Integer aNbLin = anInt.NbLines();
1480 const Standard_Integer aNbPts = anInt.NbPnts();
1482 for(Standard_Integer aLID = 1; aLID <= aNbLin; aLID++)
1484 const Handle(IntPatch_Line)& aLine = anInt.Line(aLID);
1488 for(Standard_Integer aPID = 1; aPID <= aNbPts; aPID++)
1490 const IntPatch_Point& aPoint = anInt.Point(aPID);
1491 spnt.Append(aPoint);
1496 GeomGeomPerfom(theS1, theD1, theS2, theD2, theTolArc, theTolTang, theListOfPnts, RestrictLine, theTyps1, theTyps2);
1501 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& S1,
1502 const Handle(Adaptor3d_TopolTool)& D1,
1503 const Handle(Adaptor3d_HSurface)& S2,
1504 const Handle(Adaptor3d_TopolTool)& D2,
1505 const Standard_Real U1,
1506 const Standard_Real V1,
1507 const Standard_Real U2,
1508 const Standard_Real V2,
1509 const Standard_Real TolArc,
1510 const Standard_Real TolTang)
1513 myTolTang = TolTang;
1514 if(myFleche == 0.0) {
1516 //cout<<" -- IntPatch_Intersection::myFleche fixe par defaut a 0.01 --"<<endl;
1517 //cout<<" -- Utiliser la Methode SetTolerances( ... ) "<<endl;
1521 if(myUVMaxStep==0.0) {
1523 //cout<<" -- IntPatch_Intersection::myUVMaxStep fixe par defaut a 0.01 --"<<endl;
1524 //cout<<" -- Utiliser la Methode SetTolerances( ... ) "<<endl;
1529 done = Standard_False;
1533 empt = Standard_True;
1534 tgte = Standard_False;
1535 oppo = Standard_False;
1537 const GeomAbs_SurfaceType typs1 = S1->GetType();
1538 const GeomAbs_SurfaceType typs2 = S2->GetType();
1540 if( typs1==GeomAbs_Plane
1541 || typs1==GeomAbs_Cylinder
1542 || typs1==GeomAbs_Sphere
1543 || typs1==GeomAbs_Cone
1544 || typs2==GeomAbs_Plane
1545 || typs2==GeomAbs_Cylinder
1546 || typs2==GeomAbs_Sphere
1547 || typs2==GeomAbs_Cone)
1549 myIsStartPnt = Standard_True;
1550 myU1Start = U1; myV1Start = V1; myU2Start = U2; myV2Start = V2;
1551 Perform(S1,D1,S2,D2,TolArc,TolTang);
1552 myIsStartPnt = Standard_False;
1556 IntPatch_PrmPrmIntersection interpp;
1557 interpp.Perform(S1,D1,S2,D2,U1,V1,U2,V2,TolArc,TolTang,myFleche,myUVMaxStep);
1558 if (interpp.IsDone())
1560 done = Standard_True;
1561 tgte = Standard_False;
1562 empt = interpp.IsEmpty();
1563 const Standard_Integer nblm = interpp.NbLines();
1564 Standard_Integer i = 1;
1565 for (; i<=nblm; i++) slin.Append(interpp.Line(i));
1569 //======================================================================
1570 #include <IntPatch_IType.hxx>
1571 #include <IntPatch_LineConstructor.hxx>
1572 #include <Adaptor2d_HCurve2d.hxx>
1576 //void IntPatch_Intersection__MAJ_R(Handle(Adaptor2d_HCurve2d) *R1,
1577 // Handle(Adaptor2d_HCurve2d) *R2,
1580 // Standard_Integer nbR1,
1581 // Standard_Integer nbR2,
1582 // const IntPatch_Point& VTX)
1583 void IntPatch_Intersection__MAJ_R(Handle(Adaptor2d_HCurve2d) *,
1584 Handle(Adaptor2d_HCurve2d) *,
1589 const IntPatch_Point& )
1592 if(VTX.IsOnDomS1()) {
1594 //-- long unsigned ptr= *((long unsigned *)(((Handle(Standard_Transient) *)(&(VTX.ArcOnS1())))));
1595 for(Standard_Integer i=0; i<nbR1;i++) {
1596 if(VTX.ArcOnS1()==R1[i]) {
1598 printf("\n ******************************");
1602 printf("\n R Pas trouvee (IntPatch)\n");
1609 //void IntPatch_Intersection::Dump(const Standard_Integer Mode,
1610 void IntPatch_Intersection::Dump(const Standard_Integer ,
1611 const Handle(Adaptor3d_HSurface)& S1,
1612 const Handle(Adaptor3d_TopolTool)& D1,
1613 const Handle(Adaptor3d_HSurface)& S2,
1614 const Handle(Adaptor3d_TopolTool)& D2) const
1617 //-- ----------------------------------------------------------------------
1618 //-- construction de la liste des restrictions & vertex
1620 int NR1[MAXR],NR2[MAXR];
1621 Handle(Adaptor2d_HCurve2d) R1[MAXR],R2[MAXR];
1622 Standard_Integer nbR1=0,nbR2=0;
1623 for(D1->Init();D1->More() && nbR1<MAXR; D1->Next()) {
1624 R1[nbR1]=D1->Value();
1628 for(D2->Init();D2->More() && nbR2<MAXR; D2->Next()) {
1629 R2[nbR2]=D2->Value();
1634 printf("\nDUMP_INT: ----empt:%2ud tgte:%2ud oppo:%2ud ---------------------------------",empt,tgte,empt);
1635 Standard_Integer i,j,nbr1,nbr2,nbgl,nbgc,nbge,nbgp,nbgh,nbl,nbr,nbg,nbw,nba;
1636 nbl=nbr=nbg=nbw=nba=nbgl=nbge=nbr1=nbr2=nbgc=nbgp=nbgh=0;
1638 for(i=1;i<=nbl;i++) {
1639 const Handle(IntPatch_Line)& line=Line(i);
1640 const IntPatch_IType IType=line->ArcType();
1641 if(IType == IntPatch_Walking) nbw++;
1642 else if(IType == IntPatch_Restriction) {
1644 Handle(IntPatch_RLine)& rlin =
1645 *((Handle(IntPatch_RLine) *)&line);
1646 if(rlin->IsArcOnS1()) nbr1++;
1647 if(rlin->IsArcOnS2()) nbr2++;
1649 else if(IType == IntPatch_Analytic) nba++;
1652 if(IType == IntPatch_Lin) nbgl++;
1653 else if(IType == IntPatch_Circle) nbgc++;
1654 else if(IType == IntPatch_Parabola) nbgp++;
1655 else if(IType == IntPatch_Hyperbola) nbgh++;
1656 else if(IType == IntPatch_Ellipse) nbge++;
1661 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)",
1662 nbl,nbw,nbr,nbr1,nbr2,nba,nbg,nbgl,nbgc,nbge,nbgh,nbgp);
1664 IntPatch_LineConstructor LineConstructor(2);
1666 Standard_Integer nbllc=0;
1668 Standard_Integer nbva,nbvw,nbvr,nbvg;
1669 nbva=nbvr=nbvw=nbvg=0;
1670 for (j=1; j<=nbl; j++) {
1671 Standard_Integer v,nbvtx;
1672 const Handle(IntPatch_Line)& intersLinej = Line(j);
1673 Standard_Integer NbLines;
1674 LineConstructor.Perform(SequenceOfLine(),intersLinej,S1,D1,S2,D2,1e-7);
1675 NbLines = LineConstructor.NbLines();
1677 for(Standard_Integer k=1;k<=NbLines;k++) {
1679 const Handle(IntPatch_Line)& LineK = LineConstructor.Line(k);
1680 if (LineK->ArcType() == IntPatch_Analytic) {
1681 Handle(IntPatch_ALine)& alin =
1682 *((Handle(IntPatch_ALine) *)&LineK);
1683 nbvtx=alin->NbVertex();
1685 for(v=1;v<=nbvtx;v++) {
1686 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,alin->Vertex(v));
1689 else if (LineK->ArcType() == IntPatch_Restriction) {
1690 Handle(IntPatch_RLine)& rlin =
1691 *((Handle(IntPatch_RLine) *)&LineK);
1692 nbvtx=rlin->NbVertex();
1694 for(v=1;v<=nbvtx;v++) {
1695 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,rlin->Vertex(v));
1698 else if (LineK->ArcType() == IntPatch_Walking) {
1699 Handle(IntPatch_WLine)& wlin =
1700 *((Handle(IntPatch_WLine) *)&LineK);
1701 nbvtx=wlin->NbVertex();
1703 for(v=1;v<=nbvtx;v++) {
1704 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,wlin->Vertex(v));
1708 Handle(IntPatch_GLine)& glin =
1709 *((Handle(IntPatch_GLine) *)&LineK);
1710 nbvtx=glin->NbVertex();
1712 for(v=1;v<=nbvtx;v++) {
1713 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,glin->Vertex(v));
1718 printf("\nDUMP_LC :Lines:%2d WLin:%2d Restr:%2d Ana:%2d Geom:%2d",
1719 nbllc,nbw,nbr,nba,nbg);
1720 printf("\nDUMP_LC :vtx :%2d r:%2d :%2d :%2d",
1721 nbvw,nbvr,nbva,nbvg);