1 // Created on: 2000-11-23
2 // Created by: Michael KLOKOV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <IntTools_FaceFace.ixx>
18 #include <Precision.hxx>
20 #include <TColStd_HArray1OfReal.hxx>
21 #include <TColStd_Array1OfReal.hxx>
22 #include <TColStd_Array1OfInteger.hxx>
23 #include <TColStd_SequenceOfReal.hxx>
24 #include <TColStd_ListOfInteger.hxx>
25 #include <TColStd_ListIteratorOfListOfInteger.hxx>
26 #include <TColStd_Array1OfListOfInteger.hxx>
28 #include <gp_Lin2d.hxx>
29 #include <gp_Ax22d.hxx>
30 #include <gp_Circ2d.hxx>
31 #include <gp_Torus.hxx>
32 #include <gp_Cylinder.hxx>
34 #include <Bnd_Box.hxx>
36 #include <TColgp_HArray1OfPnt2d.hxx>
37 #include <TColgp_SequenceOfPnt2d.hxx>
38 #include <TColgp_Array1OfPnt.hxx>
39 #include <TColgp_Array1OfPnt2d.hxx>
41 #include <IntAna_QuadQuadGeo.hxx>
43 #include <IntSurf_PntOn2S.hxx>
44 #include <IntSurf_LineOn2S.hxx>
45 #include <IntSurf_PntOn2S.hxx>
46 #include <IntSurf_ListOfPntOn2S.hxx>
47 #include <IntRes2d_Domain.hxx>
48 #include <ProjLib_Plane.hxx>
50 #include <IntPatch_GLine.hxx>
51 #include <IntPatch_RLine.hxx>
52 #include <IntPatch_WLine.hxx>
53 #include <IntPatch_ALine.hxx>
54 #include <IntPatch_ALineToWLine.hxx>
59 #include <Extrema_ExtCC.hxx>
60 #include <Extrema_POnCurv.hxx>
61 #include <BndLib_AddSurface.hxx>
63 #include <Adaptor3d_SurfacePtr.hxx>
64 #include <Adaptor2d_HLine2d.hxx>
66 #include <GeomAbs_SurfaceType.hxx>
67 #include <GeomAbs_CurveType.hxx>
69 #include <Geom_Surface.hxx>
70 #include <Geom_Line.hxx>
71 #include <Geom_Circle.hxx>
72 #include <Geom_Ellipse.hxx>
73 #include <Geom_Parabola.hxx>
74 #include <Geom_Hyperbola.hxx>
75 #include <Geom_TrimmedCurve.hxx>
76 #include <Geom_BSplineCurve.hxx>
77 #include <Geom_RectangularTrimmedSurface.hxx>
78 #include <Geom_OffsetSurface.hxx>
79 #include <Geom_Curve.hxx>
80 #include <Geom_Conic.hxx>
82 #include <Geom2d_TrimmedCurve.hxx>
83 #include <Geom2d_BSplineCurve.hxx>
84 #include <Geom2d_Line.hxx>
85 #include <Geom2d_Curve.hxx>
86 #include <Geom2d_Circle.hxx>
88 #include <Geom2dAPI_InterCurveCurve.hxx>
89 #include <Geom2dInt_GInter.hxx>
90 #include <GeomAdaptor_Curve.hxx>
91 #include <GeomAdaptor_HSurface.hxx>
92 #include <GeomAdaptor_Surface.hxx>
93 #include <GeomLib_CheckBSplineCurve.hxx>
94 #include <GeomLib_Check2dBSplineCurve.hxx>
96 #include <GeomInt_WLApprox.hxx>
97 #include <GeomProjLib.hxx>
98 #include <GeomAPI_ProjectPointOnSurf.hxx>
99 #include <Geom2dAdaptor_Curve.hxx>
100 #include <TopoDS.hxx>
101 #include <TopoDS_Edge.hxx>
102 #include <TopExp_Explorer.hxx>
104 #include <BRep_Tool.hxx>
105 #include <BRepTools.hxx>
106 #include <BRepAdaptor_Surface.hxx>
108 #include <IntTools_Curve.hxx>
109 #include <IntTools_Tools.hxx>
110 #include <IntTools_Tools.hxx>
111 #include <IntTools_TopolTool.hxx>
112 #include <IntTools_PntOnFace.hxx>
113 #include <IntTools_PntOn2Faces.hxx>
114 #include <IntTools_Context.hxx>
115 #include <IntSurf_ListIteratorOfListOfPntOn2S.hxx>
118 void RefineVector(gp_Vec2d& aV2D);
121 void DumpWLine(const Handle(IntPatch_WLine)& aWLine);
125 void TolR3d(const TopoDS_Face& ,
129 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)&,
130 const Standard_Integer,
131 const Standard_Integer);
134 void Parameters(const Handle(GeomAdaptor_HSurface)&,
135 const Handle(GeomAdaptor_HSurface)&,
143 void BuildPCurves (Standard_Real f,Standard_Real l,Standard_Real& Tol,
144 const Handle (Geom_Surface)& S,
145 const Handle (Geom_Curve)& C,
146 Handle (Geom2d_Curve)& C2d);
149 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
150 const Standard_Real theTolerance,
151 Standard_Real& theumin,
152 Standard_Real& theumax,
153 Standard_Real& thevmin,
154 Standard_Real& thevmax);
156 Standard_Boolean NotUseSurfacesForApprox
157 (const TopoDS_Face& aF1,
158 const TopoDS_Face& aF2,
159 const Handle(IntPatch_WLine)& WL,
160 const Standard_Integer ifprm,
161 const Standard_Integer ilprm);
164 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine);
167 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
168 const Standard_Integer ideb,
169 const Standard_Integer ifin,
170 const Standard_Boolean onFirst);
173 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
174 const Handle(GeomAdaptor_HSurface)& theSurface1,
175 const Handle(GeomAdaptor_HSurface)& theSurface2,
176 const TopoDS_Face& theFace1,
177 const TopoDS_Face& theFace2,
178 const IntTools_LineConstructor& theLConstructor,
179 const Standard_Boolean theAvoidLConstructor,
180 IntPatch_SequenceOfLine& theNewLines,
181 Standard_Real& theReachedTol3d,
182 const Handle(IntTools_Context)& );
185 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
186 const Handle(Geom_Curve)& theCurve,
187 const TopoDS_Face& theFace1,
188 const TopoDS_Face& theFace2,
189 const Standard_Real theOtherParameter,
190 const Standard_Boolean bIncreasePar,
191 Standard_Real& theNewParameter,
192 const Handle(IntTools_Context)& );
195 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve);
198 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
199 const Standard_Real theFirstBoundary,
200 const Standard_Real theSecondBoundary,
201 const Standard_Real theResolution,
202 Standard_Boolean& IsOnFirstBoundary);
204 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
205 const gp_Pnt2d& theLastPoint,
206 const Standard_Real theUmin,
207 const Standard_Real theUmax,
208 const Standard_Real theVmin,
209 const Standard_Real theVmax,
210 gp_Pnt2d& theNewPoint);
214 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
215 const Handle(GeomAdaptor_HSurface)& theSurface2,
216 const TopoDS_Face& theFace1,
217 const TopoDS_Face& theFace2,
218 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
219 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
220 Handle(TColStd_HArray1OfReal)& theResultRadius,
221 const Handle(IntTools_Context)& );
224 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
225 const gp_Pnt2d& theLastPoint,
226 const Standard_Real theUmin,
227 const Standard_Real theUmax,
228 const Standard_Real theVmin,
229 const Standard_Real theVmax,
230 const gp_Pnt2d& theTanZoneCenter,
231 const Standard_Real theZoneRadius,
232 Handle(GeomAdaptor_HSurface) theGASurface,
233 gp_Pnt2d& theNewPoint);
236 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
237 const gp_Pnt2d& theTanZoneCenter,
238 const Standard_Real theZoneRadius,
239 Handle(GeomAdaptor_HSurface) theGASurface);
242 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
243 const gp_Pnt2d& theOriginalPoint,
244 Handle(GeomAdaptor_HSurface) theGASurface);
246 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
247 const gp_Sphere& theSph);
249 static void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
250 const Handle(GeomAdaptor_HSurface)& theS2,
251 const Standard_Real TolAng,
252 const Standard_Real TolTang,
253 const Standard_Boolean theApprox1,
254 const Standard_Boolean theApprox2,
255 IntTools_SequenceOfCurves& theSeqOfCurve,
256 Standard_Boolean& theTangentFaces);
258 static Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
259 const gp_Lin2d& theLin2d,
260 const Standard_Real theTol,
261 Standard_Real& theP1,
262 Standard_Real& theP2);
265 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
266 const Handle(GeomAdaptor_HSurface)& aHS2,
267 Standard_Integer& iDegMin,
268 Standard_Integer& iNbIter,
269 Standard_Integer& iDegMax);
272 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
273 const Handle(GeomAdaptor_HSurface)& aHS2,
274 Standard_Real& aTolTang);
277 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
278 const GeomAbs_SurfaceType aType2);
280 Standard_Integer IndexType(const GeomAbs_SurfaceType aType);
284 Standard_Real MaxSquareDistance (const Standard_Real aT,
285 const Handle(Geom_Curve)& aC3D,
286 const Handle(Geom2d_Curve)& aC2D1,
287 const Handle(Geom2d_Curve)& aC2D2,
288 const Handle(GeomAdaptor_HSurface) myHS1,
289 const Handle(GeomAdaptor_HSurface) myHS2,
290 const TopoDS_Face& aF1,
291 const TopoDS_Face& aF2,
292 const Handle(IntTools_Context)& aCtx);
295 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
296 const TopoDS_Face& aFace);
300 Standard_Real FindMaxSquareDistance (const Standard_Real aA,
301 const Standard_Real aB,
302 const Standard_Real aEps,
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);
312 //=======================================================================
315 //=======================================================================
316 IntTools_FaceFace::IntTools_FaceFace()
318 myIsDone=Standard_False;
319 myTangentFaces=Standard_False;
321 myHS1 = new GeomAdaptor_HSurface ();
322 myHS2 = new GeomAdaptor_HSurface ();
325 SetParameters(Standard_True, Standard_True, Standard_True, 1.e-07);
328 //=======================================================================
329 //function : SetContext
331 //=======================================================================
332 void IntTools_FaceFace::SetContext(const Handle(IntTools_Context)& aContext)
336 //=======================================================================
339 //=======================================================================
340 const Handle(IntTools_Context)& IntTools_FaceFace::Context()const
344 //=======================================================================
347 //=======================================================================
348 const TopoDS_Face& IntTools_FaceFace::Face1() const
352 //=======================================================================
355 //=======================================================================
356 const TopoDS_Face& IntTools_FaceFace::Face2() const
360 //=======================================================================
361 //function : TangentFaces
363 //=======================================================================
364 Standard_Boolean IntTools_FaceFace::TangentFaces() const
366 return myTangentFaces;
368 //=======================================================================
371 //=======================================================================
372 const IntTools_SequenceOfPntOn2Faces& IntTools_FaceFace::Points() const
376 //=======================================================================
379 //=======================================================================
380 Standard_Boolean IntTools_FaceFace::IsDone() const
384 //=======================================================================
385 //function : TolReached3d
387 //=======================================================================
388 Standard_Real IntTools_FaceFace::TolReached3d() const
390 return myTolReached3d;
392 //=======================================================================
394 //purpose : return lines of intersection
395 //=======================================================================
396 const IntTools_SequenceOfCurves& IntTools_FaceFace::Lines() const
398 StdFail_NotDone_Raise_if
400 "IntTools_FaceFace::Lines() => myIntersector NOT DONE");
403 //=======================================================================
404 //function : TolReached2d
406 //=======================================================================
407 Standard_Real IntTools_FaceFace::TolReached2d() const
409 return myTolReached2d;
411 // =======================================================================
412 // function: SetParameters
414 // =======================================================================
415 void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d,
416 const Standard_Boolean ToApproxC2dOnS1,
417 const Standard_Boolean ToApproxC2dOnS2,
418 const Standard_Real ApproximationTolerance)
420 myApprox = ToApproxC3d;
421 myApprox1 = ToApproxC2dOnS1;
422 myApprox2 = ToApproxC2dOnS2;
423 myTolApprox = ApproximationTolerance;
425 //=======================================================================
428 //=======================================================================
429 void IntTools_FaceFace::SetList(IntSurf_ListOfPntOn2S& aListOfPnts)
431 myListOfPnts = aListOfPnts;
435 static Standard_Boolean isTreatAnalityc(const TopoDS_Face& theF1,
436 const TopoDS_Face& theF2)
438 const Standard_Real Tolang = 1.e-8;
439 const Standard_Real aTolF1=BRep_Tool::Tolerance(theF1);
440 const Standard_Real aTolF2=BRep_Tool::Tolerance(theF2);
441 const Standard_Real aTolSum = aTolF1 + aTolF2;
442 Standard_Real aHigh = 0.0;
444 const BRepAdaptor_Surface aBAS1(theF1), aBAS2(theF2);
445 const GeomAbs_SurfaceType aType1=aBAS1.GetType();
446 const GeomAbs_SurfaceType aType2=aBAS2.GetType();
450 if(aType1 == GeomAbs_Plane)
454 else if(aType2 == GeomAbs_Plane)
460 return Standard_True;
463 if(aType1 == GeomAbs_Cylinder)
465 aS2=aBAS1.Cylinder();
466 const Standard_Real VMin = aBAS1.FirstVParameter();
467 const Standard_Real VMax = aBAS1.LastVParameter();
469 if( Precision::IsNegativeInfinite(VMin) ||
470 Precision::IsPositiveInfinite(VMax))
471 return Standard_True;
475 else if(aType2 == GeomAbs_Cylinder)
477 aS2=aBAS2.Cylinder();
479 const Standard_Real VMin = aBAS2.FirstVParameter();
480 const Standard_Real VMax = aBAS2.LastVParameter();
482 if( Precision::IsNegativeInfinite(VMin) ||
483 Precision::IsPositiveInfinite(VMax))
484 return Standard_True;
490 return Standard_True;
493 IntAna_QuadQuadGeo inter;
494 inter.Perform(aS1,aS2,Tolang,aTolSum, aHigh);
495 if(inter.TypeInter() == IntAna_Ellipse)
497 const gp_Elips anEl = inter.Ellipse(1);
498 const Standard_Real aMajorR = anEl.MajorRadius();
499 const Standard_Real aMinorR = anEl.MinorRadius();
501 return (aMajorR < 100000.0 * aMinorR);
505 return inter.IsDone();
508 //=======================================================================
510 //purpose : intersect surfaces of the faces
511 //=======================================================================
512 void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
513 const TopoDS_Face& aF2)
515 Standard_Boolean RestrictLine = Standard_False, hasCone = Standard_False;
517 if (myContext.IsNull()) {
518 myContext=new IntTools_Context;
521 mySeqOfCurve.Clear();
524 myIsDone = Standard_False;
530 const BRepAdaptor_Surface aBAS1(myFace1, Standard_False);
531 const BRepAdaptor_Surface aBAS2(myFace2, Standard_False);
532 GeomAbs_SurfaceType aType1=aBAS1.GetType();
533 GeomAbs_SurfaceType aType2=aBAS2.GetType();
535 const Standard_Boolean bReverse=SortTypes(aType1, aType2);
540 aType1=aBAS2.GetType();
541 aType2=aBAS1.GetType();
543 if (myListOfPnts.Extent())
545 Standard_Real aU1,aV1,aU2,aV2;
546 IntSurf_ListIteratorOfListOfPntOn2S aItP2S;
548 aItP2S.Initialize(myListOfPnts);
549 for (; aItP2S.More(); aItP2S.Next())
551 IntSurf_PntOn2S& aP2S=aItP2S.Value();
552 aP2S.Parameters(aU1,aV1,aU2,aV2);
553 aP2S.SetValue(aU2,aV2,aU1,aV1);
557 Standard_Boolean anAproxTmp = myApprox1;
558 myApprox1 = myApprox2;
559 myApprox2 = anAproxTmp;
563 const Handle(Geom_Surface) S1=BRep_Tool::Surface(myFace1);
564 const Handle(Geom_Surface) S2=BRep_Tool::Surface(myFace2);
566 const Standard_Real aTolF1=BRep_Tool::Tolerance(myFace1);
567 const Standard_Real aTolF2=BRep_Tool::Tolerance(myFace2);
569 Standard_Real TolArc = aTolF1 + aTolF2;
570 Standard_Real TolTang = TolArc;
572 const Standard_Boolean isFace1Quad = (aType1 == GeomAbs_Cylinder ||
573 aType1 == GeomAbs_Cone ||
574 aType1 == GeomAbs_Torus);
576 const Standard_Boolean isFace2Quad = (aType2 == GeomAbs_Cylinder ||
577 aType2 == GeomAbs_Cone ||
578 aType2 == GeomAbs_Torus);
580 if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
581 Standard_Real umin, umax, vmin, vmax;
582 Standard_Real dU, dV;
584 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
591 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
593 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
600 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
602 Standard_Real TolAng = 1.e-8;
604 PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2,
605 mySeqOfCurve, myTangentFaces);
607 myIsDone = Standard_True;
609 if(!myTangentFaces) {
610 const Standard_Integer NbLinPP = mySeqOfCurve.Length();
612 Standard_Real aTolFMax;
613 myTolReached3d = 1.e-7;
614 aTolFMax=Max(aTolF1, aTolF2);
615 if (aTolFMax>myTolReached3d) {
616 myTolReached3d=aTolFMax;
619 myTolReached2d = myTolReached3d;
622 Handle(Geom2d_Curve) aC2D1, aC2D2;
623 const Standard_Integer aNbLin = mySeqOfCurve.Length();
624 for (Standard_Integer i = 1; i <= aNbLin; ++i) {
625 IntTools_Curve& aIC=mySeqOfCurve(i);
626 aC2D1=aIC.FirstCurve2d();
627 aC2D2=aIC.SecondCurve2d();
628 aIC.SetFirstCurve2d(aC2D2);
629 aIC.SetSecondCurve2d(aC2D1);
635 }//if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
637 if ((aType1==GeomAbs_Plane) && isFace2Quad)
639 Standard_Real dU, dV;
642 Standard_Real umin, umax, vmin, vmax;
643 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
651 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
653 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
654 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
655 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
657 if( aType2==GeomAbs_Cone ) {
659 hasCone = Standard_True;
662 else if ((aType2==GeomAbs_Plane) && isFace1Quad)
664 Standard_Real dU, dV;
667 Standard_Real umin, umax, vmin, vmax;
668 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
669 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
670 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
672 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
679 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
681 if( aType1==GeomAbs_Cone ) {
683 hasCone = Standard_True;
688 Standard_Real umin, umax, vmin, vmax;
689 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
690 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
691 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
692 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
693 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
694 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
697 const Handle(IntTools_TopolTool) dom1 = new IntTools_TopolTool(myHS1);
698 const Handle(IntTools_TopolTool) dom2 = new IntTools_TopolTool(myHS2);
700 myLConstruct.Load(dom1, dom2, myHS1, myHS2);
703 Tolerances(myHS1, myHS2, TolTang);
706 const Standard_Real UVMaxStep = 0.001;
707 const Standard_Real Deflection = (hasCone) ? 0.085 : 0.1;
708 myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection);
711 if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) ||
712 (myHS1->IsVClosed() && !myHS1->IsVPeriodic()) ||
713 (myHS2->IsUClosed() && !myHS2->IsUPeriodic()) ||
714 (myHS2->IsVClosed() && !myHS2->IsVPeriodic()))
716 RestrictLine = Standard_True;
719 if((aType1 != GeomAbs_BSplineSurface) &&
720 (aType1 != GeomAbs_BezierSurface) &&
721 (aType1 != GeomAbs_OtherSurface) &&
722 (aType2 != GeomAbs_BSplineSurface) &&
723 (aType2 != GeomAbs_BezierSurface) &&
724 (aType2 != GeomAbs_OtherSurface))
726 RestrictLine = Standard_True;
728 if ((aType1 == GeomAbs_Torus) ||
729 (aType2 == GeomAbs_Torus))
731 myListOfPnts.Clear();
738 TopExp_Explorer aExp;
739 for(Standard_Integer i = 0; (!RestrictLine) && (i < 2); i++)
741 const TopoDS_Face& aF=(!i) ? myFace1 : myFace2;
742 aExp.Init(aF, TopAbs_EDGE);
743 for(; aExp.More(); aExp.Next())
745 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
747 if(BRep_Tool::Degenerated(aE))
749 RestrictLine = Standard_True;
756 const Standard_Boolean isGeomInt = isTreatAnalityc(aF1, aF2);
757 myIntersector.Perform(myHS1, dom1, myHS2, dom2, TolArc, TolTang,
758 myListOfPnts, RestrictLine, isGeomInt);
760 myIsDone = myIntersector.IsDone();
764 myTangentFaces=myIntersector.TangentFaces();
765 if (myTangentFaces) {
770 myListOfPnts.Clear(); // to use LineConstructor
773 const Standard_Integer aNbLin = myIntersector.NbLines();
774 for (Standard_Integer i=1; i <= aNbLin; ++i) {
775 MakeCurve(i, dom1, dom2);
778 ComputeTolReached3d();
781 Handle(Geom2d_Curve) aC2D1, aC2D2;
783 const Standard_Integer aNbLin=mySeqOfCurve.Length();
784 for (Standard_Integer i=1; i<=aNbLin; ++i)
786 IntTools_Curve& aIC=mySeqOfCurve(i);
787 aC2D1=aIC.FirstCurve2d();
788 aC2D2=aIC.SecondCurve2d();
789 aIC.SetFirstCurve2d(aC2D2);
790 aIC.SetSecondCurve2d(aC2D1);
795 Standard_Real U1,V1,U2,V2;
796 IntTools_PntOnFace aPntOnF1, aPntOnF2;
797 IntTools_PntOn2Faces aPntOn2Faces;
799 const Standard_Integer aNbPnts = myIntersector.NbPnts();
800 for (Standard_Integer i=1; i <= aNbPnts; ++i)
802 const IntSurf_PntOn2S& aISPnt=myIntersector.Point(i).PntOn2S();
803 const gp_Pnt& aPnt=aISPnt.Value();
804 aISPnt.Parameters(U1,V1,U2,V2);
805 aPntOnF1.Init(myFace1, aPnt, U1, V1);
806 aPntOnF2.Init(myFace2, aPnt, U2, V2);
810 aPntOn2Faces.SetP1(aPntOnF1);
811 aPntOn2Faces.SetP2(aPntOnF2);
815 aPntOn2Faces.SetP2(aPntOnF1);
816 aPntOn2Faces.SetP1(aPntOnF2);
819 myPnts.Append(aPntOn2Faces);
824 //=======================================================================
825 //function :ComputeTolReached3d
827 //=======================================================================
828 void IntTools_FaceFace::ComputeTolReached3d()
830 Standard_Boolean bCase1;
831 Standard_Integer aNbLin, i;
832 GeomAbs_SurfaceType aType1, aType2;
834 aNbLin=myIntersector.NbLines();
839 aType1=myHS1->Surface().GetType();
840 aType2=myHS2->Surface().GetType();
842 bCase1=((aType1==GeomAbs_Plane && aType2==GeomAbs_SurfaceOfExtrusion) ||
843 (aType2==GeomAbs_Plane && aType1==GeomAbs_SurfaceOfExtrusion));
845 if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
847 Handle(IntPatch_Line) aIL1, aIL2;
848 IntPatch_IType aTL1, aTL2;
850 aIL1=myIntersector.Line(1);
851 aIL2=myIntersector.Line(2);
852 aTL1=aIL1->ArcType();
853 aTL2=aIL2->ArcType();
854 if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) {
855 Standard_Real aD, aDTresh, dTol;
861 aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line();
862 aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line();
863 aD=aL1.Distance(aL2);
866 myTolReached3d=aD+dTol;
872 if (aNbLin) {// Check the distances
873 Standard_Integer aNbP, j ;
874 Standard_Real aT1, aT2, dT, aD2, aD2Max, aEps, aT11, aT12;
878 aNbLin=mySeqOfCurve.Length();
880 for (i=1; i<=aNbLin; ++i) {
881 const IntTools_Curve& aIC=mySeqOfCurve(i);
882 const Handle(Geom_Curve)& aC3D=aIC.Curve();
883 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
884 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
889 const Handle(Geom_BSplineCurve)& aBC=
890 Handle(Geom_BSplineCurve)::DownCast(aC3D);
895 aT1=aBC->FirstParameter();
896 aT2=aBC->LastParameter();
900 for (j=1; j<aNbP; ++j) {
903 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
904 myHS1, myHS2, myFace1, myFace2, myContext);
909 }//for (i=1; i<=aNbLin; ++i) {
911 myTolReached3d=sqrt(aD2Max);
913 }// if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
916 else if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
917 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
921 aTolF1 = BRep_Tool::Tolerance(myFace1);
922 aTolF2 = BRep_Tool::Tolerance(myFace2);
923 aTolFMax=Max(aTolF1, aTolF2);
925 if (aTolFMax>aTolTresh) {
926 myTolReached3d=aTolFMax;
928 }//if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
931 else if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ||
932 (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) {
934 const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1);
935 if(aIL1->ArcType() == IntPatch_Circle) {
936 gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle();
937 gp_XYZ aCirDir = aCir.Axis().Direction().XYZ();
940 if(aType1 == GeomAbs_Plane) {
941 aPln = myHS1->Surface().Plane();
944 aPln = myHS2->Surface().Plane();
946 aPlDir = aPln.Axis().Direction().XYZ();
947 Standard_Real cs = aCirDir*aPlDir;
948 if(cs < 0.) aPlDir.Reverse();
949 Standard_Real eps = 1.e-14;
950 if(!aPlDir.IsEqual(aCirDir, eps)) {
951 Standard_Integer aNbP = 11;
952 Standard_Real dt = 2.*M_PI / (aNbP - 1), t;
953 for(t = 0.; t < 2.*M_PI; t += dt) {
954 Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir));
955 if(myTolReached3d < d) myTolReached3d = d;
957 myTolReached3d *= 1.1;
959 } //aIL1->ArcType() == IntPatch_Circle
961 } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane)
962 //End IFV Bug OCC20297
964 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
965 (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) {
966 aNbLin=mySeqOfCurve.Length();
971 Standard_Integer aNbP;
972 Standard_Real aT, aT1, aT2, dT, aUT, aVT, aUP, aVP;
973 Standard_Real aDP, aDT, aDmax;
978 const IntTools_Curve& aIC=mySeqOfCurve(1);
979 const Handle(Geom_Curve)& aC3D=aIC.Curve();
980 const Handle(Geom_BSplineCurve)& aBS=
981 Handle(Geom_BSplineCurve)::DownCast(aC3D);
986 aT1=aBS->FirstParameter();
987 aT2=aBS->LastParameter();
989 aPln =(aType1==GeomAbs_Plane) ? myHS1->Plane() : myHS2->Plane();
990 aTorus=(aType1==GeomAbs_Plane) ? myHS2->Torus() : myHS1->Torus();
994 dT=(aT2-aT1)/(aNbP-1);
995 for (i=0; i<aNbP; ++i) {
1003 ElSLib::Parameters(aPln, aP, aUP, aVP);
1004 aPP=ElSLib::Value(aUP, aVP, aPln);
1005 aDP=aP.SquareDistance(aPP);
1010 ElSLib::Parameters(aTorus, aP, aUT, aVT);
1011 aPT=ElSLib::Value(aUT, aVT, aTorus);
1012 aDT=aP.SquareDistance(aPT);
1018 if (aDmax > myTolReached3d*myTolReached3d) {
1019 myTolReached3d=sqrt(aDmax);
1020 myTolReached3d=1.1*myTolReached3d;
1022 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
1024 else if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) ||
1025 (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder)) {
1026 Standard_Integer j, aNbP;
1027 Standard_Real aT, aT1, aT2, dT, aD2max, aD2;
1029 aNbLin=mySeqOfCurve.Length();
1033 for (i=1; i<=aNbLin; ++i) {
1034 const IntTools_Curve& aIC=mySeqOfCurve(i);
1035 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1036 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1037 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1039 if (aC3D.IsNull()) {
1042 const Handle(Geom_BSplineCurve)& aBC=
1043 Handle(Geom_BSplineCurve)::DownCast(aC3D);
1048 aT1=aBC->FirstParameter();
1049 aT2=aBC->LastParameter();
1051 dT=(aT2-aT1)/(aNbP-1);
1052 for (j=0; j<aNbP; ++j) {
1058 aD2=MaxSquareDistance(aT, aC3D, aC2D1, aC2D2,
1059 myHS1, myHS2, myFace1, myFace2, myContext);
1063 }//for (j=0; j<aNbP; ++j) {
1065 }//for (i=1; i<=aNbLin; ++i) {
1067 aD2=myTolReached3d*myTolReached3d;
1069 myTolReached3d=sqrt(aD2max);
1071 }//if((aType1==GeomAbs_SurfaceOfRevolution ...
1072 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ||
1073 (aType2==GeomAbs_Plane && aType1==GeomAbs_Sphere)) {
1074 Standard_Integer j, aNbP;
1075 Standard_Real aT1, aT2, dT, aD2max, aD2, aEps, aT11, aT12;
1077 aNbLin=mySeqOfCurve.Length();
1081 for (i=1; i<=aNbLin; ++i) {
1082 const IntTools_Curve& aIC=mySeqOfCurve(i);
1083 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1084 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1085 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1087 const Handle(Geom2d_BSplineCurve)& aBC2D1=
1088 Handle(Geom2d_BSplineCurve)::DownCast(aC2D1);
1089 const Handle(Geom2d_BSplineCurve)& aBC2D2=
1090 Handle(Geom2d_BSplineCurve)::DownCast(aC2D2);
1092 if (aBC2D1.IsNull() && aBC2D2.IsNull()) {
1096 if (!aBC2D1.IsNull()) {
1097 aT1=aBC2D1->FirstParameter();
1098 aT2=aBC2D1->LastParameter();
1101 aT1=aBC2D2->FirstParameter();
1102 aT2=aBC2D2->LastParameter();
1105 aEps=0.01*(aT2-aT1);
1107 for (j=0; j<aNbP; ++j) {
1114 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
1115 myHS1, myHS2, myFace1, myFace2, myContext);
1119 }//for (j=0; j<aNbP; ++j) {
1121 }//for (i=1; i<=aNbLin; ++i) {
1123 aD2=myTolReached3d*myTolReached3d;
1125 myTolReached3d=sqrt(aD2max);
1127 }//else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ...
1128 else if (!myApprox || bCase1) {
1129 //else if (!myApprox) {
1130 Standard_Integer aNbP, j;
1131 Standard_Real aT1, aT2, dT, aD2, aD2Max, aEps, aT11, aT12;
1134 aNbLin=mySeqOfCurve.Length();
1136 for (i=1; i<=aNbLin; ++i) {
1137 const IntTools_Curve& aIC=mySeqOfCurve(i);
1138 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1139 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1140 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1142 if (aC3D.IsNull()) {
1145 const Handle(Geom_BSplineCurve)& aBC=
1146 Handle(Geom_BSplineCurve)::DownCast(aC3D);
1151 aT1=aBC->FirstParameter();
1152 aT2=aBC->LastParameter();
1154 aEps=0.0001*(aT2-aT1);
1157 for (j=1; j<aNbP-1; ++j) {
1160 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
1161 myHS1, myHS2, myFace1, myFace2, myContext);
1166 }//for (i=1; i<=aNbLin; ++i) {
1167 myTolReached3d=sqrt(aD2Max);
1170 //=======================================================================
1171 //function : MakeCurve
1173 //=======================================================================
1174 void IntTools_FaceFace::MakeCurve(const Standard_Integer Index,
1175 const Handle(Adaptor3d_TopolTool)& dom1,
1176 const Handle(Adaptor3d_TopolTool)& dom2)
1178 Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor;
1179 Standard_Boolean ok, bPCurvesOk;
1180 Standard_Integer i, j, aNbParts;
1181 Standard_Real fprm, lprm;
1182 Standard_Real Tolpc;
1183 Handle(IntPatch_Line) L;
1184 IntPatch_IType typl;
1185 Handle(Geom_Curve) newc;
1187 const Standard_Real TOLCHECK =0.0000001;
1188 const Standard_Real TOLANGCHECK=0.1;
1190 rejectSurface = Standard_False;
1191 reApprox = Standard_False;
1193 bPCurvesOk = Standard_True;
1197 Tolpc = myTolApprox;
1198 bAvoidLineConstructor = Standard_False;
1199 L = myIntersector.Line(Index);
1200 typl = L->ArcType();
1202 if(typl==IntPatch_Walking) {
1203 Handle(IntPatch_Line) anewL;
1205 const Handle(IntPatch_WLine)& aWLine=
1206 Handle(IntPatch_WLine)::DownCast(L);
1207 //DumpWLine(aWLine);
1209 anewL = ComputePurgedWLine(aWLine);
1210 if(anewL.IsNull()) {
1215 //const Handle(IntPatch_WLine)& aWLineX = Handle(IntPatch_WLine)::DownCast(L);
1216 //DumpWLine(aWLineX);
1219 if(!myListOfPnts.IsEmpty()) {
1220 bAvoidLineConstructor = Standard_True;
1223 Standard_Integer nbp = aWLine->NbPnts();
1224 const IntSurf_PntOn2S& p1 = aWLine->Point(1);
1225 const IntSurf_PntOn2S& p2 = aWLine->Point(nbp);
1227 const gp_Pnt& P1 = p1.Value();
1228 const gp_Pnt& P2 = p2.Value();
1230 if(P1.SquareDistance(P2) < 1.e-14) {
1231 bAvoidLineConstructor = Standard_False;
1236 if(!bAvoidLineConstructor) {
1237 myLConstruct.Perform(L);
1239 bDone=myLConstruct.IsDone();
1240 aNbParts=myLConstruct.NbParts();
1241 if (!bDone|| !aNbParts) {
1250 //########################################
1251 // Line, Parabola, Hyperbola
1252 //########################################
1254 case IntPatch_Parabola:
1255 case IntPatch_Hyperbola: {
1256 if (typl == IntPatch_Lin) {
1258 new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
1261 else if (typl == IntPatch_Parabola) {
1263 new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
1266 else if (typl == IntPatch_Hyperbola) {
1268 new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
1272 if (typl == IntPatch_Lin) {
1273 TolR3d (myFace1, myFace2, myTolReached3d);
1276 aNbParts=myLConstruct.NbParts();
1277 for (i=1; i<=aNbParts; i++) {
1278 myLConstruct.Part(i, fprm, lprm);
1280 if (!Precision::IsNegativeInfinite(fprm) &&
1281 !Precision::IsPositiveInfinite(lprm)) {
1283 IntTools_Curve aCurve;
1285 Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
1286 aCurve.SetCurve(aCT3D);
1287 if (typl == IntPatch_Parabola) {
1288 Standard_Real aTolF1, aTolF2, aTolBase;
1290 aTolF1 = BRep_Tool::Tolerance(myFace1);
1291 aTolF2 = BRep_Tool::Tolerance(myFace2);
1292 aTolBase=aTolF1+aTolF2;
1293 myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
1296 aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
1298 Handle (Geom2d_Curve) C2d;
1299 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1300 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1301 myTolReached2d=Tolpc;
1304 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1307 Handle(Geom2d_BSplineCurve) H1;
1309 aCurve.SetFirstCurve2d(H1);
1313 Handle (Geom2d_Curve) C2d;
1314 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1315 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1316 myTolReached2d=Tolpc;
1319 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1322 Handle(Geom2d_BSplineCurve) H1;
1324 aCurve.SetSecondCurve2d(H1);
1326 mySeqOfCurve.Append(aCurve);
1327 } // end of if (!Precision::IsNegativeInfinite(fprm) && !Precision::IsPositiveInfinite(lprm))
1329 // on regarde si on garde
1331 Standard_Boolean bFNIt, bLPIt;
1332 Standard_Real aTestPrm, dT=100.;
1334 bFNIt=Precision::IsNegativeInfinite(fprm);
1335 bLPIt=Precision::IsPositiveInfinite(lprm);
1339 if (bFNIt && !bLPIt) {
1342 else if (!bFNIt && bLPIt) {
1346 gp_Pnt ptref(newc->Value(aTestPrm));
1348 GeomAbs_SurfaceType typS1 = myHS1->GetType();
1349 GeomAbs_SurfaceType typS2 = myHS2->GetType();
1350 if( typS1 == GeomAbs_SurfaceOfExtrusion ||
1351 typS1 == GeomAbs_OffsetSurface ||
1352 typS1 == GeomAbs_SurfaceOfRevolution ||
1353 typS2 == GeomAbs_SurfaceOfExtrusion ||
1354 typS2 == GeomAbs_OffsetSurface ||
1355 typS2 == GeomAbs_SurfaceOfRevolution)
1357 Handle(Geom2d_BSplineCurve) H1;
1358 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1362 Standard_Real u1, v1, u2, v2, Tol;
1364 Tol = Precision::Confusion();
1365 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1366 ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
1368 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1371 Handle(Geom2d_BSplineCurve) H1;
1372 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1375 }// end of for (i=1; i<=myLConstruct.NbParts(); i++)
1376 }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola:
1379 //########################################
1380 // Circle and Ellipse
1381 //########################################
1382 case IntPatch_Circle:
1383 case IntPatch_Ellipse: {
1385 if (typl == IntPatch_Circle) {
1386 newc = new Geom_Circle
1387 (Handle(IntPatch_GLine)::DownCast(L)->Circle());
1389 else { //IntPatch_Ellipse
1390 newc = new Geom_Ellipse
1391 (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
1395 TolR3d (myFace1, myFace2, myTolReached3d);
1397 aNbParts=myLConstruct.NbParts();
1399 Standard_Real aPeriod, aNul;
1400 TColStd_SequenceOfReal aSeqFprm, aSeqLprm;
1405 for (i=1; i<=aNbParts; i++) {
1406 myLConstruct.Part(i, fprm, lprm);
1408 if (fprm < aNul && lprm > aNul) {
1409 // interval that goes through 0. is divided on two intervals;
1410 while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
1411 while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
1413 if((aPeriod - fprm) > Tolpc) {
1414 aSeqFprm.Append(fprm);
1415 aSeqLprm.Append(aPeriod);
1418 gp_Pnt P1 = newc->Value(fprm);
1419 gp_Pnt P2 = newc->Value(aPeriod);
1420 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1421 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1423 if(P1.Distance(P2) > aTolDist) {
1424 Standard_Real anewpar = fprm;
1426 if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2,
1427 lprm, Standard_False, anewpar, myContext)) {
1430 aSeqFprm.Append(fprm);
1431 aSeqLprm.Append(aPeriod);
1436 if((lprm - aNul) > Tolpc) {
1437 aSeqFprm.Append(aNul);
1438 aSeqLprm.Append(lprm);
1441 gp_Pnt P1 = newc->Value(aNul);
1442 gp_Pnt P2 = newc->Value(lprm);
1443 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1444 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1446 if(P1.Distance(P2) > aTolDist) {
1447 Standard_Real anewpar = lprm;
1449 if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2,
1450 fprm, Standard_True, anewpar, myContext)) {
1453 aSeqFprm.Append(aNul);
1454 aSeqLprm.Append(lprm);
1460 aSeqFprm.Append(fprm);
1461 aSeqLprm.Append(lprm);
1466 aNbParts=aSeqFprm.Length();
1467 for (i=1; i<=aNbParts; i++) {
1471 Standard_Real aRealEpsilon=RealEpsilon();
1472 if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*M_PI) > aRealEpsilon) {
1473 //==============================================
1475 IntTools_Curve aCurve;
1476 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1477 aCurve.SetCurve(aTC3D);
1478 fprm=aTC3D->FirstParameter();
1479 lprm=aTC3D->LastParameter ();
1481 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {////
1483 Handle (Geom2d_Curve) C2d;
1484 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1485 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1486 myTolReached2d=Tolpc;
1489 aCurve.SetFirstCurve2d(C2d);
1492 Handle(Geom2d_BSplineCurve) H1;
1493 aCurve.SetFirstCurve2d(H1);
1498 Handle (Geom2d_Curve) C2d;
1499 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1500 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1501 myTolReached2d=Tolpc;
1504 aCurve.SetSecondCurve2d(C2d);
1507 Handle(Geom2d_BSplineCurve) H1;
1508 aCurve.SetSecondCurve2d(H1);
1513 Handle(Geom2d_BSplineCurve) H1;
1514 aCurve.SetFirstCurve2d(H1);
1515 aCurve.SetSecondCurve2d(H1);
1517 mySeqOfCurve.Append(aCurve);
1518 //==============================================
1519 } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon())
1522 // on regarde si on garde
1525 // if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) {
1526 if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
1527 IntTools_Curve aCurve;
1528 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1529 aCurve.SetCurve(aTC3D);
1530 fprm=aTC3D->FirstParameter();
1531 lprm=aTC3D->LastParameter ();
1534 Handle (Geom2d_Curve) C2d;
1535 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1536 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1537 myTolReached2d=Tolpc;
1540 aCurve.SetFirstCurve2d(C2d);
1543 Handle(Geom2d_BSplineCurve) H1;
1544 aCurve.SetFirstCurve2d(H1);
1548 Handle (Geom2d_Curve) C2d;
1549 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1550 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1551 myTolReached2d=Tolpc;
1554 aCurve.SetSecondCurve2d(C2d);
1557 Handle(Geom2d_BSplineCurve) H1;
1558 aCurve.SetSecondCurve2d(H1);
1560 mySeqOfCurve.Append(aCurve);
1565 Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
1567 aTwoPIdiv17=2.*M_PI/17.;
1569 for (j=0; j<=17; j++) {
1570 gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
1571 Tol = Precision::Confusion();
1573 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1574 ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
1576 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1579 IntTools_Curve aCurve;
1580 aCurve.SetCurve(newc);
1581 //==============================================
1582 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
1585 Handle (Geom2d_Curve) C2d;
1586 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1587 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1588 myTolReached2d=Tolpc;
1591 aCurve.SetFirstCurve2d(C2d);
1594 Handle(Geom2d_BSplineCurve) H1;
1595 aCurve.SetFirstCurve2d(H1);
1599 Handle (Geom2d_Curve) C2d;
1600 BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
1601 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1602 myTolReached2d=Tolpc;
1605 aCurve.SetSecondCurve2d(C2d);
1609 Handle(Geom2d_BSplineCurve) H1;
1610 aCurve.SetSecondCurve2d(H1);
1612 }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
1615 Handle(Geom2d_BSplineCurve) H1;
1617 aCurve.SetFirstCurve2d(H1);
1618 aCurve.SetSecondCurve2d(H1);
1620 //==============================================
1622 mySeqOfCurve.Append(aCurve);
1625 }// end of if (ok) {
1626 }// end of for (Standard_Integer j=0; j<=17; j++)
1627 }// end of else { on regarde si on garde
1628 }// for (i=1; i<=myLConstruct.NbParts(); i++)
1629 }// IntPatch_Circle: IntPatch_Ellipse:
1632 case IntPatch_Analytic: {
1633 IntSurf_Quadric quad1,quad2;
1634 GeomAbs_SurfaceType typs = myHS1->Surface().GetType();
1638 quad1.SetValue(myHS1->Surface().Plane());
1640 case GeomAbs_Cylinder:
1641 quad1.SetValue(myHS1->Surface().Cylinder());
1644 quad1.SetValue(myHS1->Surface().Cone());
1646 case GeomAbs_Sphere:
1647 quad1.SetValue(myHS1->Surface().Sphere());
1650 quad1.SetValue(myHS1->Surface().Torus());
1653 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
1656 typs = myHS2->Surface().GetType();
1660 quad2.SetValue(myHS2->Surface().Plane());
1662 case GeomAbs_Cylinder:
1663 quad2.SetValue(myHS2->Surface().Cylinder());
1666 quad2.SetValue(myHS2->Surface().Cone());
1668 case GeomAbs_Sphere:
1669 quad2.SetValue(myHS2->Surface().Sphere());
1672 quad2.SetValue(myHS2->Surface().Torus());
1675 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
1679 IntPatch_ALineToWLine convert (quad1, quad2);
1682 aNbParts=myLConstruct.NbParts();
1683 for (i=1; i<=aNbParts; i++) {
1684 myLConstruct.Part(i, fprm, lprm);
1685 Handle(IntPatch_WLine) WL =
1686 convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
1688 Handle(Geom2d_BSplineCurve) H1;
1689 Handle(Geom2d_BSplineCurve) H2;
1692 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1696 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1699 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1703 else { // myApprox=TRUE
1704 GeomInt_WLApprox theapp3d;
1706 Standard_Real tol2d = myTolApprox;
1708 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
1710 aNbParts=myLConstruct.NbParts();
1711 for (i=1; i<=aNbParts; i++) {
1712 myLConstruct.Part(i, fprm, lprm);
1713 Handle(IntPatch_WLine) WL =
1714 convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
1716 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
1718 if (!theapp3d.IsDone()) {
1720 Handle(Geom2d_BSplineCurve) H1;
1721 Handle(Geom2d_BSplineCurve) H2;
1724 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1728 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1731 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1735 if(myApprox1 || myApprox2) {
1736 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
1737 myTolReached2d = theapp3d.TolReached2d();
1741 if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
1742 myTolReached3d = theapp3d.TolReached3d();
1745 Standard_Integer aNbMultiCurves, nbpoles;
1746 aNbMultiCurves=theapp3d.NbMultiCurves();
1747 for (j=1; j<=aNbMultiCurves; j++) {
1748 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1749 nbpoles = mbspc.NbPoles();
1751 TColgp_Array1OfPnt tpoles(1, nbpoles);
1752 mbspc.Curve(1, tpoles);
1753 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1755 mbspc.Multiplicities(),
1758 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1759 Check.FixTangent(Standard_True,Standard_True);
1761 IntTools_Curve aCurve;
1762 aCurve.SetCurve(BS);
1765 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1766 mbspc.Curve(2,tpoles2d);
1767 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1769 mbspc.Multiplicities(),
1772 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1773 newCheck.FixTangent(Standard_True,Standard_True);
1775 aCurve.SetFirstCurve2d(BS2);
1778 Handle(Geom2d_BSplineCurve) H1;
1779 aCurve.SetFirstCurve2d(H1);
1783 TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
1784 Standard_Integer TwoOrThree;
1785 TwoOrThree=myApprox1 ? 3 : 2;
1786 mbspc.Curve(TwoOrThree, tpoles2d);
1787 Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
1789 mbspc.Multiplicities(),
1792 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1793 newCheck.FixTangent(Standard_True,Standard_True);
1795 aCurve.SetSecondCurve2d(BS2);
1798 Handle(Geom2d_BSplineCurve) H2;
1799 aCurve.SetSecondCurve2d(H2);
1802 mySeqOfCurve.Append(aCurve);
1804 }// for (j=1; j<=aNbMultiCurves; j++) {
1805 }// else from if (!theapp3d.IsDone())
1806 }// for (i=1; i<=aNbParts; i++) {
1807 }// else { // myApprox=TRUE
1808 }// case IntPatch_Analytic:
1811 case IntPatch_Walking:{
1812 Handle(IntPatch_WLine) WL =
1813 Handle(IntPatch_WLine)::DownCast(L);
1815 Standard_Integer ifprm, ilprm;
1819 if(!bAvoidLineConstructor){
1820 aNbParts=myLConstruct.NbParts();
1822 for (i=1; i<=aNbParts; ++i) {
1823 Handle(Geom2d_BSplineCurve) H1, H2;
1824 Handle(Geom_Curve) aBSp;
1826 if(bAvoidLineConstructor) {
1828 ilprm = WL->NbPnts();
1831 myLConstruct.Part(i, fprm, lprm);
1832 ifprm=(Standard_Integer)fprm;
1833 ilprm=(Standard_Integer)lprm;
1837 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1841 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1844 aBSp=MakeBSpline(WL, ifprm, ilprm);
1845 IntTools_Curve aIC(aBSp, H1, H2);
1846 mySeqOfCurve.Append(aIC);
1847 }// for (i=1; i<=aNbParts; ++i) {
1848 }// if (!myApprox) {
1851 Standard_Boolean bIsDecomposited;
1852 Standard_Integer nbiter, aNbSeqOfL;
1853 Standard_Real tol2d, aTolApproxImp;
1854 IntPatch_SequenceOfLine aSeqOfL;
1855 GeomInt_WLApprox theapp3d;
1856 Approx_ParametrizationType aParType = Approx_ChordLength;
1858 Standard_Boolean anApprox1 = myApprox1;
1859 Standard_Boolean anApprox2 = myApprox2;
1861 aTolApproxImp=1.e-5;
1862 tol2d = myTolApprox;
1864 GeomAbs_SurfaceType typs1, typs2;
1865 typs1 = myHS1->Surface().GetType();
1866 typs2 = myHS2->Surface().GetType();
1867 Standard_Boolean anWithPC = Standard_True;
1869 if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
1871 ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
1873 else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
1875 ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
1879 myTolApprox = aTolApproxImp;//1.e-5;
1880 anApprox1 = Standard_False;
1881 anApprox2 = Standard_False;
1883 tol2d = myTolApprox;
1886 if(myHS1 == myHS2) {
1887 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1888 rejectSurface = Standard_True;
1891 if(reApprox && !rejectSurface)
1892 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1894 Standard_Integer iDegMax, iDegMin, iNbIter;
1896 ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter);
1897 theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType);
1901 Standard_Real aReachedTol = Precision::Confusion();
1902 bIsDecomposited=DecompositionOfWLine(WL,
1908 bAvoidLineConstructor,
1912 if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) ) {
1913 myTolReached3d = aReachedTol;
1916 aNbSeqOfL=aSeqOfL.Length();
1918 if (bIsDecomposited) {
1924 if (!bAvoidLineConstructor) {
1925 aNbParts=myLConstruct.NbParts();
1930 for(i = 1; i <= nbiter; ++i) {
1931 if(bIsDecomposited) {
1932 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
1934 ilprm = WL->NbPnts();
1937 if(bAvoidLineConstructor) {
1939 ilprm = WL->NbPnts();
1942 myLConstruct.Part(i, fprm, lprm);
1943 ifprm = (Standard_Integer)fprm;
1944 ilprm = (Standard_Integer)lprm;
1948 //-- Si une des surfaces est un plan , on approxime en 2d
1949 //-- sur cette surface et on remonte les points 2d en 3d.
1950 if(typs1 == GeomAbs_Plane) {
1951 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
1953 else if(typs2 == GeomAbs_Plane) {
1954 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
1958 if (myHS1 != myHS2){
1959 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
1960 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
1962 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
1964 Standard_Boolean bUseSurfaces;
1965 bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
1968 rejectSurface = Standard_True;
1970 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1975 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
1978 if (!theapp3d.IsDone()) {
1979 Handle(Geom2d_BSplineCurve) H1;
1980 Handle(Geom2d_BSplineCurve) H2;
1982 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
1985 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1989 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1992 IntTools_Curve aIC(aBSp, H1, H2);
1993 mySeqOfCurve.Append(aIC);
1997 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
1998 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
1999 myTolReached2d = theapp3d.TolReached2d();
2002 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
2003 myTolReached3d = myTolReached2d;
2005 if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
2006 if (myTolReached3d<1.e-6) {
2007 myTolReached3d = theapp3d.TolReached3d();
2008 myTolReached3d=1.e-6;
2012 else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
2013 myTolReached3d = theapp3d.TolReached3d();
2016 Standard_Integer aNbMultiCurves, nbpoles;
2017 aNbMultiCurves=theapp3d.NbMultiCurves();
2018 for (j=1; j<=aNbMultiCurves; j++) {
2019 if(typs1 == GeomAbs_Plane) {
2020 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2021 nbpoles = mbspc.NbPoles();
2023 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2024 TColgp_Array1OfPnt tpoles(1,nbpoles);
2026 mbspc.Curve(1,tpoles2d);
2027 const gp_Pln& Pln = myHS1->Surface().Plane();
2029 Standard_Integer ik;
2030 for(ik = 1; ik<= nbpoles; ik++) {
2032 ElSLib::Value(tpoles2d.Value(ik).X(),
2033 tpoles2d.Value(ik).Y(),
2037 Handle(Geom_BSplineCurve) BS =
2038 new Geom_BSplineCurve(tpoles,
2040 mbspc.Multiplicities(),
2042 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2043 Check.FixTangent(Standard_True, Standard_True);
2045 IntTools_Curve aCurve;
2046 aCurve.SetCurve(BS);
2049 Handle(Geom2d_BSplineCurve) BS1 =
2050 new Geom2d_BSplineCurve(tpoles2d,
2052 mbspc.Multiplicities(),
2054 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2055 Check1.FixTangent(Standard_True,Standard_True);
2057 // ############################################
2058 if(!rejectSurface && !reApprox) {
2059 Standard_Boolean isValid = IsCurveValid(BS1);
2061 reApprox = Standard_True;
2065 // ############################################
2066 aCurve.SetFirstCurve2d(BS1);
2069 Handle(Geom2d_BSplineCurve) H1;
2070 aCurve.SetFirstCurve2d(H1);
2074 mbspc.Curve(2, tpoles2d);
2076 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
2078 mbspc.Multiplicities(),
2080 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2081 newCheck.FixTangent(Standard_True,Standard_True);
2083 // ###########################################
2084 if(!rejectSurface && !reApprox) {
2085 Standard_Boolean isValid = IsCurveValid(BS2);
2087 reApprox = Standard_True;
2091 // ###########################################
2093 aCurve.SetSecondCurve2d(BS2);
2096 Handle(Geom2d_BSplineCurve) H2;
2098 aCurve.SetSecondCurve2d(H2);
2101 mySeqOfCurve.Append(aCurve);
2102 }//if(typs1 == GeomAbs_Plane) {
2104 else if(typs2 == GeomAbs_Plane) {
2105 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2106 nbpoles = mbspc.NbPoles();
2108 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2109 TColgp_Array1OfPnt tpoles(1,nbpoles);
2110 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
2111 const gp_Pln& Pln = myHS2->Surface().Plane();
2113 Standard_Integer ik;
2114 for(ik = 1; ik<= nbpoles; ik++) {
2116 ElSLib::Value(tpoles2d.Value(ik).X(),
2117 tpoles2d.Value(ik).Y(),
2122 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
2124 mbspc.Multiplicities(),
2126 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2127 Check.FixTangent(Standard_True,Standard_True);
2129 IntTools_Curve aCurve;
2130 aCurve.SetCurve(BS);
2133 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
2135 mbspc.Multiplicities(),
2137 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2138 Check1.FixTangent(Standard_True,Standard_True);
2140 // ###########################################
2141 if(!rejectSurface && !reApprox) {
2142 Standard_Boolean isValid = IsCurveValid(BS1);
2144 reApprox = Standard_True;
2148 // ###########################################
2149 bPCurvesOk = CheckPCurve(BS1, myFace2);
2150 aCurve.SetSecondCurve2d(BS1);
2153 Handle(Geom2d_BSplineCurve) H2;
2154 aCurve.SetSecondCurve2d(H2);
2158 mbspc.Curve(1,tpoles2d);
2159 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
2161 mbspc.Multiplicities(),
2163 GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
2164 Check2.FixTangent(Standard_True,Standard_True);
2166 // ###########################################
2167 if(!rejectSurface && !reApprox) {
2168 Standard_Boolean isValid = IsCurveValid(BS2);
2170 reApprox = Standard_True;
2174 // ###########################################
2175 bPCurvesOk = bPCurvesOk && CheckPCurve(BS2, myFace1);
2176 aCurve.SetFirstCurve2d(BS2);
2179 Handle(Geom2d_BSplineCurve) H1;
2181 aCurve.SetFirstCurve2d(H1);
2184 //if points of the pcurves are out of the faces bounds
2185 //create 3d and 2d curves without approximation
2187 Handle(Geom2d_BSplineCurve) H1, H2;
2188 bPCurvesOk = Standard_True;
2190 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
2193 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
2194 bPCurvesOk = CheckPCurve(H1, myFace1);
2198 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
2199 bPCurvesOk = bPCurvesOk && CheckPCurve(H2, myFace2);
2202 //if pcurves created without approximation are out of the
2203 //faces bounds, use approximated 3d and 2d curves
2205 IntTools_Curve aIC(aBSp, H1, H2);
2206 mySeqOfCurve.Append(aIC);
2208 mySeqOfCurve.Append(aCurve);
2211 mySeqOfCurve.Append(aCurve);
2213 }// else if(typs2 == GeomAbs_Plane)
2215 else { //typs2 != GeomAbs_Plane && typs1 != GeomAbs_Plane
2216 Standard_Boolean bIsValid1, bIsValid2;
2217 Handle(Geom_BSplineCurve) BS;
2218 Handle(Geom2d_BSplineCurve) aH2D;
2219 IntTools_Curve aCurve;
2221 bIsValid1=Standard_True;
2222 bIsValid2=Standard_True;
2224 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2225 nbpoles = mbspc.NbPoles();
2226 TColgp_Array1OfPnt tpoles(1,nbpoles);
2227 mbspc.Curve(1,tpoles);
2228 BS=new Geom_BSplineCurve(tpoles,
2230 mbspc.Multiplicities(),
2232 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2233 Check.FixTangent(Standard_True,Standard_True);
2235 aCurve.SetCurve(BS);
2236 aCurve.SetFirstCurve2d(aH2D);
2237 aCurve.SetSecondCurve2d(aH2D);
2241 Handle(Geom2d_BSplineCurve) BS1;
2242 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2243 mbspc.Curve(2,tpoles2d);
2245 BS1=new Geom2d_BSplineCurve(tpoles2d,
2247 mbspc.Multiplicities(),
2249 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
2250 newCheck.FixTangent(Standard_True,Standard_True);
2253 bIsValid1=CheckPCurve(BS1, myFace1);
2256 aCurve.SetFirstCurve2d(BS1);
2259 Handle(Geom2d_BSplineCurve) BS1;
2260 fprm = BS->FirstParameter();
2261 lprm = BS->LastParameter();
2263 Handle(Geom2d_Curve) C2d;
2264 Standard_Real aTol = myTolApprox;
2265 BuildPCurves(fprm, lprm, aTol, myHS1->ChangeSurface().Surface(), BS, C2d);
2266 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2267 aCurve.SetFirstCurve2d(BS1);
2269 } // if(myApprox1) {
2273 Handle(Geom2d_BSplineCurve) BS2;
2274 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2275 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
2276 BS2=new Geom2d_BSplineCurve(tpoles2d,
2278 mbspc.Multiplicities(),
2280 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2281 newCheck.FixTangent(Standard_True,Standard_True);
2284 bIsValid2=CheckPCurve(BS2, myFace2);
2286 aCurve.SetSecondCurve2d(BS2);
2289 Handle(Geom2d_BSplineCurve) BS2;
2290 fprm = BS->FirstParameter();
2291 lprm = BS->LastParameter();
2293 Handle(Geom2d_Curve) C2d;
2294 Standard_Real aTol = myTolApprox;
2295 BuildPCurves(fprm, lprm, aTol, myHS2->ChangeSurface().Surface(), BS, C2d);
2296 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2297 aCurve.SetSecondCurve2d(BS2);
2300 if (!bIsValid1 || !bIsValid2) {
2301 myTolApprox=aTolApproxImp;//1.e-5;
2302 tol2d = myTolApprox;
2303 reApprox = Standard_True;
2307 mySeqOfCurve.Append(aCurve);
2313 }// case IntPatch_Walking:{
2316 case IntPatch_Restriction:
2324 //=======================================================================
2325 //function : BuildPCurves
2327 //=======================================================================
2328 void BuildPCurves (Standard_Real f,
2331 const Handle (Geom_Surface)& S,
2332 const Handle (Geom_Curve)& C,
2333 Handle (Geom2d_Curve)& C2d)
2335 if (!C2d.IsNull()) {
2339 Standard_Real umin,umax,vmin,vmax;
2341 S->Bounds(umin, umax, vmin, vmax);
2342 // in class ProjLib_Function the range of parameters is shrank by 1.e-09
2343 if((l - f) > 2.e-09) {
2344 C2d = GeomProjLib::Curve2d(C,f,l,S,umin,umax,vmin,vmax,Tol);
2347 // proj. a circle that goes through the pole on a sphere to the sphere
2348 Tol += Precision::Confusion();
2349 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2353 if((l - f) > Epsilon(Abs(f))) {
2354 GeomAPI_ProjectPointOnSurf aProjector1, aProjector2;
2355 gp_Pnt P1 = C->Value(f);
2356 gp_Pnt P2 = C->Value(l);
2357 aProjector1.Init(P1, S);
2358 aProjector2.Init(P2, S);
2360 if(aProjector1.IsDone() && aProjector2.IsDone()) {
2361 Standard_Real U=0., V=0.;
2362 aProjector1.LowerDistanceParameters(U, V);
2365 aProjector2.LowerDistanceParameters(U, V);
2368 if(p1.Distance(p2) > gp::Resolution()) {
2369 TColgp_Array1OfPnt2d poles(1,2);
2370 TColStd_Array1OfReal knots(1,2);
2371 TColStd_Array1OfInteger mults(1,2);
2376 mults(1) = mults(2) = 2;
2378 C2d = new Geom2d_BSplineCurve(poles,knots,mults,1);
2380 // compute reached tolerance.begin
2381 gp_Pnt PMid = C->Value((f + l) * 0.5);
2382 aProjector1.Perform(PMid);
2384 if(aProjector1.IsDone()) {
2385 aProjector1.LowerDistanceParameters(U, V);
2386 gp_Pnt2d pmidproj(U, V);
2387 gp_Pnt2d pmidcurve2d = C2d->Value((f + l) * 0.5);
2388 Standard_Real adist = pmidcurve2d.Distance(pmidproj);
2389 Tol = (adist > Tol) ? adist : Tol;
2391 // compute reached tolerance.end
2397 if (S->IsUPeriodic() && !C2d.IsNull()) {
2398 // Recadre dans le domaine UV de la face
2399 Standard_Real aTm, U0, aEps, period, du, U0x;
2400 Standard_Boolean bAdjust;
2402 aEps = Precision::PConfusion();
2403 period = S->UPeriod();
2406 gp_Pnt2d pm = C2d->Value(aTm);
2410 IntTools_Tools::AdjustPeriodic(U0, umin, umax, period, U0x, du, aEps);
2412 gp_Vec2d T1(du, 0.);
2418 //=======================================================================
2419 //function : Parameters
2421 //=======================================================================
2422 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
2423 const Handle(GeomAdaptor_HSurface)& HS2,
2424 const gp_Pnt& Ptref,
2431 IntSurf_Quadric quad1,quad2;
2432 GeomAbs_SurfaceType typs = HS1->Surface().GetType();
2436 quad1.SetValue(HS1->Surface().Plane());
2438 case GeomAbs_Cylinder:
2439 quad1.SetValue(HS1->Surface().Cylinder());
2442 quad1.SetValue(HS1->Surface().Cone());
2444 case GeomAbs_Sphere:
2445 quad1.SetValue(HS1->Surface().Sphere());
2448 quad1.SetValue(HS1->Surface().Torus());
2451 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2454 typs = HS2->Surface().GetType();
2457 quad2.SetValue(HS2->Surface().Plane());
2459 case GeomAbs_Cylinder:
2460 quad2.SetValue(HS2->Surface().Cylinder());
2463 quad2.SetValue(HS2->Surface().Cone());
2465 case GeomAbs_Sphere:
2466 quad2.SetValue(HS2->Surface().Sphere());
2469 quad2.SetValue(HS2->Surface().Torus());
2472 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2475 quad1.Parameters(Ptref,U1,V1);
2476 quad2.Parameters(Ptref,U2,V2);
2479 //=======================================================================
2480 //function : MakeBSpline
2482 //=======================================================================
2483 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
2484 const Standard_Integer ideb,
2485 const Standard_Integer ifin)
2487 Standard_Integer i,nbpnt = ifin-ideb+1;
2488 TColgp_Array1OfPnt poles(1,nbpnt);
2489 TColStd_Array1OfReal knots(1,nbpnt);
2490 TColStd_Array1OfInteger mults(1,nbpnt);
2491 Standard_Integer ipidebm1;
2492 for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) {
2493 poles(i) = WL->Point(ipidebm1).Value();
2497 mults(1) = mults(nbpnt) = 2;
2499 new Geom_BSplineCurve(poles,knots,mults,1);
2503 //=======================================================================
2504 //function : MakeBSpline2d
2506 //=======================================================================
2507 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
2508 const Standard_Integer ideb,
2509 const Standard_Integer ifin,
2510 const Standard_Boolean onFirst)
2512 Standard_Integer i, nbpnt = ifin-ideb+1;
2513 TColgp_Array1OfPnt2d poles(1,nbpnt);
2514 TColStd_Array1OfReal knots(1,nbpnt);
2515 TColStd_Array1OfInteger mults(1,nbpnt);
2516 Standard_Integer ipidebm1;
2518 for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
2521 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
2523 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
2524 poles(i).SetCoord(U, V);
2528 mults(1) = mults(nbpnt) = 2;
2530 return new Geom2d_BSplineCurve(poles,knots,mults,1);
2532 //=======================================================================
2533 //function : PrepareLines3D
2535 //=======================================================================
2536 void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit)
2538 Standard_Integer i, aNbCurves;
2539 GeomAbs_SurfaceType aType1, aType2;
2540 IntTools_SequenceOfCurves aNewCvs;
2542 // 1. Treatment closed curves
2543 aNbCurves=mySeqOfCurve.Length();
2544 for (i=1; i<=aNbCurves; ++i) {
2545 const IntTools_Curve& aIC=mySeqOfCurve(i);
2548 Standard_Integer j, aNbC;
2549 IntTools_SequenceOfCurves aSeqCvs;
2551 aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
2553 for (j=1; j<=aNbC; ++j) {
2554 const IntTools_Curve& aICNew=aSeqCvs(j);
2555 aNewCvs.Append(aICNew);
2559 aNewCvs.Append(aIC);
2563 aNewCvs.Append(aIC);
2567 // 2. Plane\Cone intersection when we had 4 curves
2568 aType1=myHS1->GetType();
2569 aType2=myHS2->GetType();
2570 aNbCurves=aNewCvs.Length();
2572 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) ||
2573 (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) {
2575 GeomAbs_CurveType aCType1;
2577 aCType1=aNewCvs(1).Type();
2578 if (aCType1==GeomAbs_Line) {
2579 IntTools_SequenceOfCurves aSeqIn, aSeqOut;
2581 for (i=1; i<=aNbCurves; ++i) {
2582 const IntTools_Curve& aIC=aNewCvs(i);
2586 IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
2589 aNbCurves=aSeqOut.Length();
2590 for (i=1; i<=aNbCurves; ++i) {
2591 const IntTools_Curve& aIC=aSeqOut(i);
2592 aNewCvs.Append(aIC);
2596 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)...
2598 // 3. Fill mySeqOfCurve
2599 mySeqOfCurve.Clear();
2600 aNbCurves=aNewCvs.Length();
2601 for (i=1; i<=aNbCurves; ++i) {
2602 const IntTools_Curve& aIC=aNewCvs(i);
2603 mySeqOfCurve.Append(aIC);
2606 //=======================================================================
2607 //function : CorrectSurfaceBoundaries
2609 //=======================================================================
2610 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
2611 const Standard_Real theTolerance,
2612 Standard_Real& theumin,
2613 Standard_Real& theumax,
2614 Standard_Real& thevmin,
2615 Standard_Real& thevmax)
2617 Standard_Boolean enlarge, isuperiodic, isvperiodic;
2618 Standard_Real uinf, usup, vinf, vsup, delta;
2619 GeomAbs_SurfaceType aType;
2620 Handle(Geom_Surface) aSurface;
2622 aSurface = BRep_Tool::Surface(theFace);
2623 aSurface->Bounds(uinf, usup, vinf, vsup);
2624 delta = theTolerance;
2625 enlarge = Standard_False;
2627 GeomAdaptor_Surface anAdaptorSurface(aSurface);
2629 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
2630 Handle(Geom_Surface) aBasisSurface =
2631 (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface();
2633 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2634 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2639 if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2640 Handle(Geom_Surface) aBasisSurface =
2641 (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface();
2643 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2644 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2649 isuperiodic = anAdaptorSurface.IsUPeriodic();
2650 isvperiodic = anAdaptorSurface.IsVPeriodic();
2652 aType=anAdaptorSurface.GetType();
2653 if((aType==GeomAbs_BezierSurface) ||
2654 (aType==GeomAbs_BSplineSurface) ||
2655 (aType==GeomAbs_SurfaceOfExtrusion) ||
2656 (aType==GeomAbs_SurfaceOfRevolution) ||
2657 (aType==GeomAbs_Cylinder)) {
2658 enlarge=Standard_True;
2661 if(!isuperiodic && enlarge) {
2663 if((theumin - uinf) > delta )
2669 if((usup - theumax) > delta )
2675 if(!isvperiodic && enlarge) {
2676 if((thevmin - vinf) > delta ) {
2682 if((vsup - thevmax) > delta ) {
2691 Standard_Integer aNbP;
2692 Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA;
2694 aTolPA=Precision::Angular();
2697 aXP=anAdaptorSurface.UPeriod();
2698 dXfact=theumax-theumin;
2699 if (dXfact-aTolPA>aXP) {
2700 aXmid=0.5*(theumax+theumin);
2701 aNbP=RealToInt(aXmid/aXP);
2706 if (theumin>aTolPA) {
2707 aX1=theumin+aNbP*aXP;
2720 aXP=anAdaptorSurface.VPeriod();
2721 dXfact=thevmax-thevmin;
2722 if (dXfact-aTolPA>aXP) {
2723 aXmid=0.5*(thevmax+thevmin);
2724 aNbP=RealToInt(aXmid/aXP);
2729 if (thevmin>aTolPA) {
2730 aX1=thevmin+aNbP*aXP;
2743 if(isuperiodic || isvperiodic) {
2744 Standard_Boolean correct = Standard_False;
2745 Standard_Boolean correctU = Standard_False;
2746 Standard_Boolean correctV = Standard_False;
2748 TopExp_Explorer anExp;
2750 for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2751 if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
2752 correct = Standard_True;
2754 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
2756 for(Standard_Integer i = 0; i < 2; i++) {
2758 anEdge.Orientation(TopAbs_FORWARD);
2761 anEdge.Orientation(TopAbs_REVERSED);
2763 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
2765 if(aCurve.IsNull()) {
2766 correct = Standard_False;
2769 Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
2771 if(aLine.IsNull()) {
2772 correct = Standard_False;
2775 gp_Dir2d anUDir(1., 0.);
2776 gp_Dir2d aVDir(0., 1.);
2777 Standard_Real anAngularTolerance = Precision::Angular();
2779 correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
2780 correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
2782 gp_Pnt2d pp1 = aCurve->Value(f);
2784 gp_Pnt2d pp2 = aCurve->Value(l);
2793 Standard_Real umin, vmin, umax, vmax;
2794 aBox.Get(umin, vmin, umax, vmax);
2796 if(isuperiodic && correctU) {
2801 if(theumax > umax) {
2805 if(isvperiodic && correctV) {
2817 // The block is dedicated to determine whether WLine [ifprm, ilprm]
2818 // crosses the degenerated zone on each given surface or not.
2819 // If Yes -> We will not use info about surfaces during approximation
2820 // because inside degenerated zone of the surface the approx. algo.
2821 // uses wrong values of normal, etc., and resulting curve will have
2822 // oscillations that we would not like to have.
2827 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2828 const Handle(Geom_Surface)& aS,
2829 const Standard_Integer iDir);
2831 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2832 const TopoDS_Face& aF1,
2833 const TopoDS_Face& aF2);
2834 //=======================================================================
2835 //function : NotUseSurfacesForApprox
2837 //=======================================================================
2838 Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
2839 const TopoDS_Face& aF2,
2840 const Handle(IntPatch_WLine)& WL,
2841 const Standard_Integer ifprm,
2842 const Standard_Integer ilprm)
2844 Standard_Boolean bPInDZ;
2846 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
2848 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
2849 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
2854 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
2855 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
2859 //=======================================================================
2860 //function : IsPointInDegeneratedZone
2862 //=======================================================================
2863 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2864 const TopoDS_Face& aF1,
2865 const TopoDS_Face& aF2)
2868 Standard_Boolean bFlag=Standard_True;
2869 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
2870 Standard_Real U1, V1, U2, V2, aDelta, aD;
2873 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
2874 aS1->Bounds(US11, US12, VS11, VS12);
2875 GeomAdaptor_Surface aGAS1(aS1);
2877 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
2878 aS1->Bounds(US21, US22, VS21, VS22);
2879 GeomAdaptor_Surface aGAS2(aS2);
2881 //const gp_Pnt& aP=aP2S.Value();
2882 aP2S.Parameters(U1, V1, U2, V2);
2886 aD=aGAS1.UResolution(aDelta);
2887 aP2d.SetCoord(U1, V1);
2888 if (fabs(U1-US11) < aD) {
2889 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2894 if (fabs(U1-US12) < aD) {
2895 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2900 aD=aGAS1.VResolution(aDelta);
2901 if (fabs(V1-VS11) < aDelta) {
2902 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2907 if (fabs(V1-VS12) < aDelta) {
2908 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2914 aD=aGAS2.UResolution(aDelta);
2915 aP2d.SetCoord(U2, V2);
2916 if (fabs(U2-US21) < aDelta) {
2917 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2922 if (fabs(U2-US22) < aDelta) {
2923 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2928 aD=aGAS2.VResolution(aDelta);
2929 if (fabs(V2-VS21) < aDelta) {
2930 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2935 if (fabs(V2-VS22) < aDelta) {
2936 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2944 //=======================================================================
2945 //function : IsDegeneratedZone
2947 //=======================================================================
2948 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2949 const Handle(Geom_Surface)& aS,
2950 const Standard_Integer iDir)
2952 Standard_Boolean bFlag=Standard_True;
2953 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
2954 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
2955 aS->Bounds(US1, US2, VS1, VS2);
2957 gp_Pnt aPm, aPb, aPe;
2962 aS->D0(aXm, aYm, aPm);
2979 aS->D0(aXb, aYb, aPb);
2980 aS->D0(aXe, aYe, aPe);
2982 d1=aPm.Distance(aPb);
2983 d2=aPm.Distance(aPe);
2984 if (d1 < dD && d2 < dD) {
3001 aS->D0(aXb, aYb, aPb);
3002 aS->D0(aXe, aYe, aPe);
3004 d1=aPm.Distance(aPb);
3005 d2=aPm.Distance(aPe);
3006 if (d1 < dD && d2 < dD) {
3014 //=========================================================================
3015 // static function : ComputePurgedWLine
3016 // purpose : Removes equal points (leave one of equal points) from theWLine
3017 // and recompute vertex parameters.
3018 // Returns new WLine or null WLine if the number
3019 // of the points is less than 2.
3020 //=========================================================================
3021 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) {
3023 Standard_Integer i, k, v, nb, nbvtx;
3024 Handle(IntPatch_WLine) aResult;
3025 nbvtx = theWLine->NbVertex();
3026 nb = theWLine->NbPnts();
3028 const IntSurf_PntOn2S& p1 = theWLine->Point(1);
3029 const IntSurf_PntOn2S& p2 = theWLine->Point(2);
3030 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
3035 Handle(IntPatch_WLine) aLocalWLine;
3036 Handle(IntPatch_WLine) aTmpWLine = theWLine;
3037 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
3038 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
3039 for(i = 1; i <= nb; i++) {
3040 aLineOn2S->Add(theWLine->Point(i));
3043 for(v = 1; v <= nbvtx; v++) {
3044 aLocalWLine->AddVertex(theWLine->Vertex(v));
3047 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
3048 Standard_Integer aStartIndex = i + 1;
3049 Standard_Integer anEndIndex = i + 5;
3050 nb = aLineOn2S->NbPoints();
3051 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
3053 if((aStartIndex > nb) || (anEndIndex <= 1)) {
3058 while(k <= anEndIndex) {
3061 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
3062 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
3064 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
3065 aTmpWLine = aLocalWLine;
3066 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
3068 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
3069 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
3070 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
3072 if(avertexindex >= k) {
3073 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
3075 aLocalWLine->AddVertex(aVertex);
3077 aLineOn2S->RemovePoint(k);
3086 if(aLineOn2S->NbPoints() > 1) {
3087 aResult = aLocalWLine;
3092 //=======================================================================
3095 //=======================================================================
3096 void TolR3d(const TopoDS_Face& aF1,
3097 const TopoDS_Face& aF2,
3098 Standard_Real& myTolReached3d)
3100 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
3102 aTolTresh=2.999999e-3;
3103 aTolF1 = BRep_Tool::Tolerance(aF1);
3104 aTolF2 = BRep_Tool::Tolerance(aF2);
3105 aTolFMax=Max(aTolF1, aTolF2);
3107 if (aTolFMax>aTolTresh) {
3108 myTolReached3d=aTolFMax;
3111 //=======================================================================
3112 //function : IsPointOnBoundary
3114 //=======================================================================
3115 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
3116 const Standard_Real theFirstBoundary,
3117 const Standard_Real theSecondBoundary,
3118 const Standard_Real theResolution,
3119 Standard_Boolean& IsOnFirstBoundary)
3121 Standard_Boolean bRet;
3123 Standard_Real adist;
3125 bRet=Standard_False;
3126 for(i = 0; i < 2; ++i) {
3127 IsOnFirstBoundary = (i == 0);
3128 if (IsOnFirstBoundary) {
3129 adist = fabs(theParameter - theFirstBoundary);
3132 adist = fabs(theParameter - theSecondBoundary);
3134 if(adist < theResolution) {
3140 // ------------------------------------------------------------------------------------------------
3141 // static function: FindPoint
3143 // ------------------------------------------------------------------------------------------------
3144 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3145 const gp_Pnt2d& theLastPoint,
3146 const Standard_Real theUmin,
3147 const Standard_Real theUmax,
3148 const Standard_Real theVmin,
3149 const Standard_Real theVmax,
3150 gp_Pnt2d& theNewPoint) {
3152 gp_Vec2d aVec(theFirstPoint, theLastPoint);
3153 Standard_Integer i = 0, j = 0;
3155 for(i = 0; i < 4; i++) {
3156 gp_Vec2d anOtherVec;
3157 gp_Vec2d anOtherVecNormal;
3158 gp_Pnt2d aprojpoint = theLastPoint;
3161 anOtherVec.SetX(0.);
3162 anOtherVec.SetY(1.);
3163 anOtherVecNormal.SetX(1.);
3164 anOtherVecNormal.SetY(0.);
3167 aprojpoint.SetX(theUmin);
3169 aprojpoint.SetX(theUmax);
3172 anOtherVec.SetX(1.);
3173 anOtherVec.SetY(0.);
3174 anOtherVecNormal.SetX(0.);
3175 anOtherVecNormal.SetY(1.);
3178 aprojpoint.SetY(theVmin);
3180 aprojpoint.SetY(theVmax);
3182 gp_Vec2d anormvec = aVec;
3183 anormvec.Normalize();
3184 RefineVector(anormvec);
3185 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
3187 if(fabs(adot1) < Precision::Angular())
3189 Standard_Real adist = 0.;
3190 Standard_Boolean bIsOut = Standard_False;
3193 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
3194 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
3197 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
3198 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
3200 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
3202 for(j = 0; j < 2; j++) {
3203 anoffset = (j == 0) ? anoffset : -anoffset;
3204 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
3205 gp_Vec2d acurvec(theLastPoint, acurpoint);
3209 Standard_Real aDotX, anAngleX;
3211 aDotX = aVec.Dot(acurvec);
3212 anAngleX = aVec.Angle(acurvec);
3214 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
3216 if((acurpoint.Y() >= theVmin) &&
3217 (acurpoint.Y() <= theVmax)) {
3218 theNewPoint = acurpoint;
3219 return Standard_True;
3223 if((acurpoint.X() >= theUmin) &&
3224 (acurpoint.X() <= theUmax)) {
3225 theNewPoint = acurpoint;
3226 return Standard_True;
3232 return Standard_False;
3236 // ------------------------------------------------------------------------------------------------
3237 // static function: FindPoint
3238 // purpose: Find point on the boundary of radial tangent zone
3239 // ------------------------------------------------------------------------------------------------
3240 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3241 const gp_Pnt2d& theLastPoint,
3242 const Standard_Real theUmin,
3243 const Standard_Real theUmax,
3244 const Standard_Real theVmin,
3245 const Standard_Real theVmax,
3246 const gp_Pnt2d& theTanZoneCenter,
3247 const Standard_Real theZoneRadius,
3248 Handle(GeomAdaptor_HSurface) theGASurface,
3249 gp_Pnt2d& theNewPoint) {
3250 theNewPoint = theLastPoint;
3252 if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
3253 return Standard_False;
3255 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3256 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3258 Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3259 gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) );
3260 gp_Circ2d aCircle( anAxis, aRadius );
3263 gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() );
3264 Standard_Real aLength = aDir.Magnitude();
3265 if ( aLength <= gp::Resolution() )
3266 return Standard_False;
3267 gp_Lin2d aLine( theFirstPoint, aDir );
3270 Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine );
3271 Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength );
3272 Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle );
3274 Standard_Real aTol = aRadius * 0.001;
3275 aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol;
3277 Geom2dAPI_InterCurveCurve anIntersector;
3278 anIntersector.Init( aC1, aC2, aTol );
3280 if ( anIntersector.NbPoints() == 0 )
3281 return Standard_False;
3283 Standard_Boolean aFound = Standard_False;
3284 Standard_Real aMinDist = aLength * aLength;
3285 Standard_Integer i = 0;
3286 for ( i = 1; i <= anIntersector.NbPoints(); i++ ) {
3287 gp_Pnt2d aPInt = anIntersector.Point( i );
3288 if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
3289 if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
3290 ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
3291 theNewPoint = aPInt;
3292 aFound = Standard_True;
3300 // ------------------------------------------------------------------------------------------------
3301 // static function: IsInsideTanZone
3302 // purpose: Check if point is inside a radial tangent zone
3303 // ------------------------------------------------------------------------------------------------
3304 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
3305 const gp_Pnt2d& theTanZoneCenter,
3306 const Standard_Real theZoneRadius,
3307 Handle(GeomAdaptor_HSurface) theGASurface) {
3309 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3310 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3311 Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3312 aRadiusSQR *= aRadiusSQR;
3313 if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR )
3314 return Standard_True;
3315 return Standard_False;
3318 // ------------------------------------------------------------------------------------------------
3319 // static function: CheckTangentZonesExist
3320 // purpose: Check if tangent zone exists
3321 // ------------------------------------------------------------------------------------------------
3322 Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
3323 const Handle(GeomAdaptor_HSurface)& theSurface2 )
3325 if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
3326 ( theSurface2->GetType() != GeomAbs_Torus ) )
3327 return Standard_False;
3329 gp_Torus aTor1 = theSurface1->Torus();
3330 gp_Torus aTor2 = theSurface2->Torus();
3332 if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() )
3333 return Standard_False;
3335 if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) ||
3336 ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) )
3337 return Standard_False;
3339 if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) ||
3340 ( aTor2.MajorRadius() < aTor2.MinorRadius() ) )
3341 return Standard_False;
3342 return Standard_True;
3345 // ------------------------------------------------------------------------------------------------
3346 // static function: ComputeTangentZones
3348 // ------------------------------------------------------------------------------------------------
3349 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
3350 const Handle(GeomAdaptor_HSurface)& theSurface2,
3351 const TopoDS_Face& theFace1,
3352 const TopoDS_Face& theFace2,
3353 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
3354 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
3355 Handle(TColStd_HArray1OfReal)& theResultRadius,
3356 const Handle(IntTools_Context)& aContext)
3358 Standard_Integer aResult = 0;
3359 if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) )
3363 TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2;
3364 TColStd_SequenceOfReal aSeqResultRad;
3366 gp_Torus aTor1 = theSurface1->Torus();
3367 gp_Torus aTor2 = theSurface2->Torus();
3369 gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() );
3370 gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() );
3371 Standard_Integer j = 0;
3373 for ( j = 0; j < 2; j++ ) {
3374 Standard_Real aCoef = ( j == 0 ) ? -1 : 1;
3375 Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius());
3376 Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius());
3378 gp_Circ aCircle1( anax1, aRadius1 );
3379 gp_Circ aCircle2( anax2, aRadius2 );
3381 // roughly compute radius of tangent zone for perpendicular case
3382 Standard_Real aCriteria = Precision::Confusion() * 0.5;
3384 Standard_Real aT1 = aCriteria;
3385 Standard_Real aT2 = aCriteria;
3387 // internal tangency
3388 Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3389 //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria );
3390 aT1 = 2. * aR * aCriteria;
3394 // external tangency
3395 Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3396 Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3397 Standard_Real aDelta = aRb - aCriteria;
3399 aDelta -= aRm * aRm;
3400 aDelta /= 2. * (aRb - aRm);
3401 aDelta -= 0.5 * (aRb - aRm);
3403 aT1 = 2. * aRm * (aRm - aDelta);
3406 aCriteria = ( aT1 > aT2) ? aT1 : aT2;
3407 if ( aCriteria > 0 )
3408 aCriteria = sqrt( aCriteria );
3410 if ( aCriteria > 0.5 * aTor1.MinorRadius() ) {
3411 // too big zone -> drop to minimum
3412 aCriteria = Precision::Confusion();
3415 GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) );
3416 GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) );
3417 Extrema_ExtCC anExtrema(aC1, aC2, 0, 2. * M_PI, 0, 2. * M_PI,
3418 Precision::PConfusion(), Precision::PConfusion());
3420 if ( anExtrema.IsDone() ) {
3422 Standard_Integer i = 0;
3423 for ( i = 1; i <= anExtrema.NbExt(); i++ ) {
3424 if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
3427 Extrema_POnCurv P1, P2;
3428 anExtrema.Points( i, P1, P2 );
3430 Standard_Boolean bFoundResult = Standard_True;
3433 Standard_Integer surfit = 0;
3434 for ( surfit = 0; surfit < 2; surfit++ ) {
3435 GeomAPI_ProjectPointOnSurf& aProjector =
3436 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3438 gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
3439 aProjector.Perform(aP3d);
3441 if(!aProjector.IsDone())
3442 bFoundResult = Standard_False;
3444 if(aProjector.LowerDistance() > aCriteria) {
3445 bFoundResult = Standard_False;
3448 Standard_Real foundU = 0, foundV = 0;
3449 aProjector.LowerDistanceParameters(foundU, foundV);
3451 pr1 = gp_Pnt2d( foundU, foundV );
3453 pr2 = gp_Pnt2d( foundU, foundV );
3457 if ( bFoundResult ) {
3458 aSeqResultS1.Append( pr1 );
3459 aSeqResultS2.Append( pr2 );
3460 aSeqResultRad.Append( aCriteria );
3462 // torus is u and v periodic
3463 const Standard_Real twoPI = M_PI + M_PI;
3464 Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
3465 Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
3467 // iteration on period bounds
3468 for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
3469 Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
3470 Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
3472 // iteration on surfaces
3473 for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
3474 Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
3475 Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
3476 TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
3477 TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
3479 if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
3480 aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
3481 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3482 aSeqResultRad.Append( aCriteria );
3484 if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
3485 aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
3486 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3487 aSeqResultRad.Append( aCriteria );
3495 aResult = aSeqResultRad.Length();
3497 if ( aResult > 0 ) {
3498 theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult );
3499 theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult );
3500 theResultRadius = new TColStd_HArray1OfReal( 1, aResult );
3502 for ( Standard_Integer i = 1 ; i <= aResult; i++ ) {
3503 theResultOnS1->SetValue( i, aSeqResultS1.Value(i) );
3504 theResultOnS2->SetValue( i, aSeqResultS2.Value(i) );
3505 theResultRadius->SetValue( i, aSeqResultRad.Value(i) );
3511 // ------------------------------------------------------------------------------------------------
3512 // static function: AdjustByNeighbour
3514 // ------------------------------------------------------------------------------------------------
3515 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
3516 const gp_Pnt2d& theOriginalPoint,
3517 Handle(GeomAdaptor_HSurface) theGASurface) {
3519 gp_Pnt2d ap1 = theaNeighbourPoint;
3520 gp_Pnt2d ap2 = theOriginalPoint;
3522 if ( theGASurface->IsUPeriodic() ) {
3523 Standard_Real aPeriod = theGASurface->UPeriod();
3524 gp_Pnt2d aPTest = ap2;
3525 Standard_Real aSqDistMin = 1.e+100;
3527 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3528 aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt );
3529 Standard_Real dd = ap1.SquareDistance( aPTest );
3531 if ( dd < aSqDistMin ) {
3537 if ( theGASurface->IsVPeriodic() ) {
3538 Standard_Real aPeriod = theGASurface->VPeriod();
3539 gp_Pnt2d aPTest = ap2;
3540 Standard_Real aSqDistMin = 1.e+100;
3542 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3543 aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt );
3544 Standard_Real dd = ap1.SquareDistance( aPTest );
3546 if ( dd < aSqDistMin ) {
3555 // ------------------------------------------------------------------------------------------------
3556 //function: DecompositionOfWLine
3558 // ------------------------------------------------------------------------------------------------
3559 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
3560 const Handle(GeomAdaptor_HSurface)& theSurface1,
3561 const Handle(GeomAdaptor_HSurface)& theSurface2,
3562 const TopoDS_Face& theFace1,
3563 const TopoDS_Face& theFace2,
3564 const IntTools_LineConstructor& theLConstructor,
3565 const Standard_Boolean theAvoidLConstructor,
3566 IntPatch_SequenceOfLine& theNewLines,
3567 Standard_Real& theReachedTol3d,
3568 const Handle(IntTools_Context)& aContext)
3571 Standard_Boolean bRet, bAvoidLineConstructor;
3572 Standard_Integer aNbPnts, aNbParts;
3574 bRet=Standard_False;
3575 aNbPnts=theWLine->NbPnts();
3576 bAvoidLineConstructor=theAvoidLConstructor;
3581 if (!bAvoidLineConstructor) {
3582 aNbParts=theLConstructor.NbParts();
3588 Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary;
3589 Standard_Integer nblines, pit, i, j;
3591 TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts);
3592 TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts);
3593 TColStd_ListOfInteger aListOfPointIndex;
3595 Handle(TColgp_HArray1OfPnt2d) aTanZoneS1;
3596 Handle(TColgp_HArray1OfPnt2d) aTanZoneS2;
3597 Handle(TColStd_HArray1OfReal) aTanZoneRadius;
3598 Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2,
3599 aTanZoneS1, aTanZoneS2, aTanZoneRadius, aContext);
3603 aTol=Precision::Confusion();
3605 bIsPrevPointOnBoundary=Standard_False;
3606 bIsPointOnBoundary=Standard_False;
3611 for(pit = 1; pit <= aNbPnts; ++pit) {
3612 Standard_Boolean bIsOnFirstBoundary, isperiodic;
3613 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
3614 Standard_Real aParameter, anoffset, anAdjustPar;
3615 Standard_Real umin, umax, vmin, vmax;
3617 bIsCurrentPointOnBoundary = Standard_False;
3618 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
3621 for(i = 0; i < 2; ++i) {
3622 Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
3623 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3625 aPoint.ParametersOnS1(U, V);
3628 aPoint.ParametersOnS2(U, V);
3631 for(j = 0; j < 2; j++) {
3632 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3638 aResolution=aGASurface->UResolution(aTol);
3639 aPeriod=aGASurface->UPeriod();
3640 alowerboundary=umin;
3641 aupperboundary=umax;
3645 aResolution=aGASurface->VResolution(aTol);
3646 aPeriod=aGASurface->VPeriod();
3647 alowerboundary=vmin;
3648 aupperboundary=vmax;
3652 IntTools_Tools::AdjustPeriodic(aParameter,
3659 bIsOnFirstBoundary = Standard_True;// ?
3661 IsPointOnBoundary(anAdjustPar,
3665 bIsOnFirstBoundary);
3667 if(bIsPointOnBoundary) {
3668 bIsCurrentPointOnBoundary = Standard_True;
3672 // check if a point belong to a tangent zone. Begin
3673 Standard_Integer zIt = 0;
3674 for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
3675 gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3676 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3678 if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
3679 // set boundary flag to split the curve by a tangent zone
3680 bIsPointOnBoundary = Standard_True;
3681 bIsCurrentPointOnBoundary = Standard_True;
3682 if ( theReachedTol3d < aZoneRadius ) {
3683 theReachedTol3d = aZoneRadius;
3689 }//for(j = 0; j < 2; j++) {
3691 if(bIsCurrentPointOnBoundary){
3694 }//for(i = 0; i < 2; ++i) {
3696 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
3697 if(!aListOfPointIndex.IsEmpty()) {
3699 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3700 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3701 aListOfPointIndex.Clear();
3703 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
3705 aListOfPointIndex.Append(pit);
3706 } //for(pit = 1; pit <= aNbPnts; ++pit) {
3708 if(!aListOfPointIndex.IsEmpty()) {
3710 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3711 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3712 aListOfPointIndex.Clear();
3716 return bRet; //Standard_False;
3720 // 2. Correct wlines.begin
3721 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
3722 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S();
3724 for(i = 1; i <= nblines; i++) {
3725 if(anArrayOfLineType.Value(i) != 0) {
3728 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3729 if(aListOfIndex.Extent() < 2) {
3732 TColStd_ListOfInteger aListOfFLIndex;
3734 for(j = 0; j < 2; j++) {
3735 Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1);
3737 if((aneighbourindex < 1) || (aneighbourindex > nblines))
3740 if(anArrayOfLineType.Value(aneighbourindex) == 0)
3742 const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex);
3743 Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First();
3744 const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
3746 IntSurf_PntOn2S aNewP = aPoint;
3748 for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
3750 Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
3751 Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
3752 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3753 Standard_Real U=0., V=0.;
3756 aNewP.ParametersOnS1(U, V);
3758 aNewP.ParametersOnS2(U, V);
3759 Standard_Integer nbboundaries = 0;
3761 Standard_Boolean bIsNearBoundary = Standard_False;
3762 Standard_Integer aZoneIndex = 0;
3763 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
3764 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
3767 for(Standard_Integer parit = 0; parit < 2; parit++) {
3768 Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3770 Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
3771 Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
3772 Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
3774 Standard_Real aParameter = (parit == 0) ? U : V;
3775 Standard_Boolean bIsOnFirstBoundary = Standard_True;
3779 IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3780 if(bIsPointOnBoundary) {
3781 bIsUBoundary = (parit == 0);
3782 bIsFirstBoundary = bIsOnFirstBoundary;
3787 Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3788 Standard_Real anoffset, anAdjustPar;
3789 IntTools_Tools::AdjustPeriodic(aParameter, alowerboundary, aupperboundary,
3790 aPeriod, anAdjustPar, anoffset);
3793 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3794 if(bIsPointOnBoundary) {
3795 bIsUBoundary = (parit == 0);
3796 bIsFirstBoundary = bIsOnFirstBoundary;
3800 //check neighbourhood of boundary
3801 Standard_Real anEpsilon = aResolution * 100.;
3802 Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
3803 anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
3805 bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
3806 anEpsilon, bIsOnFirstBoundary);
3812 // check if a point belong to a tangent zone. Begin
3813 for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
3814 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3815 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3817 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3818 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3819 Standard_Real nU1, nV1;
3822 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3824 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3825 gp_Pnt2d ap1(nU1, nV1);
3826 gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
3829 if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
3831 bIsNearBoundary = Standard_True;
3832 if ( theReachedTol3d < aZoneRadius ) {
3833 theReachedTol3d = aZoneRadius;
3837 // check if a point belong to a tangent zone. End
3838 Standard_Boolean bComputeLineEnd = Standard_False;
3840 if(nbboundaries == 2) {
3842 bComputeLineEnd = Standard_True;
3845 else if(nbboundaries == 1) {
3846 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3849 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
3850 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
3851 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3852 Standard_Real aParameter = (bIsUBoundary) ? U : V;
3853 Standard_Real anoffset, anAdjustPar;
3854 IntTools_Tools::AdjustPeriodic(aParameter, alowerboundary, aupperboundary,
3855 aPeriod, anAdjustPar, anoffset);
3857 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
3858 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
3859 anotherPar += anoffset;
3860 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3861 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
3862 Standard_Real nU1, nV1;
3865 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3867 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3869 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
3870 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
3871 bComputeLineEnd = Standard_True;
3872 Standard_Boolean bCheckAngle1 = Standard_False;
3873 Standard_Boolean bCheckAngle2 = Standard_False;
3875 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
3876 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
3878 if(((adist1 - adist2) > Precision::PConfusion()) &&
3879 (adist2 < (aPeriod / 4.))) {
3880 bCheckAngle1 = Standard_True;
3881 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
3883 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3884 aNewP.SetValue((surfit == 0), anewU, anewV);
3885 bCheckAngle1 = Standard_False;
3888 else if(adist1 < (aPeriod / 4.)) {
3889 bCheckAngle2 = Standard_True;
3890 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
3892 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3893 bCheckAngle2 = Standard_False;
3897 if(bCheckAngle1 || bCheckAngle2) {
3898 // assume there are at least two points in line (see "if" above)
3899 Standard_Integer anindexother = aneighbourpointindex;
3901 while((anindexother <= aListOfIndex.Last()) && (anindexother >= aListOfIndex.First())) {
3902 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
3903 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
3904 Standard_Real nU2, nV2;
3907 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3909 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3910 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
3912 if(aVecOld.SquareMagnitude() <= (gp::Resolution() * gp::Resolution())) {
3916 Standard_Real anAngle = aNewVec.Angle(aVecOld);
3918 if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
3921 Standard_Real U1, U2, V1, V2;
3922 IntSurf_PntOn2S atmppoint = aNewP;
3923 atmppoint.SetValue((surfit == 0), anewU, anewV);
3924 atmppoint.Parameters(U1, V1, U2, V2);
3925 gp_Pnt P1 = theSurface1->Value(U1, V1);
3926 gp_Pnt P2 = theSurface2->Value(U2, V2);
3927 gp_Pnt P0 = aPoint.Value();
3929 if(P0.IsEqual(P1, aTol) &&
3930 P0.IsEqual(P2, aTol) &&
3931 P1.IsEqual(P2, aTol)) {
3932 bComputeLineEnd = Standard_False;
3933 aNewP.SetValue((surfit == 0), anewU, anewV);
3938 bComputeLineEnd = Standard_False;
3943 } // end while(anindexother...)
3947 else if ( bIsNearBoundary ) {
3948 bComputeLineEnd = Standard_True;
3951 if(bComputeLineEnd) {
3954 Standard_Boolean found = Standard_False;
3956 if ( bIsNearBoundary ) {
3957 // re-compute point near natural boundary or near tangent zone
3958 Standard_Real u1, v1, u2, v2;
3959 aNewP.Parameters( u1, v1, u2, v2 );
3961 anewpoint = gp_Pnt2d( u1, v1 );
3963 anewpoint = gp_Pnt2d( u2, v2 );
3965 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3966 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3967 Standard_Real nU1, nV1;
3970 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3972 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3973 gp_Pnt2d ap1(nU1, nV1);
3978 // exclude point from a tangent zone
3979 anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3980 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
3981 Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
3983 if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
3984 aPZone, aZoneRadius, aGASurface, ap2) ) {
3986 found = Standard_True;
3989 else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
3990 // re-compute point near boundary if shifted on a period
3991 ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3993 if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
3994 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
3995 found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
3999 aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
4005 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
4006 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
4007 Standard_Real nU1, nV1;
4010 aNeighbourPoint.ParametersOnS1(nU1, nV1);
4012 aNeighbourPoint.ParametersOnS2(nU1, nV1);
4013 gp_Pnt2d ap1(nU1, nV1);
4014 gp_Pnt2d ap2(nU1, nV1);
4015 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
4017 while((aneighbourpointindex2 <= aListOfIndex.Last()) && (aneighbourpointindex2 >= aListOfIndex.First())) {
4018 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
4019 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
4020 Standard_Real nU2, nV2;
4023 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
4025 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
4029 if(ap1.SquareDistance(ap2) > (gp::Resolution() * gp::Resolution())) {
4033 found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
4038 Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4039 GeomAPI_ProjectPointOnSurf& aProjector =
4040 (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
4041 Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
4043 Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
4045 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
4046 aProjector.Perform(aP3d);
4048 if(aProjector.IsDone()) {
4049 if(aProjector.LowerDistance() < aCriteria) {
4050 Standard_Real foundU = U, foundV = V;
4051 aProjector.LowerDistanceParameters(foundU, foundV);
4053 //Correction of projected coordinates. Begin
4054 //Note, it may be shifted on a period
4055 Standard_Integer aneindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
4056 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
4057 Standard_Real nUn, nVn;
4060 aNeighbourPoint.ParametersOnS2(nUn, nVn);
4062 aNeighbourPoint.ParametersOnS1(nUn, nVn);
4063 gp_Pnt2d aNeighbour2d(nUn, nVn);
4064 gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
4065 foundU = anAdjustedPoint.X();
4066 foundV = anAdjustedPoint.Y();
4068 if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
4069 ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
4070 // attempt to roughly re-compute point
4071 foundU = ( foundU < umin ) ? umin : foundU;
4072 foundU = ( foundU > umax ) ? umax : foundU;
4073 foundV = ( foundV < vmin ) ? vmin : foundV;
4074 foundV = ( foundV > vmax ) ? vmax : foundV;
4076 GeomAPI_ProjectPointOnSurf& aProjector2 =
4077 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
4079 aP3d = aSurfaceOther->Value(foundU, foundV);
4080 aProjector2.Perform(aP3d);
4082 if(aProjector2.IsDone()) {
4083 if(aProjector2.LowerDistance() < aCriteria) {
4084 Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
4085 aProjector2.LowerDistanceParameters(foundU2, foundV2);
4086 anewpoint.SetX(foundU2);
4087 anewpoint.SetY(foundV2);
4091 //Correction of projected coordinates. End
4094 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
4096 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
4102 aSeqOfPntOn2S->Add(aNewP);
4103 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
4105 anArrayOfLineEnds.SetValue(i, aListOfFLIndex);
4107 // Correct wlines.end
4109 // Split wlines.begin
4110 Standard_Integer nbiter;
4113 if (!bAvoidLineConstructor) {
4114 nbiter=theLConstructor.NbParts();
4117 for(j = 1; j <= nbiter; ++j) {
4118 Standard_Real fprm, lprm;
4119 Standard_Integer ifprm, ilprm;
4121 if(bAvoidLineConstructor) {
4123 ilprm = theWLine->NbPnts();
4126 theLConstructor.Part(j, fprm, lprm);
4127 ifprm = (Standard_Integer)fprm;
4128 ilprm = (Standard_Integer)lprm;
4131 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
4133 for(i = 1; i <= nblines; i++) {
4134 if(anArrayOfLineType.Value(i) != 0) {
4137 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
4139 if(aListOfIndex.Extent() < 2) {
4142 const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
4143 Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
4144 Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
4146 if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
4147 bhasfirstpoint = (i != 1);
4150 if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
4151 bhaslastpoint = (i != nblines);
4153 Standard_Boolean bIsFirstInside = ((ifprm >= aListOfIndex.First()) && (ifprm <= aListOfIndex.Last()));
4154 Standard_Boolean bIsLastInside = ((ilprm >= aListOfIndex.First()) && (ilprm <= aListOfIndex.Last()));
4156 if(!bIsFirstInside && !bIsLastInside) {
4157 if((ifprm < aListOfIndex.First()) && (ilprm > aListOfIndex.Last())) {
4158 // append whole line, and boundaries if neccesary
4159 if(bhasfirstpoint) {
4160 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
4163 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4165 for(; anIt.More(); anIt.Next()) {
4166 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4171 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
4175 // check end of split line (end is almost always)
4176 Standard_Integer aneighbour = i + 1;
4177 Standard_Boolean bIsEndOfLine = Standard_True;
4179 if(aneighbour <= nblines) {
4180 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4182 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4183 (aListOfNeighbourIndex.IsEmpty())) {
4184 bIsEndOfLine = Standard_False;
4189 if(aLineOn2S->NbPoints() > 1) {
4190 Handle(IntPatch_WLine) aNewWLine =
4191 new IntPatch_WLine(aLineOn2S, Standard_False);
4192 theNewLines.Append(aNewWLine);
4194 aLineOn2S = new IntSurf_LineOn2S();
4199 // end if(!bIsFirstInside && !bIsLastInside)
4201 if(bIsFirstInside && bIsLastInside) {
4202 // append inside points between ifprm and ilprm
4203 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4205 for(; anIt.More(); anIt.Next()) {
4206 if((anIt.Value() < ifprm) || (anIt.Value() > ilprm))
4208 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4214 if(bIsFirstInside) {
4215 // append points from ifprm to last point + boundary point
4216 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4218 for(; anIt.More(); anIt.Next()) {
4219 if(anIt.Value() < ifprm)
4221 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4226 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
4229 // check end of split line (end is almost always)
4230 Standard_Integer aneighbour = i + 1;
4231 Standard_Boolean bIsEndOfLine = Standard_True;
4233 if(aneighbour <= nblines) {
4234 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4236 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4237 (aListOfNeighbourIndex.IsEmpty())) {
4238 bIsEndOfLine = Standard_False;
4243 if(aLineOn2S->NbPoints() > 1) {
4244 Handle(IntPatch_WLine) aNewWLine =
4245 new IntPatch_WLine(aLineOn2S, Standard_False);
4246 theNewLines.Append(aNewWLine);
4248 aLineOn2S = new IntSurf_LineOn2S();
4251 // end if(bIsFirstInside)
4254 // append points from first boundary point to ilprm
4255 if(bhasfirstpoint) {
4256 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
4259 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4261 for(; anIt.More(); anIt.Next()) {
4262 if(anIt.Value() > ilprm)
4264 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4268 //end if(bIsLastInside)
4272 if(aLineOn2S->NbPoints() > 1) {
4273 Handle(IntPatch_WLine) aNewWLine =
4274 new IntPatch_WLine(aLineOn2S, Standard_False);
4275 theNewLines.Append(aNewWLine);
4280 return Standard_True;
4283 // ------------------------------------------------------------------------------------------------
4284 // static function: ParameterOutOfBoundary
4285 // purpose: Computes a new parameter for given curve. The corresponding 2d points
4286 // does not lay on any boundary of given faces
4287 // ------------------------------------------------------------------------------------------------
4288 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
4289 const Handle(Geom_Curve)& theCurve,
4290 const TopoDS_Face& theFace1,
4291 const TopoDS_Face& theFace2,
4292 const Standard_Real theOtherParameter,
4293 const Standard_Boolean bIncreasePar,
4294 Standard_Real& theNewParameter,
4295 const Handle(IntTools_Context)& aContext)
4297 Standard_Boolean bIsComputed = Standard_False;
4298 theNewParameter = theParameter;
4300 Standard_Real acurpar = theParameter;
4301 TopAbs_State aState = TopAbs_ON;
4302 Standard_Integer iter = 0;
4303 Standard_Real asumtol = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4304 Standard_Real adelta = asumtol * 0.1;
4305 adelta = (adelta < Precision::Confusion()) ? Precision::Confusion() : adelta;
4306 Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(theFace1);
4307 Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(theFace2);
4309 Standard_Real u1, u2, v1, v2;
4311 GeomAPI_ProjectPointOnSurf aPrj1;
4312 aSurf1->Bounds(u1, u2, v1, v2);
4313 aPrj1.Init(aSurf1, u1, u2, v1, v2);
4315 GeomAPI_ProjectPointOnSurf aPrj2;
4316 aSurf2->Bounds(u1, u2, v1, v2);
4317 aPrj2.Init(aSurf2, u1, u2, v1, v2);
4319 while(aState == TopAbs_ON) {
4324 gp_Pnt aPCurrent = theCurve->Value(acurpar);
4325 aPrj1.Perform(aPCurrent);
4326 Standard_Real U=0., V=0.;
4328 if(aPrj1.IsDone()) {
4329 aPrj1.LowerDistanceParameters(U, V);
4330 aState = aContext->StatePointFace(theFace1, gp_Pnt2d(U, V));
4333 if(aState != TopAbs_ON) {
4334 aPrj2.Perform(aPCurrent);
4336 if(aPrj2.IsDone()) {
4337 aPrj2.LowerDistanceParameters(U, V);
4338 aState = aContext->StatePointFace(theFace2, gp_Pnt2d(U, V));
4349 theNewParameter = acurpar;
4350 bIsComputed = Standard_True;
4353 if(acurpar >= theOtherParameter)
4354 theNewParameter = theOtherParameter;
4357 if(acurpar <= theOtherParameter)
4358 theNewParameter = theOtherParameter;
4364 //=======================================================================
4365 //function : IsCurveValid
4367 //=======================================================================
4368 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve)
4370 if(thePCurve.IsNull())
4371 return Standard_False;
4373 Standard_Real tolint = 1.e-10;
4374 Geom2dAdaptor_Curve PCA;
4375 IntRes2d_Domain PCD;
4376 Geom2dInt_GInter PCI;
4378 Standard_Real pf = 0., pl = 0.;
4379 gp_Pnt2d pntf, pntl;
4381 if(!thePCurve->IsClosed() && !thePCurve->IsPeriodic()) {
4382 pf = thePCurve->FirstParameter();
4383 pl = thePCurve->LastParameter();
4384 pntf = thePCurve->Value(pf);
4385 pntl = thePCurve->Value(pl);
4386 PCA.Load(thePCurve);
4387 if(!PCA.IsPeriodic()) {
4388 if(PCA.FirstParameter() > pf) pf = PCA.FirstParameter();
4389 if(PCA.LastParameter() < pl) pl = PCA.LastParameter();
4391 PCD.SetValues(pntf,pf,tolint,pntl,pl,tolint);
4392 PCI.Perform(PCA,PCD,tolint,tolint);
4394 if(PCI.NbPoints() > 0) {
4395 return Standard_False;
4399 return Standard_True;
4402 //=======================================================================
4403 //static function : ApproxWithPCurves
4404 //purpose : for bug 20964 only
4405 //=======================================================================
4406 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
4407 const gp_Sphere& theSph)
4409 Standard_Boolean bRes = Standard_True;
4410 Standard_Real R1 = theCyl.Radius(), R2 = theSph.Radius();
4413 Standard_Real aD2, aRc2, aEps;
4419 const gp_Ax3& aAx3Sph=theSph.Position();
4420 const gp_Pnt& aLocSph=aAx3Sph.Location();
4421 const gp_Dir& aDirSph=aAx3Sph.Direction();
4423 const gp_Ax1& aAx1Cyl=theCyl.Axis();
4424 gp_Lin aLinCyl(aAx1Cyl);
4426 aApexSph.SetXYZ(aLocSph.XYZ()+R2*aDirSph.XYZ());
4427 aD2=aLinCyl.SquareDistance(aApexSph);
4428 if (fabs(aD2-aRc2)<aEps) {
4432 aApexSph.SetXYZ(aLocSph.XYZ()-R2*aDirSph.XYZ());
4433 aD2=aLinCyl.SquareDistance(aApexSph);
4434 if (fabs(aD2-aRc2)<aEps) {
4443 gp_Lin anCylAx(theCyl.Axis());
4445 Standard_Real aDist = anCylAx.Distance(theSph.Location());
4446 Standard_Real aDRel = Abs(aDist - R1)/R2;
4448 if(aDRel > .2) return bRes;
4450 Standard_Real par = ElCLib::Parameter(anCylAx, theSph.Location());
4451 gp_Pnt aP = ElCLib::Value(par, anCylAx);
4452 gp_Vec aV(aP, theSph.Location());
4454 Standard_Real dd = aV.Dot(theSph.Position().XDirection());
4456 if(aDist < R1 && dd > 0.) return Standard_False;
4457 if(aDist > R1 && dd < 0.) return Standard_False;
4462 //=======================================================================
4463 //function : PerformPlanes
4465 //=======================================================================
4466 void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
4467 const Handle(GeomAdaptor_HSurface)& theS2,
4468 const Standard_Real TolAng,
4469 const Standard_Real TolTang,
4470 const Standard_Boolean theApprox1,
4471 const Standard_Boolean theApprox2,
4472 IntTools_SequenceOfCurves& theSeqOfCurve,
4473 Standard_Boolean& theTangentFaces)
4476 gp_Pln aPln1 = theS1->Surface().Plane();
4477 gp_Pln aPln2 = theS2->Surface().Plane();
4479 IntAna_QuadQuadGeo aPlnInter(aPln1, aPln2, TolAng, TolTang);
4481 if(!aPlnInter.IsDone()) {
4482 theTangentFaces = Standard_False;
4486 IntAna_ResultType aResType = aPlnInter.TypeInter();
4488 if(aResType == IntAna_Same) {
4489 theTangentFaces = Standard_True;
4493 theTangentFaces = Standard_False;
4495 if(aResType == IntAna_Empty) {
4499 gp_Lin aLin = aPlnInter.Line(1);
4501 ProjLib_Plane aProj;
4504 aProj.Project(aLin);
4505 gp_Lin2d aLin2d1 = aProj.Line();
4508 aProj.Project(aLin);
4509 gp_Lin2d aLin2d2 = aProj.Line();
4511 //classify line2d1 relatively first plane
4512 Standard_Real P11, P12;
4513 Standard_Boolean IsCrossed = ClassifyLin2d(theS1, aLin2d1, TolTang, P11, P12);
4514 if(!IsCrossed) return;
4515 //classify line2d2 relatively second plane
4516 Standard_Real P21, P22;
4517 IsCrossed = ClassifyLin2d(theS2, aLin2d2, TolTang, P21, P22);
4518 if(!IsCrossed) return;
4520 //Analysis of parametric intervals: must have common part
4522 if(P21 >= P12) return;
4523 if(P22 <= P11) return;
4525 Standard_Real pmin, pmax;
4526 pmin = Max(P11, P21);
4527 pmax = Min(P12, P22);
4529 if(pmax - pmin <= TolTang) return;
4531 Handle(Geom_Line) aGLin = new Geom_Line(aLin);
4533 IntTools_Curve aCurve;
4534 Handle(Geom_TrimmedCurve) aGTLin = new Geom_TrimmedCurve(aGLin, pmin, pmax);
4536 aCurve.SetCurve(aGTLin);
4539 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d1);
4540 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4543 Handle(Geom2d_Curve) H1;
4544 aCurve.SetFirstCurve2d(H1);
4547 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d2);
4548 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4551 Handle(Geom2d_Curve) H1;
4552 aCurve.SetFirstCurve2d(H1);
4555 theSeqOfCurve.Append(aCurve);
4559 //=======================================================================
4560 //function : ClassifyLin2d
4562 //=======================================================================
4563 static inline Standard_Boolean INTER(const Standard_Real d1,
4564 const Standard_Real d2,
4565 const Standard_Real tol)
4567 return (d1 > tol && d2 < -tol) ||
4568 (d1 < -tol && d2 > tol) ||
4569 ((d1 <= tol && d1 >= -tol) && (d2 > tol || d2 < -tol)) ||
4570 ((d2 <= tol && d2 >= -tol) && (d1 > tol || d1 < -tol));
4572 static inline Standard_Boolean COINC(const Standard_Real d1,
4573 const Standard_Real d2,
4574 const Standard_Real tol)
4576 return (d1 <= tol && d1 >= -tol) && (d2 <= tol && d2 >= -tol);
4578 Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
4579 const gp_Lin2d& theLin2d,
4580 const Standard_Real theTol,
4581 Standard_Real& theP1,
4582 Standard_Real& theP2)
4585 Standard_Real xmin, xmax, ymin, ymax, d1, d2, A, B, C;
4586 Standard_Real par[2];
4587 Standard_Integer nbi = 0;
4589 xmin = theS->Surface().FirstUParameter();
4590 xmax = theS->Surface().LastUParameter();
4591 ymin = theS->Surface().FirstVParameter();
4592 ymax = theS->Surface().LastVParameter();
4594 theLin2d.Coefficients(A, B, C);
4596 //xmin, ymin <-> xmin, ymax
4597 d1 = A*xmin + B*ymin + C;
4598 d2 = A*xmin + B*ymax + C;
4600 if(INTER(d1, d2, theTol)) {
4601 //Intersection with boundary
4602 Standard_Real y = -(C + A*xmin)/B;
4603 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, y));
4606 else if (COINC(d1, d2, theTol)) {
4607 //Coincidence with boundary
4608 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4609 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4615 if(fabs(par[0]-par[1]) > theTol) {
4616 theP1 = Min(par[0], par[1]);
4617 theP2 = Max(par[0], par[1]);
4618 return Standard_True;
4620 else return Standard_False;
4624 //xmin, ymax <-> xmax, ymax
4626 d2 = A*xmax + B*ymax + C;
4628 if(d1 > theTol || d1 < -theTol) {//to avoid checking of
4629 //coincidence with the same point
4630 if(INTER(d1, d2, theTol)) {
4631 Standard_Real x = -(C + B*ymax)/A;
4632 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymax));
4635 else if (COINC(d1, d2, theTol)) {
4636 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4637 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4644 if(fabs(par[0]-par[1]) > theTol) {
4645 theP1 = Min(par[0], par[1]);
4646 theP2 = Max(par[0], par[1]);
4647 return Standard_True;
4649 else return Standard_False;
4653 //xmax, ymax <-> xmax, ymin
4655 d2 = A*xmax + B*ymin + C;
4657 if(d1 > theTol || d1 < -theTol) {
4658 if(INTER(d1, d2, theTol)) {
4659 Standard_Real y = -(C + A*xmax)/B;
4660 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, y));
4663 else if (COINC(d1, d2, theTol)) {
4664 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4665 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4671 if(fabs(par[0]-par[1]) > theTol) {
4672 theP1 = Min(par[0], par[1]);
4673 theP2 = Max(par[0], par[1]);
4674 return Standard_True;
4676 else return Standard_False;
4679 //xmax, ymin <-> xmin, ymin
4681 d2 = A*xmin + B*ymin + C;
4683 if(d1 > theTol || d1 < -theTol) {
4684 if(INTER(d1, d2, theTol)) {
4685 Standard_Real x = -(C + B*ymin)/A;
4686 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymin));
4689 else if (COINC(d1, d2, theTol)) {
4690 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4691 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4697 if(fabs(par[0]-par[1]) > theTol) {
4698 theP1 = Min(par[0], par[1]);
4699 theP2 = Max(par[0], par[1]);
4700 return Standard_True;
4702 else return Standard_False;
4705 return Standard_False;
4709 //=======================================================================
4710 //function : ApproxParameters
4712 //=======================================================================
4713 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
4714 const Handle(GeomAdaptor_HSurface)& aHS2,
4715 Standard_Integer& iDegMin,
4716 Standard_Integer& iDegMax,
4717 Standard_Integer& iNbIter)
4720 GeomAbs_SurfaceType aTS1, aTS2;
4727 aTS1=aHS1->Surface().GetType();
4728 aTS2=aHS2->Surface().GetType();
4731 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4732 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4733 Standard_Real aRC, aRT, dR, aPC;
4734 gp_Cylinder aCylinder;
4737 aPC=Precision::Confusion();
4739 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4740 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4742 aRC=aCylinder.Radius();
4743 aRT=aTorus.MinorRadius();
4753 if (aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Cylinder) {
4757 //=======================================================================
4758 //function : Tolerances
4760 //=======================================================================
4761 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
4762 const Handle(GeomAdaptor_HSurface)& aHS2,
4763 Standard_Real& aTolTang)
4765 GeomAbs_SurfaceType aTS1, aTS2;
4767 aTS1=aHS1->Surface().GetType();
4768 aTS2=aHS2->Surface().GetType();
4771 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4772 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4773 Standard_Real aRC, aRT, dR, aPC;
4774 gp_Cylinder aCylinder;
4777 aPC=Precision::Confusion();
4779 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4780 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4782 aRC=aCylinder.Radius();
4783 aRT=aTorus.MinorRadius();
4790 aTolTang=0.1*aTolTang;
4794 //=======================================================================
4795 //function : SortTypes
4797 //=======================================================================
4798 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
4799 const GeomAbs_SurfaceType aType2)
4801 Standard_Boolean bRet;
4802 Standard_Integer aI1, aI2;
4804 bRet=Standard_False;
4806 aI1=IndexType(aType1);
4807 aI2=IndexType(aType2);
4813 //=======================================================================
4814 //function : IndexType
4816 //=======================================================================
4817 Standard_Integer IndexType(const GeomAbs_SurfaceType aType)
4819 Standard_Integer aIndex;
4823 if (aType==GeomAbs_Plane) {
4826 else if (aType==GeomAbs_Cylinder) {
4829 else if (aType==GeomAbs_Cone) {
4832 else if (aType==GeomAbs_Sphere) {
4835 else if (aType==GeomAbs_Torus) {
4838 else if (aType==GeomAbs_BezierSurface) {
4841 else if (aType==GeomAbs_BSplineSurface) {
4844 else if (aType==GeomAbs_SurfaceOfRevolution) {
4847 else if (aType==GeomAbs_SurfaceOfExtrusion) {
4850 else if (aType==GeomAbs_OffsetSurface) {
4853 else if (aType==GeomAbs_OtherSurface) {
4858 #ifdef DEB_DUMPWLINE
4859 //=======================================================================
4860 //function : DumpWLine
4862 //=======================================================================
4863 void DumpWLine(const Handle(IntPatch_WLine)& aWLine)
4865 Standard_Integer i, aNbPnts;
4866 Standard_Real aX, aY, aZ, aU1, aV1, aU2, aV2;
4868 printf(" *WLine\n");
4869 aNbPnts=aWLine->NbPnts();
4870 for (i=1; i<=aNbPnts; ++i) {
4871 const IntSurf_PntOn2S aPntOn2S=aWLine->Point(i);
4872 const gp_Pnt& aP3D=aPntOn2S.Value();
4873 aP3D.Coord(aX, aY, aZ);
4874 aPntOn2S.Parameters(aU1, aV1, aU2, aV2);
4876 printf("point p_%d %lf %lf %lf\n", i, aX, aY, aZ);
4877 //printf("point p_%d %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf\n",
4878 // i, aX, aY, aZ, aU1, aV1, aU2, aV2);
4882 //=======================================================================
4883 //function : RefineVector
4885 //=======================================================================
4886 void RefineVector(gp_Vec2d& aV2D)
4888 Standard_Integer k,m;
4889 Standard_Real aC[2], aEps, aR1, aR2, aNum;
4895 aV2D.Coord(aC[0], aC[1]);
4897 for (k=0; k<2; ++k) {
4900 if (aNum>aR1 && aNum<aR2) {
4911 aV2D.SetCoord(aC[0], aC[1]);
4913 //=======================================================================
4914 //function : FindMaxSquareDistance
4916 //=======================================================================
4917 Standard_Real FindMaxSquareDistance (const Standard_Real aT1,
4918 const Standard_Real aT2,
4919 const Standard_Real aEps,
4920 const Handle(Geom_Curve)& aC3D,
4921 const Handle(Geom2d_Curve)& aC2D1,
4922 const Handle(Geom2d_Curve)& aC2D2,
4923 const Handle(GeomAdaptor_HSurface)& myHS1,
4924 const Handle(GeomAdaptor_HSurface)& myHS2,
4925 const TopoDS_Face& myFace1,
4926 const TopoDS_Face& myFace2,
4927 const Handle(IntTools_Context)& myContext)
4929 Standard_Real aA, aB, aCf, aX1, aX2, aF1, aF2, aX, aF;
4931 aCf=1.6180339887498948482045868343656;// =0.5*(1.+sqrt(5.));
4935 aF1=MaxSquareDistance(aX1,
4936 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4938 aF2=MaxSquareDistance(aX2,
4939 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4943 if (fabs(aA-aB)<aEps) {
4945 aF=MaxSquareDistance(aX,
4946 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4954 aF2=MaxSquareDistance(aX2,
4955 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4963 aF1=MaxSquareDistance(aX1,
4964 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4969 //=======================================================================
4970 //function : MaxSquareDistance
4972 //=======================================================================
4973 Standard_Real MaxSquareDistance (const Standard_Real aT,
4974 const Handle(Geom_Curve)& aC3D,
4975 const Handle(Geom2d_Curve)& aC2D1,
4976 const Handle(Geom2d_Curve)& aC2D2,
4977 const Handle(GeomAdaptor_HSurface) myHS1,
4978 const Handle(GeomAdaptor_HSurface) myHS2,
4979 const TopoDS_Face& aF1,
4980 const TopoDS_Face& aF2,
4981 const Handle(IntTools_Context)& aCtx)
4983 Standard_Boolean bIsDone;
4985 Standard_Real aU, aV, aD2Max, aD2;
4992 if (aC3D.IsNull()) {
4996 for (i=0; i<2; ++i) {
4997 const Handle(GeomAdaptor_HSurface)& aGHS=(!i) ? myHS1 : myHS2;
4998 const TopoDS_Face &aF=(!i) ? aF1 : aF2;
4999 const Handle(Geom2d_Curve)& aC2D=(!i) ? aC2D1 : aC2D2;
5001 if (!aC2D.IsNull()) {
5004 aGHS->D0(aU, aV, aPS);
5005 aD2=aP.SquareDistance(aPS);
5011 GeomAPI_ProjectPointOnSurf& aProjector=aCtx->ProjPS(aF);
5013 aProjector.Perform(aP);
5014 bIsDone=aProjector.IsDone();
5016 aProjector.LowerDistanceParameters(aU, aV);
5017 aGHS->D0(aU, aV, aPS);
5018 aD2=aP.SquareDistance(aPS);
5028 //=======================================================================
5029 //function : CheckPCurve
5030 //purpose : Checks if points of the pcurve are out of the face bounds.
5031 //=======================================================================
5032 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
5033 const TopoDS_Face& aFace)
5035 const Standard_Integer NPoints = 23;
5037 Standard_Real umin,umax,vmin,vmax;
5039 BRepTools::UVBounds(aFace, umin, umax, vmin, vmax);
5040 Standard_Real tolU = Max ((umax-umin)*0.01, Precision::Confusion());
5041 Standard_Real tolV = Max ((vmax-vmin)*0.01, Precision::Confusion());
5042 Standard_Real fp = aPC->FirstParameter();
5043 Standard_Real lp = aPC->LastParameter();
5046 // adjust domain for periodic surfaces
5047 TopLoc_Location aLoc;
5048 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
5049 if (aSurf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
5050 aSurf = (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf))->BasisSurface();
5052 gp_Pnt2d pnt = aPC->Value((fp+lp)/2);
5056 if (aSurf->IsUPeriodic()) {
5057 Standard_Real aPer = aSurf->UPeriod();
5058 Standard_Integer nshift = (Standard_Integer) ((u-umin)/aPer);
5059 if (u < umin+aPer*nshift) nshift--;
5060 umin += aPer*nshift;
5061 umax += aPer*nshift;
5063 if (aSurf->IsVPeriodic()) {
5064 Standard_Real aPer = aSurf->VPeriod();
5065 Standard_Integer nshift = (Standard_Integer) ((v-vmin)/aPer);
5066 if (v < vmin+aPer*nshift) nshift--;
5067 vmin += aPer*nshift;
5068 vmax += aPer*nshift;
5071 //--------------------------------------------------------
5072 Standard_Boolean bRet;
5073 Standard_Integer j, aNbIntervals;
5074 Standard_Real aT, dT;
5077 Geom2dAdaptor_Curve aGAC(aPC);
5078 aNbIntervals=aGAC.NbIntervals(GeomAbs_CN);
5080 TColStd_Array1OfReal aTI(1, aNbIntervals+1);
5081 aGAC.Intervals(aTI,GeomAbs_CN);
5083 bRet=Standard_False;
5085 aT=aGAC.FirstParameter();
5086 for (j=1; j<=aNbIntervals; ++j) {
5087 dT=(aTI(j+1)-aTI(j))/NPoints;
5089 for (i=1; i<NPoints; i++) {
5093 if (umin-u > tolU || u-umax > tolU ||
5094 vmin-v > tolV || v-vmax > tolV) {