Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:50

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 
0028   //! Default constructor.
0029   Graphic3d_WorldViewProjState()
0030   {
0031     Reset();
0032   }
0033 
0034   //! Constructor for custom projector type.
0035   //! @param theProjectionState [in] the projection state.
0036   //! @param theWorldViewState [in] the world view state.
0037   //! @param theCamera [in] the pointer to the class supplying projection and
0038   //!                       world view matrices (camera).
0039   Graphic3d_WorldViewProjState (const Standard_Size theProjectionState,
0040                                 const Standard_Size theWorldViewState,
0041                                 const Standard_Transient* theCamera = NULL)
0042   {
0043     Initialize (theProjectionState, theWorldViewState, theCamera);
0044   }
0045 
0046 public:
0047 
0048   //! Check state validity.
0049   //! @return true if state is set.
0050   Standard_Boolean IsValid()
0051   {
0052     return myIsValid;
0053   }
0054 
0055   //! Invalidate world view projection state.
0056   void Reset()
0057   {
0058     myIsValid         = Standard_False;
0059     myCamera          = NULL;
0060     myProjectionState = 0;
0061     myWorldViewState  = 0;
0062   }
0063 
0064   //! Initialize world view projection state.
0065   void Initialize (const Standard_Size theProjectionState,
0066                    const Standard_Size theWorldViewState,
0067                    const Standard_Transient* theCamera = NULL)
0068   {
0069     myIsValid         = Standard_True;
0070     myCamera          = const_cast<Standard_Transient*> (theCamera);
0071     myProjectionState = theProjectionState;
0072     myWorldViewState  = theWorldViewState;
0073   }
0074 
0075   //! Initialize world view projection state.
0076   void Initialize (const Standard_Transient* theCamera = NULL)
0077   {
0078     myIsValid         = Standard_True;
0079     myCamera          = const_cast<Standard_Transient*> (theCamera);
0080     myProjectionState = 0;
0081     myWorldViewState  = 0;
0082   }
0083 
0084 public:
0085 
0086   //! @return projection state counter.
0087   Standard_Size& ProjectionState()
0088   {
0089     return myProjectionState;
0090   }
0091 
0092   //! @return world view state counter.
0093   Standard_Size& WorldViewState()
0094   {
0095     return myWorldViewState;
0096   }
0097 
0098 public:
0099 
0100   //! Compare projection with other state.
0101   //! @return true when the projection of the given camera state differs from this one.
0102   Standard_Boolean IsProjectionChanged (const Graphic3d_WorldViewProjState& theState)
0103   {
0104     return myIsValid         != theState.myIsValid
0105         || myCamera          != theState.myCamera
0106         || myProjectionState != theState.myProjectionState;
0107   }
0108 
0109   //! Compare world view transformation with other state.
0110   //! @return true when the orientation of the given camera state differs from this one.
0111   Standard_Boolean IsWorldViewChanged (const Graphic3d_WorldViewProjState& theState)
0112   {
0113     return myIsValid        != theState.myIsValid
0114         || myCamera         != theState.myCamera
0115         || myWorldViewState != theState.myWorldViewState;
0116   }
0117 
0118   //! Compare with other world view projection state.
0119   //! @return true when the projection of the given camera state differs from this one.
0120   Standard_Boolean IsChanged (const Graphic3d_WorldViewProjState& theState)
0121   {
0122     return *this != theState;
0123   }
0124 
0125 public:
0126 
0127   //! Compare with other world view projection state.
0128   //! @return true if the other projection state is different to this one.
0129   bool operator != (const Graphic3d_WorldViewProjState& theOther) const
0130   {
0131     return !(*this == theOther);
0132   }
0133 
0134   //! Compare with other world view projection state.
0135   //! @return true if the other projection state is equal to this one.
0136   bool operator == (const Graphic3d_WorldViewProjState& theOther) const
0137   {
0138     return myIsValid         == theOther.myIsValid
0139         && myCamera          == theOther.myCamera
0140         && myProjectionState == theOther.myProjectionState
0141         && myWorldViewState  == theOther.myWorldViewState;
0142   }
0143 
0144   //! Dumps the content of me into the stream
0145   void DumpJson (Standard_OStream& theOStream, Standard_Integer) const
0146   {
0147     OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsValid)
0148     OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myCamera)
0149     OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myProjectionState)
0150     OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myWorldViewState)
0151   }
0152 
0153 private:
0154 
0155   Standard_Boolean    myIsValid;
0156   Standard_Transient* myCamera;
0157   Standard_Size       myProjectionState;
0158   Standard_Size       myWorldViewState;
0159 };
0160 
0161 #endif