OpenCOVER
VRViewer.h
Go to the documentation of this file.
1/* This file is part of COVISE.
2
3 You can use it under the terms of the GNU Lesser General Public License
4 version 2.1 or later, see lgpl-2.1.txt.
5
6 * License: LGPL 2+ */
7
8#ifndef VR_VIEWER_H
9#define VR_VIEWER_H
10
28#include <osgViewer/Viewer>
29#include <osgViewer/ViewerEventHandlers>
30
31#include <util/common.h>
32
33#include <osg/Vec3>
34#include <osg/Vec4>
35#include <osg/Matrix>
36#include "ui/Owner.h"
37
38namespace osg
39{
40class Group;
41class DisplaySettings;
42}
43
44namespace opencover
45{
46class MSEventHandler;
47class ARToolKitMarker;
48class angleStruct;
49class coVRStatsDisplay;
50class InitGLOperation;
51
52class COVEREXPORT VRViewer : public osgViewer::Viewer, public ui::Owner
53{
54 friend class OpenCOVER;
55public:
57 static bool mustDraw();
58
60 virtual bool update();
61
63 virtual void frame();
64
66
67 void redrawHUD(double interval);
68
69 static int unsyncedFrames;
70
72 virtual void startThreading();
73
74 void addCamera(osg::Camera *camera);
75 void removeCamera(osg::Camera *camera);
76
77 void setClearColor(const osg::Vec4 &color);
79 void flipStereo();
80
81 void setFullscreen(bool state);
82 bool isFullscreen() const;
83
86
87private:
88 static VRViewer *s_singleton;
89 MSEventHandler *myeh = nullptr;
90
91 // stereo parameters
92 char stereoCommand[500];
93 char monoCommand[500];
94 double lastFrameTime;
95
96 virtual void renderingTraversals();
97
98 // view
99 osg::Vec3 viewPos, viewDir; //, viewYDir;
100 osg::Vec3 initialViewPos;
101 osg::Matrix viewMat;
102 osgViewer::StatsHandler *statsHandler = nullptr;
103
104 angleStruct *screen_angle; // Screen angle: IWR movable screen
105
106 void readConfigFile();
107
108 void setStereoMode();
109
110 void createChannels(int i);
111 void destroyChannels(int i);
112
113 int isHeadtracking;
114 bool fixViewer;
115 osg::Vec4 backgroundColor;
116
117 bool arTracking;
118 ARToolKitMarker *vpMarker;
119 bool overwritePAndV;
120 bool reEnableCulling;
121
122 osg::Geometry *distortionMesh(const char *fileName);
123 void createViewportCameras(int i);
124 void destroyViewportCameras(int i);
125 void createBlendingCameras(int i);
126 void destroyBlendingCameras(int i);
127 float requestedSeparation, separation;
128 int animateSeparation;
129 bool stereoOn;
130
131 std::list<osg::ref_ptr<osg::Camera> > myCameras;
132 void setAffinity();
133
134public:
136 {
137 osg::Matrix view;
138 osg::Matrix proj;
139 };
141 {
145 };
146
148
149 void setFrustumAndView(int i);
150
151 enum Eye {
155 };
156
157 osg::Vec3 eyeOffset(Eye eye) const;
158
160 void setSeparation(float stereoSep);
162
163 virtual ~VRViewer();
164
165 void config();
166 void unconfig();
167
168 virtual void getCameras(Cameras &cameras, bool onlyActive = true);
169 virtual void getContexts(Contexts &contexts, bool onlyValid = true);
170 virtual void getScenes(Scenes &scenes, bool onlyValid = true);
171
172 void updateViewerMat(const osg::Matrix &mat);
173 void setViewerMat(osg::Matrix &mat)
174 {
175 viewMat = mat;
176 };
177 osg::Matrix &getViewerMat()
178 {
179 return (viewMat);
180 };
181 osg::Vec3 &getViewerPos()
182 {
183 return viewPos;
184 };
186 {
187 return initialViewPos;
188 };
189 void setInitialViewerPos(osg::Vec3 &po)
190 {
191 initialViewPos = po;
192 };
193
194 void culling(bool enable, osg::CullSettings::CullingModeValues mode = osg::CullSettings::ENABLE_ALL_CULLING, bool once = false);
195
197 // request angle for movable screen
199 {
200 return screen_angle;
201 };
203 {
204 return separation;
205 };
206
208 {
209 return backgroundColor;
210 };
211
212 bool clearWindow = true; // if set to true, the whole window is cleared once
213 int numClears = 0;
214
216 {
217 overwritePAndV = state;
218 };
220 {
221 return overwritePAndV;
222 };
223
224 void glContextOperation(osg::GraphicsContext *ctx);
225
226 // assert: cull masks of all channels are equal!
227 osg::Node::NodeMask getCullMask() /*const*/;
228 osg::Node::NodeMask getCullMaskLeft() /*const*/;
229 osg::Node::NodeMask getCullMaskRight() /*const*/;
230 std::vector<osg::ref_ptr<osg::Camera>> viewportCamera;
231 std::vector<osg::ref_ptr<osg::Camera>> blendingCamera;
232
233 bool m_fullscreen = false;
234
235 coVRStatsDisplay *statsDisplay = nullptr;
236 InitGLOperation *m_initGlOp = nullptr;
237
238 bool m_requireGlFinish = true;
239};
240
241std::pair<osg::Matrix, osg::Matrix> COVEREXPORT computeViewProjFixedScreen(const osg::Matrix &viewerMat, osg::Vec3 eye, const osg::Vec3 &xyz, const osg::Vec3 &hpr, const osg::Vec2 &size, double near, double far, bool ortho=false, double worldAngle=0.f);
242}
243#endif
Definition: ARToolKit.h:33
std::pair< osg::Matrix, osg::Matrix > COVEREXPORT computeViewProjFixedScreen(const osg::Matrix &viewerMat, osg::Vec3 eye, const osg::Vec3 &xyz, const osg::Vec3 &hpr, const osg::Vec2 &size, double near, double far, bool ortho=false, double worldAngle=0.f)
Definition: coClusterStat.h:29
Definition: ARToolKit.h:168
Definition: coVRConfig.h:127
Definition: coVRStatsDisplay.h:24
Definition: InitGLOperation.h:39
Definition: MSEventHandler.h:10
Definition: OpenCOVER.h:61
Definition: VRViewer.h:53
bool isFullscreen() const
angleStruct * getAngleStruct()
Definition: VRViewer.h:198
virtual void getCameras(Cameras &cameras, bool onlyActive=true)
osg::Vec3 & getViewerPos()
Definition: VRViewer.h:181
void setFrustumAndView(int i)
void setInitialViewerPos(osg::Vec3 &po)
Definition: VRViewer.h:189
FrustaAndViews computeFrustumAndView(int i)
static bool mustDraw()
virtual bool update()
static VRViewer * instance()
void setClearColor(const osg::Vec4 &color)
void overwriteViewAndProjectionMatrix(bool state)
Definition: VRViewer.h:215
void redrawHUD(double interval)
std::vector< osg::ref_ptr< osg::Camera > > viewportCamera
Definition: VRViewer.h:230
osg::Node::NodeMask getCullMaskRight()
virtual void getScenes(Scenes &scenes, bool onlyValid=true)
void glContextOperation(osg::GraphicsContext *ctx)
osg::Vec3 & getInitialViewerPos()
Definition: VRViewer.h:185
osg::Vec3 eyeOffset(Eye eye) const
std::vector< osg::ref_ptr< osg::Camera > > blendingCamera
Definition: VRViewer.h:231
osg::Node::NodeMask getCullMask()
osg::Vec4 getBackgroundColor()
Definition: VRViewer.h:207
void updateViewerMat(const osg::Matrix &mat)
void setRenderToTexture(bool)
virtual void getContexts(Contexts &contexts, bool onlyValid=true)
osg::Node::NodeMask getCullMaskLeft()
void addCamera(osg::Camera *camera)
virtual void frame()
osg::Matrix & getViewerMat()
Definition: VRViewer.h:177
virtual void startThreading()
bool isMatrixOverwriteOn()
Definition: VRViewer.h:219
void setFullscreen(bool state)
float getSeparation()
Definition: VRViewer.h:202
void removeCamera(osg::Camera *camera)
void setViewerMat(osg::Matrix &mat)
Definition: VRViewer.h:173
void setSeparation(float stereoSep)
void culling(bool enable, osg::CullSettings::CullingModeValues mode=osg::CullSettings::ENABLE_ALL_CULLING, bool once=false)
Eye
Definition: VRViewer.h:151
@ EyeRight
Definition: VRViewer.h:154
@ EyeLeft
Definition: VRViewer.h:153
@ EyeMiddle
Definition: VRViewer.h:152
static int unsyncedFrames
Definition: VRViewer.h:69
Definition: VRViewer.h:136
osg::Matrix view
Definition: VRViewer.h:137
osg::Matrix proj
Definition: VRViewer.h:138
Definition: VRViewer.h:141
FrustumAndView right
Definition: VRViewer.h:143
FrustumAndView middle
Definition: VRViewer.h:144
FrustumAndView left
Definition: VRViewer.h:142