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>
116 #include <GeomInt.hxx>
119 void RefineVector(gp_Vec2d& aV2D);
120 #ifdef OCCT_DEBUG_DUMPWLINE
122 void DumpWLine(const Handle(IntPatch_WLine)& aWLine);
126 void TolR3d(const TopoDS_Face& ,
130 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)&,
131 const Standard_Integer,
132 const Standard_Integer);
135 void Parameters(const Handle(GeomAdaptor_HSurface)&,
136 const Handle(GeomAdaptor_HSurface)&,
144 void BuildPCurves (Standard_Real f,Standard_Real l,Standard_Real& Tol,
145 const Handle (Geom_Surface)& S,
146 const Handle (Geom_Curve)& C,
147 Handle (Geom2d_Curve)& C2d);
150 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
151 const Standard_Real theTolerance,
152 Standard_Real& theumin,
153 Standard_Real& theumax,
154 Standard_Real& thevmin,
155 Standard_Real& thevmax);
157 Standard_Boolean NotUseSurfacesForApprox
158 (const TopoDS_Face& aF1,
159 const TopoDS_Face& aF2,
160 const Handle(IntPatch_WLine)& WL,
161 const Standard_Integer ifprm,
162 const Standard_Integer ilprm);
165 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine);
168 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
169 const Standard_Integer ideb,
170 const Standard_Integer ifin,
171 const Standard_Boolean onFirst);
174 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
175 const Handle(GeomAdaptor_HSurface)& theSurface1,
176 const Handle(GeomAdaptor_HSurface)& theSurface2,
177 const TopoDS_Face& theFace1,
178 const TopoDS_Face& theFace2,
179 const GeomInt_LineConstructor& theLConstructor,
180 const Standard_Boolean theAvoidLConstructor,
181 IntPatch_SequenceOfLine& theNewLines,
182 Standard_Real& theReachedTol3d,
183 const Handle(IntTools_Context)& );
186 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
187 const Handle(Geom_Curve)& theCurve,
188 const TopoDS_Face& theFace1,
189 const TopoDS_Face& theFace2,
190 const Standard_Real theOtherParameter,
191 const Standard_Boolean bIncreasePar,
192 Standard_Real& theNewParameter,
193 const Handle(IntTools_Context)& );
196 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve);
199 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
200 const Standard_Real theFirstBoundary,
201 const Standard_Real theSecondBoundary,
202 const Standard_Real theResolution,
203 Standard_Boolean& IsOnFirstBoundary);
205 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
206 const gp_Pnt2d& theLastPoint,
207 const Standard_Real theUmin,
208 const Standard_Real theUmax,
209 const Standard_Real theVmin,
210 const Standard_Real theVmax,
211 gp_Pnt2d& theNewPoint);
215 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
216 const Handle(GeomAdaptor_HSurface)& theSurface2,
217 const TopoDS_Face& theFace1,
218 const TopoDS_Face& theFace2,
219 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
220 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
221 Handle(TColStd_HArray1OfReal)& theResultRadius,
222 const Handle(IntTools_Context)& );
225 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
226 const gp_Pnt2d& theLastPoint,
227 const Standard_Real theUmin,
228 const Standard_Real theUmax,
229 const Standard_Real theVmin,
230 const Standard_Real theVmax,
231 const gp_Pnt2d& theTanZoneCenter,
232 const Standard_Real theZoneRadius,
233 Handle(GeomAdaptor_HSurface) theGASurface,
234 gp_Pnt2d& theNewPoint);
237 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
238 const gp_Pnt2d& theTanZoneCenter,
239 const Standard_Real theZoneRadius,
240 Handle(GeomAdaptor_HSurface) theGASurface);
243 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
244 const gp_Pnt2d& theOriginalPoint,
245 Handle(GeomAdaptor_HSurface) theGASurface);
247 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
248 const gp_Sphere& theSph);
250 static void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
251 const Handle(GeomAdaptor_HSurface)& theS2,
252 const Standard_Real TolAng,
253 const Standard_Real TolTang,
254 const Standard_Boolean theApprox1,
255 const Standard_Boolean theApprox2,
256 IntTools_SequenceOfCurves& theSeqOfCurve,
257 Standard_Boolean& theTangentFaces);
259 static Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
260 const gp_Lin2d& theLin2d,
261 const Standard_Real theTol,
262 Standard_Real& theP1,
263 Standard_Real& theP2);
266 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
267 const Handle(GeomAdaptor_HSurface)& aHS2,
268 Standard_Integer& iDegMin,
269 Standard_Integer& iNbIter,
270 Standard_Integer& iDegMax);
273 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
274 const Handle(GeomAdaptor_HSurface)& aHS2,
275 Standard_Real& aTolTang);
278 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
279 const GeomAbs_SurfaceType aType2);
281 Standard_Integer IndexType(const GeomAbs_SurfaceType aType);
285 Standard_Real MaxSquareDistance (const Standard_Real aT,
286 const Handle(Geom_Curve)& aC3D,
287 const Handle(Geom2d_Curve)& aC2D1,
288 const Handle(Geom2d_Curve)& aC2D2,
289 const Handle(GeomAdaptor_HSurface) myHS1,
290 const Handle(GeomAdaptor_HSurface) myHS2,
291 const TopoDS_Face& aF1,
292 const TopoDS_Face& aF2,
293 const Handle(IntTools_Context)& aCtx);
296 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
297 const TopoDS_Face& aFace);
301 Standard_Real FindMaxSquareDistance (const Standard_Real aA,
302 const Standard_Real aB,
303 const Standard_Real aEps,
304 const Handle(Geom_Curve)& aC3D,
305 const Handle(Geom2d_Curve)& aC2D1,
306 const Handle(Geom2d_Curve)& aC2D2,
307 const Handle(GeomAdaptor_HSurface)& myHS1,
308 const Handle(GeomAdaptor_HSurface)& myHS2,
309 const TopoDS_Face& aF1,
310 const TopoDS_Face& aF2,
311 const Handle(IntTools_Context)& aCtx);
313 //=======================================================================
316 //=======================================================================
317 IntTools_FaceFace::IntTools_FaceFace()
319 myIsDone=Standard_False;
320 myTangentFaces=Standard_False;
322 myHS1 = new GeomAdaptor_HSurface ();
323 myHS2 = new GeomAdaptor_HSurface ();
326 SetParameters(Standard_True, Standard_True, Standard_True, 1.e-07);
329 //=======================================================================
330 //function : SetContext
332 //=======================================================================
333 void IntTools_FaceFace::SetContext(const Handle(IntTools_Context)& aContext)
337 //=======================================================================
340 //=======================================================================
341 const Handle(IntTools_Context)& IntTools_FaceFace::Context()const
345 //=======================================================================
348 //=======================================================================
349 const TopoDS_Face& IntTools_FaceFace::Face1() const
353 //=======================================================================
356 //=======================================================================
357 const TopoDS_Face& IntTools_FaceFace::Face2() const
361 //=======================================================================
362 //function : TangentFaces
364 //=======================================================================
365 Standard_Boolean IntTools_FaceFace::TangentFaces() const
367 return myTangentFaces;
369 //=======================================================================
372 //=======================================================================
373 const IntTools_SequenceOfPntOn2Faces& IntTools_FaceFace::Points() const
377 //=======================================================================
380 //=======================================================================
381 Standard_Boolean IntTools_FaceFace::IsDone() const
385 //=======================================================================
386 //function : TolReached3d
388 //=======================================================================
389 Standard_Real IntTools_FaceFace::TolReached3d() const
391 return myTolReached3d;
393 //=======================================================================
395 //purpose : return lines of intersection
396 //=======================================================================
397 const IntTools_SequenceOfCurves& IntTools_FaceFace::Lines() const
399 StdFail_NotDone_Raise_if
401 "IntTools_FaceFace::Lines() => myIntersector NOT DONE");
404 //=======================================================================
405 //function : TolReached2d
407 //=======================================================================
408 Standard_Real IntTools_FaceFace::TolReached2d() const
410 return myTolReached2d;
412 // =======================================================================
413 // function: SetParameters
415 // =======================================================================
416 void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d,
417 const Standard_Boolean ToApproxC2dOnS1,
418 const Standard_Boolean ToApproxC2dOnS2,
419 const Standard_Real ApproximationTolerance)
421 myApprox = ToApproxC3d;
422 myApprox1 = ToApproxC2dOnS1;
423 myApprox2 = ToApproxC2dOnS2;
424 myTolApprox = ApproximationTolerance;
426 //=======================================================================
429 //=======================================================================
430 void IntTools_FaceFace::SetList(IntSurf_ListOfPntOn2S& aListOfPnts)
432 myListOfPnts = aListOfPnts;
436 static Standard_Boolean isTreatAnalityc(const TopoDS_Face& theF1,
437 const TopoDS_Face& theF2)
439 const Standard_Real Tolang = 1.e-8;
440 const Standard_Real aTolF1=BRep_Tool::Tolerance(theF1);
441 const Standard_Real aTolF2=BRep_Tool::Tolerance(theF2);
442 const Standard_Real aTolSum = aTolF1 + aTolF2;
443 Standard_Real aHigh = 0.0;
445 const BRepAdaptor_Surface aBAS1(theF1), aBAS2(theF2);
446 const GeomAbs_SurfaceType aType1=aBAS1.GetType();
447 const GeomAbs_SurfaceType aType2=aBAS2.GetType();
451 if(aType1 == GeomAbs_Plane)
455 else if(aType2 == GeomAbs_Plane)
461 return Standard_True;
464 if(aType1 == GeomAbs_Cylinder)
466 aS2=aBAS1.Cylinder();
467 const Standard_Real VMin = aBAS1.FirstVParameter();
468 const Standard_Real VMax = aBAS1.LastVParameter();
470 if( Precision::IsNegativeInfinite(VMin) ||
471 Precision::IsPositiveInfinite(VMax))
472 return Standard_True;
476 else if(aType2 == GeomAbs_Cylinder)
478 aS2=aBAS2.Cylinder();
480 const Standard_Real VMin = aBAS2.FirstVParameter();
481 const Standard_Real VMax = aBAS2.LastVParameter();
483 if( Precision::IsNegativeInfinite(VMin) ||
484 Precision::IsPositiveInfinite(VMax))
485 return Standard_True;
491 return Standard_True;
494 IntAna_QuadQuadGeo inter;
495 inter.Perform(aS1,aS2,Tolang,aTolSum, aHigh);
496 if(inter.TypeInter() == IntAna_Ellipse)
498 const gp_Elips anEl = inter.Ellipse(1);
499 const Standard_Real aMajorR = anEl.MajorRadius();
500 const Standard_Real aMinorR = anEl.MinorRadius();
502 return (aMajorR < 100000.0 * aMinorR);
506 return inter.IsDone();
509 //=======================================================================
511 //purpose : intersect surfaces of the faces
512 //=======================================================================
513 void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
514 const TopoDS_Face& aF2)
516 Standard_Boolean RestrictLine = Standard_False, hasCone = Standard_False;
518 if (myContext.IsNull()) {
519 myContext=new IntTools_Context;
522 mySeqOfCurve.Clear();
525 myIsDone = Standard_False;
531 const BRepAdaptor_Surface aBAS1(myFace1, Standard_False);
532 const BRepAdaptor_Surface aBAS2(myFace2, Standard_False);
533 GeomAbs_SurfaceType aType1=aBAS1.GetType();
534 GeomAbs_SurfaceType aType2=aBAS2.GetType();
536 const Standard_Boolean bReverse=SortTypes(aType1, aType2);
541 aType1=aBAS2.GetType();
542 aType2=aBAS1.GetType();
544 if (myListOfPnts.Extent())
546 Standard_Real aU1,aV1,aU2,aV2;
547 IntSurf_ListIteratorOfListOfPntOn2S aItP2S;
549 aItP2S.Initialize(myListOfPnts);
550 for (; aItP2S.More(); aItP2S.Next())
552 IntSurf_PntOn2S& aP2S=aItP2S.Value();
553 aP2S.Parameters(aU1,aV1,aU2,aV2);
554 aP2S.SetValue(aU2,aV2,aU1,aV1);
558 Standard_Boolean anAproxTmp = myApprox1;
559 myApprox1 = myApprox2;
560 myApprox2 = anAproxTmp;
564 const Handle(Geom_Surface) S1=BRep_Tool::Surface(myFace1);
565 const Handle(Geom_Surface) S2=BRep_Tool::Surface(myFace2);
567 const Standard_Real aTolF1=BRep_Tool::Tolerance(myFace1);
568 const Standard_Real aTolF2=BRep_Tool::Tolerance(myFace2);
570 Standard_Real TolArc = aTolF1 + aTolF2;
571 Standard_Real TolTang = TolArc;
573 const Standard_Boolean isFace1Quad = (aType1 == GeomAbs_Cylinder ||
574 aType1 == GeomAbs_Cone ||
575 aType1 == GeomAbs_Torus);
577 const Standard_Boolean isFace2Quad = (aType2 == GeomAbs_Cylinder ||
578 aType2 == GeomAbs_Cone ||
579 aType2 == GeomAbs_Torus);
581 if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
582 Standard_Real umin, umax, vmin, vmax;
583 Standard_Real dU, dV;
585 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
592 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
594 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
601 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
603 Standard_Real TolAng = 1.e-8;
605 PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2,
606 mySeqOfCurve, myTangentFaces);
608 myIsDone = Standard_True;
610 if(!myTangentFaces) {
611 const Standard_Integer NbLinPP = mySeqOfCurve.Length();
613 Standard_Real aTolFMax;
614 myTolReached3d = 1.e-7;
615 aTolFMax=Max(aTolF1, aTolF2);
616 if (aTolFMax>myTolReached3d) {
617 myTolReached3d=aTolFMax;
620 myTolReached2d = myTolReached3d;
623 Handle(Geom2d_Curve) aC2D1, aC2D2;
624 const Standard_Integer aNbLin = mySeqOfCurve.Length();
625 for (Standard_Integer i = 1; i <= aNbLin; ++i) {
626 IntTools_Curve& aIC=mySeqOfCurve(i);
627 aC2D1=aIC.FirstCurve2d();
628 aC2D2=aIC.SecondCurve2d();
629 aIC.SetFirstCurve2d(aC2D2);
630 aIC.SetSecondCurve2d(aC2D1);
636 }//if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
638 if ((aType1==GeomAbs_Plane) && isFace2Quad)
640 Standard_Real dU, dV;
643 Standard_Real umin, umax, vmin, vmax;
644 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
652 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
654 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
655 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
656 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
658 if( aType2==GeomAbs_Cone ) {
660 hasCone = Standard_True;
663 else if ((aType2==GeomAbs_Plane) && isFace1Quad)
665 Standard_Real dU, dV;
668 Standard_Real umin, umax, vmin, vmax;
669 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
670 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
671 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
673 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
680 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
682 if( aType1==GeomAbs_Cone ) {
684 hasCone = Standard_True;
689 Standard_Real umin, umax, vmin, vmax;
690 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
691 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
692 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
693 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
694 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
695 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
698 const Handle(IntTools_TopolTool) dom1 = new IntTools_TopolTool(myHS1);
699 const Handle(IntTools_TopolTool) dom2 = new IntTools_TopolTool(myHS2);
701 myLConstruct.Load(dom1, dom2, myHS1, myHS2);
704 Tolerances(myHS1, myHS2, TolTang);
707 const Standard_Real UVMaxStep = 0.001;
708 const Standard_Real Deflection = (hasCone) ? 0.085 : 0.1;
709 myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection);
712 if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) ||
713 (myHS1->IsVClosed() && !myHS1->IsVPeriodic()) ||
714 (myHS2->IsUClosed() && !myHS2->IsUPeriodic()) ||
715 (myHS2->IsVClosed() && !myHS2->IsVPeriodic()))
717 RestrictLine = Standard_True;
720 if((aType1 != GeomAbs_BSplineSurface) &&
721 (aType1 != GeomAbs_BezierSurface) &&
722 (aType1 != GeomAbs_OtherSurface) &&
723 (aType2 != GeomAbs_BSplineSurface) &&
724 (aType2 != GeomAbs_BezierSurface) &&
725 (aType2 != GeomAbs_OtherSurface))
727 RestrictLine = Standard_True;
729 if ((aType1 == GeomAbs_Torus) ||
730 (aType2 == GeomAbs_Torus))
732 myListOfPnts.Clear();
739 TopExp_Explorer aExp;
740 for(Standard_Integer i = 0; (!RestrictLine) && (i < 2); i++)
742 const TopoDS_Face& aF=(!i) ? myFace1 : myFace2;
743 aExp.Init(aF, TopAbs_EDGE);
744 for(; aExp.More(); aExp.Next())
746 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
748 if(BRep_Tool::Degenerated(aE))
750 RestrictLine = Standard_True;
757 const Standard_Boolean isGeomInt = isTreatAnalityc(aF1, aF2);
758 myIntersector.Perform(myHS1, dom1, myHS2, dom2, TolArc, TolTang,
759 myListOfPnts, RestrictLine, isGeomInt);
761 myIsDone = myIntersector.IsDone();
765 myTangentFaces=myIntersector.TangentFaces();
766 if (myTangentFaces) {
771 myListOfPnts.Clear(); // to use LineConstructor
774 const Standard_Integer aNbLin = myIntersector.NbLines();
775 for (Standard_Integer i=1; i <= aNbLin; ++i) {
776 MakeCurve(i, dom1, dom2);
779 ComputeTolReached3d();
782 Handle(Geom2d_Curve) aC2D1, aC2D2;
784 const Standard_Integer aNbLin=mySeqOfCurve.Length();
785 for (Standard_Integer i=1; i<=aNbLin; ++i)
787 IntTools_Curve& aIC=mySeqOfCurve(i);
788 aC2D1=aIC.FirstCurve2d();
789 aC2D2=aIC.SecondCurve2d();
790 aIC.SetFirstCurve2d(aC2D2);
791 aIC.SetSecondCurve2d(aC2D1);
796 Standard_Real U1,V1,U2,V2;
797 IntTools_PntOnFace aPntOnF1, aPntOnF2;
798 IntTools_PntOn2Faces aPntOn2Faces;
800 const Standard_Integer aNbPnts = myIntersector.NbPnts();
801 for (Standard_Integer i=1; i <= aNbPnts; ++i)
803 const IntSurf_PntOn2S& aISPnt=myIntersector.Point(i).PntOn2S();
804 const gp_Pnt& aPnt=aISPnt.Value();
805 aISPnt.Parameters(U1,V1,U2,V2);
806 aPntOnF1.Init(myFace1, aPnt, U1, V1);
807 aPntOnF2.Init(myFace2, aPnt, U2, V2);
811 aPntOn2Faces.SetP1(aPntOnF1);
812 aPntOn2Faces.SetP2(aPntOnF2);
816 aPntOn2Faces.SetP2(aPntOnF1);
817 aPntOn2Faces.SetP1(aPntOnF2);
820 myPnts.Append(aPntOn2Faces);
825 //=======================================================================
826 //function :ComputeTolReached3d
828 //=======================================================================
829 void IntTools_FaceFace::ComputeTolReached3d()
831 Standard_Boolean bCase1;
832 Standard_Integer aNbLin, i;
833 GeomAbs_SurfaceType aType1, aType2;
835 aNbLin=myIntersector.NbLines();
840 aType1=myHS1->Surface().GetType();
841 aType2=myHS2->Surface().GetType();
843 bCase1=((aType1==GeomAbs_Plane && aType2==GeomAbs_SurfaceOfExtrusion) ||
844 (aType2==GeomAbs_Plane && aType1==GeomAbs_SurfaceOfExtrusion));
846 if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
848 Handle(IntPatch_Line) aIL1, aIL2;
849 IntPatch_IType aTL1, aTL2;
851 aIL1=myIntersector.Line(1);
852 aIL2=myIntersector.Line(2);
853 aTL1=aIL1->ArcType();
854 aTL2=aIL2->ArcType();
855 if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) {
856 Standard_Real aD, aDTresh, dTol;
862 aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line();
863 aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line();
864 aD=aL1.Distance(aL2);
867 myTolReached3d=aD+dTol;
873 if (aNbLin) {// Check the distances
874 Standard_Integer aNbP, j ;
875 Standard_Real aT1, aT2, dT, aD2, aD2Max, aEps, aT11, aT12;
879 aNbLin=mySeqOfCurve.Length();
881 for (i=1; i<=aNbLin; ++i) {
882 const IntTools_Curve& aIC=mySeqOfCurve(i);
883 const Handle(Geom_Curve)& aC3D=aIC.Curve();
884 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
885 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
890 const Handle(Geom_BSplineCurve)& aBC=
891 Handle(Geom_BSplineCurve)::DownCast(aC3D);
896 aT1=aBC->FirstParameter();
897 aT2=aBC->LastParameter();
901 for (j=1; j<aNbP; ++j) {
904 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
905 myHS1, myHS2, myFace1, myFace2, myContext);
910 }//for (i=1; i<=aNbLin; ++i) {
912 myTolReached3d=sqrt(aD2Max);
914 }// if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
917 else if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
918 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
922 aTolF1 = BRep_Tool::Tolerance(myFace1);
923 aTolF2 = BRep_Tool::Tolerance(myFace2);
924 aTolFMax=Max(aTolF1, aTolF2);
926 if (aTolFMax>aTolTresh) {
927 myTolReached3d=aTolFMax;
929 }//if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
932 else if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ||
933 (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) {
935 const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1);
936 if(aIL1->ArcType() == IntPatch_Circle) {
937 gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle();
938 gp_XYZ aCirDir = aCir.Axis().Direction().XYZ();
941 if(aType1 == GeomAbs_Plane) {
942 aPln = myHS1->Surface().Plane();
945 aPln = myHS2->Surface().Plane();
947 aPlDir = aPln.Axis().Direction().XYZ();
948 Standard_Real cs = aCirDir*aPlDir;
949 if(cs < 0.) aPlDir.Reverse();
950 Standard_Real eps = 1.e-14;
951 if(!aPlDir.IsEqual(aCirDir, eps)) {
952 Standard_Integer aNbP = 11;
953 Standard_Real dt = 2.*M_PI / (aNbP - 1), t;
954 for(t = 0.; t < 2.*M_PI; t += dt) {
955 Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir));
956 if(myTolReached3d < d) myTolReached3d = d;
958 myTolReached3d *= 1.1;
960 } //aIL1->ArcType() == IntPatch_Circle
962 } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane)
963 //End IFV Bug OCC20297
965 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
966 (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) {
967 aNbLin=mySeqOfCurve.Length();
972 Standard_Integer aNbP;
973 Standard_Real aT, aT1, aT2, dT, aUT, aVT, aUP, aVP;
974 Standard_Real aDP, aDT, aDmax;
979 const IntTools_Curve& aIC=mySeqOfCurve(1);
980 const Handle(Geom_Curve)& aC3D=aIC.Curve();
981 const Handle(Geom_BSplineCurve)& aBS=
982 Handle(Geom_BSplineCurve)::DownCast(aC3D);
987 aT1=aBS->FirstParameter();
988 aT2=aBS->LastParameter();
990 aPln =(aType1==GeomAbs_Plane) ? myHS1->Plane() : myHS2->Plane();
991 aTorus=(aType1==GeomAbs_Plane) ? myHS2->Torus() : myHS1->Torus();
995 dT=(aT2-aT1)/(aNbP-1);
996 for (i=0; i<aNbP; ++i) {
1004 ElSLib::Parameters(aPln, aP, aUP, aVP);
1005 aPP=ElSLib::Value(aUP, aVP, aPln);
1006 aDP=aP.SquareDistance(aPP);
1011 ElSLib::Parameters(aTorus, aP, aUT, aVT);
1012 aPT=ElSLib::Value(aUT, aVT, aTorus);
1013 aDT=aP.SquareDistance(aPT);
1019 if (aDmax > myTolReached3d*myTolReached3d) {
1020 myTolReached3d=sqrt(aDmax);
1021 myTolReached3d=1.1*myTolReached3d;
1023 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
1025 else if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) ||
1026 (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder)) {
1027 Standard_Integer j, aNbP;
1028 Standard_Real aT, aT1, aT2, dT, aD2max, aD2;
1030 aNbLin=mySeqOfCurve.Length();
1034 for (i=1; i<=aNbLin; ++i) {
1035 const IntTools_Curve& aIC=mySeqOfCurve(i);
1036 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1037 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1038 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1040 if (aC3D.IsNull()) {
1043 const Handle(Geom_BSplineCurve)& aBC=
1044 Handle(Geom_BSplineCurve)::DownCast(aC3D);
1049 aT1=aBC->FirstParameter();
1050 aT2=aBC->LastParameter();
1052 dT=(aT2-aT1)/(aNbP-1);
1053 for (j=0; j<aNbP; ++j) {
1059 aD2=MaxSquareDistance(aT, aC3D, aC2D1, aC2D2,
1060 myHS1, myHS2, myFace1, myFace2, myContext);
1064 }//for (j=0; j<aNbP; ++j) {
1066 }//for (i=1; i<=aNbLin; ++i) {
1068 aD2=myTolReached3d*myTolReached3d;
1070 myTolReached3d=sqrt(aD2max);
1072 }//if((aType1==GeomAbs_SurfaceOfRevolution ...
1073 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ||
1074 (aType2==GeomAbs_Plane && aType1==GeomAbs_Sphere)) {
1075 Standard_Integer j, aNbP;
1076 Standard_Real aT1, aT2, dT, aD2max, aD2, aEps, aT11, aT12;
1078 aNbLin=mySeqOfCurve.Length();
1082 for (i=1; i<=aNbLin; ++i) {
1083 const IntTools_Curve& aIC=mySeqOfCurve(i);
1084 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1085 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1086 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1088 const Handle(Geom2d_BSplineCurve)& aBC2D1=
1089 Handle(Geom2d_BSplineCurve)::DownCast(aC2D1);
1090 const Handle(Geom2d_BSplineCurve)& aBC2D2=
1091 Handle(Geom2d_BSplineCurve)::DownCast(aC2D2);
1093 if (aBC2D1.IsNull() && aBC2D2.IsNull()) {
1097 if (!aBC2D1.IsNull()) {
1098 aT1=aBC2D1->FirstParameter();
1099 aT2=aBC2D1->LastParameter();
1102 aT1=aBC2D2->FirstParameter();
1103 aT2=aBC2D2->LastParameter();
1106 aEps=0.01*(aT2-aT1);
1108 for (j=0; j<aNbP; ++j) {
1115 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
1116 myHS1, myHS2, myFace1, myFace2, myContext);
1120 }//for (j=0; j<aNbP; ++j) {
1122 }//for (i=1; i<=aNbLin; ++i) {
1124 aD2=myTolReached3d*myTolReached3d;
1126 myTolReached3d=sqrt(aD2max);
1128 }//else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ...
1129 else if (!myApprox || bCase1) {
1130 //else if (!myApprox) {
1131 Standard_Integer aNbP, j;
1132 Standard_Real aT1, aT2, dT, aD2, aD2Max, aEps, aT11, aT12;
1135 aNbLin=mySeqOfCurve.Length();
1137 for (i=1; i<=aNbLin; ++i) {
1138 const IntTools_Curve& aIC=mySeqOfCurve(i);
1139 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1140 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1141 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1143 if (aC3D.IsNull()) {
1146 const Handle(Geom_BSplineCurve)& aBC=
1147 Handle(Geom_BSplineCurve)::DownCast(aC3D);
1152 aT1=aBC->FirstParameter();
1153 aT2=aBC->LastParameter();
1155 aEps=0.0001*(aT2-aT1);
1158 for (j=1; j<aNbP-1; ++j) {
1161 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
1162 myHS1, myHS2, myFace1, myFace2, myContext);
1167 }//for (i=1; i<=aNbLin; ++i) {
1168 myTolReached3d=sqrt(aD2Max);
1171 //=======================================================================
1172 //function : MakeCurve
1174 //=======================================================================
1175 void IntTools_FaceFace::MakeCurve(const Standard_Integer Index,
1176 const Handle(Adaptor3d_TopolTool)& dom1,
1177 const Handle(Adaptor3d_TopolTool)& dom2)
1179 Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor;
1180 Standard_Boolean ok, bPCurvesOk;
1181 Standard_Integer i, j, aNbParts;
1182 Standard_Real fprm, lprm;
1183 Standard_Real Tolpc;
1184 Handle(IntPatch_Line) L;
1185 IntPatch_IType typl;
1186 Handle(Geom_Curve) newc;
1188 const Standard_Real TOLCHECK =0.0000001;
1189 const Standard_Real TOLANGCHECK=0.1;
1191 rejectSurface = Standard_False;
1192 reApprox = Standard_False;
1194 bPCurvesOk = Standard_True;
1198 Tolpc = myTolApprox;
1199 bAvoidLineConstructor = Standard_False;
1200 L = myIntersector.Line(Index);
1201 typl = L->ArcType();
1203 if(typl==IntPatch_Walking) {
1204 Handle(IntPatch_Line) anewL;
1206 const Handle(IntPatch_WLine)& aWLine=
1207 Handle(IntPatch_WLine)::DownCast(L);
1208 //DumpWLine(aWLine);
1210 anewL = ComputePurgedWLine(aWLine);
1211 if(anewL.IsNull()) {
1216 //const Handle(IntPatch_WLine)& aWLineX = Handle(IntPatch_WLine)::DownCast(L);
1217 //DumpWLine(aWLineX);
1220 if(!myListOfPnts.IsEmpty()) {
1221 bAvoidLineConstructor = Standard_True;
1224 Standard_Integer nbp = aWLine->NbPnts();
1225 const IntSurf_PntOn2S& p1 = aWLine->Point(1);
1226 const IntSurf_PntOn2S& p2 = aWLine->Point(nbp);
1228 const gp_Pnt& P1 = p1.Value();
1229 const gp_Pnt& P2 = p2.Value();
1231 if(P1.SquareDistance(P2) < 1.e-14) {
1232 bAvoidLineConstructor = Standard_False;
1237 if(!bAvoidLineConstructor) {
1238 myLConstruct.Perform(L);
1240 bDone=myLConstruct.IsDone();
1241 aNbParts=myLConstruct.NbParts();
1242 if (!bDone|| !aNbParts) {
1251 //########################################
1252 // Line, Parabola, Hyperbola
1253 //########################################
1255 case IntPatch_Parabola:
1256 case IntPatch_Hyperbola: {
1257 if (typl == IntPatch_Lin) {
1259 new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
1262 else if (typl == IntPatch_Parabola) {
1264 new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
1267 else if (typl == IntPatch_Hyperbola) {
1269 new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
1273 if (typl == IntPatch_Lin) {
1274 TolR3d (myFace1, myFace2, myTolReached3d);
1277 aNbParts=myLConstruct.NbParts();
1278 for (i=1; i<=aNbParts; i++) {
1279 myLConstruct.Part(i, fprm, lprm);
1281 if (!Precision::IsNegativeInfinite(fprm) &&
1282 !Precision::IsPositiveInfinite(lprm)) {
1284 IntTools_Curve aCurve;
1286 Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
1287 aCurve.SetCurve(aCT3D);
1288 if (typl == IntPatch_Parabola) {
1289 Standard_Real aTolF1, aTolF2, aTolBase;
1291 aTolF1 = BRep_Tool::Tolerance(myFace1);
1292 aTolF2 = BRep_Tool::Tolerance(myFace2);
1293 aTolBase=aTolF1+aTolF2;
1294 myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
1297 aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
1299 Handle (Geom2d_Curve) C2d;
1300 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1301 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1302 myTolReached2d=Tolpc;
1305 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1308 Handle(Geom2d_BSplineCurve) H1;
1310 aCurve.SetFirstCurve2d(H1);
1314 Handle (Geom2d_Curve) C2d;
1315 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1316 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1317 myTolReached2d=Tolpc;
1320 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1323 Handle(Geom2d_BSplineCurve) H1;
1325 aCurve.SetSecondCurve2d(H1);
1327 mySeqOfCurve.Append(aCurve);
1328 } // end of if (!Precision::IsNegativeInfinite(fprm) && !Precision::IsPositiveInfinite(lprm))
1330 // on regarde si on garde
1332 Standard_Boolean bFNIt, bLPIt;
1333 Standard_Real aTestPrm, dT=100.;
1335 bFNIt=Precision::IsNegativeInfinite(fprm);
1336 bLPIt=Precision::IsPositiveInfinite(lprm);
1340 if (bFNIt && !bLPIt) {
1343 else if (!bFNIt && bLPIt) {
1347 gp_Pnt ptref(newc->Value(aTestPrm));
1349 GeomAbs_SurfaceType typS1 = myHS1->GetType();
1350 GeomAbs_SurfaceType typS2 = myHS2->GetType();
1351 if( typS1 == GeomAbs_SurfaceOfExtrusion ||
1352 typS1 == GeomAbs_OffsetSurface ||
1353 typS1 == GeomAbs_SurfaceOfRevolution ||
1354 typS2 == GeomAbs_SurfaceOfExtrusion ||
1355 typS2 == GeomAbs_OffsetSurface ||
1356 typS2 == GeomAbs_SurfaceOfRevolution)
1358 Handle(Geom2d_BSplineCurve) H1;
1359 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1363 Standard_Real u1, v1, u2, v2, Tol;
1365 Tol = Precision::Confusion();
1366 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1367 ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
1369 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1372 Handle(Geom2d_BSplineCurve) H1;
1373 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1376 }// end of for (i=1; i<=myLConstruct.NbParts(); i++)
1377 }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola:
1380 //########################################
1381 // Circle and Ellipse
1382 //########################################
1383 case IntPatch_Circle:
1384 case IntPatch_Ellipse: {
1386 if (typl == IntPatch_Circle) {
1387 newc = new Geom_Circle
1388 (Handle(IntPatch_GLine)::DownCast(L)->Circle());
1390 else { //IntPatch_Ellipse
1391 newc = new Geom_Ellipse
1392 (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
1396 TolR3d (myFace1, myFace2, myTolReached3d);
1398 aNbParts=myLConstruct.NbParts();
1400 Standard_Real aPeriod, aNul;
1401 TColStd_SequenceOfReal aSeqFprm, aSeqLprm;
1406 for (i=1; i<=aNbParts; i++) {
1407 myLConstruct.Part(i, fprm, lprm);
1409 if (fprm < aNul && lprm > aNul) {
1410 // interval that goes through 0. is divided on two intervals;
1411 while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
1412 while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
1414 if((aPeriod - fprm) > Tolpc) {
1415 aSeqFprm.Append(fprm);
1416 aSeqLprm.Append(aPeriod);
1419 gp_Pnt P1 = newc->Value(fprm);
1420 gp_Pnt P2 = newc->Value(aPeriod);
1421 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1422 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1424 if(P1.Distance(P2) > aTolDist) {
1425 Standard_Real anewpar = fprm;
1427 if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2,
1428 lprm, Standard_False, anewpar, myContext)) {
1431 aSeqFprm.Append(fprm);
1432 aSeqLprm.Append(aPeriod);
1437 if((lprm - aNul) > Tolpc) {
1438 aSeqFprm.Append(aNul);
1439 aSeqLprm.Append(lprm);
1442 gp_Pnt P1 = newc->Value(aNul);
1443 gp_Pnt P2 = newc->Value(lprm);
1444 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1445 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1447 if(P1.Distance(P2) > aTolDist) {
1448 Standard_Real anewpar = lprm;
1450 if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2,
1451 fprm, Standard_True, anewpar, myContext)) {
1454 aSeqFprm.Append(aNul);
1455 aSeqLprm.Append(lprm);
1461 aSeqFprm.Append(fprm);
1462 aSeqLprm.Append(lprm);
1467 aNbParts=aSeqFprm.Length();
1468 for (i=1; i<=aNbParts; i++) {
1472 Standard_Real aRealEpsilon=RealEpsilon();
1473 if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*M_PI) > aRealEpsilon) {
1474 //==============================================
1476 IntTools_Curve aCurve;
1477 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1478 aCurve.SetCurve(aTC3D);
1479 fprm=aTC3D->FirstParameter();
1480 lprm=aTC3D->LastParameter ();
1482 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {////
1484 Handle (Geom2d_Curve) C2d;
1485 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1486 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1487 myTolReached2d=Tolpc;
1490 aCurve.SetFirstCurve2d(C2d);
1493 Handle(Geom2d_BSplineCurve) H1;
1494 aCurve.SetFirstCurve2d(H1);
1499 Handle (Geom2d_Curve) C2d;
1500 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1501 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1502 myTolReached2d=Tolpc;
1505 aCurve.SetSecondCurve2d(C2d);
1508 Handle(Geom2d_BSplineCurve) H1;
1509 aCurve.SetSecondCurve2d(H1);
1514 Handle(Geom2d_BSplineCurve) H1;
1515 aCurve.SetFirstCurve2d(H1);
1516 aCurve.SetSecondCurve2d(H1);
1518 mySeqOfCurve.Append(aCurve);
1519 //==============================================
1520 } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon())
1523 // on regarde si on garde
1526 // if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) {
1527 if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
1528 IntTools_Curve aCurve;
1529 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1530 aCurve.SetCurve(aTC3D);
1531 fprm=aTC3D->FirstParameter();
1532 lprm=aTC3D->LastParameter ();
1535 Handle (Geom2d_Curve) C2d;
1536 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1537 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1538 myTolReached2d=Tolpc;
1541 aCurve.SetFirstCurve2d(C2d);
1544 Handle(Geom2d_BSplineCurve) H1;
1545 aCurve.SetFirstCurve2d(H1);
1549 Handle (Geom2d_Curve) C2d;
1550 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1551 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1552 myTolReached2d=Tolpc;
1555 aCurve.SetSecondCurve2d(C2d);
1558 Handle(Geom2d_BSplineCurve) H1;
1559 aCurve.SetSecondCurve2d(H1);
1561 mySeqOfCurve.Append(aCurve);
1566 Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
1568 aTwoPIdiv17=2.*M_PI/17.;
1570 for (j=0; j<=17; j++) {
1571 gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
1572 Tol = Precision::Confusion();
1574 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1575 ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
1577 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1580 IntTools_Curve aCurve;
1581 aCurve.SetCurve(newc);
1582 //==============================================
1583 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
1586 Handle (Geom2d_Curve) C2d;
1587 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1588 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1589 myTolReached2d=Tolpc;
1592 aCurve.SetFirstCurve2d(C2d);
1595 Handle(Geom2d_BSplineCurve) H1;
1596 aCurve.SetFirstCurve2d(H1);
1600 Handle (Geom2d_Curve) C2d;
1601 BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
1602 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1603 myTolReached2d=Tolpc;
1606 aCurve.SetSecondCurve2d(C2d);
1610 Handle(Geom2d_BSplineCurve) H1;
1611 aCurve.SetSecondCurve2d(H1);
1613 }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
1616 Handle(Geom2d_BSplineCurve) H1;
1618 aCurve.SetFirstCurve2d(H1);
1619 aCurve.SetSecondCurve2d(H1);
1621 //==============================================
1623 mySeqOfCurve.Append(aCurve);
1626 }// end of if (ok) {
1627 }// end of for (Standard_Integer j=0; j<=17; j++)
1628 }// end of else { on regarde si on garde
1629 }// for (i=1; i<=myLConstruct.NbParts(); i++)
1630 }// IntPatch_Circle: IntPatch_Ellipse:
1633 case IntPatch_Analytic: {
1634 IntSurf_Quadric quad1,quad2;
1635 GeomAbs_SurfaceType typs = myHS1->Surface().GetType();
1639 quad1.SetValue(myHS1->Surface().Plane());
1641 case GeomAbs_Cylinder:
1642 quad1.SetValue(myHS1->Surface().Cylinder());
1645 quad1.SetValue(myHS1->Surface().Cone());
1647 case GeomAbs_Sphere:
1648 quad1.SetValue(myHS1->Surface().Sphere());
1651 quad1.SetValue(myHS1->Surface().Torus());
1654 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
1657 typs = myHS2->Surface().GetType();
1661 quad2.SetValue(myHS2->Surface().Plane());
1663 case GeomAbs_Cylinder:
1664 quad2.SetValue(myHS2->Surface().Cylinder());
1667 quad2.SetValue(myHS2->Surface().Cone());
1669 case GeomAbs_Sphere:
1670 quad2.SetValue(myHS2->Surface().Sphere());
1673 quad2.SetValue(myHS2->Surface().Torus());
1676 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
1680 IntPatch_ALineToWLine convert (quad1, quad2);
1683 aNbParts=myLConstruct.NbParts();
1684 for (i=1; i<=aNbParts; i++) {
1685 myLConstruct.Part(i, fprm, lprm);
1686 Handle(IntPatch_WLine) WL =
1687 convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
1689 Handle(Geom2d_BSplineCurve) H1;
1690 Handle(Geom2d_BSplineCurve) H2;
1693 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1697 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1700 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1704 else { // myApprox=TRUE
1705 GeomInt_WLApprox theapp3d;
1707 Standard_Real tol2d = myTolApprox;
1709 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
1711 aNbParts=myLConstruct.NbParts();
1712 for (i=1; i<=aNbParts; i++) {
1713 myLConstruct.Part(i, fprm, lprm);
1714 Handle(IntPatch_WLine) WL =
1715 convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
1717 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
1719 if (!theapp3d.IsDone()) {
1721 Handle(Geom2d_BSplineCurve) H1;
1722 Handle(Geom2d_BSplineCurve) H2;
1725 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1729 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1732 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1736 if(myApprox1 || myApprox2) {
1737 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
1738 myTolReached2d = theapp3d.TolReached2d();
1742 if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
1743 myTolReached3d = theapp3d.TolReached3d();
1746 Standard_Integer aNbMultiCurves, nbpoles;
1747 aNbMultiCurves=theapp3d.NbMultiCurves();
1748 for (j=1; j<=aNbMultiCurves; j++) {
1749 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1750 nbpoles = mbspc.NbPoles();
1752 TColgp_Array1OfPnt tpoles(1, nbpoles);
1753 mbspc.Curve(1, tpoles);
1754 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1756 mbspc.Multiplicities(),
1759 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1760 Check.FixTangent(Standard_True,Standard_True);
1762 IntTools_Curve aCurve;
1763 aCurve.SetCurve(BS);
1766 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1767 mbspc.Curve(2,tpoles2d);
1768 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1770 mbspc.Multiplicities(),
1773 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1774 newCheck.FixTangent(Standard_True,Standard_True);
1776 aCurve.SetFirstCurve2d(BS2);
1779 Handle(Geom2d_BSplineCurve) H1;
1780 aCurve.SetFirstCurve2d(H1);
1784 TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
1785 Standard_Integer TwoOrThree;
1786 TwoOrThree=myApprox1 ? 3 : 2;
1787 mbspc.Curve(TwoOrThree, tpoles2d);
1788 Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
1790 mbspc.Multiplicities(),
1793 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1794 newCheck.FixTangent(Standard_True,Standard_True);
1796 aCurve.SetSecondCurve2d(BS2);
1799 Handle(Geom2d_BSplineCurve) H2;
1800 aCurve.SetSecondCurve2d(H2);
1803 mySeqOfCurve.Append(aCurve);
1805 }// for (j=1; j<=aNbMultiCurves; j++) {
1806 }// else from if (!theapp3d.IsDone())
1807 }// for (i=1; i<=aNbParts; i++) {
1808 }// else { // myApprox=TRUE
1809 }// case IntPatch_Analytic:
1812 case IntPatch_Walking:{
1813 Handle(IntPatch_WLine) WL =
1814 Handle(IntPatch_WLine)::DownCast(L);
1816 Standard_Integer ifprm, ilprm;
1820 if(!bAvoidLineConstructor){
1821 aNbParts=myLConstruct.NbParts();
1823 for (i=1; i<=aNbParts; ++i) {
1824 Handle(Geom2d_BSplineCurve) H1, H2;
1825 Handle(Geom_Curve) aBSp;
1827 if(bAvoidLineConstructor) {
1829 ilprm = WL->NbPnts();
1832 myLConstruct.Part(i, fprm, lprm);
1833 ifprm=(Standard_Integer)fprm;
1834 ilprm=(Standard_Integer)lprm;
1838 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1842 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1845 aBSp=MakeBSpline(WL, ifprm, ilprm);
1846 IntTools_Curve aIC(aBSp, H1, H2);
1847 mySeqOfCurve.Append(aIC);
1848 }// for (i=1; i<=aNbParts; ++i) {
1849 }// if (!myApprox) {
1852 Standard_Boolean bIsDecomposited;
1853 Standard_Integer nbiter, aNbSeqOfL;
1854 Standard_Real tol2d, aTolApproxImp;
1855 IntPatch_SequenceOfLine aSeqOfL;
1856 GeomInt_WLApprox theapp3d;
1857 Approx_ParametrizationType aParType = Approx_ChordLength;
1859 Standard_Boolean anApprox1 = myApprox1;
1860 Standard_Boolean anApprox2 = myApprox2;
1862 aTolApproxImp=1.e-5;
1863 tol2d = myTolApprox;
1865 GeomAbs_SurfaceType typs1, typs2;
1866 typs1 = myHS1->Surface().GetType();
1867 typs2 = myHS2->Surface().GetType();
1868 Standard_Boolean anWithPC = Standard_True;
1870 if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
1872 ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
1874 else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
1876 ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
1880 myTolApprox = aTolApproxImp;//1.e-5;
1881 anApprox1 = Standard_False;
1882 anApprox2 = Standard_False;
1884 tol2d = myTolApprox;
1887 if(myHS1 == myHS2) {
1888 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1889 rejectSurface = Standard_True;
1892 if(reApprox && !rejectSurface)
1893 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1895 Standard_Integer iDegMax, iDegMin, iNbIter;
1897 ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter);
1898 theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType);
1902 Standard_Real aReachedTol = Precision::Confusion();
1903 bIsDecomposited=DecompositionOfWLine(WL,
1909 bAvoidLineConstructor,
1913 if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) ) {
1914 myTolReached3d = aReachedTol;
1917 aNbSeqOfL=aSeqOfL.Length();
1919 if (bIsDecomposited) {
1925 if (!bAvoidLineConstructor) {
1926 aNbParts=myLConstruct.NbParts();
1931 for(i = 1; i <= nbiter; ++i) {
1932 if(bIsDecomposited) {
1933 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
1935 ilprm = WL->NbPnts();
1938 if(bAvoidLineConstructor) {
1940 ilprm = WL->NbPnts();
1943 myLConstruct.Part(i, fprm, lprm);
1944 ifprm = (Standard_Integer)fprm;
1945 ilprm = (Standard_Integer)lprm;
1949 //-- Si une des surfaces est un plan , on approxime en 2d
1950 //-- sur cette surface et on remonte les points 2d en 3d.
1951 if(typs1 == GeomAbs_Plane) {
1952 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
1954 else if(typs2 == GeomAbs_Plane) {
1955 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
1959 if (myHS1 != myHS2){
1960 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
1961 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
1963 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
1965 Standard_Boolean bUseSurfaces;
1966 bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
1969 rejectSurface = Standard_True;
1971 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1976 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
1979 if (!theapp3d.IsDone()) {
1980 Handle(Geom2d_BSplineCurve) H1;
1981 Handle(Geom2d_BSplineCurve) H2;
1983 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
1986 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1990 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1993 IntTools_Curve aIC(aBSp, H1, H2);
1994 mySeqOfCurve.Append(aIC);
1998 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
1999 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
2000 myTolReached2d = theapp3d.TolReached2d();
2003 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
2004 myTolReached3d = myTolReached2d;
2006 if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
2007 if (myTolReached3d<1.e-6) {
2008 myTolReached3d = theapp3d.TolReached3d();
2009 myTolReached3d=1.e-6;
2013 else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
2014 myTolReached3d = theapp3d.TolReached3d();
2017 Standard_Integer aNbMultiCurves, nbpoles;
2018 aNbMultiCurves=theapp3d.NbMultiCurves();
2019 for (j=1; j<=aNbMultiCurves; j++) {
2020 if(typs1 == GeomAbs_Plane) {
2021 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2022 nbpoles = mbspc.NbPoles();
2024 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2025 TColgp_Array1OfPnt tpoles(1,nbpoles);
2027 mbspc.Curve(1,tpoles2d);
2028 const gp_Pln& Pln = myHS1->Surface().Plane();
2030 Standard_Integer ik;
2031 for(ik = 1; ik<= nbpoles; ik++) {
2033 ElSLib::Value(tpoles2d.Value(ik).X(),
2034 tpoles2d.Value(ik).Y(),
2038 Handle(Geom_BSplineCurve) BS =
2039 new Geom_BSplineCurve(tpoles,
2041 mbspc.Multiplicities(),
2043 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2044 Check.FixTangent(Standard_True, Standard_True);
2046 IntTools_Curve aCurve;
2047 aCurve.SetCurve(BS);
2050 Handle(Geom2d_BSplineCurve) BS1 =
2051 new Geom2d_BSplineCurve(tpoles2d,
2053 mbspc.Multiplicities(),
2055 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2056 Check1.FixTangent(Standard_True,Standard_True);
2058 // ############################################
2059 if(!rejectSurface && !reApprox) {
2060 Standard_Boolean isValid = IsCurveValid(BS1);
2062 reApprox = Standard_True;
2066 // ############################################
2067 aCurve.SetFirstCurve2d(BS1);
2070 Handle(Geom2d_BSplineCurve) H1;
2071 aCurve.SetFirstCurve2d(H1);
2075 mbspc.Curve(2, tpoles2d);
2077 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
2079 mbspc.Multiplicities(),
2081 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2082 newCheck.FixTangent(Standard_True,Standard_True);
2084 // ###########################################
2085 if(!rejectSurface && !reApprox) {
2086 Standard_Boolean isValid = IsCurveValid(BS2);
2088 reApprox = Standard_True;
2092 // ###########################################
2094 aCurve.SetSecondCurve2d(BS2);
2097 Handle(Geom2d_BSplineCurve) H2;
2099 aCurve.SetSecondCurve2d(H2);
2102 mySeqOfCurve.Append(aCurve);
2103 }//if(typs1 == GeomAbs_Plane) {
2105 else if(typs2 == GeomAbs_Plane) {
2106 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2107 nbpoles = mbspc.NbPoles();
2109 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2110 TColgp_Array1OfPnt tpoles(1,nbpoles);
2111 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
2112 const gp_Pln& Pln = myHS2->Surface().Plane();
2114 Standard_Integer ik;
2115 for(ik = 1; ik<= nbpoles; ik++) {
2117 ElSLib::Value(tpoles2d.Value(ik).X(),
2118 tpoles2d.Value(ik).Y(),
2123 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
2125 mbspc.Multiplicities(),
2127 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2128 Check.FixTangent(Standard_True,Standard_True);
2130 IntTools_Curve aCurve;
2131 aCurve.SetCurve(BS);
2134 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
2136 mbspc.Multiplicities(),
2138 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2139 Check1.FixTangent(Standard_True,Standard_True);
2141 // ###########################################
2142 if(!rejectSurface && !reApprox) {
2143 Standard_Boolean isValid = IsCurveValid(BS1);
2145 reApprox = Standard_True;
2149 // ###########################################
2150 bPCurvesOk = CheckPCurve(BS1, myFace2);
2151 aCurve.SetSecondCurve2d(BS1);
2154 Handle(Geom2d_BSplineCurve) H2;
2155 aCurve.SetSecondCurve2d(H2);
2159 mbspc.Curve(1,tpoles2d);
2160 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
2162 mbspc.Multiplicities(),
2164 GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
2165 Check2.FixTangent(Standard_True,Standard_True);
2167 // ###########################################
2168 if(!rejectSurface && !reApprox) {
2169 Standard_Boolean isValid = IsCurveValid(BS2);
2171 reApprox = Standard_True;
2175 // ###########################################
2176 bPCurvesOk = bPCurvesOk && CheckPCurve(BS2, myFace1);
2177 aCurve.SetFirstCurve2d(BS2);
2180 Handle(Geom2d_BSplineCurve) H1;
2182 aCurve.SetFirstCurve2d(H1);
2185 //if points of the pcurves are out of the faces bounds
2186 //create 3d and 2d curves without approximation
2188 Handle(Geom2d_BSplineCurve) H1, H2;
2189 bPCurvesOk = Standard_True;
2191 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
2194 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
2195 bPCurvesOk = CheckPCurve(H1, myFace1);
2199 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
2200 bPCurvesOk = bPCurvesOk && CheckPCurve(H2, myFace2);
2203 //if pcurves created without approximation are out of the
2204 //faces bounds, use approximated 3d and 2d curves
2206 IntTools_Curve aIC(aBSp, H1, H2);
2207 mySeqOfCurve.Append(aIC);
2209 mySeqOfCurve.Append(aCurve);
2212 mySeqOfCurve.Append(aCurve);
2214 }// else if(typs2 == GeomAbs_Plane)
2216 else { //typs2 != GeomAbs_Plane && typs1 != GeomAbs_Plane
2217 Standard_Boolean bIsValid1, bIsValid2;
2218 Handle(Geom_BSplineCurve) BS;
2219 Handle(Geom2d_BSplineCurve) aH2D;
2220 IntTools_Curve aCurve;
2222 bIsValid1=Standard_True;
2223 bIsValid2=Standard_True;
2225 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2226 nbpoles = mbspc.NbPoles();
2227 TColgp_Array1OfPnt tpoles(1,nbpoles);
2228 mbspc.Curve(1,tpoles);
2229 BS=new Geom_BSplineCurve(tpoles,
2231 mbspc.Multiplicities(),
2233 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2234 Check.FixTangent(Standard_True,Standard_True);
2236 aCurve.SetCurve(BS);
2237 aCurve.SetFirstCurve2d(aH2D);
2238 aCurve.SetSecondCurve2d(aH2D);
2242 Handle(Geom2d_BSplineCurve) BS1;
2243 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2244 mbspc.Curve(2,tpoles2d);
2246 BS1=new Geom2d_BSplineCurve(tpoles2d,
2248 mbspc.Multiplicities(),
2250 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
2251 newCheck.FixTangent(Standard_True,Standard_True);
2254 bIsValid1=CheckPCurve(BS1, myFace1);
2257 aCurve.SetFirstCurve2d(BS1);
2260 Handle(Geom2d_BSplineCurve) BS1;
2261 fprm = BS->FirstParameter();
2262 lprm = BS->LastParameter();
2264 Handle(Geom2d_Curve) C2d;
2265 Standard_Real aTol = myTolApprox;
2266 BuildPCurves(fprm, lprm, aTol, myHS1->ChangeSurface().Surface(), BS, C2d);
2267 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2268 aCurve.SetFirstCurve2d(BS1);
2270 } // if(myApprox1) {
2274 Handle(Geom2d_BSplineCurve) BS2;
2275 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2276 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
2277 BS2=new Geom2d_BSplineCurve(tpoles2d,
2279 mbspc.Multiplicities(),
2281 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2282 newCheck.FixTangent(Standard_True,Standard_True);
2285 bIsValid2=CheckPCurve(BS2, myFace2);
2287 aCurve.SetSecondCurve2d(BS2);
2290 Handle(Geom2d_BSplineCurve) BS2;
2291 fprm = BS->FirstParameter();
2292 lprm = BS->LastParameter();
2294 Handle(Geom2d_Curve) C2d;
2295 Standard_Real aTol = myTolApprox;
2296 BuildPCurves(fprm, lprm, aTol, myHS2->ChangeSurface().Surface(), BS, C2d);
2297 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2298 aCurve.SetSecondCurve2d(BS2);
2301 if (!bIsValid1 || !bIsValid2) {
2302 myTolApprox=aTolApproxImp;//1.e-5;
2303 tol2d = myTolApprox;
2304 reApprox = Standard_True;
2308 mySeqOfCurve.Append(aCurve);
2314 }// case IntPatch_Walking:{
2317 case IntPatch_Restriction:
2325 //=======================================================================
2326 //function : BuildPCurves
2328 //=======================================================================
2329 void BuildPCurves (Standard_Real f,
2332 const Handle (Geom_Surface)& S,
2333 const Handle (Geom_Curve)& C,
2334 Handle (Geom2d_Curve)& C2d)
2336 if (!C2d.IsNull()) {
2340 Standard_Real umin,umax,vmin,vmax;
2342 S->Bounds(umin, umax, vmin, vmax);
2343 // in class ProjLib_Function the range of parameters is shrank by 1.e-09
2344 if((l - f) > 2.e-09) {
2345 C2d = GeomProjLib::Curve2d(C,f,l,S,umin,umax,vmin,vmax,Tol);
2348 // proj. a circle that goes through the pole on a sphere to the sphere
2349 Tol += Precision::Confusion();
2350 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2354 if((l - f) > Epsilon(Abs(f))) {
2355 GeomAPI_ProjectPointOnSurf aProjector1, aProjector2;
2356 gp_Pnt P1 = C->Value(f);
2357 gp_Pnt P2 = C->Value(l);
2358 aProjector1.Init(P1, S);
2359 aProjector2.Init(P2, S);
2361 if(aProjector1.IsDone() && aProjector2.IsDone()) {
2362 Standard_Real U=0., V=0.;
2363 aProjector1.LowerDistanceParameters(U, V);
2366 aProjector2.LowerDistanceParameters(U, V);
2369 if(p1.Distance(p2) > gp::Resolution()) {
2370 TColgp_Array1OfPnt2d poles(1,2);
2371 TColStd_Array1OfReal knots(1,2);
2372 TColStd_Array1OfInteger mults(1,2);
2377 mults(1) = mults(2) = 2;
2379 C2d = new Geom2d_BSplineCurve(poles,knots,mults,1);
2381 // compute reached tolerance.begin
2382 gp_Pnt PMid = C->Value((f + l) * 0.5);
2383 aProjector1.Perform(PMid);
2385 if(aProjector1.IsDone()) {
2386 aProjector1.LowerDistanceParameters(U, V);
2387 gp_Pnt2d pmidproj(U, V);
2388 gp_Pnt2d pmidcurve2d = C2d->Value((f + l) * 0.5);
2389 Standard_Real adist = pmidcurve2d.Distance(pmidproj);
2390 Tol = (adist > Tol) ? adist : Tol;
2392 // compute reached tolerance.end
2398 if (S->IsUPeriodic() && !C2d.IsNull()) {
2399 // Recadre dans le domaine UV de la face
2400 Standard_Real aTm, U0, aEps, period, du, U0x;
2401 Standard_Boolean bAdjust;
2403 aEps = Precision::PConfusion();
2404 period = S->UPeriod();
2407 gp_Pnt2d pm = C2d->Value(aTm);
2411 GeomInt::AdjustPeriodic(U0, umin, umax, period, U0x, du, aEps);
2413 gp_Vec2d T1(du, 0.);
2419 //=======================================================================
2420 //function : Parameters
2422 //=======================================================================
2423 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
2424 const Handle(GeomAdaptor_HSurface)& HS2,
2425 const gp_Pnt& Ptref,
2432 IntSurf_Quadric quad1,quad2;
2433 GeomAbs_SurfaceType typs = HS1->Surface().GetType();
2437 quad1.SetValue(HS1->Surface().Plane());
2439 case GeomAbs_Cylinder:
2440 quad1.SetValue(HS1->Surface().Cylinder());
2443 quad1.SetValue(HS1->Surface().Cone());
2445 case GeomAbs_Sphere:
2446 quad1.SetValue(HS1->Surface().Sphere());
2449 quad1.SetValue(HS1->Surface().Torus());
2452 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2455 typs = HS2->Surface().GetType();
2458 quad2.SetValue(HS2->Surface().Plane());
2460 case GeomAbs_Cylinder:
2461 quad2.SetValue(HS2->Surface().Cylinder());
2464 quad2.SetValue(HS2->Surface().Cone());
2466 case GeomAbs_Sphere:
2467 quad2.SetValue(HS2->Surface().Sphere());
2470 quad2.SetValue(HS2->Surface().Torus());
2473 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2476 quad1.Parameters(Ptref,U1,V1);
2477 quad2.Parameters(Ptref,U2,V2);
2480 //=======================================================================
2481 //function : MakeBSpline
2483 //=======================================================================
2484 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
2485 const Standard_Integer ideb,
2486 const Standard_Integer ifin)
2488 Standard_Integer i,nbpnt = ifin-ideb+1;
2489 TColgp_Array1OfPnt poles(1,nbpnt);
2490 TColStd_Array1OfReal knots(1,nbpnt);
2491 TColStd_Array1OfInteger mults(1,nbpnt);
2492 Standard_Integer ipidebm1;
2493 for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) {
2494 poles(i) = WL->Point(ipidebm1).Value();
2498 mults(1) = mults(nbpnt) = 2;
2500 new Geom_BSplineCurve(poles,knots,mults,1);
2504 //=======================================================================
2505 //function : MakeBSpline2d
2507 //=======================================================================
2508 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
2509 const Standard_Integer ideb,
2510 const Standard_Integer ifin,
2511 const Standard_Boolean onFirst)
2513 Standard_Integer i, nbpnt = ifin-ideb+1;
2514 TColgp_Array1OfPnt2d poles(1,nbpnt);
2515 TColStd_Array1OfReal knots(1,nbpnt);
2516 TColStd_Array1OfInteger mults(1,nbpnt);
2517 Standard_Integer ipidebm1;
2519 for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
2522 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
2524 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
2525 poles(i).SetCoord(U, V);
2529 mults(1) = mults(nbpnt) = 2;
2531 return new Geom2d_BSplineCurve(poles,knots,mults,1);
2533 //=======================================================================
2534 //function : PrepareLines3D
2536 //=======================================================================
2537 void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit)
2539 Standard_Integer i, aNbCurves;
2540 GeomAbs_SurfaceType aType1, aType2;
2541 IntTools_SequenceOfCurves aNewCvs;
2543 // 1. Treatment closed curves
2544 aNbCurves=mySeqOfCurve.Length();
2545 for (i=1; i<=aNbCurves; ++i) {
2546 const IntTools_Curve& aIC=mySeqOfCurve(i);
2549 Standard_Integer j, aNbC;
2550 IntTools_SequenceOfCurves aSeqCvs;
2552 aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
2554 for (j=1; j<=aNbC; ++j) {
2555 const IntTools_Curve& aICNew=aSeqCvs(j);
2556 aNewCvs.Append(aICNew);
2560 aNewCvs.Append(aIC);
2564 aNewCvs.Append(aIC);
2568 // 2. Plane\Cone intersection when we had 4 curves
2569 aType1=myHS1->GetType();
2570 aType2=myHS2->GetType();
2571 aNbCurves=aNewCvs.Length();
2573 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) ||
2574 (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) {
2576 GeomAbs_CurveType aCType1;
2578 aCType1=aNewCvs(1).Type();
2579 if (aCType1==GeomAbs_Line) {
2580 IntTools_SequenceOfCurves aSeqIn, aSeqOut;
2582 for (i=1; i<=aNbCurves; ++i) {
2583 const IntTools_Curve& aIC=aNewCvs(i);
2587 IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
2590 aNbCurves=aSeqOut.Length();
2591 for (i=1; i<=aNbCurves; ++i) {
2592 const IntTools_Curve& aIC=aSeqOut(i);
2593 aNewCvs.Append(aIC);
2597 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)...
2599 // 3. Fill mySeqOfCurve
2600 mySeqOfCurve.Clear();
2601 aNbCurves=aNewCvs.Length();
2602 for (i=1; i<=aNbCurves; ++i) {
2603 const IntTools_Curve& aIC=aNewCvs(i);
2604 mySeqOfCurve.Append(aIC);
2607 //=======================================================================
2608 //function : CorrectSurfaceBoundaries
2610 //=======================================================================
2611 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
2612 const Standard_Real theTolerance,
2613 Standard_Real& theumin,
2614 Standard_Real& theumax,
2615 Standard_Real& thevmin,
2616 Standard_Real& thevmax)
2618 Standard_Boolean enlarge, isuperiodic, isvperiodic;
2619 Standard_Real uinf, usup, vinf, vsup, delta;
2620 GeomAbs_SurfaceType aType;
2621 Handle(Geom_Surface) aSurface;
2623 aSurface = BRep_Tool::Surface(theFace);
2624 aSurface->Bounds(uinf, usup, vinf, vsup);
2625 delta = theTolerance;
2626 enlarge = Standard_False;
2628 GeomAdaptor_Surface anAdaptorSurface(aSurface);
2630 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
2631 Handle(Geom_Surface) aBasisSurface =
2632 (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface();
2634 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2635 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2640 if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2641 Handle(Geom_Surface) aBasisSurface =
2642 (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface();
2644 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2645 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2650 isuperiodic = anAdaptorSurface.IsUPeriodic();
2651 isvperiodic = anAdaptorSurface.IsVPeriodic();
2653 aType=anAdaptorSurface.GetType();
2654 if((aType==GeomAbs_BezierSurface) ||
2655 (aType==GeomAbs_BSplineSurface) ||
2656 (aType==GeomAbs_SurfaceOfExtrusion) ||
2657 (aType==GeomAbs_SurfaceOfRevolution) ||
2658 (aType==GeomAbs_Cylinder)) {
2659 enlarge=Standard_True;
2662 if(!isuperiodic && enlarge) {
2664 if((theumin - uinf) > delta )
2670 if((usup - theumax) > delta )
2676 if(!isvperiodic && enlarge) {
2677 if((thevmin - vinf) > delta ) {
2683 if((vsup - thevmax) > delta ) {
2692 Standard_Integer aNbP;
2693 Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA;
2695 aTolPA=Precision::Angular();
2698 aXP=anAdaptorSurface.UPeriod();
2699 dXfact=theumax-theumin;
2700 if (dXfact-aTolPA>aXP) {
2701 aXmid=0.5*(theumax+theumin);
2702 aNbP=RealToInt(aXmid/aXP);
2707 if (theumin>aTolPA) {
2708 aX1=theumin+aNbP*aXP;
2721 aXP=anAdaptorSurface.VPeriod();
2722 dXfact=thevmax-thevmin;
2723 if (dXfact-aTolPA>aXP) {
2724 aXmid=0.5*(thevmax+thevmin);
2725 aNbP=RealToInt(aXmid/aXP);
2730 if (thevmin>aTolPA) {
2731 aX1=thevmin+aNbP*aXP;
2744 if(isuperiodic || isvperiodic) {
2745 Standard_Boolean correct = Standard_False;
2746 Standard_Boolean correctU = Standard_False;
2747 Standard_Boolean correctV = Standard_False;
2749 TopExp_Explorer anExp;
2751 for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2752 if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
2753 correct = Standard_True;
2755 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
2757 for(Standard_Integer i = 0; i < 2; i++) {
2759 anEdge.Orientation(TopAbs_FORWARD);
2762 anEdge.Orientation(TopAbs_REVERSED);
2764 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
2766 if(aCurve.IsNull()) {
2767 correct = Standard_False;
2770 Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
2772 if(aLine.IsNull()) {
2773 correct = Standard_False;
2776 gp_Dir2d anUDir(1., 0.);
2777 gp_Dir2d aVDir(0., 1.);
2778 Standard_Real anAngularTolerance = Precision::Angular();
2780 correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
2781 correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
2783 gp_Pnt2d pp1 = aCurve->Value(f);
2785 gp_Pnt2d pp2 = aCurve->Value(l);
2794 Standard_Real umin, vmin, umax, vmax;
2795 aBox.Get(umin, vmin, umax, vmax);
2797 if(isuperiodic && correctU) {
2802 if(theumax > umax) {
2806 if(isvperiodic && correctV) {
2818 // The block is dedicated to determine whether WLine [ifprm, ilprm]
2819 // crosses the degenerated zone on each given surface or not.
2820 // If Yes -> We will not use info about surfaces during approximation
2821 // because inside degenerated zone of the surface the approx. algo.
2822 // uses wrong values of normal, etc., and resulting curve will have
2823 // oscillations that we would not like to have.
2828 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2829 const Handle(Geom_Surface)& aS,
2830 const Standard_Integer iDir);
2832 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2833 const TopoDS_Face& aF1,
2834 const TopoDS_Face& aF2);
2835 //=======================================================================
2836 //function : NotUseSurfacesForApprox
2838 //=======================================================================
2839 Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
2840 const TopoDS_Face& aF2,
2841 const Handle(IntPatch_WLine)& WL,
2842 const Standard_Integer ifprm,
2843 const Standard_Integer ilprm)
2845 Standard_Boolean bPInDZ;
2847 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
2849 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
2850 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
2855 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
2856 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
2860 //=======================================================================
2861 //function : IsPointInDegeneratedZone
2863 //=======================================================================
2864 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2865 const TopoDS_Face& aF1,
2866 const TopoDS_Face& aF2)
2869 Standard_Boolean bFlag=Standard_True;
2870 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
2871 Standard_Real U1, V1, U2, V2, aDelta, aD;
2874 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
2875 aS1->Bounds(US11, US12, VS11, VS12);
2876 GeomAdaptor_Surface aGAS1(aS1);
2878 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
2879 aS1->Bounds(US21, US22, VS21, VS22);
2880 GeomAdaptor_Surface aGAS2(aS2);
2882 //const gp_Pnt& aP=aP2S.Value();
2883 aP2S.Parameters(U1, V1, U2, V2);
2887 aD=aGAS1.UResolution(aDelta);
2888 aP2d.SetCoord(U1, V1);
2889 if (fabs(U1-US11) < aD) {
2890 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2895 if (fabs(U1-US12) < aD) {
2896 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2901 aD=aGAS1.VResolution(aDelta);
2902 if (fabs(V1-VS11) < aDelta) {
2903 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2908 if (fabs(V1-VS12) < aDelta) {
2909 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2915 aD=aGAS2.UResolution(aDelta);
2916 aP2d.SetCoord(U2, V2);
2917 if (fabs(U2-US21) < aDelta) {
2918 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2923 if (fabs(U2-US22) < aDelta) {
2924 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2929 aD=aGAS2.VResolution(aDelta);
2930 if (fabs(V2-VS21) < aDelta) {
2931 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2936 if (fabs(V2-VS22) < aDelta) {
2937 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2945 //=======================================================================
2946 //function : IsDegeneratedZone
2948 //=======================================================================
2949 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2950 const Handle(Geom_Surface)& aS,
2951 const Standard_Integer iDir)
2953 Standard_Boolean bFlag=Standard_True;
2954 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
2955 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
2956 aS->Bounds(US1, US2, VS1, VS2);
2958 gp_Pnt aPm, aPb, aPe;
2963 aS->D0(aXm, aYm, aPm);
2980 aS->D0(aXb, aYb, aPb);
2981 aS->D0(aXe, aYe, aPe);
2983 d1=aPm.Distance(aPb);
2984 d2=aPm.Distance(aPe);
2985 if (d1 < dD && d2 < dD) {
3002 aS->D0(aXb, aYb, aPb);
3003 aS->D0(aXe, aYe, aPe);
3005 d1=aPm.Distance(aPb);
3006 d2=aPm.Distance(aPe);
3007 if (d1 < dD && d2 < dD) {
3015 //=========================================================================
3016 // static function : ComputePurgedWLine
3017 // purpose : Removes equal points (leave one of equal points) from theWLine
3018 // and recompute vertex parameters.
3019 // Returns new WLine or null WLine if the number
3020 // of the points is less than 2.
3021 //=========================================================================
3022 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) {
3024 Standard_Integer i, k, v, nb, nbvtx;
3025 Handle(IntPatch_WLine) aResult;
3026 nbvtx = theWLine->NbVertex();
3027 nb = theWLine->NbPnts();
3029 const IntSurf_PntOn2S& p1 = theWLine->Point(1);
3030 const IntSurf_PntOn2S& p2 = theWLine->Point(2);
3031 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
3036 Handle(IntPatch_WLine) aLocalWLine;
3037 Handle(IntPatch_WLine) aTmpWLine = theWLine;
3038 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
3039 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
3040 for(i = 1; i <= nb; i++) {
3041 aLineOn2S->Add(theWLine->Point(i));
3044 for(v = 1; v <= nbvtx; v++) {
3045 aLocalWLine->AddVertex(theWLine->Vertex(v));
3048 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
3049 Standard_Integer aStartIndex = i + 1;
3050 Standard_Integer anEndIndex = i + 5;
3051 nb = aLineOn2S->NbPoints();
3052 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
3054 if((aStartIndex > nb) || (anEndIndex <= 1)) {
3059 while(k <= anEndIndex) {
3062 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
3063 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
3065 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
3066 aTmpWLine = aLocalWLine;
3067 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
3069 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
3070 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
3071 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
3073 if(avertexindex >= k) {
3074 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
3076 aLocalWLine->AddVertex(aVertex);
3078 aLineOn2S->RemovePoint(k);
3087 if(aLineOn2S->NbPoints() > 1) {
3088 aResult = aLocalWLine;
3093 //=======================================================================
3096 //=======================================================================
3097 void TolR3d(const TopoDS_Face& aF1,
3098 const TopoDS_Face& aF2,
3099 Standard_Real& myTolReached3d)
3101 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
3103 aTolTresh=2.999999e-3;
3104 aTolF1 = BRep_Tool::Tolerance(aF1);
3105 aTolF2 = BRep_Tool::Tolerance(aF2);
3106 aTolFMax=Max(aTolF1, aTolF2);
3108 if (aTolFMax>aTolTresh) {
3109 myTolReached3d=aTolFMax;
3112 //=======================================================================
3113 //function : IsPointOnBoundary
3115 //=======================================================================
3116 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
3117 const Standard_Real theFirstBoundary,
3118 const Standard_Real theSecondBoundary,
3119 const Standard_Real theResolution,
3120 Standard_Boolean& IsOnFirstBoundary)
3122 Standard_Boolean bRet;
3124 Standard_Real adist;
3126 bRet=Standard_False;
3127 for(i = 0; i < 2; ++i) {
3128 IsOnFirstBoundary = (i == 0);
3129 if (IsOnFirstBoundary) {
3130 adist = fabs(theParameter - theFirstBoundary);
3133 adist = fabs(theParameter - theSecondBoundary);
3135 if(adist < theResolution) {
3141 // ------------------------------------------------------------------------------------------------
3142 // static function: FindPoint
3144 // ------------------------------------------------------------------------------------------------
3145 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3146 const gp_Pnt2d& theLastPoint,
3147 const Standard_Real theUmin,
3148 const Standard_Real theUmax,
3149 const Standard_Real theVmin,
3150 const Standard_Real theVmax,
3151 gp_Pnt2d& theNewPoint) {
3153 gp_Vec2d aVec(theFirstPoint, theLastPoint);
3154 Standard_Integer i = 0, j = 0;
3156 for(i = 0; i < 4; i++) {
3157 gp_Vec2d anOtherVec;
3158 gp_Vec2d anOtherVecNormal;
3159 gp_Pnt2d aprojpoint = theLastPoint;
3162 anOtherVec.SetX(0.);
3163 anOtherVec.SetY(1.);
3164 anOtherVecNormal.SetX(1.);
3165 anOtherVecNormal.SetY(0.);
3168 aprojpoint.SetX(theUmin);
3170 aprojpoint.SetX(theUmax);
3173 anOtherVec.SetX(1.);
3174 anOtherVec.SetY(0.);
3175 anOtherVecNormal.SetX(0.);
3176 anOtherVecNormal.SetY(1.);
3179 aprojpoint.SetY(theVmin);
3181 aprojpoint.SetY(theVmax);
3183 gp_Vec2d anormvec = aVec;
3184 anormvec.Normalize();
3185 RefineVector(anormvec);
3186 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
3188 if(fabs(adot1) < Precision::Angular())
3190 Standard_Real adist = 0.;
3191 Standard_Boolean bIsOut = Standard_False;
3194 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
3195 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
3198 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
3199 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
3201 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
3203 for(j = 0; j < 2; j++) {
3204 anoffset = (j == 0) ? anoffset : -anoffset;
3205 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
3206 gp_Vec2d acurvec(theLastPoint, acurpoint);
3210 Standard_Real aDotX, anAngleX;
3212 aDotX = aVec.Dot(acurvec);
3213 anAngleX = aVec.Angle(acurvec);
3215 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
3217 if((acurpoint.Y() >= theVmin) &&
3218 (acurpoint.Y() <= theVmax)) {
3219 theNewPoint = acurpoint;
3220 return Standard_True;
3224 if((acurpoint.X() >= theUmin) &&
3225 (acurpoint.X() <= theUmax)) {
3226 theNewPoint = acurpoint;
3227 return Standard_True;
3233 return Standard_False;
3237 // ------------------------------------------------------------------------------------------------
3238 // static function: FindPoint
3239 // purpose: Find point on the boundary of radial tangent zone
3240 // ------------------------------------------------------------------------------------------------
3241 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3242 const gp_Pnt2d& theLastPoint,
3243 const Standard_Real theUmin,
3244 const Standard_Real theUmax,
3245 const Standard_Real theVmin,
3246 const Standard_Real theVmax,
3247 const gp_Pnt2d& theTanZoneCenter,
3248 const Standard_Real theZoneRadius,
3249 Handle(GeomAdaptor_HSurface) theGASurface,
3250 gp_Pnt2d& theNewPoint) {
3251 theNewPoint = theLastPoint;
3253 if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
3254 return Standard_False;
3256 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3257 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3259 Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3260 gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) );
3261 gp_Circ2d aCircle( anAxis, aRadius );
3264 gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() );
3265 Standard_Real aLength = aDir.Magnitude();
3266 if ( aLength <= gp::Resolution() )
3267 return Standard_False;
3268 gp_Lin2d aLine( theFirstPoint, aDir );
3271 Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine );
3272 Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength );
3273 Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle );
3275 Standard_Real aTol = aRadius * 0.001;
3276 aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol;
3278 Geom2dAPI_InterCurveCurve anIntersector;
3279 anIntersector.Init( aC1, aC2, aTol );
3281 if ( anIntersector.NbPoints() == 0 )
3282 return Standard_False;
3284 Standard_Boolean aFound = Standard_False;
3285 Standard_Real aMinDist = aLength * aLength;
3286 Standard_Integer i = 0;
3287 for ( i = 1; i <= anIntersector.NbPoints(); i++ ) {
3288 gp_Pnt2d aPInt = anIntersector.Point( i );
3289 if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
3290 if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
3291 ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
3292 theNewPoint = aPInt;
3293 aFound = Standard_True;
3301 // ------------------------------------------------------------------------------------------------
3302 // static function: IsInsideTanZone
3303 // purpose: Check if point is inside a radial tangent zone
3304 // ------------------------------------------------------------------------------------------------
3305 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
3306 const gp_Pnt2d& theTanZoneCenter,
3307 const Standard_Real theZoneRadius,
3308 Handle(GeomAdaptor_HSurface) theGASurface) {
3310 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3311 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3312 Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3313 aRadiusSQR *= aRadiusSQR;
3314 if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR )
3315 return Standard_True;
3316 return Standard_False;
3319 // ------------------------------------------------------------------------------------------------
3320 // static function: CheckTangentZonesExist
3321 // purpose: Check if tangent zone exists
3322 // ------------------------------------------------------------------------------------------------
3323 Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
3324 const Handle(GeomAdaptor_HSurface)& theSurface2 )
3326 if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
3327 ( theSurface2->GetType() != GeomAbs_Torus ) )
3328 return Standard_False;
3330 gp_Torus aTor1 = theSurface1->Torus();
3331 gp_Torus aTor2 = theSurface2->Torus();
3333 if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() )
3334 return Standard_False;
3336 if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) ||
3337 ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) )
3338 return Standard_False;
3340 if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) ||
3341 ( aTor2.MajorRadius() < aTor2.MinorRadius() ) )
3342 return Standard_False;
3343 return Standard_True;
3346 // ------------------------------------------------------------------------------------------------
3347 // static function: ComputeTangentZones
3349 // ------------------------------------------------------------------------------------------------
3350 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
3351 const Handle(GeomAdaptor_HSurface)& theSurface2,
3352 const TopoDS_Face& theFace1,
3353 const TopoDS_Face& theFace2,
3354 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
3355 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
3356 Handle(TColStd_HArray1OfReal)& theResultRadius,
3357 const Handle(IntTools_Context)& aContext)
3359 Standard_Integer aResult = 0;
3360 if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) )
3364 TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2;
3365 TColStd_SequenceOfReal aSeqResultRad;
3367 gp_Torus aTor1 = theSurface1->Torus();
3368 gp_Torus aTor2 = theSurface2->Torus();
3370 gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() );
3371 gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() );
3372 Standard_Integer j = 0;
3374 for ( j = 0; j < 2; j++ ) {
3375 Standard_Real aCoef = ( j == 0 ) ? -1 : 1;
3376 Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius());
3377 Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius());
3379 gp_Circ aCircle1( anax1, aRadius1 );
3380 gp_Circ aCircle2( anax2, aRadius2 );
3382 // roughly compute radius of tangent zone for perpendicular case
3383 Standard_Real aCriteria = Precision::Confusion() * 0.5;
3385 Standard_Real aT1 = aCriteria;
3386 Standard_Real aT2 = aCriteria;
3388 // internal tangency
3389 Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3390 //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria );
3391 aT1 = 2. * aR * aCriteria;
3395 // external tangency
3396 Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3397 Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3398 Standard_Real aDelta = aRb - aCriteria;
3400 aDelta -= aRm * aRm;
3401 aDelta /= 2. * (aRb - aRm);
3402 aDelta -= 0.5 * (aRb - aRm);
3404 aT1 = 2. * aRm * (aRm - aDelta);
3407 aCriteria = ( aT1 > aT2) ? aT1 : aT2;
3408 if ( aCriteria > 0 )
3409 aCriteria = sqrt( aCriteria );
3411 if ( aCriteria > 0.5 * aTor1.MinorRadius() ) {
3412 // too big zone -> drop to minimum
3413 aCriteria = Precision::Confusion();
3416 GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) );
3417 GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) );
3418 Extrema_ExtCC anExtrema(aC1, aC2, 0, 2. * M_PI, 0, 2. * M_PI,
3419 Precision::PConfusion(), Precision::PConfusion());
3421 if ( anExtrema.IsDone() ) {
3423 Standard_Integer i = 0;
3424 for ( i = 1; i <= anExtrema.NbExt(); i++ ) {
3425 if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
3428 Extrema_POnCurv P1, P2;
3429 anExtrema.Points( i, P1, P2 );
3431 Standard_Boolean bFoundResult = Standard_True;
3434 Standard_Integer surfit = 0;
3435 for ( surfit = 0; surfit < 2; surfit++ ) {
3436 GeomAPI_ProjectPointOnSurf& aProjector =
3437 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3439 gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
3440 aProjector.Perform(aP3d);
3442 if(!aProjector.IsDone())
3443 bFoundResult = Standard_False;
3445 if(aProjector.LowerDistance() > aCriteria) {
3446 bFoundResult = Standard_False;
3449 Standard_Real foundU = 0, foundV = 0;
3450 aProjector.LowerDistanceParameters(foundU, foundV);
3452 pr1 = gp_Pnt2d( foundU, foundV );
3454 pr2 = gp_Pnt2d( foundU, foundV );
3458 if ( bFoundResult ) {
3459 aSeqResultS1.Append( pr1 );
3460 aSeqResultS2.Append( pr2 );
3461 aSeqResultRad.Append( aCriteria );
3463 // torus is u and v periodic
3464 const Standard_Real twoPI = M_PI + M_PI;
3465 Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
3466 Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
3468 // iteration on period bounds
3469 for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
3470 Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
3471 Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
3473 // iteration on surfaces
3474 for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
3475 Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
3476 Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
3477 TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
3478 TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
3480 if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
3481 aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
3482 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3483 aSeqResultRad.Append( aCriteria );
3485 if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
3486 aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
3487 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3488 aSeqResultRad.Append( aCriteria );
3496 aResult = aSeqResultRad.Length();
3498 if ( aResult > 0 ) {
3499 theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult );
3500 theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult );
3501 theResultRadius = new TColStd_HArray1OfReal( 1, aResult );
3503 for ( Standard_Integer i = 1 ; i <= aResult; i++ ) {
3504 theResultOnS1->SetValue( i, aSeqResultS1.Value(i) );
3505 theResultOnS2->SetValue( i, aSeqResultS2.Value(i) );
3506 theResultRadius->SetValue( i, aSeqResultRad.Value(i) );
3512 // ------------------------------------------------------------------------------------------------
3513 // static function: AdjustByNeighbour
3515 // ------------------------------------------------------------------------------------------------
3516 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
3517 const gp_Pnt2d& theOriginalPoint,
3518 Handle(GeomAdaptor_HSurface) theGASurface) {
3520 gp_Pnt2d ap1 = theaNeighbourPoint;
3521 gp_Pnt2d ap2 = theOriginalPoint;
3523 if ( theGASurface->IsUPeriodic() ) {
3524 Standard_Real aPeriod = theGASurface->UPeriod();
3525 gp_Pnt2d aPTest = ap2;
3526 Standard_Real aSqDistMin = 1.e+100;
3528 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3529 aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt );
3530 Standard_Real dd = ap1.SquareDistance( aPTest );
3532 if ( dd < aSqDistMin ) {
3538 if ( theGASurface->IsVPeriodic() ) {
3539 Standard_Real aPeriod = theGASurface->VPeriod();
3540 gp_Pnt2d aPTest = ap2;
3541 Standard_Real aSqDistMin = 1.e+100;
3543 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3544 aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt );
3545 Standard_Real dd = ap1.SquareDistance( aPTest );
3547 if ( dd < aSqDistMin ) {
3556 // ------------------------------------------------------------------------------------------------
3557 //function: DecompositionOfWLine
3559 // ------------------------------------------------------------------------------------------------
3560 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
3561 const Handle(GeomAdaptor_HSurface)& theSurface1,
3562 const Handle(GeomAdaptor_HSurface)& theSurface2,
3563 const TopoDS_Face& theFace1,
3564 const TopoDS_Face& theFace2,
3565 const GeomInt_LineConstructor& theLConstructor,
3566 const Standard_Boolean theAvoidLConstructor,
3567 IntPatch_SequenceOfLine& theNewLines,
3568 Standard_Real& theReachedTol3d,
3569 const Handle(IntTools_Context)& aContext)
3572 Standard_Boolean bRet, bAvoidLineConstructor;
3573 Standard_Integer aNbPnts, aNbParts;
3575 bRet=Standard_False;
3576 aNbPnts=theWLine->NbPnts();
3577 bAvoidLineConstructor=theAvoidLConstructor;
3582 if (!bAvoidLineConstructor) {
3583 aNbParts=theLConstructor.NbParts();
3589 Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary;
3590 Standard_Integer nblines, pit, i, j;
3592 TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts);
3593 TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts);
3594 TColStd_ListOfInteger aListOfPointIndex;
3596 Handle(TColgp_HArray1OfPnt2d) aTanZoneS1;
3597 Handle(TColgp_HArray1OfPnt2d) aTanZoneS2;
3598 Handle(TColStd_HArray1OfReal) aTanZoneRadius;
3599 Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2,
3600 aTanZoneS1, aTanZoneS2, aTanZoneRadius, aContext);
3604 aTol=Precision::Confusion();
3606 bIsPrevPointOnBoundary=Standard_False;
3607 bIsPointOnBoundary=Standard_False;
3612 for(pit = 1; pit <= aNbPnts; ++pit) {
3613 Standard_Boolean bIsOnFirstBoundary, isperiodic;
3614 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
3615 Standard_Real aParameter, anoffset, anAdjustPar;
3616 Standard_Real umin, umax, vmin, vmax;
3618 bIsCurrentPointOnBoundary = Standard_False;
3619 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
3622 for(i = 0; i < 2; ++i) {
3623 Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
3624 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3626 aPoint.ParametersOnS1(U, V);
3629 aPoint.ParametersOnS2(U, V);
3632 for(j = 0; j < 2; j++) {
3633 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3639 aResolution=aGASurface->UResolution(aTol);
3640 aPeriod=aGASurface->UPeriod();
3641 alowerboundary=umin;
3642 aupperboundary=umax;
3646 aResolution=aGASurface->VResolution(aTol);
3647 aPeriod=aGASurface->VPeriod();
3648 alowerboundary=vmin;
3649 aupperboundary=vmax;
3653 GeomInt::AdjustPeriodic(aParameter,
3660 bIsOnFirstBoundary = Standard_True;// ?
3662 IsPointOnBoundary(anAdjustPar,
3666 bIsOnFirstBoundary);
3668 if(bIsPointOnBoundary) {
3669 bIsCurrentPointOnBoundary = Standard_True;
3673 // check if a point belong to a tangent zone. Begin
3674 Standard_Integer zIt = 0;
3675 for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
3676 gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3677 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3679 if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
3680 // set boundary flag to split the curve by a tangent zone
3681 bIsPointOnBoundary = Standard_True;
3682 bIsCurrentPointOnBoundary = Standard_True;
3683 if ( theReachedTol3d < aZoneRadius ) {
3684 theReachedTol3d = aZoneRadius;
3690 }//for(j = 0; j < 2; j++) {
3692 if(bIsCurrentPointOnBoundary){
3695 }//for(i = 0; i < 2; ++i) {
3697 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
3698 if(!aListOfPointIndex.IsEmpty()) {
3700 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3701 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3702 aListOfPointIndex.Clear();
3704 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
3706 aListOfPointIndex.Append(pit);
3707 } //for(pit = 1; pit <= aNbPnts; ++pit) {
3709 if(!aListOfPointIndex.IsEmpty()) {
3711 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3712 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3713 aListOfPointIndex.Clear();
3717 return bRet; //Standard_False;
3721 // 2. Correct wlines.begin
3722 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
3723 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S();
3725 for(i = 1; i <= nblines; i++) {
3726 if(anArrayOfLineType.Value(i) != 0) {
3729 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3730 TColStd_ListOfInteger aListOfFLIndex;
3732 for(j = 0; j < 2; j++) {
3733 Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1);
3735 if((aneighbourindex < 1) || (aneighbourindex > nblines))
3738 if(anArrayOfLineType.Value(aneighbourindex) == 0)
3740 const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex);
3741 Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First();
3742 const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
3744 IntSurf_PntOn2S aNewP = aPoint;
3745 if(aListOfIndex.Extent() < 2) {
3746 aSeqOfPntOn2S->Add(aNewP);
3747 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
3751 Standard_Integer iFirst = aListOfIndex.First();
3752 Standard_Integer iLast = aListOfIndex.Last();
3754 for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
3756 Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
3757 Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
3758 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3759 Standard_Real U=0., V=0.;
3762 aNewP.ParametersOnS1(U, V);
3764 aNewP.ParametersOnS2(U, V);
3765 Standard_Integer nbboundaries = 0;
3767 Standard_Boolean bIsNearBoundary = Standard_False;
3768 Standard_Integer aZoneIndex = 0;
3769 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
3770 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
3773 for(Standard_Integer parit = 0; parit < 2; parit++) {
3774 Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3776 Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
3777 Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
3778 Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
3780 Standard_Real aParameter = (parit == 0) ? U : V;
3781 Standard_Boolean bIsOnFirstBoundary = Standard_True;
3785 IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3786 if(bIsPointOnBoundary) {
3787 bIsUBoundary = (parit == 0);
3788 bIsFirstBoundary = bIsOnFirstBoundary;
3793 Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3794 Standard_Real anoffset, anAdjustPar;
3795 GeomInt::AdjustPeriodic(aParameter, alowerboundary, aupperboundary,
3796 aPeriod, anAdjustPar, anoffset);
3799 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3800 if(bIsPointOnBoundary) {
3801 bIsUBoundary = (parit == 0);
3802 bIsFirstBoundary = bIsOnFirstBoundary;
3806 //check neighbourhood of boundary
3807 Standard_Real anEpsilon = aResolution * 100.;
3808 Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
3809 anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
3811 bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
3812 anEpsilon, bIsOnFirstBoundary);
3818 // check if a point belong to a tangent zone. Begin
3819 for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
3820 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3821 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3823 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
3824 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3825 Standard_Real nU1, nV1;
3828 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3830 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3831 gp_Pnt2d ap1(nU1, nV1);
3832 gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
3835 if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
3837 bIsNearBoundary = Standard_True;
3838 if ( theReachedTol3d < aZoneRadius ) {
3839 theReachedTol3d = aZoneRadius;
3843 // check if a point belong to a tangent zone. End
3844 Standard_Boolean bComputeLineEnd = Standard_False;
3846 if(nbboundaries == 2) {
3848 bComputeLineEnd = Standard_True;
3851 else if(nbboundaries == 1) {
3852 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3855 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
3856 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
3857 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3858 Standard_Real aParameter = (bIsUBoundary) ? U : V;
3859 Standard_Real anoffset, anAdjustPar;
3860 GeomInt::AdjustPeriodic(aParameter, alowerboundary, aupperboundary,
3861 aPeriod, anAdjustPar, anoffset);
3863 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
3864 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
3865 anotherPar += anoffset;
3866 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3867 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
3868 Standard_Real nU1, nV1;
3871 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3873 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3875 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
3876 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
3877 bComputeLineEnd = Standard_True;
3878 Standard_Boolean bCheckAngle1 = Standard_False;
3879 Standard_Boolean bCheckAngle2 = Standard_False;
3881 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
3882 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
3884 if(((adist1 - adist2) > Precision::PConfusion()) &&
3885 (adist2 < (aPeriod / 4.))) {
3886 bCheckAngle1 = Standard_True;
3887 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
3889 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3890 aNewP.SetValue((surfit == 0), anewU, anewV);
3891 bCheckAngle1 = Standard_False;
3894 else if(adist1 < (aPeriod / 4.)) {
3895 bCheckAngle2 = Standard_True;
3896 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
3898 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3899 bCheckAngle2 = Standard_False;
3903 if(bCheckAngle1 || bCheckAngle2) {
3904 // assume there are at least two points in line (see "if" above)
3905 Standard_Integer anindexother = aneighbourpointindex;
3907 while((anindexother <= iLast) && (anindexother >= iFirst)) {
3908 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
3909 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
3910 Standard_Real nU2, nV2;
3913 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3915 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3916 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
3918 if(aVecOld.SquareMagnitude() <= (gp::Resolution() * gp::Resolution())) {
3922 Standard_Real anAngle = aNewVec.Angle(aVecOld);
3924 if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
3927 Standard_Real U1, U2, V1, V2;
3928 IntSurf_PntOn2S atmppoint = aNewP;
3929 atmppoint.SetValue((surfit == 0), anewU, anewV);
3930 atmppoint.Parameters(U1, V1, U2, V2);
3931 gp_Pnt P1 = theSurface1->Value(U1, V1);
3932 gp_Pnt P2 = theSurface2->Value(U2, V2);
3933 gp_Pnt P0 = aPoint.Value();
3935 if(P0.IsEqual(P1, aTol) &&
3936 P0.IsEqual(P2, aTol) &&
3937 P1.IsEqual(P2, aTol)) {
3938 bComputeLineEnd = Standard_False;
3939 aNewP.SetValue((surfit == 0), anewU, anewV);
3944 bComputeLineEnd = Standard_False;
3949 } // end while(anindexother...)
3953 else if ( bIsNearBoundary ) {
3954 bComputeLineEnd = Standard_True;
3957 if(bComputeLineEnd) {
3960 Standard_Boolean found = Standard_False;
3962 if ( bIsNearBoundary ) {
3963 // re-compute point near natural boundary or near tangent zone
3964 Standard_Real u1, v1, u2, v2;
3965 aNewP.Parameters( u1, v1, u2, v2 );
3967 anewpoint = gp_Pnt2d( u1, v1 );
3969 anewpoint = gp_Pnt2d( u2, v2 );
3971 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
3972 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3973 Standard_Real nU1, nV1;
3976 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3978 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3979 gp_Pnt2d ap1(nU1, nV1);
3984 // exclude point from a tangent zone
3985 anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3986 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
3987 Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
3989 if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
3990 aPZone, aZoneRadius, aGASurface, ap2) ) {
3992 found = Standard_True;
3995 else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
3996 // re-compute point near boundary if shifted on a period
3997 ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3999 if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
4000 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
4001 found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
4005 aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
4011 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
4012 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
4013 Standard_Real nU1, nV1;
4016 aNeighbourPoint.ParametersOnS1(nU1, nV1);
4018 aNeighbourPoint.ParametersOnS2(nU1, nV1);
4019 gp_Pnt2d ap1(nU1, nV1);
4020 gp_Pnt2d ap2(nU1, nV1);
4021 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
4023 while((aneighbourpointindex2 <= iLast) && (aneighbourpointindex2 >= iFirst)) {
4024 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
4025 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
4026 Standard_Real nU2, nV2;
4029 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
4031 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
4035 if(ap1.SquareDistance(ap2) > (gp::Resolution() * gp::Resolution())) {
4039 found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
4044 Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4045 GeomAPI_ProjectPointOnSurf& aProjector =
4046 (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
4047 Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
4049 Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
4051 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
4052 aProjector.Perform(aP3d);
4054 if(aProjector.IsDone()) {
4055 if(aProjector.LowerDistance() < aCriteria) {
4056 Standard_Real foundU = U, foundV = V;
4057 aProjector.LowerDistanceParameters(foundU, foundV);
4059 //Correction of projected coordinates. Begin
4060 //Note, it may be shifted on a period
4061 Standard_Integer aneindex1 = (j == 0) ? iFirst : iLast;
4062 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
4063 Standard_Real nUn, nVn;
4066 aNeighbourPoint.ParametersOnS2(nUn, nVn);
4068 aNeighbourPoint.ParametersOnS1(nUn, nVn);
4069 gp_Pnt2d aNeighbour2d(nUn, nVn);
4070 gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
4071 foundU = anAdjustedPoint.X();
4072 foundV = anAdjustedPoint.Y();
4074 if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
4075 ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
4076 // attempt to roughly re-compute point
4077 foundU = ( foundU < umin ) ? umin : foundU;
4078 foundU = ( foundU > umax ) ? umax : foundU;
4079 foundV = ( foundV < vmin ) ? vmin : foundV;
4080 foundV = ( foundV > vmax ) ? vmax : foundV;
4082 GeomAPI_ProjectPointOnSurf& aProjector2 =
4083 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
4085 aP3d = aSurfaceOther->Value(foundU, foundV);
4086 aProjector2.Perform(aP3d);
4088 if(aProjector2.IsDone()) {
4089 if(aProjector2.LowerDistance() < aCriteria) {
4090 Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
4091 aProjector2.LowerDistanceParameters(foundU2, foundV2);
4092 anewpoint.SetX(foundU2);
4093 anewpoint.SetY(foundV2);
4097 //Correction of projected coordinates. End
4100 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
4102 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
4108 aSeqOfPntOn2S->Add(aNewP);
4109 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
4111 anArrayOfLineEnds.SetValue(i, aListOfFLIndex);
4113 // Correct wlines.end
4115 // Split wlines.begin
4116 Standard_Integer nbiter;
4119 if (!bAvoidLineConstructor) {
4120 nbiter=theLConstructor.NbParts();
4123 for(j = 1; j <= nbiter; ++j) {
4124 Standard_Real fprm, lprm;
4125 Standard_Integer ifprm, ilprm;
4127 if(bAvoidLineConstructor) {
4129 ilprm = theWLine->NbPnts();
4132 theLConstructor.Part(j, fprm, lprm);
4133 ifprm = (Standard_Integer)fprm;
4134 ilprm = (Standard_Integer)lprm;
4137 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
4139 for(i = 1; i <= nblines; i++) {
4140 if(anArrayOfLineType.Value(i) != 0) {
4143 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
4144 const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
4145 Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
4146 Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
4148 if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
4149 bhasfirstpoint = (i != 1);
4152 if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
4153 bhaslastpoint = (i != nblines);
4156 Standard_Integer iFirst = aListOfIndex.First();
4157 Standard_Integer iLast = aListOfIndex.Last();
4158 Standard_Boolean bIsFirstInside = ((ifprm >= iFirst) && (ifprm <= iLast));
4159 Standard_Boolean bIsLastInside = ((ilprm >= iFirst) && (ilprm <= iLast));
4161 if(!bIsFirstInside && !bIsLastInside) {
4162 if((ifprm < iFirst) && (ilprm > iLast)) {
4163 // append whole line, and boundaries if neccesary
4164 if(bhasfirstpoint) {
4165 pit = aListOfFLIndex.First();
4166 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4169 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4171 for(; anIt.More(); anIt.Next()) {
4173 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4178 pit = aListOfFLIndex.Last();
4179 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4183 // check end of split line (end is almost always)
4184 Standard_Integer aneighbour = i + 1;
4185 Standard_Boolean bIsEndOfLine = Standard_True;
4187 if(aneighbour <= nblines) {
4188 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4190 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4191 (aListOfNeighbourIndex.IsEmpty())) {
4192 bIsEndOfLine = Standard_False;
4197 if(aLineOn2S->NbPoints() > 1) {
4198 Handle(IntPatch_WLine) aNewWLine =
4199 new IntPatch_WLine(aLineOn2S, Standard_False);
4200 theNewLines.Append(aNewWLine);
4202 aLineOn2S = new IntSurf_LineOn2S();
4207 // end if(!bIsFirstInside && !bIsLastInside)
4209 if(bIsFirstInside && bIsLastInside) {
4210 // append inside points between ifprm and ilprm
4211 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4213 for(; anIt.More(); anIt.Next()) {
4215 if((pit < ifprm) || (pit > ilprm))
4217 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4223 if(bIsFirstInside) {
4224 // append points from ifprm to last point + boundary point
4225 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4227 for(; anIt.More(); anIt.Next()) {
4231 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4236 pit = aListOfFLIndex.Last();
4237 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4240 // check end of split line (end is almost always)
4241 Standard_Integer aneighbour = i + 1;
4242 Standard_Boolean bIsEndOfLine = Standard_True;
4244 if(aneighbour <= nblines) {
4245 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4247 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4248 (aListOfNeighbourIndex.IsEmpty())) {
4249 bIsEndOfLine = Standard_False;
4254 if(aLineOn2S->NbPoints() > 1) {
4255 Handle(IntPatch_WLine) aNewWLine =
4256 new IntPatch_WLine(aLineOn2S, Standard_False);
4257 theNewLines.Append(aNewWLine);
4259 aLineOn2S = new IntSurf_LineOn2S();
4262 // end if(bIsFirstInside)
4265 // append points from first boundary point to ilprm
4266 if(bhasfirstpoint) {
4267 pit = aListOfFLIndex.First();
4268 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4271 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4273 for(; anIt.More(); anIt.Next()) {
4277 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4281 //end if(bIsLastInside)
4285 if(aLineOn2S->NbPoints() > 1) {
4286 Handle(IntPatch_WLine) aNewWLine =
4287 new IntPatch_WLine(aLineOn2S, Standard_False);
4288 theNewLines.Append(aNewWLine);
4293 return Standard_True;
4296 // ------------------------------------------------------------------------------------------------
4297 // static function: ParameterOutOfBoundary
4298 // purpose: Computes a new parameter for given curve. The corresponding 2d points
4299 // does not lay on any boundary of given faces
4300 // ------------------------------------------------------------------------------------------------
4301 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
4302 const Handle(Geom_Curve)& theCurve,
4303 const TopoDS_Face& theFace1,
4304 const TopoDS_Face& theFace2,
4305 const Standard_Real theOtherParameter,
4306 const Standard_Boolean bIncreasePar,
4307 Standard_Real& theNewParameter,
4308 const Handle(IntTools_Context)& aContext)
4310 Standard_Boolean bIsComputed = Standard_False;
4311 theNewParameter = theParameter;
4313 Standard_Real acurpar = theParameter;
4314 TopAbs_State aState = TopAbs_ON;
4315 Standard_Integer iter = 0;
4316 Standard_Real asumtol = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4317 Standard_Real adelta = asumtol * 0.1;
4318 adelta = (adelta < Precision::Confusion()) ? Precision::Confusion() : adelta;
4319 Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(theFace1);
4320 Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(theFace2);
4322 Standard_Real u1, u2, v1, v2;
4324 GeomAPI_ProjectPointOnSurf aPrj1;
4325 aSurf1->Bounds(u1, u2, v1, v2);
4326 aPrj1.Init(aSurf1, u1, u2, v1, v2);
4328 GeomAPI_ProjectPointOnSurf aPrj2;
4329 aSurf2->Bounds(u1, u2, v1, v2);
4330 aPrj2.Init(aSurf2, u1, u2, v1, v2);
4332 while(aState == TopAbs_ON) {
4337 gp_Pnt aPCurrent = theCurve->Value(acurpar);
4338 aPrj1.Perform(aPCurrent);
4339 Standard_Real U=0., V=0.;
4341 if(aPrj1.IsDone()) {
4342 aPrj1.LowerDistanceParameters(U, V);
4343 aState = aContext->StatePointFace(theFace1, gp_Pnt2d(U, V));
4346 if(aState != TopAbs_ON) {
4347 aPrj2.Perform(aPCurrent);
4349 if(aPrj2.IsDone()) {
4350 aPrj2.LowerDistanceParameters(U, V);
4351 aState = aContext->StatePointFace(theFace2, gp_Pnt2d(U, V));
4362 theNewParameter = acurpar;
4363 bIsComputed = Standard_True;
4366 if(acurpar >= theOtherParameter)
4367 theNewParameter = theOtherParameter;
4370 if(acurpar <= theOtherParameter)
4371 theNewParameter = theOtherParameter;
4377 //=======================================================================
4378 //function : IsCurveValid
4380 //=======================================================================
4381 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve)
4383 if(thePCurve.IsNull())
4384 return Standard_False;
4386 Standard_Real tolint = 1.e-10;
4387 Geom2dAdaptor_Curve PCA;
4388 IntRes2d_Domain PCD;
4389 Geom2dInt_GInter PCI;
4391 Standard_Real pf = 0., pl = 0.;
4392 gp_Pnt2d pntf, pntl;
4394 if(!thePCurve->IsClosed() && !thePCurve->IsPeriodic()) {
4395 pf = thePCurve->FirstParameter();
4396 pl = thePCurve->LastParameter();
4397 pntf = thePCurve->Value(pf);
4398 pntl = thePCurve->Value(pl);
4399 PCA.Load(thePCurve);
4400 if(!PCA.IsPeriodic()) {
4401 if(PCA.FirstParameter() > pf) pf = PCA.FirstParameter();
4402 if(PCA.LastParameter() < pl) pl = PCA.LastParameter();
4404 PCD.SetValues(pntf,pf,tolint,pntl,pl,tolint);
4405 PCI.Perform(PCA,PCD,tolint,tolint);
4407 if(PCI.NbPoints() > 0) {
4408 return Standard_False;
4412 return Standard_True;
4415 //=======================================================================
4416 //static function : ApproxWithPCurves
4417 //purpose : for bug 20964 only
4418 //=======================================================================
4419 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
4420 const gp_Sphere& theSph)
4422 Standard_Boolean bRes = Standard_True;
4423 Standard_Real R1 = theCyl.Radius(), R2 = theSph.Radius();
4426 Standard_Real aD2, aRc2, aEps;
4432 const gp_Ax3& aAx3Sph=theSph.Position();
4433 const gp_Pnt& aLocSph=aAx3Sph.Location();
4434 const gp_Dir& aDirSph=aAx3Sph.Direction();
4436 const gp_Ax1& aAx1Cyl=theCyl.Axis();
4437 gp_Lin aLinCyl(aAx1Cyl);
4439 aApexSph.SetXYZ(aLocSph.XYZ()+R2*aDirSph.XYZ());
4440 aD2=aLinCyl.SquareDistance(aApexSph);
4441 if (fabs(aD2-aRc2)<aEps) {
4445 aApexSph.SetXYZ(aLocSph.XYZ()-R2*aDirSph.XYZ());
4446 aD2=aLinCyl.SquareDistance(aApexSph);
4447 if (fabs(aD2-aRc2)<aEps) {
4456 gp_Lin anCylAx(theCyl.Axis());
4458 Standard_Real aDist = anCylAx.Distance(theSph.Location());
4459 Standard_Real aDRel = Abs(aDist - R1)/R2;
4461 if(aDRel > .2) return bRes;
4463 Standard_Real par = ElCLib::Parameter(anCylAx, theSph.Location());
4464 gp_Pnt aP = ElCLib::Value(par, anCylAx);
4465 gp_Vec aV(aP, theSph.Location());
4467 Standard_Real dd = aV.Dot(theSph.Position().XDirection());
4469 if(aDist < R1 && dd > 0.) return Standard_False;
4470 if(aDist > R1 && dd < 0.) return Standard_False;
4475 //=======================================================================
4476 //function : PerformPlanes
4478 //=======================================================================
4479 void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
4480 const Handle(GeomAdaptor_HSurface)& theS2,
4481 const Standard_Real TolAng,
4482 const Standard_Real TolTang,
4483 const Standard_Boolean theApprox1,
4484 const Standard_Boolean theApprox2,
4485 IntTools_SequenceOfCurves& theSeqOfCurve,
4486 Standard_Boolean& theTangentFaces)
4489 gp_Pln aPln1 = theS1->Surface().Plane();
4490 gp_Pln aPln2 = theS2->Surface().Plane();
4492 IntAna_QuadQuadGeo aPlnInter(aPln1, aPln2, TolAng, TolTang);
4494 if(!aPlnInter.IsDone()) {
4495 theTangentFaces = Standard_False;
4499 IntAna_ResultType aResType = aPlnInter.TypeInter();
4501 if(aResType == IntAna_Same) {
4502 theTangentFaces = Standard_True;
4506 theTangentFaces = Standard_False;
4508 if(aResType == IntAna_Empty) {
4512 gp_Lin aLin = aPlnInter.Line(1);
4514 ProjLib_Plane aProj;
4517 aProj.Project(aLin);
4518 gp_Lin2d aLin2d1 = aProj.Line();
4521 aProj.Project(aLin);
4522 gp_Lin2d aLin2d2 = aProj.Line();
4524 //classify line2d1 relatively first plane
4525 Standard_Real P11, P12;
4526 Standard_Boolean IsCrossed = ClassifyLin2d(theS1, aLin2d1, TolTang, P11, P12);
4527 if(!IsCrossed) return;
4528 //classify line2d2 relatively second plane
4529 Standard_Real P21, P22;
4530 IsCrossed = ClassifyLin2d(theS2, aLin2d2, TolTang, P21, P22);
4531 if(!IsCrossed) return;
4533 //Analysis of parametric intervals: must have common part
4535 if(P21 >= P12) return;
4536 if(P22 <= P11) return;
4538 Standard_Real pmin, pmax;
4539 pmin = Max(P11, P21);
4540 pmax = Min(P12, P22);
4542 if(pmax - pmin <= TolTang) return;
4544 Handle(Geom_Line) aGLin = new Geom_Line(aLin);
4546 IntTools_Curve aCurve;
4547 Handle(Geom_TrimmedCurve) aGTLin = new Geom_TrimmedCurve(aGLin, pmin, pmax);
4549 aCurve.SetCurve(aGTLin);
4552 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d1);
4553 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4556 Handle(Geom2d_Curve) H1;
4557 aCurve.SetFirstCurve2d(H1);
4560 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d2);
4561 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4564 Handle(Geom2d_Curve) H1;
4565 aCurve.SetFirstCurve2d(H1);
4568 theSeqOfCurve.Append(aCurve);
4572 //=======================================================================
4573 //function : ClassifyLin2d
4575 //=======================================================================
4576 static inline Standard_Boolean INTER(const Standard_Real d1,
4577 const Standard_Real d2,
4578 const Standard_Real tol)
4580 return (d1 > tol && d2 < -tol) ||
4581 (d1 < -tol && d2 > tol) ||
4582 ((d1 <= tol && d1 >= -tol) && (d2 > tol || d2 < -tol)) ||
4583 ((d2 <= tol && d2 >= -tol) && (d1 > tol || d1 < -tol));
4585 static inline Standard_Boolean COINC(const Standard_Real d1,
4586 const Standard_Real d2,
4587 const Standard_Real tol)
4589 return (d1 <= tol && d1 >= -tol) && (d2 <= tol && d2 >= -tol);
4591 Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
4592 const gp_Lin2d& theLin2d,
4593 const Standard_Real theTol,
4594 Standard_Real& theP1,
4595 Standard_Real& theP2)
4598 Standard_Real xmin, xmax, ymin, ymax, d1, d2, A, B, C;
4599 Standard_Real par[2];
4600 Standard_Integer nbi = 0;
4602 xmin = theS->Surface().FirstUParameter();
4603 xmax = theS->Surface().LastUParameter();
4604 ymin = theS->Surface().FirstVParameter();
4605 ymax = theS->Surface().LastVParameter();
4607 theLin2d.Coefficients(A, B, C);
4609 //xmin, ymin <-> xmin, ymax
4610 d1 = A*xmin + B*ymin + C;
4611 d2 = A*xmin + B*ymax + C;
4613 if(INTER(d1, d2, theTol)) {
4614 //Intersection with boundary
4615 Standard_Real y = -(C + A*xmin)/B;
4616 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, y));
4619 else if (COINC(d1, d2, theTol)) {
4620 //Coincidence with boundary
4621 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4622 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4628 if(fabs(par[0]-par[1]) > theTol) {
4629 theP1 = Min(par[0], par[1]);
4630 theP2 = Max(par[0], par[1]);
4631 return Standard_True;
4633 else return Standard_False;
4637 //xmin, ymax <-> xmax, ymax
4639 d2 = A*xmax + B*ymax + C;
4641 if(d1 > theTol || d1 < -theTol) {//to avoid checking of
4642 //coincidence with the same point
4643 if(INTER(d1, d2, theTol)) {
4644 Standard_Real x = -(C + B*ymax)/A;
4645 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymax));
4648 else if (COINC(d1, d2, theTol)) {
4649 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4650 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4657 if(fabs(par[0]-par[1]) > theTol) {
4658 theP1 = Min(par[0], par[1]);
4659 theP2 = Max(par[0], par[1]);
4660 return Standard_True;
4662 else return Standard_False;
4666 //xmax, ymax <-> xmax, ymin
4668 d2 = A*xmax + B*ymin + C;
4670 if(d1 > theTol || d1 < -theTol) {
4671 if(INTER(d1, d2, theTol)) {
4672 Standard_Real y = -(C + A*xmax)/B;
4673 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, y));
4676 else if (COINC(d1, d2, theTol)) {
4677 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4678 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4684 if(fabs(par[0]-par[1]) > theTol) {
4685 theP1 = Min(par[0], par[1]);
4686 theP2 = Max(par[0], par[1]);
4687 return Standard_True;
4689 else return Standard_False;
4692 //xmax, ymin <-> xmin, ymin
4694 d2 = A*xmin + B*ymin + C;
4696 if(d1 > theTol || d1 < -theTol) {
4697 if(INTER(d1, d2, theTol)) {
4698 Standard_Real x = -(C + B*ymin)/A;
4699 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymin));
4702 else if (COINC(d1, d2, theTol)) {
4703 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4704 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4710 if(fabs(par[0]-par[1]) > theTol) {
4711 theP1 = Min(par[0], par[1]);
4712 theP2 = Max(par[0], par[1]);
4713 return Standard_True;
4715 else return Standard_False;
4718 return Standard_False;
4722 //=======================================================================
4723 //function : ApproxParameters
4725 //=======================================================================
4726 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
4727 const Handle(GeomAdaptor_HSurface)& aHS2,
4728 Standard_Integer& iDegMin,
4729 Standard_Integer& iDegMax,
4730 Standard_Integer& iNbIter)
4733 GeomAbs_SurfaceType aTS1, aTS2;
4740 aTS1=aHS1->Surface().GetType();
4741 aTS2=aHS2->Surface().GetType();
4744 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4745 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4746 Standard_Real aRC, aRT, dR, aPC;
4747 gp_Cylinder aCylinder;
4750 aPC=Precision::Confusion();
4752 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4753 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4755 aRC=aCylinder.Radius();
4756 aRT=aTorus.MinorRadius();
4766 if (aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Cylinder) {
4770 //=======================================================================
4771 //function : Tolerances
4773 //=======================================================================
4774 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
4775 const Handle(GeomAdaptor_HSurface)& aHS2,
4776 Standard_Real& aTolTang)
4778 GeomAbs_SurfaceType aTS1, aTS2;
4780 aTS1=aHS1->Surface().GetType();
4781 aTS2=aHS2->Surface().GetType();
4784 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4785 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4786 Standard_Real aRC, aRT, dR, aPC;
4787 gp_Cylinder aCylinder;
4790 aPC=Precision::Confusion();
4792 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4793 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4795 aRC=aCylinder.Radius();
4796 aRT=aTorus.MinorRadius();
4803 aTolTang=0.1*aTolTang;
4807 //=======================================================================
4808 //function : SortTypes
4810 //=======================================================================
4811 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
4812 const GeomAbs_SurfaceType aType2)
4814 Standard_Boolean bRet;
4815 Standard_Integer aI1, aI2;
4817 bRet=Standard_False;
4819 aI1=IndexType(aType1);
4820 aI2=IndexType(aType2);
4826 //=======================================================================
4827 //function : IndexType
4829 //=======================================================================
4830 Standard_Integer IndexType(const GeomAbs_SurfaceType aType)
4832 Standard_Integer aIndex;
4836 if (aType==GeomAbs_Plane) {
4839 else if (aType==GeomAbs_Cylinder) {
4842 else if (aType==GeomAbs_Cone) {
4845 else if (aType==GeomAbs_Sphere) {
4848 else if (aType==GeomAbs_Torus) {
4851 else if (aType==GeomAbs_BezierSurface) {
4854 else if (aType==GeomAbs_BSplineSurface) {
4857 else if (aType==GeomAbs_SurfaceOfRevolution) {
4860 else if (aType==GeomAbs_SurfaceOfExtrusion) {
4863 else if (aType==GeomAbs_OffsetSurface) {
4866 else if (aType==GeomAbs_OtherSurface) {
4871 #ifdef OCCT_DEBUG_DUMPWLINE
4872 //=======================================================================
4873 //function : DumpWLine
4875 //=======================================================================
4876 void DumpWLine(const Handle(IntPatch_WLine)& aWLine)
4878 Standard_Integer i, aNbPnts;
4879 Standard_Real aX, aY, aZ, aU1, aV1, aU2, aV2;
4881 printf(" *WLine\n");
4882 aNbPnts=aWLine->NbPnts();
4883 for (i=1; i<=aNbPnts; ++i) {
4884 const IntSurf_PntOn2S aPntOn2S=aWLine->Point(i);
4885 const gp_Pnt& aP3D=aPntOn2S.Value();
4886 aP3D.Coord(aX, aY, aZ);
4887 aPntOn2S.Parameters(aU1, aV1, aU2, aV2);
4889 printf("point p_%d %lf %lf %lf\n", i, aX, aY, aZ);
4890 //printf("point p_%d %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf\n",
4891 // i, aX, aY, aZ, aU1, aV1, aU2, aV2);
4895 //=======================================================================
4896 //function : RefineVector
4898 //=======================================================================
4899 void RefineVector(gp_Vec2d& aV2D)
4901 Standard_Integer k,m;
4902 Standard_Real aC[2], aEps, aR1, aR2, aNum;
4908 aV2D.Coord(aC[0], aC[1]);
4910 for (k=0; k<2; ++k) {
4913 if (aNum>aR1 && aNum<aR2) {
4924 aV2D.SetCoord(aC[0], aC[1]);
4926 //=======================================================================
4927 //function : FindMaxSquareDistance
4929 //=======================================================================
4930 Standard_Real FindMaxSquareDistance (const Standard_Real aT1,
4931 const Standard_Real aT2,
4932 const Standard_Real aEps,
4933 const Handle(Geom_Curve)& aC3D,
4934 const Handle(Geom2d_Curve)& aC2D1,
4935 const Handle(Geom2d_Curve)& aC2D2,
4936 const Handle(GeomAdaptor_HSurface)& myHS1,
4937 const Handle(GeomAdaptor_HSurface)& myHS2,
4938 const TopoDS_Face& myFace1,
4939 const TopoDS_Face& myFace2,
4940 const Handle(IntTools_Context)& myContext)
4942 Standard_Real aA, aB, aCf, aX1, aX2, aF1, aF2, aX, aF;
4944 aCf=1.6180339887498948482045868343656;// =0.5*(1.+sqrt(5.));
4948 aF1=MaxSquareDistance(aX1,
4949 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4951 aF2=MaxSquareDistance(aX2,
4952 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4956 if (fabs(aA-aB)<aEps) {
4958 aF=MaxSquareDistance(aX,
4959 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4967 aF2=MaxSquareDistance(aX2,
4968 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4976 aF1=MaxSquareDistance(aX1,
4977 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4982 //=======================================================================
4983 //function : MaxSquareDistance
4985 //=======================================================================
4986 Standard_Real MaxSquareDistance (const Standard_Real aT,
4987 const Handle(Geom_Curve)& aC3D,
4988 const Handle(Geom2d_Curve)& aC2D1,
4989 const Handle(Geom2d_Curve)& aC2D2,
4990 const Handle(GeomAdaptor_HSurface) myHS1,
4991 const Handle(GeomAdaptor_HSurface) myHS2,
4992 const TopoDS_Face& aF1,
4993 const TopoDS_Face& aF2,
4994 const Handle(IntTools_Context)& aCtx)
4996 Standard_Boolean bIsDone;
4998 Standard_Real aU, aV, aD2Max, aD2;
5005 if (aC3D.IsNull()) {
5009 for (i=0; i<2; ++i) {
5010 const Handle(GeomAdaptor_HSurface)& aGHS=(!i) ? myHS1 : myHS2;
5011 const TopoDS_Face &aF=(!i) ? aF1 : aF2;
5012 const Handle(Geom2d_Curve)& aC2D=(!i) ? aC2D1 : aC2D2;
5014 if (!aC2D.IsNull()) {
5017 aGHS->D0(aU, aV, aPS);
5018 aD2=aP.SquareDistance(aPS);
5024 GeomAPI_ProjectPointOnSurf& aProjector=aCtx->ProjPS(aF);
5026 aProjector.Perform(aP);
5027 bIsDone=aProjector.IsDone();
5029 aProjector.LowerDistanceParameters(aU, aV);
5030 aGHS->D0(aU, aV, aPS);
5031 aD2=aP.SquareDistance(aPS);
5041 //=======================================================================
5042 //function : CheckPCurve
5043 //purpose : Checks if points of the pcurve are out of the face bounds.
5044 //=======================================================================
5045 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
5046 const TopoDS_Face& aFace)
5048 const Standard_Integer NPoints = 23;
5050 Standard_Real umin,umax,vmin,vmax;
5052 BRepTools::UVBounds(aFace, umin, umax, vmin, vmax);
5053 Standard_Real tolU = Max ((umax-umin)*0.01, Precision::Confusion());
5054 Standard_Real tolV = Max ((vmax-vmin)*0.01, Precision::Confusion());
5055 Standard_Real fp = aPC->FirstParameter();
5056 Standard_Real lp = aPC->LastParameter();
5059 // adjust domain for periodic surfaces
5060 TopLoc_Location aLoc;
5061 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
5062 if (aSurf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
5063 aSurf = (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf))->BasisSurface();
5065 gp_Pnt2d pnt = aPC->Value((fp+lp)/2);
5069 if (aSurf->IsUPeriodic()) {
5070 Standard_Real aPer = aSurf->UPeriod();
5071 Standard_Integer nshift = (Standard_Integer) ((u-umin)/aPer);
5072 if (u < umin+aPer*nshift) nshift--;
5073 umin += aPer*nshift;
5074 umax += aPer*nshift;
5076 if (aSurf->IsVPeriodic()) {
5077 Standard_Real aPer = aSurf->VPeriod();
5078 Standard_Integer nshift = (Standard_Integer) ((v-vmin)/aPer);
5079 if (v < vmin+aPer*nshift) nshift--;
5080 vmin += aPer*nshift;
5081 vmax += aPer*nshift;
5084 //--------------------------------------------------------
5085 Standard_Boolean bRet;
5086 Standard_Integer j, aNbIntervals;
5087 Standard_Real aT, dT;
5090 Geom2dAdaptor_Curve aGAC(aPC);
5091 aNbIntervals=aGAC.NbIntervals(GeomAbs_CN);
5093 TColStd_Array1OfReal aTI(1, aNbIntervals+1);
5094 aGAC.Intervals(aTI,GeomAbs_CN);
5096 bRet=Standard_False;
5098 aT=aGAC.FirstParameter();
5099 for (j=1; j<=aNbIntervals; ++j) {
5100 dT=(aTI(j+1)-aTI(j))/NPoints;
5102 for (i=1; i<NPoints; i++) {
5106 if (umin-u > tolU || u-umax > tolU ||
5107 vmin-v > tolV || v-vmax > tolV) {