1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #define No_Standard_OutOfRange
16 #include <Adaptor3d_CurveOnSurface.ixx>
18 #include <Adaptor3d_HCurveOnSurface.hxx>
19 #include <gp_Pnt2d.hxx>
20 #include <gp_Vec2d.hxx>
21 #include <gp_Ax22d.hxx>
22 #include <gp_Lin2d.hxx>
23 #include <gp_Circ2d.hxx>
24 #include <gp_Elips2d.hxx>
25 #include <gp_Hypr2d.hxx>
26 #include <gp_Parab2d.hxx>
27 #include <Geom_BSplineSurface.hxx>
28 #include <Geom_SurfaceOfRevolution.hxx>
29 #include <Geom_SurfaceOfLinearExtrusion.hxx>
30 #include <Geom_OffsetSurface.hxx>
31 #include <Geom2d_BezierCurve.hxx>
32 #include <Geom2d_BSplineCurve.hxx>
33 #include <Precision.hxx>
34 #include <Standard_Assert.hxx>
35 #include <TColgp_Array1OfPnt2d.hxx>
36 #include <TColgp_Array1OfPnt.hxx>
37 #include <TColStd_Array1OfReal.hxx>
38 #include <TColStd_Array1OfInteger.hxx>
39 #include <TColStd_HSequenceOfReal.hxx>
40 #include <Standard_NotImplemented.hxx>
43 #include <Adaptor3d_InterFunc.hxx>
44 #include <math_FunctionRoots.hxx>
47 static gp_Pnt to3d(const gp_Pln& Pl, const gp_Pnt2d& P)
49 return ElSLib::Value(P.X(),P.Y(),Pl);
52 static gp_Vec to3d(const gp_Pln& Pl, const gp_Vec2d& V)
54 gp_Vec Vx = Pl.XAxis().Direction();
55 gp_Vec Vy = Pl.YAxis().Direction();
62 static gp_Ax2 to3d(const gp_Pln& Pl, const gp_Ax22d& A)
64 gp_Pnt P = to3d(Pl,A.Location());
65 gp_Vec VX = to3d(Pl,A.XAxis().Direction());
66 gp_Vec VY = to3d(Pl,A.YAxis().Direction());
67 return gp_Ax2(P,VX.Crossed(VY),VX);
70 static gp_Circ to3d(const gp_Pln& Pl, const gp_Circ2d& C)
72 return gp_Circ(to3d(Pl,C.Axis()),C.Radius());
75 static gp_Elips to3d(const gp_Pln& Pl, const gp_Elips2d& E)
77 return gp_Elips(to3d(Pl,E.Axis()),E.MajorRadius(),E.MinorRadius());
80 static gp_Hypr to3d(const gp_Pln& Pl, const gp_Hypr2d& H)
82 return gp_Hypr(to3d(Pl,H.Axis()),H.MajorRadius(),H.MinorRadius());
85 static gp_Parab to3d(const gp_Pln& Pl, const gp_Parab2d& P)
87 return gp_Parab(to3d(Pl,P.Axis()),P.Focal());
90 static gp_Vec SetLinearForm(const gp_Vec2d DW, const gp_Vec2d D2W,const gp_Vec2d D3W,
91 const gp_Vec D1U, const gp_Vec D1V, const gp_Vec D2U,
92 const gp_Vec D2V, const gp_Vec D2UV, const gp_Vec D3U,
93 const gp_Vec D3V, const gp_Vec D3UUV,const gp_Vec D3UVV)
94 {gp_Vec V31, V32, V33, V34,V3 ;
95 V31.SetLinearForm(DW.X(),D1U,
98 V31.SetLinearForm(D3W.Y(),D1V,
102 V32.SetLinearForm(DW.X()*DW.X()*DW.Y(),D3UUV,
103 DW.X()*DW.Y()*DW.Y(),D3UVV);
104 V32.SetLinearForm(D2W.X()*DW.Y()+DW.X()*D2W.Y(),D2UV,
105 DW.X()*DW.Y()*DW.Y(),D3UVV,
107 V33.SetLinearForm(2*D2W.X()*DW.X(),D2U,
108 DW.X()*DW.X()*DW.X(),D3U,
109 DW.X()*DW.X()*DW.Y(),D3UUV);
111 V34.SetLinearForm(2*D2W.Y()*DW.Y(),D2V,
112 DW.Y()*DW.Y()*DW.X(),D3UVV,
113 DW.Y()*DW.Y()*DW.Y(),D3V);
114 V3.SetLinearForm(1,V31,2,V32,1,V33,V34);
118 //=======================================================================
119 static void CompareBounds(gp_Pnt2d& P1,
122 Standard_Real Lx = P1.X(),Ly = P1.Y();
123 Standard_Real Rx = P2.X(),Ry = P2.Y();
125 if (Lx > Rx) { P1.SetX(Rx); P2.SetX(Lx);}
126 if (Ly > Ry) { P1.SetY(Ry); P2.SetY(Ly);}
129 //=======================================================================
132 //=======================================================================
133 static void Hunt(const TColStd_Array1OfReal& Arr,
134 const Standard_Real Coord,
135 Standard_Integer& Iloc)
136 {//Warning: Hunt is used to find number of knot which equals co-ordinate component,
137 // when co-ordinate component definitly equals a knot only.
138 Standard_Real Tol=Precision::PConfusion()/10;
139 Standard_Integer i=1;
140 while((i <= Arr.Upper()) && (Abs(Coord - Arr(i)) > Tol)){
143 if(Abs(Coord - Arr(i)) < Tol)
146 if(Abs(Coord - Arr(i)) > Tol)
147 Standard_NotImplemented::Raise("Adaptor3d_CurveOnSurface:Hunt");
150 //=======================================================================
151 //function :ReverseParam
153 //=======================================================================
155 static void ReverseParam(const Standard_Real In1,
156 const Standard_Real In2,
158 Standard_Real& Out2 )
161 if(In1>In2) {Out1=In2;
166 //=======================================================================
167 //function :ReverseParam
169 //=======================================================================
171 static void ReverseParam(const Standard_Integer In1,
172 const Standard_Integer In2,
173 Standard_Integer& Out1,
174 Standard_Integer& Out2 )
176 if(In1>In2) {Out1=In2;
182 //=======================================================================
183 //function :FindBounds
185 //=======================================================================
186 static void FindBounds(const TColStd_Array1OfReal& Arr,
187 const Standard_Real Coord,
188 const Standard_Real Der,
189 Standard_Integer& Bound1,
190 Standard_Integer& Bound2,
191 Standard_Boolean& DerNull)
194 Standard_Integer N=0;
195 Standard_Real Tol=Precision::PConfusion()/10;
197 DerNull=Standard_False;
199 if(N==Bound1){ if(Abs(Der) > Tol) DerNull = Standard_False;
200 if(Abs(Der)<= Tol) DerNull = Standard_True;
201 Bound1=N;Bound2=N+1; return;
203 if(N==Bound2){ if( Abs(Der) > Tol ) DerNull = Standard_False;
204 if( Abs(Der)<= Tol ) DerNull = Standard_True;
205 Bound1=N-1;Bound2=N; return;
207 if((N!=Bound1)&&(N!=Bound2)) {
208 if(Abs(Der) > Tol ) {
209 if(Der>0) {Bound1=N;Bound2= N+1;}
211 if(Der<0){Bound1=N-1;Bound2=N;}
212 DerNull = Standard_False;
214 if(Abs(Der) <=Tol ) {
215 DerNull = Standard_True;
222 //=======================================================================
223 //function :Locate1Coord
224 //purpose : along BSpline curve
225 //=======================================================================
227 static void Locate1Coord(const Standard_Integer Index,
230 const Handle(Geom_BSplineCurve)& BSplC,
231 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop)
233 Standard_Real Comp1=0, DComp1=0, cur, f = 0.0, l = 0.0;
234 Standard_Real Tol = Precision::PConfusion()/10;
235 Standard_Integer i = 1, Bnd1, Bnd2;
236 Standard_Boolean DIsNull= Standard_False;
237 TColStd_Array1OfReal Arr(1,BSplC->NbKnots()); BSplC->Knots(Arr);
239 if(Index==1) { Comp1=UV.X(); DComp1=DUV.X(); }
240 if(Index==2) { Comp1=UV.Y(); DComp1=DUV.Y(); }
242 Standard_Integer Lo = BSplC->FirstUKnotIndex(), Up = BSplC->LastUKnotIndex();
245 while ( ( Abs(BSplC->Knot(i)-Comp1)>Tol )&& (i!=Up ) ) i++;
248 if( Abs(Comp1-cur)<=Tol) {
250 Bnd1 = Lo; Bnd2 = Up;
251 FindBounds(Arr,cur,DComp1,Bnd1,Bnd2,DIsNull);
252 ReverseParam(Bnd1,Bnd2,Bnd1,Bnd2);
254 if(DIsNull==Standard_False){
255 if(Index==1) {LeftBot.SetX(BSplC->Knot(Bnd1));
256 RightTop.SetX(BSplC->Knot(Bnd2));}
258 if(Index==2){ LeftBot.SetY(BSplC->Knot(Bnd1));
259 RightTop.SetY(BSplC->Knot(Bnd2)); }
262 if(DIsNull==Standard_True){
263 if( Abs( Comp1-(f=BSplC->Knot(Lo))) <= Tol)
265 if(Index==1) { LeftBot.SetX(BSplC->Knot(Lo));
266 RightTop.SetX(BSplC->Knot(Lo+1));}
267 else if(Index==2) { LeftBot.SetY(BSplC->Knot(Lo));
268 RightTop.SetY(BSplC->Knot(Lo+1));}
270 if( Abs( Comp1-(l=BSplC->Knot(Up))) <= Tol)
272 if(Index==1) { LeftBot.SetX(BSplC->Knot(Up-1));
273 RightTop.SetX(BSplC->Knot(Up));}
274 else if(Index==2) {LeftBot.SetY(BSplC->Knot(Up-1));
275 RightTop.SetY(BSplC->Knot(Up));}
277 if(Index==1) { LeftBot.SetX(BSplC->Knot(Bnd1));
278 RightTop.SetX(BSplC->Knot(Bnd2));}
279 else if(Index==2) {LeftBot.SetY(BSplC->Knot(Bnd1));
280 RightTop.SetY(BSplC->Knot(Bnd2));}
283 else//*********if Coord != Knot
287 //if((f=BSplC->Knot(i))<Comp1 && (l=BSplC->Knot(i+1))>Comp1) break;
288 //skl 28.03.2002 for OCC233
291 if(f<Comp1 && l>Comp1) break;
294 ReverseParam(f,l,f,l);
298 { if(Index==1) {LeftBot.SetX(f); RightTop.SetX(l);}else
299 if(Index==2) {LeftBot.SetY(f); RightTop.SetY(l); }
304 if(DComp1>0) {LeftBot.SetX(Comp1); RightTop.SetX(l);} else
305 if(DComp1<0) {LeftBot.SetX(f); RightTop.SetX(Comp1);}
309 if(DComp1>0) {LeftBot.SetY(Comp1); RightTop.SetY(l);} else
310 if(DComp1<0) {LeftBot.SetY(f); RightTop.SetY(Comp1);};
315 if(Index==1) {LeftBot.SetX(Comp1); RightTop.SetX(BSplC->Knot(i));}else
316 if(Index==2) {LeftBot.SetY(Comp1); RightTop.SetY(BSplC->Knot(i)); }
322 //=======================================================================
323 //function :Locate1Coord
325 //=======================================================================
327 static void Locate1Coord(const Standard_Integer Index,
330 const Handle(Geom_BSplineSurface)& BSplS,
331 Standard_Boolean& DIsNull,
335 Standard_Real Comp1=0,DComp1=0;
336 Standard_Real Tol = Precision::PConfusion()/10;
337 Standard_Integer i=1, Up=0, Up1, Up2, Down=0, Down1, Down2;
338 Standard_Real cur = 0.;
340 DIsNull= Standard_False;
342 Up1 = BSplS->LastUKnotIndex();
343 Down1 = BSplS->FirstUKnotIndex();
344 Up2 = BSplS->LastVKnotIndex();
345 Down2 = BSplS->FirstVKnotIndex();
355 while ( ( Abs(BSplS->UKnot(i)-Comp1)>Tol )&&(i!=Up1 ) )
360 cur = BSplS->UKnot(i);
370 while ( ( Abs(BSplS->VKnot(i)-Comp1)>Tol )&&(i!=Up2 ) )
375 cur = BSplS->VKnot(i);
378 if( Abs(Comp1-cur)<=Tol )
380 Standard_Integer Bnd1 = Down, Bnd2 = Up;
383 TColStd_Array1OfReal Arr1(1,BSplS->NbUKnots());
384 BSplS->UKnots(Arr1); // Up1=Arr1.Upper(); Down1=Arr1.Lower();
385 FindBounds(Arr1,cur,DUV.X(),Bnd1,Bnd2,DIsNull);
389 TColStd_Array1OfReal Arr2(1,BSplS->NbVKnots());
390 BSplS->VKnots(Arr2); // Up2=Arr2.Upper(); Down2=Arr2.Lower();
391 FindBounds(Arr2,cur,DUV.Y(),Bnd1,Bnd2,DIsNull);
394 ReverseParam(Bnd1,Bnd2,Bnd1,Bnd2);
396 if(DIsNull==Standard_False)
400 LeftBot.SetX(BSplS->UKnot(Bnd1));
401 RightTop.SetX(BSplS->UKnot(Bnd2));
405 LeftBot.SetY(BSplS->VKnot(Bnd1));
406 RightTop.SetY(BSplS->VKnot(Bnd2));
410 else//*********if Coord != Knot
412 if( (Index==1)&&(Comp1 < BSplS->UKnot(Down)) )
414 LeftBot.SetX(BSplS->UKnot(Down));
415 RightTop.SetX( BSplS->UKnot(Down + 1) );
418 else if( (Index==2)&&(Comp1 < BSplS->VKnot(Down)) )
420 LeftBot.SetY(BSplS->VKnot(Down));
421 RightTop.SetY( BSplS->VKnot(Down + 1) );
424 else if( (Index==1)&&(Comp1 > BSplS->UKnot(Up)) )
426 RightTop.SetX(BSplS->UKnot(Up - 1));
427 LeftBot.SetX( BSplS->UKnot(Up) );
430 else if( (Index==2)&&(Comp1 > BSplS->VKnot(Up)) )
432 RightTop.SetY(BSplS->VKnot(Up - 1));
433 LeftBot.SetY( BSplS->VKnot(Up) );
438 Standard_Real f = 0., l = 1.;
441 f=BSplS->UKnot(Down);
446 f=BSplS->VKnot(Down);
451 if ((!(Comp1 < f))&&(!(Comp1 > l)))
455 while (!(((f=BSplS->UKnot(i)) < Comp1)&&((l=BSplS->UKnot(i+1)) > Comp1)) && (i<Up))
462 while (!(((f=BSplS->VKnot(i)) < Comp1)&&((l=BSplS->VKnot(i+1)) > Comp1)) && (i<Up))
469 ReverseParam(f,l,f,l);
485 RightTop.SetX(Comp1);
498 RightTop.SetY(Comp1);
524 RightTop.SetX(BSplS->UKnot(i));
529 RightTop.SetY(BSplS->VKnot(i));
535 //=======================================================================
536 //function :Locate2Coord
537 //purpose : along non-BSpline curve
538 //=======================================================================
541 static void Locate2Coord(const Standard_Integer Index,
542 const gp_Pnt2d& UV, const gp_Vec2d& DUV,
543 const Standard_Real I1,
544 const Standard_Real I2,
545 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop)
547 Standard_Real Tol=Precision::PConfusion()/10;
548 Standard_Real Comp1=0,DComp1=0;
549 if(Index==1) { Comp1=UV.X();
552 if(Index==2) {Comp1=UV.Y();
555 if((Comp1!=I1)&&(Comp1!=I2))
556 { if(Abs(DComp1) > Tol)
558 { if(Index==1) { LeftBot.SetX(I1);
559 RightTop.SetX(Comp1);}
560 if(Index==2) { LeftBot.SetY(I1);
561 RightTop.SetY(Comp1);}
565 { if(Index==1) { LeftBot.SetX(Comp1);
567 if(Index==2) { LeftBot.SetY(Comp1);
570 else { if(Index==1) { LeftBot.SetX(I1);
572 if(Index==2) { LeftBot.SetY(I1);
577 if(Abs(DComp1)<=Tol) {
578 if(Index==1) { LeftBot.SetX(I1) ;
580 if(Index==2) { LeftBot.SetY(I1) ;
584 if(Abs(Comp1-I1)<Tol)
585 { if(Index==1) { LeftBot.SetX(I1) ;
587 if(Index==2) { LeftBot.SetY(I1) ;
591 if(Abs(Comp1-I2)<Tol)
592 { if(Index==1) { LeftBot.SetX(I1);
594 if(Index==2) { LeftBot.SetY(I1);
599 //=======================================================================
600 //function :Locate2Coord
602 //=======================================================================
604 static void Locate2Coord(const Standard_Integer Index,
605 const gp_Pnt2d& UV, const gp_Vec2d& DUV,
606 const Handle(Geom_BSplineSurface)& BSplS,
607 const TColStd_Array1OfReal& Arr,
608 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop)
610 Standard_Real Comp=0,DComp=0,Tmp1=0.0,Tmp2=0.0;
611 Standard_Real Tol=Precision::PConfusion()/10;
612 Standard_Integer N=0, NUp=0, NLo=0;
616 NUp = BSplS->LastUKnotIndex();
617 NLo = BSplS->FirstUKnotIndex();
622 NUp = BSplS->LastVKnotIndex();
623 NLo = BSplS->FirstVKnotIndex();
626 if((DComp > 0)&&(Abs(DComp)>Tol)) {
629 //limit case: Hunt() cought upper knot. Take the last span.
632 if(Index==1) { Tmp1=BSplS->UKnot(N);
633 Tmp2=BSplS->UKnot(N+1);}
635 if(Index==2) { Tmp1=BSplS->VKnot(N);
636 Tmp2=BSplS->VKnot(N+1);}
638 ReverseParam(Tmp1,Tmp2,Tmp1,Tmp2);
640 if(Index==1) { LeftBot.SetX(Tmp1);
641 RightTop.SetX(Tmp2);}
643 if(Index==2) { LeftBot.SetY(Tmp1);
644 RightTop.SetY(Tmp2);}
647 if((DComp < 0)&&(Abs(DComp)>Tol)){
650 //limit case: Hunt() cought lower knot. Take the first span.
653 if(Index==1) { Tmp1=BSplS->UKnot(N-1);
654 Tmp2=BSplS->UKnot(N);}
656 if(Index==2) { Tmp1=BSplS->VKnot(N-1);
657 Tmp2=BSplS->VKnot(N);}
659 ReverseParam(Tmp1,Tmp2,Tmp1,Tmp2);
661 if(Index==1) { LeftBot.SetX(Tmp1);
662 RightTop.SetX(Tmp2);}
664 if(Index==2) { LeftBot.SetY(Tmp1);
665 RightTop.SetY(Tmp2);}
671 //=======================================================================
672 //function : Adaptor3d_CurveOnSurface
674 //=======================================================================
676 Adaptor3d_CurveOnSurface::Adaptor3d_CurveOnSurface()
677 : myType(GeomAbs_OtherCurve), myIntCont(GeomAbs_CN)
680 //=======================================================================
681 //function : Adaptor3d_CurveOnSurface
683 //=======================================================================
685 Adaptor3d_CurveOnSurface::Adaptor3d_CurveOnSurface
686 (const Handle(Adaptor3d_HSurface)& S)
687 : myType(GeomAbs_OtherCurve), myIntCont(GeomAbs_CN)
692 //=======================================================================
693 //function : Adaptor3d_CurveOnSurface
695 //=======================================================================
697 Adaptor3d_CurveOnSurface::Adaptor3d_CurveOnSurface
698 (const Handle(Adaptor2d_HCurve2d)& C,
699 const Handle(Adaptor3d_HSurface)& S)
700 : myType(GeomAbs_OtherCurve), myIntCont(GeomAbs_CN)
706 //=======================================================================
709 //=======================================================================
711 void Adaptor3d_CurveOnSurface::Load(const Handle(Adaptor3d_HSurface)& S)
714 if (!myCurve.IsNull()) EvalKPart();
717 //=======================================================================
720 //=======================================================================
722 void Adaptor3d_CurveOnSurface::Load(const Handle(Adaptor2d_HCurve2d)& C)
725 if (!mySurface.IsNull())
728 GeomAbs_SurfaceType SType ;
729 SType = mySurface->GetType();
730 if( SType == GeomAbs_BSplineSurface)
732 if( SType == GeomAbs_SurfaceOfExtrusion)
734 if( SType == GeomAbs_SurfaceOfRevolution)
736 if( SType == GeomAbs_OffsetSurface) {
737 SType = mySurface->BasisSurface()->GetType();
738 if( SType == GeomAbs_SurfaceOfRevolution ||
739 SType == GeomAbs_SurfaceOfExtrusion ||
740 SType == GeomAbs_BSplineSurface )
746 //=======================================================================
749 //=======================================================================
751 void Adaptor3d_CurveOnSurface::Load (const Handle(Adaptor2d_HCurve2d)& C,
752 const Handle(Adaptor3d_HSurface)& S)
758 //=======================================================================
759 //function : FirstParameter
761 //=======================================================================
763 Standard_Real Adaptor3d_CurveOnSurface::FirstParameter() const
765 return myCurve->FirstParameter();
768 //=======================================================================
769 //function : LastParameter
771 //=======================================================================
773 Standard_Real Adaptor3d_CurveOnSurface::LastParameter() const
775 return myCurve->LastParameter();
778 //=======================================================================
779 //function : Continuity
781 //=======================================================================
783 GeomAbs_Shape Adaptor3d_CurveOnSurface::Continuity() const
785 GeomAbs_Shape ContC = myCurve->Continuity();
786 GeomAbs_Shape ContSu = mySurface->UContinuity();
787 if ( ContSu < ContC) ContC = ContSu;
788 GeomAbs_Shape ContSv = mySurface->VContinuity();
789 if ( ContSv < ContC) ContC = ContSv;
794 // Auxiliary: adds roots of equation to sorted sequence of parameters
795 // along curve, keeping it sorted and avoiding repetitions (within tolerance Tol)
796 static void AddIntervals (const Handle(TColStd_HSequenceOfReal)& theParameters,
797 const math_FunctionRoots& theRoots, Standard_Real theTol)
799 if (! theRoots.IsDone() || theRoots.IsAllNull())
802 Standard_Integer nsol = theRoots.NbSolutions();
803 for (Standard_Integer i = 1; i <= nsol; i++)
805 Standard_Real param = theRoots.Value(i);
806 if (param - theParameters->Value(1) < theTol) // skip param if equal to or less than theParameters(1)
808 for (Standard_Integer j=2; j <= theParameters->Length(); ++j)
810 Standard_Real aDelta = theParameters->Value(j) - param;
813 theParameters->InsertBefore (j, param);
816 else if (aDelta >= -theTol) // param == theParameters(j) within Tol
822 //=======================================================================
823 //function : NbIntervals
825 //=======================================================================
827 Standard_Integer Adaptor3d_CurveOnSurface::NbIntervals (const GeomAbs_Shape S) const
829 if(S == myIntCont && !myIntervals.IsNull())
830 return myIntervals->Length()-1;
832 Standard_Integer nu,nv,nc;
833 nu=mySurface->NbUIntervals(S);
834 nv=mySurface->NbVIntervals(S);
836 TColStd_Array1OfReal TabU(1,nu+1);
837 TColStd_Array1OfReal TabV(1,nv+1);
838 Standard_Integer NbSample = 20;
839 Standard_Real U,V,Tdeb,Tfin;
840 Tdeb=myCurve->FirstParameter();
841 Tfin=myCurve->LastParameter();
843 nc=myCurve->NbIntervals(S);
844 TColStd_Array1OfReal TabC(1,nc+1);
845 myCurve->Intervals(TabC,S);
847 Standard_Real Tol= Precision::PConfusion()/10;
849 // sorted sequence of parameters defining continuity intervals;
850 // started with own intervals of curve and completed by
851 // additional points coming from surface discontinuities
852 Handle(TColStd_HSequenceOfReal) aIntervals = new TColStd_HSequenceOfReal;
853 for (Standard_Integer i = 1; i <= nc + 1; i++)
855 aIntervals->Append(TabC(i));
860 mySurface->UIntervals(TabU,S);
861 for(Standard_Integer iu = 2;iu <= nu; iu++)
864 Adaptor3d_InterFunc Func(myCurve,U,1);
865 math_FunctionRoots Resol(Func,Tdeb,Tfin,NbSample,Tol,Tol,Tol,0.);
866 AddIntervals (aIntervals, Resol, Tol);
871 mySurface->VIntervals(TabV,S);
872 for(Standard_Integer iv = 2;iv <= nv; iv++)
875 Adaptor3d_InterFunc Func(myCurve,V,2);
876 math_FunctionRoots Resol(Func,Tdeb,Tfin,NbSample,Tol,Tol,Tol,0.);
877 AddIntervals (aIntervals, Resol, Tol);
881 // for case intervals==1 and first point == last point SequenceOfReal
882 // contains only one value, therefore it is necessary to add second
883 // value into aIntervals which will be equal first value.
884 if (aIntervals->Length() == 1)
885 aIntervals->Append (aIntervals->Value(1));
887 const_cast<Adaptor3d_CurveOnSurface*>(this)->myIntervals = aIntervals;
888 const_cast<Adaptor3d_CurveOnSurface*>(this)->myIntCont = S;
889 return myIntervals->Length() - 1;
892 //=======================================================================
893 //function : Intervals
895 //=======================================================================
897 void Adaptor3d_CurveOnSurface::Intervals(TColStd_Array1OfReal& T,
898 const GeomAbs_Shape S) const
901 Standard_ASSERT_RAISE (T.Length() == myIntervals->Length(), "Error: Wrong size of array buffer in call to Adaptor3d_CurveOnSurface::Intervals");
902 for(Standard_Integer i=1; i<=myIntervals->Length(); i++) {
903 T(i) = myIntervals->Value(i);
907 //=======================================================================
910 //=======================================================================
912 Handle(Adaptor3d_HCurve) Adaptor3d_CurveOnSurface::Trim
913 (const Standard_Real First,
914 const Standard_Real Last,
915 const Standard_Real Tol) const
917 Handle(Adaptor3d_HCurveOnSurface) HCS = new Adaptor3d_HCurveOnSurface();
918 HCS->ChangeCurve().Load(mySurface);
919 HCS->ChangeCurve().Load(myCurve->Trim(First,Last,Tol));
923 //=======================================================================
924 //function : IsClosed
926 //=======================================================================
928 Standard_Boolean Adaptor3d_CurveOnSurface::IsClosed() const
930 return myCurve->IsClosed();
933 //=======================================================================
934 //function : IsPeriodic
936 //=======================================================================
938 Standard_Boolean Adaptor3d_CurveOnSurface::IsPeriodic() const
940 return myCurve->IsPeriodic();
943 //=======================================================================
946 //=======================================================================
948 Standard_Real Adaptor3d_CurveOnSurface::Period() const
950 return myCurve->Period();
953 //=======================================================================
956 //=======================================================================
958 gp_Pnt Adaptor3d_CurveOnSurface::Value(const Standard_Real U ) const
963 if (myType == GeomAbs_Line ) P = ElCLib::Value(U,myLin );
964 else if (myType == GeomAbs_Circle) P = ElCLib::Value(U,myCirc);
967 mySurface->D0(Puv.X(),Puv.Y(),P);
973 //=======================================================================
976 //=======================================================================
978 void Adaptor3d_CurveOnSurface::D0(const Standard_Real U ,
983 if (myType == GeomAbs_Line ) P = ElCLib::Value(U,myLin );
984 else if (myType == GeomAbs_Circle) P = ElCLib::Value(U,myCirc);
987 mySurface->D0(Puv.X(),Puv.Y(),P);
993 //=======================================================================
996 //=======================================================================
998 void Adaptor3d_CurveOnSurface::D1(const Standard_Real U ,
1006 Standard_Real FP = myCurve->FirstParameter();
1007 Standard_Real LP = myCurve->LastParameter();
1009 Standard_Real Tol= Precision::PConfusion()/10;
1010 if( ( Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
1012 myCurve->D1(U,Puv,Duv);
1013 myFirstSurf->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1014 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1017 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
1019 myCurve->D1(U,Puv,Duv);
1020 myLastSurf->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1021 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1024 if (myType == GeomAbs_Line ) ElCLib::D1(U,myLin ,P,V);
1025 else if (myType == GeomAbs_Circle) ElCLib::D1(U,myCirc,P,V);
1027 myCurve->D1(U,Puv,Duv);
1028 mySurface->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1029 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1032 //=======================================================================
1035 //=======================================================================
1037 void Adaptor3d_CurveOnSurface::D2(const Standard_Real U,
1044 gp_Vec D1U,D1V,D2U,D2V,D2UV;
1046 Standard_Real FP = myCurve->FirstParameter();
1047 Standard_Real LP = myCurve->LastParameter();
1049 Standard_Real Tol= Precision::PConfusion()/10;
1050 if( (Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
1052 myCurve->D2(U,UV,DW,D2W);
1053 myFirstSurf->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
1055 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1056 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1057 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1060 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
1062 myCurve->D2(U,UV,DW,D2W);
1063 myLastSurf->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
1065 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1066 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1067 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1070 if (myType == GeomAbs_Line ) {
1071 ElCLib::D1(U,myLin,P,V1);
1072 V2.SetCoord(0.,0.,0.);
1074 else if (myType == GeomAbs_Circle) ElCLib::D2(U,myCirc,P,V1,V2);
1076 myCurve->D2(U,UV,DW,D2W);
1077 mySurface->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
1079 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1080 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1081 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1085 //=======================================================================
1088 //=======================================================================
1090 void Adaptor3d_CurveOnSurface::D3
1091 (const Standard_Real U,
1098 Standard_Real Tol= Precision::PConfusion()/10;
1100 gp_Vec2d DW,D2W,D3W;
1101 gp_Vec D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV;
1103 Standard_Real FP = myCurve->FirstParameter();
1104 Standard_Real LP = myCurve->LastParameter();
1106 if( (Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
1107 { myCurve->D3(U,UV,DW,D2W,D3W);
1108 myFirstSurf->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
1109 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1110 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1111 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1112 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1115 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
1116 { myCurve->D3(U,UV,DW,D2W,D3W);
1117 myLastSurf->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
1118 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1120 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1121 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1122 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1125 if (myType == GeomAbs_Line ) {
1126 ElCLib::D1(U,myLin,P,V1);
1127 V2.SetCoord(0.,0.,0.);
1128 V3.SetCoord(0.,0.,0.);
1130 else if (myType == GeomAbs_Circle) ElCLib::D3(U,myCirc,P,V1,V2,V3);
1132 myCurve->D3(U,UV,DW,D2W,D3W);
1133 mySurface->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
1134 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1136 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1137 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1138 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1143 //=======================================================================
1146 //=======================================================================
1148 gp_Vec Adaptor3d_CurveOnSurface::DN
1149 (const Standard_Real U,
1150 const Standard_Integer N) const
1165 Standard_NotImplemented::Raise("Adaptor3d_CurveOnSurface:DN");
1172 //=======================================================================
1173 //function : Resolution
1175 //=======================================================================
1177 Standard_Real Adaptor3d_CurveOnSurface::Resolution
1178 (const Standard_Real R3d) const
1180 Standard_Real ru,rv;
1181 ru = mySurface->UResolution(R3d);
1182 rv = mySurface->VResolution(R3d);
1183 return myCurve->Resolution(Min(ru,rv));
1187 //=======================================================================
1188 //function : GetType
1190 //=======================================================================
1192 GeomAbs_CurveType Adaptor3d_CurveOnSurface::GetType() const
1198 //=======================================================================
1201 //=======================================================================
1203 gp_Lin Adaptor3d_CurveOnSurface::Line() const
1205 Standard_NoSuchObject_Raise_if(myType != GeomAbs_Line, "Adaptor3d_CurveOnSurface::Line(): curve is not a line")
1209 //=======================================================================
1212 //=======================================================================
1214 gp_Circ Adaptor3d_CurveOnSurface::Circle() const
1216 Standard_NoSuchObject_Raise_if(myType != GeomAbs_Circle, "Adaptor3d_CurveOnSurface::Line(): curve is not a circle")
1220 //=======================================================================
1221 //function : Ellipse
1223 //=======================================================================
1225 gp_Elips Adaptor3d_CurveOnSurface::Ellipse() const
1227 return to3d(mySurface->Plane(),myCurve->Ellipse());
1230 //=======================================================================
1231 //function : Hyperbola
1233 //=======================================================================
1235 gp_Hypr Adaptor3d_CurveOnSurface::Hyperbola() const
1237 return to3d(mySurface->Plane(),myCurve->Hyperbola());
1240 //=======================================================================
1241 //function : Parabola
1243 //=======================================================================
1245 gp_Parab Adaptor3d_CurveOnSurface::Parabola() const
1247 return to3d(mySurface->Plane(),myCurve->Parabola());
1250 Standard_Integer Adaptor3d_CurveOnSurface::Degree() const
1253 // on a parametric surface should multiply
1254 // return TheCurve2dTool::Degree(myCurve);
1256 return myCurve->Degree();
1259 //=======================================================================
1260 //function : IsRational
1262 //=======================================================================
1264 Standard_Boolean Adaptor3d_CurveOnSurface::IsRational() const
1266 return ( myCurve->IsRational() ||
1267 mySurface->IsURational() ||
1268 mySurface->IsVRational() );
1271 //=======================================================================
1272 //function : NbPoles
1274 //=======================================================================
1276 Standard_Integer Adaptor3d_CurveOnSurface::NbPoles() const
1278 // on a parametric surface should multiply
1279 return myCurve->NbPoles();
1282 //=======================================================================
1283 //function : NbKnots
1285 //=======================================================================
1287 Standard_Integer Adaptor3d_CurveOnSurface::NbKnots() const {
1288 if (mySurface->GetType()==GeomAbs_Plane)
1289 return myCurve->NbKnots();
1291 Standard_NoSuchObject::Raise();
1296 //=======================================================================
1299 //=======================================================================
1301 Handle(Geom_BezierCurve) Adaptor3d_CurveOnSurface::Bezier() const
1303 Standard_NoSuchObject_Raise_if
1304 ( mySurface->GetType() != GeomAbs_Plane,
1305 "Adaptor3d_CurveOnSurface : Bezier");
1307 Handle(Geom2d_BezierCurve) Bez2d = myCurve->Bezier();
1308 Standard_Integer NbPoles = Bez2d->NbPoles();
1310 const gp_Pln& Plane = mySurface->Plane();
1312 TColgp_Array1OfPnt Poles(1,NbPoles);
1313 for ( Standard_Integer i=1; i<= NbPoles; i++) {
1314 Poles(i) = to3d( Plane, Bez2d->Pole(i));
1316 Handle(Geom_BezierCurve) Bez;
1318 if (Bez2d->IsRational()) {
1319 TColStd_Array1OfReal Weights(1,NbPoles);
1320 Bez2d->Weights(Weights);
1321 Bez = new Geom_BezierCurve(Poles,Weights);
1324 Bez = new Geom_BezierCurve(Poles);
1329 //=======================================================================
1330 //function : BSpline
1332 //=======================================================================
1334 Handle(Geom_BSplineCurve) Adaptor3d_CurveOnSurface::BSpline() const
1336 Standard_NoSuchObject_Raise_if
1337 ( mySurface->GetType() != GeomAbs_Plane,
1338 "Adaptor3d_CurveOnSurface : BSpline");
1340 Handle(Geom2d_BSplineCurve) Bsp2d = myCurve->BSpline();
1341 Standard_Integer NbPoles = Bsp2d->NbPoles();
1343 const gp_Pln& Plane = mySurface->Plane();
1345 TColgp_Array1OfPnt Poles(1,NbPoles);
1346 for ( Standard_Integer i=1; i<= NbPoles; i++) {
1347 Poles(i) = to3d( Plane, Bsp2d->Pole(i));
1350 TColStd_Array1OfReal Knots(1,Bsp2d->NbKnots());
1351 TColStd_Array1OfInteger Mults(1,Bsp2d->NbKnots());
1352 Bsp2d->Knots(Knots);
1353 Bsp2d->Multiplicities(Mults);
1355 Handle(Geom_BSplineCurve) Bsp;
1357 if (Bsp2d->IsRational()) {
1358 TColStd_Array1OfReal Weights(1,NbPoles);
1359 Bsp2d->Weights(Weights);
1360 Bsp = new Geom_BSplineCurve(Poles,Weights,Knots,Mults,
1362 Bsp2d->IsPeriodic());
1365 Bsp = new Geom_BSplineCurve(Poles,Knots,Mults,
1367 Bsp2d->IsPeriodic());
1372 //=======================================================================
1373 //function : GetCurve
1375 //=======================================================================
1377 const Handle(Adaptor2d_HCurve2d)& Adaptor3d_CurveOnSurface::GetCurve() const
1382 //=======================================================================
1383 //function : GetSurface
1385 //=======================================================================
1387 const Handle(Adaptor3d_HSurface)& Adaptor3d_CurveOnSurface::GetSurface() const
1392 //=======================================================================
1393 //function : ChangeCurve
1395 //=======================================================================
1397 Handle(Adaptor2d_HCurve2d)& Adaptor3d_CurveOnSurface::ChangeCurve()
1402 //=======================================================================
1403 //function : ChangeSurface
1405 //=======================================================================
1407 Handle(Adaptor3d_HSurface)& Adaptor3d_CurveOnSurface::ChangeSurface() {
1411 //=======================================================================
1412 //function : EvalKPart
1414 //=======================================================================
1416 void Adaptor3d_CurveOnSurface::EvalKPart()
1418 myType = GeomAbs_OtherCurve;
1420 GeomAbs_SurfaceType STy = mySurface->GetType();
1421 GeomAbs_CurveType CTy = myCurve->GetType();
1422 if (STy == GeomAbs_Plane) {
1424 if (myType == GeomAbs_Circle)
1425 myCirc = to3d(mySurface->Plane(),myCurve->Circle());
1426 else if (myType == GeomAbs_Line) {
1431 myCurve->D1(0.,Puv,Duv);
1433 mySurface->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1434 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1435 myLin = gp_Lin(P,V);
1439 if ( CTy == GeomAbs_Line) {
1440 gp_Dir2d D = myCurve->Line().Direction();
1441 if ( D.IsParallel(gp::DX2d(),Precision::Angular())) { // Iso V.
1442 if ( STy == GeomAbs_Sphere) {
1443 gp_Pnt2d P = myCurve->Line().Location();
1444 if ( Abs( Abs(P.Y()) -M_PI/2. ) >= Precision::PConfusion()) {
1445 myType = GeomAbs_Circle;
1446 gp_Sphere Sph = mySurface->Sphere();
1447 gp_Ax3 Axis = Sph.Position();
1448 myCirc = ElSLib::SphereVIso(Axis,
1451 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1452 gp_Ax1 AxeRev(Axis.Location(), DRev);
1453 myCirc.Rotate(AxeRev, P.X());
1454 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1455 gp_Ax2 Ax = myCirc.Position();
1456 Ax.SetDirection(Ax.Direction().Reversed());
1457 myCirc.SetPosition(Ax);
1461 else if ( STy == GeomAbs_Cylinder) {
1462 myType = GeomAbs_Circle;
1463 gp_Cylinder Cyl = mySurface->Cylinder();
1464 gp_Pnt2d P = myCurve->Line().Location();
1465 gp_Ax3 Axis = Cyl.Position();
1466 myCirc = ElSLib::CylinderVIso(Axis,
1469 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1470 gp_Ax1 AxeRev(Axis.Location(), DRev);
1471 myCirc.Rotate(AxeRev, P.X());
1472 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1473 gp_Ax2 Ax = myCirc.Position();
1474 Ax.SetDirection(Ax.Direction().Reversed());
1475 myCirc.SetPosition(Ax);
1478 else if ( STy == GeomAbs_Cone) {
1479 myType = GeomAbs_Circle;
1480 gp_Cone Cone = mySurface->Cone();
1481 gp_Pnt2d P = myCurve->Line().Location();
1482 gp_Ax3 Axis = Cone.Position();
1483 myCirc = ElSLib::ConeVIso(Axis,
1487 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1488 gp_Ax1 AxeRev(Axis.Location(), DRev);
1489 myCirc.Rotate(AxeRev, P.X());
1490 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1491 gp_Ax2 Ax = myCirc.Position();
1492 Ax.SetDirection(Ax.Direction().Reversed());
1493 myCirc.SetPosition(Ax);
1496 else if ( STy == GeomAbs_Torus) {
1497 myType = GeomAbs_Circle;
1498 gp_Torus Tore = mySurface->Torus();
1499 gp_Pnt2d P = myCurve->Line().Location();
1500 gp_Ax3 Axis = Tore.Position();
1501 myCirc = ElSLib::TorusVIso(Axis,
1505 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1506 gp_Ax1 AxeRev(Axis.Location(), DRev);
1507 myCirc.Rotate(AxeRev, P.X());
1508 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1509 gp_Ax2 Ax = myCirc.Position();
1510 Ax.SetDirection(Ax.Direction().Reversed());
1511 myCirc.SetPosition(Ax);
1515 else if ( D.IsParallel(gp::DY2d(),Precision::Angular())) { // Iso U.
1516 if ( STy == GeomAbs_Sphere) {
1517 myType = GeomAbs_Circle;
1518 gp_Sphere Sph = mySurface->Sphere();
1519 gp_Pnt2d P = myCurve->Line().Location();
1520 gp_Ax3 Axis = Sph.Position();
1521 // calcul de l'iso 0.
1522 myCirc = ElSLib::SphereUIso(Axis, Sph.Radius(),0.);
1524 // mise a sameparameter (rotation du cercle - decalage du Y)
1525 gp_Dir DRev = Axis.XDirection().Crossed(Axis. Direction());
1526 gp_Ax1 AxeRev(Axis.Location(),DRev);
1527 myCirc.Rotate(AxeRev, P.Y());
1529 // transformation en iso U ( = P.X())
1530 DRev = Axis.XDirection().Crossed(Axis.YDirection());
1531 AxeRev = gp_Ax1(Axis.Location(), DRev);
1532 myCirc.Rotate(AxeRev, P.X());
1534 if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) {
1535 gp_Ax2 Ax = myCirc.Position();
1536 Ax.SetDirection(Ax.Direction().Reversed());
1537 myCirc.SetPosition(Ax);
1540 else if ( STy == GeomAbs_Cylinder) {
1541 myType = GeomAbs_Line;
1542 gp_Cylinder Cyl = mySurface->Cylinder();
1543 gp_Pnt2d P = myCurve->Line().Location();
1544 myLin = ElSLib::CylinderUIso(Cyl.Position(),
1547 gp_Vec Tr(myLin.Direction());
1549 myLin.Translate(Tr);
1550 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
1553 else if ( STy == GeomAbs_Cone) {
1554 myType = GeomAbs_Line;
1555 gp_Cone Cone = mySurface->Cone();
1556 gp_Pnt2d P = myCurve->Line().Location();
1557 myLin = ElSLib::ConeUIso(Cone.Position(),
1561 gp_Vec Tr(myLin.Direction());
1563 myLin.Translate(Tr);
1564 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
1567 else if ( STy == GeomAbs_Torus) {
1568 myType = GeomAbs_Circle;
1569 gp_Torus Tore = mySurface->Torus();
1570 gp_Pnt2d P = myCurve->Line().Location();
1571 gp_Ax3 Axis = Tore.Position();
1572 myCirc = ElSLib::TorusUIso(Axis,
1576 myCirc.Rotate(myCirc.Axis(),P.Y());
1578 if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) {
1579 gp_Ax2 Ax = myCirc.Position();
1580 Ax.SetDirection(Ax.Direction().Reversed());
1581 myCirc.SetPosition(Ax);
1588 //=======================================================================
1589 //function :EvalFirstLastSurf
1591 //=======================================================================
1593 void Adaptor3d_CurveOnSurface::EvalFirstLastSurf()
1595 Standard_Real FirstPar,LastPar;
1596 gp_Pnt2d UV, LeftBot, RightTop;
1598 Standard_Real Tol= Precision::PConfusion()/10;
1599 Standard_Boolean Ok = Standard_True;
1602 FirstPar=myCurve->FirstParameter();
1603 myCurve->D1(FirstPar,UV,DUV);
1605 if(DUV.Magnitude() <= Tol) Ok = Standard_False;
1609 switch(mySurface->GetType()) {
1610 case GeomAbs_BSplineSurface :
1611 LocatePart(UV,DUV,mySurface,LeftBot,RightTop);
1613 case GeomAbs_SurfaceOfRevolution :
1614 case GeomAbs_SurfaceOfExtrusion :
1615 Ok = LocatePart_RevExt(UV,DUV,mySurface,LeftBot,RightTop);
1617 case GeomAbs_OffsetSurface :
1618 Ok = LocatePart_Offset(UV,DUV,mySurface,LeftBot,RightTop);
1621 Standard_NotImplemented::Raise("Adaptor3d_CurveOnSurface::EvalFirstLastSurf");
1628 CompareBounds(LeftBot,RightTop); //SVV
1630 myFirstSurf = mySurface->UTrim(LeftBot.X(),RightTop.X(),Tol);
1631 myFirstSurf = myFirstSurf->VTrim(LeftBot.Y(),RightTop.Y(),Tol);
1635 myFirstSurf = mySurface;
1638 LastPar=myCurve->LastParameter();
1640 myCurve->D1(LastPar,UV,DUV);
1641 DUV.Reverse(); //We want the other part
1643 if(DUV.Magnitude() <= Tol) Ok = Standard_False;
1647 switch(mySurface->GetType()) {
1648 case GeomAbs_BSplineSurface :
1649 LocatePart(UV,DUV,mySurface,LeftBot,RightTop);
1651 case GeomAbs_SurfaceOfRevolution :
1652 case GeomAbs_SurfaceOfExtrusion :
1653 Ok = LocatePart_RevExt(UV,DUV,mySurface,LeftBot,RightTop);
1655 case GeomAbs_OffsetSurface :
1656 Ok = LocatePart_Offset(UV,DUV,mySurface,LeftBot,RightTop);
1659 Standard_NotImplemented::Raise("Adaptor3d_CurveOnSurface::EvalFirstLastSurf");
1666 CompareBounds(LeftBot, RightTop); //SVV
1668 myLastSurf = mySurface->UTrim(LeftBot.X(),RightTop.X(),Tol);
1669 myLastSurf = myLastSurf->VTrim(LeftBot.Y(),RightTop.Y(),Tol);
1673 myLastSurf = mySurface;
1677 //=======================================================================
1678 //function :LocatePart_RevExt
1679 //purpose : processes Knots
1680 //=======================================================================
1682 Standard_Boolean Adaptor3d_CurveOnSurface::LocatePart_RevExt(const gp_Pnt2d& UV,
1683 const gp_Vec2d& DUV,
1684 const Handle(Adaptor3d_HSurface)& S,
1686 gp_Pnt2d& RightTop) const
1688 Handle(Adaptor3d_HCurve) AHC = S->BasisCurve();
1690 if (AHC->GetType() == GeomAbs_BSplineCurve) {
1691 Handle( Geom_BSplineCurve) BSplC;
1692 BSplC = AHC->BSpline();
1694 if((S->GetType())==GeomAbs_SurfaceOfExtrusion) {
1695 Locate1Coord(1,UV,DUV,BSplC,LeftBot,RightTop);
1696 Locate2Coord(2,UV,DUV,S->FirstVParameter(),S->LastVParameter(),LeftBot,RightTop);
1698 else if((S->GetType())==GeomAbs_SurfaceOfRevolution) {
1699 Locate1Coord(2,UV,DUV,BSplC,LeftBot,RightTop);
1700 Locate2Coord(1,UV,DUV,S->FirstUParameter(),S->LastUParameter(),LeftBot,RightTop);
1703 Standard_Real u1,u2,v1,v2;
1704 ReverseParam(LeftBot.X(),RightTop.X(),u1,u2);
1707 ReverseParam(LeftBot.Y(),RightTop.Y(),v1,v2);
1710 return Standard_True;
1712 return Standard_False;
1715 //=======================================================================
1716 //function :LocatePart_OffsetSurface
1718 //=======================================================================
1720 Standard_Boolean Adaptor3d_CurveOnSurface::
1721 LocatePart_Offset(const gp_Pnt2d& UV, const gp_Vec2d& DUV,
1722 const Handle(Adaptor3d_HSurface)& S,
1723 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop) const
1725 Standard_Boolean Ok = Standard_True;
1726 Handle( Adaptor3d_HSurface) AHS;
1727 Handle( Geom_BSplineSurface) BSplS;
1728 AHS = S->BasisSurface();
1729 GeomAbs_SurfaceType BasisSType = AHS->GetType();
1730 switch(BasisSType) {
1731 case GeomAbs_SurfaceOfRevolution:
1732 case GeomAbs_SurfaceOfExtrusion :
1733 Ok = LocatePart_RevExt(UV,DUV,AHS,LeftBot,RightTop);
1736 case GeomAbs_BSplineSurface:
1737 LocatePart(UV,DUV,AHS,LeftBot,RightTop);
1746 //=======================================================================
1747 //function :LocatePart
1748 //purpose : for BSplineSurface
1749 //=======================================================================
1751 void Adaptor3d_CurveOnSurface::LocatePart(const gp_Pnt2d& UV, const gp_Vec2d& DUV,
1752 const Handle(Adaptor3d_HSurface)& S,
1753 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop) const
1755 Handle( Geom_BSplineSurface) BSplS;
1756 BSplS = S->BSpline();
1757 Standard_Boolean DUIsNull=Standard_False,
1758 DVIsNull=Standard_False;
1760 Locate1Coord(1,UV,DUV,BSplS,DUIsNull,LeftBot,RightTop);
1761 Locate1Coord(2,UV,DUV,BSplS,DVIsNull,LeftBot,RightTop);
1763 if((DUIsNull==Standard_True)&&(DVIsNull==Standard_False)) {
1764 TColStd_Array1OfReal ArrU(1,BSplS->NbUKnots());
1765 BSplS->UKnots(ArrU);
1766 Locate2Coord(1,UV,DUV,BSplS,ArrU,LeftBot,RightTop);
1768 else if((DVIsNull==Standard_True)&&(DUIsNull==Standard_False)) {
1769 TColStd_Array1OfReal ArrV(1,BSplS->NbVKnots());
1770 BSplS->VKnots(ArrV);
1771 Locate2Coord(2,UV,DUV,BSplS,ArrV,LeftBot,RightTop);