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