0024171: Eliminate CLang compiler warning -Wreorder
[occt.git] / src / IntSurf / IntSurf_Quadric.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19#include <IntSurf_Quadric.ixx>
20#include <StdFail_NotDone.hxx>
21
22#include <ElCLib.hxx>
23#include <ElSLib.hxx>
24#include <gp.hxx>
25
26
27
28// ============================================================
29IntSurf_Quadric::IntSurf_Quadric ():typ(GeomAbs_OtherSurface),
30 prm1(0.), prm2(0.), prm3(0.), prm4(0.)
31{}
32// ============================================================
33IntSurf_Quadric::IntSurf_Quadric (const gp_Pln& P):
34 ax3(P.Position()),typ(GeomAbs_Plane)
35{
36 ax3direc = ax3.Direct();
37 P.Coefficients(prm1,prm2,prm3,prm4);
38}
39// ============================================================
40IntSurf_Quadric::IntSurf_Quadric (const gp_Cylinder& C):
41
42 ax3(C.Position()),lin(ax3.Axis()),typ(GeomAbs_Cylinder)
43{
44 prm2=prm3=prm4=0.0;
45 ax3direc=ax3.Direct();
46 prm1=C.Radius();
47}
48// ============================================================
49IntSurf_Quadric::IntSurf_Quadric (const gp_Sphere& S):
50
51 ax3(S.Position()),lin(ax3.Axis()),typ(GeomAbs_Sphere)
52{
53 prm2=prm3=prm4=0.0;
54 ax3direc = ax3.Direct();
55 prm1=S.Radius();
56}
57// ============================================================
58IntSurf_Quadric::IntSurf_Quadric (const gp_Cone& C):
59
60 ax3(C.Position()),typ(GeomAbs_Cone)
61{
62 ax3direc = ax3.Direct();
63 lin.SetPosition(ax3.Axis());
64 prm1 = C.RefRadius();
65 prm2 = C.SemiAngle();
66 prm3 = Cos(prm2);
67 prm4 = 0.0;
68}
69// ============================================================
70void IntSurf_Quadric::SetValue (const gp_Pln& P)
71{
72 typ = GeomAbs_Plane;
73 ax3 = P.Position();
74 ax3direc = ax3.Direct();
75 P.Coefficients(prm1,prm2,prm3,prm4);
76}
77// ============================================================
78void IntSurf_Quadric::SetValue (const gp_Cylinder& C)
79{
80 typ = GeomAbs_Cylinder;
81 ax3 = C.Position();
82 ax3direc = ax3.Direct();
83 lin.SetPosition(ax3.Axis());
84 prm1 = C.Radius();
85 prm2=prm3=prm4=0.0;
86}
87// ============================================================
88void IntSurf_Quadric::SetValue (const gp_Sphere& S)
89{
90 typ = GeomAbs_Sphere;
91 ax3 = S.Position();
92 ax3direc = ax3.Direct();
93 lin.SetPosition(ax3.Axis());
94 prm1 = S.Radius();
95 prm2=prm3=prm4=0.0;
96}
97// ============================================================
98void IntSurf_Quadric::SetValue (const gp_Cone& C)
99{
100 typ = GeomAbs_Cone;
101 ax3 = C.Position();
102 ax3direc = ax3.Direct();
103 lin.SetPosition(ax3.Axis());
104 prm1 = C.RefRadius();
105 prm2 = C.SemiAngle();
106 prm3 = Cos(prm2);
107 prm4 = 0.0;
108}
109// ============================================================
110Standard_Real IntSurf_Quadric::Distance (const gp_Pnt& P) const {
111 switch (typ) {
112 case GeomAbs_Plane: // plan
113 return prm1*P.X() + prm2*P.Y() + prm3*P.Z() + prm4;
114 case GeomAbs_Cylinder: // cylindre
115 return (lin.Distance(P) - prm1);
116 case GeomAbs_Sphere: // sphere
117 return (lin.Location().Distance(P) - prm1);
118 case GeomAbs_Cone: // cone
119 {
120 Standard_Real dist = lin.Distance(P);
121 Standard_Real U,V;
122 ElSLib::ConeParameters(ax3,prm1,prm2,P,U,V);
123 gp_Pnt Pp = ElSLib::ConeValue(U,V,ax3,prm1,prm2);
124 Standard_Real distp = lin.Distance(Pp);
125 dist = (dist-distp)/prm3;
126 return(dist);
127 }
128 default:
129 {
130 }
131 break;
132 }
133 return(0.0);
134}
135// ============================================================
136gp_Vec IntSurf_Quadric::Gradient (const gp_Pnt& P) const {
137 gp_Vec grad;
138 switch (typ) {
139 case GeomAbs_Plane: // plan
140 grad.SetCoord(prm1,prm2,prm3);
141 break;
142 case GeomAbs_Cylinder: // cylindre
143 {
144 gp_XYZ PP(lin.Location().XYZ());
145 PP.Add(ElCLib::Parameter(lin,P)*lin.Direction().XYZ());
146 grad.SetXYZ(P.XYZ()-PP);
147 Standard_Real N = grad.Magnitude();
148 if(N>1e-14) { grad.Divide(N); }
149 else { grad.SetCoord(0.0,0.0,0.0); }
150 }
151 break;
152 case GeomAbs_Sphere: // sphere
153 {
154 gp_XYZ PP(P.XYZ());
155 grad.SetXYZ((PP-lin.Location().XYZ()));
156 Standard_Real N = grad.Magnitude();
157 if(N>1e-14) { grad.Divide(N); }
158 else { grad.SetCoord(0.0,0.0,0.0); }
159 }
160 break;
161 case GeomAbs_Cone: // cone
162 {
163 Standard_Real U,V;
164 ElSLib::ConeParameters(ax3,prm1,prm2,P,U,V);
165 gp_Pnt Pp = ElSLib::ConeValue(U,V,ax3,prm1,prm2);
166 gp_Vec D1u,D1v;
167 ElSLib::ConeD1(U,V,ax3,prm1,prm2,Pp,D1u,D1v);
168 grad=D1u.Crossed(D1v);
169 if(ax3direc==Standard_False) {
170 grad.Reverse();
171 }
172 grad.Normalize();
173 }
174 break;
175 default:
176 {}
177 break;
178 }
179 return grad;
180}
181// ============================================================
182void IntSurf_Quadric::ValAndGrad (const gp_Pnt& P,
183 Standard_Real& Dist,
184 gp_Vec& Grad) const
185{
186
187 switch (typ) {
188 case GeomAbs_Plane:
189 {
190 Dist = prm1*P.X() + prm2*P.Y() + prm3*P.Z() + prm4;
191 Grad.SetCoord(prm1,prm2,prm3);
192 }
193 break;
194 case GeomAbs_Cylinder:
195 {
196 Dist = lin.Distance(P) - prm1;
197 gp_XYZ PP(lin.Location().XYZ());
198 PP.Add(ElCLib::Parameter(lin,P)*lin.Direction().XYZ());
199 Grad.SetXYZ((P.XYZ()-PP));
200 Standard_Real N = Grad.Magnitude();
201 if(N>1e-14) { Grad.Divide(N); }
202 else { Grad.SetCoord(0.0,0.0,0.0); }
203 }
204 break;
205 case GeomAbs_Sphere:
206 {
207 Dist = lin.Location().Distance(P) - prm1;
208 gp_XYZ PP(P.XYZ());
209 Grad.SetXYZ((PP-lin.Location().XYZ()));
210 Standard_Real N = Grad.Magnitude();
211 if(N>1e-14) { Grad.Divide(N); }
212 else { Grad.SetCoord(0.0,0.0,0.0); }
213 }
214 break;
215 case GeomAbs_Cone:
216 {
217 Standard_Real dist = lin.Distance(P);
218 Standard_Real U,V;
219 gp_Vec D1u,D1v;
220 gp_Pnt Pp;
221 ElSLib::ConeParameters(ax3,prm1,prm2,P,U,V);
222 ElSLib::ConeD1(U,V,ax3,prm1,prm2,Pp,D1u,D1v);
223 Standard_Real distp = lin.Distance(Pp);
224 dist = (dist-distp)/prm3;
225 Dist = dist;
226 Grad=D1u.Crossed(D1v);
227 if(ax3direc==Standard_False) {
228 Grad.Reverse();
229 }
230 //-- lbr le 7 mars 96
231 //-- Si le gardient est nul, on est sur l axe
232 //-- et dans ce cas dist vaut 0
233 //-- On peut donc renvoyer une valeur quelconque.
234 if( Grad.X() > 1e-13
235 || Grad.Y() > 1e-13
236 || Grad.Z() > 1e-13) {
237 Grad.Normalize();
238 }
239 }
240 break;
241 default:
242 {}
243 break;
244 }
245}
246// ============================================================
247gp_Pnt IntSurf_Quadric::Value(const Standard_Real U,
248 const Standard_Real V) const
249{
250 switch (typ) {
251
252 case GeomAbs_Plane:
253 return ElSLib::PlaneValue(U,V,ax3);
254 case GeomAbs_Cylinder:
255 return ElSLib::CylinderValue(U,V,ax3,prm1);
256 case GeomAbs_Sphere:
257 return ElSLib::SphereValue(U,V,ax3,prm1);
258 case GeomAbs_Cone:
259 return ElSLib::ConeValue(U,V,ax3,prm1,prm2);
260 default:
261 {
262 gp_Pnt p(0,0,0);
263 return(p);
264 }
d3f26155 265 //break;
7fd59977 266 }
267// pop : pour NT
d3f26155 268// return gp_Pnt(0,0,0);
7fd59977 269}
270// ============================================================
271void IntSurf_Quadric::D1(const Standard_Real U,
272 const Standard_Real V,
273 gp_Pnt& P,
274 gp_Vec& D1U,
275 gp_Vec& D1V) const
276{
277 switch (typ) {
278 case GeomAbs_Plane:
279 ElSLib::PlaneD1(U,V,ax3,P,D1U,D1V);
280 break;
281 case GeomAbs_Cylinder:
282 ElSLib::CylinderD1(U,V,ax3,prm1,P,D1U,D1V);
283 break;
284 case GeomAbs_Sphere:
285 ElSLib::SphereD1(U,V,ax3,prm1,P,D1U,D1V);
286 break;
287 case GeomAbs_Cone:
288 ElSLib::ConeD1(U,V,ax3,prm1,prm2,P,D1U,D1V);
289 break;
290 default:
291 {
292 }
293 break;
294 }
295}
296// ============================================================
297gp_Vec IntSurf_Quadric::DN(const Standard_Real U,
298 const Standard_Real V,
299 const Standard_Integer Nu,
300 const Standard_Integer Nv) const
301{
302 switch (typ) {
303 case GeomAbs_Plane:
304 return ElSLib::PlaneDN(U,V,ax3,Nu,Nv);
305 case GeomAbs_Cylinder:
306 return ElSLib::CylinderDN(U,V,ax3,prm1,Nu,Nv);
307 case GeomAbs_Sphere:
308 return ElSLib::SphereDN(U,V,ax3,prm1,Nu,Nv);
309 case GeomAbs_Cone:
310 return ElSLib::ConeDN(U,V,ax3,prm1,prm2,Nu,Nv);
311 default:
312 {
313 gp_Vec v(0,0,0);
314 return(v);
315 }
d3f26155 316 //break;
7fd59977 317 }
318// pop : pour NT
d3f26155 319// return gp_Vec(0,0,0);
7fd59977 320}
321// ============================================================
322gp_Vec IntSurf_Quadric::Normale(const Standard_Real U,
323 const Standard_Real V) const
324{
325 switch (typ) {
326 case GeomAbs_Plane:
327 if(ax3direc)
328 return ax3.Direction();
329 else
330 return ax3.Direction().Reversed();
331 case GeomAbs_Cylinder:
332 return Normale(Value(U,V));
333 case GeomAbs_Sphere:
334 return Normale(Value(U,V));
335 case GeomAbs_Cone:
336 {
337 gp_Pnt P;
338 gp_Vec D1u,D1v;
339 ElSLib::ConeD1(U,V,ax3,prm1,prm2,P,D1u,D1v);
340 if(D1u.Magnitude()<0.0000001) {
341 gp_Vec Vn(0.0,0.0,0.0);
342 return(Vn);
343 }
344 return(D1u.Crossed(D1v));
345 }
346 default:
347 {
348 gp_Vec v(0,0,0);
349 return(v);
350 }
d3f26155 351 // break;
7fd59977 352 }
353// pop : pour NT
d3f26155 354// return gp_Vec(0,0,0);
7fd59977 355}
356// ============================================================
357gp_Vec IntSurf_Quadric::Normale (const gp_Pnt& P) const
358{
359 switch (typ) {
360 case GeomAbs_Plane:
361 if(ax3direc)
362 return ax3.Direction();
363 else
364 return ax3.Direction().Reversed();
365 case GeomAbs_Cylinder:
366 {
367 if(ax3direc) {
368 return lin.Normal(P).Direction();
369 }
370 else {
371 gp_Dir D(lin.Normal(P).Direction());
372 D.Reverse();
373 return(D);
374 }
375 }
376 case GeomAbs_Sphere:
377 {
378 if(ax3direc) {
379 gp_Vec ax3P(ax3.Location(),P);
380 return gp_Dir(ax3P);
381 }
382 else {
383 gp_Vec Pax3(P,ax3.Location());
384 return gp_Dir(Pax3);
385 }
386 }
387 case GeomAbs_Cone:
388 {
389 Standard_Real U,V;
390 ElSLib::ConeParameters(ax3,prm1,prm2,P,U,V);
391 return Normale(U,V);;
392 }
393 default:
394 {
395 gp_Vec v(0,0,0);
396 return(v);
d3f26155 397 } // break;
7fd59977 398 }
7fd59977 399}
400// ============================================================
401void IntSurf_Quadric::Parameters (const gp_Pnt& P,
402 Standard_Real& U,
403 Standard_Real& V) const
404{
405 switch (typ) {
406 case GeomAbs_Plane:
407 ElSLib::PlaneParameters(ax3,P,U,V);
408 break;
409 case GeomAbs_Cylinder:
410 ElSLib::CylinderParameters(ax3,prm1,P,U,V);
411 break;
412 case GeomAbs_Sphere:
413 ElSLib::SphereParameters(ax3,prm1,P,U,V);
414 break;
415 case GeomAbs_Cone:
416 {
417 ElSLib::ConeParameters(ax3,prm1,prm2,P,U,V);
418 }
419 break;
420 default:
421 {}
422 break;
423 }
424}
425// ============================================================
426
427
428
429
430