0024057: Eliminate compiler warning C4100 in MSVC++ with warning level 4
[occt.git] / src / Visual3d / Visual3d_ViewOrientation.cxx
CommitLineData
b311480e 1// Created by: NW,JPB,CAL
2// Copyright (c) 1991-1999 Matra Datavision
3// Copyright (c) 1999-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
7fd59977 21
7fd59977 22
23//-Version
24
81bba717 25//-Design Declaration of variables specific to the orientation of views
7fd59977 26
81bba717 27//-Warning The view orientation is defined by :
28// - the point of origin of the reference mark
29// - the normal vector to the visualisation plane
30// - the vertical vector of the viewer
7fd59977 31
32//-References
33
34//-Language C++ 2.0
35
36//-Declarations
37
38// for the class
39#include <Visual3d_ViewOrientation.ixx>
40
41//-Aliases
42
43//-Global data definitions
44
45// -- le point origine du repere
46// MyViewReferencePoint : Vertex;
47
48// -- le vecteur normal au plan de visualisation
49// MyViewPlaneNormal : Vector;
50
51// -- le vecteur vertical de l'observateur
52// MyViewUpVector : Vector;
53
54//-Constructors
55
56//-Destructors
57
58//-Methods, in order
59
60Visual3d_ViewOrientation::Visual3d_ViewOrientation ():
61MyViewReferencePoint (0.0, 0.0, 0.0),
62MyViewPlaneNormal (0.0, 0.0, 1.0),
63MyViewUpVector (0.0, 1.0, 0.0),
64MyScaleX(1.0),
65MyScaleY(1.0),
66MyScaleZ(1.0) {
67}
68
69Visual3d_ViewOrientation::Visual3d_ViewOrientation (const Graphic3d_Vertex& VRP, const Graphic3d_Vector& VPN, const Graphic3d_Vector& VUP):
70MyViewReferencePoint (VRP),
71MyViewPlaneNormal (VPN),
72MyViewUpVector (VUP),
73MyScaleX(1.0),
74MyScaleY(1.0),
75MyScaleZ(1.0) {
76
77 if (Graphic3d_Vector::NormeOf (VPN) == 0.0)
78 Visual3d_ViewOrientationDefinitionError::Raise
79 ("Bad value for ViewPlaneNormal");
80
81 if (Graphic3d_Vector::NormeOf (VUP) == 0.0)
82 Visual3d_ViewOrientationDefinitionError::Raise
83 ("Bad value for ViewUpVector");
84
85 if (Graphic3d_Vector::IsParallel (VPN, VUP))
86 Visual3d_ViewOrientationDefinitionError::Raise
87 ("ViewPlaneNormal and ViewUpVector are parallel");
88
89}
90
35e08fe8 91Visual3d_ViewOrientation::Visual3d_ViewOrientation (const Graphic3d_Vertex& VRP, const Graphic3d_Vector& VPN, const Standard_Real /*Twist*/) {
7fd59977 92
93 if (Graphic3d_Vector::NormeOf (VPN) == 0.0)
94 Visual3d_ViewOrientationDefinitionError::Raise
95 ("Bad value for ViewPlaneNormal");
96
97 cout << "\nVisual3d_ViewOrientation : Not Yet Implemented\n\n" << flush;
98
99 MyViewReferencePoint = VRP;
100 MyViewPlaneNormal = VPN;
101
102}
103
35e08fe8 104Visual3d_ViewOrientation::Visual3d_ViewOrientation (const Graphic3d_Vertex& VRP, const Standard_Real /*Azim*/, const Standard_Real /*Inc*/, const Standard_Real /*Twist*/) {
7fd59977 105
106 cout << "\nVisual3d_ViewOrientation : Not Yet Implemented\n\n" << flush;
107
108 MyViewReferencePoint = VRP;
109
110}
111
112void Visual3d_ViewOrientation::SetViewReferencePoint (const Graphic3d_Vertex& VRP) {
113
114 MyViewReferencePoint = VRP;
115
116}
117
118Graphic3d_Vertex Visual3d_ViewOrientation::ViewReferencePoint () const {
119
120 return (MyViewReferencePoint);
121
122}
123
124void Visual3d_ViewOrientation::SetViewReferencePlane (const Graphic3d_Vector& VPN) {
125
126 if (Graphic3d_Vector::NormeOf (VPN) == 0.0)
127 Visual3d_ViewOrientationDefinitionError::Raise
128 ("Bad value for ViewPlaneNormal");
129
130 MyViewPlaneNormal = VPN;
131
132}
133
134Graphic3d_Vector Visual3d_ViewOrientation::ViewReferencePlane () const {
135
136 return (MyViewPlaneNormal);
137
138}
139
140void Visual3d_ViewOrientation::SetViewReferenceUp (const Graphic3d_Vector& VUP) {
141
142 if (Graphic3d_Vector::NormeOf (VUP) == 0.0)
143 Visual3d_ViewOrientationDefinitionError::Raise
144 ("Bad value for ViewUpVector");
145
146 MyViewUpVector = VUP;
147
148}
149
150void Visual3d_ViewOrientation::SetAxialScale (const Standard_Real Sx, const Standard_Real Sy, const Standard_Real Sz) {
151 if ( Sx <= 0. || Sy <= 0. || Sz <= 0. )
152 Visual3d_ViewOrientationDefinitionError::Raise
153 ("Bad value for ViewUpVector");
154 MyScaleX = Sx;
155 MyScaleY = Sy;
156 MyScaleZ = Sz;
157}
158
159Graphic3d_Vector Visual3d_ViewOrientation::ViewReferenceUp () const {
160
161 return (MyViewUpVector);
162
163}
164
165void Visual3d_ViewOrientation::Assign (const Visual3d_ViewOrientation& Other) {
166
167Standard_Real X, Y, Z;
168
169 (Other.ViewReferencePoint ()).Coord (X, Y, Z);
170 MyViewReferencePoint.SetCoord (X, Y, Z);
171
172 (Other.ViewReferencePlane ()).Coord (X, Y, Z);
173 MyViewPlaneNormal.SetCoord (X, Y, Z);
174
175 (Other.ViewReferenceUp ()).Coord (X, Y, Z);
176 MyViewUpVector.SetCoord (X, Y, Z);
177
178 if ( Other.IsCustomMatrix() ) {
179 MyModelViewMatrix = new TColStd_HArray2OfReal( 0, 3, 0, 3);
180 for (Standard_Integer i = 0; i < 4; i++)
181 for (Standard_Integer j = 0; j < 4; j++)
182 MyModelViewMatrix->SetValue( i, j, Other.MyModelViewMatrix->Value(i, j) );
183 }
184 else
185 MyModelViewMatrix.Nullify();
186}
187
188Standard_Real Visual3d_ViewOrientation::Twist () const {
189
190cout << "\nVisual3d_ViewOrientation::Twist : Not Yet Implemented\n\n" << flush;
191
192#ifdef OK
193Standard_Real Xrp, Yrp, Zrp;
194Standard_Real Xpn, Ypn, Zpn;
195Standard_Real Xup, Yup, Zup;
196Standard_Real a1, b1, c1, a2, b2, c2;
197Standard_Real pvx, pvy, pvz;
198Standard_Real an1, an2;
199Standard_Real pvn, sca, angle;
200
201 MyViewReferencePoint.Coord (Xrp, Yrp, Zrp) ;
202 MyViewPlaneNormal.Coord (Xpn, Ypn, Zpn) ;
203 MyViewUpVector.Coord (Xup, Yup, Zup) ;
204
205 Xrp -= Xpn ; Yrp -= Ypn ; Zrp -= Zpn ;
206 Xup -= Xpn ; Yup -= Ypn ; Zup -= Zpn ;
207 /* Compute Plane Normal EYE, AT, UP */
208 a1 = Yrp*Zup - Yup*Zrp ;
209 b1 = Zrp*Xup - Zup*Xrp ;
210 c1 = Xrp*Yup - Xup*Yrp ;
211 /* Compute Plane Normal EYE, AT, YAXIS */
212 a2 = -Zrp ;
213 b2 = 0. ;
214 c2 = Xrp ;
215 /* Compute Cross Vector from 2 last Normals */
216 pvx = b1*c2 - c1*b2 ;
217 pvy = c1*a2 - a1*c2 ;
218 pvz = a1*b2 - b1*a2 ;
219 /* Normalize vectors */
220 an1 = a1*a1 + b1*b1 + c1*c1 ;
221 an2 = a2*a2 + b2*b2 + c2*c2 ;
222 pvn = pvx*pvx + pvy*pvy + pvz*pvz ;
223 /* Compute Angle */
224 if (angle > 1.) angle = 1. ;
225 else if ( angle < -1. ) angle = -1. ;
c6541a0c 226 angle = asin (angle) / (M_PI / 180.0);
7fd59977 227 sca = a1*a2 + b1*b2 + c1*c2 ;
228 if (sca < 0.) angle = 180. - angle ;
229 if ( (angle > 0.) && (angle < 180.) ) {
230 sca = - (pvx*Xrp + pvy*Yrp + pvz*Zrp) ;
231 if (sca > 0.) angle = 360. - angle ;
232 }
233
c6541a0c 234 return (angle * M_PI / 180.0);
7fd59977 235#else
c6541a0c 236 return (M_PI / 180.0);
7fd59977 237#endif
238
239}
240
241void Visual3d_ViewOrientation::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz)const {
242 Sx = MyScaleX;
243 Sy = MyScaleY;
244 Sz = MyScaleZ;
245}
246
247
248void Visual3d_ViewOrientation::SetCustomModelViewMatrix(const Handle(TColStd_HArray2OfReal)& Mat)
249{
250 MyModelViewMatrix = Mat;
251}
252
253Standard_Boolean Visual3d_ViewOrientation::IsCustomMatrix() const
254{
255 return !MyModelViewMatrix.IsNull()
256 && MyModelViewMatrix->LowerRow() == 0
257 && MyModelViewMatrix->LowerCol() == 0
258 && MyModelViewMatrix->UpperRow() == 3
259 && MyModelViewMatrix->UpperCol() == 3;
260}