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>
111 //modified by NIZNHY-PKV Mon Dec 26 13:37:52 2011f
113 void RefineVector(gp_Vec2d& aV2D);
114 //modified by NIZNHY-PKV Mon Dec 26 13:37:54 2011t
116 void DumpWLine(const Handle(IntPatch_WLine)& aWLine);
119 void TolR3d(const TopoDS_Face& ,
123 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)&,
124 const Standard_Integer,
125 const Standard_Integer);
128 void Parameters(const Handle(GeomAdaptor_HSurface)&,
129 const Handle(GeomAdaptor_HSurface)&,
137 void BuildPCurves (Standard_Real f,Standard_Real l,Standard_Real& Tol,
138 const Handle (Geom_Surface)& S,
139 const Handle (Geom_Curve)& C,
140 Handle (Geom2d_Curve)& C2d);
143 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
144 const Standard_Real theTolerance,
145 Standard_Real& theumin,
146 Standard_Real& theumax,
147 Standard_Real& thevmin,
148 Standard_Real& thevmax);
150 Standard_Boolean NotUseSurfacesForApprox
151 (const TopoDS_Face& aF1,
152 const TopoDS_Face& aF2,
153 const Handle(IntPatch_WLine)& WL,
154 const Standard_Integer ifprm,
155 const Standard_Integer ilprm);
158 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine);
161 Standard_Real AdjustPeriodic(const Standard_Real theParameter,
162 const Standard_Real parmin,
163 const Standard_Real parmax,
164 const Standard_Real thePeriod,
165 Standard_Real& theOffset);
168 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
169 const Standard_Integer ideb,
170 const Standard_Integer ifin,
171 const Standard_Boolean onFirst);
174 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
175 const Handle(GeomAdaptor_HSurface)& theSurface1,
176 const Handle(GeomAdaptor_HSurface)& theSurface2,
177 const TopoDS_Face& theFace1,
178 const TopoDS_Face& theFace2,
179 const IntTools_LineConstructor& theLConstructor,
180 const Standard_Boolean theAvoidLConstructor,
181 IntPatch_SequenceOfLine& theNewLines,
182 Standard_Real& theReachedTol3d);
185 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
186 const Handle(Geom_Curve)& theCurve,
187 const TopoDS_Face& theFace1,
188 const TopoDS_Face& theFace2,
189 const Standard_Real theOtherParameter,
190 const Standard_Boolean bIncreasePar,
191 Standard_Real& theNewParameter);
194 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve);
197 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
198 const Standard_Real theFirstBoundary,
199 const Standard_Real theSecondBoundary,
200 const Standard_Real theResolution,
201 Standard_Boolean& IsOnFirstBoundary);
203 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
204 const gp_Pnt2d& theLastPoint,
205 const Standard_Real theUmin,
206 const Standard_Real theUmax,
207 const Standard_Real theVmin,
208 const Standard_Real theVmax,
209 gp_Pnt2d& theNewPoint);
213 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
214 const Handle(GeomAdaptor_HSurface)& theSurface2,
215 const TopoDS_Face& theFace1,
216 const TopoDS_Face& theFace2,
217 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
218 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
219 Handle(TColStd_HArray1OfReal)& theResultRadius);
222 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
223 const gp_Pnt2d& theLastPoint,
224 const Standard_Real theUmin,
225 const Standard_Real theUmax,
226 const Standard_Real theVmin,
227 const Standard_Real theVmax,
228 const gp_Pnt2d& theTanZoneCenter,
229 const Standard_Real theZoneRadius,
230 Handle(GeomAdaptor_HSurface) theGASurface,
231 gp_Pnt2d& theNewPoint);
234 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
235 const gp_Pnt2d& theTanZoneCenter,
236 const Standard_Real theZoneRadius,
237 Handle(GeomAdaptor_HSurface) theGASurface);
240 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
241 const gp_Pnt2d& theOriginalPoint,
242 Handle(GeomAdaptor_HSurface) theGASurface);
244 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
245 const gp_Sphere& theSph);
247 static void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
248 const Handle(GeomAdaptor_HSurface)& theS2,
249 const Standard_Real TolAng,
250 const Standard_Real TolTang,
251 const Standard_Boolean theApprox1,
252 const Standard_Boolean theApprox2,
253 IntTools_SequenceOfCurves& theSeqOfCurve,
254 Standard_Boolean& theTangentFaces);
256 static Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
257 const gp_Lin2d& theLin2d,
258 const Standard_Real theTol,
259 Standard_Real& theP1,
260 Standard_Real& theP2);
263 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
264 const Handle(GeomAdaptor_HSurface)& aHS2,
265 Standard_Integer& iDegMin,
266 Standard_Integer& iDegMax);
269 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
270 const Handle(GeomAdaptor_HSurface)& aHS2,
271 Standard_Real& aTolArc,
272 Standard_Real& aTolTang,
273 Standard_Real& aUVMaxStep,
274 Standard_Real& aDeflection);
277 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
278 const GeomAbs_SurfaceType aType2);
280 Standard_Integer IndexType(const GeomAbs_SurfaceType aType);
283 //=======================================================================
286 //=======================================================================
287 IntTools_FaceFace::IntTools_FaceFace()
289 myTangentFaces=Standard_False;
291 myHS1 = new GeomAdaptor_HSurface ();
292 myHS2 = new GeomAdaptor_HSurface ();
295 SetParameters(Standard_True, Standard_True, Standard_True, 1.e-07);
297 //=======================================================================
300 //=======================================================================
301 const TopoDS_Face& IntTools_FaceFace::Face1() const
306 //=======================================================================
309 //=======================================================================
310 const TopoDS_Face& IntTools_FaceFace::Face2() const
315 //=======================================================================
316 //function : TangentFaces
318 //=======================================================================
319 Standard_Boolean IntTools_FaceFace::TangentFaces() const
321 return myTangentFaces;
323 //=======================================================================
326 //=======================================================================
327 const IntTools_SequenceOfPntOn2Faces& IntTools_FaceFace::Points() const
331 //=======================================================================
334 //=======================================================================
335 Standard_Boolean IntTools_FaceFace::IsDone() const
339 //=======================================================================
340 //function : TolReached3d
342 //=======================================================================
343 Standard_Real IntTools_FaceFace::TolReached3d() const
345 return myTolReached3d;
347 //=======================================================================
349 //purpose : return lines of intersection
350 //=======================================================================
351 const IntTools_SequenceOfCurves& IntTools_FaceFace::Lines() const
353 StdFail_NotDone_Raise_if(!myIsDone,
354 "IntTools_FaceFace::Lines() => !myIntersector.IsDone()");
358 //=======================================================================
359 //function : TolReached2d
361 //=======================================================================
362 Standard_Real IntTools_FaceFace::TolReached2d() const
364 return myTolReached2d;
366 // =======================================================================
367 // function: SetParameters
369 // =======================================================================
370 void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d,
371 const Standard_Boolean ToApproxC2dOnS1,
372 const Standard_Boolean ToApproxC2dOnS2,
373 const Standard_Real ApproximationTolerance)
375 myApprox = ToApproxC3d;
376 myApprox1 = ToApproxC2dOnS1;
377 myApprox2 = ToApproxC2dOnS2;
378 myTolApprox = ApproximationTolerance;
380 //=======================================================================
383 //=======================================================================
385 void IntTools_FaceFace::SetList(IntSurf_ListOfPntOn2S& aListOfPnts)
387 myListOfPnts = aListOfPnts;
390 //=======================================================================
392 //purpose : intersect surfaces of the faces
393 //=======================================================================
394 void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
395 const TopoDS_Face& aF2)
397 Standard_Boolean hasCone, RestrictLine, bTwoPlanes, bReverse;
398 Standard_Integer aNbLin, aNbPnts, i, NbLinPP;
399 Standard_Real TolArc, TolTang, Deflection, UVMaxStep;
400 Standard_Real umin, umax, vmin, vmax;
401 Standard_Real aTolF1, aTolF2;
402 GeomAbs_SurfaceType aType1, aType2;
403 Handle(Geom_Surface) S1, S2;
404 Handle(IntTools_TopolTool) dom1, dom2;
405 BRepAdaptor_Surface aBAS1, aBAS2;
407 mySeqOfCurve.Clear();
410 myIsDone = Standard_False;
412 hasCone = Standard_False;
413 bTwoPlanes = Standard_False;
418 aBAS1.Initialize(myFace1, Standard_False);
419 aBAS2.Initialize(myFace2, Standard_False);
420 aType1=aBAS1.GetType();
421 aType2=aBAS2.GetType();
423 bReverse=SortTypes(aType1, aType2);
427 aType1=aBAS2.GetType();
428 aType2=aBAS1.GetType();
430 if (myListOfPnts.Extent()) {
431 Standard_Real aU1,aV1,aU2,aV2;
432 IntSurf_ListIteratorOfListOfPntOn2S aItP2S;
434 aItP2S.Initialize(myListOfPnts);
435 for (; aItP2S.More(); aItP2S.Next()){
436 IntSurf_PntOn2S& aP2S=aItP2S.Value();
437 aP2S.Parameters(aU1,aV1,aU2,aV2);
438 aP2S.SetValue(aU2,aV2,aU1,aV1);
443 S1=BRep_Tool::Surface(myFace1);
444 S2=BRep_Tool::Surface(myFace2);
446 aTolF1=BRep_Tool::Tolerance(myFace1);
447 aTolF2=BRep_Tool::Tolerance(myFace2);
449 TolArc= aTolF1 + aTolF2;
453 if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
454 bTwoPlanes = Standard_True;
456 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
457 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
459 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
460 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
461 Standard_Real TolAng = 1.e-8;
462 PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2,
463 mySeqOfCurve, myTangentFaces);
465 myIsDone = Standard_True;
471 NbLinPP = mySeqOfCurve.Length();
476 Standard_Real aTolFMax;
478 myTolReached3d = 1.e-7;
480 aTolFMax=Max(aTolF1, aTolF2);
482 if (aTolFMax>myTolReached3d) {
483 myTolReached3d=aTolFMax;
485 myTolReached2d = myTolReached3d;
488 Handle(Geom2d_Curve) aC2D1, aC2D2;
490 aNbLin=mySeqOfCurve.Length();
491 for (i=1; i<=aNbLin; ++i) {
492 IntTools_Curve& aIC=mySeqOfCurve(i);
493 aC2D1=aIC.FirstCurve2d();
494 aC2D2=aIC.SecondCurve2d();
496 aIC.SetFirstCurve2d(aC2D2);
497 aIC.SetSecondCurve2d(aC2D1);
501 }//if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
503 if (aType1==GeomAbs_Plane &&
504 (aType2==GeomAbs_Cylinder ||
505 aType2==GeomAbs_Cone ||
506 aType2==GeomAbs_Torus)) {
507 Standard_Real dU, dV;
509 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
516 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
518 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
519 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
520 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
522 if( aType2==GeomAbs_Cone ) {
524 hasCone = Standard_True;
528 else if ((aType1==GeomAbs_Cylinder||
529 aType1==GeomAbs_Cone ||
530 aType1==GeomAbs_Torus) &&
531 aType2==GeomAbs_Plane) {
532 Standard_Real dU, dV;
534 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
535 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
536 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
538 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
545 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
547 if( aType1==GeomAbs_Cone ) {
549 hasCone = Standard_True;
555 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
557 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
559 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
561 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
563 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
565 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
568 dom1 = new IntTools_TopolTool(myHS1);
569 dom2 = new IntTools_TopolTool(myHS2);
571 myLConstruct.Load(dom1, dom2, myHS1, myHS2);
573 Deflection = (hasCone) ? 0.085 : 0.1;
576 Tolerances(myHS1, myHS2, TolArc, TolTang, UVMaxStep, Deflection);
578 myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection);
580 RestrictLine = Standard_False;
582 if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) ||
583 (myHS1->IsVClosed() && !myHS1->IsVPeriodic()) ||
584 (myHS2->IsUClosed() && !myHS2->IsUPeriodic()) ||
585 (myHS2->IsVClosed() && !myHS2->IsVPeriodic())) {
586 RestrictLine = Standard_True;
589 if(((aType1 != GeomAbs_BSplineSurface) &&
590 (aType1 != GeomAbs_BezierSurface) &&
591 (aType1 != GeomAbs_OtherSurface)) &&
592 ((aType2 != GeomAbs_BSplineSurface) &&
593 (aType2 != GeomAbs_BezierSurface) &&
594 (aType2 != GeomAbs_OtherSurface))) {
595 RestrictLine = Standard_True;
597 if ((aType1 == GeomAbs_Torus) ||
598 (aType2 == GeomAbs_Torus) ) {
599 myListOfPnts.Clear();
604 TopExp_Explorer aExp;
606 for(i = 0; (!RestrictLine) && (i < 2); i++) {
607 const TopoDS_Face& aF=(!i) ? myFace1 : myFace2;
608 aExp.Init(aF, TopAbs_EDGE);
609 for(; aExp.More(); aExp.Next()) {
610 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
612 if(BRep_Tool::Degenerated(aE)) {
613 RestrictLine = Standard_True;
620 myIntersector.Perform(myHS1, dom1, myHS2, dom2,
622 myListOfPnts, RestrictLine);
624 myIsDone = myIntersector.IsDone();
626 myTangentFaces=myIntersector.TangentFaces();
627 if (myTangentFaces) {
632 myListOfPnts.Clear(); // to use LineConstructor
635 aNbLin = myIntersector.NbLines();
636 for (i=1; i<=aNbLin; ++i) {
637 MakeCurve(i, dom1, dom2);
640 ComputeTolReached3d();
643 Handle(Geom2d_Curve) aC2D1, aC2D2;
645 aNbLin=mySeqOfCurve.Length();
646 for (i=1; i<=aNbLin; ++i) {
647 IntTools_Curve& aIC=mySeqOfCurve(i);
648 aC2D1=aIC.FirstCurve2d();
649 aC2D2=aIC.SecondCurve2d();
651 aIC.SetFirstCurve2d(aC2D2);
652 aIC.SetSecondCurve2d(aC2D1);
657 Standard_Real U1,V1,U2,V2;
658 IntTools_PntOnFace aPntOnF1, aPntOnF2;
659 IntTools_PntOn2Faces aPntOn2Faces;
661 aNbPnts=myIntersector.NbPnts();
662 for (i=1; i<=aNbPnts; ++i) {
663 const IntSurf_PntOn2S& aISPnt=myIntersector.Point(i).PntOn2S();
664 const gp_Pnt& aPnt=aISPnt.Value();
665 aISPnt.Parameters(U1,V1,U2,V2);
666 aPntOnF1.Init(myFace1, aPnt, U1, V1);
667 aPntOnF2.Init(myFace2, aPnt, U2, V2);
670 aPntOn2Faces.SetP1(aPntOnF1);
671 aPntOn2Faces.SetP2(aPntOnF2);
674 aPntOn2Faces.SetP2(aPntOnF1);
675 aPntOn2Faces.SetP1(aPntOnF2);
677 myPnts.Append(aPntOn2Faces);
682 //=======================================================================
683 //function :ComputeTolReached3d
685 //=======================================================================
686 void IntTools_FaceFace::ComputeTolReached3d()
688 Standard_Integer aNbLin;
689 GeomAbs_SurfaceType aType1, aType2;
691 aNbLin=myIntersector.NbLines();
693 aType1=myHS1->Surface().GetType();
694 aType2=myHS2->Surface().GetType();
697 aType1==GeomAbs_Cylinder &&
698 aType2==GeomAbs_Cylinder) {
699 Handle(IntPatch_Line) aIL1, aIL2;
700 IntPatch_IType aTL1, aTL2;
702 aIL1=myIntersector.Line(1);
703 aIL2=myIntersector.Line(2);
704 aTL1=aIL1->ArcType();
705 aTL2=aIL2->ArcType();
706 if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) {
707 Standard_Real aD, aDTresh, dTol;
713 aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line();
714 aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line();
715 aD=aL1.Distance(aL2);
718 myTolReached3d=aD+dTol;
723 if (aType1==GeomAbs_Plane &&
724 aType2==GeomAbs_Plane) {
725 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
729 aTolF1 = BRep_Tool::Tolerance(myFace1);
730 aTolF2 = BRep_Tool::Tolerance(myFace2);
731 aTolFMax=Max(aTolF1, aTolF2);
733 if (aTolFMax>aTolTresh) {
734 myTolReached3d=aTolFMax;
739 if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ||
740 (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) {
742 const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1);
743 if(aIL1->ArcType() == IntPatch_Circle) {
744 gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle();
745 gp_XYZ aCirDir = aCir.Axis().Direction().XYZ();
748 if(aType1 == GeomAbs_Plane) {
749 aPln = myHS1->Surface().Plane();
752 aPln = myHS2->Surface().Plane();
754 aPlDir = aPln.Axis().Direction().XYZ();
755 Standard_Real cs = aCirDir*aPlDir;
756 if(cs < 0.) aPlDir.Reverse();
757 Standard_Real eps = 1.e-14;
758 if(!aPlDir.IsEqual(aCirDir, eps)) {
759 Standard_Integer aNbP = 11;
760 Standard_Real dt = 2.*M_PI / (aNbP - 1), t;
761 for(t = 0.; t < 2.*M_PI; t += dt) {
762 Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir));
763 if(myTolReached3d < d) myTolReached3d = d;
765 myTolReached3d *= 1.1;
767 } //aIL1->ArcType() == IntPatch_Circle
769 } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ...
770 //End IFV Bug OCC20297
772 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
773 (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) {
774 aNbLin=mySeqOfCurve.Length();
779 Standard_Integer i, aNbP;
780 Standard_Real aT, aT1, aT2, dT, aUT, aVT, aUP, aVP;
781 Standard_Real aDP, aDT, aDmax;
786 const IntTools_Curve& aIC=mySeqOfCurve(1);
787 const Handle(Geom_Curve)& aC3D=aIC.Curve();
788 const Handle(Geom_BSplineCurve)& aBS=Handle(Geom_BSplineCurve)::DownCast(aC3D);
793 aT1=aBS->FirstParameter();
794 aT2=aBS->LastParameter();
796 aPln =(aType1==GeomAbs_Plane) ? myHS1->Plane() : myHS2->Plane();
797 aTorus=(aType1==GeomAbs_Plane) ? myHS2->Torus() : myHS1->Torus();
801 dT=(aT2-aT1)/(aNbP-1);
802 for (i=0; i<aNbP; ++i) {
810 ElSLib::Parameters(aPln, aP, aUP, aVP);
811 aPP=ElSLib::Value(aUP, aVP, aPln);
812 aDP=aP.SquareDistance(aPP);
817 ElSLib::Parameters(aTorus, aP, aUT, aVT);
818 aPT=ElSLib::Value(aUT, aVT, aTorus);
819 aDT=aP.SquareDistance(aPT);
825 if (aDmax > myTolReached3d*myTolReached3d) {
826 myTolReached3d=sqrt(aDmax);
827 myTolReached3d=1.1*myTolReached3d;
829 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
831 if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) ||
832 (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder)) {
833 Standard_Boolean bIsDone;
834 Standard_Integer i, j, aNbP;
835 Standard_Real aT, aT1, aT2, dT, aU1, aV1, aU2, aV2;
836 Standard_Real aDSmax, aDS1, aDS2, aDS;
837 gp_Pnt2d aP2D1, aP2D2;
838 gp_Pnt aP3D, aP3D1, aP3D2;
839 IntTools_Context aCtx;
841 aNbLin=mySeqOfCurve.Length();
845 for (i=1; i<=aNbLin; ++i) {
846 const IntTools_Curve& aIC=mySeqOfCurve(i);
847 const Handle(Geom_Curve)& aC3D=aIC.Curve();
848 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
849 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
854 const Handle(Geom_BSplineCurve)& aBC=Handle(Geom_BSplineCurve)::DownCast(aC3D);
859 aT1=aBC->FirstParameter();
860 aT2=aBC->LastParameter();
862 dT=(aT2-aT1)/(aNbP-1);
863 for (j=0; j<aNbP; ++j) {
871 if (!aC2D1.IsNull()) {
872 aC2D1->D0(aT, aP2D1);
873 aP2D1.Coord(aU1, aV1);
874 myHS1->D0(aU1, aV1, aP3D1);
875 aDS1=aP3D.SquareDistance(aP3D1);
881 if (!aC2D2.IsNull()) {
882 aC2D2->D0(aT, aP2D2);
883 aP2D2.Coord(aU2, aV2);
884 myHS2->D0(aU2, aV2, aP3D2);
885 aDS2=aP3D.SquareDistance(aP3D2);
891 GeomAPI_ProjectPointOnSurf& aPPS1=aCtx.ProjPS(myFace1);
893 bIsDone=aPPS1.IsDone();
895 aPPS1.LowerDistanceParameters(aU1, aV1);
896 myHS1->D0(aU1, aV1, aP3D1);
897 aDS1=aP3D.SquareDistance(aP3D1);
903 GeomAPI_ProjectPointOnSurf& aPPS2=aCtx.ProjPS(myFace2);
905 bIsDone=aPPS2.IsDone();
907 aPPS2.LowerDistanceParameters(aU2, aV2);
908 myHS2->D0(aU2, aV2, aP3D2);
909 aDS2=aP3D.SquareDistance(aP3D2);
914 }//for (j=0; j<aNbP; ++j) {
915 }//for (i=1; i<=aNbLin; ++i) {
917 aDS=myTolReached3d*myTolReached3d;
919 myTolReached3d=sqrt(aDSmax);
921 }//if((aType1==GeomAbs_SurfaceOfRevolution ...
923 //=======================================================================
924 //function : MakeCurve
926 //=======================================================================
927 void IntTools_FaceFace::MakeCurve(const Standard_Integer Index,
928 const Handle(Adaptor3d_TopolTool)& dom1,
929 const Handle(Adaptor3d_TopolTool)& dom2)
931 Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor;
933 Standard_Integer i, j, aNbParts;
934 Standard_Real fprm, lprm;
936 Handle(IntPatch_Line) L;
938 Handle(Geom_Curve) newc;
940 const Standard_Real TOLCHECK =0.0000001;
941 const Standard_Real TOLANGCHECK=0.1;
943 rejectSurface = Standard_False;
944 reApprox = Standard_False;
949 bAvoidLineConstructor = Standard_False;
950 L = myIntersector.Line(Index);
953 if(typl==IntPatch_Walking) {
954 Handle(IntPatch_Line) anewL;
956 const Handle(IntPatch_WLine)& aWLine=
957 Handle(IntPatch_WLine)::DownCast(L);
959 anewL = ComputePurgedWLine(aWLine);
965 if(!myListOfPnts.IsEmpty()) {
966 bAvoidLineConstructor = Standard_True;
969 Standard_Integer nbp = aWLine->NbPnts();
970 const IntSurf_PntOn2S& p1 = aWLine->Point(1);
971 const IntSurf_PntOn2S& p2 = aWLine->Point(nbp);
973 const gp_Pnt& P1 = p1.Value();
974 const gp_Pnt& P2 = p2.Value();
976 if(P1.SquareDistance(P2) < 1.e-14) {
977 bAvoidLineConstructor = Standard_False;
983 if(!bAvoidLineConstructor) {
984 myLConstruct.Perform(L);
986 bDone=myLConstruct.IsDone();
987 aNbParts=myLConstruct.NbParts();
988 if (!bDone|| !aNbParts) {
997 //########################################
998 // Line, Parabola, Hyperbola
999 //########################################
1001 case IntPatch_Parabola:
1002 case IntPatch_Hyperbola: {
1003 if (typl == IntPatch_Lin) {
1005 new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
1008 else if (typl == IntPatch_Parabola) {
1010 new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
1013 else if (typl == IntPatch_Hyperbola) {
1015 new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
1019 if (typl == IntPatch_Lin) {
1020 TolR3d (myFace1, myFace2, myTolReached3d);
1023 aNbParts=myLConstruct.NbParts();
1024 for (i=1; i<=aNbParts; i++) {
1025 myLConstruct.Part(i, fprm, lprm);
1027 if (!Precision::IsNegativeInfinite(fprm) &&
1028 !Precision::IsPositiveInfinite(lprm)) {
1030 IntTools_Curve aCurve;
1032 Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
1033 aCurve.SetCurve(aCT3D);
1034 if (typl == IntPatch_Parabola) {
1035 Standard_Real aTolF1, aTolF2, aTolBase;
1037 aTolF1 = BRep_Tool::Tolerance(myFace1);
1038 aTolF2 = BRep_Tool::Tolerance(myFace2);
1039 aTolBase=aTolF1+aTolF2;
1040 myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
1043 aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
1045 Handle (Geom2d_Curve) C2d;
1046 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1047 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1048 myTolReached2d=Tolpc;
1051 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1054 Handle(Geom2d_BSplineCurve) H1;
1056 aCurve.SetFirstCurve2d(H1);
1060 Handle (Geom2d_Curve) C2d;
1061 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1062 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1063 myTolReached2d=Tolpc;
1066 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1069 Handle(Geom2d_BSplineCurve) H1;
1071 aCurve.SetSecondCurve2d(H1);
1073 mySeqOfCurve.Append(aCurve);
1074 } // end of if (!Precision::IsNegativeInfinite(fprm) && !Precision::IsPositiveInfinite(lprm))
1077 // on regarde si on garde
1079 Standard_Boolean bFNIt, bLPIt;
1080 Standard_Real aTestPrm, dT=100.;
1082 bFNIt=Precision::IsNegativeInfinite(fprm);
1083 bLPIt=Precision::IsPositiveInfinite(lprm);
1087 if (bFNIt && !bLPIt) {
1090 else if (!bFNIt && bLPIt) {
1094 gp_Pnt ptref(newc->Value(aTestPrm));
1097 Standard_Real u1, v1, u2, v2, Tol;
1099 Tol = Precision::Confusion();
1100 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1101 ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
1103 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1106 Handle(Geom2d_BSplineCurve) H1;
1107 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1110 }// end of for (i=1; i<=myLConstruct.NbParts(); i++)
1111 }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola:
1114 //########################################
1115 // Circle and Ellipse
1116 //########################################
1117 case IntPatch_Circle:
1118 case IntPatch_Ellipse: {
1120 if (typl == IntPatch_Circle) {
1121 newc = new Geom_Circle
1122 (Handle(IntPatch_GLine)::DownCast(L)->Circle());
1124 else { //IntPatch_Ellipse
1125 newc = new Geom_Ellipse
1126 (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
1130 TolR3d (myFace1, myFace2, myTolReached3d);
1132 aNbParts=myLConstruct.NbParts();
1134 Standard_Real aPeriod, aNul;
1135 TColStd_SequenceOfReal aSeqFprm, aSeqLprm;
1140 for (i=1; i<=aNbParts; i++) {
1141 myLConstruct.Part(i, fprm, lprm);
1143 if (fprm < aNul && lprm > aNul) {
1144 // interval that goes through 0. is divided on two intervals;
1145 while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
1146 while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
1148 if((aPeriod - fprm) > Tolpc) {
1149 aSeqFprm.Append(fprm);
1150 aSeqLprm.Append(aPeriod);
1153 gp_Pnt P1 = newc->Value(fprm);
1154 gp_Pnt P2 = newc->Value(aPeriod);
1155 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1156 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1158 if(P1.Distance(P2) > aTolDist) {
1159 Standard_Real anewpar = fprm;
1161 if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2, lprm, Standard_False, anewpar)) {
1164 aSeqFprm.Append(fprm);
1165 aSeqLprm.Append(aPeriod);
1170 if((lprm - aNul) > Tolpc) {
1171 aSeqFprm.Append(aNul);
1172 aSeqLprm.Append(lprm);
1175 gp_Pnt P1 = newc->Value(aNul);
1176 gp_Pnt P2 = newc->Value(lprm);
1177 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1178 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1180 if(P1.Distance(P2) > aTolDist) {
1181 Standard_Real anewpar = lprm;
1183 if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2, fprm, Standard_True, anewpar)) {
1186 aSeqFprm.Append(aNul);
1187 aSeqLprm.Append(lprm);
1193 aSeqFprm.Append(fprm);
1194 aSeqLprm.Append(lprm);
1199 aNbParts=aSeqFprm.Length();
1200 for (i=1; i<=aNbParts; i++) {
1204 Standard_Real aRealEpsilon=RealEpsilon();
1205 if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*M_PI) > aRealEpsilon) {
1206 //==============================================
1208 IntTools_Curve aCurve;
1209 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1210 aCurve.SetCurve(aTC3D);
1211 fprm=aTC3D->FirstParameter();
1212 lprm=aTC3D->LastParameter ();
1214 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {////
1216 Handle (Geom2d_Curve) C2d;
1217 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1218 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1219 myTolReached2d=Tolpc;
1222 aCurve.SetFirstCurve2d(C2d);
1225 Handle(Geom2d_BSplineCurve) H1;
1226 aCurve.SetFirstCurve2d(H1);
1231 Handle (Geom2d_Curve) C2d;
1232 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1233 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1234 myTolReached2d=Tolpc;
1237 aCurve.SetSecondCurve2d(C2d);
1240 Handle(Geom2d_BSplineCurve) H1;
1241 aCurve.SetSecondCurve2d(H1);
1246 Handle(Geom2d_BSplineCurve) H1;
1247 aCurve.SetFirstCurve2d(H1);
1248 aCurve.SetSecondCurve2d(H1);
1250 mySeqOfCurve.Append(aCurve);
1251 //==============================================
1252 } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon())
1255 // on regarde si on garde
1258 // if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) {
1259 if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
1260 IntTools_Curve aCurve;
1261 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1262 aCurve.SetCurve(aTC3D);
1263 fprm=aTC3D->FirstParameter();
1264 lprm=aTC3D->LastParameter ();
1267 Handle (Geom2d_Curve) C2d;
1268 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1269 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1270 myTolReached2d=Tolpc;
1273 aCurve.SetFirstCurve2d(C2d);
1276 Handle(Geom2d_BSplineCurve) H1;
1277 aCurve.SetFirstCurve2d(H1);
1281 Handle (Geom2d_Curve) C2d;
1282 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1283 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1284 myTolReached2d=Tolpc;
1287 aCurve.SetSecondCurve2d(C2d);
1290 Handle(Geom2d_BSplineCurve) H1;
1291 aCurve.SetSecondCurve2d(H1);
1293 mySeqOfCurve.Append(aCurve);
1298 Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
1300 aTwoPIdiv17=2.*M_PI/17.;
1302 for (j=0; j<=17; j++) {
1303 gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
1304 Tol = Precision::Confusion();
1306 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1307 ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
1309 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1312 IntTools_Curve aCurve;
1313 aCurve.SetCurve(newc);
1314 //==============================================
1315 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
1318 Handle (Geom2d_Curve) C2d;
1319 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1320 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1321 myTolReached2d=Tolpc;
1324 aCurve.SetFirstCurve2d(C2d);
1327 Handle(Geom2d_BSplineCurve) H1;
1328 aCurve.SetFirstCurve2d(H1);
1332 Handle (Geom2d_Curve) C2d;
1333 BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
1334 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1335 myTolReached2d=Tolpc;
1338 aCurve.SetSecondCurve2d(C2d);
1342 Handle(Geom2d_BSplineCurve) H1;
1343 aCurve.SetSecondCurve2d(H1);
1345 }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
1348 Handle(Geom2d_BSplineCurve) H1;
1350 aCurve.SetFirstCurve2d(H1);
1351 aCurve.SetSecondCurve2d(H1);
1353 //==============================================
1355 mySeqOfCurve.Append(aCurve);
1358 }// end of if (ok) {
1359 }// end of for (Standard_Integer j=0; j<=17; j++)
1360 }// end of else { on regarde si on garde
1361 }// for (i=1; i<=myLConstruct.NbParts(); i++)
1362 }// IntPatch_Circle: IntPatch_Ellipse:
1365 case IntPatch_Analytic: {
1366 IntSurf_Quadric quad1,quad2;
1367 GeomAbs_SurfaceType typs = myHS1->Surface().GetType();
1371 quad1.SetValue(myHS1->Surface().Plane());
1373 case GeomAbs_Cylinder:
1374 quad1.SetValue(myHS1->Surface().Cylinder());
1377 quad1.SetValue(myHS1->Surface().Cone());
1379 case GeomAbs_Sphere:
1380 quad1.SetValue(myHS1->Surface().Sphere());
1383 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
1386 typs = myHS2->Surface().GetType();
1390 quad2.SetValue(myHS2->Surface().Plane());
1392 case GeomAbs_Cylinder:
1393 quad2.SetValue(myHS2->Surface().Cylinder());
1396 quad2.SetValue(myHS2->Surface().Cone());
1398 case GeomAbs_Sphere:
1399 quad2.SetValue(myHS2->Surface().Sphere());
1402 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
1406 IntPatch_ALineToWLine convert (quad1, quad2);
1409 aNbParts=myLConstruct.NbParts();
1410 for (i=1; i<=aNbParts; i++) {
1411 myLConstruct.Part(i, fprm, lprm);
1412 Handle(IntPatch_WLine) WL =
1413 convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
1415 Handle(Geom2d_BSplineCurve) H1;
1416 Handle(Geom2d_BSplineCurve) H2;
1419 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1423 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1426 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1430 else { // myApprox=TRUE
1431 GeomInt_WLApprox theapp3d;
1433 Standard_Real tol2d = myTolApprox;
1435 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
1437 aNbParts=myLConstruct.NbParts();
1438 for (i=1; i<=aNbParts; i++) {
1439 myLConstruct.Part(i, fprm, lprm);
1440 Handle(IntPatch_WLine) WL =
1441 convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
1443 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
1445 if (!theapp3d.IsDone()) {
1447 Handle(Geom2d_BSplineCurve) H1;
1448 Handle(Geom2d_BSplineCurve) H2;
1451 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1455 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1458 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1462 if(myApprox1 || myApprox2) {
1463 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
1464 myTolReached2d = theapp3d.TolReached2d();
1468 if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
1469 myTolReached3d = theapp3d.TolReached3d();
1472 Standard_Integer aNbMultiCurves, nbpoles;
1473 aNbMultiCurves=theapp3d.NbMultiCurves();
1474 for (j=1; j<=aNbMultiCurves; j++) {
1475 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1476 nbpoles = mbspc.NbPoles();
1478 TColgp_Array1OfPnt tpoles(1, nbpoles);
1479 mbspc.Curve(1, tpoles);
1480 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1482 mbspc.Multiplicities(),
1485 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1486 Check.FixTangent(Standard_True,Standard_True);
1488 IntTools_Curve aCurve;
1489 aCurve.SetCurve(BS);
1492 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1493 mbspc.Curve(2,tpoles2d);
1494 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1496 mbspc.Multiplicities(),
1499 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1500 newCheck.FixTangent(Standard_True,Standard_True);
1502 aCurve.SetFirstCurve2d(BS2);
1505 Handle(Geom2d_BSplineCurve) H1;
1506 aCurve.SetFirstCurve2d(H1);
1510 TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
1511 Standard_Integer TwoOrThree;
1512 TwoOrThree=myApprox1 ? 3 : 2;
1513 mbspc.Curve(TwoOrThree, tpoles2d);
1514 Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
1516 mbspc.Multiplicities(),
1519 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1520 newCheck.FixTangent(Standard_True,Standard_True);
1522 aCurve.SetSecondCurve2d(BS2);
1525 Handle(Geom2d_BSplineCurve) H2;
1526 aCurve.SetSecondCurve2d(H2);
1529 mySeqOfCurve.Append(aCurve);
1531 }// for (j=1; j<=aNbMultiCurves; j++) {
1532 }// else from if (!theapp3d.IsDone())
1533 }// for (i=1; i<=aNbParts; i++) {
1534 }// else { // myApprox=TRUE
1535 }// case IntPatch_Analytic:
1538 case IntPatch_Walking:{
1539 Handle(IntPatch_WLine) WL =
1540 Handle(IntPatch_WLine)::DownCast(L);
1542 Standard_Integer ifprm, ilprm;
1546 if(!bAvoidLineConstructor){
1547 aNbParts=myLConstruct.NbParts();
1549 for (i=1; i<=aNbParts; ++i) {
1550 Handle(Geom2d_BSplineCurve) H1, H2;
1551 Handle(Geom_Curve) aBSp;
1553 if(bAvoidLineConstructor) {
1555 ilprm = WL->NbPnts();
1558 myLConstruct.Part(i, fprm, lprm);
1559 ifprm=(Standard_Integer)fprm;
1560 ilprm=(Standard_Integer)lprm;
1564 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1568 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1571 aBSp=MakeBSpline(WL, ifprm, ilprm);
1572 IntTools_Curve aIC(aBSp, H1, H2);
1573 mySeqOfCurve.Append(aIC);
1574 }// for (i=1; i<=aNbParts; ++i) {
1575 }// if (!myApprox) {
1578 Standard_Boolean bIsDecomposited;
1579 Standard_Integer nbiter, aNbSeqOfL;
1580 Standard_Real tol2d;
1581 IntPatch_SequenceOfLine aSeqOfL;
1582 GeomInt_WLApprox theapp3d;
1583 Approx_ParametrizationType aParType = Approx_ChordLength;
1585 Standard_Boolean anApprox1 = myApprox1;
1586 Standard_Boolean anApprox2 = myApprox2;
1588 tol2d = myTolApprox;
1590 GeomAbs_SurfaceType typs1, typs2;
1591 typs1 = myHS1->Surface().GetType();
1592 typs2 = myHS2->Surface().GetType();
1593 Standard_Boolean anWithPC = Standard_True;
1595 if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
1597 ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
1599 else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
1601 ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
1604 //aParType = Approx_Centripetal;
1605 myTolApprox = 1.e-5;
1606 anApprox1 = Standard_False;
1607 anApprox2 = Standard_False;
1609 tol2d = myTolApprox;
1612 if(myHS1 == myHS2) {
1614 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1615 rejectSurface = Standard_True;
1618 if(reApprox && !rejectSurface)
1619 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1621 Standard_Integer iDegMax, iDegMin;
1623 ApproxParameters(myHS1, myHS2, iDegMin, iDegMax);
1624 theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, 0, Standard_True, aParType);
1628 Standard_Real aReachedTol = Precision::Confusion();
1629 bIsDecomposited=DecompositionOfWLine(WL,
1635 bAvoidLineConstructor,
1638 if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) )
1639 myTolReached3d = aReachedTol;
1642 aNbSeqOfL=aSeqOfL.Length();
1644 if (bIsDecomposited) {
1650 if (!bAvoidLineConstructor) {
1651 aNbParts=myLConstruct.NbParts();
1656 // nbiter=(bIsDecomposited) ? aSeqOfL.Length() :
1657 // ((bAvoidLineConstructor) ? 1 :aNbParts);
1659 for(i = 1; i <= nbiter; ++i) {
1660 if(bIsDecomposited) {
1661 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
1663 ilprm = WL->NbPnts();
1666 if(bAvoidLineConstructor) {
1668 ilprm = WL->NbPnts();
1671 myLConstruct.Part(i, fprm, lprm);
1672 ifprm = (Standard_Integer)fprm;
1673 ilprm = (Standard_Integer)lprm;
1677 //-- Si une des surfaces est un plan , on approxime en 2d
1678 //-- sur cette surface et on remonte les points 2d en 3d.
1679 if(typs1 == GeomAbs_Plane) {
1680 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
1682 else if(typs2 == GeomAbs_Plane) {
1683 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
1687 if (myHS1 != myHS2){
1688 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
1689 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
1691 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
1693 Standard_Boolean bUseSurfaces;
1694 bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
1697 rejectSurface = Standard_True;
1699 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1704 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
1707 if (!theapp3d.IsDone()) {
1709 Handle(Geom2d_BSplineCurve) H1;
1711 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
1712 Handle(Geom2d_BSplineCurve) H2;
1715 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1719 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1722 IntTools_Curve aIC(aBSp, H1, H2);
1723 mySeqOfCurve.Append(aIC);
1727 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
1728 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
1729 myTolReached2d = theapp3d.TolReached2d();
1732 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
1733 myTolReached3d = myTolReached2d;
1735 if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
1736 if (myTolReached3d<1.e-6) {
1737 myTolReached3d = theapp3d.TolReached3d();
1738 myTolReached3d=1.e-6;
1743 else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
1744 myTolReached3d = theapp3d.TolReached3d();
1747 Standard_Integer aNbMultiCurves, nbpoles;
1748 aNbMultiCurves=theapp3d.NbMultiCurves();
1749 for (j=1; j<=aNbMultiCurves; j++) {
1750 if(typs1 == GeomAbs_Plane) {
1751 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1752 nbpoles = mbspc.NbPoles();
1754 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1755 TColgp_Array1OfPnt tpoles(1,nbpoles);
1757 mbspc.Curve(1,tpoles2d);
1758 const gp_Pln& Pln = myHS1->Surface().Plane();
1760 Standard_Integer ik;
1761 for(ik = 1; ik<= nbpoles; ik++) {
1763 ElSLib::Value(tpoles2d.Value(ik).X(),
1764 tpoles2d.Value(ik).Y(),
1768 Handle(Geom_BSplineCurve) BS =
1769 new Geom_BSplineCurve(tpoles,
1771 mbspc.Multiplicities(),
1773 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1774 Check.FixTangent(Standard_True, Standard_True);
1776 IntTools_Curve aCurve;
1777 aCurve.SetCurve(BS);
1780 Handle(Geom2d_BSplineCurve) BS1 =
1781 new Geom2d_BSplineCurve(tpoles2d,
1783 mbspc.Multiplicities(),
1785 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
1786 Check1.FixTangent(Standard_True,Standard_True);
1788 // ############################################
1789 if(!rejectSurface && !reApprox) {
1790 Standard_Boolean isValid = IsCurveValid(BS1);
1792 reApprox = Standard_True;
1796 // ############################################
1797 aCurve.SetFirstCurve2d(BS1);
1800 Handle(Geom2d_BSplineCurve) H1;
1801 aCurve.SetFirstCurve2d(H1);
1805 mbspc.Curve(2, tpoles2d);
1807 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
1809 mbspc.Multiplicities(),
1811 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1812 newCheck.FixTangent(Standard_True,Standard_True);
1814 // ###########################################
1815 if(!rejectSurface && !reApprox) {
1816 Standard_Boolean isValid = IsCurveValid(BS2);
1818 reApprox = Standard_True;
1822 // ###########################################
1824 aCurve.SetSecondCurve2d(BS2);
1827 Handle(Geom2d_BSplineCurve) H2;
1829 aCurve.SetSecondCurve2d(H2);
1832 mySeqOfCurve.Append(aCurve);
1835 else if(typs2 == GeomAbs_Plane) {
1836 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1837 nbpoles = mbspc.NbPoles();
1839 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1840 TColgp_Array1OfPnt tpoles(1,nbpoles);
1841 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
1842 const gp_Pln& Pln = myHS2->Surface().Plane();
1844 Standard_Integer ik;
1845 for(ik = 1; ik<= nbpoles; ik++) {
1847 ElSLib::Value(tpoles2d.Value(ik).X(),
1848 tpoles2d.Value(ik).Y(),
1853 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1855 mbspc.Multiplicities(),
1857 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1858 Check.FixTangent(Standard_True,Standard_True);
1860 IntTools_Curve aCurve;
1861 aCurve.SetCurve(BS);
1864 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
1866 mbspc.Multiplicities(),
1868 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
1869 Check1.FixTangent(Standard_True,Standard_True);
1871 // ###########################################
1872 if(!rejectSurface && !reApprox) {
1873 Standard_Boolean isValid = IsCurveValid(BS1);
1875 reApprox = Standard_True;
1879 // ###########################################
1880 aCurve.SetSecondCurve2d(BS1);
1883 Handle(Geom2d_BSplineCurve) H2;
1884 aCurve.SetSecondCurve2d(H2);
1888 mbspc.Curve(1,tpoles2d);
1889 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1891 mbspc.Multiplicities(),
1893 GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
1894 Check2.FixTangent(Standard_True,Standard_True);
1896 // ###########################################
1897 if(!rejectSurface && !reApprox) {
1898 Standard_Boolean isValid = IsCurveValid(BS2);
1900 reApprox = Standard_True;
1904 // ###########################################
1905 aCurve.SetFirstCurve2d(BS2);
1908 Handle(Geom2d_BSplineCurve) H1;
1910 aCurve.SetFirstCurve2d(H1);
1913 mySeqOfCurve.Append(aCurve);
1916 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1917 nbpoles = mbspc.NbPoles();
1918 TColgp_Array1OfPnt tpoles(1,nbpoles);
1919 mbspc.Curve(1,tpoles);
1920 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1922 mbspc.Multiplicities(),
1924 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1925 Check.FixTangent(Standard_True,Standard_True);
1927 IntTools_Curve aCurve;
1928 aCurve.SetCurve(BS);
1932 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1933 mbspc.Curve(2,tpoles2d);
1934 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
1936 mbspc.Multiplicities(),
1938 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
1939 newCheck.FixTangent(Standard_True,Standard_True);
1941 aCurve.SetFirstCurve2d(BS1);
1944 Handle(Geom2d_BSplineCurve) BS1;
1945 fprm = BS->FirstParameter();
1946 lprm = BS->LastParameter();
1948 Handle(Geom2d_Curve) C2d;
1949 Standard_Real aTol = myTolApprox;
1950 BuildPCurves(fprm, lprm, aTol, myHS1->ChangeSurface().Surface(), BS, C2d);
1951 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
1952 aCurve.SetFirstCurve2d(BS1);
1957 Handle(Geom2d_BSplineCurve) H1;
1959 aCurve.SetFirstCurve2d(H1);
1963 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1964 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
1965 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1967 mbspc.Multiplicities(),
1969 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1970 newCheck.FixTangent(Standard_True,Standard_True);
1972 aCurve.SetSecondCurve2d(BS2);
1975 Handle(Geom2d_BSplineCurve) BS2;
1976 fprm = BS->FirstParameter();
1977 lprm = BS->LastParameter();
1979 Handle(Geom2d_Curve) C2d;
1980 Standard_Real aTol = myTolApprox;
1981 BuildPCurves(fprm, lprm, aTol, myHS2->ChangeSurface().Surface(), BS, C2d);
1982 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
1983 aCurve.SetSecondCurve2d(BS2);
1988 Handle(Geom2d_BSplineCurve) H2;
1990 aCurve.SetSecondCurve2d(H2);
1993 mySeqOfCurve.Append(aCurve);
1999 }// case IntPatch_Walking:{
2002 case IntPatch_Restriction:
2008 //=======================================================================
2009 //function : BuildPCurves
2011 //=======================================================================
2012 void BuildPCurves (Standard_Real f,
2015 const Handle (Geom_Surface)& S,
2016 const Handle (Geom_Curve)& C,
2017 Handle (Geom2d_Curve)& C2d)
2020 Standard_Real umin,umax,vmin,vmax;
2025 // in class ProjLib_Function the range of parameters is shrank by 1.e-09
2026 if((l - f) > 2.e-09) {
2027 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2030 // proj. a circle that goes through the pole on a sphere to the sphere
2032 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2036 if((l - f) > Epsilon(Abs(f))) {
2037 GeomAPI_ProjectPointOnSurf aProjector1, aProjector2;
2038 gp_Pnt P1 = C->Value(f);
2039 gp_Pnt P2 = C->Value(l);
2040 aProjector1.Init(P1, S);
2041 aProjector2.Init(P2, S);
2043 if(aProjector1.IsDone() && aProjector2.IsDone()) {
2044 Standard_Real U=0., V=0.;
2045 aProjector1.LowerDistanceParameters(U, V);
2048 aProjector2.LowerDistanceParameters(U, V);
2051 if(p1.Distance(p2) > gp::Resolution()) {
2052 TColgp_Array1OfPnt2d poles(1,2);
2053 TColStd_Array1OfReal knots(1,2);
2054 TColStd_Array1OfInteger mults(1,2);
2059 mults(1) = mults(2) = 2;
2061 C2d = new Geom2d_BSplineCurve(poles,knots,mults,1);
2063 // compute reached tolerance.begin
2064 gp_Pnt PMid = C->Value((f + l) * 0.5);
2065 aProjector1.Perform(PMid);
2067 if(aProjector1.IsDone()) {
2068 aProjector1.LowerDistanceParameters(U, V);
2069 gp_Pnt2d pmidproj(U, V);
2070 gp_Pnt2d pmidcurve2d = C2d->Value((f + l) * 0.5);
2071 Standard_Real adist = pmidcurve2d.Distance(pmidproj);
2072 Tol = (adist > Tol) ? adist : Tol;
2074 // compute reached tolerance.end
2080 S->Bounds(umin, umax, vmin, vmax);
2082 if (S->IsUPeriodic() && !C2d.IsNull()) {
2083 // Recadre dans le domaine UV de la face
2084 Standard_Real period, U0, du, aEps;
2087 aEps=Precision::PConfusion();
2088 period = S->UPeriod();
2089 gp_Pnt2d Pf = C2d->Value(f);
2092 gp_Pnt2d Pl = C2d->Value(l);
2094 U0 = Min(Pl.X(), U0);
2095 // while(U0-umin<aEps) {
2096 while(U0-umin<-aEps) {
2101 while(U0-umax>aEps) {
2112 BOPTColStd_Dump::PrintMessage("BuildPCurves()=> Echec ProjLib\n");
2116 //=======================================================================
2117 //function : Parameters
2119 //=======================================================================
2120 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
2121 const Handle(GeomAdaptor_HSurface)& HS2,
2122 const gp_Pnt& Ptref,
2129 IntSurf_Quadric quad1,quad2;
2130 GeomAbs_SurfaceType typs = HS1->Surface().GetType();
2134 quad1.SetValue(HS1->Surface().Plane());
2136 case GeomAbs_Cylinder:
2137 quad1.SetValue(HS1->Surface().Cylinder());
2140 quad1.SetValue(HS1->Surface().Cone());
2142 case GeomAbs_Sphere:
2143 quad1.SetValue(HS1->Surface().Sphere());
2146 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2149 typs = HS2->Surface().GetType();
2152 quad2.SetValue(HS2->Surface().Plane());
2154 case GeomAbs_Cylinder:
2155 quad2.SetValue(HS2->Surface().Cylinder());
2158 quad2.SetValue(HS2->Surface().Cone());
2160 case GeomAbs_Sphere:
2161 quad2.SetValue(HS2->Surface().Sphere());
2164 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2167 quad1.Parameters(Ptref,U1,V1);
2168 quad2.Parameters(Ptref,U2,V2);
2171 //=======================================================================
2172 //function : MakeBSpline
2174 //=======================================================================
2175 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
2176 const Standard_Integer ideb,
2177 const Standard_Integer ifin)
2179 Standard_Integer i,nbpnt = ifin-ideb+1;
2180 TColgp_Array1OfPnt poles(1,nbpnt);
2181 TColStd_Array1OfReal knots(1,nbpnt);
2182 TColStd_Array1OfInteger mults(1,nbpnt);
2183 Standard_Integer ipidebm1;
2184 for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) {
2185 poles(i) = WL->Point(ipidebm1).Value();
2189 mults(1) = mults(nbpnt) = 2;
2191 new Geom_BSplineCurve(poles,knots,mults,1);
2195 //=======================================================================
2196 //function : MakeBSpline2d
2198 //=======================================================================
2199 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
2200 const Standard_Integer ideb,
2201 const Standard_Integer ifin,
2202 const Standard_Boolean onFirst)
2204 Standard_Integer i, nbpnt = ifin-ideb+1;
2205 TColgp_Array1OfPnt2d poles(1,nbpnt);
2206 TColStd_Array1OfReal knots(1,nbpnt);
2207 TColStd_Array1OfInteger mults(1,nbpnt);
2208 Standard_Integer ipidebm1;
2210 for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
2213 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
2215 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
2216 poles(i).SetCoord(U, V);
2220 mults(1) = mults(nbpnt) = 2;
2222 return new Geom2d_BSplineCurve(poles,knots,mults,1);
2224 //=======================================================================
2225 //function : PrepareLines3D
2227 //=======================================================================
2228 void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit)
2230 Standard_Integer i, aNbCurves;
2231 GeomAbs_SurfaceType aType1, aType2;
2232 IntTools_SequenceOfCurves aNewCvs;
2234 // 1. Treatment closed curves
2235 aNbCurves=mySeqOfCurve.Length();
2236 for (i=1; i<=aNbCurves; ++i) {
2237 const IntTools_Curve& aIC=mySeqOfCurve(i);
2240 Standard_Integer j, aNbC;
2241 IntTools_SequenceOfCurves aSeqCvs;
2243 aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
2245 for (j=1; j<=aNbC; ++j) {
2246 const IntTools_Curve& aICNew=aSeqCvs(j);
2247 aNewCvs.Append(aICNew);
2251 aNewCvs.Append(aIC);
2255 aNewCvs.Append(aIC);
2259 // 2. Plane\Cone intersection when we had 4 curves
2260 aType1=myHS1->GetType();
2261 aType2=myHS2->GetType();
2262 aNbCurves=aNewCvs.Length();
2264 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) ||
2265 (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) {
2267 GeomAbs_CurveType aCType1;
2269 aCType1=aNewCvs(1).Type();
2270 if (aCType1==GeomAbs_Line) {
2271 IntTools_SequenceOfCurves aSeqIn, aSeqOut;
2273 for (i=1; i<=aNbCurves; ++i) {
2274 const IntTools_Curve& aIC=aNewCvs(i);
2278 IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
2281 aNbCurves=aSeqOut.Length();
2282 for (i=1; i<=aNbCurves; ++i) {
2283 const IntTools_Curve& aIC=aSeqOut(i);
2284 aNewCvs.Append(aIC);
2288 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)...
2290 // 3. Fill mySeqOfCurve
2291 mySeqOfCurve.Clear();
2292 aNbCurves=aNewCvs.Length();
2293 for (i=1; i<=aNbCurves; ++i) {
2294 const IntTools_Curve& aIC=aNewCvs(i);
2295 mySeqOfCurve.Append(aIC);
2298 //=======================================================================
2299 //function : CorrectSurfaceBoundaries
2301 //=======================================================================
2302 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
2303 const Standard_Real theTolerance,
2304 Standard_Real& theumin,
2305 Standard_Real& theumax,
2306 Standard_Real& thevmin,
2307 Standard_Real& thevmax)
2309 Standard_Boolean enlarge, isuperiodic, isvperiodic;
2310 Standard_Real uinf, usup, vinf, vsup, delta;
2311 GeomAbs_SurfaceType aType;
2312 Handle(Geom_Surface) aSurface;
2314 aSurface = BRep_Tool::Surface(theFace);
2315 aSurface->Bounds(uinf, usup, vinf, vsup);
2316 delta = theTolerance;
2317 enlarge = Standard_False;
2319 GeomAdaptor_Surface anAdaptorSurface(aSurface);
2321 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
2322 Handle(Geom_Surface) aBasisSurface =
2323 (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface();
2325 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2326 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2331 if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2332 Handle(Geom_Surface) aBasisSurface =
2333 (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface();
2335 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2336 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2341 isuperiodic = anAdaptorSurface.IsUPeriodic();
2342 isvperiodic = anAdaptorSurface.IsVPeriodic();
2344 aType=anAdaptorSurface.GetType();
2345 if((aType==GeomAbs_BezierSurface) ||
2346 (aType==GeomAbs_BSplineSurface) ||
2347 (aType==GeomAbs_SurfaceOfExtrusion) ||
2348 (aType==GeomAbs_SurfaceOfRevolution)) {
2349 enlarge=Standard_True;
2352 if(!isuperiodic && enlarge) {
2354 if((theumin - uinf) > delta )
2360 if((usup - theumax) > delta )
2366 if(!isvperiodic && enlarge) {
2367 if((thevmin - vinf) > delta ) {
2373 if((vsup - thevmax) > delta ) {
2382 Standard_Integer aNbP;
2383 Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA;
2385 aTolPA=Precision::Angular();
2388 aXP=anAdaptorSurface.UPeriod();
2389 dXfact=theumax-theumin;
2390 if (dXfact-aTolPA>aXP) {
2391 aXmid=0.5*(theumax+theumin);
2392 aNbP=RealToInt(aXmid/aXP);
2397 if (theumin>aTolPA) {
2398 aX1=theumin+aNbP*aXP;
2411 aXP=anAdaptorSurface.VPeriod();
2412 dXfact=thevmax-thevmin;
2413 if (dXfact-aTolPA>aXP) {
2414 aXmid=0.5*(thevmax+thevmin);
2415 aNbP=RealToInt(aXmid/aXP);
2420 if (thevmin>aTolPA) {
2421 aX1=thevmin+aNbP*aXP;
2434 if(isuperiodic || isvperiodic) {
2435 Standard_Boolean correct = Standard_False;
2436 Standard_Boolean correctU = Standard_False;
2437 Standard_Boolean correctV = Standard_False;
2439 TopExp_Explorer anExp;
2441 for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2442 if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
2443 correct = Standard_True;
2445 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
2447 for(Standard_Integer i = 0; i < 2; i++) {
2449 anEdge.Orientation(TopAbs_FORWARD);
2452 anEdge.Orientation(TopAbs_REVERSED);
2454 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
2456 if(aCurve.IsNull()) {
2457 correct = Standard_False;
2460 Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
2462 if(aLine.IsNull()) {
2463 correct = Standard_False;
2466 gp_Dir2d anUDir(1., 0.);
2467 gp_Dir2d aVDir(0., 1.);
2468 Standard_Real anAngularTolerance = Precision::Angular();
2470 correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
2471 correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
2473 gp_Pnt2d pp1 = aCurve->Value(f);
2475 gp_Pnt2d pp2 = aCurve->Value(l);
2484 Standard_Real umin, vmin, umax, vmax;
2485 aBox.Get(umin, vmin, umax, vmax);
2487 if(isuperiodic && correctU) {
2492 if(theumax > umax) {
2496 if(isvperiodic && correctV) {
2508 // The block is dedicated to determine whether WLine [ifprm, ilprm]
2509 // crosses the degenerated zone on each given surface or not.
2510 // If Yes -> We will not use info about surfaces during approximation
2511 // because inside degenerated zone of the surface the approx. alogo.
2512 // uses wrong values of normal, etc., and resulting curve will have
2513 // oscillations that we would not like to have.
2514 // PKV Tue Feb 12 2002
2518 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2519 const Handle(Geom_Surface)& aS,
2520 const Standard_Integer iDir);
2522 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2523 const TopoDS_Face& aF1,
2524 const TopoDS_Face& aF2);
2525 //=======================================================================
2526 //function : NotUseSurfacesForApprox
2528 //=======================================================================
2529 Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
2530 const TopoDS_Face& aF2,
2531 const Handle(IntPatch_WLine)& WL,
2532 const Standard_Integer ifprm,
2533 const Standard_Integer ilprm)
2535 Standard_Boolean bPInDZ;
2537 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
2539 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
2540 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
2545 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
2546 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
2550 //=======================================================================
2551 //function : IsPointInDegeneratedZone
2553 //=======================================================================
2554 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2555 const TopoDS_Face& aF1,
2556 const TopoDS_Face& aF2)
2559 Standard_Boolean bFlag=Standard_True;
2560 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
2561 Standard_Real U1, V1, U2, V2, aDelta, aD;
2564 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
2565 aS1->Bounds(US11, US12, VS11, VS12);
2566 GeomAdaptor_Surface aGAS1(aS1);
2568 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
2569 aS1->Bounds(US21, US22, VS21, VS22);
2570 GeomAdaptor_Surface aGAS2(aS2);
2572 //const gp_Pnt& aP=aP2S.Value();
2573 aP2S.Parameters(U1, V1, U2, V2);
2577 aD=aGAS1.UResolution(aDelta);
2578 aP2d.SetCoord(U1, V1);
2579 if (fabs(U1-US11) < aD) {
2580 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2585 if (fabs(U1-US12) < aD) {
2586 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2591 aD=aGAS1.VResolution(aDelta);
2592 if (fabs(V1-VS11) < aDelta) {
2593 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2598 if (fabs(V1-VS12) < aDelta) {
2599 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2605 aD=aGAS2.UResolution(aDelta);
2606 aP2d.SetCoord(U2, V2);
2607 if (fabs(U2-US21) < aDelta) {
2608 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2613 if (fabs(U2-US22) < aDelta) {
2614 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2619 aD=aGAS2.VResolution(aDelta);
2620 if (fabs(V2-VS21) < aDelta) {
2621 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2626 if (fabs(V2-VS22) < aDelta) {
2627 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2635 //=======================================================================
2636 //function : IsDegeneratedZone
2638 //=======================================================================
2639 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2640 const Handle(Geom_Surface)& aS,
2641 const Standard_Integer iDir)
2643 Standard_Boolean bFlag=Standard_True;
2644 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
2645 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
2646 aS->Bounds(US1, US2, VS1, VS2);
2648 gp_Pnt aPm, aPb, aPe;
2653 aS->D0(aXm, aYm, aPm);
2670 aS->D0(aXb, aYb, aPb);
2671 aS->D0(aXe, aYe, aPe);
2673 d1=aPm.Distance(aPb);
2674 d2=aPm.Distance(aPe);
2675 if (d1 < dD && d2 < dD) {
2692 aS->D0(aXb, aYb, aPb);
2693 aS->D0(aXe, aYe, aPe);
2695 d1=aPm.Distance(aPb);
2696 d2=aPm.Distance(aPe);
2697 if (d1 < dD && d2 < dD) {
2705 //=========================================================================
2706 // static function : ComputePurgedWLine
2707 // purpose : Removes equal points (leave one of equal points) from theWLine
2708 // and recompute vertex parameters.
2709 // Returns new WLine or null WLine if the number
2710 // of the points is less than 2.
2711 //=========================================================================
2712 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) {
2714 Standard_Integer i, k, v, nb, nbvtx;
2715 Handle(IntPatch_WLine) aResult;
2716 nbvtx = theWLine->NbVertex();
2717 nb = theWLine->NbPnts();
2719 const IntSurf_PntOn2S& p1 = theWLine->Point(1);
2720 const IntSurf_PntOn2S& p2 = theWLine->Point(2);
2721 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2726 Handle(IntPatch_WLine) aLocalWLine;
2727 Handle(IntPatch_WLine) aTmpWLine = theWLine;
2728 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
2729 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2730 for(i = 1; i <= nb; i++) {
2731 aLineOn2S->Add(theWLine->Point(i));
2734 for(v = 1; v <= nbvtx; v++) {
2735 aLocalWLine->AddVertex(theWLine->Vertex(v));
2738 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
2739 Standard_Integer aStartIndex = i + 1;
2740 Standard_Integer anEndIndex = i + 5;
2741 nb = aLineOn2S->NbPoints();
2742 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
2744 if((aStartIndex > nb) || (anEndIndex <= 1)) {
2749 while(k <= anEndIndex) {
2752 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
2753 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
2755 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2756 aTmpWLine = aLocalWLine;
2757 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2759 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
2760 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
2761 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
2763 if(avertexindex >= k) {
2764 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
2766 aLocalWLine->AddVertex(aVertex);
2768 aLineOn2S->RemovePoint(k);
2777 if(aLineOn2S->NbPoints() > 1) {
2778 aResult = aLocalWLine;
2783 //=======================================================================
2786 //=======================================================================
2787 void TolR3d(const TopoDS_Face& aF1,
2788 const TopoDS_Face& aF2,
2789 Standard_Real& myTolReached3d)
2791 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
2793 aTolTresh=2.999999e-3;
2794 aTolF1 = BRep_Tool::Tolerance(aF1);
2795 aTolF2 = BRep_Tool::Tolerance(aF2);
2796 aTolFMax=Max(aTolF1, aTolF2);
2798 if (aTolFMax>aTolTresh) {
2799 myTolReached3d=aTolFMax;
2802 //=======================================================================
2803 //function : AdjustPeriodic
2805 //=======================================================================
2806 Standard_Real AdjustPeriodic(const Standard_Real theParameter,
2807 const Standard_Real parmin,
2808 const Standard_Real parmax,
2809 const Standard_Real thePeriod,
2810 Standard_Real& theOffset)
2812 Standard_Real aresult;
2815 aresult = theParameter;
2816 while(aresult < parmin) {
2817 aresult += thePeriod;
2818 theOffset += thePeriod;
2821 while(aresult > parmax) {
2822 aresult -= thePeriod;
2823 theOffset -= thePeriod;
2827 //=======================================================================
2828 //function : IsPointOnBoundary
2830 //=======================================================================
2831 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
2832 const Standard_Real theFirstBoundary,
2833 const Standard_Real theSecondBoundary,
2834 const Standard_Real theResolution,
2835 Standard_Boolean& IsOnFirstBoundary)
2837 Standard_Boolean bRet;
2839 Standard_Real adist;
2841 bRet=Standard_False;
2842 for(i = 0; i < 2; ++i) {
2843 IsOnFirstBoundary = (i == 0);
2844 if (IsOnFirstBoundary) {
2845 adist = fabs(theParameter - theFirstBoundary);
2848 adist = fabs(theParameter - theSecondBoundary);
2850 if(adist < theResolution) {
2856 // ------------------------------------------------------------------------------------------------
2857 // static function: FindPoint
2859 // ------------------------------------------------------------------------------------------------
2860 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
2861 const gp_Pnt2d& theLastPoint,
2862 const Standard_Real theUmin,
2863 const Standard_Real theUmax,
2864 const Standard_Real theVmin,
2865 const Standard_Real theVmax,
2866 gp_Pnt2d& theNewPoint) {
2868 gp_Vec2d aVec(theFirstPoint, theLastPoint);
2869 Standard_Integer i = 0, j = 0;
2871 for(i = 0; i < 4; i++) {
2872 gp_Vec2d anOtherVec;
2873 gp_Vec2d anOtherVecNormal;
2874 gp_Pnt2d aprojpoint = theLastPoint;
2877 anOtherVec.SetX(0.);
2878 anOtherVec.SetY(1.);
2879 anOtherVecNormal.SetX(1.);
2880 anOtherVecNormal.SetY(0.);
2883 aprojpoint.SetX(theUmin);
2885 aprojpoint.SetX(theUmax);
2888 anOtherVec.SetX(1.);
2889 anOtherVec.SetY(0.);
2890 anOtherVecNormal.SetX(0.);
2891 anOtherVecNormal.SetY(1.);
2894 aprojpoint.SetY(theVmin);
2896 aprojpoint.SetY(theVmax);
2898 gp_Vec2d anormvec = aVec;
2899 anormvec.Normalize();
2900 //modified by NIZNHY-PKV Mon Dec 19 11:46:06 2011f
2901 RefineVector(anormvec);
2902 //modified by NIZNHY-PKV Mon Dec 19 11:46:10 2011t
2903 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
2905 if(fabs(adot1) < Precision::Angular())
2907 Standard_Real adist = 0.;
2908 Standard_Boolean bIsOut = Standard_False;
2911 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
2912 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
2915 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
2916 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
2918 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
2920 for(j = 0; j < 2; j++) {
2921 anoffset = (j == 0) ? anoffset : -anoffset;
2922 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
2923 gp_Vec2d acurvec(theLastPoint, acurpoint);
2927 Standard_Real aDotX, anAngleX;
2929 aDotX = aVec.Dot(acurvec);
2930 anAngleX = aVec.Angle(acurvec);
2932 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
2934 if((acurpoint.Y() >= theVmin) &&
2935 (acurpoint.Y() <= theVmax)) {
2936 theNewPoint = acurpoint;
2937 return Standard_True;
2941 if((acurpoint.X() >= theUmin) &&
2942 (acurpoint.X() <= theUmax)) {
2943 theNewPoint = acurpoint;
2944 return Standard_True;
2950 return Standard_False;
2954 // ------------------------------------------------------------------------------------------------
2955 // static function: FindPoint
2956 // purpose: Find point on the boundary of radial tangent zone
2957 // ------------------------------------------------------------------------------------------------
2958 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
2959 const gp_Pnt2d& theLastPoint,
2960 const Standard_Real theUmin,
2961 const Standard_Real theUmax,
2962 const Standard_Real theVmin,
2963 const Standard_Real theVmax,
2964 const gp_Pnt2d& theTanZoneCenter,
2965 const Standard_Real theZoneRadius,
2966 Handle(GeomAdaptor_HSurface) theGASurface,
2967 gp_Pnt2d& theNewPoint) {
2968 theNewPoint = theLastPoint;
2970 if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
2971 return Standard_False;
2973 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
2974 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
2976 Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
2977 gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) );
2978 gp_Circ2d aCircle( anAxis, aRadius );
2981 gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() );
2982 Standard_Real aLength = aDir.Magnitude();
2983 if ( aLength <= gp::Resolution() )
2984 return Standard_False;
2985 gp_Lin2d aLine( theFirstPoint, aDir );
2988 Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine );
2989 Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength );
2990 Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle );
2992 Standard_Real aTol = aRadius * 0.001;
2993 aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol;
2995 Geom2dAPI_InterCurveCurve anIntersector;
2996 anIntersector.Init( aC1, aC2, aTol );
2998 if ( anIntersector.NbPoints() == 0 )
2999 return Standard_False;
3001 Standard_Boolean aFound = Standard_False;
3002 Standard_Real aMinDist = aLength * aLength;
3003 Standard_Integer i = 0;
3004 for ( i = 1; i <= anIntersector.NbPoints(); i++ ) {
3005 gp_Pnt2d aPInt = anIntersector.Point( i );
3006 if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
3007 if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
3008 ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
3009 theNewPoint = aPInt;
3010 aFound = Standard_True;
3018 // ------------------------------------------------------------------------------------------------
3019 // static function: IsInsideTanZone
3020 // purpose: Check if point is inside a radial tangent zone
3021 // ------------------------------------------------------------------------------------------------
3022 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
3023 const gp_Pnt2d& theTanZoneCenter,
3024 const Standard_Real theZoneRadius,
3025 Handle(GeomAdaptor_HSurface) theGASurface) {
3027 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3028 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3029 Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3030 aRadiusSQR *= aRadiusSQR;
3031 if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR )
3032 return Standard_True;
3033 return Standard_False;
3036 // ------------------------------------------------------------------------------------------------
3037 // static function: CheckTangentZonesExist
3038 // purpose: Check if tangent zone exists
3039 // ------------------------------------------------------------------------------------------------
3040 Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
3041 const Handle(GeomAdaptor_HSurface)& theSurface2 )
3043 if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
3044 ( theSurface2->GetType() != GeomAbs_Torus ) )
3045 return Standard_False;
3047 IntTools_Context aContext;
3049 gp_Torus aTor1 = theSurface1->Torus();
3050 gp_Torus aTor2 = theSurface2->Torus();
3052 if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() )
3053 return Standard_False;
3055 if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) ||
3056 ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) )
3057 return Standard_False;
3059 if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) ||
3060 ( aTor2.MajorRadius() < aTor2.MinorRadius() ) )
3061 return Standard_False;
3062 return Standard_True;
3065 // ------------------------------------------------------------------------------------------------
3066 // static function: ComputeTangentZones
3068 // ------------------------------------------------------------------------------------------------
3069 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
3070 const Handle(GeomAdaptor_HSurface)& theSurface2,
3071 const TopoDS_Face& theFace1,
3072 const TopoDS_Face& theFace2,
3073 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
3074 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
3075 Handle(TColStd_HArray1OfReal)& theResultRadius) {
3076 Standard_Integer aResult = 0;
3077 if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) )
3080 IntTools_Context aContext;
3082 TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2;
3083 TColStd_SequenceOfReal aSeqResultRad;
3085 gp_Torus aTor1 = theSurface1->Torus();
3086 gp_Torus aTor2 = theSurface2->Torus();
3088 gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() );
3089 gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() );
3090 Standard_Integer j = 0;
3092 for ( j = 0; j < 2; j++ ) {
3093 Standard_Real aCoef = ( j == 0 ) ? -1 : 1;
3094 Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius());
3095 Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius());
3097 gp_Circ aCircle1( anax1, aRadius1 );
3098 gp_Circ aCircle2( anax2, aRadius2 );
3100 // roughly compute radius of tangent zone for perpendicular case
3101 Standard_Real aCriteria = Precision::Confusion() * 0.5;
3103 Standard_Real aT1 = aCriteria;
3104 Standard_Real aT2 = aCriteria;
3106 // internal tangency
3107 Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3108 //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria );
3109 aT1 = 2. * aR * aCriteria;
3113 // external tangency
3114 Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3115 Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3116 Standard_Real aDelta = aRb - aCriteria;
3118 aDelta -= aRm * aRm;
3119 aDelta /= 2. * (aRb - aRm);
3120 aDelta -= 0.5 * (aRb - aRm);
3122 aT1 = 2. * aRm * (aRm - aDelta);
3125 aCriteria = ( aT1 > aT2) ? aT1 : aT2;
3126 if ( aCriteria > 0 )
3127 aCriteria = sqrt( aCriteria );
3129 if ( aCriteria > 0.5 * aTor1.MinorRadius() ) {
3130 // too big zone -> drop to minimum
3131 aCriteria = Precision::Confusion();
3134 GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) );
3135 GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) );
3136 Extrema_ExtCC anExtrema(aC1, aC2, 0, 2. * M_PI, 0, 2. * M_PI,
3137 Precision::PConfusion(), Precision::PConfusion());
3139 if ( anExtrema.IsDone() ) {
3141 Standard_Integer i = 0;
3142 for ( i = 1; i <= anExtrema.NbExt(); i++ ) {
3143 if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
3146 Extrema_POnCurv P1, P2;
3147 anExtrema.Points( i, P1, P2 );
3149 Standard_Boolean bFoundResult = Standard_True;
3152 Standard_Integer surfit = 0;
3153 for ( surfit = 0; surfit < 2; surfit++ ) {
3154 GeomAPI_ProjectPointOnSurf& aProjector = (surfit == 0) ? aContext.ProjPS(theFace1) : aContext.ProjPS(theFace2);
3156 gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
3157 aProjector.Perform(aP3d);
3159 if(!aProjector.IsDone())
3160 bFoundResult = Standard_False;
3162 if(aProjector.LowerDistance() > aCriteria) {
3163 bFoundResult = Standard_False;
3166 Standard_Real foundU = 0, foundV = 0;
3167 aProjector.LowerDistanceParameters(foundU, foundV);
3169 pr1 = gp_Pnt2d( foundU, foundV );
3171 pr2 = gp_Pnt2d( foundU, foundV );
3175 if ( bFoundResult ) {
3176 aSeqResultS1.Append( pr1 );
3177 aSeqResultS2.Append( pr2 );
3178 aSeqResultRad.Append( aCriteria );
3180 // torus is u and v periodic
3181 const Standard_Real twoPI = M_PI + M_PI;
3182 Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
3183 Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
3185 // iteration on period bounds
3186 for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
3187 Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
3188 Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
3190 // iteration on surfaces
3191 for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
3192 Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
3193 Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
3194 TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
3195 TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
3197 if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
3198 aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
3199 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3200 aSeqResultRad.Append( aCriteria );
3202 if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
3203 aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
3204 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3205 aSeqResultRad.Append( aCriteria );
3213 aResult = aSeqResultRad.Length();
3215 if ( aResult > 0 ) {
3216 theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult );
3217 theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult );
3218 theResultRadius = new TColStd_HArray1OfReal( 1, aResult );
3220 for ( Standard_Integer i = 1 ; i <= aResult; i++ ) {
3221 theResultOnS1->SetValue( i, aSeqResultS1.Value(i) );
3222 theResultOnS2->SetValue( i, aSeqResultS2.Value(i) );
3223 theResultRadius->SetValue( i, aSeqResultRad.Value(i) );
3229 // ------------------------------------------------------------------------------------------------
3230 // static function: AdjustByNeighbour
3232 // ------------------------------------------------------------------------------------------------
3233 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
3234 const gp_Pnt2d& theOriginalPoint,
3235 Handle(GeomAdaptor_HSurface) theGASurface) {
3237 gp_Pnt2d ap1 = theaNeighbourPoint;
3238 gp_Pnt2d ap2 = theOriginalPoint;
3240 if ( theGASurface->IsUPeriodic() ) {
3241 Standard_Real aPeriod = theGASurface->UPeriod();
3242 gp_Pnt2d aPTest = ap2;
3243 Standard_Real aSqDistMin = 1.e+100;
3245 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3246 aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt );
3247 Standard_Real dd = ap1.SquareDistance( aPTest );
3249 if ( dd < aSqDistMin ) {
3255 if ( theGASurface->IsVPeriodic() ) {
3256 Standard_Real aPeriod = theGASurface->VPeriod();
3257 gp_Pnt2d aPTest = ap2;
3258 Standard_Real aSqDistMin = 1.e+100;
3260 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3261 aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt );
3262 Standard_Real dd = ap1.SquareDistance( aPTest );
3264 if ( dd < aSqDistMin ) {
3273 // ------------------------------------------------------------------------------------------------
3274 //function: DecompositionOfWLine
3276 // ------------------------------------------------------------------------------------------------
3277 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
3278 const Handle(GeomAdaptor_HSurface)& theSurface1,
3279 const Handle(GeomAdaptor_HSurface)& theSurface2,
3280 const TopoDS_Face& theFace1,
3281 const TopoDS_Face& theFace2,
3282 const IntTools_LineConstructor& theLConstructor,
3283 const Standard_Boolean theAvoidLConstructor,
3284 IntPatch_SequenceOfLine& theNewLines,
3285 Standard_Real& theReachedTol3d) {
3287 Standard_Boolean bRet, bAvoidLineConstructor;
3288 Standard_Integer aNbPnts, aNbParts;
3290 bRet=Standard_False;
3291 aNbPnts=theWLine->NbPnts();
3292 bAvoidLineConstructor=theAvoidLConstructor;
3297 if (!bAvoidLineConstructor) {
3298 aNbParts=theLConstructor.NbParts();
3304 Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary;
3305 Standard_Integer nblines, pit, i, j;
3307 TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts);
3308 TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts);
3309 TColStd_ListOfInteger aListOfPointIndex;
3310 IntTools_Context aContext;
3312 Handle(TColgp_HArray1OfPnt2d) aTanZoneS1;
3313 Handle(TColgp_HArray1OfPnt2d) aTanZoneS2;
3314 Handle(TColStd_HArray1OfReal) aTanZoneRadius;
3315 Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2,
3316 aTanZoneS1, aTanZoneS2, aTanZoneRadius );
3320 aTol=Precision::Confusion();
3322 bIsPrevPointOnBoundary=Standard_False;
3323 bIsPointOnBoundary=Standard_False;
3328 for(pit = 1; pit <= aNbPnts; ++pit) {
3329 Standard_Boolean bIsOnFirstBoundary, isperiodic;
3330 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
3331 Standard_Real aParameter, anoffset, anAdjustPar;
3332 Standard_Real umin, umax, vmin, vmax;
3334 bIsCurrentPointOnBoundary = Standard_False;
3335 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
3338 for(i = 0; i < 2; ++i) {
3339 Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
3340 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3342 aPoint.ParametersOnS1(U, V);
3345 aPoint.ParametersOnS2(U, V);
3348 for(j = 0; j < 2; j++) {
3349 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3355 aResolution=aGASurface->UResolution(aTol);
3356 aPeriod=aGASurface->UPeriod();
3357 alowerboundary=umin;
3358 aupperboundary=umax;
3362 aResolution=aGASurface->VResolution(aTol);
3363 aPeriod=aGASurface->VPeriod();
3364 alowerboundary=vmin;
3365 aupperboundary=vmax;
3370 anAdjustPar = AdjustPeriodic(aParameter,
3376 bIsOnFirstBoundary = Standard_True;// ?
3378 IsPointOnBoundary(anAdjustPar,
3382 bIsOnFirstBoundary);
3384 if(bIsPointOnBoundary) {
3385 bIsCurrentPointOnBoundary = Standard_True;
3389 // check if a point belong to a tangent zone. Begin
3390 Standard_Integer zIt = 0;
3391 for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
3392 gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3393 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3395 if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
3396 // set boundary flag to split the curve by a tangent zone
3397 bIsPointOnBoundary = Standard_True;
3398 bIsCurrentPointOnBoundary = Standard_True;
3399 if ( theReachedTol3d < aZoneRadius ) {
3400 theReachedTol3d = aZoneRadius;
3406 }//for(j = 0; j < 2; j++) {
3408 if(bIsCurrentPointOnBoundary){
3411 }//for(i = 0; i < 2; ++i) {
3413 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
3414 if(!aListOfPointIndex.IsEmpty()) {
3416 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3417 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3418 aListOfPointIndex.Clear();
3420 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
3422 aListOfPointIndex.Append(pit);
3423 } //for(pit = 1; pit <= aNbPnts; ++pit) {
3425 if(!aListOfPointIndex.IsEmpty()) {
3427 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3428 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3429 aListOfPointIndex.Clear();
3433 return bRet; //Standard_False;
3437 // 2. Correct wlines.begin
3438 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
3439 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S();
3441 for(i = 1; i <= nblines; i++) {
3442 if(anArrayOfLineType.Value(i) != 0) {
3445 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3446 if(aListOfIndex.Extent() < 2) {
3449 TColStd_ListOfInteger aListOfFLIndex;
3451 for(j = 0; j < 2; j++) {
3452 Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1);
3454 if((aneighbourindex < 1) || (aneighbourindex > nblines))
3457 if(anArrayOfLineType.Value(aneighbourindex) == 0)
3459 const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex);
3460 Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First();
3461 const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
3463 IntSurf_PntOn2S aNewP = aPoint;
3465 for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
3467 Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
3468 Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
3469 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3470 Standard_Real U=0., V=0.;
3473 aNewP.ParametersOnS1(U, V);
3475 aNewP.ParametersOnS2(U, V);
3476 Standard_Integer nbboundaries = 0;
3478 Standard_Boolean bIsNearBoundary = Standard_False;
3479 Standard_Integer aZoneIndex = 0;
3480 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
3481 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
3484 for(Standard_Integer parit = 0; parit < 2; parit++) {
3485 Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3487 Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
3488 Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
3489 Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
3491 Standard_Real aParameter = (parit == 0) ? U : V;
3492 Standard_Boolean bIsOnFirstBoundary = Standard_True;
3496 IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3497 if(bIsPointOnBoundary) {
3498 bIsUBoundary = (parit == 0);
3499 bIsFirstBoundary = bIsOnFirstBoundary;
3504 Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3505 Standard_Real anoffset = 0.;
3506 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3509 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3510 if(bIsPointOnBoundary) {
3511 bIsUBoundary = (parit == 0);
3512 bIsFirstBoundary = bIsOnFirstBoundary;
3516 //check neighbourhood of boundary
3517 Standard_Real anEpsilon = aResolution * 100.;
3518 Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
3519 anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
3521 bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
3522 anEpsilon, bIsOnFirstBoundary);
3528 // check if a point belong to a tangent zone. Begin
3529 for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
3530 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3531 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3533 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3534 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3535 Standard_Real nU1, nV1;
3538 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3540 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3541 gp_Pnt2d ap1(nU1, nV1);
3542 gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
3545 if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
3547 bIsNearBoundary = Standard_True;
3548 if ( theReachedTol3d < aZoneRadius ) {
3549 theReachedTol3d = aZoneRadius;
3553 // check if a point belong to a tangent zone. End
3554 Standard_Boolean bComputeLineEnd = Standard_False;
3556 if(nbboundaries == 2) {
3558 bComputeLineEnd = Standard_True;
3561 else if(nbboundaries == 1) {
3562 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3565 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
3566 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
3567 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3568 Standard_Real aParameter = (bIsUBoundary) ? U : V;
3569 Standard_Real anoffset = 0.;
3570 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3572 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
3573 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
3574 anotherPar += anoffset;
3575 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3576 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
3577 Standard_Real nU1, nV1;
3580 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3582 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3584 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
3585 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
3586 bComputeLineEnd = Standard_True;
3587 Standard_Boolean bCheckAngle1 = Standard_False;
3588 Standard_Boolean bCheckAngle2 = Standard_False;
3590 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
3591 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
3593 if(((adist1 - adist2) > Precision::PConfusion()) &&
3594 (adist2 < (aPeriod / 4.))) {
3595 bCheckAngle1 = Standard_True;
3596 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
3598 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3599 aNewP.SetValue((surfit == 0), anewU, anewV);
3600 bCheckAngle1 = Standard_False;
3603 else if(adist1 < (aPeriod / 4.)) {
3604 bCheckAngle2 = Standard_True;
3605 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
3607 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3608 bCheckAngle2 = Standard_False;
3612 if(bCheckAngle1 || bCheckAngle2) {
3613 // assume there are at least two points in line (see "if" above)
3614 Standard_Integer anindexother = aneighbourpointindex;
3616 while((anindexother <= aListOfIndex.Last()) && (anindexother >= aListOfIndex.First())) {
3617 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
3618 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
3619 Standard_Real nU2, nV2;
3622 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3624 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3625 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
3627 if(aVecOld.SquareMagnitude() <= (gp::Resolution() * gp::Resolution())) {
3631 Standard_Real anAngle = aNewVec.Angle(aVecOld);
3633 if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
3636 Standard_Real U1, U2, V1, V2;
3637 IntSurf_PntOn2S atmppoint = aNewP;
3638 atmppoint.SetValue((surfit == 0), anewU, anewV);
3639 atmppoint.Parameters(U1, V1, U2, V2);
3640 gp_Pnt P1 = theSurface1->Value(U1, V1);
3641 gp_Pnt P2 = theSurface2->Value(U2, V2);
3642 gp_Pnt P0 = aPoint.Value();
3644 if(P0.IsEqual(P1, aTol) &&
3645 P0.IsEqual(P2, aTol) &&
3646 P1.IsEqual(P2, aTol)) {
3647 bComputeLineEnd = Standard_False;
3648 aNewP.SetValue((surfit == 0), anewU, anewV);
3653 bComputeLineEnd = Standard_False;
3658 } // end while(anindexother...)
3662 else if ( bIsNearBoundary ) {
3663 bComputeLineEnd = Standard_True;
3666 if(bComputeLineEnd) {
3669 Standard_Boolean found = Standard_False;
3671 if ( bIsNearBoundary ) {
3672 // re-compute point near natural boundary or near tangent zone
3673 Standard_Real u1, v1, u2, v2;
3674 aNewP.Parameters( u1, v1, u2, v2 );
3676 anewpoint = gp_Pnt2d( u1, v1 );
3678 anewpoint = gp_Pnt2d( u2, v2 );
3680 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3681 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3682 Standard_Real nU1, nV1;
3685 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3687 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3688 gp_Pnt2d ap1(nU1, nV1);
3693 // exclude point from a tangent zone
3694 anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3695 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
3696 Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
3698 if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
3699 aPZone, aZoneRadius, aGASurface, ap2) ) {
3701 found = Standard_True;
3704 else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
3705 // re-compute point near boundary if shifted on a period
3706 ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3708 if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
3709 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
3710 found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
3714 aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
3720 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3721 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3722 Standard_Real nU1, nV1;
3725 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3727 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3728 gp_Pnt2d ap1(nU1, nV1);
3729 gp_Pnt2d ap2(nU1, nV1);
3730 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
3732 while((aneighbourpointindex2 <= aListOfIndex.Last()) && (aneighbourpointindex2 >= aListOfIndex.First())) {
3733 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
3734 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
3735 Standard_Real nU2, nV2;
3738 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3740 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3744 if(ap1.SquareDistance(ap2) > (gp::Resolution() * gp::Resolution())) {
3748 found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
3753 Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
3754 GeomAPI_ProjectPointOnSurf& aProjector = (surfit == 0) ? aContext.ProjPS(theFace2) : aContext.ProjPS(theFace1);
3755 Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
3757 Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
3759 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
3760 aProjector.Perform(aP3d);
3762 if(aProjector.IsDone()) {
3763 if(aProjector.LowerDistance() < aCriteria) {
3764 Standard_Real foundU = U, foundV = V;
3765 aProjector.LowerDistanceParameters(foundU, foundV);
3767 //Correction of projected coordinates. Begin
3768 //Note, it may be shifted on a period
3769 Standard_Integer aneindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3770 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
3771 Standard_Real nUn, nVn;
3774 aNeighbourPoint.ParametersOnS2(nUn, nVn);
3776 aNeighbourPoint.ParametersOnS1(nUn, nVn);
3777 gp_Pnt2d aNeighbour2d(nUn, nVn);
3778 gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
3779 foundU = anAdjustedPoint.X();
3780 foundV = anAdjustedPoint.Y();
3782 if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
3783 ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
3784 // attempt to roughly re-compute point
3785 foundU = ( foundU < umin ) ? umin : foundU;
3786 foundU = ( foundU > umax ) ? umax : foundU;
3787 foundV = ( foundV < vmin ) ? vmin : foundV;
3788 foundV = ( foundV > vmax ) ? vmax : foundV;
3790 GeomAPI_ProjectPointOnSurf& aProjector2 = (surfit == 0) ? aContext.ProjPS(theFace1) : aContext.ProjPS(theFace2);
3792 aP3d = aSurfaceOther->Value(foundU, foundV);
3793 aProjector2.Perform(aP3d);
3795 if(aProjector2.IsDone()) {
3796 if(aProjector2.LowerDistance() < aCriteria) {
3797 Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
3798 aProjector2.LowerDistanceParameters(foundU2, foundV2);
3799 anewpoint.SetX(foundU2);
3800 anewpoint.SetY(foundV2);
3804 //Correction of projected coordinates. End
3807 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
3809 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
3815 aSeqOfPntOn2S->Add(aNewP);
3816 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
3818 anArrayOfLineEnds.SetValue(i, aListOfFLIndex);
3820 // Correct wlines.end
3822 // Split wlines.begin
3823 Standard_Integer nbiter;
3826 if (!bAvoidLineConstructor) {
3827 nbiter=theLConstructor.NbParts();
3830 for(j = 1; j <= nbiter; ++j) {
3831 Standard_Real fprm, lprm;
3832 Standard_Integer ifprm, ilprm;
3834 if(bAvoidLineConstructor) {
3836 ilprm = theWLine->NbPnts();
3839 theLConstructor.Part(j, fprm, lprm);
3840 ifprm = (Standard_Integer)fprm;
3841 ilprm = (Standard_Integer)lprm;
3844 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
3846 for(i = 1; i <= nblines; i++) {
3847 if(anArrayOfLineType.Value(i) != 0) {
3850 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3852 if(aListOfIndex.Extent() < 2) {
3855 const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
3856 Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
3857 Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
3859 if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
3860 bhasfirstpoint = (i != 1);
3863 if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
3864 bhaslastpoint = (i != nblines);
3866 Standard_Boolean bIsFirstInside = ((ifprm >= aListOfIndex.First()) && (ifprm <= aListOfIndex.Last()));
3867 Standard_Boolean bIsLastInside = ((ilprm >= aListOfIndex.First()) && (ilprm <= aListOfIndex.Last()));
3869 if(!bIsFirstInside && !bIsLastInside) {
3870 if((ifprm < aListOfIndex.First()) && (ilprm > aListOfIndex.Last())) {
3871 // append whole line, and boundaries if neccesary
3872 if(bhasfirstpoint) {
3873 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
3876 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
3878 for(; anIt.More(); anIt.Next()) {
3879 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
3884 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
3888 // check end of split line (end is almost always)
3889 Standard_Integer aneighbour = i + 1;
3890 Standard_Boolean bIsEndOfLine = Standard_True;
3892 if(aneighbour <= nblines) {
3893 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
3895 if((anArrayOfLineType.Value(aneighbour) != 0) &&
3896 (aListOfNeighbourIndex.IsEmpty())) {
3897 bIsEndOfLine = Standard_False;
3902 if(aLineOn2S->NbPoints() > 1) {
3903 Handle(IntPatch_WLine) aNewWLine =
3904 new IntPatch_WLine(aLineOn2S, Standard_False);
3905 theNewLines.Append(aNewWLine);
3907 aLineOn2S = new IntSurf_LineOn2S();
3912 // end if(!bIsFirstInside && !bIsLastInside)
3914 if(bIsFirstInside && bIsLastInside) {
3915 // append inside points between ifprm and ilprm
3916 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
3918 for(; anIt.More(); anIt.Next()) {
3919 if((anIt.Value() < ifprm) || (anIt.Value() > ilprm))
3921 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
3927 if(bIsFirstInside) {
3928 // append points from ifprm to last point + boundary point
3929 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
3931 for(; anIt.More(); anIt.Next()) {
3932 if(anIt.Value() < ifprm)
3934 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
3939 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
3942 // check end of split line (end is almost always)
3943 Standard_Integer aneighbour = i + 1;
3944 Standard_Boolean bIsEndOfLine = Standard_True;
3946 if(aneighbour <= nblines) {
3947 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
3949 if((anArrayOfLineType.Value(aneighbour) != 0) &&
3950 (aListOfNeighbourIndex.IsEmpty())) {
3951 bIsEndOfLine = Standard_False;
3956 if(aLineOn2S->NbPoints() > 1) {
3957 Handle(IntPatch_WLine) aNewWLine =
3958 new IntPatch_WLine(aLineOn2S, Standard_False);
3959 theNewLines.Append(aNewWLine);
3961 aLineOn2S = new IntSurf_LineOn2S();
3964 // end if(bIsFirstInside)
3967 // append points from first boundary point to ilprm
3968 if(bhasfirstpoint) {
3969 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
3972 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
3974 for(; anIt.More(); anIt.Next()) {
3975 if(anIt.Value() > ilprm)
3977 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
3981 //end if(bIsLastInside)
3985 if(aLineOn2S->NbPoints() > 1) {
3986 Handle(IntPatch_WLine) aNewWLine =
3987 new IntPatch_WLine(aLineOn2S, Standard_False);
3988 theNewLines.Append(aNewWLine);
3993 return Standard_True;
3996 // ------------------------------------------------------------------------------------------------
3997 // static function: ParameterOutOfBoundary
3998 // purpose: Computes a new parameter for given curve. The corresponding 2d points
3999 // does not lay on any boundary of given faces
4000 // ------------------------------------------------------------------------------------------------
4001 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
4002 const Handle(Geom_Curve)& theCurve,
4003 const TopoDS_Face& theFace1,
4004 const TopoDS_Face& theFace2,
4005 const Standard_Real theOtherParameter,
4006 const Standard_Boolean bIncreasePar,
4007 Standard_Real& theNewParameter) {
4008 Standard_Boolean bIsComputed = Standard_False;
4009 theNewParameter = theParameter;
4011 IntTools_Context aContext;
4012 Standard_Real acurpar = theParameter;
4013 TopAbs_State aState = TopAbs_ON;
4014 Standard_Integer iter = 0;
4015 Standard_Real asumtol = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4016 Standard_Real adelta = asumtol * 0.1;
4017 adelta = (adelta < Precision::Confusion()) ? Precision::Confusion() : adelta;
4018 Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(theFace1);
4019 Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(theFace2);
4021 Standard_Real u1, u2, v1, v2;
4023 GeomAPI_ProjectPointOnSurf aPrj1;
4024 aSurf1->Bounds(u1, u2, v1, v2);
4025 aPrj1.Init(aSurf1, u1, u2, v1, v2);
4027 GeomAPI_ProjectPointOnSurf aPrj2;
4028 aSurf2->Bounds(u1, u2, v1, v2);
4029 aPrj2.Init(aSurf2, u1, u2, v1, v2);
4031 while(aState == TopAbs_ON) {
4036 gp_Pnt aPCurrent = theCurve->Value(acurpar);
4037 aPrj1.Perform(aPCurrent);
4038 Standard_Real U=0., V=0.;
4040 if(aPrj1.IsDone()) {
4041 aPrj1.LowerDistanceParameters(U, V);
4042 aState = aContext.StatePointFace(theFace1, gp_Pnt2d(U, V));
4045 if(aState != TopAbs_ON) {
4046 aPrj2.Perform(aPCurrent);
4048 if(aPrj2.IsDone()) {
4049 aPrj2.LowerDistanceParameters(U, V);
4050 aState = aContext.StatePointFace(theFace2, gp_Pnt2d(U, V));
4061 theNewParameter = acurpar;
4062 bIsComputed = Standard_True;
4065 if(acurpar >= theOtherParameter)
4066 theNewParameter = theOtherParameter;
4069 if(acurpar <= theOtherParameter)
4070 theNewParameter = theOtherParameter;
4076 //=======================================================================
4077 //function : IsCurveValid
4079 //=======================================================================
4080 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve)
4082 if(thePCurve.IsNull())
4083 return Standard_False;
4085 Standard_Real tolint = 1.e-10;
4086 Geom2dAdaptor_Curve PCA;
4087 IntRes2d_Domain PCD;
4088 Geom2dInt_GInter PCI;
4090 Standard_Real pf = 0., pl = 0.;
4091 gp_Pnt2d pntf, pntl;
4093 if(!thePCurve->IsClosed() && !thePCurve->IsPeriodic()) {
4094 pf = thePCurve->FirstParameter();
4095 pl = thePCurve->LastParameter();
4096 pntf = thePCurve->Value(pf);
4097 pntl = thePCurve->Value(pl);
4098 PCA.Load(thePCurve);
4099 if(!PCA.IsPeriodic()) {
4100 if(PCA.FirstParameter() > pf) pf = PCA.FirstParameter();
4101 if(PCA.LastParameter() < pl) pl = PCA.LastParameter();
4103 PCD.SetValues(pntf,pf,tolint,pntl,pl,tolint);
4104 PCI.Perform(PCA,PCD,tolint,tolint);
4106 if(PCI.NbPoints() > 0) {
4107 return Standard_False;
4111 return Standard_True;
4114 //=======================================================================
4115 //static function : ApproxWithPCurves
4116 //purpose : for bug 20964 only
4117 //=======================================================================
4118 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
4119 const gp_Sphere& theSph)
4121 Standard_Boolean bRes = Standard_True;
4122 Standard_Real R1 = theCyl.Radius(), R2 = theSph.Radius();
4124 if(R1 < 2.*R2) return bRes;
4126 gp_Lin anCylAx(theCyl.Axis());
4128 Standard_Real aDist = anCylAx.Distance(theSph.Location());
4129 Standard_Real aDRel = Abs(aDist - R1)/R2;
4131 if(aDRel > .2) return bRes;
4133 Standard_Real par = ElCLib::Parameter(anCylAx, theSph.Location());
4134 gp_Pnt aP = ElCLib::Value(par, anCylAx);
4135 gp_Vec aV(aP, theSph.Location());
4137 Standard_Real dd = aV.Dot(theSph.Position().XDirection());
4139 if(aDist < R1 && dd > 0.) return Standard_False;
4140 if(aDist > R1 && dd < 0.) return Standard_False;
4145 //=======================================================================
4146 //function : PerformPlanes
4148 //=======================================================================
4149 void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
4150 const Handle(GeomAdaptor_HSurface)& theS2,
4151 const Standard_Real TolAng,
4152 const Standard_Real TolTang,
4153 const Standard_Boolean theApprox1,
4154 const Standard_Boolean theApprox2,
4155 IntTools_SequenceOfCurves& theSeqOfCurve,
4156 Standard_Boolean& theTangentFaces)
4159 gp_Pln aPln1 = theS1->Surface().Plane();
4160 gp_Pln aPln2 = theS2->Surface().Plane();
4162 IntAna_QuadQuadGeo aPlnInter(aPln1, aPln2, TolAng, TolTang);
4164 if(!aPlnInter.IsDone()) {
4165 theTangentFaces = Standard_False;
4169 IntAna_ResultType aResType = aPlnInter.TypeInter();
4171 if(aResType == IntAna_Same) {
4172 theTangentFaces = Standard_True;
4176 theTangentFaces = Standard_False;
4178 if(aResType == IntAna_Empty) {
4182 gp_Lin aLin = aPlnInter.Line(1);
4184 ProjLib_Plane aProj;
4187 aProj.Project(aLin);
4188 gp_Lin2d aLin2d1 = aProj.Line();
4191 aProj.Project(aLin);
4192 gp_Lin2d aLin2d2 = aProj.Line();
4194 //classify line2d1 relatively first plane
4195 Standard_Real P11, P12;
4196 Standard_Boolean IsCrossed = ClassifyLin2d(theS1, aLin2d1, TolTang, P11, P12);
4197 if(!IsCrossed) return;
4198 //classify line2d2 relatively second plane
4199 Standard_Real P21, P22;
4200 IsCrossed = ClassifyLin2d(theS2, aLin2d2, TolTang, P21, P22);
4201 if(!IsCrossed) return;
4203 //Analysis of parametric intervals: must have common part
4205 if(P21 >= P12) return;
4206 if(P22 <= P11) return;
4208 Standard_Real pmin, pmax;
4209 pmin = Max(P11, P21);
4210 pmax = Min(P12, P22);
4212 if(pmax - pmin <= TolTang) return;
4214 Handle(Geom_Line) aGLin = new Geom_Line(aLin);
4216 IntTools_Curve aCurve;
4217 Handle(Geom_TrimmedCurve) aGTLin = new Geom_TrimmedCurve(aGLin, pmin, pmax);
4219 aCurve.SetCurve(aGTLin);
4222 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d1);
4223 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4226 Handle(Geom2d_Curve) H1;
4227 aCurve.SetFirstCurve2d(H1);
4230 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d2);
4231 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4234 Handle(Geom2d_Curve) H1;
4235 aCurve.SetFirstCurve2d(H1);
4238 theSeqOfCurve.Append(aCurve);
4242 //=======================================================================
4243 //function : ClassifyLin2d
4245 //=======================================================================
4246 static inline Standard_Boolean INTER(const Standard_Real d1,
4247 const Standard_Real d2,
4248 const Standard_Real tol)
4250 return (d1 > tol && d2 < -tol) ||
4251 (d1 < -tol && d2 > tol) ||
4252 ((d1 <= tol && d1 >= -tol) && (d2 > tol || d2 < -tol)) ||
4253 ((d2 <= tol && d2 >= -tol) && (d1 > tol || d1 < -tol));
4255 static inline Standard_Boolean COINC(const Standard_Real d1,
4256 const Standard_Real d2,
4257 const Standard_Real tol)
4259 return (d1 <= tol && d1 >= -tol) && (d2 <= tol && d2 >= -tol);
4261 Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
4262 const gp_Lin2d& theLin2d,
4263 const Standard_Real theTol,
4264 Standard_Real& theP1,
4265 Standard_Real& theP2)
4268 Standard_Real xmin, xmax, ymin, ymax, d1, d2, A, B, C;
4269 Standard_Real par[2];
4270 Standard_Integer nbi = 0;
4272 xmin = theS->Surface().FirstUParameter();
4273 xmax = theS->Surface().LastUParameter();
4274 ymin = theS->Surface().FirstVParameter();
4275 ymax = theS->Surface().LastVParameter();
4277 theLin2d.Coefficients(A, B, C);
4279 //xmin, ymin <-> xmin, ymax
4280 d1 = A*xmin + B*ymin + C;
4281 d2 = A*xmin + B*ymax + C;
4283 if(INTER(d1, d2, theTol)) {
4284 //Intersection with boundary
4285 Standard_Real y = -(C + A*xmin)/B;
4286 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, y));
4289 else if (COINC(d1, d2, theTol)) {
4290 //Coincidence with boundary
4291 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4292 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4298 if(fabs(par[0]-par[1]) > theTol) {
4299 theP1 = Min(par[0], par[1]);
4300 theP2 = Max(par[0], par[1]);
4301 return Standard_True;
4303 else return Standard_False;
4307 //xmin, ymax <-> xmax, ymax
4309 d2 = A*xmax + B*ymax + C;
4311 if(d1 > theTol || d1 < -theTol) {//to avoid checking of
4312 //coincidence with the same point
4313 if(INTER(d1, d2, theTol)) {
4314 Standard_Real x = -(C + B*ymax)/A;
4315 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymax));
4318 else if (COINC(d1, d2, theTol)) {
4319 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4320 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4327 if(fabs(par[0]-par[1]) > theTol) {
4328 theP1 = Min(par[0], par[1]);
4329 theP2 = Max(par[0], par[1]);
4330 return Standard_True;
4332 else return Standard_False;
4336 //xmax, ymax <-> xmax, ymin
4338 d2 = A*xmax + B*ymin + C;
4340 if(d1 > theTol || d1 < -theTol) {
4341 if(INTER(d1, d2, theTol)) {
4342 Standard_Real y = -(C + A*xmax)/B;
4343 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, y));
4346 else if (COINC(d1, d2, theTol)) {
4347 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4348 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4354 if(fabs(par[0]-par[1]) > theTol) {
4355 theP1 = Min(par[0], par[1]);
4356 theP2 = Max(par[0], par[1]);
4357 return Standard_True;
4359 else return Standard_False;
4362 //xmax, ymin <-> xmin, ymin
4364 d2 = A*xmin + B*ymin + C;
4366 if(d1 > theTol || d1 < -theTol) {
4367 if(INTER(d1, d2, theTol)) {
4368 Standard_Real x = -(C + B*ymin)/A;
4369 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymin));
4372 else if (COINC(d1, d2, theTol)) {
4373 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4374 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4380 if(fabs(par[0]-par[1]) > theTol) {
4381 theP1 = Min(par[0], par[1]);
4382 theP2 = Max(par[0], par[1]);
4383 return Standard_True;
4385 else return Standard_False;
4388 return Standard_False;
4392 //=======================================================================
4393 //function : ApproxParameters
4395 //=======================================================================
4396 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
4397 const Handle(GeomAdaptor_HSurface)& aHS2,
4398 Standard_Integer& iDegMin,
4399 Standard_Integer& iDegMax)
4401 GeomAbs_SurfaceType aTS1, aTS2;
4407 aTS1=aHS1->Surface().GetType();
4408 aTS2=aHS2->Surface().GetType();
4411 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4412 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4413 Standard_Real aRC, aRT, dR, aPC;
4414 gp_Cylinder aCylinder;
4417 aPC=Precision::Confusion();
4419 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4420 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4422 aRC=aCylinder.Radius();
4423 aRT=aTorus.MinorRadius();
4434 //=======================================================================
4435 //function : Tolerances
4437 //=======================================================================
4438 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
4439 const Handle(GeomAdaptor_HSurface)& aHS2,
4440 Standard_Real& ,//aTolArc,
4441 Standard_Real& aTolTang,
4442 Standard_Real& ,//aUVMaxStep,
4443 Standard_Real& )//aDeflection)
4445 GeomAbs_SurfaceType aTS1, aTS2;
4447 aTS1=aHS1->Surface().GetType();
4448 aTS2=aHS2->Surface().GetType();
4451 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4452 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4453 Standard_Real aRC, aRT, dR, aPC;
4454 gp_Cylinder aCylinder;
4457 aPC=Precision::Confusion();
4459 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4460 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4462 aRC=aCylinder.Radius();
4463 aRT=aTorus.MinorRadius();
4470 aTolTang=0.1*aTolTang;
4474 //=======================================================================
4475 //function : SortTypes
4477 //=======================================================================
4478 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
4479 const GeomAbs_SurfaceType aType2)
4481 Standard_Boolean bRet;
4482 Standard_Integer aI1, aI2;
4484 bRet=Standard_False;
4486 aI1=IndexType(aType1);
4487 aI2=IndexType(aType2);
4493 //=======================================================================
4494 //function : IndexType
4496 //=======================================================================
4497 Standard_Integer IndexType(const GeomAbs_SurfaceType aType)
4499 Standard_Integer aIndex;
4503 if (aType==GeomAbs_Plane) {
4506 else if (aType==GeomAbs_Cylinder) {
4509 else if (aType==GeomAbs_Cone) {
4512 else if (aType==GeomAbs_Sphere) {
4515 else if (aType==GeomAbs_Torus) {
4518 else if (aType==GeomAbs_BezierSurface) {
4521 else if (aType==GeomAbs_BSplineSurface) {
4524 else if (aType==GeomAbs_SurfaceOfRevolution) {
4527 else if (aType==GeomAbs_SurfaceOfExtrusion) {
4530 else if (aType==GeomAbs_OffsetSurface) {
4533 else if (aType==GeomAbs_OtherSurface) {
4538 //=======================================================================
4539 //function : DumpWLine
4541 //=======================================================================
4542 void DumpWLine(const Handle(IntPatch_WLine)& aWLine)
4544 Standard_Integer i, aNbPnts;
4545 Standard_Real aX, aY, aZ, aU1, aV1, aU2, aV2;
4547 aNbPnts=aWLine->NbPnts();
4548 for (i=1; i<=aNbPnts; ++i) {
4549 const IntSurf_PntOn2S aPntOn2S=aWLine->Point(i);
4550 const gp_Pnt& aP3D=aPntOn2S.Value();
4551 aP3D.Coord(aX, aY, aZ);
4552 aPntOn2S.Parameters(aU1, aV1, aU2, aV2);
4554 //printf("point p_%d %lf %lf %lf\n", i, aX, aY, aZ);
4555 printf("point p_%d %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf\n",
4556 i, aX, aY, aZ, aU1, aV1, aU2, aV2);
4559 //modified by NIZNHY-PKV Wed Dec 14 12:22:48 2011f
4560 //=======================================================================
4561 //function : RefineVector
4563 //=======================================================================
4564 void RefineVector(gp_Vec2d& aV2D)
4566 Standard_Integer k,m;
4567 Standard_Real aC[2], aEps, aR1, aR2, aNum;
4573 aV2D.Coord(aC[0], aC[1]);
4575 for (k=0; k<2; ++k) {
4578 if (aNum>aR1 && aNum<aR2) {
4589 aV2D.SetCoord(aC[0], aC[1]);
4591 //modified by NIZNHY-PKV Wed Dec 14 12:22:50 2011t