0026912: CLang 3.6.2 compiler warning [-Winconsistent-missing-override]
[occt.git] / src / Contap / Contap_SurfProps.cxx
1 // Created on: 1995-02-24
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1995-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 <Adaptor3d_HSurface.hxx>
19 #include <Adaptor3d_HSurfaceTool.hxx>
20 #include <Contap_SurfProps.hxx>
21 #include <ElSLib.hxx>
22 #include <gp_Pnt.hxx>
23 #include <gp_Vec.hxx>
24
25 //=======================================================================
26 //function : Normale
27 //purpose  : 
28 //=======================================================================
29 void Contap_SurfProps::Normale(const Handle(Adaptor3d_HSurface)& S, 
30                                const Standard_Real U, 
31                                const Standard_Real V,
32                                gp_Pnt& P,
33                                gp_Vec& Norm)
34 {
35
36   GeomAbs_SurfaceType typS = Adaptor3d_HSurfaceTool::GetType(S);
37   switch (typS) {
38   case GeomAbs_Plane:
39     {
40       gp_Pln pl(Adaptor3d_HSurfaceTool::Plane(S));
41       Norm = pl.Axis().Direction();
42       P = ElSLib::Value(U,V,pl);
43       if (!pl.Direct()) {
44         Norm.Reverse();
45       }
46     }
47     break;
48
49
50   case GeomAbs_Sphere:
51     {
52       gp_Sphere sp(Adaptor3d_HSurfaceTool::Sphere(S));
53       P = ElSLib::Value(U,V,sp);
54       Norm = gp_Vec(sp.Location(),P);
55       if (sp.Direct()) {
56         Norm.Divide(sp.Radius());
57       }
58       else {
59         Norm.Divide(-sp.Radius());
60       }
61     }
62     break;
63
64   case GeomAbs_Cylinder:
65     {
66       gp_Cylinder cy(Adaptor3d_HSurfaceTool::Cylinder(S));
67       P = ElSLib::Value(U,V,cy);
68       Norm.SetLinearForm(Cos(U),cy.XAxis().Direction(),
69         Sin(U),cy.YAxis().Direction());
70       if (!cy.Direct()) {
71         Norm.Reverse();
72       }
73     }
74     break;
75
76
77   case GeomAbs_Cone:
78     {
79       gp_Cone co(Adaptor3d_HSurfaceTool::Cone(S));
80       P = ElSLib::Value(U,V,co);
81       Standard_Real Angle = co.SemiAngle();
82       Standard_Real Sina = sin(Angle);
83       Standard_Real Cosa = cos(Angle);
84       Standard_Real Rad = co.RefRadius(); 
85
86       Standard_Real Vcalc = V;
87       if (Abs(V*Sina + Rad) <= 1e-12) { // on est a l`apex
88         /*
89         Standard_Real Vfi = Adaptor3d_HSurfaceTool::FirstVParameter(S);
90         if (Vfi < -Rad/Sina) { // partie valide pour V < Vapex
91         Vcalc = V - 1;
92         }
93         else {
94         Vcalc = V + 1.;
95         }
96         */
97         Norm.SetCoord(0,0,0);
98         return;
99       }
100
101       if (Rad + Vcalc*Sina < 0.) {
102         Norm.SetLinearForm(Sina,       co.Axis().Direction(),
103           Cosa*cos(U),co.XAxis().Direction(),
104           Cosa*sin(U),co.YAxis().Direction());
105       }
106       else {
107         Norm.SetLinearForm(-Sina,       co.Axis().Direction(),
108           Cosa*cos(U),co.XAxis().Direction(),
109           Cosa*sin(U),co.YAxis().Direction());
110       }
111       if (!co.Direct()) {
112         Norm.Reverse();
113       }
114     }
115     break;
116   default:
117     {
118       gp_Vec d1u,d1v;
119       Adaptor3d_HSurfaceTool::D1(S,U,V,P,d1u,d1v);
120       Norm = d1u.Crossed(d1v);
121     }
122     break;
123
124
125   }
126 }
127
128
129 //=======================================================================
130 //function : DerivAndNorm
131 //purpose  : 
132 //=======================================================================
133
134 void Contap_SurfProps::DerivAndNorm(const Handle(Adaptor3d_HSurface)& S, 
135                                     const Standard_Real U, 
136                                     const Standard_Real V,
137                                     gp_Pnt& P,
138                                     gp_Vec& d1u,
139                                     gp_Vec& d1v,
140                                     gp_Vec& Norm)
141 {
142
143   GeomAbs_SurfaceType typS = Adaptor3d_HSurfaceTool::GetType(S);
144   switch (typS) {
145   case GeomAbs_Plane:
146     {
147       gp_Pln pl(Adaptor3d_HSurfaceTool::Plane(S));
148       Norm = pl.Axis().Direction();
149       ElSLib::D1(U,V,pl,P,d1u,d1v);
150       if (!pl.Direct()) {
151         Norm.Reverse();
152       }
153     }
154     break;
155
156
157   case GeomAbs_Sphere:
158     {
159       gp_Sphere sp(Adaptor3d_HSurfaceTool::Sphere(S));
160       ElSLib::D1(U,V,sp,P,d1u,d1v);
161       Norm = gp_Vec(sp.Location(),P);
162       if (sp.Direct()) {
163         Norm.Divide(sp.Radius());
164       }
165       else {
166         Norm.Divide(-sp.Radius());
167       }
168     }
169     break;
170
171   case GeomAbs_Cylinder:
172     {
173       gp_Cylinder cy(Adaptor3d_HSurfaceTool::Cylinder(S));
174       ElSLib::D1(U,V,cy,P,d1u,d1v);
175       Norm.SetLinearForm(Cos(U),cy.XAxis().Direction(),
176         Sin(U),cy.YAxis().Direction());
177       if (!cy.Direct()) {
178         Norm.Reverse();
179       }
180     }
181     break;
182
183
184   case GeomAbs_Cone:
185     {
186       gp_Cone co(Adaptor3d_HSurfaceTool::Cone(S));
187       ElSLib::D1(U,V,co,P,d1u,d1v);
188       Standard_Real Angle = co.SemiAngle();
189       Standard_Real Sina = Sin(Angle);
190       Standard_Real Cosa = Cos(Angle);
191       Standard_Real Rad = co.RefRadius(); 
192
193       Standard_Real Vcalc = V;
194       if (Abs(V*Sina + Rad) <= RealEpsilon()) { // on est a l`apex
195         Standard_Real Vfi = Adaptor3d_HSurfaceTool::FirstVParameter(S);
196         if (Vfi < -Rad/Sina) { // partie valide pour V < Vapex
197           Vcalc = V - 1;
198         }
199         else {
200           Vcalc = V + 1.;
201         }
202       }
203
204       if (Rad + Vcalc*Sina < 0.) {
205         Norm.SetLinearForm(Sina,       co.Axis().Direction(),
206           Cosa*Cos(U),co.XAxis().Direction(),
207           Cosa*Sin(U),co.YAxis().Direction());
208       }
209       else {
210         Norm.SetLinearForm(-Sina,       co.Axis().Direction(),
211           Cosa*Cos(U),co.XAxis().Direction(),
212           Cosa*Sin(U),co.YAxis().Direction());
213       }
214       if (!co.Direct()) {
215         Norm.Reverse();
216       }
217     }
218     break;
219   default:
220     {
221       Adaptor3d_HSurfaceTool::D1(S,U,V,P,d1u,d1v);
222       Norm = d1u.Crossed(d1v);
223     }
224     break;
225   }
226 }
227
228
229 //=======================================================================
230 //function : NormAndDn
231 //purpose  : 
232 //=======================================================================
233
234 void Contap_SurfProps::NormAndDn(const Handle(Adaptor3d_HSurface)& S, 
235                                  const Standard_Real U, 
236                                  const Standard_Real V,
237                                  gp_Pnt& P,
238                                  gp_Vec& Norm,
239                                  gp_Vec& Dnu,
240                                  gp_Vec& Dnv)
241 {
242
243   GeomAbs_SurfaceType typS = Adaptor3d_HSurfaceTool::GetType(S);
244   switch (typS) {
245   case GeomAbs_Plane:
246     {
247       gp_Pln pl(Adaptor3d_HSurfaceTool::Plane(S));
248       P = ElSLib::Value(U,V,pl);
249       Norm = pl.Axis().Direction();
250       if (!pl.Direct()) {
251         Norm.Reverse();
252       }
253       Dnu = Dnv = gp_Vec(0.,0.,0.);
254     }
255     break;
256
257   case GeomAbs_Sphere:
258     {
259       gp_Sphere sp(Adaptor3d_HSurfaceTool::Sphere(S));
260       ElSLib::D1(U,V,sp,P,Dnu,Dnv);
261       Norm = gp_Vec(sp.Location(),P);
262       Standard_Real Rad = sp.Radius();
263       if (!sp.Direct()) {
264         Rad = -Rad;
265       }
266       Norm.Divide(Rad);
267       Dnu.Divide(Rad);
268       Dnv.Divide(Rad);
269     }
270     break;
271
272   case GeomAbs_Cylinder:
273     {
274       gp_Cylinder cy(Adaptor3d_HSurfaceTool::Cylinder(S));
275       P = ElSLib::Value(U,V,cy);
276       Norm.SetLinearForm(Cos(U),cy.XAxis().Direction(),
277         Sin(U),cy.YAxis().Direction());
278       Dnu.SetLinearForm(-Sin(U),cy.XAxis().Direction(),
279         Cos(U),cy.YAxis().Direction());
280       if (!cy.Direct()) {
281         Norm.Reverse();
282         Dnu.Reverse();
283       }
284       Dnv = gp_Vec(0.,0.,0.);
285     }
286     break;
287
288   case GeomAbs_Cone:
289     {
290
291       gp_Cone co(Adaptor3d_HSurfaceTool::Cone(S));
292       P = ElSLib::Value(U,V,co);
293       Standard_Real Angle = co.SemiAngle();
294       Standard_Real Sina = Sin(Angle);
295       Standard_Real Cosa = Cos(Angle);
296       Standard_Real Rad = co.RefRadius(); 
297       Standard_Real Vcalc = V;
298       if (Abs(V*Sina + Rad) <= RealEpsilon()) { // on est a l`apex
299         Standard_Real Vfi = Adaptor3d_HSurfaceTool::FirstVParameter(S);
300         if (Vfi < -Rad/Sina) { // partie valide pour V < Vapex
301           Vcalc = V - 1;
302         }
303         else {
304           Vcalc = V + 1.;
305         }
306       }
307
308       if (Rad + Vcalc*Sina < 0.) {
309         Norm.SetLinearForm(Sina,       co.Axis().Direction(),
310           Cosa*Cos(U),co.XAxis().Direction(),
311           Cosa*Sin(U),co.YAxis().Direction());
312       }
313       else {
314         Norm.SetLinearForm(-Sina,       co.Axis().Direction(),
315           Cosa*Cos(U),co.XAxis().Direction(),
316           Cosa*Sin(U),co.YAxis().Direction());
317       }
318       Dnu.SetLinearForm(-Cosa*Sin(U),co.XAxis().Direction(),
319         Cosa*Cos(U),co.YAxis().Direction());
320       if (!co.Direct()) {
321         Norm.Reverse();
322         Dnu.Reverse();
323       }
324       Dnv = gp_Vec(0.,0.,0.);
325     }
326     break;
327
328   default: 
329     {
330       gp_Vec d1u,d1v,d2u,d2v,d2uv;
331       Adaptor3d_HSurfaceTool::D2(S,U,V,P,d1u,d1v,d2u,d2v,d2uv);
332       Norm = d1u.Crossed(d1v);
333       Dnu = d2u.Crossed(d1v) + d1u.Crossed(d2uv);
334       Dnv = d2uv.Crossed(d1v) + d1u.Crossed(d2v);
335     }
336     break;
337   }
338 }