Salome HOME
updated copyright message
[modules/gui.git] / src / SUIT / SUIT_CameraProperties.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "SUIT_CameraProperties.h"
24
25 /*!
26   \class SUIT_CameraProperties
27   \brief Base class for Camera Properties
28   
29   This class provides common properties that
30   can be used for any arbitrary camera. This
31   properties are employed by camera synchronization
32   algorithms.
33 */
34
35 /*!
36   \brief Default constructor. 
37
38   Creates invalid camera properties data, i.e. IsValid() returns \c false.
39 */
40 SUIT_CameraProperties::SUIT_CameraProperties()
41 {
42   // init with some default values
43   myUpDir[0] = 0.0;
44   myUpDir[1] = 1.0;
45   myUpDir[2] = 0.0;
46   
47   myPosition[0] = 0.0;
48   myPosition[1] = 0.0;
49   myPosition[2] = 500.0;
50   
51   myFocalPoint[0] = 0.0;
52   myFocalPoint[1] = 0.0;
53   myFocalPoint[2] = 0.0;
54     
55   myAxialScale[0] = 1.0;
56   myAxialScale[1] = 1.0;
57   myAxialScale[2] = 1.0;
58   
59   myMappingScale = 1000;
60
61   myDimension   = DimNone;        // none dimension by default
62   myProjection  = PrjOrthogonal;  // orthogonal projection by default
63   myViewSide    = ViewNone;       // no side view by default
64   
65   myViewAngle = 45.0;
66 }
67
68 /*!
69   \brief Destructor
70 */
71 SUIT_CameraProperties::~SUIT_CameraProperties()
72 {
73 }
74
75 /*!
76   \brief Check if camera properties are valid.
77   \return \c true if camera properties data is valid.
78   \sa setDimension()
79 */
80 bool SUIT_CameraProperties::isValid() const
81 {
82   return myDimension != DimNone;
83 }
84
85 /*!
86   \brief Check if this camera properties data is compatible with other camera properties.
87   \param other other properties data
88   \return \c true if both camera properties sets are compatible
89 */
90 bool SUIT_CameraProperties::isCompatible( const SUIT_CameraProperties& other )
91 {
92   bool result = false;
93   // check only valid data and data with same dimensions
94   if ( isValid() && other.isValid() && getDimension() == other.getDimension() ) {
95     switch( getDimension() ) {
96     case SUIT_CameraProperties::Dim2D:
97       // two 2d views are compatible if their view side is the same
98       result = getViewSide() == other.getViewSide();
99       break;
100     case SUIT_CameraProperties::Dim3D:
101       // two 3d views are compatible if their projection mode is the same
102       result = getProjection() == other.getProjection();
103       break;
104     default:
105       break;
106     }
107   }
108   return result;
109 }
110
111 /*!
112   \brief get dimension supported by camera.
113   \return dimension mode.
114   \sa setDimension()
115 */
116 SUIT_CameraProperties::Dimension SUIT_CameraProperties::getDimension() const
117 {
118   return myDimension;
119 }
120
121 /*!
122   \brief set dimension supported by camera.
123   \param theDimension [in] dimension mode.
124   \sa getDimension()
125 */
126 void SUIT_CameraProperties::setDimension( const SUIT_CameraProperties::Dimension theDimension )
127 {
128   myDimension = theDimension;
129 }
130
131 /*!
132   \brief get side view supported by camera (for 2d viewer).
133
134   For 2d viewer, side view can be of following values:
135   - SUIT_CameraProperties::ViewNone - no side view (for instance, for true 2d viewer)
136   - SUIT_CameraProperties::ViewXY   - XY side view of 3d scene
137   - SUIT_CameraProperties::ViewXZ   - XZ side view of 3d scene
138   - SUIT_CameraProperties::ViewYZ   - YZ side view of 3d scene
139
140   \return side view.
141   \sa setViewSide()
142 */
143 SUIT_CameraProperties::ViewSide SUIT_CameraProperties::getViewSide() const
144 {
145   return myViewSide;
146 }
147
148 /*!
149   \brief set side view supported by camera (for 2d viewer).
150
151   For 2d viewer, side view can be of following values:
152   - SUIT_CameraProperties::ViewNone - no side view (for instance, for true 2d viewer)
153   - SUIT_CameraProperties::ViewXY   - XY side view of 3d scene
154   - SUIT_CameraProperties::ViewXZ   - XZ side view of 3d scene
155   - SUIT_CameraProperties::ViewYZ   - YZ side view of 3d scene
156
157   \param theViewSide [in] view side.
158   \sa getViewSide()
159 */
160 void SUIT_CameraProperties::setViewSide( const SUIT_CameraProperties::ViewSide theViewSide )
161 {
162   myViewSide = theViewSide;
163 }
164
165 /*!
166   \brief get projection mode supported by camera (for 3d viewer).
167
168   For 3d viewer, projection mode can be of following values:
169   - SUIT_CameraProperties::PrjOrthogonal - orthogonal projection
170   - SUIT_CameraProperties::PrjPerspective - perspective projection
171
172   \return projection mode.
173   \sa setProjection()
174 */
175 SUIT_CameraProperties::Projection SUIT_CameraProperties::getProjection() const
176 {
177   return myProjection;
178 }
179
180 /*!
181   \brief set projection mode supported by camera (for 3d viewer).
182
183   For 3d viewer, projection mode can be of following values:
184   - SUIT_CameraProperties::PrjOrthogonal - orthogonal projection
185   - SUIT_CameraProperties::PrjPerspective - perspective projection
186
187   \param theProjection [in] projection mode.
188   \sa getProjection()
189 */
190 void SUIT_CameraProperties::setProjection( const SUIT_CameraProperties::Projection theProjection )
191 {
192   myProjection = theProjection;
193 }
194
195 /*!
196   \brief get camera up direction vector.
197   \param theX [out] vector's x coordinate in world-coordinates space.
198   \param theY [out] vector's y coordinate in world-coordinates space.
199   \param theZ [out] vector's z coordinate in world-coordinates space.
200   \sa setViewUp()
201 */
202 void SUIT_CameraProperties::getViewUp(double& theX, double& theY, double& theZ) const
203 {
204   theX = myUpDir[0];
205   theY = myUpDir[1];
206   theZ = myUpDir[2];
207 }
208
209 /*!
210   \brief set camera up direction vector.
211
212   It is recommended to set normalized vector coordinates for
213   synchronization compatibility.
214   
215   \param theX [in] vector's x coordinate in world-coordinates space.
216   \param theY [in] vector's y coordinate in world-coordinates space.
217   \param theZ [in] vector's z coordinate in world-coordinates space.
218   \sa getViewUp()
219 */
220 void SUIT_CameraProperties::setViewUp(const double theX, const double theY, const double theZ)
221 {
222   myUpDir[0] = theX;
223   myUpDir[1] = theY;
224   myUpDir[2] = theZ;
225 }
226
227 /*!
228   \brief get camera's position (eye).
229   \param theX [out] x coordinate in world-coordinates space.
230   \param theY [out] y coordinate in world-coordinates space.
231   \param theZ [out] z coordinate in world-coordinates space.
232   \sa setPosition()
233 */
234 void SUIT_CameraProperties::getPosition(double& theX, double& theY, double& theZ) const
235 {
236   theX = myPosition[0];
237   theY = myPosition[1];
238   theZ = myPosition[2];
239 }
240
241 /*!
242   \brief get camera's position (eye).
243   \param theX [in] x coordinate in world-coordinates space.
244   \param theY [in] y coordinate in world-coordinates space.
245   \param theZ [in] z coordinate in world-coordinates space.
246   \sa getPosition()
247 */
248 void SUIT_CameraProperties::setPosition(const double theX, const double theY, const double theZ)
249 {
250   myPosition[0] = theX;
251   myPosition[1] = theY;
252   myPosition[2] = theZ;
253 }
254
255 /*!
256   \brief get camera's focal point (look point).
257   \param theX [out] x coordinate in world-coordinates space.
258   \param theY [out] y coordinate in world-coordinates space.
259   \param theZ [out] z coordinate in world-coordinates space.
260   \sa setFocalPoint()
261 */
262 void SUIT_CameraProperties::getFocalPoint(double& theX, double& theY, double& theZ) const
263 {
264   theX = myFocalPoint[0];
265   theY = myFocalPoint[1];
266   theZ = myFocalPoint[2];
267 }
268
269 /*!
270   \brief set camera's focal point (look point).
271   \param theX [in] x coordinate in world-coordinates space.
272   \param theY [in] y coordinate in world-coordinates space.
273   \param theZ [in] z coordinate in world-coordinates space.
274   \sa getFocalPoint()
275 */
276 void SUIT_CameraProperties::setFocalPoint(const double theX, const double theY, const double theZ)
277 {
278   myFocalPoint[0] = theX;
279   myFocalPoint[1] = theY;
280   myFocalPoint[2] = theZ;
281 }
282
283 /*!
284   \brief get window mapping scale (parallel scale).
285
286   Mapping scale defines a mapping scaling factor for the height
287   of the viewport in world-coordinate distances.
288
289   \return scaling value.
290   \sa setMappingScale()
291 */
292 double SUIT_CameraProperties::getMappingScale() const
293 {
294   return myMappingScale;
295 }
296
297 /*!
298   \brief set window mapping scale (parallel scale).
299
300   Mapping scale defines a mapping scaling factor for the height
301   of the viewport in world-coordinate distances.
302
303   \param theScale [in] the scaling.
304   \sa getMappingScale()
305 */
306 void SUIT_CameraProperties::setMappingScale(const double theScale)
307 {
308   myMappingScale = theScale;
309 }
310
311 /*! 
312   \brief get scaling factors for world-coordinate space axes.
313   \param theScaleX [out] scale by x coordinate.
314   \param theScaleY [out] scale by y coordinate.
315   \param theScaleZ [out] scale by z coordinate.
316   \sa setAxialScale()
317 */
318 void SUIT_CameraProperties::getAxialScale(double& theScaleX, double& theScaleY, double& theScaleZ)
319 {
320   theScaleX = myAxialScale[0];
321   theScaleY = myAxialScale[1];
322   theScaleZ = myAxialScale[2];
323 }
324
325 /*!
326   \brief set scaling factors for world-coordinate space axes.
327   \param theScaleX [in] scale by x coordinate.
328   \param theScaleY [in] scale by y coordinate.
329   \param theScaleZ [in] scale by z coordinate.
330   \sa getAxialScale()
331 */
332 void SUIT_CameraProperties::setAxialScale(const double theScaleX, const double theScaleY, const double theScaleZ)
333
334   myAxialScale[0] = theScaleX;
335   myAxialScale[1] = theScaleY;
336   myAxialScale[2] = theScaleZ;
337 }
338
339 /*!
340   \brief get angle (typically in degrees) of view for perpective projection mode.
341   \return the angle of view.
342   \sa setViewAngle()
343 */
344 double SUIT_CameraProperties::getViewAngle() const
345 {
346   return myViewAngle;
347 }
348
349 /*!
350   \brief set angle (typically in degrees) of view for perpective projection mode.
351   \param theViewAngle [in] the angle of view.
352   \sa getViewAngle()
353 */
354 void SUIT_CameraProperties::setViewAngle(const double theViewAngle)
355 {
356   myViewAngle = theViewAngle;
357 }