0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / Geom / Geom_SphericalSurface.cxx
1 // Created on: 1993-03-10
2 // Created by: JCV
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <ElSLib.hxx>
19 #include <Geom_Circle.hxx>
20 #include <Geom_Curve.hxx>
21 #include <Geom_Geometry.hxx>
22 #include <Geom_SphericalSurface.hxx>
23 #include <Geom_TrimmedCurve.hxx>
24 #include <gp_Ax3.hxx>
25 #include <gp_Circ.hxx>
26 #include <gp_Pnt.hxx>
27 #include <gp_Sphere.hxx>
28 #include <gp_Trsf.hxx>
29 #include <gp_Vec.hxx>
30 #include <gp_XYZ.hxx>
31 #include <Standard_ConstructionError.hxx>
32 #include <Standard_RangeError.hxx>
33 #include <Standard_Type.hxx>
34
35 IMPLEMENT_STANDARD_RTTIEXT(Geom_SphericalSurface,Geom_ElementarySurface)
36
37 typedef Geom_Circle                   Circle;
38 typedef Geom_SphericalSurface         SphericalSurface;
39 typedef gp_Ax2  Ax2;
40 typedef gp_Ax3  Ax3;
41 typedef gp_Circ Circ;
42 typedef gp_Dir  Dir;
43 typedef gp_Pnt  Pnt;
44 typedef gp_Trsf Trsf;
45 typedef gp_XYZ  XYZ;
46 typedef gp_Vec  Vec;
47
48 //=======================================================================
49 //function : Copy
50 //purpose  : 
51 //=======================================================================
52
53 Handle(Geom_Geometry) Geom_SphericalSurface::Copy () const {
54  
55   Handle(Geom_SphericalSurface) Cs;
56   Cs = new SphericalSurface (pos, radius);
57   return Cs;
58 }
59
60
61
62 //=======================================================================
63 //function : Geom_SphericalSurface
64 //purpose  : 
65 //=======================================================================
66
67 Geom_SphericalSurface::Geom_SphericalSurface (const Ax3& A, const Standard_Real R) 
68 : radius (R) {
69
70   if (R < 0.0) throw Standard_ConstructionError();
71   pos = A;
72 }
73
74
75 //=======================================================================
76 //function : Geom_SphericalSurface
77 //purpose  : 
78 //=======================================================================
79
80 Geom_SphericalSurface::Geom_SphericalSurface (const gp_Sphere& S) 
81  :radius (S.Radius()) {
82
83   pos = S.Position();
84 }
85
86
87
88 //=======================================================================
89 //function : UReversedParameter
90 //purpose  : 
91 //=======================================================================
92
93 Standard_Real Geom_SphericalSurface::UReversedParameter( const Standard_Real U) const
94 {
95   return (2.*M_PI - U);
96 }
97
98 //=======================================================================
99 //function : VReversedParameter
100 //purpose  : 
101 //=======================================================================
102
103 Standard_Real Geom_SphericalSurface::VReversedParameter( const Standard_Real V) const
104 {
105   return (-V);
106 }
107
108
109 //=======================================================================
110 //function : Area
111 //purpose  : 
112 //=======================================================================
113
114 Standard_Real Geom_SphericalSurface::Area () const 
115 {return 4.0 * M_PI * radius * radius;}
116
117 //=======================================================================
118 //function : Radius
119 //purpose  : 
120 //=======================================================================
121
122 Standard_Real Geom_SphericalSurface::Radius () const                  
123 { return radius; }
124
125 //=======================================================================
126 //function : IsUClosed
127 //purpose  : 
128 //=======================================================================
129
130 Standard_Boolean Geom_SphericalSurface::IsUClosed () const           
131 { return Standard_True; }
132
133 //=======================================================================
134 //function : IsVClosed
135 //purpose  : 
136 //=======================================================================
137
138 Standard_Boolean Geom_SphericalSurface::IsVClosed () const            
139 { return Standard_False; }
140
141 //=======================================================================
142 //function : IsUPeriodic
143 //purpose  : 
144 //=======================================================================
145
146 Standard_Boolean Geom_SphericalSurface::IsUPeriodic () const          
147 { return Standard_True; }
148
149 //=======================================================================
150 //function : IsVPeriodic
151 //purpose  : 
152 //=======================================================================
153
154 Standard_Boolean Geom_SphericalSurface::IsVPeriodic () const          
155 { return Standard_False; }
156
157 //=======================================================================
158 //function : SetRadius
159 //purpose  : 
160 //=======================================================================
161
162 void Geom_SphericalSurface::SetRadius (const Standard_Real R) {
163
164   if (R < 0.0) { throw Standard_ConstructionError(); }
165   radius = R;
166 }
167
168
169 //=======================================================================
170 //function : SetSphere
171 //purpose  : 
172 //=======================================================================
173
174 void Geom_SphericalSurface::SetSphere (const gp_Sphere& S) {
175
176   radius = S.Radius();
177   pos = S.Position();
178 }
179
180
181 //=======================================================================
182 //function : Bounds
183 //purpose  : 
184 //=======================================================================
185
186 void Geom_SphericalSurface::Bounds (Standard_Real& U1, Standard_Real& U2,
187                                     Standard_Real& V1, Standard_Real& V2) const {
188
189   U1 =       0.0;  
190   U2 =  M_PI * 2.0; 
191   V1 = -M_PI / 2.0;
192   V2 =  M_PI / 2.0;
193 }
194
195
196 //=======================================================================
197 //function : Coefficients
198 //purpose  : 
199 //=======================================================================
200
201 void Geom_SphericalSurface::Coefficients (Standard_Real& A1, Standard_Real& A2, Standard_Real& A3,
202                                           Standard_Real& B1, Standard_Real& B2, Standard_Real& B3, 
203                                           Standard_Real& C1, Standard_Real& C2, Standard_Real& C3, 
204                                           Standard_Real& D ) const {
205
206    // Dans le repere local de la sphere :
207    // X*X + Y*Y + Z*Z - radius * radius = 0
208
209       Trsf T;
210       T.SetTransformation (pos);
211       Standard_Real T11 = T.Value (1, 1);
212       Standard_Real T12 = T.Value (1, 2);
213       Standard_Real T13 = T.Value (1, 3);
214       Standard_Real T14 = T.Value (1, 4);
215       Standard_Real T21 = T.Value (2, 1);
216       Standard_Real T22 = T.Value (2, 2);
217       Standard_Real T23 = T.Value (2, 3);
218       Standard_Real T24 = T.Value (2, 4);
219       Standard_Real T31 = T.Value (3, 1);
220       Standard_Real T32 = T.Value (3, 2);
221       Standard_Real T33 = T.Value (3, 3);
222       Standard_Real T34 = T.Value (3, 4);
223       A1 = T11 * T11 + T21 * T21 + T31 * T31;
224       A2 = T12 * T12 + T22 * T22 + T32 * T32;
225       A3 = T13 * T13 + T23 * T23 + T33 * T33;
226       B1 = T11 * T12 + T21 * T22 + T31 * T32;
227       B2 = T11 * T13 + T21 * T23 + T31 * T33;
228       B3 = T12 * T13 + T22 * T23 + T32 * T33;
229       C1 = T11 * T14 + T21 * T24 + T31 * T34;
230       C2 = T12 * T14 + T22 * T24 + T32 * T34;
231       C3 = T13 * T14 + T23 * T24 + T33 * T34;
232       D = T14 * T14 + T24 * T24 + T34 * T34 - radius * radius;
233 }
234
235
236 //=======================================================================
237 //function : D0
238 //purpose  : 
239 //=======================================================================
240
241 void Geom_SphericalSurface::D0 (const Standard_Real U, const Standard_Real V, Pnt& P) const 
242 {
243   ElSLib::SphereD0(U,V,pos,radius,P);
244 }
245
246
247 //=======================================================================
248 //function : D1
249 //purpose  : 
250 //=======================================================================
251
252 void Geom_SphericalSurface::D1 (const Standard_Real U, const Standard_Real V  , 
253                                       Pnt& P,       Vec& D1U, Vec& D1V
254                                ) const 
255 {
256   ElSLib::SphereD1 (U, V, pos, radius, P ,D1U, D1V);
257 }
258
259
260 //=======================================================================
261 //function : D2
262 //purpose  : 
263 //=======================================================================
264
265 void Geom_SphericalSurface::D2 (const Standard_Real U, const Standard_Real V,
266                                 Pnt& P,
267                                 Vec& D1U, Vec& D1V, 
268                                 Vec& D2U, Vec& D2V, Vec& D2UV ) const
269 {
270   ElSLib::SphereD2 (U, V, pos, radius, P, D1U, D1V, D2U, D2V, D2UV);
271 }
272
273
274 //=======================================================================
275 //function : D3
276 //purpose  : 
277 //=======================================================================
278
279 void Geom_SphericalSurface::D3 (const Standard_Real U, const Standard_Real V, 
280                                 Pnt& P,
281                                 Vec& D1U, Vec& D1V, 
282                                 Vec& D2U, Vec& D2V, Vec& D2UV,
283                                 Vec& D3U, Vec& D3V, Vec& D3UUV, Vec& D3UVV
284                                ) const
285 {
286   ElSLib::SphereD3 (U, V, pos, radius, P, D1U, D1V, D2U, D2V,
287                     D2UV, D3U, D3V, D3UUV, D3UVV);
288 }
289
290
291 //=======================================================================
292 //function : DN
293 //purpose  : 
294 //=======================================================================
295
296 Vec Geom_SphericalSurface::DN (const Standard_Real U, const Standard_Real V, 
297                                const Standard_Integer Nu, const Standard_Integer Nv) const {
298
299    Standard_RangeError_Raise_if (Nu + Nv < 1 || Nu < 0 || Nv <0, " ");
300    return  ElSLib::SphereDN (U, V, pos, radius, Nu, Nv);
301 }
302
303
304 //=======================================================================
305 //function : Sphere
306 //purpose  : 
307 //=======================================================================
308
309 gp_Sphere Geom_SphericalSurface::Sphere () const {
310
311   return gp_Sphere (pos, radius);
312 }
313
314
315 //=======================================================================
316 //function : UIso
317 //purpose  : 
318 //=======================================================================
319
320 Handle(Geom_Curve) Geom_SphericalSurface::UIso (const Standard_Real U) const 
321 {
322   Handle(Geom_Circle) GC = new Geom_Circle(ElSLib::SphereUIso(pos,radius,U));
323   Handle(Geom_TrimmedCurve) iso = new Geom_TrimmedCurve(GC,-M_PI/2.,M_PI/2);
324   return iso;
325 }
326
327
328 //=======================================================================
329 //function : VIso
330 //purpose  : 
331 //=======================================================================
332
333 Handle(Geom_Curve) Geom_SphericalSurface::VIso (const Standard_Real V) const 
334 {
335   Handle(Geom_Circle) 
336     GC = new Geom_Circle(ElSLib::SphereVIso(pos,radius,V));
337   return GC;
338 }
339
340
341 //=======================================================================
342 //function : Volume
343 //purpose  : 
344 //=======================================================================
345
346 Standard_Real Geom_SphericalSurface::Volume () const {
347
348    return (4.0 * M_PI * radius * radius * radius)/3.0;
349 }
350
351
352
353 //=======================================================================
354 //function : Transform
355 //purpose  : 
356 //=======================================================================
357
358 void Geom_SphericalSurface::Transform (const Trsf& T) {
359
360    radius = radius * Abs(T.ScaleFactor());
361    pos.Transform (T);
362 }