0025712: Non-deterministic behavior of ShapeFix_Solid
[occt.git] / src / IntPatch / IntPatch_Intersection.cxx
CommitLineData
b311480e 1// Created by: Modelization
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 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
973c2be1 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
7fd59977 14
15#include <IntPatch_Intersection.ixx>
16
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>
26
27#include <stdio.h>
28
29#define DEBUG 0
788cbaf4 30static const Standard_Integer aNbPointsInALine = 200;
7fd59977 31
32//======================================================================
33// function: SequenceOfLine
34//======================================================================
35const IntPatch_SequenceOfLine& IntPatch_Intersection::SequenceOfLine() const { return(slin); }
36
37//======================================================================
38// function: IntPatch_Intersection
39//======================================================================
40IntPatch_Intersection::IntPatch_Intersection ()
41 : done(Standard_False),
42 //empt, tgte, oppo,
43 myTolArc(0.0), myTolTang(0.0),
44 myUVMaxStep(0.0), myFleche(0.0),
45 myIsStartPnt(Standard_False)
46 //myU1Start, myV1Start, myU2Start, myV2Start
47{
48}
49
50//======================================================================
51// function: IntPatch_Intersection
52//======================================================================
53IntPatch_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),
60 //empt, tgte, oppo,
61 myTolArc(TolArc), myTolTang(TolTang),
62 myUVMaxStep(0.0), myFleche(0.0),
63 myIsStartPnt(Standard_False)
64 //myU1Start, myV1Start, myU2Start, myV2Start
65{
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);
71}
72
73//======================================================================
74// function: IntPatch_Intersection
75//======================================================================
76IntPatch_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),
81 //empt, tgte, oppo,
82 myTolArc(TolArc), myTolTang(TolTang),
83 myUVMaxStep(0.0), myFleche(0.0),
84 myIsStartPnt(Standard_False)
85 //myU1Start, myV1Start, myU2Start, myV2Start
86{
87 Perform(S1,D1,TolArc,TolTang);
88}
89
90//======================================================================
91// function: SetTolerances
92//======================================================================
93void IntPatch_Intersection::SetTolerances(const Standard_Real TolArc,
94 const Standard_Real TolTang,
95 const Standard_Real UVMaxStep,
96 const Standard_Real Fleche)
97{
98 myTolArc = TolArc;
99 myTolTang = TolTang;
100 myUVMaxStep = UVMaxStep;
101 myFleche = Fleche;
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;
110}
111
112//======================================================================
113// function: Perform
114//======================================================================
115void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& S1,
116 const Handle(Adaptor3d_TopolTool)& D1,
117 const Standard_Real TolArc,
118 const Standard_Real TolTang)
119{
120 myTolArc = TolArc;
121 myTolTang = TolTang;
122 if(myFleche == 0.0) myFleche = 0.01;
123 if(myUVMaxStep==0.0) myUVMaxStep = 0.01;
124
125 done = Standard_True;
126 spnt.Clear();
127 slin.Clear();
128
129 empt = Standard_True;
130 tgte = Standard_False;
131 oppo = Standard_False;
132
133 switch (S1->GetType())
134 {
135 case GeomAbs_Plane:
136 case GeomAbs_Cylinder:
137 case GeomAbs_Sphere:
138 case GeomAbs_Cone:
139 case GeomAbs_Torus: break;
140 default:
141 {
1d18c75e 142 IntPatch_PrmPrmIntersection interpp;
143 interpp.Perform(S1,D1,TolArc,TolTang,myFleche,myUVMaxStep);
144 if (interpp.IsDone())
145 {
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));
151 }
7fd59977 152 }
153 break;
154 }
155}
156
157/////////////////////////////////////////////////////////////////////////////
158// These several support functions provide methods which can help basic //
159// algorithm to intersect infinite surfaces of the following types: //
160// //
161// a.) SurfaceOfExtrusion; //
162// b.) SurfaceOfRevolution; //
163// c.) OffsetSurface. //
164// //
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>
cb389a77 177#include <GeomAdaptor_HSurface.hxx>
7fd59977 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>
188
189//===============================================================
190//function: FUN_GetMinMaxXYZPnt
191//===============================================================
192static void FUN_GetMinMaxXYZPnt( const Handle(Adaptor3d_HSurface)& S,
193 gp_Pnt& pMin, gp_Pnt& pMax )
194{
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)
201 {
202 for(Standard_Real V = S->FirstVParameter(); V <= S->LastVParameter(); V += DV)
1d18c75e 203 {
204 S->D0(U,V,PUV);
7fd59977 205 const Standard_Real cXYZ = PUV.XYZ().Modulus();
1d18c75e 206 if(cXYZ > tMaxXYZ) { tMaxXYZ = cXYZ; ptMax = PUV; }
207 if(cXYZ < tMinXYZ) { tMinXYZ = cXYZ; ptMin = PUV; }
208 }
7fd59977 209 }
210 pMin = ptMin;
211 pMax = ptMax;
212}
213//==========================================================================
214//function: FUN_TrimInfSurf
215//==========================================================================
216static void FUN_TrimInfSurf(const gp_Pnt& Pmin,
217 const gp_Pnt& Pmax,
218 const Handle(Adaptor3d_HSurface)& InfSurf,
219 const Standard_Real& AlternativeTrimPrm,
220 Handle(Adaptor3d_HSurface)& TrimS)
221{
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())
226 {
227 Standard_Real Umax = -1.e+100, Umin = 1.e+100, Vmax = -1.e+100, Vmin = 1.e+100, cU, cV;
228 if(ext1.IsDone())
1d18c75e 229 {
7fd59977 230 for(Standard_Integer i = 1; i <= ext1.NbExt(); i++)
231 {
1d18c75e 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;
7fd59977 238 }
1d18c75e 239 }
7fd59977 240 if(ext2.IsDone())
1d18c75e 241 {
7fd59977 242 for(Standard_Integer i = 1; i <= ext2.NbExt(); i++)
243 {
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;
250 }
1d18c75e 251 }
7fd59977 252 TP = Max(Abs(Umin),Max(Abs(Umax),Max(Abs(Vmin),Abs(Vmax))));
253 }
254 if(TP == 0.) { TrimS = InfSurf; return; }
255 else
256 {
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; }
267 if(IsTrimed)
1d18c75e 268 {
269 TmpSS = TrimS;
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);
273 }
7fd59977 274 else
1d18c75e 275 {
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);
279 }
7fd59977 280 }
281}
282//================================================================================
283//function: FUN_GetUiso
284//================================================================================
285static 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)
293{
294 if(T != GeomAbs_OffsetSurface)
295 {
296 Handle(Geom_Curve) gc = GS->UIso(U);
c6541a0c 297 if(IsVP && (FirstV == 0.0 && LastV == (2.*M_PI))) I = gc;
7fd59977 298 else
1d18c75e 299 {
300 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstV,LastV);
301 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
302 I = gtc;
303 }
7fd59977 304 }
305 else//OffsetSurface
306 {
857ffd5e 307 const Handle(Geom_OffsetSurface) gos = *(Handle(Geom_OffsetSurface)*)&GS;
7fd59977 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)
1d18c75e 313 {
314 Handle(Geom_Curve) gc = gos->UIso(U);
315 if(IsVP && (FirstV == 0.0 && LastV == (2*M_PI))) I = gc;
316 else
7fd59977 317 {
1d18c75e 318 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstV,LastV);
319 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
320 I = gtc;
321 }
322 }
7fd59977 323 else//Offset Line, Parab, Hyperb
1d18c75e 324 {
325 Standard_Real VmTr, VMTr;
326 if(GACT != GeomAbs_Hyperbola)
7fd59977 327 {
1d18c75e 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; }
331 }
332 else//Hyperbola
333 {
334 if(FirstV >= 0. && LastV >= 0.)
335 {
336 if(FirstV > 4.) return;
337 VmTr = FirstV; VMTr = (LastV > 4.) ? 4. : LastV;
338 }
339 else if(FirstV < 0. && LastV < 0.)
340 {
341 if(LastV < -4.) return;
342 VMTr = LastV; VmTr = (FirstV < -4.) ? -4. : FirstV;
343 }
344 else { VmTr = (FirstV < -4.) ? -4. : FirstV; VMTr = (LastV > 4.) ? 4. : LastV; }
345 }
346 //Make trimmed surface
347 Handle(Geom_RectangularTrimmedSurface) rts = new Geom_RectangularTrimmedSurface(gos,VmTr,VMTr,Standard_True);
348 I = rts->UIso(U);
349 }
7fd59977 350 }
351}
352//================================================================================
353//function: FUN_GetViso
354//================================================================================
355static 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)
363{
364 if(T != GeomAbs_OffsetSurface)
365 {
366 Handle(Geom_Curve) gc = GS->VIso(V);
c6541a0c 367 if(IsUP && (FirstU == 0.0 && LastU == (2*M_PI))) I = gc;
7fd59977 368 else
1d18c75e 369 {
370 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstU,LastU);
371 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
372 I = gtc;
373 }
7fd59977 374 }
375 else//OffsetSurface
376 {
857ffd5e 377 const Handle(Geom_OffsetSurface) gos = *(Handle(Geom_OffsetSurface)*)&GS;
7fd59977 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)
1d18c75e 383 {
384 Handle(Geom_Curve) gc = gos->VIso(V);
385 if(IsUP && (FirstU == 0.0 && LastU == (2*M_PI))) I = gc;
386 else
387 {
388 Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstU,LastU);
389 //szv:I = Handle(Geom_Curve)::DownCast(gtc);
390 I = gtc;
391 }
392 }
7fd59977 393 else//Offset Line, Parab, Hyperb
1d18c75e 394 {
395 Standard_Real UmTr, UMTr;
396 if(GACT != GeomAbs_Hyperbola)
397 {
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; }
401 }
402 else//Hyperbola
403 {
404 if(FirstU >= 0. && LastU >= 0.)
405 {
406 if(FirstU > 4.) return;
407 UmTr = FirstU; UMTr = (LastU > 4.) ? 4. : LastU;
408 }
409 else if(FirstU < 0. && LastU < 0.)
410 {
411 if(LastU < -4.) return;
412 UMTr = LastU; UmTr = (FirstU < -4.) ? -4. : FirstU;
413 }
414 else { UmTr = (FirstU < -4.) ? -4. : FirstU; UMTr = (LastU > 4.) ? 4. : LastU; }
415 }
416 //Make trimmed surface
417 Handle(Geom_RectangularTrimmedSurface) rts = new Geom_RectangularTrimmedSurface(gos,UmTr,UMTr,Standard_True);
418 I = rts->VIso(V);
419 }
7fd59977 420 }
421}
422//================================================================================
423//function: FUN_PL_Intersection
424//================================================================================
425static 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,
431 gp_Vec& DV)
432{
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]);
451 else {
857ffd5e 452 const Handle(Geom_OffsetSurface) gos = *(Handle(Geom_OffsetSurface)*)&gs1;
7fd59977 453 const Handle(Geom_Surface) bs = gos->BasisSurface();
454 C1 = bs->UIso(MS1[0]);
455 }
456 GeomAdaptor_Curve gac(C1);
457 if(gac.GetType() == GeomAbs_Line) isoS1isLine[0] = Standard_True;
458 }
459 if(!S1->IsUPeriodic() && !S1->IsUClosed()) {
460 if(T1 != GeomAbs_OffsetSurface) C1 = gs1->VIso(MS1[1]);
461 else {
857ffd5e 462 const Handle(Geom_OffsetSurface) gos = *(Handle(Geom_OffsetSurface)*)&gs1;
7fd59977 463 const Handle(Geom_Surface) bs = gos->BasisSurface();
464 C1 = bs->VIso(MS1[1]);
465 }
466 GeomAdaptor_Curve gac(C1);
467 if(gac.GetType() == GeomAbs_Line) isoS1isLine[1] = Standard_True;
468 }
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]);
472 else {
857ffd5e 473 const Handle(Geom_OffsetSurface) gos = *(Handle(Geom_OffsetSurface)*)&gs2;
7fd59977 474 const Handle(Geom_Surface) bs = gos->BasisSurface();
475 C2 = bs->UIso(MS2[0]);
476 }
477 GeomAdaptor_Curve gac(C2);
478 if(gac.GetType() == GeomAbs_Line) isoS2isLine[0] = Standard_True;
479 }
480 if(!S2->IsUPeriodic() && !S2->IsUClosed()) {
481 if(T2 != GeomAbs_OffsetSurface) C2 = gs2->VIso(MS2[1]);
482 else {
857ffd5e 483 const Handle(Geom_OffsetSurface) gos = *(Handle(Geom_OffsetSurface)*)&gs2;
7fd59977 484 const Handle(Geom_Surface) bs = gos->BasisSurface();
485 C2 = bs->VIso(MS2[1]);
486 }
487 GeomAdaptor_Curve gac(C2);
488 if(gac.GetType() == GeomAbs_Line) isoS2isLine[1] = Standard_True;
489 }
490 Standard_Boolean IsBothLines = ((isoS1isLine[0] || isoS1isLine[1]) &&
491 (isoS2isLine[0] || isoS2isLine[1]));
492 if(!IsBothLines){
493 return;
494 }
495 // 2. Check: Uiso lines of both surfaces are collinear.
496 gp_Pnt puvS1, puvS2;
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())) {
504 iso = 1;
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);
509 }
510 else if(isoS1isLine[0] && isoS2isLine[1] &&
511 derS1[1].IsParallel(derS2[0],Precision::Angular())) {
512 iso = 1;
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);
517 }
518 else if(isoS1isLine[1] && isoS2isLine[0] &&
519 derS1[0].IsParallel(derS2[1],Precision::Angular())) {
520 iso = 0;
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);
525 }
526 else if(isoS1isLine[1] && isoS2isLine[1] &&
527 derS1[0].IsParallel(derS2[0],Precision::Angular())) {
528 iso = 0;
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);
533 }
534 else {
535 IsOk = Standard_False;
536 return;
537 }
538 IsOk = Standard_True;
539 // 3. Make intersections of V(U)isos
540 if(C1.IsNull() || C2.IsNull()) return;
541 DV = derS1[iso];
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 =
857ffd5e 549 GeomProjLib::Curve2d(C1Prj,*(Handle(Geom_Surface) *)&GPln);
7fd59977 550 Handle(Geom2d_Curve) C2Prj2d =
857ffd5e 551 GeomProjLib::Curve2d(C2Prj,*(Handle(Geom_Surface) *)&GPln);
7fd59977 552 Geom2dAPI_InterCurveCurve ICC(C1Prj2d,C2Prj2d,1.0e-7);
553 if(ICC.NbPoints() > 0 )
554 {
555 for(Standard_Integer ip = 1; ip <= ICC.NbPoints(); ip++)
1d18c75e 556 {
557 gp_Pnt2d P = ICC.Point(ip);
558 gp_Pnt P3d = ElCLib::To3d(gp_Ax2(puvS1,gp_Dir(DV)),P);
559 SP.Append(P3d);
560 }
7fd59977 561 }
562}
563//================================================================================
564//function: FUN_NewFirstLast
565//================================================================================
566static 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)
573{
574 NewFst = Fst; NewLst = Lst; NeedTr = Standard_False;
575 switch (ga_ct)
576 {
577 case GeomAbs_Line:
578 case GeomAbs_Parabola:
579 {
580 if(Abs(Lst - Fst) > TrVal)
1d18c75e 581 {
582 if(Fst >= 0. && Lst >= 0.)
7fd59977 583 {
1d18c75e 584 NewFst = Fst;
585 NewLst = ((Fst + TrVal) < Lst) ? (Fst + TrVal) : Lst;
586 }
587 if(Fst < 0. && Lst < 0.)
588 {
589 NewLst = Lst;
590 NewFst = ((Lst - TrVal) > Fst) ? (Lst - TrVal) : Fst;
591 }
592 else
593 {
594 NewFst = (Fst < -TrVal) ? -TrVal : Fst;
595 NewLst = (Lst > TrVal) ? TrVal : Lst;
596 }
597 NeedTr = Standard_True;
598 }
599 break;
7fd59977 600 }
1d18c75e 601 case GeomAbs_Hyperbola:
7fd59977 602 {
603 if(Abs(Lst - Fst) > 10.)
1d18c75e 604 {
605 if(Fst >= 0. && Lst >= 0.)
606 {
607 if(Fst > 4.) return;
608 NewFst = Fst;
609 NewLst = (Lst > 4.) ? 4. : Lst;
610 }
611 if(Fst < 0. && Lst < 0.)
612 {
613 if(Lst < -4.) return;
614 NewLst = Lst;
615 NewFst = (Fst < -4.) ? -4. : Fst;
616 }
617 else
618 {
619 NewFst = (Fst < -4.) ? -4. : Fst;
620 NewLst = (Lst > 4.) ? 4. : Lst;
621 }
622 NeedTr = Standard_True;
623 }
7fd59977 624 break;
625 }
1d18c75e 626 default:
566f8441 627 break;
7fd59977 628 }
629}
630//================================================================================
631//function: FUN_TrimBothSurf
1d18c75e 632//================================================================================
7fd59977 633static 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)
640{
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); }
651 else
652 {
857ffd5e 653 const Handle(Geom_OffsetSurface) gos = *(Handle(Geom_OffsetSurface)*)&gs1;
7fd59977 654 const Handle(Geom_Surface) bs = gos->BasisSurface();
655 visoS1 = bs->VIso(VM1); uisoS1 = bs->UIso(UM1);
656 }
657 if(T2 != GeomAbs_OffsetSurface){ visoS2 = gs2->VIso(VM2); uisoS2 = gs2->UIso(UM2); }
658 else
659 {
857ffd5e 660 const Handle(Geom_OffsetSurface) gos = *(Handle(Geom_OffsetSurface)*)&gs2;
7fd59977 661 const Handle(Geom_Surface) bs = gos->BasisSurface();
662 visoS2 = bs->VIso(VM2); uisoS2 = bs->UIso(UM2);
663 }
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);
684 if(TrmU1)
685 {
686 if(TrmV1)
1d18c75e 687 {
688 Handle(Adaptor3d_HSurface) TS = NS1;
689 NS1 = TS->UTrim(U1S1, U2S1, 1.0e-7);
690 }
7fd59977 691 else NS1 = S1->UTrim(U1S1, U2S1, 1.0e-7);
692 }
693 if(TrmU2)
694 {
695 if(TrmV2)
1d18c75e 696 {
697 Handle(Adaptor3d_HSurface) TS = NS2;
698 NS2 = TS->UTrim(U1S2, U2S2, 1.0e-7);
699 }
7fd59977 700 else NS2 = S2->UTrim(U1S2, U2S2, 1.0e-7);
701 }
702}
703
704//=======================================================================
705//function : Perform
706//purpose :
707//=======================================================================
788cbaf4 708void 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,
7fd59977 712 const Standard_Real TolArc,
788cbaf4 713 const Standard_Real TolTang,
714 const Standard_Boolean isGeomInt)
715{
7fd59977 716 myTolArc = TolArc;
717 myTolTang = TolTang;
788cbaf4 718 if(myFleche <= Precision::PConfusion())
719 myFleche = 0.01;
720 if(myUVMaxStep <= Precision::PConfusion())
721 myUVMaxStep = 0.01;
722
7fd59977 723 done = Standard_False;
724 spnt.Clear();
725 slin.Clear();
726 empt = Standard_True;
727 tgte = Standard_False;
728 oppo = Standard_False;
729
788cbaf4 730 GeomAbs_SurfaceType typs1 = theS1->GetType();
731 GeomAbs_SurfaceType typs2 = theS2->GetType();
7fd59977 732
18d25b93 733 //treatment of the cases with cone or torus
7fd59977 734 Standard_Boolean TreatAsBiParametric = Standard_False;
1d18c75e 735 Standard_Integer bGeomGeom = 0;
18d25b93 736 //
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;
742 //
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;
747 //
748 aCTType = aCTSurf->GetType();
749 bToCheck = Standard_False;
750 //
1d18c75e 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());
18d25b93 755 bToCheck = (a1 < 0.02) || (a1 > 1.55);
1d18c75e 756 //
18d25b93 757 if (typs1 == typs2) {
1d18c75e 758 const gp_Cone aCon2 = aGeomSurf->Cone();
759 Standard_Real a2 = Abs(aCon2.SemiAngle());
18d25b93 760 bToCheck = bToCheck || (a2 < 0.02) || (a2 > 1.55);
761 //
762 if (a1 > 1.55 && a2 > 1.55) {//quasi-planes: if same domain, treat as canonic
18d25b93 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;
18d25b93 769 }
788cbaf4 770 }
771 }
7fd59977 772 }
18d25b93 773 //
1d18c75e 774 TreatAsBiParametric = bToCheck;
775 if (aCTType == GeomAbs_Cone) {
776 aCTAx = aCon1.Axis();
777 }
7fd59977 778 }
1d18c75e 779 //
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();
787 }
788 //
789 if (aCTType == GeomAbs_Torus) {
790 aCTAx = aTor1.Axis();
18d25b93 791 }
18d25b93 792 }
793 //
794 if (bToCheck) {
795 const gp_Lin aL1(aCTAx);
796 //
797 switch (aGeomSurf->GetType()) {
798 case GeomAbs_Plane: {
799 aGeomAx = aGeomSurf->Plane().Axis();
800 if (aCTType == GeomAbs_Cone) {
1d18c75e 801 bGeomGeom = 1;
18d25b93 802 if (Abs(aCTSurf->Cone().SemiAngle()) < 0.02) {
803 Standard_Real ps = Abs(aCTAx.Direction().Dot(aGeomAx.Direction()));
804 if(ps < 0.015) {
1d18c75e 805 bGeomGeom = 0;
18d25b93 806 }
788cbaf4 807 }
808 }
18d25b93 809 else {
810 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) ||
811 (aCTAx.IsNormal(aGeomAx, Precision::Angular()) &&
812 (aGeomSurf->Plane().Distance(aCTAx.Location()) < Precision::Confusion()))) {
1d18c75e 813 bGeomGeom = 1;
18d25b93 814 }
815 }
816 bToCheck = Standard_False;
817 break;
7fd59977 818 }
18d25b93 819 case GeomAbs_Sphere: {
820 if (aL1.Distance(aGeomSurf->Sphere().Location()) < Precision::Confusion()) {
1d18c75e 821 bGeomGeom = 1;
18d25b93 822 }
823 bToCheck = Standard_False;
824 break;
7fd59977 825 }
18d25b93 826 case GeomAbs_Cylinder:
827 aGeomAx = aGeomSurf->Cylinder().Axis();
828 break;
829 case GeomAbs_Cone:
830 aGeomAx = aGeomSurf->Cone().Axis();
831 break;
832 case GeomAbs_Torus:
833 aGeomAx = aGeomSurf->Torus().Axis();
834 break;
835 default:
836 bToCheck = Standard_False;
837 break;
838 }
839 //
840 if (bToCheck) {
841 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) &&
842 (aL1.Distance(aGeomAx.Location()) <= Precision::Confusion())) {
1d18c75e 843 bGeomGeom = 1;
788cbaf4 844 }
7fd59977 845 }
18d25b93 846 //
1d18c75e 847 if (bGeomGeom == 1) {
848 TreatAsBiParametric = Standard_False;
18d25b93 849 }
850 }
851 }
852 //
788cbaf4 853
854 if(theD1->DomainIsInfinite() || theD2->DomainIsInfinite()) {
bf0ba813 855 TreatAsBiParametric= Standard_False;
856 }
7fd59977 857
858// Modified by skv - Mon Sep 26 14:58:30 2005 Begin
859// if(TreatAsBiParametric) { typs1 = typs2 = GeomAbs_BezierSurface; }
788cbaf4 860 if(TreatAsBiParametric)
861 {
7fd59977 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
866 else {
867 // Using Prm-Prm Intersector
868 typs1 = GeomAbs_BezierSurface;
869 typs2 = GeomAbs_BezierSurface;
870 }
871 }
872// Modified by skv - Mon Sep 26 14:58:30 2005 End
873
874 // Surface type definition
875 Standard_Integer ts1 = 0;
876 switch (typs1)
877 {
878 case GeomAbs_Plane:
879 case GeomAbs_Cylinder:
880 case GeomAbs_Sphere:
881 case GeomAbs_Cone: ts1 = 1; break;
1d18c75e 882 case GeomAbs_Torus: ts1 = bGeomGeom; break;
7fd59977 883 default: break;
884 }
788cbaf4 885
7fd59977 886 Standard_Integer ts2 = 0;
887 switch (typs2)
888 {
889 case GeomAbs_Plane:
890 case GeomAbs_Cylinder:
891 case GeomAbs_Sphere:
892 case GeomAbs_Cone: ts2 = 1; break;
1d18c75e 893 case GeomAbs_Torus: ts2 = bGeomGeom; break;
7fd59977 894 default: break;
895 }
7eed5d29 896 //
897 // treatment of the cases with torus and any other geom surface
7eed5d29 898 //
7fd59977 899 // Possible intersection types: 1. ts1 == ts2 == 1 <Geom-Geom>
900 // 2. ts1 != ts2 <Geom-Param>
901 // 3. ts1 == ts2 == 0 <Param-Param>
902
903 // Geom - Geom
904 if(ts1 == ts2 && ts1 == 1)
905 {
788cbaf4 906 const Standard_Boolean RestrictLine = Standard_True;
907 IntSurf_ListOfPntOn2S ListOfPnts;
908 ListOfPnts.Clear();
909 if(isGeomInt)
910 {
02effd35 911 if(theD1->DomainIsInfinite() || theD2->DomainIsInfinite())
912 {
913 GeomGeomPerfom(theS1, theD1, theS2, theD2, TolArc,
914 TolTang, ListOfPnts, RestrictLine, typs1, typs2);
915 }
916 else
917 {
918 GeomGeomPerfomTrimSurf(theS1, theD1, theS2, theD2,
919 TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
920 }
788cbaf4 921 }
922 else
923 {
02effd35 924 ParamParamPerfom(theS1, theD1, theS2, theD2,
925 TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
788cbaf4 926 }
7fd59977 927 }
788cbaf4 928
7fd59977 929 // Geom - Param
930 if(ts1 != ts2)
931 {
788cbaf4 932 GeomParamPerfom(theS1, theD1, theS2, theD2, ts1 == 0, typs1, typs2);
7fd59977 933 }
788cbaf4 934
7fd59977 935 // Param - Param
936 if(ts1 == ts2 && ts1 == 0)
937 {
788cbaf4 938 const Standard_Boolean RestrictLine = Standard_True;
939 IntSurf_ListOfPntOn2S ListOfPnts;
940 ListOfPnts.Clear();
941
02effd35 942 ParamParamPerfom(theS1, theD1, theS2, theD2, TolArc,
943 TolTang, ListOfPnts, RestrictLine, typs1, typs2);
7fd59977 944 }
945}
18d25b93 946
7fd59977 947//=======================================================================
948//function : Perform
949//purpose :
950//=======================================================================
788cbaf4 951void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& theS1,
952 const Handle(Adaptor3d_TopolTool)& theD1,
953 const Handle(Adaptor3d_HSurface)& theS2,
954 const Handle(Adaptor3d_TopolTool)& theD2,
7fd59977 955 const Standard_Real TolArc,
956 const Standard_Real TolTang,
957 IntSurf_ListOfPntOn2S& ListOfPnts,
788cbaf4 958 const Standard_Boolean RestrictLine,
959 const Standard_Boolean isGeomInt)
7fd59977 960{
961 myTolArc = TolArc;
962 myTolTang = TolTang;
788cbaf4 963 if(myFleche <= Precision::PConfusion())
964 myFleche = 0.01;
965 if(myUVMaxStep <= Precision::PConfusion())
966 myUVMaxStep = 0.01;
7fd59977 967
968 done = Standard_False;
969 spnt.Clear();
970 slin.Clear();
971 empt = Standard_True;
972 tgte = Standard_False;
973 oppo = Standard_False;
974
788cbaf4 975 GeomAbs_SurfaceType typs1 = theS1->GetType();
976 GeomAbs_SurfaceType typs2 = theS2->GetType();
18d25b93 977 //
978 //treatment of the cases with cone or torus
7fd59977 979 Standard_Boolean TreatAsBiParametric = Standard_False;
1d18c75e 980 Standard_Integer bGeomGeom = 0;
18d25b93 981 //
982 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone ||
983 typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
984 gp_Ax1 aCTAx, aGeomAx;
985 GeomAbs_SurfaceType aCTType;
986 Standard_Boolean bToCheck;
987 //
988 const Handle(Adaptor3d_HSurface)& aCTSurf =
989 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS1 : theS2;
990 const Handle(Adaptor3d_HSurface)& aGeomSurf =
991 (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS2 : theS1;
992 //
993 aCTType = aCTSurf->GetType();
994 bToCheck = Standard_False;
995 //
1d18c75e 996 if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone) {
997 const gp_Cone aCon1 = (aCTType == GeomAbs_Cone) ?
998 aCTSurf->Cone() : aGeomSurf->Cone();
999 Standard_Real a1 = Abs(aCon1.SemiAngle());
18d25b93 1000 bToCheck = (a1 < 0.02) || (a1 > 1.55);
1d18c75e 1001 //
18d25b93 1002 if (typs1 == typs2) {
1d18c75e 1003 const gp_Cone aCon2 = aGeomSurf->Cone();
1004 Standard_Real a2 = Abs(aCon2.SemiAngle());
18d25b93 1005 bToCheck = bToCheck || (a2 < 0.02) || (a2 > 1.55);
1006 //
1007 if (a1 > 1.55 && a2 > 1.55) {//quasi-planes: if same domain, treat as canonic
18d25b93 1008 const gp_Ax1 A1 = aCon1.Axis(), A2 = aCon2.Axis();
1009 if (A1.IsParallel(A2,Precision::Angular())) {
1010 const gp_Pnt Apex1 = aCon1.Apex(), Apex2 = aCon2.Apex();
1011 const gp_Pln Plan1( Apex1, A1.Direction() );
1012 if (Plan1.Distance( Apex2 ) <= Precision::Confusion()) {
1013 bToCheck = Standard_False;
18d25b93 1014 }
788cbaf4 1015 }
1016 }
7fd59977 1017 }
18d25b93 1018 //
1d18c75e 1019 TreatAsBiParametric = bToCheck;
1020 if (aCTType == GeomAbs_Cone) {
1021 aCTAx = aCon1.Axis();
1022 }
788cbaf4 1023 }
1d18c75e 1024 //
1025 if (typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) {
1026 const gp_Torus aTor1 = (aCTType == GeomAbs_Torus) ?
1027 aCTSurf->Torus() : aGeomSurf->Torus();
1028 bToCheck = aTor1.MajorRadius() > aTor1.MinorRadius();
1029 if (typs1 == typs2) {
1030 const gp_Torus aTor2 = aGeomSurf->Torus();
1031 bToCheck = aTor2.MajorRadius() > aTor2.MinorRadius();
1032 }
1033 //
1034 if (aCTType == GeomAbs_Torus) {
1035 aCTAx = aTor1.Axis();
18d25b93 1036 }
18d25b93 1037 }
1038 //
1039 if (bToCheck) {
1040 const gp_Lin aL1(aCTAx);
1041 //
1042 switch (aGeomSurf->GetType()) {
1043 case GeomAbs_Plane: {
1044 aGeomAx = aGeomSurf->Plane().Axis();
1045 if (aCTType == GeomAbs_Cone) {
1d18c75e 1046 bGeomGeom = 1;
18d25b93 1047 if (Abs(aCTSurf->Cone().SemiAngle()) < 0.02) {
1048 Standard_Real ps = Abs(aCTAx.Direction().Dot(aGeomAx.Direction()));
1049 if(ps < 0.015) {
1d18c75e 1050 bGeomGeom = 0;
18d25b93 1051 }
788cbaf4 1052 }
1053 }
18d25b93 1054 else {
1055 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) ||
1056 (aCTAx.IsNormal(aGeomAx, Precision::Angular()) &&
1057 (aGeomSurf->Plane().Distance(aCTAx.Location()) < Precision::Confusion()))) {
1d18c75e 1058 bGeomGeom = 1;
18d25b93 1059 }
1060 }
1061 bToCheck = Standard_False;
1062 break;
7fd59977 1063 }
18d25b93 1064 case GeomAbs_Sphere: {
1065 if (aL1.Distance(aGeomSurf->Sphere().Location()) < Precision::Confusion()) {
1d18c75e 1066 bGeomGeom = 1;
18d25b93 1067 }
1068 bToCheck = Standard_False;
1069 break;
7fd59977 1070 }
18d25b93 1071 case GeomAbs_Cylinder:
1072 aGeomAx = aGeomSurf->Cylinder().Axis();
1073 break;
1074 case GeomAbs_Cone:
1075 aGeomAx = aGeomSurf->Cone().Axis();
1076 break;
1077 case GeomAbs_Torus:
1078 aGeomAx = aGeomSurf->Torus().Axis();
1079 break;
1080 default:
1081 bToCheck = Standard_False;
1082 break;
1083 }
1084 //
1085 if (bToCheck) {
1086 if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) &&
1087 (aL1.Distance(aGeomAx.Location()) <= Precision::Confusion())) {
1d18c75e 1088 bGeomGeom = 1;
788cbaf4 1089 }
7fd59977 1090 }
18d25b93 1091 //
1d18c75e 1092 if (bGeomGeom == 1) {
1093 TreatAsBiParametric = Standard_False;
18d25b93 1094 }
1095 }
1096 }
1097 //
7fd59977 1098
788cbaf4 1099 if(theD1->DomainIsInfinite() || theD2->DomainIsInfinite()) {
bf0ba813 1100 TreatAsBiParametric= Standard_False;
1101 }
788cbaf4 1102
1103 if(TreatAsBiParametric)
1104 {
1105 // Using Prm-Prm Intersector
1106 typs1 = GeomAbs_BezierSurface;
1107 typs2 = GeomAbs_BezierSurface;
bf0ba813 1108 }
7fd59977 1109
1110 // Surface type definition
1111 Standard_Integer ts1 = 0;
1112 switch (typs1)
1113 {
1114 case GeomAbs_Plane:
1115 case GeomAbs_Cylinder:
1116 case GeomAbs_Sphere:
1117 case GeomAbs_Cone: ts1 = 1; break;
1d18c75e 1118 case GeomAbs_Torus: ts1 = bGeomGeom; break;
7fd59977 1119 default: break;
1120 }
788cbaf4 1121
7fd59977 1122 Standard_Integer ts2 = 0;
1123 switch (typs2)
1124 {
1125 case GeomAbs_Plane:
1126 case GeomAbs_Cylinder:
1127 case GeomAbs_Sphere:
1128 case GeomAbs_Cone: ts2 = 1; break;
1d18c75e 1129 case GeomAbs_Torus: ts2 = bGeomGeom; break;
7fd59977 1130 default: break;
1131 }
7eed5d29 1132 //
7fd59977 1133 // Possible intersection types: 1. ts1 == ts2 == 1 <Geom-Geom>
1134 // 2. ts1 != ts2 <Geom-Param>
1135 // 3. ts1 == ts2 == 0 <Param-Param>
1136
788cbaf4 1137 if(!isGeomInt)
7fd59977 1138 {
02effd35 1139 ParamParamPerfom(theS1, theD1, theS2, theD2,
1140 TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
7fd59977 1141 }
788cbaf4 1142 else if(ts1 != ts2)
1143 {
1144 GeomParamPerfom(theS1, theD1, theS2, theD2, ts1 == 0, typs1, typs2);
1145 }
1146 else if (ts1 == 0)
1147 {
02effd35 1148 ParamParamPerfom(theS1, theD1, theS2, theD2,
1149 TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
788cbaf4 1150 }
1151 else if(ts1 == 1)
1152 {
ecc4f148 1153 if(theD1->DomainIsInfinite() || theD2->DomainIsInfinite())
1154 {
1155 GeomGeomPerfom(theS1, theD1, theS2, theD2, TolArc,
1156 TolTang, ListOfPnts, RestrictLine, typs1, typs2);
1157 }
1158 else
1159 {
1160 GeomGeomPerfomTrimSurf(theS1, theD1, theS2, theD2,
1161 TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
1162 }
788cbaf4 1163 }
1164}
1165
1166//=======================================================================
1167//function : ParamParamPerfom
1168//purpose :
1169//=======================================================================
1170void IntPatch_Intersection::ParamParamPerfom(const Handle(Adaptor3d_HSurface)& theS1,
1171 const Handle(Adaptor3d_TopolTool)& theD1,
1172 const Handle(Adaptor3d_HSurface)& theS2,
1173 const Handle(Adaptor3d_TopolTool)& theD2,
1174 const Standard_Real TolArc,
1175 const Standard_Real TolTang,
1176 IntSurf_ListOfPntOn2S& ListOfPnts,
1177 const Standard_Boolean RestrictLine,
1178 const GeomAbs_SurfaceType typs1,
1179 const GeomAbs_SurfaceType typs2)
1180{
1181 IntPatch_PrmPrmIntersection interpp;
1182 if(!theD1->DomainIsInfinite() && !theD2->DomainIsInfinite())
7fd59977 1183 {
788cbaf4 1184 Standard_Boolean ClearFlag = Standard_True;
1185 if(!ListOfPnts.IsEmpty())
1186 {
1187 interpp.Perform(theS1,theD1,theS2,theD2,TolArc,TolTang,myFleche,myUVMaxStep, ListOfPnts, RestrictLine);
1188 ClearFlag = Standard_False;
7fd59977 1189 }
788cbaf4 1190 interpp.Perform(theS1,theD1,theS2,theD2,TolArc,TolTang,myFleche,myUVMaxStep,ClearFlag); //double call!!!!!!!
7fd59977 1191 }
788cbaf4 1192 else if((theD1->DomainIsInfinite()) ^ (theD2->DomainIsInfinite()))
7fd59977 1193 {
788cbaf4 1194 gp_Pnt pMaxXYZ, pMinXYZ;
1195 if(theD1->DomainIsInfinite())
1196 {
1197 FUN_GetMinMaxXYZPnt( theS2, pMinXYZ, pMaxXYZ );
1198 const Standard_Real MU = Max(Abs(theS2->FirstUParameter()),Abs(theS2->LastUParameter()));
1199 const Standard_Real MV = Max(Abs(theS2->FirstVParameter()),Abs(theS2->LastVParameter()));
1200 const Standard_Real AP = Max(MU, MV);
1201 Handle(Adaptor3d_HSurface) SS;
1202 FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, theS1, AP, SS);
1203 interpp.Perform(SS,theD1,theS2,theD2,TolArc,TolTang,myFleche,myUVMaxStep);
1204 }
1205 else
1206 {
1207 FUN_GetMinMaxXYZPnt( theS1, pMinXYZ, pMaxXYZ );
1208 const Standard_Real MU = Max(Abs(theS1->FirstUParameter()),Abs(theS1->LastUParameter()));
1209 const Standard_Real MV = Max(Abs(theS1->FirstVParameter()),Abs(theS1->LastVParameter()));
1210 const Standard_Real AP = Max(MU, MV);
1211 Handle(Adaptor3d_HSurface) SS;
1212 FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, theS2, AP, SS);
1213 interpp.Perform(theS1, theD1, SS, theD2,TolArc,TolTang,myFleche,myUVMaxStep);
1214 }
1215 }//(theD1->DomainIsInfinite()) ^ (theD2->DomainIsInfinite())
1216 else
1217 {
1218 if(typs1 == GeomAbs_OtherSurface || typs2 == GeomAbs_OtherSurface)
1219 {
1220 done = Standard_False;
1221 return;
1222 }
1223
1224 Standard_Boolean IsPLInt = Standard_False;
1225 TColgp_SequenceOfPnt sop;
1226 gp_Vec v;
1227 FUN_PL_Intersection(theS1,typs1,theS2,typs2,IsPLInt,sop,v);
1228
1229 if(IsPLInt)
1230 {
1231 if(sop.Length() > 0)
1232 {
1233 for(Standard_Integer ip = 1; ip <= sop.Length(); ip++)
1234 {
1235 gp_Lin lin(sop.Value(ip),gp_Dir(v));
1236 Handle(IntPatch_GLine) gl = new IntPatch_GLine(lin,Standard_False);
857ffd5e 1237 slin.Append(*(Handle(IntPatch_Line) *)&gl);
788cbaf4 1238 }
1239
1240 done = Standard_True;
7fd59977 1241 }
788cbaf4 1242 else
1243 done = Standard_False;
1244
1245 return;
1246 }// 'COLLINEAR LINES'
1247 else
1248 {
1249 Handle(Adaptor3d_HSurface) nS1 = theS1;
1250 Handle(Adaptor3d_HSurface) nS2 = theS2;
1251 FUN_TrimBothSurf(theS1,typs1,theS2,typs2,1.e+8,nS1,nS2);
1252 interpp.Perform(nS1,theD1,nS2,theD2,TolArc,TolTang,myFleche,myUVMaxStep);
1253 }// 'NON - COLLINEAR LINES'
1254 }// both domains are infinite
1255
1256 if (interpp.IsDone())
1257 {
1258 done = Standard_True;
1259 tgte = Standard_False;
1260 empt = interpp.IsEmpty();
1261
1262 for(Standard_Integer i = 1; i <= interpp.NbLines(); i++)
1263 {
1264 if(interpp.Line(i)->ArcType() != IntPatch_Walking)
1265 slin.Append(interpp.Line(i));
1266 }
1267
1268 for (Standard_Integer i = 1; i <= interpp.NbLines(); i++)
1269 {
1270 if(interpp.Line(i)->ArcType() == IntPatch_Walking)
1271 slin.Append(interpp.Line(i));
1272 }
1273 }
1274}
1275
1276//=======================================================================
1277////function : GeomGeomPerfom
1278//purpose :
1279//=======================================================================
1280void IntPatch_Intersection::GeomGeomPerfom(const Handle(Adaptor3d_HSurface)& theS1,
1281 const Handle(Adaptor3d_TopolTool)& theD1,
1282 const Handle(Adaptor3d_HSurface)& theS2,
1283 const Handle(Adaptor3d_TopolTool)& theD2,
1284 const Standard_Real TolArc,
1285 const Standard_Real TolTang,
1286 IntSurf_ListOfPntOn2S& ListOfPnts,
1287 const Standard_Boolean RestrictLine,
1288 const GeomAbs_SurfaceType typs1,
1289 const GeomAbs_SurfaceType typs2)
1290{
1291 IntPatch_ImpImpIntersection interii(theS1,theD1,theS2,theD2,myTolArc,myTolTang);
1292 const Standard_Boolean anIS = interii.IsDone();
1293 if (anIS)
1294 {
1295 done = anIS;
1296 empt = interii.IsEmpty();
1297 if (!empt)
1298 {
1299 tgte = interii.TangentFaces();
1300 if (tgte)
1301 oppo = interii.OppositeFaces();
1302
1303 for (Standard_Integer i = 1; i <= interii.NbLines(); i++)
1304 {
857ffd5e 1305 const Handle(IntPatch_Line)& line = interii.Line(i);
788cbaf4 1306 if (line->ArcType() == IntPatch_Analytic)
1307 {
1308 const GeomAbs_SurfaceType typs1 = theS1->GetType();
1309 const GeomAbs_SurfaceType typs2 = theS2->GetType();
1310 IntSurf_Quadric Quad1,Quad2;
1311
1312 switch(typs1)
1313 {
1314 case GeomAbs_Plane:
1315 Quad1.SetValue(theS1->Plane());
1316 break;
1317
1318 case GeomAbs_Cylinder:
1319 Quad1.SetValue(theS1->Cylinder());
1320 break;
1321
1322 case GeomAbs_Sphere:
1323 Quad1.SetValue(theS1->Sphere());
1324 break;
1325
1326 case GeomAbs_Cone:
1327 Quad1.SetValue(theS1->Cone());
1328 break;
1329
7eed5d29 1330 case GeomAbs_Torus:
1331 Quad1.SetValue(theS1->Torus());
1332 break;
1333
788cbaf4 1334 default:
1335 break;
1336 }
1337
1338 switch(typs2)
1339 {
1340 case GeomAbs_Plane:
1341 Quad2.SetValue(theS2->Plane());
1342 break;
1343 case GeomAbs_Cylinder:
1344 Quad2.SetValue(theS2->Cylinder());
1345 break;
1346
1347 case GeomAbs_Sphere:
1348 Quad2.SetValue(theS2->Sphere());
1349 break;
1350
1351 case GeomAbs_Cone:
1352 Quad2.SetValue(theS2->Cone());
1353 break;
1354
7eed5d29 1355 case GeomAbs_Torus:
1356 Quad2.SetValue(theS2->Torus());
1357 break;
1358
788cbaf4 1359 default:
1360 break;
1361 }
1362
1363 IntPatch_ALineToWLine AToW(Quad1,Quad2,0.01,0.05,aNbPointsInALine);
857ffd5e 1364 Handle(IntPatch_Line) wlin=AToW.MakeWLine((*((Handle(IntPatch_ALine) *)(&line))));
788cbaf4 1365 slin.Append(wlin);
1366 }
1367 else
1368 slin.Append(interii.Line(i));
1369 }
1370
1371 for (Standard_Integer i = 1; i <= interii.NbPnts(); i++)
1372 {
1373 spnt.Append(interii.Point(i));
1374 }
1375 }
1376 }
1377 else
02effd35 1378 ParamParamPerfom(theS1, theD1, theS2, theD2,
1379 TolArc, TolTang, ListOfPnts, RestrictLine, typs1, typs2);
788cbaf4 1380}
1381
1382//=======================================================================
ecc4f148 1383//function : GeomParamPerfom
788cbaf4 1384//purpose :
1385//=======================================================================
ecc4f148 1386void IntPatch_Intersection::
1387 GeomParamPerfom(const Handle(Adaptor3d_HSurface)& theS1,
1388 const Handle(Adaptor3d_TopolTool)& theD1,
1389 const Handle(Adaptor3d_HSurface)& theS2,
1390 const Handle(Adaptor3d_TopolTool)& theD2,
1391 const Standard_Boolean isNotAnalitical,
1392 const GeomAbs_SurfaceType typs1,
1393 const GeomAbs_SurfaceType typs2)
788cbaf4 1394{
1395 IntPatch_ImpPrmIntersection interip;
1396 if (myIsStartPnt)
1397 {
1398 if (isNotAnalitical/*ts1 == 0*/)
1399 interip.SetStartPoint(myU1Start,myV1Start);
1400 else
1401 interip.SetStartPoint(myU2Start,myV2Start);
1402 }
1403
1404 if(theD1->DomainIsInfinite() && theD2->DomainIsInfinite())
1405 {
1406 Standard_Boolean IsPLInt = Standard_False;
1407 TColgp_SequenceOfPnt sop;
1408 gp_Vec v;
1409 FUN_PL_Intersection(theS1,typs1,theS2,typs2,IsPLInt,sop,v);
1410
1411 if(IsPLInt)
1412 {
1413 if(sop.Length() > 0)
1414 {
1415 for(Standard_Integer ip = 1; ip <= sop.Length(); ip++)
1416 {
1417 gp_Lin lin(sop.Value(ip),gp_Dir(v));
1418 Handle(IntPatch_GLine) gl = new IntPatch_GLine(lin,Standard_False);
857ffd5e 1419 slin.Append(*(Handle(IntPatch_Line) *)&gl);
788cbaf4 1420 }
1421
1422 done = Standard_True;
1423 }
1424 else
1425 done = Standard_False;
1426
1427 return;
1428 }
1429 else
1430 {
1431 Handle(Adaptor3d_HSurface) nS1 = theS1;
1432 Handle(Adaptor3d_HSurface) nS2 = theS2;
1433 FUN_TrimBothSurf(theS1,typs1,theS2,typs2,1.e+5,nS1,nS2);
1434 interip.Perform(nS1,theD1,nS2,theD2,myTolArc,myTolTang,myFleche,myUVMaxStep);
1435 }
1436 }
1437 else
1438 interip.Perform(theS1,theD1,theS2,theD2,myTolArc,myTolTang,myFleche,myUVMaxStep);
1439
1440 if (interip.IsDone())
1441 {
1442 done = Standard_True;
1443 empt = interip.IsEmpty();
1444
1445 if (!empt)
1446 {
b92f3572 1447 const Standard_Integer aNbLines = interip.NbLines();
1448 for(Standard_Integer i = 1; i <= aNbLines; i++)
788cbaf4 1449 {
1450 if(interip.Line(i)->ArcType() != IntPatch_Walking)
1451 slin.Append(interip.Line(i));
1452 }
1453
b92f3572 1454 for(Standard_Integer i = 1; i <= aNbLines; i++)
788cbaf4 1455 {
1456 if(interip.Line(i)->ArcType() == IntPatch_Walking)
1457 slin.Append(interip.Line(i));
1458 }
1459
1460 for (Standard_Integer i = 1; i <= interip.NbPnts(); i++)
1461 spnt.Append(interip.Point(i));
1462 }
7fd59977 1463 }
1464}
1465
ecc4f148 1466//=======================================================================
1467//function : GeomGeomPerfomTrimSurf
1468//purpose : This function returns ready walking-line (which is not need
1469// in convertation) as an intersection line between two
1470// trimmed surfaces.
1471//=======================================================================
1472void IntPatch_Intersection::
1473 GeomGeomPerfomTrimSurf( const Handle(Adaptor3d_HSurface)& theS1,
1474 const Handle(Adaptor3d_TopolTool)& theD1,
1475 const Handle(Adaptor3d_HSurface)& theS2,
1476 const Handle(Adaptor3d_TopolTool)& theD2,
1477 const Standard_Real theTolArc,
1478 const Standard_Real theTolTang,
1479 IntSurf_ListOfPntOn2S& theListOfPnts,
1480 const Standard_Boolean RestrictLine,
1481 const GeomAbs_SurfaceType theTyps1,
1482 const GeomAbs_SurfaceType theTyps2)
1483{
1484 IntSurf_Quadric Quad1,Quad2;
1485
1486 if((theTyps1 == GeomAbs_Cylinder) && (theTyps2 == GeomAbs_Cylinder))
1487 {
1488 IntPatch_ImpImpIntersection anInt;
02effd35 1489 anInt.Perform(theS1, theD1, theS2, theD2, myTolArc, myTolTang, Standard_True);
ecc4f148 1490
1491 done = anInt.IsDone();
1492
02effd35 1493 if(done)
ecc4f148 1494 {
02effd35 1495 empt = anInt.IsEmpty();
1496 if (!empt)
1497 {
1498 tgte = anInt.TangentFaces();
1499 if (tgte)
1500 oppo = anInt.OppositeFaces();
ecc4f148 1501
02effd35 1502 const Standard_Integer aNbLin = anInt.NbLines();
1503 const Standard_Integer aNbPts = anInt.NbPnts();
1504
1505 for(Standard_Integer aLID = 1; aLID <= aNbLin; aLID++)
1506 {
1507 const Handle(IntPatch_Line)& aLine = anInt.Line(aLID);
1508 slin.Append(aLine);
1509 }
1510
1511 for(Standard_Integer aPID = 1; aPID <= aNbPts; aPID++)
1512 {
1513 const IntPatch_Point& aPoint = anInt.Point(aPID);
1514 spnt.Append(aPoint);
1515 }
1516 }
ecc4f148 1517 }
1518 }
1519 else
1520 {
02effd35 1521 GeomGeomPerfom(theS1, theD1, theS2, theD2,
1522 theTolArc, theTolTang, theListOfPnts, RestrictLine, theTyps1, theTyps2);
ecc4f148 1523 }
1524}
1525
788cbaf4 1526
7fd59977 1527void IntPatch_Intersection::Perform(const Handle(Adaptor3d_HSurface)& S1,
1528 const Handle(Adaptor3d_TopolTool)& D1,
1529 const Handle(Adaptor3d_HSurface)& S2,
1530 const Handle(Adaptor3d_TopolTool)& D2,
1531 const Standard_Real U1,
1532 const Standard_Real V1,
1533 const Standard_Real U2,
1534 const Standard_Real V2,
1535 const Standard_Real TolArc,
1536 const Standard_Real TolTang)
1537{
1538 myTolArc = TolArc;
1539 myTolTang = TolTang;
1540 if(myFleche == 0.0) {
1541#if DEBUG
1542 //cout<<" -- IntPatch_Intersection::myFleche fixe par defaut a 0.01 --"<<endl;
1543 //cout<<" -- Utiliser la Methode SetTolerances( ... ) "<<endl;
1544#endif
1545 myFleche = 0.01;
1546 }
1547 if(myUVMaxStep==0.0) {
1548#if DEBUG
1549 //cout<<" -- IntPatch_Intersection::myUVMaxStep fixe par defaut a 0.01 --"<<endl;
1550 //cout<<" -- Utiliser la Methode SetTolerances( ... ) "<<endl;
1551#endif
1552 myUVMaxStep = 0.01;
1553 }
1554
1555 done = Standard_False;
1556 spnt.Clear();
1557 slin.Clear();
1558
1559 empt = Standard_True;
1560 tgte = Standard_False;
1561 oppo = Standard_False;
1562
1563 const GeomAbs_SurfaceType typs1 = S1->GetType();
1564 const GeomAbs_SurfaceType typs2 = S2->GetType();
1565
1566 if( typs1==GeomAbs_Plane
1567 || typs1==GeomAbs_Cylinder
1568 || typs1==GeomAbs_Sphere
1569 || typs1==GeomAbs_Cone
1570 || typs2==GeomAbs_Plane
1571 || typs2==GeomAbs_Cylinder
1572 || typs2==GeomAbs_Sphere
1573 || typs2==GeomAbs_Cone)
1574 {
1575 myIsStartPnt = Standard_True;
1576 myU1Start = U1; myV1Start = V1; myU2Start = U2; myV2Start = V2;
1577 Perform(S1,D1,S2,D2,TolArc,TolTang);
1578 myIsStartPnt = Standard_False;
1579 }
1580 else
1581 {
1582 IntPatch_PrmPrmIntersection interpp;
1583 interpp.Perform(S1,D1,S2,D2,U1,V1,U2,V2,TolArc,TolTang,myFleche,myUVMaxStep);
1584 if (interpp.IsDone())
1d18c75e 1585 {
7fd59977 1586 done = Standard_True;
1587 tgte = Standard_False;
1588 empt = interpp.IsEmpty();
1589 const Standard_Integer nblm = interpp.NbLines();
1590 Standard_Integer i = 1;
1591 for (; i<=nblm; i++) slin.Append(interpp.Line(i));
1592 }
1593 }
1594}
1595//======================================================================
1596#include <IntPatch_IType.hxx>
1597#include <IntPatch_LineConstructor.hxx>
cb389a77 1598#include <Adaptor2d_HCurve2d.hxx>
7fd59977 1599#define MAXR 200
1600
1601
857ffd5e 1602//void IntPatch_Intersection__MAJ_R(Handle(Adaptor2d_HCurve2d) *R1,
1603// Handle(Adaptor2d_HCurve2d) *R2,
1d18c75e 1604// int *NR1,
1605// int *NR2,
1606// Standard_Integer nbR1,
1607// Standard_Integer nbR2,
1608// const IntPatch_Point& VTX)
857ffd5e 1609void IntPatch_Intersection__MAJ_R(Handle(Adaptor2d_HCurve2d) *,
1610 Handle(Adaptor2d_HCurve2d) *,
1d18c75e 1611 int *,
1612 int *,
1613 Standard_Integer ,
1614 Standard_Integer ,
1615 const IntPatch_Point& )
7fd59977 1616{
1617 /*
1618 if(VTX.IsOnDomS1()) {
1619
857ffd5e 1620 //-- long unsigned ptr= *((long unsigned *)(((Handle(Standard_Transient) *)(&(VTX.ArcOnS1())))));
7fd59977 1621 for(Standard_Integer i=0; i<nbR1;i++) {
1622 if(VTX.ArcOnS1()==R1[i]) {
1d18c75e 1623 NR1[i]++;
1624 printf("\n ******************************");
1625 return;
7fd59977 1626 }
1627 }
1628 printf("\n R Pas trouvee (IntPatch)\n");
1629
1630 }
1631 */
1632}
1633
1634
1635//void IntPatch_Intersection::Dump(const Standard_Integer Mode,
1636void IntPatch_Intersection::Dump(const Standard_Integer ,
1d18c75e 1637 const Handle(Adaptor3d_HSurface)& S1,
1638 const Handle(Adaptor3d_TopolTool)& D1,
1639 const Handle(Adaptor3d_HSurface)& S2,
1640 const Handle(Adaptor3d_TopolTool)& D2) const
7fd59977 1641{
1642
1643 //-- ----------------------------------------------------------------------
1644 //-- construction de la liste des restrictions & vertex
1645 //--
1646 int NR1[MAXR],NR2[MAXR];
857ffd5e 1647 Handle(Adaptor2d_HCurve2d) R1[MAXR],R2[MAXR];
7fd59977 1648 Standard_Integer nbR1=0,nbR2=0;
1649 for(D1->Init();D1->More() && nbR1<MAXR; D1->Next()) {
1650 R1[nbR1]=D1->Value();
1651 NR1[nbR1]=0;
1652 nbR1++;
1653 }
1654 for(D2->Init();D2->More() && nbR2<MAXR; D2->Next()) {
1655 R2[nbR2]=D2->Value();
1656 NR2[nbR2]=0;
1657 nbR2++;
1658 }
1659
566f8441 1660 printf("\nDUMP_INT: ----empt:%2ud tgte:%2ud oppo:%2ud ---------------------------------",empt,tgte,empt);
7fd59977 1661 Standard_Integer i,j,nbr1,nbr2,nbgl,nbgc,nbge,nbgp,nbgh,nbl,nbr,nbg,nbw,nba;
1662 nbl=nbr=nbg=nbw=nba=nbgl=nbge=nbr1=nbr2=nbgc=nbgp=nbgh=0;
1663 nbl=NbLines();
1664 for(i=1;i<=nbl;i++) {
1665 const Handle(IntPatch_Line)& line=Line(i);
1666 const IntPatch_IType IType=line->ArcType();
1667 if(IType == IntPatch_Walking) nbw++;
1668 else if(IType == IntPatch_Restriction) {
1669 nbr++;
1670 Handle(IntPatch_RLine)& rlin =
1d18c75e 1671 *((Handle(IntPatch_RLine) *)&line);
7fd59977 1672 if(rlin->IsArcOnS1()) nbr1++;
1673 if(rlin->IsArcOnS2()) nbr2++;
1674 }
1675 else if(IType == IntPatch_Analytic) nba++;
1d18c75e 1676 else {
1677 nbg++;
1678 if(IType == IntPatch_Lin) nbgl++;
1679 else if(IType == IntPatch_Circle) nbgc++;
1680 else if(IType == IntPatch_Parabola) nbgp++;
1681 else if(IType == IntPatch_Hyperbola) nbgh++;
1682 else if(IType == IntPatch_Ellipse) nbge++;
1683 }
7fd59977 1684 }
1685
1686
1687 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)",
1d18c75e 1688 nbl,nbw,nbr,nbr1,nbr2,nba,nbg,nbgl,nbgc,nbge,nbgh,nbgp);
7fd59977 1689
1690 IntPatch_LineConstructor LineConstructor(2);
1691
1692 Standard_Integer nbllc=0;
1693 nbw=nbr=nbg=nba=0;
1694 Standard_Integer nbva,nbvw,nbvr,nbvg;
1695 nbva=nbvr=nbvw=nbvg=0;
1696 for (j=1; j<=nbl; j++) {
1697 Standard_Integer v,nbvtx;
1698 const Handle(IntPatch_Line)& intersLinej = Line(j);
1699 Standard_Integer NbLines;
1700 LineConstructor.Perform(SequenceOfLine(),intersLinej,S1,D1,S2,D2,1e-7);
1701 NbLines = LineConstructor.NbLines();
1702
1703 for(Standard_Integer k=1;k<=NbLines;k++) {
1704 nbllc++;
1705 const Handle(IntPatch_Line)& LineK = LineConstructor.Line(k);
1706 if (LineK->ArcType() == IntPatch_Analytic) {
1d18c75e 1707 Handle(IntPatch_ALine)& alin =
1708 *((Handle(IntPatch_ALine) *)&LineK);
1709 nbvtx=alin->NbVertex();
1710 nbva+=nbvtx; nba++;
1711 for(v=1;v<=nbvtx;v++) {
1712 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,alin->Vertex(v));
1713 }
7fd59977 1714 }
1715 else if (LineK->ArcType() == IntPatch_Restriction) {
1d18c75e 1716 Handle(IntPatch_RLine)& rlin =
1717 *((Handle(IntPatch_RLine) *)&LineK);
1718 nbvtx=rlin->NbVertex();
1719 nbvr+=nbvtx; nbr++;
1720 for(v=1;v<=nbvtx;v++) {
1721 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,rlin->Vertex(v));
1722 }
7fd59977 1723 }
1724 else if (LineK->ArcType() == IntPatch_Walking) {
1d18c75e 1725 Handle(IntPatch_WLine)& wlin =
1726 *((Handle(IntPatch_WLine) *)&LineK);
1727 nbvtx=wlin->NbVertex();
1728 nbvw+=nbvtx; nbw++;
1729 for(v=1;v<=nbvtx;v++) {
1730 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,wlin->Vertex(v));
1731 }
7fd59977 1732 }
1733 else {
1d18c75e 1734 Handle(IntPatch_GLine)& glin =
1735 *((Handle(IntPatch_GLine) *)&LineK);
1736 nbvtx=glin->NbVertex();
1737 nbvg+=nbvtx; nbg++;
1738 for(v=1;v<=nbvtx;v++) {
1739 IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,glin->Vertex(v));
1740 }
7fd59977 1741 }
1742 }
1743 }
1744 printf("\nDUMP_LC :Lines:%2d WLin:%2d Restr:%2d Ana:%2d Geom:%2d",
1d18c75e 1745 nbllc,nbw,nbr,nba,nbg);
7fd59977 1746 printf("\nDUMP_LC :vtx :%2d r:%2d :%2d :%2d",
1d18c75e 1747 nbvw,nbvr,nbva,nbvg);
7fd59977 1748
1749
1750
1751 printf("\n");
1752}