1 // File: IntTools_FaceFace.cxx
2 // Created: Thu Nov 23 14:52:53 2000
3 // Author: Michael KLOKOV
4 // Copyright: OPEN CASCADE 2000
7 #include <IntTools_FaceFace.ixx>
9 #include <Precision.hxx>
11 #include <TColStd_HArray1OfReal.hxx>
12 #include <TColStd_Array1OfReal.hxx>
13 #include <TColStd_Array1OfInteger.hxx>
14 #include <TColStd_SequenceOfReal.hxx>
15 #include <TColStd_ListOfInteger.hxx>
16 #include <TColStd_ListIteratorOfListOfInteger.hxx>
17 #include <TColStd_Array1OfListOfInteger.hxx>
19 #include <gp_Lin2d.hxx>
20 #include <gp_Ax22d.hxx>
21 #include <gp_Circ2d.hxx>
22 #include <gp_Torus.hxx>
23 #include <gp_Cylinder.hxx>
25 #include <Bnd_Box.hxx>
27 #include <TColgp_HArray1OfPnt2d.hxx>
28 #include <TColgp_SequenceOfPnt2d.hxx>
29 #include <TColgp_Array1OfPnt.hxx>
30 #include <TColgp_Array1OfPnt2d.hxx>
32 #include <IntAna_QuadQuadGeo.hxx>
34 #include <IntSurf_PntOn2S.hxx>
35 #include <IntSurf_LineOn2S.hxx>
36 #include <IntSurf_PntOn2S.hxx>
37 #include <IntSurf_ListOfPntOn2S.hxx>
38 #include <IntRes2d_Domain.hxx>
39 #include <ProjLib_Plane.hxx>
41 #include <IntPatch_GLine.hxx>
42 #include <IntPatch_RLine.hxx>
43 #include <IntPatch_WLine.hxx>
44 #include <IntPatch_ALine.hxx>
45 #include <IntPatch_ALineToWLine.hxx>
50 #include <Extrema_ExtCC.hxx>
51 #include <Extrema_POnCurv.hxx>
52 #include <BndLib_AddSurface.hxx>
54 #include <Adaptor3d_SurfacePtr.hxx>
55 #include <Adaptor2d_HLine2d.hxx>
57 #include <GeomAbs_SurfaceType.hxx>
58 #include <GeomAbs_CurveType.hxx>
60 #include <Geom_Surface.hxx>
61 #include <Geom_Line.hxx>
62 #include <Geom_Circle.hxx>
63 #include <Geom_Ellipse.hxx>
64 #include <Geom_Parabola.hxx>
65 #include <Geom_Hyperbola.hxx>
66 #include <Geom_TrimmedCurve.hxx>
67 #include <Geom_BSplineCurve.hxx>
68 #include <Geom_RectangularTrimmedSurface.hxx>
69 #include <Geom_OffsetSurface.hxx>
70 #include <Geom_Curve.hxx>
71 #include <Geom_Conic.hxx>
73 #include <Geom2d_TrimmedCurve.hxx>
74 #include <Geom2d_BSplineCurve.hxx>
75 #include <Geom2d_Line.hxx>
76 #include <Geom2d_Curve.hxx>
77 #include <Geom2d_Circle.hxx>
79 #include <Geom2dAPI_InterCurveCurve.hxx>
80 #include <Geom2dInt_GInter.hxx>
81 #include <GeomAdaptor_Curve.hxx>
82 #include <GeomAdaptor_HSurface.hxx>
83 #include <GeomAdaptor_Surface.hxx>
84 #include <GeomLib_CheckBSplineCurve.hxx>
85 #include <GeomLib_Check2dBSplineCurve.hxx>
87 #include <GeomInt_WLApprox.hxx>
88 #include <GeomProjLib.hxx>
89 #include <GeomAPI_ProjectPointOnSurf.hxx>
90 #include <Geom2dAdaptor_Curve.hxx>
93 #include <TopoDS_Edge.hxx>
94 #include <TopExp_Explorer.hxx>
96 #include <BRep_Tool.hxx>
97 #include <BRepTools.hxx>
98 #include <BRepAdaptor_Surface.hxx>
100 #include <BOPTColStd_Dump.hxx>
102 #include <IntTools_Curve.hxx>
103 #include <IntTools_Tools.hxx>
104 #include <IntTools_Tools.hxx>
105 #include <IntTools_TopolTool.hxx>
106 #include <IntTools_PntOnFace.hxx>
107 #include <IntTools_PntOn2Faces.hxx>
108 #include <IntTools_Context.hxx>
109 #include <IntSurf_ListIteratorOfListOfPntOn2S.hxx>
113 void TolR3d(const TopoDS_Face& ,
117 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)&,
118 const Standard_Integer,
119 const Standard_Integer);
122 void Parameters(const Handle(GeomAdaptor_HSurface)&,
123 const Handle(GeomAdaptor_HSurface)&,
131 void BuildPCurves (Standard_Real f,Standard_Real l,Standard_Real& Tol,
132 const Handle (Geom_Surface)& S,
133 const Handle (Geom_Curve)& C,
134 Handle (Geom2d_Curve)& C2d);
137 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
138 const Standard_Real theTolerance,
139 Standard_Real& theumin,
140 Standard_Real& theumax,
141 Standard_Real& thevmin,
142 Standard_Real& thevmax);
144 Standard_Boolean NotUseSurfacesForApprox
145 (const TopoDS_Face& aF1,
146 const TopoDS_Face& aF2,
147 const Handle(IntPatch_WLine)& WL,
148 const Standard_Integer ifprm,
149 const Standard_Integer ilprm);
152 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine);
155 Standard_Real AdjustPeriodic(const Standard_Real theParameter,
156 const Standard_Real parmin,
157 const Standard_Real parmax,
158 const Standard_Real thePeriod,
159 Standard_Real& theOffset);
162 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
163 const Standard_Integer ideb,
164 const Standard_Integer ifin,
165 const Standard_Boolean onFirst);
168 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
169 const Handle(GeomAdaptor_HSurface)& theSurface1,
170 const Handle(GeomAdaptor_HSurface)& theSurface2,
171 const TopoDS_Face& theFace1,
172 const TopoDS_Face& theFace2,
173 const IntTools_LineConstructor& theLConstructor,
174 const Standard_Boolean theAvoidLConstructor,
175 IntPatch_SequenceOfLine& theNewLines,
176 Standard_Real& theReachedTol3d);
179 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
180 const Handle(Geom_Curve)& theCurve,
181 const TopoDS_Face& theFace1,
182 const TopoDS_Face& theFace2,
183 const Standard_Real theOtherParameter,
184 const Standard_Boolean bIncreasePar,
185 Standard_Real& theNewParameter);
188 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve);
191 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
192 const Standard_Real theFirstBoundary,
193 const Standard_Real theSecondBoundary,
194 const Standard_Real theResolution,
195 Standard_Boolean& IsOnFirstBoundary);
197 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
198 const gp_Pnt2d& theLastPoint,
199 const Standard_Real theUmin,
200 const Standard_Real theUmax,
201 const Standard_Real theVmin,
202 const Standard_Real theVmax,
203 gp_Pnt2d& theNewPoint);
207 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
208 const Handle(GeomAdaptor_HSurface)& theSurface2,
209 const TopoDS_Face& theFace1,
210 const TopoDS_Face& theFace2,
211 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
212 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
213 Handle(TColStd_HArray1OfReal)& theResultRadius);
216 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
217 const gp_Pnt2d& theLastPoint,
218 const Standard_Real theUmin,
219 const Standard_Real theUmax,
220 const Standard_Real theVmin,
221 const Standard_Real theVmax,
222 const gp_Pnt2d& theTanZoneCenter,
223 const Standard_Real theZoneRadius,
224 Handle(GeomAdaptor_HSurface) theGASurface,
225 gp_Pnt2d& theNewPoint);
228 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
229 const gp_Pnt2d& theTanZoneCenter,
230 const Standard_Real theZoneRadius,
231 Handle(GeomAdaptor_HSurface) theGASurface);
234 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
235 const gp_Pnt2d& theOriginalPoint,
236 Handle(GeomAdaptor_HSurface) theGASurface);
238 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
239 const gp_Sphere& theSph);
241 static void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
242 const Handle(GeomAdaptor_HSurface)& theS2,
243 const Standard_Real TolAng,
244 const Standard_Real TolTang,
245 const Standard_Boolean theApprox1,
246 const Standard_Boolean theApprox2,
247 IntTools_SequenceOfCurves& theSeqOfCurve,
248 Standard_Boolean& theTangentFaces);
250 static Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
251 const gp_Lin2d& theLin2d,
252 const Standard_Real theTol,
253 Standard_Real& theP1,
254 Standard_Real& theP2);
257 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
258 const Handle(GeomAdaptor_HSurface)& aHS2,
259 Standard_Integer& iDegMin,
260 Standard_Integer& iDegMax);
263 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
264 const Handle(GeomAdaptor_HSurface)& aHS2,
265 Standard_Real& aTolArc,
266 Standard_Real& aTolTang,
267 Standard_Real& aUVMaxStep,
268 Standard_Real& aDeflection);
271 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
272 const GeomAbs_SurfaceType aType2);
274 Standard_Integer IndexType(const GeomAbs_SurfaceType aType);
277 //=======================================================================
280 //=======================================================================
281 IntTools_FaceFace::IntTools_FaceFace()
283 myTangentFaces=Standard_False;
285 myHS1 = new GeomAdaptor_HSurface ();
286 myHS2 = new GeomAdaptor_HSurface ();
289 SetParameters(Standard_True, Standard_True, Standard_True, 1.e-07);
291 //=======================================================================
294 //=======================================================================
295 const TopoDS_Face& IntTools_FaceFace::Face1() const
300 //=======================================================================
303 //=======================================================================
304 const TopoDS_Face& IntTools_FaceFace::Face2() const
309 //=======================================================================
310 //function : TangentFaces
312 //=======================================================================
313 Standard_Boolean IntTools_FaceFace::TangentFaces() const
315 return myTangentFaces;
317 //=======================================================================
320 //=======================================================================
321 const IntTools_SequenceOfPntOn2Faces& IntTools_FaceFace::Points() const
325 //=======================================================================
328 //=======================================================================
329 Standard_Boolean IntTools_FaceFace::IsDone() const
333 //=======================================================================
334 //function : TolReached3d
336 //=======================================================================
337 Standard_Real IntTools_FaceFace::TolReached3d() const
339 return myTolReached3d;
341 //=======================================================================
343 //purpose : return lines of intersection
344 //=======================================================================
345 const IntTools_SequenceOfCurves& IntTools_FaceFace::Lines() const
347 StdFail_NotDone_Raise_if(!myIsDone,
348 "IntTools_FaceFace::Lines() => !myIntersector.IsDone()");
352 //=======================================================================
353 //function : TolReached2d
355 //=======================================================================
356 Standard_Real IntTools_FaceFace::TolReached2d() const
358 return myTolReached2d;
360 // =======================================================================
361 // function: SetParameters
363 // =======================================================================
364 void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d,
365 const Standard_Boolean ToApproxC2dOnS1,
366 const Standard_Boolean ToApproxC2dOnS2,
367 const Standard_Real ApproximationTolerance)
369 myApprox = ToApproxC3d;
370 myApprox1 = ToApproxC2dOnS1;
371 myApprox2 = ToApproxC2dOnS2;
372 myTolApprox = ApproximationTolerance;
374 //=======================================================================
377 //=======================================================================
379 void IntTools_FaceFace::SetList(IntSurf_ListOfPntOn2S& aListOfPnts)
381 myListOfPnts = aListOfPnts;
384 //=======================================================================
386 //purpose : intersect surfaces of the faces
387 //=======================================================================
388 void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
389 const TopoDS_Face& aF2)
391 Standard_Boolean hasCone, RestrictLine, bTwoPlanes, bReverse;
392 Standard_Integer aNbLin, aNbPnts, i, NbLinPP;
393 Standard_Real TolArc, TolTang, Deflection, UVMaxStep;
394 Standard_Real umin, umax, vmin, vmax;
395 Standard_Real aTolF1, aTolF2;
396 GeomAbs_SurfaceType aType1, aType2;
397 Handle(Geom_Surface) S1, S2;
398 Handle(IntTools_TopolTool) dom1, dom2;
399 BRepAdaptor_Surface aBAS1, aBAS2;
401 mySeqOfCurve.Clear();
404 myIsDone = Standard_False;
406 hasCone = Standard_False;
407 bTwoPlanes = Standard_False;
412 aBAS1.Initialize(myFace1, Standard_False);
413 aBAS2.Initialize(myFace2, Standard_False);
414 aType1=aBAS1.GetType();
415 aType2=aBAS2.GetType();
417 bReverse=SortTypes(aType1, aType2);
421 aType1=aBAS2.GetType();
422 aType2=aBAS1.GetType();
424 if (myListOfPnts.Extent()) {
425 Standard_Real aU1,aV1,aU2,aV2;
426 IntSurf_ListIteratorOfListOfPntOn2S aItP2S;
428 aItP2S.Initialize(myListOfPnts);
429 for (; aItP2S.More(); aItP2S.Next()){
430 IntSurf_PntOn2S& aP2S=aItP2S.Value();
431 aP2S.Parameters(aU1,aV1,aU2,aV2);
432 aP2S.SetValue(aU2,aV2,aU1,aV1);
437 S1=BRep_Tool::Surface(myFace1);
438 S2=BRep_Tool::Surface(myFace2);
440 aTolF1=BRep_Tool::Tolerance(myFace1);
441 aTolF2=BRep_Tool::Tolerance(myFace2);
443 TolArc= aTolF1 + aTolF2;
447 if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
448 bTwoPlanes = Standard_True;
450 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
451 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
453 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
454 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
455 Standard_Real TolAng = 1.e-8;
456 PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2,
457 mySeqOfCurve, myTangentFaces);
459 myIsDone = Standard_True;
465 NbLinPP = mySeqOfCurve.Length();
470 Standard_Real aTolFMax;
472 myTolReached3d = 1.e-7;
474 aTolFMax=Max(aTolF1, aTolF2);
476 if (aTolFMax>myTolReached3d) {
477 myTolReached3d=aTolFMax;
479 myTolReached2d = myTolReached3d;
482 Handle(Geom2d_Curve) aC2D1, aC2D2;
484 aNbLin=mySeqOfCurve.Length();
485 for (i=1; i<=aNbLin; ++i) {
486 IntTools_Curve& aIC=mySeqOfCurve(i);
487 aC2D1=aIC.FirstCurve2d();
488 aC2D2=aIC.SecondCurve2d();
490 aIC.SetFirstCurve2d(aC2D2);
491 aIC.SetSecondCurve2d(aC2D1);
495 }//if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
497 if (aType1==GeomAbs_Plane &&
498 (aType2==GeomAbs_Cylinder ||
499 aType2==GeomAbs_Cone ||
500 aType2==GeomAbs_Torus)) {
501 Standard_Real dU, dV;
503 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
510 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
512 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
513 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
514 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
516 if( aType2==GeomAbs_Cone ) {
518 hasCone = Standard_True;
522 else if ((aType1==GeomAbs_Cylinder||
523 aType1==GeomAbs_Cone ||
524 aType1==GeomAbs_Torus) &&
525 aType2==GeomAbs_Plane) {
526 Standard_Real dU, dV;
528 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
529 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
530 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
532 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
539 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
541 if( aType1==GeomAbs_Cone ) {
543 hasCone = Standard_True;
549 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
551 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
553 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
555 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
557 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
559 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
562 dom1 = new IntTools_TopolTool(myHS1);
563 dom2 = new IntTools_TopolTool(myHS2);
565 myLConstruct.Load(dom1, dom2, myHS1, myHS2);
567 Deflection = (hasCone) ? 0.085 : 0.1;
570 Tolerances(myHS1, myHS2, TolArc, TolTang, UVMaxStep, Deflection);
572 myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection);
574 RestrictLine = Standard_False;
576 if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) ||
577 (myHS1->IsVClosed() && !myHS1->IsVPeriodic()) ||
578 (myHS2->IsUClosed() && !myHS2->IsUPeriodic()) ||
579 (myHS2->IsVClosed() && !myHS2->IsVPeriodic())) {
580 RestrictLine = Standard_True;
583 if(((aType1 != GeomAbs_BSplineSurface) &&
584 (aType1 != GeomAbs_BezierSurface) &&
585 (aType1 != GeomAbs_OtherSurface)) &&
586 ((aType2 != GeomAbs_BSplineSurface) &&
587 (aType2 != GeomAbs_BezierSurface) &&
588 (aType2 != GeomAbs_OtherSurface))) {
589 RestrictLine = Standard_True;
591 if ((aType1 == GeomAbs_Torus) ||
592 (aType2 == GeomAbs_Torus) ) {
593 myListOfPnts.Clear();
598 TopExp_Explorer aExp;
600 for(i = 0; (!RestrictLine) && (i < 2); i++) {
601 const TopoDS_Face& aF=(!i) ? myFace1 : myFace2;
602 aExp.Init(aF, TopAbs_EDGE);
603 for(; aExp.More(); aExp.Next()) {
604 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
606 if(BRep_Tool::Degenerated(aE)) {
607 RestrictLine = Standard_True;
614 myIntersector.Perform(myHS1, dom1, myHS2, dom2,
616 myListOfPnts, RestrictLine);
618 myIsDone = myIntersector.IsDone();
620 myTangentFaces=myIntersector.TangentFaces();
621 if (myTangentFaces) {
626 myListOfPnts.Clear(); // to use LineConstructor
629 aNbLin = myIntersector.NbLines();
630 for (i=1; i<=aNbLin; ++i) {
631 MakeCurve(i, dom1, dom2);
634 ComputeTolReached3d();
637 Handle(Geom2d_Curve) aC2D1, aC2D2;
639 aNbLin=mySeqOfCurve.Length();
640 for (i=1; i<=aNbLin; ++i) {
641 IntTools_Curve& aIC=mySeqOfCurve(i);
642 aC2D1=aIC.FirstCurve2d();
643 aC2D2=aIC.SecondCurve2d();
645 aIC.SetFirstCurve2d(aC2D2);
646 aIC.SetSecondCurve2d(aC2D1);
651 Standard_Real U1,V1,U2,V2;
652 IntTools_PntOnFace aPntOnF1, aPntOnF2;
653 IntTools_PntOn2Faces aPntOn2Faces;
655 aNbPnts=myIntersector.NbPnts();
656 for (i=1; i<=aNbPnts; ++i) {
657 const IntSurf_PntOn2S& aISPnt=myIntersector.Point(i).PntOn2S();
658 const gp_Pnt& aPnt=aISPnt.Value();
659 aISPnt.Parameters(U1,V1,U2,V2);
660 aPntOnF1.Init(myFace1, aPnt, U1, V1);
661 aPntOnF2.Init(myFace2, aPnt, U2, V2);
664 aPntOn2Faces.SetP1(aPntOnF1);
665 aPntOn2Faces.SetP2(aPntOnF2);
668 aPntOn2Faces.SetP2(aPntOnF1);
669 aPntOn2Faces.SetP1(aPntOnF2);
671 myPnts.Append(aPntOn2Faces);
676 //=======================================================================
677 //function :ComputeTolReached3d
679 //=======================================================================
680 void IntTools_FaceFace::ComputeTolReached3d()
682 Standard_Integer aNbLin;
683 GeomAbs_SurfaceType aType1, aType2;
685 aNbLin=myIntersector.NbLines();
687 aType1=myHS1->Surface().GetType();
688 aType2=myHS2->Surface().GetType();
691 aType1==GeomAbs_Cylinder &&
692 aType2==GeomAbs_Cylinder) {
693 Handle(IntPatch_Line) aIL1, aIL2;
694 IntPatch_IType aTL1, aTL2;
696 aIL1=myIntersector.Line(1);
697 aIL2=myIntersector.Line(2);
698 aTL1=aIL1->ArcType();
699 aTL2=aIL2->ArcType();
700 if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) {
701 Standard_Real aD, aDTresh, dTol;
707 aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line();
708 aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line();
709 aD=aL1.Distance(aL2);
712 myTolReached3d=aD+dTol;
717 if (aType1==GeomAbs_Plane &&
718 aType2==GeomAbs_Plane) {
719 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
723 aTolF1 = BRep_Tool::Tolerance(myFace1);
724 aTolF2 = BRep_Tool::Tolerance(myFace2);
725 aTolFMax=Max(aTolF1, aTolF2);
727 if (aTolFMax>aTolTresh) {
728 myTolReached3d=aTolFMax;
733 if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ||
734 (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) {
736 const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1);
737 if(aIL1->ArcType() == IntPatch_Circle) {
738 gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle();
739 gp_XYZ aCirDir = aCir.Axis().Direction().XYZ();
742 if(aType1 == GeomAbs_Plane) {
743 aPln = myHS1->Surface().Plane();
746 aPln = myHS2->Surface().Plane();
748 aPlDir = aPln.Axis().Direction().XYZ();
749 Standard_Real cs = aCirDir*aPlDir;
750 if(cs < 0.) aPlDir.Reverse();
751 Standard_Real eps = 1.e-14;
752 if(!aPlDir.IsEqual(aCirDir, eps)) {
753 Standard_Integer aNbP = 11;
754 Standard_Real dt = 2.*PI / (aNbP - 1), t;
755 for(t = 0.; t < 2.*PI; t += dt) {
756 Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir));
757 if(myTolReached3d < d) myTolReached3d = d;
759 myTolReached3d *= 1.1;
761 } //aIL1->ArcType() == IntPatch_Circle
763 } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ...
764 //End IFV Bug OCC20297
766 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
767 (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) {
768 aNbLin=mySeqOfCurve.Length();
773 Standard_Integer i, aNbP;
774 Standard_Real aT, aT1, aT2, dT, aUT, aVT, aUP, aVP;
775 Standard_Real aDP, aDT, aDmax;
780 const IntTools_Curve& aIC=mySeqOfCurve(1);
781 const Handle(Geom_Curve)& aC3D=aIC.Curve();
782 const Handle(Geom_BSplineCurve)& aBS=Handle(Geom_BSplineCurve)::DownCast(aC3D);
787 aT1=aBS->FirstParameter();
788 aT2=aBS->LastParameter();
790 aPln =(aType1==GeomAbs_Plane) ? myHS1->Plane() : myHS2->Plane();
791 aTorus=(aType1==GeomAbs_Plane) ? myHS2->Torus() : myHS1->Torus();
795 dT=(aT2-aT1)/(aNbP-1);
796 for (i=0; i<aNbP; ++i) {
804 ElSLib::Parameters(aPln, aP, aUP, aVP);
805 aPP=ElSLib::Value(aUP, aVP, aPln);
806 aDP=aP.SquareDistance(aPP);
811 ElSLib::Parameters(aTorus, aP, aUT, aVT);
812 aPT=ElSLib::Value(aUT, aVT, aTorus);
813 aDT=aP.SquareDistance(aPT);
819 if (aDmax > myTolReached3d*myTolReached3d) {
820 myTolReached3d=sqrt(aDmax);
821 myTolReached3d=1.1*myTolReached3d;
823 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
825 if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) ||
826 (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder)) {
827 Standard_Boolean bIsDone;
828 Standard_Integer i, j, aNbP;
829 Standard_Real aT, aT1, aT2, dT, aU1, aV1, aU2, aV2;
830 Standard_Real aDSmax, aDS1, aDS2, aDS;
831 gp_Pnt2d aP2D1, aP2D2;
832 gp_Pnt aP3D, aP3D1, aP3D2;
833 IntTools_Context aCtx;
835 aNbLin=mySeqOfCurve.Length();
839 for (i=1; i<=aNbLin; ++i) {
840 const IntTools_Curve& aIC=mySeqOfCurve(i);
841 const Handle(Geom_Curve)& aC3D=aIC.Curve();
842 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
843 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
848 const Handle(Geom_BSplineCurve)& aBC=Handle(Geom_BSplineCurve)::DownCast(aC3D);
853 aT1=aBC->FirstParameter();
854 aT2=aBC->LastParameter();
856 dT=(aT2-aT1)/(aNbP-1);
857 for (j=0; j<aNbP; ++j) {
865 if (!aC2D1.IsNull()) {
866 aC2D1->D0(aT, aP2D1);
867 aP2D1.Coord(aU1, aV1);
868 myHS1->D0(aU1, aV1, aP3D1);
869 aDS1=aP3D.SquareDistance(aP3D1);
875 if (!aC2D2.IsNull()) {
876 aC2D2->D0(aT, aP2D2);
877 aP2D2.Coord(aU2, aV2);
878 myHS2->D0(aU2, aV2, aP3D2);
879 aDS2=aP3D.SquareDistance(aP3D2);
885 GeomAPI_ProjectPointOnSurf& aPPS1=aCtx.ProjPS(myFace1);
887 bIsDone=aPPS1.IsDone();
889 aPPS1.LowerDistanceParameters(aU1, aV1);
890 myHS1->D0(aU1, aV1, aP3D1);
891 aDS1=aP3D.SquareDistance(aP3D1);
897 GeomAPI_ProjectPointOnSurf& aPPS2=aCtx.ProjPS(myFace2);
899 bIsDone=aPPS2.IsDone();
901 aPPS2.LowerDistanceParameters(aU2, aV2);
902 myHS2->D0(aU2, aV2, aP3D2);
903 aDS2=aP3D.SquareDistance(aP3D2);
908 }//for (j=0; j<aNbP; ++j) {
909 }//for (i=1; i<=aNbLin; ++i) {
911 aDS=myTolReached3d*myTolReached3d;
913 myTolReached3d=sqrt(aDSmax);
915 }//if((aType1==GeomAbs_SurfaceOfRevolution ...
917 //=======================================================================
918 //function : MakeCurve
920 //=======================================================================
921 void IntTools_FaceFace::MakeCurve(const Standard_Integer Index,
922 const Handle(Adaptor3d_TopolTool)& dom1,
923 const Handle(Adaptor3d_TopolTool)& dom2)
925 Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor;
927 Standard_Integer i, j, aNbParts;
928 Standard_Real fprm, lprm;
930 Handle(IntPatch_Line) L;
932 Handle(Geom_Curve) newc;
934 const Standard_Real TOLCHECK =0.0000001;
935 const Standard_Real TOLANGCHECK=0.1;
937 rejectSurface = Standard_False;
938 reApprox = Standard_False;
943 bAvoidLineConstructor = Standard_False;
944 L = myIntersector.Line(Index);
947 if(typl==IntPatch_Walking) {
948 Handle(IntPatch_Line) anewL;
950 const Handle(IntPatch_WLine)& aWLine=
951 Handle(IntPatch_WLine)::DownCast(L);
953 anewL = ComputePurgedWLine(aWLine);
959 if(!myListOfPnts.IsEmpty()) {
960 bAvoidLineConstructor = Standard_True;
963 Standard_Integer nbp = aWLine->NbPnts();
964 const IntSurf_PntOn2S& p1 = aWLine->Point(1);
965 const IntSurf_PntOn2S& p2 = aWLine->Point(nbp);
967 const gp_Pnt& P1 = p1.Value();
968 const gp_Pnt& P2 = p2.Value();
970 if(P1.SquareDistance(P2) < 1.e-14) {
971 bAvoidLineConstructor = Standard_False;
977 if(!bAvoidLineConstructor) {
978 myLConstruct.Perform(L);
980 bDone=myLConstruct.IsDone();
981 aNbParts=myLConstruct.NbParts();
982 if (!bDone|| !aNbParts) {
991 //########################################
992 // Line, Parabola, Hyperbola
993 //########################################
995 case IntPatch_Parabola:
996 case IntPatch_Hyperbola: {
997 if (typl == IntPatch_Lin) {
999 new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
1002 else if (typl == IntPatch_Parabola) {
1004 new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
1007 else if (typl == IntPatch_Hyperbola) {
1009 new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
1013 if (typl == IntPatch_Lin) {
1014 TolR3d (myFace1, myFace2, myTolReached3d);
1017 aNbParts=myLConstruct.NbParts();
1018 for (i=1; i<=aNbParts; i++) {
1019 myLConstruct.Part(i, fprm, lprm);
1021 if (!Precision::IsNegativeInfinite(fprm) &&
1022 !Precision::IsPositiveInfinite(lprm)) {
1024 IntTools_Curve aCurve;
1026 Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
1027 aCurve.SetCurve(aCT3D);
1028 if (typl == IntPatch_Parabola) {
1029 Standard_Real aTolF1, aTolF2, aTolBase;
1031 aTolF1 = BRep_Tool::Tolerance(myFace1);
1032 aTolF2 = BRep_Tool::Tolerance(myFace2);
1033 aTolBase=aTolF1+aTolF2;
1034 myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
1037 aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
1039 Handle (Geom2d_Curve) C2d;
1040 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1041 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1042 myTolReached2d=Tolpc;
1045 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1048 Handle(Geom2d_BSplineCurve) H1;
1050 aCurve.SetFirstCurve2d(H1);
1054 Handle (Geom2d_Curve) C2d;
1055 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1056 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1057 myTolReached2d=Tolpc;
1060 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1063 Handle(Geom2d_BSplineCurve) H1;
1065 aCurve.SetSecondCurve2d(H1);
1067 mySeqOfCurve.Append(aCurve);
1068 } // end of if (!Precision::IsNegativeInfinite(fprm) && !Precision::IsPositiveInfinite(lprm))
1071 // on regarde si on garde
1073 Standard_Boolean bFNIt, bLPIt;
1074 Standard_Real aTestPrm, dT=100.;
1076 bFNIt=Precision::IsNegativeInfinite(fprm);
1077 bLPIt=Precision::IsPositiveInfinite(lprm);
1081 if (bFNIt && !bLPIt) {
1084 else if (!bFNIt && bLPIt) {
1088 gp_Pnt ptref(newc->Value(aTestPrm));
1091 Standard_Real u1, v1, u2, v2, Tol;
1093 Tol = Precision::Confusion();
1094 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1095 ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
1097 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1100 Handle(Geom2d_BSplineCurve) H1;
1101 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1104 }// end of for (i=1; i<=myLConstruct.NbParts(); i++)
1105 }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola:
1108 //########################################
1109 // Circle and Ellipse
1110 //########################################
1111 case IntPatch_Circle:
1112 case IntPatch_Ellipse: {
1114 if (typl == IntPatch_Circle) {
1115 newc = new Geom_Circle
1116 (Handle(IntPatch_GLine)::DownCast(L)->Circle());
1118 else { //IntPatch_Ellipse
1119 newc = new Geom_Ellipse
1120 (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
1124 TolR3d (myFace1, myFace2, myTolReached3d);
1126 aNbParts=myLConstruct.NbParts();
1128 Standard_Real aPeriod, aNul;
1129 TColStd_SequenceOfReal aSeqFprm, aSeqLprm;
1134 for (i=1; i<=aNbParts; i++) {
1135 myLConstruct.Part(i, fprm, lprm);
1137 if (fprm < aNul && lprm > aNul) {
1138 // interval that goes through 0. is divided on two intervals;
1139 while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
1140 while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
1142 if((aPeriod - fprm) > Tolpc) {
1143 aSeqFprm.Append(fprm);
1144 aSeqLprm.Append(aPeriod);
1147 gp_Pnt P1 = newc->Value(fprm);
1148 gp_Pnt P2 = newc->Value(aPeriod);
1149 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1150 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1152 if(P1.Distance(P2) > aTolDist) {
1153 Standard_Real anewpar = fprm;
1155 if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2, lprm, Standard_False, anewpar)) {
1158 aSeqFprm.Append(fprm);
1159 aSeqLprm.Append(aPeriod);
1164 if((lprm - aNul) > Tolpc) {
1165 aSeqFprm.Append(aNul);
1166 aSeqLprm.Append(lprm);
1169 gp_Pnt P1 = newc->Value(aNul);
1170 gp_Pnt P2 = newc->Value(lprm);
1171 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1172 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1174 if(P1.Distance(P2) > aTolDist) {
1175 Standard_Real anewpar = lprm;
1177 if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2, fprm, Standard_True, anewpar)) {
1180 aSeqFprm.Append(aNul);
1181 aSeqLprm.Append(lprm);
1187 aSeqFprm.Append(fprm);
1188 aSeqLprm.Append(lprm);
1193 aNbParts=aSeqFprm.Length();
1194 for (i=1; i<=aNbParts; i++) {
1198 Standard_Real aRealEpsilon=RealEpsilon();
1199 if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*PI) > aRealEpsilon) {
1200 //==============================================
1202 IntTools_Curve aCurve;
1203 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1204 aCurve.SetCurve(aTC3D);
1205 fprm=aTC3D->FirstParameter();
1206 lprm=aTC3D->LastParameter ();
1208 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {////
1210 Handle (Geom2d_Curve) C2d;
1211 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1212 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1213 myTolReached2d=Tolpc;
1216 aCurve.SetFirstCurve2d(C2d);
1219 Handle(Geom2d_BSplineCurve) H1;
1220 aCurve.SetFirstCurve2d(H1);
1225 Handle (Geom2d_Curve) C2d;
1226 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1227 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1228 myTolReached2d=Tolpc;
1231 aCurve.SetSecondCurve2d(C2d);
1234 Handle(Geom2d_BSplineCurve) H1;
1235 aCurve.SetSecondCurve2d(H1);
1240 Handle(Geom2d_BSplineCurve) H1;
1241 aCurve.SetFirstCurve2d(H1);
1242 aCurve.SetSecondCurve2d(H1);
1244 mySeqOfCurve.Append(aCurve);
1245 //==============================================
1246 } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*PI) > RealEpsilon())
1249 // on regarde si on garde
1252 // if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*PI) < RealEpsilon()) {
1253 if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*PI) <= aRealEpsilon) {
1254 IntTools_Curve aCurve;
1255 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1256 aCurve.SetCurve(aTC3D);
1257 fprm=aTC3D->FirstParameter();
1258 lprm=aTC3D->LastParameter ();
1261 Handle (Geom2d_Curve) C2d;
1262 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1263 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1264 myTolReached2d=Tolpc;
1267 aCurve.SetFirstCurve2d(C2d);
1270 Handle(Geom2d_BSplineCurve) H1;
1271 aCurve.SetFirstCurve2d(H1);
1275 Handle (Geom2d_Curve) C2d;
1276 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1277 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1278 myTolReached2d=Tolpc;
1281 aCurve.SetSecondCurve2d(C2d);
1284 Handle(Geom2d_BSplineCurve) H1;
1285 aCurve.SetSecondCurve2d(H1);
1287 mySeqOfCurve.Append(aCurve);
1292 Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
1294 aTwoPIdiv17=2.*PI/17.;
1296 for (j=0; j<=17; j++) {
1297 gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
1298 Tol = Precision::Confusion();
1300 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1301 ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
1303 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1306 IntTools_Curve aCurve;
1307 aCurve.SetCurve(newc);
1308 //==============================================
1309 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
1312 Handle (Geom2d_Curve) C2d;
1313 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1314 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1315 myTolReached2d=Tolpc;
1318 aCurve.SetFirstCurve2d(C2d);
1321 Handle(Geom2d_BSplineCurve) H1;
1322 aCurve.SetFirstCurve2d(H1);
1326 Handle (Geom2d_Curve) C2d;
1327 BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
1328 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1329 myTolReached2d=Tolpc;
1332 aCurve.SetSecondCurve2d(C2d);
1336 Handle(Geom2d_BSplineCurve) H1;
1337 aCurve.SetSecondCurve2d(H1);
1339 }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
1342 Handle(Geom2d_BSplineCurve) H1;
1344 aCurve.SetFirstCurve2d(H1);
1345 aCurve.SetSecondCurve2d(H1);
1347 //==============================================
1349 mySeqOfCurve.Append(aCurve);
1352 }// end of if (ok) {
1353 }// end of for (Standard_Integer j=0; j<=17; j++)
1354 }// end of else { on regarde si on garde
1355 }// for (i=1; i<=myLConstruct.NbParts(); i++)
1356 }// IntPatch_Circle: IntPatch_Ellipse:
1359 case IntPatch_Analytic: {
1360 IntSurf_Quadric quad1,quad2;
1361 GeomAbs_SurfaceType typs = myHS1->Surface().GetType();
1365 quad1.SetValue(myHS1->Surface().Plane());
1367 case GeomAbs_Cylinder:
1368 quad1.SetValue(myHS1->Surface().Cylinder());
1371 quad1.SetValue(myHS1->Surface().Cone());
1373 case GeomAbs_Sphere:
1374 quad1.SetValue(myHS1->Surface().Sphere());
1377 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
1380 typs = myHS2->Surface().GetType();
1384 quad2.SetValue(myHS2->Surface().Plane());
1386 case GeomAbs_Cylinder:
1387 quad2.SetValue(myHS2->Surface().Cylinder());
1390 quad2.SetValue(myHS2->Surface().Cone());
1392 case GeomAbs_Sphere:
1393 quad2.SetValue(myHS2->Surface().Sphere());
1396 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
1400 IntPatch_ALineToWLine convert (quad1, quad2);
1403 aNbParts=myLConstruct.NbParts();
1404 for (i=1; i<=aNbParts; i++) {
1405 myLConstruct.Part(i, fprm, lprm);
1406 Handle(IntPatch_WLine) WL =
1407 convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
1409 Handle(Geom2d_BSplineCurve) H1;
1410 Handle(Geom2d_BSplineCurve) H2;
1413 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1417 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1420 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1424 else { // myApprox=TRUE
1425 GeomInt_WLApprox theapp3d;
1427 Standard_Real tol2d = myTolApprox;
1429 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
1431 aNbParts=myLConstruct.NbParts();
1432 for (i=1; i<=aNbParts; i++) {
1433 myLConstruct.Part(i, fprm, lprm);
1434 Handle(IntPatch_WLine) WL =
1435 convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
1437 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
1439 if (!theapp3d.IsDone()) {
1441 Handle(Geom2d_BSplineCurve) H1;
1442 Handle(Geom2d_BSplineCurve) H2;
1445 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1449 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1452 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1456 if(myApprox1 || myApprox2) {
1457 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
1458 myTolReached2d = theapp3d.TolReached2d();
1462 if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
1463 myTolReached3d = theapp3d.TolReached3d();
1466 Standard_Integer aNbMultiCurves, nbpoles;
1467 aNbMultiCurves=theapp3d.NbMultiCurves();
1468 for (j=1; j<=aNbMultiCurves; j++) {
1469 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1470 nbpoles = mbspc.NbPoles();
1472 TColgp_Array1OfPnt tpoles(1, nbpoles);
1473 mbspc.Curve(1, tpoles);
1474 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1476 mbspc.Multiplicities(),
1479 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1480 Check.FixTangent(Standard_True,Standard_True);
1482 IntTools_Curve aCurve;
1483 aCurve.SetCurve(BS);
1486 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1487 mbspc.Curve(2,tpoles2d);
1488 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1490 mbspc.Multiplicities(),
1493 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1494 newCheck.FixTangent(Standard_True,Standard_True);
1496 aCurve.SetFirstCurve2d(BS2);
1499 Handle(Geom2d_BSplineCurve) H1;
1500 aCurve.SetFirstCurve2d(H1);
1504 TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
1505 Standard_Integer TwoOrThree;
1506 TwoOrThree=myApprox1 ? 3 : 2;
1507 mbspc.Curve(TwoOrThree, tpoles2d);
1508 Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
1510 mbspc.Multiplicities(),
1513 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1514 newCheck.FixTangent(Standard_True,Standard_True);
1516 aCurve.SetSecondCurve2d(BS2);
1519 Handle(Geom2d_BSplineCurve) H2;
1520 aCurve.SetSecondCurve2d(H2);
1523 mySeqOfCurve.Append(aCurve);
1525 }// for (j=1; j<=aNbMultiCurves; j++) {
1526 }// else from if (!theapp3d.IsDone())
1527 }// for (i=1; i<=aNbParts; i++) {
1528 }// else { // myApprox=TRUE
1529 }// case IntPatch_Analytic:
1532 case IntPatch_Walking:{
1533 Handle(IntPatch_WLine) WL =
1534 Handle(IntPatch_WLine)::DownCast(L);
1536 Standard_Integer ifprm, ilprm;
1540 if(!bAvoidLineConstructor){
1541 aNbParts=myLConstruct.NbParts();
1543 for (i=1; i<=aNbParts; ++i) {
1544 Handle(Geom2d_BSplineCurve) H1, H2;
1545 Handle(Geom_Curve) aBSp;
1547 if(bAvoidLineConstructor) {
1549 ilprm = WL->NbPnts();
1552 myLConstruct.Part(i, fprm, lprm);
1553 ifprm=(Standard_Integer)fprm;
1554 ilprm=(Standard_Integer)lprm;
1558 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1562 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1565 aBSp=MakeBSpline(WL, ifprm, ilprm);
1566 IntTools_Curve aIC(aBSp, H1, H2);
1567 mySeqOfCurve.Append(aIC);
1568 }// for (i=1; i<=aNbParts; ++i) {
1569 }// if (!myApprox) {
1572 Standard_Boolean bIsDecomposited;
1573 Standard_Integer nbiter, aNbSeqOfL;
1574 Standard_Real tol2d;
1575 IntPatch_SequenceOfLine aSeqOfL;
1576 GeomInt_WLApprox theapp3d;
1577 Approx_ParametrizationType aParType = Approx_ChordLength;
1579 Standard_Boolean anApprox1 = myApprox1;
1580 Standard_Boolean anApprox2 = myApprox2;
1582 tol2d = myTolApprox;
1584 GeomAbs_SurfaceType typs1, typs2;
1585 typs1 = myHS1->Surface().GetType();
1586 typs2 = myHS2->Surface().GetType();
1587 Standard_Boolean anWithPC = Standard_True;
1589 if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
1591 ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
1593 else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
1595 ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
1598 //aParType = Approx_Centripetal;
1599 myTolApprox = 1.e-5;
1600 anApprox1 = Standard_False;
1601 anApprox2 = Standard_False;
1603 tol2d = myTolApprox;
1606 if(myHS1 == myHS2) {
1608 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1609 rejectSurface = Standard_True;
1612 if(reApprox && !rejectSurface)
1613 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1615 Standard_Integer iDegMax, iDegMin;
1617 ApproxParameters(myHS1, myHS2, iDegMin, iDegMax);
1618 theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, 0, Standard_True, aParType);
1622 Standard_Real aReachedTol = Precision::Confusion();
1623 bIsDecomposited=DecompositionOfWLine(WL,
1629 bAvoidLineConstructor,
1632 if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) )
1633 myTolReached3d = aReachedTol;
1636 aNbSeqOfL=aSeqOfL.Length();
1638 if (bIsDecomposited) {
1644 if (!bAvoidLineConstructor) {
1645 aNbParts=myLConstruct.NbParts();
1650 // nbiter=(bIsDecomposited) ? aSeqOfL.Length() :
1651 // ((bAvoidLineConstructor) ? 1 :aNbParts);
1653 for(i = 1; i <= nbiter; ++i) {
1654 if(bIsDecomposited) {
1655 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
1657 ilprm = WL->NbPnts();
1660 if(bAvoidLineConstructor) {
1662 ilprm = WL->NbPnts();
1665 myLConstruct.Part(i, fprm, lprm);
1666 ifprm = (Standard_Integer)fprm;
1667 ilprm = (Standard_Integer)lprm;
1671 //-- Si une des surfaces est un plan , on approxime en 2d
1672 //-- sur cette surface et on remonte les points 2d en 3d.
1673 if(typs1 == GeomAbs_Plane) {
1674 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
1676 else if(typs2 == GeomAbs_Plane) {
1677 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
1681 if (myHS1 != myHS2){
1682 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
1683 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
1685 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
1687 Standard_Boolean bUseSurfaces;
1688 bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
1691 rejectSurface = Standard_True;
1693 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1698 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
1701 if (!theapp3d.IsDone()) {
1703 Handle(Geom2d_BSplineCurve) H1;
1705 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
1706 Handle(Geom2d_BSplineCurve) H2;
1709 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1713 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1716 IntTools_Curve aIC(aBSp, H1, H2);
1717 mySeqOfCurve.Append(aIC);
1721 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
1722 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
1723 myTolReached2d = theapp3d.TolReached2d();
1726 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
1727 myTolReached3d = myTolReached2d;
1729 if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
1730 if (myTolReached3d<1.e-6) {
1731 myTolReached3d = theapp3d.TolReached3d();
1732 myTolReached3d=1.e-6;
1737 else 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 if(typs1 == GeomAbs_Plane) {
1745 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1746 nbpoles = mbspc.NbPoles();
1748 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1749 TColgp_Array1OfPnt tpoles(1,nbpoles);
1751 mbspc.Curve(1,tpoles2d);
1752 const gp_Pln& Pln = myHS1->Surface().Plane();
1754 Standard_Integer ik;
1755 for(ik = 1; ik<= nbpoles; ik++) {
1757 ElSLib::Value(tpoles2d.Value(ik).X(),
1758 tpoles2d.Value(ik).Y(),
1762 Handle(Geom_BSplineCurve) BS =
1763 new Geom_BSplineCurve(tpoles,
1765 mbspc.Multiplicities(),
1767 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1768 Check.FixTangent(Standard_True, Standard_True);
1770 IntTools_Curve aCurve;
1771 aCurve.SetCurve(BS);
1774 Handle(Geom2d_BSplineCurve) BS1 =
1775 new Geom2d_BSplineCurve(tpoles2d,
1777 mbspc.Multiplicities(),
1779 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
1780 Check1.FixTangent(Standard_True,Standard_True);
1782 // ############################################
1783 if(!rejectSurface && !reApprox) {
1784 Standard_Boolean isValid = IsCurveValid(BS1);
1786 reApprox = Standard_True;
1790 // ############################################
1791 aCurve.SetFirstCurve2d(BS1);
1794 Handle(Geom2d_BSplineCurve) H1;
1795 aCurve.SetFirstCurve2d(H1);
1799 mbspc.Curve(2, tpoles2d);
1801 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
1803 mbspc.Multiplicities(),
1805 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1806 newCheck.FixTangent(Standard_True,Standard_True);
1808 // ###########################################
1809 if(!rejectSurface && !reApprox) {
1810 Standard_Boolean isValid = IsCurveValid(BS2);
1812 reApprox = Standard_True;
1816 // ###########################################
1818 aCurve.SetSecondCurve2d(BS2);
1821 Handle(Geom2d_BSplineCurve) H2;
1823 aCurve.SetSecondCurve2d(H2);
1826 mySeqOfCurve.Append(aCurve);
1829 else if(typs2 == GeomAbs_Plane) {
1830 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1831 nbpoles = mbspc.NbPoles();
1833 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1834 TColgp_Array1OfPnt tpoles(1,nbpoles);
1835 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
1836 const gp_Pln& Pln = myHS2->Surface().Plane();
1838 Standard_Integer ik;
1839 for(ik = 1; ik<= nbpoles; ik++) {
1841 ElSLib::Value(tpoles2d.Value(ik).X(),
1842 tpoles2d.Value(ik).Y(),
1847 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1849 mbspc.Multiplicities(),
1851 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1852 Check.FixTangent(Standard_True,Standard_True);
1854 IntTools_Curve aCurve;
1855 aCurve.SetCurve(BS);
1858 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
1860 mbspc.Multiplicities(),
1862 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
1863 Check1.FixTangent(Standard_True,Standard_True);
1865 // ###########################################
1866 if(!rejectSurface && !reApprox) {
1867 Standard_Boolean isValid = IsCurveValid(BS1);
1869 reApprox = Standard_True;
1873 // ###########################################
1874 aCurve.SetSecondCurve2d(BS1);
1877 Handle(Geom2d_BSplineCurve) H2;
1878 aCurve.SetSecondCurve2d(H2);
1882 mbspc.Curve(1,tpoles2d);
1883 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1885 mbspc.Multiplicities(),
1887 GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
1888 Check2.FixTangent(Standard_True,Standard_True);
1890 // ###########################################
1891 if(!rejectSurface && !reApprox) {
1892 Standard_Boolean isValid = IsCurveValid(BS2);
1894 reApprox = Standard_True;
1898 // ###########################################
1899 aCurve.SetFirstCurve2d(BS2);
1902 Handle(Geom2d_BSplineCurve) H1;
1904 aCurve.SetFirstCurve2d(H1);
1907 mySeqOfCurve.Append(aCurve);
1910 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1911 nbpoles = mbspc.NbPoles();
1912 TColgp_Array1OfPnt tpoles(1,nbpoles);
1913 mbspc.Curve(1,tpoles);
1914 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1916 mbspc.Multiplicities(),
1918 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1919 Check.FixTangent(Standard_True,Standard_True);
1921 IntTools_Curve aCurve;
1922 aCurve.SetCurve(BS);
1926 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1927 mbspc.Curve(2,tpoles2d);
1928 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
1930 mbspc.Multiplicities(),
1932 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
1933 newCheck.FixTangent(Standard_True,Standard_True);
1935 aCurve.SetFirstCurve2d(BS1);
1938 Handle(Geom2d_BSplineCurve) BS1;
1939 fprm = BS->FirstParameter();
1940 lprm = BS->LastParameter();
1942 Handle(Geom2d_Curve) C2d;
1943 Standard_Real aTol = myTolApprox;
1944 BuildPCurves(fprm, lprm, aTol, myHS1->ChangeSurface().Surface(), BS, C2d);
1945 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
1946 aCurve.SetFirstCurve2d(BS1);
1951 Handle(Geom2d_BSplineCurve) H1;
1953 aCurve.SetFirstCurve2d(H1);
1957 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1958 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
1959 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1961 mbspc.Multiplicities(),
1963 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1964 newCheck.FixTangent(Standard_True,Standard_True);
1966 aCurve.SetSecondCurve2d(BS2);
1969 Handle(Geom2d_BSplineCurve) BS2;
1970 fprm = BS->FirstParameter();
1971 lprm = BS->LastParameter();
1973 Handle(Geom2d_Curve) C2d;
1974 Standard_Real aTol = myTolApprox;
1975 BuildPCurves(fprm, lprm, aTol, myHS2->ChangeSurface().Surface(), BS, C2d);
1976 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
1977 aCurve.SetSecondCurve2d(BS2);
1982 Handle(Geom2d_BSplineCurve) H2;
1984 aCurve.SetSecondCurve2d(H2);
1987 mySeqOfCurve.Append(aCurve);
1993 }// case IntPatch_Walking:{
1996 case IntPatch_Restriction:
2002 //=======================================================================
2003 //function : BuildPCurves
2005 //=======================================================================
2006 void BuildPCurves (Standard_Real f,
2009 const Handle (Geom_Surface)& S,
2010 const Handle (Geom_Curve)& C,
2011 Handle (Geom2d_Curve)& C2d)
2014 Standard_Real umin,umax,vmin,vmax;
2019 // in class ProjLib_Function the range of parameters is shrank by 1.e-09
2020 if((l - f) > 2.e-09) {
2021 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2024 // proj. a circle that goes through the pole on a sphere to the sphere
2026 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2030 if((l - f) > Epsilon(Abs(f))) {
2031 GeomAPI_ProjectPointOnSurf aProjector1, aProjector2;
2032 gp_Pnt P1 = C->Value(f);
2033 gp_Pnt P2 = C->Value(l);
2034 aProjector1.Init(P1, S);
2035 aProjector2.Init(P2, S);
2037 if(aProjector1.IsDone() && aProjector2.IsDone()) {
2038 Standard_Real U=0., V=0.;
2039 aProjector1.LowerDistanceParameters(U, V);
2042 aProjector2.LowerDistanceParameters(U, V);
2045 if(p1.Distance(p2) > gp::Resolution()) {
2046 TColgp_Array1OfPnt2d poles(1,2);
2047 TColStd_Array1OfReal knots(1,2);
2048 TColStd_Array1OfInteger mults(1,2);
2053 mults(1) = mults(2) = 2;
2055 C2d = new Geom2d_BSplineCurve(poles,knots,mults,1);
2057 // compute reached tolerance.begin
2058 gp_Pnt PMid = C->Value((f + l) * 0.5);
2059 aProjector1.Perform(PMid);
2061 if(aProjector1.IsDone()) {
2062 aProjector1.LowerDistanceParameters(U, V);
2063 gp_Pnt2d pmidproj(U, V);
2064 gp_Pnt2d pmidcurve2d = C2d->Value((f + l) * 0.5);
2065 Standard_Real adist = pmidcurve2d.Distance(pmidproj);
2066 Tol = (adist > Tol) ? adist : Tol;
2068 // compute reached tolerance.end
2074 S->Bounds(umin, umax, vmin, vmax);
2076 if (S->IsUPeriodic() && !C2d.IsNull()) {
2077 // Recadre dans le domaine UV de la face
2078 Standard_Real period, U0, du, aEps;
2081 aEps=Precision::PConfusion();
2082 period = S->UPeriod();
2083 gp_Pnt2d Pf = C2d->Value(f);
2086 gp_Pnt2d Pl = C2d->Value(l);
2088 U0 = Min(Pl.X(), U0);
2089 // while(U0-umin<aEps) {
2090 while(U0-umin<-aEps) {
2095 while(U0-umax>aEps) {
2106 BOPTColStd_Dump::PrintMessage("BuildPCurves()=> Echec ProjLib\n");
2110 //=======================================================================
2111 //function : Parameters
2113 //=======================================================================
2114 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
2115 const Handle(GeomAdaptor_HSurface)& HS2,
2116 const gp_Pnt& Ptref,
2123 IntSurf_Quadric quad1,quad2;
2124 GeomAbs_SurfaceType typs = HS1->Surface().GetType();
2128 quad1.SetValue(HS1->Surface().Plane());
2130 case GeomAbs_Cylinder:
2131 quad1.SetValue(HS1->Surface().Cylinder());
2134 quad1.SetValue(HS1->Surface().Cone());
2136 case GeomAbs_Sphere:
2137 quad1.SetValue(HS1->Surface().Sphere());
2140 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2143 typs = HS2->Surface().GetType();
2146 quad2.SetValue(HS2->Surface().Plane());
2148 case GeomAbs_Cylinder:
2149 quad2.SetValue(HS2->Surface().Cylinder());
2152 quad2.SetValue(HS2->Surface().Cone());
2154 case GeomAbs_Sphere:
2155 quad2.SetValue(HS2->Surface().Sphere());
2158 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2161 quad1.Parameters(Ptref,U1,V1);
2162 quad2.Parameters(Ptref,U2,V2);
2165 //=======================================================================
2166 //function : MakeBSpline
2168 //=======================================================================
2169 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
2170 const Standard_Integer ideb,
2171 const Standard_Integer ifin)
2173 Standard_Integer i,nbpnt = ifin-ideb+1;
2174 TColgp_Array1OfPnt poles(1,nbpnt);
2175 TColStd_Array1OfReal knots(1,nbpnt);
2176 TColStd_Array1OfInteger mults(1,nbpnt);
2177 Standard_Integer ipidebm1;
2178 for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) {
2179 poles(i) = WL->Point(ipidebm1).Value();
2183 mults(1) = mults(nbpnt) = 2;
2185 new Geom_BSplineCurve(poles,knots,mults,1);
2189 //=======================================================================
2190 //function : MakeBSpline2d
2192 //=======================================================================
2193 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
2194 const Standard_Integer ideb,
2195 const Standard_Integer ifin,
2196 const Standard_Boolean onFirst)
2198 Standard_Integer i, nbpnt = ifin-ideb+1;
2199 TColgp_Array1OfPnt2d poles(1,nbpnt);
2200 TColStd_Array1OfReal knots(1,nbpnt);
2201 TColStd_Array1OfInteger mults(1,nbpnt);
2202 Standard_Integer ipidebm1;
2204 for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
2207 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
2209 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
2210 poles(i).SetCoord(U, V);
2214 mults(1) = mults(nbpnt) = 2;
2216 return new Geom2d_BSplineCurve(poles,knots,mults,1);
2218 //modified by NIZNHY-PKV Fri Sep 16 07:57:30 2011f
2219 //=======================================================================
2220 //function : PrepareLines3D
2222 //=======================================================================
2223 void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit)
2225 Standard_Integer i, aNbCurves;
2226 GeomAbs_SurfaceType aType1, aType2;
2227 IntTools_SequenceOfCurves aNewCvs;
2229 // 1. Treatment closed curves
2230 aNbCurves=mySeqOfCurve.Length();
2231 for (i=1; i<=aNbCurves; ++i) {
2232 const IntTools_Curve& aIC=mySeqOfCurve(i);
2235 Standard_Integer j, aNbC;
2236 IntTools_SequenceOfCurves aSeqCvs;
2238 aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
2240 for (j=1; j<=aNbC; ++j) {
2241 const IntTools_Curve& aICNew=aSeqCvs(j);
2242 aNewCvs.Append(aICNew);
2246 aNewCvs.Append(aIC);
2250 aNewCvs.Append(aIC);
2254 // 2. Plane\Cone intersection when we had 4 curves
2255 aType1=myHS1->GetType();
2256 aType2=myHS2->GetType();
2257 aNbCurves=aNewCvs.Length();
2259 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) ||
2260 (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) {
2262 GeomAbs_CurveType aCType1;
2264 aCType1=aNewCvs(1).Type();
2265 if (aCType1==GeomAbs_Line) {
2266 IntTools_SequenceOfCurves aSeqIn, aSeqOut;
2268 for (i=1; i<=aNbCurves; ++i) {
2269 const IntTools_Curve& aIC=aNewCvs(i);
2273 IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
2276 aNbCurves=aSeqOut.Length();
2277 for (i=1; i<=aNbCurves; ++i) {
2278 const IntTools_Curve& aIC=aSeqOut(i);
2279 aNewCvs.Append(aIC);
2283 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)...
2285 // 3. Fill mySeqOfCurve
2286 mySeqOfCurve.Clear();
2287 aNbCurves=aNewCvs.Length();
2288 for (i=1; i<=aNbCurves; ++i) {
2289 const IntTools_Curve& aIC=aNewCvs(i);
2290 mySeqOfCurve.Append(aIC);
2293 //modified by NIZNHY-PKV Fri Sep 16 07:57:32 2011t
2294 //=======================================================================
2295 //function : CorrectSurfaceBoundaries
2297 //=======================================================================
2298 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
2299 const Standard_Real theTolerance,
2300 Standard_Real& theumin,
2301 Standard_Real& theumax,
2302 Standard_Real& thevmin,
2303 Standard_Real& thevmax)
2305 Standard_Boolean enlarge, isuperiodic, isvperiodic;
2306 Standard_Real uinf, usup, vinf, vsup, delta;
2307 GeomAbs_SurfaceType aType;
2308 Handle(Geom_Surface) aSurface;
2310 aSurface = BRep_Tool::Surface(theFace);
2311 aSurface->Bounds(uinf, usup, vinf, vsup);
2312 delta = theTolerance;
2313 enlarge = Standard_False;
2315 GeomAdaptor_Surface anAdaptorSurface(aSurface);
2317 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
2318 Handle(Geom_Surface) aBasisSurface =
2319 (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface();
2321 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2322 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2327 if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2328 Handle(Geom_Surface) aBasisSurface =
2329 (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface();
2331 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2332 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2337 isuperiodic = anAdaptorSurface.IsUPeriodic();
2338 isvperiodic = anAdaptorSurface.IsVPeriodic();
2340 aType=anAdaptorSurface.GetType();
2341 if((aType==GeomAbs_BezierSurface) ||
2342 (aType==GeomAbs_BSplineSurface) ||
2343 (aType==GeomAbs_SurfaceOfExtrusion) ||
2344 (aType==GeomAbs_SurfaceOfRevolution)) {
2345 enlarge=Standard_True;
2348 if(!isuperiodic && enlarge) {
2350 if((theumin - uinf) > delta )
2356 if((usup - theumax) > delta )
2362 if(!isvperiodic && enlarge) {
2363 if((thevmin - vinf) > delta ) {
2369 if((vsup - thevmax) > delta ) {
2378 Standard_Integer aNbP;
2379 Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA;
2381 aTolPA=Precision::Angular();
2384 aXP=anAdaptorSurface.UPeriod();
2385 dXfact=theumax-theumin;
2386 if (dXfact-aTolPA>aXP) {
2387 aXmid=0.5*(theumax+theumin);
2388 aNbP=RealToInt(aXmid/aXP);
2393 if (theumin>aTolPA) {
2394 aX1=theumin+aNbP*aXP;
2407 aXP=anAdaptorSurface.VPeriod();
2408 dXfact=thevmax-thevmin;
2409 if (dXfact-aTolPA>aXP) {
2410 aXmid=0.5*(thevmax+thevmin);
2411 aNbP=RealToInt(aXmid/aXP);
2416 if (thevmin>aTolPA) {
2417 aX1=thevmin+aNbP*aXP;
2430 if(isuperiodic || isvperiodic) {
2431 Standard_Boolean correct = Standard_False;
2432 Standard_Boolean correctU = Standard_False;
2433 Standard_Boolean correctV = Standard_False;
2435 TopExp_Explorer anExp;
2437 for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2438 if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
2439 correct = Standard_True;
2441 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
2443 for(Standard_Integer i = 0; i < 2; i++) {
2445 anEdge.Orientation(TopAbs_FORWARD);
2448 anEdge.Orientation(TopAbs_REVERSED);
2450 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
2452 if(aCurve.IsNull()) {
2453 correct = Standard_False;
2456 Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
2458 if(aLine.IsNull()) {
2459 correct = Standard_False;
2462 gp_Dir2d anUDir(1., 0.);
2463 gp_Dir2d aVDir(0., 1.);
2464 Standard_Real anAngularTolerance = Precision::Angular();
2466 correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
2467 correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
2469 gp_Pnt2d pp1 = aCurve->Value(f);
2471 gp_Pnt2d pp2 = aCurve->Value(l);
2480 Standard_Real umin, vmin, umax, vmax;
2481 aBox.Get(umin, vmin, umax, vmax);
2483 if(isuperiodic && correctU) {
2488 if(theumax > umax) {
2492 if(isvperiodic && correctV) {
2504 // The block is dedicated to determine whether WLine [ifprm, ilprm]
2505 // crosses the degenerated zone on each given surface or not.
2506 // If Yes -> We will not use info about surfaces during approximation
2507 // because inside degenerated zone of the surface the approx. alogo.
2508 // uses wrong values of normal, etc., and resulting curve will have
2509 // oscillations that we would not like to have.
2510 // PKV Tue Feb 12 2002
2514 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2515 const Handle(Geom_Surface)& aS,
2516 const Standard_Integer iDir);
2518 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2519 const TopoDS_Face& aF1,
2520 const TopoDS_Face& aF2);
2521 //=======================================================================
2522 //function : NotUseSurfacesForApprox
2524 //=======================================================================
2525 Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
2526 const TopoDS_Face& aF2,
2527 const Handle(IntPatch_WLine)& WL,
2528 const Standard_Integer ifprm,
2529 const Standard_Integer ilprm)
2531 Standard_Boolean bPInDZ;
2533 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
2535 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
2536 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
2541 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
2542 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
2546 //=======================================================================
2547 //function : IsPointInDegeneratedZone
2549 //=======================================================================
2550 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2551 const TopoDS_Face& aF1,
2552 const TopoDS_Face& aF2)
2555 Standard_Boolean bFlag=Standard_True;
2556 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
2557 Standard_Real U1, V1, U2, V2, aDelta, aD;
2560 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
2561 aS1->Bounds(US11, US12, VS11, VS12);
2562 GeomAdaptor_Surface aGAS1(aS1);
2564 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
2565 aS1->Bounds(US21, US22, VS21, VS22);
2566 GeomAdaptor_Surface aGAS2(aS2);
2568 //const gp_Pnt& aP=aP2S.Value();
2569 aP2S.Parameters(U1, V1, U2, V2);
2573 aD=aGAS1.UResolution(aDelta);
2574 aP2d.SetCoord(U1, V1);
2575 if (fabs(U1-US11) < aD) {
2576 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2581 if (fabs(U1-US12) < aD) {
2582 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2587 aD=aGAS1.VResolution(aDelta);
2588 if (fabs(V1-VS11) < aDelta) {
2589 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2594 if (fabs(V1-VS12) < aDelta) {
2595 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2601 aD=aGAS2.UResolution(aDelta);
2602 aP2d.SetCoord(U2, V2);
2603 if (fabs(U2-US21) < aDelta) {
2604 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2609 if (fabs(U2-US22) < aDelta) {
2610 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2615 aD=aGAS2.VResolution(aDelta);
2616 if (fabs(V2-VS21) < aDelta) {
2617 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2622 if (fabs(V2-VS22) < aDelta) {
2623 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2631 //=======================================================================
2632 //function : IsDegeneratedZone
2634 //=======================================================================
2635 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2636 const Handle(Geom_Surface)& aS,
2637 const Standard_Integer iDir)
2639 Standard_Boolean bFlag=Standard_True;
2640 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
2641 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
2642 aS->Bounds(US1, US2, VS1, VS2);
2644 gp_Pnt aPm, aPb, aPe;
2649 aS->D0(aXm, aYm, aPm);
2666 aS->D0(aXb, aYb, aPb);
2667 aS->D0(aXe, aYe, aPe);
2669 d1=aPm.Distance(aPb);
2670 d2=aPm.Distance(aPe);
2671 if (d1 < dD && d2 < dD) {
2688 aS->D0(aXb, aYb, aPb);
2689 aS->D0(aXe, aYe, aPe);
2691 d1=aPm.Distance(aPb);
2692 d2=aPm.Distance(aPe);
2693 if (d1 < dD && d2 < dD) {
2701 //=========================================================================
2702 // static function : ComputePurgedWLine
2703 // purpose : Removes equal points (leave one of equal points) from theWLine
2704 // and recompute vertex parameters.
2705 // Returns new WLine or null WLine if the number
2706 // of the points is less than 2.
2707 //=========================================================================
2708 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) {
2709 Handle(IntPatch_WLine) aResult;
2710 Handle(IntPatch_WLine) aLocalWLine;
2711 Handle(IntPatch_WLine) aTmpWLine = theWLine;
2713 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
2714 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2715 Standard_Integer i, k, v, nb, nbvtx;
2716 nbvtx = theWLine->NbVertex();
2717 nb = theWLine->NbPnts();
2719 for(i = 1; i <= nb; i++) {
2720 aLineOn2S->Add(theWLine->Point(i));
2723 for(v = 1; v <= nbvtx; v++) {
2724 aLocalWLine->AddVertex(theWLine->Vertex(v));
2727 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
2728 Standard_Integer aStartIndex = i + 1;
2729 Standard_Integer anEndIndex = i + 5;
2730 nb = aLineOn2S->NbPoints();
2731 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
2733 if((aStartIndex >= nb) || (anEndIndex <= 1)) {
2738 while(k <= anEndIndex) {
2741 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
2742 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
2744 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2745 aTmpWLine = aLocalWLine;
2746 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2748 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
2749 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
2750 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
2752 if(avertexindex >= k) {
2753 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
2755 aLocalWLine->AddVertex(aVertex);
2757 aLineOn2S->RemovePoint(k);
2766 if(aLineOn2S->NbPoints() > 1) {
2767 aResult = aLocalWLine;
2772 //=======================================================================
2775 //=======================================================================
2776 void TolR3d(const TopoDS_Face& aF1,
2777 const TopoDS_Face& aF2,
2778 Standard_Real& myTolReached3d)
2780 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
2782 aTolTresh=2.999999e-3;
2783 aTolF1 = BRep_Tool::Tolerance(aF1);
2784 aTolF2 = BRep_Tool::Tolerance(aF2);
2785 aTolFMax=Max(aTolF1, aTolF2);
2787 if (aTolFMax>aTolTresh) {
2788 myTolReached3d=aTolFMax;
2791 //=======================================================================
2792 //function : AdjustPeriodic
2794 //=======================================================================
2795 Standard_Real AdjustPeriodic(const Standard_Real theParameter,
2796 const Standard_Real parmin,
2797 const Standard_Real parmax,
2798 const Standard_Real thePeriod,
2799 Standard_Real& theOffset)
2801 Standard_Real aresult;
2804 aresult = theParameter;
2805 while(aresult < parmin) {
2806 aresult += thePeriod;
2807 theOffset += thePeriod;
2810 while(aresult > parmax) {
2811 aresult -= thePeriod;
2812 theOffset -= thePeriod;
2816 //=======================================================================
2817 //function : IsPointOnBoundary
2819 //=======================================================================
2820 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
2821 const Standard_Real theFirstBoundary,
2822 const Standard_Real theSecondBoundary,
2823 const Standard_Real theResolution,
2824 Standard_Boolean& IsOnFirstBoundary)
2826 Standard_Boolean bRet;
2828 Standard_Real adist;
2830 bRet=Standard_False;
2831 for(i = 0; i < 2; ++i) {
2832 IsOnFirstBoundary = (i == 0);
2833 if (IsOnFirstBoundary) {
2834 adist = fabs(theParameter - theFirstBoundary);
2837 adist = fabs(theParameter - theSecondBoundary);
2839 if(adist < theResolution) {
2845 // ------------------------------------------------------------------------------------------------
2846 // static function: FindPoint
2848 // ------------------------------------------------------------------------------------------------
2849 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
2850 const gp_Pnt2d& theLastPoint,
2851 const Standard_Real theUmin,
2852 const Standard_Real theUmax,
2853 const Standard_Real theVmin,
2854 const Standard_Real theVmax,
2855 gp_Pnt2d& theNewPoint) {
2857 gp_Vec2d aVec(theFirstPoint, theLastPoint);
2858 Standard_Integer i = 0, j = 0;
2860 for(i = 0; i < 4; i++) {
2861 gp_Vec2d anOtherVec;
2862 gp_Vec2d anOtherVecNormal;
2863 gp_Pnt2d aprojpoint = theLastPoint;
2866 anOtherVec.SetX(0.);
2867 anOtherVec.SetY(1.);
2868 anOtherVecNormal.SetX(1.);
2869 anOtherVecNormal.SetY(0.);
2872 aprojpoint.SetX(theUmin);
2874 aprojpoint.SetX(theUmax);
2877 anOtherVec.SetX(1.);
2878 anOtherVec.SetY(0.);
2879 anOtherVecNormal.SetX(0.);
2880 anOtherVecNormal.SetY(1.);
2883 aprojpoint.SetY(theVmin);
2885 aprojpoint.SetY(theVmax);
2887 gp_Vec2d anormvec = aVec;
2888 anormvec.Normalize();
2889 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
2891 if(fabs(adot1) < Precision::Angular())
2893 Standard_Real adist = 0.;
2894 Standard_Boolean bIsOut = Standard_False;
2897 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
2898 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
2901 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
2902 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
2904 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
2906 for(j = 0; j < 2; j++) {
2907 anoffset = (j == 0) ? anoffset : -anoffset;
2908 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
2909 gp_Vec2d acurvec(theLastPoint, acurpoint);
2913 Standard_Real aDotX, anAngleX;
2915 aDotX = aVec.Dot(acurvec);
2916 anAngleX = aVec.Angle(acurvec);
2918 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
2920 if((acurpoint.Y() >= theVmin) &&
2921 (acurpoint.Y() <= theVmax)) {
2922 theNewPoint = acurpoint;
2923 return Standard_True;
2927 if((acurpoint.X() >= theUmin) &&
2928 (acurpoint.X() <= theUmax)) {
2929 theNewPoint = acurpoint;
2930 return Standard_True;
2936 return Standard_False;
2940 // ------------------------------------------------------------------------------------------------
2941 // static function: FindPoint
2942 // purpose: Find point on the boundary of radial tangent zone
2943 // ------------------------------------------------------------------------------------------------
2944 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
2945 const gp_Pnt2d& theLastPoint,
2946 const Standard_Real theUmin,
2947 const Standard_Real theUmax,
2948 const Standard_Real theVmin,
2949 const Standard_Real theVmax,
2950 const gp_Pnt2d& theTanZoneCenter,
2951 const Standard_Real theZoneRadius,
2952 Handle(GeomAdaptor_HSurface) theGASurface,
2953 gp_Pnt2d& theNewPoint) {
2954 theNewPoint = theLastPoint;
2956 if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
2957 return Standard_False;
2959 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
2960 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
2962 Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
2963 gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) );
2964 gp_Circ2d aCircle( anAxis, aRadius );
2967 gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() );
2968 Standard_Real aLength = aDir.Magnitude();
2969 if ( aLength <= gp::Resolution() )
2970 return Standard_False;
2971 gp_Lin2d aLine( theFirstPoint, aDir );
2974 Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine );
2975 Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength );
2976 Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle );
2978 Standard_Real aTol = aRadius * 0.001;
2979 aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol;
2981 Geom2dAPI_InterCurveCurve anIntersector;
2982 anIntersector.Init( aC1, aC2, aTol );
2984 if ( anIntersector.NbPoints() == 0 )
2985 return Standard_False;
2987 Standard_Boolean aFound = Standard_False;
2988 Standard_Real aMinDist = aLength * aLength;
2989 Standard_Integer i = 0;
2990 for ( i = 1; i <= anIntersector.NbPoints(); i++ ) {
2991 gp_Pnt2d aPInt = anIntersector.Point( i );
2992 if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
2993 if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
2994 ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
2995 theNewPoint = aPInt;
2996 aFound = Standard_True;
3004 // ------------------------------------------------------------------------------------------------
3005 // static function: IsInsideTanZone
3006 // purpose: Check if point is inside a radial tangent zone
3007 // ------------------------------------------------------------------------------------------------
3008 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
3009 const gp_Pnt2d& theTanZoneCenter,
3010 const Standard_Real theZoneRadius,
3011 Handle(GeomAdaptor_HSurface) theGASurface) {
3013 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3014 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3015 Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3016 aRadiusSQR *= aRadiusSQR;
3017 if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR )
3018 return Standard_True;
3019 return Standard_False;
3022 // ------------------------------------------------------------------------------------------------
3023 // static function: CheckTangentZonesExist
3024 // purpose: Check if tangent zone exists
3025 // ------------------------------------------------------------------------------------------------
3026 Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
3027 const Handle(GeomAdaptor_HSurface)& theSurface2 )
3029 if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
3030 ( theSurface2->GetType() != GeomAbs_Torus ) )
3031 return Standard_False;
3033 IntTools_Context aContext;
3035 gp_Torus aTor1 = theSurface1->Torus();
3036 gp_Torus aTor2 = theSurface2->Torus();
3038 if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() )
3039 return Standard_False;
3041 if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) ||
3042 ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) )
3043 return Standard_False;
3045 if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) ||
3046 ( aTor2.MajorRadius() < aTor2.MinorRadius() ) )
3047 return Standard_False;
3048 return Standard_True;
3051 // ------------------------------------------------------------------------------------------------
3052 // static function: ComputeTangentZones
3054 // ------------------------------------------------------------------------------------------------
3055 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
3056 const Handle(GeomAdaptor_HSurface)& theSurface2,
3057 const TopoDS_Face& theFace1,
3058 const TopoDS_Face& theFace2,
3059 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
3060 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
3061 Handle(TColStd_HArray1OfReal)& theResultRadius) {
3062 Standard_Integer aResult = 0;
3063 if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) )
3066 IntTools_Context aContext;
3068 TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2;
3069 TColStd_SequenceOfReal aSeqResultRad;
3071 gp_Torus aTor1 = theSurface1->Torus();
3072 gp_Torus aTor2 = theSurface2->Torus();
3074 gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() );
3075 gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() );
3076 Standard_Integer j = 0;
3078 for ( j = 0; j < 2; j++ ) {
3079 Standard_Real aCoef = ( j == 0 ) ? -1 : 1;
3080 Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius());
3081 Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius());
3083 gp_Circ aCircle1( anax1, aRadius1 );
3084 gp_Circ aCircle2( anax2, aRadius2 );
3086 // roughly compute radius of tangent zone for perpendicular case
3087 Standard_Real aCriteria = Precision::Confusion() * 0.5;
3089 Standard_Real aT1 = aCriteria;
3090 Standard_Real aT2 = aCriteria;
3092 // internal tangency
3093 Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3094 //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria );
3095 aT1 = 2. * aR * aCriteria;
3099 // external tangency
3100 Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3101 Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3102 Standard_Real aDelta = aRb - aCriteria;
3104 aDelta -= aRm * aRm;
3105 aDelta /= 2. * (aRb - aRm);
3106 aDelta -= 0.5 * (aRb - aRm);
3108 aT1 = 2. * aRm * (aRm - aDelta);
3111 aCriteria = ( aT1 > aT2) ? aT1 : aT2;
3112 if ( aCriteria > 0 )
3113 aCriteria = sqrt( aCriteria );
3115 if ( aCriteria > 0.5 * aTor1.MinorRadius() ) {
3116 // too big zone -> drop to minimum
3117 aCriteria = Precision::Confusion();
3120 GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) );
3121 GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) );
3122 Extrema_ExtCC anExtrema(aC1, aC2, 0, 2.*Standard_PI, 0, 2.*Standard_PI,
3123 Precision::PConfusion(), Precision::PConfusion());
3125 if ( anExtrema.IsDone() ) {
3127 Standard_Integer i = 0;
3128 for ( i = 1; i <= anExtrema.NbExt(); i++ ) {
3129 if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
3132 Extrema_POnCurv P1, P2;
3133 anExtrema.Points( i, P1, P2 );
3135 Standard_Boolean bFoundResult = Standard_True;
3138 Standard_Integer surfit = 0;
3139 for ( surfit = 0; surfit < 2; surfit++ ) {
3140 GeomAPI_ProjectPointOnSurf& aProjector = (surfit == 0) ? aContext.ProjPS(theFace1) : aContext.ProjPS(theFace2);
3142 gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
3143 aProjector.Perform(aP3d);
3145 if(!aProjector.IsDone())
3146 bFoundResult = Standard_False;
3148 if(aProjector.LowerDistance() > aCriteria) {
3149 bFoundResult = Standard_False;
3152 Standard_Real foundU = 0, foundV = 0;
3153 aProjector.LowerDistanceParameters(foundU, foundV);
3155 pr1 = gp_Pnt2d( foundU, foundV );
3157 pr2 = gp_Pnt2d( foundU, foundV );
3161 if ( bFoundResult ) {
3162 aSeqResultS1.Append( pr1 );
3163 aSeqResultS2.Append( pr2 );
3164 aSeqResultRad.Append( aCriteria );
3166 // torus is u and v periodic
3167 const Standard_Real twoPI = Standard_PI + Standard_PI;
3168 Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
3169 Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
3171 // iteration on period bounds
3172 for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
3173 Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
3174 Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
3176 // iteration on surfaces
3177 for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
3178 Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
3179 Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
3180 TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
3181 TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
3183 if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
3184 aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
3185 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3186 aSeqResultRad.Append( aCriteria );
3188 if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
3189 aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
3190 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3191 aSeqResultRad.Append( aCriteria );
3199 aResult = aSeqResultRad.Length();
3201 if ( aResult > 0 ) {
3202 theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult );
3203 theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult );
3204 theResultRadius = new TColStd_HArray1OfReal( 1, aResult );
3206 for ( Standard_Integer i = 1 ; i <= aResult; i++ ) {
3207 theResultOnS1->SetValue( i, aSeqResultS1.Value(i) );
3208 theResultOnS2->SetValue( i, aSeqResultS2.Value(i) );
3209 theResultRadius->SetValue( i, aSeqResultRad.Value(i) );
3215 // ------------------------------------------------------------------------------------------------
3216 // static function: AdjustByNeighbour
3218 // ------------------------------------------------------------------------------------------------
3219 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
3220 const gp_Pnt2d& theOriginalPoint,
3221 Handle(GeomAdaptor_HSurface) theGASurface) {
3223 gp_Pnt2d ap1 = theaNeighbourPoint;
3224 gp_Pnt2d ap2 = theOriginalPoint;
3226 if ( theGASurface->IsUPeriodic() ) {
3227 Standard_Real aPeriod = theGASurface->UPeriod();
3228 gp_Pnt2d aPTest = ap2;
3229 Standard_Real aSqDistMin = 1.e+100;
3231 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3232 aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt );
3233 Standard_Real dd = ap1.SquareDistance( aPTest );
3235 if ( dd < aSqDistMin ) {
3241 if ( theGASurface->IsVPeriodic() ) {
3242 Standard_Real aPeriod = theGASurface->VPeriod();
3243 gp_Pnt2d aPTest = ap2;
3244 Standard_Real aSqDistMin = 1.e+100;
3246 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3247 aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt );
3248 Standard_Real dd = ap1.SquareDistance( aPTest );
3250 if ( dd < aSqDistMin ) {
3259 // ------------------------------------------------------------------------------------------------
3260 //function: DecompositionOfWLine
3262 // ------------------------------------------------------------------------------------------------
3263 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
3264 const Handle(GeomAdaptor_HSurface)& theSurface1,
3265 const Handle(GeomAdaptor_HSurface)& theSurface2,
3266 const TopoDS_Face& theFace1,
3267 const TopoDS_Face& theFace2,
3268 const IntTools_LineConstructor& theLConstructor,
3269 const Standard_Boolean theAvoidLConstructor,
3270 IntPatch_SequenceOfLine& theNewLines,
3271 Standard_Real& theReachedTol3d) {
3273 Standard_Boolean bRet, bAvoidLineConstructor;
3274 Standard_Integer aNbPnts, aNbParts;
3276 bRet=Standard_False;
3277 aNbPnts=theWLine->NbPnts();
3278 bAvoidLineConstructor=theAvoidLConstructor;
3283 if (!bAvoidLineConstructor) {
3284 aNbParts=theLConstructor.NbParts();
3290 Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary;
3291 Standard_Integer nblines, pit, i, j;
3293 TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts);
3294 TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts);
3295 TColStd_ListOfInteger aListOfPointIndex;
3296 IntTools_Context aContext;
3298 Handle(TColgp_HArray1OfPnt2d) aTanZoneS1;
3299 Handle(TColgp_HArray1OfPnt2d) aTanZoneS2;
3300 Handle(TColStd_HArray1OfReal) aTanZoneRadius;
3301 Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2,
3302 aTanZoneS1, aTanZoneS2, aTanZoneRadius );
3306 aTol=Precision::Confusion();
3308 bIsPrevPointOnBoundary=Standard_False;
3309 bIsPointOnBoundary=Standard_False;
3314 for(pit = 1; pit <= aNbPnts; ++pit) {
3315 Standard_Boolean bIsOnFirstBoundary, isperiodic;
3316 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
3317 Standard_Real aParameter, anoffset, anAdjustPar;
3318 Standard_Real umin, umax, vmin, vmax;
3320 bIsCurrentPointOnBoundary = Standard_False;
3321 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
3324 for(i = 0; i < 2; ++i) {
3325 Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
3326 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3328 aPoint.ParametersOnS1(U, V);
3331 aPoint.ParametersOnS2(U, V);
3334 for(j = 0; j < 2; j++) {
3335 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3341 aResolution=aGASurface->UResolution(aTol);
3342 aPeriod=aGASurface->UPeriod();
3343 alowerboundary=umin;
3344 aupperboundary=umax;
3348 aResolution=aGASurface->VResolution(aTol);
3349 aPeriod=aGASurface->VPeriod();
3350 alowerboundary=vmin;
3351 aupperboundary=vmax;
3356 anAdjustPar = AdjustPeriodic(aParameter,
3362 bIsOnFirstBoundary = Standard_True;// ?
3364 IsPointOnBoundary(anAdjustPar,
3368 bIsOnFirstBoundary);
3370 if(bIsPointOnBoundary) {
3371 bIsCurrentPointOnBoundary = Standard_True;
3375 // check if a point belong to a tangent zone. Begin
3376 Standard_Integer zIt = 0;
3377 for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
3378 gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3379 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3381 if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
3382 // set boundary flag to split the curve by a tangent zone
3383 bIsPointOnBoundary = Standard_True;
3384 bIsCurrentPointOnBoundary = Standard_True;
3385 if ( theReachedTol3d < aZoneRadius ) {
3386 theReachedTol3d = aZoneRadius;
3392 }//for(j = 0; j < 2; j++) {
3394 if(bIsCurrentPointOnBoundary){
3397 }//for(i = 0; i < 2; ++i) {
3399 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
3400 if(!aListOfPointIndex.IsEmpty()) {
3402 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3403 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3404 aListOfPointIndex.Clear();
3406 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
3408 aListOfPointIndex.Append(pit);
3409 } //for(pit = 1; pit <= aNbPnts; ++pit) {
3411 if(!aListOfPointIndex.IsEmpty()) {
3413 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3414 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3415 aListOfPointIndex.Clear();
3419 return bRet; //Standard_False;
3423 // 2. Correct wlines.begin
3424 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
3425 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S();
3427 for(i = 1; i <= nblines; i++) {
3428 if(anArrayOfLineType.Value(i) != 0) {
3431 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3432 if(aListOfIndex.Extent() < 2) {
3435 TColStd_ListOfInteger aListOfFLIndex;
3437 for(j = 0; j < 2; j++) {
3438 Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1);
3440 if((aneighbourindex < 1) || (aneighbourindex > nblines))
3443 if(anArrayOfLineType.Value(aneighbourindex) == 0)
3445 const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex);
3446 Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First();
3447 const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
3449 IntSurf_PntOn2S aNewP = aPoint;
3451 for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
3453 Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
3454 Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
3455 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3456 Standard_Real U=0., V=0.;
3459 aNewP.ParametersOnS1(U, V);
3461 aNewP.ParametersOnS2(U, V);
3462 Standard_Integer nbboundaries = 0;
3464 Standard_Boolean bIsNearBoundary = Standard_False;
3465 Standard_Integer aZoneIndex = 0;
3466 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
3467 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
3470 for(Standard_Integer parit = 0; parit < 2; parit++) {
3471 Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3473 Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
3474 Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
3475 Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
3477 Standard_Real aParameter = (parit == 0) ? U : V;
3478 Standard_Boolean bIsOnFirstBoundary = Standard_True;
3482 IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3483 if(bIsPointOnBoundary) {
3484 bIsUBoundary = (parit == 0);
3485 bIsFirstBoundary = bIsOnFirstBoundary;
3490 Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3491 Standard_Real anoffset = 0.;
3492 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3495 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3496 if(bIsPointOnBoundary) {
3497 bIsUBoundary = (parit == 0);
3498 bIsFirstBoundary = bIsOnFirstBoundary;
3502 //check neighbourhood of boundary
3503 Standard_Real anEpsilon = aResolution * 100.;
3504 Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
3505 anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
3507 bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
3508 anEpsilon, bIsOnFirstBoundary);
3514 // check if a point belong to a tangent zone. Begin
3515 for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
3516 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3517 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3519 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3520 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3521 Standard_Real nU1, nV1;
3524 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3526 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3527 gp_Pnt2d ap1(nU1, nV1);
3528 gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
3531 if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
3533 bIsNearBoundary = Standard_True;
3534 if ( theReachedTol3d < aZoneRadius ) {
3535 theReachedTol3d = aZoneRadius;
3539 // check if a point belong to a tangent zone. End
3540 Standard_Boolean bComputeLineEnd = Standard_False;
3542 if(nbboundaries == 2) {
3544 bComputeLineEnd = Standard_True;
3547 else if(nbboundaries == 1) {
3548 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3551 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
3552 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
3553 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3554 Standard_Real aParameter = (bIsUBoundary) ? U : V;
3555 Standard_Real anoffset = 0.;
3556 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3558 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
3559 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
3560 anotherPar += anoffset;
3561 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3562 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
3563 Standard_Real nU1, nV1;
3566 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3568 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3570 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
3571 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
3572 bComputeLineEnd = Standard_True;
3573 Standard_Boolean bCheckAngle1 = Standard_False;
3574 Standard_Boolean bCheckAngle2 = Standard_False;
3576 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
3577 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
3579 if(((adist1 - adist2) > Precision::PConfusion()) &&
3580 (adist2 < (aPeriod / 4.))) {
3581 bCheckAngle1 = Standard_True;
3582 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
3584 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3585 aNewP.SetValue((surfit == 0), anewU, anewV);
3586 bCheckAngle1 = Standard_False;
3589 else if(adist1 < (aPeriod / 4.)) {
3590 bCheckAngle2 = Standard_True;
3591 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
3593 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3594 bCheckAngle2 = Standard_False;
3598 if(bCheckAngle1 || bCheckAngle2) {
3599 // assume there are at least two points in line (see "if" above)
3600 Standard_Integer anindexother = aneighbourpointindex;
3602 while((anindexother <= aListOfIndex.Last()) && (anindexother >= aListOfIndex.First())) {
3603 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
3604 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
3605 Standard_Real nU2, nV2;
3608 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3610 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3611 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
3613 if(aVecOld.SquareMagnitude() <= (gp::Resolution() * gp::Resolution())) {
3617 Standard_Real anAngle = aNewVec.Angle(aVecOld);
3619 if((fabs(anAngle) < (Standard_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
3622 Standard_Real U1, U2, V1, V2;
3623 IntSurf_PntOn2S atmppoint = aNewP;
3624 atmppoint.SetValue((surfit == 0), anewU, anewV);
3625 atmppoint.Parameters(U1, V1, U2, V2);
3626 gp_Pnt P1 = theSurface1->Value(U1, V1);
3627 gp_Pnt P2 = theSurface2->Value(U2, V2);
3628 gp_Pnt P0 = aPoint.Value();
3630 if(P0.IsEqual(P1, aTol) &&
3631 P0.IsEqual(P2, aTol) &&
3632 P1.IsEqual(P2, aTol)) {
3633 bComputeLineEnd = Standard_False;
3634 aNewP.SetValue((surfit == 0), anewU, anewV);
3639 bComputeLineEnd = Standard_False;
3644 } // end while(anindexother...)
3648 else if ( bIsNearBoundary ) {
3649 bComputeLineEnd = Standard_True;
3652 if(bComputeLineEnd) {
3655 Standard_Boolean found = Standard_False;
3657 if ( bIsNearBoundary ) {
3658 // re-compute point near natural boundary or near tangent zone
3659 Standard_Real u1, v1, u2, v2;
3660 aNewP.Parameters( u1, v1, u2, v2 );
3662 anewpoint = gp_Pnt2d( u1, v1 );
3664 anewpoint = gp_Pnt2d( u2, v2 );
3666 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3667 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3668 Standard_Real nU1, nV1;
3671 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3673 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3674 gp_Pnt2d ap1(nU1, nV1);
3679 // exclude point from a tangent zone
3680 anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3681 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
3682 Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
3684 if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
3685 aPZone, aZoneRadius, aGASurface, ap2) ) {
3687 found = Standard_True;
3690 else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
3691 // re-compute point near boundary if shifted on a period
3692 ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3694 if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
3695 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
3696 found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
3700 aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
3706 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3707 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3708 Standard_Real nU1, nV1;
3711 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3713 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3714 gp_Pnt2d ap1(nU1, nV1);
3715 gp_Pnt2d ap2(nU1, nV1);
3716 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
3718 while((aneighbourpointindex2 <= aListOfIndex.Last()) && (aneighbourpointindex2 >= aListOfIndex.First())) {
3719 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
3720 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
3721 Standard_Real nU2, nV2;
3724 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3726 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3730 if(ap1.SquareDistance(ap2) > (gp::Resolution() * gp::Resolution())) {
3734 found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
3739 Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
3740 GeomAPI_ProjectPointOnSurf& aProjector = (surfit == 0) ? aContext.ProjPS(theFace2) : aContext.ProjPS(theFace1);
3741 Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
3743 Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
3745 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
3746 aProjector.Perform(aP3d);
3748 if(aProjector.IsDone()) {
3749 if(aProjector.LowerDistance() < aCriteria) {
3750 Standard_Real foundU = U, foundV = V;
3751 aProjector.LowerDistanceParameters(foundU, foundV);
3753 //Correction of projected coordinates. Begin
3754 //Note, it may be shifted on a period
3755 Standard_Integer aneindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3756 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
3757 Standard_Real nUn, nVn;
3760 aNeighbourPoint.ParametersOnS2(nUn, nVn);
3762 aNeighbourPoint.ParametersOnS1(nUn, nVn);
3763 gp_Pnt2d aNeighbour2d(nUn, nVn);
3764 gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
3765 foundU = anAdjustedPoint.X();
3766 foundV = anAdjustedPoint.Y();
3768 if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
3769 ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
3770 // attempt to roughly re-compute point
3771 foundU = ( foundU < umin ) ? umin : foundU;
3772 foundU = ( foundU > umax ) ? umax : foundU;
3773 foundV = ( foundV < vmin ) ? vmin : foundV;
3774 foundV = ( foundV > vmax ) ? vmax : foundV;
3776 GeomAPI_ProjectPointOnSurf& aProjector2 = (surfit == 0) ? aContext.ProjPS(theFace1) : aContext.ProjPS(theFace2);
3778 aP3d = aSurfaceOther->Value(foundU, foundV);
3779 aProjector2.Perform(aP3d);
3781 if(aProjector2.IsDone()) {
3782 if(aProjector2.LowerDistance() < aCriteria) {
3783 Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
3784 aProjector2.LowerDistanceParameters(foundU2, foundV2);
3785 anewpoint.SetX(foundU2);
3786 anewpoint.SetY(foundV2);
3790 //Correction of projected coordinates. End
3793 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
3795 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
3801 aSeqOfPntOn2S->Add(aNewP);
3802 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
3804 anArrayOfLineEnds.SetValue(i, aListOfFLIndex);
3806 // Correct wlines.end
3808 // Split wlines.begin
3809 Standard_Integer nbiter;
3812 if (!bAvoidLineConstructor) {
3813 nbiter=theLConstructor.NbParts();
3816 for(j = 1; j <= nbiter; ++j) {
3817 Standard_Real fprm, lprm;
3818 Standard_Integer ifprm, ilprm;
3820 if(bAvoidLineConstructor) {
3822 ilprm = theWLine->NbPnts();
3825 theLConstructor.Part(j, fprm, lprm);
3826 ifprm = (Standard_Integer)fprm;
3827 ilprm = (Standard_Integer)lprm;
3830 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
3832 for(i = 1; i <= nblines; i++) {
3833 if(anArrayOfLineType.Value(i) != 0) {
3836 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3838 if(aListOfIndex.Extent() < 2) {
3841 const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
3842 Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
3843 Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
3845 if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
3846 bhasfirstpoint = (i != 1);
3849 if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
3850 bhaslastpoint = (i != nblines);
3852 Standard_Boolean bIsFirstInside = ((ifprm >= aListOfIndex.First()) && (ifprm <= aListOfIndex.Last()));
3853 Standard_Boolean bIsLastInside = ((ilprm >= aListOfIndex.First()) && (ilprm <= aListOfIndex.Last()));
3855 if(!bIsFirstInside && !bIsLastInside) {
3856 if((ifprm < aListOfIndex.First()) && (ilprm > aListOfIndex.Last())) {
3857 // append whole line, and boundaries if neccesary
3858 if(bhasfirstpoint) {
3859 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
3862 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
3864 for(; anIt.More(); anIt.Next()) {
3865 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
3870 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
3874 // check end of split line (end is almost always)
3875 Standard_Integer aneighbour = i + 1;
3876 Standard_Boolean bIsEndOfLine = Standard_True;
3878 if(aneighbour <= nblines) {
3879 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
3881 if((anArrayOfLineType.Value(aneighbour) != 0) &&
3882 (aListOfNeighbourIndex.IsEmpty())) {
3883 bIsEndOfLine = Standard_False;
3888 if(aLineOn2S->NbPoints() > 1) {
3889 Handle(IntPatch_WLine) aNewWLine =
3890 new IntPatch_WLine(aLineOn2S, Standard_False);
3891 theNewLines.Append(aNewWLine);
3893 aLineOn2S = new IntSurf_LineOn2S();
3898 // end if(!bIsFirstInside && !bIsLastInside)
3900 if(bIsFirstInside && bIsLastInside) {
3901 // append inside points between ifprm and ilprm
3902 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
3904 for(; anIt.More(); anIt.Next()) {
3905 if((anIt.Value() < ifprm) || (anIt.Value() > ilprm))
3907 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
3913 if(bIsFirstInside) {
3914 // append points from ifprm to last point + boundary point
3915 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
3917 for(; anIt.More(); anIt.Next()) {
3918 if(anIt.Value() < ifprm)
3920 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
3925 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
3928 // check end of split line (end is almost always)
3929 Standard_Integer aneighbour = i + 1;
3930 Standard_Boolean bIsEndOfLine = Standard_True;
3932 if(aneighbour <= nblines) {
3933 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
3935 if((anArrayOfLineType.Value(aneighbour) != 0) &&
3936 (aListOfNeighbourIndex.IsEmpty())) {
3937 bIsEndOfLine = Standard_False;
3942 if(aLineOn2S->NbPoints() > 1) {
3943 Handle(IntPatch_WLine) aNewWLine =
3944 new IntPatch_WLine(aLineOn2S, Standard_False);
3945 theNewLines.Append(aNewWLine);
3947 aLineOn2S = new IntSurf_LineOn2S();
3950 // end if(bIsFirstInside)
3953 // append points from first boundary point to ilprm
3954 if(bhasfirstpoint) {
3955 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
3958 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
3960 for(; anIt.More(); anIt.Next()) {
3961 if(anIt.Value() > ilprm)
3963 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
3967 //end if(bIsLastInside)
3971 if(aLineOn2S->NbPoints() > 1) {
3972 Handle(IntPatch_WLine) aNewWLine =
3973 new IntPatch_WLine(aLineOn2S, Standard_False);
3974 theNewLines.Append(aNewWLine);
3979 return Standard_True;
3982 // ------------------------------------------------------------------------------------------------
3983 // static function: ParameterOutOfBoundary
3984 // purpose: Computes a new parameter for given curve. The corresponding 2d points
3985 // does not lay on any boundary of given faces
3986 // ------------------------------------------------------------------------------------------------
3987 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
3988 const Handle(Geom_Curve)& theCurve,
3989 const TopoDS_Face& theFace1,
3990 const TopoDS_Face& theFace2,
3991 const Standard_Real theOtherParameter,
3992 const Standard_Boolean bIncreasePar,
3993 Standard_Real& theNewParameter) {
3994 Standard_Boolean bIsComputed = Standard_False;
3995 theNewParameter = theParameter;
3997 IntTools_Context aContext;
3998 Standard_Real acurpar = theParameter;
3999 TopAbs_State aState = TopAbs_ON;
4000 Standard_Integer iter = 0;
4001 Standard_Real asumtol = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4002 Standard_Real adelta = asumtol * 0.1;
4003 adelta = (adelta < Precision::Confusion()) ? Precision::Confusion() : adelta;
4004 Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(theFace1);
4005 Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(theFace2);
4007 Standard_Real u1, u2, v1, v2;
4009 GeomAPI_ProjectPointOnSurf aPrj1;
4010 aSurf1->Bounds(u1, u2, v1, v2);
4011 aPrj1.Init(aSurf1, u1, u2, v1, v2);
4013 GeomAPI_ProjectPointOnSurf aPrj2;
4014 aSurf2->Bounds(u1, u2, v1, v2);
4015 aPrj2.Init(aSurf2, u1, u2, v1, v2);
4017 while(aState == TopAbs_ON) {
4022 gp_Pnt aPCurrent = theCurve->Value(acurpar);
4023 aPrj1.Perform(aPCurrent);
4024 Standard_Real U=0., V=0.;
4026 if(aPrj1.IsDone()) {
4027 aPrj1.LowerDistanceParameters(U, V);
4028 aState = aContext.StatePointFace(theFace1, gp_Pnt2d(U, V));
4031 if(aState != TopAbs_ON) {
4032 aPrj2.Perform(aPCurrent);
4034 if(aPrj2.IsDone()) {
4035 aPrj2.LowerDistanceParameters(U, V);
4036 aState = aContext.StatePointFace(theFace2, gp_Pnt2d(U, V));
4047 theNewParameter = acurpar;
4048 bIsComputed = Standard_True;
4051 if(acurpar >= theOtherParameter)
4052 theNewParameter = theOtherParameter;
4055 if(acurpar <= theOtherParameter)
4056 theNewParameter = theOtherParameter;
4062 //=======================================================================
4063 //function : IsCurveValid
4065 //=======================================================================
4066 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve)
4068 if(thePCurve.IsNull())
4069 return Standard_False;
4071 Standard_Real tolint = 1.e-10;
4072 Geom2dAdaptor_Curve PCA;
4073 IntRes2d_Domain PCD;
4074 Geom2dInt_GInter PCI;
4076 Standard_Real pf = 0., pl = 0.;
4077 gp_Pnt2d pntf, pntl;
4079 if(!thePCurve->IsClosed() && !thePCurve->IsPeriodic()) {
4080 pf = thePCurve->FirstParameter();
4081 pl = thePCurve->LastParameter();
4082 pntf = thePCurve->Value(pf);
4083 pntl = thePCurve->Value(pl);
4084 PCA.Load(thePCurve);
4085 if(!PCA.IsPeriodic()) {
4086 if(PCA.FirstParameter() > pf) pf = PCA.FirstParameter();
4087 if(PCA.LastParameter() < pl) pl = PCA.LastParameter();
4089 PCD.SetValues(pntf,pf,tolint,pntl,pl,tolint);
4090 PCI.Perform(PCA,PCD,tolint,tolint);
4092 if(PCI.NbPoints() > 0) {
4093 return Standard_False;
4097 return Standard_True;
4100 //=======================================================================
4101 //static function : ApproxWithPCurves
4102 //purpose : for bug 20964 only
4103 //=======================================================================
4104 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
4105 const gp_Sphere& theSph)
4107 Standard_Boolean bRes = Standard_True;
4108 Standard_Real R1 = theCyl.Radius(), R2 = theSph.Radius();
4110 if(R1 < 2.*R2) return bRes;
4112 gp_Lin anCylAx(theCyl.Axis());
4114 Standard_Real aDist = anCylAx.Distance(theSph.Location());
4115 Standard_Real aDRel = Abs(aDist - R1)/R2;
4117 if(aDRel > .2) return bRes;
4119 Standard_Real par = ElCLib::Parameter(anCylAx, theSph.Location());
4120 gp_Pnt aP = ElCLib::Value(par, anCylAx);
4121 gp_Vec aV(aP, theSph.Location());
4123 Standard_Real dd = aV.Dot(theSph.Position().XDirection());
4125 if(aDist < R1 && dd > 0.) return Standard_False;
4126 if(aDist > R1 && dd < 0.) return Standard_False;
4131 //=======================================================================
4132 //function : PerformPlanes
4134 //=======================================================================
4135 void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
4136 const Handle(GeomAdaptor_HSurface)& theS2,
4137 const Standard_Real TolAng,
4138 const Standard_Real TolTang,
4139 const Standard_Boolean theApprox1,
4140 const Standard_Boolean theApprox2,
4141 IntTools_SequenceOfCurves& theSeqOfCurve,
4142 Standard_Boolean& theTangentFaces)
4145 gp_Pln aPln1 = theS1->Surface().Plane();
4146 gp_Pln aPln2 = theS2->Surface().Plane();
4148 IntAna_QuadQuadGeo aPlnInter(aPln1, aPln2, TolAng, TolTang);
4150 if(!aPlnInter.IsDone()) {
4151 theTangentFaces = Standard_False;
4155 IntAna_ResultType aResType = aPlnInter.TypeInter();
4157 if(aResType == IntAna_Same) {
4158 theTangentFaces = Standard_True;
4162 theTangentFaces = Standard_False;
4164 if(aResType == IntAna_Empty) {
4168 gp_Lin aLin = aPlnInter.Line(1);
4170 ProjLib_Plane aProj;
4173 aProj.Project(aLin);
4174 gp_Lin2d aLin2d1 = aProj.Line();
4177 aProj.Project(aLin);
4178 gp_Lin2d aLin2d2 = aProj.Line();
4180 //classify line2d1 relatively first plane
4181 Standard_Real P11, P12;
4182 Standard_Boolean IsCrossed = ClassifyLin2d(theS1, aLin2d1, TolTang, P11, P12);
4183 if(!IsCrossed) return;
4184 //classify line2d2 relatively second plane
4185 Standard_Real P21, P22;
4186 IsCrossed = ClassifyLin2d(theS2, aLin2d2, TolTang, P21, P22);
4187 if(!IsCrossed) return;
4189 //Analysis of parametric intervals: must have common part
4191 if(P21 >= P12) return;
4192 if(P22 <= P11) return;
4194 Standard_Real pmin, pmax;
4195 pmin = Max(P11, P21);
4196 pmax = Min(P12, P22);
4198 if(pmax - pmin <= TolTang) return;
4200 Handle(Geom_Line) aGLin = new Geom_Line(aLin);
4202 IntTools_Curve aCurve;
4203 Handle(Geom_TrimmedCurve) aGTLin = new Geom_TrimmedCurve(aGLin, pmin, pmax);
4205 aCurve.SetCurve(aGTLin);
4208 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d1);
4209 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4212 Handle(Geom2d_Curve) H1;
4213 aCurve.SetFirstCurve2d(H1);
4216 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d2);
4217 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4220 Handle(Geom2d_Curve) H1;
4221 aCurve.SetFirstCurve2d(H1);
4224 theSeqOfCurve.Append(aCurve);
4228 //=======================================================================
4229 //function : ClassifyLin2d
4231 //=======================================================================
4232 static inline Standard_Boolean INTER(const Standard_Real d1,
4233 const Standard_Real d2,
4234 const Standard_Real tol)
4236 return (d1 > tol && d2 < -tol) ||
4237 (d1 < -tol && d2 > tol) ||
4238 ((d1 <= tol && d1 >= -tol) && (d2 > tol || d2 < -tol)) ||
4239 ((d2 <= tol && d2 >= -tol) && (d1 > tol || d1 < -tol));
4241 static inline Standard_Boolean COINC(const Standard_Real d1,
4242 const Standard_Real d2,
4243 const Standard_Real tol)
4245 return (d1 <= tol && d1 >= -tol) && (d2 <= tol && d2 >= -tol);
4247 Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
4248 const gp_Lin2d& theLin2d,
4249 const Standard_Real theTol,
4250 Standard_Real& theP1,
4251 Standard_Real& theP2)
4254 Standard_Real xmin, xmax, ymin, ymax, d1, d2, A, B, C;
4255 Standard_Real par[2];
4256 Standard_Integer nbi = 0;
4258 xmin = theS->Surface().FirstUParameter();
4259 xmax = theS->Surface().LastUParameter();
4260 ymin = theS->Surface().FirstVParameter();
4261 ymax = theS->Surface().LastVParameter();
4263 theLin2d.Coefficients(A, B, C);
4265 //xmin, ymin <-> xmin, ymax
4266 d1 = A*xmin + B*ymin + C;
4267 d2 = A*xmin + B*ymax + C;
4269 if(INTER(d1, d2, theTol)) {
4270 //Intersection with boundary
4271 Standard_Real y = -(C + A*xmin)/B;
4272 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, y));
4275 else if (COINC(d1, d2, theTol)) {
4276 //Coincidence with boundary
4277 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4278 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4284 if(fabs(par[0]-par[1]) > theTol) {
4285 theP1 = Min(par[0], par[1]);
4286 theP2 = Max(par[0], par[1]);
4287 return Standard_True;
4289 else return Standard_False;
4293 //xmin, ymax <-> xmax, ymax
4295 d2 = A*xmax + B*ymax + C;
4297 if(d1 > theTol || d1 < -theTol) {//to avoid checking of
4298 //coincidence with the same point
4299 if(INTER(d1, d2, theTol)) {
4300 Standard_Real x = -(C + B*ymax)/A;
4301 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymax));
4304 else if (COINC(d1, d2, theTol)) {
4305 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4306 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4313 if(fabs(par[0]-par[1]) > theTol) {
4314 theP1 = Min(par[0], par[1]);
4315 theP2 = Max(par[0], par[1]);
4316 return Standard_True;
4318 else return Standard_False;
4322 //xmax, ymax <-> xmax, ymin
4324 d2 = A*xmax + B*ymin + C;
4326 if(d1 > theTol || d1 < -theTol) {
4327 if(INTER(d1, d2, theTol)) {
4328 Standard_Real y = -(C + A*xmax)/B;
4329 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, y));
4332 else if (COINC(d1, d2, theTol)) {
4333 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4334 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4340 if(fabs(par[0]-par[1]) > theTol) {
4341 theP1 = Min(par[0], par[1]);
4342 theP2 = Max(par[0], par[1]);
4343 return Standard_True;
4345 else return Standard_False;
4348 //xmax, ymin <-> xmin, ymin
4350 d2 = A*xmin + B*ymin + C;
4352 if(d1 > theTol || d1 < -theTol) {
4353 if(INTER(d1, d2, theTol)) {
4354 Standard_Real x = -(C + B*ymin)/A;
4355 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymin));
4358 else if (COINC(d1, d2, theTol)) {
4359 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4360 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4366 if(fabs(par[0]-par[1]) > theTol) {
4367 theP1 = Min(par[0], par[1]);
4368 theP2 = Max(par[0], par[1]);
4369 return Standard_True;
4371 else return Standard_False;
4374 return Standard_False;
4378 //=======================================================================
4379 //function : ApproxParameters
4381 //=======================================================================
4382 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
4383 const Handle(GeomAdaptor_HSurface)& aHS2,
4384 Standard_Integer& iDegMin,
4385 Standard_Integer& iDegMax)
4387 GeomAbs_SurfaceType aTS1, aTS2;
4393 aTS1=aHS1->Surface().GetType();
4394 aTS2=aHS2->Surface().GetType();
4397 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4398 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4399 Standard_Real aRC, aRT, dR, aPC;
4400 gp_Cylinder aCylinder;
4403 aPC=Precision::Confusion();
4405 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4406 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4408 aRC=aCylinder.Radius();
4409 aRT=aTorus.MinorRadius();
4420 //=======================================================================
4421 //function : Tolerances
4423 //=======================================================================
4424 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
4425 const Handle(GeomAdaptor_HSurface)& aHS2,
4426 Standard_Real& ,//aTolArc,
4427 Standard_Real& aTolTang,
4428 Standard_Real& ,//aUVMaxStep,
4429 Standard_Real& )//aDeflection)
4431 GeomAbs_SurfaceType aTS1, aTS2;
4433 aTS1=aHS1->Surface().GetType();
4434 aTS2=aHS2->Surface().GetType();
4437 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4438 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4439 Standard_Real aRC, aRT, dR, aPC;
4440 gp_Cylinder aCylinder;
4443 aPC=Precision::Confusion();
4445 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4446 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4448 aRC=aCylinder.Radius();
4449 aRT=aTorus.MinorRadius();
4456 aTolTang=0.1*aTolTang;
4460 //=======================================================================
4461 //function : SortTypes
4463 //=======================================================================
4464 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
4465 const GeomAbs_SurfaceType aType2)
4467 Standard_Boolean bRet;
4468 Standard_Integer aI1, aI2;
4470 bRet=Standard_False;
4472 aI1=IndexType(aType1);
4473 aI2=IndexType(aType2);
4479 //=======================================================================
4480 //function : IndexType
4482 //=======================================================================
4483 Standard_Integer IndexType(const GeomAbs_SurfaceType aType)
4485 Standard_Integer aIndex;
4489 if (aType==GeomAbs_Plane) {
4492 else if (aType==GeomAbs_Cylinder) {
4495 else if (aType==GeomAbs_Cone) {
4498 else if (aType==GeomAbs_Sphere) {
4501 else if (aType==GeomAbs_Torus) {
4504 else if (aType==GeomAbs_BezierSurface) {
4507 else if (aType==GeomAbs_BSplineSurface) {
4510 else if (aType==GeomAbs_SurfaceOfRevolution) {
4513 else if (aType==GeomAbs_SurfaceOfExtrusion) {
4516 else if (aType==GeomAbs_OffsetSurface) {
4519 else if (aType==GeomAbs_OtherSurface) {