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