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