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