Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:50:01

0001 // Created on: 2015-06-30
0002 // Created by: Anton POLETAEV
0003 // Copyright (c) 2015 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_WorldViewProjState_HeaderFile
0017 #define _Graphic3d_WorldViewProjState_HeaderFile
0018 
0019 #include <Standard_Transient.hxx>
0020 #include <Standard_TypeDef.hxx>
0021 
0022 //! Helper class for keeping reference on world-view-projection state.
0023 //! Helpful for synchronizing state of WVP dependent data structures.
0024 class Graphic3d_WorldViewProjState
0025 {
0026 public:
0027   //! Default constructor.
0028   Graphic3d_WorldViewProjState() { Reset(); }
0029 
0030   //! Constructor for custom projector type.
0031   //! @param[in] theProjectionState  the projection state.
0032   //! @param[in] theWorldViewState  the world view state.
0033   //! @param[in] theCamera  the pointer to the class supplying projection and
0034   //!                       world view matrices (camera).
0035   Graphic3d_WorldViewProjState(const Standard_Size       theProjectionState,
0036                                const Standard_Size       theWorldViewState,
0037                                const Standard_Transient* theCamera = NULL)
0038   {
0039     Initialize(theProjectionState, theWorldViewState, theCamera);
0040   }
0041 
0042 public:
0043   //! Check state validity.
0044   //! @return true if state is set.
0045   Standard_Boolean IsValid() { return myIsValid; }
0046 
0047   //! Invalidate world view projection state.
0048   void Reset()
0049   {
0050     myIsValid         = Standard_False;
0051     myCamera          = NULL;
0052     myProjectionState = 0;
0053     myWorldViewState  = 0;
0054   }
0055 
0056   //! Initialize world view projection state.
0057   void Initialize(const Standard_Size       theProjectionState,
0058                   const Standard_Size       theWorldViewState,
0059                   const Standard_Transient* theCamera = NULL)
0060   {
0061     myIsValid         = Standard_True;
0062     myCamera          = const_cast<Standard_Transient*>(theCamera);
0063     myProjectionState = theProjectionState;
0064     myWorldViewState  = theWorldViewState;
0065   }
0066 
0067   //! Initialize world view projection state.
0068   void Initialize(const Standard_Transient* theCamera = NULL)
0069   {
0070     myIsValid         = Standard_True;
0071     myCamera          = const_cast<Standard_Transient*>(theCamera);
0072     myProjectionState = 0;
0073     myWorldViewState  = 0;
0074   }
0075 
0076 public:
0077   //! @return projection state counter.
0078   Standard_Size& ProjectionState() { return myProjectionState; }
0079 
0080   //! @return world view state counter.
0081   Standard_Size& WorldViewState() { return myWorldViewState; }
0082 
0083 public:
0084   //! Compare projection with other state.
0085   //! @return true when the projection of the given camera state differs from this one.
0086   Standard_Boolean IsProjectionChanged(const Graphic3d_WorldViewProjState& theState)
0087   {
0088     return myIsValid != theState.myIsValid || myCamera != theState.myCamera
0089            || myProjectionState != theState.myProjectionState;
0090   }
0091 
0092   //! Compare world view transformation with other state.
0093   //! @return true when the orientation of the given camera state differs from this one.
0094   Standard_Boolean IsWorldViewChanged(const Graphic3d_WorldViewProjState& theState)
0095   {
0096     return myIsValid != theState.myIsValid || myCamera != theState.myCamera
0097            || myWorldViewState != theState.myWorldViewState;
0098   }
0099 
0100   //! Compare with other world view projection state.
0101   //! @return true when the projection of the given camera state differs from this one.
0102   Standard_Boolean IsChanged(const Graphic3d_WorldViewProjState& theState)
0103   {
0104     return *this != theState;
0105   }
0106 
0107 public:
0108   //! Compare with other world view projection state.
0109   //! @return true if the other projection state is different to this one.
0110   bool operator!=(const Graphic3d_WorldViewProjState& theOther) const
0111   {
0112     return !(*this == theOther);
0113   }
0114 
0115   //! Compare with other world view projection state.
0116   //! @return true if the other projection state is equal to this one.
0117   bool operator==(const Graphic3d_WorldViewProjState& theOther) const
0118   {
0119     return myIsValid == theOther.myIsValid && myCamera == theOther.myCamera
0120            && myProjectionState == theOther.myProjectionState
0121            && myWorldViewState == theOther.myWorldViewState;
0122   }
0123 
0124   //! Dumps the content of me into the stream
0125   void DumpJson(Standard_OStream& theOStream, Standard_Integer) const
0126   {
0127     OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myIsValid)
0128     OCCT_DUMP_FIELD_VALUE_POINTER(theOStream, myCamera)
0129     OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myProjectionState)
0130     OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myWorldViewState)
0131   }
0132 
0133 private:
0134   Standard_Boolean    myIsValid;
0135   Standard_Transient* myCamera;
0136   Standard_Size       myProjectionState;
0137   Standard_Size       myWorldViewState;
0138 };
0139 
0140 #endif