0024307: TKOpenGl - efficient culling of large number of presentations
[occt.git] / src / IntTools / IntTools_FaceFace.cxx
CommitLineData
b311480e 1// Created on: 2000-11-23
2// Created by: Michael KLOKOV
973c2be1 3// Copyright (c) 2000-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
16#include <IntTools_FaceFace.ixx>
17
18#include <Precision.hxx>
19
20#include <TColStd_HArray1OfReal.hxx>
21#include <TColStd_Array1OfReal.hxx>
22#include <TColStd_Array1OfInteger.hxx>
23#include <TColStd_SequenceOfReal.hxx>
24#include <TColStd_ListOfInteger.hxx>
25#include <TColStd_ListIteratorOfListOfInteger.hxx>
26#include <TColStd_Array1OfListOfInteger.hxx>
27
28#include <gp_Lin2d.hxx>
29#include <gp_Ax22d.hxx>
30#include <gp_Circ2d.hxx>
31#include <gp_Torus.hxx>
32#include <gp_Cylinder.hxx>
33
34#include <Bnd_Box.hxx>
35
36#include <TColgp_HArray1OfPnt2d.hxx>
37#include <TColgp_SequenceOfPnt2d.hxx>
38#include <TColgp_Array1OfPnt.hxx>
39#include <TColgp_Array1OfPnt2d.hxx>
40
41#include <IntAna_QuadQuadGeo.hxx>
42
43#include <IntSurf_PntOn2S.hxx>
44#include <IntSurf_LineOn2S.hxx>
45#include <IntSurf_PntOn2S.hxx>
46#include <IntSurf_ListOfPntOn2S.hxx>
47#include <IntRes2d_Domain.hxx>
48#include <ProjLib_Plane.hxx>
49
50#include <IntPatch_GLine.hxx>
51#include <IntPatch_RLine.hxx>
52#include <IntPatch_WLine.hxx>
53#include <IntPatch_ALine.hxx>
54#include <IntPatch_ALineToWLine.hxx>
55
56#include <ElSLib.hxx>
57#include <ElCLib.hxx>
58
59#include <Extrema_ExtCC.hxx>
60#include <Extrema_POnCurv.hxx>
61#include <BndLib_AddSurface.hxx>
62
63#include <Adaptor3d_SurfacePtr.hxx>
64#include <Adaptor2d_HLine2d.hxx>
65
66#include <GeomAbs_SurfaceType.hxx>
67#include <GeomAbs_CurveType.hxx>
68
69#include <Geom_Surface.hxx>
70#include <Geom_Line.hxx>
71#include <Geom_Circle.hxx>
72#include <Geom_Ellipse.hxx>
73#include <Geom_Parabola.hxx>
74#include <Geom_Hyperbola.hxx>
75#include <Geom_TrimmedCurve.hxx>
76#include <Geom_BSplineCurve.hxx>
77#include <Geom_RectangularTrimmedSurface.hxx>
78#include <Geom_OffsetSurface.hxx>
79#include <Geom_Curve.hxx>
80#include <Geom_Conic.hxx>
81
82#include <Geom2d_TrimmedCurve.hxx>
83#include <Geom2d_BSplineCurve.hxx>
84#include <Geom2d_Line.hxx>
85#include <Geom2d_Curve.hxx>
86#include <Geom2d_Circle.hxx>
87
88#include <Geom2dAPI_InterCurveCurve.hxx>
89#include <Geom2dInt_GInter.hxx>
90#include <GeomAdaptor_Curve.hxx>
91#include <GeomAdaptor_HSurface.hxx>
92#include <GeomAdaptor_Surface.hxx>
93#include <GeomLib_CheckBSplineCurve.hxx>
94#include <GeomLib_Check2dBSplineCurve.hxx>
95
96#include <GeomInt_WLApprox.hxx>
97#include <GeomProjLib.hxx>
98#include <GeomAPI_ProjectPointOnSurf.hxx>
99#include <Geom2dAdaptor_Curve.hxx>
7fd59977 100#include <TopoDS.hxx>
101#include <TopoDS_Edge.hxx>
102#include <TopExp_Explorer.hxx>
103
104#include <BRep_Tool.hxx>
105#include <BRepTools.hxx>
106#include <BRepAdaptor_Surface.hxx>
107
7fd59977 108#include <IntTools_Curve.hxx>
109#include <IntTools_Tools.hxx>
110#include <IntTools_Tools.hxx>
111#include <IntTools_TopolTool.hxx>
112#include <IntTools_PntOnFace.hxx>
113#include <IntTools_PntOn2Faces.hxx>
1e143abb 114#include <IntTools_Context.hxx>
0fc4f2e2 115#include <IntSurf_ListIteratorOfListOfPntOn2S.hxx>
a2eede02 116
fa9681ca
P
117static
118 void RefineVector(gp_Vec2d& aV2D);
4e18e72a 119#ifdef DEB_DUMPWLINE
a2eede02
P
120static
121 void DumpWLine(const Handle(IntPatch_WLine)& aWLine);
4e18e72a 122#endif
7fd59977 123//
124static
125 void TolR3d(const TopoDS_Face& ,
655fddc8 126 const TopoDS_Face& ,
127 Standard_Real& );
7fd59977 128static
129 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)&,
655fddc8 130 const Standard_Integer,
131 const Standard_Integer);
7fd59977 132
133static
134 void Parameters(const Handle(GeomAdaptor_HSurface)&,
655fddc8 135 const Handle(GeomAdaptor_HSurface)&,
136 const gp_Pnt&,
137 Standard_Real&,
138 Standard_Real&,
139 Standard_Real&,
140 Standard_Real&);
7fd59977 141
142static
143 void BuildPCurves (Standard_Real f,Standard_Real l,Standard_Real& Tol,
655fddc8 144 const Handle (Geom_Surface)& S,
145 const Handle (Geom_Curve)& C,
146 Handle (Geom2d_Curve)& C2d);
7fd59977 147
148static
149 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
655fddc8 150 const Standard_Real theTolerance,
151 Standard_Real& theumin,
152 Standard_Real& theumax,
153 Standard_Real& thevmin,
154 Standard_Real& thevmax);
7fd59977 155static
156 Standard_Boolean NotUseSurfacesForApprox
157 (const TopoDS_Face& aF1,
655fddc8 158 const TopoDS_Face& aF2,
159 const Handle(IntPatch_WLine)& WL,
160 const Standard_Integer ifprm,
161 const Standard_Integer ilprm);
7fd59977 162
163static
164 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine);
165
166static
7fd59977 167 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
655fddc8 168 const Standard_Integer ideb,
169 const Standard_Integer ifin,
170 const Standard_Boolean onFirst);
7fd59977 171
172static
173 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
655fddc8 174 const Handle(GeomAdaptor_HSurface)& theSurface1,
175 const Handle(GeomAdaptor_HSurface)& theSurface2,
176 const TopoDS_Face& theFace1,
177 const TopoDS_Face& theFace2,
178 const IntTools_LineConstructor& theLConstructor,
179 const Standard_Boolean theAvoidLConstructor,
180 IntPatch_SequenceOfLine& theNewLines,
181 Standard_Real& theReachedTol3d,
1e143abb 182 const Handle(IntTools_Context)& );
7fd59977 183
184static
185 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
655fddc8 186 const Handle(Geom_Curve)& theCurve,
187 const TopoDS_Face& theFace1,
188 const TopoDS_Face& theFace2,
189 const Standard_Real theOtherParameter,
190 const Standard_Boolean bIncreasePar,
191 Standard_Real& theNewParameter,
1e143abb 192 const Handle(IntTools_Context)& );
7fd59977 193
194static
195 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve);
196
197static
198 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
655fddc8 199 const Standard_Real theFirstBoundary,
200 const Standard_Real theSecondBoundary,
201 const Standard_Real theResolution,
202 Standard_Boolean& IsOnFirstBoundary);
7fd59977 203static
204 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
655fddc8 205 const gp_Pnt2d& theLastPoint,
206 const Standard_Real theUmin,
207 const Standard_Real theUmax,
208 const Standard_Real theVmin,
209 const Standard_Real theVmax,
210 gp_Pnt2d& theNewPoint);
7fd59977 211
212
213static
214 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
655fddc8 215 const Handle(GeomAdaptor_HSurface)& theSurface2,
216 const TopoDS_Face& theFace1,
217 const TopoDS_Face& theFace2,
218 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
219 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
220 Handle(TColStd_HArray1OfReal)& theResultRadius,
1e143abb 221 const Handle(IntTools_Context)& );
7fd59977 222
223static
224 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
655fddc8 225 const gp_Pnt2d& theLastPoint,
226 const Standard_Real theUmin,
227 const Standard_Real theUmax,
228 const Standard_Real theVmin,
229 const Standard_Real theVmax,
230 const gp_Pnt2d& theTanZoneCenter,
231 const Standard_Real theZoneRadius,
232 Handle(GeomAdaptor_HSurface) theGASurface,
233 gp_Pnt2d& theNewPoint);
7fd59977 234
235static
236 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
655fddc8 237 const gp_Pnt2d& theTanZoneCenter,
238 const Standard_Real theZoneRadius,
239 Handle(GeomAdaptor_HSurface) theGASurface);
7fd59977 240
241static
4f189102 242 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
655fddc8 243 const gp_Pnt2d& theOriginalPoint,
244 Handle(GeomAdaptor_HSurface) theGASurface);
7fd59977 245static
4f189102 246 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
655fddc8 247 const gp_Sphere& theSph);
7fd59977 248
249static void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
655fddc8 250 const Handle(GeomAdaptor_HSurface)& theS2,
251 const Standard_Real TolAng,
252 const Standard_Real TolTang,
253 const Standard_Boolean theApprox1,
254 const Standard_Boolean theApprox2,
7fd59977 255 IntTools_SequenceOfCurves& theSeqOfCurve,
655fddc8 256 Standard_Boolean& theTangentFaces);
7fd59977 257
258static Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
655fddc8 259 const gp_Lin2d& theLin2d,
260 const Standard_Real theTol,
261 Standard_Real& theP1,
262 Standard_Real& theP2);
0fc4f2e2 263//
7fd59977 264static
265 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
655fddc8 266 const Handle(GeomAdaptor_HSurface)& aHS2,
267 Standard_Integer& iDegMin,
268 Standard_Integer& iNbIter,
269 Standard_Integer& iDegMax);
7fd59977 270
0fc4f2e2
P
271static
272 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
655fddc8 273 const Handle(GeomAdaptor_HSurface)& aHS2,
788cbaf4 274 Standard_Real& aTolTang);
0fc4f2e2 275
0fc4f2e2
P
276static
277 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
655fddc8 278 const GeomAbs_SurfaceType aType2);
0fc4f2e2
P
279static
280 Standard_Integer IndexType(const GeomAbs_SurfaceType aType);
d10203e8 281
7fd59977 282//
4f189102
P
283static
284 Standard_Real MaxSquareDistance (const Standard_Real aT,
655fddc8 285 const Handle(Geom_Curve)& aC3D,
286 const Handle(Geom2d_Curve)& aC2D1,
287 const Handle(Geom2d_Curve)& aC2D2,
288 const Handle(GeomAdaptor_HSurface) myHS1,
289 const Handle(GeomAdaptor_HSurface) myHS2,
290 const TopoDS_Face& aF1,
291 const TopoDS_Face& aF2,
1e143abb 292 const Handle(IntTools_Context)& aCtx);
989341c5 293
294static
295 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
296 const TopoDS_Face& aFace);
297
4f189102 298//
37b6f439 299static
300 Standard_Real FindMaxSquareDistance (const Standard_Real aA,
655fddc8 301 const Standard_Real aB,
302 const Standard_Real aEps,
303 const Handle(Geom_Curve)& aC3D,
304 const Handle(Geom2d_Curve)& aC2D1,
305 const Handle(Geom2d_Curve)& aC2D2,
306 const Handle(GeomAdaptor_HSurface)& myHS1,
307 const Handle(GeomAdaptor_HSurface)& myHS2,
308 const TopoDS_Face& aF1,
309 const TopoDS_Face& aF2,
1e143abb 310 const Handle(IntTools_Context)& aCtx);
37b6f439 311
7fd59977 312//=======================================================================
313//function :
314//purpose :
315//=======================================================================
4f189102 316IntTools_FaceFace::IntTools_FaceFace()
7fd59977 317{
3f16d970 318 myIsDone=Standard_False;
7fd59977 319 myTangentFaces=Standard_False;
320 //
321 myHS1 = new GeomAdaptor_HSurface ();
322 myHS2 = new GeomAdaptor_HSurface ();
323 myTolReached2d=0.;
324 myTolReached3d=0.;
325 SetParameters(Standard_True, Standard_True, Standard_True, 1.e-07);
4f189102
P
326
327}
328//=======================================================================
329//function : SetContext
330//purpose :
331//=======================================================================
1e143abb 332void IntTools_FaceFace::SetContext(const Handle(IntTools_Context)& aContext)
4f189102
P
333{
334 myContext=aContext;
335}
336//=======================================================================
337//function : Context
338//purpose :
339//=======================================================================
1e143abb 340const Handle(IntTools_Context)& IntTools_FaceFace::Context()const
4f189102
P
341{
342 return myContext;
7fd59977 343}
344//=======================================================================
345//function : Face1
346//purpose :
347//=======================================================================
4f189102 348const TopoDS_Face& IntTools_FaceFace::Face1() const
7fd59977 349{
350 return myFace1;
351}
7fd59977 352//=======================================================================
353//function : Face2
354//purpose :
355//=======================================================================
4f189102 356const TopoDS_Face& IntTools_FaceFace::Face2() const
7fd59977 357{
358 return myFace2;
359}
7fd59977 360//=======================================================================
361//function : TangentFaces
362//purpose :
363//=======================================================================
4f189102 364Standard_Boolean IntTools_FaceFace::TangentFaces() const
7fd59977 365{
366 return myTangentFaces;
367}
368//=======================================================================
369//function : Points
370//purpose :
371//=======================================================================
4f189102 372const IntTools_SequenceOfPntOn2Faces& IntTools_FaceFace::Points() const
7fd59977 373{
374 return myPnts;
375}
376//=======================================================================
377//function : IsDone
378//purpose :
379//=======================================================================
4f189102 380Standard_Boolean IntTools_FaceFace::IsDone() const
7fd59977 381{
382 return myIsDone;
383}
384//=======================================================================
385//function : TolReached3d
386//purpose :
387//=======================================================================
4f189102 388Standard_Real IntTools_FaceFace::TolReached3d() const
7fd59977 389{
390 return myTolReached3d;
391}
392//=======================================================================
393//function : Lines
394//purpose : return lines of intersection
395//=======================================================================
4f189102 396const IntTools_SequenceOfCurves& IntTools_FaceFace::Lines() const
7fd59977 397{
4f189102
P
398 StdFail_NotDone_Raise_if
399 (!myIsDone,
788cbaf4 400 "IntTools_FaceFace::Lines() => myIntersector NOT DONE");
7fd59977 401 return mySeqOfCurve;
402}
7fd59977 403//=======================================================================
404//function : TolReached2d
405//purpose :
406//=======================================================================
4f189102 407Standard_Real IntTools_FaceFace::TolReached2d() const
7fd59977 408{
409 return myTolReached2d;
410}
411// =======================================================================
412// function: SetParameters
413//
414// =======================================================================
4f189102 415void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d,
655fddc8 416 const Standard_Boolean ToApproxC2dOnS1,
417 const Standard_Boolean ToApproxC2dOnS2,
418 const Standard_Real ApproximationTolerance)
7fd59977 419{
420 myApprox = ToApproxC3d;
421 myApprox1 = ToApproxC2dOnS1;
422 myApprox2 = ToApproxC2dOnS2;
423 myTolApprox = ApproximationTolerance;
424}
425//=======================================================================
426//function : SetList
427//purpose :
428//=======================================================================
7fd59977 429void IntTools_FaceFace::SetList(IntSurf_ListOfPntOn2S& aListOfPnts)
430{
431 myListOfPnts = aListOfPnts;
432}
788cbaf4 433
434
435static Standard_Boolean isTreatAnalityc(const TopoDS_Face& theF1,
436 const TopoDS_Face& theF2)
437{
438 const Standard_Real Tolang = 1.e-8;
439 const Standard_Real aTolF1=BRep_Tool::Tolerance(theF1);
440 const Standard_Real aTolF2=BRep_Tool::Tolerance(theF2);
441 const Standard_Real aTolSum = aTolF1 + aTolF2;
442 Standard_Real aHigh = 0.0;
443
444 const BRepAdaptor_Surface aBAS1(theF1), aBAS2(theF2);
445 const GeomAbs_SurfaceType aType1=aBAS1.GetType();
446 const GeomAbs_SurfaceType aType2=aBAS2.GetType();
447
448 gp_Pln aS1;
449 gp_Cylinder aS2;
450 if(aType1 == GeomAbs_Plane)
451 {
452 aS1=aBAS1.Plane();
453 }
454 else if(aType2 == GeomAbs_Plane)
455 {
456 aS1=aBAS2.Plane();
457 }
458 else
459 {
460 return Standard_True;
461 }
462
463 if(aType1 == GeomAbs_Cylinder)
464 {
465 aS2=aBAS1.Cylinder();
466 const Standard_Real VMin = aBAS1.FirstVParameter();
467 const Standard_Real VMax = aBAS1.LastVParameter();
468
469 if( Precision::IsNegativeInfinite(VMin) ||
470 Precision::IsPositiveInfinite(VMax))
471 return Standard_True;
472 else
473 aHigh = VMax - VMin;
474 }
475 else if(aType2 == GeomAbs_Cylinder)
476 {
477 aS2=aBAS2.Cylinder();
478
479 const Standard_Real VMin = aBAS2.FirstVParameter();
480 const Standard_Real VMax = aBAS2.LastVParameter();
481
482 if( Precision::IsNegativeInfinite(VMin) ||
483 Precision::IsPositiveInfinite(VMax))
484 return Standard_True;
485 else
486 aHigh = VMax - VMin;
487 }
488 else
489 {
490 return Standard_True;
491 }
492
493 IntAna_QuadQuadGeo inter;
494 inter.Perform(aS1,aS2,Tolang,aTolSum, aHigh);
495 if(inter.TypeInter() == IntAna_Ellipse)
496 {
497 const gp_Elips anEl = inter.Ellipse(1);
498 const Standard_Real aMajorR = anEl.MajorRadius();
499 const Standard_Real aMinorR = anEl.MinorRadius();
500
501 return (aMajorR < 100000.0 * aMinorR);
502 }
503 else
504 {
505 return inter.IsDone();
506 }
507}
7fd59977 508//=======================================================================
509//function : Perform
510//purpose : intersect surfaces of the faces
511//=======================================================================
59495dbe 512 void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
c002793b 513 const TopoDS_Face& aF2)
7fd59977 514{
788cbaf4 515 Standard_Boolean RestrictLine = Standard_False, hasCone = Standard_False;
516
4f189102 517 if (myContext.IsNull()) {
1e143abb 518 myContext=new IntTools_Context;
4f189102 519 }
788cbaf4 520
7fd59977 521 mySeqOfCurve.Clear();
7fd59977 522 myTolReached2d=0.;
523 myTolReached3d=0.;
7fd59977 524 myIsDone = Standard_False;
0fc4f2e2 525 myNbrestr=0;//?
788cbaf4 526
0fc4f2e2
P
527 myFace1=aF1;
528 myFace2=aF2;
788cbaf4 529
530 const BRepAdaptor_Surface aBAS1(myFace1, Standard_False);
531 const BRepAdaptor_Surface aBAS2(myFace2, Standard_False);
532 GeomAbs_SurfaceType aType1=aBAS1.GetType();
533 GeomAbs_SurfaceType aType2=aBAS2.GetType();
534
535 const Standard_Boolean bReverse=SortTypes(aType1, aType2);
536 if (bReverse)
537 {
0fc4f2e2
P
538 myFace1=aF2;
539 myFace2=aF1;
540 aType1=aBAS2.GetType();
541 aType2=aBAS1.GetType();
788cbaf4 542
543 if (myListOfPnts.Extent())
544 {
0fc4f2e2
P
545 Standard_Real aU1,aV1,aU2,aV2;
546 IntSurf_ListIteratorOfListOfPntOn2S aItP2S;
547 //
548 aItP2S.Initialize(myListOfPnts);
788cbaf4 549 for (; aItP2S.More(); aItP2S.Next())
550 {
655fddc8 551 IntSurf_PntOn2S& aP2S=aItP2S.Value();
552 aP2S.Parameters(aU1,aV1,aU2,aV2);
553 aP2S.SetValue(aU2,aV2,aU1,aV1);
0fc4f2e2
P
554 }
555 }
556 }
7fd59977 557
788cbaf4 558
559 const Handle(Geom_Surface) S1=BRep_Tool::Surface(myFace1);
560 const Handle(Geom_Surface) S2=BRep_Tool::Surface(myFace2);
561
562 const Standard_Real aTolF1=BRep_Tool::Tolerance(myFace1);
563 const Standard_Real aTolF2=BRep_Tool::Tolerance(myFace2);
564
565 Standard_Real TolArc = aTolF1 + aTolF2;
566 Standard_Real TolTang = TolArc;
567
568 const Standard_Boolean isFace1Quad = (aType1 == GeomAbs_Cylinder ||
569 aType1 == GeomAbs_Cone ||
570 aType1 == GeomAbs_Torus);
571
572 const Standard_Boolean isFace2Quad = (aType2 == GeomAbs_Cylinder ||
573 aType2 == GeomAbs_Cone ||
574 aType2 == GeomAbs_Torus);
575
a34f083b 576 if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
788cbaf4 577 Standard_Real umin, umax, vmin, vmax;
a34f083b 578 Standard_Real dU, dV;
579 //
0fc4f2e2 580 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
a34f083b 581 dU=0.1*(umax-umin);
582 dV=0.1*(vmax-vmin);
583 umin=umin-dU;
584 umax=umax+dU;
585 vmin=vmin-dV;
586 vmax=vmax+dV;
7fd59977 587 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
588 //
0fc4f2e2 589 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
a34f083b 590 dU=0.1*(umax-umin);
591 dV=0.1*(vmax-vmin);
592 umin=umin-dU;
593 umax=umax+dU;
594 vmin=vmin-dV;
595 vmax=vmax+dV;
7fd59977 596 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
a34f083b 597 //
7fd59977 598 Standard_Real TolAng = 1.e-8;
a34f083b 599 //
59495dbe 600 PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2,
a34f083b 601 mySeqOfCurve, myTangentFaces);
602 //
7fd59977 603 myIsDone = Standard_True;
4f189102 604
a34f083b 605 if(!myTangentFaces) {
788cbaf4 606 const Standard_Integer NbLinPP = mySeqOfCurve.Length();
a34f083b 607 if(NbLinPP) {
655fddc8 608 Standard_Real aTolFMax;
609 myTolReached3d = 1.e-7;
610 aTolFMax=Max(aTolF1, aTolF2);
a34f083b 611 if (aTolFMax>myTolReached3d) {
655fddc8 612 myTolReached3d=aTolFMax;
613 }
a34f083b 614 //
655fddc8 615 myTolReached2d = myTolReached3d;
788cbaf4 616
a34f083b 617 if (bReverse) {
655fddc8 618 Handle(Geom2d_Curve) aC2D1, aC2D2;
788cbaf4 619 const Standard_Integer aNbLin = mySeqOfCurve.Length();
a34f083b 620 for (Standard_Integer i = 1; i <= aNbLin; ++i) {
655fddc8 621 IntTools_Curve& aIC=mySeqOfCurve(i);
622 aC2D1=aIC.FirstCurve2d();
623 aC2D2=aIC.SecondCurve2d();
624 aIC.SetFirstCurve2d(aC2D2);
625 aIC.SetSecondCurve2d(aC2D1);
626 }
627 }
0fc4f2e2
P
628 }
629 }
7fd59977 630 return;
0fc4f2e2 631 }//if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
788cbaf4 632
633 if ((aType1==GeomAbs_Plane) && isFace2Quad)
634 {
7fd59977 635 Standard_Real dU, dV;
788cbaf4 636
7fd59977 637 // F1
788cbaf4 638 Standard_Real umin, umax, vmin, vmax;
0fc4f2e2 639 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
788cbaf4 640
7fd59977 641 dU=0.1*(umax-umin);
642 dV=0.1*(vmax-vmin);
643 umin=umin-dU;
644 umax=umax+dU;
645 vmin=vmin-dV;
646 vmax=vmax+dV;
647 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
648 // F2
0fc4f2e2
P
649 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
650 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
7fd59977 651 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
652 //
653 if( aType2==GeomAbs_Cone ) {
654 TolArc = 0.0001;
7fd59977 655 hasCone = Standard_True;
656 }
657 }
788cbaf4 658 else if ((aType2==GeomAbs_Plane) && isFace1Quad)
659 {
7fd59977 660 Standard_Real dU, dV;
788cbaf4 661
7fd59977 662 //F1
788cbaf4 663 Standard_Real umin, umax, vmin, vmax;
0fc4f2e2
P
664 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
665 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
7fd59977 666 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
667 // F2
0fc4f2e2 668 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
7fd59977 669 dU=0.1*(umax-umin);
670 dV=0.1*(vmax-vmin);
671 umin=umin-dU;
672 umax=umax+dU;
673 vmin=vmin-dV;
674 vmax=vmax+dV;
675 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
676 //
677 if( aType1==GeomAbs_Cone ) {
678 TolArc = 0.0001;
7fd59977 679 hasCone = Standard_True;
680 }
681 }
788cbaf4 682 else
683 {
684 Standard_Real umin, umax, vmin, vmax;
0fc4f2e2 685 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
0fc4f2e2 686 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
7fd59977 687 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
0fc4f2e2 688 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
0fc4f2e2 689 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
7fd59977 690 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
691 }
788cbaf4 692
693 const Handle(IntTools_TopolTool) dom1 = new IntTools_TopolTool(myHS1);
694 const Handle(IntTools_TopolTool) dom2 = new IntTools_TopolTool(myHS2);
695
7fd59977 696 myLConstruct.Load(dom1, dom2, myHS1, myHS2);
788cbaf4 697
698
699 Tolerances(myHS1, myHS2, TolTang);
700
701 {
702 const Standard_Real UVMaxStep = 0.001;
703 const Standard_Real Deflection = (hasCone) ? 0.085 : 0.1;
59495dbe 704 myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection);
788cbaf4 705 }
706
7fd59977 707 if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) ||
708 (myHS1->IsVClosed() && !myHS1->IsVPeriodic()) ||
709 (myHS2->IsUClosed() && !myHS2->IsUPeriodic()) ||
788cbaf4 710 (myHS2->IsVClosed() && !myHS2->IsVPeriodic()))
711 {
7fd59977 712 RestrictLine = Standard_True;
713 }
714 //
788cbaf4 715 if((aType1 != GeomAbs_BSplineSurface) &&
59495dbe 716 (aType1 != GeomAbs_BezierSurface) &&
788cbaf4 717 (aType1 != GeomAbs_OtherSurface) &&
718 (aType2 != GeomAbs_BSplineSurface) &&
59495dbe 719 (aType2 != GeomAbs_BezierSurface) &&
788cbaf4 720 (aType2 != GeomAbs_OtherSurface))
721 {
7fd59977 722 RestrictLine = Standard_True;
788cbaf4 723
7fd59977 724 if ((aType1 == GeomAbs_Torus) ||
788cbaf4 725 (aType2 == GeomAbs_Torus))
726 {
7fd59977 727 myListOfPnts.Clear();
728 }
729 }
788cbaf4 730
7fd59977 731 //
788cbaf4 732 if(!RestrictLine)
733 {
7fd59977 734 TopExp_Explorer aExp;
788cbaf4 735 for(Standard_Integer i = 0; (!RestrictLine) && (i < 2); i++)
736 {
7fd59977 737 const TopoDS_Face& aF=(!i) ? myFace1 : myFace2;
738 aExp.Init(aF, TopAbs_EDGE);
788cbaf4 739 for(; aExp.More(); aExp.Next())
740 {
655fddc8 741 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
788cbaf4 742
743 if(BRep_Tool::Degenerated(aE))
744 {
655fddc8 745 RestrictLine = Standard_True;
746 break;
747 }
7fd59977 748 }
749 }
750 }
788cbaf4 751
752 const Standard_Boolean isGeomInt = isTreatAnalityc(aF1, aF2);
753 myIntersector.Perform(myHS1, dom1, myHS2, dom2, TolArc, TolTang,
754 myListOfPnts, RestrictLine, isGeomInt);
755
7fd59977 756 myIsDone = myIntersector.IsDone();
788cbaf4 757
758 if (myIsDone)
759 {
7fd59977 760 myTangentFaces=myIntersector.TangentFaces();
761 if (myTangentFaces) {
762 return;
763 }
764 //
765 if(RestrictLine) {
766 myListOfPnts.Clear(); // to use LineConstructor
767 }
768 //
788cbaf4 769 const Standard_Integer aNbLin = myIntersector.NbLines();
770 for (Standard_Integer i=1; i <= aNbLin; ++i) {
7fd59977 771 MakeCurve(i, dom1, dom2);
772 }
773 //
774 ComputeTolReached3d();
775 //
0fc4f2e2
P
776 if (bReverse) {
777 Handle(Geom2d_Curve) aC2D1, aC2D2;
778 //
788cbaf4 779 const Standard_Integer aNbLin=mySeqOfCurve.Length();
780 for (Standard_Integer i=1; i<=aNbLin; ++i)
781 {
655fddc8 782 IntTools_Curve& aIC=mySeqOfCurve(i);
783 aC2D1=aIC.FirstCurve2d();
784 aC2D2=aIC.SecondCurve2d();
785 aIC.SetFirstCurve2d(aC2D2);
786 aIC.SetSecondCurve2d(aC2D1);
0fc4f2e2
P
787 }
788 }
788cbaf4 789
0fc4f2e2 790 // Points
7fd59977 791 Standard_Real U1,V1,U2,V2;
792 IntTools_PntOnFace aPntOnF1, aPntOnF2;
0fc4f2e2 793 IntTools_PntOn2Faces aPntOn2Faces;
7fd59977 794 //
788cbaf4 795 const Standard_Integer aNbPnts = myIntersector.NbPnts();
796 for (Standard_Integer i=1; i <= aNbPnts; ++i)
797 {
7fd59977 798 const IntSurf_PntOn2S& aISPnt=myIntersector.Point(i).PntOn2S();
799 const gp_Pnt& aPnt=aISPnt.Value();
800 aISPnt.Parameters(U1,V1,U2,V2);
0fc4f2e2
P
801 aPntOnF1.Init(myFace1, aPnt, U1, V1);
802 aPntOnF2.Init(myFace2, aPnt, U2, V2);
d10203e8 803 //
788cbaf4 804 if (!bReverse)
805 {
655fddc8 806 aPntOn2Faces.SetP1(aPntOnF1);
807 aPntOn2Faces.SetP2(aPntOnF2);
0fc4f2e2 808 }
788cbaf4 809 else
810 {
655fddc8 811 aPntOn2Faces.SetP2(aPntOnF1);
812 aPntOn2Faces.SetP1(aPntOnF2);
0fc4f2e2 813 }
788cbaf4 814
7fd59977 815 myPnts.Append(aPntOn2Faces);
816 }
7fd59977 817 }
818}
788cbaf4 819
7fd59977 820//=======================================================================
821//function :ComputeTolReached3d
822//purpose :
823//=======================================================================
824 void IntTools_FaceFace::ComputeTolReached3d()
825{
128dba6f 826 Standard_Boolean bCase1;
827 Standard_Integer aNbLin, i;
7fd59977 828 GeomAbs_SurfaceType aType1, aType2;
829 //
830 aNbLin=myIntersector.NbLines();
37b6f439 831 if (!aNbLin) {
832 return;
833 }
834 //
7fd59977 835 aType1=myHS1->Surface().GetType();
836 aType2=myHS2->Surface().GetType();
837 //
128dba6f 838 bCase1=((aType1==GeomAbs_Plane && aType2==GeomAbs_SurfaceOfExtrusion) ||
4abae870 839 (aType2==GeomAbs_Plane && aType1==GeomAbs_SurfaceOfExtrusion));
128dba6f 840 //
4f189102
P
841 if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
842 if (aNbLin==2){
843 Handle(IntPatch_Line) aIL1, aIL2;
844 IntPatch_IType aTL1, aTL2;
7fd59977 845 //
4f189102
P
846 aIL1=myIntersector.Line(1);
847 aIL2=myIntersector.Line(2);
848 aTL1=aIL1->ArcType();
849 aTL2=aIL2->ArcType();
850 if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) {
655fddc8 851 Standard_Real aD, aDTresh, dTol;
852 gp_Lin aL1, aL2;
853 //
854 dTol=1.e-8;
855 aDTresh=1.5e-6;
856 //
857 aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line();
858 aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line();
859 aD=aL1.Distance(aL2);
860 aD=0.5*aD;
861 if (aD<aDTresh) {
862 myTolReached3d=aD+dTol;
863 }
864 return;
7fd59977 865 }
866 }
4f189102 867 //ZZ
37b6f439 868 if (aNbLin) {// Check the distances
128dba6f 869 Standard_Integer aNbP, j ;
575aec54 870 Standard_Real aT1, aT2, dT, aD2, aD2Max, aEps, aT11, aT12;
4f189102
P
871 //
872 aD2Max=0.;
0c5acd27 873 aNbP=10;
4f189102
P
874 aNbLin=mySeqOfCurve.Length();
875 //
876 for (i=1; i<=aNbLin; ++i) {
655fddc8 877 const IntTools_Curve& aIC=mySeqOfCurve(i);
878 const Handle(Geom_Curve)& aC3D=aIC.Curve();
879 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
880 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
881 //
882 if (aC3D.IsNull()) {
883 continue;
884 }
885 const Handle(Geom_BSplineCurve)& aBC=
886 Handle(Geom_BSplineCurve)::DownCast(aC3D);
887 if (aBC.IsNull()) {
888 continue;
889 }
890 //
891 aT1=aBC->FirstParameter();
892 aT2=aBC->LastParameter();
893 //
894 aEps=0.01*(aT2-aT1);
895 dT=(aT2-aT1)/aNbP;
896 for (j=1; j<aNbP; ++j) {
897 aT11=aT1+j*dT;
898 aT12=aT11+dT;
899 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
900 myHS1, myHS2, myFace1, myFace2, myContext);
901 if (aD2>aD2Max) {
902 aD2Max=aD2;
903 }
904 }
4f189102
P
905 }//for (i=1; i<=aNbLin; ++i) {
906 //
907 myTolReached3d=sqrt(aD2Max);
37b6f439 908 }// if (aNbLin)
4f189102
P
909 }// if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
910 //
0fc4f2e2 911 //904/G3 f
4f189102 912 else if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
7fd59977 913 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
914 //
915 aTolTresh=1.e-7;
916 //
917 aTolF1 = BRep_Tool::Tolerance(myFace1);
918 aTolF2 = BRep_Tool::Tolerance(myFace2);
919 aTolFMax=Max(aTolF1, aTolF2);
920 //
921 if (aTolFMax>aTolTresh) {
922 myTolReached3d=aTolFMax;
923 }
4f189102 924 }//if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
0fc4f2e2 925 //t
7fd59977 926 //IFV Bug OCC20297
4f189102 927 else if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ||
655fddc8 928 (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) {
7fd59977 929 if(aNbLin == 1) {
930 const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1);
931 if(aIL1->ArcType() == IntPatch_Circle) {
655fddc8 932 gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle();
933 gp_XYZ aCirDir = aCir.Axis().Direction().XYZ();
934 gp_XYZ aPlDir;
935 gp_Pln aPln;
936 if(aType1 == GeomAbs_Plane) {
937 aPln = myHS1->Surface().Plane();
938 }
939 else {
940 aPln = myHS2->Surface().Plane();
941 }
942 aPlDir = aPln.Axis().Direction().XYZ();
943 Standard_Real cs = aCirDir*aPlDir;
944 if(cs < 0.) aPlDir.Reverse();
945 Standard_Real eps = 1.e-14;
946 if(!aPlDir.IsEqual(aCirDir, eps)) {
947 Standard_Integer aNbP = 11;
948 Standard_Real dt = 2.*M_PI / (aNbP - 1), t;
949 for(t = 0.; t < 2.*M_PI; t += dt) {
950 Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir));
951 if(myTolReached3d < d) myTolReached3d = d;
952 }
953 myTolReached3d *= 1.1;
954 }
7fd59977 955 } //aIL1->ArcType() == IntPatch_Circle
956 } //aNbLin == 1
4f189102 957 } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane)
7fd59977 958 //End IFV Bug OCC20297
0fc4f2e2 959 //
4f189102 960 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
655fddc8 961 (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) {
0fc4f2e2
P
962 aNbLin=mySeqOfCurve.Length();
963 if (aNbLin!=1) {
964 return;
965 }
966 //
128dba6f 967 Standard_Integer aNbP;
0fc4f2e2
P
968 Standard_Real aT, aT1, aT2, dT, aUT, aVT, aUP, aVP;
969 Standard_Real aDP, aDT, aDmax;
970 gp_Pln aPln;
971 gp_Torus aTorus;
972 gp_Pnt aP, aPP, aPT;
973 //
974 const IntTools_Curve& aIC=mySeqOfCurve(1);
975 const Handle(Geom_Curve)& aC3D=aIC.Curve();
4f189102
P
976 const Handle(Geom_BSplineCurve)& aBS=
977 Handle(Geom_BSplineCurve)::DownCast(aC3D);
0fc4f2e2
P
978 if (aBS.IsNull()) {
979 return;
980 }
981 //
982 aT1=aBS->FirstParameter();
983 aT2=aBS->LastParameter();
984 //
985 aPln =(aType1==GeomAbs_Plane) ? myHS1->Plane() : myHS2->Plane();
986 aTorus=(aType1==GeomAbs_Plane) ? myHS2->Torus() : myHS1->Torus();
987 //
988 aDmax=-1.;
989 aNbP=11;
990 dT=(aT2-aT1)/(aNbP-1);
991 for (i=0; i<aNbP; ++i) {
992 aT=aT1+i*dT;
993 if (i==aNbP-1) {
655fddc8 994 aT=aT2;
0fc4f2e2
P
995 }
996 //
997 aC3D->D0(aT, aP);
998 //
999 ElSLib::Parameters(aPln, aP, aUP, aVP);
1000 aPP=ElSLib::Value(aUP, aVP, aPln);
1001 aDP=aP.SquareDistance(aPP);
1002 if (aDP>aDmax) {
655fddc8 1003 aDmax=aDP;
0fc4f2e2
P
1004 }
1005 //
1006 ElSLib::Parameters(aTorus, aP, aUT, aVT);
1007 aPT=ElSLib::Value(aUT, aVT, aTorus);
1008 aDT=aP.SquareDistance(aPT);
1009 if (aDT>aDmax) {
655fddc8 1010 aDmax=aDT;
0fc4f2e2
P
1011 }
1012 }
1013 //
1014 if (aDmax > myTolReached3d*myTolReached3d) {
1015 myTolReached3d=sqrt(aDmax);
1016 myTolReached3d=1.1*myTolReached3d;
1017 }
1018 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
a9f7b6b5 1019 //
4f189102 1020 else if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) ||
655fddc8 1021 (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder)) {
128dba6f 1022 Standard_Integer j, aNbP;
4f189102 1023 Standard_Real aT, aT1, aT2, dT, aD2max, aD2;
d10203e8
P
1024 //
1025 aNbLin=mySeqOfCurve.Length();
4f189102 1026 aD2max=0.;
d10203e8
P
1027 aNbP=11;
1028 //
1029 for (i=1; i<=aNbLin; ++i) {
1030 const IntTools_Curve& aIC=mySeqOfCurve(i);
1031 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1032 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1033 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1034 //
1035 if (aC3D.IsNull()) {
655fddc8 1036 continue;
d10203e8 1037 }
4f189102 1038 const Handle(Geom_BSplineCurve)& aBC=
655fddc8 1039 Handle(Geom_BSplineCurve)::DownCast(aC3D);
d10203e8 1040 if (aBC.IsNull()) {
655fddc8 1041 return;
d10203e8
P
1042 }
1043 //
1044 aT1=aBC->FirstParameter();
1045 aT2=aBC->LastParameter();
1046 //
1047 dT=(aT2-aT1)/(aNbP-1);
1048 for (j=0; j<aNbP; ++j) {
655fddc8 1049 aT=aT1+j*dT;
1050 if (j==aNbP-1) {
1051 aT=aT2;
1052 }
1053 //
1054 aD2=MaxSquareDistance(aT, aC3D, aC2D1, aC2D2,
1055 myHS1, myHS2, myFace1, myFace2, myContext);
1056 if (aD2>aD2max) {
1057 aD2max=aD2;
1058 }
d10203e8 1059 }//for (j=0; j<aNbP; ++j) {
37b6f439 1060
d10203e8
P
1061 }//for (i=1; i<=aNbLin; ++i) {
1062 //
4f189102
P
1063 aD2=myTolReached3d*myTolReached3d;
1064 if (aD2max > aD2) {
1065 myTolReached3d=sqrt(aD2max);
d10203e8 1066 }
a9f7b6b5 1067 }//if((aType1==GeomAbs_SurfaceOfRevolution ...
0c5acd27 1068 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ||
655fddc8 1069 (aType2==GeomAbs_Plane && aType1==GeomAbs_Sphere)) {
128dba6f 1070 Standard_Integer j, aNbP;
9c9a29ea 1071 Standard_Real aT1, aT2, dT, aD2max, aD2, aEps, aT11, aT12;
0c5acd27 1072 //
1073 aNbLin=mySeqOfCurve.Length();
1074 aD2max=0.;
1075 aNbP=10;
1076 //
1077 for (i=1; i<=aNbLin; ++i) {
1078 const IntTools_Curve& aIC=mySeqOfCurve(i);
1079 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1080 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1081 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1082 //
1083 const Handle(Geom2d_BSplineCurve)& aBC2D1=
655fddc8 1084 Handle(Geom2d_BSplineCurve)::DownCast(aC2D1);
0c5acd27 1085 const Handle(Geom2d_BSplineCurve)& aBC2D2=
655fddc8 1086 Handle(Geom2d_BSplineCurve)::DownCast(aC2D2);
0c5acd27 1087 //
1088 if (aBC2D1.IsNull() && aBC2D2.IsNull()) {
655fddc8 1089 return;
0c5acd27 1090 }
1091 //
1092 if (!aBC2D1.IsNull()) {
655fddc8 1093 aT1=aBC2D1->FirstParameter();
1094 aT2=aBC2D1->LastParameter();
0c5acd27 1095 }
1096 else {
655fddc8 1097 aT1=aBC2D2->FirstParameter();
1098 aT2=aBC2D2->LastParameter();
0c5acd27 1099 }
1100 //
1101 aEps=0.01*(aT2-aT1);
9c9a29ea 1102 dT=(aT2-aT1)/aNbP;
0c5acd27 1103 for (j=0; j<aNbP; ++j) {
655fddc8 1104 aT11=aT1+j*dT;
1105 aT12=aT11+dT;
1106 if (j==aNbP-1) {
1107 aT12=aT2;
1108 }
1109 //
1110 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
1111 myHS1, myHS2, myFace1, myFace2, myContext);
1112 if (aD2>aD2max) {
1113 aD2max=aD2;
1114 }
0c5acd27 1115 }//for (j=0; j<aNbP; ++j) {
1116
1117 }//for (i=1; i<=aNbLin; ++i) {
1118 //
1119 aD2=myTolReached3d*myTolReached3d;
1120 if (aD2max > aD2) {
1121 myTolReached3d=sqrt(aD2max);
1122 }
1123 }//else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ...
128dba6f 1124 else if (!myApprox || bCase1) {
1125 //else if (!myApprox) {
1126 Standard_Integer aNbP, j;
4e57c75e 1127 Standard_Real aT1, aT2, dT, aD2, aD2Max, aEps, aT11, aT12;
1128 //
1129 aD2Max=0.;
1130 aNbLin=mySeqOfCurve.Length();
1131 //
1132 for (i=1; i<=aNbLin; ++i) {
1133 const IntTools_Curve& aIC=mySeqOfCurve(i);
1134 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1135 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1136 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1137 //
1138 if (aC3D.IsNull()) {
4abae870 1139 continue;
59495dbe 1140}
4e57c75e 1141 const Handle(Geom_BSplineCurve)& aBC=
4abae870 1142 Handle(Geom_BSplineCurve)::DownCast(aC3D);
4e57c75e 1143 if (aBC.IsNull()) {
4abae870 1144 continue;
4e57c75e 1145 }
1146 //
1147 aT1=aBC->FirstParameter();
1148 aT2=aBC->LastParameter();
1149 //
1150 aEps=0.0001*(aT2-aT1);
1151 aNbP=11;
1152 dT=(aT2-aT1)/aNbP;
1153 for (j=1; j<aNbP-1; ++j) {
4abae870 1154 aT11=aT1+j*dT;
1155 aT12=aT11+dT;
1156 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
1157 myHS1, myHS2, myFace1, myFace2, myContext);
1158 if (aD2>aD2Max) {
1159 aD2Max=aD2;
1160 }
4e57c75e 1161 }
1162 }//for (i=1; i<=aNbLin; ++i) {
1163 myTolReached3d=sqrt(aD2Max);
1164 }
7fd59977 1165}
1166//=======================================================================
1167//function : MakeCurve
1168//purpose :
1169//=======================================================================
1170 void IntTools_FaceFace::MakeCurve(const Standard_Integer Index,
655fddc8 1171 const Handle(Adaptor3d_TopolTool)& dom1,
1172 const Handle(Adaptor3d_TopolTool)& dom2)
7fd59977 1173{
4abae870 1174 Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor;
1175 Standard_Boolean ok, bPCurvesOk;
7fd59977 1176 Standard_Integer i, j, aNbParts;
1177 Standard_Real fprm, lprm;
1178 Standard_Real Tolpc;
1179 Handle(IntPatch_Line) L;
1180 IntPatch_IType typl;
1181 Handle(Geom_Curve) newc;
1182 //
1183 const Standard_Real TOLCHECK =0.0000001;
1184 const Standard_Real TOLANGCHECK=0.1;
1185 //
1186 rejectSurface = Standard_False;
1187 reApprox = Standard_False;
989341c5 1188 //
1189 bPCurvesOk = Standard_True;
59495dbe 1190
1191 reapprox:;
1192
7fd59977 1193 Tolpc = myTolApprox;
1194 bAvoidLineConstructor = Standard_False;
1195 L = myIntersector.Line(Index);
1196 typl = L->ArcType();
1197 //
1198 if(typl==IntPatch_Walking) {
1199 Handle(IntPatch_Line) anewL;
1200 //
1201 const Handle(IntPatch_WLine)& aWLine=
1202 Handle(IntPatch_WLine)::DownCast(L);
4abae870 1203 //DumpWLine(aWLine);
1204
7fd59977 1205 anewL = ComputePurgedWLine(aWLine);
1206 if(anewL.IsNull()) {
1207 return;
1208 }
1209 L = anewL;
4abae870 1210
1211 //const Handle(IntPatch_WLine)& aWLineX = Handle(IntPatch_WLine)::DownCast(L);
1212 //DumpWLine(aWLineX);
1213
7fd59977 1214 //
1215 if(!myListOfPnts.IsEmpty()) {
1216 bAvoidLineConstructor = Standard_True;
1217 }
1218
1219 Standard_Integer nbp = aWLine->NbPnts();
1220 const IntSurf_PntOn2S& p1 = aWLine->Point(1);
1221 const IntSurf_PntOn2S& p2 = aWLine->Point(nbp);
1222
1223 const gp_Pnt& P1 = p1.Value();
1224 const gp_Pnt& P2 = p2.Value();
1225
1226 if(P1.SquareDistance(P2) < 1.e-14) {
1227 bAvoidLineConstructor = Standard_False;
1228 }
7fd59977 1229 }
1230 //
1231 // Line Constructor
1232 if(!bAvoidLineConstructor) {
1233 myLConstruct.Perform(L);
1234 //
1235 bDone=myLConstruct.IsDone();
1236 aNbParts=myLConstruct.NbParts();
1237 if (!bDone|| !aNbParts) {
1238 return;
1239 }
1240 }
1241 // Do the Curve
59495dbe 1242
1243
7fd59977 1244 typl=L->ArcType();
1245 switch (typl) {
59495dbe 1246 //########################################
1247 // Line, Parabola, Hyperbola
1248 //########################################
7fd59977 1249 case IntPatch_Lin:
1250 case IntPatch_Parabola:
1251 case IntPatch_Hyperbola: {
1252 if (typl == IntPatch_Lin) {
1253 newc =
655fddc8 1254 new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
7fd59977 1255 }
1256
1257 else if (typl == IntPatch_Parabola) {
1258 newc =
655fddc8 1259 new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
7fd59977 1260 }
59495dbe 1261
7fd59977 1262 else if (typl == IntPatch_Hyperbola) {
1263 newc =
655fddc8 1264 new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
7fd59977 1265 }
1266 //
1267 // myTolReached3d
1268 if (typl == IntPatch_Lin) {
1269 TolR3d (myFace1, myFace2, myTolReached3d);
1270 }
1271 //
1272 aNbParts=myLConstruct.NbParts();
1273 for (i=1; i<=aNbParts; i++) {
1274 myLConstruct.Part(i, fprm, lprm);
59495dbe 1275
7fd59977 1276 if (!Precision::IsNegativeInfinite(fprm) &&
655fddc8 1277 !Precision::IsPositiveInfinite(lprm)) {
1278 //
1279 IntTools_Curve aCurve;
1280 //
1281 Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
1282 aCurve.SetCurve(aCT3D);
1283 if (typl == IntPatch_Parabola) {
1284 Standard_Real aTolF1, aTolF2, aTolBase;
1285
1286 aTolF1 = BRep_Tool::Tolerance(myFace1);
1287 aTolF2 = BRep_Tool::Tolerance(myFace2);
1288 aTolBase=aTolF1+aTolF2;
1289 myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
1290 }
1291 //
1292 aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
1293 if(myApprox1) {
1294 Handle (Geom2d_Curve) C2d;
1295 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1296 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1297 myTolReached2d=Tolpc;
1298 }
1299 //
1300 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1301 }
1302 else {
1303 Handle(Geom2d_BSplineCurve) H1;
1304 //
1305 aCurve.SetFirstCurve2d(H1);
1306 }
1307
1308 if(myApprox2) {
1309 Handle (Geom2d_Curve) C2d;
1310 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1311 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1312 myTolReached2d=Tolpc;
1313 }
1314 //
1315 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1316 }
1317 else {
1318 Handle(Geom2d_BSplineCurve) H1;
1319 //
1320 aCurve.SetSecondCurve2d(H1);
1321 }
1322 mySeqOfCurve.Append(aCurve);
94218044 1323 } // end of if (!Precision::IsNegativeInfinite(fprm) && !Precision::IsPositiveInfinite(lprm))
7fd59977 1324 else {
655fddc8 1325 // on regarde si on garde
1326 //
1327 Standard_Boolean bFNIt, bLPIt;
1328 Standard_Real aTestPrm, dT=100.;
1329
1330 bFNIt=Precision::IsNegativeInfinite(fprm);
1331 bLPIt=Precision::IsPositiveInfinite(lprm);
1332
1333 aTestPrm=0.;
1334
1335 if (bFNIt && !bLPIt) {
1336 aTestPrm=lprm-dT;
1337 }
1338 else if (!bFNIt && bLPIt) {
1339 aTestPrm=fprm+dT;
1340 }
1341
1342 gp_Pnt ptref(newc->Value(aTestPrm));
1343 //
94218044 1344 GeomAbs_SurfaceType typS1 = myHS1->GetType();
1345 GeomAbs_SurfaceType typS2 = myHS2->GetType();
1346 if( typS1 == GeomAbs_SurfaceOfExtrusion ||
1347 typS1 == GeomAbs_OffsetSurface ||
1348 typS1 == GeomAbs_SurfaceOfRevolution ||
1349 typS2 == GeomAbs_SurfaceOfExtrusion ||
1350 typS2 == GeomAbs_OffsetSurface ||
1351 typS2 == GeomAbs_SurfaceOfRevolution)
1352 {
1353 Handle(Geom2d_BSplineCurve) H1;
1354 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1355 continue;
1356 }
1357
655fddc8 1358 Standard_Real u1, v1, u2, v2, Tol;
1359
1360 Tol = Precision::Confusion();
1361 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1362 ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
1363 if(ok) {
1364 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1365 }
1366 if (ok) {
1367 Handle(Geom2d_BSplineCurve) H1;
1368 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1369 }
7fd59977 1370 }
1371 }// end of for (i=1; i<=myLConstruct.NbParts(); i++)
1372 }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola:
59495dbe 1373 break;
7fd59977 1374
59495dbe 1375 //########################################
1376 // Circle and Ellipse
1377 //########################################
7fd59977 1378 case IntPatch_Circle:
1379 case IntPatch_Ellipse: {
1380
1381 if (typl == IntPatch_Circle) {
1382 newc = new Geom_Circle
655fddc8 1383 (Handle(IntPatch_GLine)::DownCast(L)->Circle());
7fd59977 1384 }
1385 else { //IntPatch_Ellipse
1386 newc = new Geom_Ellipse
655fddc8 1387 (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
7fd59977 1388 }
1389 //
1390 // myTolReached3d
1391 TolR3d (myFace1, myFace2, myTolReached3d);
1392 //
1393 aNbParts=myLConstruct.NbParts();
1394 //
1395 Standard_Real aPeriod, aNul;
1396 TColStd_SequenceOfReal aSeqFprm, aSeqLprm;
59495dbe 1397
7fd59977 1398 aNul=0.;
c6541a0c 1399 aPeriod=M_PI+M_PI;
7fd59977 1400
1401 for (i=1; i<=aNbParts; i++) {
1402 myLConstruct.Part(i, fprm, lprm);
1403
1404 if (fprm < aNul && lprm > aNul) {
655fddc8 1405 // interval that goes through 0. is divided on two intervals;
1406 while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
1407 while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
1408 //
1409 if((aPeriod - fprm) > Tolpc) {
1410 aSeqFprm.Append(fprm);
1411 aSeqLprm.Append(aPeriod);
1412 }
1413 else {
1414 gp_Pnt P1 = newc->Value(fprm);
1415 gp_Pnt P2 = newc->Value(aPeriod);
1416 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1417 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1418
1419 if(P1.Distance(P2) > aTolDist) {
1420 Standard_Real anewpar = fprm;
94218044 1421
4abae870 1422 if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2,
1423 lprm, Standard_False, anewpar, myContext)) {
655fddc8 1424 fprm = anewpar;
1425 }
1426 aSeqFprm.Append(fprm);
1427 aSeqLprm.Append(aPeriod);
1428 }
1429 }
1430
1431 //
1432 if((lprm - aNul) > Tolpc) {
1433 aSeqFprm.Append(aNul);
1434 aSeqLprm.Append(lprm);
1435 }
1436 else {
1437 gp_Pnt P1 = newc->Value(aNul);
1438 gp_Pnt P2 = newc->Value(lprm);
1439 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1440 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1441
1442 if(P1.Distance(P2) > aTolDist) {
1443 Standard_Real anewpar = lprm;
94218044 1444
4abae870 1445 if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2,
1446 fprm, Standard_True, anewpar, myContext)) {
655fddc8 1447 lprm = anewpar;
1448 }
1449 aSeqFprm.Append(aNul);
1450 aSeqLprm.Append(lprm);
1451 }
1452 }
7fd59977 1453 }
1454 else {
655fddc8 1455 // usual interval
1456 aSeqFprm.Append(fprm);
1457 aSeqLprm.Append(lprm);
7fd59977 1458 }
1459 }
59495dbe 1460
7fd59977 1461 //
1462 aNbParts=aSeqFprm.Length();
1463 for (i=1; i<=aNbParts; i++) {
1464 fprm=aSeqFprm(i);
1465 lprm=aSeqLprm(i);
1466 //
1467 Standard_Real aRealEpsilon=RealEpsilon();
c6541a0c 1468 if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*M_PI) > aRealEpsilon) {
655fddc8 1469 //==============================================
1470 ////
1471 IntTools_Curve aCurve;
1472 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1473 aCurve.SetCurve(aTC3D);
1474 fprm=aTC3D->FirstParameter();
1475 lprm=aTC3D->LastParameter ();
1476 ////
1477 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {////
1478 if(myApprox1) {
1479 Handle (Geom2d_Curve) C2d;
1480 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1481 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1482 myTolReached2d=Tolpc;
1483 }
1484 //
1485 aCurve.SetFirstCurve2d(C2d);
1486 }
1487 else { ////
1488 Handle(Geom2d_BSplineCurve) H1;
1489 aCurve.SetFirstCurve2d(H1);
1490 }
1491
1492
1493 if(myApprox2) {
1494 Handle (Geom2d_Curve) C2d;
1495 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1496 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1497 myTolReached2d=Tolpc;
1498 }
1499 //
1500 aCurve.SetSecondCurve2d(C2d);
1501 }
1502 else {
1503 Handle(Geom2d_BSplineCurve) H1;
1504 aCurve.SetSecondCurve2d(H1);
1505 }
1506 }
1507
1508 else {
1509 Handle(Geom2d_BSplineCurve) H1;
1510 aCurve.SetFirstCurve2d(H1);
1511 aCurve.SetSecondCurve2d(H1);
1512 }
1513 mySeqOfCurve.Append(aCurve);
1514 //==============================================
c6541a0c 1515 } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon())
7fd59977 1516
1517 else {
655fddc8 1518 // on regarde si on garde
1519 //
1520 if (aNbParts==1) {
1521// if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) {
1522 if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
1523 IntTools_Curve aCurve;
1524 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1525 aCurve.SetCurve(aTC3D);
1526 fprm=aTC3D->FirstParameter();
1527 lprm=aTC3D->LastParameter ();
1528
1529 if(myApprox1) {
1530 Handle (Geom2d_Curve) C2d;
1531 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1532 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1533 myTolReached2d=Tolpc;
1534 }
1535 //
1536 aCurve.SetFirstCurve2d(C2d);
1537 }
1538 else { ////
1539 Handle(Geom2d_BSplineCurve) H1;
1540 aCurve.SetFirstCurve2d(H1);
1541 }
1542
1543 if(myApprox2) {
1544 Handle (Geom2d_Curve) C2d;
1545 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1546 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1547 myTolReached2d=Tolpc;
1548 }
1549 //
1550 aCurve.SetSecondCurve2d(C2d);
1551 }
1552 else {
1553 Handle(Geom2d_BSplineCurve) H1;
1554 aCurve.SetSecondCurve2d(H1);
1555 }
1556 mySeqOfCurve.Append(aCurve);
1557 break;
1558 }
1559 }
1560 //
1561 Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
1562
1563 aTwoPIdiv17=2.*M_PI/17.;
1564
1565 for (j=0; j<=17; j++) {
1566 gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
1567 Tol = Precision::Confusion();
1568
1569 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1570 ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
1571 if(ok) {
1572 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1573 }
1574 if (ok) {
1575 IntTools_Curve aCurve;
1576 aCurve.SetCurve(newc);
1577 //==============================================
1578 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
1579
1580 if(myApprox1) {
1581 Handle (Geom2d_Curve) C2d;
1582 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1583 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1584 myTolReached2d=Tolpc;
1585 }
1586 //
1587 aCurve.SetFirstCurve2d(C2d);
1588 }
1589 else {
1590 Handle(Geom2d_BSplineCurve) H1;
1591 aCurve.SetFirstCurve2d(H1);
1592 }
1593
1594 if(myApprox2) {
1595 Handle (Geom2d_Curve) C2d;
1596 BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
1597 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1598 myTolReached2d=Tolpc;
1599 }
1600 //
1601 aCurve.SetSecondCurve2d(C2d);
1602 }
1603
1604 else {
1605 Handle(Geom2d_BSplineCurve) H1;
1606 aCurve.SetSecondCurve2d(H1);
1607 }
1608 }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
1609
1610 else {
1611 Handle(Geom2d_BSplineCurve) H1;
1612 //
1613 aCurve.SetFirstCurve2d(H1);
1614 aCurve.SetSecondCurve2d(H1);
1615 }
1616 //==============================================
1617 //
1618 mySeqOfCurve.Append(aCurve);
1619 break;
1620
1621 }// end of if (ok) {
1622 }// end of for (Standard_Integer j=0; j<=17; j++)
1623 }// end of else { on regarde si on garde
59495dbe 1624 }// for (i=1; i<=myLConstruct.NbParts(); i++)
1625 }// IntPatch_Circle: IntPatch_Ellipse:
1626 break;
1627
7fd59977 1628 case IntPatch_Analytic: {
1629 IntSurf_Quadric quad1,quad2;
1630 GeomAbs_SurfaceType typs = myHS1->Surface().GetType();
59495dbe 1631
7fd59977 1632 switch (typs) {
59495dbe 1633 case GeomAbs_Plane:
1634 quad1.SetValue(myHS1->Surface().Plane());
655fddc8 1635 break;
59495dbe 1636 case GeomAbs_Cylinder:
655fddc8 1637 quad1.SetValue(myHS1->Surface().Cylinder());
1638 break;
59495dbe 1639 case GeomAbs_Cone:
655fddc8 1640 quad1.SetValue(myHS1->Surface().Cone());
1641 break;
59495dbe 1642 case GeomAbs_Sphere:
655fddc8 1643 quad1.SetValue(myHS1->Surface().Sphere());
1644 break;
7eed5d29 1645 case GeomAbs_Torus:
1646 quad1.SetValue(myHS1->Surface().Torus());
1647 break;
59495dbe 1648 default:
655fddc8 1649 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
59495dbe 1650 }
1651
7fd59977 1652 typs = myHS2->Surface().GetType();
59495dbe 1653
7fd59977 1654 switch (typs) {
59495dbe 1655 case GeomAbs_Plane:
1656 quad2.SetValue(myHS2->Surface().Plane());
655fddc8 1657 break;
59495dbe 1658 case GeomAbs_Cylinder:
655fddc8 1659 quad2.SetValue(myHS2->Surface().Cylinder());
1660 break;
59495dbe 1661 case GeomAbs_Cone:
655fddc8 1662 quad2.SetValue(myHS2->Surface().Cone());
1663 break;
59495dbe 1664 case GeomAbs_Sphere:
655fddc8 1665 quad2.SetValue(myHS2->Surface().Sphere());
1666 break;
7eed5d29 1667 case GeomAbs_Torus:
1668 quad2.SetValue(myHS2->Surface().Torus());
1669 break;
59495dbe 1670 default:
655fddc8 1671 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
59495dbe 1672 }
7fd59977 1673 //
1674 //=========
1675 IntPatch_ALineToWLine convert (quad1, quad2);
59495dbe 1676
7fd59977 1677 if (!myApprox) {
1678 aNbParts=myLConstruct.NbParts();
1679 for (i=1; i<=aNbParts; i++) {
655fddc8 1680 myLConstruct.Part(i, fprm, lprm);
1681 Handle(IntPatch_WLine) WL =
1682 convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
1683 //
1684 Handle(Geom2d_BSplineCurve) H1;
1685 Handle(Geom2d_BSplineCurve) H2;
1686
1687 if(myApprox1) {
1688 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1689 }
1690
1691 if(myApprox2) {
1692 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1693 }
1694 //
1695 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
7fd59977 1696 }
1697 } // if (!myApprox)
1698
1699 else { // myApprox=TRUE
1700 GeomInt_WLApprox theapp3d;
1701 //
1702 Standard_Real tol2d = myTolApprox;
655fddc8 1703 //
7fd59977 1704 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
59495dbe 1705
7fd59977 1706 aNbParts=myLConstruct.NbParts();
1707 for (i=1; i<=aNbParts; i++) {
655fddc8 1708 myLConstruct.Part(i, fprm, lprm);
1709 Handle(IntPatch_WLine) WL =
1710 convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
1711
1712 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
1713
1714 if (!theapp3d.IsDone()) {
1715 //
1716 Handle(Geom2d_BSplineCurve) H1;
1717 Handle(Geom2d_BSplineCurve) H2;
1718
1719 if(myApprox1) {
1720 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1721 }
1722
1723 if(myApprox2) {
1724 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1725 }
1726 //
1727 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1728 }
1729
1730 else {
1731 if(myApprox1 || myApprox2) {
1732 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
1733 myTolReached2d = theapp3d.TolReached2d();
1734 }
1735 }
1736
1737 if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
1738 myTolReached3d = theapp3d.TolReached3d();
1739 }
1740
1741 Standard_Integer aNbMultiCurves, nbpoles;
1742 aNbMultiCurves=theapp3d.NbMultiCurves();
1743 for (j=1; j<=aNbMultiCurves; j++) {
1744 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1745 nbpoles = mbspc.NbPoles();
1746
1747 TColgp_Array1OfPnt tpoles(1, nbpoles);
1748 mbspc.Curve(1, tpoles);
1749 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1750 mbspc.Knots(),
1751 mbspc.Multiplicities(),
1752 mbspc.Degree());
1753
1754 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1755 Check.FixTangent(Standard_True,Standard_True);
1756 //
1757 IntTools_Curve aCurve;
1758 aCurve.SetCurve(BS);
1759
1760 if(myApprox1) {
1761 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1762 mbspc.Curve(2,tpoles2d);
1763 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1764 mbspc.Knots(),
1765 mbspc.Multiplicities(),
1766 mbspc.Degree());
1767
1768 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1769 newCheck.FixTangent(Standard_True,Standard_True);
1770 //
1771 aCurve.SetFirstCurve2d(BS2);
1772 }
1773 else {
1774 Handle(Geom2d_BSplineCurve) H1;
1775 aCurve.SetFirstCurve2d(H1);
1776 }
1777
1778 if(myApprox2) {
1779 TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
1780 Standard_Integer TwoOrThree;
1781 TwoOrThree=myApprox1 ? 3 : 2;
1782 mbspc.Curve(TwoOrThree, tpoles2d);
1783 Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
1784 mbspc.Knots(),
1785 mbspc.Multiplicities(),
1786 mbspc.Degree());
1787
1788 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1789 newCheck.FixTangent(Standard_True,Standard_True);
1790 //
1791 aCurve.SetSecondCurve2d(BS2);
1792 }
1793 else {
1794 Handle(Geom2d_BSplineCurve) H2;
1795 aCurve.SetSecondCurve2d(H2);
1796 }
1797 //
1798 mySeqOfCurve.Append(aCurve);
1799
1800 }// for (j=1; j<=aNbMultiCurves; j++) {
1801 }// else from if (!theapp3d.IsDone())
7fd59977 1802 }// for (i=1; i<=aNbParts; i++) {
1803 }// else { // myApprox=TRUE
1804 }// case IntPatch_Analytic:
59495dbe 1805 break;
7fd59977 1806
59495dbe 1807 case IntPatch_Walking:{
7fd59977 1808 Handle(IntPatch_WLine) WL =
1809 Handle(IntPatch_WLine)::DownCast(L);
1810 //
1811 Standard_Integer ifprm, ilprm;
1812 //
1813 if (!myApprox) {
1814 aNbParts = 1;
1815 if(!bAvoidLineConstructor){
655fddc8 1816 aNbParts=myLConstruct.NbParts();
7fd59977 1817 }
1818 for (i=1; i<=aNbParts; ++i) {
655fddc8 1819 Handle(Geom2d_BSplineCurve) H1, H2;
1820 Handle(Geom_Curve) aBSp;
1821 //
1822 if(bAvoidLineConstructor) {
1823 ifprm = 1;
1824 ilprm = WL->NbPnts();
1825 }
1826 else {
1827 myLConstruct.Part(i, fprm, lprm);
1828 ifprm=(Standard_Integer)fprm;
1829 ilprm=(Standard_Integer)lprm;
1830 }
1831 //
1832 if(myApprox1) {
1833 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1834 }
1835 //
1836 if(myApprox2) {
1837 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1838 }
1839 //
1840 aBSp=MakeBSpline(WL, ifprm, ilprm);
1841 IntTools_Curve aIC(aBSp, H1, H2);
1842 mySeqOfCurve.Append(aIC);
7fd59977 1843 }// for (i=1; i<=aNbParts; ++i) {
1844 }// if (!myApprox) {
1845 //
1846 else { // X
1847 Standard_Boolean bIsDecomposited;
1848 Standard_Integer nbiter, aNbSeqOfL;
4abae870 1849 Standard_Real tol2d, aTolApproxImp;
7fd59977 1850 IntPatch_SequenceOfLine aSeqOfL;
1851 GeomInt_WLApprox theapp3d;
1852 Approx_ParametrizationType aParType = Approx_ChordLength;
1853 //
1854 Standard_Boolean anApprox1 = myApprox1;
1855 Standard_Boolean anApprox2 = myApprox2;
4abae870 1856 //
1857 aTolApproxImp=1.e-5;
7fd59977 1858 tol2d = myTolApprox;
1859
1860 GeomAbs_SurfaceType typs1, typs2;
1861 typs1 = myHS1->Surface().GetType();
1862 typs2 = myHS2->Surface().GetType();
1863 Standard_Boolean anWithPC = Standard_True;
1864
1865 if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
655fddc8 1866 anWithPC =
1867 ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
7fd59977 1868 }
1869 else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
655fddc8 1870 anWithPC =
1871 ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
7fd59977 1872 }
4abae870 1873 //
7fd59977 1874 if(!anWithPC) {
4abae870 1875 myTolApprox = aTolApproxImp;//1.e-5;
655fddc8 1876 anApprox1 = Standard_False;
1877 anApprox2 = Standard_False;
1878 //
1879 tol2d = myTolApprox;
7fd59977 1880 }
655fddc8 1881
7fd59977 1882 if(myHS1 == myHS2) {
655fddc8 1883 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1884 rejectSurface = Standard_True;
7fd59977 1885 }
1886 else {
655fddc8 1887 if(reApprox && !rejectSurface)
1888 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1889 else {
1890 Standard_Integer iDegMax, iDegMin, iNbIter;
1891 //
1892 ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter);
1893 theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType);
1894 }
7fd59977 1895 }
1896 //
1897 Standard_Real aReachedTol = Precision::Confusion();
1898 bIsDecomposited=DecompositionOfWLine(WL,
655fddc8 1899 myHS1,
1900 myHS2,
1901 myFace1,
1902 myFace2,
1903 myLConstruct,
1904 bAvoidLineConstructor,
1905 aSeqOfL,
1906 aReachedTol,
1907 myContext);
4abae870 1908 if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) ) {
655fddc8 1909 myTolReached3d = aReachedTol;
4abae870 1910 }
7fd59977 1911 //
1912 aNbSeqOfL=aSeqOfL.Length();
1913 //
1914 if (bIsDecomposited) {
655fddc8 1915 nbiter=aNbSeqOfL;
7fd59977 1916 }
1917 else {
655fddc8 1918 nbiter=1;
1919 aNbParts=1;
1920 if (!bAvoidLineConstructor) {
1921 aNbParts=myLConstruct.NbParts();
1922 nbiter=aNbParts;
1923 }
7fd59977 1924 }
1925 //
7fd59977 1926 for(i = 1; i <= nbiter; ++i) {
655fddc8 1927 if(bIsDecomposited) {
1928 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
1929 ifprm = 1;
1930 ilprm = WL->NbPnts();
1931 }
1932 else {
1933 if(bAvoidLineConstructor) {
1934 ifprm = 1;
1935 ilprm = WL->NbPnts();
1936 }
1937 else {
1938 myLConstruct.Part(i, fprm, lprm);
1939 ifprm = (Standard_Integer)fprm;
1940 ilprm = (Standard_Integer)lprm;
1941 }
1942 }
1943 //-- lbr :
1944 //-- Si une des surfaces est un plan , on approxime en 2d
1945 //-- sur cette surface et on remonte les points 2d en 3d.
1946 if(typs1 == GeomAbs_Plane) {
1947 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
1948 }
1949 else if(typs2 == GeomAbs_Plane) {
1950 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
1951 }
1952 else {
1953 //
1954 if (myHS1 != myHS2){
1955 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
1956 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
1957
1958 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
1959
1960 Standard_Boolean bUseSurfaces;
1961 bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
1962 if (bUseSurfaces) {
1963 // ######
1964 rejectSurface = Standard_True;
1965 // ######
1966 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1967 }
1968 }
1969 }
1970 //
1971 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
1972 }
1973 //
94218044 1974 if (!theapp3d.IsDone()) {
655fddc8 1975 Handle(Geom2d_BSplineCurve) H1;
94218044 1976 Handle(Geom2d_BSplineCurve) H2;
655fddc8 1977 //
1978 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
4abae870 1979 //
655fddc8 1980 if(myApprox1) {
1981 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1982 }
4abae870 1983 //
655fddc8 1984 if(myApprox2) {
1985 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1986 }
1987 //
1988 IntTools_Curve aIC(aBSp, H1, H2);
1989 mySeqOfCurve.Append(aIC);
1990 }
1991
1992 else {
1993 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
1994 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
1995 myTolReached2d = theapp3d.TolReached2d();
1996 }
1997 }
1998 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
1999 myTolReached3d = myTolReached2d;
2000 //
2001 if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
2002 if (myTolReached3d<1.e-6) {
2003 myTolReached3d = theapp3d.TolReached3d();
2004 myTolReached3d=1.e-6;
2005 }
2006 }
2007 }
2008 else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
2009 myTolReached3d = theapp3d.TolReached3d();
2010 }
2011
2012 Standard_Integer aNbMultiCurves, nbpoles;
2013 aNbMultiCurves=theapp3d.NbMultiCurves();
2014 for (j=1; j<=aNbMultiCurves; j++) {
2015 if(typs1 == GeomAbs_Plane) {
2016 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2017 nbpoles = mbspc.NbPoles();
2018
2019 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2020 TColgp_Array1OfPnt tpoles(1,nbpoles);
2021
2022 mbspc.Curve(1,tpoles2d);
2023 const gp_Pln& Pln = myHS1->Surface().Plane();
2024 //
2025 Standard_Integer ik;
2026 for(ik = 1; ik<= nbpoles; ik++) {
2027 tpoles.SetValue(ik,
2028 ElSLib::Value(tpoles2d.Value(ik).X(),
2029 tpoles2d.Value(ik).Y(),
2030 Pln));
2031 }
2032 //
2033 Handle(Geom_BSplineCurve) BS =
2034 new Geom_BSplineCurve(tpoles,
2035 mbspc.Knots(),
2036 mbspc.Multiplicities(),
2037 mbspc.Degree());
2038 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2039 Check.FixTangent(Standard_True, Standard_True);
2040 //
2041 IntTools_Curve aCurve;
2042 aCurve.SetCurve(BS);
2043
2044 if(myApprox1) {
2045 Handle(Geom2d_BSplineCurve) BS1 =
2046 new Geom2d_BSplineCurve(tpoles2d,
2047 mbspc.Knots(),
2048 mbspc.Multiplicities(),
2049 mbspc.Degree());
2050 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2051 Check1.FixTangent(Standard_True,Standard_True);
2052 //
2053 // ############################################
2054 if(!rejectSurface && !reApprox) {
2055 Standard_Boolean isValid = IsCurveValid(BS1);
2056 if(!isValid) {
2057 reApprox = Standard_True;
2058 goto reapprox;
2059 }
2060 }
2061 // ############################################
2062 aCurve.SetFirstCurve2d(BS1);
2063 }
2064 else {
2065 Handle(Geom2d_BSplineCurve) H1;
2066 aCurve.SetFirstCurve2d(H1);
2067 }
2068
2069 if(myApprox2) {
2070 mbspc.Curve(2, tpoles2d);
2071
2072 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
2073 mbspc.Knots(),
2074 mbspc.Multiplicities(),
2075 mbspc.Degree());
2076 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2077 newCheck.FixTangent(Standard_True,Standard_True);
2078
2079 // ###########################################
2080 if(!rejectSurface && !reApprox) {
2081 Standard_Boolean isValid = IsCurveValid(BS2);
2082 if(!isValid) {
2083 reApprox = Standard_True;
2084 goto reapprox;
2085 }
2086 }
2087 // ###########################################
2088 //
2089 aCurve.SetSecondCurve2d(BS2);
2090 }
2091 else {
2092 Handle(Geom2d_BSplineCurve) H2;
2093 //
2094 aCurve.SetSecondCurve2d(H2);
2095 }
2096 //
2097 mySeqOfCurve.Append(aCurve);
4abae870 2098 }//if(typs1 == GeomAbs_Plane) {
655fddc8 2099
2100 else if(typs2 == GeomAbs_Plane) {
2101 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2102 nbpoles = mbspc.NbPoles();
2103
2104 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2105 TColgp_Array1OfPnt tpoles(1,nbpoles);
2106 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
2107 const gp_Pln& Pln = myHS2->Surface().Plane();
2108 //
2109 Standard_Integer ik;
2110 for(ik = 1; ik<= nbpoles; ik++) {
2111 tpoles.SetValue(ik,
2112 ElSLib::Value(tpoles2d.Value(ik).X(),
2113 tpoles2d.Value(ik).Y(),
2114 Pln));
2115
2116 }
2117 //
2118 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
2119 mbspc.Knots(),
2120 mbspc.Multiplicities(),
2121 mbspc.Degree());
2122 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2123 Check.FixTangent(Standard_True,Standard_True);
2124 //
2125 IntTools_Curve aCurve;
2126 aCurve.SetCurve(BS);
2127
2128 if(myApprox2) {
2129 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
2130 mbspc.Knots(),
2131 mbspc.Multiplicities(),
2132 mbspc.Degree());
2133 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2134 Check1.FixTangent(Standard_True,Standard_True);
2135 //
2136 // ###########################################
2137 if(!rejectSurface && !reApprox) {
2138 Standard_Boolean isValid = IsCurveValid(BS1);
2139 if(!isValid) {
2140 reApprox = Standard_True;
2141 goto reapprox;
2142 }
2143 }
989341c5 2144 // ###########################################
2145 bPCurvesOk = CheckPCurve(BS1, myFace2);
655fddc8 2146 aCurve.SetSecondCurve2d(BS1);
2147 }
2148 else {
2149 Handle(Geom2d_BSplineCurve) H2;
2150 aCurve.SetSecondCurve2d(H2);
2151 }
2152
2153 if(myApprox1) {
2154 mbspc.Curve(1,tpoles2d);
2155 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
2156 mbspc.Knots(),
2157 mbspc.Multiplicities(),
2158 mbspc.Degree());
2159 GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
2160 Check2.FixTangent(Standard_True,Standard_True);
2161 //
2162 // ###########################################
2163 if(!rejectSurface && !reApprox) {
2164 Standard_Boolean isValid = IsCurveValid(BS2);
2165 if(!isValid) {
2166 reApprox = Standard_True;
2167 goto reapprox;
2168 }
2169 }
989341c5 2170 // ###########################################
2171 bPCurvesOk = bPCurvesOk && CheckPCurve(BS2, myFace1);
655fddc8 2172 aCurve.SetFirstCurve2d(BS2);
2173 }
2174 else {
2175 Handle(Geom2d_BSplineCurve) H1;
2176 //
2177 aCurve.SetFirstCurve2d(H1);
2178 }
2179 //
989341c5 2180 //if points of the pcurves are out of the faces bounds
2181 //create 3d and 2d curves without approximation
2182 if (!bPCurvesOk) {
2183 Handle(Geom2d_BSplineCurve) H1, H2;
655fddc8 2184 bPCurvesOk = Standard_True;
2185 //
989341c5 2186 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
59495dbe 2187
989341c5 2188 if(myApprox1) {
2189 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
655fddc8 2190 bPCurvesOk = CheckPCurve(H1, myFace1);
989341c5 2191 }
59495dbe 2192
989341c5 2193 if(myApprox2) {
2194 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
655fddc8 2195 bPCurvesOk = bPCurvesOk && CheckPCurve(H2, myFace2);
989341c5 2196 }
2197 //
655fddc8 2198 //if pcurves created without approximation are out of the
2199 //faces bounds, use approximated 3d and 2d curves
2200 if (bPCurvesOk) {
2201 IntTools_Curve aIC(aBSp, H1, H2);
2202 mySeqOfCurve.Append(aIC);
2203 } else {
2204 mySeqOfCurve.Append(aCurve);
2205 }
989341c5 2206 } else {
2207 mySeqOfCurve.Append(aCurve);
2208 }
4abae870 2209 }// else if(typs2 == GeomAbs_Plane)
2210 //
2211 else { //typs2 != GeomAbs_Plane && typs1 != GeomAbs_Plane
2212 Standard_Boolean bIsValid1, bIsValid2;
2213 Handle(Geom_BSplineCurve) BS;
2214 Handle(Geom2d_BSplineCurve) aH2D;
2215 IntTools_Curve aCurve;
2216 //
2217 bIsValid1=Standard_True;
2218 bIsValid2=Standard_True;
2219 //
655fddc8 2220 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2221 nbpoles = mbspc.NbPoles();
2222 TColgp_Array1OfPnt tpoles(1,nbpoles);
2223 mbspc.Curve(1,tpoles);
4abae870 2224 BS=new Geom_BSplineCurve(tpoles,
655fddc8 2225 mbspc.Knots(),
2226 mbspc.Multiplicities(),
2227 mbspc.Degree());
2228 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2229 Check.FixTangent(Standard_True,Standard_True);
2230 //
2231 aCurve.SetCurve(BS);
4abae870 2232 aCurve.SetFirstCurve2d(aH2D);
2233 aCurve.SetSecondCurve2d(aH2D);
2234 //
655fddc8 2235 if(myApprox1) {
2236 if(anApprox1) {
4abae870 2237 Handle(Geom2d_BSplineCurve) BS1;
655fddc8 2238 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2239 mbspc.Curve(2,tpoles2d);
4abae870 2240 //
2241 BS1=new Geom2d_BSplineCurve(tpoles2d,
655fddc8 2242 mbspc.Knots(),
2243 mbspc.Multiplicities(),
2244 mbspc.Degree());
2245 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
2246 newCheck.FixTangent(Standard_True,Standard_True);
2247 //
4abae870 2248 if (!reApprox) {
2249 bIsValid1=CheckPCurve(BS1, myFace1);
2250 }
2251 //
655fddc8 2252 aCurve.SetFirstCurve2d(BS1);
2253 }
2254 else {
2255 Handle(Geom2d_BSplineCurve) BS1;
2256 fprm = BS->FirstParameter();
2257 lprm = BS->LastParameter();
2258
2259 Handle(Geom2d_Curve) C2d;
2260 Standard_Real aTol = myTolApprox;
2261 BuildPCurves(fprm, lprm, aTol, myHS1->ChangeSurface().Surface(), BS, C2d);
2262 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2263 aCurve.SetFirstCurve2d(BS1);
2264 }
4abae870 2265 } // if(myApprox1) {
655fddc8 2266 //
2267 if(myApprox2) {
2268 if(anApprox2) {
4abae870 2269 Handle(Geom2d_BSplineCurve) BS2;
655fddc8 2270 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2271 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
4abae870 2272 BS2=new Geom2d_BSplineCurve(tpoles2d,
655fddc8 2273 mbspc.Knots(),
2274 mbspc.Multiplicities(),
2275 mbspc.Degree());
2276 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2277 newCheck.FixTangent(Standard_True,Standard_True);
2278 //
4abae870 2279 if (!reApprox) {
2280 bIsValid2=CheckPCurve(BS2, myFace2);
2281 }
655fddc8 2282 aCurve.SetSecondCurve2d(BS2);
2283 }
2284 else {
2285 Handle(Geom2d_BSplineCurve) BS2;
2286 fprm = BS->FirstParameter();
2287 lprm = BS->LastParameter();
2288
2289 Handle(Geom2d_Curve) C2d;
2290 Standard_Real aTol = myTolApprox;
2291 BuildPCurves(fprm, lprm, aTol, myHS2->ChangeSurface().Surface(), BS, C2d);
2292 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2293 aCurve.SetSecondCurve2d(BS2);
2294 }
4abae870 2295 } //if(myApprox2) {
2296 if (!bIsValid1 || !bIsValid2) {
2297 myTolApprox=aTolApproxImp;//1.e-5;
2298 tol2d = myTolApprox;
2299 reApprox = Standard_True;
2300 goto reapprox;
655fddc8 2301 }
2302 //
2303 mySeqOfCurve.Append(aCurve);
2304 }
2305 }
2306 }
7fd59977 2307 }
2308 }// else { // X
2309 }// case IntPatch_Walking:{
59495dbe 2310 break;
2311
7fd59977 2312 case IntPatch_Restriction:
2313 break;
4abae870 2314 default:
2315 break;
7fd59977 2316
2317 }
2318}
2319
2320//=======================================================================
2321//function : BuildPCurves
2322//purpose :
2323//=======================================================================
655fddc8 2324void BuildPCurves (Standard_Real f,
2325 Standard_Real l,
2326 Standard_Real& Tol,
2327 const Handle (Geom_Surface)& S,
2328 const Handle (Geom_Curve)& C,
2329 Handle (Geom2d_Curve)& C2d)
7fd59977 2330{
655fddc8 2331 if (!C2d.IsNull()) {
2332 return;
2333 }
2334 //
7fd59977 2335 Standard_Real umin,umax,vmin,vmax;
2336 //
655fddc8 2337 S->Bounds(umin, umax, vmin, vmax);
2338 // in class ProjLib_Function the range of parameters is shrank by 1.e-09
2339 if((l - f) > 2.e-09) {
2340 C2d = GeomProjLib::Curve2d(C,f,l,S,umin,umax,vmin,vmax,Tol);
2341 //
2342 if (C2d.IsNull()) {
2343 // proj. a circle that goes through the pole on a sphere to the sphere
2344 Tol += Precision::Confusion();
7fd59977 2345 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
7fd59977 2346 }
655fddc8 2347 }
2348 else {
2349 if((l - f) > Epsilon(Abs(f))) {
2350 GeomAPI_ProjectPointOnSurf aProjector1, aProjector2;
2351 gp_Pnt P1 = C->Value(f);
2352 gp_Pnt P2 = C->Value(l);
2353 aProjector1.Init(P1, S);
2354 aProjector2.Init(P2, S);
2355
2356 if(aProjector1.IsDone() && aProjector2.IsDone()) {
2357 Standard_Real U=0., V=0.;
2358 aProjector1.LowerDistanceParameters(U, V);
2359 gp_Pnt2d p1(U, V);
2360
2361 aProjector2.LowerDistanceParameters(U, V);
2362 gp_Pnt2d p2(U, V);
2363
2364 if(p1.Distance(p2) > gp::Resolution()) {
2365 TColgp_Array1OfPnt2d poles(1,2);
2366 TColStd_Array1OfReal knots(1,2);
2367 TColStd_Array1OfInteger mults(1,2);
2368 poles(1) = p1;
2369 poles(2) = p2;
2370 knots(1) = f;
2371 knots(2) = l;
2372 mults(1) = mults(2) = 2;
2373
2374 C2d = new Geom2d_BSplineCurve(poles,knots,mults,1);
2375
2376 // compute reached tolerance.begin
2377 gp_Pnt PMid = C->Value((f + l) * 0.5);
2378 aProjector1.Perform(PMid);
2379
2380 if(aProjector1.IsDone()) {
2381 aProjector1.LowerDistanceParameters(U, V);
2382 gp_Pnt2d pmidproj(U, V);
2383 gp_Pnt2d pmidcurve2d = C2d->Value((f + l) * 0.5);
2384 Standard_Real adist = pmidcurve2d.Distance(pmidproj);
2385 Tol = (adist > Tol) ? adist : Tol;
4abae870 2386 }
655fddc8 2387 // compute reached tolerance.end
4abae870 2388 }
7fd59977 2389 }
2390 }
655fddc8 2391 }
2392 //
2393 if (S->IsUPeriodic() && !C2d.IsNull()) {
2394 // Recadre dans le domaine UV de la face
2395 Standard_Real aTm, U0, aEps, period, du, U0x;
2396 Standard_Boolean bAdjust;
7fd59977 2397 //
655fddc8 2398 aEps = Precision::PConfusion();
2399 period = S->UPeriod();
2400 //
2401 aTm = .5*(f + l);
2402 gp_Pnt2d pm = C2d->Value(aTm);
2403 U0 = pm.X();
2404 //
2405 bAdjust =
2406 IntTools_Tools::AdjustPeriodic(U0, umin, umax, period, U0x, du, aEps);
2407 if (bAdjust) {
2408 gp_Vec2d T1(du, 0.);
2409 C2d->Translate(T1);
7fd59977 2410 }
2411 }
7fd59977 2412}
2413
2414//=======================================================================
2415//function : Parameters
2416//purpose :
2417//=======================================================================
2418 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
655fddc8 2419 const Handle(GeomAdaptor_HSurface)& HS2,
2420 const gp_Pnt& Ptref,
2421 Standard_Real& U1,
2422 Standard_Real& V1,
2423 Standard_Real& U2,
2424 Standard_Real& V2)
7fd59977 2425{
2426
2427 IntSurf_Quadric quad1,quad2;
2428 GeomAbs_SurfaceType typs = HS1->Surface().GetType();
2429
2430 switch (typs) {
2431 case GeomAbs_Plane:
2432 quad1.SetValue(HS1->Surface().Plane());
2433 break;
2434 case GeomAbs_Cylinder:
2435 quad1.SetValue(HS1->Surface().Cylinder());
2436 break;
2437 case GeomAbs_Cone:
2438 quad1.SetValue(HS1->Surface().Cone());
2439 break;
2440 case GeomAbs_Sphere:
2441 quad1.SetValue(HS1->Surface().Sphere());
2442 break;
7eed5d29 2443 case GeomAbs_Torus:
2444 quad1.SetValue(HS1->Surface().Torus());
2445 break;
7fd59977 2446 default:
2447 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2448 }
2449
2450 typs = HS2->Surface().GetType();
2451 switch (typs) {
2452 case GeomAbs_Plane:
2453 quad2.SetValue(HS2->Surface().Plane());
2454 break;
2455 case GeomAbs_Cylinder:
2456 quad2.SetValue(HS2->Surface().Cylinder());
2457 break;
2458 case GeomAbs_Cone:
2459 quad2.SetValue(HS2->Surface().Cone());
2460 break;
2461 case GeomAbs_Sphere:
2462 quad2.SetValue(HS2->Surface().Sphere());
2463 break;
7eed5d29 2464 case GeomAbs_Torus:
2465 quad2.SetValue(HS2->Surface().Torus());
2466 break;
7fd59977 2467 default:
2468 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2469 }
2470
2471 quad1.Parameters(Ptref,U1,V1);
2472 quad2.Parameters(Ptref,U2,V2);
2473}
2474
2475//=======================================================================
2476//function : MakeBSpline
2477//purpose :
2478//=======================================================================
2479Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
655fddc8 2480 const Standard_Integer ideb,
2481 const Standard_Integer ifin)
7fd59977 2482{
2483 Standard_Integer i,nbpnt = ifin-ideb+1;
2484 TColgp_Array1OfPnt poles(1,nbpnt);
2485 TColStd_Array1OfReal knots(1,nbpnt);
2486 TColStd_Array1OfInteger mults(1,nbpnt);
2487 Standard_Integer ipidebm1;
2488 for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) {
2489 poles(i) = WL->Point(ipidebm1).Value();
2490 mults(i) = 1;
2491 knots(i) = i-1;
2492 }
2493 mults(1) = mults(nbpnt) = 2;
2494 return
2495 new Geom_BSplineCurve(poles,knots,mults,1);
2496}
2497//
2498
2499//=======================================================================
2500//function : MakeBSpline2d
2501//purpose :
2502//=======================================================================
2503Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
655fddc8 2504 const Standard_Integer ideb,
2505 const Standard_Integer ifin,
2506 const Standard_Boolean onFirst)
7fd59977 2507{
2508 Standard_Integer i, nbpnt = ifin-ideb+1;
2509 TColgp_Array1OfPnt2d poles(1,nbpnt);
2510 TColStd_Array1OfReal knots(1,nbpnt);
2511 TColStd_Array1OfInteger mults(1,nbpnt);
2512 Standard_Integer ipidebm1;
2513
2514 for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
2515 Standard_Real U, V;
2516 if(onFirst)
655fddc8 2517 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
7fd59977 2518 else
655fddc8 2519 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
7fd59977 2520 poles(i).SetCoord(U, V);
2521 mults(i) = 1;
2522 knots(i) = i-1;
2523 }
2524 mults(1) = mults(nbpnt) = 2;
2525
2526 return new Geom2d_BSplineCurve(poles,knots,mults,1);
2527}
2528//=======================================================================
2529//function : PrepareLines3D
2530//purpose :
2531//=======================================================================
a9f7b6b5 2532 void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit)
7fd59977 2533{
a9f7b6b5
P
2534 Standard_Integer i, aNbCurves;
2535 GeomAbs_SurfaceType aType1, aType2;
7fd59977 2536 IntTools_SequenceOfCurves aNewCvs;
7fd59977 2537 //
a9f7b6b5 2538 // 1. Treatment closed curves
7fd59977 2539 aNbCurves=mySeqOfCurve.Length();
a9f7b6b5 2540 for (i=1; i<=aNbCurves; ++i) {
7fd59977 2541 const IntTools_Curve& aIC=mySeqOfCurve(i);
7fd59977 2542 //
a9f7b6b5
P
2543 if (bToSplit) {
2544 Standard_Integer j, aNbC;
2545 IntTools_SequenceOfCurves aSeqCvs;
2546 //
2547 aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
2548 if (aNbC) {
655fddc8 2549 for (j=1; j<=aNbC; ++j) {
2550 const IntTools_Curve& aICNew=aSeqCvs(j);
2551 aNewCvs.Append(aICNew);
2552 }
a9f7b6b5
P
2553 }
2554 else {
655fddc8 2555 aNewCvs.Append(aIC);
7fd59977 2556 }
2557 }
7fd59977 2558 else {
2559 aNewCvs.Append(aIC);
2560 }
2561 }
2562 //
2563 // 2. Plane\Cone intersection when we had 4 curves
a9f7b6b5
P
2564 aType1=myHS1->GetType();
2565 aType2=myHS2->GetType();
2566 aNbCurves=aNewCvs.Length();
2567 //
7fd59977 2568 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) ||
2569 (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) {
7fd59977 2570 if (aNbCurves==4) {
a9f7b6b5
P
2571 GeomAbs_CurveType aCType1;
2572 //
2573 aCType1=aNewCvs(1).Type();
7fd59977 2574 if (aCType1==GeomAbs_Line) {
655fddc8 2575 IntTools_SequenceOfCurves aSeqIn, aSeqOut;
2576 //
2577 for (i=1; i<=aNbCurves; ++i) {
2578 const IntTools_Curve& aIC=aNewCvs(i);
2579 aSeqIn.Append(aIC);
2580 }
2581 //
2582 IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
2583 //
2584 aNewCvs.Clear();
2585 aNbCurves=aSeqOut.Length();
2586 for (i=1; i<=aNbCurves; ++i) {
2587 const IntTools_Curve& aIC=aSeqOut(i);
2588 aNewCvs.Append(aIC);
2589 }
7fd59977 2590 }
2591 }
a9f7b6b5 2592 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)...
7fd59977 2593 //
2594 // 3. Fill mySeqOfCurve
2595 mySeqOfCurve.Clear();
2596 aNbCurves=aNewCvs.Length();
a9f7b6b5 2597 for (i=1; i<=aNbCurves; ++i) {
7fd59977 2598 const IntTools_Curve& aIC=aNewCvs(i);
2599 mySeqOfCurve.Append(aIC);
2600 }
7fd59977 2601}
7fd59977 2602//=======================================================================
2603//function : CorrectSurfaceBoundaries
2604//purpose :
2605//=======================================================================
59495dbe 2606 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
c002793b 2607 const Standard_Real theTolerance,
2608 Standard_Real& theumin,
2609 Standard_Real& theumax,
2610 Standard_Real& thevmin,
2611 Standard_Real& thevmax)
7fd59977 2612{
2613 Standard_Boolean enlarge, isuperiodic, isvperiodic;
2614 Standard_Real uinf, usup, vinf, vsup, delta;
2615 GeomAbs_SurfaceType aType;
2616 Handle(Geom_Surface) aSurface;
2617 //
2618 aSurface = BRep_Tool::Surface(theFace);
2619 aSurface->Bounds(uinf, usup, vinf, vsup);
2620 delta = theTolerance;
2621 enlarge = Standard_False;
2622 //
2623 GeomAdaptor_Surface anAdaptorSurface(aSurface);
2624 //
2625 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
2626 Handle(Geom_Surface) aBasisSurface =
2627 (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface();
2628
2629 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2630 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2631 return;
2632 }
2633 }
2634 //
2635 if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2636 Handle(Geom_Surface) aBasisSurface =
2637 (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface();
2638
2639 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2640 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2641 return;
2642 }
2643 }
2644 //
2645 isuperiodic = anAdaptorSurface.IsUPeriodic();
2646 isvperiodic = anAdaptorSurface.IsVPeriodic();
2647 //
2648 aType=anAdaptorSurface.GetType();
2649 if((aType==GeomAbs_BezierSurface) ||
2650 (aType==GeomAbs_BSplineSurface) ||
2651 (aType==GeomAbs_SurfaceOfExtrusion) ||
c002793b 2652 (aType==GeomAbs_SurfaceOfRevolution) ||
2653 (aType==GeomAbs_Cylinder)) {
7fd59977 2654 enlarge=Standard_True;
2655 }
2656 //
2657 if(!isuperiodic && enlarge) {
2658
2659 if((theumin - uinf) > delta )
2660 theumin -= delta;
2661 else {
2662 theumin = uinf;
2663 }
2664
2665 if((usup - theumax) > delta )
2666 theumax += delta;
2667 else
2668 theumax = usup;
2669 }
2670 //
2671 if(!isvperiodic && enlarge) {
2672 if((thevmin - vinf) > delta ) {
2673 thevmin -= delta;
2674 }
2675 else {
2676 thevmin = vinf;
2677 }
2678 if((vsup - thevmax) > delta ) {
2679 thevmax += delta;
2680 }
2681 else {
2682 thevmax = vsup;
2683 }
2684 }
2685 //
2686 {
2687 Standard_Integer aNbP;
2688 Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA;
2689 //
2690 aTolPA=Precision::Angular();
2691 // U
2692 if (isuperiodic) {
2693 aXP=anAdaptorSurface.UPeriod();
2694 dXfact=theumax-theumin;
2695 if (dXfact-aTolPA>aXP) {
655fddc8 2696 aXmid=0.5*(theumax+theumin);
2697 aNbP=RealToInt(aXmid/aXP);
2698 if (aXmid<0.) {
2699 aNbP=aNbP-1;
2700 }
2701 aX1=aNbP*aXP;
2702 if (theumin>aTolPA) {
2703 aX1=theumin+aNbP*aXP;
2704 }
2705 aX2=aX1+aXP;
2706 if (theumin<aX1) {
2707 theumin=aX1;
2708 }
2709 if (theumax>aX2) {
2710 theumax=aX2;
2711 }
7fd59977 2712 }
2713 }
2714 // V
2715 if (isvperiodic) {
2716 aXP=anAdaptorSurface.VPeriod();
2717 dXfact=thevmax-thevmin;
2718 if (dXfact-aTolPA>aXP) {
655fddc8 2719 aXmid=0.5*(thevmax+thevmin);
2720 aNbP=RealToInt(aXmid/aXP);
2721 if (aXmid<0.) {
2722 aNbP=aNbP-1;
2723 }
2724 aX1=aNbP*aXP;
2725 if (thevmin>aTolPA) {
2726 aX1=thevmin+aNbP*aXP;
2727 }
2728 aX2=aX1+aXP;
2729 if (thevmin<aX1) {
2730 thevmin=aX1;
2731 }
2732 if (thevmax>aX2) {
2733 thevmax=aX2;
2734 }
7fd59977 2735 }
2736 }
2737 }
2738 //
2739 if(isuperiodic || isvperiodic) {
2740 Standard_Boolean correct = Standard_False;
2741 Standard_Boolean correctU = Standard_False;
2742 Standard_Boolean correctV = Standard_False;
2743 Bnd_Box2d aBox;
2744 TopExp_Explorer anExp;
2745
2746 for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2747 if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
655fddc8 2748 correct = Standard_True;
2749 Standard_Real f, l;
2750 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
2751
2752 for(Standard_Integer i = 0; i < 2; i++) {
2753 if(i==0) {
2754 anEdge.Orientation(TopAbs_FORWARD);
2755 }
2756 else {
2757 anEdge.Orientation(TopAbs_REVERSED);
2758 }
2759 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
2760
2761 if(aCurve.IsNull()) {
2762 correct = Standard_False;
2763 break;
2764 }
2765 Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
2766
2767 if(aLine.IsNull()) {
2768 correct = Standard_False;
2769 break;
2770 }
2771 gp_Dir2d anUDir(1., 0.);
2772 gp_Dir2d aVDir(0., 1.);
2773 Standard_Real anAngularTolerance = Precision::Angular();
2774
2775 correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
2776 correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
2777
2778 gp_Pnt2d pp1 = aCurve->Value(f);
2779 aBox.Add(pp1);
2780 gp_Pnt2d pp2 = aCurve->Value(l);
2781 aBox.Add(pp2);
2782 }
2783 if(!correct)
2784 break;
7fd59977 2785 }
2786 }
2787
2788 if(correct) {
2789 Standard_Real umin, vmin, umax, vmax;
2790 aBox.Get(umin, vmin, umax, vmax);
2791
2792 if(isuperiodic && correctU) {
655fddc8 2793
2794 if(theumin < umin)
2795 theumin = umin;
2796
2797 if(theumax > umax) {
2798 theumax = umax;
2799 }
7fd59977 2800 }
2801 if(isvperiodic && correctV) {
655fddc8 2802
2803 if(thevmin < vmin)
2804 thevmin = vmin;
2805 if(thevmax > vmax)
2806 thevmax = vmax;
7fd59977 2807 }
2808 }
2809 }
2810}
2811//
2812//
2813// The block is dedicated to determine whether WLine [ifprm, ilprm]
2814// crosses the degenerated zone on each given surface or not.
2815// If Yes -> We will not use info about surfaces during approximation
8e0115e4 2816// because inside degenerated zone of the surface the approx. algo.
7fd59977 2817// uses wrong values of normal, etc., and resulting curve will have
2818// oscillations that we would not like to have.
7fd59977 2819
2820
4e57c75e 2821
7fd59977 2822static
2823 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
655fddc8 2824 const Handle(Geom_Surface)& aS,
2825 const Standard_Integer iDir);
7fd59977 2826static
2827 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
655fddc8 2828 const TopoDS_Face& aF1,
2829 const TopoDS_Face& aF2);
7fd59977 2830//=======================================================================
2831//function : NotUseSurfacesForApprox
2832//purpose :
2833//=======================================================================
2834Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
655fddc8 2835 const TopoDS_Face& aF2,
2836 const Handle(IntPatch_WLine)& WL,
2837 const Standard_Integer ifprm,
2838 const Standard_Integer ilprm)
7fd59977 2839{
2840 Standard_Boolean bPInDZ;
2841
2842 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
2843
2844 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
2845 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
2846 if (bPInDZ) {
2847 return bPInDZ;
2848 }
2849
2850 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
2851 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
2852
2853 return bPInDZ;
2854}
2855//=======================================================================
2856//function : IsPointInDegeneratedZone
2857//purpose :
2858//=======================================================================
2859Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
655fddc8 2860 const TopoDS_Face& aF1,
2861 const TopoDS_Face& aF2)
2862
7fd59977 2863{
2864 Standard_Boolean bFlag=Standard_True;
2865 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
2866 Standard_Real U1, V1, U2, V2, aDelta, aD;
2867 gp_Pnt2d aP2d;
2868
2869 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
2870 aS1->Bounds(US11, US12, VS11, VS12);
2871 GeomAdaptor_Surface aGAS1(aS1);
2872
2873 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
2874 aS1->Bounds(US21, US22, VS21, VS22);
2875 GeomAdaptor_Surface aGAS2(aS2);
2876 //
2877 //const gp_Pnt& aP=aP2S.Value();
2878 aP2S.Parameters(U1, V1, U2, V2);
2879 //
2880 aDelta=1.e-7;
2881 // Check on Surf 1
2882 aD=aGAS1.UResolution(aDelta);
2883 aP2d.SetCoord(U1, V1);
2884 if (fabs(U1-US11) < aD) {
2885 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2886 if (bFlag) {
2887 return bFlag;
2888 }
2889 }
2890 if (fabs(U1-US12) < aD) {
2891 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2892 if (bFlag) {
2893 return bFlag;
2894 }
2895 }
2896 aD=aGAS1.VResolution(aDelta);
2897 if (fabs(V1-VS11) < aDelta) {
2898 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2899 if (bFlag) {
2900 return bFlag;
2901 }
2902 }
2903 if (fabs(V1-VS12) < aDelta) {
2904 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2905 if (bFlag) {
2906 return bFlag;
2907 }
2908 }
2909 // Check on Surf 2
2910 aD=aGAS2.UResolution(aDelta);
2911 aP2d.SetCoord(U2, V2);
2912 if (fabs(U2-US21) < aDelta) {
2913 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2914 if (bFlag) {
2915 return bFlag;
2916 }
2917 }
2918 if (fabs(U2-US22) < aDelta) {
2919 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2920 if (bFlag) {
2921 return bFlag;
2922 }
2923 }
2924 aD=aGAS2.VResolution(aDelta);
2925 if (fabs(V2-VS21) < aDelta) {
2926 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2927 if (bFlag) {
2928 return bFlag;
2929 }
2930 }
2931 if (fabs(V2-VS22) < aDelta) {
2932 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2933 if (bFlag) {
2934 return bFlag;
2935 }
2936 }
2937 return !bFlag;
2938}
2939
2940//=======================================================================
2941//function : IsDegeneratedZone
2942//purpose :
2943//=======================================================================
2944Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
655fddc8 2945 const Handle(Geom_Surface)& aS,
2946 const Standard_Integer iDir)
7fd59977 2947{
2948 Standard_Boolean bFlag=Standard_True;
2949 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
2950 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
2951 aS->Bounds(US1, US2, VS1, VS2);
2952
2953 gp_Pnt aPm, aPb, aPe;
2954
2955 aXm=aP2d.X();
2956 aYm=aP2d.Y();
2957
2958 aS->D0(aXm, aYm, aPm);
2959
2960 dX=1.e-5;
2961 dY=1.e-5;
2962 dD=1.e-12;
2963
2964 if (iDir==1) {
2965 aXb=aXm;
2966 aXe=aXm;
2967 aYb=aYm-dY;
2968 if (aYb < VS1) {
2969 aYb=VS1;
2970 }
2971 aYe=aYm+dY;
2972 if (aYe > VS2) {
2973 aYe=VS2;
2974 }
2975 aS->D0(aXb, aYb, aPb);
2976 aS->D0(aXe, aYe, aPe);
2977
2978 d1=aPm.Distance(aPb);
2979 d2=aPm.Distance(aPe);
2980 if (d1 < dD && d2 < dD) {
2981 return bFlag;
2982 }
2983 return !bFlag;
2984 }
2985 //
2986 else if (iDir==2) {
2987 aYb=aYm;
2988 aYe=aYm;
2989 aXb=aXm-dX;
2990 if (aXb < US1) {
2991 aXb=US1;
2992 }
2993 aXe=aXm+dX;
2994 if (aXe > US2) {
2995 aXe=US2;
2996 }
2997 aS->D0(aXb, aYb, aPb);
2998 aS->D0(aXe, aYe, aPe);
2999
3000 d1=aPm.Distance(aPb);
3001 d2=aPm.Distance(aPe);
3002 if (d1 < dD && d2 < dD) {
3003 return bFlag;
3004 }
3005 return !bFlag;
3006 }
3007 return !bFlag;
3008}
3009
3010//=========================================================================
3011// static function : ComputePurgedWLine
3012// purpose : Removes equal points (leave one of equal points) from theWLine
3013// and recompute vertex parameters.
3014// Returns new WLine or null WLine if the number
3015// of the points is less than 2.
3016//=========================================================================
3017Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) {
3928aec6 3018
3928aec6 3019 Standard_Integer i, k, v, nb, nbvtx;
7fd59977 3020 Handle(IntPatch_WLine) aResult;
3928aec6
P
3021 nbvtx = theWLine->NbVertex();
3022 nb = theWLine->NbPnts();
3023 if (nb==2) {
3024 const IntSurf_PntOn2S& p1 = theWLine->Point(1);
3025 const IntSurf_PntOn2S& p2 = theWLine->Point(2);
3026 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
3027 return aResult;
3028 }
3029 }
3030 //
7fd59977 3031 Handle(IntPatch_WLine) aLocalWLine;
3032 Handle(IntPatch_WLine) aTmpWLine = theWLine;
7fd59977 3033 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
3034 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
7fd59977 3035 for(i = 1; i <= nb; i++) {
3036 aLineOn2S->Add(theWLine->Point(i));
3037 }
3038
3039 for(v = 1; v <= nbvtx; v++) {
3040 aLocalWLine->AddVertex(theWLine->Vertex(v));
3041 }
3042
3043 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
3044 Standard_Integer aStartIndex = i + 1;
3045 Standard_Integer anEndIndex = i + 5;
3046 nb = aLineOn2S->NbPoints();
3047 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
3048
a2eede02 3049 if((aStartIndex > nb) || (anEndIndex <= 1)) {
7fd59977 3050 continue;
3051 }
3052 k = aStartIndex;
3053
3054 while(k <= anEndIndex) {
3055
3056 if(i != k) {
655fddc8 3057 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
3058 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
3059
3060 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
3061 aTmpWLine = aLocalWLine;
3062 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
3063
3064 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
3065 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
3066 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
3067
3068 if(avertexindex >= k) {
3069 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
3070 }
3071 aLocalWLine->AddVertex(aVertex);
3072 }
3073 aLineOn2S->RemovePoint(k);
3074 anEndIndex--;
3075 continue;
3076 }
7fd59977 3077 }
3078 k++;
3079 }
3080 }
3081
3082 if(aLineOn2S->NbPoints() > 1) {
3083 aResult = aLocalWLine;
3084 }
3085 return aResult;
3086}
3087
3088//=======================================================================
3089//function : TolR3d
3090//purpose :
3091//=======================================================================
3092void TolR3d(const TopoDS_Face& aF1,
655fddc8 3093 const TopoDS_Face& aF2,
3094 Standard_Real& myTolReached3d)
7fd59977 3095{
3096 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
3097
3098 aTolTresh=2.999999e-3;
3099 aTolF1 = BRep_Tool::Tolerance(aF1);
3100 aTolF2 = BRep_Tool::Tolerance(aF2);
3101 aTolFMax=Max(aTolF1, aTolF2);
3102
3103 if (aTolFMax>aTolTresh) {
3104 myTolReached3d=aTolFMax;
3105 }
3106}
3107//=======================================================================
7fd59977 3108//function : IsPointOnBoundary
3109//purpose :
3110//=======================================================================
3111Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
655fddc8 3112 const Standard_Real theFirstBoundary,
3113 const Standard_Real theSecondBoundary,
3114 const Standard_Real theResolution,
3115 Standard_Boolean& IsOnFirstBoundary)
7fd59977 3116{
3117 Standard_Boolean bRet;
3118 Standard_Integer i;
3119 Standard_Real adist;
3120 //
3121 bRet=Standard_False;
3122 for(i = 0; i < 2; ++i) {
3123 IsOnFirstBoundary = (i == 0);
3124 if (IsOnFirstBoundary) {
3125 adist = fabs(theParameter - theFirstBoundary);
3126 }
3127 else {
3128 adist = fabs(theParameter - theSecondBoundary);
3129 }
3130 if(adist < theResolution) {
3131 return !bRet;
3132 }
3133 }
3134 return bRet;
3135}
3136// ------------------------------------------------------------------------------------------------
3137// static function: FindPoint
3138// purpose:
3139// ------------------------------------------------------------------------------------------------
3140Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
655fddc8 3141 const gp_Pnt2d& theLastPoint,
3142 const Standard_Real theUmin,
3143 const Standard_Real theUmax,
3144 const Standard_Real theVmin,
3145 const Standard_Real theVmax,
3146 gp_Pnt2d& theNewPoint) {
7fd59977 3147
3148 gp_Vec2d aVec(theFirstPoint, theLastPoint);
3149 Standard_Integer i = 0, j = 0;
3150
3151 for(i = 0; i < 4; i++) {
3152 gp_Vec2d anOtherVec;
3153 gp_Vec2d anOtherVecNormal;
3154 gp_Pnt2d aprojpoint = theLastPoint;
3155
3156 if((i % 2) == 0) {
3157 anOtherVec.SetX(0.);
3158 anOtherVec.SetY(1.);
3159 anOtherVecNormal.SetX(1.);
3160 anOtherVecNormal.SetY(0.);
3161
3162 if(i < 2)
655fddc8 3163 aprojpoint.SetX(theUmin);
7fd59977 3164 else
655fddc8 3165 aprojpoint.SetX(theUmax);
7fd59977 3166 }
3167 else {
3168 anOtherVec.SetX(1.);
3169 anOtherVec.SetY(0.);
3170 anOtherVecNormal.SetX(0.);
3171 anOtherVecNormal.SetY(1.);
3172
3173 if(i < 2)
655fddc8 3174 aprojpoint.SetY(theVmin);
7fd59977 3175 else
655fddc8 3176 aprojpoint.SetY(theVmax);
7fd59977 3177 }
3178 gp_Vec2d anormvec = aVec;
3179 anormvec.Normalize();
fa9681ca 3180 RefineVector(anormvec);
7fd59977 3181 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
3182
3183 if(fabs(adot1) < Precision::Angular())
3184 continue;
3185 Standard_Real adist = 0.;
3186 Standard_Boolean bIsOut = Standard_False;
3187
3188 if((i % 2) == 0) {
3189 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
3190 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
3191 }
3192 else {
3193 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
3194 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
3195 }
3196 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
3197
3198 for(j = 0; j < 2; j++) {
3199 anoffset = (j == 0) ? anoffset : -anoffset;
3200 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
3201 gp_Vec2d acurvec(theLastPoint, acurpoint);
3202 if ( bIsOut )
655fddc8 3203 acurvec.Reverse();
7fd59977 3204
9e9df9d9
P
3205 Standard_Real aDotX, anAngleX;
3206 //
3207 aDotX = aVec.Dot(acurvec);
3208 anAngleX = aVec.Angle(acurvec);
3209 //
3210 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
655fddc8 3211 if((i % 2) == 0) {
3212 if((acurpoint.Y() >= theVmin) &&
3213 (acurpoint.Y() <= theVmax)) {
3214 theNewPoint = acurpoint;
3215 return Standard_True;
3216 }
3217 }
3218 else {
3219 if((acurpoint.X() >= theUmin) &&
3220 (acurpoint.X() <= theUmax)) {
3221 theNewPoint = acurpoint;
3222 return Standard_True;
3223 }
3224 }
7fd59977 3225 }
3226 }
3227 }
3228 return Standard_False;
3229}
3230
3231
3232// ------------------------------------------------------------------------------------------------
3233// static function: FindPoint
3234// purpose: Find point on the boundary of radial tangent zone
3235// ------------------------------------------------------------------------------------------------
3236Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
655fddc8 3237 const gp_Pnt2d& theLastPoint,
3238 const Standard_Real theUmin,
3239 const Standard_Real theUmax,
3240 const Standard_Real theVmin,
3241 const Standard_Real theVmax,
3242 const gp_Pnt2d& theTanZoneCenter,
3243 const Standard_Real theZoneRadius,
3244 Handle(GeomAdaptor_HSurface) theGASurface,
3245 gp_Pnt2d& theNewPoint) {
7fd59977 3246 theNewPoint = theLastPoint;
3247
3248 if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
3249 return Standard_False;
3250
3251 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3252 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3253
3254 Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3255 gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) );
3256 gp_Circ2d aCircle( anAxis, aRadius );
3257
3258 //
3259 gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() );
3260 Standard_Real aLength = aDir.Magnitude();
3261 if ( aLength <= gp::Resolution() )
3262 return Standard_False;
3263 gp_Lin2d aLine( theFirstPoint, aDir );
3264
3265 //
3266 Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine );
3267 Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength );
3268 Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle );
3269
3270 Standard_Real aTol = aRadius * 0.001;
3271 aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol;
3272
3273 Geom2dAPI_InterCurveCurve anIntersector;
3274 anIntersector.Init( aC1, aC2, aTol );
3275
3276 if ( anIntersector.NbPoints() == 0 )
3277 return Standard_False;
3278
3279 Standard_Boolean aFound = Standard_False;
3280 Standard_Real aMinDist = aLength * aLength;
3281 Standard_Integer i = 0;
3282 for ( i = 1; i <= anIntersector.NbPoints(); i++ ) {
3283 gp_Pnt2d aPInt = anIntersector.Point( i );
3284 if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
3285 if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
655fddc8 3286 ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
3287 theNewPoint = aPInt;
3288 aFound = Standard_True;
7fd59977 3289 }
3290 }
3291 }
3292
3293 return aFound;
3294}
3295
3296// ------------------------------------------------------------------------------------------------
3297// static function: IsInsideTanZone
3298// purpose: Check if point is inside a radial tangent zone
3299// ------------------------------------------------------------------------------------------------
3300Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
655fddc8 3301 const gp_Pnt2d& theTanZoneCenter,
3302 const Standard_Real theZoneRadius,
3303 Handle(GeomAdaptor_HSurface) theGASurface) {
7fd59977 3304
3305 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3306 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3307 Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3308 aRadiusSQR *= aRadiusSQR;
3309 if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR )
3310 return Standard_True;
3311 return Standard_False;
3312}
3313
3314// ------------------------------------------------------------------------------------------------
3315// static function: CheckTangentZonesExist
3316// purpose: Check if tangent zone exists
3317// ------------------------------------------------------------------------------------------------
3318Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
655fddc8 3319 const Handle(GeomAdaptor_HSurface)& theSurface2 )
7fd59977 3320{
3321 if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
3322 ( theSurface2->GetType() != GeomAbs_Torus ) )
3323 return Standard_False;
3324
7fd59977 3325 gp_Torus aTor1 = theSurface1->Torus();
3326 gp_Torus aTor2 = theSurface2->Torus();
3327
3328 if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() )
3329 return Standard_False;
3330
3331 if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) ||
3332 ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) )
3333 return Standard_False;
3334
3335 if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) ||
3336 ( aTor2.MajorRadius() < aTor2.MinorRadius() ) )
3337 return Standard_False;
3338 return Standard_True;
3339}
3340
3341// ------------------------------------------------------------------------------------------------
3342// static function: ComputeTangentZones
3343// purpose:
3344// ------------------------------------------------------------------------------------------------
3345Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
655fddc8 3346 const Handle(GeomAdaptor_HSurface)& theSurface2,
3347 const TopoDS_Face& theFace1,
3348 const TopoDS_Face& theFace2,
3349 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
3350 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
3351 Handle(TColStd_HArray1OfReal)& theResultRadius,
1e143abb 3352 const Handle(IntTools_Context)& aContext)
4f189102 3353{
7fd59977 3354 Standard_Integer aResult = 0;
3355 if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) )
3356 return aResult;
3357
7fd59977 3358
3359 TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2;
3360 TColStd_SequenceOfReal aSeqResultRad;
3361
3362 gp_Torus aTor1 = theSurface1->Torus();
3363 gp_Torus aTor2 = theSurface2->Torus();
3364
3365 gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() );
3366 gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() );
3367 Standard_Integer j = 0;
3368
3369 for ( j = 0; j < 2; j++ ) {
3370 Standard_Real aCoef = ( j == 0 ) ? -1 : 1;
3371 Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius());
3372 Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius());
3373
3374 gp_Circ aCircle1( anax1, aRadius1 );
3375 gp_Circ aCircle2( anax2, aRadius2 );
3376
3377 // roughly compute radius of tangent zone for perpendicular case
3378 Standard_Real aCriteria = Precision::Confusion() * 0.5;