1 // Created by: Modelization
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
20 #include <IntPatch_Intersection.ixx>
22 #include <IntPatch_ALineToWLine.hxx>
23 #include <IntPatch_GLine.hxx>
24 #include <IntPatch_ALine.hxx>
25 #include <IntPatch_WLine.hxx>
26 #include <IntPatch_RLine.hxx>
27 #include <IntPatch_PrmPrmIntersection.hxx>
28 #include <IntPatch_ImpPrmIntersection.hxx>
29 #include <IntPatch_ImpImpIntersection.hxx>
30 #include <IntSurf_Quadric.hxx>
35 static Standard_Integer NBPOINTSSURALINE = 200;
37 //======================================================================
38 // function: SequenceOfLine
39 //======================================================================
40 const IntPatch_SequenceOfLine& IntPatch_Intersection::SequenceOfLine() const { return(slin); }
42 //======================================================================
43 // function: IntPatch_Intersection
44 //======================================================================
45 IntPatch_Intersection::IntPatch_Intersection ()
46 : done(Standard_False),
48 myTolArc(0.0), myTolTang(0.0),
49 myUVMaxStep(0.0), myFleche(0.0),
50 myIsStartPnt(Standard_False)
51 //myU1Start, myV1Start, myU2Start, myV2Start
55 //======================================================================
56 // function: IntPatch_Intersection
57 //======================================================================
58 IntPatch_Intersection::IntPatch_Intersection(const Handle(Adaptor3d_HSurface)& S1,
59 const Handle(Adaptor3d_TopolTool)& D1,
60 const Handle(Adaptor3d_HSurface)& S2,
61 const Handle(Adaptor3d_TopolTool)& D2,
62 const Standard_Real TolArc,
63 const Standard_Real TolTang)
64 : done(Standard_False),
66 myTolArc(TolArc), myTolTang(TolTang),
67 myUVMaxStep(0.0), myFleche(0.0),
68 myIsStartPnt(Standard_False)
69 //myU1Start, myV1Start, myU2Start, myV2Start
71 if(myTolArc<1e-8) myTolArc=1e-8;
72 if(myTolTang<1e-8) myTolTang=1e-8;
73 if(myTolArc>0.5) myTolArc=0.5;
74 if(myTolTang>0.5) myTolTang=0.5;
75 Perform(S1,D1,S2,D2,TolArc,TolTang);
78 //======================================================================
79 // function: IntPatch_Intersection
80 //======================================================================
81 IntPatch_Intersection::IntPatch_Intersection(const Handle(Adaptor3d_HSurface)& S1,
82 const Handle(Adaptor3d_TopolTool)& D1,
83 const Standard_Real TolArc,
84 const Standard_Real TolTang)
85 : done(Standard_False),
87 myTolArc(TolArc), myTolTang(TolTang),
88 myUVMaxStep(0.0), myFleche(0.0),
89 myIsStartPnt(Standard_False)
90 //myU1Start, myV1Start, myU2Start, myV2Start
92 Perform(S1,D1,TolArc,TolTang);
95 //======================================================================
96 // function: SetTolerances
97 //======================================================================
98 void IntPatch_Intersection::SetTolerances(const Standard_Real TolArc,
99 const Standard_Real TolTang,
100 const Standard_Real UVMaxStep,
101 const Standard_Real Fleche)
105 myUVMaxStep = UVMaxStep;
107 if(myTolArc<1e-8) myTolArc=1e-8;
108 if(myTolTang<1e-8) myTolTang=1e-8;
109 if(myTolArc>0.5) myTolArc=0.5;
110 if(myTolTang>0.5) myTolTang=0.5;
111 if(myFleche<1.0e-3) myFleche=1e-3;
112 if(myUVMaxStep<1.0e-3) myUVMaxStep=1e-3;
113 if(myFleche>10) myFleche=10;
114 if(myUVMaxStep>0.5) myUVMaxStep=0.5;
117 //======================================================================
119 //======================================================================
120 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& S1,
121 const Handle(Adaptor3d_TopolTool)& D1,
122 const Standard_Real TolArc,
123 const Standard_Real TolTang)
127 if(myFleche == 0.0) myFleche = 0.01;
128 if(myUVMaxStep==0.0) myUVMaxStep = 0.01;
130 done = Standard_True;
134 empt = Standard_True;
135 tgte = Standard_False;
136 oppo = Standard_False;
138 switch (S1->GetType())
141 case GeomAbs_Cylinder:
144 case GeomAbs_Torus: break;
147 IntPatch_PrmPrmIntersection interpp;
148 interpp.Perform(S1,D1,TolArc,TolTang,myFleche,myUVMaxStep);
149 if (interpp.IsDone())
151 done = Standard_True;
152 tgte = Standard_False;
153 empt = interpp.IsEmpty();
154 const Standard_Integer nblm = interpp.NbLines();
155 for (Standard_Integer i=1; i<=nblm; i++) slin.Append(interpp.Line(i));
162 /////////////////////////////////////////////////////////////////////////////
163 // These several support functions provide methods which can help basic //
164 // algorithm to intersect infinite surfaces of the following types: //
166 // a.) SurfaceOfExtrusion; //
167 // b.) SurfaceOfRevolution; //
168 // c.) OffsetSurface. //
170 /////////////////////////////////////////////////////////////////////////////
171 #include <TColgp_Array1OfXYZ.hxx>
172 #include <TColgp_Array1OfPnt.hxx>
173 #include <TColgp_SequenceOfPnt.hxx>
174 #include <Extrema_ExtPS.hxx>
175 #include <Extrema_POnSurf.hxx>
176 #include <Geom2d_Curve.hxx>
177 #include <Geom2dAPI_InterCurveCurve.hxx>
178 #include <GeomAdaptor.hxx>
179 #include <GeomAdaptor_HCurve.hxx>
180 #include <GeomAdaptor_Curve.hxx>
181 #include <GeomAdaptor_Surface.hxx>
182 #include <Handle_GeomAdaptor_HSurface.hxx>
183 #include <Geom_Plane.hxx>
184 #include <ProjLib_ProjectOnPlane.hxx>
185 #include <GeomProjLib.hxx>
186 #include <ElCLib.hxx>
187 #include <Geom_TrimmedCurve.hxx>
188 #include <Geom_Surface.hxx>
189 #include <Geom_SurfaceOfLinearExtrusion.hxx>
190 #include <Geom_OffsetSurface.hxx>
191 #include <Geom_SurfaceOfRevolution.hxx>
192 #include <Geom_RectangularTrimmedSurface.hxx>
194 //===============================================================
195 //function: FUN_GetMinMaxXYZPnt
196 //===============================================================
197 static void FUN_GetMinMaxXYZPnt( const Handle(Adaptor3d_HSurface)& S,
198 gp_Pnt& pMin, gp_Pnt& pMax )
200 const Standard_Real DU = 0.25 * Abs(S->LastUParameter() - S->FirstUParameter());
201 const Standard_Real DV = 0.25 * Abs(S->LastVParameter() - S->FirstVParameter());
202 Standard_Real tMinXYZ = RealLast();
203 Standard_Real tMaxXYZ = -tMinXYZ;
204 gp_Pnt PUV, ptMax, ptMin;
205 for(Standard_Real U = S->FirstUParameter(); U <= S->LastUParameter(); U += DU)
207 for(Standard_Real V = S->FirstVParameter(); V <= S->LastVParameter(); V += DV)
210 const Standard_Real cXYZ = PUV.XYZ().Modulus();
211 if(cXYZ > tMaxXYZ) { tMaxXYZ = cXYZ; ptMax = PUV; }
212 if(cXYZ < tMinXYZ) { tMinXYZ = cXYZ; ptMin = PUV; }
218 //==========================================================================
219 //function: FUN_TrimInfSurf
220 //==========================================================================
221 static void FUN_TrimInfSurf(const gp_Pnt& Pmin,
223 const Handle(Adaptor3d_HSurface)& InfSurf,
224 const Standard_Real& AlternativeTrimPrm,
225 Handle(Adaptor3d_HSurface)& TrimS)
227 Standard_Real TP = AlternativeTrimPrm;
228 Extrema_ExtPS ext1(Pmin, InfSurf->Surface(), 1.e-7, 1.e-7);
229 Extrema_ExtPS ext2(Pmax, InfSurf->Surface(), 1.e-7, 1.e-7);
230 if(ext1.IsDone() || ext2.IsDone())
232 Standard_Real Umax = -1.e+100, Umin = 1.e+100, Vmax = -1.e+100, Vmin = 1.e+100, cU, cV;
235 for(Standard_Integer i = 1; i <= ext1.NbExt(); i++)
237 const Extrema_POnSurf & pons = ext1.Point(i);
238 pons.Parameter(cU,cV);
239 if(cU > Umax) Umax = cU;
240 if(cU < Umin) Umin = cU;
241 if(cV > Vmax) Vmax = cV;
242 if(cV < Vmin) Vmin = cV;
247 for(Standard_Integer i = 1; i <= ext2.NbExt(); i++)
249 const Extrema_POnSurf & pons = ext2.Point(i);
250 pons.Parameter(cU,cV);
251 if(cU > Umax) Umax = cU;
252 if(cU < Umin) Umin = cU;
253 if(cV > Vmax) Vmax = cV;
254 if(cV < Vmin) Vmin = cV;
257 TP = Max(Abs(Umin),Max(Abs(Umax),Max(Abs(Vmin),Abs(Vmax))));
259 if(TP == 0.) { TrimS = InfSurf; return; }
262 const Standard_Boolean Uinf = Precision::IsNegativeInfinite(InfSurf->FirstUParameter());
263 const Standard_Boolean Usup = Precision::IsPositiveInfinite(InfSurf->LastUParameter());
264 const Standard_Boolean Vinf = Precision::IsNegativeInfinite(InfSurf->FirstVParameter());
265 const Standard_Boolean Vsup = Precision::IsPositiveInfinite(InfSurf->LastVParameter());
266 Handle(Adaptor3d_HSurface) TmpSS;
267 Standard_Integer IsTrimed = 0;
268 const Standard_Real tp = 1000.0 * TP;
269 if(Vinf && Vsup) { TrimS = InfSurf->VTrim(-tp, tp, 1.0e-7); IsTrimed = 1; }
270 if(Vinf && !Vsup){ TrimS = InfSurf->VTrim(-tp, InfSurf->LastVParameter(), 1.0e-7); IsTrimed = 1; }
271 if(!Vinf && Vsup){ TrimS = InfSurf->VTrim(InfSurf->FirstVParameter(), tp, 1.0e-7); IsTrimed = 1; }
275 if(Uinf && Usup) TrimS = TmpSS->UTrim(-tp, tp, 1.0e-7);
276 if(Uinf && !Usup) TrimS = TmpSS->UTrim(-tp, InfSurf->LastUParameter(), 1.0e-7);
277 if(!Uinf && Usup) TrimS = TmpSS->UTrim(InfSurf->FirstUParameter(), tp, 1.0e-7);
281 if(Uinf && Usup) TrimS = InfSurf->UTrim(-tp, tp, 1.0e-7);
282 if(Uinf && !Usup) TrimS = InfSurf->UTrim(-tp, InfSurf->LastUParameter(), 1.0e-7);
283 if(!Uinf && Usup) TrimS = InfSurf->UTrim(InfSurf->FirstUParameter(), tp, 1.0e-7);
287 //================================================================================
288 //function: FUN_GetUiso
289 //================================================================================
290 static void FUN_GetUiso(const Handle(Geom_Surface)& GS,
291 const GeomAbs_SurfaceType& T,
292 const Standard_Real& FirstV,
293 const Standard_Real& LastV,
294 const Standard_Boolean& IsVC,
295 const Standard_Boolean& IsVP,
296 const Standard_Real& U,
297 Handle(Geom_Curve)& I)
299 if(T != GeomAbs_OffsetSurface)
301 Handle(Geom_Curve) gc = GS->UIso(U);
302 if(IsVP && (FirstV == 0.0 && LastV == (2.*M_PI))) I = gc;
305 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstV,LastV);
306 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
312 const Handle(Geom_OffsetSurface) gos = *(Handle_Geom_OffsetSurface*)&GS;
313 const Handle(Geom_Surface) bs = gos->BasisSurface();
314 Handle(Geom_Curve) gcbs = bs->UIso(U);
315 GeomAdaptor_Curve gac(gcbs);
316 const GeomAbs_CurveType GACT = gac.GetType();
317 if(IsVP || IsVC || GACT == GeomAbs_BSplineCurve || GACT == GeomAbs_BezierCurve || Abs(LastV - FirstV) < 1.e+5)
319 Handle(Geom_Curve) gc = gos->UIso(U);
320 if(IsVP && (FirstV == 0.0 && LastV == (2*M_PI))) I = gc;
323 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstV,LastV);
324 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
328 else//Offset Line, Parab, Hyperb
330 Standard_Real VmTr, VMTr;
331 if(GACT != GeomAbs_Hyperbola)
333 if(FirstV >= 0. && LastV >= 0.){ VmTr = FirstV; VMTr = ((LastV - FirstV) > 1.e+4) ? (FirstV + 1.e+4) : LastV; }
334 else if(FirstV < 0. && LastV < 0.){ VMTr = LastV; VmTr = ((FirstV - LastV) < -1.e+4) ? (LastV - 1.e+4) : FirstV; }
335 else { VmTr = (FirstV < -1.e+4) ? -1.e+4 : FirstV; VMTr = (LastV > 1.e+4) ? 1.e+4 : LastV; }
339 if(FirstV >= 0. && LastV >= 0.)
341 if(FirstV > 4.) return;
342 VmTr = FirstV; VMTr = (LastV > 4.) ? 4. : LastV;
344 else if(FirstV < 0. && LastV < 0.)
346 if(LastV < -4.) return;
347 VMTr = LastV; VmTr = (FirstV < -4.) ? -4. : FirstV;
349 else { VmTr = (FirstV < -4.) ? -4. : FirstV; VMTr = (LastV > 4.) ? 4. : LastV; }
351 //Make trimmed surface
352 Handle(Geom_RectangularTrimmedSurface) rts = new Geom_RectangularTrimmedSurface(gos,VmTr,VMTr,Standard_True);
357 //================================================================================
358 //function: FUN_GetViso
359 //================================================================================
360 static void FUN_GetViso(const Handle(Geom_Surface)& GS,
361 const GeomAbs_SurfaceType& T,
362 const Standard_Real& FirstU,
363 const Standard_Real& LastU,
364 const Standard_Boolean& IsUC,
365 const Standard_Boolean& IsUP,
366 const Standard_Real& V,
367 Handle(Geom_Curve)& I)
369 if(T != GeomAbs_OffsetSurface)
371 Handle(Geom_Curve) gc = GS->VIso(V);
372 if(IsUP && (FirstU == 0.0 && LastU == (2*M_PI))) I = gc;
375 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstU,LastU);
376 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
382 const Handle(Geom_OffsetSurface) gos = *(Handle_Geom_OffsetSurface*)&GS;
383 const Handle(Geom_Surface) bs = gos->BasisSurface();
384 Handle(Geom_Curve) gcbs = bs->VIso(V);
385 GeomAdaptor_Curve gac(gcbs);
386 const GeomAbs_CurveType GACT = gac.GetType();
387 if(IsUP || IsUC || GACT == GeomAbs_BSplineCurve || GACT == GeomAbs_BezierCurve || Abs(LastU - FirstU) < 1.e+5)
389 Handle(Geom_Curve) gc = gos->VIso(V);
390 if(IsUP && (FirstU == 0.0 && LastU == (2*M_PI))) I = gc;
393 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstU,LastU);
394 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
398 else//Offset Line, Parab, Hyperb
400 Standard_Real UmTr, UMTr;
401 if(GACT != GeomAbs_Hyperbola)
403 if(FirstU >= 0. && LastU >= 0.){ UmTr = FirstU; UMTr = ((LastU - FirstU) > 1.e+4) ? (FirstU + 1.e+4) : LastU; }
404 else if(FirstU < 0. && LastU < 0.){ UMTr = LastU; UmTr = ((FirstU - LastU) < -1.e+4) ? (LastU - 1.e+4) : FirstU; }
405 else { UmTr = (FirstU < -1.e+4) ? -1.e+4 : FirstU; UMTr = (LastU > 1.e+4) ? 1.e+4 : LastU; }
409 if(FirstU >= 0. && LastU >= 0.)
411 if(FirstU > 4.) return;
412 UmTr = FirstU; UMTr = (LastU > 4.) ? 4. : LastU;
414 else if(FirstU < 0. && LastU < 0.)
416 if(LastU < -4.) return;
417 UMTr = LastU; UmTr = (FirstU < -4.) ? -4. : FirstU;
419 else { UmTr = (FirstU < -4.) ? -4. : FirstU; UMTr = (LastU > 4.) ? 4. : LastU; }
421 //Make trimmed surface
422 Handle(Geom_RectangularTrimmedSurface) rts = new Geom_RectangularTrimmedSurface(gos,UmTr,UMTr,Standard_True);
427 //================================================================================
428 //function: FUN_PL_Intersection
429 //================================================================================
430 static void FUN_PL_Intersection(const Handle(Adaptor3d_HSurface)& S1,
431 const GeomAbs_SurfaceType& T1,
432 const Handle(Adaptor3d_HSurface)& S2,
433 const GeomAbs_SurfaceType& T2,
434 Standard_Boolean& IsOk,
435 TColgp_SequenceOfPnt& SP,
438 IsOk = Standard_False;
439 // 1. Check: both surfaces have U(V)isos - lines.
440 DV = gp_Vec(0.,0.,1.);
441 Standard_Boolean isoS1isLine[2] = {0, 0};
442 Standard_Boolean isoS2isLine[2] = {0, 0};
443 Handle(Geom_Curve) C1, C2;
444 const GeomAdaptor_Surface & gas1 = *(GeomAdaptor_Surface*)(&(S1->Surface()));
445 const GeomAdaptor_Surface & gas2 = *(GeomAdaptor_Surface*)(&(S2->Surface()));
446 const Handle(Geom_Surface) gs1 = gas1.Surface();
447 const Handle(Geom_Surface) gs2 = gas2.Surface();
448 Standard_Real MS1[2], MS2[2];
449 MS1[0] = 0.5 * (S1->LastUParameter() + S1->FirstUParameter());
450 MS1[1] = 0.5 * (S1->LastVParameter() + S1->FirstVParameter());
451 MS2[0] = 0.5 * (S2->LastUParameter() + S2->FirstUParameter());
452 MS2[1] = 0.5 * (S2->LastVParameter() + S2->FirstVParameter());
453 if(T1 == GeomAbs_SurfaceOfExtrusion) isoS1isLine[0] = Standard_True;
454 else if(!S1->IsVPeriodic() && !S1->IsVClosed()) {
455 if(T1 != GeomAbs_OffsetSurface) C1 = gs1->UIso(MS1[0]);
457 const Handle(Geom_OffsetSurface) gos = *(Handle_Geom_OffsetSurface*)&gs1;
458 const Handle(Geom_Surface) bs = gos->BasisSurface();
459 C1 = bs->UIso(MS1[0]);
461 GeomAdaptor_Curve gac(C1);
462 if(gac.GetType() == GeomAbs_Line) isoS1isLine[0] = Standard_True;
464 if(!S1->IsUPeriodic() && !S1->IsUClosed()) {
465 if(T1 != GeomAbs_OffsetSurface) C1 = gs1->VIso(MS1[1]);
467 const Handle(Geom_OffsetSurface) gos = *(Handle_Geom_OffsetSurface*)&gs1;
468 const Handle(Geom_Surface) bs = gos->BasisSurface();
469 C1 = bs->VIso(MS1[1]);
471 GeomAdaptor_Curve gac(C1);
472 if(gac.GetType() == GeomAbs_Line) isoS1isLine[1] = Standard_True;
474 if(T2 == GeomAbs_SurfaceOfExtrusion) isoS2isLine[0] = Standard_True;
475 else if(!S2->IsVPeriodic() && !S2->IsVClosed()) {
476 if(T2 != GeomAbs_OffsetSurface) C2 = gs2->UIso(MS2[0]);
478 const Handle(Geom_OffsetSurface) gos = *(Handle_Geom_OffsetSurface*)&gs2;
479 const Handle(Geom_Surface) bs = gos->BasisSurface();
480 C2 = bs->UIso(MS2[0]);
482 GeomAdaptor_Curve gac(C2);
483 if(gac.GetType() == GeomAbs_Line) isoS2isLine[0] = Standard_True;
485 if(!S2->IsUPeriodic() && !S2->IsUClosed()) {
486 if(T2 != GeomAbs_OffsetSurface) C2 = gs2->VIso(MS2[1]);
488 const Handle(Geom_OffsetSurface) gos = *(Handle_Geom_OffsetSurface*)&gs2;
489 const Handle(Geom_Surface) bs = gos->BasisSurface();
490 C2 = bs->VIso(MS2[1]);
492 GeomAdaptor_Curve gac(C2);
493 if(gac.GetType() == GeomAbs_Line) isoS2isLine[1] = Standard_True;
495 Standard_Boolean IsBothLines = ((isoS1isLine[0] || isoS1isLine[1]) &&
496 (isoS2isLine[0] || isoS2isLine[1]));
500 // 2. Check: Uiso lines of both surfaces are collinear.
502 gp_Vec derS1[2], derS2[2];
503 S1->D1(MS1[0], MS1[1], puvS1, derS1[0], derS1[1]);
504 S2->D1(MS2[0], MS2[1], puvS2, derS2[0], derS2[1]);
505 C1.Nullify(); C2.Nullify();
506 Standard_Integer iso = 0;
507 if(isoS1isLine[0] && isoS2isLine[0] &&
508 derS1[1].IsParallel(derS2[1],Precision::Angular())) {
510 FUN_GetViso(gs1,T1,S1->FirstUParameter(),S1->LastUParameter(),
511 S1->IsUClosed(),S1->IsUPeriodic(),MS1[1],C1);
512 FUN_GetViso(gs2,T2,S2->FirstUParameter(),S2->LastUParameter(),
513 S2->IsUClosed(),S2->IsUPeriodic(),MS2[1],C2);
515 else if(isoS1isLine[0] && isoS2isLine[1] &&
516 derS1[1].IsParallel(derS2[0],Precision::Angular())) {
518 FUN_GetViso(gs1,T1,S1->FirstUParameter(),S1->LastUParameter(),
519 S1->IsUClosed(),S1->IsUPeriodic(),MS1[1],C1);
520 FUN_GetUiso(gs2,T2,S2->FirstVParameter(),S2->LastVParameter(),
521 S2->IsVClosed(),S2->IsVPeriodic(),MS2[0],C2);
523 else if(isoS1isLine[1] && isoS2isLine[0] &&
524 derS1[0].IsParallel(derS2[1],Precision::Angular())) {
526 FUN_GetUiso(gs1,T1,S1->FirstVParameter(),S1->LastVParameter(),
527 S1->IsVClosed(),S1->IsVPeriodic(),MS1[0],C1);
528 FUN_GetViso(gs2,T2,S2->FirstUParameter(),S2->LastUParameter(),
529 S2->IsUClosed(),S2->IsUPeriodic(),MS2[1],C2);
531 else if(isoS1isLine[1] && isoS2isLine[1] &&
532 derS1[0].IsParallel(derS2[0],Precision::Angular())) {
534 FUN_GetUiso(gs1,T1,S1->FirstVParameter(),S1->LastVParameter(),
535 S1->IsVClosed(),S1->IsVPeriodic(),MS1[0],C1);
536 FUN_GetUiso(gs2,T2,S2->FirstVParameter(),S2->LastVParameter(),
537 S2->IsVClosed(),S2->IsVPeriodic(),MS2[0],C2);
540 IsOk = Standard_False;
543 IsOk = Standard_True;
544 // 3. Make intersections of V(U)isos
545 if(C1.IsNull() || C2.IsNull()) return;
547 Handle(Geom_Plane) GPln = new Geom_Plane(gp_Pln(puvS1,gp_Dir(DV)));
548 Handle(Geom_Curve) C1Prj =
549 GeomProjLib::ProjectOnPlane(C1,GPln,gp_Dir(DV),Standard_True);
550 Handle(Geom_Curve) C2Prj =
551 GeomProjLib::ProjectOnPlane(C2,GPln,gp_Dir(DV),Standard_True);
552 if(C1Prj.IsNull() || C2Prj.IsNull()) return;
553 Handle(Geom2d_Curve) C1Prj2d =
554 GeomProjLib::Curve2d(C1Prj,*(Handle_Geom_Surface *)&GPln);
555 Handle(Geom2d_Curve) C2Prj2d =
556 GeomProjLib::Curve2d(C2Prj,*(Handle_Geom_Surface *)&GPln);
557 Geom2dAPI_InterCurveCurve ICC(C1Prj2d,C2Prj2d,1.0e-7);
558 if(ICC.NbPoints() > 0 )
560 for(Standard_Integer ip = 1; ip <= ICC.NbPoints(); ip++)
562 gp_Pnt2d P = ICC.Point(ip);
563 gp_Pnt P3d = ElCLib::To3d(gp_Ax2(puvS1,gp_Dir(DV)),P);
568 //================================================================================
569 //function: FUN_NewFirstLast
570 //================================================================================
571 static void FUN_NewFirstLast(const GeomAbs_CurveType& ga_ct,
572 const Standard_Real& Fst,
573 const Standard_Real& Lst,
574 const Standard_Real& TrVal,
575 Standard_Real& NewFst,
576 Standard_Real& NewLst,
577 Standard_Boolean& NeedTr)
579 NewFst = Fst; NewLst = Lst; NeedTr = Standard_False;
583 case GeomAbs_Parabola:
585 if(Abs(Lst - Fst) > TrVal)
587 if(Fst >= 0. && Lst >= 0.)
590 NewLst = ((Fst + TrVal) < Lst) ? (Fst + TrVal) : Lst;
592 if(Fst < 0. && Lst < 0.)
595 NewFst = ((Lst - TrVal) > Fst) ? (Lst - TrVal) : Fst;
599 NewFst = (Fst < -TrVal) ? -TrVal : Fst;
600 NewLst = (Lst > TrVal) ? TrVal : Lst;
602 NeedTr = Standard_True;
606 case GeomAbs_Hyperbola:
608 if(Abs(Lst - Fst) > 10.)
610 if(Fst >= 0. && Lst >= 0.)
614 NewLst = (Lst > 4.) ? 4. : Lst;
616 if(Fst < 0. && Lst < 0.)
618 if(Lst < -4.) return;
620 NewFst = (Fst < -4.) ? -4. : Fst;
624 NewFst = (Fst < -4.) ? -4. : Fst;
625 NewLst = (Lst > 4.) ? 4. : Lst;
627 NeedTr = Standard_True;
633 //================================================================================
634 //function: FUN_TrimBothSurf
635 //================================================================================
636 static void FUN_TrimBothSurf(const Handle(Adaptor3d_HSurface)& S1,
637 const GeomAbs_SurfaceType& T1,
638 const Handle(Adaptor3d_HSurface)& S2,
639 const GeomAbs_SurfaceType& T2,
640 const Standard_Real& TV,
641 Handle(Adaptor3d_HSurface)& NS1,
642 Handle(Adaptor3d_HSurface)& NS2)
644 const GeomAdaptor_Surface & gas1 = *(GeomAdaptor_Surface*)(&(S1->Surface()));
645 const GeomAdaptor_Surface & gas2 = *(GeomAdaptor_Surface*)(&(S2->Surface()));
646 const Handle(Geom_Surface) gs1 = gas1.Surface();
647 const Handle(Geom_Surface) gs2 = gas2.Surface();
648 const Standard_Real UM1 = 0.5 * (S1->LastUParameter() + S1->FirstUParameter());
649 const Standard_Real UM2 = 0.5 * (S2->LastUParameter() + S2->FirstUParameter());
650 const Standard_Real VM1 = 0.5 * (S1->LastVParameter() + S1->FirstVParameter());
651 const Standard_Real VM2 = 0.5 * (S2->LastVParameter() + S2->FirstVParameter());
652 Handle(Geom_Curve) visoS1, visoS2, uisoS1, uisoS2;
653 if(T1 != GeomAbs_OffsetSurface){ visoS1 = gs1->VIso(VM1); uisoS1 = gs1->UIso(UM1); }
656 const Handle(Geom_OffsetSurface) gos = *(Handle_Geom_OffsetSurface*)&gs1;
657 const Handle(Geom_Surface) bs = gos->BasisSurface();
658 visoS1 = bs->VIso(VM1); uisoS1 = bs->UIso(UM1);
660 if(T2 != GeomAbs_OffsetSurface){ visoS2 = gs2->VIso(VM2); uisoS2 = gs2->UIso(UM2); }
663 const Handle(Geom_OffsetSurface) gos = *(Handle_Geom_OffsetSurface*)&gs2;
664 const Handle(Geom_Surface) bs = gos->BasisSurface();
665 visoS2 = bs->VIso(VM2); uisoS2 = bs->UIso(UM2);
667 if(uisoS1.IsNull() || uisoS2.IsNull() || visoS1.IsNull() || visoS2.IsNull()){ NS1 = S1; NS2 = S2; return; }
668 GeomAdaptor_Curve gau1(uisoS1);
669 GeomAdaptor_Curve gav1(visoS1);
670 GeomAdaptor_Curve gau2(uisoS2);
671 GeomAdaptor_Curve gav2(visoS2);
672 GeomAbs_CurveType GA_U1 = gau1.GetType();
673 GeomAbs_CurveType GA_V1 = gav1.GetType();
674 GeomAbs_CurveType GA_U2 = gau2.GetType();
675 GeomAbs_CurveType GA_V2 = gav2.GetType();
676 Standard_Boolean TrmU1 = Standard_False;
677 Standard_Boolean TrmV1 = Standard_False;
678 Standard_Boolean TrmU2 = Standard_False;
679 Standard_Boolean TrmV2 = Standard_False;
680 Standard_Real V1S1,V2S1,U1S1,U2S1, V1S2,V2S2,U1S2,U2S2;
681 FUN_NewFirstLast(GA_U1,S1->FirstVParameter(),S1->LastVParameter(),TV,V1S1,V2S1,TrmV1);
682 FUN_NewFirstLast(GA_V1,S1->FirstUParameter(),S1->LastUParameter(),TV,U1S1,U2S1,TrmU1);
683 FUN_NewFirstLast(GA_U2,S2->FirstVParameter(),S2->LastVParameter(),TV,V1S2,V2S2,TrmV2);
684 FUN_NewFirstLast(GA_V2,S2->FirstUParameter(),S2->LastUParameter(),TV,U1S2,U2S2,TrmU2);
685 if(TrmV1) NS1 = S1->VTrim(V1S1, V2S1, 1.0e-7);
686 if(TrmV2) NS2 = S2->VTrim(V1S2, V2S2, 1.0e-7);
691 Handle(Adaptor3d_HSurface) TS = NS1;
692 NS1 = TS->UTrim(U1S1, U2S1, 1.0e-7);
694 else NS1 = S1->UTrim(U1S1, U2S1, 1.0e-7);
700 Handle(Adaptor3d_HSurface) TS = NS2;
701 NS2 = TS->UTrim(U1S2, U2S2, 1.0e-7);
703 else NS2 = S2->UTrim(U1S2, U2S2, 1.0e-7);
707 //=======================================================================
710 //=======================================================================
711 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& S1,
712 const Handle(Adaptor3d_TopolTool)& D1,
713 const Handle(Adaptor3d_HSurface)& S2,
714 const Handle(Adaptor3d_TopolTool)& D2,
715 const Standard_Real TolArc,
716 const Standard_Real TolTang)
720 if(myFleche == 0.0) myFleche = 0.01;
721 if(myUVMaxStep == 0.0) myUVMaxStep = 0.01;
723 done = Standard_False;
726 empt = Standard_True;
727 tgte = Standard_False;
728 oppo = Standard_False;
732 GeomAbs_SurfaceType typs1 = S1->GetType();
733 GeomAbs_SurfaceType typs2 = S2->GetType();
735 Standard_Boolean TreatAsBiParametric = Standard_False;
736 if(typs1 == GeomAbs_Cone) {
737 Standard_Real a1 = S1->Cone().SemiAngle();
739 if(a1<2.e-2 || a1>1.55) {
740 if(typs2==GeomAbs_Plane) {
742 const gp_Dir axec = S1->Cone().Axis().Direction();
743 const gp_Dir axep = S2->Plane().Axis().Direction();
744 Standard_Real ps=axec.Dot(axep);
748 //modified by NIZNHY-PKV Thu Jul 01 12:14:29 2010f
751 //modified by NIZNHY-PKV Thu Jul 01 12:14:35 2010t
752 TreatAsBiParametric = Standard_True;
756 else TreatAsBiParametric = Standard_True;
759 if(typs2 == GeomAbs_Cone) {
760 gp_Cone Con2 = S2->Cone();
761 Standard_Real a2 = Con2.SemiAngle();
763 if(a2<2.e-2 || a2>1.55) {
764 if(typs1==GeomAbs_Plane) {
766 const gp_Dir axec = S2->Cone().Axis().Direction();
767 const gp_Dir axep = S1->Plane().Axis().Direction();
768 Standard_Real ps=axec.Dot(axep);
772 //modified by NIZNHY-PKV Thu Jul 01 12:15:04 2010f
775 //modified by NIZNHY-PKV Thu Jul 01 12:15:08 2010t
776 TreatAsBiParametric = Standard_True;
780 else TreatAsBiParametric = Standard_True;
782 //// modified by jgv, 15.12.02 for OCC565 ////
783 if (typs1 == GeomAbs_Cone) {
784 gp_Cone Con1 = S1->Cone();
785 Standard_Real a1 = Con1.SemiAngle();
786 if (a1 < 0.0) a1 = -a1;
787 if (a1 < 2.e-2 && a2 < 2.e-2) {//quasi-cylinders: if same domain, treat as canonic
788 gp_Ax1 A1 = Con1.Axis(), A2 = Con2.Axis();
789 if (A1.IsParallel(A2,Precision::Angular())) {
791 if (L1.Distance( A2.Location() ) <= Precision::Confusion()){
792 TreatAsBiParametric = Standard_False;
796 else if (a1 > 1.55 && a2 > 1.55) {//quasi-planes: if same domain, treat as canonic
797 gp_Ax1 A1 = Con1.Axis(), A2 = Con2.Axis();
798 if (A1.IsParallel(A2,Precision::Angular())) {
799 gp_Pnt Apex1 = Con1.Apex(), Apex2 = Con2.Apex();
800 gp_Pln Plan1( Apex1, A1.Direction() );
801 if (Plan1.Distance( Apex2 ) <= Precision::Confusion()){
802 TreatAsBiParametric = Standard_False;
807 //////////////////////////////////////////////
810 if(D1->DomainIsInfinite() || D2->DomainIsInfinite()) TreatAsBiParametric= Standard_False;
812 // Modified by skv - Mon Sep 26 14:58:30 2005 Begin
813 // if(TreatAsBiParametric) { typs1 = typs2 = GeomAbs_BezierSurface; }
814 if(TreatAsBiParametric) {
815 if (typs1 == GeomAbs_Cone && typs2 == GeomAbs_Plane)
816 typs1 = GeomAbs_BezierSurface; // Using Imp-Prm Intersector
817 else if (typs1 == GeomAbs_Plane && typs2 == GeomAbs_Cone)
818 typs2 = GeomAbs_BezierSurface; // Using Imp-Prm Intersector
820 // Using Prm-Prm Intersector
821 typs1 = GeomAbs_BezierSurface;
822 typs2 = GeomAbs_BezierSurface;
825 // Modified by skv - Mon Sep 26 14:58:30 2005 End
827 // Surface type definition
828 Standard_Integer ts1 = 0;
832 case GeomAbs_Cylinder:
834 case GeomAbs_Cone: ts1 = 1; break;
837 Standard_Integer ts2 = 0;
841 case GeomAbs_Cylinder:
843 case GeomAbs_Cone: ts2 = 1; break;
846 // Possible intersection types: 1. ts1 == ts2 == 1 <Geom-Geom>
847 // 2. ts1 != ts2 <Geom-Param>
848 // 3. ts1 == ts2 == 0 <Param-Param>
851 if(ts1 == ts2 && ts1 == 1)
853 IntPatch_ImpImpIntersection interii(S1,D1,S2,D2,myTolArc,myTolTang);
854 if (interii.IsDone())
856 done = Standard_True;
857 empt = interii.IsEmpty();
860 tgte = interii.TangentFaces();
861 if (tgte) oppo = interii.OppositeFaces();
862 for (i = 1; i <= interii.NbLines(); i++)
864 const Handle_IntPatch_Line& line = interii.Line(i);
865 if (line->ArcType() == IntPatch_Analytic)
867 const GeomAbs_SurfaceType typs1 = S1->GetType();
868 const GeomAbs_SurfaceType typs2 = S2->GetType();
869 IntSurf_Quadric Quad1,Quad2;
872 case GeomAbs_Plane: Quad1.SetValue(S1->Plane()); break;
873 case GeomAbs_Cylinder: Quad1.SetValue(S1->Cylinder()); break;
874 case GeomAbs_Sphere: Quad1.SetValue(S1->Sphere()); break;
875 case GeomAbs_Cone: Quad1.SetValue(S1->Cone()); break;
880 case GeomAbs_Plane: Quad2.SetValue(S2->Plane()); break;
881 case GeomAbs_Cylinder: Quad2.SetValue(S2->Cylinder()); break;
882 case GeomAbs_Sphere: Quad2.SetValue(S2->Sphere()); break;
883 case GeomAbs_Cone: Quad2.SetValue(S2->Cone()); break;
886 IntPatch_ALineToWLine AToW(Quad1,Quad2,0.01,0.05,NBPOINTSSURALINE);
887 Handle(IntPatch_Line) wlin=AToW.MakeWLine((*((Handle_IntPatch_ALine *)(&line))));
890 else slin.Append(interii.Line(i));
892 for (i = 1; i <= interii.NbPnts(); i++) spnt.Append(interii.Point(i));
900 //cout << "IP" << endl;
901 IntPatch_ImpPrmIntersection interip;
903 if (ts1 == 0) interip.SetStartPoint(myU1Start,myV1Start);
904 else interip.SetStartPoint(myU2Start,myV2Start);
906 if(D1->DomainIsInfinite() && D2->DomainIsInfinite())
908 Standard_Boolean IsPLInt = Standard_False;
909 TColgp_SequenceOfPnt sop;
911 FUN_PL_Intersection(S1,typs1,S2,typs2,IsPLInt,sop,v);
916 for(Standard_Integer ip = 1; ip <= sop.Length(); ip++)
918 gp_Lin lin(sop.Value(ip),gp_Dir(v));
919 Handle(IntPatch_GLine) gl = new IntPatch_GLine(lin,Standard_False);
920 slin.Append(*(Handle_IntPatch_Line *)&gl);
922 done = Standard_True;
924 else done = Standard_False;
929 Handle(Adaptor3d_HSurface) nS1 = S1;
930 Handle(Adaptor3d_HSurface) nS2 = S2;
931 FUN_TrimBothSurf(S1,typs1,S2,typs2,1.e+5,nS1,nS2);
932 interip.Perform(nS1,D1,nS2,D2,myTolArc,myTolTang,myFleche,myUVMaxStep);
935 else interip.Perform(S1,D1,S2,D2,myTolArc,myTolTang,myFleche,myUVMaxStep);
936 // IntPatch_ImpPrmIntersection interip(S1,D1,S2,D2,myTolArc,myTolTang,myFleche,myUVMaxStep);
937 if (interip.IsDone())
939 done = Standard_True;
940 empt = interip.IsEmpty();
943 for(i = 1; i <= interip.NbLines(); i++)
945 if(interip.Line(i)->ArcType() != IntPatch_Walking) slin.Append(interip.Line(i));
947 for(i = 1; i <= interip.NbLines(); i++)
949 if(interip.Line(i)->ArcType() == IntPatch_Walking) slin.Append(interip.Line(i));
951 for (i = 1; i <= interip.NbPnts(); i++) spnt.Append(interip.Point(i));
956 if(ts1 == ts2 && ts1 == 0)
958 //cout << "PP" << endl;
959 prm:; // this algorithm was modified last by OFV [29-Oct-2001] -> [2-Nov-2001]
960 IntPatch_PrmPrmIntersection interpp;
961 if(!D1->DomainIsInfinite() && !D2->DomainIsInfinite())
963 interpp.Perform(S1,D1,S2,D2,TolArc,TolTang,myFleche,myUVMaxStep);
966 else if( (!D1->DomainIsInfinite() && D2->DomainIsInfinite()) || (D1->DomainIsInfinite() && !D2->DomainIsInfinite()) )
968 gp_Pnt pMaxXYZ, pMinXYZ;
969 if(D1->DomainIsInfinite())
971 FUN_GetMinMaxXYZPnt( S2, pMinXYZ, pMaxXYZ );
972 const Standard_Real MU = Max(Abs(S2->FirstUParameter()),Abs(S2->LastUParameter()));
973 const Standard_Real MV = Max(Abs(S2->FirstVParameter()),Abs(S2->LastVParameter()));
974 const Standard_Real AP = Max(MU, MV);
975 Handle(Adaptor3d_HSurface) SS;
976 FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, S1, AP, SS);
977 interpp.Perform(SS,D1,S2,D2,TolArc,TolTang,myFleche,myUVMaxStep);
981 FUN_GetMinMaxXYZPnt( S1, pMinXYZ, pMaxXYZ );
982 const Standard_Real MU = Max(Abs(S1->FirstUParameter()),Abs(S1->LastUParameter()));
983 const Standard_Real MV = Max(Abs(S1->FirstVParameter()),Abs(S1->LastVParameter()));
984 const Standard_Real AP = Max(MU, MV);
985 Handle(Adaptor3d_HSurface) SS;
986 FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, S2, AP, SS);
987 interpp.Perform(S1,D1,SS,D2,TolArc,TolTang,myFleche,myUVMaxStep);
990 }//(!D1->DomainIsInfinite() && D2->DomainIsInfinite()) || (D1->DomainIsInfinite() && !D2->DomainIsInfinite())
993 if(typs1 == GeomAbs_OtherSurface || typs2 == GeomAbs_OtherSurface){ done = Standard_False; return; }
994 Standard_Boolean IsPLInt = Standard_False;
995 TColgp_SequenceOfPnt sop;
997 FUN_PL_Intersection(S1,typs1,S2,typs2,IsPLInt,sop,v);
1000 if(sop.Length() > 0)
1002 for(Standard_Integer ip = 1; ip <= sop.Length(); ip++)
1004 gp_Lin lin(sop.Value(ip),gp_Dir(v));
1005 Handle(IntPatch_GLine) gl = new IntPatch_GLine(lin,Standard_False);
1006 slin.Append(*(Handle_IntPatch_Line *)&gl);
1008 done = Standard_True;
1010 else done = Standard_False;
1012 } // 'COLLINEAR LINES'
1015 Handle(Adaptor3d_HSurface) nS1 = S1;
1016 Handle(Adaptor3d_HSurface) nS2 = S2;
1017 FUN_TrimBothSurf(S1,typs1,S2,typs2,1.e+8,nS1,nS2);
1018 interpp.Perform(nS1,D1,nS2,D2,TolArc,TolTang,myFleche,myUVMaxStep);
1020 }// 'NON - COLLINEAR LINES'
1021 }// both domains are infinite
1022 met:if (interpp.IsDone())
1024 done = Standard_True;
1025 tgte = Standard_False;
1026 empt = interpp.IsEmpty();
1027 for(i=1; i <= interpp.NbLines(); i++)
1029 if(interpp.Line(i)->ArcType() != IntPatch_Walking) slin.Append(interpp.Line(i));
1031 for(i=1; i <= interpp.NbLines(); i++)
1033 if(interpp.Line(i)->ArcType() == IntPatch_Walking) slin.Append(interpp.Line(i));
1039 //=======================================================================
1040 //function : Perform
1042 //=======================================================================
1043 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& S1,
1044 const Handle(Adaptor3d_TopolTool)& D1,
1045 const Handle(Adaptor3d_HSurface)& S2,
1046 const Handle(Adaptor3d_TopolTool)& D2,
1047 const Standard_Real TolArc,
1048 const Standard_Real TolTang,
1049 IntSurf_ListOfPntOn2S& ListOfPnts,
1050 const Standard_Boolean RestrictLine)
1053 myTolTang = TolTang;
1054 if(myFleche == 0.0) myFleche = 0.01;
1055 if(myUVMaxStep == 0.0) myUVMaxStep = 0.01;
1057 done = Standard_False;
1060 empt = Standard_True;
1061 tgte = Standard_False;
1062 oppo = Standard_False;
1066 GeomAbs_SurfaceType typs1 = S1->GetType();
1067 GeomAbs_SurfaceType typs2 = S2->GetType();
1069 Standard_Boolean TreatAsBiParametric = Standard_False;
1070 if(typs1 == GeomAbs_Cone) {
1071 Standard_Real a1 = S1->Cone().SemiAngle();
1073 if(a1<2e-2 || a1>1.55) {
1074 if(typs2==GeomAbs_Plane) {
1076 gp_Dir axec = S1->Cone().Axis().Direction();
1077 gp_Dir axep = S2->Plane().Axis().Direction();
1078 Standard_Real ps=axec.Dot(axep);
1082 //modified by NIZNHY-PKV Thu Jul 01 12:17:56 2010f
1085 //modified by NIZNHY-PKV Thu Jul 01 12:18:09 2010t
1086 TreatAsBiParametric = Standard_True;
1091 TreatAsBiParametric = Standard_True;
1095 if(typs2 == GeomAbs_Cone) {
1096 Standard_Real a2 = S2->Cone().SemiAngle();
1098 if(a2<2.e-2 || a2>1.55) {
1099 if(typs1==GeomAbs_Plane) {
1101 const gp_Dir axec = S2->Cone().Axis().Direction();
1102 const gp_Dir axep = S1->Plane().Axis().Direction();
1103 Standard_Real ps=axec.Dot(axep);
1107 //modified by NIZNHY-PKV Thu Jul 01 12:17:44 2010f
1110 //modified by NIZNHY-PKV Thu Jul 01 12:17:48 2010t
1111 TreatAsBiParametric = Standard_True;
1116 TreatAsBiParametric = Standard_True;
1120 //// modified by jgv, 15.12.02 for OCC565 ////
1121 if (typs1 == GeomAbs_Cone && typs2 == GeomAbs_Cone)
1123 gp_Cone Con1 = S1->Cone();
1124 gp_Cone Con2 = S2->Cone();
1125 Standard_Real a1 = Con1.SemiAngle();
1126 if (a1 < 0.0) a1 = -a1;
1127 Standard_Real a2 = Con2.SemiAngle();
1128 if (a2 < 0.0) a2 = -a2;
1129 if (a1 < 2e-2 && a2 < 2e-2) //quasi-cylinders: if same domain, treat as canonic
1131 gp_Ax1 A1 = Con1.Axis(), A2 = Con2.Axis();
1132 if (A1.IsParallel(A2,Precision::Angular()))
1135 if (L1.Distance( A2.Location() ) <= Precision::Confusion())
1136 TreatAsBiParametric = Standard_False;
1139 else if (a1 > 1.55 && a2 > 1.55) //quasi-planes: if same domain, treat as canonic
1141 gp_Ax1 A1 = Con1.Axis(), A2 = Con2.Axis();
1142 if (A1.IsParallel(A2,Precision::Angular()))
1144 gp_Pnt Apex1 = Con1.Apex(), Apex2 = Con2.Apex();
1145 gp_Pln Plan1( Apex1, A1.Direction() );
1146 if (Plan1.Distance( Apex2 ) <= Precision::Confusion())
1147 TreatAsBiParametric = Standard_False;
1151 //////////////////////////////////////////////
1153 if(D1->DomainIsInfinite() || D2->DomainIsInfinite()) TreatAsBiParametric= Standard_False;
1155 if(TreatAsBiParametric) { typs1 = typs2 = GeomAbs_BezierSurface; }
1157 // Surface type definition
1158 Standard_Integer ts1 = 0;
1162 case GeomAbs_Cylinder:
1163 case GeomAbs_Sphere:
1164 case GeomAbs_Cone: ts1 = 1; break;
1167 Standard_Integer ts2 = 0;
1171 case GeomAbs_Cylinder:
1172 case GeomAbs_Sphere:
1173 case GeomAbs_Cone: ts2 = 1; break;
1176 // Possible intersection types: 1. ts1 == ts2 == 1 <Geom-Geom>
1177 // 2. ts1 != ts2 <Geom-Param>
1178 // 3. ts1 == ts2 == 0 <Param-Param>
1181 if(ts1 == ts2 && ts1 == 1)
1183 IntPatch_ImpImpIntersection interii(S1,D1,S2,D2,myTolArc,myTolTang);
1184 if (interii.IsDone())
1186 done = Standard_True;
1187 empt = interii.IsEmpty();
1190 tgte = interii.TangentFaces();
1191 if (tgte) oppo = interii.OppositeFaces();
1192 for (i = 1; i <= interii.NbLines(); i++)
1194 const Handle_IntPatch_Line& line = interii.Line(i);
1195 if (line->ArcType() == IntPatch_Analytic)
1197 const GeomAbs_SurfaceType typs1 = S1->GetType();
1198 const GeomAbs_SurfaceType typs2 = S2->GetType();
1199 IntSurf_Quadric Quad1,Quad2;
1202 case GeomAbs_Plane: Quad1.SetValue(S1->Plane()); break;
1203 case GeomAbs_Cylinder: Quad1.SetValue(S1->Cylinder()); break;
1204 case GeomAbs_Sphere: Quad1.SetValue(S1->Sphere()); break;
1205 case GeomAbs_Cone: Quad1.SetValue(S1->Cone()); break;
1210 case GeomAbs_Plane: Quad2.SetValue(S2->Plane()); break;
1211 case GeomAbs_Cylinder: Quad2.SetValue(S2->Cylinder()); break;
1212 case GeomAbs_Sphere: Quad2.SetValue(S2->Sphere()); break;
1213 case GeomAbs_Cone: Quad2.SetValue(S2->Cone()); break;
1216 IntPatch_ALineToWLine AToW(Quad1,Quad2,0.01,0.05,NBPOINTSSURALINE);
1217 Handle(IntPatch_Line) wlin=AToW.MakeWLine((*((Handle_IntPatch_ALine *)(&line))));
1220 else slin.Append(interii.Line(i));
1222 for (i = 1; i <= interii.NbPnts(); i++) spnt.Append(interii.Point(i));
1230 //cout << "IP" << endl;
1231 IntPatch_ImpPrmIntersection interip;
1233 if (ts1 == 0) interip.SetStartPoint(myU1Start,myV1Start);
1234 else interip.SetStartPoint(myU2Start,myV2Start);
1236 if(D1->DomainIsInfinite() && D2->DomainIsInfinite())
1238 Standard_Boolean IsPLInt = Standard_False;
1239 TColgp_SequenceOfPnt sop;
1241 FUN_PL_Intersection(S1,typs1,S2,typs2,IsPLInt,sop,v);
1244 if(sop.Length() > 0)
1246 for(Standard_Integer ip = 1; ip <= sop.Length(); ip++)
1248 gp_Lin lin(sop.Value(ip),gp_Dir(v));
1249 Handle(IntPatch_GLine) gl = new IntPatch_GLine(lin,Standard_False);
1250 slin.Append(*(Handle_IntPatch_Line *)&gl);
1252 done = Standard_True;
1254 else done = Standard_False;
1259 Handle(Adaptor3d_HSurface) nS1 = S1;
1260 Handle(Adaptor3d_HSurface) nS2 = S2;
1261 FUN_TrimBothSurf(S1,typs1,S2,typs2,1.e+5,nS1,nS2);
1262 interip.Perform(nS1,D1,nS2,D2,myTolArc,myTolTang,myFleche,myUVMaxStep);
1265 else interip.Perform(S1,D1,S2,D2,myTolArc,myTolTang,myFleche,myUVMaxStep);
1266 // IntPatch_ImpPrmIntersection interip(S1,D1,S2,D2,myTolArc,myTolTang,myFleche,myUVMaxStep);
1267 if (interip.IsDone())
1269 done = Standard_True;
1270 empt = interip.IsEmpty();
1273 for(i = 1; i <= interip.NbLines(); i++)
1275 if(interip.Line(i)->ArcType() != IntPatch_Walking) slin.Append(interip.Line(i));
1277 for(i = 1; i <= interip.NbLines(); i++)
1279 if(interip.Line(i)->ArcType() == IntPatch_Walking) slin.Append(interip.Line(i));
1281 for (i = 1; i <= interip.NbPnts(); i++) spnt.Append(interip.Point(i));
1286 if(ts1 == ts2 && ts1 == 0)
1288 //cout << "PP" << endl;
1289 prm:; // this algorithm was modified last by OFV [29-Oct-2001] -> [2-Nov-2001]
1290 IntPatch_PrmPrmIntersection interpp;
1291 if(!D1->DomainIsInfinite() && !D2->DomainIsInfinite())
1293 // modified by NIZHNY-AMV Tue Oct 18 12:37:02 2005.BEGIN
1294 Standard_Boolean ClearFlag = Standard_True;
1295 if(!ListOfPnts.IsEmpty()){
1296 interpp.Perform(S1,D1,S2,D2,TolArc,TolTang,myFleche,myUVMaxStep, ListOfPnts, RestrictLine);
1297 ClearFlag = Standard_False;
1299 // modified by NIZHNY-AMV Tue Oct 18 12:37:02 2005.END
1300 interpp.Perform(S1,D1,S2,D2,TolArc,TolTang,myFleche,myUVMaxStep,ClearFlag);
1303 else if( (!D1->DomainIsInfinite() && D2->DomainIsInfinite()) || (D1->DomainIsInfinite() && !D2->DomainIsInfinite()) )
1305 gp_Pnt pMaxXYZ, pMinXYZ;
1306 if(D1->DomainIsInfinite())
1308 FUN_GetMinMaxXYZPnt( S2, pMinXYZ, pMaxXYZ );
1309 const Standard_Real MU = Max(Abs(S2->FirstUParameter()),Abs(S2->LastUParameter()));
1310 const Standard_Real MV = Max(Abs(S2->FirstVParameter()),Abs(S2->LastVParameter()));
1311 const Standard_Real AP = Max(MU, MV);
1312 Handle(Adaptor3d_HSurface) SS;
1313 FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, S1, AP, SS);
1314 interpp.Perform(SS,D1,S2,D2,TolArc,TolTang,myFleche,myUVMaxStep);
1318 FUN_GetMinMaxXYZPnt( S1, pMinXYZ, pMaxXYZ );
1319 const Standard_Real MU = Max(Abs(S1->FirstUParameter()),Abs(S1->LastUParameter()));
1320 const Standard_Real MV = Max(Abs(S1->FirstVParameter()),Abs(S1->LastVParameter()));
1321 const Standard_Real AP = Max(MU, MV);
1322 Handle(Adaptor3d_HSurface) SS;
1323 FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, S2, AP, SS);
1324 interpp.Perform(S1,D1,SS,D2,TolArc,TolTang,myFleche,myUVMaxStep);
1327 }//(!D1->DomainIsInfinite() && D2->DomainIsInfinite()) || (D1->DomainIsInfinite() && !D2->DomainIsInfinite())
1330 if(typs1 == GeomAbs_OtherSurface || typs2 == GeomAbs_OtherSurface){ done = Standard_False; return; }
1331 Standard_Boolean IsPLInt = Standard_False;
1332 TColgp_SequenceOfPnt sop;
1334 FUN_PL_Intersection(S1,typs1,S2,typs2,IsPLInt,sop,v);
1337 if(sop.Length() > 0)
1339 for(Standard_Integer ip = 1; ip <= sop.Length(); ip++)
1341 gp_Lin lin(sop.Value(ip),gp_Dir(v));
1342 Handle(IntPatch_GLine) gl = new IntPatch_GLine(lin,Standard_False);
1343 slin.Append(*(Handle_IntPatch_Line *)&gl);
1345 done = Standard_True;
1347 else done = Standard_False;
1349 } // 'COLLINEAR LINES'
1352 Handle(Adaptor3d_HSurface) nS1 = S1;
1353 Handle(Adaptor3d_HSurface) nS2 = S2;
1354 FUN_TrimBothSurf(S1,typs1,S2,typs2,1.e+8,nS1,nS2);
1355 interpp.Perform(nS1,D1,nS2,D2,TolArc,TolTang,myFleche,myUVMaxStep);
1357 }// 'NON - COLLINEAR LINES'
1358 }// both domains are infinite
1359 met: if (interpp.IsDone())
1361 done = Standard_True;
1362 tgte = Standard_False;
1363 empt = interpp.IsEmpty();
1364 for(i=1; i <= interpp.NbLines(); i++)
1366 if(interpp.Line(i)->ArcType() != IntPatch_Walking) slin.Append(interpp.Line(i));
1368 for (i=1; i <= interpp.NbLines(); i++)
1370 if(interpp.Line(i)->ArcType() == IntPatch_Walking) slin.Append(interpp.Line(i));
1376 void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& S1,
1377 const Handle(Adaptor3d_TopolTool)& D1,
1378 const Handle(Adaptor3d_HSurface)& S2,
1379 const Handle(Adaptor3d_TopolTool)& D2,
1380 const Standard_Real U1,
1381 const Standard_Real V1,
1382 const Standard_Real U2,
1383 const Standard_Real V2,
1384 const Standard_Real TolArc,
1385 const Standard_Real TolTang)
1388 myTolTang = TolTang;
1389 if(myFleche == 0.0) {
1391 //cout<<" -- IntPatch_Intersection::myFleche fixe par defaut a 0.01 --"<<endl;
1392 //cout<<" -- Utiliser la Methode SetTolerances( ... ) "<<endl;
1396 if(myUVMaxStep==0.0) {
1398 //cout<<" -- IntPatch_Intersection::myUVMaxStep fixe par defaut a 0.01 --"<<endl;
1399 //cout<<" -- Utiliser la Methode SetTolerances( ... ) "<<endl;
1404 done = Standard_False;
1408 empt = Standard_True;
1409 tgte = Standard_False;
1410 oppo = Standard_False;
1412 const GeomAbs_SurfaceType typs1 = S1->GetType();
1413 const GeomAbs_SurfaceType typs2 = S2->GetType();
1415 if( typs1==GeomAbs_Plane
1416 || typs1==GeomAbs_Cylinder
1417 || typs1==GeomAbs_Sphere
1418 || typs1==GeomAbs_Cone
1419 || typs2==GeomAbs_Plane
1420 || typs2==GeomAbs_Cylinder
1421 || typs2==GeomAbs_Sphere
1422 || typs2==GeomAbs_Cone)
1424 myIsStartPnt = Standard_True;
1425 myU1Start = U1; myV1Start = V1; myU2Start = U2; myV2Start = V2;
1426 Perform(S1,D1,S2,D2,TolArc,TolTang);
1427 myIsStartPnt = Standard_False;
1431 IntPatch_PrmPrmIntersection interpp;
1432 interpp.Perform(S1,D1,S2,D2,U1,V1,U2,V2,TolArc,TolTang,myFleche,myUVMaxStep);
1433 if (interpp.IsDone())
1435 done = Standard_True;
1436 tgte = Standard_False;
1437 empt = interpp.IsEmpty();
1438 const Standard_Integer nblm = interpp.NbLines();
1439 Standard_Integer i = 1;
1440 for (; i<=nblm; i++) slin.Append(interpp.Line(i));
1444 //======================================================================
1445 #include <IntPatch_IType.hxx>
1446 #include <IntPatch_LineConstructor.hxx>
1447 #include <Handle_Adaptor2d_HCurve2d.hxx>
1451 //void IntPatch_Intersection__MAJ_R(Handle_Adaptor2d_HCurve2d *R1,
1452 // Handle_Adaptor2d_HCurve2d *R2,
1455 // Standard_Integer nbR1,
1456 // Standard_Integer nbR2,
1457 // const IntPatch_Point& VTX)
1458 void IntPatch_Intersection__MAJ_R(Handle_Adaptor2d_HCurve2d *,
1459 Handle_Adaptor2d_HCurve2d *,
1464 const IntPatch_Point& )
1467 if(VTX.IsOnDomS1()) {
1469 //-- long unsigned ptr= *((long unsigned *)(((Handle_Standard_Transient *)(&(VTX.ArcOnS1())))));
1470 for(Standard_Integer i=0; i<nbR1;i++) {
1471 if(VTX.ArcOnS1()==R1[i]) {
1473 printf("\n ******************************");
1477 printf("\n R Pas trouvee (IntPatch)\n");
1484 //void IntPatch_Intersection::Dump(const Standard_Integer Mode,
1485 void IntPatch_Intersection::Dump(const Standard_Integer ,
1486 const Handle(Adaptor3d_HSurface)& S1,
1487 const Handle(Adaptor3d_TopolTool)& D1,
1488 const Handle(Adaptor3d_HSurface)& S2,
1489 const Handle(Adaptor3d_TopolTool)& D2) const
1492 //-- ----------------------------------------------------------------------
1493 //-- construction de la liste des restrictions & vertex
1495 int NR1[MAXR],NR2[MAXR];
1496 Handle_Adaptor2d_HCurve2d R1[MAXR],R2[MAXR];
1497 Standard_Integer nbR1=0,nbR2=0;
1498 for(D1->Init();D1->More() && nbR1<MAXR; D1->Next()) {
1499 R1[nbR1]=D1->Value();
1503 for(D2->Init();D2->More() && nbR2<MAXR; D2->Next()) {
1504 R2[nbR2]=D2->Value();
1509 printf("\nDUMP_INT: ----empt:%2d tgte:%2d oppo:%2d ---------------------------------",empt,tgte,empt);
1510 Standard_Integer i,j,nbr1,nbr2,nbgl,nbgc,nbge,nbgp,nbgh,nbl,nbr,nbg,nbw,nba;
1511 nbl=nbr=nbg=nbw=nba=nbgl=nbge=nbr1=nbr2=nbgc=nbgp=nbgh=0;
1513 for(i=1;i<=nbl;i++) {
1514 const Handle(IntPatch_Line)& line=Line(i);
1515 const IntPatch_IType IType=line->ArcType();
1516 if(IType == IntPatch_Walking) nbw++;
1517 else if(IType == IntPatch_Restriction) {
1519 Handle(IntPatch_RLine)& rlin =
1520 *((Handle(IntPatch_RLine) *)&line);
1521 if(rlin->IsArcOnS1()) nbr1++;
1522 if(rlin->IsArcOnS2()) nbr2++;
1524 else if(IType == IntPatch_Analytic) nba++;
1526 if(IType == IntPatch_Lin) nbgl++;
1527 else if(IType == IntPatch_Circle) nbgc++;
1528 else if(IType == IntPatch_Parabola) nbgp++;
1529 else if(IType == IntPatch_Hyperbola) nbgh++;
1530 else if(IType == IntPatch_Ellipse) nbge++;
1535 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)",
1536 nbl,nbw,nbr,nbr1,nbr2,nba,nbg,nbgl,nbgc,nbge,nbgh,nbgp);
1538 IntPatch_LineConstructor LineConstructor(2);
1540 Standard_Integer nbllc=0;
1542 Standard_Integer nbva,nbvw,nbvr,nbvg;
1543 nbva=nbvr=nbvw=nbvg=0;
1544 for (j=1; j<=nbl; j++) {
1545 Standard_Integer v,nbvtx;
1546 const Handle(IntPatch_Line)& intersLinej = Line(j);
1547 Standard_Integer NbLines;
1548 LineConstructor.Perform(SequenceOfLine(),intersLinej,S1,D1,S2,D2,1e-7);
1549 NbLines = LineConstructor.NbLines();
1551 for(Standard_Integer k=1;k<=NbLines;k++) {
1553 const Handle(IntPatch_Line)& LineK = LineConstructor.Line(k);
1554 if (LineK->ArcType() == IntPatch_Analytic) {
1555 Handle(IntPatch_ALine)& alin =
1556 *((Handle(IntPatch_ALine) *)&LineK);
1557 nbvtx=alin->NbVertex();
1559 for(v=1;v<=nbvtx;v++) {
1560 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,alin->Vertex(v));
1563 else if (LineK->ArcType() == IntPatch_Restriction) {
1564 Handle(IntPatch_RLine)& rlin =
1565 *((Handle(IntPatch_RLine) *)&LineK);
1566 nbvtx=rlin->NbVertex();
1568 for(v=1;v<=nbvtx;v++) {
1569 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,rlin->Vertex(v));
1572 else if (LineK->ArcType() == IntPatch_Walking) {
1573 Handle(IntPatch_WLine)& wlin =
1574 *((Handle(IntPatch_WLine) *)&LineK);
1575 nbvtx=wlin->NbVertex();
1577 for(v=1;v<=nbvtx;v++) {
1578 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,wlin->Vertex(v));
1582 Handle(IntPatch_GLine)& glin =
1583 *((Handle(IntPatch_GLine) *)&LineK);
1584 nbvtx=glin->NbVertex();
1586 for(v=1;v<=nbvtx;v++) {
1587 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,glin->Vertex(v));
1592 printf("\nDUMP_LC :Lines:%2d WLin:%2d Restr:%2d Ana:%2d Geom:%2d",
1593 nbllc,nbw,nbr,nba,nbg);
1594 printf("\nDUMP_LC :vtx :%2d r:%2d :%2d :%2d",
1595 nbvw,nbvr,nbva,nbvg);