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_BSplineSurface.hxx>
29 #include <Geom_OffsetSurface.hxx>
30 #include <Geom_SurfaceOfLinearExtrusion.hxx>
31 #include <Geom_SurfaceOfRevolution.hxx>
32 #include <gp_Ax22d.hxx>
33 #include <gp_Circ.hxx>
34 #include <gp_Circ2d.hxx>
35 #include <gp_Elips.hxx>
36 #include <gp_Elips2d.hxx>
37 #include <gp_Hypr.hxx>
38 #include <gp_Hypr2d.hxx>
40 #include <gp_Lin2d.hxx>
41 #include <gp_Parab.hxx>
42 #include <gp_Parab2d.hxx>
44 #include <gp_Pnt2d.hxx>
46 #include <gp_Vec2d.hxx>
47 #include <math_FunctionRoots.hxx>
48 #include <Precision.hxx>
49 #include <Standard_Assert.hxx>
50 #include <Standard_DomainError.hxx>
51 #include <Standard_NoSuchObject.hxx>
52 #include <Standard_NotImplemented.hxx>
53 #include <Standard_OutOfRange.hxx>
54 #include <TColgp_Array1OfPnt.hxx>
55 #include <TColgp_Array1OfPnt2d.hxx>
56 #include <TColStd_Array1OfInteger.hxx>
57 #include <TColStd_Array1OfReal.hxx>
58 #include <TColStd_HSequenceOfReal.hxx>
60 IMPLEMENT_STANDARD_RTTIEXT(Adaptor3d_CurveOnSurface, Adaptor3d_Curve)
62 static gp_Pnt to3d(const gp_Pln& Pl, const gp_Pnt2d& P)
64 return ElSLib::Value(P.X(),P.Y(),Pl);
67 static gp_Vec to3d(const gp_Pln& Pl, const gp_Vec2d& V)
69 gp_Vec Vx = Pl.XAxis().Direction();
70 gp_Vec Vy = Pl.YAxis().Direction();
77 static gp_Ax2 to3d(const gp_Pln& Pl, const gp_Ax22d& A)
79 gp_Pnt P = to3d(Pl,A.Location());
80 gp_Vec VX = to3d(Pl,A.XAxis().Direction());
81 gp_Vec VY = to3d(Pl,A.YAxis().Direction());
82 return gp_Ax2(P,VX.Crossed(VY),VX);
85 static gp_Circ to3d(const gp_Pln& Pl, const gp_Circ2d& C)
87 return gp_Circ(to3d(Pl,C.Axis()),C.Radius());
90 static gp_Elips to3d(const gp_Pln& Pl, const gp_Elips2d& E)
92 return gp_Elips(to3d(Pl,E.Axis()),E.MajorRadius(),E.MinorRadius());
95 static gp_Hypr to3d(const gp_Pln& Pl, const gp_Hypr2d& H)
97 return gp_Hypr(to3d(Pl,H.Axis()),H.MajorRadius(),H.MinorRadius());
100 static gp_Parab to3d(const gp_Pln& Pl, const gp_Parab2d& P)
102 return gp_Parab(to3d(Pl,P.Axis()),P.Focal());
105 static gp_Vec SetLinearForm(const gp_Vec2d DW, const gp_Vec2d D2W,const gp_Vec2d D3W,
106 const gp_Vec D1U, const gp_Vec D1V, const gp_Vec D2U,
107 const gp_Vec D2V, const gp_Vec D2UV, const gp_Vec D3U,
108 const gp_Vec D3V, const gp_Vec D3UUV,const gp_Vec D3UVV)
109 {gp_Vec V31, V32, V33, V34,V3 ;
110 V31.SetLinearForm(DW.X(),D1U,
112 D2W.X()*DW.Y(),D2UV);
113 V31.SetLinearForm(D3W.Y(),D1V,
117 V32.SetLinearForm(DW.X()*DW.X()*DW.Y(),D3UUV,
118 DW.X()*DW.Y()*DW.Y(),D3UVV);
119 V32.SetLinearForm(D2W.X()*DW.Y()+DW.X()*D2W.Y(),D2UV,
120 DW.X()*DW.Y()*DW.Y(),D3UVV,
122 V33.SetLinearForm(2*D2W.X()*DW.X(),D2U,
123 DW.X()*DW.X()*DW.X(),D3U,
124 DW.X()*DW.X()*DW.Y(),D3UUV);
126 V34.SetLinearForm(2*D2W.Y()*DW.Y(),D2V,
127 DW.Y()*DW.Y()*DW.X(),D3UVV,
128 DW.Y()*DW.Y()*DW.Y(),D3V);
129 V3.SetLinearForm(1,V31,2,V32,1,V33,V34);
133 //=======================================================================
134 static void CompareBounds(gp_Pnt2d& P1,
137 Standard_Real Lx = P1.X(),Ly = P1.Y();
138 Standard_Real Rx = P2.X(),Ry = P2.Y();
140 if (Lx > Rx) { P1.SetX(Rx); P2.SetX(Lx);}
141 if (Ly > Ry) { P1.SetY(Ry); P2.SetY(Ly);}
144 //=======================================================================
147 //=======================================================================
148 static void Hunt(const TColStd_Array1OfReal& Arr,
149 const Standard_Real Coord,
150 Standard_Integer& Iloc)
151 {//Warning: Hunt is used to find number of knot which equals coordinate component,
152 // when coordinate component definitly equals a knot only.
153 Standard_Real Tol=Precision::PConfusion()/10;
154 Standard_Integer i=1;
155 while((i <= Arr.Upper()) && (Abs(Coord - Arr(i)) > Tol)){
158 if(Abs(Coord - Arr(i)) < Tol)
161 if(Abs(Coord - Arr(i)) > Tol)
162 throw Standard_NotImplemented("Adaptor3d_CurveOnSurface:Hunt");
165 //=======================================================================
166 //function :ReverseParam
168 //=======================================================================
170 static void ReverseParam(const Standard_Real In1,
171 const Standard_Real In2,
173 Standard_Real& Out2 )
176 if(In1>In2) {Out1=In2;
181 //=======================================================================
182 //function :ReverseParam
184 //=======================================================================
186 static void ReverseParam(const Standard_Integer In1,
187 const Standard_Integer In2,
188 Standard_Integer& Out1,
189 Standard_Integer& Out2 )
191 if(In1>In2) {Out1=In2;
197 //=======================================================================
198 //function :FindBounds
200 //=======================================================================
201 static void FindBounds(const TColStd_Array1OfReal& Arr,
202 const Standard_Real Coord,
203 const Standard_Real Der,
204 Standard_Integer& Bound1,
205 Standard_Integer& Bound2,
206 Standard_Boolean& DerNull)
209 Standard_Integer N=0;
210 Standard_Real Tol=Precision::PConfusion()/10;
212 DerNull=Standard_False;
214 if(N==Bound1){ if(Abs(Der) > Tol) DerNull = Standard_False;
215 if(Abs(Der)<= Tol) DerNull = Standard_True;
216 Bound1=N;Bound2=N+1; return;
218 if(N==Bound2){ if( Abs(Der) > Tol ) DerNull = Standard_False;
219 if( Abs(Der)<= Tol ) DerNull = Standard_True;
220 Bound1=N-1;Bound2=N; return;
222 if((N!=Bound1)&&(N!=Bound2)) {
223 if(Abs(Der) > Tol ) {
224 if(Der>0) {Bound1=N;Bound2= N+1;}
226 if(Der<0){Bound1=N-1;Bound2=N;}
227 DerNull = Standard_False;
229 if(Abs(Der) <=Tol ) {
230 DerNull = Standard_True;
237 //=======================================================================
238 //function :Locate1Coord
239 //purpose : along BSpline curve
240 //=======================================================================
242 static void Locate1Coord(const Standard_Integer Index,
245 const Handle(Geom_BSplineCurve)& BSplC,
246 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop)
248 Standard_Real Comp1=0, DComp1=0, cur, f = 0.0, l = 0.0;
249 Standard_Real Tol = Precision::PConfusion()/10;
250 Standard_Integer i = 1, Bnd1, Bnd2;
251 Standard_Boolean DIsNull= Standard_False;
252 TColStd_Array1OfReal Arr(1,BSplC->NbKnots()); BSplC->Knots(Arr);
254 if(Index==1) { Comp1=UV.X(); DComp1=DUV.X(); }
255 if(Index==2) { Comp1=UV.Y(); DComp1=DUV.Y(); }
257 Standard_Integer Lo = BSplC->FirstUKnotIndex(), Up = BSplC->LastUKnotIndex();
260 while ( ( Abs(BSplC->Knot(i)-Comp1)>Tol )&& (i!=Up ) ) i++;
263 if( Abs(Comp1-cur)<=Tol) {
265 Bnd1 = Lo; Bnd2 = Up;
266 FindBounds(Arr,cur,DComp1,Bnd1,Bnd2,DIsNull);
267 ReverseParam(Bnd1,Bnd2,Bnd1,Bnd2);
269 if(DIsNull==Standard_False){
270 if(Index==1) {LeftBot.SetX(BSplC->Knot(Bnd1));
271 RightTop.SetX(BSplC->Knot(Bnd2));}
273 if(Index==2){ LeftBot.SetY(BSplC->Knot(Bnd1));
274 RightTop.SetY(BSplC->Knot(Bnd2)); }
277 if(DIsNull==Standard_True){
278 if( Abs( Comp1-(f=BSplC->Knot(Lo))) <= Tol)
280 if(Index==1) { LeftBot.SetX(BSplC->Knot(Lo));
281 RightTop.SetX(BSplC->Knot(Lo+1));}
282 else if(Index==2) { LeftBot.SetY(BSplC->Knot(Lo));
283 RightTop.SetY(BSplC->Knot(Lo+1));}
285 if( Abs( Comp1-(l=BSplC->Knot(Up))) <= Tol)
287 if(Index==1) { LeftBot.SetX(BSplC->Knot(Up-1));
288 RightTop.SetX(BSplC->Knot(Up));}
289 else if(Index==2) {LeftBot.SetY(BSplC->Knot(Up-1));
290 RightTop.SetY(BSplC->Knot(Up));}
292 if(Index==1) { LeftBot.SetX(BSplC->Knot(Bnd1));
293 RightTop.SetX(BSplC->Knot(Bnd2));}
294 else if(Index==2) {LeftBot.SetY(BSplC->Knot(Bnd1));
295 RightTop.SetY(BSplC->Knot(Bnd2));}
298 else//*********if Coord != Knot
302 //if((f=BSplC->Knot(i))<Comp1 && (l=BSplC->Knot(i+1))>Comp1) break;
303 //skl 28.03.2002 for OCC233
306 if(f<Comp1 && l>Comp1) break;
309 ReverseParam(f,l,f,l);
313 { if(Index==1) {LeftBot.SetX(f); RightTop.SetX(l);}else
314 if(Index==2) {LeftBot.SetY(f); RightTop.SetY(l); }
319 if(DComp1>0) {LeftBot.SetX(Comp1); RightTop.SetX(l);} else
320 if(DComp1<0) {LeftBot.SetX(f); RightTop.SetX(Comp1);}
324 if(DComp1>0) {LeftBot.SetY(Comp1); RightTop.SetY(l);} else
325 if(DComp1<0) {LeftBot.SetY(f); RightTop.SetY(Comp1);};
330 if(Index==1) {LeftBot.SetX(Comp1); RightTop.SetX(BSplC->Knot(i));}else
331 if(Index==2) {LeftBot.SetY(Comp1); RightTop.SetY(BSplC->Knot(i)); }
337 //=======================================================================
338 //function :Locate1Coord
340 //=======================================================================
342 static void Locate1Coord(const Standard_Integer Index,
345 const Handle(Geom_BSplineSurface)& BSplS,
346 Standard_Boolean& DIsNull,
350 Standard_Real Comp1=0,DComp1=0;
351 Standard_Real Tol = Precision::PConfusion()/10;
352 Standard_Integer i=1, Up=0, Up1, Up2, Down=0, Down1, Down2;
353 Standard_Real cur = 0.;
355 DIsNull= Standard_False;
357 Up1 = BSplS->LastUKnotIndex();
358 Down1 = BSplS->FirstUKnotIndex();
359 Up2 = BSplS->LastVKnotIndex();
360 Down2 = BSplS->FirstVKnotIndex();
370 while ( ( Abs(BSplS->UKnot(i)-Comp1)>Tol )&&(i!=Up1 ) )
375 cur = BSplS->UKnot(i);
385 while ( ( Abs(BSplS->VKnot(i)-Comp1)>Tol )&&(i!=Up2 ) )
390 cur = BSplS->VKnot(i);
393 if( Abs(Comp1-cur)<=Tol )
395 Standard_Integer Bnd1 = Down, Bnd2 = Up;
398 TColStd_Array1OfReal Arr1(1,BSplS->NbUKnots());
399 BSplS->UKnots(Arr1); // Up1=Arr1.Upper(); Down1=Arr1.Lower();
400 FindBounds(Arr1,cur,DUV.X(),Bnd1,Bnd2,DIsNull);
404 TColStd_Array1OfReal Arr2(1,BSplS->NbVKnots());
405 BSplS->VKnots(Arr2); // Up2=Arr2.Upper(); Down2=Arr2.Lower();
406 FindBounds(Arr2,cur,DUV.Y(),Bnd1,Bnd2,DIsNull);
409 ReverseParam(Bnd1,Bnd2,Bnd1,Bnd2);
411 if(DIsNull==Standard_False)
415 LeftBot.SetX(BSplS->UKnot(Bnd1));
416 RightTop.SetX(BSplS->UKnot(Bnd2));
420 LeftBot.SetY(BSplS->VKnot(Bnd1));
421 RightTop.SetY(BSplS->VKnot(Bnd2));
425 else//*********if Coord != Knot
427 if( (Index==1)&&(Comp1 < BSplS->UKnot(Down)) )
429 LeftBot.SetX(BSplS->UKnot(Down));
430 RightTop.SetX( BSplS->UKnot(Down + 1) );
433 else if( (Index==2)&&(Comp1 < BSplS->VKnot(Down)) )
435 LeftBot.SetY(BSplS->VKnot(Down));
436 RightTop.SetY( BSplS->VKnot(Down + 1) );
439 else if( (Index==1)&&(Comp1 > BSplS->UKnot(Up)) )
441 RightTop.SetX(BSplS->UKnot(Up - 1));
442 LeftBot.SetX( BSplS->UKnot(Up) );
445 else if( (Index==2)&&(Comp1 > BSplS->VKnot(Up)) )
447 RightTop.SetY(BSplS->VKnot(Up - 1));
448 LeftBot.SetY( BSplS->VKnot(Up) );
453 Standard_Real f = 0., l = 1.;
456 f=BSplS->UKnot(Down);
461 f=BSplS->VKnot(Down);
466 if ((!(Comp1 < f))&&(!(Comp1 > l)))
470 while (!(((f=BSplS->UKnot(i)) < Comp1)&&((l=BSplS->UKnot(i+1)) > Comp1)) && (i<Up))
477 while (!(((f=BSplS->VKnot(i)) < Comp1)&&((l=BSplS->VKnot(i+1)) > Comp1)) && (i<Up))
484 ReverseParam(f,l,f,l);
500 RightTop.SetX(Comp1);
513 RightTop.SetY(Comp1);
539 RightTop.SetX(BSplS->UKnot(i));
544 RightTop.SetY(BSplS->VKnot(i));
550 //=======================================================================
551 //function :Locate2Coord
552 //purpose : along non-BSpline curve
553 //=======================================================================
556 static void Locate2Coord(const Standard_Integer Index,
557 const gp_Pnt2d& UV, const gp_Vec2d& DUV,
558 const Standard_Real I1,
559 const Standard_Real I2,
560 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop)
562 Standard_Real Tol=Precision::PConfusion()/10;
563 Standard_Real Comp1=0,DComp1=0;
564 if(Index==1) { Comp1=UV.X();
567 if(Index==2) {Comp1=UV.Y();
570 if((Comp1!=I1)&&(Comp1!=I2))
571 { if(Abs(DComp1) > Tol)
573 { if(Index==1) { LeftBot.SetX(I1);
574 RightTop.SetX(Comp1);}
575 if(Index==2) { LeftBot.SetY(I1);
576 RightTop.SetY(Comp1);}
580 { if(Index==1) { LeftBot.SetX(Comp1);
582 if(Index==2) { LeftBot.SetY(Comp1);
585 else { if(Index==1) { LeftBot.SetX(I1);
587 if(Index==2) { LeftBot.SetY(I1);
592 if(Abs(DComp1)<=Tol) {
593 if(Index==1) { LeftBot.SetX(I1) ;
595 if(Index==2) { LeftBot.SetY(I1) ;
599 if(Abs(Comp1-I1)<Tol)
600 { if(Index==1) { LeftBot.SetX(I1) ;
602 if(Index==2) { LeftBot.SetY(I1) ;
606 if(Abs(Comp1-I2)<Tol)
607 { if(Index==1) { LeftBot.SetX(I1);
609 if(Index==2) { LeftBot.SetY(I1);
614 //=======================================================================
615 //function :Locate2Coord
617 //=======================================================================
619 static void Locate2Coord(const Standard_Integer Index,
620 const gp_Pnt2d& UV, const gp_Vec2d& DUV,
621 const Handle(Geom_BSplineSurface)& BSplS,
622 const TColStd_Array1OfReal& Arr,
623 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop)
625 Standard_Real Comp=0,DComp=0,Tmp1=0.0,Tmp2=0.0;
626 Standard_Real Tol=Precision::PConfusion()/10;
627 Standard_Integer N=0, NUp=0, NLo=0;
631 NUp = BSplS->LastUKnotIndex();
632 NLo = BSplS->FirstUKnotIndex();
637 NUp = BSplS->LastVKnotIndex();
638 NLo = BSplS->FirstVKnotIndex();
641 if((DComp > 0)&&(Abs(DComp)>Tol)) {
644 //limit case: Hunt() cought upper knot. Take the last span.
647 if(Index==1) { Tmp1=BSplS->UKnot(N);
648 Tmp2=BSplS->UKnot(N+1);}
650 if(Index==2) { Tmp1=BSplS->VKnot(N);
651 Tmp2=BSplS->VKnot(N+1);}
653 ReverseParam(Tmp1,Tmp2,Tmp1,Tmp2);
655 if(Index==1) { LeftBot.SetX(Tmp1);
656 RightTop.SetX(Tmp2);}
658 if(Index==2) { LeftBot.SetY(Tmp1);
659 RightTop.SetY(Tmp2);}
662 if((DComp < 0)&&(Abs(DComp)>Tol)){
665 //limit case: Hunt() cought lower knot. Take the first span.
668 if(Index==1) { Tmp1=BSplS->UKnot(N-1);
669 Tmp2=BSplS->UKnot(N);}
671 if(Index==2) { Tmp1=BSplS->VKnot(N-1);
672 Tmp2=BSplS->VKnot(N);}
674 ReverseParam(Tmp1,Tmp2,Tmp1,Tmp2);
676 if(Index==1) { LeftBot.SetX(Tmp1);
677 RightTop.SetX(Tmp2);}
679 if(Index==2) { LeftBot.SetY(Tmp1);
680 RightTop.SetY(Tmp2);}
686 //=======================================================================
687 //function : Adaptor3d_CurveOnSurface
689 //=======================================================================
691 Adaptor3d_CurveOnSurface::Adaptor3d_CurveOnSurface()
692 : myType(GeomAbs_OtherCurve), myIntCont(GeomAbs_CN)
695 //=======================================================================
696 //function : Adaptor3d_CurveOnSurface
698 //=======================================================================
700 Adaptor3d_CurveOnSurface::Adaptor3d_CurveOnSurface
701 (const Handle(Adaptor3d_Surface)& S)
702 : myType(GeomAbs_OtherCurve), myIntCont(GeomAbs_CN)
707 //=======================================================================
708 //function : Adaptor3d_CurveOnSurface
710 //=======================================================================
712 Adaptor3d_CurveOnSurface::Adaptor3d_CurveOnSurface
713 (const Handle(Adaptor2d_Curve2d)& C,
714 const Handle(Adaptor3d_Surface)& S)
715 : myType(GeomAbs_OtherCurve), myIntCont(GeomAbs_CN)
721 //=======================================================================
724 //=======================================================================
726 void Adaptor3d_CurveOnSurface::Load(const Handle(Adaptor3d_Surface)& S)
729 if (!myCurve.IsNull()) EvalKPart();
732 //=======================================================================
735 //=======================================================================
737 void Adaptor3d_CurveOnSurface::Load(const Handle(Adaptor2d_Curve2d)& C)
740 if (mySurface.IsNull())
747 GeomAbs_SurfaceType SType = mySurface->GetType();
748 if (SType == GeomAbs_OffsetSurface)
750 SType = mySurface->BasisSurface()->GetType();
753 if (SType == GeomAbs_BSplineSurface ||
754 SType == GeomAbs_SurfaceOfExtrusion ||
755 SType == GeomAbs_SurfaceOfRevolution)
761 //=======================================================================
764 //=======================================================================
766 void Adaptor3d_CurveOnSurface::Load (const Handle(Adaptor2d_Curve2d)& C,
767 const Handle(Adaptor3d_Surface)& S)
773 //=======================================================================
774 //function : FirstParameter
776 //=======================================================================
778 Standard_Real Adaptor3d_CurveOnSurface::FirstParameter() const
780 return myCurve->FirstParameter();
783 //=======================================================================
784 //function : LastParameter
786 //=======================================================================
788 Standard_Real Adaptor3d_CurveOnSurface::LastParameter() const
790 return myCurve->LastParameter();
793 //=======================================================================
794 //function : Continuity
796 //=======================================================================
798 GeomAbs_Shape Adaptor3d_CurveOnSurface::Continuity() const
800 GeomAbs_Shape ContC = myCurve->Continuity();
801 GeomAbs_Shape ContSu = mySurface->UContinuity();
802 if ( ContSu < ContC) ContC = ContSu;
803 GeomAbs_Shape ContSv = mySurface->VContinuity();
804 if ( ContSv < ContC) ContC = ContSv;
809 // Auxiliary: adds roots of equation to sorted sequence of parameters
810 // along curve, keeping it sorted and avoiding repetitions (within tolerance Tol)
811 static void AddIntervals (const Handle(TColStd_HSequenceOfReal)& theParameters,
812 const math_FunctionRoots& theRoots, Standard_Real theTol)
814 if (! theRoots.IsDone() || theRoots.IsAllNull())
817 Standard_Integer nsol = theRoots.NbSolutions();
818 for (Standard_Integer i = 1; i <= nsol; i++)
820 Standard_Real param = theRoots.Value(i);
821 if (param - theParameters->Value(1) < theTol) // skip param if equal to or less than theParameters(1)
823 for (Standard_Integer j=2; j <= theParameters->Length(); ++j)
825 Standard_Real aDelta = theParameters->Value(j) - param;
828 theParameters->InsertBefore (j, param);
831 else if (aDelta >= -theTol) // param == theParameters(j) within Tol
837 //=======================================================================
838 //function : NbIntervals
840 //=======================================================================
842 Standard_Integer Adaptor3d_CurveOnSurface::NbIntervals (const GeomAbs_Shape S) const
844 if(S == myIntCont && !myIntervals.IsNull())
845 return myIntervals->Length()-1;
847 Standard_Integer nu,nv,nc;
848 nu=mySurface->NbUIntervals(S);
849 nv=mySurface->NbVIntervals(S);
850 nc=myCurve->NbIntervals(S);
852 // Allocate the memory for arrays TabU, TabV, TabC only once using the buffer TabBuf.
853 TColStd_Array1OfReal TabBuf(1, nu + nv + nc + 3);
854 TColStd_Array1OfReal TabU(TabBuf(1), 1, nu+1);
855 TColStd_Array1OfReal TabV(TabBuf(nu + 2), 1, nv+1);
856 TColStd_Array1OfReal TabC(TabBuf(nu + nv + 3), 1, nc+1);
858 Standard_Integer NbSample = 20;
859 Standard_Real U,V,Tdeb,Tfin;
860 Tdeb=myCurve->FirstParameter();
861 Tfin=myCurve->LastParameter();
863 myCurve->Intervals(TabC,S);
865 Standard_Real Tol= Precision::PConfusion()/10;
867 // sorted sequence of parameters defining continuity intervals;
868 // started with own intervals of curve and completed by
869 // additional points coming from surface discontinuities
870 Handle(TColStd_HSequenceOfReal) aIntervals = new TColStd_HSequenceOfReal;
871 for (Standard_Integer i = 1; i <= nc + 1; i++)
873 aIntervals->Append(TabC(i));
878 mySurface->UIntervals(TabU,S);
879 for(Standard_Integer iu = 2;iu <= nu; iu++)
882 Adaptor3d_InterFunc Func(myCurve,U,1);
883 math_FunctionRoots Resol(Func,Tdeb,Tfin,NbSample,Tol,Tol,Tol,0.);
884 AddIntervals (aIntervals, Resol, Tol);
889 mySurface->VIntervals(TabV,S);
890 for(Standard_Integer iv = 2;iv <= nv; iv++)
893 Adaptor3d_InterFunc Func(myCurve,V,2);
894 math_FunctionRoots Resol(Func,Tdeb,Tfin,NbSample,Tol,Tol,Tol,0.);
895 AddIntervals (aIntervals, Resol, Tol);
899 // for case intervals==1 and first point == last point SequenceOfReal
900 // contains only one value, therefore it is necessary to add second
901 // value into aIntervals which will be equal first value.
902 if (aIntervals->Length() == 1)
903 aIntervals->Append (aIntervals->Value(1));
905 const_cast<Adaptor3d_CurveOnSurface*>(this)->myIntervals = aIntervals;
906 const_cast<Adaptor3d_CurveOnSurface*>(this)->myIntCont = S;
907 return myIntervals->Length() - 1;
910 //=======================================================================
911 //function : Intervals
913 //=======================================================================
915 void Adaptor3d_CurveOnSurface::Intervals(TColStd_Array1OfReal& T,
916 const GeomAbs_Shape S) const
919 Standard_ASSERT_RAISE (T.Length() == myIntervals->Length(), "Error: Wrong size of array buffer in call to Adaptor3d_CurveOnSurface::Intervals");
920 for(Standard_Integer i=1; i<=myIntervals->Length(); i++) {
921 T(i) = myIntervals->Value(i);
925 //=======================================================================
928 //=======================================================================
930 Handle(Adaptor3d_Curve) Adaptor3d_CurveOnSurface::Trim
931 (const Standard_Real First,
932 const Standard_Real Last,
933 const Standard_Real Tol) const
935 Handle(Adaptor3d_CurveOnSurface) HCS = new Adaptor3d_CurveOnSurface();
936 HCS->Load(mySurface);
937 HCS->Load(myCurve->Trim(First,Last,Tol));
941 //=======================================================================
942 //function : IsClosed
944 //=======================================================================
946 Standard_Boolean Adaptor3d_CurveOnSurface::IsClosed() const
948 return myCurve->IsClosed();
951 //=======================================================================
952 //function : IsPeriodic
954 //=======================================================================
956 Standard_Boolean Adaptor3d_CurveOnSurface::IsPeriodic() const
958 if (myType == GeomAbs_Circle ||
959 myType == GeomAbs_Ellipse)
960 return Standard_True;
962 return myCurve->IsPeriodic();
965 //=======================================================================
968 //=======================================================================
970 Standard_Real Adaptor3d_CurveOnSurface::Period() const
972 if (myType == GeomAbs_Circle ||
973 myType == GeomAbs_Ellipse)
976 return myCurve->Period();
979 //=======================================================================
982 //=======================================================================
984 gp_Pnt Adaptor3d_CurveOnSurface::Value(const Standard_Real U ) const
989 if (myType == GeomAbs_Line ) P = ElCLib::Value(U,myLin );
990 else if (myType == GeomAbs_Circle) P = ElCLib::Value(U,myCirc);
993 mySurface->D0(Puv.X(),Puv.Y(),P);
999 //=======================================================================
1002 //=======================================================================
1004 void Adaptor3d_CurveOnSurface::D0(const Standard_Real U ,
1009 if (myType == GeomAbs_Line ) P = ElCLib::Value(U,myLin );
1010 else if (myType == GeomAbs_Circle) P = ElCLib::Value(U,myCirc);
1013 mySurface->D0(Puv.X(),Puv.Y(),P);
1019 //=======================================================================
1022 //=======================================================================
1024 void Adaptor3d_CurveOnSurface::D1(const Standard_Real U ,
1032 Standard_Real FP = myCurve->FirstParameter();
1033 Standard_Real LP = myCurve->LastParameter();
1035 Standard_Real Tol= Precision::PConfusion()/10;
1036 if( ( Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
1038 myCurve->D1(U,Puv,Duv);
1039 myFirstSurf->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1040 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1043 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
1045 myCurve->D1(U,Puv,Duv);
1046 myLastSurf->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1047 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1050 if (myType == GeomAbs_Line ) ElCLib::D1(U,myLin ,P,V);
1051 else if (myType == GeomAbs_Circle) ElCLib::D1(U,myCirc,P,V);
1053 myCurve->D1(U,Puv,Duv);
1054 mySurface->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1055 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1058 //=======================================================================
1061 //=======================================================================
1063 void Adaptor3d_CurveOnSurface::D2(const Standard_Real U,
1070 gp_Vec D1U,D1V,D2U,D2V,D2UV;
1072 Standard_Real FP = myCurve->FirstParameter();
1073 Standard_Real LP = myCurve->LastParameter();
1075 Standard_Real Tol= Precision::PConfusion()/10;
1076 if( (Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
1078 myCurve->D2(U,UV,DW,D2W);
1079 myFirstSurf->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
1081 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1082 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1083 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1086 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
1088 myCurve->D2(U,UV,DW,D2W);
1089 myLastSurf->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
1091 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1092 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1093 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1096 if (myType == GeomAbs_Line ) {
1097 ElCLib::D1(U,myLin,P,V1);
1098 V2.SetCoord(0.,0.,0.);
1100 else if (myType == GeomAbs_Circle) ElCLib::D2(U,myCirc,P,V1,V2);
1102 myCurve->D2(U,UV,DW,D2W);
1103 mySurface->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
1105 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1106 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1107 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1111 //=======================================================================
1114 //=======================================================================
1116 void Adaptor3d_CurveOnSurface::D3
1117 (const Standard_Real U,
1124 Standard_Real Tol= Precision::PConfusion()/10;
1126 gp_Vec2d DW,D2W,D3W;
1127 gp_Vec D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV;
1129 Standard_Real FP = myCurve->FirstParameter();
1130 Standard_Real LP = myCurve->LastParameter();
1132 if( (Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
1133 { myCurve->D3(U,UV,DW,D2W,D3W);
1134 myFirstSurf->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
1135 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1136 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1137 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1138 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1141 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
1142 { myCurve->D3(U,UV,DW,D2W,D3W);
1143 myLastSurf->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
1144 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1146 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1147 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1148 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1151 if (myType == GeomAbs_Line ) {
1152 ElCLib::D1(U,myLin,P,V1);
1153 V2.SetCoord(0.,0.,0.);
1154 V3.SetCoord(0.,0.,0.);
1156 else if (myType == GeomAbs_Circle) ElCLib::D3(U,myCirc,P,V1,V2,V3);
1158 myCurve->D3(U,UV,DW,D2W,D3W);
1159 mySurface->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
1160 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1162 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1163 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1164 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1169 //=======================================================================
1172 //=======================================================================
1174 gp_Vec Adaptor3d_CurveOnSurface::DN
1175 (const Standard_Real U,
1176 const Standard_Integer N) const
1191 throw Standard_NotImplemented("Adaptor3d_CurveOnSurface:DN");
1198 //=======================================================================
1199 //function : Resolution
1201 //=======================================================================
1203 Standard_Real Adaptor3d_CurveOnSurface::Resolution
1204 (const Standard_Real R3d) const
1206 Standard_Real ru,rv;
1207 ru = mySurface->UResolution(R3d);
1208 rv = mySurface->VResolution(R3d);
1209 return myCurve->Resolution(Min(ru,rv));
1213 //=======================================================================
1214 //function : GetType
1216 //=======================================================================
1218 GeomAbs_CurveType Adaptor3d_CurveOnSurface::GetType() const
1224 //=======================================================================
1227 //=======================================================================
1229 gp_Lin Adaptor3d_CurveOnSurface::Line() const
1231 Standard_NoSuchObject_Raise_if(myType != GeomAbs_Line, "Adaptor3d_CurveOnSurface::Line(): curve is not a line")
1235 //=======================================================================
1238 //=======================================================================
1240 gp_Circ Adaptor3d_CurveOnSurface::Circle() const
1242 Standard_NoSuchObject_Raise_if(myType != GeomAbs_Circle, "Adaptor3d_CurveOnSurface::Line(): curve is not a circle")
1246 //=======================================================================
1247 //function : Ellipse
1249 //=======================================================================
1251 gp_Elips Adaptor3d_CurveOnSurface::Ellipse() const
1253 return to3d(mySurface->Plane(),myCurve->Ellipse());
1256 //=======================================================================
1257 //function : Hyperbola
1259 //=======================================================================
1261 gp_Hypr Adaptor3d_CurveOnSurface::Hyperbola() const
1263 return to3d(mySurface->Plane(),myCurve->Hyperbola());
1266 //=======================================================================
1267 //function : Parabola
1269 //=======================================================================
1271 gp_Parab Adaptor3d_CurveOnSurface::Parabola() const
1273 return to3d(mySurface->Plane(),myCurve->Parabola());
1276 Standard_Integer Adaptor3d_CurveOnSurface::Degree() const
1279 // on a parametric surface should multiply
1280 // return TheCurve2dTool::Degree(myCurve);
1282 return myCurve->Degree();
1285 //=======================================================================
1286 //function : IsRational
1288 //=======================================================================
1290 Standard_Boolean Adaptor3d_CurveOnSurface::IsRational() const
1292 return ( myCurve->IsRational() ||
1293 mySurface->IsURational() ||
1294 mySurface->IsVRational() );
1297 //=======================================================================
1298 //function : NbPoles
1300 //=======================================================================
1302 Standard_Integer Adaptor3d_CurveOnSurface::NbPoles() const
1304 // on a parametric surface should multiply
1305 return myCurve->NbPoles();
1308 //=======================================================================
1309 //function : NbKnots
1311 //=======================================================================
1313 Standard_Integer Adaptor3d_CurveOnSurface::NbKnots() const {
1314 if (mySurface->GetType()==GeomAbs_Plane)
1315 return myCurve->NbKnots();
1317 throw Standard_NoSuchObject();
1321 //=======================================================================
1324 //=======================================================================
1326 Handle(Geom_BezierCurve) Adaptor3d_CurveOnSurface::Bezier() const
1328 Standard_NoSuchObject_Raise_if
1329 ( mySurface->GetType() != GeomAbs_Plane,
1330 "Adaptor3d_CurveOnSurface : Bezier");
1332 Handle(Geom2d_BezierCurve) Bez2d = myCurve->Bezier();
1333 Standard_Integer NbPoles = Bez2d->NbPoles();
1335 const gp_Pln& Plane = mySurface->Plane();
1337 TColgp_Array1OfPnt Poles(1,NbPoles);
1338 for ( Standard_Integer i=1; i<= NbPoles; i++) {
1339 Poles(i) = to3d( Plane, Bez2d->Pole(i));
1341 Handle(Geom_BezierCurve) Bez;
1343 if (Bez2d->IsRational()) {
1344 TColStd_Array1OfReal Weights(1,NbPoles);
1345 Bez2d->Weights(Weights);
1346 Bez = new Geom_BezierCurve(Poles,Weights);
1349 Bez = new Geom_BezierCurve(Poles);
1354 //=======================================================================
1355 //function : BSpline
1357 //=======================================================================
1359 Handle(Geom_BSplineCurve) Adaptor3d_CurveOnSurface::BSpline() const
1361 Standard_NoSuchObject_Raise_if
1362 ( mySurface->GetType() != GeomAbs_Plane,
1363 "Adaptor3d_CurveOnSurface : BSpline");
1365 Handle(Geom2d_BSplineCurve) Bsp2d = myCurve->BSpline();
1366 Standard_Integer NbPoles = Bsp2d->NbPoles();
1368 const gp_Pln& Plane = mySurface->Plane();
1370 TColgp_Array1OfPnt Poles(1,NbPoles);
1371 for ( Standard_Integer i=1; i<= NbPoles; i++) {
1372 Poles(i) = to3d( Plane, Bsp2d->Pole(i));
1375 TColStd_Array1OfReal Knots(1,Bsp2d->NbKnots());
1376 TColStd_Array1OfInteger Mults(1,Bsp2d->NbKnots());
1377 Bsp2d->Knots(Knots);
1378 Bsp2d->Multiplicities(Mults);
1380 Handle(Geom_BSplineCurve) Bsp;
1382 if (Bsp2d->IsRational()) {
1383 TColStd_Array1OfReal Weights(1,NbPoles);
1384 Bsp2d->Weights(Weights);
1385 Bsp = new Geom_BSplineCurve(Poles,Weights,Knots,Mults,
1387 Bsp2d->IsPeriodic());
1390 Bsp = new Geom_BSplineCurve(Poles,Knots,Mults,
1392 Bsp2d->IsPeriodic());
1397 //=======================================================================
1398 //function : GetCurve
1400 //=======================================================================
1402 const Handle(Adaptor2d_Curve2d)& Adaptor3d_CurveOnSurface::GetCurve() const
1407 //=======================================================================
1408 //function : GetSurface
1410 //=======================================================================
1412 const Handle(Adaptor3d_Surface)& Adaptor3d_CurveOnSurface::GetSurface() const
1417 //=======================================================================
1418 //function : ChangeCurve
1420 //=======================================================================
1422 Handle(Adaptor2d_Curve2d)& Adaptor3d_CurveOnSurface::ChangeCurve()
1427 //=======================================================================
1428 //function : ChangeSurface
1430 //=======================================================================
1432 Handle(Adaptor3d_Surface)& Adaptor3d_CurveOnSurface::ChangeSurface() {
1436 //=======================================================================
1437 //function : EvalKPart
1439 //=======================================================================
1441 void Adaptor3d_CurveOnSurface::EvalKPart()
1443 myType = GeomAbs_OtherCurve;
1445 GeomAbs_SurfaceType STy = mySurface->GetType();
1446 GeomAbs_CurveType CTy = myCurve->GetType();
1447 if (STy == GeomAbs_Plane) {
1449 if (myType == GeomAbs_Circle)
1450 myCirc = to3d(mySurface->Plane(),myCurve->Circle());
1451 else if (myType == GeomAbs_Line) {
1456 myCurve->D1(0.,Puv,Duv);
1458 mySurface->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1459 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1460 myLin = gp_Lin(P,V);
1464 if ( CTy == GeomAbs_Line) {
1465 gp_Dir2d D = myCurve->Line().Direction();
1466 if ( D.IsParallel(gp::DX2d(),Precision::Angular())) { // Iso V.
1467 if ( STy == GeomAbs_Sphere) {
1468 gp_Pnt2d P = myCurve->Line().Location();
1469 if ( Abs( Abs(P.Y()) -M_PI/2. ) >= Precision::PConfusion()) {
1470 myType = GeomAbs_Circle;
1471 gp_Sphere Sph = mySurface->Sphere();
1472 gp_Ax3 Axis = Sph.Position();
1473 myCirc = ElSLib::SphereVIso(Axis,
1476 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1477 gp_Ax1 AxeRev(Axis.Location(), DRev);
1478 myCirc.Rotate(AxeRev, P.X());
1479 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1480 gp_Ax2 Ax = myCirc.Position();
1481 Ax.SetDirection(Ax.Direction().Reversed());
1482 myCirc.SetPosition(Ax);
1486 else if ( STy == GeomAbs_Cylinder) {
1487 myType = GeomAbs_Circle;
1488 gp_Cylinder Cyl = mySurface->Cylinder();
1489 gp_Pnt2d P = myCurve->Line().Location();
1490 gp_Ax3 Axis = Cyl.Position();
1491 myCirc = ElSLib::CylinderVIso(Axis,
1494 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1495 gp_Ax1 AxeRev(Axis.Location(), DRev);
1496 myCirc.Rotate(AxeRev, P.X());
1497 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1498 gp_Ax2 Ax = myCirc.Position();
1499 Ax.SetDirection(Ax.Direction().Reversed());
1500 myCirc.SetPosition(Ax);
1503 else if ( STy == GeomAbs_Cone) {
1504 myType = GeomAbs_Circle;
1505 gp_Cone Cone = mySurface->Cone();
1506 gp_Pnt2d P = myCurve->Line().Location();
1507 gp_Ax3 Axis = Cone.Position();
1508 myCirc = ElSLib::ConeVIso(Axis,
1512 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1513 gp_Ax1 AxeRev(Axis.Location(), DRev);
1514 myCirc.Rotate(AxeRev, P.X());
1515 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1516 gp_Ax2 Ax = myCirc.Position();
1517 Ax.SetDirection(Ax.Direction().Reversed());
1518 myCirc.SetPosition(Ax);
1521 else if ( STy == GeomAbs_Torus) {
1522 myType = GeomAbs_Circle;
1523 gp_Torus Tore = mySurface->Torus();
1524 gp_Pnt2d P = myCurve->Line().Location();
1525 gp_Ax3 Axis = Tore.Position();
1526 myCirc = ElSLib::TorusVIso(Axis,
1530 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1531 gp_Ax1 AxeRev(Axis.Location(), DRev);
1532 myCirc.Rotate(AxeRev, P.X());
1533 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1534 gp_Ax2 Ax = myCirc.Position();
1535 Ax.SetDirection(Ax.Direction().Reversed());
1536 myCirc.SetPosition(Ax);
1540 else if ( D.IsParallel(gp::DY2d(),Precision::Angular())) { // Iso U.
1541 if ( STy == GeomAbs_Sphere) {
1542 myType = GeomAbs_Circle;
1543 gp_Sphere Sph = mySurface->Sphere();
1544 gp_Pnt2d P = myCurve->Line().Location();
1545 gp_Ax3 Axis = Sph.Position();
1546 // calcul de l'iso 0.
1547 myCirc = ElSLib::SphereUIso(Axis, Sph.Radius(),0.);
1549 // mise a sameparameter (rotation du cercle - decalage du Y)
1550 gp_Dir DRev = Axis.XDirection().Crossed(Axis. Direction());
1551 gp_Ax1 AxeRev(Axis.Location(),DRev);
1552 myCirc.Rotate(AxeRev, P.Y());
1554 // transformation en iso U ( = P.X())
1555 DRev = Axis.XDirection().Crossed(Axis.YDirection());
1556 AxeRev = gp_Ax1(Axis.Location(), DRev);
1557 myCirc.Rotate(AxeRev, P.X());
1559 if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) {
1560 gp_Ax2 Ax = myCirc.Position();
1561 Ax.SetDirection(Ax.Direction().Reversed());
1562 myCirc.SetPosition(Ax);
1565 else if ( STy == GeomAbs_Cylinder) {
1566 myType = GeomAbs_Line;
1567 gp_Cylinder Cyl = mySurface->Cylinder();
1568 gp_Pnt2d P = myCurve->Line().Location();
1569 myLin = ElSLib::CylinderUIso(Cyl.Position(),
1572 gp_Vec Tr(myLin.Direction());
1574 myLin.Translate(Tr);
1575 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
1578 else if ( STy == GeomAbs_Cone) {
1579 myType = GeomAbs_Line;
1580 gp_Cone Cone = mySurface->Cone();
1581 gp_Pnt2d P = myCurve->Line().Location();
1582 myLin = ElSLib::ConeUIso(Cone.Position(),
1586 gp_Vec Tr(myLin.Direction());
1588 myLin.Translate(Tr);
1589 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
1592 else if ( STy == GeomAbs_Torus) {
1593 myType = GeomAbs_Circle;
1594 gp_Torus Tore = mySurface->Torus();
1595 gp_Pnt2d P = myCurve->Line().Location();
1596 gp_Ax3 Axis = Tore.Position();
1597 myCirc = ElSLib::TorusUIso(Axis,
1601 myCirc.Rotate(myCirc.Axis(),P.Y());
1603 if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) {
1604 gp_Ax2 Ax = myCirc.Position();
1605 Ax.SetDirection(Ax.Direction().Reversed());
1606 myCirc.SetPosition(Ax);
1613 //=======================================================================
1614 //function :EvalFirstLastSurf
1616 //=======================================================================
1618 void Adaptor3d_CurveOnSurface::EvalFirstLastSurf()
1620 Standard_Real FirstPar,LastPar;
1621 gp_Pnt2d UV, LeftBot, RightTop;
1623 Standard_Real Tol= Precision::PConfusion()/10;
1624 Standard_Boolean Ok = Standard_True;
1627 FirstPar=myCurve->FirstParameter();
1628 myCurve->D1(FirstPar,UV,DUV);
1630 if(DUV.Magnitude() <= Tol) Ok = Standard_False;
1634 switch(mySurface->GetType()) {
1635 case GeomAbs_BSplineSurface :
1636 LocatePart(UV,DUV,mySurface,LeftBot,RightTop);
1638 case GeomAbs_SurfaceOfRevolution :
1639 case GeomAbs_SurfaceOfExtrusion :
1640 Ok = LocatePart_RevExt(UV,DUV,mySurface,LeftBot,RightTop);
1642 case GeomAbs_OffsetSurface :
1643 Ok = LocatePart_Offset(UV,DUV,mySurface,LeftBot,RightTop);
1646 throw Standard_NotImplemented("Adaptor3d_CurveOnSurface::EvalFirstLastSurf");
1653 CompareBounds(LeftBot,RightTop); //SVV
1655 myFirstSurf = mySurface->UTrim(LeftBot.X(),RightTop.X(),Tol);
1656 myFirstSurf = myFirstSurf->VTrim(LeftBot.Y(),RightTop.Y(),Tol);
1660 myFirstSurf = mySurface;
1663 LastPar=myCurve->LastParameter();
1665 myCurve->D1(LastPar,UV,DUV);
1666 DUV.Reverse(); //We want the other part
1668 if(DUV.Magnitude() <= Tol) Ok = Standard_False;
1672 switch(mySurface->GetType()) {
1673 case GeomAbs_BSplineSurface :
1674 LocatePart(UV,DUV,mySurface,LeftBot,RightTop);
1676 case GeomAbs_SurfaceOfRevolution :
1677 case GeomAbs_SurfaceOfExtrusion :
1678 Ok = LocatePart_RevExt(UV,DUV,mySurface,LeftBot,RightTop);
1680 case GeomAbs_OffsetSurface :
1681 Ok = LocatePart_Offset(UV,DUV,mySurface,LeftBot,RightTop);
1684 throw Standard_NotImplemented("Adaptor3d_CurveOnSurface::EvalFirstLastSurf");
1691 CompareBounds(LeftBot, RightTop); //SVV
1693 myLastSurf = mySurface->UTrim(LeftBot.X(),RightTop.X(),Tol);
1694 myLastSurf = myLastSurf->VTrim(LeftBot.Y(),RightTop.Y(),Tol);
1698 myLastSurf = mySurface;
1702 //=======================================================================
1703 //function :LocatePart_RevExt
1704 //purpose : processes Knots
1705 //=======================================================================
1707 Standard_Boolean Adaptor3d_CurveOnSurface::LocatePart_RevExt(const gp_Pnt2d& UV,
1708 const gp_Vec2d& DUV,
1709 const Handle(Adaptor3d_Surface)& S,
1711 gp_Pnt2d& RightTop) const
1713 Handle(Adaptor3d_Curve) AHC = S->BasisCurve();
1715 if (AHC->GetType() == GeomAbs_BSplineCurve) {
1716 Handle( Geom_BSplineCurve) BSplC;
1717 BSplC = AHC->BSpline();
1719 if((S->GetType())==GeomAbs_SurfaceOfExtrusion) {
1720 Locate1Coord(1,UV,DUV,BSplC,LeftBot,RightTop);
1721 Locate2Coord(2,UV,DUV,S->FirstVParameter(),S->LastVParameter(),LeftBot,RightTop);
1723 else if((S->GetType())==GeomAbs_SurfaceOfRevolution) {
1724 Locate1Coord(2,UV,DUV,BSplC,LeftBot,RightTop);
1725 Locate2Coord(1,UV,DUV,S->FirstUParameter(),S->LastUParameter(),LeftBot,RightTop);
1728 Standard_Real u1,u2,v1,v2;
1729 ReverseParam(LeftBot.X(),RightTop.X(),u1,u2);
1732 ReverseParam(LeftBot.Y(),RightTop.Y(),v1,v2);
1735 return Standard_True;
1737 return Standard_False;
1740 //=======================================================================
1741 //function :LocatePart_OffsetSurface
1743 //=======================================================================
1745 Standard_Boolean Adaptor3d_CurveOnSurface::
1746 LocatePart_Offset(const gp_Pnt2d& UV, const gp_Vec2d& DUV,
1747 const Handle(Adaptor3d_Surface)& S,
1748 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop) const
1750 Standard_Boolean Ok = Standard_True;
1751 Handle( Adaptor3d_Surface) AHS;
1752 Handle( Geom_BSplineSurface) BSplS;
1753 AHS = S->BasisSurface();
1754 GeomAbs_SurfaceType BasisSType = AHS->GetType();
1755 switch(BasisSType) {
1756 case GeomAbs_SurfaceOfRevolution:
1757 case GeomAbs_SurfaceOfExtrusion :
1758 Ok = LocatePart_RevExt(UV,DUV,AHS,LeftBot,RightTop);
1761 case GeomAbs_BSplineSurface:
1762 LocatePart(UV,DUV,AHS,LeftBot,RightTop);
1771 //=======================================================================
1772 //function :LocatePart
1773 //purpose : for BSplineSurface
1774 //=======================================================================
1776 void Adaptor3d_CurveOnSurface::LocatePart(const gp_Pnt2d& UV, const gp_Vec2d& DUV,
1777 const Handle(Adaptor3d_Surface)& S,
1778 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop) const
1780 Handle( Geom_BSplineSurface) BSplS;
1781 BSplS = S->BSpline();
1782 Standard_Boolean DUIsNull=Standard_False,
1783 DVIsNull=Standard_False;
1785 Locate1Coord(1,UV,DUV,BSplS,DUIsNull,LeftBot,RightTop);
1786 Locate1Coord(2,UV,DUV,BSplS,DVIsNull,LeftBot,RightTop);
1788 if((DUIsNull==Standard_True)&&(DVIsNull==Standard_False)) {
1789 TColStd_Array1OfReal ArrU(1,BSplS->NbUKnots());
1790 BSplS->UKnots(ArrU);
1791 Locate2Coord(1,UV,DUV,BSplS,ArrU,LeftBot,RightTop);
1793 else if((DVIsNull==Standard_True)&&(DUIsNull==Standard_False)) {
1794 TColStd_Array1OfReal ArrV(1,BSplS->NbVKnots());
1795 BSplS->VKnots(ArrV);
1796 Locate2Coord(2,UV,DUV,BSplS,ArrV,LeftBot,RightTop);