1 // Created on: 1993-03-10
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BSplCLib.hxx>
19 #include <BSplSLib.hxx>
20 #include <Geom_BSplineCurve.hxx>
21 #include <Geom_Circle.hxx>
22 #include <Geom_Curve.hxx>
23 #include <Geom_Geometry.hxx>
24 #include <Geom_SurfaceOfRevolution.hxx>
25 #include <Geom_UndefinedDerivative.hxx>
26 #include <GeomEvaluator_SurfaceOfRevolution.hxx>
30 #include <gp_Ax2d.hxx>
32 #include <gp_GTrsf2d.hxx>
35 #include <gp_Trsf.hxx>
38 #include <Precision.hxx>
39 #include <Standard_ConstructionError.hxx>
40 #include <Standard_NotImplemented.hxx>
41 #include <Standard_RangeError.hxx>
42 #include <Standard_Type.hxx>
44 IMPLEMENT_STANDARD_RTTIEXT(Geom_SurfaceOfRevolution,Geom_SweptSurface)
46 #define POLES (poles->Array2())
47 #define WEIGHTS (weights->Array2())
48 #define UKNOTS (uknots->Array1())
49 #define VKNOTS (vknots->Array1())
50 #define UFKNOTS (ufknots->Array1())
51 #define VFKNOTS (vfknots->Array1())
52 #define FMULTS (BSplCLib::NoMults())
54 typedef Geom_SurfaceOfRevolution SurfaceOfRevolution;
55 typedef Geom_Curve Curve;
69 //=======================================================================
72 //=======================================================================
74 Handle(Geom_Geometry) Geom_SurfaceOfRevolution::Copy () const {
76 return new Geom_SurfaceOfRevolution (basisCurve, Axis());
80 //=======================================================================
81 //function : Geom_SurfaceOfRevolution
83 //=======================================================================
85 Geom_SurfaceOfRevolution::Geom_SurfaceOfRevolution
86 (const Handle(Geom_Curve)& C ,
87 const Ax1& A1 ) : loc (A1.Location()) {
89 direction = A1.Direction();
94 //=======================================================================
97 //=======================================================================
99 void Geom_SurfaceOfRevolution::UReverse () {
102 myEvaluator->SetDirection(direction);
106 //=======================================================================
107 //function : UReversedParameter
109 //=======================================================================
111 Standard_Real Geom_SurfaceOfRevolution::UReversedParameter (const Standard_Real U) const {
113 return ( 2.*M_PI - U);
117 //=======================================================================
118 //function : VReverse
120 //=======================================================================
122 void Geom_SurfaceOfRevolution::VReverse () {
124 basisCurve->Reverse();
128 //=======================================================================
129 //function : VReversedParameter
131 //=======================================================================
133 Standard_Real Geom_SurfaceOfRevolution::VReversedParameter (const Standard_Real V) const {
135 return basisCurve->ReversedParameter(V);
139 //=======================================================================
140 //function : Location
142 //=======================================================================
144 const gp_Pnt& Geom_SurfaceOfRevolution::Location () const {
149 //=======================================================================
150 //function : IsUPeriodic
152 //=======================================================================
154 Standard_Boolean Geom_SurfaceOfRevolution::IsUPeriodic () const {
156 return Standard_True;
159 //=======================================================================
162 //=======================================================================
164 Standard_Boolean Geom_SurfaceOfRevolution::IsCNu (const Standard_Integer ) const {
166 return Standard_True;
169 //=======================================================================
172 //=======================================================================
174 Ax1 Geom_SurfaceOfRevolution::Axis () const {
176 return Ax1 (loc, direction);
179 //=======================================================================
182 //=======================================================================
184 Standard_Boolean Geom_SurfaceOfRevolution::IsCNv (const Standard_Integer N) const {
186 Standard_RangeError_Raise_if (N < 0, " ");
187 return basisCurve->IsCN(N);
191 //=======================================================================
192 //function : IsUClosed
194 //=======================================================================
196 Standard_Boolean Geom_SurfaceOfRevolution::IsUClosed () const {
198 return Standard_True;
201 //=======================================================================
202 //function : IsVClosed
204 //=======================================================================
206 Standard_Boolean Geom_SurfaceOfRevolution::IsVClosed () const
208 return basisCurve->IsClosed();
212 //=======================================================================
213 //function : IsVPeriodic
215 //=======================================================================
217 Standard_Boolean Geom_SurfaceOfRevolution::IsVPeriodic () const {
219 return basisCurve->IsPeriodic();
223 //=======================================================================
226 //=======================================================================
228 void Geom_SurfaceOfRevolution::SetAxis (const Ax1& A1) {
230 direction = A1.Direction();
232 myEvaluator->SetAxis(A1);
236 //=======================================================================
237 //function : SetDirection
239 //=======================================================================
241 void Geom_SurfaceOfRevolution::SetDirection (const Dir& V) {
244 myEvaluator->SetDirection(direction);
248 //=======================================================================
249 //function : SetBasisCurve
251 //=======================================================================
253 void Geom_SurfaceOfRevolution::SetBasisCurve (const Handle(Geom_Curve)& C) {
255 basisCurve = Handle(Geom_Curve)::DownCast(C->Copy());
256 smooth = C->Continuity();
257 myEvaluator = new GeomEvaluator_SurfaceOfRevolution(basisCurve, direction, loc);
261 //=======================================================================
262 //function : SetLocation
264 //=======================================================================
266 void Geom_SurfaceOfRevolution::SetLocation (const Pnt& P) {
269 myEvaluator->SetLocation(loc);
273 //=======================================================================
276 //=======================================================================
278 void Geom_SurfaceOfRevolution::Bounds ( Standard_Real& U1,
281 Standard_Real& V2 ) const {
285 V1 = basisCurve->FirstParameter();
286 V2 = basisCurve->LastParameter();
290 //=======================================================================
293 //=======================================================================
295 void Geom_SurfaceOfRevolution::D0
296 (const Standard_Real U, const Standard_Real V, Pnt& P) const
298 myEvaluator->D0(U, V, P);
302 //=======================================================================
305 //=======================================================================
307 void Geom_SurfaceOfRevolution::D1
308 (const Standard_Real U, const Standard_Real V,
310 Vec& D1U, Vec& D1V ) const
312 myEvaluator->D1(U, V, P, D1U, D1V);
315 //=======================================================================
318 //=======================================================================
320 void Geom_SurfaceOfRevolution::D2
321 (const Standard_Real U, const Standard_Real V,
324 Vec& D2U, Vec& D2V, Vec& D2UV ) const
326 myEvaluator->D2(U, V, P, D1U, D1V, D2U, D2V, D2UV);
331 //=======================================================================
334 //=======================================================================
336 void Geom_SurfaceOfRevolution::D3
337 (const Standard_Real U, const Standard_Real V,
340 Vec& D2U, Vec& D2V, Vec& D2UV,
341 Vec& D3U, Vec& D3V, Vec& D3UUV, Vec& D3UVV ) const
343 myEvaluator->D3(U, V, P, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);
347 //=======================================================================
350 //=======================================================================
352 Vec Geom_SurfaceOfRevolution::DN (const Standard_Real U , const Standard_Real V,
353 const Standard_Integer Nu, const Standard_Integer Nv) const
355 return myEvaluator->DN(U, V, Nu, Nv);
359 //=======================================================================
360 //function : ReferencePlane
362 //=======================================================================
364 Ax2 Geom_SurfaceOfRevolution::ReferencePlane() const {
366 throw Standard_NotImplemented();
370 //=======================================================================
373 //=======================================================================
375 Handle(Geom_Curve) Geom_SurfaceOfRevolution::UIso (const Standard_Real U) const {
377 Handle(Geom_Curve) C = Handle(Geom_Curve)::DownCast(basisCurve->Copy());
378 Ax1 RotAxis = Ax1 (loc, direction);
379 C->Rotate (RotAxis, U);
384 //=======================================================================
387 //=======================================================================
389 Handle(Geom_Curve) Geom_SurfaceOfRevolution::VIso (const Standard_Real V) const {
391 Handle(Geom_Circle) Circ;
392 Pnt Pc = basisCurve->Value (V);
393 gp_Lin L1(loc,direction);
394 Standard_Real Rad= L1.Distance(Pc);
397 if ( Rad > gp::Resolution()) {
400 C.SetLinearForm((P-loc.XYZ()).Dot(direction.XYZ()),
401 direction.XYZ(), loc.XYZ() );
403 if(P.Modulus() > gp::Resolution()) {
404 gp_Dir D = P.Normalized();
405 Rep = gp_Ax2(C, direction, D);
408 Rep = gp_Ax2(C, direction);
411 Rep = gp_Ax2(Pc, direction);
413 Circ = new Geom_Circle (Rep, Rad);
418 //=======================================================================
419 //function : Transform
421 //=======================================================================
423 void Geom_SurfaceOfRevolution::Transform (const Trsf& T) {
426 direction.Transform (T);
427 basisCurve->Transform (T);
428 if(T.ScaleFactor()*T.HVectorialPart().Determinant() < 0.) UReverse();
429 myEvaluator->SetDirection(direction);
430 myEvaluator->SetLocation(loc);
433 //=======================================================================
434 //function : TransformParameters
436 //=======================================================================
438 void Geom_SurfaceOfRevolution::TransformParameters(Standard_Real& ,
443 V = basisCurve->TransformedParameter(V,T);
446 //=======================================================================
447 //function : ParametricTransformation
449 //=======================================================================
451 gp_GTrsf2d Geom_SurfaceOfRevolution::ParametricTransformation
452 (const gp_Trsf& T) const
455 gp_Ax2d Axis(gp::Origin2d(),gp::DX2d());
456 T2.SetAffinity(Axis, basisCurve->ParametricTransformation(T));