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 throw Standard_NotImplemented("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())
746 GeomAbs_SurfaceType SType = mySurface->GetType();
747 if (SType == GeomAbs_OffsetSurface)
749 SType = mySurface->BasisSurface()->GetType();
752 if (SType == GeomAbs_BSplineSurface ||
753 SType == GeomAbs_SurfaceOfExtrusion ||
754 SType == GeomAbs_SurfaceOfRevolution)
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);
849 nc=myCurve->NbIntervals(S);
851 // Allocate the memory for arrays TabU, TabV, TabC only once using the buffer TabBuf.
852 TColStd_Array1OfReal TabBuf(1, nu + nv + nc + 3);
853 TColStd_Array1OfReal TabU(TabBuf(1), 1, nu+1);
854 TColStd_Array1OfReal TabV(TabBuf(nu + 2), 1, nv+1);
855 TColStd_Array1OfReal TabC(TabBuf(nu + nv + 3), 1, nc+1);
857 Standard_Integer NbSample = 20;
858 Standard_Real U,V,Tdeb,Tfin;
859 Tdeb=myCurve->FirstParameter();
860 Tfin=myCurve->LastParameter();
862 myCurve->Intervals(TabC,S);
864 Standard_Real Tol= Precision::PConfusion()/10;
866 // sorted sequence of parameters defining continuity intervals;
867 // started with own intervals of curve and completed by
868 // additional points coming from surface discontinuities
869 Handle(TColStd_HSequenceOfReal) aIntervals = new TColStd_HSequenceOfReal;
870 for (Standard_Integer i = 1; i <= nc + 1; i++)
872 aIntervals->Append(TabC(i));
877 mySurface->UIntervals(TabU,S);
878 for(Standard_Integer iu = 2;iu <= nu; iu++)
881 Adaptor3d_InterFunc Func(myCurve,U,1);
882 math_FunctionRoots Resol(Func,Tdeb,Tfin,NbSample,Tol,Tol,Tol,0.);
883 AddIntervals (aIntervals, Resol, Tol);
888 mySurface->VIntervals(TabV,S);
889 for(Standard_Integer iv = 2;iv <= nv; iv++)
892 Adaptor3d_InterFunc Func(myCurve,V,2);
893 math_FunctionRoots Resol(Func,Tdeb,Tfin,NbSample,Tol,Tol,Tol,0.);
894 AddIntervals (aIntervals, Resol, Tol);
898 // for case intervals==1 and first point == last point SequenceOfReal
899 // contains only one value, therefore it is necessary to add second
900 // value into aIntervals which will be equal first value.
901 if (aIntervals->Length() == 1)
902 aIntervals->Append (aIntervals->Value(1));
904 const_cast<Adaptor3d_CurveOnSurface*>(this)->myIntervals = aIntervals;
905 const_cast<Adaptor3d_CurveOnSurface*>(this)->myIntCont = S;
906 return myIntervals->Length() - 1;
909 //=======================================================================
910 //function : Intervals
912 //=======================================================================
914 void Adaptor3d_CurveOnSurface::Intervals(TColStd_Array1OfReal& T,
915 const GeomAbs_Shape S) const
918 Standard_ASSERT_RAISE (T.Length() == myIntervals->Length(), "Error: Wrong size of array buffer in call to Adaptor3d_CurveOnSurface::Intervals");
919 for(Standard_Integer i=1; i<=myIntervals->Length(); i++) {
920 T(i) = myIntervals->Value(i);
924 //=======================================================================
927 //=======================================================================
929 Handle(Adaptor3d_HCurve) Adaptor3d_CurveOnSurface::Trim
930 (const Standard_Real First,
931 const Standard_Real Last,
932 const Standard_Real Tol) const
934 Handle(Adaptor3d_HCurveOnSurface) HCS = new Adaptor3d_HCurveOnSurface();
935 HCS->ChangeCurve().Load(mySurface);
936 HCS->ChangeCurve().Load(myCurve->Trim(First,Last,Tol));
940 //=======================================================================
941 //function : IsClosed
943 //=======================================================================
945 Standard_Boolean Adaptor3d_CurveOnSurface::IsClosed() const
947 return myCurve->IsClosed();
950 //=======================================================================
951 //function : IsPeriodic
953 //=======================================================================
955 Standard_Boolean Adaptor3d_CurveOnSurface::IsPeriodic() const
957 if (myType == GeomAbs_Circle ||
958 myType == GeomAbs_Ellipse)
959 return Standard_True;
961 return myCurve->IsPeriodic();
964 //=======================================================================
967 //=======================================================================
969 Standard_Real Adaptor3d_CurveOnSurface::Period() const
971 if (myType == GeomAbs_Circle ||
972 myType == GeomAbs_Ellipse)
975 return myCurve->Period();
978 //=======================================================================
981 //=======================================================================
983 gp_Pnt Adaptor3d_CurveOnSurface::Value(const Standard_Real U ) const
988 if (myType == GeomAbs_Line ) P = ElCLib::Value(U,myLin );
989 else if (myType == GeomAbs_Circle) P = ElCLib::Value(U,myCirc);
992 mySurface->D0(Puv.X(),Puv.Y(),P);
998 //=======================================================================
1001 //=======================================================================
1003 void Adaptor3d_CurveOnSurface::D0(const Standard_Real U ,
1008 if (myType == GeomAbs_Line ) P = ElCLib::Value(U,myLin );
1009 else if (myType == GeomAbs_Circle) P = ElCLib::Value(U,myCirc);
1012 mySurface->D0(Puv.X(),Puv.Y(),P);
1018 //=======================================================================
1021 //=======================================================================
1023 void Adaptor3d_CurveOnSurface::D1(const Standard_Real U ,
1031 Standard_Real FP = myCurve->FirstParameter();
1032 Standard_Real LP = myCurve->LastParameter();
1034 Standard_Real Tol= Precision::PConfusion()/10;
1035 if( ( Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
1037 myCurve->D1(U,Puv,Duv);
1038 myFirstSurf->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1039 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1042 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
1044 myCurve->D1(U,Puv,Duv);
1045 myLastSurf->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1046 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1049 if (myType == GeomAbs_Line ) ElCLib::D1(U,myLin ,P,V);
1050 else if (myType == GeomAbs_Circle) ElCLib::D1(U,myCirc,P,V);
1052 myCurve->D1(U,Puv,Duv);
1053 mySurface->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1054 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1057 //=======================================================================
1060 //=======================================================================
1062 void Adaptor3d_CurveOnSurface::D2(const Standard_Real U,
1069 gp_Vec D1U,D1V,D2U,D2V,D2UV;
1071 Standard_Real FP = myCurve->FirstParameter();
1072 Standard_Real LP = myCurve->LastParameter();
1074 Standard_Real Tol= Precision::PConfusion()/10;
1075 if( (Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
1077 myCurve->D2(U,UV,DW,D2W);
1078 myFirstSurf->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
1080 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1081 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1082 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1085 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
1087 myCurve->D2(U,UV,DW,D2W);
1088 myLastSurf->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
1090 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1091 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1092 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1095 if (myType == GeomAbs_Line ) {
1096 ElCLib::D1(U,myLin,P,V1);
1097 V2.SetCoord(0.,0.,0.);
1099 else if (myType == GeomAbs_Circle) ElCLib::D2(U,myCirc,P,V1,V2);
1101 myCurve->D2(U,UV,DW,D2W);
1102 mySurface->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
1104 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1105 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1106 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1110 //=======================================================================
1113 //=======================================================================
1115 void Adaptor3d_CurveOnSurface::D3
1116 (const Standard_Real U,
1123 Standard_Real Tol= Precision::PConfusion()/10;
1125 gp_Vec2d DW,D2W,D3W;
1126 gp_Vec D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV;
1128 Standard_Real FP = myCurve->FirstParameter();
1129 Standard_Real LP = myCurve->LastParameter();
1131 if( (Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
1132 { myCurve->D3(U,UV,DW,D2W,D3W);
1133 myFirstSurf->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
1134 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1135 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1136 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1137 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1140 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
1141 { myCurve->D3(U,UV,DW,D2W,D3W);
1142 myLastSurf->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
1143 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1145 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1146 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1147 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1150 if (myType == GeomAbs_Line ) {
1151 ElCLib::D1(U,myLin,P,V1);
1152 V2.SetCoord(0.,0.,0.);
1153 V3.SetCoord(0.,0.,0.);
1155 else if (myType == GeomAbs_Circle) ElCLib::D3(U,myCirc,P,V1,V2,V3);
1157 myCurve->D3(U,UV,DW,D2W,D3W);
1158 mySurface->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
1159 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1161 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1162 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1163 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1168 //=======================================================================
1171 //=======================================================================
1173 gp_Vec Adaptor3d_CurveOnSurface::DN
1174 (const Standard_Real U,
1175 const Standard_Integer N) const
1190 throw Standard_NotImplemented("Adaptor3d_CurveOnSurface:DN");
1197 //=======================================================================
1198 //function : Resolution
1200 //=======================================================================
1202 Standard_Real Adaptor3d_CurveOnSurface::Resolution
1203 (const Standard_Real R3d) const
1205 Standard_Real ru,rv;
1206 ru = mySurface->UResolution(R3d);
1207 rv = mySurface->VResolution(R3d);
1208 return myCurve->Resolution(Min(ru,rv));
1212 //=======================================================================
1213 //function : GetType
1215 //=======================================================================
1217 GeomAbs_CurveType Adaptor3d_CurveOnSurface::GetType() const
1223 //=======================================================================
1226 //=======================================================================
1228 gp_Lin Adaptor3d_CurveOnSurface::Line() const
1230 Standard_NoSuchObject_Raise_if(myType != GeomAbs_Line, "Adaptor3d_CurveOnSurface::Line(): curve is not a line")
1234 //=======================================================================
1237 //=======================================================================
1239 gp_Circ Adaptor3d_CurveOnSurface::Circle() const
1241 Standard_NoSuchObject_Raise_if(myType != GeomAbs_Circle, "Adaptor3d_CurveOnSurface::Line(): curve is not a circle")
1245 //=======================================================================
1246 //function : Ellipse
1248 //=======================================================================
1250 gp_Elips Adaptor3d_CurveOnSurface::Ellipse() const
1252 return to3d(mySurface->Plane(),myCurve->Ellipse());
1255 //=======================================================================
1256 //function : Hyperbola
1258 //=======================================================================
1260 gp_Hypr Adaptor3d_CurveOnSurface::Hyperbola() const
1262 return to3d(mySurface->Plane(),myCurve->Hyperbola());
1265 //=======================================================================
1266 //function : Parabola
1268 //=======================================================================
1270 gp_Parab Adaptor3d_CurveOnSurface::Parabola() const
1272 return to3d(mySurface->Plane(),myCurve->Parabola());
1275 Standard_Integer Adaptor3d_CurveOnSurface::Degree() const
1278 // on a parametric surface should multiply
1279 // return TheCurve2dTool::Degree(myCurve);
1281 return myCurve->Degree();
1284 //=======================================================================
1285 //function : IsRational
1287 //=======================================================================
1289 Standard_Boolean Adaptor3d_CurveOnSurface::IsRational() const
1291 return ( myCurve->IsRational() ||
1292 mySurface->IsURational() ||
1293 mySurface->IsVRational() );
1296 //=======================================================================
1297 //function : NbPoles
1299 //=======================================================================
1301 Standard_Integer Adaptor3d_CurveOnSurface::NbPoles() const
1303 // on a parametric surface should multiply
1304 return myCurve->NbPoles();
1307 //=======================================================================
1308 //function : NbKnots
1310 //=======================================================================
1312 Standard_Integer Adaptor3d_CurveOnSurface::NbKnots() const {
1313 if (mySurface->GetType()==GeomAbs_Plane)
1314 return myCurve->NbKnots();
1316 throw Standard_NoSuchObject();
1320 //=======================================================================
1323 //=======================================================================
1325 Handle(Geom_BezierCurve) Adaptor3d_CurveOnSurface::Bezier() const
1327 Standard_NoSuchObject_Raise_if
1328 ( mySurface->GetType() != GeomAbs_Plane,
1329 "Adaptor3d_CurveOnSurface : Bezier");
1331 Handle(Geom2d_BezierCurve) Bez2d = myCurve->Bezier();
1332 Standard_Integer NbPoles = Bez2d->NbPoles();
1334 const gp_Pln& Plane = mySurface->Plane();
1336 TColgp_Array1OfPnt Poles(1,NbPoles);
1337 for ( Standard_Integer i=1; i<= NbPoles; i++) {
1338 Poles(i) = to3d( Plane, Bez2d->Pole(i));
1340 Handle(Geom_BezierCurve) Bez;
1342 if (Bez2d->IsRational()) {
1343 TColStd_Array1OfReal Weights(1,NbPoles);
1344 Bez2d->Weights(Weights);
1345 Bez = new Geom_BezierCurve(Poles,Weights);
1348 Bez = new Geom_BezierCurve(Poles);
1353 //=======================================================================
1354 //function : BSpline
1356 //=======================================================================
1358 Handle(Geom_BSplineCurve) Adaptor3d_CurveOnSurface::BSpline() const
1360 Standard_NoSuchObject_Raise_if
1361 ( mySurface->GetType() != GeomAbs_Plane,
1362 "Adaptor3d_CurveOnSurface : BSpline");
1364 Handle(Geom2d_BSplineCurve) Bsp2d = myCurve->BSpline();
1365 Standard_Integer NbPoles = Bsp2d->NbPoles();
1367 const gp_Pln& Plane = mySurface->Plane();
1369 TColgp_Array1OfPnt Poles(1,NbPoles);
1370 for ( Standard_Integer i=1; i<= NbPoles; i++) {
1371 Poles(i) = to3d( Plane, Bsp2d->Pole(i));
1374 TColStd_Array1OfReal Knots(1,Bsp2d->NbKnots());
1375 TColStd_Array1OfInteger Mults(1,Bsp2d->NbKnots());
1376 Bsp2d->Knots(Knots);
1377 Bsp2d->Multiplicities(Mults);
1379 Handle(Geom_BSplineCurve) Bsp;
1381 if (Bsp2d->IsRational()) {
1382 TColStd_Array1OfReal Weights(1,NbPoles);
1383 Bsp2d->Weights(Weights);
1384 Bsp = new Geom_BSplineCurve(Poles,Weights,Knots,Mults,
1386 Bsp2d->IsPeriodic());
1389 Bsp = new Geom_BSplineCurve(Poles,Knots,Mults,
1391 Bsp2d->IsPeriodic());
1396 //=======================================================================
1397 //function : GetCurve
1399 //=======================================================================
1401 const Handle(Adaptor2d_HCurve2d)& Adaptor3d_CurveOnSurface::GetCurve() const
1406 //=======================================================================
1407 //function : GetSurface
1409 //=======================================================================
1411 const Handle(Adaptor3d_HSurface)& Adaptor3d_CurveOnSurface::GetSurface() const
1416 //=======================================================================
1417 //function : ChangeCurve
1419 //=======================================================================
1421 Handle(Adaptor2d_HCurve2d)& Adaptor3d_CurveOnSurface::ChangeCurve()
1426 //=======================================================================
1427 //function : ChangeSurface
1429 //=======================================================================
1431 Handle(Adaptor3d_HSurface)& Adaptor3d_CurveOnSurface::ChangeSurface() {
1435 //=======================================================================
1436 //function : EvalKPart
1438 //=======================================================================
1440 void Adaptor3d_CurveOnSurface::EvalKPart()
1442 myType = GeomAbs_OtherCurve;
1444 GeomAbs_SurfaceType STy = mySurface->GetType();
1445 GeomAbs_CurveType CTy = myCurve->GetType();
1446 if (STy == GeomAbs_Plane) {
1448 if (myType == GeomAbs_Circle)
1449 myCirc = to3d(mySurface->Plane(),myCurve->Circle());
1450 else if (myType == GeomAbs_Line) {
1455 myCurve->D1(0.,Puv,Duv);
1457 mySurface->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1458 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1459 myLin = gp_Lin(P,V);
1463 if ( CTy == GeomAbs_Line) {
1464 gp_Dir2d D = myCurve->Line().Direction();
1465 if ( D.IsParallel(gp::DX2d(),Precision::Angular())) { // Iso V.
1466 if ( STy == GeomAbs_Sphere) {
1467 gp_Pnt2d P = myCurve->Line().Location();
1468 if ( Abs( Abs(P.Y()) -M_PI/2. ) >= Precision::PConfusion()) {
1469 myType = GeomAbs_Circle;
1470 gp_Sphere Sph = mySurface->Sphere();
1471 gp_Ax3 Axis = Sph.Position();
1472 myCirc = ElSLib::SphereVIso(Axis,
1475 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1476 gp_Ax1 AxeRev(Axis.Location(), DRev);
1477 myCirc.Rotate(AxeRev, P.X());
1478 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1479 gp_Ax2 Ax = myCirc.Position();
1480 Ax.SetDirection(Ax.Direction().Reversed());
1481 myCirc.SetPosition(Ax);
1485 else if ( STy == GeomAbs_Cylinder) {
1486 myType = GeomAbs_Circle;
1487 gp_Cylinder Cyl = mySurface->Cylinder();
1488 gp_Pnt2d P = myCurve->Line().Location();
1489 gp_Ax3 Axis = Cyl.Position();
1490 myCirc = ElSLib::CylinderVIso(Axis,
1493 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1494 gp_Ax1 AxeRev(Axis.Location(), DRev);
1495 myCirc.Rotate(AxeRev, P.X());
1496 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1497 gp_Ax2 Ax = myCirc.Position();
1498 Ax.SetDirection(Ax.Direction().Reversed());
1499 myCirc.SetPosition(Ax);
1502 else if ( STy == GeomAbs_Cone) {
1503 myType = GeomAbs_Circle;
1504 gp_Cone Cone = mySurface->Cone();
1505 gp_Pnt2d P = myCurve->Line().Location();
1506 gp_Ax3 Axis = Cone.Position();
1507 myCirc = ElSLib::ConeVIso(Axis,
1511 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1512 gp_Ax1 AxeRev(Axis.Location(), DRev);
1513 myCirc.Rotate(AxeRev, P.X());
1514 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1515 gp_Ax2 Ax = myCirc.Position();
1516 Ax.SetDirection(Ax.Direction().Reversed());
1517 myCirc.SetPosition(Ax);
1520 else if ( STy == GeomAbs_Torus) {
1521 myType = GeomAbs_Circle;
1522 gp_Torus Tore = mySurface->Torus();
1523 gp_Pnt2d P = myCurve->Line().Location();
1524 gp_Ax3 Axis = Tore.Position();
1525 myCirc = ElSLib::TorusVIso(Axis,
1529 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1530 gp_Ax1 AxeRev(Axis.Location(), DRev);
1531 myCirc.Rotate(AxeRev, P.X());
1532 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1533 gp_Ax2 Ax = myCirc.Position();
1534 Ax.SetDirection(Ax.Direction().Reversed());
1535 myCirc.SetPosition(Ax);
1539 else if ( D.IsParallel(gp::DY2d(),Precision::Angular())) { // Iso U.
1540 if ( STy == GeomAbs_Sphere) {
1541 myType = GeomAbs_Circle;
1542 gp_Sphere Sph = mySurface->Sphere();
1543 gp_Pnt2d P = myCurve->Line().Location();
1544 gp_Ax3 Axis = Sph.Position();
1545 // calcul de l'iso 0.
1546 myCirc = ElSLib::SphereUIso(Axis, Sph.Radius(),0.);
1548 // mise a sameparameter (rotation du cercle - decalage du Y)
1549 gp_Dir DRev = Axis.XDirection().Crossed(Axis. Direction());
1550 gp_Ax1 AxeRev(Axis.Location(),DRev);
1551 myCirc.Rotate(AxeRev, P.Y());
1553 // transformation en iso U ( = P.X())
1554 DRev = Axis.XDirection().Crossed(Axis.YDirection());
1555 AxeRev = gp_Ax1(Axis.Location(), DRev);
1556 myCirc.Rotate(AxeRev, P.X());
1558 if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) {
1559 gp_Ax2 Ax = myCirc.Position();
1560 Ax.SetDirection(Ax.Direction().Reversed());
1561 myCirc.SetPosition(Ax);
1564 else if ( STy == GeomAbs_Cylinder) {
1565 myType = GeomAbs_Line;
1566 gp_Cylinder Cyl = mySurface->Cylinder();
1567 gp_Pnt2d P = myCurve->Line().Location();
1568 myLin = ElSLib::CylinderUIso(Cyl.Position(),
1571 gp_Vec Tr(myLin.Direction());
1573 myLin.Translate(Tr);
1574 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
1577 else if ( STy == GeomAbs_Cone) {
1578 myType = GeomAbs_Line;
1579 gp_Cone Cone = mySurface->Cone();
1580 gp_Pnt2d P = myCurve->Line().Location();
1581 myLin = ElSLib::ConeUIso(Cone.Position(),
1585 gp_Vec Tr(myLin.Direction());
1587 myLin.Translate(Tr);
1588 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
1591 else if ( STy == GeomAbs_Torus) {
1592 myType = GeomAbs_Circle;
1593 gp_Torus Tore = mySurface->Torus();
1594 gp_Pnt2d P = myCurve->Line().Location();
1595 gp_Ax3 Axis = Tore.Position();
1596 myCirc = ElSLib::TorusUIso(Axis,
1600 myCirc.Rotate(myCirc.Axis(),P.Y());
1602 if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) {
1603 gp_Ax2 Ax = myCirc.Position();
1604 Ax.SetDirection(Ax.Direction().Reversed());
1605 myCirc.SetPosition(Ax);
1612 //=======================================================================
1613 //function :EvalFirstLastSurf
1615 //=======================================================================
1617 void Adaptor3d_CurveOnSurface::EvalFirstLastSurf()
1619 Standard_Real FirstPar,LastPar;
1620 gp_Pnt2d UV, LeftBot, RightTop;
1622 Standard_Real Tol= Precision::PConfusion()/10;
1623 Standard_Boolean Ok = Standard_True;
1626 FirstPar=myCurve->FirstParameter();
1627 myCurve->D1(FirstPar,UV,DUV);
1629 if(DUV.Magnitude() <= Tol) Ok = Standard_False;
1633 switch(mySurface->GetType()) {
1634 case GeomAbs_BSplineSurface :
1635 LocatePart(UV,DUV,mySurface,LeftBot,RightTop);
1637 case GeomAbs_SurfaceOfRevolution :
1638 case GeomAbs_SurfaceOfExtrusion :
1639 Ok = LocatePart_RevExt(UV,DUV,mySurface,LeftBot,RightTop);
1641 case GeomAbs_OffsetSurface :
1642 Ok = LocatePart_Offset(UV,DUV,mySurface,LeftBot,RightTop);
1645 throw Standard_NotImplemented("Adaptor3d_CurveOnSurface::EvalFirstLastSurf");
1652 CompareBounds(LeftBot,RightTop); //SVV
1654 myFirstSurf = mySurface->UTrim(LeftBot.X(),RightTop.X(),Tol);
1655 myFirstSurf = myFirstSurf->VTrim(LeftBot.Y(),RightTop.Y(),Tol);
1659 myFirstSurf = mySurface;
1662 LastPar=myCurve->LastParameter();
1664 myCurve->D1(LastPar,UV,DUV);
1665 DUV.Reverse(); //We want the other part
1667 if(DUV.Magnitude() <= Tol) Ok = Standard_False;
1671 switch(mySurface->GetType()) {
1672 case GeomAbs_BSplineSurface :
1673 LocatePart(UV,DUV,mySurface,LeftBot,RightTop);
1675 case GeomAbs_SurfaceOfRevolution :
1676 case GeomAbs_SurfaceOfExtrusion :
1677 Ok = LocatePart_RevExt(UV,DUV,mySurface,LeftBot,RightTop);
1679 case GeomAbs_OffsetSurface :
1680 Ok = LocatePart_Offset(UV,DUV,mySurface,LeftBot,RightTop);
1683 throw Standard_NotImplemented("Adaptor3d_CurveOnSurface::EvalFirstLastSurf");
1690 CompareBounds(LeftBot, RightTop); //SVV
1692 myLastSurf = mySurface->UTrim(LeftBot.X(),RightTop.X(),Tol);
1693 myLastSurf = myLastSurf->VTrim(LeftBot.Y(),RightTop.Y(),Tol);
1697 myLastSurf = mySurface;
1701 //=======================================================================
1702 //function :LocatePart_RevExt
1703 //purpose : processes Knots
1704 //=======================================================================
1706 Standard_Boolean Adaptor3d_CurveOnSurface::LocatePart_RevExt(const gp_Pnt2d& UV,
1707 const gp_Vec2d& DUV,
1708 const Handle(Adaptor3d_HSurface)& S,
1710 gp_Pnt2d& RightTop) const
1712 Handle(Adaptor3d_HCurve) AHC = S->BasisCurve();
1714 if (AHC->GetType() == GeomAbs_BSplineCurve) {
1715 Handle( Geom_BSplineCurve) BSplC;
1716 BSplC = AHC->BSpline();
1718 if((S->GetType())==GeomAbs_SurfaceOfExtrusion) {
1719 Locate1Coord(1,UV,DUV,BSplC,LeftBot,RightTop);
1720 Locate2Coord(2,UV,DUV,S->FirstVParameter(),S->LastVParameter(),LeftBot,RightTop);
1722 else if((S->GetType())==GeomAbs_SurfaceOfRevolution) {
1723 Locate1Coord(2,UV,DUV,BSplC,LeftBot,RightTop);
1724 Locate2Coord(1,UV,DUV,S->FirstUParameter(),S->LastUParameter(),LeftBot,RightTop);
1727 Standard_Real u1,u2,v1,v2;
1728 ReverseParam(LeftBot.X(),RightTop.X(),u1,u2);
1731 ReverseParam(LeftBot.Y(),RightTop.Y(),v1,v2);
1734 return Standard_True;
1736 return Standard_False;
1739 //=======================================================================
1740 //function :LocatePart_OffsetSurface
1742 //=======================================================================
1744 Standard_Boolean Adaptor3d_CurveOnSurface::
1745 LocatePart_Offset(const gp_Pnt2d& UV, const gp_Vec2d& DUV,
1746 const Handle(Adaptor3d_HSurface)& S,
1747 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop) const
1749 Standard_Boolean Ok = Standard_True;
1750 Handle( Adaptor3d_HSurface) AHS;
1751 Handle( Geom_BSplineSurface) BSplS;
1752 AHS = S->BasisSurface();
1753 GeomAbs_SurfaceType BasisSType = AHS->GetType();
1754 switch(BasisSType) {
1755 case GeomAbs_SurfaceOfRevolution:
1756 case GeomAbs_SurfaceOfExtrusion :
1757 Ok = LocatePart_RevExt(UV,DUV,AHS,LeftBot,RightTop);
1760 case GeomAbs_BSplineSurface:
1761 LocatePart(UV,DUV,AHS,LeftBot,RightTop);
1770 //=======================================================================
1771 //function :LocatePart
1772 //purpose : for BSplineSurface
1773 //=======================================================================
1775 void Adaptor3d_CurveOnSurface::LocatePart(const gp_Pnt2d& UV, const gp_Vec2d& DUV,
1776 const Handle(Adaptor3d_HSurface)& S,
1777 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop) const
1779 Handle( Geom_BSplineSurface) BSplS;
1780 BSplS = S->BSpline();
1781 Standard_Boolean DUIsNull=Standard_False,
1782 DVIsNull=Standard_False;
1784 Locate1Coord(1,UV,DUV,BSplS,DUIsNull,LeftBot,RightTop);
1785 Locate1Coord(2,UV,DUV,BSplS,DVIsNull,LeftBot,RightTop);
1787 if((DUIsNull==Standard_True)&&(DVIsNull==Standard_False)) {
1788 TColStd_Array1OfReal ArrU(1,BSplS->NbUKnots());
1789 BSplS->UKnots(ArrU);
1790 Locate2Coord(1,UV,DUV,BSplS,ArrU,LeftBot,RightTop);
1792 else if((DVIsNull==Standard_True)&&(DUIsNull==Standard_False)) {
1793 TColStd_Array1OfReal ArrV(1,BSplS->NbVKnots());
1794 BSplS->VKnots(ArrV);
1795 Locate2Coord(2,UV,DUV,BSplS,ArrV,LeftBot,RightTop);