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>
36 : class Observer : public Object
37 : {
38 : public:
39 : /** The observer visitor type. @version 1.0 */
40 : typedef LeafVisitor<O> Visitor;
41 :
42 : /** @name Data Access */
43 : //@{
44 : /**
45 : * Set the head matrix.
46 : *
47 : * The head matrix specifies the transformation origin->observer. Together
48 : * with the eye separation, this determines the eye positions in the global
49 : * coordinate system. The eye position and wall or projection description
50 : * define the shape of the frustum and the channel's head transformation
51 : * during rendering.
52 : *
53 : * @param matrix the matrix
54 : * @return true if the matrix was changed, false otherwise.
55 : * @version 1.0
56 : */
57 : EQFABRIC_INL bool setHeadMatrix(const Matrix4f& matrix);
58 :
59 : /** @return the current head matrix. @version 1.0 */
60 414 : const Matrix4f& getHeadMatrix() const { return _data.headMatrix; }
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 : /** Set the focal distance. @sa setFocusMode @version 1.1 */
75 : EQFABRIC_INL void setFocusDistance(const float focusDistance);
76 :
77 : /** @return the current focal distance. @version 1.1 */
78 206 : float getFocusDistance() const { return _data.focusDistance; }
79 : /** Set the focal mode. @version 1.1 */
80 : EQFABRIC_INL void setFocusMode(const FocusMode focusMode);
81 :
82 : /** @return the current focal mode. @version 1.1 */
83 324 : FocusMode getFocusMode() const { return _data.focusMode; }
84 : /** Set the index of the OpenCV camera for tracking. @version 1.5.2 */
85 : EQFABRIC_INL void setOpenCVCamera(const int32_t index);
86 :
87 : /** @return the current OpenCV camera. @version 1.5.2 */
88 206 : int32_t getOpenCVCamera() const { return _data.camera; }
89 : /** Set the VRPN tracker device. @version 1.5.2 */
90 : EQFABRIC_INL void setVRPNTracker(const std::string& index);
91 :
92 : /** @return the current VRPN tracker device name. @version 1.5.2 */
93 207 : const std::string& getVRPNTracker() const { return _data.vrpnTracker; }
94 : /** @return the parent config of this observer. @version 1.0 */
95 0 : const C* getConfig() const { return _config; }
96 : /** @return the parent config of this observer. @version 1.0 */
97 820 : C* getConfig() { return _config; }
98 : /** @internal @return the index path to this observer. */
99 : ObserverPath getPath() const;
100 : //@}
101 :
102 : /** @name Operations */
103 : //@{
104 : /**
105 : * Traverse this observer using a observer visitor.
106 : *
107 : * @param visitor the visitor.
108 : * @return the result of the visitor traversal.
109 : * @version 1.0
110 : */
111 : EQFABRIC_INL VisitorResult accept(Visitor& visitor);
112 :
113 : /** Const-version of accept(). @version 1.0 */
114 : EQFABRIC_INL VisitorResult accept(Visitor& visitor) const;
115 :
116 : virtual void backup(); //!< @internal
117 : virtual void restore(); //!< @internal
118 : //@}
119 :
120 : protected:
121 : /** @internal Construct a new Observer. */
122 : EQFABRIC_INL explicit Observer(C* config);
123 :
124 : /** @internal Destruct this observer. */
125 : EQFABRIC_INL virtual ~Observer();
126 :
127 : /** @internal */
128 : virtual void serialize(co::DataOStream& os, const uint64_t dirtyBits);
129 : /** @internal */
130 : virtual void deserialize(co::DataIStream& is, const uint64_t dirtyBits);
131 : virtual void setDirty(const uint64_t bits); //!< @internal
132 :
133 : /** @internal */
134 : enum DirtyBits
135 : {
136 : DIRTY_EYE_POSITION = Object::DIRTY_CUSTOM << 0,
137 : DIRTY_HEAD = Object::DIRTY_CUSTOM << 1,
138 : DIRTY_FOCUS = Object::DIRTY_CUSTOM << 2,
139 : DIRTY_TRACKER = Object::DIRTY_CUSTOM << 3,
140 : DIRTY_OBSERVER_BITS = DIRTY_EYE_POSITION | DIRTY_HEAD | DIRTY_FOCUS |
141 : DIRTY_TRACKER | DIRTY_OBJECT_BITS
142 : };
143 :
144 : /** @internal @return the bits to be re-committed by the master. */
145 2 : virtual uint64_t getRedistributableBits() const
146 : {
147 2 : return DIRTY_OBSERVER_BITS;
148 : }
149 :
150 : private:
151 : /** The parent Config. */
152 : C* const _config;
153 :
154 816 : struct BackupData
155 : {
156 : BackupData();
157 :
158 : Matrix4f headMatrix; //!< The current head position
159 : Vector3f eyePosition[NUM_EYES]; //!< The current eye positions
160 : float focusDistance; //!< The current focal distance
161 : FocusMode focusMode; //!< The current focal distance mode
162 : int32_t camera; //!< The OpenCV camera used for head tracking
163 : std::string vrpnTracker; //!< VRPN tracking device
164 : } _data, _backup;
165 :
166 : struct Private;
167 : Private* _private; // placeholder for binary-compatible changes
168 : };
169 :
170 : template <class C, class O>
171 : EQFABRIC_INL std::ostream& operator<<(std::ostream&, const Observer<C, O>&);
172 : }
173 : }
174 : #endif // EQFABRIC_OBSERVER_H
|