0022492: Scaled sphere (Solid with BSplineSurface) is wrongly exported in STEP.
[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) ||
d10203e8
P
824 //modified by NIZNHY-PKV Mon Sep 12 09:32:44 2011f
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 }
915 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
916 //modified by NIZNHY-PKV Mon Sep 12 09:32:46 2011t
7fd59977 917}
918//=======================================================================
919//function : MakeCurve
920//purpose :
921//=======================================================================
922 void IntTools_FaceFace::MakeCurve(const Standard_Integer Index,
923 const Handle(Adaptor3d_TopolTool)& dom1,
924 const Handle(Adaptor3d_TopolTool)& dom2)
925{
926 Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor;
927 Standard_Boolean ok;
928 Standard_Integer i, j, aNbParts;
929 Standard_Real fprm, lprm;
930 Standard_Real Tolpc;
931 Handle(IntPatch_Line) L;
932 IntPatch_IType typl;
933 Handle(Geom_Curve) newc;
934 //
935 const Standard_Real TOLCHECK =0.0000001;
936 const Standard_Real TOLANGCHECK=0.1;
937 //
938 rejectSurface = Standard_False;
939 reApprox = Standard_False;
940
941 reapprox:;
942
943 Tolpc = myTolApprox;
944 bAvoidLineConstructor = Standard_False;
945 L = myIntersector.Line(Index);
946 typl = L->ArcType();
947 //
948 if(typl==IntPatch_Walking) {
949 Handle(IntPatch_Line) anewL;
950 //
951 const Handle(IntPatch_WLine)& aWLine=
952 Handle(IntPatch_WLine)::DownCast(L);
953 //
954 anewL = ComputePurgedWLine(aWLine);
955 if(anewL.IsNull()) {
956 return;
957 }
958 L = anewL;
959 //
960 if(!myListOfPnts.IsEmpty()) {
961 bAvoidLineConstructor = Standard_True;
962 }
963
964 Standard_Integer nbp = aWLine->NbPnts();
965 const IntSurf_PntOn2S& p1 = aWLine->Point(1);
966 const IntSurf_PntOn2S& p2 = aWLine->Point(nbp);
967
968 const gp_Pnt& P1 = p1.Value();
969 const gp_Pnt& P2 = p2.Value();
970
971 if(P1.SquareDistance(P2) < 1.e-14) {
972 bAvoidLineConstructor = Standard_False;
973 }
974
975 }
976 //
977 // Line Constructor
978 if(!bAvoidLineConstructor) {
979 myLConstruct.Perform(L);
980 //
981 bDone=myLConstruct.IsDone();
982 aNbParts=myLConstruct.NbParts();
983 if (!bDone|| !aNbParts) {
984 return;
985 }
986 }
987 // Do the Curve
988
989
990 typl=L->ArcType();
991 switch (typl) {
992 //########################################
993 // Line, Parabola, Hyperbola
994 //########################################
995 case IntPatch_Lin:
996 case IntPatch_Parabola:
997 case IntPatch_Hyperbola: {
998 if (typl == IntPatch_Lin) {
999 newc =
1000 new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
1001 }
1002
1003 else if (typl == IntPatch_Parabola) {
1004 newc =
1005 new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
1006 }
1007
1008 else if (typl == IntPatch_Hyperbola) {
1009 newc =
1010 new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
1011 }
1012 //
1013 // myTolReached3d
1014 if (typl == IntPatch_Lin) {
1015 TolR3d (myFace1, myFace2, myTolReached3d);
1016 }
1017 //
1018 aNbParts=myLConstruct.NbParts();
1019 for (i=1; i<=aNbParts; i++) {
1020 myLConstruct.Part(i, fprm, lprm);
1021
1022 if (!Precision::IsNegativeInfinite(fprm) &&
1023 !Precision::IsPositiveInfinite(lprm)) {
1024 //
1025 IntTools_Curve aCurve;
1026 //
1027 Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
1028 aCurve.SetCurve(aCT3D);
1029 if (typl == IntPatch_Parabola) {
1030 Standard_Real aTolF1, aTolF2, aTolBase;
1031
1032 aTolF1 = BRep_Tool::Tolerance(myFace1);
1033 aTolF2 = BRep_Tool::Tolerance(myFace2);
1034 aTolBase=aTolF1+aTolF2;
1035 myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
1036 }
1037 //
1038 aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
1039 if(myApprox1) {
1040 Handle (Geom2d_Curve) C2d;
1041 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1042 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1043 myTolReached2d=Tolpc;
1044 }
1045 //
1046 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1047 }
1048 else {
1049 Handle(Geom2d_BSplineCurve) H1;
1050 //
1051 aCurve.SetFirstCurve2d(H1);
1052 }
1053
1054 if(myApprox2) {
1055 Handle (Geom2d_Curve) C2d;
1056 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1057 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1058 myTolReached2d=Tolpc;
1059 }
1060 //
1061 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1062 }
1063 else {
1064 Handle(Geom2d_BSplineCurve) H1;
1065 //
1066 aCurve.SetSecondCurve2d(H1);
1067 }
1068 mySeqOfCurve.Append(aCurve);
1069 } // end of if (!Precision::IsNegativeInfinite(fprm) && !Precision::IsPositiveInfinite(lprm))
1070
1071 else {
0fc4f2e2 1072 // on regarde si on garde
7fd59977 1073 //
1074 Standard_Boolean bFNIt, bLPIt;
1075 Standard_Real aTestPrm, dT=100.;
1076
1077 bFNIt=Precision::IsNegativeInfinite(fprm);
1078 bLPIt=Precision::IsPositiveInfinite(lprm);
1079
1080 aTestPrm=0.;
1081
1082 if (bFNIt && !bLPIt) {
1083 aTestPrm=lprm-dT;
1084 }
1085 else if (!bFNIt && bLPIt) {
1086 aTestPrm=fprm+dT;
1087 }
1088
1089 gp_Pnt ptref(newc->Value(aTestPrm));
1090 //
1091
1092 Standard_Real u1, v1, u2, v2, Tol;
1093
1094 Tol = Precision::Confusion();
1095 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1096 ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
1097 if(ok) {
1098 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1099 }
1100 if (ok) {
1101 Handle(Geom2d_BSplineCurve) H1;
1102 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1103 }
1104 }
1105 }// end of for (i=1; i<=myLConstruct.NbParts(); i++)
1106 }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola:
1107 break;
1108
1109 //########################################
1110 // Circle and Ellipse
1111 //########################################
1112 case IntPatch_Circle:
1113 case IntPatch_Ellipse: {
1114
1115 if (typl == IntPatch_Circle) {
1116 newc = new Geom_Circle
1117 (Handle(IntPatch_GLine)::DownCast(L)->Circle());
1118 }
1119 else { //IntPatch_Ellipse
1120 newc = new Geom_Ellipse
1121 (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
1122 }
1123 //
1124 // myTolReached3d
1125 TolR3d (myFace1, myFace2, myTolReached3d);
1126 //
1127 aNbParts=myLConstruct.NbParts();
1128 //
1129 Standard_Real aPeriod, aNul;
1130 TColStd_SequenceOfReal aSeqFprm, aSeqLprm;
1131
1132 aNul=0.;
1133 aPeriod=PI+PI;
1134
1135 for (i=1; i<=aNbParts; i++) {
1136 myLConstruct.Part(i, fprm, lprm);
1137
1138 if (fprm < aNul && lprm > aNul) {
1139 // interval that goes through 0. is divided on two intervals;
1140 while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
1141 while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
1142 //
1143 if((aPeriod - fprm) > Tolpc) {
1144 aSeqFprm.Append(fprm);
1145 aSeqLprm.Append(aPeriod);
1146 }
1147 else {
1148 gp_Pnt P1 = newc->Value(fprm);
1149 gp_Pnt P2 = newc->Value(aPeriod);
1150 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1151 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1152
1153 if(P1.Distance(P2) > aTolDist) {
1154 Standard_Real anewpar = fprm;
1155
1156 if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2, lprm, Standard_False, anewpar)) {
1157 fprm = anewpar;
1158 }
1159 aSeqFprm.Append(fprm);
1160 aSeqLprm.Append(aPeriod);
1161 }
1162 }
1163
1164 //
1165 if((lprm - aNul) > Tolpc) {
1166 aSeqFprm.Append(aNul);
1167 aSeqLprm.Append(lprm);
1168 }
1169 else {
1170 gp_Pnt P1 = newc->Value(aNul);
1171 gp_Pnt P2 = newc->Value(lprm);
1172 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1173 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1174
1175 if(P1.Distance(P2) > aTolDist) {
1176 Standard_Real anewpar = lprm;
1177
1178 if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2, fprm, Standard_True, anewpar)) {
1179 lprm = anewpar;
1180 }
1181 aSeqFprm.Append(aNul);
1182 aSeqLprm.Append(lprm);
1183 }
1184 }
1185 }
1186 else {
1187 // usual interval
1188 aSeqFprm.Append(fprm);
1189 aSeqLprm.Append(lprm);
1190 }
1191 }
1192
1193 //
1194 aNbParts=aSeqFprm.Length();
1195 for (i=1; i<=aNbParts; i++) {
1196 fprm=aSeqFprm(i);
1197 lprm=aSeqLprm(i);
1198 //
1199 Standard_Real aRealEpsilon=RealEpsilon();
1200 if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*PI) > aRealEpsilon) {
1201 //==============================================
1202 ////
1203 IntTools_Curve aCurve;
1204 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1205 aCurve.SetCurve(aTC3D);
1206 fprm=aTC3D->FirstParameter();
1207 lprm=aTC3D->LastParameter ();
1208 ////
1209 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {////
1210 if(myApprox1) {
1211 Handle (Geom2d_Curve) C2d;
1212 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1213 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1214 myTolReached2d=Tolpc;
1215 }
1216 //
1217 aCurve.SetFirstCurve2d(C2d);
1218 }
1219 else { ////
1220 Handle(Geom2d_BSplineCurve) H1;
1221 aCurve.SetFirstCurve2d(H1);
1222 }
1223
1224
1225 if(myApprox2) {
1226 Handle (Geom2d_Curve) C2d;
1227 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1228 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1229 myTolReached2d=Tolpc;
1230 }
1231 //
1232 aCurve.SetSecondCurve2d(C2d);
1233 }
1234 else {
1235 Handle(Geom2d_BSplineCurve) H1;
1236 aCurve.SetSecondCurve2d(H1);
1237 }
1238 }
1239
1240 else {
1241 Handle(Geom2d_BSplineCurve) H1;
1242 aCurve.SetFirstCurve2d(H1);
1243 aCurve.SetSecondCurve2d(H1);
1244 }
1245 mySeqOfCurve.Append(aCurve);
1246 //==============================================
1247 } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*PI) > RealEpsilon())
1248
1249 else {
1250 // on regarde si on garde
1251 //
1252 if (aNbParts==1) {
1253// if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*PI) < RealEpsilon()) {
1254 if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*PI) <= aRealEpsilon) {
1255 IntTools_Curve aCurve;
1256 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1257 aCurve.SetCurve(aTC3D);
1258 fprm=aTC3D->FirstParameter();
1259 lprm=aTC3D->LastParameter ();
1260
1261 if(myApprox1) {
1262 Handle (Geom2d_Curve) C2d;
1263 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1264 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1265 myTolReached2d=Tolpc;
1266 }
1267 //
1268 aCurve.SetFirstCurve2d(C2d);
1269 }
1270 else { ////
1271 Handle(Geom2d_BSplineCurve) H1;
1272 aCurve.SetFirstCurve2d(H1);
1273 }
1274
1275 if(myApprox2) {
1276 Handle (Geom2d_Curve) C2d;
1277 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1278 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1279 myTolReached2d=Tolpc;
1280 }
1281 //
1282 aCurve.SetSecondCurve2d(C2d);
1283 }
1284 else {
1285 Handle(Geom2d_BSplineCurve) H1;
1286 aCurve.SetSecondCurve2d(H1);
1287 }
1288 mySeqOfCurve.Append(aCurve);
1289 break;
1290 }
1291 }
1292 //
1293 Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
1294
1295 aTwoPIdiv17=2.*PI/17.;
1296
1297 for (j=0; j<=17; j++) {
1298 gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
1299 Tol = Precision::Confusion();
1300
1301 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1302 ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
1303 if(ok) {
1304 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1305 }
1306 if (ok) {
1307 IntTools_Curve aCurve;
1308 aCurve.SetCurve(newc);
1309 //==============================================
1310 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
1311
1312 if(myApprox1) {
1313 Handle (Geom2d_Curve) C2d;
1314 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1315 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1316 myTolReached2d=Tolpc;
1317 }
1318 //
1319 aCurve.SetFirstCurve2d(C2d);
1320 }
1321 else {
1322 Handle(Geom2d_BSplineCurve) H1;
1323 aCurve.SetFirstCurve2d(H1);
1324 }
1325
1326 if(myApprox2) {
1327 Handle (Geom2d_Curve) C2d;
1328 BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
1329 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1330 myTolReached2d=Tolpc;
1331 }
1332 //
1333 aCurve.SetSecondCurve2d(C2d);
1334 }
1335
1336 else {
1337 Handle(Geom2d_BSplineCurve) H1;
1338 aCurve.SetSecondCurve2d(H1);
1339 }
1340 }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
1341
1342 else {
1343 Handle(Geom2d_BSplineCurve) H1;
1344 //
1345 aCurve.SetFirstCurve2d(H1);
1346 aCurve.SetSecondCurve2d(H1);
1347 }
1348 //==============================================
1349 //
1350 mySeqOfCurve.Append(aCurve);
1351 break;
1352
1353 }// end of if (ok) {
1354 }// end of for (Standard_Integer j=0; j<=17; j++)
0fc4f2e2 1355 }// end of else { on regarde si on garde
7fd59977 1356 }// for (i=1; i<=myLConstruct.NbParts(); i++)
1357 }// IntPatch_Circle: IntPatch_Ellipse:
1358 break;
1359
1360 case IntPatch_Analytic: {
1361 IntSurf_Quadric quad1,quad2;
1362 GeomAbs_SurfaceType typs = myHS1->Surface().GetType();
1363
1364 switch (typs) {
1365 case GeomAbs_Plane:
1366 quad1.SetValue(myHS1->Surface().Plane());
1367 break;
1368 case GeomAbs_Cylinder:
1369 quad1.SetValue(myHS1->Surface().Cylinder());
1370 break;
1371 case GeomAbs_Cone:
1372 quad1.SetValue(myHS1->Surface().Cone());
1373 break;
1374 case GeomAbs_Sphere:
1375 quad1.SetValue(myHS1->Surface().Sphere());
1376 break;
1377 default:
1378 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
1379 }
1380
1381 typs = myHS2->Surface().GetType();
1382
1383 switch (typs) {
1384 case GeomAbs_Plane:
1385 quad2.SetValue(myHS2->Surface().Plane());
1386 break;
1387 case GeomAbs_Cylinder:
1388 quad2.SetValue(myHS2->Surface().Cylinder());
1389 break;
1390 case GeomAbs_Cone:
1391 quad2.SetValue(myHS2->Surface().Cone());
1392 break;
1393 case GeomAbs_Sphere:
1394 quad2.SetValue(myHS2->Surface().Sphere());
1395 break;
1396 default:
1397 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
1398 }
1399 //
1400 //=========
1401 IntPatch_ALineToWLine convert (quad1, quad2);
1402
1403 if (!myApprox) {
1404 aNbParts=myLConstruct.NbParts();
1405 for (i=1; i<=aNbParts; i++) {
1406 myLConstruct.Part(i, fprm, lprm);
1407 Handle(IntPatch_WLine) WL =
1408 convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
1409 //
1410 Handle(Geom2d_BSplineCurve) H1;
1411 Handle(Geom2d_BSplineCurve) H2;
1412
1413 if(myApprox1) {
1414 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1415 }
1416
1417 if(myApprox2) {
1418 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1419 }
1420 //
1421 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1422 }
1423 } // if (!myApprox)
1424
1425 else { // myApprox=TRUE
1426 GeomInt_WLApprox theapp3d;
1427 //
1428 Standard_Real tol2d = myTolApprox;
1429 //
1430 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
1431
1432 aNbParts=myLConstruct.NbParts();
1433 for (i=1; i<=aNbParts; i++) {
1434 myLConstruct.Part(i, fprm, lprm);
1435 Handle(IntPatch_WLine) WL =
1436 convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
1437
1438 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
1439
1440 if (!theapp3d.IsDone()) {
1441 //
1442 Handle(Geom2d_BSplineCurve) H1;
1443 Handle(Geom2d_BSplineCurve) H2;
1444
1445 if(myApprox1) {
1446 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1447 }
1448
1449 if(myApprox2) {
1450 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1451 }
1452 //
1453 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1454 }
1455
1456 else {
1457 if(myApprox1 || myApprox2) {
1458 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
1459 myTolReached2d = theapp3d.TolReached2d();
1460 }
1461 }
1462
1463 if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
1464 myTolReached3d = theapp3d.TolReached3d();
1465 }
1466
1467 Standard_Integer aNbMultiCurves, nbpoles;
1468 aNbMultiCurves=theapp3d.NbMultiCurves();
1469 for (j=1; j<=aNbMultiCurves; j++) {
1470 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1471 nbpoles = mbspc.NbPoles();
1472
1473 TColgp_Array1OfPnt tpoles(1, nbpoles);
1474 mbspc.Curve(1, tpoles);
1475 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1476 mbspc.Knots(),
1477 mbspc.Multiplicities(),
1478 mbspc.Degree());
1479
1480 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1481 Check.FixTangent(Standard_True,Standard_True);
1482 //
1483 IntTools_Curve aCurve;
1484 aCurve.SetCurve(BS);
1485
1486 if(myApprox1) {
1487 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1488 mbspc.Curve(2,tpoles2d);
1489 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1490 mbspc.Knots(),
1491 mbspc.Multiplicities(),
1492 mbspc.Degree());
1493
1494 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1495 newCheck.FixTangent(Standard_True,Standard_True);
1496 //
1497 aCurve.SetFirstCurve2d(BS2);
1498 }
1499 else {
1500 Handle(Geom2d_BSplineCurve) H1;
1501 aCurve.SetFirstCurve2d(H1);
1502 }
1503
1504 if(myApprox2) {
1505 TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
1506 Standard_Integer TwoOrThree;
1507 TwoOrThree=myApprox1 ? 3 : 2;
1508 mbspc.Curve(TwoOrThree, tpoles2d);
1509 Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
1510 mbspc.Knots(),
1511 mbspc.Multiplicities(),
1512 mbspc.Degree());
1513
1514 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1515 newCheck.FixTangent(Standard_True,Standard_True);
1516 //
1517 aCurve.SetSecondCurve2d(BS2);
1518 }
1519 else {
1520 Handle(Geom2d_BSplineCurve) H2;
1521 aCurve.SetSecondCurve2d(H2);
1522 }
1523 //
1524 mySeqOfCurve.Append(aCurve);
1525
1526 }// for (j=1; j<=aNbMultiCurves; j++) {
1527 }// else from if (!theapp3d.IsDone())
1528 }// for (i=1; i<=aNbParts; i++) {
1529 }// else { // myApprox=TRUE
1530 }// case IntPatch_Analytic:
1531 break;
1532
1533 case IntPatch_Walking:{
1534 Handle(IntPatch_WLine) WL =
1535 Handle(IntPatch_WLine)::DownCast(L);
1536 //
1537 Standard_Integer ifprm, ilprm;
1538 //
1539 if (!myApprox) {
1540 aNbParts = 1;
1541 if(!bAvoidLineConstructor){
1542 aNbParts=myLConstruct.NbParts();
1543 }
1544 for (i=1; i<=aNbParts; ++i) {
1545 Handle(Geom2d_BSplineCurve) H1, H2;
1546 Handle(Geom_Curve) aBSp;
1547 //
1548 if(bAvoidLineConstructor) {
1549 ifprm = 1;
1550 ilprm = WL->NbPnts();
1551 }
1552 else {
1553 myLConstruct.Part(i, fprm, lprm);
1554 ifprm=(Standard_Integer)fprm;
1555 ilprm=(Standard_Integer)lprm;
1556 }
1557 //
1558 if(myApprox1) {
1559 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1560 }
1561 //
1562 if(myApprox2) {
1563 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1564 }
1565 //
1566 aBSp=MakeBSpline(WL, ifprm, ilprm);
1567 IntTools_Curve aIC(aBSp, H1, H2);
1568 mySeqOfCurve.Append(aIC);
1569 }// for (i=1; i<=aNbParts; ++i) {
1570 }// if (!myApprox) {
1571 //
1572 else { // X
1573 Standard_Boolean bIsDecomposited;
1574 Standard_Integer nbiter, aNbSeqOfL;
1575 Standard_Real tol2d;
1576 IntPatch_SequenceOfLine aSeqOfL;
1577 GeomInt_WLApprox theapp3d;
1578 Approx_ParametrizationType aParType = Approx_ChordLength;
1579 //
1580 Standard_Boolean anApprox1 = myApprox1;
1581 Standard_Boolean anApprox2 = myApprox2;
1582
1583 tol2d = myTolApprox;
1584
1585 GeomAbs_SurfaceType typs1, typs2;
1586 typs1 = myHS1->Surface().GetType();
1587 typs2 = myHS2->Surface().GetType();
1588 Standard_Boolean anWithPC = Standard_True;
1589
1590 if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
1591 anWithPC =
1592 ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
1593 }
1594 else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
1595 anWithPC =
1596 ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
1597 }
1598 if(!anWithPC) {
1599 //aParType = Approx_Centripetal;
1600 myTolApprox = 1.e-5;
1601 anApprox1 = Standard_False;
1602 anApprox2 = Standard_False;
1603 //
1604 tol2d = myTolApprox;
1605 }
1606
1607 if(myHS1 == myHS2) {
1608 //
1609 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1610 rejectSurface = Standard_True;
1611 }
1612 else {
1613 if(reApprox && !rejectSurface)
1614 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1615 else {
0fc4f2e2 1616 Standard_Integer iDegMax, iDegMin;
7fd59977 1617 //
0fc4f2e2
P
1618 ApproxParameters(myHS1, myHS2, iDegMin, iDegMax);
1619 theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, 0, Standard_True, aParType);
7fd59977 1620 }
1621 }
1622 //
1623 Standard_Real aReachedTol = Precision::Confusion();
1624 bIsDecomposited=DecompositionOfWLine(WL,
1625 myHS1,
1626 myHS2,
1627 myFace1,
1628 myFace2,
1629 myLConstruct,
1630 bAvoidLineConstructor,
1631 aSeqOfL,
1632 aReachedTol);
1633 if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) )
1634 myTolReached3d = aReachedTol;
1635
1636 //
1637 aNbSeqOfL=aSeqOfL.Length();
1638 //
1639 if (bIsDecomposited) {
1640 nbiter=aNbSeqOfL;
1641 }
1642 else {
1643 nbiter=1;
1644 aNbParts=1;
1645 if (!bAvoidLineConstructor) {
1646 aNbParts=myLConstruct.NbParts();
1647 nbiter=aNbParts;
1648 }
1649 }
1650 //
1651 // nbiter=(bIsDecomposited) ? aSeqOfL.Length() :
1652 // ((bAvoidLineConstructor) ? 1 :aNbParts);
1653 //
1654 for(i = 1; i <= nbiter; ++i) {
1655 if(bIsDecomposited) {
1656 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
1657 ifprm = 1;
1658 ilprm = WL->NbPnts();
1659 }
1660 else {
1661 if(bAvoidLineConstructor) {
1662 ifprm = 1;
1663 ilprm = WL->NbPnts();
1664 }
1665 else {
1666 myLConstruct.Part(i, fprm, lprm);
1667 ifprm = (Standard_Integer)fprm;
1668 ilprm = (Standard_Integer)lprm;
1669 }
1670 }
0fc4f2e2
P
1671 //-- lbr :
1672 //-- Si une des surfaces est un plan , on approxime en 2d
1673 //-- sur cette surface et on remonte les points 2d en 3d.
7fd59977 1674 if(typs1 == GeomAbs_Plane) {
1675 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
1676 }
1677 else if(typs2 == GeomAbs_Plane) {
1678 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
1679 }
1680 else {
1681 //
1682 if (myHS1 != myHS2){
1683 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
1684 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
1685
1686 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
1687
1688 Standard_Boolean bUseSurfaces;
1689 bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
1690 if (bUseSurfaces) {
1691 // ######
1692 rejectSurface = Standard_True;
1693 // ######
1694 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1695 }
1696 }
1697 }
1698 //
1699 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
1700 }
1701
1702 if (!theapp3d.IsDone()) {
1703 //
1704 Handle(Geom2d_BSplineCurve) H1;
1705 //
1706 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
1707 Handle(Geom2d_BSplineCurve) H2;
1708
1709 if(myApprox1) {
1710 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1711 }
1712
1713 if(myApprox2) {
1714 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1715 }
1716 //
1717 IntTools_Curve aIC(aBSp, H1, H2);
1718 mySeqOfCurve.Append(aIC);
1719 }
1720
1721 else {
1722 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
1723 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
1724 myTolReached2d = theapp3d.TolReached2d();
1725 }
1726 }
1727 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
1728 myTolReached3d = myTolReached2d;
1729 //
1730 if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
1731 if (myTolReached3d<1.e-6) {
1732 myTolReached3d = theapp3d.TolReached3d();
1733 myTolReached3d=1.e-6;
1734 }
1735 }
1736 //
1737 }
1738 else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
1739 myTolReached3d = theapp3d.TolReached3d();
1740 }
1741
1742 Standard_Integer aNbMultiCurves, nbpoles;
1743 aNbMultiCurves=theapp3d.NbMultiCurves();
1744 for (j=1; j<=aNbMultiCurves; j++) {
1745 if(typs1 == GeomAbs_Plane) {
1746 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1747 nbpoles = mbspc.NbPoles();
1748
1749 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1750 TColgp_Array1OfPnt tpoles(1,nbpoles);
1751
1752 mbspc.Curve(1,tpoles2d);
1753 const gp_Pln& Pln = myHS1->Surface().Plane();
1754 //
1755 Standard_Integer ik;
1756 for(ik = 1; ik<= nbpoles; ik++) {
1757 tpoles.SetValue(ik,
1758 ElSLib::Value(tpoles2d.Value(ik).X(),
1759 tpoles2d.Value(ik).Y(),
1760 Pln));
1761 }
1762 //
1763 Handle(Geom_BSplineCurve) BS =
1764 new Geom_BSplineCurve(tpoles,
1765 mbspc.Knots(),
1766 mbspc.Multiplicities(),
1767 mbspc.Degree());
1768 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1769 Check.FixTangent(Standard_True, Standard_True);
1770 //
1771 IntTools_Curve aCurve;
1772 aCurve.SetCurve(BS);
1773
1774 if(myApprox1) {
1775 Handle(Geom2d_BSplineCurve) BS1 =
1776 new Geom2d_BSplineCurve(tpoles2d,
1777 mbspc.Knots(),
1778 mbspc.Multiplicities(),
1779 mbspc.Degree());
1780 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
1781 Check1.FixTangent(Standard_True,Standard_True);
1782 //
1783 // ############################################
1784 if(!rejectSurface && !reApprox) {
1785 Standard_Boolean isValid = IsCurveValid(BS1);
1786 if(!isValid) {
1787 reApprox = Standard_True;
1788 goto reapprox;
1789 }
1790 }
1791 // ############################################
1792 aCurve.SetFirstCurve2d(BS1);
1793 }
1794 else {
1795 Handle(Geom2d_BSplineCurve) H1;
1796 aCurve.SetFirstCurve2d(H1);
1797 }
1798
1799 if(myApprox2) {
1800 mbspc.Curve(2, tpoles2d);
1801
1802 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
1803 mbspc.Knots(),
1804 mbspc.Multiplicities(),
1805 mbspc.Degree());
1806 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1807 newCheck.FixTangent(Standard_True,Standard_True);
1808
1809 // ###########################################
1810 if(!rejectSurface && !reApprox) {
1811 Standard_Boolean isValid = IsCurveValid(BS2);
1812 if(!isValid) {
1813 reApprox = Standard_True;
1814 goto reapprox;
1815 }
1816 }
1817 // ###########################################
1818 //
1819 aCurve.SetSecondCurve2d(BS2);
1820 }
1821 else {
1822 Handle(Geom2d_BSplineCurve) H2;
1823 //
1824 aCurve.SetSecondCurve2d(H2);
1825 }
1826 //
1827 mySeqOfCurve.Append(aCurve);
1828 }
1829
1830 else if(typs2 == GeomAbs_Plane) {
1831 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1832 nbpoles = mbspc.NbPoles();
1833
1834 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1835 TColgp_Array1OfPnt tpoles(1,nbpoles);
1836 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
1837 const gp_Pln& Pln = myHS2->Surface().Plane();
1838 //
1839 Standard_Integer ik;
1840 for(ik = 1; ik<= nbpoles; ik++) {
1841 tpoles.SetValue(ik,
1842 ElSLib::Value(tpoles2d.Value(ik).X(),
1843 tpoles2d.Value(ik).Y(),
1844 Pln));
1845
1846 }
1847 //
1848 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1849 mbspc.Knots(),
1850 mbspc.Multiplicities(),
1851 mbspc.Degree());
1852 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1853 Check.FixTangent(Standard_True,Standard_True);
1854 //
1855 IntTools_Curve aCurve;
1856 aCurve.SetCurve(BS);
1857
1858 if(myApprox2) {
1859 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
1860 mbspc.Knots(),
1861 mbspc.Multiplicities(),
1862 mbspc.Degree());
1863 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
1864 Check1.FixTangent(Standard_True,Standard_True);
1865 //
1866 // ###########################################
1867 if(!rejectSurface && !reApprox) {
1868 Standard_Boolean isValid = IsCurveValid(BS1);
1869 if(!isValid) {
1870 reApprox = Standard_True;
1871 goto reapprox;
1872 }
1873 }
1874 // ###########################################
1875 aCurve.SetSecondCurve2d(BS1);
1876 }
1877 else {
1878 Handle(Geom2d_BSplineCurve) H2;
1879 aCurve.SetSecondCurve2d(H2);
1880 }
1881
1882 if(myApprox1) {
1883 mbspc.Curve(1,tpoles2d);
1884 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1885 mbspc.Knots(),
1886 mbspc.Multiplicities(),
1887 mbspc.Degree());
1888 GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
1889 Check2.FixTangent(Standard_True,Standard_True);
1890 //
1891 // ###########################################
1892 if(!rejectSurface && !reApprox) {
1893 Standard_Boolean isValid = IsCurveValid(BS2);
1894 if(!isValid) {
1895 reApprox = Standard_True;
1896 goto reapprox;
1897 }
1898 }
1899 // ###########################################
1900 aCurve.SetFirstCurve2d(BS2);
1901 }
1902 else {
1903 Handle(Geom2d_BSplineCurve) H1;
1904 //
1905 aCurve.SetFirstCurve2d(H1);
1906 }
1907 //
1908 mySeqOfCurve.Append(aCurve);
1909 }
1910 else {
1911 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1912 nbpoles = mbspc.NbPoles();
1913 TColgp_Array1OfPnt tpoles(1,nbpoles);
1914 mbspc.Curve(1,tpoles);
1915 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1916 mbspc.Knots(),
1917 mbspc.Multiplicities(),
1918 mbspc.Degree());
1919 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1920 Check.FixTangent(Standard_True,Standard_True);
1921 //
1922 IntTools_Curve aCurve;
1923 aCurve.SetCurve(BS);
1924
1925 if(myApprox1) {
1926 if(anApprox1) {
1927 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1928 mbspc.Curve(2,tpoles2d);
1929 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
1930 mbspc.Knots(),
1931 mbspc.Multiplicities(),
1932 mbspc.Degree());
1933 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
1934 newCheck.FixTangent(Standard_True,Standard_True);
1935 //
1936 aCurve.SetFirstCurve2d(BS1);
1937 }
1938 else {
1939 Handle(Geom2d_BSplineCurve) BS1;
1940 fprm = BS->FirstParameter();
1941 lprm = BS->LastParameter();
1942
1943 Handle(Geom2d_Curve) C2d;
1944 Standard_Real aTol = myTolApprox;
1945 BuildPCurves(fprm, lprm, aTol, myHS1->ChangeSurface().Surface(), BS, C2d);
1946 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
1947 aCurve.SetFirstCurve2d(BS1);
1948 }
1949
1950 }
1951 else {
1952 Handle(Geom2d_BSplineCurve) H1;
1953 //
1954 aCurve.SetFirstCurve2d(H1);
1955 }
1956 if(myApprox2) {
1957 if(anApprox2) {
1958 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1959 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
1960 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1961 mbspc.Knots(),
1962 mbspc.Multiplicities(),
1963 mbspc.Degree());
1964 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1965 newCheck.FixTangent(Standard_True,Standard_True);
1966 //
1967 aCurve.SetSecondCurve2d(BS2);
1968 }
1969 else {
1970 Handle(Geom2d_BSplineCurve) BS2;
1971 fprm = BS->FirstParameter();
1972 lprm = BS->LastParameter();
1973
1974 Handle(Geom2d_Curve) C2d;
1975 Standard_Real aTol = myTolApprox;
1976 BuildPCurves(fprm, lprm, aTol, myHS2->ChangeSurface().Surface(), BS, C2d);
1977 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
1978 aCurve.SetSecondCurve2d(BS2);
1979 }
1980
1981 }
1982 else {
1983 Handle(Geom2d_BSplineCurve) H2;
1984 //
1985 aCurve.SetSecondCurve2d(H2);
1986 }
1987 //
1988 mySeqOfCurve.Append(aCurve);
1989 }
1990 }
1991 }
1992 }
1993 }// else { // X
1994 }// case IntPatch_Walking:{
1995 break;
1996
1997 case IntPatch_Restriction:
1998 break;
1999
2000 }
2001}
2002
2003//=======================================================================
2004//function : BuildPCurves
2005//purpose :
2006//=======================================================================
2007 void BuildPCurves (Standard_Real f,
2008 Standard_Real l,
2009 Standard_Real& Tol,
2010 const Handle (Geom_Surface)& S,
2011 const Handle (Geom_Curve)& C,
2012 Handle (Geom2d_Curve)& C2d)
2013{
2014
2015 Standard_Real umin,umax,vmin,vmax;
2016 //
2017
2018 if (C2d.IsNull()) {
2019
2020 // in class ProjLib_Function the range of parameters is shrank by 1.e-09
2021 if((l - f) > 2.e-09) {
2022 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2023 //
2024 if (C2d.IsNull()) {
2025 // proj. a circle that goes through the pole on a sphere to the sphere
2026 Tol=Tol+1.e-7;
2027 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2028 }
2029 }
2030 else {
2031 if((l - f) > Epsilon(Abs(f))) {
2032 GeomAPI_ProjectPointOnSurf aProjector1, aProjector2;
2033 gp_Pnt P1 = C->Value(f);
2034 gp_Pnt P2 = C->Value(l);
2035 aProjector1.Init(P1, S);
2036 aProjector2.Init(P2, S);
2037
2038 if(aProjector1.IsDone() && aProjector2.IsDone()) {
2039 Standard_Real U=0., V=0.;
2040 aProjector1.LowerDistanceParameters(U, V);
2041 gp_Pnt2d p1(U, V);
2042
2043 aProjector2.LowerDistanceParameters(U, V);
2044 gp_Pnt2d p2(U, V);
2045
2046 if(p1.Distance(p2) > gp::Resolution()) {
2047 TColgp_Array1OfPnt2d poles(1,2);
2048 TColStd_Array1OfReal knots(1,2);
2049 TColStd_Array1OfInteger mults(1,2);
2050 poles(1) = p1;
2051 poles(2) = p2;
2052 knots(1) = f;
2053 knots(2) = l;
2054 mults(1) = mults(2) = 2;
2055
2056 C2d = new Geom2d_BSplineCurve(poles,knots,mults,1);
2057
2058 // compute reached tolerance.begin
2059 gp_Pnt PMid = C->Value((f + l) * 0.5);
2060 aProjector1.Perform(PMid);
2061
2062 if(aProjector1.IsDone()) {
2063 aProjector1.LowerDistanceParameters(U, V);
2064 gp_Pnt2d pmidproj(U, V);
2065 gp_Pnt2d pmidcurve2d = C2d->Value((f + l) * 0.5);
2066 Standard_Real adist = pmidcurve2d.Distance(pmidproj);
2067 Tol = (adist > Tol) ? adist : Tol;
2068 }
2069 // compute reached tolerance.end
2070 }
2071 }
2072 }
2073 }
2074 //
2075 S->Bounds(umin, umax, vmin, vmax);
2076
2077 if (S->IsUPeriodic() && !C2d.IsNull()) {
0fc4f2e2 2078 // Recadre dans le domaine UV de la face
7fd59977 2079 Standard_Real period, U0, du, aEps;
2080
2081 du =0.0;
2082 aEps=Precision::PConfusion();
2083 period = S->UPeriod();
2084 gp_Pnt2d Pf = C2d->Value(f);
2085 U0=Pf.X();
2086 //
2087 gp_Pnt2d Pl = C2d->Value(l);
2088
2089 U0 = Min(Pl.X(), U0);
2090// while(U0-umin<aEps) {
2091 while(U0-umin<-aEps) {
2092 U0+=period;
2093 du+=period;
2094 }
2095 //
2096 while(U0-umax>aEps) {
2097 U0-=period;
2098 du-=period;
2099 }
2100 if (du != 0) {
2101 gp_Vec2d T1(du,0.);
2102 C2d->Translate(T1);
2103 }
2104 }
2105 }
2106 if (C2d.IsNull()) {
2107 BOPTColStd_Dump::PrintMessage("BuildPCurves()=> Echec ProjLib\n");
2108 }
2109}
2110
2111//=======================================================================
2112//function : Parameters
2113//purpose :
2114//=======================================================================
2115 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
2116 const Handle(GeomAdaptor_HSurface)& HS2,
2117 const gp_Pnt& Ptref,
2118 Standard_Real& U1,
2119 Standard_Real& V1,
2120 Standard_Real& U2,
2121 Standard_Real& V2)
2122{
2123
2124 IntSurf_Quadric quad1,quad2;
2125 GeomAbs_SurfaceType typs = HS1->Surface().GetType();
2126
2127 switch (typs) {
2128 case GeomAbs_Plane:
2129 quad1.SetValue(HS1->Surface().Plane());
2130 break;
2131 case GeomAbs_Cylinder:
2132 quad1.SetValue(HS1->Surface().Cylinder());
2133 break;
2134 case GeomAbs_Cone:
2135 quad1.SetValue(HS1->Surface().Cone());
2136 break;
2137 case GeomAbs_Sphere:
2138 quad1.SetValue(HS1->Surface().Sphere());
2139 break;
2140 default:
2141 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2142 }
2143
2144 typs = HS2->Surface().GetType();
2145 switch (typs) {
2146 case GeomAbs_Plane:
2147 quad2.SetValue(HS2->Surface().Plane());
2148 break;
2149 case GeomAbs_Cylinder:
2150 quad2.SetValue(HS2->Surface().Cylinder());
2151 break;
2152 case GeomAbs_Cone:
2153 quad2.SetValue(HS2->Surface().Cone());
2154 break;
2155 case GeomAbs_Sphere:
2156 quad2.SetValue(HS2->Surface().Sphere());
2157 break;
2158 default:
2159 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2160 }
2161
2162 quad1.Parameters(Ptref,U1,V1);
2163 quad2.Parameters(Ptref,U2,V2);
2164}
2165
2166//=======================================================================
2167//function : MakeBSpline
2168//purpose :
2169//=======================================================================
2170Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
2171 const Standard_Integer ideb,
2172 const Standard_Integer ifin)
2173{
2174 Standard_Integer i,nbpnt = ifin-ideb+1;
2175 TColgp_Array1OfPnt poles(1,nbpnt);
2176 TColStd_Array1OfReal knots(1,nbpnt);
2177 TColStd_Array1OfInteger mults(1,nbpnt);
2178 Standard_Integer ipidebm1;
2179 for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) {
2180 poles(i) = WL->Point(ipidebm1).Value();
2181 mults(i) = 1;
2182 knots(i) = i-1;
2183 }
2184 mults(1) = mults(nbpnt) = 2;
2185 return
2186 new Geom_BSplineCurve(poles,knots,mults,1);
2187}
2188//
2189
2190//=======================================================================
2191//function : MakeBSpline2d
2192//purpose :
2193//=======================================================================
2194Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
2195 const Standard_Integer ideb,
2196 const Standard_Integer ifin,
2197 const Standard_Boolean onFirst)
2198{
2199 Standard_Integer i, nbpnt = ifin-ideb+1;
2200 TColgp_Array1OfPnt2d poles(1,nbpnt);
2201 TColStd_Array1OfReal knots(1,nbpnt);
2202 TColStd_Array1OfInteger mults(1,nbpnt);
2203 Standard_Integer ipidebm1;
2204
2205 for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
2206 Standard_Real U, V;
2207 if(onFirst)
2208 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
2209 else
2210 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
2211 poles(i).SetCoord(U, V);
2212 mults(i) = 1;
2213 knots(i) = i-1;
2214 }
2215 mults(1) = mults(nbpnt) = 2;
2216
2217 return new Geom2d_BSplineCurve(poles,knots,mults,1);
2218}
2219//=======================================================================
2220//function : PrepareLines3D
2221//purpose :
2222//=======================================================================
2223 void IntTools_FaceFace::PrepareLines3D()
2224{
2225 Standard_Integer i, aNbCurves, j, aNbNewCurves;
2226 IntTools_SequenceOfCurves aNewCvs;
2227
2228 //
0fc4f2e2 2229 // 1. Treatment of periodic and closed curves
7fd59977 2230 aNbCurves=mySeqOfCurve.Length();
2231 for (i=1; i<=aNbCurves; i++) {
2232 const IntTools_Curve& aIC=mySeqOfCurve(i);
2233 // DEBUG
2234 // const Handle(Geom_Curve)& aC3D =aIC.Curve();
2235 // const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
2236 // const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
2237 //
2238 IntTools_SequenceOfCurves aSeqCvs;
2239 aNbNewCurves=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
2240
2241 if (aNbNewCurves) {
2242 for (j=1; j<=aNbNewCurves; j++) {
2243 const IntTools_Curve& aICNew=aSeqCvs(j);
2244 aNewCvs.Append(aICNew);
2245 }
2246 }
2247 //
2248 else {
2249 aNewCvs.Append(aIC);
2250 }
2251 }
2252 //
2253 // 2. Plane\Cone intersection when we had 4 curves
2254 GeomAbs_SurfaceType aType1, aType2;
2255 BRepAdaptor_Surface aBS1, aBS2;
2256
2257 aBS1.Initialize(myFace1);
2258 aType1=aBS1.GetType();
2259
2260 aBS2.Initialize(myFace2);
2261 aType2=aBS2.GetType();
2262
2263 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) ||
2264 (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) {
2265 aNbCurves=aNewCvs.Length();
2266 if (aNbCurves==4) {
2267 GeomAbs_CurveType aCType1=aNewCvs(1).Type();
2268 if (aCType1==GeomAbs_Line) {
2269 IntTools_SequenceOfCurves aSeqIn, aSeqOut;
2270 //
2271 for (i=1; i<=aNbCurves; i++) {
2272 const IntTools_Curve& aIC=aNewCvs(i);
2273 aSeqIn.Append(aIC);
2274 }
2275 //
2276 IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
2277 //
2278 aNewCvs.Clear();
2279 aNbCurves=aSeqOut.Length();
2280 for (i=1; i<=aNbCurves; i++) {
2281 const IntTools_Curve& aIC=aSeqOut(i);
2282 aNewCvs.Append(aIC);
2283 }
2284 //
2285 }
2286 }
2287 }// end of if ((aType1==GeomAbs_Plane && ...
2288 //
2289 // 3. Fill mySeqOfCurve
2290 mySeqOfCurve.Clear();
2291 aNbCurves=aNewCvs.Length();
2292 for (i=1; i<=aNbCurves; i++) {
2293 const IntTools_Curve& aIC=aNewCvs(i);
2294 mySeqOfCurve.Append(aIC);
2295 }
2296
2297}
2298
2299
2300//=======================================================================
2301//function : CorrectSurfaceBoundaries
2302//purpose :
2303//=======================================================================
2304 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
2305 const Standard_Real theTolerance,
2306 Standard_Real& theumin,
2307 Standard_Real& theumax,
2308 Standard_Real& thevmin,
2309 Standard_Real& thevmax)
2310{
2311 Standard_Boolean enlarge, isuperiodic, isvperiodic;
2312 Standard_Real uinf, usup, vinf, vsup, delta;
2313 GeomAbs_SurfaceType aType;
2314 Handle(Geom_Surface) aSurface;
2315 //
2316 aSurface = BRep_Tool::Surface(theFace);
2317 aSurface->Bounds(uinf, usup, vinf, vsup);
2318 delta = theTolerance;
2319 enlarge = Standard_False;
2320 //
2321 GeomAdaptor_Surface anAdaptorSurface(aSurface);
2322 //
2323 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
2324 Handle(Geom_Surface) aBasisSurface =
2325 (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface();
2326
2327 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2328 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2329 return;
2330 }
2331 }
2332 //
2333 if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2334 Handle(Geom_Surface) aBasisSurface =
2335 (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface();
2336
2337 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2338 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2339 return;
2340 }
2341 }
2342 //
2343 isuperiodic = anAdaptorSurface.IsUPeriodic();
2344 isvperiodic = anAdaptorSurface.IsVPeriodic();
2345 //
2346 aType=anAdaptorSurface.GetType();
2347 if((aType==GeomAbs_BezierSurface) ||
2348 (aType==GeomAbs_BSplineSurface) ||
2349 (aType==GeomAbs_SurfaceOfExtrusion) ||
2350 (aType==GeomAbs_SurfaceOfRevolution)) {
2351 enlarge=Standard_True;
2352 }
2353 //
2354 if(!isuperiodic && enlarge) {
2355
2356 if((theumin - uinf) > delta )
2357 theumin -= delta;
2358 else {
2359 theumin = uinf;
2360 }
2361
2362 if((usup - theumax) > delta )
2363 theumax += delta;
2364 else
2365 theumax = usup;
2366 }
2367 //
2368 if(!isvperiodic && enlarge) {
2369 if((thevmin - vinf) > delta ) {
2370 thevmin -= delta;
2371 }
2372 else {
2373 thevmin = vinf;
2374 }
2375 if((vsup - thevmax) > delta ) {
2376 thevmax += delta;
2377 }
2378 else {
2379 thevmax = vsup;
2380 }
2381 }
2382 //
2383 {
2384 Standard_Integer aNbP;
2385 Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA;
2386 //
2387 aTolPA=Precision::Angular();
2388 // U
2389 if (isuperiodic) {
2390 aXP=anAdaptorSurface.UPeriod();
2391 dXfact=theumax-theumin;
2392 if (dXfact-aTolPA>aXP) {
2393 aXmid=0.5*(theumax+theumin);
2394 aNbP=RealToInt(aXmid/aXP);
2395 if (aXmid<0.) {
2396 aNbP=aNbP-1;
2397 }
2398 aX1=aNbP*aXP;
0fc4f2e2
P
2399 if (theumin>aTolPA) {
2400 aX1=theumin+aNbP*aXP;
2401 }
7fd59977 2402 aX2=aX1+aXP;
2403 if (theumin<aX1) {
2404 theumin=aX1;
2405 }
2406 if (theumax>aX2) {
2407 theumax=aX2;
2408 }
2409 }
2410 }
2411 // V
2412 if (isvperiodic) {
2413 aXP=anAdaptorSurface.VPeriod();
2414 dXfact=thevmax-thevmin;
2415 if (dXfact-aTolPA>aXP) {
2416 aXmid=0.5*(thevmax+thevmin);
2417 aNbP=RealToInt(aXmid/aXP);
2418 if (aXmid<0.) {
2419 aNbP=aNbP-1;
2420 }
2421 aX1=aNbP*aXP;
0fc4f2e2
P
2422 if (thevmin>aTolPA) {
2423 aX1=thevmin+aNbP*aXP;
2424 }
7fd59977 2425 aX2=aX1+aXP;
2426 if (thevmin<aX1) {
2427 thevmin=aX1;
2428 }
2429 if (thevmax>aX2) {
2430 thevmax=aX2;
2431 }
2432 }
2433 }
2434 }
2435 //
2436 if(isuperiodic || isvperiodic) {
2437 Standard_Boolean correct = Standard_False;
2438 Standard_Boolean correctU = Standard_False;
2439 Standard_Boolean correctV = Standard_False;
2440 Bnd_Box2d aBox;
2441 TopExp_Explorer anExp;
2442
2443 for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2444 if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
2445 correct = Standard_True;
2446 Standard_Real f, l;
2447 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
2448
2449 for(Standard_Integer i = 0; i < 2; i++) {
2450 if(i==0) {
2451 anEdge.Orientation(TopAbs_FORWARD);
2452 }
2453 else {
2454 anEdge.Orientation(TopAbs_REVERSED);
2455 }
2456 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
2457
2458 if(aCurve.IsNull()) {
2459 correct = Standard_False;
2460 break;
2461 }
2462 Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
2463
2464 if(aLine.IsNull()) {
2465 correct = Standard_False;
2466 break;
2467 }
2468 gp_Dir2d anUDir(1., 0.);
2469 gp_Dir2d aVDir(0., 1.);
2470 Standard_Real anAngularTolerance = Precision::Angular();
2471
2472 correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
2473 correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
2474
2475 gp_Pnt2d pp1 = aCurve->Value(f);
2476 aBox.Add(pp1);
2477 gp_Pnt2d pp2 = aCurve->Value(l);
2478 aBox.Add(pp2);
2479 }
2480 if(!correct)
2481 break;
2482 }
2483 }
2484
2485 if(correct) {
2486 Standard_Real umin, vmin, umax, vmax;
2487 aBox.Get(umin, vmin, umax, vmax);
2488
2489 if(isuperiodic && correctU) {
2490
2491 if(theumin < umin)
2492 theumin = umin;
2493
2494 if(theumax > umax) {
2495 theumax = umax;
2496 }
2497 }
2498 if(isvperiodic && correctV) {
2499
2500 if(thevmin < vmin)
2501 thevmin = vmin;
2502 if(thevmax > vmax)
2503 thevmax = vmax;
2504 }
2505 }
2506 }
2507}
2508//
2509//
2510// The block is dedicated to determine whether WLine [ifprm, ilprm]
2511// crosses the degenerated zone on each given surface or not.
2512// If Yes -> We will not use info about surfaces during approximation
2513// because inside degenerated zone of the surface the approx. alogo.
2514// uses wrong values of normal, etc., and resulting curve will have
2515// oscillations that we would not like to have.
2516// PKV Tue Feb 12 2002
2517
2518
2519static
2520 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2521 const Handle(Geom_Surface)& aS,
2522 const Standard_Integer iDir);
2523static
2524 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2525 const TopoDS_Face& aF1,
2526 const TopoDS_Face& aF2);
2527//=======================================================================
2528//function : NotUseSurfacesForApprox
2529//purpose :
2530//=======================================================================
2531Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
2532 const TopoDS_Face& aF2,
2533 const Handle(IntPatch_WLine)& WL,
2534 const Standard_Integer ifprm,
2535 const Standard_Integer ilprm)
2536{
2537 Standard_Boolean bPInDZ;
2538
2539 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
2540
2541 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
2542 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
2543 if (bPInDZ) {
2544 return bPInDZ;
2545 }
2546
2547 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
2548 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
2549
2550 return bPInDZ;
2551}
2552//=======================================================================
2553//function : IsPointInDegeneratedZone
2554//purpose :
2555//=======================================================================
2556Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2557 const TopoDS_Face& aF1,
2558 const TopoDS_Face& aF2)
2559
2560{
2561 Standard_Boolean bFlag=Standard_True;
2562 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
2563 Standard_Real U1, V1, U2, V2, aDelta, aD;
2564 gp_Pnt2d aP2d;
2565
2566 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
2567 aS1->Bounds(US11, US12, VS11, VS12);
2568 GeomAdaptor_Surface aGAS1(aS1);
2569
2570 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
2571 aS1->Bounds(US21, US22, VS21, VS22);
2572 GeomAdaptor_Surface aGAS2(aS2);
2573 //
2574 //const gp_Pnt& aP=aP2S.Value();
2575 aP2S.Parameters(U1, V1, U2, V2);
2576 //
2577 aDelta=1.e-7;
2578 // Check on Surf 1
2579 aD=aGAS1.UResolution(aDelta);
2580 aP2d.SetCoord(U1, V1);
2581 if (fabs(U1-US11) < aD) {
2582 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2583 if (bFlag) {
2584 return bFlag;
2585 }
2586 }
2587 if (fabs(U1-US12) < aD) {
2588 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2589 if (bFlag) {
2590 return bFlag;
2591 }
2592 }
2593 aD=aGAS1.VResolution(aDelta);
2594 if (fabs(V1-VS11) < aDelta) {
2595 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2596 if (bFlag) {
2597 return bFlag;
2598 }
2599 }
2600 if (fabs(V1-VS12) < aDelta) {
2601 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2602 if (bFlag) {
2603 return bFlag;
2604 }
2605 }
2606 // Check on Surf 2
2607 aD=aGAS2.UResolution(aDelta);
2608 aP2d.SetCoord(U2, V2);
2609 if (fabs(U2-US21) < aDelta) {
2610 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2611 if (bFlag) {
2612 return bFlag;
2613 }
2614 }
2615 if (fabs(U2-US22) < aDelta) {
2616 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2617 if (bFlag) {
2618 return bFlag;
2619 }
2620 }
2621 aD=aGAS2.VResolution(aDelta);
2622 if (fabs(V2-VS21) < aDelta) {
2623 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2624 if (bFlag) {
2625 return bFlag;
2626 }
2627 }
2628 if (fabs(V2-VS22) < aDelta) {
2629 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2630 if (bFlag) {
2631 return bFlag;
2632 }
2633 }
2634 return !bFlag;
2635}
2636
2637//=======================================================================
2638//function : IsDegeneratedZone
2639//purpose :
2640//=======================================================================
2641Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2642 const Handle(Geom_Surface)& aS,
2643 const Standard_Integer iDir)
2644{
2645 Standard_Boolean bFlag=Standard_True;
2646 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
2647 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
2648 aS->Bounds(US1, US2, VS1, VS2);
2649
2650 gp_Pnt aPm, aPb, aPe;
2651
2652 aXm=aP2d.X();
2653 aYm=aP2d.Y();
2654
2655 aS->D0(aXm, aYm, aPm);
2656
2657 dX=1.e-5;
2658 dY=1.e-5;
2659 dD=1.e-12;
2660
2661 if (iDir==1) {
2662 aXb=aXm;
2663 aXe=aXm;
2664 aYb=aYm-dY;
2665 if (aYb < VS1) {
2666 aYb=VS1;
2667 }
2668 aYe=aYm+dY;
2669 if (aYe > VS2) {
2670 aYe=VS2;
2671 }
2672 aS->D0(aXb, aYb, aPb);
2673 aS->D0(aXe, aYe, aPe);
2674
2675 d1=aPm.Distance(aPb);
2676 d2=aPm.Distance(aPe);
2677 if (d1 < dD && d2 < dD) {
2678 return bFlag;
2679 }
2680 return !bFlag;
2681 }
2682 //
2683 else if (iDir==2) {
2684 aYb=aYm;
2685 aYe=aYm;
2686 aXb=aXm-dX;
2687 if (aXb < US1) {
2688 aXb=US1;
2689 }
2690 aXe=aXm+dX;
2691 if (aXe > US2) {
2692 aXe=US2;
2693 }
2694 aS->D0(aXb, aYb, aPb);
2695 aS->D0(aXe, aYe, aPe);
2696
2697 d1=aPm.Distance(aPb);
2698 d2=aPm.Distance(aPe);
2699 if (d1 < dD && d2 < dD) {
2700 return bFlag;
2701 }
2702 return !bFlag;
2703 }
2704 return !bFlag;
2705}
2706
2707//=========================================================================
2708// static function : ComputePurgedWLine
2709// purpose : Removes equal points (leave one of equal points) from theWLine
2710// and recompute vertex parameters.
2711// Returns new WLine or null WLine if the number
2712// of the points is less than 2.
2713//=========================================================================
2714Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) {
2715 Handle(IntPatch_WLine) aResult;
2716 Handle(IntPatch_WLine) aLocalWLine;
2717 Handle(IntPatch_WLine) aTmpWLine = theWLine;
2718
2719 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
2720 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2721 Standard_Integer i, k, v, nb, nbvtx;
2722 nbvtx = theWLine->NbVertex();
2723 nb = theWLine->NbPnts();
2724
2725 for(i = 1; i <= nb; i++) {
2726 aLineOn2S->Add(theWLine->Point(i));
2727 }
2728
2729 for(v = 1; v <= nbvtx; v++) {
2730 aLocalWLine->AddVertex(theWLine->Vertex(v));
2731 }
2732
2733 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
2734 Standard_Integer aStartIndex = i + 1;
2735 Standard_Integer anEndIndex = i + 5;
2736 nb = aLineOn2S->NbPoints();
2737 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
2738
2739 if((aStartIndex >= nb) || (anEndIndex <= 1)) {
2740 continue;
2741 }
2742 k = aStartIndex;
2743
2744 while(k <= anEndIndex) {
2745
2746 if(i != k) {
2747 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
2748 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
2749
2750 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2751 aTmpWLine = aLocalWLine;
2752 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2753
2754 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
2755 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
2756 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
2757
2758 if(avertexindex >= k) {
2759 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
2760 }
2761 aLocalWLine->AddVertex(aVertex);
2762 }
2763 aLineOn2S->RemovePoint(k);
2764 anEndIndex--;
2765 continue;
2766 }
2767 }
2768 k++;
2769 }
2770 }
2771
2772 if(aLineOn2S->NbPoints() > 1) {
2773 aResult = aLocalWLine;
2774 }
2775 return aResult;
2776}
2777
2778//=======================================================================
2779//function : TolR3d
2780//purpose :
2781//=======================================================================
2782void TolR3d(const TopoDS_Face& aF1,
2783 const TopoDS_Face& aF2,
2784 Standard_Real& myTolReached3d)
2785{
2786 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
2787
2788 aTolTresh=2.999999e-3;
2789 aTolF1 = BRep_Tool::Tolerance(aF1);
2790 aTolF2 = BRep_Tool::Tolerance(aF2);
2791 aTolFMax=Max(aTolF1, aTolF2);
2792
2793 if (aTolFMax>aTolTresh) {
2794 myTolReached3d=aTolFMax;
2795 }
2796}
2797//=======================================================================
2798//function : AdjustPeriodic
2799//purpose :
2800//=======================================================================
2801Standard_Real AdjustPeriodic(const Standard_Real theParameter,
2802 const Standard_Real parmin,
2803 const Standard_Real parmax,
2804 const Standard_Real thePeriod,
2805 Standard_Real& theOffset)
2806{
2807 Standard_Real aresult;
2808 //
2809 theOffset = 0.;
2810 aresult = theParameter;
2811 while(aresult < parmin) {
2812 aresult += thePeriod;
2813 theOffset += thePeriod;
2814 }
2815
2816 while(aresult > parmax) {
2817 aresult -= thePeriod;
2818 theOffset -= thePeriod;
2819 }
2820 return aresult;
2821}
2822//=======================================================================
2823//function : IsPointOnBoundary
2824//purpose :
2825//=======================================================================
2826Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
2827 const Standard_Real theFirstBoundary,
2828 const Standard_Real theSecondBoundary,
2829 const Standard_Real theResolution,
2830 Standard_Boolean& IsOnFirstBoundary)
2831{
2832 Standard_Boolean bRet;
2833 Standard_Integer i;
2834 Standard_Real adist;
2835 //
2836 bRet=Standard_False;
2837 for(i = 0; i < 2; ++i) {
2838 IsOnFirstBoundary = (i == 0);
2839 if (IsOnFirstBoundary) {
2840 adist = fabs(theParameter - theFirstBoundary);
2841 }
2842 else {
2843 adist = fabs(theParameter - theSecondBoundary);
2844 }
2845 if(adist < theResolution) {
2846 return !bRet;
2847 }
2848 }
2849 return bRet;
2850}
2851// ------------------------------------------------------------------------------------------------
2852// static function: FindPoint
2853// purpose:
2854// ------------------------------------------------------------------------------------------------
2855Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
2856 const gp_Pnt2d& theLastPoint,
2857 const Standard_Real theUmin,
2858 const Standard_Real theUmax,
2859 const Standard_Real theVmin,
2860 const Standard_Real theVmax,
2861 gp_Pnt2d& theNewPoint) {
2862
2863 gp_Vec2d aVec(theFirstPoint, theLastPoint);
2864 Standard_Integer i = 0, j = 0;
2865
2866 for(i = 0; i < 4; i++) {
2867 gp_Vec2d anOtherVec;
2868 gp_Vec2d anOtherVecNormal;
2869 gp_Pnt2d aprojpoint = theLastPoint;
2870
2871 if((i % 2) == 0) {
2872 anOtherVec.SetX(0.);
2873 anOtherVec.SetY(1.);
2874 anOtherVecNormal.SetX(1.);
2875 anOtherVecNormal.SetY(0.);
2876
2877 if(i < 2)
2878 aprojpoint.SetX(theUmin);
2879 else
2880 aprojpoint.SetX(theUmax);
2881 }
2882 else {
2883 anOtherVec.SetX(1.);
2884 anOtherVec.SetY(0.);
2885 anOtherVecNormal.SetX(0.);
2886 anOtherVecNormal.SetY(1.);
2887
2888 if(i < 2)
2889 aprojpoint.SetY(theVmin);
2890 else
2891 aprojpoint.SetY(theVmax);
2892 }
2893 gp_Vec2d anormvec = aVec;
2894 anormvec.Normalize();
2895 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
2896
2897 if(fabs(adot1) < Precision::Angular())
2898 continue;
2899 Standard_Real adist = 0.;
2900 Standard_Boolean bIsOut = Standard_False;
2901
2902 if((i % 2) == 0) {
2903 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
2904 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
2905 }
2906 else {
2907 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
2908 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
2909 }
2910 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
2911
2912 for(j = 0; j < 2; j++) {
2913 anoffset = (j == 0) ? anoffset : -anoffset;
2914 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
2915 gp_Vec2d acurvec(theLastPoint, acurpoint);
2916 if ( bIsOut )
2917 acurvec.Reverse();
2918
9e9df9d9
P
2919 Standard_Real aDotX, anAngleX;
2920 //
2921 aDotX = aVec.Dot(acurvec);
2922 anAngleX = aVec.Angle(acurvec);
2923 //
2924 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
7fd59977 2925 if((i % 2) == 0) {
2926 if((acurpoint.Y() >= theVmin) &&
2927 (acurpoint.Y() <= theVmax)) {
2928 theNewPoint = acurpoint;
2929 return Standard_True;
2930 }
2931 }
2932 else {
2933 if((acurpoint.X() >= theUmin) &&
2934 (acurpoint.X() <= theUmax)) {
2935 theNewPoint = acurpoint;
2936 return Standard_True;
2937 }
2938 }
2939 }
2940 }
2941 }
2942 return Standard_False;
2943}
2944
2945
2946// ------------------------------------------------------------------------------------------------
2947// static function: FindPoint
2948// purpose: Find point on the boundary of radial tangent zone
2949// ------------------------------------------------------------------------------------------------
2950Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
2951 const gp_Pnt2d& theLastPoint,
2952 const Standard_Real theUmin,
2953 const Standard_Real theUmax,
2954 const Standard_Real theVmin,
2955 const Standard_Real theVmax,
2956 const gp_Pnt2d& theTanZoneCenter,
2957 const Standard_Real theZoneRadius,
2958 Handle(GeomAdaptor_HSurface) theGASurface,
2959 gp_Pnt2d& theNewPoint) {
2960 theNewPoint = theLastPoint;
2961
2962 if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
2963 return Standard_False;
2964
2965 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
2966 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
2967
2968 Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
2969 gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) );
2970 gp_Circ2d aCircle( anAxis, aRadius );
2971
2972 //
2973 gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() );
2974 Standard_Real aLength = aDir.Magnitude();
2975 if ( aLength <= gp::Resolution() )
2976 return Standard_False;
2977 gp_Lin2d aLine( theFirstPoint, aDir );
2978
2979 //
2980 Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine );
2981 Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength );
2982 Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle );
2983
2984 Standard_Real aTol = aRadius * 0.001;
2985 aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol;
2986
2987 Geom2dAPI_InterCurveCurve anIntersector;
2988 anIntersector.Init( aC1, aC2, aTol );
2989
2990 if ( anIntersector.NbPoints() == 0 )
2991 return Standard_False;
2992
2993 Standard_Boolean aFound = Standard_False;
2994 Standard_Real aMinDist = aLength * aLength;
2995 Standard_Integer i = 0;
2996 for ( i = 1; i <= anIntersector.NbPoints(); i++ ) {
2997 gp_Pnt2d aPInt = anIntersector.Point( i );
2998 if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
2999 if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
3000 ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
3001 theNewPoint = aPInt;
3002 aFound = Standard_True;
3003 }
3004 }
3005 }
3006
3007 return aFound;
3008}
3009
3010// ------------------------------------------------------------------------------------------------
3011// static function: IsInsideTanZone
3012// purpose: Check if point is inside a radial tangent zone
3013// ------------------------------------------------------------------------------------------------
3014Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
3015 const gp_Pnt2d& theTanZoneCenter,
3016 const Standard_Real theZoneRadius,
3017 Handle(GeomAdaptor_HSurface) theGASurface) {
3018
3019 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3020 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3021 Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3022 aRadiusSQR *= aRadiusSQR;
3023 if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR )
3024 return Standard_True;
3025 return Standard_False;
3026}
3027
3028// ------------------------------------------------------------------------------------------------
3029// static function: CheckTangentZonesExist
3030// purpose: Check if tangent zone exists
3031// ------------------------------------------------------------------------------------------------
3032Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
3033 const Handle(GeomAdaptor_HSurface)& theSurface2 )
3034{
3035 if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
3036 ( theSurface2->GetType() != GeomAbs_Torus ) )
3037 return Standard_False;
3038
3039 IntTools_Context aContext;
3040
3041 gp_Torus aTor1 = theSurface1->Torus();
3042 gp_Torus aTor2 = theSurface2->Torus();
3043
3044 if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() )
3045 return Standard_False;
3046
3047 if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) ||
3048 ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) )
3049 return Standard_False;
3050
3051 if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) ||
3052 ( aTor2.MajorRadius() < aTor2.MinorRadius() ) )
3053 return Standard_False;
3054 return Standard_True;
3055}
3056
3057// ------------------------------------------------------------------------------------------------
3058// static function: ComputeTangentZones
3059// purpose:
3060// ------------------------------------------------------------------------------------------------
3061Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
3062 const Handle(GeomAdaptor_HSurface)& theSurface2,
3063 const TopoDS_Face& theFace1,
3064 const TopoDS_Face& theFace2,
3065 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
3066 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
3067 Handle(TColStd_HArray1OfReal)& theResultRadius) {
3068 Standard_Integer aResult = 0;
3069 if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) )
3070 return aResult;
3071
3072 IntTools_Context aContext;
3073
3074 TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2;
3075 TColStd_SequenceOfReal aSeqResultRad;
3076
3077 gp_Torus aTor1 = theSurface1->Torus();
3078 gp_Torus aTor2 = theSurface2->Torus();
3079
3080 gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() );
3081 gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() );
3082 Standard_Integer j = 0;
3083
3084 for ( j = 0; j < 2; j++ ) {
3085 Standard_Real aCoef = ( j == 0 ) ? -1 : 1;
3086 Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius());
3087 Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius());
3088
3089 gp_Circ aCircle1( anax1, aRadius1 );
3090 gp_Circ aCircle2( anax2, aRadius2 );
3091
3092 // roughly compute radius of tangent zone for perpendicular case
3093 Standard_Real aCriteria = Precision::Confusion() * 0.5;
3094
3095 Standard_Real aT1 = aCriteria;
3096 Standard_Real aT2 = aCriteria;
3097 if ( j == 0 ) {
3098 // internal tangency
3099 Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3100 //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria );
3101 aT1 = 2. * aR * aCriteria;
3102 aT2 = aT1;
3103 }
3104 else {
3105 // external tangency
3106 Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3107 Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3108 Standard_Real aDelta = aRb - aCriteria;
3109 aDelta *= aDelta;
3110 aDelta -= aRm * aRm;
3111 aDelta /= 2. * (aRb - aRm);
3112 aDelta -= 0.5 * (aRb - aRm);
3113
3114 aT1 = 2. * aRm * (aRm - aDelta);
3115 aT2 = aT1;
3116 }
3117 aCriteria = ( aT1 > aT2) ? aT1 : aT2;
3118 if ( aCriteria > 0 )
3119 aCriteria = sqrt( aCriteria );
3120
3121 if ( aCriteria > 0.5 * aTor1.MinorRadius() ) {
3122 // too big zone -> drop to minimum
3123 aCriteria = Precision::Confusion();
3124 }
3125
3126 GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) );
3127 GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) );
3128 Extrema_ExtCC anExtrema(aC1, aC2, 0, 2.*Standard_PI, 0, 2.*Standard_PI,
3129 Precision::PConfusion(), Precision::PConfusion());
3130
3131 if ( anExtrema.IsDone() ) {
3132
3133 Standard_Integer i = 0;
3134 for ( i = 1; i <= anExtrema.NbExt(); i++ ) {
3135 if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
3136 continue;
3137
3138 Extrema_POnCurv P1, P2;
3139 anExtrema.Points( i, P1, P2 );
3140
3141 Standard_Boolean bFoundResult = Standard_True;
3142 gp_Pnt2d pr1, pr2;
3143
3144 Standard_Integer surfit = 0;
3145 for ( surfit = 0; surfit < 2; surfit++ ) {
3146 GeomAPI_ProjectPointOnSurf& aProjector = (surfit == 0) ? aContext.ProjPS(theFace1) : aContext.ProjPS(theFace2);
3147
3148 gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
3149 aProjector.Perform(aP3d);
3150
3151 if(!aProjector.IsDone())
3152 bFoundResult = Standard_False;
3153 else {
3154 if(aProjector.LowerDistance() > aCriteria) {
3155 bFoundResult = Standard_False;
3156 }
3157 else {
3158 Standard_Real foundU = 0, foundV = 0;
3159 aProjector.LowerDistanceParameters(foundU, foundV);
3160 if ( surfit == 0 )
3161 pr1 = gp_Pnt2d( foundU, foundV );
3162 else
3163 pr2 = gp_Pnt2d( foundU, foundV );
3164 }
3165 }
3166 }
3167 if ( bFoundResult ) {
3168 aSeqResultS1.Append( pr1 );
3169 aSeqResultS2.Append( pr2 );
3170 aSeqResultRad.Append( aCriteria );
3171
3172 // torus is u and v periodic
3173 const Standard_Real twoPI = Standard_PI + Standard_PI;
3174 Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
3175 Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
3176
3177 // iteration on period bounds
3178 for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
3179 Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
3180 Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
3181
3182 // iteration on surfaces
3183 for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
3184 Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
3185 Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
3186 TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
3187 TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
3188
3189 if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
3190 aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
3191 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3192 aSeqResultRad.Append( aCriteria );
3193 }
3194 if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
3195 aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
3196 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3197 aSeqResultRad.Append( aCriteria );
3198 }
3199 }
3200 } //
3201 }
3202 }
3203 }
3204 }
3205 aResult = aSeqResultRad.Length();
3206
3207 if ( aResult > 0 ) {
3208 theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult );
3209 theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult );
3210 theResultRadius = new TColStd_HArray1OfReal( 1, aResult );
3211
3212 for ( Standard_Integer i = 1 ; i <= aResult; i++ ) {
3213 theResultOnS1->SetValue( i, aSeqResultS1.Value(i) );
3214 theResultOnS2->SetValue( i, aSeqResultS2.Value(i) );
3215 theResultRadius->SetValue( i, aSeqResultRad.Value(i) );
3216 }
3217 }
3218 return aResult;
3219}
3220
3221// ------------------------------------------------------------------------------------------------
3222// static function: AdjustByNeighbour
3223// purpose:
3224// ------------------------------------------------------------------------------------------------
3225gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
3226 const gp_Pnt2d& theOriginalPoint,
3227 Handle(GeomAdaptor_HSurface) theGASurface) {
3228
3229 gp_Pnt2d ap1 = theaNeighbourPoint;
3230 gp_Pnt2d ap2 = theOriginalPoint;
3231
3232 if ( theGASurface->IsUPeriodic() ) {
3233 Standard_Real aPeriod = theGASurface->UPeriod();
3234 gp_Pnt2d aPTest = ap2;
3235 Standard_Real aSqDistMin = 1.e+100;
3236
3237 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3238 aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt );
3239 Standard_Real dd = ap1.SquareDistance( aPTest );
3240
3241 if ( dd < aSqDistMin ) {
3242 ap2 = aPTest;
3243 aSqDistMin = dd;
3244 }
3245 }
3246 }
3247 if ( theGASurface->IsVPeriodic() ) {
3248 Standard_Real aPeriod = theGASurface->VPeriod();
3249 gp_Pnt2d aPTest = ap2;
3250 Standard_Real aSqDistMin = 1.e+100;
3251
3252 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3253 aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt );
3254 Standard_Real dd = ap1.SquareDistance( aPTest );
3255
3256 if ( dd < aSqDistMin ) {
3257 ap2 = aPTest;
3258 aSqDistMin = dd;
3259 }
3260 }
3261 }
3262 return ap2;
3263}
3264
3265// ------------------------------------------------------------------------------------------------
3266//function: DecompositionOfWLine
3267// purpose:
3268// ------------------------------------------------------------------------------------------------
3269Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
3270 const Handle(GeomAdaptor_HSurface)& theSurface1,
3271 const Handle(GeomAdaptor_HSurface)& theSurface2,
3272 const TopoDS_Face& theFace1,
3273 const TopoDS_Face& theFace2,
3274 const IntTools_LineConstructor& theLConstructor,
3275 const Standard_Boolean theAvoidLConstructor,
3276 IntPatch_SequenceOfLine& theNewLines,
3277 Standard_Real& theReachedTol3d) {
3278
3279 Standard_Boolean bRet, bAvoidLineConstructor;
3280 Standard_Integer aNbPnts, aNbParts;
3281 //
3282 bRet=Standard_False;
3283 aNbPnts=theWLine->NbPnts();
3284 bAvoidLineConstructor=theAvoidLConstructor;
3285 //
3286 if(!aNbPnts){
3287 return bRet;
3288 }
3289 if (!bAvoidLineConstructor) {
3290 aNbParts=theLConstructor.NbParts();
3291 if (!aNbParts) {
3292 return bRet;
3293 }
3294 }
3295 //
3296 Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary;
3297 Standard_Integer nblines, pit, i, j;
3298 Standard_Real aTol;
3299 TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts);
3300 TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts);
3301 TColStd_ListOfInteger aListOfPointIndex;
3302 IntTools_Context aContext;
3303
3304 Handle(TColgp_HArray1OfPnt2d) aTanZoneS1;
3305 Handle(TColgp_HArray1OfPnt2d) aTanZoneS2;
3306 Handle(TColStd_HArray1OfReal) aTanZoneRadius;
3307 Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2,
3308 aTanZoneS1, aTanZoneS2, aTanZoneRadius );
3309
3310 //
3311 nblines=0;
3312 aTol=Precision::Confusion();
3313 aTol=0.5*aTol;
3314 bIsPrevPointOnBoundary=Standard_False;
3315 bIsPointOnBoundary=Standard_False;
3316 //
3317 // 1. ...
3318 //
3319 // Points
3320 for(pit = 1; pit <= aNbPnts; ++pit) {
3321 Standard_Boolean bIsOnFirstBoundary, isperiodic;
3322 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
3323 Standard_Real aParameter, anoffset, anAdjustPar;
3324 Standard_Real umin, umax, vmin, vmax;
3325 //
3326 bIsCurrentPointOnBoundary = Standard_False;
3327 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
3328 //
3329 // Surface
3330 for(i = 0; i < 2; ++i) {
3331 Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
3332 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3333 if(!i) {
3334 aPoint.ParametersOnS1(U, V);
3335 }
3336 else {
3337 aPoint.ParametersOnS2(U, V);
3338 }
3339 // U, V
3340 for(j = 0; j < 2; j++) {
3341 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3342 if(!isperiodic){
3343 continue;
3344 }
3345 //
3346 if (!j) {
3347 aResolution=aGASurface->UResolution(aTol);
3348 aPeriod=aGASurface->UPeriod();
3349 alowerboundary=umin;
3350 aupperboundary=umax;
3351 aParameter=U;
3352 }
3353 else {
3354 aResolution=aGASurface->VResolution(aTol);
3355 aPeriod=aGASurface->VPeriod();
3356 alowerboundary=vmin;
3357 aupperboundary=vmax;
3358 aParameter=V;
3359 }
3360
3361 anoffset = 0.;
3362 anAdjustPar = AdjustPeriodic(aParameter,
3363 alowerboundary,
3364 aupperboundary,
3365 aPeriod,
3366 anoffset);
3367 //
3368 bIsOnFirstBoundary = Standard_True;// ?
3369 bIsPointOnBoundary=
3370 IsPointOnBoundary(anAdjustPar,
3371 alowerboundary,
3372 aupperboundary,
3373 aResolution,
3374 bIsOnFirstBoundary);
3375 //
3376 if(bIsPointOnBoundary) {
3377 bIsCurrentPointOnBoundary = Standard_True;
3378 break;
3379 }
3380 else {
3381 // check if a point belong to a tangent zone. Begin
3382 Standard_Integer zIt = 0;
3383 for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
3384 gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3385 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3386
3387 if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
3388 // set boundary flag to split the curve by a tangent zone
3389 bIsPointOnBoundary = Standard_True;
3390 bIsCurrentPointOnBoundary = Standard_True;
3391 if ( theReachedTol3d < aZoneRadius ) {
3392 theReachedTol3d = aZoneRadius;
3393 }
3394 break;
3395 }
3396 }
3397 }
3398 }//for(j = 0; j < 2; j++) {
3399
3400 if(bIsCurrentPointOnBoundary){
3401 break;
3402 }
3403 }//for(i = 0; i < 2; ++i) {
3404 //
3405 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
3406 if(!aListOfPointIndex.IsEmpty()) {
3407 nblines++;
3408 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3409 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3410 aListOfPointIndex.Clear();
3411 }
3412 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
3413 }
3414 aListOfPointIndex.Append(pit);
3415 } //for(pit = 1; pit <= aNbPnts; ++pit) {
3416 //
3417 if(!aListOfPointIndex.IsEmpty()) {
3418 nblines++;
3419 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3420 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3421 aListOfPointIndex.Clear();
3422 }
3423 //
3424 if(nblines<=1) {
3425 return bRet; //Standard_False;
3426 }
3427 //
3428 //
3429 // 2. Correct wlines.begin
3430 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
3431 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S();
3432 //
3433 for(i = 1; i <= nblines; i++) {
3434 if(anArrayOfLineType.Value(i) != 0) {
3435 continue;
3436 }
3437 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3438 if(aListOfIndex.Extent() < 2) {
3439 continue;
3440 }
3441 TColStd_ListOfInteger aListOfFLIndex;
3442
3443 for(j = 0; j < 2; j++) {
3444 Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1);
3445
3446 if((aneighbourindex < 1) || (aneighbourindex > nblines))
3447 continue;
3448
3449 if(anArrayOfLineType.Value(aneighbourindex) == 0)
3450 continue;
3451 const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex);
3452 Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First();
3453 const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
3454
3455 IntSurf_PntOn2S aNewP = aPoint;
3456
3457 for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
3458
3459 Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
3460 Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
3461 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3462 Standard_Real U=0., V=0.;
3463
3464 if(surfit == 0)
3465 aNewP.ParametersOnS1(U, V);
3466 else
3467 aNewP.ParametersOnS2(U, V);
3468 Standard_Integer nbboundaries = 0;
3469
3470 Standard_Boolean bIsNearBoundary = Standard_False;
3471 Standard_Integer aZoneIndex = 0;
3472 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
3473 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
3474
3475
3476 for(Standard_Integer parit = 0; parit < 2; parit++) {
3477 Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3478
3479 Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
3480 Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
3481 Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
3482
3483 Standard_Real aParameter = (parit == 0) ? U : V;
3484 Standard_Boolean bIsOnFirstBoundary = Standard_True;
3485
3486 if(!isperiodic) {
3487 bIsPointOnBoundary=
3488 IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3489 if(bIsPointOnBoundary) {
3490 bIsUBoundary = (parit == 0);
3491 bIsFirstBoundary = bIsOnFirstBoundary;
3492 nbboundaries++;
3493 }
3494 }
3495 else {
3496 Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3497 Standard_Real anoffset = 0.;
3498 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3499
3500 bIsPointOnBoundary=
3501 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3502 if(bIsPointOnBoundary) {
3503 bIsUBoundary = (parit == 0);
3504 bIsFirstBoundary = bIsOnFirstBoundary;
3505 nbboundaries++;
3506 }
3507 else {
3508 //check neighbourhood of boundary
3509 Standard_Real anEpsilon = aResolution * 100.;
3510 Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
3511 anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
3512
3513 bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
3514 anEpsilon, bIsOnFirstBoundary);
3515
3516 }
3517 }
3518 }
3519
3520 // check if a point belong to a tangent zone. Begin
3521 for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
3522 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3523 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3524
3525 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3526 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3527 Standard_Real nU1, nV1;
3528
3529 if(surfit == 0)
3530 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3531 else
3532 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3533 gp_Pnt2d ap1(nU1, nV1);
3534 gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
3535
3536
3537 if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
3538 aZoneIndex = zIt;
3539 bIsNearBoundary = Standard_True;
3540 if ( theReachedTol3d < aZoneRadius ) {
3541 theReachedTol3d = aZoneRadius;
3542 }
3543 }
3544 }
3545 // check if a point belong to a tangent zone. End
3546 Standard_Boolean bComputeLineEnd = Standard_False;
3547
3548 if(nbboundaries == 2) {
3549 //xf
9e9df9d9 3550 bComputeLineEnd = Standard_True;
7fd59977 3551 //xt
3552 }
3553 else if(nbboundaries == 1) {
3554 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3555
3556 if(isperiodic) {
3557 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
3558 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
3559 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3560 Standard_Real aParameter = (bIsUBoundary) ? U : V;
3561 Standard_Real anoffset = 0.;
3562 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3563
3564 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
3565 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
3566 anotherPar += anoffset;
3567 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3568 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
3569 Standard_Real nU1, nV1;
3570
3571 if(surfit == 0)
3572 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3573 else
3574 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3575
3576 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
3577 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
3578 bComputeLineEnd = Standard_True;
3579 Standard_Boolean bCheckAngle1 = Standard_False;
3580 Standard_Boolean bCheckAngle2 = Standard_False;
3581 gp_Vec2d aNewVec;
3582 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
3583 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
3584
3585 if(((adist1 - adist2) > Precision::PConfusion()) &&
3586 (adist2 < (aPeriod / 4.))) {
3587 bCheckAngle1 = Standard_True;
3588 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
3589
3590 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3591 aNewP.SetValue((surfit == 0), anewU, anewV);
3592 bCheckAngle1 = Standard_False;
3593 }
3594 }
3595 else if(adist1 < (aPeriod / 4.)) {
3596 bCheckAngle2 = Standard_True;
3597 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
3598
3599 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3600 bCheckAngle2 = Standard_False;
3601 }
3602 }
3603
3604 if(bCheckAngle1 || bCheckAngle2) {
3605 // assume there are at least two points in line (see "if" above)
3606 Standard_Integer anindexother = aneighbourpointindex;
3607
3608 while((anindexother <= aListOfIndex.Last()) && (anindexother >= aListOfIndex.First())) {
3609 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
3610 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
3611 Standard_Real nU2, nV2;
3612
3613 if(surfit == 0)
3614 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3615 else
3616 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3617 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
3618
3619 if(aVecOld.SquareMagnitude() <= (gp::Resolution() * gp::Resolution())) {
3620 continue;
3621 }
3622 else {
3623 Standard_Real anAngle = aNewVec.Angle(aVecOld);
3624
3625 if((fabs(anAngle) < (Standard_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
3626
3627 if(bCheckAngle1) {
3628 Standard_Real U1, U2, V1, V2;
3629 IntSurf_PntOn2S atmppoint = aNewP;
3630 atmppoint.SetValue((surfit == 0), anewU, anewV);
3631 atmppoint.Parameters(U1, V1, U2, V2);
3632 gp_Pnt P1 = theSurface1->Value(U1, V1);
3633 gp_Pnt P2 = theSurface2->Value(U2, V2);
3634 gp_Pnt P0 = aPoint.Value();
3635
3636 if(P0.IsEqual(P1, aTol) &&
3637 P0.IsEqual(P2, aTol) &&
3638 P1.IsEqual(P2, aTol)) {
3639 bComputeLineEnd = Standard_False;
3640 aNewP.SetValue((surfit == 0), anewU, anewV);
3641 }
3642 }
3643
3644 if(bCheckAngle2) {
3645 bComputeLineEnd = Standard_False;
3646 }
3647 }
3648 break;
3649 }
3650 } // end while(anindexother...)
3651 }
3652 }
3653 }
3654 else if ( bIsNearBoundary ) {
3655 bComputeLineEnd = Standard_True;
3656 }
3657
3658 if(bComputeLineEnd) {
3659
3660 gp_Pnt2d anewpoint;
3661 Standard_Boolean found = Standard_False;
3662
3663 if ( bIsNearBoundary ) {
3664 // re-compute point near natural boundary or near tangent zone
3665 Standard_Real u1, v1, u2, v2;
3666 aNewP.Parameters( u1, v1, u2, v2 );
3667 if(surfit == 0)
3668 anewpoint = gp_Pnt2d( u1, v1 );
3669 else
3670 anewpoint = gp_Pnt2d( u2, v2 );
3671
3672 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3673 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3674 Standard_Real nU1, nV1;
3675
3676 if(surfit == 0)
3677 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3678 else
3679 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3680 gp_Pnt2d ap1(nU1, nV1);
3681 gp_Pnt2d ap2;
3682
3683
3684 if ( aZoneIndex ) {
3685 // exclude point from a tangent zone
3686 anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3687 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
3688 Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
3689
3690 if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
3691 aPZone, aZoneRadius, aGASurface, ap2) ) {
3692 anewpoint = ap2;
3693 found = Standard_True;
3694 }
3695 }
3696 else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
3697 // re-compute point near boundary if shifted on a period
3698 ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3699
3700 if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
3701 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
3702 found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
3703 }
3704 else {
3705 anewpoint = ap2;
3706 aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
3707 }
3708 }
3709 }
3710 else {
3711
3712 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3713 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3714 Standard_Real nU1, nV1;
3715
3716 if(surfit == 0)
3717 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3718 else
3719 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3720 gp_Pnt2d ap1(nU1, nV1);
3721 gp_Pnt2d ap2(nU1, nV1);
3722 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
3723
3724 while((aneighbourpointindex2 <= aListOfIndex.Last()) && (aneighbourpointindex2 >= aListOfIndex.First())) {
3725 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
3726 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
3727 Standard_Real nU2, nV2;
3728
3729 if(surfit == 0)
3730 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3731 else
3732 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3733 ap2.SetX(nU2);
3734 ap2.SetY(nV2);
3735
3736 if(ap1.SquareDistance(ap2) > (gp::Resolution() * gp::Resolution())) {
3737 break;
3738 }
3739 }
3740 found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
3741 }
3742
3743 if(found) {
3744 // check point
3745 Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
3746 GeomAPI_ProjectPointOnSurf& aProjector = (surfit == 0) ? aContext.ProjPS(theFace2) : aContext.ProjPS(theFace1);
3747 Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
3748
3749 Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
3750
3751 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
3752 aProjector.Perform(aP3d);
3753
3754 if(aProjector.IsDone()) {
3755 if(aProjector.LowerDistance() < aCriteria) {
3756 Standard_Real foundU = U, foundV = V;
3757 aProjector.LowerDistanceParameters(foundU, foundV);
3758
3759 //Correction of projected coordinates. Begin
3760 //Note, it may be shifted on a period
3761 Standard_Integer aneindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3762 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
3763 Standard_Real nUn, nVn;
3764
3765 if(surfit == 0)
3766 aNeighbourPoint.ParametersOnS2(nUn, nVn);
3767 else
3768 aNeighbourPoint.ParametersOnS1(nUn, nVn);
3769 gp_Pnt2d aNeighbour2d(nUn, nVn);
3770 gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
3771 foundU = anAdjustedPoint.X();
3772 foundV = anAdjustedPoint.Y();
3773
3774 if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
3775 ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
3776 // attempt to roughly re-compute point
3777 foundU = ( foundU < umin ) ? umin : foundU;
3778 foundU = ( foundU > umax ) ? umax : foundU;
3779 foundV = ( foundV < vmin ) ? vmin : foundV;
3780 foundV = ( foundV > vmax ) ? vmax : foundV;
3781
3782 GeomAPI_ProjectPointOnSurf& aProjector2 = (surfit == 0) ? aContext.ProjPS(theFace1) : aContext.ProjPS(theFace2);
3783
3784 aP3d = aSurfaceOther->Value(foundU, foundV);
3785 aProjector2.Perform(aP3d);
3786
3787 if(aProjector2.IsDone()) {
3788 if(aProjector2.LowerDistance() < aCriteria) {
3789 Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
3790 aProjector2.LowerDistanceParameters(foundU2, foundV2);
3791 anewpoint.SetX(foundU2);
3792 anewpoint.SetY(foundV2);
3793 }