Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-29 10:53:45

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 size_t              theProjectionState,
0036                                const size_t              theWorldViewState,
0037                                const Standard_Transient* theCamera = nullptr)
0038   {
0039     Initialize(theProjectionState, theWorldViewState, theCamera);
0040   }
0041 
0042 public:
0043   //! Check state validity.
0044   //! @return true if state is set.
0045   bool IsValid() { return myIsValid; }
0046 
0047   //! Invalidate world view projection state.
0048   void Reset()
0049   {
0050     myIsValid         = false;
0051     myCamera          = nullptr;
0052     myProjectionState = 0;
0053     myWorldViewState  = 0;
0054   }
0055 
0056   //! Initialize world view projection state.
0057   void Initialize(const size_t              theProjectionState,
0058                   const size_t              theWorldViewState,
0059                   const Standard_Transient* theCamera = nullptr)
0060   {
0061     myIsValid         = 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 = nullptr)
0069   {
0070     myIsValid         = true;
0071     myCamera          = const_cast<Standard_Transient*>(theCamera);
0072     myProjectionState = 0;
0073     myWorldViewState  = 0;
0074   }
0075 
0076 public:
0077   //! @return projection state counter.
0078   size_t& ProjectionState() { return myProjectionState; }
0079 
0080   //! @return world view state counter.
0081   size_t& 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   bool 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   bool 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   bool IsChanged(const Graphic3d_WorldViewProjState& theState) { return *this != theState; }
0103 
0104 public:
0105   //! Compare with other world view projection state.
0106   //! @return true if the other projection state is different to this one.
0107   bool operator!=(const Graphic3d_WorldViewProjState& theOther) const
0108   {
0109     return !(*this == theOther);
0110   }
0111 
0112   //! Compare with other world view projection state.
0113   //! @return true if the other projection state is equal to this one.
0114   bool operator==(const Graphic3d_WorldViewProjState& theOther) const
0115   {
0116     return myIsValid == theOther.myIsValid && myCamera == theOther.myCamera
0117            && myProjectionState == theOther.myProjectionState
0118            && myWorldViewState == theOther.myWorldViewState;
0119   }
0120 
0121   //! Dumps the content of me into the stream
0122   void DumpJson(Standard_OStream& theOStream, int) const
0123   {
0124     OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myIsValid)
0125     OCCT_DUMP_FIELD_VALUE_POINTER(theOStream, myCamera)
0126     OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myProjectionState)
0127     OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myWorldViewState)
0128   }
0129 
0130 private:
0131   bool                myIsValid;
0132   Standard_Transient* myCamera;
0133   size_t              myProjectionState;
0134   size_t              myWorldViewState;
0135 };
0136 
0137 #endif