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
8 // under the terms of the GNU Lesser General Public 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 <BOPInt_Context.hxx>
115 #include <IntSurf_ListIteratorOfListOfPntOn2S.hxx>
118 void RefineVector(gp_Vec2d& aV2D);
121 void DumpWLine(const Handle(IntPatch_WLine)& aWLine);
125 void TolR3d(const TopoDS_Face& ,
129 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)&,
130 const Standard_Integer,
131 const Standard_Integer);
134 void Parameters(const Handle(GeomAdaptor_HSurface)&,
135 const Handle(GeomAdaptor_HSurface)&,
143 void BuildPCurves (Standard_Real f,Standard_Real l,Standard_Real& Tol,
144 const Handle (Geom_Surface)& S,
145 const Handle (Geom_Curve)& C,
146 Handle (Geom2d_Curve)& C2d);
149 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
150 const Standard_Real theTolerance,
151 Standard_Real& theumin,
152 Standard_Real& theumax,
153 Standard_Real& thevmin,
154 Standard_Real& thevmax);
156 Standard_Boolean NotUseSurfacesForApprox
157 (const TopoDS_Face& aF1,
158 const TopoDS_Face& aF2,
159 const Handle(IntPatch_WLine)& WL,
160 const Standard_Integer ifprm,
161 const Standard_Integer ilprm);
164 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine);
167 Standard_Real AdjustPeriodic(const Standard_Real theParameter,
168 const Standard_Real parmin,
169 const Standard_Real parmax,
170 const Standard_Real thePeriod,
171 Standard_Real& theOffset);
174 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
175 const Standard_Integer ideb,
176 const Standard_Integer ifin,
177 const Standard_Boolean onFirst);
180 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
181 const Handle(GeomAdaptor_HSurface)& theSurface1,
182 const Handle(GeomAdaptor_HSurface)& theSurface2,
183 const TopoDS_Face& theFace1,
184 const TopoDS_Face& theFace2,
185 const IntTools_LineConstructor& theLConstructor,
186 const Standard_Boolean theAvoidLConstructor,
187 IntPatch_SequenceOfLine& theNewLines,
188 Standard_Real& theReachedTol3d,
189 const Handle(BOPInt_Context)& );
192 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
193 const Handle(Geom_Curve)& theCurve,
194 const TopoDS_Face& theFace1,
195 const TopoDS_Face& theFace2,
196 const Standard_Real theOtherParameter,
197 const Standard_Boolean bIncreasePar,
198 Standard_Real& theNewParameter,
199 const Handle(BOPInt_Context)& );
202 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve);
205 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
206 const Standard_Real theFirstBoundary,
207 const Standard_Real theSecondBoundary,
208 const Standard_Real theResolution,
209 Standard_Boolean& IsOnFirstBoundary);
211 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
212 const gp_Pnt2d& theLastPoint,
213 const Standard_Real theUmin,
214 const Standard_Real theUmax,
215 const Standard_Real theVmin,
216 const Standard_Real theVmax,
217 gp_Pnt2d& theNewPoint);
221 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
222 const Handle(GeomAdaptor_HSurface)& theSurface2,
223 const TopoDS_Face& theFace1,
224 const TopoDS_Face& theFace2,
225 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
226 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
227 Handle(TColStd_HArray1OfReal)& theResultRadius,
228 const Handle(BOPInt_Context)& );
231 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
232 const gp_Pnt2d& theLastPoint,
233 const Standard_Real theUmin,
234 const Standard_Real theUmax,
235 const Standard_Real theVmin,
236 const Standard_Real theVmax,
237 const gp_Pnt2d& theTanZoneCenter,
238 const Standard_Real theZoneRadius,
239 Handle(GeomAdaptor_HSurface) theGASurface,
240 gp_Pnt2d& theNewPoint);
243 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
244 const gp_Pnt2d& theTanZoneCenter,
245 const Standard_Real theZoneRadius,
246 Handle(GeomAdaptor_HSurface) theGASurface);
249 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
250 const gp_Pnt2d& theOriginalPoint,
251 Handle(GeomAdaptor_HSurface) theGASurface);
253 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
254 const gp_Sphere& theSph);
256 static void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
257 const Handle(GeomAdaptor_HSurface)& theS2,
258 const Standard_Real TolAng,
259 const Standard_Real TolTang,
260 const Standard_Boolean theApprox1,
261 const Standard_Boolean theApprox2,
262 IntTools_SequenceOfCurves& theSeqOfCurve,
263 Standard_Boolean& theTangentFaces);
265 static Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
266 const gp_Lin2d& theLin2d,
267 const Standard_Real theTol,
268 Standard_Real& theP1,
269 Standard_Real& theP2);
272 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
273 const Handle(GeomAdaptor_HSurface)& aHS2,
274 Standard_Integer& iDegMin,
275 Standard_Integer& iNbIter,
276 Standard_Integer& iDegMax);
279 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
280 const Handle(GeomAdaptor_HSurface)& aHS2,
281 Standard_Real& aTolTang);
284 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
285 const GeomAbs_SurfaceType aType2);
287 Standard_Integer IndexType(const GeomAbs_SurfaceType aType);
291 Standard_Real MaxSquareDistance (const Standard_Real aT,
292 const Handle(Geom_Curve)& aC3D,
293 const Handle(Geom2d_Curve)& aC2D1,
294 const Handle(Geom2d_Curve)& aC2D2,
295 const Handle(GeomAdaptor_HSurface) myHS1,
296 const Handle(GeomAdaptor_HSurface) myHS2,
297 const TopoDS_Face& aF1,
298 const TopoDS_Face& aF2,
299 const Handle(BOPInt_Context)& aCtx);
302 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
303 const TopoDS_Face& aFace);
307 Standard_Real FindMaxSquareDistance (const Standard_Real aA,
308 const Standard_Real aB,
309 const Standard_Real aEps,
310 const Handle(Geom_Curve)& aC3D,
311 const Handle(Geom2d_Curve)& aC2D1,
312 const Handle(Geom2d_Curve)& aC2D2,
313 const Handle(GeomAdaptor_HSurface)& myHS1,
314 const Handle(GeomAdaptor_HSurface)& myHS2,
315 const TopoDS_Face& aF1,
316 const TopoDS_Face& aF2,
317 const Handle(BOPInt_Context)& aCtx);
319 //=======================================================================
322 //=======================================================================
323 IntTools_FaceFace::IntTools_FaceFace()
325 myIsDone=Standard_False;
326 myTangentFaces=Standard_False;
328 myHS1 = new GeomAdaptor_HSurface ();
329 myHS2 = new GeomAdaptor_HSurface ();
332 SetParameters(Standard_True, Standard_True, Standard_True, 1.e-07);
335 //=======================================================================
336 //function : SetContext
338 //=======================================================================
339 void IntTools_FaceFace::SetContext(const Handle(BOPInt_Context)& aContext)
343 //=======================================================================
346 //=======================================================================
347 const Handle(BOPInt_Context)& IntTools_FaceFace::Context()const
351 //=======================================================================
354 //=======================================================================
355 const TopoDS_Face& IntTools_FaceFace::Face1() const
359 //=======================================================================
362 //=======================================================================
363 const TopoDS_Face& IntTools_FaceFace::Face2() const
367 //=======================================================================
368 //function : TangentFaces
370 //=======================================================================
371 Standard_Boolean IntTools_FaceFace::TangentFaces() const
373 return myTangentFaces;
375 //=======================================================================
378 //=======================================================================
379 const IntTools_SequenceOfPntOn2Faces& IntTools_FaceFace::Points() const
383 //=======================================================================
386 //=======================================================================
387 Standard_Boolean IntTools_FaceFace::IsDone() const
391 //=======================================================================
392 //function : TolReached3d
394 //=======================================================================
395 Standard_Real IntTools_FaceFace::TolReached3d() const
397 return myTolReached3d;
399 //=======================================================================
401 //purpose : return lines of intersection
402 //=======================================================================
403 const IntTools_SequenceOfCurves& IntTools_FaceFace::Lines() const
405 StdFail_NotDone_Raise_if
407 "IntTools_FaceFace::Lines() => myIntersector NOT DONE");
410 //=======================================================================
411 //function : TolReached2d
413 //=======================================================================
414 Standard_Real IntTools_FaceFace::TolReached2d() const
416 return myTolReached2d;
418 // =======================================================================
419 // function: SetParameters
421 // =======================================================================
422 void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d,
423 const Standard_Boolean ToApproxC2dOnS1,
424 const Standard_Boolean ToApproxC2dOnS2,
425 const Standard_Real ApproximationTolerance)
427 myApprox = ToApproxC3d;
428 myApprox1 = ToApproxC2dOnS1;
429 myApprox2 = ToApproxC2dOnS2;
430 myTolApprox = ApproximationTolerance;
432 //=======================================================================
435 //=======================================================================
436 void IntTools_FaceFace::SetList(IntSurf_ListOfPntOn2S& aListOfPnts)
438 myListOfPnts = aListOfPnts;
442 static Standard_Boolean isTreatAnalityc(const TopoDS_Face& theF1,
443 const TopoDS_Face& theF2)
445 const Standard_Real Tolang = 1.e-8;
446 const Standard_Real aTolF1=BRep_Tool::Tolerance(theF1);
447 const Standard_Real aTolF2=BRep_Tool::Tolerance(theF2);
448 const Standard_Real aTolSum = aTolF1 + aTolF2;
449 Standard_Real aHigh = 0.0;
451 const BRepAdaptor_Surface aBAS1(theF1), aBAS2(theF2);
452 const GeomAbs_SurfaceType aType1=aBAS1.GetType();
453 const GeomAbs_SurfaceType aType2=aBAS2.GetType();
457 if(aType1 == GeomAbs_Plane)
461 else if(aType2 == GeomAbs_Plane)
467 return Standard_True;
470 if(aType1 == GeomAbs_Cylinder)
472 aS2=aBAS1.Cylinder();
473 const Standard_Real VMin = aBAS1.FirstVParameter();
474 const Standard_Real VMax = aBAS1.LastVParameter();
476 if( Precision::IsNegativeInfinite(VMin) ||
477 Precision::IsPositiveInfinite(VMax))
478 return Standard_True;
482 else if(aType2 == GeomAbs_Cylinder)
484 aS2=aBAS2.Cylinder();
486 const Standard_Real VMin = aBAS2.FirstVParameter();
487 const Standard_Real VMax = aBAS2.LastVParameter();
489 if( Precision::IsNegativeInfinite(VMin) ||
490 Precision::IsPositiveInfinite(VMax))
491 return Standard_True;
497 return Standard_True;
500 IntAna_QuadQuadGeo inter;
501 inter.Perform(aS1,aS2,Tolang,aTolSum, aHigh);
502 if(inter.TypeInter() == IntAna_Ellipse)
504 const gp_Elips anEl = inter.Ellipse(1);
505 const Standard_Real aMajorR = anEl.MajorRadius();
506 const Standard_Real aMinorR = anEl.MinorRadius();
508 return (aMajorR < 100000.0 * aMinorR);
512 return inter.IsDone();
518 //=======================================================================
520 //purpose : intersect surfaces of the faces
521 //=======================================================================
522 void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
523 const TopoDS_Face& aF2)
525 Standard_Boolean RestrictLine = Standard_False, hasCone = Standard_False;
527 if (myContext.IsNull()) {
528 myContext=new BOPInt_Context;
531 mySeqOfCurve.Clear();
534 myIsDone = Standard_False;
540 const BRepAdaptor_Surface aBAS1(myFace1, Standard_False);
541 const BRepAdaptor_Surface aBAS2(myFace2, Standard_False);
542 GeomAbs_SurfaceType aType1=aBAS1.GetType();
543 GeomAbs_SurfaceType aType2=aBAS2.GetType();
545 const Standard_Boolean bReverse=SortTypes(aType1, aType2);
550 aType1=aBAS2.GetType();
551 aType2=aBAS1.GetType();
553 if (myListOfPnts.Extent())
555 Standard_Real aU1,aV1,aU2,aV2;
556 IntSurf_ListIteratorOfListOfPntOn2S aItP2S;
558 aItP2S.Initialize(myListOfPnts);
559 for (; aItP2S.More(); aItP2S.Next())
561 IntSurf_PntOn2S& aP2S=aItP2S.Value();
562 aP2S.Parameters(aU1,aV1,aU2,aV2);
563 aP2S.SetValue(aU2,aV2,aU1,aV1);
569 const Handle(Geom_Surface) S1=BRep_Tool::Surface(myFace1);
570 const Handle(Geom_Surface) S2=BRep_Tool::Surface(myFace2);
572 const Standard_Real aTolF1=BRep_Tool::Tolerance(myFace1);
573 const Standard_Real aTolF2=BRep_Tool::Tolerance(myFace2);
575 Standard_Real TolArc = aTolF1 + aTolF2;
576 Standard_Real TolTang = TolArc;
578 const Standard_Boolean isFace1Quad = (aType1 == GeomAbs_Cylinder ||
579 aType1 == GeomAbs_Cone ||
580 aType1 == GeomAbs_Torus);
582 const Standard_Boolean isFace2Quad = (aType2 == GeomAbs_Cylinder ||
583 aType2 == GeomAbs_Cone ||
584 aType2 == GeomAbs_Torus);
586 if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane)
588 Standard_Real umin, umax, vmin, vmax;
589 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
590 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
592 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
593 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
594 Standard_Real TolAng = 1.e-8;
596 PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2,
597 mySeqOfCurve, myTangentFaces);
599 myIsDone = Standard_True;
603 const Standard_Integer NbLinPP = mySeqOfCurve.Length();
606 Standard_Real aTolFMax;
607 myTolReached3d = 1.e-7;
608 aTolFMax=Max(aTolF1, aTolF2);
609 if (aTolFMax>myTolReached3d)
611 myTolReached3d=aTolFMax;
614 myTolReached2d = myTolReached3d;
618 Handle(Geom2d_Curve) aC2D1, aC2D2;
619 const Standard_Integer aNbLin = mySeqOfCurve.Length();
620 for (Standard_Integer i = 1; i <= aNbLin; ++i)
622 IntTools_Curve& aIC=mySeqOfCurve(i);
623 aC2D1=aIC.FirstCurve2d();
624 aC2D2=aIC.SecondCurve2d();
625 aIC.SetFirstCurve2d(aC2D2);
626 aIC.SetSecondCurve2d(aC2D1);
633 }//if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
635 if ((aType1==GeomAbs_Plane) && isFace2Quad)
637 Standard_Real dU, dV;
640 Standard_Real umin, umax, vmin, vmax;
641 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
649 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
651 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
652 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
653 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
655 if( aType2==GeomAbs_Cone ) {
657 hasCone = Standard_True;
660 else if ((aType2==GeomAbs_Plane) && isFace1Quad)
662 Standard_Real dU, dV;
665 Standard_Real umin, umax, vmin, vmax;
666 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
667 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
668 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
670 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
677 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
679 if( aType1==GeomAbs_Cone ) {
681 hasCone = Standard_True;
686 Standard_Real umin, umax, vmin, vmax;
687 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
688 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
689 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
690 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
691 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
692 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
695 const Handle(IntTools_TopolTool) dom1 = new IntTools_TopolTool(myHS1);
696 const Handle(IntTools_TopolTool) dom2 = new IntTools_TopolTool(myHS2);
698 myLConstruct.Load(dom1, dom2, myHS1, myHS2);
701 Tolerances(myHS1, myHS2, TolTang);
704 const Standard_Real UVMaxStep = 0.001;
705 const Standard_Real Deflection = (hasCone) ? 0.085 : 0.1;
706 myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection);
709 if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) ||
710 (myHS1->IsVClosed() && !myHS1->IsVPeriodic()) ||
711 (myHS2->IsUClosed() && !myHS2->IsUPeriodic()) ||
712 (myHS2->IsVClosed() && !myHS2->IsVPeriodic()))
714 RestrictLine = Standard_True;
717 if((aType1 != GeomAbs_BSplineSurface) &&
718 (aType1 != GeomAbs_BezierSurface) &&
719 (aType1 != GeomAbs_OtherSurface) &&
720 (aType2 != GeomAbs_BSplineSurface) &&
721 (aType2 != GeomAbs_BezierSurface) &&
722 (aType2 != GeomAbs_OtherSurface))
724 RestrictLine = Standard_True;
726 if ((aType1 == GeomAbs_Torus) ||
727 (aType2 == GeomAbs_Torus))
729 myListOfPnts.Clear();
736 TopExp_Explorer aExp;
737 for(Standard_Integer i = 0; (!RestrictLine) && (i < 2); i++)
739 const TopoDS_Face& aF=(!i) ? myFace1 : myFace2;
740 aExp.Init(aF, TopAbs_EDGE);
741 for(; aExp.More(); aExp.Next())
743 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
745 if(BRep_Tool::Degenerated(aE))
747 RestrictLine = Standard_True;
754 const Standard_Boolean isGeomInt = isTreatAnalityc(aF1, aF2);
755 myIntersector.Perform(myHS1, dom1, myHS2, dom2, TolArc, TolTang,
756 myListOfPnts, RestrictLine, isGeomInt);
758 myIsDone = myIntersector.IsDone();
762 myTangentFaces=myIntersector.TangentFaces();
763 if (myTangentFaces) {
768 myListOfPnts.Clear(); // to use LineConstructor
771 const Standard_Integer aNbLin = myIntersector.NbLines();
772 for (Standard_Integer i=1; i <= aNbLin; ++i) {
773 MakeCurve(i, dom1, dom2);
776 ComputeTolReached3d();
779 Handle(Geom2d_Curve) aC2D1, aC2D2;
781 const Standard_Integer aNbLin=mySeqOfCurve.Length();
782 for (Standard_Integer i=1; i<=aNbLin; ++i)
784 IntTools_Curve& aIC=mySeqOfCurve(i);
785 aC2D1=aIC.FirstCurve2d();
786 aC2D2=aIC.SecondCurve2d();
787 aIC.SetFirstCurve2d(aC2D2);
788 aIC.SetSecondCurve2d(aC2D1);
793 Standard_Real U1,V1,U2,V2;
794 IntTools_PntOnFace aPntOnF1, aPntOnF2;
795 IntTools_PntOn2Faces aPntOn2Faces;
797 const Standard_Integer aNbPnts = myIntersector.NbPnts();
798 for (Standard_Integer i=1; i <= aNbPnts; ++i)
800 const IntSurf_PntOn2S& aISPnt=myIntersector.Point(i).PntOn2S();
801 const gp_Pnt& aPnt=aISPnt.Value();
802 aISPnt.Parameters(U1,V1,U2,V2);
803 aPntOnF1.Init(myFace1, aPnt, U1, V1);
804 aPntOnF2.Init(myFace2, aPnt, U2, V2);
808 aPntOn2Faces.SetP1(aPntOnF1);
809 aPntOn2Faces.SetP2(aPntOnF2);
813 aPntOn2Faces.SetP2(aPntOnF1);
814 aPntOn2Faces.SetP1(aPntOnF2);
817 myPnts.Append(aPntOn2Faces);
822 //=======================================================================
823 //function :ComputeTolReached3d
825 //=======================================================================
826 void IntTools_FaceFace::ComputeTolReached3d()
828 Standard_Boolean bCase1;
829 Standard_Integer aNbLin, i;
830 GeomAbs_SurfaceType aType1, aType2;
832 aNbLin=myIntersector.NbLines();
837 aType1=myHS1->Surface().GetType();
838 aType2=myHS2->Surface().GetType();
840 bCase1=((aType1==GeomAbs_Plane && aType2==GeomAbs_SurfaceOfExtrusion) ||
841 (aType2==GeomAbs_Plane && aType1==GeomAbs_SurfaceOfExtrusion));
843 if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
845 Handle(IntPatch_Line) aIL1, aIL2;
846 IntPatch_IType aTL1, aTL2;
848 aIL1=myIntersector.Line(1);
849 aIL2=myIntersector.Line(2);
850 aTL1=aIL1->ArcType();
851 aTL2=aIL2->ArcType();
852 if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) {
853 Standard_Real aD, aDTresh, dTol;
859 aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line();
860 aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line();
861 aD=aL1.Distance(aL2);
864 myTolReached3d=aD+dTol;
870 if (aNbLin) {// Check the distances
871 Standard_Integer aNbP, j ;
872 Standard_Real aT1, aT2, dT, aD2, aD2Max, aEps, aT11, aT12;
876 aNbLin=mySeqOfCurve.Length();
878 for (i=1; i<=aNbLin; ++i) {
879 const IntTools_Curve& aIC=mySeqOfCurve(i);
880 const Handle(Geom_Curve)& aC3D=aIC.Curve();
881 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
882 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
887 const Handle(Geom_BSplineCurve)& aBC=
888 Handle(Geom_BSplineCurve)::DownCast(aC3D);
893 aT1=aBC->FirstParameter();
894 aT2=aBC->LastParameter();
898 for (j=1; j<aNbP; ++j) {
901 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
902 myHS1, myHS2, myFace1, myFace2, myContext);
907 }//for (i=1; i<=aNbLin; ++i) {
909 myTolReached3d=sqrt(aD2Max);
911 }// if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
914 else if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
915 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
919 aTolF1 = BRep_Tool::Tolerance(myFace1);
920 aTolF2 = BRep_Tool::Tolerance(myFace2);
921 aTolFMax=Max(aTolF1, aTolF2);
923 if (aTolFMax>aTolTresh) {
924 myTolReached3d=aTolFMax;
926 }//if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
929 else if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ||
930 (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) {
932 const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1);
933 if(aIL1->ArcType() == IntPatch_Circle) {
934 gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle();
935 gp_XYZ aCirDir = aCir.Axis().Direction().XYZ();
938 if(aType1 == GeomAbs_Plane) {
939 aPln = myHS1->Surface().Plane();
942 aPln = myHS2->Surface().Plane();
944 aPlDir = aPln.Axis().Direction().XYZ();
945 Standard_Real cs = aCirDir*aPlDir;
946 if(cs < 0.) aPlDir.Reverse();
947 Standard_Real eps = 1.e-14;
948 if(!aPlDir.IsEqual(aCirDir, eps)) {
949 Standard_Integer aNbP = 11;
950 Standard_Real dt = 2.*M_PI / (aNbP - 1), t;
951 for(t = 0.; t < 2.*M_PI; t += dt) {
952 Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir));
953 if(myTolReached3d < d) myTolReached3d = d;
955 myTolReached3d *= 1.1;
957 } //aIL1->ArcType() == IntPatch_Circle
959 } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane)
960 //End IFV Bug OCC20297
962 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
963 (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) {
964 aNbLin=mySeqOfCurve.Length();
969 Standard_Integer aNbP;
970 Standard_Real aT, aT1, aT2, dT, aUT, aVT, aUP, aVP;
971 Standard_Real aDP, aDT, aDmax;
976 const IntTools_Curve& aIC=mySeqOfCurve(1);
977 const Handle(Geom_Curve)& aC3D=aIC.Curve();
978 const Handle(Geom_BSplineCurve)& aBS=
979 Handle(Geom_BSplineCurve)::DownCast(aC3D);
984 aT1=aBS->FirstParameter();
985 aT2=aBS->LastParameter();
987 aPln =(aType1==GeomAbs_Plane) ? myHS1->Plane() : myHS2->Plane();
988 aTorus=(aType1==GeomAbs_Plane) ? myHS2->Torus() : myHS1->Torus();
992 dT=(aT2-aT1)/(aNbP-1);
993 for (i=0; i<aNbP; ++i) {
1001 ElSLib::Parameters(aPln, aP, aUP, aVP);
1002 aPP=ElSLib::Value(aUP, aVP, aPln);
1003 aDP=aP.SquareDistance(aPP);
1008 ElSLib::Parameters(aTorus, aP, aUT, aVT);
1009 aPT=ElSLib::Value(aUT, aVT, aTorus);
1010 aDT=aP.SquareDistance(aPT);
1016 if (aDmax > myTolReached3d*myTolReached3d) {
1017 myTolReached3d=sqrt(aDmax);
1018 myTolReached3d=1.1*myTolReached3d;
1020 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
1022 else if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) ||
1023 (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder)) {
1024 Standard_Integer j, aNbP;
1025 Standard_Real aT, aT1, aT2, dT, aD2max, aD2;
1027 aNbLin=mySeqOfCurve.Length();
1031 for (i=1; i<=aNbLin; ++i) {
1032 const IntTools_Curve& aIC=mySeqOfCurve(i);
1033 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1034 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1035 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1037 if (aC3D.IsNull()) {
1040 const Handle(Geom_BSplineCurve)& aBC=
1041 Handle(Geom_BSplineCurve)::DownCast(aC3D);
1046 aT1=aBC->FirstParameter();
1047 aT2=aBC->LastParameter();
1049 dT=(aT2-aT1)/(aNbP-1);
1050 for (j=0; j<aNbP; ++j) {
1056 aD2=MaxSquareDistance(aT, aC3D, aC2D1, aC2D2,
1057 myHS1, myHS2, myFace1, myFace2, myContext);
1061 }//for (j=0; j<aNbP; ++j) {
1063 }//for (i=1; i<=aNbLin; ++i) {
1065 aD2=myTolReached3d*myTolReached3d;
1067 myTolReached3d=sqrt(aD2max);
1069 }//if((aType1==GeomAbs_SurfaceOfRevolution ...
1070 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ||
1071 (aType2==GeomAbs_Plane && aType1==GeomAbs_Sphere)) {
1072 Standard_Integer j, aNbP;
1073 Standard_Real aT1, aT2, dT, aD2max, aD2, aEps, aT11, aT12;
1075 aNbLin=mySeqOfCurve.Length();
1079 for (i=1; i<=aNbLin; ++i) {
1080 const IntTools_Curve& aIC=mySeqOfCurve(i);
1081 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1082 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1083 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1085 const Handle(Geom2d_BSplineCurve)& aBC2D1=
1086 Handle(Geom2d_BSplineCurve)::DownCast(aC2D1);
1087 const Handle(Geom2d_BSplineCurve)& aBC2D2=
1088 Handle(Geom2d_BSplineCurve)::DownCast(aC2D2);
1090 if (aBC2D1.IsNull() && aBC2D2.IsNull()) {
1094 if (!aBC2D1.IsNull()) {
1095 aT1=aBC2D1->FirstParameter();
1096 aT2=aBC2D1->LastParameter();
1099 aT1=aBC2D2->FirstParameter();
1100 aT2=aBC2D2->LastParameter();
1103 aEps=0.01*(aT2-aT1);
1105 for (j=0; j<aNbP; ++j) {
1112 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
1113 myHS1, myHS2, myFace1, myFace2, myContext);
1117 }//for (j=0; j<aNbP; ++j) {
1119 }//for (i=1; i<=aNbLin; ++i) {
1121 aD2=myTolReached3d*myTolReached3d;
1123 myTolReached3d=sqrt(aD2max);
1125 }//else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ...
1126 else if (!myApprox || bCase1) {
1127 //else if (!myApprox) {
1128 Standard_Integer aNbP, j;
1129 Standard_Real aT1, aT2, dT, aD2, aD2Max, aEps, aT11, aT12;
1132 aNbLin=mySeqOfCurve.Length();
1134 for (i=1; i<=aNbLin; ++i) {
1135 const IntTools_Curve& aIC=mySeqOfCurve(i);
1136 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1137 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1138 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1140 if (aC3D.IsNull()) {
1143 const Handle(Geom_BSplineCurve)& aBC=
1144 Handle(Geom_BSplineCurve)::DownCast(aC3D);
1149 aT1=aBC->FirstParameter();
1150 aT2=aBC->LastParameter();
1152 aEps=0.0001*(aT2-aT1);
1155 for (j=1; j<aNbP-1; ++j) {
1158 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
1159 myHS1, myHS2, myFace1, myFace2, myContext);
1164 }//for (i=1; i<=aNbLin; ++i) {
1165 myTolReached3d=sqrt(aD2Max);
1168 //=======================================================================
1169 //function : MakeCurve
1171 //=======================================================================
1172 void IntTools_FaceFace::MakeCurve(const Standard_Integer Index,
1173 const Handle(Adaptor3d_TopolTool)& dom1,
1174 const Handle(Adaptor3d_TopolTool)& dom2)
1176 Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor;
1177 Standard_Boolean ok, bPCurvesOk;
1178 Standard_Integer i, j, aNbParts;
1179 Standard_Real fprm, lprm;
1180 Standard_Real Tolpc;
1181 Handle(IntPatch_Line) L;
1182 IntPatch_IType typl;
1183 Handle(Geom_Curve) newc;
1185 const Standard_Real TOLCHECK =0.0000001;
1186 const Standard_Real TOLANGCHECK=0.1;
1188 rejectSurface = Standard_False;
1189 reApprox = Standard_False;
1191 bPCurvesOk = Standard_True;
1195 Tolpc = myTolApprox;
1196 bAvoidLineConstructor = Standard_False;
1197 L = myIntersector.Line(Index);
1198 typl = L->ArcType();
1200 if(typl==IntPatch_Walking) {
1201 Handle(IntPatch_Line) anewL;
1203 const Handle(IntPatch_WLine)& aWLine=
1204 Handle(IntPatch_WLine)::DownCast(L);
1205 //DumpWLine(aWLine);
1207 anewL = ComputePurgedWLine(aWLine);
1208 if(anewL.IsNull()) {
1213 //const Handle(IntPatch_WLine)& aWLineX = Handle(IntPatch_WLine)::DownCast(L);
1214 //DumpWLine(aWLineX);
1217 if(!myListOfPnts.IsEmpty()) {
1218 bAvoidLineConstructor = Standard_True;
1221 Standard_Integer nbp = aWLine->NbPnts();
1222 const IntSurf_PntOn2S& p1 = aWLine->Point(1);
1223 const IntSurf_PntOn2S& p2 = aWLine->Point(nbp);
1225 const gp_Pnt& P1 = p1.Value();
1226 const gp_Pnt& P2 = p2.Value();
1228 if(P1.SquareDistance(P2) < 1.e-14) {
1229 bAvoidLineConstructor = Standard_False;
1234 if(!bAvoidLineConstructor) {
1235 myLConstruct.Perform(L);
1237 bDone=myLConstruct.IsDone();
1238 aNbParts=myLConstruct.NbParts();
1239 if (!bDone|| !aNbParts) {
1248 //########################################
1249 // Line, Parabola, Hyperbola
1250 //########################################
1252 case IntPatch_Parabola:
1253 case IntPatch_Hyperbola: {
1254 if (typl == IntPatch_Lin) {
1256 new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
1259 else if (typl == IntPatch_Parabola) {
1261 new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
1264 else if (typl == IntPatch_Hyperbola) {
1266 new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
1270 if (typl == IntPatch_Lin) {
1271 TolR3d (myFace1, myFace2, myTolReached3d);
1274 aNbParts=myLConstruct.NbParts();
1275 for (i=1; i<=aNbParts; i++) {
1276 myLConstruct.Part(i, fprm, lprm);
1278 if (!Precision::IsNegativeInfinite(fprm) &&
1279 !Precision::IsPositiveInfinite(lprm)) {
1281 IntTools_Curve aCurve;
1283 Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
1284 aCurve.SetCurve(aCT3D);
1285 if (typl == IntPatch_Parabola) {
1286 Standard_Real aTolF1, aTolF2, aTolBase;
1288 aTolF1 = BRep_Tool::Tolerance(myFace1);
1289 aTolF2 = BRep_Tool::Tolerance(myFace2);
1290 aTolBase=aTolF1+aTolF2;
1291 myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
1294 aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
1296 Handle (Geom2d_Curve) C2d;
1297 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1298 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1299 myTolReached2d=Tolpc;
1302 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1305 Handle(Geom2d_BSplineCurve) H1;
1307 aCurve.SetFirstCurve2d(H1);
1311 Handle (Geom2d_Curve) C2d;
1312 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1313 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1314 myTolReached2d=Tolpc;
1317 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1320 Handle(Geom2d_BSplineCurve) H1;
1322 aCurve.SetSecondCurve2d(H1);
1324 mySeqOfCurve.Append(aCurve);
1325 } // end of if (!Precision::IsNegativeInfinite(fprm) && !Precision::IsPositiveInfinite(lprm))
1327 // on regarde si on garde
1329 Standard_Boolean bFNIt, bLPIt;
1330 Standard_Real aTestPrm, dT=100.;
1332 bFNIt=Precision::IsNegativeInfinite(fprm);
1333 bLPIt=Precision::IsPositiveInfinite(lprm);
1337 if (bFNIt && !bLPIt) {
1340 else if (!bFNIt && bLPIt) {
1344 gp_Pnt ptref(newc->Value(aTestPrm));
1346 GeomAbs_SurfaceType typS1 = myHS1->GetType();
1347 GeomAbs_SurfaceType typS2 = myHS2->GetType();
1348 if( typS1 == GeomAbs_SurfaceOfExtrusion ||
1349 typS1 == GeomAbs_OffsetSurface ||
1350 typS1 == GeomAbs_SurfaceOfRevolution ||
1351 typS2 == GeomAbs_SurfaceOfExtrusion ||
1352 typS2 == GeomAbs_OffsetSurface ||
1353 typS2 == GeomAbs_SurfaceOfRevolution)
1355 Handle(Geom2d_BSplineCurve) H1;
1356 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1360 Standard_Real u1, v1, u2, v2, Tol;
1362 Tol = Precision::Confusion();
1363 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1364 ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
1366 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1369 Handle(Geom2d_BSplineCurve) H1;
1370 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1373 }// end of for (i=1; i<=myLConstruct.NbParts(); i++)
1374 }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola:
1377 //########################################
1378 // Circle and Ellipse
1379 //########################################
1380 case IntPatch_Circle:
1381 case IntPatch_Ellipse: {
1383 if (typl == IntPatch_Circle) {
1384 newc = new Geom_Circle
1385 (Handle(IntPatch_GLine)::DownCast(L)->Circle());
1387 else { //IntPatch_Ellipse
1388 newc = new Geom_Ellipse
1389 (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
1393 TolR3d (myFace1, myFace2, myTolReached3d);
1395 aNbParts=myLConstruct.NbParts();
1397 Standard_Real aPeriod, aNul;
1398 TColStd_SequenceOfReal aSeqFprm, aSeqLprm;
1403 for (i=1; i<=aNbParts; i++) {
1404 myLConstruct.Part(i, fprm, lprm);
1406 if (fprm < aNul && lprm > aNul) {
1407 // interval that goes through 0. is divided on two intervals;
1408 while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
1409 while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
1411 if((aPeriod - fprm) > Tolpc) {
1412 aSeqFprm.Append(fprm);
1413 aSeqLprm.Append(aPeriod);
1416 gp_Pnt P1 = newc->Value(fprm);
1417 gp_Pnt P2 = newc->Value(aPeriod);
1418 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1419 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1421 if(P1.Distance(P2) > aTolDist) {
1422 Standard_Real anewpar = fprm;
1424 if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2,
1425 lprm, Standard_False, anewpar, myContext)) {
1428 aSeqFprm.Append(fprm);
1429 aSeqLprm.Append(aPeriod);
1434 if((lprm - aNul) > Tolpc) {
1435 aSeqFprm.Append(aNul);
1436 aSeqLprm.Append(lprm);
1439 gp_Pnt P1 = newc->Value(aNul);
1440 gp_Pnt P2 = newc->Value(lprm);
1441 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1442 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1444 if(P1.Distance(P2) > aTolDist) {
1445 Standard_Real anewpar = lprm;
1447 if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2,
1448 fprm, Standard_True, anewpar, myContext)) {
1451 aSeqFprm.Append(aNul);
1452 aSeqLprm.Append(lprm);
1458 aSeqFprm.Append(fprm);
1459 aSeqLprm.Append(lprm);
1464 aNbParts=aSeqFprm.Length();
1465 for (i=1; i<=aNbParts; i++) {
1469 Standard_Real aRealEpsilon=RealEpsilon();
1470 if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*M_PI) > aRealEpsilon) {
1471 //==============================================
1473 IntTools_Curve aCurve;
1474 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1475 aCurve.SetCurve(aTC3D);
1476 fprm=aTC3D->FirstParameter();
1477 lprm=aTC3D->LastParameter ();
1479 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {////
1481 Handle (Geom2d_Curve) C2d;
1482 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1483 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1484 myTolReached2d=Tolpc;
1487 aCurve.SetFirstCurve2d(C2d);
1490 Handle(Geom2d_BSplineCurve) H1;
1491 aCurve.SetFirstCurve2d(H1);
1496 Handle (Geom2d_Curve) C2d;
1497 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1498 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1499 myTolReached2d=Tolpc;
1502 aCurve.SetSecondCurve2d(C2d);
1505 Handle(Geom2d_BSplineCurve) H1;
1506 aCurve.SetSecondCurve2d(H1);
1511 Handle(Geom2d_BSplineCurve) H1;
1512 aCurve.SetFirstCurve2d(H1);
1513 aCurve.SetSecondCurve2d(H1);
1515 mySeqOfCurve.Append(aCurve);
1516 //==============================================
1517 } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon())
1520 // on regarde si on garde
1523 // if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) {
1524 if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
1525 IntTools_Curve aCurve;
1526 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1527 aCurve.SetCurve(aTC3D);
1528 fprm=aTC3D->FirstParameter();
1529 lprm=aTC3D->LastParameter ();
1532 Handle (Geom2d_Curve) C2d;
1533 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1534 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1535 myTolReached2d=Tolpc;
1538 aCurve.SetFirstCurve2d(C2d);
1541 Handle(Geom2d_BSplineCurve) H1;
1542 aCurve.SetFirstCurve2d(H1);
1546 Handle (Geom2d_Curve) C2d;
1547 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1548 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1549 myTolReached2d=Tolpc;
1552 aCurve.SetSecondCurve2d(C2d);
1555 Handle(Geom2d_BSplineCurve) H1;
1556 aCurve.SetSecondCurve2d(H1);
1558 mySeqOfCurve.Append(aCurve);
1563 Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
1565 aTwoPIdiv17=2.*M_PI/17.;
1567 for (j=0; j<=17; j++) {
1568 gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
1569 Tol = Precision::Confusion();
1571 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1572 ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
1574 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1577 IntTools_Curve aCurve;
1578 aCurve.SetCurve(newc);
1579 //==============================================
1580 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
1583 Handle (Geom2d_Curve) C2d;
1584 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1585 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1586 myTolReached2d=Tolpc;
1589 aCurve.SetFirstCurve2d(C2d);
1592 Handle(Geom2d_BSplineCurve) H1;
1593 aCurve.SetFirstCurve2d(H1);
1597 Handle (Geom2d_Curve) C2d;
1598 BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
1599 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1600 myTolReached2d=Tolpc;
1603 aCurve.SetSecondCurve2d(C2d);
1607 Handle(Geom2d_BSplineCurve) H1;
1608 aCurve.SetSecondCurve2d(H1);
1610 }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
1613 Handle(Geom2d_BSplineCurve) H1;
1615 aCurve.SetFirstCurve2d(H1);
1616 aCurve.SetSecondCurve2d(H1);
1618 //==============================================
1620 mySeqOfCurve.Append(aCurve);
1623 }// end of if (ok) {
1624 }// end of for (Standard_Integer j=0; j<=17; j++)
1625 }// end of else { on regarde si on garde
1626 }// for (i=1; i<=myLConstruct.NbParts(); i++)
1627 }// IntPatch_Circle: IntPatch_Ellipse:
1630 case IntPatch_Analytic: {
1631 IntSurf_Quadric quad1,quad2;
1632 GeomAbs_SurfaceType typs = myHS1->Surface().GetType();
1636 quad1.SetValue(myHS1->Surface().Plane());
1638 case GeomAbs_Cylinder:
1639 quad1.SetValue(myHS1->Surface().Cylinder());
1642 quad1.SetValue(myHS1->Surface().Cone());
1644 case GeomAbs_Sphere:
1645 quad1.SetValue(myHS1->Surface().Sphere());
1648 quad1.SetValue(myHS1->Surface().Torus());
1651 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
1654 typs = myHS2->Surface().GetType();
1658 quad2.SetValue(myHS2->Surface().Plane());
1660 case GeomAbs_Cylinder:
1661 quad2.SetValue(myHS2->Surface().Cylinder());
1664 quad2.SetValue(myHS2->Surface().Cone());
1666 case GeomAbs_Sphere:
1667 quad2.SetValue(myHS2->Surface().Sphere());
1670 quad2.SetValue(myHS2->Surface().Torus());
1673 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
1677 IntPatch_ALineToWLine convert (quad1, quad2);
1680 aNbParts=myLConstruct.NbParts();
1681 for (i=1; i<=aNbParts; i++) {
1682 myLConstruct.Part(i, fprm, lprm);
1683 Handle(IntPatch_WLine) WL =
1684 convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
1686 Handle(Geom2d_BSplineCurve) H1;
1687 Handle(Geom2d_BSplineCurve) H2;
1690 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1694 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1697 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1701 else { // myApprox=TRUE
1702 GeomInt_WLApprox theapp3d;
1704 Standard_Real tol2d = myTolApprox;
1706 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
1708 aNbParts=myLConstruct.NbParts();
1709 for (i=1; i<=aNbParts; i++) {
1710 myLConstruct.Part(i, fprm, lprm);
1711 Handle(IntPatch_WLine) WL =
1712 convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
1714 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
1716 if (!theapp3d.IsDone()) {
1718 Handle(Geom2d_BSplineCurve) H1;
1719 Handle(Geom2d_BSplineCurve) H2;
1722 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1726 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1729 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1733 if(myApprox1 || myApprox2) {
1734 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
1735 myTolReached2d = theapp3d.TolReached2d();
1739 if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
1740 myTolReached3d = theapp3d.TolReached3d();
1743 Standard_Integer aNbMultiCurves, nbpoles;
1744 aNbMultiCurves=theapp3d.NbMultiCurves();
1745 for (j=1; j<=aNbMultiCurves; j++) {
1746 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1747 nbpoles = mbspc.NbPoles();
1749 TColgp_Array1OfPnt tpoles(1, nbpoles);
1750 mbspc.Curve(1, tpoles);
1751 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1753 mbspc.Multiplicities(),
1756 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1757 Check.FixTangent(Standard_True,Standard_True);
1759 IntTools_Curve aCurve;
1760 aCurve.SetCurve(BS);
1763 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1764 mbspc.Curve(2,tpoles2d);
1765 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1767 mbspc.Multiplicities(),
1770 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1771 newCheck.FixTangent(Standard_True,Standard_True);
1773 aCurve.SetFirstCurve2d(BS2);
1776 Handle(Geom2d_BSplineCurve) H1;
1777 aCurve.SetFirstCurve2d(H1);
1781 TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
1782 Standard_Integer TwoOrThree;
1783 TwoOrThree=myApprox1 ? 3 : 2;
1784 mbspc.Curve(TwoOrThree, tpoles2d);
1785 Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
1787 mbspc.Multiplicities(),
1790 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1791 newCheck.FixTangent(Standard_True,Standard_True);
1793 aCurve.SetSecondCurve2d(BS2);
1796 Handle(Geom2d_BSplineCurve) H2;
1797 aCurve.SetSecondCurve2d(H2);
1800 mySeqOfCurve.Append(aCurve);
1802 }// for (j=1; j<=aNbMultiCurves; j++) {
1803 }// else from if (!theapp3d.IsDone())
1804 }// for (i=1; i<=aNbParts; i++) {
1805 }// else { // myApprox=TRUE
1806 }// case IntPatch_Analytic:
1809 case IntPatch_Walking: {
1810 Handle(IntPatch_WLine) WL =
1811 Handle(IntPatch_WLine)::DownCast(L);
1813 Standard_Integer ifprm, ilprm;
1817 if(!bAvoidLineConstructor){
1818 aNbParts=myLConstruct.NbParts();
1820 for (i=1; i<=aNbParts; ++i) {
1821 Handle(Geom2d_BSplineCurve) H1, H2;
1822 Handle(Geom_Curve) aBSp;
1824 if(bAvoidLineConstructor) {
1826 ilprm = WL->NbPnts();
1829 myLConstruct.Part(i, fprm, lprm);
1830 ifprm=(Standard_Integer)fprm;
1831 ilprm=(Standard_Integer)lprm;
1835 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1839 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1842 aBSp=MakeBSpline(WL, ifprm, ilprm);
1843 IntTools_Curve aIC(aBSp, H1, H2);
1844 mySeqOfCurve.Append(aIC);
1845 }// for (i=1; i<=aNbParts; ++i) {
1846 }// if (!myApprox) {
1849 Standard_Boolean bIsDecomposited;
1850 Standard_Integer nbiter, aNbSeqOfL;
1851 Standard_Real tol2d, aTolApproxImp;
1852 IntPatch_SequenceOfLine aSeqOfL;
1853 GeomInt_WLApprox theapp3d;
1854 Approx_ParametrizationType aParType = Approx_ChordLength;
1856 Standard_Boolean anApprox1 = myApprox1;
1857 Standard_Boolean anApprox2 = myApprox2;
1859 aTolApproxImp=1.e-5;
1860 tol2d = myTolApprox;
1862 GeomAbs_SurfaceType typs1, typs2;
1863 typs1 = myHS1->Surface().GetType();
1864 typs2 = myHS2->Surface().GetType();
1865 Standard_Boolean anWithPC = Standard_True;
1867 if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
1869 ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
1871 else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
1873 ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
1877 myTolApprox = aTolApproxImp;//1.e-5;
1878 anApprox1 = Standard_False;
1879 anApprox2 = Standard_False;
1881 tol2d = myTolApprox;
1884 if(myHS1 == myHS2) {
1885 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1886 rejectSurface = Standard_True;
1889 if(reApprox && !rejectSurface)
1890 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1892 Standard_Integer iDegMax, iDegMin, iNbIter;
1894 ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter);
1895 theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType);
1899 Standard_Real aReachedTol = Precision::Confusion();
1900 bIsDecomposited=DecompositionOfWLine(WL,
1906 bAvoidLineConstructor,
1910 if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) ) {
1911 myTolReached3d = aReachedTol;
1914 aNbSeqOfL=aSeqOfL.Length();
1916 if (bIsDecomposited) {
1922 if (!bAvoidLineConstructor) {
1923 aNbParts=myLConstruct.NbParts();
1928 for(i = 1; i <= nbiter; ++i) {
1929 if(bIsDecomposited) {
1930 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
1932 ilprm = WL->NbPnts();
1935 if(bAvoidLineConstructor) {
1937 ilprm = WL->NbPnts();
1940 myLConstruct.Part(i, fprm, lprm);
1941 ifprm = (Standard_Integer)fprm;
1942 ilprm = (Standard_Integer)lprm;
1946 //-- Si une des surfaces est un plan , on approxime en 2d
1947 //-- sur cette surface et on remonte les points 2d en 3d.
1948 if(typs1 == GeomAbs_Plane) {
1949 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
1951 else if(typs2 == GeomAbs_Plane) {
1952 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
1956 if (myHS1 != myHS2){
1957 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
1958 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
1960 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
1962 Standard_Boolean bUseSurfaces;
1963 bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
1966 rejectSurface = Standard_True;
1968 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1973 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
1976 if (!theapp3d.IsDone()) {
1977 Handle(Geom2d_BSplineCurve) H1;
1978 Handle(Geom2d_BSplineCurve) H2;
1980 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
1983 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1987 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1990 IntTools_Curve aIC(aBSp, H1, H2);
1991 mySeqOfCurve.Append(aIC);
1995 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
1996 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
1997 myTolReached2d = theapp3d.TolReached2d();
2000 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
2001 myTolReached3d = myTolReached2d;
2003 if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
2004 if (myTolReached3d<1.e-6) {
2005 myTolReached3d = theapp3d.TolReached3d();
2006 myTolReached3d=1.e-6;
2010 else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
2011 myTolReached3d = theapp3d.TolReached3d();
2014 Standard_Integer aNbMultiCurves, nbpoles;
2015 aNbMultiCurves=theapp3d.NbMultiCurves();
2016 for (j=1; j<=aNbMultiCurves; j++) {
2017 if(typs1 == GeomAbs_Plane) {
2018 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2019 nbpoles = mbspc.NbPoles();
2021 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2022 TColgp_Array1OfPnt tpoles(1,nbpoles);
2024 mbspc.Curve(1,tpoles2d);
2025 const gp_Pln& Pln = myHS1->Surface().Plane();
2027 Standard_Integer ik;
2028 for(ik = 1; ik<= nbpoles; ik++) {
2030 ElSLib::Value(tpoles2d.Value(ik).X(),
2031 tpoles2d.Value(ik).Y(),
2035 Handle(Geom_BSplineCurve) BS =
2036 new Geom_BSplineCurve(tpoles,
2038 mbspc.Multiplicities(),
2040 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2041 Check.FixTangent(Standard_True, Standard_True);
2043 IntTools_Curve aCurve;
2044 aCurve.SetCurve(BS);
2047 Handle(Geom2d_BSplineCurve) BS1 =
2048 new Geom2d_BSplineCurve(tpoles2d,
2050 mbspc.Multiplicities(),
2052 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2053 Check1.FixTangent(Standard_True,Standard_True);
2055 // ############################################
2056 if(!rejectSurface && !reApprox) {
2057 Standard_Boolean isValid = IsCurveValid(BS1);
2059 reApprox = Standard_True;
2063 // ############################################
2064 aCurve.SetFirstCurve2d(BS1);
2067 Handle(Geom2d_BSplineCurve) H1;
2068 aCurve.SetFirstCurve2d(H1);
2072 mbspc.Curve(2, tpoles2d);
2074 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
2076 mbspc.Multiplicities(),
2078 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2079 newCheck.FixTangent(Standard_True,Standard_True);
2081 // ###########################################
2082 if(!rejectSurface && !reApprox) {
2083 Standard_Boolean isValid = IsCurveValid(BS2);
2085 reApprox = Standard_True;
2089 // ###########################################
2091 aCurve.SetSecondCurve2d(BS2);
2094 Handle(Geom2d_BSplineCurve) H2;
2096 aCurve.SetSecondCurve2d(H2);
2099 mySeqOfCurve.Append(aCurve);
2100 }//if(typs1 == GeomAbs_Plane) {
2102 else if(typs2 == GeomAbs_Plane) {
2103 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2104 nbpoles = mbspc.NbPoles();
2106 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2107 TColgp_Array1OfPnt tpoles(1,nbpoles);
2108 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
2109 const gp_Pln& Pln = myHS2->Surface().Plane();
2111 Standard_Integer ik;
2112 for(ik = 1; ik<= nbpoles; ik++) {
2114 ElSLib::Value(tpoles2d.Value(ik).X(),
2115 tpoles2d.Value(ik).Y(),
2120 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
2122 mbspc.Multiplicities(),
2124 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2125 Check.FixTangent(Standard_True,Standard_True);
2127 IntTools_Curve aCurve;
2128 aCurve.SetCurve(BS);
2131 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
2133 mbspc.Multiplicities(),
2135 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2136 Check1.FixTangent(Standard_True,Standard_True);
2138 // ###########################################
2139 if(!rejectSurface && !reApprox) {
2140 Standard_Boolean isValid = IsCurveValid(BS1);
2142 reApprox = Standard_True;
2146 // ###########################################
2147 bPCurvesOk = CheckPCurve(BS1, myFace2);
2148 aCurve.SetSecondCurve2d(BS1);
2151 Handle(Geom2d_BSplineCurve) H2;
2152 aCurve.SetSecondCurve2d(H2);
2156 mbspc.Curve(1,tpoles2d);
2157 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
2159 mbspc.Multiplicities(),
2161 GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
2162 Check2.FixTangent(Standard_True,Standard_True);
2164 // ###########################################
2165 if(!rejectSurface && !reApprox) {
2166 Standard_Boolean isValid = IsCurveValid(BS2);
2168 reApprox = Standard_True;
2172 // ###########################################
2173 bPCurvesOk = bPCurvesOk && CheckPCurve(BS2, myFace1);
2174 aCurve.SetFirstCurve2d(BS2);
2177 Handle(Geom2d_BSplineCurve) H1;
2179 aCurve.SetFirstCurve2d(H1);
2182 //if points of the pcurves are out of the faces bounds
2183 //create 3d and 2d curves without approximation
2185 Handle(Geom2d_BSplineCurve) H1, H2;
2186 bPCurvesOk = Standard_True;
2188 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
2191 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
2192 bPCurvesOk = CheckPCurve(H1, myFace1);
2196 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
2197 bPCurvesOk = bPCurvesOk && CheckPCurve(H2, myFace2);
2200 //if pcurves created without approximation are out of the
2201 //faces bounds, use approximated 3d and 2d curves
2203 IntTools_Curve aIC(aBSp, H1, H2);
2204 mySeqOfCurve.Append(aIC);
2206 mySeqOfCurve.Append(aCurve);
2209 mySeqOfCurve.Append(aCurve);
2211 }// else if(typs2 == GeomAbs_Plane)
2213 else { //typs2 != GeomAbs_Plane && typs1 != GeomAbs_Plane
2214 Standard_Boolean bIsValid1, bIsValid2;
2215 Handle(Geom_BSplineCurve) BS;
2216 Handle(Geom2d_BSplineCurve) aH2D;
2217 IntTools_Curve aCurve;
2219 bIsValid1=Standard_True;
2220 bIsValid2=Standard_True;
2222 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2223 nbpoles = mbspc.NbPoles();
2224 TColgp_Array1OfPnt tpoles(1,nbpoles);
2225 mbspc.Curve(1,tpoles);
2226 BS=new Geom_BSplineCurve(tpoles,
2228 mbspc.Multiplicities(),
2230 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2231 Check.FixTangent(Standard_True,Standard_True);
2233 aCurve.SetCurve(BS);
2234 aCurve.SetFirstCurve2d(aH2D);
2235 aCurve.SetSecondCurve2d(aH2D);
2239 Handle(Geom2d_BSplineCurve) BS1;
2240 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2241 mbspc.Curve(2,tpoles2d);
2243 BS1=new Geom2d_BSplineCurve(tpoles2d,
2245 mbspc.Multiplicities(),
2247 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
2248 newCheck.FixTangent(Standard_True,Standard_True);
2251 bIsValid1=CheckPCurve(BS1, myFace1);
2254 aCurve.SetFirstCurve2d(BS1);
2257 Handle(Geom2d_BSplineCurve) BS1;
2258 fprm = BS->FirstParameter();
2259 lprm = BS->LastParameter();
2261 Handle(Geom2d_Curve) C2d;
2262 Standard_Real aTol = myTolApprox;
2263 BuildPCurves(fprm, lprm, aTol, myHS1->ChangeSurface().Surface(), BS, C2d);
2264 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2265 aCurve.SetFirstCurve2d(BS1);
2267 } // if(myApprox1) {
2271 Handle(Geom2d_BSplineCurve) BS2;
2272 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2273 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
2274 BS2=new Geom2d_BSplineCurve(tpoles2d,
2276 mbspc.Multiplicities(),
2278 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2279 newCheck.FixTangent(Standard_True,Standard_True);
2282 bIsValid2=CheckPCurve(BS2, myFace2);
2284 aCurve.SetSecondCurve2d(BS2);
2287 Handle(Geom2d_BSplineCurve) BS2;
2288 fprm = BS->FirstParameter();
2289 lprm = BS->LastParameter();
2291 Handle(Geom2d_Curve) C2d;
2292 Standard_Real aTol = myTolApprox;
2293 BuildPCurves(fprm, lprm, aTol, myHS2->ChangeSurface().Surface(), BS, C2d);
2294 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2295 aCurve.SetSecondCurve2d(BS2);
2298 if (!bIsValid1 || !bIsValid2) {
2299 myTolApprox=aTolApproxImp;//1.e-5;
2300 tol2d = myTolApprox;
2301 reApprox = Standard_True;
2305 mySeqOfCurve.Append(aCurve);
2311 }// case IntPatch_Walking:{
2314 case IntPatch_Restriction:
2322 //=======================================================================
2323 //function : BuildPCurves
2325 //=======================================================================
2326 void BuildPCurves (Standard_Real f,
2329 const Handle (Geom_Surface)& S,
2330 const Handle (Geom_Curve)& C,
2331 Handle (Geom2d_Curve)& C2d)
2334 Standard_Real umin,umax,vmin,vmax;
2339 // in class ProjLib_Function the range of parameters is shrank by 1.e-09
2340 if((l - f) > 2.e-09) {
2341 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2344 // proj. a circle that goes through the pole on a sphere to the sphere
2346 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2350 if((l - f) > Epsilon(Abs(f))) {
2351 GeomAPI_ProjectPointOnSurf aProjector1, aProjector2;
2352 gp_Pnt P1 = C->Value(f);
2353 gp_Pnt P2 = C->Value(l);
2354 aProjector1.Init(P1, S);
2355 aProjector2.Init(P2, S);
2357 if(aProjector1.IsDone() && aProjector2.IsDone()) {
2358 Standard_Real U=0., V=0.;
2359 aProjector1.LowerDistanceParameters(U, V);
2362 aProjector2.LowerDistanceParameters(U, V);
2365 if(p1.Distance(p2) > gp::Resolution()) {
2366 TColgp_Array1OfPnt2d poles(1,2);
2367 TColStd_Array1OfReal knots(1,2);
2368 TColStd_Array1OfInteger mults(1,2);
2373 mults(1) = mults(2) = 2;
2375 C2d = new Geom2d_BSplineCurve(poles,knots,mults,1);
2377 // compute reached tolerance.begin
2378 gp_Pnt PMid = C->Value((f + l) * 0.5);
2379 aProjector1.Perform(PMid);
2381 if(aProjector1.IsDone()) {
2382 aProjector1.LowerDistanceParameters(U, V);
2383 gp_Pnt2d pmidproj(U, V);
2384 gp_Pnt2d pmidcurve2d = C2d->Value((f + l) * 0.5);
2385 Standard_Real adist = pmidcurve2d.Distance(pmidproj);
2386 Tol = (adist > Tol) ? adist : Tol;
2388 // compute reached tolerance.end
2394 S->Bounds(umin, umax, vmin, vmax);
2396 if (S->IsUPeriodic() && !C2d.IsNull()) {
2397 // Recadre dans le domaine UV de la face
2398 Standard_Real period, U0, du, aEps;
2401 aEps=Precision::PConfusion();
2402 period = S->UPeriod();
2403 gp_Pnt2d Pf = C2d->Value(f);
2406 gp_Pnt2d Pl = C2d->Value(l);
2408 U0 = Min(Pl.X(), U0);
2409 // while(U0-umin<aEps) {
2410 while(U0-umin<-aEps) {
2415 while(U0-umax>aEps) {
2427 //=======================================================================
2428 //function : Parameters
2430 //=======================================================================
2431 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
2432 const Handle(GeomAdaptor_HSurface)& HS2,
2433 const gp_Pnt& Ptref,
2440 IntSurf_Quadric quad1,quad2;
2441 GeomAbs_SurfaceType typs = HS1->Surface().GetType();
2445 quad1.SetValue(HS1->Surface().Plane());
2447 case GeomAbs_Cylinder:
2448 quad1.SetValue(HS1->Surface().Cylinder());
2451 quad1.SetValue(HS1->Surface().Cone());
2453 case GeomAbs_Sphere:
2454 quad1.SetValue(HS1->Surface().Sphere());
2457 quad1.SetValue(HS1->Surface().Torus());
2460 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2463 typs = HS2->Surface().GetType();
2466 quad2.SetValue(HS2->Surface().Plane());
2468 case GeomAbs_Cylinder:
2469 quad2.SetValue(HS2->Surface().Cylinder());
2472 quad2.SetValue(HS2->Surface().Cone());
2474 case GeomAbs_Sphere:
2475 quad2.SetValue(HS2->Surface().Sphere());
2478 quad2.SetValue(HS2->Surface().Torus());
2481 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2484 quad1.Parameters(Ptref,U1,V1);
2485 quad2.Parameters(Ptref,U2,V2);
2488 //=======================================================================
2489 //function : MakeBSpline
2491 //=======================================================================
2492 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
2493 const Standard_Integer ideb,
2494 const Standard_Integer ifin)
2496 Standard_Integer i,nbpnt = ifin-ideb+1;
2497 TColgp_Array1OfPnt poles(1,nbpnt);
2498 TColStd_Array1OfReal knots(1,nbpnt);
2499 TColStd_Array1OfInteger mults(1,nbpnt);
2500 Standard_Integer ipidebm1;
2501 for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) {
2502 poles(i) = WL->Point(ipidebm1).Value();
2506 mults(1) = mults(nbpnt) = 2;
2508 new Geom_BSplineCurve(poles,knots,mults,1);
2512 //=======================================================================
2513 //function : MakeBSpline2d
2515 //=======================================================================
2516 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
2517 const Standard_Integer ideb,
2518 const Standard_Integer ifin,
2519 const Standard_Boolean onFirst)
2521 Standard_Integer i, nbpnt = ifin-ideb+1;
2522 TColgp_Array1OfPnt2d poles(1,nbpnt);
2523 TColStd_Array1OfReal knots(1,nbpnt);
2524 TColStd_Array1OfInteger mults(1,nbpnt);
2525 Standard_Integer ipidebm1;
2527 for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
2530 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
2532 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
2533 poles(i).SetCoord(U, V);
2537 mults(1) = mults(nbpnt) = 2;
2539 return new Geom2d_BSplineCurve(poles,knots,mults,1);
2541 //=======================================================================
2542 //function : PrepareLines3D
2544 //=======================================================================
2545 void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit)
2547 Standard_Integer i, aNbCurves;
2548 GeomAbs_SurfaceType aType1, aType2;
2549 IntTools_SequenceOfCurves aNewCvs;
2551 // 1. Treatment closed curves
2552 aNbCurves=mySeqOfCurve.Length();
2553 for (i=1; i<=aNbCurves; ++i) {
2554 const IntTools_Curve& aIC=mySeqOfCurve(i);
2557 Standard_Integer j, aNbC;
2558 IntTools_SequenceOfCurves aSeqCvs;
2560 aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
2562 for (j=1; j<=aNbC; ++j) {
2563 const IntTools_Curve& aICNew=aSeqCvs(j);
2564 aNewCvs.Append(aICNew);
2568 aNewCvs.Append(aIC);
2572 aNewCvs.Append(aIC);
2576 // 2. Plane\Cone intersection when we had 4 curves
2577 aType1=myHS1->GetType();
2578 aType2=myHS2->GetType();
2579 aNbCurves=aNewCvs.Length();
2581 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) ||
2582 (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) {
2584 GeomAbs_CurveType aCType1;
2586 aCType1=aNewCvs(1).Type();
2587 if (aCType1==GeomAbs_Line) {
2588 IntTools_SequenceOfCurves aSeqIn, aSeqOut;
2590 for (i=1; i<=aNbCurves; ++i) {
2591 const IntTools_Curve& aIC=aNewCvs(i);
2595 IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
2598 aNbCurves=aSeqOut.Length();
2599 for (i=1; i<=aNbCurves; ++i) {
2600 const IntTools_Curve& aIC=aSeqOut(i);
2601 aNewCvs.Append(aIC);
2605 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)...
2607 // 3. Fill mySeqOfCurve
2608 mySeqOfCurve.Clear();
2609 aNbCurves=aNewCvs.Length();
2610 for (i=1; i<=aNbCurves; ++i) {
2611 const IntTools_Curve& aIC=aNewCvs(i);
2612 mySeqOfCurve.Append(aIC);
2615 //=======================================================================
2616 //function : CorrectSurfaceBoundaries
2618 //=======================================================================
2619 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
2620 const Standard_Real theTolerance,
2621 Standard_Real& theumin,
2622 Standard_Real& theumax,
2623 Standard_Real& thevmin,
2624 Standard_Real& thevmax)
2626 Standard_Boolean enlarge, isuperiodic, isvperiodic;
2627 Standard_Real uinf, usup, vinf, vsup, delta;
2628 GeomAbs_SurfaceType aType;
2629 Handle(Geom_Surface) aSurface;
2631 aSurface = BRep_Tool::Surface(theFace);
2632 aSurface->Bounds(uinf, usup, vinf, vsup);
2633 delta = theTolerance;
2634 enlarge = Standard_False;
2636 GeomAdaptor_Surface anAdaptorSurface(aSurface);
2638 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
2639 Handle(Geom_Surface) aBasisSurface =
2640 (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface();
2642 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2643 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2648 if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2649 Handle(Geom_Surface) aBasisSurface =
2650 (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface();
2652 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2653 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2658 isuperiodic = anAdaptorSurface.IsUPeriodic();
2659 isvperiodic = anAdaptorSurface.IsVPeriodic();
2661 aType=anAdaptorSurface.GetType();
2662 if((aType==GeomAbs_BezierSurface) ||
2663 (aType==GeomAbs_BSplineSurface) ||
2664 (aType==GeomAbs_SurfaceOfExtrusion) ||
2665 (aType==GeomAbs_SurfaceOfRevolution)) {
2666 enlarge=Standard_True;
2669 if(!isuperiodic && enlarge) {
2671 if((theumin - uinf) > delta )
2677 if((usup - theumax) > delta )
2683 if(!isvperiodic && enlarge) {
2684 if((thevmin - vinf) > delta ) {
2690 if((vsup - thevmax) > delta ) {
2699 Standard_Integer aNbP;
2700 Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA;
2702 aTolPA=Precision::Angular();
2705 aXP=anAdaptorSurface.UPeriod();
2706 dXfact=theumax-theumin;
2707 if (dXfact-aTolPA>aXP) {
2708 aXmid=0.5*(theumax+theumin);
2709 aNbP=RealToInt(aXmid/aXP);
2714 if (theumin>aTolPA) {
2715 aX1=theumin+aNbP*aXP;
2728 aXP=anAdaptorSurface.VPeriod();
2729 dXfact=thevmax-thevmin;
2730 if (dXfact-aTolPA>aXP) {
2731 aXmid=0.5*(thevmax+thevmin);
2732 aNbP=RealToInt(aXmid/aXP);
2737 if (thevmin>aTolPA) {
2738 aX1=thevmin+aNbP*aXP;
2751 if(isuperiodic || isvperiodic) {
2752 Standard_Boolean correct = Standard_False;
2753 Standard_Boolean correctU = Standard_False;
2754 Standard_Boolean correctV = Standard_False;
2756 TopExp_Explorer anExp;
2758 for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2759 if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
2760 correct = Standard_True;
2762 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
2764 for(Standard_Integer i = 0; i < 2; i++) {
2766 anEdge.Orientation(TopAbs_FORWARD);
2769 anEdge.Orientation(TopAbs_REVERSED);
2771 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
2773 if(aCurve.IsNull()) {
2774 correct = Standard_False;
2777 Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
2779 if(aLine.IsNull()) {
2780 correct = Standard_False;
2783 gp_Dir2d anUDir(1., 0.);
2784 gp_Dir2d aVDir(0., 1.);
2785 Standard_Real anAngularTolerance = Precision::Angular();
2787 correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
2788 correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
2790 gp_Pnt2d pp1 = aCurve->Value(f);
2792 gp_Pnt2d pp2 = aCurve->Value(l);
2801 Standard_Real umin, vmin, umax, vmax;
2802 aBox.Get(umin, vmin, umax, vmax);
2804 if(isuperiodic && correctU) {
2809 if(theumax > umax) {
2813 if(isvperiodic && correctV) {
2825 // The block is dedicated to determine whether WLine [ifprm, ilprm]
2826 // crosses the degenerated zone on each given surface or not.
2827 // If Yes -> We will not use info about surfaces during approximation
2828 // because inside degenerated zone of the surface the approx. algo.
2829 // uses wrong values of normal, etc., and resulting curve will have
2830 // oscillations that we would not like to have.
2835 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2836 const Handle(Geom_Surface)& aS,
2837 const Standard_Integer iDir);
2839 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2840 const TopoDS_Face& aF1,
2841 const TopoDS_Face& aF2);
2842 //=======================================================================
2843 //function : NotUseSurfacesForApprox
2845 //=======================================================================
2846 Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
2847 const TopoDS_Face& aF2,
2848 const Handle(IntPatch_WLine)& WL,
2849 const Standard_Integer ifprm,
2850 const Standard_Integer ilprm)
2852 Standard_Boolean bPInDZ;
2854 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
2856 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
2857 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
2862 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
2863 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
2867 //=======================================================================
2868 //function : IsPointInDegeneratedZone
2870 //=======================================================================
2871 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2872 const TopoDS_Face& aF1,
2873 const TopoDS_Face& aF2)
2876 Standard_Boolean bFlag=Standard_True;
2877 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
2878 Standard_Real U1, V1, U2, V2, aDelta, aD;
2881 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
2882 aS1->Bounds(US11, US12, VS11, VS12);
2883 GeomAdaptor_Surface aGAS1(aS1);
2885 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
2886 aS1->Bounds(US21, US22, VS21, VS22);
2887 GeomAdaptor_Surface aGAS2(aS2);
2889 //const gp_Pnt& aP=aP2S.Value();
2890 aP2S.Parameters(U1, V1, U2, V2);
2894 aD=aGAS1.UResolution(aDelta);
2895 aP2d.SetCoord(U1, V1);
2896 if (fabs(U1-US11) < aD) {
2897 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2902 if (fabs(U1-US12) < aD) {
2903 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2908 aD=aGAS1.VResolution(aDelta);
2909 if (fabs(V1-VS11) < aDelta) {
2910 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2915 if (fabs(V1-VS12) < aDelta) {
2916 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2922 aD=aGAS2.UResolution(aDelta);
2923 aP2d.SetCoord(U2, V2);
2924 if (fabs(U2-US21) < aDelta) {
2925 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2930 if (fabs(U2-US22) < aDelta) {
2931 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2936 aD=aGAS2.VResolution(aDelta);
2937 if (fabs(V2-VS21) < aDelta) {
2938 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2943 if (fabs(V2-VS22) < aDelta) {
2944 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2952 //=======================================================================
2953 //function : IsDegeneratedZone
2955 //=======================================================================
2956 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2957 const Handle(Geom_Surface)& aS,
2958 const Standard_Integer iDir)
2960 Standard_Boolean bFlag=Standard_True;
2961 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
2962 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
2963 aS->Bounds(US1, US2, VS1, VS2);
2965 gp_Pnt aPm, aPb, aPe;
2970 aS->D0(aXm, aYm, aPm);
2987 aS->D0(aXb, aYb, aPb);
2988 aS->D0(aXe, aYe, aPe);
2990 d1=aPm.Distance(aPb);
2991 d2=aPm.Distance(aPe);
2992 if (d1 < dD && d2 < dD) {
3009 aS->D0(aXb, aYb, aPb);
3010 aS->D0(aXe, aYe, aPe);
3012 d1=aPm.Distance(aPb);
3013 d2=aPm.Distance(aPe);
3014 if (d1 < dD && d2 < dD) {
3022 //=========================================================================
3023 // static function : ComputePurgedWLine
3024 // purpose : Removes equal points (leave one of equal points) from theWLine
3025 // and recompute vertex parameters.
3026 // Returns new WLine or null WLine if the number
3027 // of the points is less than 2.
3028 //=========================================================================
3029 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) {
3031 Standard_Integer i, k, v, nb, nbvtx;
3032 Handle(IntPatch_WLine) aResult;
3033 nbvtx = theWLine->NbVertex();
3034 nb = theWLine->NbPnts();
3036 const IntSurf_PntOn2S& p1 = theWLine->Point(1);
3037 const IntSurf_PntOn2S& p2 = theWLine->Point(2);
3038 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
3043 Handle(IntPatch_WLine) aLocalWLine;
3044 Handle(IntPatch_WLine) aTmpWLine = theWLine;
3045 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
3046 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
3047 for(i = 1; i <= nb; i++) {
3048 aLineOn2S->Add(theWLine->Point(i));
3051 for(v = 1; v <= nbvtx; v++) {
3052 aLocalWLine->AddVertex(theWLine->Vertex(v));
3055 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
3056 Standard_Integer aStartIndex = i + 1;
3057 Standard_Integer anEndIndex = i + 5;
3058 nb = aLineOn2S->NbPoints();
3059 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
3061 if((aStartIndex > nb) || (anEndIndex <= 1)) {
3066 while(k <= anEndIndex) {
3069 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
3070 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
3072 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
3073 aTmpWLine = aLocalWLine;
3074 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
3076 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
3077 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
3078 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
3080 if(avertexindex >= k) {
3081 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
3083 aLocalWLine->AddVertex(aVertex);
3085 aLineOn2S->RemovePoint(k);
3094 if(aLineOn2S->NbPoints() > 1) {
3095 aResult = aLocalWLine;
3100 //=======================================================================
3103 //=======================================================================
3104 void TolR3d(const TopoDS_Face& aF1,
3105 const TopoDS_Face& aF2,
3106 Standard_Real& myTolReached3d)
3108 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
3110 aTolTresh=2.999999e-3;
3111 aTolF1 = BRep_Tool::Tolerance(aF1);
3112 aTolF2 = BRep_Tool::Tolerance(aF2);
3113 aTolFMax=Max(aTolF1, aTolF2);
3115 if (aTolFMax>aTolTresh) {
3116 myTolReached3d=aTolFMax;
3119 //=======================================================================
3120 //function : AdjustPeriodic
3122 //=======================================================================
3123 Standard_Real AdjustPeriodic(const Standard_Real theParameter,
3124 const Standard_Real parmin,
3125 const Standard_Real parmax,
3126 const Standard_Real thePeriod,
3127 Standard_Real& theOffset)
3129 Standard_Real aresult;
3132 aresult = theParameter;
3133 while(aresult < parmin) {
3134 aresult += thePeriod;
3135 theOffset += thePeriod;
3138 while(aresult > parmax) {
3139 aresult -= thePeriod;
3140 theOffset -= thePeriod;
3144 //=======================================================================
3145 //function : IsPointOnBoundary
3147 //=======================================================================
3148 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
3149 const Standard_Real theFirstBoundary,
3150 const Standard_Real theSecondBoundary,
3151 const Standard_Real theResolution,
3152 Standard_Boolean& IsOnFirstBoundary)
3154 Standard_Boolean bRet;
3156 Standard_Real adist;
3158 bRet=Standard_False;
3159 for(i = 0; i < 2; ++i) {
3160 IsOnFirstBoundary = (i == 0);
3161 if (IsOnFirstBoundary) {
3162 adist = fabs(theParameter - theFirstBoundary);
3165 adist = fabs(theParameter - theSecondBoundary);
3167 if(adist < theResolution) {
3173 // ------------------------------------------------------------------------------------------------
3174 // static function: FindPoint
3176 // ------------------------------------------------------------------------------------------------
3177 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3178 const gp_Pnt2d& theLastPoint,
3179 const Standard_Real theUmin,
3180 const Standard_Real theUmax,
3181 const Standard_Real theVmin,
3182 const Standard_Real theVmax,
3183 gp_Pnt2d& theNewPoint) {
3185 gp_Vec2d aVec(theFirstPoint, theLastPoint);
3186 Standard_Integer i = 0, j = 0;
3188 for(i = 0; i < 4; i++) {
3189 gp_Vec2d anOtherVec;
3190 gp_Vec2d anOtherVecNormal;
3191 gp_Pnt2d aprojpoint = theLastPoint;
3194 anOtherVec.SetX(0.);
3195 anOtherVec.SetY(1.);
3196 anOtherVecNormal.SetX(1.);
3197 anOtherVecNormal.SetY(0.);
3200 aprojpoint.SetX(theUmin);
3202 aprojpoint.SetX(theUmax);
3205 anOtherVec.SetX(1.);
3206 anOtherVec.SetY(0.);
3207 anOtherVecNormal.SetX(0.);
3208 anOtherVecNormal.SetY(1.);
3211 aprojpoint.SetY(theVmin);
3213 aprojpoint.SetY(theVmax);
3215 gp_Vec2d anormvec = aVec;
3216 anormvec.Normalize();
3217 RefineVector(anormvec);
3218 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
3220 if(fabs(adot1) < Precision::Angular())
3222 Standard_Real adist = 0.;
3223 Standard_Boolean bIsOut = Standard_False;
3226 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
3227 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
3230 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
3231 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
3233 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
3235 for(j = 0; j < 2; j++) {
3236 anoffset = (j == 0) ? anoffset : -anoffset;
3237 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
3238 gp_Vec2d acurvec(theLastPoint, acurpoint);
3242 Standard_Real aDotX, anAngleX;
3244 aDotX = aVec.Dot(acurvec);
3245 anAngleX = aVec.Angle(acurvec);
3247 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
3249 if((acurpoint.Y() >= theVmin) &&
3250 (acurpoint.Y() <= theVmax)) {
3251 theNewPoint = acurpoint;
3252 return Standard_True;
3256 if((acurpoint.X() >= theUmin) &&
3257 (acurpoint.X() <= theUmax)) {
3258 theNewPoint = acurpoint;
3259 return Standard_True;
3265 return Standard_False;
3269 // ------------------------------------------------------------------------------------------------
3270 // static function: FindPoint
3271 // purpose: Find point on the boundary of radial tangent zone
3272 // ------------------------------------------------------------------------------------------------
3273 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3274 const gp_Pnt2d& theLastPoint,
3275 const Standard_Real theUmin,
3276 const Standard_Real theUmax,
3277 const Standard_Real theVmin,
3278 const Standard_Real theVmax,
3279 const gp_Pnt2d& theTanZoneCenter,
3280 const Standard_Real theZoneRadius,
3281 Handle(GeomAdaptor_HSurface) theGASurface,
3282 gp_Pnt2d& theNewPoint) {
3283 theNewPoint = theLastPoint;
3285 if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
3286 return Standard_False;
3288 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3289 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3291 Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3292 gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) );
3293 gp_Circ2d aCircle( anAxis, aRadius );
3296 gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() );
3297 Standard_Real aLength = aDir.Magnitude();
3298 if ( aLength <= gp::Resolution() )
3299 return Standard_False;
3300 gp_Lin2d aLine( theFirstPoint, aDir );
3303 Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine );
3304 Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength );
3305 Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle );
3307 Standard_Real aTol = aRadius * 0.001;
3308 aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol;
3310 Geom2dAPI_InterCurveCurve anIntersector;
3311 anIntersector.Init( aC1, aC2, aTol );
3313 if ( anIntersector.NbPoints() == 0 )
3314 return Standard_False;
3316 Standard_Boolean aFound = Standard_False;
3317 Standard_Real aMinDist = aLength * aLength;
3318 Standard_Integer i = 0;
3319 for ( i = 1; i <= anIntersector.NbPoints(); i++ ) {
3320 gp_Pnt2d aPInt = anIntersector.Point( i );
3321 if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
3322 if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
3323 ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
3324 theNewPoint = aPInt;
3325 aFound = Standard_True;
3333 // ------------------------------------------------------------------------------------------------
3334 // static function: IsInsideTanZone
3335 // purpose: Check if point is inside a radial tangent zone
3336 // ------------------------------------------------------------------------------------------------
3337 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
3338 const gp_Pnt2d& theTanZoneCenter,
3339 const Standard_Real theZoneRadius,
3340 Handle(GeomAdaptor_HSurface) theGASurface) {
3342 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3343 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3344 Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3345 aRadiusSQR *= aRadiusSQR;
3346 if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR )
3347 return Standard_True;
3348 return Standard_False;
3351 // ------------------------------------------------------------------------------------------------
3352 // static function: CheckTangentZonesExist
3353 // purpose: Check if tangent zone exists
3354 // ------------------------------------------------------------------------------------------------
3355 Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
3356 const Handle(GeomAdaptor_HSurface)& theSurface2 )
3358 if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
3359 ( theSurface2->GetType() != GeomAbs_Torus ) )
3360 return Standard_False;
3362 gp_Torus aTor1 = theSurface1->Torus();
3363 gp_Torus aTor2 = theSurface2->Torus();
3365 if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() )
3366 return Standard_False;
3368 if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) ||
3369 ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) )
3370 return Standard_False;
3372 if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) ||
3373 ( aTor2.MajorRadius() < aTor2.MinorRadius() ) )
3374 return Standard_False;
3375 return Standard_True;
3378 // ------------------------------------------------------------------------------------------------
3379 // static function: ComputeTangentZones
3381 // ------------------------------------------------------------------------------------------------
3382 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
3383 const Handle(GeomAdaptor_HSurface)& theSurface2,
3384 const TopoDS_Face& theFace1,
3385 const TopoDS_Face& theFace2,
3386 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
3387 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
3388 Handle(TColStd_HArray1OfReal)& theResultRadius,
3389 const Handle(BOPInt_Context)& aContext)
3391 Standard_Integer aResult = 0;
3392 if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) )
3396 TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2;
3397 TColStd_SequenceOfReal aSeqResultRad;
3399 gp_Torus aTor1 = theSurface1->Torus();
3400 gp_Torus aTor2 = theSurface2->Torus();
3402 gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() );
3403 gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() );
3404 Standard_Integer j = 0;
3406 for ( j = 0; j < 2; j++ ) {
3407 Standard_Real aCoef = ( j == 0 ) ? -1 : 1;
3408 Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius());
3409 Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius());
3411 gp_Circ aCircle1( anax1, aRadius1 );
3412 gp_Circ aCircle2( anax2, aRadius2 );
3414 // roughly compute radius of tangent zone for perpendicular case
3415 Standard_Real aCriteria = Precision::Confusion() * 0.5;
3417 Standard_Real aT1 = aCriteria;
3418 Standard_Real aT2 = aCriteria;
3420 // internal tangency
3421 Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3422 //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria );
3423 aT1 = 2. * aR * aCriteria;
3427 // external tangency
3428 Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3429 Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3430 Standard_Real aDelta = aRb - aCriteria;
3432 aDelta -= aRm * aRm;
3433 aDelta /= 2. * (aRb - aRm);
3434 aDelta -= 0.5 * (aRb - aRm);
3436 aT1 = 2. * aRm * (aRm - aDelta);
3439 aCriteria = ( aT1 > aT2) ? aT1 : aT2;
3440 if ( aCriteria > 0 )
3441 aCriteria = sqrt( aCriteria );
3443 if ( aCriteria > 0.5 * aTor1.MinorRadius() ) {
3444 // too big zone -> drop to minimum
3445 aCriteria = Precision::Confusion();
3448 GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) );
3449 GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) );
3450 Extrema_ExtCC anExtrema(aC1, aC2, 0, 2. * M_PI, 0, 2. * M_PI,
3451 Precision::PConfusion(), Precision::PConfusion());
3453 if ( anExtrema.IsDone() ) {
3455 Standard_Integer i = 0;
3456 for ( i = 1; i <= anExtrema.NbExt(); i++ ) {
3457 if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
3460 Extrema_POnCurv P1, P2;
3461 anExtrema.Points( i, P1, P2 );
3463 Standard_Boolean bFoundResult = Standard_True;
3466 Standard_Integer surfit = 0;
3467 for ( surfit = 0; surfit < 2; surfit++ ) {
3468 GeomAPI_ProjectPointOnSurf& aProjector =
3469 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3471 gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
3472 aProjector.Perform(aP3d);
3474 if(!aProjector.IsDone())
3475 bFoundResult = Standard_False;
3477 if(aProjector.LowerDistance() > aCriteria) {
3478 bFoundResult = Standard_False;
3481 Standard_Real foundU = 0, foundV = 0;
3482 aProjector.LowerDistanceParameters(foundU, foundV);
3484 pr1 = gp_Pnt2d( foundU, foundV );
3486 pr2 = gp_Pnt2d( foundU, foundV );
3490 if ( bFoundResult ) {
3491 aSeqResultS1.Append( pr1 );
3492 aSeqResultS2.Append( pr2 );
3493 aSeqResultRad.Append( aCriteria );
3495 // torus is u and v periodic
3496 const Standard_Real twoPI = M_PI + M_PI;
3497 Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
3498 Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
3500 // iteration on period bounds
3501 for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
3502 Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
3503 Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
3505 // iteration on surfaces
3506 for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
3507 Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
3508 Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
3509 TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
3510 TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
3512 if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
3513 aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
3514 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3515 aSeqResultRad.Append( aCriteria );
3517 if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
3518 aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
3519 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3520 aSeqResultRad.Append( aCriteria );
3528 aResult = aSeqResultRad.Length();
3530 if ( aResult > 0 ) {
3531 theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult );
3532 theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult );
3533 theResultRadius = new TColStd_HArray1OfReal( 1, aResult );
3535 for ( Standard_Integer i = 1 ; i <= aResult; i++ ) {
3536 theResultOnS1->SetValue( i, aSeqResultS1.Value(i) );
3537 theResultOnS2->SetValue( i, aSeqResultS2.Value(i) );
3538 theResultRadius->SetValue( i, aSeqResultRad.Value(i) );
3544 // ------------------------------------------------------------------------------------------------
3545 // static function: AdjustByNeighbour
3547 // ------------------------------------------------------------------------------------------------
3548 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
3549 const gp_Pnt2d& theOriginalPoint,
3550 Handle(GeomAdaptor_HSurface) theGASurface) {
3552 gp_Pnt2d ap1 = theaNeighbourPoint;
3553 gp_Pnt2d ap2 = theOriginalPoint;
3555 if ( theGASurface->IsUPeriodic() ) {
3556 Standard_Real aPeriod = theGASurface->UPeriod();
3557 gp_Pnt2d aPTest = ap2;
3558 Standard_Real aSqDistMin = 1.e+100;
3560 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3561 aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt );
3562 Standard_Real dd = ap1.SquareDistance( aPTest );
3564 if ( dd < aSqDistMin ) {
3570 if ( theGASurface->IsVPeriodic() ) {
3571 Standard_Real aPeriod = theGASurface->VPeriod();
3572 gp_Pnt2d aPTest = ap2;
3573 Standard_Real aSqDistMin = 1.e+100;
3575 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3576 aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt );
3577 Standard_Real dd = ap1.SquareDistance( aPTest );
3579 if ( dd < aSqDistMin ) {
3588 // ------------------------------------------------------------------------------------------------
3589 //function: DecompositionOfWLine
3591 // ------------------------------------------------------------------------------------------------
3592 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
3593 const Handle(GeomAdaptor_HSurface)& theSurface1,
3594 const Handle(GeomAdaptor_HSurface)& theSurface2,
3595 const TopoDS_Face& theFace1,
3596 const TopoDS_Face& theFace2,
3597 const IntTools_LineConstructor& theLConstructor,
3598 const Standard_Boolean theAvoidLConstructor,
3599 IntPatch_SequenceOfLine& theNewLines,
3600 Standard_Real& theReachedTol3d,
3601 const Handle(BOPInt_Context)& aContext)
3604 Standard_Boolean bRet, bAvoidLineConstructor;
3605 Standard_Integer aNbPnts, aNbParts;
3607 bRet=Standard_False;
3608 aNbPnts=theWLine->NbPnts();
3609 bAvoidLineConstructor=theAvoidLConstructor;
3614 if (!bAvoidLineConstructor) {
3615 aNbParts=theLConstructor.NbParts();
3621 Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary;
3622 Standard_Integer nblines, pit, i, j;
3624 TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts);
3625 TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts);
3626 TColStd_ListOfInteger aListOfPointIndex;
3628 Handle(TColgp_HArray1OfPnt2d) aTanZoneS1;
3629 Handle(TColgp_HArray1OfPnt2d) aTanZoneS2;
3630 Handle(TColStd_HArray1OfReal) aTanZoneRadius;
3631 Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2,
3632 aTanZoneS1, aTanZoneS2, aTanZoneRadius, aContext);
3636 aTol=Precision::Confusion();
3638 bIsPrevPointOnBoundary=Standard_False;
3639 bIsPointOnBoundary=Standard_False;
3644 for(pit = 1; pit <= aNbPnts; ++pit) {
3645 Standard_Boolean bIsOnFirstBoundary, isperiodic;
3646 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
3647 Standard_Real aParameter, anoffset, anAdjustPar;
3648 Standard_Real umin, umax, vmin, vmax;
3650 bIsCurrentPointOnBoundary = Standard_False;
3651 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
3654 for(i = 0; i < 2; ++i) {
3655 Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
3656 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3658 aPoint.ParametersOnS1(U, V);
3661 aPoint.ParametersOnS2(U, V);
3664 for(j = 0; j < 2; j++) {
3665 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3671 aResolution=aGASurface->UResolution(aTol);
3672 aPeriod=aGASurface->UPeriod();
3673 alowerboundary=umin;
3674 aupperboundary=umax;
3678 aResolution=aGASurface->VResolution(aTol);
3679 aPeriod=aGASurface->VPeriod();
3680 alowerboundary=vmin;
3681 aupperboundary=vmax;
3686 anAdjustPar = AdjustPeriodic(aParameter,
3692 bIsOnFirstBoundary = Standard_True;// ?
3694 IsPointOnBoundary(anAdjustPar,
3698 bIsOnFirstBoundary);
3700 if(bIsPointOnBoundary) {
3701 bIsCurrentPointOnBoundary = Standard_True;
3705 // check if a point belong to a tangent zone. Begin
3706 Standard_Integer zIt = 0;
3707 for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
3708 gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3709 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3711 if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
3712 // set boundary flag to split the curve by a tangent zone
3713 bIsPointOnBoundary = Standard_True;
3714 bIsCurrentPointOnBoundary = Standard_True;
3715 if ( theReachedTol3d < aZoneRadius ) {
3716 theReachedTol3d = aZoneRadius;
3722 }//for(j = 0; j < 2; j++) {
3724 if(bIsCurrentPointOnBoundary){
3727 }//for(i = 0; i < 2; ++i) {
3729 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
3730 if(!aListOfPointIndex.IsEmpty()) {
3732 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3733 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3734 aListOfPointIndex.Clear();
3736 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
3738 aListOfPointIndex.Append(pit);
3739 } //for(pit = 1; pit <= aNbPnts; ++pit) {
3741 if(!aListOfPointIndex.IsEmpty()) {
3743 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3744 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3745 aListOfPointIndex.Clear();
3749 return bRet; //Standard_False;
3753 // 2. Correct wlines.begin
3754 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
3755 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S();
3757 for(i = 1; i <= nblines; i++) {
3758 if(anArrayOfLineType.Value(i) != 0) {
3761 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3762 if(aListOfIndex.Extent() < 2) {
3765 TColStd_ListOfInteger aListOfFLIndex;
3767 for(j = 0; j < 2; j++) {
3768 Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1);
3770 if((aneighbourindex < 1) || (aneighbourindex > nblines))
3773 if(anArrayOfLineType.Value(aneighbourindex) == 0)
3775 const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex);
3776 Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First();
3777 const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
3779 IntSurf_PntOn2S aNewP = aPoint;
3781 for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
3783 Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
3784 Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
3785 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3786 Standard_Real U=0., V=0.;
3789 aNewP.ParametersOnS1(U, V);
3791 aNewP.ParametersOnS2(U, V);
3792 Standard_Integer nbboundaries = 0;
3794 Standard_Boolean bIsNearBoundary = Standard_False;
3795 Standard_Integer aZoneIndex = 0;
3796 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
3797 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
3800 for(Standard_Integer parit = 0; parit < 2; parit++) {
3801 Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3803 Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
3804 Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
3805 Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
3807 Standard_Real aParameter = (parit == 0) ? U : V;
3808 Standard_Boolean bIsOnFirstBoundary = Standard_True;
3812 IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3813 if(bIsPointOnBoundary) {
3814 bIsUBoundary = (parit == 0);
3815 bIsFirstBoundary = bIsOnFirstBoundary;
3820 Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3821 Standard_Real anoffset = 0.;
3822 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3825 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3826 if(bIsPointOnBoundary) {
3827 bIsUBoundary = (parit == 0);
3828 bIsFirstBoundary = bIsOnFirstBoundary;
3832 //check neighbourhood of boundary
3833 Standard_Real anEpsilon = aResolution * 100.;
3834 Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
3835 anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
3837 bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
3838 anEpsilon, bIsOnFirstBoundary);
3844 // check if a point belong to a tangent zone. Begin
3845 for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
3846 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3847 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3849 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3850 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3851 Standard_Real nU1, nV1;
3854 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3856 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3857 gp_Pnt2d ap1(nU1, nV1);
3858 gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
3861 if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
3863 bIsNearBoundary = Standard_True;
3864 if ( theReachedTol3d < aZoneRadius ) {
3865 theReachedTol3d = aZoneRadius;
3869 // check if a point belong to a tangent zone. End
3870 Standard_Boolean bComputeLineEnd = Standard_False;
3872 if(nbboundaries == 2) {
3874 bComputeLineEnd = Standard_True;
3877 else if(nbboundaries == 1) {
3878 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3881 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
3882 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
3883 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3884 Standard_Real aParameter = (bIsUBoundary) ? U : V;
3885 Standard_Real anoffset = 0.;
3886 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3888 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
3889 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
3890 anotherPar += anoffset;
3891 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3892 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
3893 Standard_Real nU1, nV1;
3896 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3898 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3900 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
3901 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
3902 bComputeLineEnd = Standard_True;
3903 Standard_Boolean bCheckAngle1 = Standard_False;
3904 Standard_Boolean bCheckAngle2 = Standard_False;
3906 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
3907 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
3909 if(((adist1 - adist2) > Precision::PConfusion()) &&
3910 (adist2 < (aPeriod / 4.))) {
3911 bCheckAngle1 = Standard_True;
3912 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
3914 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3915 aNewP.SetValue((surfit == 0), anewU, anewV);
3916 bCheckAngle1 = Standard_False;
3919 else if(adist1 < (aPeriod / 4.)) {
3920 bCheckAngle2 = Standard_True;
3921 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
3923 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3924 bCheckAngle2 = Standard_False;
3928 if(bCheckAngle1 || bCheckAngle2) {
3929 // assume there are at least two points in line (see "if" above)
3930 Standard_Integer anindexother = aneighbourpointindex;
3932 while((anindexother <= aListOfIndex.Last()) && (anindexother >= aListOfIndex.First())) {
3933 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
3934 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
3935 Standard_Real nU2, nV2;
3938 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3940 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3941 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
3943 if(aVecOld.SquareMagnitude() <= (gp::Resolution() * gp::Resolution())) {
3947 Standard_Real anAngle = aNewVec.Angle(aVecOld);
3949 if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
3952 Standard_Real U1, U2, V1, V2;
3953 IntSurf_PntOn2S atmppoint = aNewP;
3954 atmppoint.SetValue((surfit == 0), anewU, anewV);
3955 atmppoint.Parameters(U1, V1, U2, V2);
3956 gp_Pnt P1 = theSurface1->Value(U1, V1);
3957 gp_Pnt P2 = theSurface2->Value(U2, V2);
3958 gp_Pnt P0 = aPoint.Value();
3960 if(P0.IsEqual(P1, aTol) &&
3961 P0.IsEqual(P2, aTol) &&
3962 P1.IsEqual(P2, aTol)) {
3963 bComputeLineEnd = Standard_False;
3964 aNewP.SetValue((surfit == 0), anewU, anewV);
3969 bComputeLineEnd = Standard_False;
3974 } // end while(anindexother...)
3978 else if ( bIsNearBoundary ) {
3979 bComputeLineEnd = Standard_True;
3982 if(bComputeLineEnd) {
3985 Standard_Boolean found = Standard_False;
3987 if ( bIsNearBoundary ) {
3988 // re-compute point near natural boundary or near tangent zone
3989 Standard_Real u1, v1, u2, v2;
3990 aNewP.Parameters( u1, v1, u2, v2 );
3992 anewpoint = gp_Pnt2d( u1, v1 );
3994 anewpoint = gp_Pnt2d( u2, v2 );
3996 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3997 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3998 Standard_Real nU1, nV1;
4001 aNeighbourPoint.ParametersOnS1(nU1, nV1);
4003 aNeighbourPoint.ParametersOnS2(nU1, nV1);
4004 gp_Pnt2d ap1(nU1, nV1);
4009 // exclude point from a tangent zone
4010 anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
4011 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
4012 Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
4014 if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
4015 aPZone, aZoneRadius, aGASurface, ap2) ) {
4017 found = Standard_True;
4020 else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
4021 // re-compute point near boundary if shifted on a period
4022 ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
4024 if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
4025 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
4026 found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
4030 aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
4036 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
4037 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
4038 Standard_Real nU1, nV1;
4041 aNeighbourPoint.ParametersOnS1(nU1, nV1);
4043 aNeighbourPoint.ParametersOnS2(nU1, nV1);
4044 gp_Pnt2d ap1(nU1, nV1);
4045 gp_Pnt2d ap2(nU1, nV1);
4046 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
4048 while((aneighbourpointindex2 <= aListOfIndex.Last()) && (aneighbourpointindex2 >= aListOfIndex.First())) {
4049 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
4050 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
4051 Standard_Real nU2, nV2;
4054 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
4056 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
4060 if(ap1.SquareDistance(ap2) > (gp::Resolution() * gp::Resolution())) {
4064 found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
4069 Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4070 GeomAPI_ProjectPointOnSurf& aProjector =
4071 (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
4072 Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
4074 Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
4076 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
4077 aProjector.Perform(aP3d);
4079 if(aProjector.IsDone()) {
4080 if(aProjector.LowerDistance() < aCriteria) {
4081 Standard_Real foundU = U, foundV = V;
4082 aProjector.LowerDistanceParameters(foundU, foundV);
4084 //Correction of projected coordinates. Begin
4085 //Note, it may be shifted on a period
4086 Standard_Integer aneindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
4087 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
4088 Standard_Real nUn, nVn;
4091 aNeighbourPoint.ParametersOnS2(nUn, nVn);
4093 aNeighbourPoint.ParametersOnS1(nUn, nVn);
4094 gp_Pnt2d aNeighbour2d(nUn, nVn);
4095 gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
4096 foundU = anAdjustedPoint.X();
4097 foundV = anAdjustedPoint.Y();
4099 if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
4100 ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
4101 // attempt to roughly re-compute point
4102 foundU = ( foundU < umin ) ? umin : foundU;
4103 foundU = ( foundU > umax ) ? umax : foundU;
4104 foundV = ( foundV < vmin ) ? vmin : foundV;
4105 foundV = ( foundV > vmax ) ? vmax : foundV;
4107 GeomAPI_ProjectPointOnSurf& aProjector2 =
4108 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
4110 aP3d = aSurfaceOther->Value(foundU, foundV);
4111 aProjector2.Perform(aP3d);
4113 if(aProjector2.IsDone()) {
4114 if(aProjector2.LowerDistance() < aCriteria) {
4115 Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
4116 aProjector2.LowerDistanceParameters(foundU2, foundV2);
4117 anewpoint.SetX(foundU2);
4118 anewpoint.SetY(foundV2);
4122 //Correction of projected coordinates. End
4125 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
4127 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
4133 aSeqOfPntOn2S->Add(aNewP);
4134 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
4136 anArrayOfLineEnds.SetValue(i, aListOfFLIndex);
4138 // Correct wlines.end
4140 // Split wlines.begin
4141 Standard_Integer nbiter;
4144 if (!bAvoidLineConstructor) {
4145 nbiter=theLConstructor.NbParts();
4148 for(j = 1; j <= nbiter; ++j) {
4149 Standard_Real fprm, lprm;
4150 Standard_Integer ifprm, ilprm;
4152 if(bAvoidLineConstructor) {
4154 ilprm = theWLine->NbPnts();
4157 theLConstructor.Part(j, fprm, lprm);
4158 ifprm = (Standard_Integer)fprm;
4159 ilprm = (Standard_Integer)lprm;
4162 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
4164 for(i = 1; i <= nblines; i++) {
4165 if(anArrayOfLineType.Value(i) != 0) {
4168 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
4170 if(aListOfIndex.Extent() < 2) {
4173 const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
4174 Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
4175 Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
4177 if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
4178 bhasfirstpoint = (i != 1);
4181 if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
4182 bhaslastpoint = (i != nblines);
4184 Standard_Boolean bIsFirstInside = ((ifprm >= aListOfIndex.First()) && (ifprm <= aListOfIndex.Last()));
4185 Standard_Boolean bIsLastInside = ((ilprm >= aListOfIndex.First()) && (ilprm <= aListOfIndex.Last()));
4187 if(!bIsFirstInside && !bIsLastInside) {
4188 if((ifprm < aListOfIndex.First()) && (ilprm > aListOfIndex.Last())) {
4189 // append whole line, and boundaries if neccesary
4190 if(bhasfirstpoint) {
4191 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
4194 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4196 for(; anIt.More(); anIt.Next()) {
4197 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4202 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
4206 // check end of split line (end is almost always)
4207 Standard_Integer aneighbour = i + 1;
4208 Standard_Boolean bIsEndOfLine = Standard_True;
4210 if(aneighbour <= nblines) {
4211 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4213 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4214 (aListOfNeighbourIndex.IsEmpty())) {
4215 bIsEndOfLine = Standard_False;
4220 if(aLineOn2S->NbPoints() > 1) {
4221 Handle(IntPatch_WLine) aNewWLine =
4222 new IntPatch_WLine(aLineOn2S, Standard_False);
4223 theNewLines.Append(aNewWLine);
4225 aLineOn2S = new IntSurf_LineOn2S();
4230 // end if(!bIsFirstInside && !bIsLastInside)
4232 if(bIsFirstInside && bIsLastInside) {
4233 // append inside points between ifprm and ilprm
4234 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4236 for(; anIt.More(); anIt.Next()) {
4237 if((anIt.Value() < ifprm) || (anIt.Value() > ilprm))
4239 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4245 if(bIsFirstInside) {
4246 // append points from ifprm to last point + boundary point
4247 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4249 for(; anIt.More(); anIt.Next()) {
4250 if(anIt.Value() < ifprm)
4252 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4257 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
4260 // check end of split line (end is almost always)
4261 Standard_Integer aneighbour = i + 1;
4262 Standard_Boolean bIsEndOfLine = Standard_True;
4264 if(aneighbour <= nblines) {
4265 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4267 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4268 (aListOfNeighbourIndex.IsEmpty())) {
4269 bIsEndOfLine = Standard_False;
4274 if(aLineOn2S->NbPoints() > 1) {
4275 Handle(IntPatch_WLine) aNewWLine =
4276 new IntPatch_WLine(aLineOn2S, Standard_False);
4277 theNewLines.Append(aNewWLine);
4279 aLineOn2S = new IntSurf_LineOn2S();
4282 // end if(bIsFirstInside)
4285 // append points from first boundary point to ilprm
4286 if(bhasfirstpoint) {
4287 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
4290 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4292 for(; anIt.More(); anIt.Next()) {
4293 if(anIt.Value() > ilprm)
4295 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4299 //end if(bIsLastInside)
4303 if(aLineOn2S->NbPoints() > 1) {
4304 Handle(IntPatch_WLine) aNewWLine =
4305 new IntPatch_WLine(aLineOn2S, Standard_False);
4306 theNewLines.Append(aNewWLine);
4311 return Standard_True;
4314 // ------------------------------------------------------------------------------------------------
4315 // static function: ParameterOutOfBoundary
4316 // purpose: Computes a new parameter for given curve. The corresponding 2d points
4317 // does not lay on any boundary of given faces
4318 // ------------------------------------------------------------------------------------------------
4319 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
4320 const Handle(Geom_Curve)& theCurve,
4321 const TopoDS_Face& theFace1,
4322 const TopoDS_Face& theFace2,
4323 const Standard_Real theOtherParameter,
4324 const Standard_Boolean bIncreasePar,
4325 Standard_Real& theNewParameter,
4326 const Handle(BOPInt_Context)& aContext)
4328 Standard_Boolean bIsComputed = Standard_False;
4329 theNewParameter = theParameter;
4331 Standard_Real acurpar = theParameter;
4332 TopAbs_State aState = TopAbs_ON;
4333 Standard_Integer iter = 0;
4334 Standard_Real asumtol = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4335 Standard_Real adelta = asumtol * 0.1;
4336 adelta = (adelta < Precision::Confusion()) ? Precision::Confusion() : adelta;
4337 Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(theFace1);
4338 Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(theFace2);
4340 Standard_Real u1, u2, v1, v2;
4342 GeomAPI_ProjectPointOnSurf aPrj1;
4343 aSurf1->Bounds(u1, u2, v1, v2);
4344 aPrj1.Init(aSurf1, u1, u2, v1, v2);
4346 GeomAPI_ProjectPointOnSurf aPrj2;
4347 aSurf2->Bounds(u1, u2, v1, v2);
4348 aPrj2.Init(aSurf2, u1, u2, v1, v2);
4350 while(aState == TopAbs_ON) {
4355 gp_Pnt aPCurrent = theCurve->Value(acurpar);
4356 aPrj1.Perform(aPCurrent);
4357 Standard_Real U=0., V=0.;
4359 if(aPrj1.IsDone()) {
4360 aPrj1.LowerDistanceParameters(U, V);
4361 aState = aContext->StatePointFace(theFace1, gp_Pnt2d(U, V));
4364 if(aState != TopAbs_ON) {
4365 aPrj2.Perform(aPCurrent);
4367 if(aPrj2.IsDone()) {
4368 aPrj2.LowerDistanceParameters(U, V);
4369 aState = aContext->StatePointFace(theFace2, gp_Pnt2d(U, V));
4380 theNewParameter = acurpar;
4381 bIsComputed = Standard_True;
4384 if(acurpar >= theOtherParameter)
4385 theNewParameter = theOtherParameter;
4388 if(acurpar <= theOtherParameter)
4389 theNewParameter = theOtherParameter;
4395 //=======================================================================
4396 //function : IsCurveValid
4398 //=======================================================================
4399 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve)
4401 if(thePCurve.IsNull())
4402 return Standard_False;
4404 Standard_Real tolint = 1.e-10;
4405 Geom2dAdaptor_Curve PCA;
4406 IntRes2d_Domain PCD;
4407 Geom2dInt_GInter PCI;
4409 Standard_Real pf = 0., pl = 0.;
4410 gp_Pnt2d pntf, pntl;
4412 if(!thePCurve->IsClosed() && !thePCurve->IsPeriodic()) {
4413 pf = thePCurve->FirstParameter();
4414 pl = thePCurve->LastParameter();
4415 pntf = thePCurve->Value(pf);
4416 pntl = thePCurve->Value(pl);
4417 PCA.Load(thePCurve);
4418 if(!PCA.IsPeriodic()) {
4419 if(PCA.FirstParameter() > pf) pf = PCA.FirstParameter();
4420 if(PCA.LastParameter() < pl) pl = PCA.LastParameter();
4422 PCD.SetValues(pntf,pf,tolint,pntl,pl,tolint);
4423 PCI.Perform(PCA,PCD,tolint,tolint);
4425 if(PCI.NbPoints() > 0) {
4426 return Standard_False;
4430 return Standard_True;
4433 //=======================================================================
4434 //static function : ApproxWithPCurves
4435 //purpose : for bug 20964 only
4436 //=======================================================================
4437 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
4438 const gp_Sphere& theSph)
4440 Standard_Boolean bRes = Standard_True;
4441 Standard_Real R1 = theCyl.Radius(), R2 = theSph.Radius();
4443 if(R1 < 2.*R2) return bRes;
4445 gp_Lin anCylAx(theCyl.Axis());
4447 Standard_Real aDist = anCylAx.Distance(theSph.Location());
4448 Standard_Real aDRel = Abs(aDist - R1)/R2;
4450 if(aDRel > .2) return bRes;
4452 Standard_Real par = ElCLib::Parameter(anCylAx, theSph.Location());
4453 gp_Pnt aP = ElCLib::Value(par, anCylAx);
4454 gp_Vec aV(aP, theSph.Location());
4456 Standard_Real dd = aV.Dot(theSph.Position().XDirection());
4458 if(aDist < R1 && dd > 0.) return Standard_False;
4459 if(aDist > R1 && dd < 0.) return Standard_False;
4464 //=======================================================================
4465 //function : PerformPlanes
4467 //=======================================================================
4468 void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
4469 const Handle(GeomAdaptor_HSurface)& theS2,
4470 const Standard_Real TolAng,
4471 const Standard_Real TolTang,
4472 const Standard_Boolean theApprox1,
4473 const Standard_Boolean theApprox2,
4474 IntTools_SequenceOfCurves& theSeqOfCurve,
4475 Standard_Boolean& theTangentFaces)
4478 gp_Pln aPln1 = theS1->Surface().Plane();
4479 gp_Pln aPln2 = theS2->Surface().Plane();
4481 IntAna_QuadQuadGeo aPlnInter(aPln1, aPln2, TolAng, TolTang);
4483 if(!aPlnInter.IsDone()) {
4484 theTangentFaces = Standard_False;
4488 IntAna_ResultType aResType = aPlnInter.TypeInter();
4490 if(aResType == IntAna_Same) {
4491 theTangentFaces = Standard_True;
4495 theTangentFaces = Standard_False;
4497 if(aResType == IntAna_Empty) {
4501 gp_Lin aLin = aPlnInter.Line(1);
4503 ProjLib_Plane aProj;
4506 aProj.Project(aLin);
4507 gp_Lin2d aLin2d1 = aProj.Line();
4510 aProj.Project(aLin);
4511 gp_Lin2d aLin2d2 = aProj.Line();
4513 //classify line2d1 relatively first plane
4514 Standard_Real P11, P12;
4515 Standard_Boolean IsCrossed = ClassifyLin2d(theS1, aLin2d1, TolTang, P11, P12);
4516 if(!IsCrossed) return;
4517 //classify line2d2 relatively second plane
4518 Standard_Real P21, P22;
4519 IsCrossed = ClassifyLin2d(theS2, aLin2d2, TolTang, P21, P22);
4520 if(!IsCrossed) return;
4522 //Analysis of parametric intervals: must have common part
4524 if(P21 >= P12) return;
4525 if(P22 <= P11) return;
4527 Standard_Real pmin, pmax;
4528 pmin = Max(P11, P21);
4529 pmax = Min(P12, P22);
4531 if(pmax - pmin <= TolTang) return;
4533 Handle(Geom_Line) aGLin = new Geom_Line(aLin);
4535 IntTools_Curve aCurve;
4536 Handle(Geom_TrimmedCurve) aGTLin = new Geom_TrimmedCurve(aGLin, pmin, pmax);
4538 aCurve.SetCurve(aGTLin);
4541 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d1);
4542 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4545 Handle(Geom2d_Curve) H1;
4546 aCurve.SetFirstCurve2d(H1);
4549 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d2);
4550 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4553 Handle(Geom2d_Curve) H1;
4554 aCurve.SetFirstCurve2d(H1);
4557 theSeqOfCurve.Append(aCurve);
4561 //=======================================================================
4562 //function : ClassifyLin2d
4564 //=======================================================================
4565 static inline Standard_Boolean INTER(const Standard_Real d1,
4566 const Standard_Real d2,
4567 const Standard_Real tol)
4569 return (d1 > tol && d2 < -tol) ||
4570 (d1 < -tol && d2 > tol) ||
4571 ((d1 <= tol && d1 >= -tol) && (d2 > tol || d2 < -tol)) ||
4572 ((d2 <= tol && d2 >= -tol) && (d1 > tol || d1 < -tol));
4574 static inline Standard_Boolean COINC(const Standard_Real d1,
4575 const Standard_Real d2,
4576 const Standard_Real tol)
4578 return (d1 <= tol && d1 >= -tol) && (d2 <= tol && d2 >= -tol);
4580 Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
4581 const gp_Lin2d& theLin2d,
4582 const Standard_Real theTol,
4583 Standard_Real& theP1,
4584 Standard_Real& theP2)
4587 Standard_Real xmin, xmax, ymin, ymax, d1, d2, A, B, C;
4588 Standard_Real par[2];
4589 Standard_Integer nbi = 0;
4591 xmin = theS->Surface().FirstUParameter();
4592 xmax = theS->Surface().LastUParameter();
4593 ymin = theS->Surface().FirstVParameter();
4594 ymax = theS->Surface().LastVParameter();
4596 theLin2d.Coefficients(A, B, C);
4598 //xmin, ymin <-> xmin, ymax
4599 d1 = A*xmin + B*ymin + C;
4600 d2 = A*xmin + B*ymax + C;
4602 if(INTER(d1, d2, theTol)) {
4603 //Intersection with boundary
4604 Standard_Real y = -(C + A*xmin)/B;
4605 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, y));
4608 else if (COINC(d1, d2, theTol)) {
4609 //Coincidence with boundary
4610 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4611 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4617 if(fabs(par[0]-par[1]) > theTol) {
4618 theP1 = Min(par[0], par[1]);
4619 theP2 = Max(par[0], par[1]);
4620 return Standard_True;
4622 else return Standard_False;
4626 //xmin, ymax <-> xmax, ymax
4628 d2 = A*xmax + B*ymax + C;
4630 if(d1 > theTol || d1 < -theTol) {//to avoid checking of
4631 //coincidence with the same point
4632 if(INTER(d1, d2, theTol)) {
4633 Standard_Real x = -(C + B*ymax)/A;
4634 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymax));
4637 else if (COINC(d1, d2, theTol)) {
4638 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4639 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4646 if(fabs(par[0]-par[1]) > theTol) {
4647 theP1 = Min(par[0], par[1]);
4648 theP2 = Max(par[0], par[1]);
4649 return Standard_True;
4651 else return Standard_False;
4655 //xmax, ymax <-> xmax, ymin
4657 d2 = A*xmax + B*ymin + C;
4659 if(d1 > theTol || d1 < -theTol) {
4660 if(INTER(d1, d2, theTol)) {
4661 Standard_Real y = -(C + A*xmax)/B;
4662 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, y));
4665 else if (COINC(d1, d2, theTol)) {
4666 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4667 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4673 if(fabs(par[0]-par[1]) > theTol) {
4674 theP1 = Min(par[0], par[1]);
4675 theP2 = Max(par[0], par[1]);
4676 return Standard_True;
4678 else return Standard_False;
4681 //xmax, ymin <-> xmin, ymin
4683 d2 = A*xmin + B*ymin + C;
4685 if(d1 > theTol || d1 < -theTol) {
4686 if(INTER(d1, d2, theTol)) {
4687 Standard_Real x = -(C + B*ymin)/A;
4688 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymin));
4691 else if (COINC(d1, d2, theTol)) {
4692 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4693 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4699 if(fabs(par[0]-par[1]) > theTol) {
4700 theP1 = Min(par[0], par[1]);
4701 theP2 = Max(par[0], par[1]);
4702 return Standard_True;
4704 else return Standard_False;
4707 return Standard_False;
4711 //=======================================================================
4712 //function : ApproxParameters
4714 //=======================================================================
4715 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
4716 const Handle(GeomAdaptor_HSurface)& aHS2,
4717 Standard_Integer& iDegMin,
4718 Standard_Integer& iDegMax,
4719 Standard_Integer& iNbIter)
4722 GeomAbs_SurfaceType aTS1, aTS2;
4729 aTS1=aHS1->Surface().GetType();
4730 aTS2=aHS2->Surface().GetType();
4733 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4734 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4735 Standard_Real aRC, aRT, dR, aPC;
4736 gp_Cylinder aCylinder;
4739 aPC=Precision::Confusion();
4741 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4742 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4744 aRC=aCylinder.Radius();
4745 aRT=aTorus.MinorRadius();
4755 if (aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Cylinder) {
4759 //=======================================================================
4760 //function : Tolerances
4762 //=======================================================================
4763 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
4764 const Handle(GeomAdaptor_HSurface)& aHS2,
4765 Standard_Real& aTolTang)
4767 GeomAbs_SurfaceType aTS1, aTS2;
4769 aTS1=aHS1->Surface().GetType();
4770 aTS2=aHS2->Surface().GetType();
4773 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4774 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4775 Standard_Real aRC, aRT, dR, aPC;
4776 gp_Cylinder aCylinder;
4779 aPC=Precision::Confusion();
4781 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4782 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4784 aRC=aCylinder.Radius();
4785 aRT=aTorus.MinorRadius();
4792 aTolTang=0.1*aTolTang;
4796 //=======================================================================
4797 //function : SortTypes
4799 //=======================================================================
4800 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
4801 const GeomAbs_SurfaceType aType2)
4803 Standard_Boolean bRet;
4804 Standard_Integer aI1, aI2;
4806 bRet=Standard_False;
4808 aI1=IndexType(aType1);
4809 aI2=IndexType(aType2);
4815 //=======================================================================
4816 //function : IndexType
4818 //=======================================================================
4819 Standard_Integer IndexType(const GeomAbs_SurfaceType aType)
4821 Standard_Integer aIndex;
4825 if (aType==GeomAbs_Plane) {
4828 else if (aType==GeomAbs_Cylinder) {
4831 else if (aType==GeomAbs_Cone) {
4834 else if (aType==GeomAbs_Sphere) {
4837 else if (aType==GeomAbs_Torus) {
4840 else if (aType==GeomAbs_BezierSurface) {
4843 else if (aType==GeomAbs_BSplineSurface) {
4846 else if (aType==GeomAbs_SurfaceOfRevolution) {
4849 else if (aType==GeomAbs_SurfaceOfExtrusion) {
4852 else if (aType==GeomAbs_OffsetSurface) {
4855 else if (aType==GeomAbs_OtherSurface) {
4860 #ifdef DEB_DUMPWLINE
4861 //=======================================================================
4862 //function : DumpWLine
4864 //=======================================================================
4865 void DumpWLine(const Handle(IntPatch_WLine)& aWLine)
4867 Standard_Integer i, aNbPnts;
4868 Standard_Real aX, aY, aZ, aU1, aV1, aU2, aV2;
4870 printf(" *WLine\n");
4871 aNbPnts=aWLine->NbPnts();
4872 for (i=1; i<=aNbPnts; ++i) {
4873 const IntSurf_PntOn2S aPntOn2S=aWLine->Point(i);
4874 const gp_Pnt& aP3D=aPntOn2S.Value();
4875 aP3D.Coord(aX, aY, aZ);
4876 aPntOn2S.Parameters(aU1, aV1, aU2, aV2);
4878 printf("point p_%d %lf %lf %lf\n", i, aX, aY, aZ);
4879 //printf("point p_%d %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf\n",
4880 // i, aX, aY, aZ, aU1, aV1, aU2, aV2);
4884 //=======================================================================
4885 //function : RefineVector
4887 //=======================================================================
4888 void RefineVector(gp_Vec2d& aV2D)
4890 Standard_Integer k,m;
4891 Standard_Real aC[2], aEps, aR1, aR2, aNum;
4897 aV2D.Coord(aC[0], aC[1]);
4899 for (k=0; k<2; ++k) {
4902 if (aNum>aR1 && aNum<aR2) {
4913 aV2D.SetCoord(aC[0], aC[1]);
4915 //=======================================================================
4916 //function : FindMaxSquareDistance
4918 //=======================================================================
4919 Standard_Real FindMaxSquareDistance (const Standard_Real aT1,
4920 const Standard_Real aT2,
4921 const Standard_Real aEps,
4922 const Handle(Geom_Curve)& aC3D,
4923 const Handle(Geom2d_Curve)& aC2D1,
4924 const Handle(Geom2d_Curve)& aC2D2,
4925 const Handle(GeomAdaptor_HSurface)& myHS1,
4926 const Handle(GeomAdaptor_HSurface)& myHS2,
4927 const TopoDS_Face& myFace1,
4928 const TopoDS_Face& myFace2,
4929 const Handle(BOPInt_Context)& myContext)
4931 Standard_Real aA, aB, aCf, aX1, aX2, aF1, aF2, aX, aF;
4933 aCf=1.6180339887498948482045868343656;// =0.5*(1.+sqrt(5.));
4937 aF1=MaxSquareDistance(aX1,
4938 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4940 aF2=MaxSquareDistance(aX2,
4941 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4945 if (fabs(aA-aB)<aEps) {
4947 aF=MaxSquareDistance(aX,
4948 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4956 aF2=MaxSquareDistance(aX2,
4957 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4965 aF1=MaxSquareDistance(aX1,
4966 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4971 //=======================================================================
4972 //function : MaxSquareDistance
4974 //=======================================================================
4975 Standard_Real MaxSquareDistance (const Standard_Real aT,
4976 const Handle(Geom_Curve)& aC3D,
4977 const Handle(Geom2d_Curve)& aC2D1,
4978 const Handle(Geom2d_Curve)& aC2D2,
4979 const Handle(GeomAdaptor_HSurface) myHS1,
4980 const Handle(GeomAdaptor_HSurface) myHS2,
4981 const TopoDS_Face& aF1,
4982 const TopoDS_Face& aF2,
4983 const Handle(BOPInt_Context)& aCtx)
4985 Standard_Boolean bIsDone;
4987 Standard_Real aU, aV, aD2Max, aD2;
4994 if (aC3D.IsNull()) {
4998 for (i=0; i<2; ++i) {
4999 const Handle(GeomAdaptor_HSurface)& aGHS=(!i) ? myHS1 : myHS2;
5000 const TopoDS_Face &aF=(!i) ? aF1 : aF2;
5001 const Handle(Geom2d_Curve)& aC2D=(!i) ? aC2D1 : aC2D2;
5003 if (!aC2D.IsNull()) {
5006 aGHS->D0(aU, aV, aPS);
5007 aD2=aP.SquareDistance(aPS);
5013 GeomAPI_ProjectPointOnSurf& aProjector=aCtx->ProjPS(aF);
5015 aProjector.Perform(aP);
5016 bIsDone=aProjector.IsDone();
5018 aProjector.LowerDistanceParameters(aU, aV);
5019 aGHS->D0(aU, aV, aPS);
5020 aD2=aP.SquareDistance(aPS);
5030 //=======================================================================
5031 //function : CheckPCurve
5032 //purpose : Checks if points of the pcurve are out of the face bounds.
5033 //=======================================================================
5034 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
5035 const TopoDS_Face& aFace)
5037 const Standard_Integer NPoints = 23;
5039 Standard_Real umin,umax,vmin,vmax;
5041 BRepTools::UVBounds(aFace, umin, umax, vmin, vmax);
5042 Standard_Real tolU = Max ((umax-umin)*0.01, Precision::Confusion());
5043 Standard_Real tolV = Max ((vmax-vmin)*0.01, Precision::Confusion());
5044 Standard_Real fp = aPC->FirstParameter();
5045 Standard_Real lp = aPC->LastParameter();
5048 // adjust domain for periodic surfaces
5049 TopLoc_Location aLoc;
5050 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
5051 if (aSurf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
5052 aSurf = (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf))->BasisSurface();
5054 gp_Pnt2d pnt = aPC->Value((fp+lp)/2);
5058 if (aSurf->IsUPeriodic()) {
5059 Standard_Real aPer = aSurf->UPeriod();
5060 Standard_Integer nshift = (Standard_Integer) ((u-umin)/aPer);
5061 if (u < umin+aPer*nshift) nshift--;
5062 umin += aPer*nshift;
5063 umax += aPer*nshift;
5065 if (aSurf->IsVPeriodic()) {
5066 Standard_Real aPer = aSurf->VPeriod();
5067 Standard_Integer nshift = (Standard_Integer) ((v-vmin)/aPer);
5068 if (v < vmin+aPer*nshift) nshift--;
5069 vmin += aPer*nshift;
5070 vmax += aPer*nshift;
5073 //--------------------------------------------------------
5074 Standard_Boolean bRet;
5075 Standard_Integer j, aNbIntervals;
5076 Standard_Real aT, dT;
5079 Geom2dAdaptor_Curve aGAC(aPC);
5080 aNbIntervals=aGAC.NbIntervals(GeomAbs_CN);
5082 TColStd_Array1OfReal aTI(1, aNbIntervals+1);
5083 aGAC.Intervals(aTI,GeomAbs_CN);
5085 bRet=Standard_False;
5087 aT=aGAC.FirstParameter();
5088 for (j=1; j<=aNbIntervals; ++j) {
5089 dT=(aTI(j+1)-aTI(j))/NPoints;
5091 for (i=1; i<NPoints; i++) {
5095 if (umin-u > tolU || u-umax > tolU ||
5096 vmin-v > tolV || v-vmax > tolV) {