Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/opencascade/Graphic3d_Camera.hxx was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Created on: 2013-05-29
0002 // Created by: Anton POLETAEV
0003 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _Graphic3d_Camera_HeaderFile
0017 #define _Graphic3d_Camera_HeaderFile
0018 
0019 #include <Aspect_Eye.hxx>
0020 #include <Aspect_FrustumLRBT.hxx>
0021 #include <Graphic3d_CameraTile.hxx>
0022 #include <Graphic3d_Mat4d.hxx>
0023 #include <Graphic3d_Mat4.hxx>
0024 #include <Graphic3d_Vec3.hxx>
0025 #include <Graphic3d_WorldViewProjState.hxx>
0026 #include <NCollection_Lerp.hxx>
0027 #include <NCollection_Array1.hxx>
0028 
0029 #include <gp_Dir.hxx>
0030 #include <gp_Pnt.hxx>
0031 
0032 #include <Standard_Macro.hxx>
0033 #include <Standard_TypeDef.hxx>
0034 
0035 #include <Bnd_Box.hxx>
0036 
0037 //! Forward declaration
0038 
0039 //! Camera class provides object-oriented approach to setting up projection
0040 //! and orientation properties of 3D view.
0041 class Graphic3d_Camera : public Standard_Transient
0042 {
0043 private:
0044 
0045   //! Template container for cached matrices or Real/ShortReal types.
0046   template<typename Elem_t>
0047   struct TransformMatrices
0048   {
0049 
0050     //! Default constructor.
0051     TransformMatrices() : myIsOrientationValid (Standard_False), myIsProjectionValid (Standard_False) {}
0052 
0053     //! Initialize orientation.
0054     void InitOrientation()
0055     {
0056       myIsOrientationValid = Standard_True;
0057       Orientation.InitIdentity();
0058     }
0059 
0060     //! Initialize projection.
0061     void InitProjection()
0062     {
0063       myIsProjectionValid = Standard_True;
0064       MProjection.InitIdentity();
0065       LProjection.InitIdentity();
0066       RProjection.InitIdentity();
0067     }
0068 
0069     //! Invalidate orientation.
0070     void ResetOrientation() { myIsOrientationValid = Standard_False; }
0071 
0072     //! Invalidate projection.
0073     void ResetProjection()  { myIsProjectionValid  = Standard_False; }
0074 
0075     //! Return true if Orientation was not invalidated.
0076     Standard_Boolean IsOrientationValid() const { return myIsOrientationValid; }
0077 
0078     //! Return true if Projection was not invalidated.
0079     Standard_Boolean IsProjectionValid()  const { return myIsProjectionValid;  }
0080     
0081     //! Dumps the content of me into the stream
0082     void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const
0083     {
0084       if (IsOrientationValid())
0085       {
0086         OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &Orientation)
0087       }
0088       if (IsProjectionValid())
0089       {
0090         OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &MProjection)
0091         OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &LProjection)
0092         OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &RProjection)
0093       }
0094       OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsOrientationValid)
0095       OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsProjectionValid)
0096     }
0097 
0098   public:
0099 
0100     NCollection_Mat4<Elem_t> Orientation;
0101     NCollection_Mat4<Elem_t> MProjection;
0102     NCollection_Mat4<Elem_t> LProjection;
0103     NCollection_Mat4<Elem_t> RProjection;
0104 
0105   private:
0106 
0107     Standard_Boolean myIsOrientationValid;
0108     Standard_Boolean myIsProjectionValid;
0109 
0110   };
0111 
0112 public:
0113 
0114   //! Enumerates supported monographic projections.
0115   //! - Projection_Orthographic : orthographic projection.
0116   //! - Projection_Perspective  : perspective projection.
0117   //! - Projection_Stereo       : stereographic projection.
0118   //! - Projection_MonoLeftEye  : mono projection for stereo left eye.
0119   //! - Projection_MonoRightEye : mono projection for stereo right eye.
0120   enum Projection
0121   {
0122     Projection_Orthographic,
0123     Projection_Perspective,
0124     Projection_Stereo,
0125     Projection_MonoLeftEye,
0126     Projection_MonoRightEye
0127   };
0128 
0129   //! Enumerates approaches to define stereographic focus.
0130   //! - FocusType_Absolute : focus is specified as absolute value.
0131   //! - FocusType_Relative : focus is specified relative to
0132   //! (as coefficient of) camera focal length.
0133   enum FocusType
0134   {
0135     FocusType_Absolute,
0136     FocusType_Relative
0137   };
0138 
0139   //! Enumerates approaches to define Intraocular distance.
0140   //! - IODType_Absolute : Intraocular distance is defined as absolute value.
0141   //! - IODType_Relative : Intraocular distance is defined relative to
0142   //! (as coefficient of) camera focal length.
0143   enum IODType
0144   {
0145     IODType_Absolute,
0146     IODType_Relative
0147   };
0148 
0149 public:
0150 
0151   //! Linear interpolation tool for camera orientation and position.
0152   //! This tool interpolates camera parameters scale, eye, center, rotation (up and direction vectors) independently.
0153   //! @sa Graphic3d_CameraLerp
0154   //!
0155   //! Eye/Center interpolation is performed through defining an anchor point in-between Center and Eye.
0156   //! The anchor position is defined as point near to the camera point which has smaller translation part.
0157   //! The main idea is to keep the distance between Center and Eye
0158   //! (which will change if Center and Eye translation will be interpolated independently).
0159   //! E.g.:
0160   //!  - When both Center and Eye are moved at the same vector -> both will be just translated by straight line;
0161   //!  - When Center is not moved -> camera Eye    will move around Center through arc;
0162   //!  - When Eye    is not moved -> camera Center will move around Eye    through arc;
0163   //!  - When both Center and Eye are move by different vectors -> transformation will be something in between,
0164   //!    and will try interpolate linearly the distance between Center and Eye.
0165   //!
0166   //! This transformation might be not in line with user expectations.
0167   //! In this case, application might define intermediate camera positions for interpolation or implement own interpolation logic.
0168   //!
0169   //! @param theStart  [in] initial camera position
0170   //! @param theEnd    [in] final   camera position
0171   //! @param theT      [in] step between initial and final positions within [0,1] range
0172   //! @param theCamera [out] interpolation result
0173   Standard_EXPORT static void Interpolate (const Handle(Graphic3d_Camera)& theStart,
0174                                            const Handle(Graphic3d_Camera)& theEnd,
0175                                            const double theT,
0176                                            Handle(Graphic3d_Camera)& theCamera);
0177 
0178 public:
0179 
0180   //! Default constructor.
0181   //! Initializes camera with the following properties:
0182   //! Eye (0, 0, -2); Center (0, 0, 0); Up (0, 1, 0);
0183   //! Type (Orthographic); FOVy (45); Scale (1000); IsStereo(false);
0184   //! ZNear (0.001); ZFar (3000.0); Aspect(1);
0185   //! ZFocus(1.0); ZFocusType(Relative); IOD(0.05); IODType(Relative)
0186   Standard_EXPORT Graphic3d_Camera();
0187 
0188   //! Copy constructor.
0189   //! @param theOther [in] the camera to copy from.
0190   Standard_EXPORT Graphic3d_Camera (const Handle(Graphic3d_Camera)& theOther);
0191 
0192   //! Initialize mapping related parameters from other camera handle.
0193   Standard_EXPORT void CopyMappingData (const Handle(Graphic3d_Camera)& theOtherCamera);
0194 
0195   //! Initialize orientation related parameters from other camera handle.
0196   Standard_EXPORT void CopyOrientationData (const Handle(Graphic3d_Camera)& theOtherCamera);
0197 
0198   //! Copy properties of another camera.
0199   //! @param theOther [in] the camera to copy from.
0200   Standard_EXPORT void Copy (const Handle(Graphic3d_Camera)& theOther);
0201 
0202 //! @name Public camera properties
0203 public:
0204 
0205   //! Get camera look direction.
0206   //! @return camera look direction.
0207   const gp_Dir& Direction() const { return myDirection; }
0208 
0209   //! Sets camera look direction preserving the current Eye() position.
0210   //! WARNING! This method does NOT verify that the current Up() vector is orthogonal to the new Direction.
0211   //! @param theDir [in] the direction.
0212   Standard_EXPORT void SetDirectionFromEye (const gp_Dir& theDir);
0213 
0214   //! Sets camera look direction and computes the new Eye position relative to current Center.
0215   //! WARNING! This method does NOT verify that the current Up() vector is orthogonal to the new Direction.
0216   //! @param theDir [in] the direction.
0217   Standard_EXPORT void SetDirection (const gp_Dir& theDir);
0218 
0219   //! Get camera Up direction vector.
0220   //! @return Camera's Up direction vector.
0221   const gp_Dir& Up() const { return myUp; }
0222 
0223   //! Sets camera Up direction vector, orthogonal to camera direction.
0224   //! WARNING! This method does NOT verify that the new Up vector is orthogonal to the current Direction().
0225   //! @param theUp [in] the Up direction vector.
0226   //! @sa OrthogonalizeUp().
0227   Standard_EXPORT void SetUp (const gp_Dir& theUp);
0228 
0229   //! Orthogonalize up direction vector.
0230   Standard_EXPORT void OrthogonalizeUp();
0231 
0232   //! Return a copy of orthogonalized up direction vector.
0233   Standard_EXPORT gp_Dir OrthogonalizedUp() const;
0234 
0235   //! Right side direction.
0236   gp_Dir SideRight() const
0237   {
0238     return -(gp_Vec (Direction()) ^ gp_Vec (OrthogonalizedUp()));
0239   }
0240 
0241   //! Get camera Eye position.
0242   //! @return camera eye location.
0243   const gp_Pnt& Eye() const { return myEye; }
0244 
0245   //! Sets camera Eye position.
0246   //! Unlike SetEye(), this method only changes Eye point and preserves camera direction.
0247   //! @param theEye [in] the location of camera's Eye.
0248   //! @sa SetEye()
0249   Standard_EXPORT void MoveEyeTo (const gp_Pnt& theEye);
0250 
0251   //! Sets camera Eye and Center positions.
0252   //! @param theEye    [in] the location of camera's Eye
0253   //! @param theCenter [in] the location of camera's Center
0254   Standard_EXPORT void SetEyeAndCenter (const gp_Pnt& theEye,
0255                                         const gp_Pnt& theCenter);
0256 
0257   //! Sets camera Eye position.
0258   //! WARNING! For backward compatibility reasons, this method also changes view direction,
0259   //! so that the new direction is computed from new Eye position to old Center position.
0260   //! @param theEye [in] the location of camera's Eye.
0261   //! @sa MoveEyeTo(), SetEyeAndCenter()
0262   Standard_EXPORT void SetEye (const gp_Pnt& theEye);
0263 
0264   //! Get Center of the camera, e.g. the point where camera looks at.
0265   //! This point is computed as Eye() translated along Direction() at Distance().
0266   //! @return the point where the camera looks at.
0267   gp_Pnt Center() const
0268   {
0269     return myEye.XYZ() + myDirection.XYZ() * myDistance;
0270   }
0271 
0272   //! Sets Center of the camera, e.g. the point where camera looks at.
0273   //! This methods changes camera direction, so that the new direction is computed
0274   //! from current Eye position to specified Center position.
0275   //! @param theCenter [in] the point where the camera looks at.
0276   Standard_EXPORT void SetCenter (const gp_Pnt& theCenter);
0277 
0278   //! Get distance of Eye from camera Center.
0279   //! @return the distance.
0280   Standard_Real Distance() const { return myDistance; }
0281 
0282   //! Set distance of Eye from camera Center.
0283   //! @param theDistance [in] the distance.
0284   Standard_EXPORT void SetDistance (const Standard_Real theDistance);
0285 
0286   //! Get camera scale.
0287   //! @return camera scale factor.
0288   Standard_EXPORT Standard_Real Scale() const;
0289 
0290   //! Sets camera scale. For orthographic projection the scale factor
0291   //! corresponds to parallel scale of view mapping  (i.e. size
0292   //! of viewport). For perspective camera scale is converted to
0293   //! distance. The scale specifies equal size of the view projection in
0294   //! both dimensions assuming that the aspect is 1.0. The projection height
0295   //! and width are specified with the scale and correspondingly multiplied
0296   //! by the aspect.
0297   //! @param theScale [in] the scale factor.
0298   Standard_EXPORT void SetScale (const Standard_Real theScale);
0299 
0300   //! Get camera axial scale.
0301   //! @return Camera's axial scale.
0302   const gp_XYZ& AxialScale() const { return myAxialScale; }
0303 
0304   //! Set camera axial scale.
0305   //! @param theAxialScale [in] the axial scale vector.
0306   Standard_EXPORT void SetAxialScale (const gp_XYZ& theAxialScale);
0307 
0308   //! Change camera projection type.
0309   //! When switching to perspective projection from orthographic one,
0310   //! the ZNear and ZFar are reset to default values (0.001, 3000.0)
0311   //! if less than 0.0.
0312   //! @param[in] theProjection the camera projection type.
0313   Standard_EXPORT void SetProjectionType (const Projection theProjection);
0314 
0315   //! @return camera projection type.
0316   Projection ProjectionType() const
0317   {
0318     return myProjType;
0319   }
0320 
0321   //! Check that the camera projection is orthographic.
0322   //! @return boolean flag that indicates whether the camera's projection is
0323   //! orthographic or not.
0324   Standard_Boolean IsOrthographic() const
0325   {
0326     return (myProjType == Projection_Orthographic);
0327   }
0328 
0329   //! Check whether the camera projection is stereo.
0330   //! Please note that stereo rendering is now implemented with support of
0331   //! Quad buffering.
0332   //! @return boolean flag indicating whether the stereographic L/R projection
0333   //! is chosen.
0334   Standard_Boolean IsStereo() const
0335   {
0336     return (myProjType == Projection_Stereo);
0337   }
0338 
0339   //! Set Field Of View (FOV) in y axis for perspective projection.
0340   //! Field of View in x axis is automatically scaled from view aspect ratio.
0341   //! @param theFOVy [in] the FOV in degrees.
0342   Standard_EXPORT void SetFOVy (const Standard_Real theFOVy);
0343 
0344   //! Get Field Of View (FOV) in y axis.
0345   //! @return the FOV value in degrees.
0346   Standard_Real FOVy() const { return myFOVy; }
0347 
0348   //! Get Field Of View (FOV) in x axis.
0349   //! @return the FOV value in degrees.
0350   Standard_Real FOVx() const { return myFOVx; }
0351 
0352   //! Get Field Of View (FOV) restriction for 2D on-screen elements; 180 degrees by default.
0353   //! When 2D FOV is smaller than FOVy or FOVx, 2D elements defined within offset from view corner
0354   //! will be extended to fit into specified 2D FOV.
0355   //! This can be useful to make 2D elements sharply visible, like in case of HMD normally having extra large FOVy.
0356   Standard_Real FOV2d() const { return myFOV2d; }
0357 
0358   //! Set Field Of View (FOV) restriction for 2D on-screen elements.
0359   Standard_EXPORT void SetFOV2d (Standard_Real theFOV);
0360 
0361   //! Adjust camera to fit in specified AABB.
0362   Standard_EXPORT bool FitMinMax (const Bnd_Box& theBox,
0363                                   const Standard_Real theResolution,
0364                                   const bool theToEnlargeIfLine);
0365 
0366   //! Estimate Z-min and Z-max planes of projection volume to match the
0367   //! displayed objects. The methods ensures that view volume will
0368   //! be close by depth range to the displayed objects. Fitting assumes that
0369   //! for orthogonal projection the view volume contains the displayed objects
0370   //! completely. For zoomed perspective view, the view volume is adjusted such
0371   //! that it contains the objects or their parts, located in front of the camera.
0372   //! @param[in] theScaleFactor the scale factor for Z-range.
0373   //!   The range between Z-min, Z-max projection volume planes
0374   //!   evaluated by z fitting method will be scaled using this coefficient.
0375   //!   Program error exception is thrown if negative or zero value is passed.
0376   //! @param[in] theMinMax applicative min max boundaries.
0377   //! @param[in] theGraphicBB real graphical boundaries (not accounting infinite flag).
0378   Standard_EXPORT bool ZFitAll (const Standard_Real theScaleFactor,
0379                                 const Bnd_Box&      theMinMax,
0380                                 const Bnd_Box&      theGraphicBB,
0381                                 Standard_Real&      theZNear,
0382                                 Standard_Real&      theZFar) const;
0383 
0384   //! Change Z-min and Z-max planes of projection volume to match the displayed objects.
0385   void ZFitAll (const Standard_Real theScaleFactor, const Bnd_Box& theMinMax, const Bnd_Box& theGraphicBB)
0386   {
0387     Standard_Real aZNear = 0.0, aZFar = 1.0;
0388     ZFitAll (theScaleFactor, theMinMax, theGraphicBB, aZNear, aZFar);
0389     SetZRange (aZNear, aZFar);
0390   }
0391 
0392   //! Change the Near and Far Z-clipping plane positions.
0393   //! For orthographic projection, theZNear, theZFar can be negative or positive.
0394   //! For perspective projection, only positive values are allowed.
0395   //! Program error exception is raised if non-positive values are
0396   //! specified for perspective projection or theZNear >= theZFar.
0397   //! @param theZNear [in] the distance of the plane from the Eye.
0398   //! @param theZFar [in] the distance of the plane from the Eye.
0399   Standard_EXPORT void SetZRange (const Standard_Real theZNear, const Standard_Real theZFar);
0400 
0401   //! Get the Near Z-clipping plane position.
0402   //! @return the distance of the plane from the Eye.
0403   Standard_Real ZNear() const
0404   {
0405     return myZNear;
0406   }
0407 
0408   //! Get the Far Z-clipping plane position.
0409   //! @return the distance of the plane from the Eye.
0410   Standard_Real ZFar() const
0411   {
0412     return myZFar;
0413   }
0414 
0415   //! Return TRUE if camera should calculate projection matrix for [0, 1] depth range or for [-1, 1] range.
0416   //! FALSE by default.
0417   Standard_Boolean IsZeroToOneDepth() const { return myIsZeroToOneDepth; }
0418 
0419   //! Set using [0, 1] depth range or [-1, 1] range.
0420   void SetZeroToOneDepth (Standard_Boolean theIsZeroToOne)
0421   {
0422     if (myIsZeroToOneDepth != theIsZeroToOne)
0423     {
0424       myIsZeroToOneDepth = theIsZeroToOne;
0425       InvalidateProjection();
0426     }
0427   }
0428 
0429   //! Changes width / height display ratio.
0430   //! @param theAspect [in] the display ratio.
0431   Standard_EXPORT void SetAspect (const Standard_Real theAspect);
0432 
0433   //! Get camera display ratio.
0434   //! @return display ratio.
0435   Standard_Real Aspect() const
0436   {
0437     return myAspect;
0438   }
0439 
0440   //! Sets stereographic focus distance.
0441   //! @param theType [in] the focus definition type. Focus can be defined
0442   //! as absolute value or relatively to (as coefficient of) coefficient of
0443   //! camera focal length.
0444   //! @param theZFocus [in] the focus absolute value or coefficient depending
0445   //! on the passed definition type.
0446   Standard_EXPORT void SetZFocus (const FocusType theType, const Standard_Real theZFocus);
0447 
0448   //! Get stereographic focus value.
0449   //! @return absolute or relative stereographic focus value
0450   //! depending on its definition type.
0451   Standard_Real ZFocus() const
0452   {
0453     return myZFocus;
0454   }
0455 
0456   //! Get stereographic focus definition type.
0457   //! @return definition type used for stereographic focus.
0458   FocusType ZFocusType() const
0459   {
0460     return myZFocusType;
0461   }
0462 
0463   //! Sets Intraocular distance.
0464   //! @param theType [in] the IOD definition type. IOD can be defined as
0465   //! absolute value or relatively to (as coefficient of) camera focal length.
0466   //! @param theIOD [in] the Intraocular distance.
0467   Standard_EXPORT void SetIOD (const IODType theType, const Standard_Real theIOD);
0468 
0469   //! Get Intraocular distance value.
0470   //! @return absolute or relative IOD value depending on its definition type.
0471   Standard_Real IOD() const
0472   {
0473     return myIOD;
0474   }
0475 
0476   //! Get Intraocular distance definition type.
0477   //! @return definition type used for Intraocular distance.
0478   IODType GetIODType() const
0479   {
0480     return myIODType;
0481   }
0482 
0483   //! Get current tile.
0484   const Graphic3d_CameraTile& Tile() const { return myTile; }
0485 
0486   //! Sets the Tile defining the drawing sub-area within View.
0487   //! Note that tile defining a region outside the view boundaries is also valid - use method Graphic3d_CameraTile::Cropped() to assign a cropped copy.
0488   //! @param theTile tile definition
0489   Standard_EXPORT void SetTile (const Graphic3d_CameraTile& theTile);
0490 
0491   //! Sets camera parameters to make current orientation matrix identity one.
0492   Standard_EXPORT void SetIdentityOrientation();
0493 
0494 //! @name Basic camera operations
0495 public:
0496 
0497   //! Transform orientation components of the camera:
0498   //! Eye, Up and Center points.
0499   //! @param theTrsf [in] the transformation to apply.
0500   Standard_EXPORT void Transform (const gp_Trsf& theTrsf);
0501 
0502   //! Calculate view plane size at center (target) point
0503   //! and distance between ZFar and ZNear planes.
0504   //! @return values in form of gp_Pnt (Width, Height, Depth).
0505   gp_XYZ ViewDimensions() const
0506   {
0507     return ViewDimensions (Distance());
0508   }
0509 
0510   //! Calculate view plane size at center point with specified Z offset
0511   //! and distance between ZFar and ZNear planes.
0512   //! @param theZValue [in] the distance from the eye in eye-to-center direction
0513   //! @return values in form of gp_Pnt (Width, Height, Depth).
0514   Standard_EXPORT gp_XYZ ViewDimensions (const Standard_Real theZValue) const;
0515 
0516   //! Return offset to the view corner in NDC space within dimension X for 2d on-screen elements, which is normally 0.5.
0517   //! Can be clamped when FOVx exceeds FOV2d.
0518   Standard_Real NDC2dOffsetX() const
0519   {
0520     return myFOV2d >= myFOVx
0521          ? 0.5
0522          : 0.5 * myFOV2d / myFOVx;
0523   }
0524 
0525   //! Return offset to the view corner in NDC space within dimension X for 2d on-screen elements, which is normally 0.5.
0526   //! Can be clamped when FOVy exceeds FOV2d.
0527   Standard_Real NDC2dOffsetY() const
0528   {
0529     return myFOV2d >= myFOVy
0530          ? 0.5
0531          : 0.5 * myFOV2d / myFOVy;
0532   }
0533 
0534   //! Calculate WCS frustum planes for the camera projection volume.
0535   //! Frustum is a convex volume determined by six planes directing
0536   //! inwards.
0537   //! The frustum planes are usually used as inputs for camera algorithms.
0538   //! Thus, if any changes to projection matrix calculation are necessary,
0539   //! the frustum planes calculation should be also touched.
0540   //! @param theLeft [out] the frustum plane for left side of view.
0541   //! @param theRight [out] the frustum plane for right side of view.
0542   //! @param theBottom [out] the frustum plane for bottom side of view.
0543   //! @param theTop [out] the frustum plane for top side of view.
0544   //! @param theNear [out] the frustum plane for near side of view.
0545   //! @param theFar [out] the frustum plane for far side of view.
0546   Standard_EXPORT void Frustum (gp_Pln& theLeft,
0547                                 gp_Pln& theRight,
0548                                 gp_Pln& theBottom,
0549                                 gp_Pln& theTop,
0550                                 gp_Pln& theNear,
0551                                 gp_Pln& theFar) const;
0552 
0553 //! @name Projection methods
0554 public:
0555 
0556   //! Project point from world coordinate space to
0557   //! normalized device coordinates (mapping).
0558   //! @param thePnt [in] the 3D point in WCS.
0559   //! @return mapped point in NDC.
0560   Standard_EXPORT gp_Pnt Project (const gp_Pnt& thePnt) const;
0561 
0562   //! Unproject point from normalized device coordinates
0563   //! to world coordinate space.
0564   //! @param thePnt [in] the NDC point.
0565   //! @return 3D point in WCS.
0566   Standard_EXPORT gp_Pnt UnProject (const gp_Pnt& thePnt) const;
0567 
0568   //! Convert point from view coordinate space to
0569   //! projection coordinate space.
0570   //! @param thePnt [in] the point in VCS.
0571   //! @return point in NDC.
0572   Standard_EXPORT gp_Pnt ConvertView2Proj (const gp_Pnt& thePnt) const;
0573 
0574   //! Convert point from projection coordinate space
0575   //! to view coordinate space.
0576   //! @param thePnt [in] the point in NDC.
0577   //! @return point in VCS.
0578   Standard_EXPORT gp_Pnt ConvertProj2View (const gp_Pnt& thePnt) const;
0579 
0580   //! Convert point from world coordinate space to
0581   //! view coordinate space.
0582   //! @param thePnt [in] the 3D point in WCS.
0583   //! @return point in VCS.
0584   Standard_EXPORT gp_Pnt ConvertWorld2View (const gp_Pnt& thePnt) const;
0585 
0586   //! Convert point from view coordinate space to
0587   //! world coordinates.
0588   //! @param thePnt [in] the 3D point in VCS.
0589   //! @return point in WCS.
0590   Standard_EXPORT gp_Pnt ConvertView2World (const gp_Pnt& thePnt) const;
0591 
0592 //! @name Camera modification state
0593 public:
0594 
0595   //! @return projection modification state of the camera.
0596   const Graphic3d_WorldViewProjState& WorldViewProjState() const
0597   {
0598     return myWorldViewProjState;
0599   }
0600 
0601 
0602   //! Returns modification state of camera projection matrix
0603   Standard_Size ProjectionState() const
0604   {
0605     return myWorldViewProjState.ProjectionState();
0606   }
0607 
0608   //! Returns modification state of camera world view transformation matrix.
0609   Standard_Size WorldViewState() const
0610   {
0611     return myWorldViewProjState.WorldViewState();
0612   }
0613 
0614 //! @name Lazily-computed orientation and projection matrices derived from camera parameters
0615 public:
0616 
0617   //! Get orientation matrix.
0618   //! @return camera orientation matrix.
0619   Standard_EXPORT const Graphic3d_Mat4d& OrientationMatrix() const;
0620 
0621   //! Get orientation matrix of Standard_ShortReal precision.
0622   //! @return camera orientation matrix.
0623   Standard_EXPORT const Graphic3d_Mat4& OrientationMatrixF() const;
0624 
0625   //! Get monographic or middle point projection matrix used for monographic
0626   //! rendering and for point projection / unprojection.
0627   //! @return monographic projection matrix.
0628   Standard_EXPORT const Graphic3d_Mat4d& ProjectionMatrix() const;
0629 
0630   //! Get monographic or middle point projection matrix of Standard_ShortReal precision used for monographic
0631   //! rendering and for point projection / unprojection.
0632   //! @return monographic projection matrix.
0633   Standard_EXPORT const Graphic3d_Mat4& ProjectionMatrixF() const;
0634 
0635   //! @return stereographic matrix computed for left eye. Please note
0636   //! that this method is used for rendering for <i>Projection_Stereo</i>.
0637   Standard_EXPORT const Graphic3d_Mat4d& ProjectionStereoLeft() const;
0638 
0639   //! @return stereographic matrix of Standard_ShortReal precision computed for left eye.
0640   //! Please note that this method is used for rendering for <i>Projection_Stereo</i>.
0641   Standard_EXPORT const Graphic3d_Mat4& ProjectionStereoLeftF() const;
0642 
0643   //! @return stereographic matrix computed for right eye. Please note
0644   //! that this method is used for rendering for <i>Projection_Stereo</i>.
0645   Standard_EXPORT const Graphic3d_Mat4d& ProjectionStereoRight() const;
0646 
0647   //! @return stereographic matrix of Standard_ShortReal precision computed for right eye.
0648   //! Please note that this method is used for rendering for <i>Projection_Stereo</i>.
0649   Standard_EXPORT const Graphic3d_Mat4& ProjectionStereoRightF() const;
0650 
0651   //! Invalidate state of projection matrix.
0652   //! The matrix will be updated on request.
0653   Standard_EXPORT void InvalidateProjection();
0654 
0655   //! Invalidate orientation matrix.
0656   //! The matrix will be updated on request.
0657   Standard_EXPORT void InvalidateOrientation();
0658 
0659 public:
0660 
0661   //! Get stereo projection matrices.
0662   //! @param theProjL      [out] left  eye projection matrix
0663   //! @param theHeadToEyeL [out] left  head to eye translation matrix
0664   //! @param theProjR      [out] right eye projection matrix
0665   //! @param theHeadToEyeR [out] right head to eye translation matrix
0666   Standard_EXPORT void StereoProjection (Graphic3d_Mat4d& theProjL,
0667                                          Graphic3d_Mat4d& theHeadToEyeL,
0668                                          Graphic3d_Mat4d& theProjR,
0669                                          Graphic3d_Mat4d& theHeadToEyeR) const;
0670 
0671   //! Get stereo projection matrices.
0672   //! @param theProjL      [out] left  eye projection matrix
0673   //! @param theHeadToEyeL [out] left  head to eye translation matrix
0674   //! @param theProjR      [out] right eye projection matrix
0675   //! @param theHeadToEyeR [out] right head to eye translation matrix
0676   Standard_EXPORT void StereoProjectionF (Graphic3d_Mat4& theProjL,
0677                                           Graphic3d_Mat4& theHeadToEyeL,
0678                                           Graphic3d_Mat4& theProjR,
0679                                           Graphic3d_Mat4& theHeadToEyeR) const;
0680 
0681   //! Unset all custom frustums and projection matrices.
0682   Standard_EXPORT void ResetCustomProjection();
0683 
0684   //! Return TRUE if custom stereo frustums are set.
0685   bool IsCustomStereoFrustum() const { return myIsCustomFrustomLR; }
0686 
0687   //! Set custom stereo frustums.
0688   //! These can be retrieved from APIs like OpenVR.
0689   Standard_EXPORT void SetCustomStereoFrustums (const Aspect_FrustumLRBT<Standard_Real>& theFrustumL,
0690                                                 const Aspect_FrustumLRBT<Standard_Real>& theFrustumR);
0691 
0692   //! Return TRUE if custom stereo projection matrices are set.
0693   bool IsCustomStereoProjection() const { return myIsCustomProjMatLR; }
0694 
0695   //! Set custom stereo projection matrices.
0696   //! @param theProjL      [in] left  eye projection matrix
0697   //! @param theHeadToEyeL [in] left  head to eye translation matrix
0698   //! @param theProjR      [in] right eye projection matrix
0699   //! @param theHeadToEyeR [in] right head to eye translation matrix
0700   Standard_EXPORT void SetCustomStereoProjection (const Graphic3d_Mat4d& theProjL,
0701                                                   const Graphic3d_Mat4d& theHeadToEyeL,
0702                                                   const Graphic3d_Mat4d& theProjR,
0703                                                   const Graphic3d_Mat4d& theHeadToEyeR);
0704 
0705   //! Return TRUE if custom projection matrix is set.
0706   bool IsCustomMonoProjection() const { return myIsCustomProjMatM; }
0707 
0708   //! Set custom projection matrix.
0709   Standard_EXPORT void SetCustomMonoProjection (const Graphic3d_Mat4d& theProj);
0710 
0711   //! Dumps the content of me into the stream
0712   Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0713 
0714 //! @name Managing projection and orientation cache
0715 private:
0716 
0717   //! Get stereo projection matrices.
0718   //! @param theProjL      [out] left  eye projection matrix
0719   //! @param theHeadToEyeL [out] left  head to eye translation matrix
0720   //! @param theProjR      [out] right eye projection matrix
0721   //! @param theHeadToEyeR [out] right head to eye translation matrix
0722   template <typename Elem_t>
0723   Standard_EXPORT void stereoProjection (NCollection_Mat4<Elem_t>& theProjL,
0724                                          NCollection_Mat4<Elem_t>& theHeadToEyeL,
0725                                          NCollection_Mat4<Elem_t>& theProjR,
0726                                          NCollection_Mat4<Elem_t>& theHeadToEyeR) const;
0727 
0728   //! Compute projection matrices.
0729   //! @param theProjM [out] mono projection matrix
0730   //! @param theProjL [out] left  eye projection matrix
0731   //! @param theProjR [out] right eye projection matrix
0732   //! @param theToAddHeadToEye [in] flag to pre-multiply head-to-eye translation
0733   template <typename Elem_t>
0734   Standard_EXPORT void computeProjection (NCollection_Mat4<Elem_t>& theProjM,
0735                                           NCollection_Mat4<Elem_t>& theProjL,
0736                                           NCollection_Mat4<Elem_t>& theProjR,
0737                                           bool theToAddHeadToEye) const;
0738 
0739   //! Compute projection matrices.
0740   //! @param theMatrices [in] the matrices data container.
0741   template <typename Elem_t>
0742   TransformMatrices<Elem_t>& UpdateProjection (TransformMatrices<Elem_t>& theMatrices) const
0743   {
0744     if (!theMatrices.IsProjectionValid())
0745     {
0746       theMatrices.InitProjection();
0747       computeProjection (theMatrices.MProjection, theMatrices.LProjection, theMatrices.RProjection, true);
0748     }
0749     return theMatrices;
0750   }
0751 
0752   //! Compute orientation matrix.
0753   //! @param theMatrices [in] the matrices data container.
0754   template <typename Elem_t>
0755   Standard_EXPORT
0756     TransformMatrices<Elem_t>& UpdateOrientation (TransformMatrices<Elem_t>& theMatrices) const;
0757 
0758 private:
0759 
0760   //! Compose orthographic projection matrix for the passed camera volume mapping.
0761   //! @param theOutMx [out] the projection matrix
0762   //! @param theLRBT [in] the left/right/bottom/top mapping (clipping) coordinates
0763   //! @param theNear [in] the near mapping (clipping) coordinate
0764   //! @param theFar [in] the far mapping (clipping) coordinate
0765   template <typename Elem_t>
0766   void orthoProj (NCollection_Mat4<Elem_t>& theOutMx,
0767                   const Aspect_FrustumLRBT<Elem_t>& theLRBT,
0768                   const Elem_t theNear,
0769                   const Elem_t theFar) const;
0770 
0771   //! Compose perspective projection matrix for the passed camera volume mapping.
0772   //! @param theOutMx [out] the projection matrix
0773   //! @param theLRBT [in] the left/right/bottom/top mapping (clipping) coordinates
0774   //! @param theNear [in] the near mapping (clipping) coordinate
0775   //! @param theFar [in] the far mapping (clipping) coordinate
0776   template <typename Elem_t>
0777   void perspectiveProj (NCollection_Mat4<Elem_t>& theOutMx,
0778                         const Aspect_FrustumLRBT<Elem_t>& theLRBT,
0779                         const Elem_t theNear,
0780                         const Elem_t theFar) const;
0781 
0782   //! Compose projection matrix for L/R stereo eyes.
0783   //! @param theOutMx [out] the projection matrix
0784   //! @param theLRBT [in] the left/right/bottom/top mapping (clipping) coordinates
0785   //! @param theNear [in] the near mapping (clipping) coordinate
0786   //! @param theFar [in] the far mapping (clipping) coordinate
0787   //! @param theIOD [in] the Intraocular distance
0788   //! @param theZFocus [in] the z coordinate of off-axis projection plane with zero parallax
0789   //! @param theEyeIndex [in] choose between L/R eyes
0790   template <typename Elem_t>
0791   void stereoEyeProj (NCollection_Mat4<Elem_t>& theOutMx,
0792                       const Aspect_FrustumLRBT<Elem_t>& theLRBT,
0793                       const Elem_t theNear,
0794                       const Elem_t theFar,
0795                       const Elem_t theIOD,
0796                       const Elem_t theZFocus,
0797                       const Aspect_Eye theEyeIndex) const;
0798 
0799   //! Construct "look at" orientation transformation.
0800   //! Reference point differs for perspective and ortho modes 
0801   //! (made for compatibility, to be improved..).
0802   //! @param theEye [in] the eye coordinates in 3D space.
0803   //! @param theFwdDir [in] view direction
0804   //! @param theUpDir [in] the up direction vector.
0805   //! @param theAxialScale [in] the axial scale vector.
0806   //! @param theOutMx [in/out] the orientation matrix.
0807   template <typename Elem_t>
0808   static void
0809     LookOrientation (const NCollection_Vec3<Elem_t>& theEye,
0810                      const NCollection_Vec3<Elem_t>& theFwdDir,
0811                      const NCollection_Vec3<Elem_t>& theUpDir,
0812                      const NCollection_Vec3<Elem_t>& theAxialScale,
0813                      NCollection_Mat4<Elem_t>&       theOutMx);
0814 
0815 public:
0816 
0817   //! Enumerates vertices of view volume.
0818   enum
0819   {
0820     FrustumVert_LeftBottomNear,
0821     FrustumVert_LeftBottomFar,
0822     FrustumVert_LeftTopNear,
0823     FrustumVert_LeftTopFar,
0824     FrustumVert_RightBottomNear,
0825     FrustumVert_RightBottomFar,
0826     FrustumVert_RightTopNear,
0827     FrustumVert_RightTopFar,
0828     FrustumVerticesNB
0829   };
0830 
0831   //! Fill array of current view frustum corners.
0832   //! The size of this array is equal to FrustumVerticesNB.
0833   //! The order of vertices is as defined in FrustumVert_* enumeration.
0834   Standard_EXPORT void FrustumPoints (NCollection_Array1<Graphic3d_Vec3d>& thePoints,
0835                                       const Graphic3d_Mat4d& theModelWorld = Graphic3d_Mat4d()) const;
0836 
0837 private:
0838 
0839   gp_Dir        myUp;       //!< Camera up direction vector
0840   gp_Dir        myDirection;//!< Camera view direction (from eye)
0841   gp_Pnt        myEye;      //!< Camera eye position
0842   Standard_Real myDistance; //!< distance from Eye to Center
0843 
0844   gp_XYZ myAxialScale; //!< World axial scale.
0845 
0846   Projection    myProjType; //!< Projection type used for rendering.
0847   Standard_Real myFOVy;     //!< Field Of View in y axis.
0848   Standard_Real myFOVx;     //!< Field Of View in x axis.
0849   Standard_Real myFOV2d;    //!< Field Of View limit for 2d on-screen elements
0850   Standard_Real myFOVyTan;  //!< Field Of View as Tan(DTR_HALF * myFOVy)
0851   Standard_Real myZNear;    //!< Distance to near clipping plane.
0852   Standard_Real myZFar;     //!< Distance to far clipping plane.
0853   Standard_Real myAspect;   //!< Width to height display ratio.
0854   Standard_Boolean myIsZeroToOneDepth; //!< use [0, 1] depth range or [-1, 1]
0855 
0856   Standard_Real myScale;      //!< Specifies parallel scale for orthographic projection.
0857   Standard_Real myZFocus;     //!< Stereographic focus value.
0858   FocusType     myZFocusType; //!< Stereographic focus definition type.
0859 
0860   Standard_Real myIOD;     //!< Intraocular distance value.
0861   IODType       myIODType; //!< Intraocular distance definition type.
0862 
0863   Graphic3d_CameraTile myTile;//!< Tile defining sub-area for drawing
0864 
0865   Graphic3d_Mat4d  myCustomProjMatM;
0866   Graphic3d_Mat4d  myCustomProjMatL;
0867   Graphic3d_Mat4d  myCustomProjMatR;
0868   Graphic3d_Mat4d  myCustomHeadToEyeMatL;
0869   Graphic3d_Mat4d  myCustomHeadToEyeMatR;
0870   Aspect_FrustumLRBT<Standard_Real> myCustomFrustumL; //!< left  custom frustum
0871   Aspect_FrustumLRBT<Standard_Real> myCustomFrustumR; //!< right custom frustum
0872   Standard_Boolean myIsCustomProjMatM;  //!< flag indicating usage of custom projection matrix
0873   Standard_Boolean myIsCustomProjMatLR; //!< flag indicating usage of custom stereo projection matrices
0874   Standard_Boolean myIsCustomFrustomLR; //!< flag indicating usage of custom stereo frustums
0875 
0876   mutable TransformMatrices<Standard_Real>      myMatricesD;
0877   mutable TransformMatrices<Standard_ShortReal> myMatricesF;
0878 
0879   mutable Graphic3d_WorldViewProjState myWorldViewProjState;
0880 
0881 public:
0882 
0883   DEFINE_STANDARD_RTTIEXT(Graphic3d_Camera,Standard_Transient)
0884 };
0885 
0886 DEFINE_STANDARD_HANDLE (Graphic3d_Camera, Standard_Transient)
0887 
0888 //! Linear interpolation tool for camera orientation and position.
0889 //! This tool interpolates camera parameters scale, eye, center, rotation (up and direction vectors) independently.
0890 //! @sa Graphic3d_Camera::Interpolate()
0891 template<>
0892 inline void NCollection_Lerp<Handle(Graphic3d_Camera)>::Interpolate (const double theT,
0893                                                                      Handle(Graphic3d_Camera)& theResult) const
0894 {
0895   Graphic3d_Camera::Interpolate (myStart, myEnd, theT, theResult);
0896 }
0897 
0898 //! Linear interpolation tool for camera orientation and position.
0899 //! This tool interpolates camera parameters scale, eye, center, rotation (up and direction vectors) independently.
0900 //! @sa Graphic3d_Camera::Interpolate()
0901 typedef NCollection_Lerp<Handle(Graphic3d_Camera)> Graphic3d_CameraLerp;
0902 
0903 #endif