1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SUIT_CameraProperties.h"
26 \class SUIT_CameraProperties
27 \brief Base class for Camera Properties
29 This class provides common properties that
30 can be used for any arbitrary camera. This
31 properties are employed by camera synchronization
36 \brief Default constructor.
38 Creates invalid camera properties data, i.e. IsValid() returns \c false.
40 SUIT_CameraProperties::SUIT_CameraProperties()
42 // init with some default values
49 myPosition[2] = 500.0;
51 myFocalPoint[0] = 0.0;
52 myFocalPoint[1] = 0.0;
53 myFocalPoint[2] = 0.0;
55 myAxialScale[0] = 1.0;
56 myAxialScale[1] = 1.0;
57 myAxialScale[2] = 1.0;
59 myMappingScale = 1000;
61 myDimension = DimNone; // none dimension by default
62 myProjection = PrjOrthogonal; // orthogonal projection by default
63 myViewSide = ViewNone; // no side view by default
71 SUIT_CameraProperties::~SUIT_CameraProperties()
76 \brief Check if camera properties are valid.
77 \return \c true if camera properties data is valid.
80 bool SUIT_CameraProperties::isValid() const
82 return myDimension != DimNone;
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
90 bool SUIT_CameraProperties::isCompatible( const SUIT_CameraProperties& other )
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();
100 case SUIT_CameraProperties::Dim3D:
101 // two 3d views are compatible if their projection mode is the same
102 result = getProjection() == other.getProjection();
112 \brief get dimension supported by camera.
113 \return dimension mode.
116 SUIT_CameraProperties::Dimension SUIT_CameraProperties::getDimension() const
122 \brief set dimension supported by camera.
123 \param theDimension [in] dimension mode.
126 void SUIT_CameraProperties::setDimension( const SUIT_CameraProperties::Dimension theDimension )
128 myDimension = theDimension;
132 \brief get side view supported by camera (for 2d viewer).
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
143 SUIT_CameraProperties::ViewSide SUIT_CameraProperties::getViewSide() const
149 \brief set side view supported by camera (for 2d viewer).
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
157 \param theViewSide [in] view side.
160 void SUIT_CameraProperties::setViewSide( const SUIT_CameraProperties::ViewSide theViewSide )
162 myViewSide = theViewSide;
166 \brief get projection mode supported by camera (for 3d viewer).
168 For 3d viewer, projection mode can be of following values:
169 - SUIT_CameraProperties::PrjOrthogonal - orthogonal projection
170 - SUIT_CameraProperties::PrjPerspective - perspective projection
172 \return projection mode.
175 SUIT_CameraProperties::Projection SUIT_CameraProperties::getProjection() const
181 \brief set projection mode supported by camera (for 3d viewer).
183 For 3d viewer, projection mode can be of following values:
184 - SUIT_CameraProperties::PrjOrthogonal - orthogonal projection
185 - SUIT_CameraProperties::PrjPerspective - perspective projection
187 \param theProjection [in] projection mode.
190 void SUIT_CameraProperties::setProjection( const SUIT_CameraProperties::Projection theProjection )
192 myProjection = theProjection;
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.
202 void SUIT_CameraProperties::getViewUp(double& theX, double& theY, double& theZ) const
210 \brief set camera up direction vector.
212 It is recommended to set normalized vector coordinates for
213 synchronization compatibility.
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.
220 void SUIT_CameraProperties::setViewUp(const double theX, const double theY, const double theZ)
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.
234 void SUIT_CameraProperties::getPosition(double& theX, double& theY, double& theZ) const
236 theX = myPosition[0];
237 theY = myPosition[1];
238 theZ = myPosition[2];
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.
248 void SUIT_CameraProperties::setPosition(const double theX, const double theY, const double theZ)
250 myPosition[0] = theX;
251 myPosition[1] = theY;
252 myPosition[2] = theZ;
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.
262 void SUIT_CameraProperties::getFocalPoint(double& theX, double& theY, double& theZ) const
264 theX = myFocalPoint[0];
265 theY = myFocalPoint[1];
266 theZ = myFocalPoint[2];
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.
276 void SUIT_CameraProperties::setFocalPoint(const double theX, const double theY, const double theZ)
278 myFocalPoint[0] = theX;
279 myFocalPoint[1] = theY;
280 myFocalPoint[2] = theZ;
284 \brief get window mapping scale (parallel scale).
286 Mapping scale defines a mapping scaling factor for the height
287 of the viewport in world-coordinate distances.
289 \return scaling value.
290 \sa setMappingScale()
292 double SUIT_CameraProperties::getMappingScale() const
294 return myMappingScale;
298 \brief set window mapping scale (parallel scale).
300 Mapping scale defines a mapping scaling factor for the height
301 of the viewport in world-coordinate distances.
303 \param theScale [in] the scaling.
304 \sa getMappingScale()
306 void SUIT_CameraProperties::setMappingScale(const double theScale)
308 myMappingScale = theScale;
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.
318 void SUIT_CameraProperties::getAxialScale(double& theScaleX, double& theScaleY, double& theScaleZ)
320 theScaleX = myAxialScale[0];
321 theScaleY = myAxialScale[1];
322 theScaleZ = myAxialScale[2];
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.
332 void SUIT_CameraProperties::setAxialScale(const double theScaleX, const double theScaleY, const double theScaleZ)
334 myAxialScale[0] = theScaleX;
335 myAxialScale[1] = theScaleY;
336 myAxialScale[2] = theScaleZ;
340 \brief get angle (typically in degrees) of view for perpective projection mode.
341 \return the angle of view.
344 double SUIT_CameraProperties::getViewAngle() const
350 \brief set angle (typically in degrees) of view for perpective projection mode.
351 \param theViewAngle [in] the angle of view.
354 void SUIT_CameraProperties::setViewAngle(const double theViewAngle)
356 myViewAngle = theViewAngle;