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