0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / Geom / Geom_CylindricalSurface.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_CylindricalSurface.hxx>
22 #include <Geom_Geometry.hxx>
23 #include <Geom_Line.hxx>
24 #include <gp.hxx>
25 #include <gp_Ax2d.hxx>
26 #include <gp_Ax3.hxx>
27 #include <gp_Circ.hxx>
28 #include <gp_Cylinder.hxx>
29 #include <gp_GTrsf2d.hxx>
30 #include <gp_Lin.hxx>
31 #include <gp_Pnt.hxx>
32 #include <gp_Trsf.hxx>
33 #include <gp_Vec.hxx>
34 #include <gp_XYZ.hxx>
35 #include <Precision.hxx>
36 #include <Standard_ConstructionError.hxx>
37 #include <Standard_RangeError.hxx>
38 #include <Standard_Type.hxx>
39
40 IMPLEMENT_STANDARD_RTTIEXT(Geom_CylindricalSurface,Geom_ElementarySurface)
41
42 typedef Geom_CylindricalSurface         CylindricalSurface;
43
44 typedef gp_Ax1  Ax1;
45 typedef gp_Ax2  Ax2;
46 typedef gp_Ax3  Ax3;
47 typedef gp_Circ Circ;
48 typedef gp_Dir  Dir;
49 typedef gp_Lin  Lin;
50 typedef gp_Pnt  Pnt;
51 typedef gp_Trsf Trsf;
52 typedef gp_Vec  Vec;
53 typedef gp_XYZ  XYZ;
54
55
56
57 //=======================================================================
58 //function : Copy
59 //purpose  : 
60 //=======================================================================
61
62 Handle(Geom_Geometry) Geom_CylindricalSurface::Copy () const {
63
64    Handle(Geom_CylindricalSurface) Cs;
65    Cs = new CylindricalSurface (pos, radius);
66    return Cs;
67 }
68
69
70 //=======================================================================
71 //function : Geom_CylindricalSurface
72 //purpose  : 
73 //=======================================================================
74
75 Geom_CylindricalSurface::Geom_CylindricalSurface (const gp_Cylinder& C) 
76 : radius (C.Radius()) {
77
78   pos = C.Position (); 
79 }
80
81
82 //=======================================================================
83 //function : Geom_CylindricalSurface
84 //purpose  : 
85 //=======================================================================
86
87 Geom_CylindricalSurface::Geom_CylindricalSurface ( const Ax3& A3, 
88                                                    const Standard_Real R) 
89 : radius (R) {
90
91   if (R < 0.0) throw Standard_ConstructionError();
92   pos = A3;
93 }
94
95
96 //=======================================================================
97 //function : UReversedParameter
98 //purpose  : 
99 //=======================================================================
100
101 Standard_Real Geom_CylindricalSurface::UReversedParameter( const Standard_Real U) const
102 {
103   return (2.*M_PI - U);
104 }
105
106 //=======================================================================
107 //function : VReversedParameter
108 //purpose  : 
109 //=======================================================================
110
111 Standard_Real Geom_CylindricalSurface::VReversedParameter( const Standard_Real V) const 
112 {
113   return (-V);
114 }
115
116 //=======================================================================
117 //function : Radius
118 //purpose  : 
119 //=======================================================================
120
121 Standard_Real Geom_CylindricalSurface::Radius () const             { return radius; }
122
123 //=======================================================================
124 //function : IsUClosed
125 //purpose  : 
126 //=======================================================================
127
128 Standard_Boolean Geom_CylindricalSurface::IsUClosed () const       { return Standard_True; }
129
130 //=======================================================================
131 //function : IsVClosed
132 //purpose  : 
133 //=======================================================================
134
135 Standard_Boolean Geom_CylindricalSurface::IsVClosed () const       { return Standard_False; }
136
137 //=======================================================================
138 //function : IsUPeriodic
139 //purpose  : 
140 //=======================================================================
141
142 Standard_Boolean Geom_CylindricalSurface::IsUPeriodic () const     { return Standard_True; }
143
144 //=======================================================================
145 //function : IsVPeriodic
146 //purpose  : 
147 //=======================================================================
148
149 Standard_Boolean Geom_CylindricalSurface::IsVPeriodic () const     { return Standard_False; }
150
151 //=======================================================================
152 //function : SetCylinder
153 //purpose  : 
154 //=======================================================================
155
156 void Geom_CylindricalSurface::SetCylinder (const gp_Cylinder& C) {
157
158    radius = C.Radius();
159    pos = C.Position();
160 }
161
162
163 //=======================================================================
164 //function : SetRadius
165 //purpose  : 
166 //=======================================================================
167
168 void Geom_CylindricalSurface::SetRadius (const Standard_Real R) {
169
170   if (R < 0.0) { throw Standard_ConstructionError(); }
171   radius = R;
172 }
173
174
175 //=======================================================================
176 //function : Bounds
177 //purpose  : 
178 //=======================================================================
179
180 void Geom_CylindricalSurface::Bounds (Standard_Real& U1, Standard_Real& U2, 
181                                       Standard_Real& V1, Standard_Real& V2) const {
182
183    U1 = 0.0;  U2 = 2.0 * M_PI;
184    V1 = - Precision::Infinite();   V2 = Precision::Infinite();
185 }
186
187
188 //=======================================================================
189 //function : Coefficients
190 //purpose  : 
191 //=======================================================================
192
193 void Geom_CylindricalSurface::Coefficients (Standard_Real& A1, Standard_Real& A2, Standard_Real& A3, 
194                                             Standard_Real& B1, Standard_Real& B2, Standard_Real& B3, 
195                                             Standard_Real& C1, Standard_Real& C2, Standard_Real& C3, 
196                                             Standard_Real& D) const {
197 // Dans le repere local du cylindre :
198 // X**2 + Y**2 - radius = 0.0
199
200   Trsf T;
201   T.SetTransformation (pos);
202   Standard_Real T11 = T.Value (1, 1);
203   Standard_Real T12 = T.Value (1, 2);
204   Standard_Real T13 = T.Value (1, 3);
205   Standard_Real T14 = T.Value (1, 4);
206   Standard_Real T21 = T.Value (2, 1);
207   Standard_Real T22 = T.Value (2, 2);
208   Standard_Real T23 = T.Value (2, 3);
209   Standard_Real T24 = T.Value (2, 4);
210   A1 = T11 * T11 + T21 * T21;
211   A2 = T12 * T12 + T22 * T22;
212   A3 = T13 * T13 + T23 * T23;
213   B1 = T11 * T12 + T21 * T22;
214   B2 = T11 * T13 + T21 * T23;
215   B3 = T12 * T13 + T22 * T23;
216   C1 = T11 * T14 + T21 * T24;
217   C2 = T12 * T14 + T22 * T24;
218   C3 = T13 * T14 + T23 * T24;
219   D = T14 * T14 + T24 * T24 - radius * radius;  
220 }
221
222
223
224 //=======================================================================
225 //function : Cylinder
226 //purpose  : 
227 //=======================================================================
228
229 gp_Cylinder Geom_CylindricalSurface::Cylinder () const {
230   
231   return gp_Cylinder (pos, radius);
232 }
233
234
235 //=======================================================================
236 //function : D0
237 //purpose  : 
238 //=======================================================================
239
240 void Geom_CylindricalSurface::D0 (const Standard_Real U, 
241                                   const Standard_Real V,
242                                         Pnt& P ) const 
243 {
244   ElSLib::CylinderD0 (U, V, pos, radius, P);
245 }
246
247
248 //=======================================================================
249 //function : D1
250 //purpose  : 
251 //=======================================================================
252
253 void Geom_CylindricalSurface::D1 (const Standard_Real U, const Standard_Real V , 
254                                         Pnt& P, 
255                                         Vec& D1U,     Vec& D1V) const 
256 {
257   ElSLib::CylinderD1 (U, V, pos, radius, P, D1U, D1V);
258 }
259
260
261
262 //=======================================================================
263 //function : D2
264 //purpose  : 
265 //=======================================================================
266
267 void Geom_CylindricalSurface::D2 (const Standard_Real U, const Standard_Real V, 
268                                   Pnt& P,
269                                   Vec& D1U, Vec& D1V,
270                                   Vec& D2U, Vec& D2V, Vec& D2UV) const 
271 {
272   ElSLib::CylinderD2 (U, V, pos, radius, P, D1U, D1V, D2U, D2V, D2UV);
273 }
274
275
276
277 //=======================================================================
278 //function : D3
279 //purpose  : 
280 //=======================================================================
281
282 void Geom_CylindricalSurface::D3 (const Standard_Real U, const Standard_Real V,
283                                   Pnt& P, 
284                                   Vec& D1U, Vec& D1V, 
285                                   Vec& D2U, Vec& D2V, Vec& D2UV,
286                                   Vec& D3U, Vec& D3V, Vec& D3UUV, Vec& D3UVV) 
287                                   const 
288 {
289   ElSLib::CylinderD3 (U, V, pos, radius, P, D1U, D1V, D2U, D2V,
290                       D2UV, D3U, D3V, D3UUV, D3UVV);
291 }
292
293
294 //=======================================================================
295 //function : DN
296 //purpose  : 
297 //=======================================================================
298
299 Vec Geom_CylindricalSurface::DN (const Standard_Real    U , const Standard_Real    V , 
300                                  const Standard_Integer Nu, const Standard_Integer Nv ) const 
301 {
302   Standard_RangeError_Raise_if (Nu + Nv < 1 || Nu < 0 || Nv <0, " ");
303
304   if (Nv > 1) { return Vec (0.0, 0.0, 0.0); }
305   else {
306     return ElSLib::CylinderDN (U, V, pos, radius, Nu, Nv);
307   }
308 }
309
310
311
312
313 //=======================================================================
314 //function : UIso
315 //purpose  : 
316 //=======================================================================
317
318 Handle(Geom_Curve) Geom_CylindricalSurface::UIso (const Standard_Real U) const 
319 {
320   Handle(Geom_Line) GL = new Geom_Line(ElSLib::CylinderUIso(pos,radius,U));
321   return GL;
322 }
323
324
325
326 //=======================================================================
327 //function : VIso
328 //purpose  : 
329 //=======================================================================
330
331 Handle(Geom_Curve) Geom_CylindricalSurface::VIso (const Standard_Real V) const 
332 {
333   Handle(Geom_Circle) GC = new Geom_Circle(ElSLib::CylinderVIso(pos,radius,V));
334   return GC;
335 }
336
337
338
339 //=======================================================================
340 //function : Transform
341 //purpose  : 
342 //=======================================================================
343
344 void Geom_CylindricalSurface::Transform (const Trsf& T) {
345
346    radius = radius * Abs(T.ScaleFactor());
347    pos.Transform (T);
348 }
349
350 //=======================================================================
351 //function : TransformParameters
352 //purpose  : 
353 //=======================================================================
354
355 void Geom_CylindricalSurface::TransformParameters(Standard_Real& ,
356                                                   Standard_Real& V,
357                                                   const gp_Trsf& T) 
358 const
359 {
360   if (!Precision::IsInfinite(V)) V *= Abs(T.ScaleFactor());
361 }
362
363 //=======================================================================
364 //function : ParametricTransformation
365 //purpose  : 
366 //=======================================================================
367
368 gp_GTrsf2d Geom_CylindricalSurface::ParametricTransformation(const gp_Trsf& T)
369 const
370 {
371   gp_GTrsf2d T2;
372   gp_Ax2d Axis(gp::Origin2d(),gp::DX2d());
373   T2.SetAffinity(Axis, Abs(T.ScaleFactor()));
374   return T2;
375 }
376
377 //=======================================================================
378 //function : DumpJson
379 //purpose  : 
380 //=======================================================================
381 void Geom_CylindricalSurface::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
382 {
383   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
384
385   OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Geom_ElementarySurface)
386
387   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, radius)
388 }