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