825aa485 |
1 | // Created on: 2015-06-30 |
2 | // Created by: Anton POLETAEV |
3 | // Copyright (c) 2015 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #ifndef _Graphic3d_WorldViewProjState_HeaderFile |
17 | #define _Graphic3d_WorldViewProjState_HeaderFile |
18 | |
19 | #include <Standard_Transient.hxx> |
20 | #include <Standard_TypeDef.hxx> |
21 | |
22 | //! Helper class for keeping reference on world-view-projection state. |
23 | //! Helpful for synchronizing state of WVP dependent data structures. |
24 | class Graphic3d_WorldViewProjState |
25 | { |
26 | public: |
27 | |
28 | //! Default constructor. |
29 | Graphic3d_WorldViewProjState() |
30 | { |
31 | Reset(); |
32 | } |
33 | |
34 | //! Constructor for custom projector type. |
35 | //! @param theProjectionState [in] the projection state. |
36 | //! @param theWorldViewState [in] the world view state. |
37 | //! @param theCamera [in] the pointer to the class supplying projection and |
38 | //! world view matrices (camera). |
39 | Graphic3d_WorldViewProjState (const Standard_Size theProjectionState, |
40 | const Standard_Size theWorldViewState, |
41 | const Standard_Transient* theCamera = NULL) |
42 | { |
43 | Initialize (theProjectionState, theWorldViewState, theCamera); |
44 | } |
45 | |
46 | public: |
47 | |
48 | //! Check state validity. |
49 | //! @return true if state is set. |
50 | Standard_Boolean IsValid() |
51 | { |
52 | return myIsValid; |
53 | } |
54 | |
55 | //! Invalidate world view projection state. |
56 | void Reset() |
57 | { |
58 | myIsValid = Standard_False; |
59 | myCamera = NULL; |
60 | myProjectionState = 0; |
61 | myWorldViewState = 0; |
62 | } |
63 | |
64 | //! Initialize world view projection state. |
65 | void Initialize (const Standard_Size theProjectionState, |
66 | const Standard_Size theWorldViewState, |
67 | const Standard_Transient* theCamera = NULL) |
68 | { |
69 | myIsValid = Standard_True; |
70 | myCamera = const_cast<Standard_Transient*> (theCamera); |
71 | myProjectionState = theProjectionState; |
72 | myWorldViewState = theWorldViewState; |
73 | } |
74 | |
75 | //! Initialize world view projection state. |
76 | void Initialize (const Standard_Transient* theCamera = NULL) |
77 | { |
78 | myIsValid = Standard_True; |
79 | myCamera = const_cast<Standard_Transient*> (theCamera); |
80 | myProjectionState = 0; |
81 | myWorldViewState = 0; |
82 | } |
83 | |
84 | public: |
85 | |
86 | //! @return projection state counter. |
87 | Standard_Size& ProjectionState() |
88 | { |
89 | return myProjectionState; |
90 | } |
91 | |
92 | //! @return world view state counter. |
93 | Standard_Size& WorldViewState() |
94 | { |
95 | return myWorldViewState; |
96 | } |
97 | |
98 | public: |
99 | |
100 | //! Compare projection with other state. |
101 | //! @return true when the projection of the given camera state differs from this one. |
102 | Standard_Boolean IsProjectionChanged (const Graphic3d_WorldViewProjState& theState) |
103 | { |
104 | return myIsValid != theState.myIsValid |
105 | || myCamera != theState.myCamera |
106 | || myProjectionState != theState.myProjectionState; |
107 | } |
108 | |
109 | //! Compare world view transformation with other state. |
110 | //! @return true when the orientation of the given camera state differs from this one. |
111 | Standard_Boolean IsWorldViewChanged (const Graphic3d_WorldViewProjState& theState) |
112 | { |
113 | return myIsValid != theState.myIsValid |
114 | || myCamera != theState.myCamera |
115 | || myWorldViewState != theState.myWorldViewState; |
116 | } |
117 | |
118 | //! Compare with other world view projection state. |
119 | //! @return true when the projection of the given camera state differs from this one. |
120 | Standard_Boolean IsChanged (const Graphic3d_WorldViewProjState& theState) |
121 | { |
122 | return *this != theState; |
123 | } |
124 | |
125 | public: |
126 | |
127 | //! Compare with other world view projection state. |
128 | //! @return true if the other projection state is different to this one. |
129 | bool operator != (const Graphic3d_WorldViewProjState& theOther) const |
130 | { |
131 | return !(*this == theOther); |
132 | } |
133 | |
134 | //! Compare with other world view projection state. |
135 | //! @return true if the other projection state is equal to this one. |
136 | bool operator == (const Graphic3d_WorldViewProjState& theOther) const |
137 | { |
138 | return myIsValid == theOther.myIsValid |
139 | && myCamera == theOther.myCamera |
140 | && myProjectionState == theOther.myProjectionState |
141 | && myWorldViewState == theOther.myWorldViewState; |
142 | } |
143 | |
144 | //! Copy world view projection state. |
145 | void operator = (const Graphic3d_WorldViewProjState& theOther) |
146 | { |
147 | myIsValid = theOther.myIsValid; |
148 | myCamera = theOther.myCamera; |
149 | myProjectionState = theOther.myProjectionState; |
150 | myWorldViewState = theOther.myWorldViewState; |
151 | } |
152 | |
153 | private: |
154 | |
155 | Standard_Boolean myIsValid; |
156 | Standard_Transient* myCamera; |
157 | Standard_Size myProjectionState; |
158 | Standard_Size myWorldViewState; |
159 | }; |
160 | |
161 | #endif |