1 // Created on: 2000-11-23
2 // Created by: Michael KLOKOV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <IntTools_FaceFace.ixx>
18 #include <Precision.hxx>
20 #include <TColStd_HArray1OfReal.hxx>
21 #include <TColStd_Array1OfReal.hxx>
22 #include <TColStd_Array1OfInteger.hxx>
23 #include <TColStd_SequenceOfReal.hxx>
24 #include <TColStd_ListOfInteger.hxx>
25 #include <TColStd_ListIteratorOfListOfInteger.hxx>
26 #include <TColStd_Array1OfListOfInteger.hxx>
28 #include <gp_Lin2d.hxx>
29 #include <gp_Ax22d.hxx>
30 #include <gp_Circ2d.hxx>
31 #include <gp_Torus.hxx>
32 #include <gp_Cylinder.hxx>
34 #include <Bnd_Box.hxx>
36 #include <TColgp_HArray1OfPnt2d.hxx>
37 #include <TColgp_SequenceOfPnt2d.hxx>
38 #include <TColgp_Array1OfPnt.hxx>
39 #include <TColgp_Array1OfPnt2d.hxx>
41 #include <IntAna_QuadQuadGeo.hxx>
43 #include <IntSurf_PntOn2S.hxx>
44 #include <IntSurf_LineOn2S.hxx>
45 #include <IntSurf_PntOn2S.hxx>
46 #include <IntSurf_ListOfPntOn2S.hxx>
47 #include <IntRes2d_Domain.hxx>
48 #include <ProjLib_Plane.hxx>
50 #include <IntPatch_GLine.hxx>
51 #include <IntPatch_RLine.hxx>
52 #include <IntPatch_WLine.hxx>
53 #include <IntPatch_ALine.hxx>
54 #include <IntPatch_ALineToWLine.hxx>
59 #include <Extrema_ExtCC.hxx>
60 #include <Extrema_POnCurv.hxx>
61 #include <BndLib_AddSurface.hxx>
63 #include <Adaptor3d_SurfacePtr.hxx>
64 #include <Adaptor2d_HLine2d.hxx>
66 #include <GeomAbs_SurfaceType.hxx>
67 #include <GeomAbs_CurveType.hxx>
69 #include <Geom_Surface.hxx>
70 #include <Geom_Line.hxx>
71 #include <Geom_Circle.hxx>
72 #include <Geom_Ellipse.hxx>
73 #include <Geom_Parabola.hxx>
74 #include <Geom_Hyperbola.hxx>
75 #include <Geom_TrimmedCurve.hxx>
76 #include <Geom_BSplineCurve.hxx>
77 #include <Geom_RectangularTrimmedSurface.hxx>
78 #include <Geom_OffsetSurface.hxx>
79 #include <Geom_Curve.hxx>
80 #include <Geom_Conic.hxx>
82 #include <Geom2d_TrimmedCurve.hxx>
83 #include <Geom2d_BSplineCurve.hxx>
84 #include <Geom2d_Line.hxx>
85 #include <Geom2d_Curve.hxx>
86 #include <Geom2d_Circle.hxx>
88 #include <Geom2dAPI_InterCurveCurve.hxx>
89 #include <Geom2dInt_GInter.hxx>
90 #include <GeomAdaptor_Curve.hxx>
91 #include <GeomAdaptor_HSurface.hxx>
92 #include <GeomAdaptor_Surface.hxx>
93 #include <GeomLib_CheckBSplineCurve.hxx>
94 #include <GeomLib_Check2dBSplineCurve.hxx>
96 #include <GeomInt_WLApprox.hxx>
97 #include <GeomProjLib.hxx>
98 #include <GeomAPI_ProjectPointOnSurf.hxx>
99 #include <Geom2dAdaptor_Curve.hxx>
100 #include <TopoDS.hxx>
101 #include <TopoDS_Edge.hxx>
102 #include <TopExp_Explorer.hxx>
104 #include <BRep_Tool.hxx>
105 #include <BRepTools.hxx>
106 #include <BRepAdaptor_Surface.hxx>
108 #include <IntTools_Curve.hxx>
109 #include <IntTools_Tools.hxx>
110 #include <IntTools_Tools.hxx>
111 #include <IntTools_TopolTool.hxx>
112 #include <IntTools_PntOnFace.hxx>
113 #include <IntTools_PntOn2Faces.hxx>
114 #include <IntTools_Context.hxx>
115 #include <IntSurf_ListIteratorOfListOfPntOn2S.hxx>
118 void RefineVector(gp_Vec2d& aV2D);
121 void DumpWLine(const Handle(IntPatch_WLine)& aWLine);
125 void TolR3d(const TopoDS_Face& ,
129 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)&,
130 const Standard_Integer,
131 const Standard_Integer);
134 void Parameters(const Handle(GeomAdaptor_HSurface)&,
135 const Handle(GeomAdaptor_HSurface)&,
143 void BuildPCurves (Standard_Real f,Standard_Real l,Standard_Real& Tol,
144 const Handle (Geom_Surface)& S,
145 const Handle (Geom_Curve)& C,
146 Handle (Geom2d_Curve)& C2d);
149 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
150 const Standard_Real theTolerance,
151 Standard_Real& theumin,
152 Standard_Real& theumax,
153 Standard_Real& thevmin,
154 Standard_Real& thevmax);
156 Standard_Boolean NotUseSurfacesForApprox
157 (const TopoDS_Face& aF1,
158 const TopoDS_Face& aF2,
159 const Handle(IntPatch_WLine)& WL,
160 const Standard_Integer ifprm,
161 const Standard_Integer ilprm);
164 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine);
167 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
168 const Standard_Integer ideb,
169 const Standard_Integer ifin,
170 const Standard_Boolean onFirst);
173 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
174 const Handle(GeomAdaptor_HSurface)& theSurface1,
175 const Handle(GeomAdaptor_HSurface)& theSurface2,
176 const TopoDS_Face& theFace1,
177 const TopoDS_Face& theFace2,
178 const IntTools_LineConstructor& theLConstructor,
179 const Standard_Boolean theAvoidLConstructor,
180 IntPatch_SequenceOfLine& theNewLines,
181 Standard_Real& theReachedTol3d,
182 const Handle(IntTools_Context)& );
185 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
186 const Handle(Geom_Curve)& theCurve,
187 const TopoDS_Face& theFace1,
188 const TopoDS_Face& theFace2,
189 const Standard_Real theOtherParameter,
190 const Standard_Boolean bIncreasePar,
191 Standard_Real& theNewParameter,
192 const Handle(IntTools_Context)& );
195 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve);
198 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
199 const Standard_Real theFirstBoundary,
200 const Standard_Real theSecondBoundary,
201 const Standard_Real theResolution,
202 Standard_Boolean& IsOnFirstBoundary);
204 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
205 const gp_Pnt2d& theLastPoint,
206 const Standard_Real theUmin,
207 const Standard_Real theUmax,
208 const Standard_Real theVmin,
209 const Standard_Real theVmax,
210 gp_Pnt2d& theNewPoint);
214 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
215 const Handle(GeomAdaptor_HSurface)& theSurface2,
216 const TopoDS_Face& theFace1,
217 const TopoDS_Face& theFace2,
218 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
219 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
220 Handle(TColStd_HArray1OfReal)& theResultRadius,
221 const Handle(IntTools_Context)& );
224 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
225 const gp_Pnt2d& theLastPoint,
226 const Standard_Real theUmin,
227 const Standard_Real theUmax,
228 const Standard_Real theVmin,
229 const Standard_Real theVmax,
230 const gp_Pnt2d& theTanZoneCenter,
231 const Standard_Real theZoneRadius,
232 Handle(GeomAdaptor_HSurface) theGASurface,
233 gp_Pnt2d& theNewPoint);
236 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
237 const gp_Pnt2d& theTanZoneCenter,
238 const Standard_Real theZoneRadius,
239 Handle(GeomAdaptor_HSurface) theGASurface);
242 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
243 const gp_Pnt2d& theOriginalPoint,
244 Handle(GeomAdaptor_HSurface) theGASurface);
246 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
247 const gp_Sphere& theSph);
249 static void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
250 const Handle(GeomAdaptor_HSurface)& theS2,
251 const Standard_Real TolAng,
252 const Standard_Real TolTang,
253 const Standard_Boolean theApprox1,
254 const Standard_Boolean theApprox2,
255 IntTools_SequenceOfCurves& theSeqOfCurve,
256 Standard_Boolean& theTangentFaces);
258 static Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
259 const gp_Lin2d& theLin2d,
260 const Standard_Real theTol,
261 Standard_Real& theP1,
262 Standard_Real& theP2);
265 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
266 const Handle(GeomAdaptor_HSurface)& aHS2,
267 Standard_Integer& iDegMin,
268 Standard_Integer& iNbIter,
269 Standard_Integer& iDegMax);
272 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
273 const Handle(GeomAdaptor_HSurface)& aHS2,
274 Standard_Real& aTolTang);
277 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
278 const GeomAbs_SurfaceType aType2);
280 Standard_Integer IndexType(const GeomAbs_SurfaceType aType);
284 Standard_Real MaxSquareDistance (const Standard_Real aT,
285 const Handle(Geom_Curve)& aC3D,
286 const Handle(Geom2d_Curve)& aC2D1,
287 const Handle(Geom2d_Curve)& aC2D2,
288 const Handle(GeomAdaptor_HSurface) myHS1,
289 const Handle(GeomAdaptor_HSurface) myHS2,
290 const TopoDS_Face& aF1,
291 const TopoDS_Face& aF2,
292 const Handle(IntTools_Context)& aCtx);
295 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
296 const TopoDS_Face& aFace);
300 Standard_Real FindMaxSquareDistance (const Standard_Real aA,
301 const Standard_Real aB,
302 const Standard_Real aEps,
303 const Handle(Geom_Curve)& aC3D,
304 const Handle(Geom2d_Curve)& aC2D1,
305 const Handle(Geom2d_Curve)& aC2D2,
306 const Handle(GeomAdaptor_HSurface)& myHS1,
307 const Handle(GeomAdaptor_HSurface)& myHS2,
308 const TopoDS_Face& aF1,
309 const TopoDS_Face& aF2,
310 const Handle(IntTools_Context)& aCtx);
312 //=======================================================================
315 //=======================================================================
316 IntTools_FaceFace::IntTools_FaceFace()
318 myIsDone=Standard_False;
319 myTangentFaces=Standard_False;
321 myHS1 = new GeomAdaptor_HSurface ();
322 myHS2 = new GeomAdaptor_HSurface ();
325 SetParameters(Standard_True, Standard_True, Standard_True, 1.e-07);
328 //=======================================================================
329 //function : SetContext
331 //=======================================================================
332 void IntTools_FaceFace::SetContext(const Handle(IntTools_Context)& aContext)
336 //=======================================================================
339 //=======================================================================
340 const Handle(IntTools_Context)& IntTools_FaceFace::Context()const
344 //=======================================================================
347 //=======================================================================
348 const TopoDS_Face& IntTools_FaceFace::Face1() const
352 //=======================================================================
355 //=======================================================================
356 const TopoDS_Face& IntTools_FaceFace::Face2() const
360 //=======================================================================
361 //function : TangentFaces
363 //=======================================================================
364 Standard_Boolean IntTools_FaceFace::TangentFaces() const
366 return myTangentFaces;
368 //=======================================================================
371 //=======================================================================
372 const IntTools_SequenceOfPntOn2Faces& IntTools_FaceFace::Points() const
376 //=======================================================================
379 //=======================================================================
380 Standard_Boolean IntTools_FaceFace::IsDone() const
384 //=======================================================================
385 //function : TolReached3d
387 //=======================================================================
388 Standard_Real IntTools_FaceFace::TolReached3d() const
390 return myTolReached3d;
392 //=======================================================================
394 //purpose : return lines of intersection
395 //=======================================================================
396 const IntTools_SequenceOfCurves& IntTools_FaceFace::Lines() const
398 StdFail_NotDone_Raise_if
400 "IntTools_FaceFace::Lines() => myIntersector NOT DONE");
403 //=======================================================================
404 //function : TolReached2d
406 //=======================================================================
407 Standard_Real IntTools_FaceFace::TolReached2d() const
409 return myTolReached2d;
411 // =======================================================================
412 // function: SetParameters
414 // =======================================================================
415 void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d,
416 const Standard_Boolean ToApproxC2dOnS1,
417 const Standard_Boolean ToApproxC2dOnS2,
418 const Standard_Real ApproximationTolerance)
420 myApprox = ToApproxC3d;
421 myApprox1 = ToApproxC2dOnS1;
422 myApprox2 = ToApproxC2dOnS2;
423 myTolApprox = ApproximationTolerance;
425 //=======================================================================
428 //=======================================================================
429 void IntTools_FaceFace::SetList(IntSurf_ListOfPntOn2S& aListOfPnts)
431 myListOfPnts = aListOfPnts;
435 static Standard_Boolean isTreatAnalityc(const TopoDS_Face& theF1,
436 const TopoDS_Face& theF2)
438 const Standard_Real Tolang = 1.e-8;
439 const Standard_Real aTolF1=BRep_Tool::Tolerance(theF1);
440 const Standard_Real aTolF2=BRep_Tool::Tolerance(theF2);
441 const Standard_Real aTolSum = aTolF1 + aTolF2;
442 Standard_Real aHigh = 0.0;
444 const BRepAdaptor_Surface aBAS1(theF1), aBAS2(theF2);
445 const GeomAbs_SurfaceType aType1=aBAS1.GetType();
446 const GeomAbs_SurfaceType aType2=aBAS2.GetType();
450 if(aType1 == GeomAbs_Plane)
454 else if(aType2 == GeomAbs_Plane)
460 return Standard_True;
463 if(aType1 == GeomAbs_Cylinder)
465 aS2=aBAS1.Cylinder();
466 const Standard_Real VMin = aBAS1.FirstVParameter();
467 const Standard_Real VMax = aBAS1.LastVParameter();
469 if( Precision::IsNegativeInfinite(VMin) ||
470 Precision::IsPositiveInfinite(VMax))
471 return Standard_True;
475 else if(aType2 == GeomAbs_Cylinder)
477 aS2=aBAS2.Cylinder();
479 const Standard_Real VMin = aBAS2.FirstVParameter();
480 const Standard_Real VMax = aBAS2.LastVParameter();
482 if( Precision::IsNegativeInfinite(VMin) ||
483 Precision::IsPositiveInfinite(VMax))
484 return Standard_True;
490 return Standard_True;
493 IntAna_QuadQuadGeo inter;
494 inter.Perform(aS1,aS2,Tolang,aTolSum, aHigh);
495 if(inter.TypeInter() == IntAna_Ellipse)
497 const gp_Elips anEl = inter.Ellipse(1);
498 const Standard_Real aMajorR = anEl.MajorRadius();
499 const Standard_Real aMinorR = anEl.MinorRadius();
501 return (aMajorR < 100000.0 * aMinorR);
505 return inter.IsDone();
508 //=======================================================================
510 //purpose : intersect surfaces of the faces
511 //=======================================================================
512 void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
513 const TopoDS_Face& aF2)
515 Standard_Boolean RestrictLine = Standard_False, hasCone = Standard_False;
517 if (myContext.IsNull()) {
518 myContext=new IntTools_Context;
521 mySeqOfCurve.Clear();
524 myIsDone = Standard_False;
530 const BRepAdaptor_Surface aBAS1(myFace1, Standard_False);
531 const BRepAdaptor_Surface aBAS2(myFace2, Standard_False);
532 GeomAbs_SurfaceType aType1=aBAS1.GetType();
533 GeomAbs_SurfaceType aType2=aBAS2.GetType();
535 const Standard_Boolean bReverse=SortTypes(aType1, aType2);
540 aType1=aBAS2.GetType();
541 aType2=aBAS1.GetType();
543 if (myListOfPnts.Extent())
545 Standard_Real aU1,aV1,aU2,aV2;
546 IntSurf_ListIteratorOfListOfPntOn2S aItP2S;
548 aItP2S.Initialize(myListOfPnts);
549 for (; aItP2S.More(); aItP2S.Next())
551 IntSurf_PntOn2S& aP2S=aItP2S.Value();
552 aP2S.Parameters(aU1,aV1,aU2,aV2);
553 aP2S.SetValue(aU2,aV2,aU1,aV1);
559 const Handle(Geom_Surface) S1=BRep_Tool::Surface(myFace1);
560 const Handle(Geom_Surface) S2=BRep_Tool::Surface(myFace2);
562 const Standard_Real aTolF1=BRep_Tool::Tolerance(myFace1);
563 const Standard_Real aTolF2=BRep_Tool::Tolerance(myFace2);
565 Standard_Real TolArc = aTolF1 + aTolF2;
566 Standard_Real TolTang = TolArc;
568 const Standard_Boolean isFace1Quad = (aType1 == GeomAbs_Cylinder ||
569 aType1 == GeomAbs_Cone ||
570 aType1 == GeomAbs_Torus);
572 const Standard_Boolean isFace2Quad = (aType2 == GeomAbs_Cylinder ||
573 aType2 == GeomAbs_Cone ||
574 aType2 == GeomAbs_Torus);
576 if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
577 Standard_Real umin, umax, vmin, vmax;
578 Standard_Real dU, dV;
580 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
587 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
589 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
596 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
598 Standard_Real TolAng = 1.e-8;
600 PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2,
601 mySeqOfCurve, myTangentFaces);
603 myIsDone = Standard_True;
605 if(!myTangentFaces) {
606 const Standard_Integer NbLinPP = mySeqOfCurve.Length();
608 Standard_Real aTolFMax;
609 myTolReached3d = 1.e-7;
610 aTolFMax=Max(aTolF1, aTolF2);
611 if (aTolFMax>myTolReached3d) {
612 myTolReached3d=aTolFMax;
615 myTolReached2d = myTolReached3d;
618 Handle(Geom2d_Curve) aC2D1, aC2D2;
619 const Standard_Integer aNbLin = mySeqOfCurve.Length();
620 for (Standard_Integer i = 1; i <= aNbLin; ++i) {
621 IntTools_Curve& aIC=mySeqOfCurve(i);
622 aC2D1=aIC.FirstCurve2d();
623 aC2D2=aIC.SecondCurve2d();
624 aIC.SetFirstCurve2d(aC2D2);
625 aIC.SetSecondCurve2d(aC2D1);
631 }//if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
633 if ((aType1==GeomAbs_Plane) && isFace2Quad)
635 Standard_Real dU, dV;
638 Standard_Real umin, umax, vmin, vmax;
639 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
647 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
649 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
650 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
651 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
653 if( aType2==GeomAbs_Cone ) {
655 hasCone = Standard_True;
658 else if ((aType2==GeomAbs_Plane) && isFace1Quad)
660 Standard_Real dU, dV;
663 Standard_Real umin, umax, vmin, vmax;
664 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
665 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
666 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
668 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
675 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
677 if( aType1==GeomAbs_Cone ) {
679 hasCone = Standard_True;
684 Standard_Real umin, umax, vmin, vmax;
685 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
686 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
687 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
688 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
689 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
690 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
693 const Handle(IntTools_TopolTool) dom1 = new IntTools_TopolTool(myHS1);
694 const Handle(IntTools_TopolTool) dom2 = new IntTools_TopolTool(myHS2);
696 myLConstruct.Load(dom1, dom2, myHS1, myHS2);
699 Tolerances(myHS1, myHS2, TolTang);
702 const Standard_Real UVMaxStep = 0.001;
703 const Standard_Real Deflection = (hasCone) ? 0.085 : 0.1;
704 myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection);
707 if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) ||
708 (myHS1->IsVClosed() && !myHS1->IsVPeriodic()) ||
709 (myHS2->IsUClosed() && !myHS2->IsUPeriodic()) ||
710 (myHS2->IsVClosed() && !myHS2->IsVPeriodic()))
712 RestrictLine = Standard_True;
715 if((aType1 != GeomAbs_BSplineSurface) &&
716 (aType1 != GeomAbs_BezierSurface) &&
717 (aType1 != GeomAbs_OtherSurface) &&
718 (aType2 != GeomAbs_BSplineSurface) &&
719 (aType2 != GeomAbs_BezierSurface) &&
720 (aType2 != GeomAbs_OtherSurface))
722 RestrictLine = Standard_True;
724 if ((aType1 == GeomAbs_Torus) ||
725 (aType2 == GeomAbs_Torus))
727 myListOfPnts.Clear();
734 TopExp_Explorer aExp;
735 for(Standard_Integer i = 0; (!RestrictLine) && (i < 2); i++)
737 const TopoDS_Face& aF=(!i) ? myFace1 : myFace2;
738 aExp.Init(aF, TopAbs_EDGE);
739 for(; aExp.More(); aExp.Next())
741 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
743 if(BRep_Tool::Degenerated(aE))
745 RestrictLine = Standard_True;
752 const Standard_Boolean isGeomInt = isTreatAnalityc(aF1, aF2);
753 myIntersector.Perform(myHS1, dom1, myHS2, dom2, TolArc, TolTang,
754 myListOfPnts, RestrictLine, isGeomInt);
756 myIsDone = myIntersector.IsDone();
760 myTangentFaces=myIntersector.TangentFaces();
761 if (myTangentFaces) {
766 myListOfPnts.Clear(); // to use LineConstructor
769 const Standard_Integer aNbLin = myIntersector.NbLines();
770 for (Standard_Integer i=1; i <= aNbLin; ++i) {
771 MakeCurve(i, dom1, dom2);
774 ComputeTolReached3d();
777 Handle(Geom2d_Curve) aC2D1, aC2D2;
779 const Standard_Integer aNbLin=mySeqOfCurve.Length();
780 for (Standard_Integer i=1; i<=aNbLin; ++i)
782 IntTools_Curve& aIC=mySeqOfCurve(i);
783 aC2D1=aIC.FirstCurve2d();
784 aC2D2=aIC.SecondCurve2d();
785 aIC.SetFirstCurve2d(aC2D2);
786 aIC.SetSecondCurve2d(aC2D1);
791 Standard_Real U1,V1,U2,V2;
792 IntTools_PntOnFace aPntOnF1, aPntOnF2;
793 IntTools_PntOn2Faces aPntOn2Faces;
795 const Standard_Integer aNbPnts = myIntersector.NbPnts();
796 for (Standard_Integer i=1; i <= aNbPnts; ++i)
798 const IntSurf_PntOn2S& aISPnt=myIntersector.Point(i).PntOn2S();
799 const gp_Pnt& aPnt=aISPnt.Value();
800 aISPnt.Parameters(U1,V1,U2,V2);
801 aPntOnF1.Init(myFace1, aPnt, U1, V1);
802 aPntOnF2.Init(myFace2, aPnt, U2, V2);
806 aPntOn2Faces.SetP1(aPntOnF1);
807 aPntOn2Faces.SetP2(aPntOnF2);
811 aPntOn2Faces.SetP2(aPntOnF1);
812 aPntOn2Faces.SetP1(aPntOnF2);
815 myPnts.Append(aPntOn2Faces);
820 //=======================================================================
821 //function :ComputeTolReached3d
823 //=======================================================================
824 void IntTools_FaceFace::ComputeTolReached3d()
826 Standard_Boolean bCase1;
827 Standard_Integer aNbLin, i;
828 GeomAbs_SurfaceType aType1, aType2;
830 aNbLin=myIntersector.NbLines();
835 aType1=myHS1->Surface().GetType();
836 aType2=myHS2->Surface().GetType();
838 bCase1=((aType1==GeomAbs_Plane && aType2==GeomAbs_SurfaceOfExtrusion) ||
839 (aType2==GeomAbs_Plane && aType1==GeomAbs_SurfaceOfExtrusion));
841 if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
843 Handle(IntPatch_Line) aIL1, aIL2;
844 IntPatch_IType aTL1, aTL2;
846 aIL1=myIntersector.Line(1);
847 aIL2=myIntersector.Line(2);
848 aTL1=aIL1->ArcType();
849 aTL2=aIL2->ArcType();
850 if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) {
851 Standard_Real aD, aDTresh, dTol;
857 aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line();
858 aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line();
859 aD=aL1.Distance(aL2);
862 myTolReached3d=aD+dTol;
868 if (aNbLin) {// Check the distances
869 Standard_Integer aNbP, j ;
870 Standard_Real aT1, aT2, dT, aD2, aD2Max, aEps, aT11, aT12;
874 aNbLin=mySeqOfCurve.Length();
876 for (i=1; i<=aNbLin; ++i) {
877 const IntTools_Curve& aIC=mySeqOfCurve(i);
878 const Handle(Geom_Curve)& aC3D=aIC.Curve();
879 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
880 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
885 const Handle(Geom_BSplineCurve)& aBC=
886 Handle(Geom_BSplineCurve)::DownCast(aC3D);
891 aT1=aBC->FirstParameter();
892 aT2=aBC->LastParameter();
896 for (j=1; j<aNbP; ++j) {
899 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
900 myHS1, myHS2, myFace1, myFace2, myContext);
905 }//for (i=1; i<=aNbLin; ++i) {
907 myTolReached3d=sqrt(aD2Max);
909 }// if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
912 else if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
913 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
917 aTolF1 = BRep_Tool::Tolerance(myFace1);
918 aTolF2 = BRep_Tool::Tolerance(myFace2);
919 aTolFMax=Max(aTolF1, aTolF2);
921 if (aTolFMax>aTolTresh) {
922 myTolReached3d=aTolFMax;
924 }//if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
927 else if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ||
928 (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) {
930 const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1);
931 if(aIL1->ArcType() == IntPatch_Circle) {
932 gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle();
933 gp_XYZ aCirDir = aCir.Axis().Direction().XYZ();
936 if(aType1 == GeomAbs_Plane) {
937 aPln = myHS1->Surface().Plane();
940 aPln = myHS2->Surface().Plane();
942 aPlDir = aPln.Axis().Direction().XYZ();
943 Standard_Real cs = aCirDir*aPlDir;
944 if(cs < 0.) aPlDir.Reverse();
945 Standard_Real eps = 1.e-14;
946 if(!aPlDir.IsEqual(aCirDir, eps)) {
947 Standard_Integer aNbP = 11;
948 Standard_Real dt = 2.*M_PI / (aNbP - 1), t;
949 for(t = 0.; t < 2.*M_PI; t += dt) {
950 Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir));
951 if(myTolReached3d < d) myTolReached3d = d;
953 myTolReached3d *= 1.1;
955 } //aIL1->ArcType() == IntPatch_Circle
957 } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane)
958 //End IFV Bug OCC20297
960 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
961 (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) {
962 aNbLin=mySeqOfCurve.Length();
967 Standard_Integer aNbP;
968 Standard_Real aT, aT1, aT2, dT, aUT, aVT, aUP, aVP;
969 Standard_Real aDP, aDT, aDmax;
974 const IntTools_Curve& aIC=mySeqOfCurve(1);
975 const Handle(Geom_Curve)& aC3D=aIC.Curve();
976 const Handle(Geom_BSplineCurve)& aBS=
977 Handle(Geom_BSplineCurve)::DownCast(aC3D);
982 aT1=aBS->FirstParameter();
983 aT2=aBS->LastParameter();
985 aPln =(aType1==GeomAbs_Plane) ? myHS1->Plane() : myHS2->Plane();
986 aTorus=(aType1==GeomAbs_Plane) ? myHS2->Torus() : myHS1->Torus();
990 dT=(aT2-aT1)/(aNbP-1);
991 for (i=0; i<aNbP; ++i) {
999 ElSLib::Parameters(aPln, aP, aUP, aVP);
1000 aPP=ElSLib::Value(aUP, aVP, aPln);
1001 aDP=aP.SquareDistance(aPP);
1006 ElSLib::Parameters(aTorus, aP, aUT, aVT);
1007 aPT=ElSLib::Value(aUT, aVT, aTorus);
1008 aDT=aP.SquareDistance(aPT);
1014 if (aDmax > myTolReached3d*myTolReached3d) {
1015 myTolReached3d=sqrt(aDmax);
1016 myTolReached3d=1.1*myTolReached3d;
1018 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
1020 else if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) ||
1021 (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder)) {
1022 Standard_Integer j, aNbP;
1023 Standard_Real aT, aT1, aT2, dT, aD2max, aD2;
1025 aNbLin=mySeqOfCurve.Length();
1029 for (i=1; i<=aNbLin; ++i) {
1030 const IntTools_Curve& aIC=mySeqOfCurve(i);
1031 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1032 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1033 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1035 if (aC3D.IsNull()) {
1038 const Handle(Geom_BSplineCurve)& aBC=
1039 Handle(Geom_BSplineCurve)::DownCast(aC3D);
1044 aT1=aBC->FirstParameter();
1045 aT2=aBC->LastParameter();
1047 dT=(aT2-aT1)/(aNbP-1);
1048 for (j=0; j<aNbP; ++j) {
1054 aD2=MaxSquareDistance(aT, aC3D, aC2D1, aC2D2,
1055 myHS1, myHS2, myFace1, myFace2, myContext);
1059 }//for (j=0; j<aNbP; ++j) {
1061 }//for (i=1; i<=aNbLin; ++i) {
1063 aD2=myTolReached3d*myTolReached3d;
1065 myTolReached3d=sqrt(aD2max);
1067 }//if((aType1==GeomAbs_SurfaceOfRevolution ...
1068 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ||
1069 (aType2==GeomAbs_Plane && aType1==GeomAbs_Sphere)) {
1070 Standard_Integer j, aNbP;
1071 Standard_Real aT1, aT2, dT, aD2max, aD2, aEps, aT11, aT12;
1073 aNbLin=mySeqOfCurve.Length();
1077 for (i=1; i<=aNbLin; ++i) {
1078 const IntTools_Curve& aIC=mySeqOfCurve(i);
1079 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1080 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1081 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1083 const Handle(Geom2d_BSplineCurve)& aBC2D1=
1084 Handle(Geom2d_BSplineCurve)::DownCast(aC2D1);
1085 const Handle(Geom2d_BSplineCurve)& aBC2D2=
1086 Handle(Geom2d_BSplineCurve)::DownCast(aC2D2);
1088 if (aBC2D1.IsNull() && aBC2D2.IsNull()) {
1092 if (!aBC2D1.IsNull()) {
1093 aT1=aBC2D1->FirstParameter();
1094 aT2=aBC2D1->LastParameter();
1097 aT1=aBC2D2->FirstParameter();
1098 aT2=aBC2D2->LastParameter();
1101 aEps=0.01*(aT2-aT1);
1103 for (j=0; j<aNbP; ++j) {
1110 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
1111 myHS1, myHS2, myFace1, myFace2, myContext);
1115 }//for (j=0; j<aNbP; ++j) {
1117 }//for (i=1; i<=aNbLin; ++i) {
1119 aD2=myTolReached3d*myTolReached3d;
1121 myTolReached3d=sqrt(aD2max);
1123 }//else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ...
1124 else if (!myApprox || bCase1) {
1125 //else if (!myApprox) {
1126 Standard_Integer aNbP, j;
1127 Standard_Real aT1, aT2, dT, aD2, aD2Max, aEps, aT11, aT12;
1130 aNbLin=mySeqOfCurve.Length();
1132 for (i=1; i<=aNbLin; ++i) {
1133 const IntTools_Curve& aIC=mySeqOfCurve(i);
1134 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1135 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1136 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1138 if (aC3D.IsNull()) {
1141 const Handle(Geom_BSplineCurve)& aBC=
1142 Handle(Geom_BSplineCurve)::DownCast(aC3D);
1147 aT1=aBC->FirstParameter();
1148 aT2=aBC->LastParameter();
1150 aEps=0.0001*(aT2-aT1);
1153 for (j=1; j<aNbP-1; ++j) {
1156 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
1157 myHS1, myHS2, myFace1, myFace2, myContext);
1162 }//for (i=1; i<=aNbLin; ++i) {
1163 myTolReached3d=sqrt(aD2Max);
1166 //=======================================================================
1167 //function : MakeCurve
1169 //=======================================================================
1170 void IntTools_FaceFace::MakeCurve(const Standard_Integer Index,
1171 const Handle(Adaptor3d_TopolTool)& dom1,
1172 const Handle(Adaptor3d_TopolTool)& dom2)
1174 Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor;
1175 Standard_Boolean ok, bPCurvesOk;
1176 Standard_Integer i, j, aNbParts;
1177 Standard_Real fprm, lprm;
1178 Standard_Real Tolpc;
1179 Handle(IntPatch_Line) L;
1180 IntPatch_IType typl;
1181 Handle(Geom_Curve) newc;
1183 const Standard_Real TOLCHECK =0.0000001;
1184 const Standard_Real TOLANGCHECK=0.1;
1186 rejectSurface = Standard_False;
1187 reApprox = Standard_False;
1189 bPCurvesOk = Standard_True;
1193 Tolpc = myTolApprox;
1194 bAvoidLineConstructor = Standard_False;
1195 L = myIntersector.Line(Index);
1196 typl = L->ArcType();
1198 if(typl==IntPatch_Walking) {
1199 Handle(IntPatch_Line) anewL;
1201 const Handle(IntPatch_WLine)& aWLine=
1202 Handle(IntPatch_WLine)::DownCast(L);
1203 //DumpWLine(aWLine);
1205 anewL = ComputePurgedWLine(aWLine);
1206 if(anewL.IsNull()) {
1211 //const Handle(IntPatch_WLine)& aWLineX = Handle(IntPatch_WLine)::DownCast(L);
1212 //DumpWLine(aWLineX);
1215 if(!myListOfPnts.IsEmpty()) {
1216 bAvoidLineConstructor = Standard_True;
1219 Standard_Integer nbp = aWLine->NbPnts();
1220 const IntSurf_PntOn2S& p1 = aWLine->Point(1);
1221 const IntSurf_PntOn2S& p2 = aWLine->Point(nbp);
1223 const gp_Pnt& P1 = p1.Value();
1224 const gp_Pnt& P2 = p2.Value();
1226 if(P1.SquareDistance(P2) < 1.e-14) {
1227 bAvoidLineConstructor = Standard_False;
1232 if(!bAvoidLineConstructor) {
1233 myLConstruct.Perform(L);
1235 bDone=myLConstruct.IsDone();
1236 aNbParts=myLConstruct.NbParts();
1237 if (!bDone|| !aNbParts) {
1246 //########################################
1247 // Line, Parabola, Hyperbola
1248 //########################################
1250 case IntPatch_Parabola:
1251 case IntPatch_Hyperbola: {
1252 if (typl == IntPatch_Lin) {
1254 new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
1257 else if (typl == IntPatch_Parabola) {
1259 new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
1262 else if (typl == IntPatch_Hyperbola) {
1264 new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
1268 if (typl == IntPatch_Lin) {
1269 TolR3d (myFace1, myFace2, myTolReached3d);
1272 aNbParts=myLConstruct.NbParts();
1273 for (i=1; i<=aNbParts; i++) {
1274 myLConstruct.Part(i, fprm, lprm);
1276 if (!Precision::IsNegativeInfinite(fprm) &&
1277 !Precision::IsPositiveInfinite(lprm)) {
1279 IntTools_Curve aCurve;
1281 Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
1282 aCurve.SetCurve(aCT3D);
1283 if (typl == IntPatch_Parabola) {
1284 Standard_Real aTolF1, aTolF2, aTolBase;
1286 aTolF1 = BRep_Tool::Tolerance(myFace1);
1287 aTolF2 = BRep_Tool::Tolerance(myFace2);
1288 aTolBase=aTolF1+aTolF2;
1289 myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
1292 aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
1294 Handle (Geom2d_Curve) C2d;
1295 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1296 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1297 myTolReached2d=Tolpc;
1300 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1303 Handle(Geom2d_BSplineCurve) H1;
1305 aCurve.SetFirstCurve2d(H1);
1309 Handle (Geom2d_Curve) C2d;
1310 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1311 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1312 myTolReached2d=Tolpc;
1315 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1318 Handle(Geom2d_BSplineCurve) H1;
1320 aCurve.SetSecondCurve2d(H1);
1322 mySeqOfCurve.Append(aCurve);
1323 } // end of if (!Precision::IsNegativeInfinite(fprm) && !Precision::IsPositiveInfinite(lprm))
1325 // on regarde si on garde
1327 Standard_Boolean bFNIt, bLPIt;
1328 Standard_Real aTestPrm, dT=100.;
1330 bFNIt=Precision::IsNegativeInfinite(fprm);
1331 bLPIt=Precision::IsPositiveInfinite(lprm);
1335 if (bFNIt && !bLPIt) {
1338 else if (!bFNIt && bLPIt) {
1342 gp_Pnt ptref(newc->Value(aTestPrm));
1344 GeomAbs_SurfaceType typS1 = myHS1->GetType();
1345 GeomAbs_SurfaceType typS2 = myHS2->GetType();
1346 if( typS1 == GeomAbs_SurfaceOfExtrusion ||
1347 typS1 == GeomAbs_OffsetSurface ||
1348 typS1 == GeomAbs_SurfaceOfRevolution ||
1349 typS2 == GeomAbs_SurfaceOfExtrusion ||
1350 typS2 == GeomAbs_OffsetSurface ||
1351 typS2 == GeomAbs_SurfaceOfRevolution)
1353 Handle(Geom2d_BSplineCurve) H1;
1354 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1358 Standard_Real u1, v1, u2, v2, Tol;
1360 Tol = Precision::Confusion();
1361 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1362 ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
1364 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1367 Handle(Geom2d_BSplineCurve) H1;
1368 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1371 }// end of for (i=1; i<=myLConstruct.NbParts(); i++)
1372 }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola:
1375 //########################################
1376 // Circle and Ellipse
1377 //########################################
1378 case IntPatch_Circle:
1379 case IntPatch_Ellipse: {
1381 if (typl == IntPatch_Circle) {
1382 newc = new Geom_Circle
1383 (Handle(IntPatch_GLine)::DownCast(L)->Circle());
1385 else { //IntPatch_Ellipse
1386 newc = new Geom_Ellipse
1387 (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
1391 TolR3d (myFace1, myFace2, myTolReached3d);
1393 aNbParts=myLConstruct.NbParts();
1395 Standard_Real aPeriod, aNul;
1396 TColStd_SequenceOfReal aSeqFprm, aSeqLprm;
1401 for (i=1; i<=aNbParts; i++) {
1402 myLConstruct.Part(i, fprm, lprm);
1404 if (fprm < aNul && lprm > aNul) {
1405 // interval that goes through 0. is divided on two intervals;
1406 while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
1407 while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
1409 if((aPeriod - fprm) > Tolpc) {
1410 aSeqFprm.Append(fprm);
1411 aSeqLprm.Append(aPeriod);
1414 gp_Pnt P1 = newc->Value(fprm);
1415 gp_Pnt P2 = newc->Value(aPeriod);
1416 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1417 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1419 if(P1.Distance(P2) > aTolDist) {
1420 Standard_Real anewpar = fprm;
1422 if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2,
1423 lprm, Standard_False, anewpar, myContext)) {
1426 aSeqFprm.Append(fprm);
1427 aSeqLprm.Append(aPeriod);
1432 if((lprm - aNul) > Tolpc) {
1433 aSeqFprm.Append(aNul);
1434 aSeqLprm.Append(lprm);
1437 gp_Pnt P1 = newc->Value(aNul);
1438 gp_Pnt P2 = newc->Value(lprm);
1439 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1440 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1442 if(P1.Distance(P2) > aTolDist) {
1443 Standard_Real anewpar = lprm;
1445 if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2,
1446 fprm, Standard_True, anewpar, myContext)) {
1449 aSeqFprm.Append(aNul);
1450 aSeqLprm.Append(lprm);
1456 aSeqFprm.Append(fprm);
1457 aSeqLprm.Append(lprm);
1462 aNbParts=aSeqFprm.Length();
1463 for (i=1; i<=aNbParts; i++) {
1467 Standard_Real aRealEpsilon=RealEpsilon();
1468 if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*M_PI) > aRealEpsilon) {
1469 //==============================================
1471 IntTools_Curve aCurve;
1472 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1473 aCurve.SetCurve(aTC3D);
1474 fprm=aTC3D->FirstParameter();
1475 lprm=aTC3D->LastParameter ();
1477 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {////
1479 Handle (Geom2d_Curve) C2d;
1480 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1481 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1482 myTolReached2d=Tolpc;
1485 aCurve.SetFirstCurve2d(C2d);
1488 Handle(Geom2d_BSplineCurve) H1;
1489 aCurve.SetFirstCurve2d(H1);
1494 Handle (Geom2d_Curve) C2d;
1495 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1496 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1497 myTolReached2d=Tolpc;
1500 aCurve.SetSecondCurve2d(C2d);
1503 Handle(Geom2d_BSplineCurve) H1;
1504 aCurve.SetSecondCurve2d(H1);
1509 Handle(Geom2d_BSplineCurve) H1;
1510 aCurve.SetFirstCurve2d(H1);
1511 aCurve.SetSecondCurve2d(H1);
1513 mySeqOfCurve.Append(aCurve);
1514 //==============================================
1515 } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon())
1518 // on regarde si on garde
1521 // if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) {
1522 if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
1523 IntTools_Curve aCurve;
1524 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1525 aCurve.SetCurve(aTC3D);
1526 fprm=aTC3D->FirstParameter();
1527 lprm=aTC3D->LastParameter ();
1530 Handle (Geom2d_Curve) C2d;
1531 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1532 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1533 myTolReached2d=Tolpc;
1536 aCurve.SetFirstCurve2d(C2d);
1539 Handle(Geom2d_BSplineCurve) H1;
1540 aCurve.SetFirstCurve2d(H1);
1544 Handle (Geom2d_Curve) C2d;
1545 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1546 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1547 myTolReached2d=Tolpc;
1550 aCurve.SetSecondCurve2d(C2d);
1553 Handle(Geom2d_BSplineCurve) H1;
1554 aCurve.SetSecondCurve2d(H1);
1556 mySeqOfCurve.Append(aCurve);
1561 Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
1563 aTwoPIdiv17=2.*M_PI/17.;
1565 for (j=0; j<=17; j++) {
1566 gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
1567 Tol = Precision::Confusion();
1569 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1570 ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
1572 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1575 IntTools_Curve aCurve;
1576 aCurve.SetCurve(newc);
1577 //==============================================
1578 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
1581 Handle (Geom2d_Curve) C2d;
1582 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1583 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1584 myTolReached2d=Tolpc;
1587 aCurve.SetFirstCurve2d(C2d);
1590 Handle(Geom2d_BSplineCurve) H1;
1591 aCurve.SetFirstCurve2d(H1);
1595 Handle (Geom2d_Curve) C2d;
1596 BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
1597 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1598 myTolReached2d=Tolpc;
1601 aCurve.SetSecondCurve2d(C2d);
1605 Handle(Geom2d_BSplineCurve) H1;
1606 aCurve.SetSecondCurve2d(H1);
1608 }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
1611 Handle(Geom2d_BSplineCurve) H1;
1613 aCurve.SetFirstCurve2d(H1);
1614 aCurve.SetSecondCurve2d(H1);
1616 //==============================================
1618 mySeqOfCurve.Append(aCurve);
1621 }// end of if (ok) {
1622 }// end of for (Standard_Integer j=0; j<=17; j++)
1623 }// end of else { on regarde si on garde
1624 }// for (i=1; i<=myLConstruct.NbParts(); i++)
1625 }// IntPatch_Circle: IntPatch_Ellipse:
1628 case IntPatch_Analytic: {
1629 IntSurf_Quadric quad1,quad2;
1630 GeomAbs_SurfaceType typs = myHS1->Surface().GetType();
1634 quad1.SetValue(myHS1->Surface().Plane());
1636 case GeomAbs_Cylinder:
1637 quad1.SetValue(myHS1->Surface().Cylinder());
1640 quad1.SetValue(myHS1->Surface().Cone());
1642 case GeomAbs_Sphere:
1643 quad1.SetValue(myHS1->Surface().Sphere());
1646 quad1.SetValue(myHS1->Surface().Torus());
1649 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
1652 typs = myHS2->Surface().GetType();
1656 quad2.SetValue(myHS2->Surface().Plane());
1658 case GeomAbs_Cylinder:
1659 quad2.SetValue(myHS2->Surface().Cylinder());
1662 quad2.SetValue(myHS2->Surface().Cone());
1664 case GeomAbs_Sphere:
1665 quad2.SetValue(myHS2->Surface().Sphere());
1668 quad2.SetValue(myHS2->Surface().Torus());
1671 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
1675 IntPatch_ALineToWLine convert (quad1, quad2);
1678 aNbParts=myLConstruct.NbParts();
1679 for (i=1; i<=aNbParts; i++) {
1680 myLConstruct.Part(i, fprm, lprm);
1681 Handle(IntPatch_WLine) WL =
1682 convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
1684 Handle(Geom2d_BSplineCurve) H1;
1685 Handle(Geom2d_BSplineCurve) H2;
1688 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1692 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1695 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1699 else { // myApprox=TRUE
1700 GeomInt_WLApprox theapp3d;
1702 Standard_Real tol2d = myTolApprox;
1704 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
1706 aNbParts=myLConstruct.NbParts();
1707 for (i=1; i<=aNbParts; i++) {
1708 myLConstruct.Part(i, fprm, lprm);
1709 Handle(IntPatch_WLine) WL =
1710 convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
1712 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
1714 if (!theapp3d.IsDone()) {
1716 Handle(Geom2d_BSplineCurve) H1;
1717 Handle(Geom2d_BSplineCurve) H2;
1720 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1724 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1727 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1731 if(myApprox1 || myApprox2) {
1732 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
1733 myTolReached2d = theapp3d.TolReached2d();
1737 if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
1738 myTolReached3d = theapp3d.TolReached3d();
1741 Standard_Integer aNbMultiCurves, nbpoles;
1742 aNbMultiCurves=theapp3d.NbMultiCurves();
1743 for (j=1; j<=aNbMultiCurves; j++) {
1744 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1745 nbpoles = mbspc.NbPoles();
1747 TColgp_Array1OfPnt tpoles(1, nbpoles);
1748 mbspc.Curve(1, tpoles);
1749 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1751 mbspc.Multiplicities(),
1754 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1755 Check.FixTangent(Standard_True,Standard_True);
1757 IntTools_Curve aCurve;
1758 aCurve.SetCurve(BS);
1761 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1762 mbspc.Curve(2,tpoles2d);
1763 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1765 mbspc.Multiplicities(),
1768 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1769 newCheck.FixTangent(Standard_True,Standard_True);
1771 aCurve.SetFirstCurve2d(BS2);
1774 Handle(Geom2d_BSplineCurve) H1;
1775 aCurve.SetFirstCurve2d(H1);
1779 TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
1780 Standard_Integer TwoOrThree;
1781 TwoOrThree=myApprox1 ? 3 : 2;
1782 mbspc.Curve(TwoOrThree, tpoles2d);
1783 Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
1785 mbspc.Multiplicities(),
1788 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1789 newCheck.FixTangent(Standard_True,Standard_True);
1791 aCurve.SetSecondCurve2d(BS2);
1794 Handle(Geom2d_BSplineCurve) H2;
1795 aCurve.SetSecondCurve2d(H2);
1798 mySeqOfCurve.Append(aCurve);
1800 }// for (j=1; j<=aNbMultiCurves; j++) {
1801 }// else from if (!theapp3d.IsDone())
1802 }// for (i=1; i<=aNbParts; i++) {
1803 }// else { // myApprox=TRUE
1804 }// case IntPatch_Analytic:
1807 case IntPatch_Walking:{
1808 Handle(IntPatch_WLine) WL =
1809 Handle(IntPatch_WLine)::DownCast(L);
1811 Standard_Integer ifprm, ilprm;
1815 if(!bAvoidLineConstructor){
1816 aNbParts=myLConstruct.NbParts();
1818 for (i=1; i<=aNbParts; ++i) {
1819 Handle(Geom2d_BSplineCurve) H1, H2;
1820 Handle(Geom_Curve) aBSp;
1822 if(bAvoidLineConstructor) {
1824 ilprm = WL->NbPnts();
1827 myLConstruct.Part(i, fprm, lprm);
1828 ifprm=(Standard_Integer)fprm;
1829 ilprm=(Standard_Integer)lprm;
1833 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1837 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1840 aBSp=MakeBSpline(WL, ifprm, ilprm);
1841 IntTools_Curve aIC(aBSp, H1, H2);
1842 mySeqOfCurve.Append(aIC);
1843 }// for (i=1; i<=aNbParts; ++i) {
1844 }// if (!myApprox) {
1847 Standard_Boolean bIsDecomposited;
1848 Standard_Integer nbiter, aNbSeqOfL;
1849 Standard_Real tol2d, aTolApproxImp;
1850 IntPatch_SequenceOfLine aSeqOfL;
1851 GeomInt_WLApprox theapp3d;
1852 Approx_ParametrizationType aParType = Approx_ChordLength;
1854 Standard_Boolean anApprox1 = myApprox1;
1855 Standard_Boolean anApprox2 = myApprox2;
1857 aTolApproxImp=1.e-5;
1858 tol2d = myTolApprox;
1860 GeomAbs_SurfaceType typs1, typs2;
1861 typs1 = myHS1->Surface().GetType();
1862 typs2 = myHS2->Surface().GetType();
1863 Standard_Boolean anWithPC = Standard_True;
1865 if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
1867 ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
1869 else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
1871 ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
1875 myTolApprox = aTolApproxImp;//1.e-5;
1876 anApprox1 = Standard_False;
1877 anApprox2 = Standard_False;
1879 tol2d = myTolApprox;
1882 if(myHS1 == myHS2) {
1883 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1884 rejectSurface = Standard_True;
1887 if(reApprox && !rejectSurface)
1888 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1890 Standard_Integer iDegMax, iDegMin, iNbIter;
1892 ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter);
1893 theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType);
1897 Standard_Real aReachedTol = Precision::Confusion();
1898 bIsDecomposited=DecompositionOfWLine(WL,
1904 bAvoidLineConstructor,
1908 if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) ) {
1909 myTolReached3d = aReachedTol;
1912 aNbSeqOfL=aSeqOfL.Length();
1914 if (bIsDecomposited) {
1920 if (!bAvoidLineConstructor) {
1921 aNbParts=myLConstruct.NbParts();
1926 for(i = 1; i <= nbiter; ++i) {
1927 if(bIsDecomposited) {
1928 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
1930 ilprm = WL->NbPnts();
1933 if(bAvoidLineConstructor) {
1935 ilprm = WL->NbPnts();
1938 myLConstruct.Part(i, fprm, lprm);
1939 ifprm = (Standard_Integer)fprm;
1940 ilprm = (Standard_Integer)lprm;
1944 //-- Si une des surfaces est un plan , on approxime en 2d
1945 //-- sur cette surface et on remonte les points 2d en 3d.
1946 if(typs1 == GeomAbs_Plane) {
1947 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
1949 else if(typs2 == GeomAbs_Plane) {
1950 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
1954 if (myHS1 != myHS2){
1955 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
1956 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
1958 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
1960 Standard_Boolean bUseSurfaces;
1961 bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
1964 rejectSurface = Standard_True;
1966 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1971 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
1974 if (!theapp3d.IsDone()) {
1975 Handle(Geom2d_BSplineCurve) H1;
1976 Handle(Geom2d_BSplineCurve) H2;
1978 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
1981 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1985 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1988 IntTools_Curve aIC(aBSp, H1, H2);
1989 mySeqOfCurve.Append(aIC);
1993 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
1994 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
1995 myTolReached2d = theapp3d.TolReached2d();
1998 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
1999 myTolReached3d = myTolReached2d;
2001 if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
2002 if (myTolReached3d<1.e-6) {
2003 myTolReached3d = theapp3d.TolReached3d();
2004 myTolReached3d=1.e-6;
2008 else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
2009 myTolReached3d = theapp3d.TolReached3d();
2012 Standard_Integer aNbMultiCurves, nbpoles;
2013 aNbMultiCurves=theapp3d.NbMultiCurves();
2014 for (j=1; j<=aNbMultiCurves; j++) {
2015 if(typs1 == GeomAbs_Plane) {
2016 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2017 nbpoles = mbspc.NbPoles();
2019 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2020 TColgp_Array1OfPnt tpoles(1,nbpoles);
2022 mbspc.Curve(1,tpoles2d);
2023 const gp_Pln& Pln = myHS1->Surface().Plane();
2025 Standard_Integer ik;
2026 for(ik = 1; ik<= nbpoles; ik++) {
2028 ElSLib::Value(tpoles2d.Value(ik).X(),
2029 tpoles2d.Value(ik).Y(),
2033 Handle(Geom_BSplineCurve) BS =
2034 new Geom_BSplineCurve(tpoles,
2036 mbspc.Multiplicities(),
2038 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2039 Check.FixTangent(Standard_True, Standard_True);
2041 IntTools_Curve aCurve;
2042 aCurve.SetCurve(BS);
2045 Handle(Geom2d_BSplineCurve) BS1 =
2046 new Geom2d_BSplineCurve(tpoles2d,
2048 mbspc.Multiplicities(),
2050 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2051 Check1.FixTangent(Standard_True,Standard_True);
2053 // ############################################
2054 if(!rejectSurface && !reApprox) {
2055 Standard_Boolean isValid = IsCurveValid(BS1);
2057 reApprox = Standard_True;
2061 // ############################################
2062 aCurve.SetFirstCurve2d(BS1);
2065 Handle(Geom2d_BSplineCurve) H1;
2066 aCurve.SetFirstCurve2d(H1);
2070 mbspc.Curve(2, tpoles2d);
2072 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
2074 mbspc.Multiplicities(),
2076 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2077 newCheck.FixTangent(Standard_True,Standard_True);
2079 // ###########################################
2080 if(!rejectSurface && !reApprox) {
2081 Standard_Boolean isValid = IsCurveValid(BS2);
2083 reApprox = Standard_True;
2087 // ###########################################
2089 aCurve.SetSecondCurve2d(BS2);
2092 Handle(Geom2d_BSplineCurve) H2;
2094 aCurve.SetSecondCurve2d(H2);
2097 mySeqOfCurve.Append(aCurve);
2098 }//if(typs1 == GeomAbs_Plane) {
2100 else if(typs2 == GeomAbs_Plane) {
2101 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2102 nbpoles = mbspc.NbPoles();
2104 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2105 TColgp_Array1OfPnt tpoles(1,nbpoles);
2106 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
2107 const gp_Pln& Pln = myHS2->Surface().Plane();
2109 Standard_Integer ik;
2110 for(ik = 1; ik<= nbpoles; ik++) {
2112 ElSLib::Value(tpoles2d.Value(ik).X(),
2113 tpoles2d.Value(ik).Y(),
2118 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
2120 mbspc.Multiplicities(),
2122 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2123 Check.FixTangent(Standard_True,Standard_True);
2125 IntTools_Curve aCurve;
2126 aCurve.SetCurve(BS);
2129 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
2131 mbspc.Multiplicities(),
2133 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2134 Check1.FixTangent(Standard_True,Standard_True);
2136 // ###########################################
2137 if(!rejectSurface && !reApprox) {
2138 Standard_Boolean isValid = IsCurveValid(BS1);
2140 reApprox = Standard_True;
2144 // ###########################################
2145 bPCurvesOk = CheckPCurve(BS1, myFace2);
2146 aCurve.SetSecondCurve2d(BS1);
2149 Handle(Geom2d_BSplineCurve) H2;
2150 aCurve.SetSecondCurve2d(H2);
2154 mbspc.Curve(1,tpoles2d);
2155 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
2157 mbspc.Multiplicities(),
2159 GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
2160 Check2.FixTangent(Standard_True,Standard_True);
2162 // ###########################################
2163 if(!rejectSurface && !reApprox) {
2164 Standard_Boolean isValid = IsCurveValid(BS2);
2166 reApprox = Standard_True;
2170 // ###########################################
2171 bPCurvesOk = bPCurvesOk && CheckPCurve(BS2, myFace1);
2172 aCurve.SetFirstCurve2d(BS2);
2175 Handle(Geom2d_BSplineCurve) H1;
2177 aCurve.SetFirstCurve2d(H1);
2180 //if points of the pcurves are out of the faces bounds
2181 //create 3d and 2d curves without approximation
2183 Handle(Geom2d_BSplineCurve) H1, H2;
2184 bPCurvesOk = Standard_True;
2186 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
2189 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
2190 bPCurvesOk = CheckPCurve(H1, myFace1);
2194 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
2195 bPCurvesOk = bPCurvesOk && CheckPCurve(H2, myFace2);
2198 //if pcurves created without approximation are out of the
2199 //faces bounds, use approximated 3d and 2d curves
2201 IntTools_Curve aIC(aBSp, H1, H2);
2202 mySeqOfCurve.Append(aIC);
2204 mySeqOfCurve.Append(aCurve);
2207 mySeqOfCurve.Append(aCurve);
2209 }// else if(typs2 == GeomAbs_Plane)
2211 else { //typs2 != GeomAbs_Plane && typs1 != GeomAbs_Plane
2212 Standard_Boolean bIsValid1, bIsValid2;
2213 Handle(Geom_BSplineCurve) BS;
2214 Handle(Geom2d_BSplineCurve) aH2D;
2215 IntTools_Curve aCurve;
2217 bIsValid1=Standard_True;
2218 bIsValid2=Standard_True;
2220 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2221 nbpoles = mbspc.NbPoles();
2222 TColgp_Array1OfPnt tpoles(1,nbpoles);
2223 mbspc.Curve(1,tpoles);
2224 BS=new Geom_BSplineCurve(tpoles,
2226 mbspc.Multiplicities(),
2228 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2229 Check.FixTangent(Standard_True,Standard_True);
2231 aCurve.SetCurve(BS);
2232 aCurve.SetFirstCurve2d(aH2D);
2233 aCurve.SetSecondCurve2d(aH2D);
2237 Handle(Geom2d_BSplineCurve) BS1;
2238 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2239 mbspc.Curve(2,tpoles2d);
2241 BS1=new Geom2d_BSplineCurve(tpoles2d,
2243 mbspc.Multiplicities(),
2245 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
2246 newCheck.FixTangent(Standard_True,Standard_True);
2249 bIsValid1=CheckPCurve(BS1, myFace1);
2252 aCurve.SetFirstCurve2d(BS1);
2255 Handle(Geom2d_BSplineCurve) BS1;
2256 fprm = BS->FirstParameter();
2257 lprm = BS->LastParameter();
2259 Handle(Geom2d_Curve) C2d;
2260 Standard_Real aTol = myTolApprox;
2261 BuildPCurves(fprm, lprm, aTol, myHS1->ChangeSurface().Surface(), BS, C2d);
2262 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2263 aCurve.SetFirstCurve2d(BS1);
2265 } // if(myApprox1) {
2269 Handle(Geom2d_BSplineCurve) BS2;
2270 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2271 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
2272 BS2=new Geom2d_BSplineCurve(tpoles2d,
2274 mbspc.Multiplicities(),
2276 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2277 newCheck.FixTangent(Standard_True,Standard_True);
2280 bIsValid2=CheckPCurve(BS2, myFace2);
2282 aCurve.SetSecondCurve2d(BS2);
2285 Handle(Geom2d_BSplineCurve) BS2;
2286 fprm = BS->FirstParameter();
2287 lprm = BS->LastParameter();
2289 Handle(Geom2d_Curve) C2d;
2290 Standard_Real aTol = myTolApprox;
2291 BuildPCurves(fprm, lprm, aTol, myHS2->ChangeSurface().Surface(), BS, C2d);
2292 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2293 aCurve.SetSecondCurve2d(BS2);
2296 if (!bIsValid1 || !bIsValid2) {
2297 myTolApprox=aTolApproxImp;//1.e-5;
2298 tol2d = myTolApprox;
2299 reApprox = Standard_True;
2303 mySeqOfCurve.Append(aCurve);
2309 }// case IntPatch_Walking:{
2312 case IntPatch_Restriction:
2320 //=======================================================================
2321 //function : BuildPCurves
2323 //=======================================================================
2324 void BuildPCurves (Standard_Real f,
2327 const Handle (Geom_Surface)& S,
2328 const Handle (Geom_Curve)& C,
2329 Handle (Geom2d_Curve)& C2d)
2331 if (!C2d.IsNull()) {
2335 Standard_Real umin,umax,vmin,vmax;
2337 S->Bounds(umin, umax, vmin, vmax);
2338 // in class ProjLib_Function the range of parameters is shrank by 1.e-09
2339 if((l - f) > 2.e-09) {
2340 C2d = GeomProjLib::Curve2d(C,f,l,S,umin,umax,vmin,vmax,Tol);
2343 // proj. a circle that goes through the pole on a sphere to the sphere
2344 Tol += Precision::Confusion();
2345 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2349 if((l - f) > Epsilon(Abs(f))) {
2350 GeomAPI_ProjectPointOnSurf aProjector1, aProjector2;
2351 gp_Pnt P1 = C->Value(f);
2352 gp_Pnt P2 = C->Value(l);
2353 aProjector1.Init(P1, S);
2354 aProjector2.Init(P2, S);
2356 if(aProjector1.IsDone() && aProjector2.IsDone()) {
2357 Standard_Real U=0., V=0.;
2358 aProjector1.LowerDistanceParameters(U, V);
2361 aProjector2.LowerDistanceParameters(U, V);
2364 if(p1.Distance(p2) > gp::Resolution()) {
2365 TColgp_Array1OfPnt2d poles(1,2);
2366 TColStd_Array1OfReal knots(1,2);
2367 TColStd_Array1OfInteger mults(1,2);
2372 mults(1) = mults(2) = 2;
2374 C2d = new Geom2d_BSplineCurve(poles,knots,mults,1);
2376 // compute reached tolerance.begin
2377 gp_Pnt PMid = C->Value((f + l) * 0.5);
2378 aProjector1.Perform(PMid);
2380 if(aProjector1.IsDone()) {
2381 aProjector1.LowerDistanceParameters(U, V);
2382 gp_Pnt2d pmidproj(U, V);
2383 gp_Pnt2d pmidcurve2d = C2d->Value((f + l) * 0.5);
2384 Standard_Real adist = pmidcurve2d.Distance(pmidproj);
2385 Tol = (adist > Tol) ? adist : Tol;
2387 // compute reached tolerance.end
2393 if (S->IsUPeriodic() && !C2d.IsNull()) {
2394 // Recadre dans le domaine UV de la face
2395 Standard_Real aTm, U0, aEps, period, du, U0x;
2396 Standard_Boolean bAdjust;
2398 aEps = Precision::PConfusion();
2399 period = S->UPeriod();
2402 gp_Pnt2d pm = C2d->Value(aTm);
2406 IntTools_Tools::AdjustPeriodic(U0, umin, umax, period, U0x, du, aEps);
2408 gp_Vec2d T1(du, 0.);
2414 //=======================================================================
2415 //function : Parameters
2417 //=======================================================================
2418 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
2419 const Handle(GeomAdaptor_HSurface)& HS2,
2420 const gp_Pnt& Ptref,
2427 IntSurf_Quadric quad1,quad2;
2428 GeomAbs_SurfaceType typs = HS1->Surface().GetType();
2432 quad1.SetValue(HS1->Surface().Plane());
2434 case GeomAbs_Cylinder:
2435 quad1.SetValue(HS1->Surface().Cylinder());
2438 quad1.SetValue(HS1->Surface().Cone());
2440 case GeomAbs_Sphere:
2441 quad1.SetValue(HS1->Surface().Sphere());
2444 quad1.SetValue(HS1->Surface().Torus());
2447 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2450 typs = HS2->Surface().GetType();
2453 quad2.SetValue(HS2->Surface().Plane());
2455 case GeomAbs_Cylinder:
2456 quad2.SetValue(HS2->Surface().Cylinder());
2459 quad2.SetValue(HS2->Surface().Cone());
2461 case GeomAbs_Sphere:
2462 quad2.SetValue(HS2->Surface().Sphere());
2465 quad2.SetValue(HS2->Surface().Torus());
2468 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2471 quad1.Parameters(Ptref,U1,V1);
2472 quad2.Parameters(Ptref,U2,V2);
2475 //=======================================================================
2476 //function : MakeBSpline
2478 //=======================================================================
2479 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
2480 const Standard_Integer ideb,
2481 const Standard_Integer ifin)
2483 Standard_Integer i,nbpnt = ifin-ideb+1;
2484 TColgp_Array1OfPnt poles(1,nbpnt);
2485 TColStd_Array1OfReal knots(1,nbpnt);
2486 TColStd_Array1OfInteger mults(1,nbpnt);
2487 Standard_Integer ipidebm1;
2488 for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) {
2489 poles(i) = WL->Point(ipidebm1).Value();
2493 mults(1) = mults(nbpnt) = 2;
2495 new Geom_BSplineCurve(poles,knots,mults,1);
2499 //=======================================================================
2500 //function : MakeBSpline2d
2502 //=======================================================================
2503 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
2504 const Standard_Integer ideb,
2505 const Standard_Integer ifin,
2506 const Standard_Boolean onFirst)
2508 Standard_Integer i, nbpnt = ifin-ideb+1;
2509 TColgp_Array1OfPnt2d poles(1,nbpnt);
2510 TColStd_Array1OfReal knots(1,nbpnt);
2511 TColStd_Array1OfInteger mults(1,nbpnt);
2512 Standard_Integer ipidebm1;
2514 for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
2517 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
2519 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
2520 poles(i).SetCoord(U, V);
2524 mults(1) = mults(nbpnt) = 2;
2526 return new Geom2d_BSplineCurve(poles,knots,mults,1);
2528 //=======================================================================
2529 //function : PrepareLines3D
2531 //=======================================================================
2532 void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit)
2534 Standard_Integer i, aNbCurves;
2535 GeomAbs_SurfaceType aType1, aType2;
2536 IntTools_SequenceOfCurves aNewCvs;
2538 // 1. Treatment closed curves
2539 aNbCurves=mySeqOfCurve.Length();
2540 for (i=1; i<=aNbCurves; ++i) {
2541 const IntTools_Curve& aIC=mySeqOfCurve(i);
2544 Standard_Integer j, aNbC;
2545 IntTools_SequenceOfCurves aSeqCvs;
2547 aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
2549 for (j=1; j<=aNbC; ++j) {
2550 const IntTools_Curve& aICNew=aSeqCvs(j);
2551 aNewCvs.Append(aICNew);
2555 aNewCvs.Append(aIC);
2559 aNewCvs.Append(aIC);
2563 // 2. Plane\Cone intersection when we had 4 curves
2564 aType1=myHS1->GetType();
2565 aType2=myHS2->GetType();
2566 aNbCurves=aNewCvs.Length();
2568 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) ||
2569 (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) {
2571 GeomAbs_CurveType aCType1;
2573 aCType1=aNewCvs(1).Type();
2574 if (aCType1==GeomAbs_Line) {
2575 IntTools_SequenceOfCurves aSeqIn, aSeqOut;
2577 for (i=1; i<=aNbCurves; ++i) {
2578 const IntTools_Curve& aIC=aNewCvs(i);
2582 IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
2585 aNbCurves=aSeqOut.Length();
2586 for (i=1; i<=aNbCurves; ++i) {
2587 const IntTools_Curve& aIC=aSeqOut(i);
2588 aNewCvs.Append(aIC);
2592 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)...
2594 // 3. Fill mySeqOfCurve
2595 mySeqOfCurve.Clear();
2596 aNbCurves=aNewCvs.Length();
2597 for (i=1; i<=aNbCurves; ++i) {
2598 const IntTools_Curve& aIC=aNewCvs(i);
2599 mySeqOfCurve.Append(aIC);
2602 //=======================================================================
2603 //function : CorrectSurfaceBoundaries
2605 //=======================================================================
2606 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
2607 const Standard_Real theTolerance,
2608 Standard_Real& theumin,
2609 Standard_Real& theumax,
2610 Standard_Real& thevmin,
2611 Standard_Real& thevmax)
2613 Standard_Boolean enlarge, isuperiodic, isvperiodic;
2614 Standard_Real uinf, usup, vinf, vsup, delta;
2615 GeomAbs_SurfaceType aType;
2616 Handle(Geom_Surface) aSurface;
2618 aSurface = BRep_Tool::Surface(theFace);
2619 aSurface->Bounds(uinf, usup, vinf, vsup);
2620 delta = theTolerance;
2621 enlarge = Standard_False;
2623 GeomAdaptor_Surface anAdaptorSurface(aSurface);
2625 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
2626 Handle(Geom_Surface) aBasisSurface =
2627 (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface();
2629 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2630 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2635 if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2636 Handle(Geom_Surface) aBasisSurface =
2637 (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface();
2639 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2640 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2645 isuperiodic = anAdaptorSurface.IsUPeriodic();
2646 isvperiodic = anAdaptorSurface.IsVPeriodic();
2648 aType=anAdaptorSurface.GetType();
2649 if((aType==GeomAbs_BezierSurface) ||
2650 (aType==GeomAbs_BSplineSurface) ||
2651 (aType==GeomAbs_SurfaceOfExtrusion) ||
2652 (aType==GeomAbs_SurfaceOfRevolution) ||
2653 (aType==GeomAbs_Cylinder)) {
2654 enlarge=Standard_True;
2657 if(!isuperiodic && enlarge) {
2659 if((theumin - uinf) > delta )
2665 if((usup - theumax) > delta )
2671 if(!isvperiodic && enlarge) {
2672 if((thevmin - vinf) > delta ) {
2678 if((vsup - thevmax) > delta ) {
2687 Standard_Integer aNbP;
2688 Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA;
2690 aTolPA=Precision::Angular();
2693 aXP=anAdaptorSurface.UPeriod();
2694 dXfact=theumax-theumin;
2695 if (dXfact-aTolPA>aXP) {
2696 aXmid=0.5*(theumax+theumin);
2697 aNbP=RealToInt(aXmid/aXP);
2702 if (theumin>aTolPA) {
2703 aX1=theumin+aNbP*aXP;
2716 aXP=anAdaptorSurface.VPeriod();
2717 dXfact=thevmax-thevmin;
2718 if (dXfact-aTolPA>aXP) {
2719 aXmid=0.5*(thevmax+thevmin);
2720 aNbP=RealToInt(aXmid/aXP);
2725 if (thevmin>aTolPA) {
2726 aX1=thevmin+aNbP*aXP;
2739 if(isuperiodic || isvperiodic) {
2740 Standard_Boolean correct = Standard_False;
2741 Standard_Boolean correctU = Standard_False;
2742 Standard_Boolean correctV = Standard_False;
2744 TopExp_Explorer anExp;
2746 for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2747 if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
2748 correct = Standard_True;
2750 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
2752 for(Standard_Integer i = 0; i < 2; i++) {
2754 anEdge.Orientation(TopAbs_FORWARD);
2757 anEdge.Orientation(TopAbs_REVERSED);
2759 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
2761 if(aCurve.IsNull()) {
2762 correct = Standard_False;
2765 Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
2767 if(aLine.IsNull()) {
2768 correct = Standard_False;
2771 gp_Dir2d anUDir(1., 0.);
2772 gp_Dir2d aVDir(0., 1.);
2773 Standard_Real anAngularTolerance = Precision::Angular();
2775 correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
2776 correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
2778 gp_Pnt2d pp1 = aCurve->Value(f);
2780 gp_Pnt2d pp2 = aCurve->Value(l);
2789 Standard_Real umin, vmin, umax, vmax;
2790 aBox.Get(umin, vmin, umax, vmax);
2792 if(isuperiodic && correctU) {
2797 if(theumax > umax) {
2801 if(isvperiodic && correctV) {
2813 // The block is dedicated to determine whether WLine [ifprm, ilprm]
2814 // crosses the degenerated zone on each given surface or not.
2815 // If Yes -> We will not use info about surfaces during approximation
2816 // because inside degenerated zone of the surface the approx. algo.
2817 // uses wrong values of normal, etc., and resulting curve will have
2818 // oscillations that we would not like to have.
2823 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2824 const Handle(Geom_Surface)& aS,
2825 const Standard_Integer iDir);
2827 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2828 const TopoDS_Face& aF1,
2829 const TopoDS_Face& aF2);
2830 //=======================================================================
2831 //function : NotUseSurfacesForApprox
2833 //=======================================================================
2834 Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
2835 const TopoDS_Face& aF2,
2836 const Handle(IntPatch_WLine)& WL,
2837 const Standard_Integer ifprm,
2838 const Standard_Integer ilprm)
2840 Standard_Boolean bPInDZ;
2842 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
2844 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
2845 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
2850 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
2851 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
2855 //=======================================================================
2856 //function : IsPointInDegeneratedZone
2858 //=======================================================================
2859 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2860 const TopoDS_Face& aF1,
2861 const TopoDS_Face& aF2)
2864 Standard_Boolean bFlag=Standard_True;
2865 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
2866 Standard_Real U1, V1, U2, V2, aDelta, aD;
2869 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
2870 aS1->Bounds(US11, US12, VS11, VS12);
2871 GeomAdaptor_Surface aGAS1(aS1);
2873 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
2874 aS1->Bounds(US21, US22, VS21, VS22);
2875 GeomAdaptor_Surface aGAS2(aS2);
2877 //const gp_Pnt& aP=aP2S.Value();
2878 aP2S.Parameters(U1, V1, U2, V2);
2882 aD=aGAS1.UResolution(aDelta);
2883 aP2d.SetCoord(U1, V1);
2884 if (fabs(U1-US11) < aD) {
2885 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2890 if (fabs(U1-US12) < aD) {
2891 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2896 aD=aGAS1.VResolution(aDelta);
2897 if (fabs(V1-VS11) < aDelta) {
2898 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2903 if (fabs(V1-VS12) < aDelta) {
2904 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2910 aD=aGAS2.UResolution(aDelta);
2911 aP2d.SetCoord(U2, V2);
2912 if (fabs(U2-US21) < aDelta) {
2913 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2918 if (fabs(U2-US22) < aDelta) {
2919 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2924 aD=aGAS2.VResolution(aDelta);
2925 if (fabs(V2-VS21) < aDelta) {
2926 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2931 if (fabs(V2-VS22) < aDelta) {
2932 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2940 //=======================================================================
2941 //function : IsDegeneratedZone
2943 //=======================================================================
2944 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2945 const Handle(Geom_Surface)& aS,
2946 const Standard_Integer iDir)
2948 Standard_Boolean bFlag=Standard_True;
2949 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
2950 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
2951 aS->Bounds(US1, US2, VS1, VS2);
2953 gp_Pnt aPm, aPb, aPe;
2958 aS->D0(aXm, aYm, aPm);
2975 aS->D0(aXb, aYb, aPb);
2976 aS->D0(aXe, aYe, aPe);
2978 d1=aPm.Distance(aPb);
2979 d2=aPm.Distance(aPe);
2980 if (d1 < dD && d2 < dD) {
2997 aS->D0(aXb, aYb, aPb);
2998 aS->D0(aXe, aYe, aPe);
3000 d1=aPm.Distance(aPb);
3001 d2=aPm.Distance(aPe);
3002 if (d1 < dD && d2 < dD) {
3010 //=========================================================================
3011 // static function : ComputePurgedWLine
3012 // purpose : Removes equal points (leave one of equal points) from theWLine
3013 // and recompute vertex parameters.
3014 // Returns new WLine or null WLine if the number
3015 // of the points is less than 2.
3016 //=========================================================================
3017 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) {
3019 Standard_Integer i, k, v, nb, nbvtx;
3020 Handle(IntPatch_WLine) aResult;
3021 nbvtx = theWLine->NbVertex();
3022 nb = theWLine->NbPnts();
3024 const IntSurf_PntOn2S& p1 = theWLine->Point(1);
3025 const IntSurf_PntOn2S& p2 = theWLine->Point(2);
3026 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
3031 Handle(IntPatch_WLine) aLocalWLine;
3032 Handle(IntPatch_WLine) aTmpWLine = theWLine;
3033 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
3034 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
3035 for(i = 1; i <= nb; i++) {
3036 aLineOn2S->Add(theWLine->Point(i));
3039 for(v = 1; v <= nbvtx; v++) {
3040 aLocalWLine->AddVertex(theWLine->Vertex(v));
3043 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
3044 Standard_Integer aStartIndex = i + 1;
3045 Standard_Integer anEndIndex = i + 5;
3046 nb = aLineOn2S->NbPoints();
3047 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
3049 if((aStartIndex > nb) || (anEndIndex <= 1)) {
3054 while(k <= anEndIndex) {
3057 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
3058 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
3060 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
3061 aTmpWLine = aLocalWLine;
3062 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
3064 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
3065 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
3066 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
3068 if(avertexindex >= k) {
3069 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
3071 aLocalWLine->AddVertex(aVertex);
3073 aLineOn2S->RemovePoint(k);
3082 if(aLineOn2S->NbPoints() > 1) {
3083 aResult = aLocalWLine;
3088 //=======================================================================
3091 //=======================================================================
3092 void TolR3d(const TopoDS_Face& aF1,
3093 const TopoDS_Face& aF2,
3094 Standard_Real& myTolReached3d)
3096 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
3098 aTolTresh=2.999999e-3;
3099 aTolF1 = BRep_Tool::Tolerance(aF1);
3100 aTolF2 = BRep_Tool::Tolerance(aF2);
3101 aTolFMax=Max(aTolF1, aTolF2);
3103 if (aTolFMax>aTolTresh) {
3104 myTolReached3d=aTolFMax;
3107 //=======================================================================
3108 //function : IsPointOnBoundary
3110 //=======================================================================
3111 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
3112 const Standard_Real theFirstBoundary,
3113 const Standard_Real theSecondBoundary,
3114 const Standard_Real theResolution,
3115 Standard_Boolean& IsOnFirstBoundary)
3117 Standard_Boolean bRet;
3119 Standard_Real adist;
3121 bRet=Standard_False;
3122 for(i = 0; i < 2; ++i) {
3123 IsOnFirstBoundary = (i == 0);
3124 if (IsOnFirstBoundary) {
3125 adist = fabs(theParameter - theFirstBoundary);
3128 adist = fabs(theParameter - theSecondBoundary);
3130 if(adist < theResolution) {
3136 // ------------------------------------------------------------------------------------------------
3137 // static function: FindPoint
3139 // ------------------------------------------------------------------------------------------------
3140 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3141 const gp_Pnt2d& theLastPoint,
3142 const Standard_Real theUmin,
3143 const Standard_Real theUmax,
3144 const Standard_Real theVmin,
3145 const Standard_Real theVmax,
3146 gp_Pnt2d& theNewPoint) {
3148 gp_Vec2d aVec(theFirstPoint, theLastPoint);
3149 Standard_Integer i = 0, j = 0;
3151 for(i = 0; i < 4; i++) {
3152 gp_Vec2d anOtherVec;
3153 gp_Vec2d anOtherVecNormal;
3154 gp_Pnt2d aprojpoint = theLastPoint;
3157 anOtherVec.SetX(0.);
3158 anOtherVec.SetY(1.);
3159 anOtherVecNormal.SetX(1.);
3160 anOtherVecNormal.SetY(0.);
3163 aprojpoint.SetX(theUmin);
3165 aprojpoint.SetX(theUmax);
3168 anOtherVec.SetX(1.);
3169 anOtherVec.SetY(0.);
3170 anOtherVecNormal.SetX(0.);
3171 anOtherVecNormal.SetY(1.);
3174 aprojpoint.SetY(theVmin);
3176 aprojpoint.SetY(theVmax);
3178 gp_Vec2d anormvec = aVec;
3179 anormvec.Normalize();
3180 RefineVector(anormvec);
3181 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
3183 if(fabs(adot1) < Precision::Angular())
3185 Standard_Real adist = 0.;
3186 Standard_Boolean bIsOut = Standard_False;
3189 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
3190 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
3193 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
3194 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
3196 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
3198 for(j = 0; j < 2; j++) {
3199 anoffset = (j == 0) ? anoffset : -anoffset;
3200 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
3201 gp_Vec2d acurvec(theLastPoint, acurpoint);
3205 Standard_Real aDotX, anAngleX;
3207 aDotX = aVec.Dot(acurvec);
3208 anAngleX = aVec.Angle(acurvec);
3210 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
3212 if((acurpoint.Y() >= theVmin) &&
3213 (acurpoint.Y() <= theVmax)) {
3214 theNewPoint = acurpoint;
3215 return Standard_True;
3219 if((acurpoint.X() >= theUmin) &&
3220 (acurpoint.X() <= theUmax)) {
3221 theNewPoint = acurpoint;
3222 return Standard_True;
3228 return Standard_False;
3232 // ------------------------------------------------------------------------------------------------
3233 // static function: FindPoint
3234 // purpose: Find point on the boundary of radial tangent zone
3235 // ------------------------------------------------------------------------------------------------
3236 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3237 const gp_Pnt2d& theLastPoint,
3238 const Standard_Real theUmin,
3239 const Standard_Real theUmax,
3240 const Standard_Real theVmin,
3241 const Standard_Real theVmax,
3242 const gp_Pnt2d& theTanZoneCenter,
3243 const Standard_Real theZoneRadius,
3244 Handle(GeomAdaptor_HSurface) theGASurface,
3245 gp_Pnt2d& theNewPoint) {
3246 theNewPoint = theLastPoint;
3248 if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
3249 return Standard_False;
3251 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3252 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3254 Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3255 gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) );
3256 gp_Circ2d aCircle( anAxis, aRadius );
3259 gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() );
3260 Standard_Real aLength = aDir.Magnitude();
3261 if ( aLength <= gp::Resolution() )
3262 return Standard_False;
3263 gp_Lin2d aLine( theFirstPoint, aDir );
3266 Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine );
3267 Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength );
3268 Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle );
3270 Standard_Real aTol = aRadius * 0.001;
3271 aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol;
3273 Geom2dAPI_InterCurveCurve anIntersector;
3274 anIntersector.Init( aC1, aC2, aTol );
3276 if ( anIntersector.NbPoints() == 0 )
3277 return Standard_False;
3279 Standard_Boolean aFound = Standard_False;
3280 Standard_Real aMinDist = aLength * aLength;
3281 Standard_Integer i = 0;
3282 for ( i = 1; i <= anIntersector.NbPoints(); i++ ) {
3283 gp_Pnt2d aPInt = anIntersector.Point( i );
3284 if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
3285 if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
3286 ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
3287 theNewPoint = aPInt;
3288 aFound = Standard_True;
3296 // ------------------------------------------------------------------------------------------------
3297 // static function: IsInsideTanZone
3298 // purpose: Check if point is inside a radial tangent zone
3299 // ------------------------------------------------------------------------------------------------
3300 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
3301 const gp_Pnt2d& theTanZoneCenter,
3302 const Standard_Real theZoneRadius,
3303 Handle(GeomAdaptor_HSurface) theGASurface) {
3305 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3306 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3307 Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3308 aRadiusSQR *= aRadiusSQR;
3309 if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR )
3310 return Standard_True;
3311 return Standard_False;
3314 // ------------------------------------------------------------------------------------------------
3315 // static function: CheckTangentZonesExist
3316 // purpose: Check if tangent zone exists
3317 // ------------------------------------------------------------------------------------------------
3318 Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
3319 const Handle(GeomAdaptor_HSurface)& theSurface2 )
3321 if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
3322 ( theSurface2->GetType() != GeomAbs_Torus ) )
3323 return Standard_False;
3325 gp_Torus aTor1 = theSurface1->Torus();
3326 gp_Torus aTor2 = theSurface2->Torus();
3328 if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() )
3329 return Standard_False;
3331 if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) ||
3332 ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) )
3333 return Standard_False;
3335 if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) ||
3336 ( aTor2.MajorRadius() < aTor2.MinorRadius() ) )
3337 return Standard_False;
3338 return Standard_True;
3341 // ------------------------------------------------------------------------------------------------
3342 // static function: ComputeTangentZones
3344 // ------------------------------------------------------------------------------------------------
3345 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
3346 const Handle(GeomAdaptor_HSurface)& theSurface2,
3347 const TopoDS_Face& theFace1,
3348 const TopoDS_Face& theFace2,
3349 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
3350 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
3351 Handle(TColStd_HArray1OfReal)& theResultRadius,
3352 const Handle(IntTools_Context)& aContext)
3354 Standard_Integer aResult = 0;
3355 if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) )
3359 TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2;
3360 TColStd_SequenceOfReal aSeqResultRad;
3362 gp_Torus aTor1 = theSurface1->Torus();
3363 gp_Torus aTor2 = theSurface2->Torus();
3365 gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() );
3366 gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() );
3367 Standard_Integer j = 0;
3369 for ( j = 0; j < 2; j++ ) {
3370 Standard_Real aCoef = ( j == 0 ) ? -1 : 1;
3371 Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius());
3372 Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius());
3374 gp_Circ aCircle1( anax1, aRadius1 );
3375 gp_Circ aCircle2( anax2, aRadius2 );
3377 // roughly compute radius of tangent zone for perpendicular case
3378 Standard_Real aCriteria = Precision::Confusion() * 0.5;
3380 Standard_Real aT1 = aCriteria;
3381 Standard_Real aT2 = aCriteria;
3383 // internal tangency
3384 Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3385 //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria );
3386 aT1 = 2. * aR * aCriteria;
3390 // external tangency
3391 Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3392 Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3393 Standard_Real aDelta = aRb - aCriteria;
3395 aDelta -= aRm * aRm;
3396 aDelta /= 2. * (aRb - aRm);
3397 aDelta -= 0.5 * (aRb - aRm);
3399 aT1 = 2. * aRm * (aRm - aDelta);
3402 aCriteria = ( aT1 > aT2) ? aT1 : aT2;
3403 if ( aCriteria > 0 )
3404 aCriteria = sqrt( aCriteria );
3406 if ( aCriteria > 0.5 * aTor1.MinorRadius() ) {
3407 // too big zone -> drop to minimum
3408 aCriteria = Precision::Confusion();
3411 GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) );
3412 GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) );
3413 Extrema_ExtCC anExtrema(aC1, aC2, 0, 2. * M_PI, 0, 2. * M_PI,
3414 Precision::PConfusion(), Precision::PConfusion());
3416 if ( anExtrema.IsDone() ) {
3418 Standard_Integer i = 0;
3419 for ( i = 1; i <= anExtrema.NbExt(); i++ ) {
3420 if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
3423 Extrema_POnCurv P1, P2;
3424 anExtrema.Points( i, P1, P2 );
3426 Standard_Boolean bFoundResult = Standard_True;
3429 Standard_Integer surfit = 0;
3430 for ( surfit = 0; surfit < 2; surfit++ ) {
3431 GeomAPI_ProjectPointOnSurf& aProjector =
3432 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3434 gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
3435 aProjector.Perform(aP3d);
3437 if(!aProjector.IsDone())
3438 bFoundResult = Standard_False;
3440 if(aProjector.LowerDistance() > aCriteria) {
3441 bFoundResult = Standard_False;
3444 Standard_Real foundU = 0, foundV = 0;
3445 aProjector.LowerDistanceParameters(foundU, foundV);
3447 pr1 = gp_Pnt2d( foundU, foundV );
3449 pr2 = gp_Pnt2d( foundU, foundV );
3453 if ( bFoundResult ) {
3454 aSeqResultS1.Append( pr1 );
3455 aSeqResultS2.Append( pr2 );
3456 aSeqResultRad.Append( aCriteria );
3458 // torus is u and v periodic
3459 const Standard_Real twoPI = M_PI + M_PI;
3460 Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
3461 Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
3463 // iteration on period bounds
3464 for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
3465 Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
3466 Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
3468 // iteration on surfaces
3469 for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
3470 Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
3471 Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
3472 TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
3473 TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
3475 if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
3476 aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
3477 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3478 aSeqResultRad.Append( aCriteria );
3480 if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
3481 aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
3482 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3483 aSeqResultRad.Append( aCriteria );
3491 aResult = aSeqResultRad.Length();
3493 if ( aResult > 0 ) {
3494 theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult );
3495 theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult );
3496 theResultRadius = new TColStd_HArray1OfReal( 1, aResult );
3498 for ( Standard_Integer i = 1 ; i <= aResult; i++ ) {
3499 theResultOnS1->SetValue( i, aSeqResultS1.Value(i) );
3500 theResultOnS2->SetValue( i, aSeqResultS2.Value(i) );
3501 theResultRadius->SetValue( i, aSeqResultRad.Value(i) );
3507 // ------------------------------------------------------------------------------------------------
3508 // static function: AdjustByNeighbour
3510 // ------------------------------------------------------------------------------------------------
3511 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
3512 const gp_Pnt2d& theOriginalPoint,
3513 Handle(GeomAdaptor_HSurface) theGASurface) {
3515 gp_Pnt2d ap1 = theaNeighbourPoint;
3516 gp_Pnt2d ap2 = theOriginalPoint;
3518 if ( theGASurface->IsUPeriodic() ) {
3519 Standard_Real aPeriod = theGASurface->UPeriod();
3520 gp_Pnt2d aPTest = ap2;
3521 Standard_Real aSqDistMin = 1.e+100;
3523 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3524 aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt );
3525 Standard_Real dd = ap1.SquareDistance( aPTest );
3527 if ( dd < aSqDistMin ) {
3533 if ( theGASurface->IsVPeriodic() ) {
3534 Standard_Real aPeriod = theGASurface->VPeriod();
3535 gp_Pnt2d aPTest = ap2;
3536 Standard_Real aSqDistMin = 1.e+100;
3538 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3539 aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt );
3540 Standard_Real dd = ap1.SquareDistance( aPTest );
3542 if ( dd < aSqDistMin ) {
3551 // ------------------------------------------------------------------------------------------------
3552 //function: DecompositionOfWLine
3554 // ------------------------------------------------------------------------------------------------
3555 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
3556 const Handle(GeomAdaptor_HSurface)& theSurface1,
3557 const Handle(GeomAdaptor_HSurface)& theSurface2,
3558 const TopoDS_Face& theFace1,
3559 const TopoDS_Face& theFace2,
3560 const IntTools_LineConstructor& theLConstructor,
3561 const Standard_Boolean theAvoidLConstructor,
3562 IntPatch_SequenceOfLine& theNewLines,
3563 Standard_Real& theReachedTol3d,
3564 const Handle(IntTools_Context)& aContext)
3567 Standard_Boolean bRet, bAvoidLineConstructor;
3568 Standard_Integer aNbPnts, aNbParts;
3570 bRet=Standard_False;
3571 aNbPnts=theWLine->NbPnts();
3572 bAvoidLineConstructor=theAvoidLConstructor;
3577 if (!bAvoidLineConstructor) {
3578 aNbParts=theLConstructor.NbParts();
3584 Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary;
3585 Standard_Integer nblines, pit, i, j;
3587 TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts);
3588 TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts);
3589 TColStd_ListOfInteger aListOfPointIndex;
3591 Handle(TColgp_HArray1OfPnt2d) aTanZoneS1;
3592 Handle(TColgp_HArray1OfPnt2d) aTanZoneS2;
3593 Handle(TColStd_HArray1OfReal) aTanZoneRadius;
3594 Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2,
3595 aTanZoneS1, aTanZoneS2, aTanZoneRadius, aContext);
3599 aTol=Precision::Confusion();
3601 bIsPrevPointOnBoundary=Standard_False;
3602 bIsPointOnBoundary=Standard_False;
3607 for(pit = 1; pit <= aNbPnts; ++pit) {
3608 Standard_Boolean bIsOnFirstBoundary, isperiodic;
3609 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
3610 Standard_Real aParameter, anoffset, anAdjustPar;
3611 Standard_Real umin, umax, vmin, vmax;
3613 bIsCurrentPointOnBoundary = Standard_False;
3614 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
3617 for(i = 0; i < 2; ++i) {
3618 Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
3619 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3621 aPoint.ParametersOnS1(U, V);
3624 aPoint.ParametersOnS2(U, V);
3627 for(j = 0; j < 2; j++) {
3628 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3634 aResolution=aGASurface->UResolution(aTol);
3635 aPeriod=aGASurface->UPeriod();
3636 alowerboundary=umin;
3637 aupperboundary=umax;
3641 aResolution=aGASurface->VResolution(aTol);
3642 aPeriod=aGASurface->VPeriod();
3643 alowerboundary=vmin;
3644 aupperboundary=vmax;
3648 IntTools_Tools::AdjustPeriodic(aParameter,
3655 bIsOnFirstBoundary = Standard_True;// ?
3657 IsPointOnBoundary(anAdjustPar,
3661 bIsOnFirstBoundary);
3663 if(bIsPointOnBoundary) {
3664 bIsCurrentPointOnBoundary = Standard_True;
3668 // check if a point belong to a tangent zone. Begin
3669 Standard_Integer zIt = 0;
3670 for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
3671 gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3672 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3674 if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
3675 // set boundary flag to split the curve by a tangent zone
3676 bIsPointOnBoundary = Standard_True;
3677 bIsCurrentPointOnBoundary = Standard_True;
3678 if ( theReachedTol3d < aZoneRadius ) {
3679 theReachedTol3d = aZoneRadius;
3685 }//for(j = 0; j < 2; j++) {
3687 if(bIsCurrentPointOnBoundary){
3690 }//for(i = 0; i < 2; ++i) {
3692 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
3693 if(!aListOfPointIndex.IsEmpty()) {
3695 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3696 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3697 aListOfPointIndex.Clear();
3699 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
3701 aListOfPointIndex.Append(pit);
3702 } //for(pit = 1; pit <= aNbPnts; ++pit) {
3704 if(!aListOfPointIndex.IsEmpty()) {
3706 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3707 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3708 aListOfPointIndex.Clear();
3712 return bRet; //Standard_False;
3716 // 2. Correct wlines.begin
3717 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
3718 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S();
3720 for(i = 1; i <= nblines; i++) {
3721 if(anArrayOfLineType.Value(i) != 0) {
3724 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3725 if(aListOfIndex.Extent() < 2) {
3728 TColStd_ListOfInteger aListOfFLIndex;
3730 for(j = 0; j < 2; j++) {
3731 Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1);
3733 if((aneighbourindex < 1) || (aneighbourindex > nblines))
3736 if(anArrayOfLineType.Value(aneighbourindex) == 0)
3738 const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex);
3739 Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First();
3740 const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
3742 IntSurf_PntOn2S aNewP = aPoint;
3744 for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
3746 Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
3747 Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
3748 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3749 Standard_Real U=0., V=0.;
3752 aNewP.ParametersOnS1(U, V);
3754 aNewP.ParametersOnS2(U, V);
3755 Standard_Integer nbboundaries = 0;
3757 Standard_Boolean bIsNearBoundary = Standard_False;
3758 Standard_Integer aZoneIndex = 0;
3759 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
3760 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
3763 for(Standard_Integer parit = 0; parit < 2; parit++) {
3764 Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3766 Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
3767 Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
3768 Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
3770 Standard_Real aParameter = (parit == 0) ? U : V;
3771 Standard_Boolean bIsOnFirstBoundary = Standard_True;
3775 IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3776 if(bIsPointOnBoundary) {
3777 bIsUBoundary = (parit == 0);
3778 bIsFirstBoundary = bIsOnFirstBoundary;
3783 Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3784 Standard_Real anoffset, anAdjustPar;
3785 IntTools_Tools::AdjustPeriodic(aParameter, alowerboundary, aupperboundary,
3786 aPeriod, anAdjustPar, anoffset);
3789 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3790 if(bIsPointOnBoundary) {
3791 bIsUBoundary = (parit == 0);
3792 bIsFirstBoundary = bIsOnFirstBoundary;
3796 //check neighbourhood of boundary
3797 Standard_Real anEpsilon = aResolution * 100.;
3798 Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
3799 anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
3801 bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
3802 anEpsilon, bIsOnFirstBoundary);
3808 // check if a point belong to a tangent zone. Begin
3809 for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
3810 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3811 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3813 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3814 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3815 Standard_Real nU1, nV1;
3818 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3820 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3821 gp_Pnt2d ap1(nU1, nV1);
3822 gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
3825 if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
3827 bIsNearBoundary = Standard_True;
3828 if ( theReachedTol3d < aZoneRadius ) {
3829 theReachedTol3d = aZoneRadius;
3833 // check if a point belong to a tangent zone. End
3834 Standard_Boolean bComputeLineEnd = Standard_False;
3836 if(nbboundaries == 2) {
3838 bComputeLineEnd = Standard_True;
3841 else if(nbboundaries == 1) {
3842 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3845 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
3846 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
3847 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3848 Standard_Real aParameter = (bIsUBoundary) ? U : V;
3849 Standard_Real anoffset, anAdjustPar;
3850 IntTools_Tools::AdjustPeriodic(aParameter, alowerboundary, aupperboundary,
3851 aPeriod, anAdjustPar, anoffset);
3853 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
3854 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
3855 anotherPar += anoffset;
3856 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3857 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
3858 Standard_Real nU1, nV1;
3861 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3863 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3865 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
3866 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
3867 bComputeLineEnd = Standard_True;
3868 Standard_Boolean bCheckAngle1 = Standard_False;
3869 Standard_Boolean bCheckAngle2 = Standard_False;
3871 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
3872 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
3874 if(((adist1 - adist2) > Precision::PConfusion()) &&
3875 (adist2 < (aPeriod / 4.))) {
3876 bCheckAngle1 = Standard_True;
3877 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
3879 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3880 aNewP.SetValue((surfit == 0), anewU, anewV);
3881 bCheckAngle1 = Standard_False;
3884 else if(adist1 < (aPeriod / 4.)) {
3885 bCheckAngle2 = Standard_True;
3886 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
3888 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3889 bCheckAngle2 = Standard_False;
3893 if(bCheckAngle1 || bCheckAngle2) {
3894 // assume there are at least two points in line (see "if" above)
3895 Standard_Integer anindexother = aneighbourpointindex;
3897 while((anindexother <= aListOfIndex.Last()) && (anindexother >= aListOfIndex.First())) {
3898 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
3899 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
3900 Standard_Real nU2, nV2;
3903 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3905 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3906 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
3908 if(aVecOld.SquareMagnitude() <= (gp::Resolution() * gp::Resolution())) {
3912 Standard_Real anAngle = aNewVec.Angle(aVecOld);
3914 if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
3917 Standard_Real U1, U2, V1, V2;
3918 IntSurf_PntOn2S atmppoint = aNewP;
3919 atmppoint.SetValue((surfit == 0), anewU, anewV);
3920 atmppoint.Parameters(U1, V1, U2, V2);
3921 gp_Pnt P1 = theSurface1->Value(U1, V1);
3922 gp_Pnt P2 = theSurface2->Value(U2, V2);
3923 gp_Pnt P0 = aPoint.Value();
3925 if(P0.IsEqual(P1, aTol) &&
3926 P0.IsEqual(P2, aTol) &&
3927 P1.IsEqual(P2, aTol)) {
3928 bComputeLineEnd = Standard_False;
3929 aNewP.SetValue((surfit == 0), anewU, anewV);
3934 bComputeLineEnd = Standard_False;
3939 } // end while(anindexother...)
3943 else if ( bIsNearBoundary ) {
3944 bComputeLineEnd = Standard_True;
3947 if(bComputeLineEnd) {
3950 Standard_Boolean found = Standard_False;
3952 if ( bIsNearBoundary ) {
3953 // re-compute point near natural boundary or near tangent zone
3954 Standard_Real u1, v1, u2, v2;
3955 aNewP.Parameters( u1, v1, u2, v2 );
3957 anewpoint = gp_Pnt2d( u1, v1 );
3959 anewpoint = gp_Pnt2d( u2, v2 );
3961 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3962 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3963 Standard_Real nU1, nV1;
3966 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3968 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3969 gp_Pnt2d ap1(nU1, nV1);
3974 // exclude point from a tangent zone
3975 anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3976 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
3977 Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
3979 if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
3980 aPZone, aZoneRadius, aGASurface, ap2) ) {
3982 found = Standard_True;
3985 else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
3986 // re-compute point near boundary if shifted on a period
3987 ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3989 if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
3990 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
3991 found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
3995 aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
4001 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
4002 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
4003 Standard_Real nU1, nV1;
4006 aNeighbourPoint.ParametersOnS1(nU1, nV1);
4008 aNeighbourPoint.ParametersOnS2(nU1, nV1);
4009 gp_Pnt2d ap1(nU1, nV1);
4010 gp_Pnt2d ap2(nU1, nV1);
4011 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
4013 while((aneighbourpointindex2 <= aListOfIndex.Last()) && (aneighbourpointindex2 >= aListOfIndex.First())) {
4014 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
4015 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
4016 Standard_Real nU2, nV2;
4019 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
4021 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
4025 if(ap1.SquareDistance(ap2) > (gp::Resolution() * gp::Resolution())) {
4029 found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
4034 Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4035 GeomAPI_ProjectPointOnSurf& aProjector =
4036 (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
4037 Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
4039 Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
4041 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
4042 aProjector.Perform(aP3d);
4044 if(aProjector.IsDone()) {
4045 if(aProjector.LowerDistance() < aCriteria) {
4046 Standard_Real foundU = U, foundV = V;
4047 aProjector.LowerDistanceParameters(foundU, foundV);
4049 //Correction of projected coordinates. Begin
4050 //Note, it may be shifted on a period
4051 Standard_Integer aneindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
4052 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
4053 Standard_Real nUn, nVn;
4056 aNeighbourPoint.ParametersOnS2(nUn, nVn);
4058 aNeighbourPoint.ParametersOnS1(nUn, nVn);
4059 gp_Pnt2d aNeighbour2d(nUn, nVn);
4060 gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
4061 foundU = anAdjustedPoint.X();
4062 foundV = anAdjustedPoint.Y();
4064 if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
4065 ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
4066 // attempt to roughly re-compute point
4067 foundU = ( foundU < umin ) ? umin : foundU;
4068 foundU = ( foundU > umax ) ? umax : foundU;
4069 foundV = ( foundV < vmin ) ? vmin : foundV;
4070 foundV = ( foundV > vmax ) ? vmax : foundV;
4072 GeomAPI_ProjectPointOnSurf& aProjector2 =
4073 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
4075 aP3d = aSurfaceOther->Value(foundU, foundV);
4076 aProjector2.Perform(aP3d);
4078 if(aProjector2.IsDone()) {
4079 if(aProjector2.LowerDistance() < aCriteria) {
4080 Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
4081 aProjector2.LowerDistanceParameters(foundU2, foundV2);
4082 anewpoint.SetX(foundU2);
4083 anewpoint.SetY(foundV2);
4087 //Correction of projected coordinates. End
4090 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
4092 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
4098 aSeqOfPntOn2S->Add(aNewP);
4099 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
4101 anArrayOfLineEnds.SetValue(i, aListOfFLIndex);
4103 // Correct wlines.end
4105 // Split wlines.begin
4106 Standard_Integer nbiter;
4109 if (!bAvoidLineConstructor) {
4110 nbiter=theLConstructor.NbParts();
4113 for(j = 1; j <= nbiter; ++j) {
4114 Standard_Real fprm, lprm;
4115 Standard_Integer ifprm, ilprm;
4117 if(bAvoidLineConstructor) {
4119 ilprm = theWLine->NbPnts();
4122 theLConstructor.Part(j, fprm, lprm);
4123 ifprm = (Standard_Integer)fprm;
4124 ilprm = (Standard_Integer)lprm;
4127 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
4129 for(i = 1; i <= nblines; i++) {
4130 if(anArrayOfLineType.Value(i) != 0) {
4133 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
4135 if(aListOfIndex.Extent() < 2) {
4138 const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
4139 Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
4140 Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
4142 if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
4143 bhasfirstpoint = (i != 1);
4146 if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
4147 bhaslastpoint = (i != nblines);
4149 Standard_Boolean bIsFirstInside = ((ifprm >= aListOfIndex.First()) && (ifprm <= aListOfIndex.Last()));
4150 Standard_Boolean bIsLastInside = ((ilprm >= aListOfIndex.First()) && (ilprm <= aListOfIndex.Last()));
4152 if(!bIsFirstInside && !bIsLastInside) {
4153 if((ifprm < aListOfIndex.First()) && (ilprm > aListOfIndex.Last())) {
4154 // append whole line, and boundaries if neccesary
4155 if(bhasfirstpoint) {
4156 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
4159 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4161 for(; anIt.More(); anIt.Next()) {
4162 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4167 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
4171 // check end of split line (end is almost always)
4172 Standard_Integer aneighbour = i + 1;
4173 Standard_Boolean bIsEndOfLine = Standard_True;
4175 if(aneighbour <= nblines) {
4176 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4178 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4179 (aListOfNeighbourIndex.IsEmpty())) {
4180 bIsEndOfLine = Standard_False;
4185 if(aLineOn2S->NbPoints() > 1) {
4186 Handle(IntPatch_WLine) aNewWLine =
4187 new IntPatch_WLine(aLineOn2S, Standard_False);
4188 theNewLines.Append(aNewWLine);
4190 aLineOn2S = new IntSurf_LineOn2S();
4195 // end if(!bIsFirstInside && !bIsLastInside)
4197 if(bIsFirstInside && bIsLastInside) {
4198 // append inside points between ifprm and ilprm
4199 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4201 for(; anIt.More(); anIt.Next()) {
4202 if((anIt.Value() < ifprm) || (anIt.Value() > ilprm))
4204 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4210 if(bIsFirstInside) {
4211 // append points from ifprm to last point + boundary point
4212 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4214 for(; anIt.More(); anIt.Next()) {
4215 if(anIt.Value() < ifprm)
4217 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4222 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
4225 // check end of split line (end is almost always)
4226 Standard_Integer aneighbour = i + 1;
4227 Standard_Boolean bIsEndOfLine = Standard_True;
4229 if(aneighbour <= nblines) {
4230 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4232 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4233 (aListOfNeighbourIndex.IsEmpty())) {
4234 bIsEndOfLine = Standard_False;
4239 if(aLineOn2S->NbPoints() > 1) {
4240 Handle(IntPatch_WLine) aNewWLine =
4241 new IntPatch_WLine(aLineOn2S, Standard_False);
4242 theNewLines.Append(aNewWLine);
4244 aLineOn2S = new IntSurf_LineOn2S();
4247 // end if(bIsFirstInside)
4250 // append points from first boundary point to ilprm
4251 if(bhasfirstpoint) {
4252 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
4255 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4257 for(; anIt.More(); anIt.Next()) {
4258 if(anIt.Value() > ilprm)
4260 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4264 //end if(bIsLastInside)
4268 if(aLineOn2S->NbPoints() > 1) {
4269 Handle(IntPatch_WLine) aNewWLine =
4270 new IntPatch_WLine(aLineOn2S, Standard_False);
4271 theNewLines.Append(aNewWLine);
4276 return Standard_True;
4279 // ------------------------------------------------------------------------------------------------
4280 // static function: ParameterOutOfBoundary
4281 // purpose: Computes a new parameter for given curve. The corresponding 2d points
4282 // does not lay on any boundary of given faces
4283 // ------------------------------------------------------------------------------------------------
4284 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
4285 const Handle(Geom_Curve)& theCurve,
4286 const TopoDS_Face& theFace1,
4287 const TopoDS_Face& theFace2,
4288 const Standard_Real theOtherParameter,
4289 const Standard_Boolean bIncreasePar,
4290 Standard_Real& theNewParameter,
4291 const Handle(IntTools_Context)& aContext)
4293 Standard_Boolean bIsComputed = Standard_False;
4294 theNewParameter = theParameter;
4296 Standard_Real acurpar = theParameter;
4297 TopAbs_State aState = TopAbs_ON;
4298 Standard_Integer iter = 0;
4299 Standard_Real asumtol = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4300 Standard_Real adelta = asumtol * 0.1;
4301 adelta = (adelta < Precision::Confusion()) ? Precision::Confusion() : adelta;
4302 Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(theFace1);
4303 Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(theFace2);
4305 Standard_Real u1, u2, v1, v2;
4307 GeomAPI_ProjectPointOnSurf aPrj1;
4308 aSurf1->Bounds(u1, u2, v1, v2);
4309 aPrj1.Init(aSurf1, u1, u2, v1, v2);
4311 GeomAPI_ProjectPointOnSurf aPrj2;
4312 aSurf2->Bounds(u1, u2, v1, v2);
4313 aPrj2.Init(aSurf2, u1, u2, v1, v2);
4315 while(aState == TopAbs_ON) {
4320 gp_Pnt aPCurrent = theCurve->Value(acurpar);
4321 aPrj1.Perform(aPCurrent);
4322 Standard_Real U=0., V=0.;
4324 if(aPrj1.IsDone()) {
4325 aPrj1.LowerDistanceParameters(U, V);
4326 aState = aContext->StatePointFace(theFace1, gp_Pnt2d(U, V));
4329 if(aState != TopAbs_ON) {
4330 aPrj2.Perform(aPCurrent);
4332 if(aPrj2.IsDone()) {
4333 aPrj2.LowerDistanceParameters(U, V);
4334 aState = aContext->StatePointFace(theFace2, gp_Pnt2d(U, V));
4345 theNewParameter = acurpar;
4346 bIsComputed = Standard_True;
4349 if(acurpar >= theOtherParameter)
4350 theNewParameter = theOtherParameter;
4353 if(acurpar <= theOtherParameter)
4354 theNewParameter = theOtherParameter;
4360 //=======================================================================
4361 //function : IsCurveValid
4363 //=======================================================================
4364 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve)
4366 if(thePCurve.IsNull())
4367 return Standard_False;
4369 Standard_Real tolint = 1.e-10;
4370 Geom2dAdaptor_Curve PCA;
4371 IntRes2d_Domain PCD;
4372 Geom2dInt_GInter PCI;
4374 Standard_Real pf = 0., pl = 0.;
4375 gp_Pnt2d pntf, pntl;
4377 if(!thePCurve->IsClosed() && !thePCurve->IsPeriodic()) {
4378 pf = thePCurve->FirstParameter();
4379 pl = thePCurve->LastParameter();
4380 pntf = thePCurve->Value(pf);
4381 pntl = thePCurve->Value(pl);
4382 PCA.Load(thePCurve);
4383 if(!PCA.IsPeriodic()) {
4384 if(PCA.FirstParameter() > pf) pf = PCA.FirstParameter();
4385 if(PCA.LastParameter() < pl) pl = PCA.LastParameter();
4387 PCD.SetValues(pntf,pf,tolint,pntl,pl,tolint);
4388 PCI.Perform(PCA,PCD,tolint,tolint);
4390 if(PCI.NbPoints() > 0) {
4391 return Standard_False;
4395 return Standard_True;
4398 //=======================================================================
4399 //static function : ApproxWithPCurves
4400 //purpose : for bug 20964 only
4401 //=======================================================================
4402 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
4403 const gp_Sphere& theSph)
4405 Standard_Boolean bRes = Standard_True;
4406 Standard_Real R1 = theCyl.Radius(), R2 = theSph.Radius();
4409 Standard_Real aD2, aRc2, aEps;
4415 const gp_Ax3& aAx3Sph=theSph.Position();
4416 const gp_Pnt& aLocSph=aAx3Sph.Location();
4417 const gp_Dir& aDirSph=aAx3Sph.Direction();
4419 const gp_Ax1& aAx1Cyl=theCyl.Axis();
4420 gp_Lin aLinCyl(aAx1Cyl);
4422 aApexSph.SetXYZ(aLocSph.XYZ()+R2*aDirSph.XYZ());
4423 aD2=aLinCyl.SquareDistance(aApexSph);
4424 if (fabs(aD2-aRc2)<aEps) {
4428 aApexSph.SetXYZ(aLocSph.XYZ()-R2*aDirSph.XYZ());
4429 aD2=aLinCyl.SquareDistance(aApexSph);
4430 if (fabs(aD2-aRc2)<aEps) {
4439 gp_Lin anCylAx(theCyl.Axis());
4441 Standard_Real aDist = anCylAx.Distance(theSph.Location());
4442 Standard_Real aDRel = Abs(aDist - R1)/R2;
4444 if(aDRel > .2) return bRes;
4446 Standard_Real par = ElCLib::Parameter(anCylAx, theSph.Location());
4447 gp_Pnt aP = ElCLib::Value(par, anCylAx);
4448 gp_Vec aV(aP, theSph.Location());
4450 Standard_Real dd = aV.Dot(theSph.Position().XDirection());
4452 if(aDist < R1 && dd > 0.) return Standard_False;
4453 if(aDist > R1 && dd < 0.) return Standard_False;
4458 //=======================================================================
4459 //function : PerformPlanes
4461 //=======================================================================
4462 void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
4463 const Handle(GeomAdaptor_HSurface)& theS2,
4464 const Standard_Real TolAng,
4465 const Standard_Real TolTang,
4466 const Standard_Boolean theApprox1,
4467 const Standard_Boolean theApprox2,
4468 IntTools_SequenceOfCurves& theSeqOfCurve,
4469 Standard_Boolean& theTangentFaces)
4472 gp_Pln aPln1 = theS1->Surface().Plane();
4473 gp_Pln aPln2 = theS2->Surface().Plane();
4475 IntAna_QuadQuadGeo aPlnInter(aPln1, aPln2, TolAng, TolTang);
4477 if(!aPlnInter.IsDone()) {
4478 theTangentFaces = Standard_False;
4482 IntAna_ResultType aResType = aPlnInter.TypeInter();
4484 if(aResType == IntAna_Same) {
4485 theTangentFaces = Standard_True;
4489 theTangentFaces = Standard_False;
4491 if(aResType == IntAna_Empty) {
4495 gp_Lin aLin = aPlnInter.Line(1);
4497 ProjLib_Plane aProj;
4500 aProj.Project(aLin);
4501 gp_Lin2d aLin2d1 = aProj.Line();
4504 aProj.Project(aLin);
4505 gp_Lin2d aLin2d2 = aProj.Line();
4507 //classify line2d1 relatively first plane
4508 Standard_Real P11, P12;
4509 Standard_Boolean IsCrossed = ClassifyLin2d(theS1, aLin2d1, TolTang, P11, P12);
4510 if(!IsCrossed) return;
4511 //classify line2d2 relatively second plane
4512 Standard_Real P21, P22;
4513 IsCrossed = ClassifyLin2d(theS2, aLin2d2, TolTang, P21, P22);
4514 if(!IsCrossed) return;
4516 //Analysis of parametric intervals: must have common part
4518 if(P21 >= P12) return;
4519 if(P22 <= P11) return;
4521 Standard_Real pmin, pmax;
4522 pmin = Max(P11, P21);
4523 pmax = Min(P12, P22);
4525 if(pmax - pmin <= TolTang) return;
4527 Handle(Geom_Line) aGLin = new Geom_Line(aLin);
4529 IntTools_Curve aCurve;
4530 Handle(Geom_TrimmedCurve) aGTLin = new Geom_TrimmedCurve(aGLin, pmin, pmax);
4532 aCurve.SetCurve(aGTLin);
4535 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d1);
4536 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4539 Handle(Geom2d_Curve) H1;
4540 aCurve.SetFirstCurve2d(H1);
4543 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d2);
4544 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4547 Handle(Geom2d_Curve) H1;
4548 aCurve.SetFirstCurve2d(H1);
4551 theSeqOfCurve.Append(aCurve);
4555 //=======================================================================
4556 //function : ClassifyLin2d
4558 //=======================================================================
4559 static inline Standard_Boolean INTER(const Standard_Real d1,
4560 const Standard_Real d2,
4561 const Standard_Real tol)
4563 return (d1 > tol && d2 < -tol) ||
4564 (d1 < -tol && d2 > tol) ||
4565 ((d1 <= tol && d1 >= -tol) && (d2 > tol || d2 < -tol)) ||
4566 ((d2 <= tol && d2 >= -tol) && (d1 > tol || d1 < -tol));
4568 static inline Standard_Boolean COINC(const Standard_Real d1,
4569 const Standard_Real d2,
4570 const Standard_Real tol)
4572 return (d1 <= tol && d1 >= -tol) && (d2 <= tol && d2 >= -tol);
4574 Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
4575 const gp_Lin2d& theLin2d,
4576 const Standard_Real theTol,
4577 Standard_Real& theP1,
4578 Standard_Real& theP2)
4581 Standard_Real xmin, xmax, ymin, ymax, d1, d2, A, B, C;
4582 Standard_Real par[2];
4583 Standard_Integer nbi = 0;
4585 xmin = theS->Surface().FirstUParameter();
4586 xmax = theS->Surface().LastUParameter();
4587 ymin = theS->Surface().FirstVParameter();
4588 ymax = theS->Surface().LastVParameter();
4590 theLin2d.Coefficients(A, B, C);
4592 //xmin, ymin <-> xmin, ymax
4593 d1 = A*xmin + B*ymin + C;
4594 d2 = A*xmin + B*ymax + C;
4596 if(INTER(d1, d2, theTol)) {
4597 //Intersection with boundary
4598 Standard_Real y = -(C + A*xmin)/B;
4599 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, y));
4602 else if (COINC(d1, d2, theTol)) {
4603 //Coincidence with boundary
4604 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4605 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4611 if(fabs(par[0]-par[1]) > theTol) {
4612 theP1 = Min(par[0], par[1]);
4613 theP2 = Max(par[0], par[1]);
4614 return Standard_True;
4616 else return Standard_False;
4620 //xmin, ymax <-> xmax, ymax
4622 d2 = A*xmax + B*ymax + C;
4624 if(d1 > theTol || d1 < -theTol) {//to avoid checking of
4625 //coincidence with the same point
4626 if(INTER(d1, d2, theTol)) {
4627 Standard_Real x = -(C + B*ymax)/A;
4628 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymax));
4631 else if (COINC(d1, d2, theTol)) {
4632 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4633 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4640 if(fabs(par[0]-par[1]) > theTol) {
4641 theP1 = Min(par[0], par[1]);
4642 theP2 = Max(par[0], par[1]);
4643 return Standard_True;
4645 else return Standard_False;
4649 //xmax, ymax <-> xmax, ymin
4651 d2 = A*xmax + B*ymin + C;
4653 if(d1 > theTol || d1 < -theTol) {
4654 if(INTER(d1, d2, theTol)) {
4655 Standard_Real y = -(C + A*xmax)/B;
4656 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, y));
4659 else if (COINC(d1, d2, theTol)) {
4660 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4661 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4667 if(fabs(par[0]-par[1]) > theTol) {
4668 theP1 = Min(par[0], par[1]);
4669 theP2 = Max(par[0], par[1]);
4670 return Standard_True;
4672 else return Standard_False;
4675 //xmax, ymin <-> xmin, ymin
4677 d2 = A*xmin + B*ymin + C;
4679 if(d1 > theTol || d1 < -theTol) {
4680 if(INTER(d1, d2, theTol)) {
4681 Standard_Real x = -(C + B*ymin)/A;
4682 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymin));
4685 else if (COINC(d1, d2, theTol)) {
4686 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4687 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4693 if(fabs(par[0]-par[1]) > theTol) {
4694 theP1 = Min(par[0], par[1]);
4695 theP2 = Max(par[0], par[1]);
4696 return Standard_True;
4698 else return Standard_False;
4701 return Standard_False;
4705 //=======================================================================
4706 //function : ApproxParameters
4708 //=======================================================================
4709 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
4710 const Handle(GeomAdaptor_HSurface)& aHS2,
4711 Standard_Integer& iDegMin,
4712 Standard_Integer& iDegMax,
4713 Standard_Integer& iNbIter)
4716 GeomAbs_SurfaceType aTS1, aTS2;
4723 aTS1=aHS1->Surface().GetType();
4724 aTS2=aHS2->Surface().GetType();
4727 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4728 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4729 Standard_Real aRC, aRT, dR, aPC;
4730 gp_Cylinder aCylinder;
4733 aPC=Precision::Confusion();
4735 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4736 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4738 aRC=aCylinder.Radius();
4739 aRT=aTorus.MinorRadius();
4749 if (aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Cylinder) {
4753 //=======================================================================
4754 //function : Tolerances
4756 //=======================================================================
4757 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
4758 const Handle(GeomAdaptor_HSurface)& aHS2,
4759 Standard_Real& aTolTang)
4761 GeomAbs_SurfaceType aTS1, aTS2;
4763 aTS1=aHS1->Surface().GetType();
4764 aTS2=aHS2->Surface().GetType();
4767 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4768 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4769 Standard_Real aRC, aRT, dR, aPC;
4770 gp_Cylinder aCylinder;
4773 aPC=Precision::Confusion();
4775 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4776 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4778 aRC=aCylinder.Radius();
4779 aRT=aTorus.MinorRadius();
4786 aTolTang=0.1*aTolTang;
4790 //=======================================================================
4791 //function : SortTypes
4793 //=======================================================================
4794 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
4795 const GeomAbs_SurfaceType aType2)
4797 Standard_Boolean bRet;
4798 Standard_Integer aI1, aI2;
4800 bRet=Standard_False;
4802 aI1=IndexType(aType1);
4803 aI2=IndexType(aType2);
4809 //=======================================================================
4810 //function : IndexType
4812 //=======================================================================
4813 Standard_Integer IndexType(const GeomAbs_SurfaceType aType)
4815 Standard_Integer aIndex;
4819 if (aType==GeomAbs_Plane) {
4822 else if (aType==GeomAbs_Cylinder) {
4825 else if (aType==GeomAbs_Cone) {
4828 else if (aType==GeomAbs_Sphere) {
4831 else if (aType==GeomAbs_Torus) {
4834 else if (aType==GeomAbs_BezierSurface) {
4837 else if (aType==GeomAbs_BSplineSurface) {
4840 else if (aType==GeomAbs_SurfaceOfRevolution) {
4843 else if (aType==GeomAbs_SurfaceOfExtrusion) {
4846 else if (aType==GeomAbs_OffsetSurface) {
4849 else if (aType==GeomAbs_OtherSurface) {
4854 #ifdef DEB_DUMPWLINE
4855 //=======================================================================
4856 //function : DumpWLine
4858 //=======================================================================
4859 void DumpWLine(const Handle(IntPatch_WLine)& aWLine)
4861 Standard_Integer i, aNbPnts;
4862 Standard_Real aX, aY, aZ, aU1, aV1, aU2, aV2;
4864 printf(" *WLine\n");
4865 aNbPnts=aWLine->NbPnts();
4866 for (i=1; i<=aNbPnts; ++i) {
4867 const IntSurf_PntOn2S aPntOn2S=aWLine->Point(i);
4868 const gp_Pnt& aP3D=aPntOn2S.Value();
4869 aP3D.Coord(aX, aY, aZ);
4870 aPntOn2S.Parameters(aU1, aV1, aU2, aV2);
4872 printf("point p_%d %lf %lf %lf\n", i, aX, aY, aZ);
4873 //printf("point p_%d %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf\n",
4874 // i, aX, aY, aZ, aU1, aV1, aU2, aV2);
4878 //=======================================================================
4879 //function : RefineVector
4881 //=======================================================================
4882 void RefineVector(gp_Vec2d& aV2D)
4884 Standard_Integer k,m;
4885 Standard_Real aC[2], aEps, aR1, aR2, aNum;
4891 aV2D.Coord(aC[0], aC[1]);
4893 for (k=0; k<2; ++k) {
4896 if (aNum>aR1 && aNum<aR2) {
4907 aV2D.SetCoord(aC[0], aC[1]);
4909 //=======================================================================
4910 //function : FindMaxSquareDistance
4912 //=======================================================================
4913 Standard_Real FindMaxSquareDistance (const Standard_Real aT1,
4914 const Standard_Real aT2,
4915 const Standard_Real aEps,
4916 const Handle(Geom_Curve)& aC3D,
4917 const Handle(Geom2d_Curve)& aC2D1,
4918 const Handle(Geom2d_Curve)& aC2D2,
4919 const Handle(GeomAdaptor_HSurface)& myHS1,
4920 const Handle(GeomAdaptor_HSurface)& myHS2,
4921 const TopoDS_Face& myFace1,
4922 const TopoDS_Face& myFace2,
4923 const Handle(IntTools_Context)& myContext)
4925 Standard_Real aA, aB, aCf, aX1, aX2, aF1, aF2, aX, aF;
4927 aCf=1.6180339887498948482045868343656;// =0.5*(1.+sqrt(5.));
4931 aF1=MaxSquareDistance(aX1,
4932 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4934 aF2=MaxSquareDistance(aX2,
4935 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4939 if (fabs(aA-aB)<aEps) {
4941 aF=MaxSquareDistance(aX,
4942 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4950 aF2=MaxSquareDistance(aX2,
4951 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4959 aF1=MaxSquareDistance(aX1,
4960 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4965 //=======================================================================
4966 //function : MaxSquareDistance
4968 //=======================================================================
4969 Standard_Real MaxSquareDistance (const Standard_Real aT,
4970 const Handle(Geom_Curve)& aC3D,
4971 const Handle(Geom2d_Curve)& aC2D1,
4972 const Handle(Geom2d_Curve)& aC2D2,
4973 const Handle(GeomAdaptor_HSurface) myHS1,
4974 const Handle(GeomAdaptor_HSurface) myHS2,
4975 const TopoDS_Face& aF1,
4976 const TopoDS_Face& aF2,
4977 const Handle(IntTools_Context)& aCtx)
4979 Standard_Boolean bIsDone;
4981 Standard_Real aU, aV, aD2Max, aD2;
4988 if (aC3D.IsNull()) {
4992 for (i=0; i<2; ++i) {
4993 const Handle(GeomAdaptor_HSurface)& aGHS=(!i) ? myHS1 : myHS2;
4994 const TopoDS_Face &aF=(!i) ? aF1 : aF2;
4995 const Handle(Geom2d_Curve)& aC2D=(!i) ? aC2D1 : aC2D2;
4997 if (!aC2D.IsNull()) {
5000 aGHS->D0(aU, aV, aPS);
5001 aD2=aP.SquareDistance(aPS);
5007 GeomAPI_ProjectPointOnSurf& aProjector=aCtx->ProjPS(aF);
5009 aProjector.Perform(aP);
5010 bIsDone=aProjector.IsDone();
5012 aProjector.LowerDistanceParameters(aU, aV);
5013 aGHS->D0(aU, aV, aPS);
5014 aD2=aP.SquareDistance(aPS);
5024 //=======================================================================
5025 //function : CheckPCurve
5026 //purpose : Checks if points of the pcurve are out of the face bounds.
5027 //=======================================================================
5028 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
5029 const TopoDS_Face& aFace)
5031 const Standard_Integer NPoints = 23;
5033 Standard_Real umin,umax,vmin,vmax;
5035 BRepTools::UVBounds(aFace, umin, umax, vmin, vmax);
5036 Standard_Real tolU = Max ((umax-umin)*0.01, Precision::Confusion());
5037 Standard_Real tolV = Max ((vmax-vmin)*0.01, Precision::Confusion());
5038 Standard_Real fp = aPC->FirstParameter();
5039 Standard_Real lp = aPC->LastParameter();
5042 // adjust domain for periodic surfaces
5043 TopLoc_Location aLoc;
5044 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
5045 if (aSurf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
5046 aSurf = (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf))->BasisSurface();
5048 gp_Pnt2d pnt = aPC->Value((fp+lp)/2);
5052 if (aSurf->IsUPeriodic()) {
5053 Standard_Real aPer = aSurf->UPeriod();
5054 Standard_Integer nshift = (Standard_Integer) ((u-umin)/aPer);
5055 if (u < umin+aPer*nshift) nshift--;
5056 umin += aPer*nshift;
5057 umax += aPer*nshift;
5059 if (aSurf->IsVPeriodic()) {
5060 Standard_Real aPer = aSurf->VPeriod();
5061 Standard_Integer nshift = (Standard_Integer) ((v-vmin)/aPer);
5062 if (v < vmin+aPer*nshift) nshift--;
5063 vmin += aPer*nshift;
5064 vmax += aPer*nshift;
5067 //--------------------------------------------------------
5068 Standard_Boolean bRet;
5069 Standard_Integer j, aNbIntervals;
5070 Standard_Real aT, dT;
5073 Geom2dAdaptor_Curve aGAC(aPC);
5074 aNbIntervals=aGAC.NbIntervals(GeomAbs_CN);
5076 TColStd_Array1OfReal aTI(1, aNbIntervals+1);
5077 aGAC.Intervals(aTI,GeomAbs_CN);
5079 bRet=Standard_False;
5081 aT=aGAC.FirstParameter();
5082 for (j=1; j<=aNbIntervals; ++j) {
5083 dT=(aTI(j+1)-aTI(j))/NPoints;
5085 for (i=1; i<NPoints; i++) {
5089 if (umin-u > tolU || u-umax > tolU ||
5090 vmin-v > tolV || v-vmax > tolV) {