0023029: split shape algorithm works incorrectly in some cases
[occt.git] / src / IntTools / IntTools_FaceFace.cxx
... / ...
CommitLineData
1// Created on: 2000-11-23
2// Created by: Michael KLOKOV
3// Copyright (c) 2000-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
20
21
22#include <IntTools_FaceFace.ixx>
23
24#include <Precision.hxx>
25
26#include <TColStd_HArray1OfReal.hxx>
27#include <TColStd_Array1OfReal.hxx>
28#include <TColStd_Array1OfInteger.hxx>
29#include <TColStd_SequenceOfReal.hxx>
30#include <TColStd_ListOfInteger.hxx>
31#include <TColStd_ListIteratorOfListOfInteger.hxx>
32#include <TColStd_Array1OfListOfInteger.hxx>
33
34#include <gp_Lin2d.hxx>
35#include <gp_Ax22d.hxx>
36#include <gp_Circ2d.hxx>
37#include <gp_Torus.hxx>
38#include <gp_Cylinder.hxx>
39
40#include <Bnd_Box.hxx>
41
42#include <TColgp_HArray1OfPnt2d.hxx>
43#include <TColgp_SequenceOfPnt2d.hxx>
44#include <TColgp_Array1OfPnt.hxx>
45#include <TColgp_Array1OfPnt2d.hxx>
46
47#include <IntAna_QuadQuadGeo.hxx>
48
49#include <IntSurf_PntOn2S.hxx>
50#include <IntSurf_LineOn2S.hxx>
51#include <IntSurf_PntOn2S.hxx>
52#include <IntSurf_ListOfPntOn2S.hxx>
53#include <IntRes2d_Domain.hxx>
54#include <ProjLib_Plane.hxx>
55
56#include <IntPatch_GLine.hxx>
57#include <IntPatch_RLine.hxx>
58#include <IntPatch_WLine.hxx>
59#include <IntPatch_ALine.hxx>
60#include <IntPatch_ALineToWLine.hxx>
61
62#include <ElSLib.hxx>
63#include <ElCLib.hxx>
64
65#include <Extrema_ExtCC.hxx>
66#include <Extrema_POnCurv.hxx>
67#include <BndLib_AddSurface.hxx>
68
69#include <Adaptor3d_SurfacePtr.hxx>
70#include <Adaptor2d_HLine2d.hxx>
71
72#include <GeomAbs_SurfaceType.hxx>
73#include <GeomAbs_CurveType.hxx>
74
75#include <Geom_Surface.hxx>
76#include <Geom_Line.hxx>
77#include <Geom_Circle.hxx>
78#include <Geom_Ellipse.hxx>
79#include <Geom_Parabola.hxx>
80#include <Geom_Hyperbola.hxx>
81#include <Geom_TrimmedCurve.hxx>
82#include <Geom_BSplineCurve.hxx>
83#include <Geom_RectangularTrimmedSurface.hxx>
84#include <Geom_OffsetSurface.hxx>
85#include <Geom_Curve.hxx>
86#include <Geom_Conic.hxx>
87
88#include <Geom2d_TrimmedCurve.hxx>
89#include <Geom2d_BSplineCurve.hxx>
90#include <Geom2d_Line.hxx>
91#include <Geom2d_Curve.hxx>
92#include <Geom2d_Circle.hxx>
93
94#include <Geom2dAPI_InterCurveCurve.hxx>
95#include <Geom2dInt_GInter.hxx>
96#include <GeomAdaptor_Curve.hxx>
97#include <GeomAdaptor_HSurface.hxx>
98#include <GeomAdaptor_Surface.hxx>
99#include <GeomLib_CheckBSplineCurve.hxx>
100#include <GeomLib_Check2dBSplineCurve.hxx>
101
102#include <GeomInt_WLApprox.hxx>
103#include <GeomProjLib.hxx>
104#include <GeomAPI_ProjectPointOnSurf.hxx>
105#include <Geom2dAdaptor_Curve.hxx>
106#include <TopoDS.hxx>
107#include <TopoDS_Edge.hxx>
108#include <TopExp_Explorer.hxx>
109
110#include <BRep_Tool.hxx>
111#include <BRepTools.hxx>
112#include <BRepAdaptor_Surface.hxx>
113
114#include <BOPTColStd_Dump.hxx>
115
116#include <IntTools_Curve.hxx>
117#include <IntTools_Tools.hxx>
118#include <IntTools_Tools.hxx>
119#include <IntTools_TopolTool.hxx>
120#include <IntTools_PntOnFace.hxx>
121#include <IntTools_PntOn2Faces.hxx>
122#include <IntTools_Context.hxx>
123#include <IntSurf_ListIteratorOfListOfPntOn2S.hxx>
124
125static
126 void RefineVector(gp_Vec2d& aV2D);
127
128static
129 void DumpWLine(const Handle(IntPatch_WLine)& aWLine);
130//
131static
132 void TolR3d(const TopoDS_Face& ,
133 const TopoDS_Face& ,
134 Standard_Real& );
135static
136 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)&,
137 const Standard_Integer,
138 const Standard_Integer);
139
140static
141 void Parameters(const Handle(GeomAdaptor_HSurface)&,
142 const Handle(GeomAdaptor_HSurface)&,
143 const gp_Pnt&,
144 Standard_Real&,
145 Standard_Real&,
146 Standard_Real&,
147 Standard_Real&);
148
149static
150 void BuildPCurves (Standard_Real f,Standard_Real l,Standard_Real& Tol,
151 const Handle (Geom_Surface)& S,
152 const Handle (Geom_Curve)& C,
153 Handle (Geom2d_Curve)& C2d);
154
155static
156 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
157 const Standard_Real theTolerance,
158 Standard_Real& theumin,
159 Standard_Real& theumax,
160 Standard_Real& thevmin,
161 Standard_Real& thevmax);
162static
163 Standard_Boolean NotUseSurfacesForApprox
164 (const TopoDS_Face& aF1,
165 const TopoDS_Face& aF2,
166 const Handle(IntPatch_WLine)& WL,
167 const Standard_Integer ifprm,
168 const Standard_Integer ilprm);
169
170static
171 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine);
172
173static
174 Standard_Real AdjustPeriodic(const Standard_Real theParameter,
175 const Standard_Real parmin,
176 const Standard_Real parmax,
177 const Standard_Real thePeriod,
178 Standard_Real& theOffset);
179
180static
181 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
182 const Standard_Integer ideb,
183 const Standard_Integer ifin,
184 const Standard_Boolean onFirst);
185
186static
187 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
188 const Handle(GeomAdaptor_HSurface)& theSurface1,
189 const Handle(GeomAdaptor_HSurface)& theSurface2,
190 const TopoDS_Face& theFace1,
191 const TopoDS_Face& theFace2,
192 const IntTools_LineConstructor& theLConstructor,
193 const Standard_Boolean theAvoidLConstructor,
194 IntPatch_SequenceOfLine& theNewLines,
195 Standard_Real& theReachedTol3d,
196 const Handle(IntTools_Context)& );
197
198static
199 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
200 const Handle(Geom_Curve)& theCurve,
201 const TopoDS_Face& theFace1,
202 const TopoDS_Face& theFace2,
203 const Standard_Real theOtherParameter,
204 const Standard_Boolean bIncreasePar,
205 Standard_Real& theNewParameter,
206 const Handle(IntTools_Context)& );
207
208static
209 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve);
210
211static
212 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
213 const Standard_Real theFirstBoundary,
214 const Standard_Real theSecondBoundary,
215 const Standard_Real theResolution,
216 Standard_Boolean& IsOnFirstBoundary);
217static
218 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
219 const gp_Pnt2d& theLastPoint,
220 const Standard_Real theUmin,
221 const Standard_Real theUmax,
222 const Standard_Real theVmin,
223 const Standard_Real theVmax,
224 gp_Pnt2d& theNewPoint);
225
226
227static
228 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
229 const Handle(GeomAdaptor_HSurface)& theSurface2,
230 const TopoDS_Face& theFace1,
231 const TopoDS_Face& theFace2,
232 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
233 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
234 Handle(TColStd_HArray1OfReal)& theResultRadius,
235 const Handle(IntTools_Context)& );
236
237static
238 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
239 const gp_Pnt2d& theLastPoint,
240 const Standard_Real theUmin,
241 const Standard_Real theUmax,
242 const Standard_Real theVmin,
243 const Standard_Real theVmax,
244 const gp_Pnt2d& theTanZoneCenter,
245 const Standard_Real theZoneRadius,
246 Handle(GeomAdaptor_HSurface) theGASurface,
247 gp_Pnt2d& theNewPoint);
248
249static
250 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
251 const gp_Pnt2d& theTanZoneCenter,
252 const Standard_Real theZoneRadius,
253 Handle(GeomAdaptor_HSurface) theGASurface);
254
255static
256 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
257 const gp_Pnt2d& theOriginalPoint,
258 Handle(GeomAdaptor_HSurface) theGASurface);
259static
260 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
261 const gp_Sphere& theSph);
262
263static void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
264 const Handle(GeomAdaptor_HSurface)& theS2,
265 const Standard_Real TolAng,
266 const Standard_Real TolTang,
267 const Standard_Boolean theApprox1,
268 const Standard_Boolean theApprox2,
269 IntTools_SequenceOfCurves& theSeqOfCurve,
270 Standard_Boolean& theTangentFaces);
271
272static Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
273 const gp_Lin2d& theLin2d,
274 const Standard_Real theTol,
275 Standard_Real& theP1,
276 Standard_Real& theP2);
277//
278static
279 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
280 const Handle(GeomAdaptor_HSurface)& aHS2,
281 Standard_Integer& iDegMin,
282 Standard_Integer& iNbIter,
283 Standard_Integer& iDegMax);
284
285static
286 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
287 const Handle(GeomAdaptor_HSurface)& aHS2,
288 Standard_Real& aTolArc,
289 Standard_Real& aTolTang,
290 Standard_Real& aUVMaxStep,
291 Standard_Real& aDeflection);
292
293static
294 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
295 const GeomAbs_SurfaceType aType2);
296static
297 Standard_Integer IndexType(const GeomAbs_SurfaceType aType);
298
299//
300//modified by NIZNHY-PKV Tue Jan 31 08:02:24 2012f
301static
302 Standard_Real MaxSquareDistance (const Standard_Real aT,
303 const Handle(Geom_Curve)& aC3D,
304 const Handle(Geom2d_Curve)& aC2D1,
305 const Handle(Geom2d_Curve)& aC2D2,
306 const Handle(GeomAdaptor_HSurface) myHS1,
307 const Handle(GeomAdaptor_HSurface) myHS2,
308 const TopoDS_Face& aF1,
309 const TopoDS_Face& aF2,
310 const Handle(IntTools_Context)& aCtx);
311//modified by NIZNHY-PKV Tue Jan 31 08:02:28 2012t
312//
313//=======================================================================
314//function :
315//purpose :
316//=======================================================================
317IntTools_FaceFace::IntTools_FaceFace()
318{
319 myTangentFaces=Standard_False;
320 //
321 myHS1 = new GeomAdaptor_HSurface ();
322 myHS2 = new GeomAdaptor_HSurface ();
323 myTolReached2d=0.;
324 myTolReached3d=0.;
325 SetParameters(Standard_True, Standard_True, Standard_True, 1.e-07);
326
327}
328//=======================================================================
329//function : SetContext
330//purpose :
331//=======================================================================
332void IntTools_FaceFace::SetContext(const Handle(IntTools_Context)& aContext)
333{
334 myContext=aContext;
335}
336//=======================================================================
337//function : Context
338//purpose :
339//=======================================================================
340const Handle(IntTools_Context)& IntTools_FaceFace::Context()const
341{
342 return myContext;
343}
344//=======================================================================
345//function : Face1
346//purpose :
347//=======================================================================
348const TopoDS_Face& IntTools_FaceFace::Face1() const
349{
350 return myFace1;
351}
352//=======================================================================
353//function : Face2
354//purpose :
355//=======================================================================
356const TopoDS_Face& IntTools_FaceFace::Face2() const
357{
358 return myFace2;
359}
360//=======================================================================
361//function : TangentFaces
362//purpose :
363//=======================================================================
364Standard_Boolean IntTools_FaceFace::TangentFaces() const
365{
366 return myTangentFaces;
367}
368//=======================================================================
369//function : Points
370//purpose :
371//=======================================================================
372const IntTools_SequenceOfPntOn2Faces& IntTools_FaceFace::Points() const
373{
374 return myPnts;
375}
376//=======================================================================
377//function : IsDone
378//purpose :
379//=======================================================================
380Standard_Boolean IntTools_FaceFace::IsDone() const
381{
382 return myIsDone;
383}
384//=======================================================================
385//function : TolReached3d
386//purpose :
387//=======================================================================
388Standard_Real IntTools_FaceFace::TolReached3d() const
389{
390 return myTolReached3d;
391}
392//=======================================================================
393//function : Lines
394//purpose : return lines of intersection
395//=======================================================================
396const IntTools_SequenceOfCurves& IntTools_FaceFace::Lines() const
397{
398 StdFail_NotDone_Raise_if
399 (!myIsDone,
400 "IntTools_FaceFace::Lines() => !myIntersector.IsDone()");
401 return mySeqOfCurve;
402}
403//=======================================================================
404//function : TolReached2d
405//purpose :
406//=======================================================================
407Standard_Real IntTools_FaceFace::TolReached2d() const
408{
409 return myTolReached2d;
410}
411// =======================================================================
412// function: SetParameters
413//
414// =======================================================================
415void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d,
416 const Standard_Boolean ToApproxC2dOnS1,
417 const Standard_Boolean ToApproxC2dOnS2,
418 const Standard_Real ApproximationTolerance)
419{
420 myApprox = ToApproxC3d;
421 myApprox1 = ToApproxC2dOnS1;
422 myApprox2 = ToApproxC2dOnS2;
423 myTolApprox = ApproximationTolerance;
424}
425//=======================================================================
426//function : SetList
427//purpose :
428//=======================================================================
429void IntTools_FaceFace::SetList(IntSurf_ListOfPntOn2S& aListOfPnts)
430{
431 myListOfPnts = aListOfPnts;
432}
433//=======================================================================
434//function : Perform
435//purpose : intersect surfaces of the faces
436//=======================================================================
437 void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
438 const TopoDS_Face& aF2)
439{
440 Standard_Boolean hasCone, RestrictLine, bTwoPlanes, bReverse;
441 Standard_Integer aNbLin, aNbPnts, i, NbLinPP;
442 Standard_Real TolArc, TolTang, Deflection, UVMaxStep;
443 Standard_Real umin, umax, vmin, vmax;
444 Standard_Real aTolF1, aTolF2;
445 GeomAbs_SurfaceType aType1, aType2;
446 Handle(Geom_Surface) S1, S2;
447 Handle(IntTools_TopolTool) dom1, dom2;
448 BRepAdaptor_Surface aBAS1, aBAS2;
449 //
450 if (myContext.IsNull()) {
451 myContext=new IntTools_Context;
452 }
453 //
454 mySeqOfCurve.Clear();
455 myTolReached2d=0.;
456 myTolReached3d=0.;
457 myIsDone = Standard_False;
458 myNbrestr=0;//?
459 hasCone = Standard_False;
460 bTwoPlanes = Standard_False;
461 //
462 myFace1=aF1;
463 myFace2=aF2;
464 //
465 aBAS1.Initialize(myFace1, Standard_False);
466 aBAS2.Initialize(myFace2, Standard_False);
467 aType1=aBAS1.GetType();
468 aType2=aBAS2.GetType();
469 //
470 bReverse=SortTypes(aType1, aType2);
471 if (bReverse) {
472 myFace1=aF2;
473 myFace2=aF1;
474 aType1=aBAS2.GetType();
475 aType2=aBAS1.GetType();
476 //
477 if (myListOfPnts.Extent()) {
478 Standard_Real aU1,aV1,aU2,aV2;
479 IntSurf_ListIteratorOfListOfPntOn2S aItP2S;
480 //
481 aItP2S.Initialize(myListOfPnts);
482 for (; aItP2S.More(); aItP2S.Next()){
483 IntSurf_PntOn2S& aP2S=aItP2S.Value();
484 aP2S.Parameters(aU1,aV1,aU2,aV2);
485 aP2S.SetValue(aU2,aV2,aU1,aV1);
486 }
487 }
488 }
489 //
490 S1=BRep_Tool::Surface(myFace1);
491 S2=BRep_Tool::Surface(myFace2);
492 //
493 aTolF1=BRep_Tool::Tolerance(myFace1);
494 aTolF2=BRep_Tool::Tolerance(myFace2);
495 //
496 TolArc= aTolF1 + aTolF2;
497 TolTang = TolArc;
498 //
499 NbLinPP = 0;
500 if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
501 bTwoPlanes = Standard_True;
502
503 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
504 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
505 //
506 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
507 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
508 Standard_Real TolAng = 1.e-8;
509 PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2,
510 mySeqOfCurve, myTangentFaces);
511
512 myIsDone = Standard_True;
513
514 if(!myTangentFaces) {
515 //
516 NbLinPP = mySeqOfCurve.Length();
517 if(NbLinPP) {
518 Standard_Real aTolFMax;
519 //
520 myTolReached3d = 1.e-7;
521 //
522 aTolFMax=Max(aTolF1, aTolF2);
523 //
524 if (aTolFMax>myTolReached3d) {
525 myTolReached3d=aTolFMax;
526 }
527 myTolReached2d = myTolReached3d;
528 //
529 if (bReverse) {
530 Handle(Geom2d_Curve) aC2D1, aC2D2;
531 //
532 aNbLin=mySeqOfCurve.Length();
533 for (i=1; i<=aNbLin; ++i) {
534 IntTools_Curve& aIC=mySeqOfCurve(i);
535 aC2D1=aIC.FirstCurve2d();
536 aC2D2=aIC.SecondCurve2d();
537 //
538 aIC.SetFirstCurve2d(aC2D2);
539 aIC.SetSecondCurve2d(aC2D1);
540 }
541 }
542 }
543 }
544 return;
545 }//if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
546 //
547 if (aType1==GeomAbs_Plane &&
548 (aType2==GeomAbs_Cylinder ||
549 aType2==GeomAbs_Cone ||
550 aType2==GeomAbs_Torus)) {
551 Standard_Real dU, dV;
552 // F1
553 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
554 dU=0.1*(umax-umin);
555 dV=0.1*(vmax-vmin);
556 umin=umin-dU;
557 umax=umax+dU;
558 vmin=vmin-dV;
559 vmax=vmax+dV;
560 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
561 // F2
562 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
563 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
564 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
565 //
566 if( aType2==GeomAbs_Cone ) {
567 TolArc = 0.0001;
568 hasCone = Standard_True;
569 }
570 }
571 //
572 else if ((aType1==GeomAbs_Cylinder||
573 aType1==GeomAbs_Cone ||
574 aType1==GeomAbs_Torus) &&
575 aType2==GeomAbs_Plane) {
576 Standard_Real dU, dV;
577 //F1
578 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
579 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
580 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
581 // F2
582 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
583 dU=0.1*(umax-umin);
584 dV=0.1*(vmax-vmin);
585 umin=umin-dU;
586 umax=umax+dU;
587 vmin=vmin-dV;
588 vmax=vmax+dV;
589 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
590 //
591 if( aType1==GeomAbs_Cone ) {
592 TolArc = 0.0001;
593 hasCone = Standard_True;
594 }
595 }
596
597 //
598 else {
599 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
600 //
601 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
602 //
603 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
604 //
605 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
606 //
607 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
608 //
609 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
610 }
611 //
612 dom1 = new IntTools_TopolTool(myHS1);
613 dom2 = new IntTools_TopolTool(myHS2);
614 //
615 myLConstruct.Load(dom1, dom2, myHS1, myHS2);
616 //
617 Deflection = (hasCone) ? 0.085 : 0.1;
618 UVMaxStep = 0.001;
619 //
620 Tolerances(myHS1, myHS2, TolArc, TolTang, UVMaxStep, Deflection);
621 //
622 myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection);
623 //
624 RestrictLine = Standard_False;
625 //
626 if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) ||
627 (myHS1->IsVClosed() && !myHS1->IsVPeriodic()) ||
628 (myHS2->IsUClosed() && !myHS2->IsUPeriodic()) ||
629 (myHS2->IsVClosed() && !myHS2->IsVPeriodic())) {
630 RestrictLine = Standard_True;
631 }
632 //
633 if(((aType1 != GeomAbs_BSplineSurface) &&
634 (aType1 != GeomAbs_BezierSurface) &&
635 (aType1 != GeomAbs_OtherSurface)) &&
636 ((aType2 != GeomAbs_BSplineSurface) &&
637 (aType2 != GeomAbs_BezierSurface) &&
638 (aType2 != GeomAbs_OtherSurface))) {
639 RestrictLine = Standard_True;
640 //
641 if ((aType1 == GeomAbs_Torus) ||
642 (aType2 == GeomAbs_Torus) ) {
643 myListOfPnts.Clear();
644 }
645 }
646 //
647 if(!RestrictLine) {
648 TopExp_Explorer aExp;
649 //
650 for(i = 0; (!RestrictLine) && (i < 2); i++) {
651 const TopoDS_Face& aF=(!i) ? myFace1 : myFace2;
652 aExp.Init(aF, TopAbs_EDGE);
653 for(; aExp.More(); aExp.Next()) {
654 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
655 //
656 if(BRep_Tool::Degenerated(aE)) {
657 RestrictLine = Standard_True;
658 break;
659 }
660 }
661 }
662 }
663 //
664 myIntersector.Perform(myHS1, dom1, myHS2, dom2,
665 TolArc, TolTang,
666 myListOfPnts, RestrictLine);
667 //
668 myIsDone = myIntersector.IsDone();
669 if (myIsDone) {
670 myTangentFaces=myIntersector.TangentFaces();
671 if (myTangentFaces) {
672 return;
673 }
674 //
675 if(RestrictLine) {
676 myListOfPnts.Clear(); // to use LineConstructor
677 }
678 //
679 aNbLin = myIntersector.NbLines();
680 for (i=1; i<=aNbLin; ++i) {
681 MakeCurve(i, dom1, dom2);
682 }
683 //
684 ComputeTolReached3d();
685 //
686 if (bReverse) {
687 Handle(Geom2d_Curve) aC2D1, aC2D2;
688 //
689 aNbLin=mySeqOfCurve.Length();
690 for (i=1; i<=aNbLin; ++i) {
691 IntTools_Curve& aIC=mySeqOfCurve(i);
692 aC2D1=aIC.FirstCurve2d();
693 aC2D2=aIC.SecondCurve2d();
694 //
695 aIC.SetFirstCurve2d(aC2D2);
696 aIC.SetSecondCurve2d(aC2D1);
697 }
698 }
699 //
700 // Points
701 Standard_Real U1,V1,U2,V2;
702 IntTools_PntOnFace aPntOnF1, aPntOnF2;
703 IntTools_PntOn2Faces aPntOn2Faces;
704 //
705 aNbPnts=myIntersector.NbPnts();
706 for (i=1; i<=aNbPnts; ++i) {
707 const IntSurf_PntOn2S& aISPnt=myIntersector.Point(i).PntOn2S();
708 const gp_Pnt& aPnt=aISPnt.Value();
709 aISPnt.Parameters(U1,V1,U2,V2);
710 aPntOnF1.Init(myFace1, aPnt, U1, V1);
711 aPntOnF2.Init(myFace2, aPnt, U2, V2);
712 //
713 if (!bReverse) {
714 aPntOn2Faces.SetP1(aPntOnF1);
715 aPntOn2Faces.SetP2(aPntOnF2);
716 }
717 else {
718 aPntOn2Faces.SetP2(aPntOnF1);
719 aPntOn2Faces.SetP1(aPntOnF2);
720 }
721 myPnts.Append(aPntOn2Faces);
722 }
723 //
724 }
725}
726//=======================================================================
727//function :ComputeTolReached3d
728//purpose :
729//=======================================================================
730 void IntTools_FaceFace::ComputeTolReached3d()
731{
732 Standard_Integer aNbLin;
733 GeomAbs_SurfaceType aType1, aType2;
734 //
735 aNbLin=myIntersector.NbLines();
736 aType1=myHS1->Surface().GetType();
737 aType2=myHS2->Surface().GetType();
738 //
739 if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
740 if (aNbLin==2){
741 Handle(IntPatch_Line) aIL1, aIL2;
742 IntPatch_IType aTL1, aTL2;
743 //
744 aIL1=myIntersector.Line(1);
745 aIL2=myIntersector.Line(2);
746 aTL1=aIL1->ArcType();
747 aTL2=aIL2->ArcType();
748 if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) {
749 Standard_Real aD, aDTresh, dTol;
750 gp_Lin aL1, aL2;
751 //
752 dTol=1.e-8;
753 aDTresh=1.5e-6;
754 //
755 aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line();
756 aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line();
757 aD=aL1.Distance(aL2);
758 aD=0.5*aD;
759 if (aD<aDTresh) {
760 myTolReached3d=aD+dTol;
761 }
762 return;
763 }
764 }
765 //ZZ
766
767 {// Check the distances
768 Standard_Integer i, j, aNbP;
769 Standard_Real aT, aT1, aT2, dT, aD2, aD2Max;
770 //
771 aD2Max=0.;
772 aNbP=11;
773 aNbLin=mySeqOfCurve.Length();
774 //
775 for (i=1; i<=aNbLin; ++i) {
776 const IntTools_Curve& aIC=mySeqOfCurve(i);
777 const Handle(Geom_Curve)& aC3D=aIC.Curve();
778 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
779 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
780 //
781 if (aC3D.IsNull()) {
782 continue;
783 }
784 const Handle(Geom_BSplineCurve)& aBC=
785 Handle(Geom_BSplineCurve)::DownCast(aC3D);
786 if (aBC.IsNull()) {
787 continue;
788 }
789 //
790 aT1=aBC->FirstParameter();
791 aT2=aBC->LastParameter();
792 //
793 dT=(aT2-aT1)/(aNbP-1);
794 for (j=0; j<aNbP; ++j) {
795 aT=aT1+j*dT;
796 if (j==aNbP-1) {
797 aT=aT2;
798 }
799 aD2=MaxSquareDistance(aT, aC3D, aC2D1, aC2D2,
800 myHS1, myHS2, myFace1, myFace2, myContext);
801 if (aD2>aD2Max) {
802 aD2Max=aD2;
803 }
804 }//for (j=0; j<aNbP; ++j) {
805 }//for (i=1; i<=aNbLin; ++i) {
806 //
807 myTolReached3d=sqrt(aD2Max);
808 }
809
810 }// if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
811 //
812 //904/G3 f
813 else if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
814 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
815 //
816 aTolTresh=1.e-7;
817 //
818 aTolF1 = BRep_Tool::Tolerance(myFace1);
819 aTolF2 = BRep_Tool::Tolerance(myFace2);
820 aTolFMax=Max(aTolF1, aTolF2);
821 //
822 if (aTolFMax>aTolTresh) {
823 myTolReached3d=aTolFMax;
824 }
825 }//if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
826 //t
827 //IFV Bug OCC20297
828 else if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ||
829 (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) {
830 if(aNbLin == 1) {
831 const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1);
832 if(aIL1->ArcType() == IntPatch_Circle) {
833 gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle();
834 gp_XYZ aCirDir = aCir.Axis().Direction().XYZ();
835 gp_XYZ aPlDir;
836 gp_Pln aPln;
837 if(aType1 == GeomAbs_Plane) {
838 aPln = myHS1->Surface().Plane();
839 }
840 else {
841 aPln = myHS2->Surface().Plane();
842 }
843 aPlDir = aPln.Axis().Direction().XYZ();
844 Standard_Real cs = aCirDir*aPlDir;
845 if(cs < 0.) aPlDir.Reverse();
846 Standard_Real eps = 1.e-14;
847 if(!aPlDir.IsEqual(aCirDir, eps)) {
848 Standard_Integer aNbP = 11;
849 Standard_Real dt = 2.*M_PI / (aNbP - 1), t;
850 for(t = 0.; t < 2.*M_PI; t += dt) {
851 Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir));
852 if(myTolReached3d < d) myTolReached3d = d;
853 }
854 myTolReached3d *= 1.1;
855 }
856 } //aIL1->ArcType() == IntPatch_Circle
857 } //aNbLin == 1
858 } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane)
859 //End IFV Bug OCC20297
860 //
861 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
862 (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) {
863 aNbLin=mySeqOfCurve.Length();
864 if (aNbLin!=1) {
865 return;
866 }
867 //
868 Standard_Integer i, aNbP;
869 Standard_Real aT, aT1, aT2, dT, aUT, aVT, aUP, aVP;
870 Standard_Real aDP, aDT, aDmax;
871 gp_Pln aPln;
872 gp_Torus aTorus;
873 gp_Pnt aP, aPP, aPT;
874 //
875 const IntTools_Curve& aIC=mySeqOfCurve(1);
876 const Handle(Geom_Curve)& aC3D=aIC.Curve();
877 const Handle(Geom_BSplineCurve)& aBS=
878 Handle(Geom_BSplineCurve)::DownCast(aC3D);
879 if (aBS.IsNull()) {
880 return;
881 }
882 //
883 aT1=aBS->FirstParameter();
884 aT2=aBS->LastParameter();
885 //
886 aPln =(aType1==GeomAbs_Plane) ? myHS1->Plane() : myHS2->Plane();
887 aTorus=(aType1==GeomAbs_Plane) ? myHS2->Torus() : myHS1->Torus();
888 //
889 aDmax=-1.;
890 aNbP=11;
891 dT=(aT2-aT1)/(aNbP-1);
892 for (i=0; i<aNbP; ++i) {
893 aT=aT1+i*dT;
894 if (i==aNbP-1) {
895 aT=aT2;
896 }
897 //
898 aC3D->D0(aT, aP);
899 //
900 ElSLib::Parameters(aPln, aP, aUP, aVP);
901 aPP=ElSLib::Value(aUP, aVP, aPln);
902 aDP=aP.SquareDistance(aPP);
903 if (aDP>aDmax) {
904 aDmax=aDP;
905 }
906 //
907 ElSLib::Parameters(aTorus, aP, aUT, aVT);
908 aPT=ElSLib::Value(aUT, aVT, aTorus);
909 aDT=aP.SquareDistance(aPT);
910 if (aDT>aDmax) {
911 aDmax=aDT;
912 }
913 }
914 //
915 if (aDmax > myTolReached3d*myTolReached3d) {
916 myTolReached3d=sqrt(aDmax);
917 myTolReached3d=1.1*myTolReached3d;
918 }
919 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
920 //
921 else if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) ||
922 (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder)) {
923 Standard_Integer i, j, aNbP;
924 Standard_Real aT, aT1, aT2, dT, aD2max, aD2;
925 //
926 aNbLin=mySeqOfCurve.Length();
927 aD2max=0.;
928 aNbP=11;
929 //
930 for (i=1; i<=aNbLin; ++i) {
931 const IntTools_Curve& aIC=mySeqOfCurve(i);
932 const Handle(Geom_Curve)& aC3D=aIC.Curve();
933 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
934 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
935 //
936 if (aC3D.IsNull()) {
937 continue;
938 }
939 const Handle(Geom_BSplineCurve)& aBC=
940 Handle(Geom_BSplineCurve)::DownCast(aC3D);
941 if (aBC.IsNull()) {
942 return;
943 }
944 //
945 aT1=aBC->FirstParameter();
946 aT2=aBC->LastParameter();
947 //
948 dT=(aT2-aT1)/(aNbP-1);
949 for (j=0; j<aNbP; ++j) {
950 aT=aT1+j*dT;
951 if (j==aNbP-1) {
952 aT=aT2;
953 }
954 //
955 aD2=MaxSquareDistance(aT, aC3D, aC2D1, aC2D2,
956 myHS1, myHS2, myFace1, myFace2, myContext);
957 if (aD2>aD2max) {
958 aD2max=aD2;
959 }
960 }//for (j=0; j<aNbP; ++j) {
961 }//for (i=1; i<=aNbLin; ++i) {
962 //
963 aD2=myTolReached3d*myTolReached3d;
964 if (aD2max > aD2) {
965 myTolReached3d=sqrt(aD2max);
966 }
967 }//if((aType1==GeomAbs_SurfaceOfRevolution ...
968}
969//=======================================================================
970//function : MakeCurve
971//purpose :
972//=======================================================================
973 void IntTools_FaceFace::MakeCurve(const Standard_Integer Index,
974 const Handle(Adaptor3d_TopolTool)& dom1,
975 const Handle(Adaptor3d_TopolTool)& dom2)
976{
977 Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor;
978 Standard_Boolean ok;
979 Standard_Integer i, j, aNbParts;
980 Standard_Real fprm, lprm;
981 Standard_Real Tolpc;
982 Handle(IntPatch_Line) L;
983 IntPatch_IType typl;
984 Handle(Geom_Curve) newc;
985 //
986 const Standard_Real TOLCHECK =0.0000001;
987 const Standard_Real TOLANGCHECK=0.1;
988 //
989 rejectSurface = Standard_False;
990 reApprox = Standard_False;
991
992 reapprox:;
993
994 Tolpc = myTolApprox;
995 bAvoidLineConstructor = Standard_False;
996 L = myIntersector.Line(Index);
997 typl = L->ArcType();
998 //
999 if(typl==IntPatch_Walking) {
1000 Handle(IntPatch_Line) anewL;
1001 //
1002 const Handle(IntPatch_WLine)& aWLine=
1003 Handle(IntPatch_WLine)::DownCast(L);
1004 //DEBf
1005 //DumpWLine(aWLine);
1006 //DEBt
1007 anewL = ComputePurgedWLine(aWLine);
1008 if(anewL.IsNull()) {
1009 return;
1010 }
1011 L = anewL;
1012 //DEBf
1013 /*
1014 { const Handle(IntPatch_WLine)& aWLineX=
1015 Handle(IntPatch_WLine)::DownCast(L);
1016 DumpWLine(aWLineX);
1017 }
1018 */
1019 //DEBt
1020 //
1021 if(!myListOfPnts.IsEmpty()) {
1022 bAvoidLineConstructor = Standard_True;
1023 }
1024
1025 Standard_Integer nbp = aWLine->NbPnts();
1026 const IntSurf_PntOn2S& p1 = aWLine->Point(1);
1027 const IntSurf_PntOn2S& p2 = aWLine->Point(nbp);
1028
1029 const gp_Pnt& P1 = p1.Value();
1030 const gp_Pnt& P2 = p2.Value();
1031
1032 if(P1.SquareDistance(P2) < 1.e-14) {
1033 bAvoidLineConstructor = Standard_False;
1034 }
1035
1036 }
1037 //
1038 // Line Constructor
1039 if(!bAvoidLineConstructor) {
1040 myLConstruct.Perform(L);
1041 //
1042 bDone=myLConstruct.IsDone();
1043 aNbParts=myLConstruct.NbParts();
1044 if (!bDone|| !aNbParts) {
1045 return;
1046 }
1047 }
1048 // Do the Curve
1049
1050
1051 typl=L->ArcType();
1052 switch (typl) {
1053 //########################################
1054 // Line, Parabola, Hyperbola
1055 //########################################
1056 case IntPatch_Lin:
1057 case IntPatch_Parabola:
1058 case IntPatch_Hyperbola: {
1059 if (typl == IntPatch_Lin) {
1060 newc =
1061 new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
1062 }
1063
1064 else if (typl == IntPatch_Parabola) {
1065 newc =
1066 new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
1067 }
1068
1069 else if (typl == IntPatch_Hyperbola) {
1070 newc =
1071 new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
1072 }
1073 //
1074 // myTolReached3d
1075 if (typl == IntPatch_Lin) {
1076 TolR3d (myFace1, myFace2, myTolReached3d);
1077 }
1078 //
1079 aNbParts=myLConstruct.NbParts();
1080 for (i=1; i<=aNbParts; i++) {
1081 myLConstruct.Part(i, fprm, lprm);
1082
1083 if (!Precision::IsNegativeInfinite(fprm) &&
1084 !Precision::IsPositiveInfinite(lprm)) {
1085 //
1086 IntTools_Curve aCurve;
1087 //
1088 Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
1089 aCurve.SetCurve(aCT3D);
1090 if (typl == IntPatch_Parabola) {
1091 Standard_Real aTolF1, aTolF2, aTolBase;
1092
1093 aTolF1 = BRep_Tool::Tolerance(myFace1);
1094 aTolF2 = BRep_Tool::Tolerance(myFace2);
1095 aTolBase=aTolF1+aTolF2;
1096 myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
1097 }
1098 //
1099 aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
1100 if(myApprox1) {
1101 Handle (Geom2d_Curve) C2d;
1102 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1103 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1104 myTolReached2d=Tolpc;
1105 }
1106 //
1107 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1108 }
1109 else {
1110 Handle(Geom2d_BSplineCurve) H1;
1111 //
1112 aCurve.SetFirstCurve2d(H1);
1113 }
1114
1115 if(myApprox2) {
1116 Handle (Geom2d_Curve) C2d;
1117 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1118 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1119 myTolReached2d=Tolpc;
1120 }
1121 //
1122 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1123 }
1124 else {
1125 Handle(Geom2d_BSplineCurve) H1;
1126 //
1127 aCurve.SetSecondCurve2d(H1);
1128 }
1129 mySeqOfCurve.Append(aCurve);
1130 } // end of if (!Precision::IsNegativeInfinite(fprm) && !Precision::IsPositiveInfinite(lprm))
1131
1132 else {
1133 // on regarde si on garde
1134 //
1135 Standard_Boolean bFNIt, bLPIt;
1136 Standard_Real aTestPrm, dT=100.;
1137
1138 bFNIt=Precision::IsNegativeInfinite(fprm);
1139 bLPIt=Precision::IsPositiveInfinite(lprm);
1140
1141 aTestPrm=0.;
1142
1143 if (bFNIt && !bLPIt) {
1144 aTestPrm=lprm-dT;
1145 }
1146 else if (!bFNIt && bLPIt) {
1147 aTestPrm=fprm+dT;
1148 }
1149
1150 gp_Pnt ptref(newc->Value(aTestPrm));
1151 //
1152
1153 Standard_Real u1, v1, u2, v2, Tol;
1154
1155 Tol = Precision::Confusion();
1156 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1157 ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
1158 if(ok) {
1159 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1160 }
1161 if (ok) {
1162 Handle(Geom2d_BSplineCurve) H1;
1163 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1164 }
1165 }
1166 }// end of for (i=1; i<=myLConstruct.NbParts(); i++)
1167 }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola:
1168 break;
1169
1170 //########################################
1171 // Circle and Ellipse
1172 //########################################
1173 case IntPatch_Circle:
1174 case IntPatch_Ellipse: {
1175
1176 if (typl == IntPatch_Circle) {
1177 newc = new Geom_Circle
1178 (Handle(IntPatch_GLine)::DownCast(L)->Circle());
1179 }
1180 else { //IntPatch_Ellipse
1181 newc = new Geom_Ellipse
1182 (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
1183 }
1184 //
1185 // myTolReached3d
1186 TolR3d (myFace1, myFace2, myTolReached3d);
1187 //
1188 aNbParts=myLConstruct.NbParts();
1189 //
1190 Standard_Real aPeriod, aNul;
1191 TColStd_SequenceOfReal aSeqFprm, aSeqLprm;
1192
1193 aNul=0.;
1194 aPeriod=M_PI+M_PI;
1195
1196 for (i=1; i<=aNbParts; i++) {
1197 myLConstruct.Part(i, fprm, lprm);
1198
1199 if (fprm < aNul && lprm > aNul) {
1200 // interval that goes through 0. is divided on two intervals;
1201 while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
1202 while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
1203 //
1204 if((aPeriod - fprm) > Tolpc) {
1205 aSeqFprm.Append(fprm);
1206 aSeqLprm.Append(aPeriod);
1207 }
1208 else {
1209 gp_Pnt P1 = newc->Value(fprm);
1210 gp_Pnt P2 = newc->Value(aPeriod);
1211 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1212 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1213
1214 if(P1.Distance(P2) > aTolDist) {
1215 Standard_Real anewpar = fprm;
1216
1217 if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2, lprm, Standard_False, anewpar, myContext)) {
1218 fprm = anewpar;
1219 }
1220 aSeqFprm.Append(fprm);
1221 aSeqLprm.Append(aPeriod);
1222 }
1223 }
1224
1225 //
1226 if((lprm - aNul) > Tolpc) {
1227 aSeqFprm.Append(aNul);
1228 aSeqLprm.Append(lprm);
1229 }
1230 else {
1231 gp_Pnt P1 = newc->Value(aNul);
1232 gp_Pnt P2 = newc->Value(lprm);
1233 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1234 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1235
1236 if(P1.Distance(P2) > aTolDist) {
1237 Standard_Real anewpar = lprm;
1238
1239 if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2, fprm, Standard_True, anewpar, myContext)) {
1240 lprm = anewpar;
1241 }
1242 aSeqFprm.Append(aNul);
1243 aSeqLprm.Append(lprm);
1244 }
1245 }
1246 }
1247 else {
1248 // usual interval
1249 aSeqFprm.Append(fprm);
1250 aSeqLprm.Append(lprm);
1251 }
1252 }
1253
1254 //
1255 aNbParts=aSeqFprm.Length();
1256 for (i=1; i<=aNbParts; i++) {
1257 fprm=aSeqFprm(i);
1258 lprm=aSeqLprm(i);
1259 //
1260 Standard_Real aRealEpsilon=RealEpsilon();
1261 if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*M_PI) > aRealEpsilon) {
1262 //==============================================
1263 ////
1264 IntTools_Curve aCurve;
1265 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1266 aCurve.SetCurve(aTC3D);
1267 fprm=aTC3D->FirstParameter();
1268 lprm=aTC3D->LastParameter ();
1269 ////
1270 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {////
1271 if(myApprox1) {
1272 Handle (Geom2d_Curve) C2d;
1273 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1274 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1275 myTolReached2d=Tolpc;
1276 }
1277 //
1278 aCurve.SetFirstCurve2d(C2d);
1279 }
1280 else { ////
1281 Handle(Geom2d_BSplineCurve) H1;
1282 aCurve.SetFirstCurve2d(H1);
1283 }
1284
1285
1286 if(myApprox2) {
1287 Handle (Geom2d_Curve) C2d;
1288 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1289 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1290 myTolReached2d=Tolpc;
1291 }
1292 //
1293 aCurve.SetSecondCurve2d(C2d);
1294 }
1295 else {
1296 Handle(Geom2d_BSplineCurve) H1;
1297 aCurve.SetSecondCurve2d(H1);
1298 }
1299 }
1300
1301 else {
1302 Handle(Geom2d_BSplineCurve) H1;
1303 aCurve.SetFirstCurve2d(H1);
1304 aCurve.SetSecondCurve2d(H1);
1305 }
1306 mySeqOfCurve.Append(aCurve);
1307 //==============================================
1308 } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon())
1309
1310 else {
1311 // on regarde si on garde
1312 //
1313 if (aNbParts==1) {
1314// if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) {
1315 if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
1316 IntTools_Curve aCurve;
1317 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1318 aCurve.SetCurve(aTC3D);
1319 fprm=aTC3D->FirstParameter();
1320 lprm=aTC3D->LastParameter ();
1321
1322 if(myApprox1) {
1323 Handle (Geom2d_Curve) C2d;
1324 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1325 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1326 myTolReached2d=Tolpc;
1327 }
1328 //
1329 aCurve.SetFirstCurve2d(C2d);
1330 }
1331 else { ////
1332 Handle(Geom2d_BSplineCurve) H1;
1333 aCurve.SetFirstCurve2d(H1);
1334 }
1335
1336 if(myApprox2) {
1337 Handle (Geom2d_Curve) C2d;
1338 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1339 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1340 myTolReached2d=Tolpc;
1341 }
1342 //
1343 aCurve.SetSecondCurve2d(C2d);
1344 }
1345 else {
1346 Handle(Geom2d_BSplineCurve) H1;
1347 aCurve.SetSecondCurve2d(H1);
1348 }
1349 mySeqOfCurve.Append(aCurve);
1350 break;
1351 }
1352 }
1353 //
1354 Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
1355
1356 aTwoPIdiv17=2.*M_PI/17.;
1357
1358 for (j=0; j<=17; j++) {
1359 gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
1360 Tol = Precision::Confusion();
1361
1362 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1363 ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
1364 if(ok) {
1365 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1366 }
1367 if (ok) {
1368 IntTools_Curve aCurve;
1369 aCurve.SetCurve(newc);
1370 //==============================================
1371 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
1372
1373 if(myApprox1) {
1374 Handle (Geom2d_Curve) C2d;
1375 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1376 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1377 myTolReached2d=Tolpc;
1378 }
1379 //
1380 aCurve.SetFirstCurve2d(C2d);
1381 }
1382 else {
1383 Handle(Geom2d_BSplineCurve) H1;
1384 aCurve.SetFirstCurve2d(H1);
1385 }
1386
1387 if(myApprox2) {
1388 Handle (Geom2d_Curve) C2d;
1389 BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
1390 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1391 myTolReached2d=Tolpc;
1392 }
1393 //
1394 aCurve.SetSecondCurve2d(C2d);
1395 }
1396
1397 else {
1398 Handle(Geom2d_BSplineCurve) H1;
1399 aCurve.SetSecondCurve2d(H1);
1400 }
1401 }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
1402
1403 else {
1404 Handle(Geom2d_BSplineCurve) H1;
1405 //
1406 aCurve.SetFirstCurve2d(H1);
1407 aCurve.SetSecondCurve2d(H1);
1408 }
1409 //==============================================
1410 //
1411 mySeqOfCurve.Append(aCurve);
1412 break;
1413
1414 }// end of if (ok) {
1415 }// end of for (Standard_Integer j=0; j<=17; j++)
1416 }// end of else { on regarde si on garde
1417 }// for (i=1; i<=myLConstruct.NbParts(); i++)
1418 }// IntPatch_Circle: IntPatch_Ellipse:
1419 break;
1420
1421 case IntPatch_Analytic: {
1422 IntSurf_Quadric quad1,quad2;
1423 GeomAbs_SurfaceType typs = myHS1->Surface().GetType();
1424
1425 switch (typs) {
1426 case GeomAbs_Plane:
1427 quad1.SetValue(myHS1->Surface().Plane());
1428 break;
1429 case GeomAbs_Cylinder:
1430 quad1.SetValue(myHS1->Surface().Cylinder());
1431 break;
1432 case GeomAbs_Cone:
1433 quad1.SetValue(myHS1->Surface().Cone());
1434 break;
1435 case GeomAbs_Sphere:
1436 quad1.SetValue(myHS1->Surface().Sphere());
1437 break;
1438 default:
1439 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
1440 }
1441
1442 typs = myHS2->Surface().GetType();
1443
1444 switch (typs) {
1445 case GeomAbs_Plane:
1446 quad2.SetValue(myHS2->Surface().Plane());
1447 break;
1448 case GeomAbs_Cylinder:
1449 quad2.SetValue(myHS2->Surface().Cylinder());
1450 break;
1451 case GeomAbs_Cone:
1452 quad2.SetValue(myHS2->Surface().Cone());
1453 break;
1454 case GeomAbs_Sphere:
1455 quad2.SetValue(myHS2->Surface().Sphere());
1456 break;
1457 default:
1458 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
1459 }
1460 //
1461 //=========
1462 IntPatch_ALineToWLine convert (quad1, quad2);
1463
1464 if (!myApprox) {
1465 aNbParts=myLConstruct.NbParts();
1466 for (i=1; i<=aNbParts; i++) {
1467 myLConstruct.Part(i, fprm, lprm);
1468 Handle(IntPatch_WLine) WL =
1469 convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
1470 //
1471 Handle(Geom2d_BSplineCurve) H1;
1472 Handle(Geom2d_BSplineCurve) H2;
1473
1474 if(myApprox1) {
1475 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1476 }
1477
1478 if(myApprox2) {
1479 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1480 }
1481 //
1482 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1483 }
1484 } // if (!myApprox)
1485
1486 else { // myApprox=TRUE
1487 GeomInt_WLApprox theapp3d;
1488 //
1489 Standard_Real tol2d = myTolApprox;
1490 //
1491 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
1492
1493 aNbParts=myLConstruct.NbParts();
1494 for (i=1; i<=aNbParts; i++) {
1495 myLConstruct.Part(i, fprm, lprm);
1496 Handle(IntPatch_WLine) WL =
1497 convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
1498
1499 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
1500
1501 if (!theapp3d.IsDone()) {
1502 //
1503 Handle(Geom2d_BSplineCurve) H1;
1504 Handle(Geom2d_BSplineCurve) H2;
1505
1506 if(myApprox1) {
1507 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1508 }
1509
1510 if(myApprox2) {
1511 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1512 }
1513 //
1514 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1515 }
1516
1517 else {
1518 if(myApprox1 || myApprox2) {
1519 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
1520 myTolReached2d = theapp3d.TolReached2d();
1521 }
1522 }
1523
1524 if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
1525 myTolReached3d = theapp3d.TolReached3d();
1526 }
1527
1528 Standard_Integer aNbMultiCurves, nbpoles;
1529 aNbMultiCurves=theapp3d.NbMultiCurves();
1530 for (j=1; j<=aNbMultiCurves; j++) {
1531 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1532 nbpoles = mbspc.NbPoles();
1533
1534 TColgp_Array1OfPnt tpoles(1, nbpoles);
1535 mbspc.Curve(1, tpoles);
1536 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1537 mbspc.Knots(),
1538 mbspc.Multiplicities(),
1539 mbspc.Degree());
1540
1541 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1542 Check.FixTangent(Standard_True,Standard_True);
1543 //
1544 IntTools_Curve aCurve;
1545 aCurve.SetCurve(BS);
1546
1547 if(myApprox1) {
1548 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1549 mbspc.Curve(2,tpoles2d);
1550 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1551 mbspc.Knots(),
1552 mbspc.Multiplicities(),
1553 mbspc.Degree());
1554
1555 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1556 newCheck.FixTangent(Standard_True,Standard_True);
1557 //
1558 aCurve.SetFirstCurve2d(BS2);
1559 }
1560 else {
1561 Handle(Geom2d_BSplineCurve) H1;
1562 aCurve.SetFirstCurve2d(H1);
1563 }
1564
1565 if(myApprox2) {
1566 TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
1567 Standard_Integer TwoOrThree;
1568 TwoOrThree=myApprox1 ? 3 : 2;
1569 mbspc.Curve(TwoOrThree, tpoles2d);
1570 Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
1571 mbspc.Knots(),
1572 mbspc.Multiplicities(),
1573 mbspc.Degree());
1574
1575 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1576 newCheck.FixTangent(Standard_True,Standard_True);
1577 //
1578 aCurve.SetSecondCurve2d(BS2);
1579 }
1580 else {
1581 Handle(Geom2d_BSplineCurve) H2;
1582 aCurve.SetSecondCurve2d(H2);
1583 }
1584 //
1585 mySeqOfCurve.Append(aCurve);
1586
1587 }// for (j=1; j<=aNbMultiCurves; j++) {
1588 }// else from if (!theapp3d.IsDone())
1589 }// for (i=1; i<=aNbParts; i++) {
1590 }// else { // myApprox=TRUE
1591 }// case IntPatch_Analytic:
1592 break;
1593
1594 case IntPatch_Walking:{
1595 Handle(IntPatch_WLine) WL =
1596 Handle(IntPatch_WLine)::DownCast(L);
1597 //
1598 Standard_Integer ifprm, ilprm;
1599 //
1600 if (!myApprox) {
1601 aNbParts = 1;
1602 if(!bAvoidLineConstructor){
1603 aNbParts=myLConstruct.NbParts();
1604 }
1605 for (i=1; i<=aNbParts; ++i) {
1606 Handle(Geom2d_BSplineCurve) H1, H2;
1607 Handle(Geom_Curve) aBSp;
1608 //
1609 if(bAvoidLineConstructor) {
1610 ifprm = 1;
1611 ilprm = WL->NbPnts();
1612 }
1613 else {
1614 myLConstruct.Part(i, fprm, lprm);
1615 ifprm=(Standard_Integer)fprm;
1616 ilprm=(Standard_Integer)lprm;
1617 }
1618 //
1619 if(myApprox1) {
1620 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1621 }
1622 //
1623 if(myApprox2) {
1624 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1625 }
1626 //
1627 aBSp=MakeBSpline(WL, ifprm, ilprm);
1628 IntTools_Curve aIC(aBSp, H1, H2);
1629 mySeqOfCurve.Append(aIC);
1630 }// for (i=1; i<=aNbParts; ++i) {
1631 }// if (!myApprox) {
1632 //
1633 else { // X
1634 Standard_Boolean bIsDecomposited;
1635 Standard_Integer nbiter, aNbSeqOfL;
1636 Standard_Real tol2d;
1637 IntPatch_SequenceOfLine aSeqOfL;
1638 GeomInt_WLApprox theapp3d;
1639 Approx_ParametrizationType aParType = Approx_ChordLength;
1640 //
1641 Standard_Boolean anApprox1 = myApprox1;
1642 Standard_Boolean anApprox2 = myApprox2;
1643
1644 tol2d = myTolApprox;
1645
1646 GeomAbs_SurfaceType typs1, typs2;
1647 typs1 = myHS1->Surface().GetType();
1648 typs2 = myHS2->Surface().GetType();
1649 Standard_Boolean anWithPC = Standard_True;
1650
1651 if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
1652 anWithPC =
1653 ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
1654 }
1655 else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
1656 anWithPC =
1657 ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
1658 }
1659 if(!anWithPC) {
1660 //aParType = Approx_Centripetal;
1661 myTolApprox = 1.e-5;
1662 anApprox1 = Standard_False;
1663 anApprox2 = Standard_False;
1664 //
1665 tol2d = myTolApprox;
1666 }
1667
1668 if(myHS1 == myHS2) {
1669 //
1670 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1671 rejectSurface = Standard_True;
1672 }
1673 else {
1674 if(reApprox && !rejectSurface)
1675 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1676 else {
1677 Standard_Integer iDegMax, iDegMin, iNbIter;
1678 //
1679 //modified by NIZNHY-PKV Mon Jan 30 14:19:32 2012f
1680 ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter);
1681 theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType);
1682 //
1683 // ApproxParameters(myHS1, myHS2, iDegMin, iDegMax);
1684 // theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, 0, Standard_True, aParType);
1685 //modified by NIZNHY-PKV Mon Jan 30 14:19:35 2012t
1686 }
1687 }
1688 //
1689 Standard_Real aReachedTol = Precision::Confusion();
1690 bIsDecomposited=DecompositionOfWLine(WL,
1691 myHS1,
1692 myHS2,
1693 myFace1,
1694 myFace2,
1695 myLConstruct,
1696 bAvoidLineConstructor,
1697 aSeqOfL,
1698 aReachedTol,
1699 myContext);
1700 if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) )
1701 myTolReached3d = aReachedTol;
1702
1703 //
1704 aNbSeqOfL=aSeqOfL.Length();
1705 //
1706 if (bIsDecomposited) {
1707 nbiter=aNbSeqOfL;
1708 }
1709 else {
1710 nbiter=1;
1711 aNbParts=1;
1712 if (!bAvoidLineConstructor) {
1713 aNbParts=myLConstruct.NbParts();
1714 nbiter=aNbParts;
1715 }
1716 }
1717 //
1718 // nbiter=(bIsDecomposited) ? aSeqOfL.Length() :
1719 // ((bAvoidLineConstructor) ? 1 :aNbParts);
1720 //
1721 for(i = 1; i <= nbiter; ++i) {
1722 if(bIsDecomposited) {
1723 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
1724 ifprm = 1;
1725 ilprm = WL->NbPnts();
1726 }
1727 else {
1728 if(bAvoidLineConstructor) {
1729 ifprm = 1;
1730 ilprm = WL->NbPnts();
1731 }
1732 else {
1733 myLConstruct.Part(i, fprm, lprm);
1734 ifprm = (Standard_Integer)fprm;
1735 ilprm = (Standard_Integer)lprm;
1736 }
1737 }
1738 //-- lbr :
1739 //-- Si une des surfaces est un plan , on approxime en 2d
1740 //-- sur cette surface et on remonte les points 2d en 3d.
1741 if(typs1 == GeomAbs_Plane) {
1742 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
1743 }
1744 else if(typs2 == GeomAbs_Plane) {
1745 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
1746 }
1747 else {
1748 //
1749 if (myHS1 != myHS2){
1750 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
1751 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
1752
1753 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
1754
1755 Standard_Boolean bUseSurfaces;
1756 bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
1757 if (bUseSurfaces) {
1758 // ######
1759 rejectSurface = Standard_True;
1760 // ######
1761 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1762 }
1763 }
1764 }
1765 //
1766 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
1767 }
1768
1769 if (!theapp3d.IsDone()) {
1770 //
1771 Handle(Geom2d_BSplineCurve) H1;
1772 //
1773 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
1774 Handle(Geom2d_BSplineCurve) H2;
1775
1776 if(myApprox1) {
1777 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1778 }
1779
1780 if(myApprox2) {
1781 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1782 }
1783 //
1784 IntTools_Curve aIC(aBSp, H1, H2);
1785 mySeqOfCurve.Append(aIC);
1786 }
1787
1788 else {
1789 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
1790 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
1791 myTolReached2d = theapp3d.TolReached2d();
1792 }
1793 }
1794 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
1795 myTolReached3d = myTolReached2d;
1796 //
1797 if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
1798 if (myTolReached3d<1.e-6) {
1799 myTolReached3d = theapp3d.TolReached3d();
1800 myTolReached3d=1.e-6;
1801 }
1802 }
1803 //
1804 }
1805 else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
1806 myTolReached3d = theapp3d.TolReached3d();
1807 }
1808
1809 Standard_Integer aNbMultiCurves, nbpoles;
1810 aNbMultiCurves=theapp3d.NbMultiCurves();
1811 for (j=1; j<=aNbMultiCurves; j++) {
1812 if(typs1 == GeomAbs_Plane) {
1813 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1814 nbpoles = mbspc.NbPoles();
1815
1816 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1817 TColgp_Array1OfPnt tpoles(1,nbpoles);
1818
1819 mbspc.Curve(1,tpoles2d);
1820 const gp_Pln& Pln = myHS1->Surface().Plane();
1821 //
1822 Standard_Integer ik;
1823 for(ik = 1; ik<= nbpoles; ik++) {
1824 tpoles.SetValue(ik,
1825 ElSLib::Value(tpoles2d.Value(ik).X(),
1826 tpoles2d.Value(ik).Y(),
1827 Pln));
1828 }
1829 //
1830 Handle(Geom_BSplineCurve) BS =
1831 new Geom_BSplineCurve(tpoles,
1832 mbspc.Knots(),
1833 mbspc.Multiplicities(),
1834 mbspc.Degree());
1835 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1836 Check.FixTangent(Standard_True, Standard_True);
1837 //
1838 IntTools_Curve aCurve;
1839 aCurve.SetCurve(BS);
1840
1841 if(myApprox1) {
1842 Handle(Geom2d_BSplineCurve) BS1 =
1843 new Geom2d_BSplineCurve(tpoles2d,
1844 mbspc.Knots(),
1845 mbspc.Multiplicities(),
1846 mbspc.Degree());
1847 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
1848 Check1.FixTangent(Standard_True,Standard_True);
1849 //
1850 // ############################################
1851 if(!rejectSurface && !reApprox) {
1852 Standard_Boolean isValid = IsCurveValid(BS1);
1853 if(!isValid) {
1854 reApprox = Standard_True;
1855 goto reapprox;
1856 }
1857 }
1858 // ############################################
1859 aCurve.SetFirstCurve2d(BS1);
1860 }
1861 else {
1862 Handle(Geom2d_BSplineCurve) H1;
1863 aCurve.SetFirstCurve2d(H1);
1864 }
1865
1866 if(myApprox2) {
1867 mbspc.Curve(2, tpoles2d);
1868
1869 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
1870 mbspc.Knots(),
1871 mbspc.Multiplicities(),
1872 mbspc.Degree());
1873 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1874 newCheck.FixTangent(Standard_True,Standard_True);
1875
1876 // ###########################################
1877 if(!rejectSurface && !reApprox) {
1878 Standard_Boolean isValid = IsCurveValid(BS2);
1879 if(!isValid) {
1880 reApprox = Standard_True;
1881 goto reapprox;
1882 }
1883 }
1884 // ###########################################
1885 //
1886 aCurve.SetSecondCurve2d(BS2);
1887 }
1888 else {
1889 Handle(Geom2d_BSplineCurve) H2;
1890 //
1891 aCurve.SetSecondCurve2d(H2);
1892 }
1893 //
1894 mySeqOfCurve.Append(aCurve);
1895 }
1896
1897 else if(typs2 == GeomAbs_Plane) {
1898 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1899 nbpoles = mbspc.NbPoles();
1900
1901 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1902 TColgp_Array1OfPnt tpoles(1,nbpoles);
1903 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
1904 const gp_Pln& Pln = myHS2->Surface().Plane();
1905 //
1906 Standard_Integer ik;
1907 for(ik = 1; ik<= nbpoles; ik++) {
1908 tpoles.SetValue(ik,
1909 ElSLib::Value(tpoles2d.Value(ik).X(),
1910 tpoles2d.Value(ik).Y(),
1911 Pln));
1912
1913 }
1914 //
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(myApprox2) {
1926 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
1927 mbspc.Knots(),
1928 mbspc.Multiplicities(),
1929 mbspc.Degree());
1930 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
1931 Check1.FixTangent(Standard_True,Standard_True);
1932 //
1933 // ###########################################
1934 if(!rejectSurface && !reApprox) {
1935 Standard_Boolean isValid = IsCurveValid(BS1);
1936 if(!isValid) {
1937 reApprox = Standard_True;
1938 goto reapprox;
1939 }
1940 }
1941 // ###########################################
1942 aCurve.SetSecondCurve2d(BS1);
1943 }
1944 else {
1945 Handle(Geom2d_BSplineCurve) H2;
1946 aCurve.SetSecondCurve2d(H2);
1947 }
1948
1949 if(myApprox1) {
1950 mbspc.Curve(1,tpoles2d);
1951 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1952 mbspc.Knots(),
1953 mbspc.Multiplicities(),
1954 mbspc.Degree());
1955 GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
1956 Check2.FixTangent(Standard_True,Standard_True);
1957 //
1958 // ###########################################
1959 if(!rejectSurface && !reApprox) {
1960 Standard_Boolean isValid = IsCurveValid(BS2);
1961 if(!isValid) {
1962 reApprox = Standard_True;
1963 goto reapprox;
1964 }
1965 }
1966 // ###########################################
1967 aCurve.SetFirstCurve2d(BS2);
1968 }
1969 else {
1970 Handle(Geom2d_BSplineCurve) H1;
1971 //
1972 aCurve.SetFirstCurve2d(H1);
1973 }
1974 //
1975 mySeqOfCurve.Append(aCurve);
1976 }
1977 else {
1978 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1979 nbpoles = mbspc.NbPoles();
1980 TColgp_Array1OfPnt tpoles(1,nbpoles);
1981 mbspc.Curve(1,tpoles);
1982 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1983 mbspc.Knots(),
1984 mbspc.Multiplicities(),
1985 mbspc.Degree());
1986 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1987 Check.FixTangent(Standard_True,Standard_True);
1988 //
1989 IntTools_Curve aCurve;
1990 aCurve.SetCurve(BS);
1991
1992 if(myApprox1) {
1993 if(anApprox1) {
1994 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1995 mbspc.Curve(2,tpoles2d);
1996 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
1997 mbspc.Knots(),
1998 mbspc.Multiplicities(),
1999 mbspc.Degree());
2000 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
2001 newCheck.FixTangent(Standard_True,Standard_True);
2002 //
2003 aCurve.SetFirstCurve2d(BS1);
2004 }
2005 else {
2006 Handle(Geom2d_BSplineCurve) BS1;
2007 fprm = BS->FirstParameter();
2008 lprm = BS->LastParameter();
2009
2010 Handle(Geom2d_Curve) C2d;
2011 Standard_Real aTol = myTolApprox;
2012 BuildPCurves(fprm, lprm, aTol, myHS1->ChangeSurface().Surface(), BS, C2d);
2013 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2014 aCurve.SetFirstCurve2d(BS1);
2015 }
2016
2017 }
2018 else {
2019 Handle(Geom2d_BSplineCurve) H1;
2020 //
2021 aCurve.SetFirstCurve2d(H1);
2022 }
2023 if(myApprox2) {
2024 if(anApprox2) {
2025 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2026 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
2027 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
2028 mbspc.Knots(),
2029 mbspc.Multiplicities(),
2030 mbspc.Degree());
2031 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2032 newCheck.FixTangent(Standard_True,Standard_True);
2033 //
2034 aCurve.SetSecondCurve2d(BS2);
2035 }
2036 else {
2037 Handle(Geom2d_BSplineCurve) BS2;
2038 fprm = BS->FirstParameter();
2039 lprm = BS->LastParameter();
2040
2041 Handle(Geom2d_Curve) C2d;
2042 Standard_Real aTol = myTolApprox;
2043 BuildPCurves(fprm, lprm, aTol, myHS2->ChangeSurface().Surface(), BS, C2d);
2044 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2045 aCurve.SetSecondCurve2d(BS2);
2046 }
2047
2048 }
2049 else {
2050 Handle(Geom2d_BSplineCurve) H2;
2051 //
2052 aCurve.SetSecondCurve2d(H2);
2053 }
2054 //
2055 mySeqOfCurve.Append(aCurve);
2056 }
2057 }
2058 }
2059 }
2060 }// else { // X
2061 }// case IntPatch_Walking:{
2062 break;
2063
2064 case IntPatch_Restriction:
2065 break;
2066
2067 }
2068}
2069
2070//=======================================================================
2071//function : BuildPCurves
2072//purpose :
2073//=======================================================================
2074 void BuildPCurves (Standard_Real f,
2075 Standard_Real l,
2076 Standard_Real& Tol,
2077 const Handle (Geom_Surface)& S,
2078 const Handle (Geom_Curve)& C,
2079 Handle (Geom2d_Curve)& C2d)
2080{
2081
2082 Standard_Real umin,umax,vmin,vmax;
2083 //
2084
2085 if (C2d.IsNull()) {
2086
2087 // in class ProjLib_Function the range of parameters is shrank by 1.e-09
2088 if((l - f) > 2.e-09) {
2089 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2090 //
2091 if (C2d.IsNull()) {
2092 // proj. a circle that goes through the pole on a sphere to the sphere
2093 Tol=Tol+1.e-7;
2094 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2095 }
2096 }
2097 else {
2098 if((l - f) > Epsilon(Abs(f))) {
2099 GeomAPI_ProjectPointOnSurf aProjector1, aProjector2;
2100 gp_Pnt P1 = C->Value(f);
2101 gp_Pnt P2 = C->Value(l);
2102 aProjector1.Init(P1, S);
2103 aProjector2.Init(P2, S);
2104
2105 if(aProjector1.IsDone() && aProjector2.IsDone()) {
2106 Standard_Real U=0., V=0.;
2107 aProjector1.LowerDistanceParameters(U, V);
2108 gp_Pnt2d p1(U, V);
2109
2110 aProjector2.LowerDistanceParameters(U, V);
2111 gp_Pnt2d p2(U, V);
2112
2113 if(p1.Distance(p2) > gp::Resolution()) {
2114 TColgp_Array1OfPnt2d poles(1,2);
2115 TColStd_Array1OfReal knots(1,2);
2116 TColStd_Array1OfInteger mults(1,2);
2117 poles(1) = p1;
2118 poles(2) = p2;
2119 knots(1) = f;
2120 knots(2) = l;
2121 mults(1) = mults(2) = 2;
2122
2123 C2d = new Geom2d_BSplineCurve(poles,knots,mults,1);
2124
2125 // compute reached tolerance.begin
2126 gp_Pnt PMid = C->Value((f + l) * 0.5);
2127 aProjector1.Perform(PMid);
2128
2129 if(aProjector1.IsDone()) {
2130 aProjector1.LowerDistanceParameters(U, V);
2131 gp_Pnt2d pmidproj(U, V);
2132 gp_Pnt2d pmidcurve2d = C2d->Value((f + l) * 0.5);
2133 Standard_Real adist = pmidcurve2d.Distance(pmidproj);
2134 Tol = (adist > Tol) ? adist : Tol;
2135 }
2136 // compute reached tolerance.end
2137 }
2138 }
2139 }
2140 }
2141 //
2142 S->Bounds(umin, umax, vmin, vmax);
2143
2144 if (S->IsUPeriodic() && !C2d.IsNull()) {
2145 // Recadre dans le domaine UV de la face
2146 Standard_Real period, U0, du, aEps;
2147
2148 du =0.0;
2149 aEps=Precision::PConfusion();
2150 period = S->UPeriod();
2151 gp_Pnt2d Pf = C2d->Value(f);
2152 U0=Pf.X();
2153 //
2154 gp_Pnt2d Pl = C2d->Value(l);
2155
2156 U0 = Min(Pl.X(), U0);
2157// while(U0-umin<aEps) {
2158 while(U0-umin<-aEps) {
2159 U0+=period;
2160 du+=period;
2161 }
2162 //
2163 while(U0-umax>aEps) {
2164 U0-=period;
2165 du-=period;
2166 }
2167 if (du != 0) {
2168 gp_Vec2d T1(du,0.);
2169 C2d->Translate(T1);
2170 }
2171 }
2172 }
2173 if (C2d.IsNull()) {
2174 BOPTColStd_Dump::PrintMessage("BuildPCurves()=> Echec ProjLib\n");
2175 }
2176}
2177
2178//=======================================================================
2179//function : Parameters
2180//purpose :
2181//=======================================================================
2182 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
2183 const Handle(GeomAdaptor_HSurface)& HS2,
2184 const gp_Pnt& Ptref,
2185 Standard_Real& U1,
2186 Standard_Real& V1,
2187 Standard_Real& U2,
2188 Standard_Real& V2)
2189{
2190
2191 IntSurf_Quadric quad1,quad2;
2192 GeomAbs_SurfaceType typs = HS1->Surface().GetType();
2193
2194 switch (typs) {
2195 case GeomAbs_Plane:
2196 quad1.SetValue(HS1->Surface().Plane());
2197 break;
2198 case GeomAbs_Cylinder:
2199 quad1.SetValue(HS1->Surface().Cylinder());
2200 break;
2201 case GeomAbs_Cone:
2202 quad1.SetValue(HS1->Surface().Cone());
2203 break;
2204 case GeomAbs_Sphere:
2205 quad1.SetValue(HS1->Surface().Sphere());
2206 break;
2207 default:
2208 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2209 }
2210
2211 typs = HS2->Surface().GetType();
2212 switch (typs) {
2213 case GeomAbs_Plane:
2214 quad2.SetValue(HS2->Surface().Plane());
2215 break;
2216 case GeomAbs_Cylinder:
2217 quad2.SetValue(HS2->Surface().Cylinder());
2218 break;
2219 case GeomAbs_Cone:
2220 quad2.SetValue(HS2->Surface().Cone());
2221 break;
2222 case GeomAbs_Sphere:
2223 quad2.SetValue(HS2->Surface().Sphere());
2224 break;
2225 default:
2226 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2227 }
2228
2229 quad1.Parameters(Ptref,U1,V1);
2230 quad2.Parameters(Ptref,U2,V2);
2231}
2232
2233//=======================================================================
2234//function : MakeBSpline
2235//purpose :
2236//=======================================================================
2237Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
2238 const Standard_Integer ideb,
2239 const Standard_Integer ifin)
2240{
2241 Standard_Integer i,nbpnt = ifin-ideb+1;
2242 TColgp_Array1OfPnt poles(1,nbpnt);
2243 TColStd_Array1OfReal knots(1,nbpnt);
2244 TColStd_Array1OfInteger mults(1,nbpnt);
2245 Standard_Integer ipidebm1;
2246 for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) {
2247 poles(i) = WL->Point(ipidebm1).Value();
2248 mults(i) = 1;
2249 knots(i) = i-1;
2250 }
2251 mults(1) = mults(nbpnt) = 2;
2252 return
2253 new Geom_BSplineCurve(poles,knots,mults,1);
2254}
2255//
2256
2257//=======================================================================
2258//function : MakeBSpline2d
2259//purpose :
2260//=======================================================================
2261Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
2262 const Standard_Integer ideb,
2263 const Standard_Integer ifin,
2264 const Standard_Boolean onFirst)
2265{
2266 Standard_Integer i, nbpnt = ifin-ideb+1;
2267 TColgp_Array1OfPnt2d poles(1,nbpnt);
2268 TColStd_Array1OfReal knots(1,nbpnt);
2269 TColStd_Array1OfInteger mults(1,nbpnt);
2270 Standard_Integer ipidebm1;
2271
2272 for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
2273 Standard_Real U, V;
2274 if(onFirst)
2275 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
2276 else
2277 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
2278 poles(i).SetCoord(U, V);
2279 mults(i) = 1;
2280 knots(i) = i-1;
2281 }
2282 mults(1) = mults(nbpnt) = 2;
2283
2284 return new Geom2d_BSplineCurve(poles,knots,mults,1);
2285}
2286//=======================================================================
2287//function : PrepareLines3D
2288//purpose :
2289//=======================================================================
2290 void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit)
2291{
2292 Standard_Integer i, aNbCurves;
2293 GeomAbs_SurfaceType aType1, aType2;
2294 IntTools_SequenceOfCurves aNewCvs;
2295 //
2296 // 1. Treatment closed curves
2297 aNbCurves=mySeqOfCurve.Length();
2298 for (i=1; i<=aNbCurves; ++i) {
2299 const IntTools_Curve& aIC=mySeqOfCurve(i);
2300 //
2301 if (bToSplit) {
2302 Standard_Integer j, aNbC;
2303 IntTools_SequenceOfCurves aSeqCvs;
2304 //
2305 aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
2306 if (aNbC) {
2307 for (j=1; j<=aNbC; ++j) {
2308 const IntTools_Curve& aICNew=aSeqCvs(j);
2309 aNewCvs.Append(aICNew);
2310 }
2311 }
2312 else {
2313 aNewCvs.Append(aIC);
2314 }
2315 }
2316 else {
2317 aNewCvs.Append(aIC);
2318 }
2319 }
2320 //
2321 // 2. Plane\Cone intersection when we had 4 curves
2322 aType1=myHS1->GetType();
2323 aType2=myHS2->GetType();
2324 aNbCurves=aNewCvs.Length();
2325 //
2326 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) ||
2327 (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) {
2328 if (aNbCurves==4) {
2329 GeomAbs_CurveType aCType1;
2330 //
2331 aCType1=aNewCvs(1).Type();
2332 if (aCType1==GeomAbs_Line) {
2333 IntTools_SequenceOfCurves aSeqIn, aSeqOut;
2334 //
2335 for (i=1; i<=aNbCurves; ++i) {
2336 const IntTools_Curve& aIC=aNewCvs(i);
2337 aSeqIn.Append(aIC);
2338 }
2339 //
2340 IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
2341 //
2342 aNewCvs.Clear();
2343 aNbCurves=aSeqOut.Length();
2344 for (i=1; i<=aNbCurves; ++i) {
2345 const IntTools_Curve& aIC=aSeqOut(i);
2346 aNewCvs.Append(aIC);
2347 }
2348 }
2349 }
2350 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)...
2351 //
2352 // 3. Fill mySeqOfCurve
2353 mySeqOfCurve.Clear();
2354 aNbCurves=aNewCvs.Length();
2355 for (i=1; i<=aNbCurves; ++i) {
2356 const IntTools_Curve& aIC=aNewCvs(i);
2357 mySeqOfCurve.Append(aIC);
2358 }
2359}
2360//=======================================================================
2361//function : CorrectSurfaceBoundaries
2362//purpose :
2363//=======================================================================
2364 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
2365 const Standard_Real theTolerance,
2366 Standard_Real& theumin,
2367 Standard_Real& theumax,
2368 Standard_Real& thevmin,
2369 Standard_Real& thevmax)
2370{
2371 Standard_Boolean enlarge, isuperiodic, isvperiodic;
2372 Standard_Real uinf, usup, vinf, vsup, delta;
2373 GeomAbs_SurfaceType aType;
2374 Handle(Geom_Surface) aSurface;
2375 //
2376 aSurface = BRep_Tool::Surface(theFace);
2377 aSurface->Bounds(uinf, usup, vinf, vsup);
2378 delta = theTolerance;
2379 enlarge = Standard_False;
2380 //
2381 GeomAdaptor_Surface anAdaptorSurface(aSurface);
2382 //
2383 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
2384 Handle(Geom_Surface) aBasisSurface =
2385 (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface();
2386
2387 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2388 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2389 return;
2390 }
2391 }
2392 //
2393 if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2394 Handle(Geom_Surface) aBasisSurface =
2395 (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface();
2396
2397 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2398 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2399 return;
2400 }
2401 }
2402 //
2403 isuperiodic = anAdaptorSurface.IsUPeriodic();
2404 isvperiodic = anAdaptorSurface.IsVPeriodic();
2405 //
2406 aType=anAdaptorSurface.GetType();
2407 if((aType==GeomAbs_BezierSurface) ||
2408 (aType==GeomAbs_BSplineSurface) ||
2409 (aType==GeomAbs_SurfaceOfExtrusion) ||
2410 (aType==GeomAbs_SurfaceOfRevolution)) {
2411 enlarge=Standard_True;
2412 }
2413 //
2414 if(!isuperiodic && enlarge) {
2415
2416 if((theumin - uinf) > delta )
2417 theumin -= delta;
2418 else {
2419 theumin = uinf;
2420 }
2421
2422 if((usup - theumax) > delta )
2423 theumax += delta;
2424 else
2425 theumax = usup;
2426 }
2427 //
2428 if(!isvperiodic && enlarge) {
2429 if((thevmin - vinf) > delta ) {
2430 thevmin -= delta;
2431 }
2432 else {
2433 thevmin = vinf;
2434 }
2435 if((vsup - thevmax) > delta ) {
2436 thevmax += delta;
2437 }
2438 else {
2439 thevmax = vsup;
2440 }
2441 }
2442 //
2443 {
2444 Standard_Integer aNbP;
2445 Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA;
2446 //
2447 aTolPA=Precision::Angular();
2448 // U
2449 if (isuperiodic) {
2450 aXP=anAdaptorSurface.UPeriod();
2451 dXfact=theumax-theumin;
2452 if (dXfact-aTolPA>aXP) {
2453 aXmid=0.5*(theumax+theumin);
2454 aNbP=RealToInt(aXmid/aXP);
2455 if (aXmid<0.) {
2456 aNbP=aNbP-1;
2457 }
2458 aX1=aNbP*aXP;
2459 if (theumin>aTolPA) {
2460 aX1=theumin+aNbP*aXP;
2461 }
2462 aX2=aX1+aXP;
2463 if (theumin<aX1) {
2464 theumin=aX1;
2465 }
2466 if (theumax>aX2) {
2467 theumax=aX2;
2468 }
2469 }
2470 }
2471 // V
2472 if (isvperiodic) {
2473 aXP=anAdaptorSurface.VPeriod();
2474 dXfact=thevmax-thevmin;
2475 if (dXfact-aTolPA>aXP) {
2476 aXmid=0.5*(thevmax+thevmin);
2477 aNbP=RealToInt(aXmid/aXP);
2478 if (aXmid<0.) {
2479 aNbP=aNbP-1;
2480 }
2481 aX1=aNbP*aXP;
2482 if (thevmin>aTolPA) {
2483 aX1=thevmin+aNbP*aXP;
2484 }
2485 aX2=aX1+aXP;
2486 if (thevmin<aX1) {
2487 thevmin=aX1;
2488 }
2489 if (thevmax>aX2) {
2490 thevmax=aX2;
2491 }
2492 }
2493 }
2494 }
2495 //
2496 if(isuperiodic || isvperiodic) {
2497 Standard_Boolean correct = Standard_False;
2498 Standard_Boolean correctU = Standard_False;
2499 Standard_Boolean correctV = Standard_False;
2500 Bnd_Box2d aBox;
2501 TopExp_Explorer anExp;
2502
2503 for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2504 if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
2505 correct = Standard_True;
2506 Standard_Real f, l;
2507 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
2508
2509 for(Standard_Integer i = 0; i < 2; i++) {
2510 if(i==0) {
2511 anEdge.Orientation(TopAbs_FORWARD);
2512 }
2513 else {
2514 anEdge.Orientation(TopAbs_REVERSED);
2515 }
2516 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
2517
2518 if(aCurve.IsNull()) {
2519 correct = Standard_False;
2520 break;
2521 }
2522 Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
2523
2524 if(aLine.IsNull()) {
2525 correct = Standard_False;
2526 break;
2527 }
2528 gp_Dir2d anUDir(1., 0.);
2529 gp_Dir2d aVDir(0., 1.);
2530 Standard_Real anAngularTolerance = Precision::Angular();
2531
2532 correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
2533 correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
2534
2535 gp_Pnt2d pp1 = aCurve->Value(f);
2536 aBox.Add(pp1);
2537 gp_Pnt2d pp2 = aCurve->Value(l);
2538 aBox.Add(pp2);
2539 }
2540 if(!correct)
2541 break;
2542 }
2543 }
2544
2545 if(correct) {
2546 Standard_Real umin, vmin, umax, vmax;
2547 aBox.Get(umin, vmin, umax, vmax);
2548
2549 if(isuperiodic && correctU) {
2550
2551 if(theumin < umin)
2552 theumin = umin;
2553
2554 if(theumax > umax) {
2555 theumax = umax;
2556 }
2557 }
2558 if(isvperiodic && correctV) {
2559
2560 if(thevmin < vmin)
2561 thevmin = vmin;
2562 if(thevmax > vmax)
2563 thevmax = vmax;
2564 }
2565 }
2566 }
2567}
2568//
2569//
2570// The block is dedicated to determine whether WLine [ifprm, ilprm]
2571// crosses the degenerated zone on each given surface or not.
2572// If Yes -> We will not use info about surfaces during approximation
2573// because inside degenerated zone of the surface the approx. alogo.
2574// uses wrong values of normal, etc., and resulting curve will have
2575// oscillations that we would not like to have.
2576// PKV Tue Feb 12 2002
2577
2578
2579static
2580 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2581 const Handle(Geom_Surface)& aS,
2582 const Standard_Integer iDir);
2583static
2584 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2585 const TopoDS_Face& aF1,
2586 const TopoDS_Face& aF2);
2587//=======================================================================
2588//function : NotUseSurfacesForApprox
2589//purpose :
2590//=======================================================================
2591Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
2592 const TopoDS_Face& aF2,
2593 const Handle(IntPatch_WLine)& WL,
2594 const Standard_Integer ifprm,
2595 const Standard_Integer ilprm)
2596{
2597 Standard_Boolean bPInDZ;
2598
2599 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
2600
2601 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
2602 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
2603 if (bPInDZ) {
2604 return bPInDZ;
2605 }
2606
2607 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
2608 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
2609
2610 return bPInDZ;
2611}
2612//=======================================================================
2613//function : IsPointInDegeneratedZone
2614//purpose :
2615//=======================================================================
2616Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2617 const TopoDS_Face& aF1,
2618 const TopoDS_Face& aF2)
2619
2620{
2621 Standard_Boolean bFlag=Standard_True;
2622 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
2623 Standard_Real U1, V1, U2, V2, aDelta, aD;
2624 gp_Pnt2d aP2d;
2625
2626 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
2627 aS1->Bounds(US11, US12, VS11, VS12);
2628 GeomAdaptor_Surface aGAS1(aS1);
2629
2630 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
2631 aS1->Bounds(US21, US22, VS21, VS22);
2632 GeomAdaptor_Surface aGAS2(aS2);
2633 //
2634 //const gp_Pnt& aP=aP2S.Value();
2635 aP2S.Parameters(U1, V1, U2, V2);
2636 //
2637 aDelta=1.e-7;
2638 // Check on Surf 1
2639 aD=aGAS1.UResolution(aDelta);
2640 aP2d.SetCoord(U1, V1);
2641 if (fabs(U1-US11) < aD) {
2642 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2643 if (bFlag) {
2644 return bFlag;
2645 }
2646 }
2647 if (fabs(U1-US12) < aD) {
2648 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2649 if (bFlag) {
2650 return bFlag;
2651 }
2652 }
2653 aD=aGAS1.VResolution(aDelta);
2654 if (fabs(V1-VS11) < aDelta) {
2655 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2656 if (bFlag) {
2657 return bFlag;
2658 }
2659 }
2660 if (fabs(V1-VS12) < aDelta) {
2661 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2662 if (bFlag) {
2663 return bFlag;
2664 }
2665 }
2666 // Check on Surf 2
2667 aD=aGAS2.UResolution(aDelta);
2668 aP2d.SetCoord(U2, V2);
2669 if (fabs(U2-US21) < aDelta) {
2670 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2671 if (bFlag) {
2672 return bFlag;
2673 }
2674 }
2675 if (fabs(U2-US22) < aDelta) {
2676 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2677 if (bFlag) {
2678 return bFlag;
2679 }
2680 }
2681 aD=aGAS2.VResolution(aDelta);
2682 if (fabs(V2-VS21) < aDelta) {
2683 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2684 if (bFlag) {
2685 return bFlag;
2686 }
2687 }
2688 if (fabs(V2-VS22) < aDelta) {
2689 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2690 if (bFlag) {
2691 return bFlag;
2692 }
2693 }
2694 return !bFlag;
2695}
2696
2697//=======================================================================
2698//function : IsDegeneratedZone
2699//purpose :
2700//=======================================================================
2701Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2702 const Handle(Geom_Surface)& aS,
2703 const Standard_Integer iDir)
2704{
2705 Standard_Boolean bFlag=Standard_True;
2706 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
2707 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
2708 aS->Bounds(US1, US2, VS1, VS2);
2709
2710 gp_Pnt aPm, aPb, aPe;
2711
2712 aXm=aP2d.X();
2713 aYm=aP2d.Y();
2714
2715 aS->D0(aXm, aYm, aPm);
2716
2717 dX=1.e-5;
2718 dY=1.e-5;
2719 dD=1.e-12;
2720
2721 if (iDir==1) {
2722 aXb=aXm;
2723 aXe=aXm;
2724 aYb=aYm-dY;
2725 if (aYb < VS1) {
2726 aYb=VS1;
2727 }
2728 aYe=aYm+dY;
2729 if (aYe > VS2) {
2730 aYe=VS2;
2731 }
2732 aS->D0(aXb, aYb, aPb);
2733 aS->D0(aXe, aYe, aPe);
2734
2735 d1=aPm.Distance(aPb);
2736 d2=aPm.Distance(aPe);
2737 if (d1 < dD && d2 < dD) {
2738 return bFlag;
2739 }
2740 return !bFlag;
2741 }
2742 //
2743 else if (iDir==2) {
2744 aYb=aYm;
2745 aYe=aYm;
2746 aXb=aXm-dX;
2747 if (aXb < US1) {
2748 aXb=US1;
2749 }
2750 aXe=aXm+dX;
2751 if (aXe > US2) {
2752 aXe=US2;
2753 }
2754 aS->D0(aXb, aYb, aPb);
2755 aS->D0(aXe, aYe, aPe);
2756
2757 d1=aPm.Distance(aPb);
2758 d2=aPm.Distance(aPe);
2759 if (d1 < dD && d2 < dD) {
2760 return bFlag;
2761 }
2762 return !bFlag;
2763 }
2764 return !bFlag;
2765}
2766
2767//=========================================================================
2768// static function : ComputePurgedWLine
2769// purpose : Removes equal points (leave one of equal points) from theWLine
2770// and recompute vertex parameters.
2771// Returns new WLine or null WLine if the number
2772// of the points is less than 2.
2773//=========================================================================
2774Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) {
2775
2776 Standard_Integer i, k, v, nb, nbvtx;
2777 Handle(IntPatch_WLine) aResult;
2778 nbvtx = theWLine->NbVertex();
2779 nb = theWLine->NbPnts();
2780 if (nb==2) {
2781 const IntSurf_PntOn2S& p1 = theWLine->Point(1);
2782 const IntSurf_PntOn2S& p2 = theWLine->Point(2);
2783 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2784 return aResult;
2785 }
2786 }
2787 //
2788 Handle(IntPatch_WLine) aLocalWLine;
2789 Handle(IntPatch_WLine) aTmpWLine = theWLine;
2790 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
2791 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2792 for(i = 1; i <= nb; i++) {
2793 aLineOn2S->Add(theWLine->Point(i));
2794 }
2795
2796 for(v = 1; v <= nbvtx; v++) {
2797 aLocalWLine->AddVertex(theWLine->Vertex(v));
2798 }
2799
2800 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
2801 Standard_Integer aStartIndex = i + 1;
2802 Standard_Integer anEndIndex = i + 5;
2803 nb = aLineOn2S->NbPoints();
2804 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
2805
2806 if((aStartIndex > nb) || (anEndIndex <= 1)) {
2807 continue;
2808 }
2809 k = aStartIndex;
2810
2811 while(k <= anEndIndex) {
2812
2813 if(i != k) {
2814 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
2815 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
2816
2817 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2818 aTmpWLine = aLocalWLine;
2819 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2820
2821 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
2822 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
2823 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
2824
2825 if(avertexindex >= k) {
2826 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
2827 }
2828 aLocalWLine->AddVertex(aVertex);
2829 }
2830 aLineOn2S->RemovePoint(k);
2831 anEndIndex--;
2832 continue;
2833 }
2834 }
2835 k++;
2836 }
2837 }
2838
2839 if(aLineOn2S->NbPoints() > 1) {
2840 aResult = aLocalWLine;
2841 }
2842 return aResult;
2843}
2844
2845//=======================================================================
2846//function : TolR3d
2847//purpose :
2848//=======================================================================
2849void TolR3d(const TopoDS_Face& aF1,
2850 const TopoDS_Face& aF2,
2851 Standard_Real& myTolReached3d)
2852{
2853 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
2854
2855 aTolTresh=2.999999e-3;
2856 aTolF1 = BRep_Tool::Tolerance(aF1);
2857 aTolF2 = BRep_Tool::Tolerance(aF2);
2858 aTolFMax=Max(aTolF1, aTolF2);
2859
2860 if (aTolFMax>aTolTresh) {
2861 myTolReached3d=aTolFMax;
2862 }
2863}
2864//=======================================================================
2865//function : AdjustPeriodic
2866//purpose :
2867//=======================================================================
2868Standard_Real AdjustPeriodic(const Standard_Real theParameter,
2869 const Standard_Real parmin,
2870 const Standard_Real parmax,
2871 const Standard_Real thePeriod,
2872 Standard_Real& theOffset)
2873{
2874 Standard_Real aresult;
2875 //
2876 theOffset = 0.;
2877 aresult = theParameter;
2878 while(aresult < parmin) {
2879 aresult += thePeriod;
2880 theOffset += thePeriod;
2881 }
2882
2883 while(aresult > parmax) {
2884 aresult -= thePeriod;
2885 theOffset -= thePeriod;
2886 }
2887 return aresult;
2888}
2889//=======================================================================
2890//function : IsPointOnBoundary
2891//purpose :
2892//=======================================================================
2893Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
2894 const Standard_Real theFirstBoundary,
2895 const Standard_Real theSecondBoundary,
2896 const Standard_Real theResolution,
2897 Standard_Boolean& IsOnFirstBoundary)
2898{
2899 Standard_Boolean bRet;
2900 Standard_Integer i;
2901 Standard_Real adist;
2902 //
2903 bRet=Standard_False;
2904 for(i = 0; i < 2; ++i) {
2905 IsOnFirstBoundary = (i == 0);
2906 if (IsOnFirstBoundary) {
2907 adist = fabs(theParameter - theFirstBoundary);
2908 }
2909 else {
2910 adist = fabs(theParameter - theSecondBoundary);
2911 }
2912 if(adist < theResolution) {
2913 return !bRet;
2914 }
2915 }
2916 return bRet;
2917}
2918// ------------------------------------------------------------------------------------------------
2919// static function: FindPoint
2920// purpose:
2921// ------------------------------------------------------------------------------------------------
2922Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
2923 const gp_Pnt2d& theLastPoint,
2924 const Standard_Real theUmin,
2925 const Standard_Real theUmax,
2926 const Standard_Real theVmin,
2927 const Standard_Real theVmax,
2928 gp_Pnt2d& theNewPoint) {
2929
2930 gp_Vec2d aVec(theFirstPoint, theLastPoint);
2931 Standard_Integer i = 0, j = 0;
2932
2933 for(i = 0; i < 4; i++) {
2934 gp_Vec2d anOtherVec;
2935 gp_Vec2d anOtherVecNormal;
2936 gp_Pnt2d aprojpoint = theLastPoint;
2937
2938 if((i % 2) == 0) {
2939 anOtherVec.SetX(0.);
2940 anOtherVec.SetY(1.);
2941 anOtherVecNormal.SetX(1.);
2942 anOtherVecNormal.SetY(0.);
2943
2944 if(i < 2)
2945 aprojpoint.SetX(theUmin);
2946 else
2947 aprojpoint.SetX(theUmax);
2948 }
2949 else {
2950 anOtherVec.SetX(1.);
2951 anOtherVec.SetY(0.);
2952 anOtherVecNormal.SetX(0.);
2953 anOtherVecNormal.SetY(1.);
2954
2955 if(i < 2)
2956 aprojpoint.SetY(theVmin);
2957 else
2958 aprojpoint.SetY(theVmax);
2959 }
2960 gp_Vec2d anormvec = aVec;
2961 anormvec.Normalize();
2962 RefineVector(anormvec);
2963 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
2964
2965 if(fabs(adot1) < Precision::Angular())
2966 continue;
2967 Standard_Real adist = 0.;
2968 Standard_Boolean bIsOut = Standard_False;
2969
2970 if((i % 2) == 0) {
2971 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
2972 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
2973 }
2974 else {
2975 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
2976 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
2977 }
2978 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
2979
2980 for(j = 0; j < 2; j++) {
2981 anoffset = (j == 0) ? anoffset : -anoffset;
2982 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
2983 gp_Vec2d acurvec(theLastPoint, acurpoint);
2984 if ( bIsOut )
2985 acurvec.Reverse();
2986
2987 Standard_Real aDotX, anAngleX;
2988 //
2989 aDotX = aVec.Dot(acurvec);
2990 anAngleX = aVec.Angle(acurvec);
2991 //
2992 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
2993 if((i % 2) == 0) {
2994 if((acurpoint.Y() >= theVmin) &&
2995 (acurpoint.Y() <= theVmax)) {
2996 theNewPoint = acurpoint;
2997 return Standard_True;
2998 }
2999 }
3000 else {
3001 if((acurpoint.X() >= theUmin) &&
3002 (acurpoint.X() <= theUmax)) {
3003 theNewPoint = acurpoint;
3004 return Standard_True;
3005 }
3006 }
3007 }
3008 }
3009 }
3010 return Standard_False;
3011}
3012
3013
3014// ------------------------------------------------------------------------------------------------
3015// static function: FindPoint
3016// purpose: Find point on the boundary of radial tangent zone
3017// ------------------------------------------------------------------------------------------------
3018Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3019 const gp_Pnt2d& theLastPoint,
3020 const Standard_Real theUmin,
3021 const Standard_Real theUmax,
3022 const Standard_Real theVmin,
3023 const Standard_Real theVmax,
3024 const gp_Pnt2d& theTanZoneCenter,
3025 const Standard_Real theZoneRadius,
3026 Handle(GeomAdaptor_HSurface) theGASurface,
3027 gp_Pnt2d& theNewPoint) {
3028 theNewPoint = theLastPoint;
3029
3030 if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
3031 return Standard_False;
3032
3033 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3034 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3035
3036 Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3037 gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) );
3038 gp_Circ2d aCircle( anAxis, aRadius );
3039
3040 //
3041 gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() );
3042 Standard_Real aLength = aDir.Magnitude();
3043 if ( aLength <= gp::Resolution() )
3044 return Standard_False;
3045 gp_Lin2d aLine( theFirstPoint, aDir );
3046
3047 //
3048 Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine );
3049 Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength );
3050 Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle );
3051
3052 Standard_Real aTol = aRadius * 0.001;
3053 aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol;
3054
3055 Geom2dAPI_InterCurveCurve anIntersector;
3056 anIntersector.Init( aC1, aC2, aTol );
3057
3058 if ( anIntersector.NbPoints() == 0 )
3059 return Standard_False;
3060
3061 Standard_Boolean aFound = Standard_False;
3062 Standard_Real aMinDist = aLength * aLength;
3063 Standard_Integer i = 0;
3064 for ( i = 1; i <= anIntersector.NbPoints(); i++ ) {
3065 gp_Pnt2d aPInt = anIntersector.Point( i );
3066 if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
3067 if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
3068 ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
3069 theNewPoint = aPInt;
3070 aFound = Standard_True;
3071 }
3072 }
3073 }
3074
3075 return aFound;
3076}
3077
3078// ------------------------------------------------------------------------------------------------
3079// static function: IsInsideTanZone
3080// purpose: Check if point is inside a radial tangent zone
3081// ------------------------------------------------------------------------------------------------
3082Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
3083 const gp_Pnt2d& theTanZoneCenter,
3084 const Standard_Real theZoneRadius,
3085 Handle(GeomAdaptor_HSurface) theGASurface) {
3086
3087 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3088 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3089 Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3090 aRadiusSQR *= aRadiusSQR;
3091 if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR )
3092 return Standard_True;
3093 return Standard_False;
3094}
3095
3096// ------------------------------------------------------------------------------------------------
3097// static function: CheckTangentZonesExist
3098// purpose: Check if tangent zone exists
3099// ------------------------------------------------------------------------------------------------
3100Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
3101 const Handle(GeomAdaptor_HSurface)& theSurface2 )
3102{
3103 if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
3104 ( theSurface2->GetType() != GeomAbs_Torus ) )
3105 return Standard_False;
3106
3107 gp_Torus aTor1 = theSurface1->Torus();
3108 gp_Torus aTor2 = theSurface2->Torus();
3109
3110 if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() )
3111 return Standard_False;
3112
3113 if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) ||
3114 ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) )
3115 return Standard_False;
3116
3117 if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) ||
3118 ( aTor2.MajorRadius() < aTor2.MinorRadius() ) )
3119 return Standard_False;
3120 return Standard_True;
3121}
3122
3123// ------------------------------------------------------------------------------------------------
3124// static function: ComputeTangentZones
3125// purpose:
3126// ------------------------------------------------------------------------------------------------
3127Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
3128 const Handle(GeomAdaptor_HSurface)& theSurface2,
3129 const TopoDS_Face& theFace1,
3130 const TopoDS_Face& theFace2,
3131 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
3132 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
3133 Handle(TColStd_HArray1OfReal)& theResultRadius,
3134 const Handle(IntTools_Context)& aContext)
3135{
3136 Standard_Integer aResult = 0;
3137 if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) )
3138 return aResult;
3139
3140
3141 TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2;
3142 TColStd_SequenceOfReal aSeqResultRad;
3143
3144 gp_Torus aTor1 = theSurface1->Torus();
3145 gp_Torus aTor2 = theSurface2->Torus();
3146
3147 gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() );
3148 gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() );
3149 Standard_Integer j = 0;
3150
3151 for ( j = 0; j < 2; j++ ) {
3152 Standard_Real aCoef = ( j == 0 ) ? -1 : 1;
3153 Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius());
3154 Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius());
3155
3156 gp_Circ aCircle1( anax1, aRadius1 );
3157 gp_Circ aCircle2( anax2, aRadius2 );
3158
3159 // roughly compute radius of tangent zone for perpendicular case
3160 Standard_Real aCriteria = Precision::Confusion() * 0.5;
3161
3162 Standard_Real aT1 = aCriteria;
3163 Standard_Real aT2 = aCriteria;
3164 if ( j == 0 ) {
3165 // internal tangency
3166 Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3167 //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria );
3168 aT1 = 2. * aR * aCriteria;
3169 aT2 = aT1;
3170 }
3171 else {
3172 // external tangency
3173 Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3174 Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3175 Standard_Real aDelta = aRb - aCriteria;
3176 aDelta *= aDelta;
3177 aDelta -= aRm * aRm;
3178 aDelta /= 2. * (aRb - aRm);
3179 aDelta -= 0.5 * (aRb - aRm);
3180
3181 aT1 = 2. * aRm * (aRm - aDelta);
3182 aT2 = aT1;
3183 }
3184 aCriteria = ( aT1 > aT2) ? aT1 : aT2;
3185 if ( aCriteria > 0 )
3186 aCriteria = sqrt( aCriteria );
3187
3188 if ( aCriteria > 0.5 * aTor1.MinorRadius() ) {
3189 // too big zone -> drop to minimum
3190 aCriteria = Precision::Confusion();
3191 }
3192
3193 GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) );
3194 GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) );
3195 Extrema_ExtCC anExtrema(aC1, aC2, 0, 2. * M_PI, 0, 2. * M_PI,
3196 Precision::PConfusion(), Precision::PConfusion());
3197
3198 if ( anExtrema.IsDone() ) {
3199
3200 Standard_Integer i = 0;
3201 for ( i = 1; i <= anExtrema.NbExt(); i++ ) {
3202 if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
3203 continue;
3204
3205 Extrema_POnCurv P1, P2;
3206 anExtrema.Points( i, P1, P2 );
3207
3208 Standard_Boolean bFoundResult = Standard_True;
3209 gp_Pnt2d pr1, pr2;
3210
3211 Standard_Integer surfit = 0;
3212 for ( surfit = 0; surfit < 2; surfit++ ) {
3213 GeomAPI_ProjectPointOnSurf& aProjector =
3214 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3215
3216 gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
3217 aProjector.Perform(aP3d);
3218
3219 if(!aProjector.IsDone())
3220 bFoundResult = Standard_False;
3221 else {
3222 if(aProjector.LowerDistance() > aCriteria) {
3223 bFoundResult = Standard_False;
3224 }
3225 else {
3226 Standard_Real foundU = 0, foundV = 0;
3227 aProjector.LowerDistanceParameters(foundU, foundV);
3228 if ( surfit == 0 )
3229 pr1 = gp_Pnt2d( foundU, foundV );
3230 else
3231 pr2 = gp_Pnt2d( foundU, foundV );
3232 }
3233 }
3234 }
3235 if ( bFoundResult ) {
3236 aSeqResultS1.Append( pr1 );
3237 aSeqResultS2.Append( pr2 );
3238 aSeqResultRad.Append( aCriteria );
3239
3240 // torus is u and v periodic
3241 const Standard_Real twoPI = M_PI + M_PI;
3242 Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
3243 Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
3244
3245 // iteration on period bounds
3246 for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
3247 Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
3248 Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
3249
3250 // iteration on surfaces
3251 for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
3252 Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
3253 Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
3254 TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
3255 TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
3256
3257 if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
3258 aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
3259 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3260 aSeqResultRad.Append( aCriteria );
3261 }
3262 if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
3263 aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
3264 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3265 aSeqResultRad.Append( aCriteria );
3266 }
3267 }
3268 } //
3269 }
3270 }
3271 }
3272 }
3273 aResult = aSeqResultRad.Length();
3274
3275 if ( aResult > 0 ) {
3276 theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult );
3277 theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult );
3278 theResultRadius = new TColStd_HArray1OfReal( 1, aResult );
3279
3280 for ( Standard_Integer i = 1 ; i <= aResult; i++ ) {
3281 theResultOnS1->SetValue( i, aSeqResultS1.Value(i) );
3282 theResultOnS2->SetValue( i, aSeqResultS2.Value(i) );
3283 theResultRadius->SetValue( i, aSeqResultRad.Value(i) );
3284 }
3285 }
3286 return aResult;
3287}
3288
3289// ------------------------------------------------------------------------------------------------
3290// static function: AdjustByNeighbour
3291// purpose:
3292// ------------------------------------------------------------------------------------------------
3293gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
3294 const gp_Pnt2d& theOriginalPoint,
3295 Handle(GeomAdaptor_HSurface) theGASurface) {
3296
3297 gp_Pnt2d ap1 = theaNeighbourPoint;
3298 gp_Pnt2d ap2 = theOriginalPoint;
3299
3300 if ( theGASurface->IsUPeriodic() ) {
3301 Standard_Real aPeriod = theGASurface->UPeriod();
3302 gp_Pnt2d aPTest = ap2;
3303 Standard_Real aSqDistMin = 1.e+100;
3304
3305 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3306 aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt );
3307 Standard_Real dd = ap1.SquareDistance( aPTest );
3308
3309 if ( dd < aSqDistMin ) {
3310 ap2 = aPTest;
3311 aSqDistMin = dd;
3312 }
3313 }
3314 }
3315 if ( theGASurface->IsVPeriodic() ) {
3316 Standard_Real aPeriod = theGASurface->VPeriod();
3317 gp_Pnt2d aPTest = ap2;
3318 Standard_Real aSqDistMin = 1.e+100;
3319
3320 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3321 aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt );
3322 Standard_Real dd = ap1.SquareDistance( aPTest );
3323
3324 if ( dd < aSqDistMin ) {
3325 ap2 = aPTest;
3326 aSqDistMin = dd;
3327 }
3328 }
3329 }
3330 return ap2;
3331}
3332
3333// ------------------------------------------------------------------------------------------------
3334//function: DecompositionOfWLine
3335// purpose:
3336// ------------------------------------------------------------------------------------------------
3337Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
3338 const Handle(GeomAdaptor_HSurface)& theSurface1,
3339 const Handle(GeomAdaptor_HSurface)& theSurface2,
3340 const TopoDS_Face& theFace1,
3341 const TopoDS_Face& theFace2,
3342 const IntTools_LineConstructor& theLConstructor,
3343 const Standard_Boolean theAvoidLConstructor,
3344 IntPatch_SequenceOfLine& theNewLines,
3345 Standard_Real& theReachedTol3d,
3346 const Handle(IntTools_Context)& aContext)
3347{
3348
3349 Standard_Boolean bRet, bAvoidLineConstructor;
3350 Standard_Integer aNbPnts, aNbParts;
3351 //
3352 bRet=Standard_False;
3353 aNbPnts=theWLine->NbPnts();
3354 bAvoidLineConstructor=theAvoidLConstructor;
3355 //
3356 if(!aNbPnts){
3357 return bRet;
3358 }
3359 if (!bAvoidLineConstructor) {
3360 aNbParts=theLConstructor.NbParts();
3361 if (!aNbParts) {
3362 return bRet;
3363 }
3364 }
3365 //
3366 Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary;
3367 Standard_Integer nblines, pit, i, j;
3368 Standard_Real aTol;
3369 TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts);
3370 TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts);
3371 TColStd_ListOfInteger aListOfPointIndex;
3372
3373 Handle(TColgp_HArray1OfPnt2d) aTanZoneS1;
3374 Handle(TColgp_HArray1OfPnt2d) aTanZoneS2;
3375 Handle(TColStd_HArray1OfReal) aTanZoneRadius;
3376 Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2,
3377 aTanZoneS1, aTanZoneS2, aTanZoneRadius, aContext);
3378
3379 //
3380 nblines=0;
3381 aTol=Precision::Confusion();
3382 aTol=0.5*aTol;
3383 bIsPrevPointOnBoundary=Standard_False;
3384 bIsPointOnBoundary=Standard_False;
3385 //
3386 // 1. ...
3387 //
3388 // Points
3389 for(pit = 1; pit <= aNbPnts; ++pit) {
3390 Standard_Boolean bIsOnFirstBoundary, isperiodic;
3391 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
3392 Standard_Real aParameter, anoffset, anAdjustPar;
3393 Standard_Real umin, umax, vmin, vmax;
3394 //
3395 bIsCurrentPointOnBoundary = Standard_False;
3396 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
3397 //
3398 // Surface
3399 for(i = 0; i < 2; ++i) {
3400 Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
3401 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3402 if(!i) {
3403 aPoint.ParametersOnS1(U, V);
3404 }
3405 else {
3406 aPoint.ParametersOnS2(U, V);
3407 }
3408 // U, V
3409 for(j = 0; j < 2; j++) {
3410 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3411 if(!isperiodic){
3412 continue;
3413 }
3414 //
3415 if (!j) {
3416 aResolution=aGASurface->UResolution(aTol);
3417 aPeriod=aGASurface->UPeriod();
3418 alowerboundary=umin;
3419 aupperboundary=umax;
3420 aParameter=U;
3421 }
3422 else {
3423 aResolution=aGASurface->VResolution(aTol);
3424 aPeriod=aGASurface->VPeriod();
3425 alowerboundary=vmin;
3426 aupperboundary=vmax;
3427 aParameter=V;
3428 }
3429
3430 anoffset = 0.;
3431 anAdjustPar = AdjustPeriodic(aParameter,
3432 alowerboundary,
3433 aupperboundary,
3434 aPeriod,
3435 anoffset);
3436 //
3437 bIsOnFirstBoundary = Standard_True;// ?
3438 bIsPointOnBoundary=
3439 IsPointOnBoundary(anAdjustPar,
3440 alowerboundary,
3441 aupperboundary,
3442 aResolution,
3443 bIsOnFirstBoundary);
3444 //
3445 if(bIsPointOnBoundary) {
3446 bIsCurrentPointOnBoundary = Standard_True;
3447 break;
3448 }
3449 else {
3450 // check if a point belong to a tangent zone. Begin
3451 Standard_Integer zIt = 0;
3452 for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
3453 gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3454 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3455
3456 if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
3457 // set boundary flag to split the curve by a tangent zone
3458 bIsPointOnBoundary = Standard_True;
3459 bIsCurrentPointOnBoundary = Standard_True;
3460 if ( theReachedTol3d < aZoneRadius ) {
3461 theReachedTol3d = aZoneRadius;
3462 }
3463 break;
3464 }
3465 }
3466 }
3467 }//for(j = 0; j < 2; j++) {
3468
3469 if(bIsCurrentPointOnBoundary){
3470 break;
3471 }
3472 }//for(i = 0; i < 2; ++i) {
3473 //
3474 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
3475 if(!aListOfPointIndex.IsEmpty()) {
3476 nblines++;
3477 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3478 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3479 aListOfPointIndex.Clear();
3480 }
3481 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
3482 }
3483 aListOfPointIndex.Append(pit);
3484 } //for(pit = 1; pit <= aNbPnts; ++pit) {
3485 //
3486 if(!aListOfPointIndex.IsEmpty()) {
3487 nblines++;
3488 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3489 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3490 aListOfPointIndex.Clear();
3491 }
3492 //
3493 if(nblines<=1) {
3494 return bRet; //Standard_False;
3495 }
3496 //
3497 //
3498 // 2. Correct wlines.begin
3499 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
3500 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S();
3501 //
3502 for(i = 1; i <= nblines; i++) {
3503 if(anArrayOfLineType.Value(i) != 0) {
3504 continue;
3505 }
3506 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3507 if(aListOfIndex.Extent() < 2) {
3508 continue;
3509 }
3510 TColStd_ListOfInteger aListOfFLIndex;
3511
3512 for(j = 0; j < 2; j++) {
3513 Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1);
3514
3515 if((aneighbourindex < 1) || (aneighbourindex > nblines))
3516 continue;
3517
3518 if(anArrayOfLineType.Value(aneighbourindex) == 0)
3519 continue;
3520 const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex);
3521 Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First();
3522 const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
3523
3524 IntSurf_PntOn2S aNewP = aPoint;
3525
3526 for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
3527
3528 Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
3529 Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
3530 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3531 Standard_Real U=0., V=0.;
3532
3533 if(surfit == 0)
3534 aNewP.ParametersOnS1(U, V);
3535 else
3536 aNewP.ParametersOnS2(U, V);
3537 Standard_Integer nbboundaries = 0;
3538
3539 Standard_Boolean bIsNearBoundary = Standard_False;
3540 Standard_Integer aZoneIndex = 0;
3541 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
3542 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
3543
3544
3545 for(Standard_Integer parit = 0; parit < 2; parit++) {
3546 Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3547
3548 Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
3549 Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
3550 Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
3551
3552 Standard_Real aParameter = (parit == 0) ? U : V;
3553 Standard_Boolean bIsOnFirstBoundary = Standard_True;
3554
3555 if(!isperiodic) {
3556 bIsPointOnBoundary=
3557 IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3558 if(bIsPointOnBoundary) {
3559 bIsUBoundary = (parit == 0);
3560 bIsFirstBoundary = bIsOnFirstBoundary;
3561 nbboundaries++;
3562 }
3563 }
3564 else {
3565 Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3566 Standard_Real anoffset = 0.;
3567 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3568
3569 bIsPointOnBoundary=
3570 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3571 if(bIsPointOnBoundary) {
3572 bIsUBoundary = (parit == 0);
3573 bIsFirstBoundary = bIsOnFirstBoundary;
3574 nbboundaries++;
3575 }
3576 else {
3577 //check neighbourhood of boundary
3578 Standard_Real anEpsilon = aResolution * 100.;
3579 Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
3580 anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
3581
3582 bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
3583 anEpsilon, bIsOnFirstBoundary);
3584
3585 }
3586 }
3587 }
3588
3589 // check if a point belong to a tangent zone. Begin
3590 for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
3591 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3592 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3593
3594 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3595 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3596 Standard_Real nU1, nV1;
3597
3598 if(surfit == 0)
3599 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3600 else
3601 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3602 gp_Pnt2d ap1(nU1, nV1);
3603 gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
3604
3605
3606 if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
3607 aZoneIndex = zIt;
3608 bIsNearBoundary = Standard_True;
3609 if ( theReachedTol3d < aZoneRadius ) {
3610 theReachedTol3d = aZoneRadius;
3611 }
3612 }
3613 }
3614 // check if a point belong to a tangent zone. End
3615 Standard_Boolean bComputeLineEnd = Standard_False;
3616
3617 if(nbboundaries == 2) {
3618 //xf
3619 bComputeLineEnd = Standard_True;
3620 //xt
3621 }
3622 else if(nbboundaries == 1) {
3623 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3624
3625 if(isperiodic) {
3626 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
3627 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
3628 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3629 Standard_Real aParameter = (bIsUBoundary) ? U : V;
3630 Standard_Real anoffset = 0.;
3631 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3632
3633 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
3634 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
3635 anotherPar += anoffset;
3636 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3637 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
3638 Standard_Real nU1, nV1;
3639
3640 if(surfit == 0)
3641 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3642 else
3643 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3644
3645 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
3646 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
3647 bComputeLineEnd = Standard_True;
3648 Standard_Boolean bCheckAngle1 = Standard_False;
3649 Standard_Boolean bCheckAngle2 = Standard_False;
3650 gp_Vec2d aNewVec;
3651 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
3652 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
3653
3654 if(((adist1 - adist2) > Precision::PConfusion()) &&
3655 (adist2 < (aPeriod / 4.))) {
3656 bCheckAngle1 = Standard_True;
3657 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
3658
3659 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3660 aNewP.SetValue((surfit == 0), anewU, anewV);
3661 bCheckAngle1 = Standard_False;
3662 }
3663 }
3664 else if(adist1 < (aPeriod / 4.)) {
3665 bCheckAngle2 = Standard_True;
3666 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
3667
3668 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3669 bCheckAngle2 = Standard_False;
3670 }
3671 }
3672
3673 if(bCheckAngle1 || bCheckAngle2) {
3674 // assume there are at least two points in line (see "if" above)
3675 Standard_Integer anindexother = aneighbourpointindex;
3676
3677 while((anindexother <= aListOfIndex.Last()) && (anindexother >= aListOfIndex.First())) {
3678 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
3679 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
3680 Standard_Real nU2, nV2;
3681
3682 if(surfit == 0)
3683 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3684 else
3685 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3686 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
3687
3688 if(aVecOld.SquareMagnitude() <= (gp::Resolution() * gp::Resolution())) {
3689 continue;
3690 }
3691 else {
3692 Standard_Real anAngle = aNewVec.Angle(aVecOld);
3693
3694 if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
3695
3696 if(bCheckAngle1) {
3697 Standard_Real U1, U2, V1, V2;
3698 IntSurf_PntOn2S atmppoint = aNewP;
3699 atmppoint.SetValue((surfit == 0), anewU, anewV);
3700 atmppoint.Parameters(U1, V1, U2, V2);
3701 gp_Pnt P1 = theSurface1->Value(U1, V1);
3702 gp_Pnt P2 = theSurface2->Value(U2, V2);
3703 gp_Pnt P0 = aPoint.Value();
3704
3705 if(P0.IsEqual(P1, aTol) &&
3706 P0.IsEqual(P2, aTol) &&
3707 P1.IsEqual(P2, aTol)) {
3708 bComputeLineEnd = Standard_False;
3709 aNewP.SetValue((surfit == 0), anewU, anewV);
3710 }
3711 }
3712
3713 if(bCheckAngle2) {
3714 bComputeLineEnd = Standard_False;
3715 }
3716 }
3717 break;
3718 }
3719 } // end while(anindexother...)
3720 }
3721 }
3722 }
3723 else if ( bIsNearBoundary ) {
3724 bComputeLineEnd = Standard_True;
3725 }
3726
3727 if(bComputeLineEnd) {
3728
3729 gp_Pnt2d anewpoint;
3730 Standard_Boolean found = Standard_False;
3731
3732 if ( bIsNearBoundary ) {
3733 // re-compute point near natural boundary or near tangent zone
3734 Standard_Real u1, v1, u2, v2;
3735 aNewP.Parameters( u1, v1, u2, v2 );
3736 if(surfit == 0)
3737 anewpoint = gp_Pnt2d( u1, v1 );
3738 else
3739 anewpoint = gp_Pnt2d( u2, v2 );
3740
3741 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3742 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3743 Standard_Real nU1, nV1;
3744
3745 if(surfit == 0)
3746 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3747 else
3748 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3749 gp_Pnt2d ap1(nU1, nV1);
3750 gp_Pnt2d ap2;
3751
3752
3753 if ( aZoneIndex ) {
3754 // exclude point from a tangent zone
3755 anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3756 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
3757 Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
3758
3759 if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
3760 aPZone, aZoneRadius, aGASurface, ap2) ) {
3761 anewpoint = ap2;
3762 found = Standard_True;
3763 }
3764 }
3765 else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
3766 // re-compute point near boundary if shifted on a period
3767 ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3768
3769 if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
3770 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
3771 found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
3772 }
3773 else {
3774 anewpoint = ap2;
3775 aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
3776 }
3777 }
3778 }
3779 else {
3780
3781 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3782 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3783 Standard_Real nU1, nV1;
3784
3785 if(surfit == 0)
3786 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3787 else
3788 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3789 gp_Pnt2d ap1(nU1, nV1);
3790 gp_Pnt2d ap2(nU1, nV1);
3791 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
3792
3793 while((aneighbourpointindex2 <= aListOfIndex.Last()) && (aneighbourpointindex2 >= aListOfIndex.First())) {
3794 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
3795 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
3796 Standard_Real nU2, nV2;
3797
3798 if(surfit == 0)
3799 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3800 else
3801 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3802 ap2.SetX(nU2);
3803 ap2.SetY(nV2);
3804
3805 if(ap1.SquareDistance(ap2) > (gp::Resolution() * gp::Resolution())) {
3806 break;
3807 }
3808 }
3809 found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
3810 }
3811
3812 if(found) {
3813 // check point
3814 Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
3815 GeomAPI_ProjectPointOnSurf& aProjector =
3816 (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
3817 Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
3818
3819 Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
3820
3821 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
3822 aProjector.Perform(aP3d);
3823
3824 if(aProjector.IsDone()) {
3825 if(aProjector.LowerDistance() < aCriteria) {
3826 Standard_Real foundU = U, foundV = V;
3827 aProjector.LowerDistanceParameters(foundU, foundV);
3828
3829 //Correction of projected coordinates. Begin
3830 //Note, it may be shifted on a period
3831 Standard_Integer aneindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3832 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
3833 Standard_Real nUn, nVn;
3834
3835 if(surfit == 0)
3836 aNeighbourPoint.ParametersOnS2(nUn, nVn);
3837 else
3838 aNeighbourPoint.ParametersOnS1(nUn, nVn);
3839 gp_Pnt2d aNeighbour2d(nUn, nVn);
3840 gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
3841 foundU = anAdjustedPoint.X();
3842 foundV = anAdjustedPoint.Y();
3843
3844 if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
3845 ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
3846 // attempt to roughly re-compute point
3847 foundU = ( foundU < umin ) ? umin : foundU;
3848 foundU = ( foundU > umax ) ? umax : foundU;
3849 foundV = ( foundV < vmin ) ? vmin : foundV;
3850 foundV = ( foundV > vmax ) ? vmax : foundV;
3851
3852 GeomAPI_ProjectPointOnSurf& aProjector2 =
3853 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3854
3855 aP3d = aSurfaceOther->Value(foundU, foundV);
3856 aProjector2.Perform(aP3d);
3857
3858 if(aProjector2.IsDone()) {
3859 if(aProjector2.LowerDistance() < aCriteria) {
3860 Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
3861 aProjector2.LowerDistanceParameters(foundU2, foundV2);
3862 anewpoint.SetX(foundU2);
3863 anewpoint.SetY(foundV2);
3864 }
3865 }
3866 }
3867 //Correction of projected coordinates. End
3868
3869 if(surfit == 0)
3870 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
3871 else
3872 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
3873 }
3874 }
3875 }
3876 }
3877 }
3878 aSeqOfPntOn2S->Add(aNewP);
3879 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
3880 }
3881 anArrayOfLineEnds.SetValue(i, aListOfFLIndex);
3882 }
3883 // Correct wlines.end
3884
3885 // Split wlines.begin
3886 Standard_Integer nbiter;
3887 //
3888 nbiter=1;
3889 if (!bAvoidLineConstructor) {
3890 nbiter=theLConstructor.NbParts();
3891 }
3892 //
3893 for(j = 1; j <= nbiter; ++j) {
3894 Standard_Real fprm, lprm;
3895 Standard_Integer ifprm, ilprm;
3896 //
3897 if(bAvoidLineConstructor) {
3898 ifprm = 1;
3899 ilprm = theWLine->NbPnts();
3900 }
3901 else {
3902 theLConstructor.Part(j, fprm, lprm);
3903 ifprm = (Standard_Integer)fprm;
3904 ilprm = (Standard_Integer)lprm;
3905 }
3906
3907 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
3908 //
3909 for(i = 1; i <= nblines; i++) {
3910 if(anArrayOfLineType.Value(i) != 0) {
3911 continue;
3912 }
3913 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3914
3915 if(aListOfIndex.Extent() < 2) {
3916 continue;
3917 }
3918 const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
3919 Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
3920 Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
3921
3922 if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
3923 bhasfirstpoint = (i != 1);
3924 }
3925
3926 if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
3927 bhaslastpoint = (i != nblines);
3928 }
3929 Standard_Boolean bIsFirstInside = ((ifprm >= aListOfIndex.First()) && (ifprm <= aListOfIndex.Last()));
3930 Standard_Boolean bIsLastInside = ((ilprm >= aListOfIndex.First()) && (ilprm <= aListOfIndex.Last()));
3931
3932 if(!bIsFirstInside && !bIsLastInside) {
3933 if((ifprm < aListOfIndex.First()) && (ilprm > aListOfIndex.Last())) {
3934 // append whole line, and boundaries if neccesary
3935 if(bhasfirstpoint) {
3936 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
3937 aLineOn2S->Add(aP);
3938 }
3939 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
3940
3941 for(; anIt.More(); anIt.Next()) {
3942 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
3943 aLineOn2S->Add(aP);
3944 }
3945
3946 if(bhaslastpoint) {
3947 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
3948 aLineOn2S->Add(aP);
3949 }
3950
3951 // check end of split line (end is almost always)
3952 Standard_Integer aneighbour = i + 1;
3953 Standard_Boolean bIsEndOfLine = Standard_True;
3954
3955 if(aneighbour <= nblines) {
3956 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
3957
3958 if((anArrayOfLineType.Value(aneighbour) != 0) &&
3959 (aListOfNeighbourIndex.IsEmpty())) {
3960 bIsEndOfLine = Standard_False;
3961 }
3962 }
3963
3964 if(bIsEndOfLine) {
3965 if(aLineOn2S->NbPoints() > 1) {
3966 Handle(IntPatch_WLine) aNewWLine =
3967 new IntPatch_WLine(aLineOn2S, Standard_False);
3968 theNewLines.Append(aNewWLine);
3969 }
3970 aLineOn2S = new IntSurf_LineOn2S();
3971 }
3972 }
3973 continue;
3974 }
3975 // end if(!bIsFirstInside && !bIsLastInside)
3976
3977 if(bIsFirstInside && bIsLastInside) {
3978 // append inside points between ifprm and ilprm
3979 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
3980
3981 for(; anIt.More(); anIt.Next()) {
3982 if((anIt.Value() < ifprm) || (anIt.Value() > ilprm))
3983 continue;
3984 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
3985 aLineOn2S->Add(aP);
3986 }
3987 }
3988 else {
3989
3990 if(bIsFirstInside) {
3991 // append points from ifprm to last point + boundary point
3992 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
3993
3994 for(; anIt.More(); anIt.Next()) {
3995 if(anIt.Value() < ifprm)
3996 continue;
3997 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
3998 aLineOn2S->Add(aP);
3999 }
4000
4001 if(bhaslastpoint) {
4002 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
4003 aLineOn2S->Add(aP);
4004 }
4005 // check end of split line (end is almost always)
4006 Standard_Integer aneighbour = i + 1;
4007 Standard_Boolean bIsEndOfLine = Standard_True;
4008
4009 if(aneighbour <= nblines) {
4010 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4011
4012 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4013 (aListOfNeighbourIndex.IsEmpty())) {
4014 bIsEndOfLine = Standard_False;
4015 }
4016 }
4017
4018 if(bIsEndOfLine) {
4019 if(aLineOn2S->NbPoints() > 1) {
4020 Handle(IntPatch_WLine) aNewWLine =
4021 new IntPatch_WLine(aLineOn2S, Standard_False);
4022 theNewLines.Append(aNewWLine);
4023 }
4024 aLineOn2S = new IntSurf_LineOn2S();
4025 }
4026 }
4027 // end if(bIsFirstInside)
4028
4029 if(bIsLastInside) {
4030 // append points from first boundary point to ilprm
4031 if(bhasfirstpoint) {
4032 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
4033 aLineOn2S->Add(aP);
4034 }
4035 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4036
4037 for(; anIt.More(); anIt.Next()) {
4038 if(anIt.Value() > ilprm)
4039 continue;
4040 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4041 aLineOn2S->Add(aP);
4042 }
4043 }
4044 //end if(bIsLastInside)
4045 }
4046 }
4047
4048 if(aLineOn2S->NbPoints() > 1) {
4049 Handle(IntPatch_WLine) aNewWLine =
4050 new IntPatch_WLine(aLineOn2S, Standard_False);
4051 theNewLines.Append(aNewWLine);
4052 }
4053 }
4054 // Split wlines.end
4055
4056 return Standard_True;
4057}
4058
4059// ------------------------------------------------------------------------------------------------
4060// static function: ParameterOutOfBoundary
4061// purpose: Computes a new parameter for given curve. The corresponding 2d points
4062// does not lay on any boundary of given faces
4063// ------------------------------------------------------------------------------------------------
4064Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
4065 const Handle(Geom_Curve)& theCurve,
4066 const TopoDS_Face& theFace1,
4067 const TopoDS_Face& theFace2,
4068 const Standard_Real theOtherParameter,
4069 const Standard_Boolean bIncreasePar,
4070 Standard_Real& theNewParameter,
4071 const Handle(IntTools_Context)& aContext)
4072{
4073 Standard_Boolean bIsComputed = Standard_False;
4074 theNewParameter = theParameter;
4075
4076 Standard_Real acurpar = theParameter;
4077 TopAbs_State aState = TopAbs_ON;
4078 Standard_Integer iter = 0;
4079 Standard_Real asumtol = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4080 Standard_Real adelta = asumtol * 0.1;
4081 adelta = (adelta < Precision::Confusion()) ? Precision::Confusion() : adelta;
4082 Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(theFace1);
4083 Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(theFace2);
4084
4085 Standard_Real u1, u2, v1, v2;
4086
4087 GeomAPI_ProjectPointOnSurf aPrj1;
4088 aSurf1->Bounds(u1, u2, v1, v2);
4089 aPrj1.Init(aSurf1, u1, u2, v1, v2);
4090
4091 GeomAPI_ProjectPointOnSurf aPrj2;
4092 aSurf2->Bounds(u1, u2, v1, v2);
4093 aPrj2.Init(aSurf2, u1, u2, v1, v2);
4094
4095 while(aState == TopAbs_ON) {
4096 if(bIncreasePar)
4097 acurpar += adelta;
4098 else
4099 acurpar -= adelta;
4100 gp_Pnt aPCurrent = theCurve->Value(acurpar);
4101 aPrj1.Perform(aPCurrent);
4102 Standard_Real U=0., V=0.;
4103
4104 if(aPrj1.IsDone()) {
4105 aPrj1.LowerDistanceParameters(U, V);
4106 aState = aContext->StatePointFace(theFace1, gp_Pnt2d(U, V));
4107 }
4108
4109 if(aState != TopAbs_ON) {
4110 aPrj2.Perform(aPCurrent);
4111
4112 if(aPrj2.IsDone()) {
4113 aPrj2.LowerDistanceParameters(U, V);
4114 aState = aContext->StatePointFace(theFace2, gp_Pnt2d(U, V));
4115 }
4116 }
4117
4118 if(iter > 11) {
4119 break;
4120 }
4121 iter++;
4122 }
4123
4124 if(iter <= 11) {
4125 theNewParameter = acurpar;
4126 bIsComputed = Standard_True;
4127
4128 if(bIncreasePar) {
4129 if(acurpar >= theOtherParameter)
4130 theNewParameter = theOtherParameter;
4131 }
4132 else {
4133 if(acurpar <= theOtherParameter)
4134 theNewParameter = theOtherParameter;
4135 }
4136 }
4137 return bIsComputed;
4138}
4139
4140//=======================================================================
4141//function : IsCurveValid
4142//purpose :
4143//=======================================================================
4144Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve)
4145{
4146 if(thePCurve.IsNull())
4147 return Standard_False;
4148
4149 Standard_Real tolint = 1.e-10;
4150 Geom2dAdaptor_Curve PCA;
4151 IntRes2d_Domain PCD;
4152 Geom2dInt_GInter PCI;
4153
4154 Standard_Real pf = 0., pl = 0.;
4155 gp_Pnt2d pntf, pntl;
4156
4157 if(!thePCurve->IsClosed() && !thePCurve->IsPeriodic()) {
4158 pf = thePCurve->FirstParameter();
4159 pl = thePCurve->LastParameter();
4160 pntf = thePCurve->Value(pf);
4161 pntl = thePCurve->Value(pl);
4162 PCA.Load(thePCurve);
4163 if(!PCA.IsPeriodic()) {
4164 if(PCA.FirstParameter() > pf) pf = PCA.FirstParameter();
4165 if(PCA.LastParameter() < pl) pl = PCA.LastParameter();
4166 }
4167 PCD.SetValues(pntf,pf,tolint,pntl,pl,tolint);
4168 PCI.Perform(PCA,PCD,tolint,tolint);
4169 if(PCI.IsDone())
4170 if(PCI.NbPoints() > 0) {
4171 return Standard_False;
4172 }
4173 }
4174
4175 return Standard_True;
4176}
4177
4178//=======================================================================
4179//static function : ApproxWithPCurves
4180//purpose : for bug 20964 only
4181//=======================================================================
4182Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
4183 const gp_Sphere& theSph)
4184{
4185 Standard_Boolean bRes = Standard_True;
4186 Standard_Real R1 = theCyl.Radius(), R2 = theSph.Radius();
4187
4188 if(R1 < 2.*R2) return bRes;
4189
4190 gp_Lin anCylAx(theCyl.Axis());
4191
4192 Standard_Real aDist = anCylAx.Distance(theSph.Location());
4193 Standard_Real aDRel = Abs(aDist - R1)/R2;
4194
4195 if(aDRel > .2) return bRes;
4196
4197 Standard_Real par = ElCLib::Parameter(anCylAx, theSph.Location());
4198 gp_Pnt aP = ElCLib::Value(par, anCylAx);
4199 gp_Vec aV(aP, theSph.Location());
4200
4201 Standard_Real dd = aV.Dot(theSph.Position().XDirection());
4202
4203 if(aDist < R1 && dd > 0.) return Standard_False;
4204 if(aDist > R1 && dd < 0.) return Standard_False;
4205
4206
4207 return bRes;
4208}
4209//=======================================================================
4210//function : PerformPlanes
4211//purpose :
4212//=======================================================================
4213void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
4214 const Handle(GeomAdaptor_HSurface)& theS2,
4215 const Standard_Real TolAng,
4216 const Standard_Real TolTang,
4217 const Standard_Boolean theApprox1,
4218 const Standard_Boolean theApprox2,
4219 IntTools_SequenceOfCurves& theSeqOfCurve,
4220 Standard_Boolean& theTangentFaces)
4221{
4222
4223 gp_Pln aPln1 = theS1->Surface().Plane();
4224 gp_Pln aPln2 = theS2->Surface().Plane();
4225
4226 IntAna_QuadQuadGeo aPlnInter(aPln1, aPln2, TolAng, TolTang);
4227
4228 if(!aPlnInter.IsDone()) {
4229 theTangentFaces = Standard_False;
4230 return;
4231 }
4232
4233 IntAna_ResultType aResType = aPlnInter.TypeInter();
4234
4235 if(aResType == IntAna_Same) {
4236 theTangentFaces = Standard_True;
4237 return;
4238 }
4239
4240 theTangentFaces = Standard_False;
4241
4242 if(aResType == IntAna_Empty) {
4243 return;
4244 }
4245
4246 gp_Lin aLin = aPlnInter.Line(1);
4247
4248 ProjLib_Plane aProj;
4249
4250 aProj.Init(aPln1);
4251 aProj.Project(aLin);
4252 gp_Lin2d aLin2d1 = aProj.Line();
4253 //
4254 aProj.Init(aPln2);
4255 aProj.Project(aLin);
4256 gp_Lin2d aLin2d2 = aProj.Line();
4257 //
4258 //classify line2d1 relatively first plane
4259 Standard_Real P11, P12;
4260 Standard_Boolean IsCrossed = ClassifyLin2d(theS1, aLin2d1, TolTang, P11, P12);
4261 if(!IsCrossed) return;
4262 //classify line2d2 relatively second plane
4263 Standard_Real P21, P22;
4264 IsCrossed = ClassifyLin2d(theS2, aLin2d2, TolTang, P21, P22);
4265 if(!IsCrossed) return;
4266
4267 //Analysis of parametric intervals: must have common part
4268
4269 if(P21 >= P12) return;
4270 if(P22 <= P11) return;
4271
4272 Standard_Real pmin, pmax;
4273 pmin = Max(P11, P21);
4274 pmax = Min(P12, P22);
4275
4276 if(pmax - pmin <= TolTang) return;
4277
4278 Handle(Geom_Line) aGLin = new Geom_Line(aLin);
4279
4280 IntTools_Curve aCurve;
4281 Handle(Geom_TrimmedCurve) aGTLin = new Geom_TrimmedCurve(aGLin, pmin, pmax);
4282
4283 aCurve.SetCurve(aGTLin);
4284
4285 if(theApprox1) {
4286 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d1);
4287 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4288 }
4289 else {
4290 Handle(Geom2d_Curve) H1;
4291 aCurve.SetFirstCurve2d(H1);
4292 }
4293 if(theApprox2) {
4294 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d2);
4295 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4296 }
4297 else {
4298 Handle(Geom2d_Curve) H1;
4299 aCurve.SetFirstCurve2d(H1);
4300 }
4301
4302 theSeqOfCurve.Append(aCurve);
4303
4304}
4305
4306//=======================================================================
4307//function : ClassifyLin2d
4308//purpose :
4309//=======================================================================
4310static inline Standard_Boolean INTER(const Standard_Real d1,
4311 const Standard_Real d2,
4312 const Standard_Real tol)
4313{
4314 return (d1 > tol && d2 < -tol) ||
4315 (d1 < -tol && d2 > tol) ||
4316 ((d1 <= tol && d1 >= -tol) && (d2 > tol || d2 < -tol)) ||
4317 ((d2 <= tol && d2 >= -tol) && (d1 > tol || d1 < -tol));
4318}
4319static inline Standard_Boolean COINC(const Standard_Real d1,
4320 const Standard_Real d2,
4321 const Standard_Real tol)
4322{
4323 return (d1 <= tol && d1 >= -tol) && (d2 <= tol && d2 >= -tol);
4324}
4325Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
4326 const gp_Lin2d& theLin2d,
4327 const Standard_Real theTol,
4328 Standard_Real& theP1,
4329 Standard_Real& theP2)
4330
4331{
4332 Standard_Real xmin, xmax, ymin, ymax, d1, d2, A, B, C;
4333 Standard_Real par[2];
4334 Standard_Integer nbi = 0;
4335
4336 xmin = theS->Surface().FirstUParameter();
4337 xmax = theS->Surface().LastUParameter();
4338 ymin = theS->Surface().FirstVParameter();
4339 ymax = theS->Surface().LastVParameter();
4340
4341 theLin2d.Coefficients(A, B, C);
4342
4343 //xmin, ymin <-> xmin, ymax
4344 d1 = A*xmin + B*ymin + C;
4345 d2 = A*xmin + B*ymax + C;
4346
4347 if(INTER(d1, d2, theTol)) {
4348 //Intersection with boundary
4349 Standard_Real y = -(C + A*xmin)/B;
4350 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, y));
4351 nbi++;
4352 }
4353 else if (COINC(d1, d2, theTol)) {
4354 //Coincidence with boundary
4355 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4356 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4357 nbi = 2;
4358 }
4359
4360 if(nbi == 2) {
4361
4362 if(fabs(par[0]-par[1]) > theTol) {
4363 theP1 = Min(par[0], par[1]);
4364 theP2 = Max(par[0], par[1]);
4365 return Standard_True;
4366 }
4367 else return Standard_False;
4368
4369 }
4370
4371 //xmin, ymax <-> xmax, ymax
4372 d1 = d2;
4373 d2 = A*xmax + B*ymax + C;
4374
4375 if(d1 > theTol || d1 < -theTol) {//to avoid checking of
4376 //coincidence with the same point
4377 if(INTER(d1, d2, theTol)) {
4378 Standard_Real x = -(C + B*ymax)/A;
4379 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymax));
4380 nbi++;
4381 }
4382 else if (COINC(d1, d2, theTol)) {
4383 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4384 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4385 nbi = 2;
4386 }
4387 }
4388
4389 if(nbi == 2) {
4390
4391 if(fabs(par[0]-par[1]) > theTol) {
4392 theP1 = Min(par[0], par[1]);
4393 theP2 = Max(par[0], par[1]);
4394 return Standard_True;
4395 }
4396 else return Standard_False;
4397
4398 }
4399
4400 //xmax, ymax <-> xmax, ymin
4401 d1 = d2;
4402 d2 = A*xmax + B*ymin + C;
4403
4404 if(d1 > theTol || d1 < -theTol) {
4405 if(INTER(d1, d2, theTol)) {
4406 Standard_Real y = -(C + A*xmax)/B;
4407 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, y));
4408 nbi++;
4409 }
4410 else if (COINC(d1, d2, theTol)) {
4411 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4412 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4413 nbi = 2;
4414 }
4415 }
4416
4417 if(nbi == 2) {
4418 if(fabs(par[0]-par[1]) > theTol) {
4419 theP1 = Min(par[0], par[1]);
4420 theP2 = Max(par[0], par[1]);
4421 return Standard_True;
4422 }
4423 else return Standard_False;
4424 }
4425
4426 //xmax, ymin <-> xmin, ymin
4427 d1 = d2;
4428 d2 = A*xmin + B*ymin + C;
4429
4430 if(d1 > theTol || d1 < -theTol) {
4431 if(INTER(d1, d2, theTol)) {
4432 Standard_Real x = -(C + B*ymin)/A;
4433 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymin));
4434 nbi++;
4435 }
4436 else if (COINC(d1, d2, theTol)) {
4437 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4438 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4439 nbi = 2;
4440 }
4441 }
4442
4443 if(nbi == 2) {
4444 if(fabs(par[0]-par[1]) > theTol) {
4445 theP1 = Min(par[0], par[1]);
4446 theP2 = Max(par[0], par[1]);
4447 return Standard_True;
4448 }
4449 else return Standard_False;
4450 }
4451
4452 return Standard_False;
4453
4454}
4455//
4456//=======================================================================
4457//function : ApproxParameters
4458//purpose :
4459//=======================================================================
4460void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
4461 const Handle(GeomAdaptor_HSurface)& aHS2,
4462 Standard_Integer& iDegMin,
4463 Standard_Integer& iDegMax,
4464 Standard_Integer& iNbIter)
4465
4466{
4467 GeomAbs_SurfaceType aTS1, aTS2;
4468
4469 //
4470 iNbIter=0;
4471 iDegMin=4;
4472 iDegMax=8;
4473 //
4474 aTS1=aHS1->Surface().GetType();
4475 aTS2=aHS2->Surface().GetType();
4476 //
4477 // Cylinder/Torus
4478 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4479 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4480 Standard_Real aRC, aRT, dR, aPC;
4481 gp_Cylinder aCylinder;
4482 gp_Torus aTorus;
4483 //
4484 aPC=Precision::Confusion();
4485 //
4486 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4487 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4488 //
4489 aRC=aCylinder.Radius();
4490 aRT=aTorus.MinorRadius();
4491 dR=aRC-aRT;
4492 if (dR<0.) {
4493 dR=-dR;
4494 }
4495 //
4496 if (dR<aPC) {
4497 iDegMax=6;
4498 }
4499 }
4500 //modified by NIZNHY-PKV Mon Jan 30 14:20:08 2012f
4501 if (aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Cylinder) {
4502 iNbIter=1; //ZZ
4503 }
4504 //modified by NIZNHY-PKV Mon Jan 30 14:20:10 2012t
4505}
4506//=======================================================================
4507//function : Tolerances
4508//purpose :
4509//=======================================================================
4510void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
4511 const Handle(GeomAdaptor_HSurface)& aHS2,
4512 Standard_Real& ,//aTolArc,
4513 Standard_Real& aTolTang,
4514 Standard_Real& ,//aUVMaxStep,
4515 Standard_Real& )//aDeflection)
4516{
4517 GeomAbs_SurfaceType aTS1, aTS2;
4518 //
4519 aTS1=aHS1->Surface().GetType();
4520 aTS2=aHS2->Surface().GetType();
4521 //
4522 // Cylinder/Torus
4523 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4524 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4525 Standard_Real aRC, aRT, dR, aPC;
4526 gp_Cylinder aCylinder;
4527 gp_Torus aTorus;
4528 //
4529 aPC=Precision::Confusion();
4530 //
4531 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4532 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4533 //
4534 aRC=aCylinder.Radius();
4535 aRT=aTorus.MinorRadius();
4536 dR=aRC-aRT;
4537 if (dR<0.) {
4538 dR=-dR;
4539 }
4540 //
4541 if (dR<aPC) {
4542 aTolTang=0.1*aTolTang;
4543 }
4544 }
4545}
4546//=======================================================================
4547//function : SortTypes
4548//purpose :
4549//=======================================================================
4550Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
4551 const GeomAbs_SurfaceType aType2)
4552{
4553 Standard_Boolean bRet;
4554 Standard_Integer aI1, aI2;
4555 //
4556 bRet=Standard_False;
4557 //
4558 aI1=IndexType(aType1);
4559 aI2=IndexType(aType2);
4560 if (aI1<aI2){
4561 bRet=!bRet;
4562 }
4563 return bRet;
4564}
4565//=======================================================================
4566//function : IndexType
4567//purpose :
4568//=======================================================================
4569Standard_Integer IndexType(const GeomAbs_SurfaceType aType)
4570{
4571 Standard_Integer aIndex;
4572 //
4573 aIndex=11;
4574 //
4575 if (aType==GeomAbs_Plane) {
4576 aIndex=0;
4577 }
4578 else if (aType==GeomAbs_Cylinder) {
4579 aIndex=1;
4580 }
4581 else if (aType==GeomAbs_Cone) {
4582 aIndex=2;
4583 }
4584 else if (aType==GeomAbs_Sphere) {
4585 aIndex=3;
4586 }
4587 else if (aType==GeomAbs_Torus) {
4588 aIndex=4;
4589 }
4590 else if (aType==GeomAbs_BezierSurface) {
4591 aIndex=5;
4592 }
4593 else if (aType==GeomAbs_BSplineSurface) {
4594 aIndex=6;
4595 }
4596 else if (aType==GeomAbs_SurfaceOfRevolution) {
4597 aIndex=7;
4598 }
4599 else if (aType==GeomAbs_SurfaceOfExtrusion) {
4600 aIndex=8;
4601 }
4602 else if (aType==GeomAbs_OffsetSurface) {
4603 aIndex=9;
4604 }
4605 else if (aType==GeomAbs_OtherSurface) {
4606 aIndex=10;
4607 }
4608 return aIndex;
4609}
4610//=======================================================================
4611//function : DumpWLine
4612//purpose :
4613//=======================================================================
4614void DumpWLine(const Handle(IntPatch_WLine)& aWLine)
4615{
4616 Standard_Integer i, aNbPnts;
4617 Standard_Real aX, aY, aZ, aU1, aV1, aU2, aV2;
4618 //
4619 printf(" *WLine\n");
4620 aNbPnts=aWLine->NbPnts();
4621 for (i=1; i<=aNbPnts; ++i) {
4622 const IntSurf_PntOn2S aPntOn2S=aWLine->Point(i);
4623 const gp_Pnt& aP3D=aPntOn2S.Value();
4624 aP3D.Coord(aX, aY, aZ);
4625 aPntOn2S.Parameters(aU1, aV1, aU2, aV2);
4626 //
4627 printf("point p_%d %lf %lf %lf\n", i, aX, aY, aZ);
4628 //printf("point p_%d %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf\n",
4629 // i, aX, aY, aZ, aU1, aV1, aU2, aV2);
4630 }
4631}
4632//=======================================================================
4633//function : RefineVector
4634//purpose :
4635//=======================================================================
4636void RefineVector(gp_Vec2d& aV2D)
4637{
4638 Standard_Integer k,m;
4639 Standard_Real aC[2], aEps, aR1, aR2, aNum;
4640 //
4641 aEps=RealEpsilon();
4642 aR1=1.-aEps;
4643 aR2=1.+aEps;
4644 //
4645 aV2D.Coord(aC[0], aC[1]);
4646 //
4647 for (k=0; k<2; ++k) {
4648 m=(k+1)%2;
4649 aNum=fabs(aC[k]);
4650 if (aNum>aR1 && aNum<aR2) {
4651 if (aC[k]<0.) {
4652 aC[k]=-1.;
4653 }
4654 else {
4655 aC[k]=1.;
4656 }
4657 aC[m]=0.;
4658 break;
4659 }
4660 }
4661 aV2D.SetCoord(aC[0], aC[1]);
4662}
4663//modified by NIZNHY-PKV Tue Jan 31 07:38:19 2012f
4664//=======================================================================
4665//function : MaxSquareDistance
4666//purpose :
4667//=======================================================================
4668Standard_Real MaxSquareDistance (const Standard_Real aT,
4669 const Handle(Geom_Curve)& aC3D,
4670 const Handle(Geom2d_Curve)& aC2D1,
4671 const Handle(Geom2d_Curve)& aC2D2,
4672 const Handle(GeomAdaptor_HSurface) myHS1,
4673 const Handle(GeomAdaptor_HSurface) myHS2,
4674 const TopoDS_Face& aF1,
4675 const TopoDS_Face& aF2,
4676 const Handle(IntTools_Context)& aCtx)
4677{
4678 Standard_Boolean bIsDone;
4679 Standard_Integer i;
4680 Standard_Real aU, aV, aD2Max, aD2;
4681 gp_Pnt2d aP2D;
4682 gp_Pnt aP, aPS;
4683 //
4684 aD2Max=0.;
4685 //
4686 aC3D->D0(aT, aP);
4687 if (aC3D.IsNull()) {
4688 return aD2Max;
4689 }
4690 //
4691 for (i=0; i<2; ++i) {
4692 const Handle(GeomAdaptor_HSurface)& aGHS=(!i) ? myHS1 : myHS2;
4693 const TopoDS_Face &aF=(!i) ? aF1 : aF2;
4694 const Handle(Geom2d_Curve)& aC2D=(!i) ? aC2D1 : aC2D2;
4695 //
4696 if (!aC2D.IsNull()) {
4697 aC2D->D0(aT, aP2D);
4698 aP2D.Coord(aU, aV);
4699 aGHS->D0(aU, aV, aPS);
4700 aD2=aP.SquareDistance(aPS);
4701 if (aD2>aD2Max) {
4702 aD2Max=aD2;
4703 }
4704 }
4705 //
4706 GeomAPI_ProjectPointOnSurf& aProjector=aCtx->ProjPS(aF);
4707 //
4708 aProjector.Perform(aP);
4709 bIsDone=aProjector.IsDone();
4710 if (bIsDone) {
4711 aProjector.LowerDistanceParameters(aU, aV);
4712 aGHS->D0(aU, aV, aPS);
4713 aD2=aP.SquareDistance(aPS);
4714 if (aD2>aD2Max) {
4715 aD2Max=aD2;
4716 }
4717 }
4718 }
4719 //
4720 return aD2Max;
4721}
4722//modified by NIZNHY-PKV Tue Jan 31 07:38:21 2012t