0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / IntAna / IntAna_Quadric.cxx
CommitLineData
b311480e 1// Created on: 1992-07-01
2// Created by: Laurent BUCHARD
3// Copyright (c) 1992-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
0797d9d3 17#ifndef OCCT_DEBUG
7fd59977 18#define No_Standard_RangeError
19#define No_Standard_OutOfRange
20#endif
21
42cf5bc1 22
23#include <gp_Ax3.hxx>
24#include <gp_Cone.hxx>
25#include <gp_Cylinder.hxx>
26#include <gp_Pln.hxx>
27#include <gp_Sphere.hxx>
7fd59977 28#include <gp_Trsf.hxx>
29#include <gp_Vec.hxx>
42cf5bc1 30#include <IntAna_Quadric.hxx>
3306fdd9 31#include <ElSLib.hxx>
7fd59977 32
33//----------------------------------------------------------------------
34//--
35//-- Equation generale des quadriques :
36//--
37//-- f(x,y,z) = CXX X**2 + CYY Y**2 + CZZ Z**2
38//--
39//-- + 2 ( CXY X Y + CXZ X Z + CYZ Y Z )
40//--
41//-- + 2 ( CX X + CY Y + CZ Z)
42//--
43//-- + CCte
44//--
45//--
46//----------------------------------------------------------------------
7fd59977 47//----------------------------------------------------------------------
48//-- Quadric Vide
49//----------------------------------------------------------------------
50IntAna_Quadric::IntAna_Quadric(void) {
51 CXX=CYY=CZZ=CXY=CXZ=CYZ=CX=CY=CZ=0.0; CCte=1.0;
52}
53//----------------------------------------------------------------------
54//-- Pln -----> Quadric
55//--
56//-- Coefficients sur gp_Pln retourne A,B,C,D
57//-- avec f(x,y,z) = A x + B y + C z + D
58//--
59//-- que l on identifie a 2( CX x + CY y + CZ z ) + CCte
60//----------------------------------------------------------------------
61void IntAna_Quadric::SetQuadric(const gp_Pln& P) {
62 P.Coefficients(CX,CY,CZ,CCte);
63 CX*=0.5;
64 CY*=0.5;
65 CZ*=0.5;
66 CXX=CYY=CZZ=CXY=CXZ=CYZ=0.0;
67}
68
69IntAna_Quadric::IntAna_Quadric(const gp_Pln& P) {
70 P.Coefficients(CX,CY,CZ,CCte);
71 CX*=0.5;
72 CY*=0.5;
73 CZ*=0.5;
74 CXX=CYY=CZZ=CXY=CXZ=CYZ=0.0;
75}
76//----------------------------------------------------------------------
77//-- Cylinder -----> Quadric
78//----------------------------------------------------------------------
79void IntAna_Quadric::SetQuadric(const gp_Cylinder& Cyl) {
80 Cyl.Coefficients(CXX,CYY,CZZ,CXY,CXZ,CYZ,CX,CY,CZ,CCte);
81}
82
83IntAna_Quadric::IntAna_Quadric(const gp_Cylinder& Cyl) {
84 Cyl.Coefficients(CXX,CYY,CZZ,CXY,CXZ,CYZ,CX,CY,CZ,CCte);
85}
86//----------------------------------------------------------------------
87//-- Cone -----> Quadric
88//----------------------------------------------------------------------
3306fdd9 89IntAna_Quadric::IntAna_Quadric(const gp_Cone& Cone)
90{
91 SetQuadric(Cone);
7fd59977 92}
93
94void IntAna_Quadric::SetQuadric(const gp_Cone& Cone) {
95 Cone.Coefficients(CXX,CYY,CZZ,CXY,CXZ,CYZ,CX,CY,CZ,CCte);
3306fdd9 96 const Standard_Real aVParam = -Cone.RefRadius() / Sin(Cone.SemiAngle());
97 mySpecialPoints.Append(ElSLib::Value(0.0, aVParam, Cone));
7fd59977 98}
99//----------------------------------------------------------------------
100//-- Sphere -----> Quadric
101//----------------------------------------------------------------------
102void IntAna_Quadric::SetQuadric(const gp_Sphere& Sph) {
103 Sph.Coefficients(CXX,CYY,CZZ,CXY,CXZ,CYZ,CX,CY,CZ,CCte);
3306fdd9 104 mySpecialPoints.Append(ElSLib::Value(0.0, -M_PI_2, Sph));
105 mySpecialPoints.Append(ElSLib::Value(0.0, M_PI_2, Sph));
7fd59977 106}
107
108IntAna_Quadric::IntAna_Quadric(const gp_Sphere& Sph) {
3306fdd9 109 SetQuadric(Sph);
7fd59977 110}
111//----------------------------------------------------------------------
112//-- Returns the Coefficients of the Quadric
113//----------------------------------------------------------------------
114void IntAna_Quadric::Coefficients(Standard_Real& _CXX,Standard_Real& _CYY,Standard_Real& _CZZ,
115 Standard_Real& _CXY,Standard_Real& _CXZ,Standard_Real& _CYZ,
116 Standard_Real& _CX, Standard_Real& _CY, Standard_Real& _CZ,
117 Standard_Real& _CCte) const
118{
119 _CXX=CXX; _CYY=CYY; _CZZ=CZZ;
120 _CXY=CXY; _CXZ=CXZ; _CYZ=CYZ;
121 _CX=CX; _CY=CY; _CZ=CZ;
122 _CCte=CCte;
123}
124//----------------------------------------------------------------------
125//-- Computes the Coefficients in a new coordinate system
126//----------------------------------------------------------------------
127void IntAna_Quadric::NewCoefficients( Standard_Real& _CXX,Standard_Real& _CYY,Standard_Real& _CZZ
128 ,Standard_Real& _CXY,Standard_Real& _CXZ,Standard_Real& _CYZ
129 ,Standard_Real& _CX, Standard_Real& _CY, Standard_Real& _CZ
130 ,Standard_Real& _CCte
131 ,const gp_Ax3& Axis) const
132{
133 Standard_Real t11,t12,t13,t14; // x = t11 X + t12 Y + t13 Z + t14
134 Standard_Real t21,t22,t23,t24; // y = t21 X + t22 Y + t23 Z + t24
135 Standard_Real t31,t32,t33,t34; // z = t31 X + t32 Y + t33 Z + t34
136
137 // = X DirX + Y DirY + Z DirZ + Loc
138
139 Standard_Real Cxx,Cyy,Czz,Cxy,Cxz,Cyz,Cx,Cy,Cz,Ccte;
7fd59977 140
141 gp_Trsf Trans;
7fd59977 142 Trans.SetTransformation(Axis);
143 Trans.Invert();
144 t11=Trans.Value(1,1); t12=Trans.Value(1,2); t13=Trans.Value(1,3); t14=Trans.Value(1,4);
145 t21=Trans.Value(2,1); t22=Trans.Value(2,2); t23=Trans.Value(2,3); t24=Trans.Value(2,4);
146 t31=Trans.Value(3,1); t32=Trans.Value(3,2); t33=Trans.Value(3,3); t34=Trans.Value(3,4);
147
148
149 // P0(x,y,z)=_CXX x x + _CYY y y + ... + _CCte =0 (x,y,z "absolute" coordinates)
150 // and P1(X(x,y,z),Y(x,y,z),Z(x,y,z))=P0(x,y,z)
151 //
152 // with P1(X,Y,Z)= Cxx X X + Cyy Y Y + Czz Z Z + 2 Cxy X Y ... + Ccte
153 // = _CXX x x + _CYY y y + ... + _CCte
154
155 Standard_Real t11_P2=t11*t11; Standard_Real t21_P2=t21*t21; Standard_Real t31_P2=t31*t31;
156 Standard_Real t12_P2=t12*t12; Standard_Real t22_P2=t22*t22; Standard_Real t32_P2=t32*t32;
157 Standard_Real t13_P2=t13*t13; Standard_Real t23_P2=t23*t23; Standard_Real t33_P2=t33*t33;
158 Standard_Real t14_P2=t14*t14; Standard_Real t24_P2=t24*t24; Standard_Real t34_P2=t34*t34;
159
160 Ccte = ((_CCte)
161 + t14_P2* (_CXX)
162 + t24_P2* (_CYY)
163 + t34_P2* (_CZZ)
164 + 2.0 * ( t14*( (_CX)
165 +t24* (_CXY)
166 +t34* (_CXZ))
167 +t24*( (_CY)
168 +t34* (_CYZ))
169 +t34* (_CZ)));
170
171 Cxx = ( t11_P2* (_CXX)
172 + t21_P2* (_CYY)
173 + t31_P2* (_CZZ)
174 + 2.0*( t11*( t21* (_CXY)
175 +t31* (_CXZ))
176 +t21*t31* (_CYZ)));
177
178 Cyy = (t12_P2* (_CXX)
179 + t22_P2* (_CYY)
180 + t32_P2* (_CZZ)
181 + 2.0*( t12*( t22* (_CXY)
182 +t32* (_CXZ))
183 +t22*t32* (_CYZ)));
184
185 Czz = (t13_P2* (_CXX)
186 + t33_P2* (_CZZ)
187 + t23_P2* (_CYY)
188 + 2.0*( t13*( t23* (_CXY)
189 +t33* (_CXZ))
190 +t23*t33* (_CYZ)));
191
192 Cz = (t13* (_CX)
193 + t13*( t14* (_CXX)
194 + t24* (_CXY)
195 + t34* (_CXZ))
196 + t14*( t23* (_CXY)
197 +t33* (_CXZ))
198 + t23*( (_CY)
199 +t24* (_CYY)
200 +t34* (_CYZ))
201 + t33*( t24* (_CYZ)
202 +(_CZ)
203 + t34* (_CZZ)));
204
205 Cx = (t11* ((_CX)
206 +t14* (_CXX)
207 +t24* (_CXY)
208 +t34* (_CXZ))
209 + t14*( t21* (_CXY)
210 +t31* (_CXZ))
211 + t21*( (_CY)
212 +t24* (_CYY)
213 +t34* (_CYZ))
214 + t31*( t24* (_CYZ)
215 +(_CZ)
216 +t34* (_CZZ)));
217
218 Cxy = (t11*( t12* (_CXX)
219 +t22* (_CXY)
220 +t32* (_CXZ))
221 + t12*( t21* (_CXY)
222 +t31* (_CXZ))
223 + t21*( t22* (_CYY)
224 +t32* (_CYZ))
225 + t31*( t22* (_CYZ)
226 +t32* (_CZZ)));
227
228 Cxz = (t11*( t13* (_CXX)
229 +t23* (_CXY)
230 +t33* (_CXZ))
231 + t13*( t21* (_CXY)
232 +t31* (_CXZ))
233 + t21*( t23* (_CYY)
234 +t33* (_CYZ))
235 + t31*( t23* (_CYZ)
236 +t33* (_CZZ)));
237
238 Cy = (t12* ( (_CX)
239 +t14* (_CXX)
240 +t24* (_CXY)
241 +t34* (_CXZ))
242 + t14*( t22* (_CXY)
243 +t32* (_CXZ))
244 + t22*( (_CY)
245 +t24* (_CYY)
246 +t34* (_CYZ))
247 + t32*( (_CZ)
248 + t24* (_CYZ)
249 + t34* (_CZZ)));
250
251 Cyz = (t12*( t13* (_CXX)
252 +t23* (_CXY)
253 +t33* (_CXZ))
254 + t13*( t22* (_CXY)
255 +t32* (_CXZ))
256 + t22*( t23* (_CYY)
257 +t33* (_CYZ))
258 + t32*( t23* (_CYZ)
259 +t33* (_CZZ)));
260
261
262 _CXX=Cxx; _CYY=Cyy; _CZZ=Czz; _CX=Cx; _CY=Cy; _CZ=Cz;
263 _CXY=Cxy; _CXZ=Cxz; _CYZ=Cyz; _CCte=Ccte;
264
265
266}
267