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 <Adaptor2d_HCurve2d.hxx>
18 #include <Adaptor3d_CurveOnSurface.hxx>
19 #include <Adaptor3d_HCurve.hxx>
20 #include <Adaptor3d_HCurveOnSurface.hxx>
21 #include <Adaptor3d_HSurface.hxx>
22 #include <Adaptor3d_InterFunc.hxx>
25 #include <Geom2d_BezierCurve.hxx>
26 #include <Geom2d_BSplineCurve.hxx>
27 #include <Geom_BezierCurve.hxx>
28 #include <Geom_BSplineCurve.hxx>
29 #include <Geom_BSplineSurface.hxx>
30 #include <Geom_OffsetSurface.hxx>
31 #include <Geom_SurfaceOfLinearExtrusion.hxx>
32 #include <Geom_SurfaceOfRevolution.hxx>
33 #include <gp_Ax22d.hxx>
34 #include <gp_Circ.hxx>
35 #include <gp_Circ2d.hxx>
36 #include <gp_Elips.hxx>
37 #include <gp_Elips2d.hxx>
38 #include <gp_Hypr.hxx>
39 #include <gp_Hypr2d.hxx>
41 #include <gp_Lin2d.hxx>
42 #include <gp_Parab.hxx>
43 #include <gp_Parab2d.hxx>
45 #include <gp_Pnt2d.hxx>
47 #include <gp_Vec2d.hxx>
48 #include <math_FunctionRoots.hxx>
49 #include <Precision.hxx>
50 #include <Standard_Assert.hxx>
51 #include <Standard_DomainError.hxx>
52 #include <Standard_NoSuchObject.hxx>
53 #include <Standard_NotImplemented.hxx>
54 #include <Standard_OutOfRange.hxx>
55 #include <TColgp_Array1OfPnt.hxx>
56 #include <TColgp_Array1OfPnt2d.hxx>
57 #include <TColStd_Array1OfInteger.hxx>
58 #include <TColStd_Array1OfReal.hxx>
59 #include <TColStd_HSequenceOfReal.hxx>
61 static gp_Pnt to3d(const gp_Pln& Pl, const gp_Pnt2d& P)
63 return ElSLib::Value(P.X(),P.Y(),Pl);
66 static gp_Vec to3d(const gp_Pln& Pl, const gp_Vec2d& V)
68 gp_Vec Vx = Pl.XAxis().Direction();
69 gp_Vec Vy = Pl.YAxis().Direction();
76 static gp_Ax2 to3d(const gp_Pln& Pl, const gp_Ax22d& A)
78 gp_Pnt P = to3d(Pl,A.Location());
79 gp_Vec VX = to3d(Pl,A.XAxis().Direction());
80 gp_Vec VY = to3d(Pl,A.YAxis().Direction());
81 return gp_Ax2(P,VX.Crossed(VY),VX);
84 static gp_Circ to3d(const gp_Pln& Pl, const gp_Circ2d& C)
86 return gp_Circ(to3d(Pl,C.Axis()),C.Radius());
89 static gp_Elips to3d(const gp_Pln& Pl, const gp_Elips2d& E)
91 return gp_Elips(to3d(Pl,E.Axis()),E.MajorRadius(),E.MinorRadius());
94 static gp_Hypr to3d(const gp_Pln& Pl, const gp_Hypr2d& H)
96 return gp_Hypr(to3d(Pl,H.Axis()),H.MajorRadius(),H.MinorRadius());
99 static gp_Parab to3d(const gp_Pln& Pl, const gp_Parab2d& P)
101 return gp_Parab(to3d(Pl,P.Axis()),P.Focal());
104 static gp_Vec SetLinearForm(const gp_Vec2d DW, const gp_Vec2d D2W,const gp_Vec2d D3W,
105 const gp_Vec D1U, const gp_Vec D1V, const gp_Vec D2U,
106 const gp_Vec D2V, const gp_Vec D2UV, const gp_Vec D3U,
107 const gp_Vec D3V, const gp_Vec D3UUV,const gp_Vec D3UVV)
108 {gp_Vec V31, V32, V33, V34,V3 ;
109 V31.SetLinearForm(DW.X(),D1U,
111 D2W.X()*DW.Y(),D2UV);
112 V31.SetLinearForm(D3W.Y(),D1V,
116 V32.SetLinearForm(DW.X()*DW.X()*DW.Y(),D3UUV,
117 DW.X()*DW.Y()*DW.Y(),D3UVV);
118 V32.SetLinearForm(D2W.X()*DW.Y()+DW.X()*D2W.Y(),D2UV,
119 DW.X()*DW.Y()*DW.Y(),D3UVV,
121 V33.SetLinearForm(2*D2W.X()*DW.X(),D2U,
122 DW.X()*DW.X()*DW.X(),D3U,
123 DW.X()*DW.X()*DW.Y(),D3UUV);
125 V34.SetLinearForm(2*D2W.Y()*DW.Y(),D2V,
126 DW.Y()*DW.Y()*DW.X(),D3UVV,
127 DW.Y()*DW.Y()*DW.Y(),D3V);
128 V3.SetLinearForm(1,V31,2,V32,1,V33,V34);
132 //=======================================================================
133 static void CompareBounds(gp_Pnt2d& P1,
136 Standard_Real Lx = P1.X(),Ly = P1.Y();
137 Standard_Real Rx = P2.X(),Ry = P2.Y();
139 if (Lx > Rx) { P1.SetX(Rx); P2.SetX(Lx);}
140 if (Ly > Ry) { P1.SetY(Ry); P2.SetY(Ly);}
143 //=======================================================================
146 //=======================================================================
147 static void Hunt(const TColStd_Array1OfReal& Arr,
148 const Standard_Real Coord,
149 Standard_Integer& Iloc)
150 {//Warning: Hunt is used to find number of knot which equals co-ordinate component,
151 // when co-ordinate component definitly equals a knot only.
152 Standard_Real Tol=Precision::PConfusion()/10;
153 Standard_Integer i=1;
154 while((i <= Arr.Upper()) && (Abs(Coord - Arr(i)) > Tol)){
157 if(Abs(Coord - Arr(i)) < Tol)
160 if(Abs(Coord - Arr(i)) > Tol)
161 Standard_NotImplemented::Raise("Adaptor3d_CurveOnSurface:Hunt");
164 //=======================================================================
165 //function :ReverseParam
167 //=======================================================================
169 static void ReverseParam(const Standard_Real In1,
170 const Standard_Real In2,
172 Standard_Real& Out2 )
175 if(In1>In2) {Out1=In2;
180 //=======================================================================
181 //function :ReverseParam
183 //=======================================================================
185 static void ReverseParam(const Standard_Integer In1,
186 const Standard_Integer In2,
187 Standard_Integer& Out1,
188 Standard_Integer& Out2 )
190 if(In1>In2) {Out1=In2;
196 //=======================================================================
197 //function :FindBounds
199 //=======================================================================
200 static void FindBounds(const TColStd_Array1OfReal& Arr,
201 const Standard_Real Coord,
202 const Standard_Real Der,
203 Standard_Integer& Bound1,
204 Standard_Integer& Bound2,
205 Standard_Boolean& DerNull)
208 Standard_Integer N=0;
209 Standard_Real Tol=Precision::PConfusion()/10;
211 DerNull=Standard_False;
213 if(N==Bound1){ if(Abs(Der) > Tol) DerNull = Standard_False;
214 if(Abs(Der)<= Tol) DerNull = Standard_True;
215 Bound1=N;Bound2=N+1; return;
217 if(N==Bound2){ if( Abs(Der) > Tol ) DerNull = Standard_False;
218 if( Abs(Der)<= Tol ) DerNull = Standard_True;
219 Bound1=N-1;Bound2=N; return;
221 if((N!=Bound1)&&(N!=Bound2)) {
222 if(Abs(Der) > Tol ) {
223 if(Der>0) {Bound1=N;Bound2= N+1;}
225 if(Der<0){Bound1=N-1;Bound2=N;}
226 DerNull = Standard_False;
228 if(Abs(Der) <=Tol ) {
229 DerNull = Standard_True;
236 //=======================================================================
237 //function :Locate1Coord
238 //purpose : along BSpline curve
239 //=======================================================================
241 static void Locate1Coord(const Standard_Integer Index,
244 const Handle(Geom_BSplineCurve)& BSplC,
245 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop)
247 Standard_Real Comp1=0, DComp1=0, cur, f = 0.0, l = 0.0;
248 Standard_Real Tol = Precision::PConfusion()/10;
249 Standard_Integer i = 1, Bnd1, Bnd2;
250 Standard_Boolean DIsNull= Standard_False;
251 TColStd_Array1OfReal Arr(1,BSplC->NbKnots()); BSplC->Knots(Arr);
253 if(Index==1) { Comp1=UV.X(); DComp1=DUV.X(); }
254 if(Index==2) { Comp1=UV.Y(); DComp1=DUV.Y(); }
256 Standard_Integer Lo = BSplC->FirstUKnotIndex(), Up = BSplC->LastUKnotIndex();
259 while ( ( Abs(BSplC->Knot(i)-Comp1)>Tol )&& (i!=Up ) ) i++;
262 if( Abs(Comp1-cur)<=Tol) {
264 Bnd1 = Lo; Bnd2 = Up;
265 FindBounds(Arr,cur,DComp1,Bnd1,Bnd2,DIsNull);
266 ReverseParam(Bnd1,Bnd2,Bnd1,Bnd2);
268 if(DIsNull==Standard_False){
269 if(Index==1) {LeftBot.SetX(BSplC->Knot(Bnd1));
270 RightTop.SetX(BSplC->Knot(Bnd2));}
272 if(Index==2){ LeftBot.SetY(BSplC->Knot(Bnd1));
273 RightTop.SetY(BSplC->Knot(Bnd2)); }
276 if(DIsNull==Standard_True){
277 if( Abs( Comp1-(f=BSplC->Knot(Lo))) <= Tol)
279 if(Index==1) { LeftBot.SetX(BSplC->Knot(Lo));
280 RightTop.SetX(BSplC->Knot(Lo+1));}
281 else if(Index==2) { LeftBot.SetY(BSplC->Knot(Lo));
282 RightTop.SetY(BSplC->Knot(Lo+1));}
284 if( Abs( Comp1-(l=BSplC->Knot(Up))) <= Tol)
286 if(Index==1) { LeftBot.SetX(BSplC->Knot(Up-1));
287 RightTop.SetX(BSplC->Knot(Up));}
288 else if(Index==2) {LeftBot.SetY(BSplC->Knot(Up-1));
289 RightTop.SetY(BSplC->Knot(Up));}
291 if(Index==1) { LeftBot.SetX(BSplC->Knot(Bnd1));
292 RightTop.SetX(BSplC->Knot(Bnd2));}
293 else if(Index==2) {LeftBot.SetY(BSplC->Knot(Bnd1));
294 RightTop.SetY(BSplC->Knot(Bnd2));}
297 else//*********if Coord != Knot
301 //if((f=BSplC->Knot(i))<Comp1 && (l=BSplC->Knot(i+1))>Comp1) break;
302 //skl 28.03.2002 for OCC233
305 if(f<Comp1 && l>Comp1) break;
308 ReverseParam(f,l,f,l);
312 { if(Index==1) {LeftBot.SetX(f); RightTop.SetX(l);}else
313 if(Index==2) {LeftBot.SetY(f); RightTop.SetY(l); }
318 if(DComp1>0) {LeftBot.SetX(Comp1); RightTop.SetX(l);} else
319 if(DComp1<0) {LeftBot.SetX(f); RightTop.SetX(Comp1);}
323 if(DComp1>0) {LeftBot.SetY(Comp1); RightTop.SetY(l);} else
324 if(DComp1<0) {LeftBot.SetY(f); RightTop.SetY(Comp1);};
329 if(Index==1) {LeftBot.SetX(Comp1); RightTop.SetX(BSplC->Knot(i));}else
330 if(Index==2) {LeftBot.SetY(Comp1); RightTop.SetY(BSplC->Knot(i)); }
336 //=======================================================================
337 //function :Locate1Coord
339 //=======================================================================
341 static void Locate1Coord(const Standard_Integer Index,
344 const Handle(Geom_BSplineSurface)& BSplS,
345 Standard_Boolean& DIsNull,
349 Standard_Real Comp1=0,DComp1=0;
350 Standard_Real Tol = Precision::PConfusion()/10;
351 Standard_Integer i=1, Up=0, Up1, Up2, Down=0, Down1, Down2;
352 Standard_Real cur = 0.;
354 DIsNull= Standard_False;
356 Up1 = BSplS->LastUKnotIndex();
357 Down1 = BSplS->FirstUKnotIndex();
358 Up2 = BSplS->LastVKnotIndex();
359 Down2 = BSplS->FirstVKnotIndex();
369 while ( ( Abs(BSplS->UKnot(i)-Comp1)>Tol )&&(i!=Up1 ) )
374 cur = BSplS->UKnot(i);
384 while ( ( Abs(BSplS->VKnot(i)-Comp1)>Tol )&&(i!=Up2 ) )
389 cur = BSplS->VKnot(i);
392 if( Abs(Comp1-cur)<=Tol )
394 Standard_Integer Bnd1 = Down, Bnd2 = Up;
397 TColStd_Array1OfReal Arr1(1,BSplS->NbUKnots());
398 BSplS->UKnots(Arr1); // Up1=Arr1.Upper(); Down1=Arr1.Lower();
399 FindBounds(Arr1,cur,DUV.X(),Bnd1,Bnd2,DIsNull);
403 TColStd_Array1OfReal Arr2(1,BSplS->NbVKnots());
404 BSplS->VKnots(Arr2); // Up2=Arr2.Upper(); Down2=Arr2.Lower();
405 FindBounds(Arr2,cur,DUV.Y(),Bnd1,Bnd2,DIsNull);
408 ReverseParam(Bnd1,Bnd2,Bnd1,Bnd2);
410 if(DIsNull==Standard_False)
414 LeftBot.SetX(BSplS->UKnot(Bnd1));
415 RightTop.SetX(BSplS->UKnot(Bnd2));
419 LeftBot.SetY(BSplS->VKnot(Bnd1));
420 RightTop.SetY(BSplS->VKnot(Bnd2));
424 else//*********if Coord != Knot
426 if( (Index==1)&&(Comp1 < BSplS->UKnot(Down)) )
428 LeftBot.SetX(BSplS->UKnot(Down));
429 RightTop.SetX( BSplS->UKnot(Down + 1) );
432 else if( (Index==2)&&(Comp1 < BSplS->VKnot(Down)) )
434 LeftBot.SetY(BSplS->VKnot(Down));
435 RightTop.SetY( BSplS->VKnot(Down + 1) );
438 else if( (Index==1)&&(Comp1 > BSplS->UKnot(Up)) )
440 RightTop.SetX(BSplS->UKnot(Up - 1));
441 LeftBot.SetX( BSplS->UKnot(Up) );
444 else if( (Index==2)&&(Comp1 > BSplS->VKnot(Up)) )
446 RightTop.SetY(BSplS->VKnot(Up - 1));
447 LeftBot.SetY( BSplS->VKnot(Up) );
452 Standard_Real f = 0., l = 1.;
455 f=BSplS->UKnot(Down);
460 f=BSplS->VKnot(Down);
465 if ((!(Comp1 < f))&&(!(Comp1 > l)))
469 while (!(((f=BSplS->UKnot(i)) < Comp1)&&((l=BSplS->UKnot(i+1)) > Comp1)) && (i<Up))
476 while (!(((f=BSplS->VKnot(i)) < Comp1)&&((l=BSplS->VKnot(i+1)) > Comp1)) && (i<Up))
483 ReverseParam(f,l,f,l);
499 RightTop.SetX(Comp1);
512 RightTop.SetY(Comp1);
538 RightTop.SetX(BSplS->UKnot(i));
543 RightTop.SetY(BSplS->VKnot(i));
549 //=======================================================================
550 //function :Locate2Coord
551 //purpose : along non-BSpline curve
552 //=======================================================================
555 static void Locate2Coord(const Standard_Integer Index,
556 const gp_Pnt2d& UV, const gp_Vec2d& DUV,
557 const Standard_Real I1,
558 const Standard_Real I2,
559 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop)
561 Standard_Real Tol=Precision::PConfusion()/10;
562 Standard_Real Comp1=0,DComp1=0;
563 if(Index==1) { Comp1=UV.X();
566 if(Index==2) {Comp1=UV.Y();
569 if((Comp1!=I1)&&(Comp1!=I2))
570 { if(Abs(DComp1) > Tol)
572 { if(Index==1) { LeftBot.SetX(I1);
573 RightTop.SetX(Comp1);}
574 if(Index==2) { LeftBot.SetY(I1);
575 RightTop.SetY(Comp1);}
579 { if(Index==1) { LeftBot.SetX(Comp1);
581 if(Index==2) { LeftBot.SetY(Comp1);
584 else { if(Index==1) { LeftBot.SetX(I1);
586 if(Index==2) { LeftBot.SetY(I1);
591 if(Abs(DComp1)<=Tol) {
592 if(Index==1) { LeftBot.SetX(I1) ;
594 if(Index==2) { LeftBot.SetY(I1) ;
598 if(Abs(Comp1-I1)<Tol)
599 { if(Index==1) { LeftBot.SetX(I1) ;
601 if(Index==2) { LeftBot.SetY(I1) ;
605 if(Abs(Comp1-I2)<Tol)
606 { if(Index==1) { LeftBot.SetX(I1);
608 if(Index==2) { LeftBot.SetY(I1);
613 //=======================================================================
614 //function :Locate2Coord
616 //=======================================================================
618 static void Locate2Coord(const Standard_Integer Index,
619 const gp_Pnt2d& UV, const gp_Vec2d& DUV,
620 const Handle(Geom_BSplineSurface)& BSplS,
621 const TColStd_Array1OfReal& Arr,
622 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop)
624 Standard_Real Comp=0,DComp=0,Tmp1=0.0,Tmp2=0.0;
625 Standard_Real Tol=Precision::PConfusion()/10;
626 Standard_Integer N=0, NUp=0, NLo=0;
630 NUp = BSplS->LastUKnotIndex();
631 NLo = BSplS->FirstUKnotIndex();
636 NUp = BSplS->LastVKnotIndex();
637 NLo = BSplS->FirstVKnotIndex();
640 if((DComp > 0)&&(Abs(DComp)>Tol)) {
643 //limit case: Hunt() cought upper knot. Take the last span.
646 if(Index==1) { Tmp1=BSplS->UKnot(N);
647 Tmp2=BSplS->UKnot(N+1);}
649 if(Index==2) { Tmp1=BSplS->VKnot(N);
650 Tmp2=BSplS->VKnot(N+1);}
652 ReverseParam(Tmp1,Tmp2,Tmp1,Tmp2);
654 if(Index==1) { LeftBot.SetX(Tmp1);
655 RightTop.SetX(Tmp2);}
657 if(Index==2) { LeftBot.SetY(Tmp1);
658 RightTop.SetY(Tmp2);}
661 if((DComp < 0)&&(Abs(DComp)>Tol)){
664 //limit case: Hunt() cought lower knot. Take the first span.
667 if(Index==1) { Tmp1=BSplS->UKnot(N-1);
668 Tmp2=BSplS->UKnot(N);}
670 if(Index==2) { Tmp1=BSplS->VKnot(N-1);
671 Tmp2=BSplS->VKnot(N);}
673 ReverseParam(Tmp1,Tmp2,Tmp1,Tmp2);
675 if(Index==1) { LeftBot.SetX(Tmp1);
676 RightTop.SetX(Tmp2);}
678 if(Index==2) { LeftBot.SetY(Tmp1);
679 RightTop.SetY(Tmp2);}
685 //=======================================================================
686 //function : Adaptor3d_CurveOnSurface
688 //=======================================================================
690 Adaptor3d_CurveOnSurface::Adaptor3d_CurveOnSurface()
691 : myType(GeomAbs_OtherCurve), myIntCont(GeomAbs_CN)
694 //=======================================================================
695 //function : Adaptor3d_CurveOnSurface
697 //=======================================================================
699 Adaptor3d_CurveOnSurface::Adaptor3d_CurveOnSurface
700 (const Handle(Adaptor3d_HSurface)& S)
701 : myType(GeomAbs_OtherCurve), myIntCont(GeomAbs_CN)
706 //=======================================================================
707 //function : Adaptor3d_CurveOnSurface
709 //=======================================================================
711 Adaptor3d_CurveOnSurface::Adaptor3d_CurveOnSurface
712 (const Handle(Adaptor2d_HCurve2d)& C,
713 const Handle(Adaptor3d_HSurface)& S)
714 : myType(GeomAbs_OtherCurve), myIntCont(GeomAbs_CN)
720 //=======================================================================
723 //=======================================================================
725 void Adaptor3d_CurveOnSurface::Load(const Handle(Adaptor3d_HSurface)& S)
728 if (!myCurve.IsNull()) EvalKPart();
731 //=======================================================================
734 //=======================================================================
736 void Adaptor3d_CurveOnSurface::Load(const Handle(Adaptor2d_HCurve2d)& C)
739 if (!mySurface.IsNull())
742 GeomAbs_SurfaceType SType ;
743 SType = mySurface->GetType();
744 if( SType == GeomAbs_BSplineSurface)
746 if( SType == GeomAbs_SurfaceOfExtrusion)
748 if( SType == GeomAbs_SurfaceOfRevolution)
750 if( SType == GeomAbs_OffsetSurface) {
751 SType = mySurface->BasisSurface()->GetType();
752 if( SType == GeomAbs_SurfaceOfRevolution ||
753 SType == GeomAbs_SurfaceOfExtrusion ||
754 SType == GeomAbs_BSplineSurface )
760 //=======================================================================
763 //=======================================================================
765 void Adaptor3d_CurveOnSurface::Load (const Handle(Adaptor2d_HCurve2d)& C,
766 const Handle(Adaptor3d_HSurface)& S)
772 //=======================================================================
773 //function : FirstParameter
775 //=======================================================================
777 Standard_Real Adaptor3d_CurveOnSurface::FirstParameter() const
779 return myCurve->FirstParameter();
782 //=======================================================================
783 //function : LastParameter
785 //=======================================================================
787 Standard_Real Adaptor3d_CurveOnSurface::LastParameter() const
789 return myCurve->LastParameter();
792 //=======================================================================
793 //function : Continuity
795 //=======================================================================
797 GeomAbs_Shape Adaptor3d_CurveOnSurface::Continuity() const
799 GeomAbs_Shape ContC = myCurve->Continuity();
800 GeomAbs_Shape ContSu = mySurface->UContinuity();
801 if ( ContSu < ContC) ContC = ContSu;
802 GeomAbs_Shape ContSv = mySurface->VContinuity();
803 if ( ContSv < ContC) ContC = ContSv;
808 // Auxiliary: adds roots of equation to sorted sequence of parameters
809 // along curve, keeping it sorted and avoiding repetitions (within tolerance Tol)
810 static void AddIntervals (const Handle(TColStd_HSequenceOfReal)& theParameters,
811 const math_FunctionRoots& theRoots, Standard_Real theTol)
813 if (! theRoots.IsDone() || theRoots.IsAllNull())
816 Standard_Integer nsol = theRoots.NbSolutions();
817 for (Standard_Integer i = 1; i <= nsol; i++)
819 Standard_Real param = theRoots.Value(i);
820 if (param - theParameters->Value(1) < theTol) // skip param if equal to or less than theParameters(1)
822 for (Standard_Integer j=2; j <= theParameters->Length(); ++j)
824 Standard_Real aDelta = theParameters->Value(j) - param;
827 theParameters->InsertBefore (j, param);
830 else if (aDelta >= -theTol) // param == theParameters(j) within Tol
836 //=======================================================================
837 //function : NbIntervals
839 //=======================================================================
841 Standard_Integer Adaptor3d_CurveOnSurface::NbIntervals (const GeomAbs_Shape S) const
843 if(S == myIntCont && !myIntervals.IsNull())
844 return myIntervals->Length()-1;
846 Standard_Integer nu,nv,nc;
847 nu=mySurface->NbUIntervals(S);
848 nv=mySurface->NbVIntervals(S);
850 TColStd_Array1OfReal TabU(1,nu+1);
851 TColStd_Array1OfReal TabV(1,nv+1);
852 Standard_Integer NbSample = 20;
853 Standard_Real U,V,Tdeb,Tfin;
854 Tdeb=myCurve->FirstParameter();
855 Tfin=myCurve->LastParameter();
857 nc=myCurve->NbIntervals(S);
858 TColStd_Array1OfReal TabC(1,nc+1);
859 myCurve->Intervals(TabC,S);
861 Standard_Real Tol= Precision::PConfusion()/10;
863 // sorted sequence of parameters defining continuity intervals;
864 // started with own intervals of curve and completed by
865 // additional points coming from surface discontinuities
866 Handle(TColStd_HSequenceOfReal) aIntervals = new TColStd_HSequenceOfReal;
867 for (Standard_Integer i = 1; i <= nc + 1; i++)
869 aIntervals->Append(TabC(i));
874 mySurface->UIntervals(TabU,S);
875 for(Standard_Integer iu = 2;iu <= nu; iu++)
878 Adaptor3d_InterFunc Func(myCurve,U,1);
879 math_FunctionRoots Resol(Func,Tdeb,Tfin,NbSample,Tol,Tol,Tol,0.);
880 AddIntervals (aIntervals, Resol, Tol);
885 mySurface->VIntervals(TabV,S);
886 for(Standard_Integer iv = 2;iv <= nv; iv++)
889 Adaptor3d_InterFunc Func(myCurve,V,2);
890 math_FunctionRoots Resol(Func,Tdeb,Tfin,NbSample,Tol,Tol,Tol,0.);
891 AddIntervals (aIntervals, Resol, Tol);
895 // for case intervals==1 and first point == last point SequenceOfReal
896 // contains only one value, therefore it is necessary to add second
897 // value into aIntervals which will be equal first value.
898 if (aIntervals->Length() == 1)
899 aIntervals->Append (aIntervals->Value(1));
901 const_cast<Adaptor3d_CurveOnSurface*>(this)->myIntervals = aIntervals;
902 const_cast<Adaptor3d_CurveOnSurface*>(this)->myIntCont = S;
903 return myIntervals->Length() - 1;
906 //=======================================================================
907 //function : Intervals
909 //=======================================================================
911 void Adaptor3d_CurveOnSurface::Intervals(TColStd_Array1OfReal& T,
912 const GeomAbs_Shape S) const
915 Standard_ASSERT_RAISE (T.Length() == myIntervals->Length(), "Error: Wrong size of array buffer in call to Adaptor3d_CurveOnSurface::Intervals");
916 for(Standard_Integer i=1; i<=myIntervals->Length(); i++) {
917 T(i) = myIntervals->Value(i);
921 //=======================================================================
924 //=======================================================================
926 Handle(Adaptor3d_HCurve) Adaptor3d_CurveOnSurface::Trim
927 (const Standard_Real First,
928 const Standard_Real Last,
929 const Standard_Real Tol) const
931 Handle(Adaptor3d_HCurveOnSurface) HCS = new Adaptor3d_HCurveOnSurface();
932 HCS->ChangeCurve().Load(mySurface);
933 HCS->ChangeCurve().Load(myCurve->Trim(First,Last,Tol));
937 //=======================================================================
938 //function : IsClosed
940 //=======================================================================
942 Standard_Boolean Adaptor3d_CurveOnSurface::IsClosed() const
944 return myCurve->IsClosed();
947 //=======================================================================
948 //function : IsPeriodic
950 //=======================================================================
952 Standard_Boolean Adaptor3d_CurveOnSurface::IsPeriodic() const
954 return myCurve->IsPeriodic();
957 //=======================================================================
960 //=======================================================================
962 Standard_Real Adaptor3d_CurveOnSurface::Period() const
964 return myCurve->Period();
967 //=======================================================================
970 //=======================================================================
972 gp_Pnt Adaptor3d_CurveOnSurface::Value(const Standard_Real U ) const
977 if (myType == GeomAbs_Line ) P = ElCLib::Value(U,myLin );
978 else if (myType == GeomAbs_Circle) P = ElCLib::Value(U,myCirc);
981 mySurface->D0(Puv.X(),Puv.Y(),P);
987 //=======================================================================
990 //=======================================================================
992 void Adaptor3d_CurveOnSurface::D0(const Standard_Real U ,
997 if (myType == GeomAbs_Line ) P = ElCLib::Value(U,myLin );
998 else if (myType == GeomAbs_Circle) P = ElCLib::Value(U,myCirc);
1001 mySurface->D0(Puv.X(),Puv.Y(),P);
1007 //=======================================================================
1010 //=======================================================================
1012 void Adaptor3d_CurveOnSurface::D1(const Standard_Real U ,
1020 Standard_Real FP = myCurve->FirstParameter();
1021 Standard_Real LP = myCurve->LastParameter();
1023 Standard_Real Tol= Precision::PConfusion()/10;
1024 if( ( Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
1026 myCurve->D1(U,Puv,Duv);
1027 myFirstSurf->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1028 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1031 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
1033 myCurve->D1(U,Puv,Duv);
1034 myLastSurf->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1035 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1038 if (myType == GeomAbs_Line ) ElCLib::D1(U,myLin ,P,V);
1039 else if (myType == GeomAbs_Circle) ElCLib::D1(U,myCirc,P,V);
1041 myCurve->D1(U,Puv,Duv);
1042 mySurface->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1043 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1046 //=======================================================================
1049 //=======================================================================
1051 void Adaptor3d_CurveOnSurface::D2(const Standard_Real U,
1058 gp_Vec D1U,D1V,D2U,D2V,D2UV;
1060 Standard_Real FP = myCurve->FirstParameter();
1061 Standard_Real LP = myCurve->LastParameter();
1063 Standard_Real Tol= Precision::PConfusion()/10;
1064 if( (Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
1066 myCurve->D2(U,UV,DW,D2W);
1067 myFirstSurf->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
1069 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1070 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1071 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1074 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
1076 myCurve->D2(U,UV,DW,D2W);
1077 myLastSurf->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);
1084 if (myType == GeomAbs_Line ) {
1085 ElCLib::D1(U,myLin,P,V1);
1086 V2.SetCoord(0.,0.,0.);
1088 else if (myType == GeomAbs_Circle) ElCLib::D2(U,myCirc,P,V1,V2);
1090 myCurve->D2(U,UV,DW,D2W);
1091 mySurface->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
1093 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1094 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1095 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1099 //=======================================================================
1102 //=======================================================================
1104 void Adaptor3d_CurveOnSurface::D3
1105 (const Standard_Real U,
1112 Standard_Real Tol= Precision::PConfusion()/10;
1114 gp_Vec2d DW,D2W,D3W;
1115 gp_Vec D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV;
1117 Standard_Real FP = myCurve->FirstParameter();
1118 Standard_Real LP = myCurve->LastParameter();
1120 if( (Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
1121 { myCurve->D3(U,UV,DW,D2W,D3W);
1122 myFirstSurf->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
1123 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1124 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1125 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1126 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1129 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
1130 { myCurve->D3(U,UV,DW,D2W,D3W);
1131 myLastSurf->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
1132 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1134 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1135 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1136 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1139 if (myType == GeomAbs_Line ) {
1140 ElCLib::D1(U,myLin,P,V1);
1141 V2.SetCoord(0.,0.,0.);
1142 V3.SetCoord(0.,0.,0.);
1144 else if (myType == GeomAbs_Circle) ElCLib::D3(U,myCirc,P,V1,V2,V3);
1146 myCurve->D3(U,UV,DW,D2W,D3W);
1147 mySurface->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
1148 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1150 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1151 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1152 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1157 //=======================================================================
1160 //=======================================================================
1162 gp_Vec Adaptor3d_CurveOnSurface::DN
1163 (const Standard_Real U,
1164 const Standard_Integer N) const
1179 Standard_NotImplemented::Raise("Adaptor3d_CurveOnSurface:DN");
1186 //=======================================================================
1187 //function : Resolution
1189 //=======================================================================
1191 Standard_Real Adaptor3d_CurveOnSurface::Resolution
1192 (const Standard_Real R3d) const
1194 Standard_Real ru,rv;
1195 ru = mySurface->UResolution(R3d);
1196 rv = mySurface->VResolution(R3d);
1197 return myCurve->Resolution(Min(ru,rv));
1201 //=======================================================================
1202 //function : GetType
1204 //=======================================================================
1206 GeomAbs_CurveType Adaptor3d_CurveOnSurface::GetType() const
1212 //=======================================================================
1215 //=======================================================================
1217 gp_Lin Adaptor3d_CurveOnSurface::Line() const
1219 Standard_NoSuchObject_Raise_if(myType != GeomAbs_Line, "Adaptor3d_CurveOnSurface::Line(): curve is not a line")
1223 //=======================================================================
1226 //=======================================================================
1228 gp_Circ Adaptor3d_CurveOnSurface::Circle() const
1230 Standard_NoSuchObject_Raise_if(myType != GeomAbs_Circle, "Adaptor3d_CurveOnSurface::Line(): curve is not a circle")
1234 //=======================================================================
1235 //function : Ellipse
1237 //=======================================================================
1239 gp_Elips Adaptor3d_CurveOnSurface::Ellipse() const
1241 return to3d(mySurface->Plane(),myCurve->Ellipse());
1244 //=======================================================================
1245 //function : Hyperbola
1247 //=======================================================================
1249 gp_Hypr Adaptor3d_CurveOnSurface::Hyperbola() const
1251 return to3d(mySurface->Plane(),myCurve->Hyperbola());
1254 //=======================================================================
1255 //function : Parabola
1257 //=======================================================================
1259 gp_Parab Adaptor3d_CurveOnSurface::Parabola() const
1261 return to3d(mySurface->Plane(),myCurve->Parabola());
1264 Standard_Integer Adaptor3d_CurveOnSurface::Degree() const
1267 // on a parametric surface should multiply
1268 // return TheCurve2dTool::Degree(myCurve);
1270 return myCurve->Degree();
1273 //=======================================================================
1274 //function : IsRational
1276 //=======================================================================
1278 Standard_Boolean Adaptor3d_CurveOnSurface::IsRational() const
1280 return ( myCurve->IsRational() ||
1281 mySurface->IsURational() ||
1282 mySurface->IsVRational() );
1285 //=======================================================================
1286 //function : NbPoles
1288 //=======================================================================
1290 Standard_Integer Adaptor3d_CurveOnSurface::NbPoles() const
1292 // on a parametric surface should multiply
1293 return myCurve->NbPoles();
1296 //=======================================================================
1297 //function : NbKnots
1299 //=======================================================================
1301 Standard_Integer Adaptor3d_CurveOnSurface::NbKnots() const {
1302 if (mySurface->GetType()==GeomAbs_Plane)
1303 return myCurve->NbKnots();
1305 Standard_NoSuchObject::Raise();
1310 //=======================================================================
1313 //=======================================================================
1315 Handle(Geom_BezierCurve) Adaptor3d_CurveOnSurface::Bezier() const
1317 Standard_NoSuchObject_Raise_if
1318 ( mySurface->GetType() != GeomAbs_Plane,
1319 "Adaptor3d_CurveOnSurface : Bezier");
1321 Handle(Geom2d_BezierCurve) Bez2d = myCurve->Bezier();
1322 Standard_Integer NbPoles = Bez2d->NbPoles();
1324 const gp_Pln& Plane = mySurface->Plane();
1326 TColgp_Array1OfPnt Poles(1,NbPoles);
1327 for ( Standard_Integer i=1; i<= NbPoles; i++) {
1328 Poles(i) = to3d( Plane, Bez2d->Pole(i));
1330 Handle(Geom_BezierCurve) Bez;
1332 if (Bez2d->IsRational()) {
1333 TColStd_Array1OfReal Weights(1,NbPoles);
1334 Bez2d->Weights(Weights);
1335 Bez = new Geom_BezierCurve(Poles,Weights);
1338 Bez = new Geom_BezierCurve(Poles);
1343 //=======================================================================
1344 //function : BSpline
1346 //=======================================================================
1348 Handle(Geom_BSplineCurve) Adaptor3d_CurveOnSurface::BSpline() const
1350 Standard_NoSuchObject_Raise_if
1351 ( mySurface->GetType() != GeomAbs_Plane,
1352 "Adaptor3d_CurveOnSurface : BSpline");
1354 Handle(Geom2d_BSplineCurve) Bsp2d = myCurve->BSpline();
1355 Standard_Integer NbPoles = Bsp2d->NbPoles();
1357 const gp_Pln& Plane = mySurface->Plane();
1359 TColgp_Array1OfPnt Poles(1,NbPoles);
1360 for ( Standard_Integer i=1; i<= NbPoles; i++) {
1361 Poles(i) = to3d( Plane, Bsp2d->Pole(i));
1364 TColStd_Array1OfReal Knots(1,Bsp2d->NbKnots());
1365 TColStd_Array1OfInteger Mults(1,Bsp2d->NbKnots());
1366 Bsp2d->Knots(Knots);
1367 Bsp2d->Multiplicities(Mults);
1369 Handle(Geom_BSplineCurve) Bsp;
1371 if (Bsp2d->IsRational()) {
1372 TColStd_Array1OfReal Weights(1,NbPoles);
1373 Bsp2d->Weights(Weights);
1374 Bsp = new Geom_BSplineCurve(Poles,Weights,Knots,Mults,
1376 Bsp2d->IsPeriodic());
1379 Bsp = new Geom_BSplineCurve(Poles,Knots,Mults,
1381 Bsp2d->IsPeriodic());
1386 //=======================================================================
1387 //function : GetCurve
1389 //=======================================================================
1391 const Handle(Adaptor2d_HCurve2d)& Adaptor3d_CurveOnSurface::GetCurve() const
1396 //=======================================================================
1397 //function : GetSurface
1399 //=======================================================================
1401 const Handle(Adaptor3d_HSurface)& Adaptor3d_CurveOnSurface::GetSurface() const
1406 //=======================================================================
1407 //function : ChangeCurve
1409 //=======================================================================
1411 Handle(Adaptor2d_HCurve2d)& Adaptor3d_CurveOnSurface::ChangeCurve()
1416 //=======================================================================
1417 //function : ChangeSurface
1419 //=======================================================================
1421 Handle(Adaptor3d_HSurface)& Adaptor3d_CurveOnSurface::ChangeSurface() {
1425 //=======================================================================
1426 //function : EvalKPart
1428 //=======================================================================
1430 void Adaptor3d_CurveOnSurface::EvalKPart()
1432 myType = GeomAbs_OtherCurve;
1434 GeomAbs_SurfaceType STy = mySurface->GetType();
1435 GeomAbs_CurveType CTy = myCurve->GetType();
1436 if (STy == GeomAbs_Plane) {
1438 if (myType == GeomAbs_Circle)
1439 myCirc = to3d(mySurface->Plane(),myCurve->Circle());
1440 else if (myType == GeomAbs_Line) {
1445 myCurve->D1(0.,Puv,Duv);
1447 mySurface->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1448 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1449 myLin = gp_Lin(P,V);
1453 if ( CTy == GeomAbs_Line) {
1454 gp_Dir2d D = myCurve->Line().Direction();
1455 if ( D.IsParallel(gp::DX2d(),Precision::Angular())) { // Iso V.
1456 if ( STy == GeomAbs_Sphere) {
1457 gp_Pnt2d P = myCurve->Line().Location();
1458 if ( Abs( Abs(P.Y()) -M_PI/2. ) >= Precision::PConfusion()) {
1459 myType = GeomAbs_Circle;
1460 gp_Sphere Sph = mySurface->Sphere();
1461 gp_Ax3 Axis = Sph.Position();
1462 myCirc = ElSLib::SphereVIso(Axis,
1465 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1466 gp_Ax1 AxeRev(Axis.Location(), DRev);
1467 myCirc.Rotate(AxeRev, P.X());
1468 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1469 gp_Ax2 Ax = myCirc.Position();
1470 Ax.SetDirection(Ax.Direction().Reversed());
1471 myCirc.SetPosition(Ax);
1475 else if ( STy == GeomAbs_Cylinder) {
1476 myType = GeomAbs_Circle;
1477 gp_Cylinder Cyl = mySurface->Cylinder();
1478 gp_Pnt2d P = myCurve->Line().Location();
1479 gp_Ax3 Axis = Cyl.Position();
1480 myCirc = ElSLib::CylinderVIso(Axis,
1483 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1484 gp_Ax1 AxeRev(Axis.Location(), DRev);
1485 myCirc.Rotate(AxeRev, P.X());
1486 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1487 gp_Ax2 Ax = myCirc.Position();
1488 Ax.SetDirection(Ax.Direction().Reversed());
1489 myCirc.SetPosition(Ax);
1492 else if ( STy == GeomAbs_Cone) {
1493 myType = GeomAbs_Circle;
1494 gp_Cone Cone = mySurface->Cone();
1495 gp_Pnt2d P = myCurve->Line().Location();
1496 gp_Ax3 Axis = Cone.Position();
1497 myCirc = ElSLib::ConeVIso(Axis,
1501 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1502 gp_Ax1 AxeRev(Axis.Location(), DRev);
1503 myCirc.Rotate(AxeRev, P.X());
1504 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1505 gp_Ax2 Ax = myCirc.Position();
1506 Ax.SetDirection(Ax.Direction().Reversed());
1507 myCirc.SetPosition(Ax);
1510 else if ( STy == GeomAbs_Torus) {
1511 myType = GeomAbs_Circle;
1512 gp_Torus Tore = mySurface->Torus();
1513 gp_Pnt2d P = myCurve->Line().Location();
1514 gp_Ax3 Axis = Tore.Position();
1515 myCirc = ElSLib::TorusVIso(Axis,
1519 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1520 gp_Ax1 AxeRev(Axis.Location(), DRev);
1521 myCirc.Rotate(AxeRev, P.X());
1522 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1523 gp_Ax2 Ax = myCirc.Position();
1524 Ax.SetDirection(Ax.Direction().Reversed());
1525 myCirc.SetPosition(Ax);
1529 else if ( D.IsParallel(gp::DY2d(),Precision::Angular())) { // Iso U.
1530 if ( STy == GeomAbs_Sphere) {
1531 myType = GeomAbs_Circle;
1532 gp_Sphere Sph = mySurface->Sphere();
1533 gp_Pnt2d P = myCurve->Line().Location();
1534 gp_Ax3 Axis = Sph.Position();
1535 // calcul de l'iso 0.
1536 myCirc = ElSLib::SphereUIso(Axis, Sph.Radius(),0.);
1538 // mise a sameparameter (rotation du cercle - decalage du Y)
1539 gp_Dir DRev = Axis.XDirection().Crossed(Axis. Direction());
1540 gp_Ax1 AxeRev(Axis.Location(),DRev);
1541 myCirc.Rotate(AxeRev, P.Y());
1543 // transformation en iso U ( = P.X())
1544 DRev = Axis.XDirection().Crossed(Axis.YDirection());
1545 AxeRev = gp_Ax1(Axis.Location(), DRev);
1546 myCirc.Rotate(AxeRev, P.X());
1548 if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) {
1549 gp_Ax2 Ax = myCirc.Position();
1550 Ax.SetDirection(Ax.Direction().Reversed());
1551 myCirc.SetPosition(Ax);
1554 else if ( STy == GeomAbs_Cylinder) {
1555 myType = GeomAbs_Line;
1556 gp_Cylinder Cyl = mySurface->Cylinder();
1557 gp_Pnt2d P = myCurve->Line().Location();
1558 myLin = ElSLib::CylinderUIso(Cyl.Position(),
1561 gp_Vec Tr(myLin.Direction());
1563 myLin.Translate(Tr);
1564 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
1567 else if ( STy == GeomAbs_Cone) {
1568 myType = GeomAbs_Line;
1569 gp_Cone Cone = mySurface->Cone();
1570 gp_Pnt2d P = myCurve->Line().Location();
1571 myLin = ElSLib::ConeUIso(Cone.Position(),
1575 gp_Vec Tr(myLin.Direction());
1577 myLin.Translate(Tr);
1578 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
1581 else if ( STy == GeomAbs_Torus) {
1582 myType = GeomAbs_Circle;
1583 gp_Torus Tore = mySurface->Torus();
1584 gp_Pnt2d P = myCurve->Line().Location();
1585 gp_Ax3 Axis = Tore.Position();
1586 myCirc = ElSLib::TorusUIso(Axis,
1590 myCirc.Rotate(myCirc.Axis(),P.Y());
1592 if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) {
1593 gp_Ax2 Ax = myCirc.Position();
1594 Ax.SetDirection(Ax.Direction().Reversed());
1595 myCirc.SetPosition(Ax);
1602 //=======================================================================
1603 //function :EvalFirstLastSurf
1605 //=======================================================================
1607 void Adaptor3d_CurveOnSurface::EvalFirstLastSurf()
1609 Standard_Real FirstPar,LastPar;
1610 gp_Pnt2d UV, LeftBot, RightTop;
1612 Standard_Real Tol= Precision::PConfusion()/10;
1613 Standard_Boolean Ok = Standard_True;
1616 FirstPar=myCurve->FirstParameter();
1617 myCurve->D1(FirstPar,UV,DUV);
1619 if(DUV.Magnitude() <= Tol) Ok = Standard_False;
1623 switch(mySurface->GetType()) {
1624 case GeomAbs_BSplineSurface :
1625 LocatePart(UV,DUV,mySurface,LeftBot,RightTop);
1627 case GeomAbs_SurfaceOfRevolution :
1628 case GeomAbs_SurfaceOfExtrusion :
1629 Ok = LocatePart_RevExt(UV,DUV,mySurface,LeftBot,RightTop);
1631 case GeomAbs_OffsetSurface :
1632 Ok = LocatePart_Offset(UV,DUV,mySurface,LeftBot,RightTop);
1635 Standard_NotImplemented::Raise("Adaptor3d_CurveOnSurface::EvalFirstLastSurf");
1642 CompareBounds(LeftBot,RightTop); //SVV
1644 myFirstSurf = mySurface->UTrim(LeftBot.X(),RightTop.X(),Tol);
1645 myFirstSurf = myFirstSurf->VTrim(LeftBot.Y(),RightTop.Y(),Tol);
1649 myFirstSurf = mySurface;
1652 LastPar=myCurve->LastParameter();
1654 myCurve->D1(LastPar,UV,DUV);
1655 DUV.Reverse(); //We want the other part
1657 if(DUV.Magnitude() <= Tol) Ok = Standard_False;
1661 switch(mySurface->GetType()) {
1662 case GeomAbs_BSplineSurface :
1663 LocatePart(UV,DUV,mySurface,LeftBot,RightTop);
1665 case GeomAbs_SurfaceOfRevolution :
1666 case GeomAbs_SurfaceOfExtrusion :
1667 Ok = LocatePart_RevExt(UV,DUV,mySurface,LeftBot,RightTop);
1669 case GeomAbs_OffsetSurface :
1670 Ok = LocatePart_Offset(UV,DUV,mySurface,LeftBot,RightTop);
1673 Standard_NotImplemented::Raise("Adaptor3d_CurveOnSurface::EvalFirstLastSurf");
1680 CompareBounds(LeftBot, RightTop); //SVV
1682 myLastSurf = mySurface->UTrim(LeftBot.X(),RightTop.X(),Tol);
1683 myLastSurf = myLastSurf->VTrim(LeftBot.Y(),RightTop.Y(),Tol);
1687 myLastSurf = mySurface;
1691 //=======================================================================
1692 //function :LocatePart_RevExt
1693 //purpose : processes Knots
1694 //=======================================================================
1696 Standard_Boolean Adaptor3d_CurveOnSurface::LocatePart_RevExt(const gp_Pnt2d& UV,
1697 const gp_Vec2d& DUV,
1698 const Handle(Adaptor3d_HSurface)& S,
1700 gp_Pnt2d& RightTop) const
1702 Handle(Adaptor3d_HCurve) AHC = S->BasisCurve();
1704 if (AHC->GetType() == GeomAbs_BSplineCurve) {
1705 Handle( Geom_BSplineCurve) BSplC;
1706 BSplC = AHC->BSpline();
1708 if((S->GetType())==GeomAbs_SurfaceOfExtrusion) {
1709 Locate1Coord(1,UV,DUV,BSplC,LeftBot,RightTop);
1710 Locate2Coord(2,UV,DUV,S->FirstVParameter(),S->LastVParameter(),LeftBot,RightTop);
1712 else if((S->GetType())==GeomAbs_SurfaceOfRevolution) {
1713 Locate1Coord(2,UV,DUV,BSplC,LeftBot,RightTop);
1714 Locate2Coord(1,UV,DUV,S->FirstUParameter(),S->LastUParameter(),LeftBot,RightTop);
1717 Standard_Real u1,u2,v1,v2;
1718 ReverseParam(LeftBot.X(),RightTop.X(),u1,u2);
1721 ReverseParam(LeftBot.Y(),RightTop.Y(),v1,v2);
1724 return Standard_True;
1726 return Standard_False;
1729 //=======================================================================
1730 //function :LocatePart_OffsetSurface
1732 //=======================================================================
1734 Standard_Boolean Adaptor3d_CurveOnSurface::
1735 LocatePart_Offset(const gp_Pnt2d& UV, const gp_Vec2d& DUV,
1736 const Handle(Adaptor3d_HSurface)& S,
1737 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop) const
1739 Standard_Boolean Ok = Standard_True;
1740 Handle( Adaptor3d_HSurface) AHS;
1741 Handle( Geom_BSplineSurface) BSplS;
1742 AHS = S->BasisSurface();
1743 GeomAbs_SurfaceType BasisSType = AHS->GetType();
1744 switch(BasisSType) {
1745 case GeomAbs_SurfaceOfRevolution:
1746 case GeomAbs_SurfaceOfExtrusion :
1747 Ok = LocatePart_RevExt(UV,DUV,AHS,LeftBot,RightTop);
1750 case GeomAbs_BSplineSurface:
1751 LocatePart(UV,DUV,AHS,LeftBot,RightTop);
1760 //=======================================================================
1761 //function :LocatePart
1762 //purpose : for BSplineSurface
1763 //=======================================================================
1765 void Adaptor3d_CurveOnSurface::LocatePart(const gp_Pnt2d& UV, const gp_Vec2d& DUV,
1766 const Handle(Adaptor3d_HSurface)& S,
1767 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop) const
1769 Handle( Geom_BSplineSurface) BSplS;
1770 BSplS = S->BSpline();
1771 Standard_Boolean DUIsNull=Standard_False,
1772 DVIsNull=Standard_False;
1774 Locate1Coord(1,UV,DUV,BSplS,DUIsNull,LeftBot,RightTop);
1775 Locate1Coord(2,UV,DUV,BSplS,DVIsNull,LeftBot,RightTop);
1777 if((DUIsNull==Standard_True)&&(DVIsNull==Standard_False)) {
1778 TColStd_Array1OfReal ArrU(1,BSplS->NbUKnots());
1779 BSplS->UKnots(ArrU);
1780 Locate2Coord(1,UV,DUV,BSplS,ArrU,LeftBot,RightTop);
1782 else if((DVIsNull==Standard_True)&&(DUIsNull==Standard_False)) {
1783 TColStd_Array1OfReal ArrV(1,BSplS->NbVKnots());
1784 BSplS->VKnots(ArrV);
1785 Locate2Coord(2,UV,DUV,BSplS,ArrV,LeftBot,RightTop);