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
17 #include <Adaptor3d_CurveOnSurface.hxx>
19 #include <Adaptor2d_Curve2d.hxx>
20 #include <Adaptor3d_Surface.hxx>
21 #include <Adaptor3d_InterFunc.hxx>
24 #include <Geom2d_BezierCurve.hxx>
25 #include <Geom2d_BSplineCurve.hxx>
26 #include <Geom_BezierCurve.hxx>
27 #include <Geom_BSplineCurve.hxx>
28 #include <Geom_OffsetSurface.hxx>
29 #include <Geom_SurfaceOfRevolution.hxx>
30 #include <gp_Ax22d.hxx>
31 #include <gp_Circ.hxx>
32 #include <gp_Circ2d.hxx>
33 #include <gp_Elips.hxx>
34 #include <gp_Elips2d.hxx>
35 #include <gp_Hypr.hxx>
36 #include <gp_Hypr2d.hxx>
38 #include <gp_Lin2d.hxx>
39 #include <gp_Parab.hxx>
40 #include <gp_Parab2d.hxx>
42 #include <gp_Pnt2d.hxx>
44 #include <gp_Vec2d.hxx>
45 #include <math_FunctionRoots.hxx>
46 #include <Precision.hxx>
47 #include <Standard_Assert.hxx>
48 #include <Standard_DomainError.hxx>
49 #include <Standard_NoSuchObject.hxx>
50 #include <Standard_NotImplemented.hxx>
51 #include <TColgp_Array1OfPnt.hxx>
52 #include <TColgp_Array1OfPnt2d.hxx>
53 #include <TColStd_Array1OfInteger.hxx>
54 #include <TColStd_Array1OfReal.hxx>
55 #include <TColStd_HSequenceOfReal.hxx>
57 IMPLEMENT_STANDARD_RTTIEXT(Adaptor3d_CurveOnSurface, Adaptor3d_Curve)
59 static gp_Pnt to3d(const gp_Pln& Pl, const gp_Pnt2d& P)
61 return ElSLib::Value(P.X(),P.Y(),Pl);
64 static gp_Vec to3d(const gp_Pln& Pl, const gp_Vec2d& V)
66 gp_Vec Vx = Pl.XAxis().Direction();
67 gp_Vec Vy = Pl.YAxis().Direction();
74 static gp_Ax2 to3d(const gp_Pln& Pl, const gp_Ax22d& A)
76 gp_Pnt P = to3d(Pl,A.Location());
77 gp_Vec VX = to3d(Pl,A.XAxis().Direction());
78 gp_Vec VY = to3d(Pl,A.YAxis().Direction());
79 return gp_Ax2(P,VX.Crossed(VY),VX);
82 static gp_Circ to3d(const gp_Pln& Pl, const gp_Circ2d& C)
84 return gp_Circ(to3d(Pl,C.Axis()),C.Radius());
87 static gp_Elips to3d(const gp_Pln& Pl, const gp_Elips2d& E)
89 return gp_Elips(to3d(Pl,E.Axis()),E.MajorRadius(),E.MinorRadius());
92 static gp_Hypr to3d(const gp_Pln& Pl, const gp_Hypr2d& H)
94 return gp_Hypr(to3d(Pl,H.Axis()),H.MajorRadius(),H.MinorRadius());
97 static gp_Parab to3d(const gp_Pln& Pl, const gp_Parab2d& P)
99 return gp_Parab(to3d(Pl,P.Axis()),P.Focal());
102 static gp_Vec SetLinearForm(const gp_Vec2d& DW, const gp_Vec2d& D2W, const gp_Vec2d& D3W,
103 const gp_Vec& D1U, const gp_Vec& D1V, const gp_Vec& D2U,
104 const gp_Vec& D2V, const gp_Vec& D2UV, const gp_Vec& D3U,
105 const gp_Vec& D3V, const gp_Vec& D3UUV,const gp_Vec& D3UVV)
106 {gp_Vec V31, V32, V33, V34,V3 ;
107 V31.SetLinearForm(DW.X(),D1U,
109 D2W.X()*DW.Y(),D2UV);
110 V31.SetLinearForm(D3W.Y(),D1V,
114 V32.SetLinearForm(DW.X()*DW.X()*DW.Y(),D3UUV,
115 DW.X()*DW.Y()*DW.Y(),D3UVV);
116 V32.SetLinearForm(D2W.X()*DW.Y()+DW.X()*D2W.Y(),D2UV,
117 DW.X()*DW.Y()*DW.Y(),D3UVV,
119 V33.SetLinearForm(2*D2W.X()*DW.X(),D2U,
120 DW.X()*DW.X()*DW.X(),D3U,
121 DW.X()*DW.X()*DW.Y(),D3UUV);
123 V34.SetLinearForm(2*D2W.Y()*DW.Y(),D2V,
124 DW.Y()*DW.Y()*DW.X(),D3UVV,
125 DW.Y()*DW.Y()*DW.Y(),D3V);
126 V3.SetLinearForm(1,V31,2,V32,1,V33,V34);
130 //=======================================================================
131 static void CompareBounds(gp_Pnt2d& P1,
134 Standard_Real Lx = P1.X(),Ly = P1.Y();
135 Standard_Real Rx = P2.X(),Ry = P2.Y();
137 if (Lx > Rx) { P1.SetX(Rx); P2.SetX(Lx);}
138 if (Ly > Ry) { P1.SetY(Ry); P2.SetY(Ly);}
141 //=======================================================================
144 //=======================================================================
145 static void Hunt(const TColStd_Array1OfReal& Arr,
146 const Standard_Real Coord,
147 Standard_Integer& Iloc)
148 {//Warning: Hunt is used to find number of knot which equals coordinate component,
149 // when coordinate component definitly equals a knot only.
150 Standard_Real Tol=Precision::PConfusion()/10;
151 Standard_Integer i=1;
152 while((i <= Arr.Upper()) && (Abs(Coord - Arr(i)) > Tol)){
155 if(Abs(Coord - Arr(i)) < Tol)
158 if(Abs(Coord - Arr(i)) > Tol)
159 throw Standard_NotImplemented("Adaptor3d_CurveOnSurface:Hunt");
162 //=======================================================================
163 //function :ReverseParam
165 //=======================================================================
167 static void ReverseParam(const Standard_Real In1,
168 const Standard_Real In2,
170 Standard_Real& Out2 )
173 if(In1>In2) {Out1=In2;
178 //=======================================================================
179 //function :ReverseParam
181 //=======================================================================
183 static void ReverseParam(const Standard_Integer In1,
184 const Standard_Integer In2,
185 Standard_Integer& Out1,
186 Standard_Integer& Out2 )
188 if(In1>In2) {Out1=In2;
194 //=======================================================================
195 //function :FindBounds
197 //=======================================================================
198 static void FindBounds(const TColStd_Array1OfReal& Arr,
199 const Standard_Real Coord,
200 const Standard_Real Der,
201 Standard_Integer& Bound1,
202 Standard_Integer& Bound2,
203 Standard_Boolean& DerNull)
206 Standard_Integer N=0;
207 Standard_Real Tol=Precision::PConfusion()/10;
209 DerNull=Standard_False;
211 if(N==Bound1){ if(Abs(Der) > Tol) DerNull = Standard_False;
212 if(Abs(Der)<= Tol) DerNull = Standard_True;
213 Bound1=N;Bound2=N+1; return;
215 if(N==Bound2){ if( Abs(Der) > Tol ) DerNull = Standard_False;
216 if( Abs(Der)<= Tol ) DerNull = Standard_True;
217 Bound1=N-1;Bound2=N; return;
219 if((N!=Bound1)&&(N!=Bound2)) {
220 if(Abs(Der) > Tol ) {
221 if(Der>0) {Bound1=N;Bound2= N+1;}
223 if(Der<0){Bound1=N-1;Bound2=N;}
224 DerNull = Standard_False;
226 if(Abs(Der) <=Tol ) {
227 DerNull = Standard_True;
234 //=======================================================================
235 //function :Locate1Coord
236 //purpose : along BSpline curve
237 //=======================================================================
239 static void Locate1Coord(const Standard_Integer Index,
242 const Handle(Geom_BSplineCurve)& BSplC,
243 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop)
245 Standard_Real Comp1=0, DComp1=0, cur, f = 0.0, l = 0.0;
246 Standard_Real Tol = Precision::PConfusion()/10;
247 Standard_Integer i = 1, Bnd1, Bnd2;
248 Standard_Boolean DIsNull= Standard_False;
249 TColStd_Array1OfReal Arr(1,BSplC->NbKnots()); BSplC->Knots(Arr);
251 if(Index==1) { Comp1=UV.X(); DComp1=DUV.X(); }
252 if(Index==2) { Comp1=UV.Y(); DComp1=DUV.Y(); }
254 Standard_Integer Lo = BSplC->FirstUKnotIndex(), Up = BSplC->LastUKnotIndex();
257 while ( ( Abs(BSplC->Knot(i)-Comp1)>Tol )&& (i!=Up ) ) i++;
260 if( Abs(Comp1-cur)<=Tol) {
262 Bnd1 = Lo; Bnd2 = Up;
263 FindBounds(Arr,cur,DComp1,Bnd1,Bnd2,DIsNull);
264 ReverseParam(Bnd1,Bnd2,Bnd1,Bnd2);
266 if(DIsNull==Standard_False){
267 if(Index==1) {LeftBot.SetX(BSplC->Knot(Bnd1));
268 RightTop.SetX(BSplC->Knot(Bnd2));}
270 if(Index==2){ LeftBot.SetY(BSplC->Knot(Bnd1));
271 RightTop.SetY(BSplC->Knot(Bnd2)); }
274 if(DIsNull==Standard_True){
275 if( Abs( Comp1-(f=BSplC->Knot(Lo))) <= Tol)
277 if(Index==1) { LeftBot.SetX(BSplC->Knot(Lo));
278 RightTop.SetX(BSplC->Knot(Lo+1));}
279 else if(Index==2) { LeftBot.SetY(BSplC->Knot(Lo));
280 RightTop.SetY(BSplC->Knot(Lo+1));}
282 if( Abs( Comp1-(l=BSplC->Knot(Up))) <= Tol)
284 if(Index==1) { LeftBot.SetX(BSplC->Knot(Up-1));
285 RightTop.SetX(BSplC->Knot(Up));}
286 else if(Index==2) {LeftBot.SetY(BSplC->Knot(Up-1));
287 RightTop.SetY(BSplC->Knot(Up));}
289 if(Index==1) { LeftBot.SetX(BSplC->Knot(Bnd1));
290 RightTop.SetX(BSplC->Knot(Bnd2));}
291 else if(Index==2) {LeftBot.SetY(BSplC->Knot(Bnd1));
292 RightTop.SetY(BSplC->Knot(Bnd2));}
295 else//*********if Coord != Knot
299 //if((f=BSplC->Knot(i))<Comp1 && (l=BSplC->Knot(i+1))>Comp1) break;
300 //skl 28.03.2002 for OCC233
303 if(f<Comp1 && l>Comp1) break;
306 ReverseParam(f,l,f,l);
310 { if(Index==1) {LeftBot.SetX(f); RightTop.SetX(l);}else
311 if(Index==2) {LeftBot.SetY(f); RightTop.SetY(l); }
316 if(DComp1>0) {LeftBot.SetX(Comp1); RightTop.SetX(l);} else
317 if(DComp1<0) {LeftBot.SetX(f); RightTop.SetX(Comp1);}
321 if(DComp1>0) {LeftBot.SetY(Comp1); RightTop.SetY(l);} else
322 if(DComp1<0) {LeftBot.SetY(f); RightTop.SetY(Comp1);};
327 if(Index==1) {LeftBot.SetX(Comp1); RightTop.SetX(BSplC->Knot(i));}else
328 if(Index==2) {LeftBot.SetY(Comp1); RightTop.SetY(BSplC->Knot(i)); }
334 //=======================================================================
335 //function :Locate1Coord
337 //=======================================================================
339 static void Locate1Coord(const Standard_Integer Index,
342 const Handle(Geom_BSplineSurface)& BSplS,
343 Standard_Boolean& DIsNull,
347 Standard_Real Comp1=0,DComp1=0;
348 Standard_Real Tol = Precision::PConfusion()/10;
349 Standard_Integer i=1, Up=0, Up1, Up2, Down=0, Down1, Down2;
350 Standard_Real cur = 0.;
352 DIsNull= Standard_False;
354 Up1 = BSplS->LastUKnotIndex();
355 Down1 = BSplS->FirstUKnotIndex();
356 Up2 = BSplS->LastVKnotIndex();
357 Down2 = BSplS->FirstVKnotIndex();
367 while ( ( Abs(BSplS->UKnot(i)-Comp1)>Tol )&&(i!=Up1 ) )
372 cur = BSplS->UKnot(i);
382 while ( ( Abs(BSplS->VKnot(i)-Comp1)>Tol )&&(i!=Up2 ) )
387 cur = BSplS->VKnot(i);
390 if( Abs(Comp1-cur)<=Tol )
392 Standard_Integer Bnd1 = Down, Bnd2 = Up;
395 TColStd_Array1OfReal Arr1(1,BSplS->NbUKnots());
396 BSplS->UKnots(Arr1); // Up1=Arr1.Upper(); Down1=Arr1.Lower();
397 FindBounds(Arr1,cur,DUV.X(),Bnd1,Bnd2,DIsNull);
401 TColStd_Array1OfReal Arr2(1,BSplS->NbVKnots());
402 BSplS->VKnots(Arr2); // Up2=Arr2.Upper(); Down2=Arr2.Lower();
403 FindBounds(Arr2,cur,DUV.Y(),Bnd1,Bnd2,DIsNull);
406 ReverseParam(Bnd1,Bnd2,Bnd1,Bnd2);
408 if(DIsNull==Standard_False)
412 LeftBot.SetX(BSplS->UKnot(Bnd1));
413 RightTop.SetX(BSplS->UKnot(Bnd2));
417 LeftBot.SetY(BSplS->VKnot(Bnd1));
418 RightTop.SetY(BSplS->VKnot(Bnd2));
422 else//*********if Coord != Knot
424 if( (Index==1)&&(Comp1 < BSplS->UKnot(Down)) )
426 LeftBot.SetX(BSplS->UKnot(Down));
427 RightTop.SetX( BSplS->UKnot(Down + 1) );
430 else if( (Index==2)&&(Comp1 < BSplS->VKnot(Down)) )
432 LeftBot.SetY(BSplS->VKnot(Down));
433 RightTop.SetY( BSplS->VKnot(Down + 1) );
436 else if( (Index==1)&&(Comp1 > BSplS->UKnot(Up)) )
438 RightTop.SetX(BSplS->UKnot(Up - 1));
439 LeftBot.SetX( BSplS->UKnot(Up) );
442 else if( (Index==2)&&(Comp1 > BSplS->VKnot(Up)) )
444 RightTop.SetY(BSplS->VKnot(Up - 1));
445 LeftBot.SetY( BSplS->VKnot(Up) );
450 Standard_Real f = 0., l = 1.;
453 f=BSplS->UKnot(Down);
458 f=BSplS->VKnot(Down);
463 if ((!(Comp1 < f))&&(!(Comp1 > l)))
467 while (!(((f=BSplS->UKnot(i)) < Comp1)&&((l=BSplS->UKnot(i+1)) > Comp1)) && (i<Up))
474 while (!(((f=BSplS->VKnot(i)) < Comp1)&&((l=BSplS->VKnot(i+1)) > Comp1)) && (i<Up))
481 ReverseParam(f,l,f,l);
497 RightTop.SetX(Comp1);
510 RightTop.SetY(Comp1);
536 RightTop.SetX(BSplS->UKnot(i));
541 RightTop.SetY(BSplS->VKnot(i));
547 //=======================================================================
548 //function :Locate2Coord
549 //purpose : along non-BSpline curve
550 //=======================================================================
553 static void Locate2Coord(const Standard_Integer Index,
554 const gp_Pnt2d& UV, const gp_Vec2d& DUV,
555 const Standard_Real I1,
556 const Standard_Real I2,
557 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop)
559 Standard_Real Tol=Precision::PConfusion()/10;
560 Standard_Real Comp1=0,DComp1=0;
561 if(Index==1) { Comp1=UV.X();
564 if(Index==2) {Comp1=UV.Y();
567 if((Comp1!=I1)&&(Comp1!=I2))
568 { if(Abs(DComp1) > Tol)
570 { if(Index==1) { LeftBot.SetX(I1);
571 RightTop.SetX(Comp1);}
572 if(Index==2) { LeftBot.SetY(I1);
573 RightTop.SetY(Comp1);}
577 { if(Index==1) { LeftBot.SetX(Comp1);
579 if(Index==2) { LeftBot.SetY(Comp1);
582 else { if(Index==1) { LeftBot.SetX(I1);
584 if(Index==2) { LeftBot.SetY(I1);
589 if(Abs(DComp1)<=Tol) {
590 if(Index==1) { LeftBot.SetX(I1) ;
592 if(Index==2) { LeftBot.SetY(I1) ;
596 if(Abs(Comp1-I1)<Tol)
597 { if(Index==1) { LeftBot.SetX(I1) ;
599 if(Index==2) { LeftBot.SetY(I1) ;
603 if(Abs(Comp1-I2)<Tol)
604 { if(Index==1) { LeftBot.SetX(I1);
606 if(Index==2) { LeftBot.SetY(I1);
611 //=======================================================================
612 //function :Locate2Coord
614 //=======================================================================
616 static void Locate2Coord(const Standard_Integer Index,
617 const gp_Pnt2d& UV, const gp_Vec2d& DUV,
618 const Handle(Geom_BSplineSurface)& BSplS,
619 const TColStd_Array1OfReal& Arr,
620 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop)
622 Standard_Real Comp=0,DComp=0,Tmp1=0.0,Tmp2=0.0;
623 Standard_Real Tol=Precision::PConfusion()/10;
624 Standard_Integer N=0, NUp=0, NLo=0;
628 NUp = BSplS->LastUKnotIndex();
629 NLo = BSplS->FirstUKnotIndex();
634 NUp = BSplS->LastVKnotIndex();
635 NLo = BSplS->FirstVKnotIndex();
638 if((DComp > 0)&&(Abs(DComp)>Tol)) {
641 //limit case: Hunt() cought upper knot. Take the last span.
644 if(Index==1) { Tmp1=BSplS->UKnot(N);
645 Tmp2=BSplS->UKnot(N+1);}
647 if(Index==2) { Tmp1=BSplS->VKnot(N);
648 Tmp2=BSplS->VKnot(N+1);}
650 ReverseParam(Tmp1,Tmp2,Tmp1,Tmp2);
652 if(Index==1) { LeftBot.SetX(Tmp1);
653 RightTop.SetX(Tmp2);}
655 if(Index==2) { LeftBot.SetY(Tmp1);
656 RightTop.SetY(Tmp2);}
659 if((DComp < 0)&&(Abs(DComp)>Tol)){
662 //limit case: Hunt() cought lower knot. Take the first span.
665 if(Index==1) { Tmp1=BSplS->UKnot(N-1);
666 Tmp2=BSplS->UKnot(N);}
668 if(Index==2) { Tmp1=BSplS->VKnot(N-1);
669 Tmp2=BSplS->VKnot(N);}
671 ReverseParam(Tmp1,Tmp2,Tmp1,Tmp2);
673 if(Index==1) { LeftBot.SetX(Tmp1);
674 RightTop.SetX(Tmp2);}
676 if(Index==2) { LeftBot.SetY(Tmp1);
677 RightTop.SetY(Tmp2);}
683 //=======================================================================
684 //function : Adaptor3d_CurveOnSurface
686 //=======================================================================
688 Adaptor3d_CurveOnSurface::Adaptor3d_CurveOnSurface()
689 : myType(GeomAbs_OtherCurve), myIntCont(GeomAbs_CN)
692 //=======================================================================
693 //function : Adaptor3d_CurveOnSurface
695 //=======================================================================
697 Adaptor3d_CurveOnSurface::Adaptor3d_CurveOnSurface
698 (const Handle(Adaptor3d_Surface)& S)
699 : myType(GeomAbs_OtherCurve), myIntCont(GeomAbs_CN)
704 //=======================================================================
705 //function : Adaptor3d_CurveOnSurface
707 //=======================================================================
709 Adaptor3d_CurveOnSurface::Adaptor3d_CurveOnSurface
710 (const Handle(Adaptor2d_Curve2d)& C,
711 const Handle(Adaptor3d_Surface)& S)
712 : myType(GeomAbs_OtherCurve), myIntCont(GeomAbs_CN)
718 //=======================================================================
719 //function : ShallowCopy
721 //=======================================================================
723 Handle(Adaptor3d_Curve) Adaptor3d_CurveOnSurface::ShallowCopy() const
725 Handle(Adaptor3d_CurveOnSurface) aCopy = new Adaptor3d_CurveOnSurface();
727 if (!mySurface.IsNull())
729 aCopy->mySurface = mySurface->ShallowCopy();
731 if (!myCurve.IsNull())
733 aCopy->myCurve = myCurve->ShallowCopy();
735 aCopy->myType = myType;
736 aCopy->myCirc = myCirc;
737 aCopy->myLin = myLin;
738 if (!myFirstSurf.IsNull())
740 aCopy->myFirstSurf = myFirstSurf->ShallowCopy();
742 if (!myLastSurf.IsNull())
744 aCopy->myLastSurf = myLastSurf->ShallowCopy();
746 aCopy->myIntervals = myIntervals;
747 aCopy->myIntCont = myIntCont;
752 //=======================================================================
755 //=======================================================================
757 void Adaptor3d_CurveOnSurface::Load(const Handle(Adaptor3d_Surface)& S)
760 if (!myCurve.IsNull()) EvalKPart();
763 //=======================================================================
766 //=======================================================================
768 void Adaptor3d_CurveOnSurface::Load(const Handle(Adaptor2d_Curve2d)& C)
771 if (mySurface.IsNull())
778 GeomAbs_SurfaceType SType = mySurface->GetType();
779 if (SType == GeomAbs_OffsetSurface)
781 SType = mySurface->BasisSurface()->GetType();
784 if (SType == GeomAbs_BSplineSurface ||
785 SType == GeomAbs_SurfaceOfExtrusion ||
786 SType == GeomAbs_SurfaceOfRevolution)
792 //=======================================================================
795 //=======================================================================
797 void Adaptor3d_CurveOnSurface::Load (const Handle(Adaptor2d_Curve2d)& C,
798 const Handle(Adaptor3d_Surface)& S)
804 //=======================================================================
805 //function : FirstParameter
807 //=======================================================================
809 Standard_Real Adaptor3d_CurveOnSurface::FirstParameter() const
811 return myCurve->FirstParameter();
814 //=======================================================================
815 //function : LastParameter
817 //=======================================================================
819 Standard_Real Adaptor3d_CurveOnSurface::LastParameter() const
821 return myCurve->LastParameter();
824 //=======================================================================
825 //function : Continuity
827 //=======================================================================
829 GeomAbs_Shape Adaptor3d_CurveOnSurface::Continuity() const
831 GeomAbs_Shape ContC = myCurve->Continuity();
832 GeomAbs_Shape ContSu = mySurface->UContinuity();
833 if ( ContSu < ContC) ContC = ContSu;
834 GeomAbs_Shape ContSv = mySurface->VContinuity();
835 if ( ContSv < ContC) ContC = ContSv;
840 // Auxiliary: adds roots of equation to sorted sequence of parameters
841 // along curve, keeping it sorted and avoiding repetitions (within tolerance Tol)
842 static void AddIntervals (const Handle(TColStd_HSequenceOfReal)& theParameters,
843 const math_FunctionRoots& theRoots, Standard_Real theTol)
845 if (! theRoots.IsDone() || theRoots.IsAllNull())
848 Standard_Integer nsol = theRoots.NbSolutions();
849 for (Standard_Integer i = 1; i <= nsol; i++)
851 Standard_Real param = theRoots.Value(i);
852 if (param - theParameters->Value(1) < theTol) // skip param if equal to or less than theParameters(1)
854 for (Standard_Integer j=2; j <= theParameters->Length(); ++j)
856 Standard_Real aDelta = theParameters->Value(j) - param;
859 theParameters->InsertBefore (j, param);
862 else if (aDelta >= -theTol) // param == theParameters(j) within Tol
868 //=======================================================================
869 //function : NbIntervals
871 //=======================================================================
873 Standard_Integer Adaptor3d_CurveOnSurface::NbIntervals (const GeomAbs_Shape S) const
875 if(S == myIntCont && !myIntervals.IsNull())
876 return myIntervals->Length()-1;
878 Standard_Integer nu,nv,nc;
879 nu=mySurface->NbUIntervals(S);
880 nv=mySurface->NbVIntervals(S);
881 nc=myCurve->NbIntervals(S);
883 // Allocate the memory for arrays TabU, TabV, TabC only once using the buffer TabBuf.
884 TColStd_Array1OfReal TabBuf(1, nu + nv + nc + 3);
885 TColStd_Array1OfReal TabU(TabBuf(1), 1, nu+1);
886 TColStd_Array1OfReal TabV(TabBuf(nu + 2), 1, nv+1);
887 TColStd_Array1OfReal TabC(TabBuf(nu + nv + 3), 1, nc+1);
889 Standard_Integer NbSample = 20;
890 Standard_Real U,V,Tdeb,Tfin;
891 Tdeb=myCurve->FirstParameter();
892 Tfin=myCurve->LastParameter();
894 myCurve->Intervals(TabC,S);
896 Standard_Real Tol= Precision::PConfusion()/10;
898 // sorted sequence of parameters defining continuity intervals;
899 // started with own intervals of curve and completed by
900 // additional points coming from surface discontinuities
901 Handle(TColStd_HSequenceOfReal) aIntervals = new TColStd_HSequenceOfReal;
902 for (Standard_Integer i = 1; i <= nc + 1; i++)
904 aIntervals->Append(TabC(i));
909 mySurface->UIntervals(TabU,S);
910 for(Standard_Integer iu = 2;iu <= nu; iu++)
913 Adaptor3d_InterFunc Func(myCurve,U,1);
914 math_FunctionRoots Resol(Func,Tdeb,Tfin,NbSample,Tol,Tol,Tol,0.);
915 AddIntervals (aIntervals, Resol, Tol);
920 mySurface->VIntervals(TabV,S);
921 for(Standard_Integer iv = 2;iv <= nv; iv++)
924 Adaptor3d_InterFunc Func(myCurve,V,2);
925 math_FunctionRoots Resol(Func,Tdeb,Tfin,NbSample,Tol,Tol,Tol,0.);
926 AddIntervals (aIntervals, Resol, Tol);
930 // for case intervals==1 and first point == last point SequenceOfReal
931 // contains only one value, therefore it is necessary to add second
932 // value into aIntervals which will be equal first value.
933 if (aIntervals->Length() == 1)
934 aIntervals->Append (aIntervals->Value(1));
936 const_cast<Adaptor3d_CurveOnSurface*>(this)->myIntervals = aIntervals;
937 const_cast<Adaptor3d_CurveOnSurface*>(this)->myIntCont = S;
938 return myIntervals->Length() - 1;
941 //=======================================================================
942 //function : Intervals
944 //=======================================================================
946 void Adaptor3d_CurveOnSurface::Intervals(TColStd_Array1OfReal& T,
947 const GeomAbs_Shape S) const
950 Standard_ASSERT_RAISE (T.Length() == myIntervals->Length(), "Error: Wrong size of array buffer in call to Adaptor3d_CurveOnSurface::Intervals");
951 for(Standard_Integer i=1; i<=myIntervals->Length(); i++) {
952 T(i) = myIntervals->Value(i);
956 //=======================================================================
959 //=======================================================================
961 Handle(Adaptor3d_Curve) Adaptor3d_CurveOnSurface::Trim
962 (const Standard_Real First,
963 const Standard_Real Last,
964 const Standard_Real Tol) const
966 Handle(Adaptor3d_CurveOnSurface) HCS = new Adaptor3d_CurveOnSurface();
967 HCS->Load(mySurface);
968 HCS->Load(myCurve->Trim(First,Last,Tol));
972 //=======================================================================
973 //function : IsClosed
975 //=======================================================================
977 Standard_Boolean Adaptor3d_CurveOnSurface::IsClosed() const
979 return myCurve->IsClosed();
982 //=======================================================================
983 //function : IsPeriodic
985 //=======================================================================
987 Standard_Boolean Adaptor3d_CurveOnSurface::IsPeriodic() const
989 if (myType == GeomAbs_Circle ||
990 myType == GeomAbs_Ellipse)
991 return Standard_True;
993 return myCurve->IsPeriodic();
996 //=======================================================================
999 //=======================================================================
1001 Standard_Real Adaptor3d_CurveOnSurface::Period() const
1003 if (myType == GeomAbs_Circle ||
1004 myType == GeomAbs_Ellipse)
1007 return myCurve->Period();
1010 //=======================================================================
1013 //=======================================================================
1015 gp_Pnt Adaptor3d_CurveOnSurface::Value(const Standard_Real U ) const
1020 if (myType == GeomAbs_Line ) P = ElCLib::Value(U,myLin );
1021 else if (myType == GeomAbs_Circle) P = ElCLib::Value(U,myCirc);
1024 mySurface->D0(Puv.X(),Puv.Y(),P);
1030 //=======================================================================
1033 //=======================================================================
1035 void Adaptor3d_CurveOnSurface::D0(const Standard_Real U ,
1040 if (myType == GeomAbs_Line ) P = ElCLib::Value(U,myLin );
1041 else if (myType == GeomAbs_Circle) P = ElCLib::Value(U,myCirc);
1044 mySurface->D0(Puv.X(),Puv.Y(),P);
1050 //=======================================================================
1053 //=======================================================================
1055 void Adaptor3d_CurveOnSurface::D1(const Standard_Real U ,
1063 Standard_Real FP = myCurve->FirstParameter();
1064 Standard_Real LP = myCurve->LastParameter();
1066 Standard_Real Tol= Precision::PConfusion()/10;
1067 if( ( Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
1069 myCurve->D1(U,Puv,Duv);
1070 myFirstSurf->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1071 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1074 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
1076 myCurve->D1(U,Puv,Duv);
1077 myLastSurf->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1078 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1081 if (myType == GeomAbs_Line ) ElCLib::D1(U,myLin ,P,V);
1082 else if (myType == GeomAbs_Circle) ElCLib::D1(U,myCirc,P,V);
1084 myCurve->D1(U,Puv,Duv);
1085 mySurface->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1086 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1089 //=======================================================================
1092 //=======================================================================
1094 void Adaptor3d_CurveOnSurface::D2(const Standard_Real U,
1101 gp_Vec D1U,D1V,D2U,D2V,D2UV;
1103 Standard_Real FP = myCurve->FirstParameter();
1104 Standard_Real LP = myCurve->LastParameter();
1106 Standard_Real Tol= Precision::PConfusion()/10;
1107 if( (Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
1109 myCurve->D2(U,UV,DW,D2W);
1110 myFirstSurf->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
1112 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1113 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1114 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1117 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
1119 myCurve->D2(U,UV,DW,D2W);
1120 myLastSurf->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
1122 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1123 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1124 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1127 if (myType == GeomAbs_Line ) {
1128 ElCLib::D1(U,myLin,P,V1);
1129 V2.SetCoord(0.,0.,0.);
1131 else if (myType == GeomAbs_Circle) ElCLib::D2(U,myCirc,P,V1,V2);
1133 myCurve->D2(U,UV,DW,D2W);
1134 mySurface->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
1136 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1137 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1138 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1142 //=======================================================================
1145 //=======================================================================
1147 void Adaptor3d_CurveOnSurface::D3
1148 (const Standard_Real U,
1155 Standard_Real Tol= Precision::PConfusion()/10;
1157 gp_Vec2d DW,D2W,D3W;
1158 gp_Vec D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV;
1160 Standard_Real FP = myCurve->FirstParameter();
1161 Standard_Real LP = myCurve->LastParameter();
1163 if( (Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
1164 { myCurve->D3(U,UV,DW,D2W,D3W);
1165 myFirstSurf->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
1166 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1167 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1168 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1169 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1172 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
1173 { myCurve->D3(U,UV,DW,D2W,D3W);
1174 myLastSurf->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
1175 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1177 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1178 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1179 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1182 if (myType == GeomAbs_Line ) {
1183 ElCLib::D1(U,myLin,P,V1);
1184 V2.SetCoord(0.,0.,0.);
1185 V3.SetCoord(0.,0.,0.);
1187 else if (myType == GeomAbs_Circle) ElCLib::D3(U,myCirc,P,V1,V2,V3);
1189 myCurve->D3(U,UV,DW,D2W,D3W);
1190 mySurface->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
1191 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1193 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1194 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1195 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1200 //=======================================================================
1203 //=======================================================================
1205 gp_Vec Adaptor3d_CurveOnSurface::DN
1206 (const Standard_Real U,
1207 const Standard_Integer N) const
1222 throw Standard_NotImplemented("Adaptor3d_CurveOnSurface:DN");
1229 //=======================================================================
1230 //function : Resolution
1232 //=======================================================================
1234 Standard_Real Adaptor3d_CurveOnSurface::Resolution
1235 (const Standard_Real R3d) const
1237 Standard_Real ru,rv;
1238 ru = mySurface->UResolution(R3d);
1239 rv = mySurface->VResolution(R3d);
1240 return myCurve->Resolution(Min(ru,rv));
1244 //=======================================================================
1245 //function : GetType
1247 //=======================================================================
1249 GeomAbs_CurveType Adaptor3d_CurveOnSurface::GetType() const
1255 //=======================================================================
1258 //=======================================================================
1260 gp_Lin Adaptor3d_CurveOnSurface::Line() const
1262 Standard_NoSuchObject_Raise_if(myType != GeomAbs_Line, "Adaptor3d_CurveOnSurface::Line(): curve is not a line")
1266 //=======================================================================
1269 //=======================================================================
1271 gp_Circ Adaptor3d_CurveOnSurface::Circle() const
1273 Standard_NoSuchObject_Raise_if(myType != GeomAbs_Circle, "Adaptor3d_CurveOnSurface::Line(): curve is not a circle")
1277 //=======================================================================
1278 //function : Ellipse
1280 //=======================================================================
1282 gp_Elips Adaptor3d_CurveOnSurface::Ellipse() const
1284 return to3d(mySurface->Plane(),myCurve->Ellipse());
1287 //=======================================================================
1288 //function : Hyperbola
1290 //=======================================================================
1292 gp_Hypr Adaptor3d_CurveOnSurface::Hyperbola() const
1294 return to3d(mySurface->Plane(),myCurve->Hyperbola());
1297 //=======================================================================
1298 //function : Parabola
1300 //=======================================================================
1302 gp_Parab Adaptor3d_CurveOnSurface::Parabola() const
1304 return to3d(mySurface->Plane(),myCurve->Parabola());
1307 Standard_Integer Adaptor3d_CurveOnSurface::Degree() const
1310 // on a parametric surface should multiply
1311 // return TheCurve2dTool::Degree(myCurve);
1313 return myCurve->Degree();
1316 //=======================================================================
1317 //function : IsRational
1319 //=======================================================================
1321 Standard_Boolean Adaptor3d_CurveOnSurface::IsRational() const
1323 return ( myCurve->IsRational() ||
1324 mySurface->IsURational() ||
1325 mySurface->IsVRational() );
1328 //=======================================================================
1329 //function : NbPoles
1331 //=======================================================================
1333 Standard_Integer Adaptor3d_CurveOnSurface::NbPoles() const
1335 // on a parametric surface should multiply
1336 return myCurve->NbPoles();
1339 //=======================================================================
1340 //function : NbKnots
1342 //=======================================================================
1344 Standard_Integer Adaptor3d_CurveOnSurface::NbKnots() const {
1345 if (mySurface->GetType()==GeomAbs_Plane)
1346 return myCurve->NbKnots();
1348 throw Standard_NoSuchObject();
1352 //=======================================================================
1355 //=======================================================================
1357 Handle(Geom_BezierCurve) Adaptor3d_CurveOnSurface::Bezier() const
1359 Standard_NoSuchObject_Raise_if
1360 ( mySurface->GetType() != GeomAbs_Plane,
1361 "Adaptor3d_CurveOnSurface : Bezier");
1363 Handle(Geom2d_BezierCurve) Bez2d = myCurve->Bezier();
1364 Standard_Integer NbPoles = Bez2d->NbPoles();
1366 const gp_Pln& Plane = mySurface->Plane();
1368 TColgp_Array1OfPnt Poles(1,NbPoles);
1369 for ( Standard_Integer i=1; i<= NbPoles; i++) {
1370 Poles(i) = to3d( Plane, Bez2d->Pole(i));
1372 Handle(Geom_BezierCurve) Bez;
1374 if (Bez2d->IsRational()) {
1375 TColStd_Array1OfReal Weights(1,NbPoles);
1376 Bez2d->Weights(Weights);
1377 Bez = new Geom_BezierCurve(Poles,Weights);
1380 Bez = new Geom_BezierCurve(Poles);
1385 //=======================================================================
1386 //function : BSpline
1388 //=======================================================================
1390 Handle(Geom_BSplineCurve) Adaptor3d_CurveOnSurface::BSpline() const
1392 Standard_NoSuchObject_Raise_if
1393 ( mySurface->GetType() != GeomAbs_Plane,
1394 "Adaptor3d_CurveOnSurface : BSpline");
1396 Handle(Geom2d_BSplineCurve) Bsp2d = myCurve->BSpline();
1397 Standard_Integer NbPoles = Bsp2d->NbPoles();
1399 const gp_Pln& Plane = mySurface->Plane();
1401 TColgp_Array1OfPnt Poles(1,NbPoles);
1402 for ( Standard_Integer i=1; i<= NbPoles; i++) {
1403 Poles(i) = to3d( Plane, Bsp2d->Pole(i));
1406 TColStd_Array1OfReal Knots(1,Bsp2d->NbKnots());
1407 TColStd_Array1OfInteger Mults(1,Bsp2d->NbKnots());
1408 Bsp2d->Knots(Knots);
1409 Bsp2d->Multiplicities(Mults);
1411 Handle(Geom_BSplineCurve) Bsp;
1413 if (Bsp2d->IsRational()) {
1414 TColStd_Array1OfReal Weights(1,NbPoles);
1415 Bsp2d->Weights(Weights);
1416 Bsp = new Geom_BSplineCurve(Poles,Weights,Knots,Mults,
1418 Bsp2d->IsPeriodic());
1421 Bsp = new Geom_BSplineCurve(Poles,Knots,Mults,
1423 Bsp2d->IsPeriodic());
1428 //=======================================================================
1429 //function : GetCurve
1431 //=======================================================================
1433 const Handle(Adaptor2d_Curve2d)& Adaptor3d_CurveOnSurface::GetCurve() const
1438 //=======================================================================
1439 //function : GetSurface
1441 //=======================================================================
1443 const Handle(Adaptor3d_Surface)& Adaptor3d_CurveOnSurface::GetSurface() const
1448 //=======================================================================
1449 //function : ChangeCurve
1451 //=======================================================================
1453 Handle(Adaptor2d_Curve2d)& Adaptor3d_CurveOnSurface::ChangeCurve()
1458 //=======================================================================
1459 //function : ChangeSurface
1461 //=======================================================================
1463 Handle(Adaptor3d_Surface)& Adaptor3d_CurveOnSurface::ChangeSurface() {
1467 //=======================================================================
1468 //function : EvalKPart
1470 //=======================================================================
1472 void Adaptor3d_CurveOnSurface::EvalKPart()
1474 myType = GeomAbs_OtherCurve;
1476 GeomAbs_SurfaceType STy = mySurface->GetType();
1477 GeomAbs_CurveType CTy = myCurve->GetType();
1478 if (STy == GeomAbs_Plane) {
1480 if (myType == GeomAbs_Circle)
1481 myCirc = to3d(mySurface->Plane(),myCurve->Circle());
1482 else if (myType == GeomAbs_Line) {
1487 myCurve->D1(0.,Puv,Duv);
1489 mySurface->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1490 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1491 myLin = gp_Lin(P,V);
1495 if ( CTy == GeomAbs_Line) {
1496 gp_Dir2d D = myCurve->Line().Direction();
1497 if ( D.IsParallel(gp::DX2d(),Precision::Angular())) { // Iso V.
1498 if ( STy == GeomAbs_Sphere) {
1499 gp_Pnt2d P = myCurve->Line().Location();
1500 if ( Abs( Abs(P.Y()) -M_PI/2. ) >= Precision::PConfusion()) {
1501 myType = GeomAbs_Circle;
1502 gp_Sphere Sph = mySurface->Sphere();
1503 gp_Ax3 Axis = Sph.Position();
1504 myCirc = ElSLib::SphereVIso(Axis,
1507 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1508 gp_Ax1 AxeRev(Axis.Location(), DRev);
1509 myCirc.Rotate(AxeRev, P.X());
1510 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1511 gp_Ax2 Ax = myCirc.Position();
1512 Ax.SetDirection(Ax.Direction().Reversed());
1513 myCirc.SetPosition(Ax);
1517 else if ( STy == GeomAbs_Cylinder) {
1518 myType = GeomAbs_Circle;
1519 gp_Cylinder Cyl = mySurface->Cylinder();
1520 gp_Pnt2d P = myCurve->Line().Location();
1521 gp_Ax3 Axis = Cyl.Position();
1522 myCirc = ElSLib::CylinderVIso(Axis,
1525 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1526 gp_Ax1 AxeRev(Axis.Location(), DRev);
1527 myCirc.Rotate(AxeRev, P.X());
1528 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1529 gp_Ax2 Ax = myCirc.Position();
1530 Ax.SetDirection(Ax.Direction().Reversed());
1531 myCirc.SetPosition(Ax);
1534 else if ( STy == GeomAbs_Cone) {
1535 myType = GeomAbs_Circle;
1536 gp_Cone Cone = mySurface->Cone();
1537 gp_Pnt2d P = myCurve->Line().Location();
1538 gp_Ax3 Axis = Cone.Position();
1539 myCirc = ElSLib::ConeVIso(Axis,
1543 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1544 gp_Ax1 AxeRev(Axis.Location(), DRev);
1545 myCirc.Rotate(AxeRev, P.X());
1546 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1547 gp_Ax2 Ax = myCirc.Position();
1548 Ax.SetDirection(Ax.Direction().Reversed());
1549 myCirc.SetPosition(Ax);
1552 else if ( STy == GeomAbs_Torus) {
1553 myType = GeomAbs_Circle;
1554 gp_Torus Tore = mySurface->Torus();
1555 gp_Pnt2d P = myCurve->Line().Location();
1556 gp_Ax3 Axis = Tore.Position();
1557 myCirc = ElSLib::TorusVIso(Axis,
1561 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1562 gp_Ax1 AxeRev(Axis.Location(), DRev);
1563 myCirc.Rotate(AxeRev, P.X());
1564 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1565 gp_Ax2 Ax = myCirc.Position();
1566 Ax.SetDirection(Ax.Direction().Reversed());
1567 myCirc.SetPosition(Ax);
1571 else if ( D.IsParallel(gp::DY2d(),Precision::Angular())) { // Iso U.
1572 if ( STy == GeomAbs_Sphere) {
1573 myType = GeomAbs_Circle;
1574 gp_Sphere Sph = mySurface->Sphere();
1575 gp_Pnt2d P = myCurve->Line().Location();
1576 gp_Ax3 Axis = Sph.Position();
1577 // calcul de l'iso 0.
1578 myCirc = ElSLib::SphereUIso(Axis, Sph.Radius(),0.);
1580 // mise a sameparameter (rotation du cercle - decalage du Y)
1581 gp_Dir DRev = Axis.XDirection().Crossed(Axis. Direction());
1582 gp_Ax1 AxeRev(Axis.Location(),DRev);
1583 myCirc.Rotate(AxeRev, P.Y());
1585 // transformation en iso U ( = P.X())
1586 DRev = Axis.XDirection().Crossed(Axis.YDirection());
1587 AxeRev = gp_Ax1(Axis.Location(), DRev);
1588 myCirc.Rotate(AxeRev, P.X());
1590 if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) {
1591 gp_Ax2 Ax = myCirc.Position();
1592 Ax.SetDirection(Ax.Direction().Reversed());
1593 myCirc.SetPosition(Ax);
1596 else if ( STy == GeomAbs_Cylinder) {
1597 myType = GeomAbs_Line;
1598 gp_Cylinder Cyl = mySurface->Cylinder();
1599 gp_Pnt2d P = myCurve->Line().Location();
1600 myLin = ElSLib::CylinderUIso(Cyl.Position(),
1603 gp_Vec Tr(myLin.Direction());
1605 myLin.Translate(Tr);
1606 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
1609 else if ( STy == GeomAbs_Cone) {
1610 myType = GeomAbs_Line;
1611 gp_Cone Cone = mySurface->Cone();
1612 gp_Pnt2d P = myCurve->Line().Location();
1613 myLin = ElSLib::ConeUIso(Cone.Position(),
1617 gp_Vec Tr(myLin.Direction());
1619 myLin.Translate(Tr);
1620 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
1623 else if ( STy == GeomAbs_Torus) {
1624 myType = GeomAbs_Circle;
1625 gp_Torus Tore = mySurface->Torus();
1626 gp_Pnt2d P = myCurve->Line().Location();
1627 gp_Ax3 Axis = Tore.Position();
1628 myCirc = ElSLib::TorusUIso(Axis,
1632 myCirc.Rotate(myCirc.Axis(),P.Y());
1634 if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) {
1635 gp_Ax2 Ax = myCirc.Position();
1636 Ax.SetDirection(Ax.Direction().Reversed());
1637 myCirc.SetPosition(Ax);
1644 //=======================================================================
1645 //function :EvalFirstLastSurf
1647 //=======================================================================
1649 void Adaptor3d_CurveOnSurface::EvalFirstLastSurf()
1651 Standard_Real FirstPar,LastPar;
1652 gp_Pnt2d UV, LeftBot, RightTop;
1654 Standard_Real Tol= Precision::PConfusion()/10;
1655 Standard_Boolean Ok = Standard_True;
1658 FirstPar=myCurve->FirstParameter();
1659 myCurve->D1(FirstPar,UV,DUV);
1661 if(DUV.Magnitude() <= Tol) Ok = Standard_False;
1665 switch(mySurface->GetType()) {
1666 case GeomAbs_BSplineSurface :
1667 LocatePart(UV,DUV,mySurface,LeftBot,RightTop);
1669 case GeomAbs_SurfaceOfRevolution :
1670 case GeomAbs_SurfaceOfExtrusion :
1671 Ok = LocatePart_RevExt(UV,DUV,mySurface,LeftBot,RightTop);
1673 case GeomAbs_OffsetSurface :
1674 Ok = LocatePart_Offset(UV,DUV,mySurface,LeftBot,RightTop);
1677 throw Standard_NotImplemented("Adaptor3d_CurveOnSurface::EvalFirstLastSurf");
1684 CompareBounds(LeftBot,RightTop); //SVV
1686 myFirstSurf = mySurface->UTrim(LeftBot.X(),RightTop.X(),Tol);
1687 myFirstSurf = myFirstSurf->VTrim(LeftBot.Y(),RightTop.Y(),Tol);
1691 myFirstSurf = mySurface;
1694 LastPar=myCurve->LastParameter();
1696 myCurve->D1(LastPar,UV,DUV);
1697 DUV.Reverse(); //We want the other part
1699 if(DUV.Magnitude() <= Tol) Ok = Standard_False;
1703 switch(mySurface->GetType()) {
1704 case GeomAbs_BSplineSurface :
1705 LocatePart(UV,DUV,mySurface,LeftBot,RightTop);
1707 case GeomAbs_SurfaceOfRevolution :
1708 case GeomAbs_SurfaceOfExtrusion :
1709 Ok = LocatePart_RevExt(UV,DUV,mySurface,LeftBot,RightTop);
1711 case GeomAbs_OffsetSurface :
1712 Ok = LocatePart_Offset(UV,DUV,mySurface,LeftBot,RightTop);
1715 throw Standard_NotImplemented("Adaptor3d_CurveOnSurface::EvalFirstLastSurf");
1722 CompareBounds(LeftBot, RightTop); //SVV
1724 myLastSurf = mySurface->UTrim(LeftBot.X(),RightTop.X(),Tol);
1725 myLastSurf = myLastSurf->VTrim(LeftBot.Y(),RightTop.Y(),Tol);
1729 myLastSurf = mySurface;
1733 //=======================================================================
1734 //function :LocatePart_RevExt
1735 //purpose : processes Knots
1736 //=======================================================================
1738 Standard_Boolean Adaptor3d_CurveOnSurface::LocatePart_RevExt(const gp_Pnt2d& UV,
1739 const gp_Vec2d& DUV,
1740 const Handle(Adaptor3d_Surface)& S,
1742 gp_Pnt2d& RightTop) const
1744 Handle(Adaptor3d_Curve) AHC = S->BasisCurve();
1746 if (AHC->GetType() == GeomAbs_BSplineCurve) {
1747 Handle( Geom_BSplineCurve) BSplC;
1748 BSplC = AHC->BSpline();
1750 if((S->GetType())==GeomAbs_SurfaceOfExtrusion) {
1751 Locate1Coord(1,UV,DUV,BSplC,LeftBot,RightTop);
1752 Locate2Coord(2,UV,DUV,S->FirstVParameter(),S->LastVParameter(),LeftBot,RightTop);
1754 else if((S->GetType())==GeomAbs_SurfaceOfRevolution) {
1755 Locate1Coord(2,UV,DUV,BSplC,LeftBot,RightTop);
1756 Locate2Coord(1,UV,DUV,S->FirstUParameter(),S->LastUParameter(),LeftBot,RightTop);
1759 Standard_Real u1,u2,v1,v2;
1760 ReverseParam(LeftBot.X(),RightTop.X(),u1,u2);
1763 ReverseParam(LeftBot.Y(),RightTop.Y(),v1,v2);
1766 return Standard_True;
1768 return Standard_False;
1771 //=======================================================================
1772 //function :LocatePart_OffsetSurface
1774 //=======================================================================
1776 Standard_Boolean Adaptor3d_CurveOnSurface::
1777 LocatePart_Offset(const gp_Pnt2d& UV, const gp_Vec2d& DUV,
1778 const Handle(Adaptor3d_Surface)& S,
1779 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop) const
1781 Standard_Boolean Ok = Standard_True;
1782 Handle( Adaptor3d_Surface) AHS;
1783 Handle( Geom_BSplineSurface) BSplS;
1784 AHS = S->BasisSurface();
1785 GeomAbs_SurfaceType BasisSType = AHS->GetType();
1786 switch(BasisSType) {
1787 case GeomAbs_SurfaceOfRevolution:
1788 case GeomAbs_SurfaceOfExtrusion :
1789 Ok = LocatePart_RevExt(UV,DUV,AHS,LeftBot,RightTop);
1792 case GeomAbs_BSplineSurface:
1793 LocatePart(UV,DUV,AHS,LeftBot,RightTop);
1802 //=======================================================================
1803 //function :LocatePart
1804 //purpose : for BSplineSurface
1805 //=======================================================================
1807 void Adaptor3d_CurveOnSurface::LocatePart(const gp_Pnt2d& UV, const gp_Vec2d& DUV,
1808 const Handle(Adaptor3d_Surface)& S,
1809 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop) const
1811 Handle( Geom_BSplineSurface) BSplS;
1812 BSplS = S->BSpline();
1813 Standard_Boolean DUIsNull=Standard_False,
1814 DVIsNull=Standard_False;
1816 Locate1Coord(1,UV,DUV,BSplS,DUIsNull,LeftBot,RightTop);
1817 Locate1Coord(2,UV,DUV,BSplS,DVIsNull,LeftBot,RightTop);
1819 if((DUIsNull==Standard_True)&&(DVIsNull==Standard_False)) {
1820 TColStd_Array1OfReal ArrU(1,BSplS->NbUKnots());
1821 BSplS->UKnots(ArrU);
1822 Locate2Coord(1,UV,DUV,BSplS,ArrU,LeftBot,RightTop);
1824 else if((DVIsNull==Standard_True)&&(DUIsNull==Standard_False)) {
1825 TColStd_Array1OfReal ArrV(1,BSplS->NbVKnots());
1826 BSplS->VKnots(ArrV);
1827 Locate2Coord(2,UV,DUV,BSplS,ArrV,LeftBot,RightTop);