Merging OCC22247 and OCC22138 bug fixes
[occt.git] / src / Adaptor3d / Adaptor3d_CurveOnSurface.cxx
CommitLineData
7fd59977 1#define No_Standard_OutOfRange
2
3#include <Adaptor3d_CurveOnSurface.ixx>
4
5#include <gp_Pnt2d.hxx>
6#include <gp_Vec2d.hxx>
7#include <gp_Ax22d.hxx>
8#include <gp_Lin2d.hxx>
9#include <gp_Circ2d.hxx>
10#include <gp_Elips2d.hxx>
11#include <gp_Hypr2d.hxx>
12#include <gp_Parab2d.hxx>
13#include <Geom_BSplineSurface.hxx>
14#include <Geom_SurfaceOfRevolution.hxx>
15#include <Geom_SurfaceOfLinearExtrusion.hxx>
16#include <Geom_OffsetSurface.hxx>
17#include <Geom2d_BezierCurve.hxx>
18#include <Geom2d_BSplineCurve.hxx>
19#include <Precision.hxx>
20#include <TColgp_Array1OfPnt2d.hxx>
21#include <TColgp_Array1OfPnt.hxx>
22#include <TColStd_Array1OfReal.hxx>
23#include <TColStd_Array1OfInteger.hxx>
24#include <Standard_NotImplemented.hxx>
25#include <Adaptor3d_HCurveOnSurface.hxx>
26#include <ElCLib.hxx>
27#include <ElSLib.hxx>
28#include <Adaptor3d_InterFunc.hxx>
29#include <math_FunctionRoots.hxx>
30#include <SortTools_StraightInsertionSortOfReal.hxx>
31#include <TCollection_CompareOfReal.hxx>
32#include <ElSLib.hxx>
33#include <TColStd_SetIteratorOfSetOfReal.hxx>
34#include <TColStd_SetOfReal.hxx>
35#include <TColStd_HSetOfReal.hxx>
36
37static gp_Pnt to3d(const gp_Pln& Pl, const gp_Pnt2d& P)
38{
39 return ElSLib::Value(P.X(),P.Y(),Pl);
40}
41
42static gp_Vec to3d(const gp_Pln& Pl, const gp_Vec2d& V)
43{
44 gp_Vec Vx = Pl.XAxis().Direction();
45 gp_Vec Vy = Pl.YAxis().Direction();
46 Vx.Multiply(V.X());
47 Vy.Multiply(V.Y());
48 Vx.Add(Vy);
49 return Vx;
50}
51
52static gp_Ax2 to3d(const gp_Pln& Pl, const gp_Ax22d& A)
53{
54 gp_Pnt P = to3d(Pl,A.Location());
55 gp_Vec VX = to3d(Pl,A.XAxis().Direction());
56 gp_Vec VY = to3d(Pl,A.YAxis().Direction());
57 return gp_Ax2(P,VX.Crossed(VY),VX);
58}
59
60static gp_Circ to3d(const gp_Pln& Pl, const gp_Circ2d& C)
61{
62 return gp_Circ(to3d(Pl,C.Axis()),C.Radius());
63}
64
65static gp_Elips to3d(const gp_Pln& Pl, const gp_Elips2d& E)
66{
67 return gp_Elips(to3d(Pl,E.Axis()),E.MajorRadius(),E.MinorRadius());
68}
69
70static gp_Hypr to3d(const gp_Pln& Pl, const gp_Hypr2d& H)
71{
72 return gp_Hypr(to3d(Pl,H.Axis()),H.MajorRadius(),H.MinorRadius());
73}
74
75static gp_Parab to3d(const gp_Pln& Pl, const gp_Parab2d& P)
76{
77 return gp_Parab(to3d(Pl,P.Axis()),P.Focal());
78}
79
80static gp_Vec SetLinearForm(const gp_Vec2d DW, const gp_Vec2d D2W,const gp_Vec2d D3W,
81 const gp_Vec D1U, const gp_Vec D1V, const gp_Vec D2U,
82 const gp_Vec D2V, const gp_Vec D2UV, const gp_Vec D3U,
83 const gp_Vec D3V, const gp_Vec D3UUV,const gp_Vec D3UVV)
84{gp_Vec V31, V32, V33, V34,V3 ;
85 V31.SetLinearForm(DW.X(),D1U,
86 D2W.X()*DW.X(),D2U,
87 D2W.X()*DW.Y(),D2UV);
88 V31.SetLinearForm(D3W.Y(),D1V,
89 D2W.Y()*DW.X(),D2UV,
90 D2W.Y()*DW.Y(),D2V,
91 V31);
92 V32.SetLinearForm(DW.X()*DW.X()*DW.Y(),D3UUV,
93 DW.X()*DW.Y()*DW.Y(),D3UVV);
94 V32.SetLinearForm(D2W.X()*DW.Y()+DW.X()*D2W.Y(),D2UV,
95 DW.X()*DW.Y()*DW.Y(),D3UVV,
96 V32);
97 V33.SetLinearForm(2*D2W.X()*DW.X(),D2U,
98 DW.X()*DW.X()*DW.X(),D3U,
99 DW.X()*DW.X()*DW.Y(),D3UUV);
100
101 V34.SetLinearForm(2*D2W.Y()*DW.Y(),D2V,
102 DW.Y()*DW.Y()*DW.X(),D3UVV,
103 DW.Y()*DW.Y()*DW.Y(),D3V);
104 V3.SetLinearForm(1,V31,2,V32,1,V33,V34);
105 return V3;
106}
107
108//=======================================================================
109static void CompareBounds(gp_Pnt2d& P1,
110 gp_Pnt2d& P2)//SVV
111{
112 Standard_Real Lx = P1.X(),Ly = P1.Y();
113 Standard_Real Rx = P2.X(),Ry = P2.Y();
114
115 if (Lx > Rx) { P1.SetX(Rx); P2.SetX(Lx);}
116 if (Ly > Ry) { P1.SetY(Ry); P2.SetY(Ly);}
117}
118
119//=======================================================================
120//function :Hunt
121//purpose :
122//=======================================================================
123static void Hunt(const TColStd_Array1OfReal& Arr,
124 const Standard_Real Coord,
125 Standard_Integer& Iloc)
126{//Warning: Hunt is used to find number of knot which equals co-ordinate component,
127 // when co-ordinate component definitly equals a knot only.
128 Standard_Real Tol=Precision::PConfusion()/10;
129 Standard_Integer i=1;
130 while((i<=Arr.Upper())&&(Abs(Coord-Arr(i))>Tol)){
131 i++;}
132
133 if(Abs(Coord-Arr(i))<Tol)
134 Iloc = i;
135 else
136 if(Abs(Coord-Arr(i)>Tol)) Standard_NotImplemented::Raise("Adaptor3d_CurveOnSurface:Hunt");
137}
138
139//=======================================================================
140//function :ReverseParam
141//purpose :
142//=======================================================================
143
144static void ReverseParam(const Standard_Real In1,
145 const Standard_Real In2,
146 Standard_Real& Out1,
147 Standard_Real& Out2 )
148{
149
150 if(In1>In2) {Out1=In2;
151 Out2=In1;}
152 else {Out1=In1;
153 Out2=In2;}
154}
155//=======================================================================
156//function :ReverseParam
157//purpose :
158//=======================================================================
159
160static void ReverseParam(const Standard_Integer In1,
161 const Standard_Integer In2,
162 Standard_Integer& Out1,
163 Standard_Integer& Out2 )
164{
165 if(In1>In2) {Out1=In2;
166 Out2=In1;}
167 else {Out1=In1;
168 Out2=In2;}
169}
170
171//=======================================================================
172//function :FindBounds
173//purpose :
174//=======================================================================
175static void FindBounds(const TColStd_Array1OfReal& Arr,
176 const Standard_Real Coord,
177 const Standard_Real Der,
178 Standard_Integer& Bound1,
179 Standard_Integer& Bound2,
180 Standard_Boolean& DerNull)
181
182{
183 Standard_Integer N;
184 Standard_Real Tol=Precision::PConfusion()/10;
185 Hunt(Arr,Coord,N);
186 DerNull=Standard_False;
187
188 if(N==Bound1){ if(Abs(Der) > Tol) DerNull = Standard_False;
189 if(Abs(Der)<= Tol) DerNull = Standard_True;
190 Bound1=N;Bound2=N+1; return;
191 }
192 if(N==Bound2){ if( Abs(Der) > Tol ) DerNull = Standard_False;
193 if( Abs(Der)<= Tol ) DerNull = Standard_True;
194 Bound1=N-1;Bound2=N; return;
195 }
196 if((N!=Bound1)&&(N!=Bound2)) {
197 if(Abs(Der) > Tol ) {
198 if(Der>0) {Bound1=N;Bound2= N+1;}
199 else
200 if(Der<0){Bound1=N-1;Bound2=N;}
201 DerNull = Standard_False;
202 }
203 if(Abs(Der) <=Tol ) {
204 DerNull = Standard_True;
205 Bound1=N-1;
206 Bound2=N+1;
207 }
208 }
209}
210
211//=======================================================================
212//function :Locate1Coord
213//purpose : along BSpline curve
214//=======================================================================
215
216static void Locate1Coord(const Standard_Integer Index,
217 const gp_Pnt2d& UV,
218 const gp_Vec2d& DUV,
219 const Handle(Geom_BSplineCurve)& BSplC,
220 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop)
221{
222 Standard_Real Comp1=0, DComp1=0, cur, f, l;
223 Standard_Real Tol = Precision::PConfusion()/10;
224 Standard_Integer i = 1, Bnd1, Bnd2;
225 Standard_Boolean DIsNull= Standard_False;
226 TColStd_Array1OfReal Arr(1,BSplC->NbKnots()); BSplC->Knots(Arr);
227
228 if(Index==1) { Comp1=UV.X(); DComp1=DUV.X(); }
229 if(Index==2) { Comp1=UV.Y(); DComp1=DUV.Y(); }
230
231 Standard_Integer Lo = BSplC->FirstUKnotIndex(), Up = BSplC->LastUKnotIndex();
232
233 i = Lo;
234 while ( ( Abs(BSplC->Knot(i)-Comp1)>Tol )&& (i!=Up ) ) i++;
235 cur=BSplC->Knot(i);
236
237 if( Abs(Comp1-cur)<=Tol) {
238
239 Bnd1 = Lo; Bnd2 = Up;
240 FindBounds(Arr,cur,DComp1,Bnd1,Bnd2,DIsNull);
241 ReverseParam(Bnd1,Bnd2,Bnd1,Bnd2);
242
243 if(DIsNull==Standard_False){
244 if(Index==1) {LeftBot.SetX(BSplC->Knot(Bnd1));
245 RightTop.SetX(BSplC->Knot(Bnd2));}
246 else
247 if(Index==2){ LeftBot.SetY(BSplC->Knot(Bnd1));
248 RightTop.SetY(BSplC->Knot(Bnd2)); }
249 }
250 else
251 if(DIsNull==Standard_True){
252 if( Abs( Comp1-(f=BSplC->Knot(Lo))) <= Tol)
253 {
254 if(Index==1) { LeftBot.SetX(BSplC->Knot(Lo));
255 RightTop.SetX(BSplC->Knot(Lo+1));}
256 else if(Index==2) { LeftBot.SetY(BSplC->Knot(Lo));
257 RightTop.SetY(BSplC->Knot(Lo+1));}
258 } else
259 if( Abs( Comp1-(l=BSplC->Knot(Up))) <= Tol)
260 {
261 if(Index==1) { LeftBot.SetX(BSplC->Knot(Up-1));
262 RightTop.SetX(BSplC->Knot(Up));}
263 else if(Index==2) {LeftBot.SetY(BSplC->Knot(Up-1));
264 RightTop.SetY(BSplC->Knot(Up));}
265 }else
266 if(Index==1) { LeftBot.SetX(BSplC->Knot(Bnd1));
267 RightTop.SetX(BSplC->Knot(Bnd2));}
268 else if(Index==2) {LeftBot.SetY(BSplC->Knot(Bnd1));
269 RightTop.SetY(BSplC->Knot(Bnd2));}
270 }
271 }
272 else//*********if Coord != Knot
273 {
274 i=Lo;
275 while (i < Up) {
276 //if((f=BSplC->Knot(i))<Comp1 && (l=BSplC->Knot(i+1))>Comp1) break;
277 //skl 28.03.2002 for OCC233
278 f=BSplC->Knot(i);
279 l=BSplC->Knot(i+1);
280 if(f<Comp1 && l>Comp1) break;
281 i++;
282 }
283 ReverseParam(f,l,f,l);
284
285 if(i!=Up) {
286 if(Abs(DComp1)<Tol)
287 { if(Index==1) {LeftBot.SetX(f); RightTop.SetX(l);}else
288 if(Index==2) {LeftBot.SetY(f); RightTop.SetY(l); }
289 }else
290 if(Abs(DComp1)>Tol)
291 {
292 if(Index==1) {
293 if(DComp1>0) {LeftBot.SetX(Comp1); RightTop.SetX(l);} else
294 if(DComp1<0) {LeftBot.SetX(f); RightTop.SetX(Comp1);}
295 }
296 else
297 if(Index==2) {
298 if(DComp1>0) {LeftBot.SetY(Comp1); RightTop.SetY(l);} else
299 if(DComp1<0) {LeftBot.SetY(f); RightTop.SetY(Comp1);};
300 }
301 }
302 }else
303 if(i==Up) {
304 if(Index==1) {LeftBot.SetX(Comp1); RightTop.SetX(BSplC->Knot(i));}else
305 if(Index==2) {LeftBot.SetY(Comp1); RightTop.SetY(BSplC->Knot(i)); }
306 }
307 }
308}
309
310
311//=======================================================================
312//function :Locate1Coord
313//purpose :
314//=======================================================================
315
316static void Locate1Coord(const Standard_Integer Index,
317 const gp_Pnt2d& UV,
318 const gp_Vec2d& DUV,
319 const Handle(Geom_BSplineSurface)& BSplS,
320 Standard_Boolean& DIsNull,
321 gp_Pnt2d& LeftBot,
322 gp_Pnt2d& RightTop)
323{
324 Standard_Real Comp1=0,DComp1=0;
325 Standard_Real Tol = Precision::PConfusion()/10;
326 Standard_Integer i=1, Up=0, Up1, Up2, Down=0, Down1, Down2, Bnd1, Bnd2;
327 Standard_Real cur=0, f, l;
328
329 DIsNull= Standard_False;
330
331 Up1 = BSplS->LastUKnotIndex();
332 Down1 = BSplS->FirstUKnotIndex();
333 Up2 = BSplS->LastVKnotIndex();
334 Down2 = BSplS->FirstVKnotIndex();
335
336
337 if(Index==1){ i = Down1; Comp1 = UV.X(); DComp1= DUV.X(); Up=Up1; Down=Down1;
338 while ( ( Abs(BSplS->UKnot(i)-Comp1)>Tol )&&(i!=Up1 ) ) i++;
339 cur = BSplS->UKnot(i);
340 } else
341 if(Index==2) { i = Down2; Comp1 = UV.Y(); DComp1=DUV.Y(); Up=Up2; Down=Down2;
342 while ( ( Abs(BSplS->VKnot(i)-Comp1)>Tol )&&(i!=Up2 ) ) i++;
343 cur = BSplS->VKnot(i);
344 }
345
346 if( Abs(Comp1-cur)<=Tol )
347 {
348 Bnd1 = Down; Bnd2 = Up;
349 if(Index==1) {
350 TColStd_Array1OfReal Arr1(1,BSplS->NbUKnots());
351 BSplS->UKnots(Arr1); // Up1=Arr1.Upper(); Down1=Arr1.Lower();
352 FindBounds(Arr1,cur,DUV.X(),Bnd1,Bnd2,DIsNull);
353 }
354 else if(Index==2) {
355 TColStd_Array1OfReal Arr2(1,BSplS->NbVKnots());
356 BSplS->VKnots(Arr2); // Up2=Arr2.Upper(); Down2=Arr2.Lower();
357 FindBounds(Arr2,cur,DUV.Y(),Bnd1,Bnd2,DIsNull);
358 }
359
360 ReverseParam(Bnd1,Bnd2,Bnd1,Bnd2);
361
362 if(DIsNull==Standard_False){
363 if(Index==1) {LeftBot.SetX(BSplS->UKnot(Bnd1));
364 RightTop.SetX(BSplS->UKnot(Bnd2));}
365 else
366 if(Index==2){ LeftBot.SetY(BSplS->VKnot(Bnd1));
367 RightTop.SetY(BSplS->VKnot(Bnd2));
368 }
369 }
370 }
371 else//*********if Coord != Knot
372 {
373 if( (Index==1)&&(Comp1 < BSplS->UKnot(Down)) )
374 { LeftBot.SetX(BSplS->UKnot(Down));
375 RightTop.SetX( BSplS->UKnot(Down + 1) );
376 return; }
377 else
378 if( (Index==2)&&(Comp1 < BSplS->VKnot(Down)) )
379 { LeftBot.SetY(BSplS->VKnot(Down));
380 RightTop.SetY( BSplS->VKnot(Down + 1) );
381 return; }
382 else
383 if( (Index==1)&&(Comp1 > BSplS->UKnot(Up)) )
384 { RightTop.SetX(BSplS->UKnot(Up - 1));
385 LeftBot.SetX( BSplS->UKnot(Up) );
386 return; }
387 else
388 if( (Index==2)&&(Comp1 > BSplS->VKnot(Up)) )
389 { RightTop.SetY(BSplS->VKnot(Up - 1));
390 LeftBot.SetY( BSplS->VKnot(Up) );
391 return; }
392 else
393 { i = Down;
394 if( (Index==1)&&(!(Comp1 < BSplS->UKnot(Down)))&&(!(Comp1 > BSplS->UKnot(Up))) )
395 while (!( ((f=BSplS->UKnot(i)) < Comp1)&&((l=BSplS->UKnot(i+1)) > Comp1)) && (i<Up)) i++;
396 else
397 if( (Index==2)&&(!(Comp1 < BSplS->VKnot(Down)))&&(!(Comp1 > BSplS->VKnot(Up))) )
398 while (!(((f=BSplS->VKnot(i)) < Comp1)&&((l=BSplS->VKnot(i+1)) > Comp1)) && (i<Up)) i++;
399 else
400 ReverseParam(f,l,f,l);
401
402 if(i!=Up){
403 if(Abs(DComp1)>Tol)
404 {if(Index==1) {
405 if(DComp1>0){ LeftBot.SetX(Comp1); RightTop.SetX(l);}else
406 if(DComp1<0){LeftBot.SetX(f); RightTop.SetX(Comp1);}
407 }else
408 if(Index==2) {
409 if(DComp1>0){ LeftBot.SetY(Comp1); RightTop.SetY(l);}else
410 if(DComp1<0){ LeftBot.SetY(f); RightTop.SetY(Comp1);}
411 }
412 }
413 else
414 {
415 if(Abs(DComp1)<Tol)
416 {if(Index==1){LeftBot.SetX(f); RightTop.SetX(l);} else
417 if(Index==2) { LeftBot.SetY(f); RightTop.SetY(l);}
418 }
419 }
420 }else
421 if(i==Up){if(Index==1){LeftBot.SetX(Comp1); RightTop.SetX(BSplS->UKnot(i));} else
422 if(Index==2) { LeftBot.SetY(Comp1); RightTop.SetY(BSplS->VKnot(i));}
423 }
424 }
425 }
426}
427//=======================================================================
428//function :Locate2Coord
429//purpose : along non-BSpline curve
430//=======================================================================
431
432
433static void Locate2Coord(const Standard_Integer Index,
434 const gp_Pnt2d& UV, const gp_Vec2d& DUV,
435 const Standard_Real I1,
436 const Standard_Real I2,
437 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop)
438{
439 Standard_Real Tol=Precision::PConfusion()/10;
440 Standard_Real Comp1=0,DComp1=0;
441 Standard_Boolean DIsNull = Standard_False;
442 if(Index==1) { Comp1=UV.X();
443 DComp1=DUV.X();}
444 else
445 if(Index==2) {Comp1=UV.Y();
446 DComp1=DUV.Y();}
447
448 if((Comp1!=I1)&&(Comp1!=I2))
449 { if(Abs(DComp1) > Tol)
450 { if(DComp1 < 0)
451 { if(Index==1) { LeftBot.SetX(I1);
452 RightTop.SetX(Comp1);}
453 if(Index==2) { LeftBot.SetY(I1);
454 RightTop.SetY(Comp1);}
455 }
456 else
457 if(DComp1 > 0)
458 { if(Index==1) { LeftBot.SetX(Comp1);
459 RightTop.SetX(I2);}
460 if(Index==2) { LeftBot.SetY(Comp1);
461 RightTop.SetY(I2);}
462 }
463 else { if(Index==1) { LeftBot.SetX(I1);
464 RightTop.SetX(I2);}
465 if(Index==2) { LeftBot.SetY(I1);
466 RightTop.SetY(I2);}
467 }
468 DIsNull=Standard_False;
469 }
470 else
471 if(Abs(DComp1)<=Tol) { DIsNull = Standard_True;
472 if(Index==1) { LeftBot.SetX(I1) ;
473 RightTop.SetX(I2);}
474 if(Index==2) { LeftBot.SetY(I1) ;
475 RightTop.SetY(I2);}
476 }
477 }else
478 if(Abs(Comp1-I1)<Tol)
479 { if(Index==1) { LeftBot.SetX(I1) ;
480 RightTop.SetX(I2);}
481 if(Index==2) { LeftBot.SetY(I1) ;
482 RightTop.SetY(I2);}
483 }
484 else
485 if(Abs(Comp1-I2)<Tol)
486 { if(Index==1) { LeftBot.SetX(I1);
487 RightTop.SetX(I2);}
488 if(Index==2) { LeftBot.SetY(I1);
489 RightTop.SetY(I2);}
490 }
491}
492
493//=======================================================================
494//function :Locate2Coord
495//purpose :
496//=======================================================================
497
498static void Locate2Coord(const Standard_Integer Index,
499 const gp_Pnt2d& UV, const gp_Vec2d& DUV,
500 const Handle(Geom_BSplineSurface)& BSplS,
501 const TColStd_Array1OfReal& Arr,
502 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop)
503{
504 Standard_Real Comp=0,DComp=0,Tmp1,Tmp2;
505 Standard_Real Tol=Precision::PConfusion()/10;
506 Standard_Integer N, NUp=0, NLo=0;
507 if(Index==1)
508 { Comp=UV.X();
509 DComp=DUV.Y();
510 NUp = BSplS->LastUKnotIndex();
511 NLo = BSplS->FirstUKnotIndex();
512 }
513 if(Index==2)
514 { Comp=UV.Y();
515 DComp=DUV.X();
516 NUp = BSplS->LastVKnotIndex();
517 NLo = BSplS->FirstVKnotIndex();
518 }
519
520 if((DComp > 0)&&(Abs(DComp)>Tol)) {
521 Hunt(Arr,Comp,N);
522 if (N >= NUp){
523 //limit case: Hunt() cought upper knot. Take the last span.
524 N = NUp - 1;
525 }
526 if(Index==1) { Tmp1=BSplS->UKnot(N);
527 Tmp2=BSplS->UKnot(N+1);}
528 else
529 if(Index==2) { Tmp1=BSplS->VKnot(N);
530 Tmp2=BSplS->VKnot(N+1);}
531
532 ReverseParam(Tmp1,Tmp2,Tmp1,Tmp2);
533
534 if(Index==1) { LeftBot.SetX(Tmp1);
535 RightTop.SetX(Tmp2);}
536 else
537 if(Index==2) { LeftBot.SetY(Tmp1);
538 RightTop.SetY(Tmp2);}
539 }
540 else
541 if((DComp < 0)&&(Abs(DComp)>Tol)){
542 Hunt(Arr,Comp,N);
543 if (N <= NLo) {
544 //limit case: Hunt() cought lower knot. Take the first span.
545 N = NLo + 1;
546 }
547 if(Index==1) { Tmp1=BSplS->UKnot(N-1);
548 Tmp2=BSplS->UKnot(N);}
549 else
550 if(Index==2) { Tmp1=BSplS->VKnot(N-1);
551 Tmp2=BSplS->VKnot(N);}
552
553 ReverseParam(Tmp1,Tmp2,Tmp1,Tmp2);
554
555 if(Index==1) { LeftBot.SetX(Tmp1);
556 RightTop.SetX(Tmp2);}
557 else
558 if(Index==2) { LeftBot.SetY(Tmp1);
559 RightTop.SetY(Tmp2);}
560 }
561}
562
563
564
565//=======================================================================
566//function : Adaptor3d_CurveOnSurface
567//purpose :
568//=======================================================================
569
570Adaptor3d_CurveOnSurface::Adaptor3d_CurveOnSurface()
571 : myType(GeomAbs_OtherCurve), myIntCont(GeomAbs_CN)
572{}
573
574//=======================================================================
575//function : Adaptor3d_CurveOnSurface
576//purpose :
577//=======================================================================
578
579Adaptor3d_CurveOnSurface::Adaptor3d_CurveOnSurface
580(const Handle(Adaptor3d_HSurface)& S)
581 : myType(GeomAbs_OtherCurve), myIntCont(GeomAbs_CN)
582{
583 Load(S);
584}
585
586//=======================================================================
587//function : Adaptor3d_CurveOnSurface
588//purpose :
589//=======================================================================
590
591Adaptor3d_CurveOnSurface::Adaptor3d_CurveOnSurface
592(const Handle(Adaptor2d_HCurve2d)& C,
593 const Handle(Adaptor3d_HSurface)& S)
594 : myType(GeomAbs_OtherCurve), myIntCont(GeomAbs_CN)
595{
596 Load(S);
597 Load(C);
598}
599
600//=======================================================================
601//function : Load
602//purpose :
603//=======================================================================
604
605void Adaptor3d_CurveOnSurface::Load(const Handle(Adaptor3d_HSurface)& S)
606{
607 mySurface = S;
608 if (!myCurve.IsNull()) EvalKPart();
609}
610
611//=======================================================================
612//function : Load
613//purpose :
614//=======================================================================
615
616void Adaptor3d_CurveOnSurface::Load(const Handle(Adaptor2d_HCurve2d)& C)
617{
618 myCurve = C;
619 if (!mySurface.IsNull())
620 {
621 EvalKPart();
622 GeomAbs_SurfaceType SType ;
623 SType = mySurface->GetType();
624 if( SType == GeomAbs_BSplineSurface)
625 EvalFirstLastSurf();
626 if( SType == GeomAbs_SurfaceOfExtrusion)
627 EvalFirstLastSurf();
628 if( SType == GeomAbs_SurfaceOfRevolution)
629 EvalFirstLastSurf();
630 if( SType == GeomAbs_OffsetSurface) {
631 SType = mySurface->BasisSurface()->GetType();
632 if( SType == GeomAbs_SurfaceOfRevolution ||
633 SType == GeomAbs_SurfaceOfExtrusion ||
634 SType == GeomAbs_BSplineSurface )
635 EvalFirstLastSurf();
636 }
637 }
638}
639
640//=======================================================================
641//function : FirstParameter
642//purpose :
643//=======================================================================
644
645Standard_Real Adaptor3d_CurveOnSurface::FirstParameter() const
646{
647 return myCurve->FirstParameter();
648}
649
650//=======================================================================
651//function : LastParameter
652//purpose :
653//=======================================================================
654
655Standard_Real Adaptor3d_CurveOnSurface::LastParameter() const
656{
657 return myCurve->LastParameter();
658}
659
660//=======================================================================
661//function : Continuity
662//purpose :
663//=======================================================================
664
665GeomAbs_Shape Adaptor3d_CurveOnSurface::Continuity() const
666{
667 GeomAbs_Shape ContC = myCurve->Continuity();
668 GeomAbs_Shape ContSu = mySurface->UContinuity();
669 if ( ContSu < ContC) ContC = ContSu;
670 GeomAbs_Shape ContSv = mySurface->VContinuity();
671 if ( ContSv < ContC) ContC = ContSv;
672
673 return ContC;
674}
675
676//=======================================================================
677//function : NbIntervals
678//purpose :
679//=======================================================================
680
681Standard_Integer Adaptor3d_CurveOnSurface::NbIntervals
682(const GeomAbs_Shape S)
683{
684 if(S == myIntCont && !myIntervals.IsNull())
685 return myIntervals->Length()-1;
686
687 Standard_Integer nu,nv,nc,i;
688 nu=mySurface->NbUIntervals(S);
689 nv=mySurface->NbVIntervals(S);
690 Handle(TColStd_HSetOfReal) tmpIntervals = new TColStd_HSetOfReal;
691 TColStd_SetIteratorOfSetOfReal It;
692 TColStd_Array1OfReal TabU(1,nu+1);
693 TColStd_Array1OfReal TabV(1,nv+1);
694 Standard_Integer NbSample = 20;
695 Standard_Real U,V,Tdeb,Tfin;
696 Tdeb=myCurve->FirstParameter();
697 Tfin=myCurve->LastParameter();
698 nc=myCurve->NbIntervals(S);
699 TColStd_Array1OfReal TabC(1,nc+1);
700 myCurve->Intervals(TabC,S);
701 Standard_Real Tol= Precision::PConfusion()/10;
702 for (i=1;i<=nc+1;i++)
703 {tmpIntervals->Add(TabC(i));}
704
705 Standard_Integer nbpoint=nc+1;
706 if (nu>1)
707 { mySurface->UIntervals(TabU,S);
708 for(Standard_Integer iu = 2;iu <= nu; iu++)
709 { U = TabU.Value(iu);
710 Adaptor3d_InterFunc Func(myCurve,U,1);
711 math_FunctionRoots Resol(Func,Tdeb,Tfin,NbSample,Tol,Tol,Tol,0.);
712 if (Resol.IsDone())
713 { if (!Resol.IsAllNull())
714 { Standard_Integer nsol=Resol.NbSolutions();
715 for ( i=1;i<=nsol;i++)
716 { Standard_Real param =Resol.Value(i);
717 { Standard_Boolean insere=Standard_True;
718 for (It.Initialize(tmpIntervals->Set());It.More();It.Next())
719 { if (Abs(param- It.Value())<=Tol)
720 insere=Standard_False;}
721 if (insere)
722 {nbpoint++;
723 tmpIntervals->Add(param);}
724 }
725 }
726 }
727 }
728 }
729 }
730 if (nv>1)
731
732 { mySurface->VIntervals(TabV,S);
733 for(Standard_Integer iv = 2;iv <= nv; iv++)
734 { V = TabV.Value(iv);
735 Adaptor3d_InterFunc Func(myCurve,V,2);
736 math_FunctionRoots Resol(Func,Tdeb,Tfin,NbSample,Tol,Tol,Tol,0.);
737 if (Resol.IsDone())
738 { if (!Resol.IsAllNull())
739 { Standard_Integer nsol=Resol.NbSolutions();
740 for ( i=1;i<=nsol;i++)
741 { Standard_Real param =Resol.Value(i);
742 { Standard_Boolean insere=Standard_True;
743 for (It.Initialize(tmpIntervals->Set());It.More();It.Next())
744 { if (Abs(param- It.Value())<=Tol)
745 insere=Standard_False;}
746 if (insere)
747 {nbpoint++;
748 tmpIntervals->Add(param);}
749 }
750 }
751 }
752 }
753 }
754 }
755
756 // for case intervals==1 and first point == last point SetOfReal
757 // contains only one value, therefore it is necessary to add second
758 // value into myIntervals which will be equal first value.
759 myIntervals = new TColStd_HArray1OfReal(1,nbpoint);
760 i=0;
761 for (It.Initialize(tmpIntervals->Set());It.More();It.Next(),i)
762 { i++;
763 myIntervals->SetValue(i,It.Value());
764 }
765 if( i==1 )
766 myIntervals->SetValue(2,myIntervals->Value(1));
767
768 myIntCont = S;
769 return nbpoint-1;
770}
771
772//=======================================================================
773//function : Intervals
774//purpose :
775//=======================================================================
776
777void Adaptor3d_CurveOnSurface::Intervals(TColStd_Array1OfReal& T,
778 const GeomAbs_Shape S)
779{
780 NbIntervals(S);
781 for(Standard_Integer i=1; i<=myIntervals->Length(); i++) {
782 T(i) = myIntervals->Value(i);
783 }
784 TCollection_CompareOfReal comp;
785 SortTools_StraightInsertionSortOfReal::Sort(T,comp);
786}
787
788//=======================================================================
789//function : Trim
790//purpose :
791//=======================================================================
792
793Handle(Adaptor3d_HCurve) Adaptor3d_CurveOnSurface::Trim
794(const Standard_Real First,
795 const Standard_Real Last,
796 const Standard_Real Tol) const
797{
798 Handle(Adaptor3d_HCurveOnSurface) HCS = new Adaptor3d_HCurveOnSurface();
799 HCS->ChangeCurve().Load(mySurface);
800 HCS->ChangeCurve().Load(myCurve->Trim(First,Last,Tol));
801 return HCS;
802}
803
804//=======================================================================
805//function : IsClosed
806//purpose :
807//=======================================================================
808
809Standard_Boolean Adaptor3d_CurveOnSurface::IsClosed() const
810{
811 return myCurve->IsClosed();
812}
813
814//=======================================================================
815//function : IsPeriodic
816//purpose :
817//=======================================================================
818
819Standard_Boolean Adaptor3d_CurveOnSurface::IsPeriodic() const
820{
821 return myCurve->IsPeriodic();
822}
823
824//=======================================================================
825//function : Period
826//purpose :
827//=======================================================================
828
829Standard_Real Adaptor3d_CurveOnSurface::Period() const
830{
831 return myCurve->Period();
832}
833
834//=======================================================================
835//function : Value
836//purpose :
837//=======================================================================
838
839gp_Pnt Adaptor3d_CurveOnSurface::Value(const Standard_Real U ) const
840{
841 gp_Pnt P;
842 gp_Pnt2d Puv;
843
844 if (myType == GeomAbs_Line ) P = ElCLib::Value(U,myLin );
845 else if (myType == GeomAbs_Circle) P = ElCLib::Value(U,myCirc);
846 else {
847 myCurve->D0(U,Puv);
848 mySurface->D0(Puv.X(),Puv.Y(),P);
849 }
850
851 return P;
852}
853
854//=======================================================================
855//function : D0
856//purpose :
857//=======================================================================
858
859void Adaptor3d_CurveOnSurface::D0(const Standard_Real U ,
860 gp_Pnt& P) const
861{
862 gp_Pnt2d Puv;
863
864 if (myType == GeomAbs_Line ) P = ElCLib::Value(U,myLin );
865 else if (myType == GeomAbs_Circle) P = ElCLib::Value(U,myCirc);
866 else {
867 myCurve->D0(U,Puv);
868 mySurface->D0(Puv.X(),Puv.Y(),P);
869 }
870
871}
872
873
874//=======================================================================
875//function : D1
876//purpose :
877//=======================================================================
878
879void Adaptor3d_CurveOnSurface::D1(const Standard_Real U ,
880 gp_Pnt& P,
881 gp_Vec& V) const
882{
883 gp_Pnt2d Puv;
884 gp_Vec2d Duv;
885 gp_Vec D1U,D1V;
886
887 Standard_Real FP = myCurve->FirstParameter();
888 Standard_Real LP = myCurve->LastParameter();
889
890 Standard_Real Tol= Precision::PConfusion()/10;
891 if( ( Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
892 {
893 myCurve->D1(U,Puv,Duv);
894 myFirstSurf->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
895 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
896 }
897 else
898 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
899 {
900 myCurve->D1(U,Puv,Duv);
901 myLastSurf->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
902 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
903 }
904 else
905 if (myType == GeomAbs_Line ) ElCLib::D1(U,myLin ,P,V);
906 else if (myType == GeomAbs_Circle) ElCLib::D1(U,myCirc,P,V);
907 else {
908 myCurve->D1(U,Puv,Duv);
909 mySurface->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
910 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
911 }
912}
913//=======================================================================
914//function : D2
915//purpose :
916//=======================================================================
917
918void Adaptor3d_CurveOnSurface::D2(const Standard_Real U,
919 gp_Pnt& P,
920 gp_Vec& V1,
921 gp_Vec& V2) const
922{
923 gp_Pnt2d UV;
924 gp_Vec2d DW,D2W;
925 gp_Vec D1U,D1V,D2U,D2V,D2UV;
926
927 Standard_Real FP = myCurve->FirstParameter();
928 Standard_Real LP = myCurve->LastParameter();
929
930 Standard_Real Tol= Precision::PConfusion()/10;
931 if( (Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
932 {
933 myCurve->D2(U,UV,DW,D2W);
934 myFirstSurf->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
935
936 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
937 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
938 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
939 }
940 else
941 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
942 {
943 myCurve->D2(U,UV,DW,D2W);
944 myLastSurf->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
945
946 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
947 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
948 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
949 }
950 else
951 if (myType == GeomAbs_Line ) {
952 ElCLib::D1(U,myLin,P,V1);
953 V2.SetCoord(0.,0.,0.);
954 }
955 else if (myType == GeomAbs_Circle) ElCLib::D2(U,myCirc,P,V1,V2);
956 else {
957 myCurve->D2(U,UV,DW,D2W);
958 mySurface->D2(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV);
959
960 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
961 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
962 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
963 }
964}
965
966//=======================================================================
967//function : D3
968//purpose :
969//=======================================================================
970
971void Adaptor3d_CurveOnSurface::D3
972 (const Standard_Real U,
973 gp_Pnt& P,
974 gp_Vec& V1,
975 gp_Vec& V2,
976 gp_Vec& V3) const
977{
978
979 Standard_Real Tol= Precision::PConfusion()/10;
980 gp_Pnt2d UV;
981 gp_Vec2d DW,D2W,D3W;
982 gp_Vec D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV;
983
984 Standard_Real FP = myCurve->FirstParameter();
985 Standard_Real LP = myCurve->LastParameter();
986
987 if( (Abs(U-FP)<Tol)&&(!myFirstSurf.IsNull()) )
988 { myCurve->D3(U,UV,DW,D2W,D3W);
989 myFirstSurf->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
990 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
991 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
992 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
993 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
994 }else
995
996 if( (Abs(U-LP)<Tol)&&(!myLastSurf.IsNull()) )
997 { myCurve->D3(U,UV,DW,D2W,D3W);
998 myLastSurf->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
999 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1000
1001 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1002 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1003 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1004 }
1005 else
1006 if (myType == GeomAbs_Line ) {
1007 ElCLib::D1(U,myLin,P,V1);
1008 V2.SetCoord(0.,0.,0.);
1009 V3.SetCoord(0.,0.,0.);
1010 }
1011 else if (myType == GeomAbs_Circle) ElCLib::D3(U,myCirc,P,V1,V2,V3);
1012 else {
1013 myCurve->D3(U,UV,DW,D2W,D3W);
1014 mySurface->D3(UV.X(),UV.Y(),P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
1015 V1.SetLinearForm(DW.X(),D1U,DW.Y(),D1V);
1016
1017 V2.SetLinearForm(D2W.X(), D1U, D2W.Y(), D1V, 2.*DW.X()*DW.Y(),D2UV);
1018 V2.SetLinearForm(DW.X()*DW.X(), D2U, DW.Y()*DW.Y(), D2V, V2);
1019 V3=SetLinearForm( DW, D2W, D3W, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
1020 }
1021}
1022
1023
1024//=======================================================================
1025//function : DN
1026//purpose :
1027//=======================================================================
1028
1029gp_Vec Adaptor3d_CurveOnSurface::DN
1030 (const Standard_Real U,
1031 const Standard_Integer N) const
1032{
1033 gp_Pnt P;
1034 gp_Vec V1, V2, V;
1035 switch (N) {
1036 case 1:
1037 D1(U,P,V);
1038 break ;
1039 case 2:
1040 D2(U,P,V1,V);
1041 break ;
1042 case 3:
1043 D3(U,P,V1,V2,V);
1044 break ;
1045 default:
1046 Standard_NotImplemented::Raise("Adaptor3d_CurveOnSurface:DN");
1047 break;
1048 }
1049 return V;
1050}
1051
1052
1053//=======================================================================
1054//function : Resolution
1055//purpose :
1056//=======================================================================
1057
1058Standard_Real Adaptor3d_CurveOnSurface::Resolution
1059 (const Standard_Real R3d) const
1060{
1061 Standard_Real ru,rv;
1062 ru = mySurface->UResolution(R3d);
1063 rv = mySurface->VResolution(R3d);
1064 return myCurve->Resolution(Min(ru,rv));
1065}
1066
1067
1068//=======================================================================
1069//function : GetType
1070//purpose :
1071//=======================================================================
1072
1073GeomAbs_CurveType Adaptor3d_CurveOnSurface::GetType() const
1074{
1075 return myType;
1076}
1077
1078
1079//=======================================================================
1080//function : Line
1081//purpose :
1082//=======================================================================
1083
1084gp_Lin Adaptor3d_CurveOnSurface::Line() const
1085{
1086 Standard_NoSuchObject_Raise_if(myType != GeomAbs_Line, "Adaptor3d_CurveOnSurface::Line(): curve is not a line")
1087 return myLin;
1088}
1089
1090//=======================================================================
1091//function : Circle
1092//purpose :
1093//=======================================================================
1094
1095gp_Circ Adaptor3d_CurveOnSurface::Circle() const
1096{
1097 Standard_NoSuchObject_Raise_if(myType != GeomAbs_Circle, "Adaptor3d_CurveOnSurface::Line(): curve is not a circle")
1098 return myCirc;
1099}
1100
1101//=======================================================================
1102//function : Ellipse
1103//purpose :
1104//=======================================================================
1105
1106gp_Elips Adaptor3d_CurveOnSurface::Ellipse() const
1107{
1108 return to3d(mySurface->Plane(),myCurve->Ellipse());
1109}
1110
1111//=======================================================================
1112//function : Hyperbola
1113//purpose :
1114//=======================================================================
1115
1116gp_Hypr Adaptor3d_CurveOnSurface::Hyperbola() const
1117{
1118 return to3d(mySurface->Plane(),myCurve->Hyperbola());
1119}
1120
1121//=======================================================================
1122//function : Parabola
1123//purpose :
1124//=======================================================================
1125
1126gp_Parab Adaptor3d_CurveOnSurface::Parabola() const
1127{
1128 return to3d(mySurface->Plane(),myCurve->Parabola());
1129}
1130
1131Standard_Integer Adaptor3d_CurveOnSurface::Degree() const
1132{
1133
1134 // on a parametric surface should multiply
1135 // return TheCurve2dTool::Degree(myCurve);
1136
1137 return myCurve->Degree();
1138}
1139
1140//=======================================================================
1141//function : IsRational
1142//purpose :
1143//=======================================================================
1144
1145Standard_Boolean Adaptor3d_CurveOnSurface::IsRational() const
1146{
1147 return ( myCurve->IsRational() ||
1148 mySurface->IsURational() ||
1149 mySurface->IsVRational() );
1150}
1151
1152//=======================================================================
1153//function : NbPoles
1154//purpose :
1155//=======================================================================
1156
1157Standard_Integer Adaptor3d_CurveOnSurface::NbPoles() const
1158{
1159 // on a parametric surface should multiply
1160 return myCurve->NbPoles();
1161}
1162
1163//=======================================================================
1164//function : NbKnots
1165//purpose :
1166//=======================================================================
1167
1168Standard_Integer Adaptor3d_CurveOnSurface::NbKnots() const {
1169 if (mySurface->GetType()==GeomAbs_Plane)
1170 return myCurve->NbKnots();
1171 else {
1172 Standard_NoSuchObject::Raise();
1173 return 0;
1174 }
1175}
1176
1177//=======================================================================
1178//function : Bezier
1179//purpose :
1180//=======================================================================
1181
1182Handle(Geom_BezierCurve) Adaptor3d_CurveOnSurface::Bezier() const
1183{
1184 Standard_NoSuchObject_Raise_if
1185 ( mySurface->GetType() != GeomAbs_Plane,
1186 "Adaptor3d_CurveOnSurface : Bezier");
1187
1188 Handle(Geom2d_BezierCurve) Bez2d = myCurve->Bezier();
1189 Standard_Integer NbPoles = Bez2d->NbPoles();
1190
1191 const gp_Pln& Plane = mySurface->Plane();
1192
1193 TColgp_Array1OfPnt Poles(1,NbPoles);
1194 for ( Standard_Integer i=1; i<= NbPoles; i++) {
1195 Poles(i) = to3d( Plane, Bez2d->Pole(i));
1196 }
1197 Handle(Geom_BezierCurve) Bez;
1198
1199 if (Bez2d->IsRational()) {
1200 TColStd_Array1OfReal Weights(1,NbPoles);
1201 Bez2d->Weights(Weights);
1202 Bez = new Geom_BezierCurve(Poles,Weights);
1203 }
1204 else {
1205 Bez = new Geom_BezierCurve(Poles);
1206 }
1207 return Bez;
1208}
1209
1210//=======================================================================
1211//function : BSpline
1212//purpose :
1213//=======================================================================
1214
1215Handle(Geom_BSplineCurve) Adaptor3d_CurveOnSurface::BSpline() const
1216{
1217 Standard_NoSuchObject_Raise_if
1218 ( mySurface->GetType() != GeomAbs_Plane,
1219 "Adaptor3d_CurveOnSurface : BSpline");
1220
1221 Handle(Geom2d_BSplineCurve) Bsp2d = myCurve->BSpline();
1222 Standard_Integer NbPoles = Bsp2d->NbPoles();
1223
1224 const gp_Pln& Plane = mySurface->Plane();
1225
1226 TColgp_Array1OfPnt Poles(1,NbPoles);
1227 for ( Standard_Integer i=1; i<= NbPoles; i++) {
1228 Poles(i) = to3d( Plane, Bsp2d->Pole(i));
1229 }
1230
1231 TColStd_Array1OfReal Knots(1,Bsp2d->NbKnots());
1232 TColStd_Array1OfInteger Mults(1,Bsp2d->NbKnots());
1233 Bsp2d->Knots(Knots);
1234 Bsp2d->Multiplicities(Mults);
1235
1236 Handle(Geom_BSplineCurve) Bsp;
1237
1238 if (Bsp2d->IsRational()) {
1239 TColStd_Array1OfReal Weights(1,NbPoles);
1240 Bsp2d->Weights(Weights);
1241 Bsp = new Geom_BSplineCurve(Poles,Weights,Knots,Mults,
1242 Bsp2d->Degree(),
1243 Bsp2d->IsPeriodic());
1244 }
1245 else {
1246 Bsp = new Geom_BSplineCurve(Poles,Knots,Mults,
1247 Bsp2d->Degree(),
1248 Bsp2d->IsPeriodic());
1249 }
1250 return Bsp;
1251}
1252
1253//=======================================================================
1254//function : GetCurve
1255//purpose :
1256//=======================================================================
1257
1258const Handle(Adaptor2d_HCurve2d)& Adaptor3d_CurveOnSurface::GetCurve() const
1259{
1260 return myCurve;
1261}
1262
1263//=======================================================================
1264//function : GetSurface
1265//purpose :
1266//=======================================================================
1267
1268const Handle(Adaptor3d_HSurface)& Adaptor3d_CurveOnSurface::GetSurface() const
1269{
1270 return mySurface;
1271}
1272
1273//=======================================================================
1274//function : ChangeCurve
1275//purpose :
1276//=======================================================================
1277
1278Handle(Adaptor2d_HCurve2d)& Adaptor3d_CurveOnSurface::ChangeCurve()
1279{
1280 return myCurve;
1281}
1282
1283//=======================================================================
1284//function : ChangeSurface
1285//purpose :
1286//=======================================================================
1287
1288Handle(Adaptor3d_HSurface)& Adaptor3d_CurveOnSurface::ChangeSurface() {
1289 return mySurface;
1290}
1291
1292//=======================================================================
1293//function : EvalKPart
1294//purpose :
1295//=======================================================================
1296
1297void Adaptor3d_CurveOnSurface::EvalKPart()
1298{
1299 myType = GeomAbs_OtherCurve;
1300
1301 GeomAbs_SurfaceType STy = mySurface->GetType();
1302 GeomAbs_CurveType CTy = myCurve->GetType();
1303 if (STy == GeomAbs_Plane) {
1304 myType = CTy;
1305 if (myType == GeomAbs_Circle)
1306 myCirc = to3d(mySurface->Plane(),myCurve->Circle());
1307 else if (myType == GeomAbs_Line) {
1308 gp_Pnt P;
1309 gp_Vec V;
1310 gp_Pnt2d Puv;
1311 gp_Vec2d Duv;
1312 myCurve->D1(0.,Puv,Duv);
1313 gp_Vec D1U,D1V;
1314 mySurface->D1(Puv.X(),Puv.Y(),P,D1U,D1V);
1315 V.SetLinearForm(Duv.X(),D1U,Duv.Y(),D1V);
1316 myLin = gp_Lin(P,V);
1317 }
1318 }
1319 else {
1320 if ( CTy == GeomAbs_Line) {
1321 gp_Dir2d D = myCurve->Line().Direction();
1322 if ( D.IsParallel(gp::DX2d(),Precision::Angular())) { // Iso V.
1323 if ( STy == GeomAbs_Sphere) {
1324 gp_Pnt2d P = myCurve->Line().Location();
1325 if ( Abs( Abs(P.Y()) -PI/2. ) >= Precision::PConfusion()) {
1326 myType = GeomAbs_Circle;
1327 gp_Sphere Sph = mySurface->Sphere();
1328 gp_Ax3 Axis = Sph.Position();
1329 myCirc = ElSLib::SphereVIso(Axis,
1330 Sph.Radius(),
1331 P.Y());
1332 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1333 gp_Ax1 AxeRev(Axis.Location(), DRev);
1334 myCirc.Rotate(AxeRev, P.X());
1335 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1336 gp_Ax2 Ax = myCirc.Position();
1337 Ax.SetDirection(Ax.Direction().Reversed());
1338 myCirc.SetPosition(Ax);
1339 }
1340 }
1341 }
1342 else if ( STy == GeomAbs_Cylinder) {
1343 myType = GeomAbs_Circle;
1344 gp_Cylinder Cyl = mySurface->Cylinder();
1345 gp_Pnt2d P = myCurve->Line().Location();
1346 gp_Ax3 Axis = Cyl.Position();
1347 myCirc = ElSLib::CylinderVIso(Axis,
1348 Cyl.Radius(),
1349 P.Y());
1350 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1351 gp_Ax1 AxeRev(Axis.Location(), DRev);
1352 myCirc.Rotate(AxeRev, P.X());
1353 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1354 gp_Ax2 Ax = myCirc.Position();
1355 Ax.SetDirection(Ax.Direction().Reversed());
1356 myCirc.SetPosition(Ax);
1357 }
1358 }
1359 else if ( STy == GeomAbs_Cone) {
1360 myType = GeomAbs_Circle;
1361 gp_Cone Cone = mySurface->Cone();
1362 gp_Pnt2d P = myCurve->Line().Location();
1363 gp_Ax3 Axis = Cone.Position();
1364 myCirc = ElSLib::ConeVIso(Axis,
1365 Cone.RefRadius(),
1366 Cone.SemiAngle(),
1367 P.Y());
1368 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1369 gp_Ax1 AxeRev(Axis.Location(), DRev);
1370 myCirc.Rotate(AxeRev, P.X());
1371 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1372 gp_Ax2 Ax = myCirc.Position();
1373 Ax.SetDirection(Ax.Direction().Reversed());
1374 myCirc.SetPosition(Ax);
1375 }
1376 }
1377 else if ( STy == GeomAbs_Torus) {
1378 myType = GeomAbs_Circle;
1379 gp_Torus Tore = mySurface->Torus();
1380 gp_Pnt2d P = myCurve->Line().Location();
1381 gp_Ax3 Axis = Tore.Position();
1382 myCirc = ElSLib::TorusVIso(Axis,
1383 Tore.MajorRadius(),
1384 Tore.MinorRadius(),
1385 P.Y());
1386 gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection());
1387 gp_Ax1 AxeRev(Axis.Location(), DRev);
1388 myCirc.Rotate(AxeRev, P.X());
1389 if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) {
1390 gp_Ax2 Ax = myCirc.Position();
1391 Ax.SetDirection(Ax.Direction().Reversed());
1392 myCirc.SetPosition(Ax);
1393 }
1394 }
1395 }
1396 else if ( D.IsParallel(gp::DY2d(),Precision::Angular())) { // Iso U.
1397 if ( STy == GeomAbs_Sphere) {
1398 myType = GeomAbs_Circle;
1399 gp_Sphere Sph = mySurface->Sphere();
1400 gp_Pnt2d P = myCurve->Line().Location();
1401 gp_Ax3 Axis = Sph.Position();
1402 // calcul de l'iso 0.
1403 myCirc = ElSLib::SphereUIso(Axis, Sph.Radius(),0.);
1404
1405 // mise a sameparameter (rotation du cercle - decalage du Y)
1406 gp_Dir DRev = Axis.XDirection().Crossed(Axis. Direction());
1407 gp_Ax1 AxeRev(Axis.Location(),DRev);
1408 myCirc.Rotate(AxeRev, P.Y());
1409
1410 // transformation en iso U ( = P.X())
1411 DRev = Axis.XDirection().Crossed(Axis.YDirection());
1412 AxeRev = gp_Ax1(Axis.Location(), DRev);
1413 myCirc.Rotate(AxeRev, P.X());
1414
1415 if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) {
1416 gp_Ax2 Ax = myCirc.Position();
1417 Ax.SetDirection(Ax.Direction().Reversed());
1418 myCirc.SetPosition(Ax);
1419 }
1420 }
1421 else if ( STy == GeomAbs_Cylinder) {
1422 myType = GeomAbs_Line;
1423 gp_Cylinder Cyl = mySurface->Cylinder();
1424 gp_Pnt2d P = myCurve->Line().Location();
1425 myLin = ElSLib::CylinderUIso(Cyl.Position(),
1426 Cyl.Radius(),
1427 P.X());
1428 gp_Vec Tr(myLin.Direction());
1429 Tr.Multiply(P.Y());
1430 myLin.Translate(Tr);
1431 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
1432 myLin.Reverse();
1433 }
1434 else if ( STy == GeomAbs_Cone) {
1435 myType = GeomAbs_Line;
1436 gp_Cone Cone = mySurface->Cone();
1437 gp_Pnt2d P = myCurve->Line().Location();
1438 myLin = ElSLib::ConeUIso(Cone.Position(),
1439 Cone.RefRadius(),
1440 Cone.SemiAngle(),
1441 P.X());
1442 gp_Vec Tr(myLin.Direction());
1443 Tr.Multiply(P.Y());
1444 myLin.Translate(Tr);
1445 if ( D.IsOpposite(gp::DY2d(),Precision::Angular()))
1446 myLin.Reverse();
1447 }
1448 else if ( STy == GeomAbs_Torus) {
1449 myType = GeomAbs_Circle;
1450 gp_Torus Tore = mySurface->Torus();
1451 gp_Pnt2d P = myCurve->Line().Location();
1452 gp_Ax3 Axis = Tore.Position();
1453 myCirc = ElSLib::TorusUIso(Axis,
1454 Tore.MajorRadius(),
1455 Tore.MinorRadius(),
1456 P.X());
1457 myCirc.Rotate(myCirc.Axis(),P.Y());
1458
1459 if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) {
1460 gp_Ax2 Ax = myCirc.Position();
1461 Ax.SetDirection(Ax.Direction().Reversed());
1462 myCirc.SetPosition(Ax);
1463 }
1464 }
1465 }
1466 }
1467 }
1468}
1469//=======================================================================
1470//function :EvalFirstLastSurf
1471//purpose :
1472//=======================================================================
1473
1474void Adaptor3d_CurveOnSurface::EvalFirstLastSurf()
1475{
1476 Standard_Real FirstPar,LastPar;
1477 gp_Pnt2d UV, LeftBot, RightTop;
1478 gp_Vec2d DUV;
1479 Standard_Real Tol= Precision::PConfusion()/10;
1480 Standard_Boolean Ok = Standard_True;
1481
1482
1483 FirstPar=myCurve->FirstParameter();
1484 myCurve->D1(FirstPar,UV,DUV);
1485
1486 if(DUV.Magnitude() <= Tol) Ok = Standard_False;
1487
1488 if(Ok) {
1489
1490 switch(mySurface->GetType()) {
1491 case GeomAbs_BSplineSurface :
1492 LocatePart(UV,DUV,mySurface,LeftBot,RightTop);
1493 break;
1494 case GeomAbs_SurfaceOfRevolution :
1495 case GeomAbs_SurfaceOfExtrusion :
1496 Ok = LocatePart_RevExt(UV,DUV,mySurface,LeftBot,RightTop);
1497 break;
1498 case GeomAbs_OffsetSurface :
1499 Ok = LocatePart_Offset(UV,DUV,mySurface,LeftBot,RightTop);
1500 break;
1501 default :
1502 Standard_NotImplemented::Raise("Adaptor3d_CurveOnSurface::EvalFirstLastSurf");
1503 break;
1504 }
1505 }
1506
1507 if (Ok) {
1508
1509 CompareBounds(LeftBot,RightTop); //SVV
1510
1511 myFirstSurf = mySurface->UTrim(LeftBot.X(),RightTop.X(),Tol);
1512 myFirstSurf = myFirstSurf->VTrim(LeftBot.Y(),RightTop.Y(),Tol);
1513
1514 }
1515 else {
1516 myFirstSurf = mySurface;
1517 }
1518
1519 LastPar=myCurve->LastParameter();
1520 Ok = Standard_True;
1521 myCurve->D1(LastPar,UV,DUV);
1522 DUV.Reverse(); //We want the other part
1523
1524 if(DUV.Magnitude() <= Tol) Ok = Standard_False;
1525
1526 if(Ok) {
1527
1528 switch(mySurface->GetType()) {
1529 case GeomAbs_BSplineSurface :
1530 LocatePart(UV,DUV,mySurface,LeftBot,RightTop);
1531 break;
1532 case GeomAbs_SurfaceOfRevolution :
1533 case GeomAbs_SurfaceOfExtrusion :
1534 Ok = LocatePart_RevExt(UV,DUV,mySurface,LeftBot,RightTop);
1535 break;
1536 case GeomAbs_OffsetSurface :
1537 Ok = LocatePart_Offset(UV,DUV,mySurface,LeftBot,RightTop);
1538 break;
1539 default :
1540 Standard_NotImplemented::Raise("Adaptor3d_CurveOnSurface::EvalFirstLastSurf");
1541 break;
1542 }
1543 }
1544
1545 if (Ok) {
1546
1547 CompareBounds(LeftBot, RightTop); //SVV
1548
1549 myLastSurf = mySurface->UTrim(LeftBot.X(),RightTop.X(),Tol);
1550 myLastSurf = myLastSurf->VTrim(LeftBot.Y(),RightTop.Y(),Tol);
1551
1552 }
1553 else {
1554 myLastSurf = mySurface;
1555 }
1556}
1557
1558//=======================================================================
1559//function :LocatePart_RevExt
1560//purpose : processes Knots
1561//=======================================================================
1562
1563Standard_Boolean Adaptor3d_CurveOnSurface::LocatePart_RevExt(const gp_Pnt2d& UV,
1564 const gp_Vec2d& DUV,
1565 const Handle(Adaptor3d_HSurface)& S,
1566 gp_Pnt2d& LeftBot,
1567 gp_Pnt2d& RightTop) const
1568{
1569 Handle(Adaptor3d_HCurve) AHC = S->BasisCurve();
1570
1571 if (AHC->GetType() == GeomAbs_BSplineCurve) {
1572 Handle( Geom_BSplineCurve) BSplC;
1573 BSplC = AHC->BSpline();
1574
1575 if((S->GetType())==GeomAbs_SurfaceOfExtrusion) {
1576 Locate1Coord(1,UV,DUV,BSplC,LeftBot,RightTop);
1577 Locate2Coord(2,UV,DUV,S->FirstVParameter(),S->LastVParameter(),LeftBot,RightTop);
1578 }
1579 else if((S->GetType())==GeomAbs_SurfaceOfRevolution) {
1580 Locate1Coord(2,UV,DUV,BSplC,LeftBot,RightTop);
1581 Locate2Coord(1,UV,DUV,S->FirstUParameter(),S->LastUParameter(),LeftBot,RightTop);
1582 }
1583
1584 Standard_Real u1,u2,v1,v2;
1585 ReverseParam(LeftBot.X(),RightTop.X(),u1,u2);
1586 LeftBot.SetX(u1);
1587 RightTop.SetX(u2);
1588 ReverseParam(LeftBot.Y(),RightTop.Y(),v1,v2);
1589 LeftBot.SetY(v1);
1590 RightTop.SetY(v2);
1591 return Standard_True;
1592 }
1593 return Standard_False;
1594}
1595
1596//=======================================================================
1597//function :LocatePart_OffsetSurface
1598//purpose :
1599//=======================================================================
1600
1601Standard_Boolean Adaptor3d_CurveOnSurface::
1602 LocatePart_Offset(const gp_Pnt2d& UV, const gp_Vec2d& DUV,
1603 const Handle(Adaptor3d_HSurface)& S,
1604 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop) const
1605{
1606 Standard_Boolean Ok = Standard_True;
1607 Handle( Adaptor3d_HSurface) AHS;
1608 Handle( Geom_BSplineSurface) BSplS;
1609 AHS = S->BasisSurface();
1610 GeomAbs_SurfaceType BasisSType = AHS->GetType();
1611 switch(BasisSType) {
1612 case GeomAbs_SurfaceOfRevolution:
1613 case GeomAbs_SurfaceOfExtrusion :
1614 Ok = LocatePart_RevExt(UV,DUV,AHS,LeftBot,RightTop);
1615 break;
1616
1617 case GeomAbs_BSplineSurface:
1618 LocatePart(UV,DUV,AHS,LeftBot,RightTop);
1619 break;
1620
1621 default :
1622 Ok=Standard_False;
1623 }
1624 return Ok;
1625}
1626
1627//=======================================================================
1628//function :LocatePart
1629//purpose : for BSplineSurface
1630//=======================================================================
1631
1632void Adaptor3d_CurveOnSurface::LocatePart(const gp_Pnt2d& UV, const gp_Vec2d& DUV,
1633 const Handle(Adaptor3d_HSurface)& S,
1634 gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop) const
1635{
1636 Handle( Geom_BSplineSurface) BSplS;
1637 BSplS = S->BSpline();
1638 Standard_Boolean DUIsNull=Standard_False,
1639 DVIsNull=Standard_False;
1640
1641 Locate1Coord(1,UV,DUV,BSplS,DUIsNull,LeftBot,RightTop);
1642 Locate1Coord(2,UV,DUV,BSplS,DVIsNull,LeftBot,RightTop);
1643
1644 if((DUIsNull==Standard_True)&&(DVIsNull==Standard_False)) {
1645 TColStd_Array1OfReal ArrU(1,BSplS->NbUKnots());
1646 BSplS->UKnots(ArrU);
1647 Locate2Coord(1,UV,DUV,BSplS,ArrU,LeftBot,RightTop);
1648 }
1649 else if((DVIsNull==Standard_True)&&(DUIsNull==Standard_False)) {
1650 TColStd_Array1OfReal ArrV(1,BSplS->NbVKnots());
1651 BSplS->VKnots(ArrV);
1652 Locate2Coord(2,UV,DUV,BSplS,ArrV,LeftBot,RightTop);
1653 }
1654}
1655
1656
1657