Line data Source code
1 :
2 : /* Copyright (c) 2009-2016, Stefan Eilemann <eile@equalizergraphics.com>
3 : *
4 : * This library is free software; you can redistribute it and/or modify it under
5 : * the terms of the GNU Lesser General Public License version 2.1 as published
6 : * by the Free Software Foundation.
7 : *
8 : * This library is distributed in the hope that it will be useful, but WITHOUT
9 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 : * details.
12 : *
13 : * You should have received a copy of the GNU Lesser General Public License
14 : * along with this library; if not, write to the Free Software Foundation, Inc.,
15 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 : */
17 :
18 : #ifndef EQFABRIC_OBSERVER_H
19 : #define EQFABRIC_OBSERVER_H
20 :
21 : #include <eq/fabric/api.h>
22 : #include <eq/fabric/eye.h> // enum
23 : #include <eq/fabric/focusMode.h> // enum
24 : #include <eq/fabric/object.h> // base class
25 : #include <eq/fabric/vmmlib.h>
26 : #include <string>
27 : #include <vector>
28 :
29 : namespace eq
30 : {
31 : namespace fabric
32 : {
33 : /** Base data transport class for observers. @sa eq::Observer */
34 : // cppcheck-suppress noConstructor
35 : template< class C, class O > class Observer : public Object
36 : {
37 : public:
38 : /** The observer visitor type. @version 1.0 */
39 : typedef LeafVisitor< O > Visitor;
40 :
41 : /** @name Data Access */
42 : //@{
43 : /**
44 : * Set the head matrix.
45 : *
46 : * The head matrix specifies the transformation origin->observer. Together
47 : * with the eye separation, this determines the eye positions in the global
48 : * coordinate system. The eye position and wall or projection description
49 : * define the shape of the frustum and the channel's head transformation
50 : * during rendering.
51 : *
52 : * @param matrix the matrix
53 : * @return true if the matrix was changed, false otherwise.
54 : * @version 1.0
55 : */
56 : EQFABRIC_INL bool setHeadMatrix( const Matrix4f& matrix );
57 :
58 : /** @return the current head matrix. @version 1.0 */
59 434 : const Matrix4f& getHeadMatrix() const { return _data.headMatrix; }
60 :
61 : /**
62 : * Set the position of the given eye relative to the observer.
63 : *
64 : * A standard symmetric eye setup uses (+-eyeBase/2, 0, 0).
65 : * @param eye the eye to update.
66 : * @param pos the new eye position.
67 : * @version 1.5.2
68 : */
69 : EQFABRIC_INL void setEyePosition( const Eye eye, const Vector3f& pos );
70 :
71 : /** @return the position of the given eye. @version 1.5.2 */
72 : EQFABRIC_INL const Vector3f& getEyePosition( const Eye eye ) const;
73 :
74 :
75 : /** Set the focal distance. @sa setFocusMode @version 1.1 */
76 : EQFABRIC_INL void setFocusDistance( const float focusDistance );
77 :
78 : /** @return the current focal distance. @version 1.1 */
79 216 : float getFocusDistance() const { return _data.focusDistance; }
80 :
81 : /** Set the focal mode. @version 1.1 */
82 : EQFABRIC_INL void setFocusMode( const FocusMode focusMode );
83 :
84 : /** @return the current focal mode. @version 1.1 */
85 220 : FocusMode getFocusMode() const { return _data.focusMode; }
86 :
87 : /** Set the index of the OpenCV camera for tracking. @version 1.5.2 */
88 : EQFABRIC_INL void setOpenCVCamera( const int32_t index );
89 :
90 : /** @return the current OpenCV camera. @version 1.5.2 */
91 216 : int32_t getOpenCVCamera() const { return _data.camera; }
92 :
93 : /** Set the VRPN tracker device. @version 1.5.2 */
94 : EQFABRIC_INL void setVRPNTracker( const std::string& index );
95 :
96 : /** @return the current VRPN tracker device name. @version 1.5.2 */
97 217 : const std::string& getVRPNTracker() const { return _data.vrpnTracker; }
98 :
99 : /** @return the parent config of this observer. @version 1.0 */
100 0 : const C* getConfig() const { return _config; }
101 :
102 : /** @return the parent config of this observer. @version 1.0 */
103 870 : C* getConfig() { return _config; }
104 :
105 : /** @internal @return the index path to this observer. */
106 : ObserverPath getPath() const;
107 : //@}
108 :
109 : /** @name Operations */
110 : //@{
111 : /**
112 : * Traverse this observer using a observer visitor.
113 : *
114 : * @param visitor the visitor.
115 : * @return the result of the visitor traversal.
116 : * @version 1.0
117 : */
118 : EQFABRIC_INL VisitorResult accept( Visitor& visitor );
119 :
120 : /** Const-version of accept(). @version 1.0 */
121 : EQFABRIC_INL VisitorResult accept( Visitor& visitor ) const;
122 :
123 : virtual void backup(); //!< @internal
124 : virtual void restore(); //!< @internal
125 : //@}
126 :
127 : protected:
128 : /** @internal Construct a new Observer. */
129 : EQFABRIC_INL explicit Observer( C* config );
130 :
131 : /** @internal Destruct this observer. */
132 : EQFABRIC_INL virtual ~Observer();
133 :
134 : /** @internal */
135 : virtual void serialize( co::DataOStream& os,
136 : const uint64_t dirtyBits );
137 : /** @internal */
138 : virtual void deserialize( co::DataIStream& is,
139 : const uint64_t dirtyBits );
140 : virtual void setDirty( const uint64_t bits ); //!< @internal
141 :
142 : /** @internal */
143 : enum DirtyBits
144 : {
145 : DIRTY_EYE_POSITION = Object::DIRTY_CUSTOM << 0,
146 : DIRTY_HEAD = Object::DIRTY_CUSTOM << 1,
147 : DIRTY_FOCUS = Object::DIRTY_CUSTOM << 2,
148 : DIRTY_TRACKER = Object::DIRTY_CUSTOM << 3,
149 : DIRTY_OBSERVER_BITS =
150 : DIRTY_EYE_POSITION | DIRTY_HEAD | DIRTY_FOCUS | DIRTY_TRACKER |
151 : DIRTY_OBJECT_BITS
152 : };
153 :
154 : /** @internal @return the bits to be re-committed by the master. */
155 0 : virtual uint64_t getRedistributableBits() const
156 0 : { return DIRTY_OBSERVER_BITS; }
157 :
158 : private:
159 : /** The parent Config. */
160 : C* const _config;
161 :
162 868 : struct BackupData
163 : {
164 : BackupData();
165 :
166 : Matrix4f headMatrix; //!< The current head position
167 : Vector3f eyePosition[ NUM_EYES ]; //!< The current eye positions
168 : float focusDistance; //!< The current focal distance
169 : FocusMode focusMode; //!< The current focal distance mode
170 : int32_t camera; //!< The OpenCV camera used for head tracking
171 : std::string vrpnTracker; //!< VRPN tracking device
172 : }
173 : _data, _backup;
174 :
175 : struct Private;
176 : Private* _private; // placeholder for binary-compatible changes
177 : };
178 :
179 : template< class C, class O >
180 : EQFABRIC_INL std::ostream& operator << ( std::ostream&,
181 : const Observer< C, O >& );
182 : }
183 : }
184 : #endif // EQFABRIC_OBSERVER_H
|