0a484866afbe949e2264c4a3961ba70645418953
[occt.git] / src / Adaptor3d / Adaptor3d_SurfaceOfLinearExtrusion.cxx
1 // Created on: 1993-04-21
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 #include <Adaptor3d_SurfaceOfLinearExtrusion.ixx>
23 #include <Adaptor3d_HSurfaceOfLinearExtrusion.hxx>
24 #include <Precision.hxx>
25 #include <gp.hxx>
26
27 //=======================================================================
28 //function : Adaptor3d_SurfaceOfLinearExtrusion
29 //purpose  : 
30 //=======================================================================
31
32 Adaptor3d_SurfaceOfLinearExtrusion::Adaptor3d_SurfaceOfLinearExtrusion()
33 {}
34
35 //=======================================================================
36 //function : Adaptor3d_SurfaceOfLinearExtrusion
37 //purpose  : 
38 //=======================================================================
39
40 Adaptor3d_SurfaceOfLinearExtrusion::Adaptor3d_SurfaceOfLinearExtrusion
41 (const Handle(Adaptor3d_HCurve)& C)
42 {
43   Load( C);
44 }
45
46 //=======================================================================
47 //function : Adaptor3d_SurfaceOfLinearExtrusion
48 //purpose  : 
49 //=======================================================================
50
51 Adaptor3d_SurfaceOfLinearExtrusion::Adaptor3d_SurfaceOfLinearExtrusion
52 (const Handle(Adaptor3d_HCurve)& C,
53  const gp_Dir&        V)
54 {
55   Load( C);
56   Load( V);
57 }
58
59 //=======================================================================
60 //function : Load
61 //purpose  : 
62 //=======================================================================
63
64 void Adaptor3d_SurfaceOfLinearExtrusion::Load( const Handle(Adaptor3d_HCurve)& C)
65 {
66   myBasisCurve = C;
67 }
68
69 //=======================================================================
70 //function : Load
71 //purpose  : 
72 //=======================================================================
73
74 void Adaptor3d_SurfaceOfLinearExtrusion::Load( const gp_Dir& V)
75 {
76   myDirection = V;
77 }
78
79 //=======================================================================
80 //function : FirstUParameter
81 //purpose  : 
82 //=======================================================================
83
84 Standard_Real Adaptor3d_SurfaceOfLinearExtrusion::FirstUParameter() const 
85 {
86   return myBasisCurve->FirstParameter();
87 }
88
89 //=======================================================================
90 //function : LastUParameter
91 //purpose  : 
92 //=======================================================================
93
94 Standard_Real Adaptor3d_SurfaceOfLinearExtrusion::LastUParameter() const 
95 {
96   return myBasisCurve->LastParameter();
97 }
98
99 //=======================================================================
100 //function : FirstVParameter
101 //purpose  : 
102 //=======================================================================
103
104 Standard_Real Adaptor3d_SurfaceOfLinearExtrusion::FirstVParameter() const 
105 {
106   return RealFirst();
107 }
108
109 //=======================================================================
110 //function : LastVParameter
111 //purpose  : 
112 //=======================================================================
113
114 Standard_Real Adaptor3d_SurfaceOfLinearExtrusion::LastVParameter() const 
115 {
116   return RealLast();
117 }
118
119 //=======================================================================
120 //function : UContinuity
121 //purpose  : 
122 //=======================================================================
123
124 GeomAbs_Shape Adaptor3d_SurfaceOfLinearExtrusion::UContinuity() const 
125 {
126   return myBasisCurve->Continuity();
127 }
128
129 //=======================================================================
130 //function : VContinuity
131 //purpose  : 
132 //=======================================================================
133
134 GeomAbs_Shape Adaptor3d_SurfaceOfLinearExtrusion::VContinuity() const 
135 {
136   return GeomAbs_CN;
137 }
138
139 //=======================================================================
140 //function : NbUIntervals
141 //purpose  : 
142 //=======================================================================
143
144 Standard_Integer Adaptor3d_SurfaceOfLinearExtrusion::NbUIntervals
145 (const GeomAbs_Shape S)  const 
146 {
147   return   myBasisCurve->NbIntervals(S);
148 }
149
150 //=======================================================================
151 //function : NbVIntervals
152 //purpose  : 
153 //=======================================================================
154
155 Standard_Integer Adaptor3d_SurfaceOfLinearExtrusion::NbVIntervals
156 (const GeomAbs_Shape ) const 
157 {
158   return 1;
159 }
160
161 //=======================================================================
162 //function : UIntervals
163 //purpose  : 
164 //=======================================================================
165
166 void Adaptor3d_SurfaceOfLinearExtrusion::UIntervals
167 (TColStd_Array1OfReal&  T, const GeomAbs_Shape S) const 
168 {
169   myBasisCurve->Intervals(T,S);
170 }
171
172 //=======================================================================
173 //function : VIntervals
174 //purpose  : 
175 //=======================================================================
176
177 void Adaptor3d_SurfaceOfLinearExtrusion::VIntervals
178 //(TColStd_Array1OfReal&  T, const GeomAbs_Shape S) const 
179 (TColStd_Array1OfReal&  T, const GeomAbs_Shape ) const 
180 {
181  T(T.Lower()) = FirstVParameter() ;
182  T(T.Lower() + 1) = LastVParameter() ;
183 }
184
185 //=======================================================================
186 //function : VTrim
187 //purpose  : 
188 //=======================================================================
189
190 Handle(Adaptor3d_HSurface)  Adaptor3d_SurfaceOfLinearExtrusion::VTrim
191 (const Standard_Real First ,
192  const Standard_Real Last,
193  const Standard_Real Tol) const 
194 {
195   Handle(Adaptor3d_HCurve) newBasisCurve =
196   myBasisCurve->Trim(First, Last, Tol);
197   
198   Adaptor3d_SurfaceOfLinearExtrusion * SurfacePtr =
199   new  Adaptor3d_SurfaceOfLinearExtrusion(newBasisCurve, myDirection) ;
200
201   return new Adaptor3d_HSurfaceOfLinearExtrusion(*SurfacePtr);
202 }
203
204 //=======================================================================
205 //function : UTrim
206 //purpose  : 
207 //=======================================================================
208
209 Handle(Adaptor3d_HSurface)  Adaptor3d_SurfaceOfLinearExtrusion::UTrim
210 //(const Standard_Real First ,
211 // const Standard_Real Last,
212 // const Standard_Real Tol) const 
213 (const Standard_Real ,
214  const Standard_Real ,
215  const Standard_Real ) const 
216 {
217   Adaptor3d_SurfaceOfLinearExtrusion * SurfacePtr = 
218   new  Adaptor3d_SurfaceOfLinearExtrusion(myBasisCurve,myDirection);
219
220   return new Adaptor3d_HSurfaceOfLinearExtrusion(*SurfacePtr) ;
221 }
222
223 //=======================================================================
224 //function : IsUClosed
225 //purpose  : 
226 //=======================================================================
227
228 Standard_Boolean Adaptor3d_SurfaceOfLinearExtrusion::IsUClosed() const 
229 {
230   return myBasisCurve->IsClosed();
231 }
232
233 //=======================================================================
234 //function : IsVClosed
235 //purpose  : 
236 //=======================================================================
237
238 Standard_Boolean Adaptor3d_SurfaceOfLinearExtrusion::IsVClosed() const 
239 {
240   return Standard_True;
241 }
242
243 //=======================================================================
244 //function : IsUPeriodic
245 //purpose  : 
246 //=======================================================================
247
248 Standard_Boolean Adaptor3d_SurfaceOfLinearExtrusion::IsUPeriodic() const 
249 {
250   return myBasisCurve->IsPeriodic();
251 }
252
253 //=======================================================================
254 //function : UPeriod
255 //purpose  : 
256 //=======================================================================
257
258 Standard_Real Adaptor3d_SurfaceOfLinearExtrusion::UPeriod() const 
259 {
260   return myBasisCurve->Period() ;
261 }
262
263 //=======================================================================
264 //function : IsVPeriodic
265 //purpose  : 
266 //=======================================================================
267
268 Standard_Boolean Adaptor3d_SurfaceOfLinearExtrusion::IsVPeriodic() const 
269 {
270   return Standard_False;
271 }
272
273 //=======================================================================
274 //function : VPeriod
275 //purpose  : 
276 //=======================================================================
277
278 Standard_Real Adaptor3d_SurfaceOfLinearExtrusion::VPeriod() const 
279 {
280   Standard_DomainError::Raise("Adaptor3d_SurfaceOfLinearExtrusion::VPeriod");
281   return 0.0e0 ;
282 }
283
284 //=======================================================================
285 //function : Value
286 //purpose  : 
287 //=======================================================================
288
289 gp_Pnt Adaptor3d_SurfaceOfLinearExtrusion::Value(const Standard_Real U, 
290                                                  const Standard_Real V)
291      const 
292 {
293   gp_Pnt P;
294   P = myBasisCurve->Value(U);
295   P.Translate( V * gp_Vec(myDirection));
296   return P;
297 }
298
299 //=======================================================================
300 //function : D0
301 //purpose  : 
302 //=======================================================================
303
304 void Adaptor3d_SurfaceOfLinearExtrusion::D0(const Standard_Real U,
305                                             const Standard_Real V, 
306                                             gp_Pnt&             P) const 
307 {
308   myBasisCurve->D0(U,P);
309   P.Translate( V * gp_Vec(myDirection));
310 }
311
312 //=======================================================================
313 //function : D1
314 //purpose  : 
315 //=======================================================================
316
317 void Adaptor3d_SurfaceOfLinearExtrusion::D1(const Standard_Real U, 
318                                             const Standard_Real V, 
319                                                   gp_Pnt& P, 
320                                                   gp_Vec& D1U, 
321                                                   gp_Vec& D1V) const 
322 {
323   myBasisCurve->D1(U,P,D1U);
324   D0(U,V,P);
325   D1V = gp_Vec(myDirection);
326 }
327
328 //=======================================================================
329 //function : D2
330 //purpose  : 
331 //=======================================================================
332
333 void Adaptor3d_SurfaceOfLinearExtrusion::D2(const Standard_Real U, 
334                                             const Standard_Real V,
335                                             gp_Pnt& P, 
336                                             gp_Vec& D1U, gp_Vec& D1V,
337                                             gp_Vec& D2U, gp_Vec& D2V, 
338                                             gp_Vec& D2UV) const 
339 {
340   myBasisCurve->D2(U,P,D1U,D2U);
341   D1V = gp_Vec(myDirection);
342   D2V.SetCoord( 0., 0., 0.);
343   D2UV.SetCoord( 0., 0., 0.);
344   D0(U,V,P);
345 }
346
347 //=======================================================================
348 //function : D3
349 //purpose  : 
350 //=======================================================================
351
352 void Adaptor3d_SurfaceOfLinearExtrusion::D3(const Standard_Real U, 
353                                             const Standard_Real V,
354                                             gp_Pnt& P,
355                                             gp_Vec& D1U, gp_Vec& D1V,
356                                             gp_Vec& D2U, gp_Vec& D2V, 
357                                             gp_Vec& D2UV,
358                                             gp_Vec& D3U, gp_Vec& D3V, 
359                                             gp_Vec& D3UUV, gp_Vec& D3UVV) const 
360 {
361   myBasisCurve->D3(U,P,D1U,D2U,D3U);
362   D1V = gp_Vec(myDirection);
363   D2V.SetCoord( 0., 0., 0.);
364   D2UV.SetCoord( 0., 0., 0.);
365   D3V.SetCoord( 0., 0., 0.);
366   D3UUV.SetCoord( 0., 0., 0.);
367   D3UVV.SetCoord( 0., 0., 0.);
368   D0(U,V,P);
369 }
370
371 //=======================================================================
372 //function : DN
373 //purpose  : 
374 //=======================================================================
375
376 gp_Vec Adaptor3d_SurfaceOfLinearExtrusion::DN
377 (const Standard_Real    U, 
378 // const Standard_Real    V,
379  const Standard_Real    ,
380  const Standard_Integer NU, 
381  const Standard_Integer NV) const 
382 {
383   if ( (NU+NV)<1 || NU<0 || NV<0) {
384     Standard_DomainError::Raise("Adaptor3d_SurfaceOfLinearExtrusion::DN");
385     return gp_Vec();
386   }
387   else {
388     if (NU == 0 && NV ==1) return gp_Vec( myDirection);
389     else if (NV == 0)      return myBasisCurve->DN(U,NU);
390     else                   return gp_Vec( 0., 0., 0.);
391   }   
392 }
393
394 //=======================================================================
395 //function : UResolution
396 //purpose  : 
397 //=======================================================================
398
399 Standard_Real Adaptor3d_SurfaceOfLinearExtrusion::UResolution
400 (const Standard_Real R3d) const 
401 {
402   return myBasisCurve->Resolution(R3d);
403 }
404
405 //=======================================================================
406 //function : VResolution
407 //purpose  : 
408 //=======================================================================
409
410 Standard_Real Adaptor3d_SurfaceOfLinearExtrusion::VResolution
411 (const Standard_Real R3d) const 
412 {
413   return R3d;
414 }
415
416 //=======================================================================
417 //function : GetType
418 //purpose  : 
419 //=======================================================================
420
421 GeomAbs_SurfaceType Adaptor3d_SurfaceOfLinearExtrusion::GetType() const 
422 {
423   switch ( myBasisCurve->GetType()) {
424     
425   case GeomAbs_Line:
426     {
427       gp_Dir D = myBasisCurve->Line().Direction();
428       if (myDirection.IsParallel( D, Precision::Angular())) {
429         return GeomAbs_SurfaceOfExtrusion;
430       }
431       else {
432         return GeomAbs_Plane;
433       }
434       break;
435     }
436     
437   case GeomAbs_Circle:
438     {
439       gp_Dir D = (myBasisCurve->Circle()).Axis().Direction();
440       if ( myDirection.IsParallel( D, Precision::Angular())) {
441         return GeomAbs_Cylinder;
442       }
443       // JAG 10.11.95
444       else if (myDirection.IsNormal(D, Precision::Angular())) {
445         return GeomAbs_Plane;
446       }
447       else {
448         return GeomAbs_SurfaceOfExtrusion;
449       }
450       break;
451     }
452     // JAG 10.11.95
453     
454   case GeomAbs_Ellipse:
455     {
456       gp_Dir D = (myBasisCurve->Ellipse()).Axis().Direction();
457       if (myDirection.IsNormal(D, Precision::Angular())) {
458         return GeomAbs_Plane;
459       }
460       else {
461         return GeomAbs_SurfaceOfExtrusion;
462       }
463       break;
464     }
465     
466   case GeomAbs_Parabola:
467     {
468       gp_Dir D = (myBasisCurve->Parabola()).Axis().Direction();
469       if (myDirection.IsNormal(D, Precision::Angular())) {
470         return GeomAbs_Plane;
471       }
472       else {
473         return GeomAbs_SurfaceOfExtrusion;
474       }
475       break;
476     }
477     
478   case GeomAbs_Hyperbola:
479     {
480       gp_Dir D = (myBasisCurve->Hyperbola()).Axis().Direction();
481       if (myDirection.IsNormal(D, Precision::Angular())) {
482         return GeomAbs_Plane;
483       }
484       else {
485         return GeomAbs_SurfaceOfExtrusion;
486       }
487       break;
488     }
489
490   default:
491     return GeomAbs_SurfaceOfExtrusion;
492
493   }
494 }
495
496 //=======================================================================
497 //function : Plane
498 //purpose  : 
499 //=======================================================================
500
501 gp_Pln Adaptor3d_SurfaceOfLinearExtrusion::Plane() const 
502
503   Standard_NoSuchObject_Raise_if (GetType() != GeomAbs_Plane,
504                   "Adaptor3d_SurfaceOfLinearExtrusion::Plane");
505 /*
506   gp_Pnt P;
507   gp_Vec Ox, Oy;
508   D1( 0., 0., P, Ox, Oy);
509   gp_Ax3 Ax3(P,gp_Dir(Ox^Oy),gp_Dir(Ox));
510   if (gp_Dir(Oy).Dot(Ax3.YDirection())<0.){
511     Ax3.YReverse();
512   }
513   return gp_Pln(Ax3);
514 */
515
516   gp_Pnt P;
517   gp_Vec D1u, newZ;
518   Standard_Real UFirst = myBasisCurve->FirstParameter();
519   Standard_Real ULast  = myBasisCurve->LastParameter();
520   if (Precision::IsNegativeInfinite(UFirst) &&
521       Precision::IsPositiveInfinite(ULast)) {
522     UFirst = -100.;
523     ULast  = 100.;
524   }
525   else if (Precision::IsNegativeInfinite(UFirst)) {
526     UFirst = ULast - 200.;
527   }
528   else if (Precision::IsPositiveInfinite(ULast)) {
529     ULast = UFirst + 200.;
530   }
531   Standard_Real deltau = (ULast-UFirst)/20.;
532   for (Standard_Integer i =1; i<=21; i++) {
533     Standard_Real prm = UFirst + (i-1)*deltau;
534     myBasisCurve->D1(prm,P,D1u);
535     newZ = D1u.Normalized().Crossed(myDirection);
536     if (newZ.Magnitude() > 1.e-12) break;
537   }
538   gp_Ax3 Ax3(P,gp_Dir(newZ),gp_Dir(D1u));
539   if (myDirection.Dot(Ax3.YDirection())<0.){
540     Ax3.YReverse();
541   }
542   return gp_Pln(Ax3);
543 }
544
545
546 //=======================================================================
547 //function : Cylinder
548 //purpose  : 
549 //=======================================================================
550
551 gp_Cylinder Adaptor3d_SurfaceOfLinearExtrusion::Cylinder() const 
552 {
553   Standard_NoSuchObject_Raise_if 
554     (GetType() != GeomAbs_Cylinder,
555      "Adaptor3d_SurfaceOfLinearExtrusion::Cylinder");
556
557   gp_Circ C =  myBasisCurve->Circle() ;
558   gp_Ax3 Ax3(C.Position());
559   if(myDirection.Dot((C.Axis()).Direction())<0.){
560     Ax3.ZReverse();
561   }
562   return gp_Cylinder(Ax3,C.Radius());
563 }
564
565 //=======================================================================
566 //function : Cone
567 //purpose  : 
568 //=======================================================================
569
570 gp_Cone Adaptor3d_SurfaceOfLinearExtrusion::Cone() const 
571 {
572   Standard_NoSuchObject::Raise("Adaptor3d_SurfaceOfLinearExtrusion::Cone");
573   return gp_Cone();
574 }
575
576 //=======================================================================
577 //function : Sphere
578 //purpose  : 
579 //=======================================================================
580
581 gp_Sphere Adaptor3d_SurfaceOfLinearExtrusion::Sphere() const 
582 {
583   Standard_NoSuchObject::Raise("Adaptor3d_SurfaceOfLinearExtrusion::Sphere");
584   return gp_Sphere();
585 }
586
587 //=======================================================================
588 //function : Torus
589 //purpose  : 
590 //=======================================================================
591
592 gp_Torus Adaptor3d_SurfaceOfLinearExtrusion::Torus() const 
593 {
594   Standard_NoSuchObject::Raise("Adaptor3d_SurfaceOfLinearExtrusion::Torus");
595   return gp_Torus();
596 }
597
598
599 //=======================================================================
600 //function : Axis
601 //purpose  : 
602 //=======================================================================
603
604 gp_Ax1 Adaptor3d_SurfaceOfLinearExtrusion::AxeOfRevolution() const 
605 {
606   Standard_NoSuchObject::Raise("Adaptor3d_SurfaceOfLinearExtrusion::Axes");
607   return gp_Ax1();
608 }
609
610 //=======================================================================
611 //function : UDegree
612 //purpose  : 
613 //=======================================================================
614
615 Standard_Integer Adaptor3d_SurfaceOfLinearExtrusion::UDegree() const 
616 {
617   return myBasisCurve -> Degree();
618 }
619 //=======================================================================
620 //function : NbUPoles
621 //purpose  : 
622 //=======================================================================
623
624 Standard_Integer Adaptor3d_SurfaceOfLinearExtrusion::NbUPoles() const 
625 {
626   return myBasisCurve->NbPoles();
627 }
628 //=======================================================================
629 //function : VDegree
630 //purpose  : 
631 //=======================================================================
632
633 Standard_Integer Adaptor3d_SurfaceOfLinearExtrusion::VDegree() const 
634 {
635   Standard_NoSuchObject::Raise("Adaptor3d_SurfaceOfLinearExtrusion::VDegree");
636   return 0;
637 }
638
639 //=======================================================================
640 //function : NbVPoles
641 //purpose  : 
642 //=======================================================================
643
644 Standard_Integer Adaptor3d_SurfaceOfLinearExtrusion::NbVPoles() const 
645 {
646   Standard_NoSuchObject::Raise("Adaptor3d_SurfaceOfLinearExtrusion::NbVPoles");
647   return 0;
648 }
649
650 //=======================================================================
651 //function : NbUKnots
652 //purpose  : 
653 //=======================================================================
654
655 Standard_Integer Adaptor3d_SurfaceOfLinearExtrusion::NbUKnots() const 
656 {
657   Standard_NoSuchObject::Raise
658     ("Adaptor3d_SurfaceOfLinearExtrusion::NbUKnots");
659   return 0;
660 }
661 //=======================================================================
662 //function : NbVKnots
663 //purpose  : 
664 //=======================================================================
665
666 Standard_Integer Adaptor3d_SurfaceOfLinearExtrusion::NbVKnots() const 
667 {
668   Standard_NoSuchObject::Raise("Adaptor3d_SurfaceOfLinearExtrusion::NbVKnots");
669   return 0;
670 }
671 //=======================================================================
672 //function : IsURational
673 //purpose  : 
674 //=======================================================================
675
676 Standard_Boolean Adaptor3d_SurfaceOfLinearExtrusion::IsURational() const 
677 {
678   Standard_NoSuchObject::Raise
679     ("Adaptor3d_SurfaceOfLinearExtrusion::IsURational");
680   return Standard_False;
681 }
682 //=======================================================================
683 //function : IsVRational
684 //purpose  : 
685 //=======================================================================
686
687 Standard_Boolean Adaptor3d_SurfaceOfLinearExtrusion::IsVRational() const 
688 {
689   Standard_NoSuchObject::Raise
690     ("Adaptor3d_SurfaceOfLinearExtrusion::IsVRational");
691   return Standard_False;
692 }
693 //=======================================================================
694 //function : Bezier
695 //purpose  : 
696 //=======================================================================
697
698
699 Handle(Geom_BezierSurface)  Adaptor3d_SurfaceOfLinearExtrusion::Bezier() const 
700 {
701   Standard_NoSuchObject::Raise("Adaptor3d_SurfaceOfLinearExtrusion::Axes");
702   return Handle(Geom_BezierSurface)() ;
703 }
704
705 //=======================================================================
706 //function : BSpline
707 //purpose  : 
708 //=======================================================================
709
710 Handle(Geom_BSplineSurface)  Adaptor3d_SurfaceOfLinearExtrusion::BSpline() const 
711 {
712   Standard_NoSuchObject::Raise("Adaptor3d_SurfaceOfLinearExtrusion::Axes");
713   return Handle(Geom_BSplineSurface)() ;
714 }
715
716 //=======================================================================
717 //function : Direction
718 //purpose  : 
719 //=======================================================================
720
721 gp_Dir Adaptor3d_SurfaceOfLinearExtrusion::Direction() const
722 {
723   return myDirection;
724 }
725
726 //=======================================================================
727 //function : BasisCurve
728 //purpose  : 
729 //=======================================================================
730
731 Handle(Adaptor3d_HCurve) Adaptor3d_SurfaceOfLinearExtrusion::BasisCurve() const 
732 {
733   return myBasisCurve;
734 }