1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #define No_Standard_OutOfRange
20 #include <Adaptor3d_CurveOnSurface.ixx>
22 #include <gp_Pnt2d.hxx>
23 #include <gp_Vec2d.hxx>
24 #include <gp_Ax22d.hxx>
25 #include <gp_Lin2d.hxx>
26 #include <gp_Circ2d.hxx>
27 #include <gp_Elips2d.hxx>
28 #include <gp_Hypr2d.hxx>
29 #include <gp_Parab2d.hxx>
30 #include <Geom_BSplineSurface.hxx>
31 #include <Geom_SurfaceOfRevolution.hxx>
32 #include <Geom_SurfaceOfLinearExtrusion.hxx>
33 #include <Geom_OffsetSurface.hxx>
34 #include <Geom2d_BezierCurve.hxx>
35 #include <Geom2d_BSplineCurve.hxx>
36 #include <Precision.hxx>
37 #include <TColgp_Array1OfPnt2d.hxx>
38 #include <TColgp_Array1OfPnt.hxx>
39 #include <TColStd_Array1OfReal.hxx>
40 #include <TColStd_Array1OfInteger.hxx>
41 #include <Standard_NotImplemented.hxx>
42 #include <Adaptor3d_HCurveOnSurface.hxx>
45 #include <Adaptor3d_InterFunc.hxx>
46 #include <math_FunctionRoots.hxx>
47 #include <SortTools_StraightInsertionSortOfReal.hxx>
48 #include <TCollection_CompareOfReal.hxx>
50 #include <TColStd_SetIteratorOfSetOfReal.hxx>
51 #include <TColStd_SetOfReal.hxx>
52 #include <TColStd_HSetOfReal.hxx>
54 static gp_Pnt to3d(const gp_Pln& Pl, const gp_Pnt2d& P)
56 return ElSLib::Value(P.X(),P.Y(),Pl);
59 static gp_Vec to3d(const gp_Pln& Pl, const gp_Vec2d& V)
61 gp_Vec Vx = Pl.XAxis().Direction();
62 gp_Vec Vy = Pl.YAxis().Direction();
69 static gp_Ax2 to3d(const gp_Pln& Pl, const gp_Ax22d& A)
71 gp_Pnt P = to3d(Pl,A.Location());
72 gp_Vec VX = to3d(Pl,A.XAxis().Direction());
73 gp_Vec VY = to3d(Pl,A.YAxis().Direction());
74 return gp_Ax2(P,VX.Crossed(VY),VX);
77 static gp_Circ to3d(const gp_Pln& Pl, const gp_Circ2d& C)
79 return gp_Circ(to3d(Pl,C.Axis()),C.Radius());
82 static gp_Elips to3d(const gp_Pln& Pl, const gp_Elips2d& E)
84 return gp_Elips(to3d(Pl,E.Axis()),E.MajorRadius(),E.MinorRadius());
87 static gp_Hypr to3d(const gp_Pln& Pl, const gp_Hypr2d& H)
89 return gp_Hypr(to3d(Pl,H.Axis()),H.MajorRadius(),H.MinorRadius());
92 static gp_Parab to3d(const gp_Pln& Pl, const gp_Parab2d& P)
94 return gp_Parab(to3d(Pl,P.Axis()),P.Focal());
97 static gp_Vec SetLinearForm(const gp_Vec2d DW, const gp_Vec2d D2W,const gp_Vec2d D3W,
98 const gp_Vec D1U, const gp_Vec D1V, const gp_Vec D2U,
99 const gp_Vec D2V, const gp_Vec D2UV, const gp_Vec D3U,
100 const gp_Vec D3V, const gp_Vec D3UUV,const gp_Vec D3UVV)
101 {gp_Vec V31, V32, V33, V34,V3 ;
102 V31.SetLinearForm(DW.X(),D1U,
104 D2W.X()*DW.Y(),D2UV);
105 V31.SetLinearForm(D3W.Y(),D1V,
109 V32.SetLinearForm(DW.X()*DW.X()*DW.Y(),D3UUV,
110 DW.X()*DW.Y()*DW.Y(),D3UVV);
111 V32.SetLinearForm(D2W.X()*DW.Y()+DW.X()*D2W.Y(),D2UV,
112 DW.X()*DW.Y()*DW.Y(),D3UVV,
114 V33.SetLinearForm(2*D2W.X()*DW.X(),D2U,
115 DW.X()*DW.X()*DW.X(),D3U,
116 DW.X()*DW.X()*DW.Y(),D3UUV);
118 V34.SetLinearForm(2*D2W.Y()*DW.Y(),D2V,
119 DW.Y()*DW.Y()*DW.X(),D3UVV,
120 DW.Y()*DW.Y()*DW.Y(),D3V);
121 V3.SetLinearForm(1,V31,2,V32,1,V33,V34);
125 //=======================================================================
126 static void CompareBounds(gp_Pnt2d& P1,
129 Standard_Real Lx = P1.X(),Ly = P1.Y();
130 Standard_Real Rx = P2.X(),Ry = P2.Y();
132 if (Lx > Rx) { P1.SetX(Rx); P2.SetX(Lx);}
133 if (Ly > Ry) { P1.SetY(Ry); P2.SetY(Ly);}
136 //=======================================================================
139 //=======================================================================
140 static void Hunt(const TColStd_Array1OfReal& Arr,
141 const Standard_Real Coord,
142 Standard_Integer& Iloc)
143 {//Warning: Hunt is used to find number of knot which equals co-ordinate component,
144 // when co-ordinate component definitly equals a knot only.
145 Standard_Real Tol=Precision::PConfusion()/10;
146 Standard_Integer i=1;
147 while((i <= Arr.Upper()) && (Abs(Coord - Arr(i)) > Tol)){
150 if(Abs(Coord - Arr(i)) < Tol)
153 if(Abs(Coord - Arr(i)) > Tol)
154 Standard_NotImplemented::Raise("Adaptor3d_CurveOnSurface:Hunt");
157 //=======================================================================
158 //function :ReverseParam
160 //=======================================================================
162 static void ReverseParam(const Standard_Real In1,
163 const Standard_Real In2,
165 Standard_Real& Out2 )
168 if(In1>In2) {Out1=In2;
173 //=======================================================================
174 //function :ReverseParam
176 //=======================================================================
178 static void ReverseParam(const Standard_Integer In1,
179 const Standard_Integer In2,
180 Standard_Integer& Out1,
181 Standard_Integer& Out2 )
183 if(In1>In2) {Out1=In2;
189 //=======================================================================
190 //function :FindBounds
192 //=======================================================================
193 static void FindBounds(const TColStd_Array1OfReal& Arr,
194 const Standard_Real Coord,
195 const Standard_Real Der,
196 Standard_Integer& Bound1,
197 Standard_Integer& Bound2,
198 Standard_Boolean& DerNull)
202 Standard_Real Tol=Precision::PConfusion()/10;
204 DerNull=Standard_False;
206 if(N==Bound1){ if(Abs(Der) > Tol) DerNull = Standard_False;
207 if(Abs(Der)<= Tol) DerNull = Standard_True;
208 Bound1=N;Bound2=N+1; return;
210 if(N==Bound2){ if( Abs(Der) > Tol ) DerNull = Standard_False;
211 if( Abs(Der)<= Tol ) DerNull = Standard_True;
212 Bound1=N-1;Bound2=N; return;
214 if((N!=Bound1)&&(N!=Bound2)) {
215 if(Abs(Der) > Tol ) {
216 if(Der>0) {Bound1=N;Bound2= N+1;}
218 if(Der<0){Bound1=N-1;Bound2=N;}
219 DerNull = Standard_False;
221 if(Abs(Der) <=Tol ) {
222 DerNull = Standard_True;
229 //=======================================================================
230 //function :Locate1Coord
231 //purpose : along BSpline curve
232 //=======================================================================
234 static void Locate1Coord(const Standard_Integer Index,
237 const Handle(Geom_BSplineCurve)& BSplC,
238 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop)
240 Standard_Real Comp1=0, DComp1=0, cur, f = 0.0, l = 0.0;
241 Standard_Real Tol = Precision::PConfusion()/10;
242 Standard_Integer i = 1, Bnd1, Bnd2;
243 Standard_Boolean DIsNull= Standard_False;
244 TColStd_Array1OfReal Arr(1,BSplC->NbKnots()); BSplC->Knots(Arr);
246 if(Index==1) { Comp1=UV.X(); DComp1=DUV.X(); }
247 if(Index==2) { Comp1=UV.Y(); DComp1=DUV.Y(); }
249 Standard_Integer Lo = BSplC->FirstUKnotIndex(), Up = BSplC->LastUKnotIndex();
252 while ( ( Abs(BSplC->Knot(i)-Comp1)>Tol )&& (i!=Up ) ) i++;
255 if( Abs(Comp1-cur)<=Tol) {
257 Bnd1 = Lo; Bnd2 = Up;
258 FindBounds(Arr,cur,DComp1,Bnd1,Bnd2,DIsNull);
259 ReverseParam(Bnd1,Bnd2,Bnd1,Bnd2);
261 if(DIsNull==Standard_False){
262 if(Index==1) {LeftBot.SetX(BSplC->Knot(Bnd1));
263 RightTop.SetX(BSplC->Knot(Bnd2));}
265 if(Index==2){ LeftBot.SetY(BSplC->Knot(Bnd1));
266 RightTop.SetY(BSplC->Knot(Bnd2)); }
269 if(DIsNull==Standard_True){
270 if( Abs( Comp1-(f=BSplC->Knot(Lo))) <= Tol)
272 if(Index==1) { LeftBot.SetX(BSplC->Knot(Lo));
273 RightTop.SetX(BSplC->Knot(Lo+1));}
274 else if(Index==2) { LeftBot.SetY(BSplC->Knot(Lo));
275 RightTop.SetY(BSplC->Knot(Lo+1));}
277 if( Abs( Comp1-(l=BSplC->Knot(Up))) <= Tol)
279 if(Index==1) { LeftBot.SetX(BSplC->Knot(Up-1));
280 RightTop.SetX(BSplC->Knot(Up));}
281 else if(Index==2) {LeftBot.SetY(BSplC->Knot(Up-1));
282 RightTop.SetY(BSplC->Knot(Up));}
284 if(Index==1) { LeftBot.SetX(BSplC->Knot(Bnd1));
285 RightTop.SetX(BSplC->Knot(Bnd2));}
286 else if(Index==2) {LeftBot.SetY(BSplC->Knot(Bnd1));
287 RightTop.SetY(BSplC->Knot(Bnd2));}
290 else//*********if Coord != Knot
294 //if((f=BSplC->Knot(i))<Comp1 && (l=BSplC->Knot(i+1))>Comp1) break;
295 //skl 28.03.2002 for OCC233
298 if(f<Comp1 && l>Comp1) break;
301 ReverseParam(f,l,f,l);
305 { if(Index==1) {LeftBot.SetX(f); RightTop.SetX(l);}else
306 if(Index==2) {LeftBot.SetY(f); RightTop.SetY(l); }
311 if(DComp1>0) {LeftBot.SetX(Comp1); RightTop.SetX(l);} else
312 if(DComp1<0) {LeftBot.SetX(f); RightTop.SetX(Comp1);}
316 if(DComp1>0) {LeftBot.SetY(Comp1); RightTop.SetY(l);} else
317 if(DComp1<0) {LeftBot.SetY(f); RightTop.SetY(Comp1);};
322 if(Index==1) {LeftBot.SetX(Comp1); RightTop.SetX(BSplC->Knot(i));}else
323 if(Index==2) {LeftBot.SetY(Comp1); RightTop.SetY(BSplC->Knot(i)); }
329 //=======================================================================
330 //function :Locate1Coord
332 //=======================================================================
334 static void Locate1Coord(const Standard_Integer Index,
337 const Handle(Geom_BSplineSurface)& BSplS,
338 Standard_Boolean& DIsNull,
342 Standard_Real Comp1=0,DComp1=0;
343 Standard_Real Tol = Precision::PConfusion()/10;
344 Standard_Integer i=1, Up=0, Up1, Up2, Down=0, Down1, Down2;
345 Standard_Real cur = 0.;
347 DIsNull= Standard_False;
349 Up1 = BSplS->LastUKnotIndex();
350 Down1 = BSplS->FirstUKnotIndex();
351 Up2 = BSplS->LastVKnotIndex();
352 Down2 = BSplS->FirstVKnotIndex();
362 while ( ( Abs(BSplS->UKnot(i)-Comp1)>Tol )&&(i!=Up1 ) )
367 cur = BSplS->UKnot(i);
377 while ( ( Abs(BSplS->VKnot(i)-Comp1)>Tol )&&(i!=Up2 ) )
382 cur = BSplS->VKnot(i);
385 if( Abs(Comp1-cur)<=Tol )
387 Standard_Integer Bnd1 = Down, Bnd2 = Up;
390 TColStd_Array1OfReal Arr1(1,BSplS->NbUKnots());
391 BSplS->UKnots(Arr1); // Up1=Arr1.Upper(); Down1=Arr1.Lower();
392 FindBounds(Arr1,cur,DUV.X(),Bnd1,Bnd2,DIsNull);
396 TColStd_Array1OfReal Arr2(1,BSplS->NbVKnots());
397 BSplS->VKnots(Arr2); // Up2=Arr2.Upper(); Down2=Arr2.Lower();
398 FindBounds(Arr2,cur,DUV.Y(),Bnd1,Bnd2,DIsNull);
401 ReverseParam(Bnd1,Bnd2,Bnd1,Bnd2);
403 if(DIsNull==Standard_False)
407 LeftBot.SetX(BSplS->UKnot(Bnd1));
408 RightTop.SetX(BSplS->UKnot(Bnd2));
412 LeftBot.SetY(BSplS->VKnot(Bnd1));
413 RightTop.SetY(BSplS->VKnot(Bnd2));
417 else//*********if Coord != Knot
419 if( (Index==1)&&(Comp1 < BSplS->UKnot(Down)) )
421 LeftBot.SetX(BSplS->UKnot(Down));
422 RightTop.SetX( BSplS->UKnot(Down + 1) );
425 else if( (Index==2)&&(Comp1 < BSplS->VKnot(Down)) )
427 LeftBot.SetY(BSplS->VKnot(Down));
428 RightTop.SetY( BSplS->VKnot(Down + 1) );
431 else if( (Index==1)&&(Comp1 > BSplS->UKnot(Up)) )
433 RightTop.SetX(BSplS->UKnot(Up - 1));
434 LeftBot.SetX( BSplS->UKnot(Up) );
437 else if( (Index==2)&&(Comp1 > BSplS->VKnot(Up)) )
439 RightTop.SetY(BSplS->VKnot(Up - 1));
440 LeftBot.SetY( BSplS->VKnot(Up) );
445 Standard_Real f = 0., l = 1.;
448 f=BSplS->UKnot(Down);
453 f=BSplS->VKnot(Down);
458 if ((!(Comp1 < f))&&(!(Comp1 > l)))
462 while (!(((f=BSplS->UKnot(i)) < Comp1)&&((l=BSplS->UKnot(i+1)) > Comp1)) && (i<Up))
469 while (!(((f=BSplS->VKnot(i)) < Comp1)&&((l=BSplS->VKnot(i+1)) > Comp1)) && (i<Up))
476 ReverseParam(f,l,f,l);
492 RightTop.SetX(Comp1);
505 RightTop.SetY(Comp1);
531 RightTop.SetX(BSplS->UKnot(i));
536 RightTop.SetY(BSplS->VKnot(i));
542 //=======================================================================
543 //function :Locate2Coord
544 //purpose : along non-BSpline curve
545 //=======================================================================
548 static void Locate2Coord(const Standard_Integer Index,
549 const gp_Pnt2d& UV, const gp_Vec2d& DUV,
550 const Standard_Real I1,
551 const Standard_Real I2,
552 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop)
554 Standard_Real Tol=Precision::PConfusion()/10;
555 Standard_Real Comp1=0,DComp1=0;
556 Standard_Boolean DIsNull = Standard_False;
557 if(Index==1) { Comp1=UV.X();
560 if(Index==2) {Comp1=UV.Y();
563 if((Comp1!=I1)&&(Comp1!=I2))
564 { if(Abs(DComp1) > Tol)
566 { if(Index==1) { LeftBot.SetX(I1);
567 RightTop.SetX(Comp1);}
568 if(Index==2) { LeftBot.SetY(I1);
569 RightTop.SetY(Comp1);}
573 { if(Index==1) { LeftBot.SetX(Comp1);
575 if(Index==2) { LeftBot.SetY(Comp1);
578 else { if(Index==1) { LeftBot.SetX(I1);
580 if(Index==2) { LeftBot.SetY(I1);
583 DIsNull=Standard_False;
586 if(Abs(DComp1)<=Tol) { DIsNull = Standard_True;
587 if(Index==1) { LeftBot.SetX(I1) ;
589 if(Index==2) { LeftBot.SetY(I1) ;
593 if(Abs(Comp1-I1)<Tol)
594 { if(Index==1) { LeftBot.SetX(I1) ;
596 if(Index==2) { LeftBot.SetY(I1) ;
600 if(Abs(Comp1-I2)<Tol)
601 { if(Index==1) { LeftBot.SetX(I1);
603 if(Index==2) { LeftBot.SetY(I1);
608 //=======================================================================
609 //function :Locate2Coord
611 //=======================================================================
613 static void Locate2Coord(const Standard_Integer Index,
614 const gp_Pnt2d& UV, const gp_Vec2d& DUV,
615 const Handle(Geom_BSplineSurface)& BSplS,
616 const TColStd_Array1OfReal& Arr,
617 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop)
619 Standard_Real Comp=0,DComp=0,Tmp1=0.0,Tmp2=0.0;
620 Standard_Real Tol=Precision::PConfusion()/10;
621 Standard_Integer N, NUp=0, NLo=0;
625 NUp = BSplS->LastUKnotIndex();
626 NLo = BSplS->FirstUKnotIndex();
631 NUp = BSplS->LastVKnotIndex();
632 NLo = BSplS->FirstVKnotIndex();
635 if((DComp > 0)&&(Abs(DComp)>Tol)) {
638 //limit case: Hunt() cought upper knot. Take the last span.
641 if(Index==1) { Tmp1=BSplS->UKnot(N);
642 Tmp2=BSplS->UKnot(N+1);}
644 if(Index==2) { Tmp1=BSplS->VKnot(N);
645 Tmp2=BSplS->VKnot(N+1);}
647 ReverseParam(Tmp1,Tmp2,Tmp1,Tmp2);
649 if(Index==1) { LeftBot.SetX(Tmp1);
650 RightTop.SetX(Tmp2);}
652 if(Index==2) { LeftBot.SetY(Tmp1);
653 RightTop.SetY(Tmp2);}
656 if((DComp < 0)&&(Abs(DComp)>Tol)){
659 //limit case: Hunt() cought lower knot. Take the first span.
662 if(Index==1) { Tmp1=BSplS->UKnot(N-1);
663 Tmp2=BSplS->UKnot(N);}
665 if(Index==2) { Tmp1=BSplS->VKnot(N-1);
666 Tmp2=BSplS->VKnot(N);}
668 ReverseParam(Tmp1,Tmp2,Tmp1,Tmp2);
670 if(Index==1) { LeftBot.SetX(Tmp1);
671 RightTop.SetX(Tmp2);}
673 if(Index==2) { LeftBot.SetY(Tmp1);
674 RightTop.SetY(Tmp2);}
680 //=======================================================================
681 //function : Adaptor3d_CurveOnSurface
683 //=======================================================================
685 Adaptor3d_CurveOnSurface::Adaptor3d_CurveOnSurface()
686 : myType(GeomAbs_OtherCurve), myIntCont(GeomAbs_CN)
689 //=======================================================================
690 //function : Adaptor3d_CurveOnSurface
692 //=======================================================================
694 Adaptor3d_CurveOnSurface::Adaptor3d_CurveOnSurface
695 (const Handle(Adaptor3d_HSurface)& S)
696 : myType(GeomAbs_OtherCurve), myIntCont(GeomAbs_CN)
701 //=======================================================================
702 //function : Adaptor3d_CurveOnSurface
704 //=======================================================================
706 Adaptor3d_CurveOnSurface::Adaptor3d_CurveOnSurface
707 (const Handle(Adaptor2d_HCurve2d)& C,
708 const Handle(Adaptor3d_HSurface)& S)
709 : myType(GeomAbs_OtherCurve), myIntCont(GeomAbs_CN)
715 //=======================================================================
718 //=======================================================================
720 void Adaptor3d_CurveOnSurface::Load(const Handle(Adaptor3d_HSurface)& S)
723 if (!myCurve.IsNull()) EvalKPart();
726 //=======================================================================
729 //=======================================================================
731 void Adaptor3d_CurveOnSurface::Load(const Handle(Adaptor2d_HCurve2d)& C)
734 if (!mySurface.IsNull())
737 GeomAbs_SurfaceType SType ;
738 SType = mySurface->GetType();
739 if( SType == GeomAbs_BSplineSurface)
741 if( SType == GeomAbs_SurfaceOfExtrusion)
743 if( SType == GeomAbs_SurfaceOfRevolution)
745 if( SType == GeomAbs_OffsetSurface) {
746 SType = mySurface->BasisSurface()->GetType();
747 if( SType == GeomAbs_SurfaceOfRevolution ||
748 SType == GeomAbs_SurfaceOfExtrusion ||
749 SType == GeomAbs_BSplineSurface )
755 //=======================================================================
756 //function : FirstParameter
758 //=======================================================================
760 Standard_Real Adaptor3d_CurveOnSurface::FirstParameter() const
762 return myCurve->FirstParameter();
765 //=======================================================================
766 //function : LastParameter
768 //=======================================================================
770 Standard_Real Adaptor3d_CurveOnSurface::LastParameter() const
772 return myCurve->LastParameter();
775 //=======================================================================
776 //function : Continuity
778 //=======================================================================
780 GeomAbs_Shape Adaptor3d_CurveOnSurface::Continuity() const
782 GeomAbs_Shape ContC = myCurve->Continuity();
783 GeomAbs_Shape ContSu = mySurface->UContinuity();
784 if ( ContSu < ContC) ContC = ContSu;
785 GeomAbs_Shape ContSv = mySurface->VContinuity();
786 if ( ContSv < ContC) ContC = ContSv;
791 //=======================================================================
792 //function : NbIntervals
794 //=======================================================================
796 Standard_Integer Adaptor3d_CurveOnSurface::NbIntervals
797 (const GeomAbs_Shape S)
799 if(S == myIntCont && !myIntervals.IsNull())
800 return myIntervals->Length()-1;
802 Standard_Integer nu,nv,nc,i;
803 nu=mySurface->NbUIntervals(S);
804 nv=mySurface->NbVIntervals(S);
805 Handle(TColStd_HSetOfReal) tmpIntervals = new TColStd_HSetOfReal;
806 TColStd_SetIteratorOfSetOfReal It;
807 TColStd_Array1OfReal TabU(1,nu+1);
808 TColStd_Array1OfReal TabV(1,nv+1);
809 Standard_Integer NbSample = 20;
810 Standard_Real U,V,Tdeb,Tfin;
811 Tdeb=myCurve->FirstParameter();
812 Tfin=myCurve->LastParameter();
813 nc=myCurve->NbIntervals(S);
814 TColStd_Array1OfReal TabC(1,nc+1);
815 myCurve->Intervals(TabC,S);
816 Standard_Real Tol= Precision::PConfusion()/10;
817 for (i=1;i<=nc+1;i++)
818 {tmpIntervals->Add(TabC(i));}
820 Standard_Integer nbpoint=nc+1;
822 { mySurface->UIntervals(TabU,S);
823 for(Standard_Integer iu = 2;iu <= nu; iu++)
824 { U = TabU.Value(iu);
825 Adaptor3d_InterFunc Func(myCurve,U,1);
826 math_FunctionRoots Resol(Func,Tdeb,Tfin,NbSample,Tol,Tol,Tol,0.);
828 { if (!Resol.IsAllNull())
829 { Standard_Integer nsol=Resol.NbSolutions();
830 for ( i=1;i<=nsol;i++)
831 { Standard_Real param =Resol.Value(i);
832 { Standard_Boolean insere=Standard_True;
833 for (It.Initialize(tmpIntervals->Set());It.More();It.Next())
834 { if (Abs(param- It.Value())<=Tol)
835 insere=Standard_False;}
838 tmpIntervals->Add(param);}
847 { mySurface->VIntervals(TabV,S);
848 for(Standard_Integer iv = 2;iv <= nv; iv++)
849 { V = TabV.Value(iv);
850 Adaptor3d_InterFunc Func(myCurve,V,2);
851 math_FunctionRoots Resol(Func,Tdeb,Tfin,NbSample,Tol,Tol,Tol,0.);
853 { if (!Resol.IsAllNull())
854 { Standard_Integer nsol=Resol.NbSolutions();
855 for ( i=1;i<=nsol;i++)
856 { Standard_Real param =Resol.Value(i);
857 { Standard_Boolean insere=Standard_True;
858 for (It.Initialize(tmpIntervals->Set());It.More();It.Next())
859 { if (Abs(param- It.Value())<=Tol)
860 insere=Standard_False;}
863 tmpIntervals->Add(param);}
871 // for case intervals==1 and first point == last point SetOfReal
872 // contains only one value, therefore it is necessary to add second
873 // value into myIntervals which will be equal first value.
874 myIntervals = new TColStd_HArray1OfReal(1,nbpoint);
876 for (It.Initialize(tmpIntervals->Set());It.More();It.Next())
879 myIntervals->SetValue(i,It.Value());
882 myIntervals->SetValue(2,myIntervals->Value(1));
888 //=======================================================================
889 //function : Intervals
891 //=======================================================================
893 void Adaptor3d_CurveOnSurface::Intervals(TColStd_Array1OfReal& T,
894 const GeomAbs_Shape S)
897 for(Standard_Integer i=1; i<=myIntervals->Length(); i++) {
898 T(i) = myIntervals->Value(i);
900 TCollection_CompareOfReal comp;
901 SortTools_StraightInsertionSortOfReal::Sort(T,comp);
904 //=======================================================================
907 //=======================================================================
909 Handle(Adaptor3d_HCurve) Adaptor3d_CurveOnSurface::Trim
910 (const Standard_Real First,
911 const Standard_Real Last,
912 const Standard_Real Tol) const
914 Handle(Adaptor3d_HCurveOnSurface) HCS = new Adaptor3d_HCurveOnSurface();
915 HCS->ChangeCurve().Load(mySurface);
916 HCS->ChangeCurve().Load(myCurve->Trim(First,Last,Tol));
920 //=======================================================================
921 //function : IsClosed
923 //=======================================================================
925 Standard_Boolean Adaptor3d_CurveOnSurface::IsClosed() const
927 return myCurve->IsClosed();
930 //=======================================================================
931 //function : IsPeriodic
933 //=======================================================================
935 Standard_Boolean Adaptor3d_CurveOnSurface::IsPeriodic() const
937 return myCurve->IsPeriodic();
940 //=======================================================================
943 //=======================================================================
945 Standard_Real Adaptor3d_CurveOnSurface::Period() const
947 return myCurve->Period();
950 //=======================================================================
953 //=======================================================================
955 gp_Pnt Adaptor3d_CurveOnSurface::Value(const Standard_Real U ) const
960 if (myType == GeomAbs_Line ) P = ElCLib::Value(U,myLin );
961 else if (myType == GeomAbs_Circle) P = ElCLib::Value(U,myCirc);
964 mySurface->D0(Puv.X(),Puv.Y(),P);
970 //=======================================================================
973 //=======================================================================
975 void Adaptor3d_CurveOnSurface::D0(const Standard_Real U ,
980 if (myType == GeomAbs_Line ) P = ElCLib::Value(U,myLin );
981 else if (myType == GeomAbs_Circle) P = ElCLib::Value(U,myCirc);
984 mySurface->D0(Puv.X(),Puv.Y(),P);
990 //=======================================================================
993 //=======================================================================
995 void Adaptor3d_CurveOnSurface::D1(const Standard_Real U ,
1003 Standard_Real FP = myCurve->FirstParameter();
1004 Standard_Real LP = myCurve->LastParameter();
1006 Standard_Real Tol= Precision::PConfusion()/10;
1007 if( ( Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
1009 myCurve->D1(U,Puv,Duv);
1010 myFirstSurf->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1011 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1014 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
1016 myCurve->D1(U,Puv,Duv);
1017 myLastSurf->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1018 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1021 if (myType == GeomAbs_Line ) ElCLib::D1(U,myLin ,P,V);
1022 else if (myType == GeomAbs_Circle) ElCLib::D1(U,myCirc,P,V);
1024 myCurve->D1(U,Puv,Duv);
1025 mySurface->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1026 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1029 //=======================================================================
1032 //=======================================================================
1034 void Adaptor3d_CurveOnSurface::D2(const Standard_Real U,
1041 gp_Vec D1U,D1V,D2U,D2V,D2UV;
1043 Standard_Real FP = myCurve->FirstParameter();
1044 Standard_Real LP = myCurve->LastParameter();
1046 Standard_Real Tol= Precision::PConfusion()/10;
1047 if( (Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
1049 myCurve->D2(U,UV,DW,D2W);
1050 myFirstSurf->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
1052 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1053 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1054 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1057 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
1059 myCurve->D2(U,UV,DW,D2W);
1060 myLastSurf->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
1062 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1063 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1064 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1067 if (myType == GeomAbs_Line ) {
1068 ElCLib::D1(U,myLin,P,V1);
1069 V2.SetCoord(0.,0.,0.);
1071 else if (myType == GeomAbs_Circle) ElCLib::D2(U,myCirc,P,V1,V2);
1073 myCurve->D2(U,UV,DW,D2W);
1074 mySurface->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
1076 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1077 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1078 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1082 //=======================================================================
1085 //=======================================================================
1087 void Adaptor3d_CurveOnSurface::D3
1088 (const Standard_Real U,
1095 Standard_Real Tol= Precision::PConfusion()/10;
1097 gp_Vec2d DW,D2W,D3W;
1098 gp_Vec D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV;
1100 Standard_Real FP = myCurve->FirstParameter();
1101 Standard_Real LP = myCurve->LastParameter();
1103 if( (Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
1104 { myCurve->D3(U,UV,DW,D2W,D3W);
1105 myFirstSurf->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
1106 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1107 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1108 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1109 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1112 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
1113 { myCurve->D3(U,UV,DW,D2W,D3W);
1114 myLastSurf->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
1115 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1117 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1118 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1119 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1122 if (myType == GeomAbs_Line ) {
1123 ElCLib::D1(U,myLin,P,V1);
1124 V2.SetCoord(0.,0.,0.);
1125 V3.SetCoord(0.,0.,0.);
1127 else if (myType == GeomAbs_Circle) ElCLib::D3(U,myCirc,P,V1,V2,V3);
1129 myCurve->D3(U,UV,DW,D2W,D3W);
1130 mySurface->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
1131 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1133 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1134 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1135 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1140 //=======================================================================
1143 //=======================================================================
1145 gp_Vec Adaptor3d_CurveOnSurface::DN
1146 (const Standard_Real U,
1147 const Standard_Integer N) const
1162 Standard_NotImplemented::Raise("Adaptor3d_CurveOnSurface:DN");
1169 //=======================================================================
1170 //function : Resolution
1172 //=======================================================================
1174 Standard_Real Adaptor3d_CurveOnSurface::Resolution
1175 (const Standard_Real R3d) const
1177 Standard_Real ru,rv;
1178 ru = mySurface->UResolution(R3d);
1179 rv = mySurface->VResolution(R3d);
1180 return myCurve->Resolution(Min(ru,rv));
1184 //=======================================================================
1185 //function : GetType
1187 //=======================================================================
1189 GeomAbs_CurveType Adaptor3d_CurveOnSurface::GetType() const
1195 //=======================================================================
1198 //=======================================================================
1200 gp_Lin Adaptor3d_CurveOnSurface::Line() const
1202 Standard_NoSuchObject_Raise_if(myType != GeomAbs_Line, "Adaptor3d_CurveOnSurface::Line(): curve is not a line")
1206 //=======================================================================
1209 //=======================================================================
1211 gp_Circ Adaptor3d_CurveOnSurface::Circle() const
1213 Standard_NoSuchObject_Raise_if(myType != GeomAbs_Circle, "Adaptor3d_CurveOnSurface::Line(): curve is not a circle")
1217 //=======================================================================
1218 //function : Ellipse
1220 //=======================================================================
1222 gp_Elips Adaptor3d_CurveOnSurface::Ellipse() const
1224 return to3d(mySurface->Plane(),myCurve->Ellipse());
1227 //=======================================================================
1228 //function : Hyperbola
1230 //=======================================================================
1232 gp_Hypr Adaptor3d_CurveOnSurface::Hyperbola() const
1234 return to3d(mySurface->Plane(),myCurve->Hyperbola());
1237 //=======================================================================
1238 //function : Parabola
1240 //=======================================================================
1242 gp_Parab Adaptor3d_CurveOnSurface::Parabola() const
1244 return to3d(mySurface->Plane(),myCurve->Parabola());
1247 Standard_Integer Adaptor3d_CurveOnSurface::Degree() const
1250 // on a parametric surface should multiply
1251 // return TheCurve2dTool::Degree(myCurve);
1253 return myCurve->Degree();
1256 //=======================================================================
1257 //function : IsRational
1259 //=======================================================================
1261 Standard_Boolean Adaptor3d_CurveOnSurface::IsRational() const
1263 return ( myCurve->IsRational() ||
1264 mySurface->IsURational() ||
1265 mySurface->IsVRational() );
1268 //=======================================================================
1269 //function : NbPoles
1271 //=======================================================================
1273 Standard_Integer Adaptor3d_CurveOnSurface::NbPoles() const
1275 // on a parametric surface should multiply
1276 return myCurve->NbPoles();
1279 //=======================================================================
1280 //function : NbKnots
1282 //=======================================================================
1284 Standard_Integer Adaptor3d_CurveOnSurface::NbKnots() const {
1285 if (mySurface->GetType()==GeomAbs_Plane)
1286 return myCurve->NbKnots();
1288 Standard_NoSuchObject::Raise();
1293 //=======================================================================
1296 //=======================================================================
1298 Handle(Geom_BezierCurve) Adaptor3d_CurveOnSurface::Bezier() const
1300 Standard_NoSuchObject_Raise_if
1301 ( mySurface->GetType() != GeomAbs_Plane,
1302 "Adaptor3d_CurveOnSurface : Bezier");
1304 Handle(Geom2d_BezierCurve) Bez2d = myCurve->Bezier();
1305 Standard_Integer NbPoles = Bez2d->NbPoles();
1307 const gp_Pln& Plane = mySurface->Plane();
1309 TColgp_Array1OfPnt Poles(1,NbPoles);
1310 for ( Standard_Integer i=1; i<= NbPoles; i++) {
1311 Poles(i) = to3d( Plane, Bez2d->Pole(i));
1313 Handle(Geom_BezierCurve) Bez;
1315 if (Bez2d->IsRational()) {
1316 TColStd_Array1OfReal Weights(1,NbPoles);
1317 Bez2d->Weights(Weights);
1318 Bez = new Geom_BezierCurve(Poles,Weights);
1321 Bez = new Geom_BezierCurve(Poles);
1326 //=======================================================================
1327 //function : BSpline
1329 //=======================================================================
1331 Handle(Geom_BSplineCurve) Adaptor3d_CurveOnSurface::BSpline() const
1333 Standard_NoSuchObject_Raise_if
1334 ( mySurface->GetType() != GeomAbs_Plane,
1335 "Adaptor3d_CurveOnSurface : BSpline");
1337 Handle(Geom2d_BSplineCurve) Bsp2d = myCurve->BSpline();
1338 Standard_Integer NbPoles = Bsp2d->NbPoles();
1340 const gp_Pln& Plane = mySurface->Plane();
1342 TColgp_Array1OfPnt Poles(1,NbPoles);
1343 for ( Standard_Integer i=1; i<= NbPoles; i++) {
1344 Poles(i) = to3d( Plane, Bsp2d->Pole(i));
1347 TColStd_Array1OfReal Knots(1,Bsp2d->NbKnots());
1348 TColStd_Array1OfInteger Mults(1,Bsp2d->NbKnots());
1349 Bsp2d->Knots(Knots);
1350 Bsp2d->Multiplicities(Mults);
1352 Handle(Geom_BSplineCurve) Bsp;
1354 if (Bsp2d->IsRational()) {
1355 TColStd_Array1OfReal Weights(1,NbPoles);
1356 Bsp2d->Weights(Weights);
1357 Bsp = new Geom_BSplineCurve(Poles,Weights,Knots,Mults,
1359 Bsp2d->IsPeriodic());
1362 Bsp = new Geom_BSplineCurve(Poles,Knots,Mults,
1364 Bsp2d->IsPeriodic());
1369 //=======================================================================
1370 //function : GetCurve
1372 //=======================================================================
1374 const Handle(Adaptor2d_HCurve2d)& Adaptor3d_CurveOnSurface::GetCurve() const
1379 //=======================================================================
1380 //function : GetSurface
1382 //=======================================================================
1384 const Handle(Adaptor3d_HSurface)& Adaptor3d_CurveOnSurface::GetSurface() const
1389 //=======================================================================
1390 //function : ChangeCurve
1392 //=======================================================================
1394 Handle(Adaptor2d_HCurve2d)& Adaptor3d_CurveOnSurface::ChangeCurve()
1399 //=======================================================================
1400 //function : ChangeSurface
1402 //=======================================================================
1404 Handle(Adaptor3d_HSurface)& Adaptor3d_CurveOnSurface::ChangeSurface() {
1408 //=======================================================================
1409 //function : EvalKPart
1411 //=======================================================================
1413 void Adaptor3d_CurveOnSurface::EvalKPart()
1415 myType = GeomAbs_OtherCurve;
1417 GeomAbs_SurfaceType STy = mySurface->GetType();
1418 GeomAbs_CurveType CTy = myCurve->GetType();
1419 if (STy == GeomAbs_Plane) {
1421 if (myType == GeomAbs_Circle)
1422 myCirc = to3d(mySurface->Plane(),myCurve->Circle());
1423 else if (myType == GeomAbs_Line) {
1428 myCurve->D1(0.,Puv,Duv);
1430 mySurface->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1431 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1432 myLin = gp_Lin(P,V);
1436 if ( CTy == GeomAbs_Line) {
1437 gp_Dir2d D = myCurve->Line().Direction();
1438 if ( D.IsParallel(gp::DX2d(),Precision::Angular())) { // Iso V.
1439 if ( STy == GeomAbs_Sphere) {
1440 gp_Pnt2d P = myCurve->Line().Location();
1441 if ( Abs( Abs(P.Y()) -M_PI/2. ) >= Precision::PConfusion()) {
1442 myType = GeomAbs_Circle;
1443 gp_Sphere Sph = mySurface->Sphere();
1444 gp_Ax3 Axis = Sph.Position();
1445 myCirc = ElSLib::SphereVIso(Axis,
1448 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1449 gp_Ax1 AxeRev(Axis.Location(), DRev);
1450 myCirc.Rotate(AxeRev, P.X());
1451 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1452 gp_Ax2 Ax = myCirc.Position();
1453 Ax.SetDirection(Ax.Direction().Reversed());
1454 myCirc.SetPosition(Ax);
1458 else if ( STy == GeomAbs_Cylinder) {
1459 myType = GeomAbs_Circle;
1460 gp_Cylinder Cyl = mySurface->Cylinder();
1461 gp_Pnt2d P = myCurve->Line().Location();
1462 gp_Ax3 Axis = Cyl.Position();
1463 myCirc = ElSLib::CylinderVIso(Axis,
1466 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1467 gp_Ax1 AxeRev(Axis.Location(), DRev);
1468 myCirc.Rotate(AxeRev, P.X());
1469 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1470 gp_Ax2 Ax = myCirc.Position();
1471 Ax.SetDirection(Ax.Direction().Reversed());
1472 myCirc.SetPosition(Ax);
1475 else if ( STy == GeomAbs_Cone) {
1476 myType = GeomAbs_Circle;
1477 gp_Cone Cone = mySurface->Cone();
1478 gp_Pnt2d P = myCurve->Line().Location();
1479 gp_Ax3 Axis = Cone.Position();
1480 myCirc = ElSLib::ConeVIso(Axis,
1484 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1485 gp_Ax1 AxeRev(Axis.Location(), DRev);
1486 myCirc.Rotate(AxeRev, P.X());
1487 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1488 gp_Ax2 Ax = myCirc.Position();
1489 Ax.SetDirection(Ax.Direction().Reversed());
1490 myCirc.SetPosition(Ax);
1493 else if ( STy == GeomAbs_Torus) {
1494 myType = GeomAbs_Circle;
1495 gp_Torus Tore = mySurface->Torus();
1496 gp_Pnt2d P = myCurve->Line().Location();
1497 gp_Ax3 Axis = Tore.Position();
1498 myCirc = ElSLib::TorusVIso(Axis,
1502 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1503 gp_Ax1 AxeRev(Axis.Location(), DRev);
1504 myCirc.Rotate(AxeRev, P.X());
1505 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1506 gp_Ax2 Ax = myCirc.Position();
1507 Ax.SetDirection(Ax.Direction().Reversed());
1508 myCirc.SetPosition(Ax);
1512 else if ( D.IsParallel(gp::DY2d(),Precision::Angular())) { // Iso U.
1513 if ( STy == GeomAbs_Sphere) {
1514 myType = GeomAbs_Circle;
1515 gp_Sphere Sph = mySurface->Sphere();
1516 gp_Pnt2d P = myCurve->Line().Location();
1517 gp_Ax3 Axis = Sph.Position();
1518 // calcul de l'iso 0.
1519 myCirc = ElSLib::SphereUIso(Axis, Sph.Radius(),0.);
1521 // mise a sameparameter (rotation du cercle - decalage du Y)
1522 gp_Dir DRev = Axis.XDirection().Crossed(Axis. Direction());
1523 gp_Ax1 AxeRev(Axis.Location(),DRev);
1524 myCirc.Rotate(AxeRev, P.Y());
1526 // transformation en iso U ( = P.X())
1527 DRev = Axis.XDirection().Crossed(Axis.YDirection());
1528 AxeRev = gp_Ax1(Axis.Location(), DRev);
1529 myCirc.Rotate(AxeRev, P.X());
1531 if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) {
1532 gp_Ax2 Ax = myCirc.Position();
1533 Ax.SetDirection(Ax.Direction().Reversed());
1534 myCirc.SetPosition(Ax);
1537 else if ( STy == GeomAbs_Cylinder) {
1538 myType = GeomAbs_Line;
1539 gp_Cylinder Cyl = mySurface->Cylinder();
1540 gp_Pnt2d P = myCurve->Line().Location();
1541 myLin = ElSLib::CylinderUIso(Cyl.Position(),
1544 gp_Vec Tr(myLin.Direction());
1546 myLin.Translate(Tr);
1547 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
1550 else if ( STy == GeomAbs_Cone) {
1551 myType = GeomAbs_Line;
1552 gp_Cone Cone = mySurface->Cone();
1553 gp_Pnt2d P = myCurve->Line().Location();
1554 myLin = ElSLib::ConeUIso(Cone.Position(),
1558 gp_Vec Tr(myLin.Direction());
1560 myLin.Translate(Tr);
1561 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
1564 else if ( STy == GeomAbs_Torus) {
1565 myType = GeomAbs_Circle;
1566 gp_Torus Tore = mySurface->Torus();
1567 gp_Pnt2d P = myCurve->Line().Location();
1568 gp_Ax3 Axis = Tore.Position();
1569 myCirc = ElSLib::TorusUIso(Axis,
1573 myCirc.Rotate(myCirc.Axis(),P.Y());
1575 if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) {
1576 gp_Ax2 Ax = myCirc.Position();
1577 Ax.SetDirection(Ax.Direction().Reversed());
1578 myCirc.SetPosition(Ax);
1585 //=======================================================================
1586 //function :EvalFirstLastSurf
1588 //=======================================================================
1590 void Adaptor3d_CurveOnSurface::EvalFirstLastSurf()
1592 Standard_Real FirstPar,LastPar;
1593 gp_Pnt2d UV, LeftBot, RightTop;
1595 Standard_Real Tol= Precision::PConfusion()/10;
1596 Standard_Boolean Ok = Standard_True;
1599 FirstPar=myCurve->FirstParameter();
1600 myCurve->D1(FirstPar,UV,DUV);
1602 if(DUV.Magnitude() <= Tol) Ok = Standard_False;
1606 switch(mySurface->GetType()) {
1607 case GeomAbs_BSplineSurface :
1608 LocatePart(UV,DUV,mySurface,LeftBot,RightTop);
1610 case GeomAbs_SurfaceOfRevolution :
1611 case GeomAbs_SurfaceOfExtrusion :
1612 Ok = LocatePart_RevExt(UV,DUV,mySurface,LeftBot,RightTop);
1614 case GeomAbs_OffsetSurface :
1615 Ok = LocatePart_Offset(UV,DUV,mySurface,LeftBot,RightTop);
1618 Standard_NotImplemented::Raise("Adaptor3d_CurveOnSurface::EvalFirstLastSurf");
1625 CompareBounds(LeftBot,RightTop); //SVV
1627 myFirstSurf = mySurface->UTrim(LeftBot.X(),RightTop.X(),Tol);
1628 myFirstSurf = myFirstSurf->VTrim(LeftBot.Y(),RightTop.Y(),Tol);
1632 myFirstSurf = mySurface;
1635 LastPar=myCurve->LastParameter();
1637 myCurve->D1(LastPar,UV,DUV);
1638 DUV.Reverse(); //We want the other part
1640 if(DUV.Magnitude() <= Tol) Ok = Standard_False;
1644 switch(mySurface->GetType()) {
1645 case GeomAbs_BSplineSurface :
1646 LocatePart(UV,DUV,mySurface,LeftBot,RightTop);
1648 case GeomAbs_SurfaceOfRevolution :
1649 case GeomAbs_SurfaceOfExtrusion :
1650 Ok = LocatePart_RevExt(UV,DUV,mySurface,LeftBot,RightTop);
1652 case GeomAbs_OffsetSurface :
1653 Ok = LocatePart_Offset(UV,DUV,mySurface,LeftBot,RightTop);
1656 Standard_NotImplemented::Raise("Adaptor3d_CurveOnSurface::EvalFirstLastSurf");
1663 CompareBounds(LeftBot, RightTop); //SVV
1665 myLastSurf = mySurface->UTrim(LeftBot.X(),RightTop.X(),Tol);
1666 myLastSurf = myLastSurf->VTrim(LeftBot.Y(),RightTop.Y(),Tol);
1670 myLastSurf = mySurface;
1674 //=======================================================================
1675 //function :LocatePart_RevExt
1676 //purpose : processes Knots
1677 //=======================================================================
1679 Standard_Boolean Adaptor3d_CurveOnSurface::LocatePart_RevExt(const gp_Pnt2d& UV,
1680 const gp_Vec2d& DUV,
1681 const Handle(Adaptor3d_HSurface)& S,
1683 gp_Pnt2d& RightTop) const
1685 Handle(Adaptor3d_HCurve) AHC = S->BasisCurve();
1687 if (AHC->GetType() == GeomAbs_BSplineCurve) {
1688 Handle( Geom_BSplineCurve) BSplC;
1689 BSplC = AHC->BSpline();
1691 if((S->GetType())==GeomAbs_SurfaceOfExtrusion) {
1692 Locate1Coord(1,UV,DUV,BSplC,LeftBot,RightTop);
1693 Locate2Coord(2,UV,DUV,S->FirstVParameter(),S->LastVParameter(),LeftBot,RightTop);
1695 else if((S->GetType())==GeomAbs_SurfaceOfRevolution) {
1696 Locate1Coord(2,UV,DUV,BSplC,LeftBot,RightTop);
1697 Locate2Coord(1,UV,DUV,S->FirstUParameter(),S->LastUParameter(),LeftBot,RightTop);
1700 Standard_Real u1,u2,v1,v2;
1701 ReverseParam(LeftBot.X(),RightTop.X(),u1,u2);
1704 ReverseParam(LeftBot.Y(),RightTop.Y(),v1,v2);
1707 return Standard_True;
1709 return Standard_False;
1712 //=======================================================================
1713 //function :LocatePart_OffsetSurface
1715 //=======================================================================
1717 Standard_Boolean Adaptor3d_CurveOnSurface::
1718 LocatePart_Offset(const gp_Pnt2d& UV, const gp_Vec2d& DUV,
1719 const Handle(Adaptor3d_HSurface)& S,
1720 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop) const
1722 Standard_Boolean Ok = Standard_True;
1723 Handle( Adaptor3d_HSurface) AHS;
1724 Handle( Geom_BSplineSurface) BSplS;
1725 AHS = S->BasisSurface();
1726 GeomAbs_SurfaceType BasisSType = AHS->GetType();
1727 switch(BasisSType) {
1728 case GeomAbs_SurfaceOfRevolution:
1729 case GeomAbs_SurfaceOfExtrusion :
1730 Ok = LocatePart_RevExt(UV,DUV,AHS,LeftBot,RightTop);
1733 case GeomAbs_BSplineSurface:
1734 LocatePart(UV,DUV,AHS,LeftBot,RightTop);
1743 //=======================================================================
1744 //function :LocatePart
1745 //purpose : for BSplineSurface
1746 //=======================================================================
1748 void Adaptor3d_CurveOnSurface::LocatePart(const gp_Pnt2d& UV, const gp_Vec2d& DUV,
1749 const Handle(Adaptor3d_HSurface)& S,
1750 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop) const
1752 Handle( Geom_BSplineSurface) BSplS;
1753 BSplS = S->BSpline();
1754 Standard_Boolean DUIsNull=Standard_False,
1755 DVIsNull=Standard_False;
1757 Locate1Coord(1,UV,DUV,BSplS,DUIsNull,LeftBot,RightTop);
1758 Locate1Coord(2,UV,DUV,BSplS,DVIsNull,LeftBot,RightTop);
1760 if((DUIsNull==Standard_True)&&(DVIsNull==Standard_False)) {
1761 TColStd_Array1OfReal ArrU(1,BSplS->NbUKnots());
1762 BSplS->UKnots(ArrU);
1763 Locate2Coord(1,UV,DUV,BSplS,ArrU,LeftBot,RightTop);
1765 else if((DVIsNull==Standard_True)&&(DUIsNull==Standard_False)) {
1766 TColStd_Array1OfReal ArrV(1,BSplS->NbVKnots());
1767 BSplS->VKnots(ArrV);
1768 Locate2Coord(2,UV,DUV,BSplS,ArrV,LeftBot,RightTop);