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