vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Viewer.h
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include <vrecko/Export>
14 
15 #include <osgViewer/ViewerBase>
16 #include <osgViewer/Viewer>
17 #include <osgViewer/CompositeViewer>
18 
19 namespace vrecko
20 {
22 //TODO: Make this class as a osgViewer::ViewerBase child class
23 class VRECKO_EXPORT ViewerBase : public osg::Referenced
24 {
25 public:
26  virtual osgViewer::ViewerBase* getViewer() = 0;
27 
29  virtual void addView(osgViewer::View* view) = 0;
30 
36  virtual void setDisplaySettings(osg::DisplaySettings* ds1, osg::DisplaySettings* ds2 = NULL) = 0;
37 
39  virtual void setFusionDistance(osgUtil::SceneView::FusionDistanceMode mode, float value=1.0f) = 0;
40 
42  virtual void addEventHandler(osgGA::GUIEventHandler* eventHandler) = 0;
43 
45  virtual void setSceneData(osg::Node* node) = 0;
46 
48  virtual void camera_setViewMatrixAsLookAt(const osg::Vec3d& eye,const osg::Vec3d& center,const osg::Vec3d& up) = 0;
49 
51  virtual void setLight(osg::Light* light) = 0;
52 
54  virtual osg::Light* getLight() = 0;
55 
57  virtual osg::Camera* getCamera(int screenNum = 0) = 0;
58 
60  virtual int getStereoMode() = 0;
61 
63  bool done() {
64  return getViewer()->done();
65  }
66 
68  void realize() {
69  getViewer()->realize();
70  }
71 
72  void setThreadingModel(osgViewer::ViewerBase::ThreadingModel threadingModel) {
73  getViewer()->setThreadingModel(threadingModel);
74  }
75 
76  void getWindows(osgViewer::ViewerBase::Windows& windows, bool onlyValid=true) {
77  getViewer()->getWindows(windows, onlyValid);
78  }
79 
80  void getCameras(osgViewer::ViewerBase::Cameras& cameras, bool onlyActive=true) {
81  getViewer()->getCameras(cameras, onlyActive);
82  }
83 
84  void getContexts(osgViewer::ViewerBase::Contexts& contexts, bool onlyValid=true) {
85  getViewer()->getContexts(contexts, onlyValid);
86  }
87 
88  void frame(double simulationTime=USE_REFERENCE_TIME) {
89  getViewer()->frame(simulationTime);
90  }
91 };
92 
94 class VRECKO_EXPORT Viewer : public ViewerBase
95 {
96 private:
97  int m_stereo;
98  osg::ref_ptr<osgViewer::Viewer> viewer;
99 
100 public:
101  Viewer(int stereoMode);
102 
103  virtual osgViewer::ViewerBase* getViewer() { return viewer; }
104 
106  virtual void addView(osgViewer::View* view) {
107  throw new std::exception("Not supported in this viewer.");
108  }
109 
110  virtual void setDisplaySettings(osg::DisplaySettings* ds1, osg::DisplaySettings* ds2 = NULL) {
111  viewer->setDisplaySettings(ds1);
112  }
113 
114  virtual void setFusionDistance(osgUtil::SceneView::FusionDistanceMode mode, float value=1.0f) {
115  viewer->setFusionDistance(mode, value);
116  }
117 
118  virtual void addEventHandler(osgGA::GUIEventHandler* eventHandler) {
119  viewer->addEventHandler(eventHandler);
120  }
121 
122  virtual void setSceneData(osg::Node* node) {
123  viewer->setSceneData(node);
124  }
125 
126  virtual void camera_setViewMatrixAsLookAt(const osg::Vec3d& eye,const osg::Vec3d& center,const osg::Vec3d& up) {
127  viewer->getCamera()->setViewMatrixAsLookAt(eye, center, up);
128  }
129 
130  virtual void setLight(osg::Light* light) {
131  viewer->setLight(light);
132  }
133 
134  virtual osg::Light* getLight() {
135  return viewer->getLight();
136  }
137 
138  virtual osg::Camera* getCamera(int screenNum = 0) {
139  return viewer->getCamera();
140  }
141 
142  virtual int getStereoMode() {
143  return m_stereo;
144  }
145 
146 };
147 
149 
150 class VRECKO_EXPORT CompositeViewer : public ViewerBase
151 {
152 private:
153  int m_stereo;
154  osg::ref_ptr<osgViewer::CompositeViewer> viewer;
155 
156 public:
157  CompositeViewer(int stereoMode);
158 
159  virtual osgViewer::ViewerBase* getViewer() { return viewer; }
160 
161  virtual void addView(osgViewer::View* view) {
162  viewer->addView(view);
163  }
164 
165  virtual void setDisplaySettings(osg::DisplaySettings* ds1, osg::DisplaySettings* ds2 = NULL) {
166  viewer->getView(0)->setDisplaySettings(ds1);
167  if(m_stereo == 5 && ds2) viewer->getView(1)->setDisplaySettings(ds2);
168  }
169 
170  virtual void setFusionDistance(osgUtil::SceneView::FusionDistanceMode mode, float value=1.0f) {
171  viewer->getView(0)->setFusionDistance(mode, value);
172  if(m_stereo == 5) viewer->getView(1)->setFusionDistance(mode, value);
173  }
174 
175  virtual void addEventHandler(osgGA::GUIEventHandler* eventHandler) {
176  viewer->getView(0)->addEventHandler(eventHandler);
177  }
178 
179  virtual void setSceneData(osg::Node* node) {
180  viewer->getView(0)->setSceneData(node);
181  if(m_stereo == 5) viewer->getView(1)->setSceneData(node);
182  }
183 
184  virtual void camera_setViewMatrixAsLookAt(const osg::Vec3d& eye,const osg::Vec3d& center,const osg::Vec3d& up) {
185  viewer->getView(0)->getCamera()->setViewMatrixAsLookAt(eye, center, up);
186  if(m_stereo == 5) viewer->getView(1)->getCamera()->setViewMatrixAsLookAt(eye, center, up);
187  }
188 
189  virtual void setLight(osg::Light* light) {
190  viewer->getView(0)->setLight(light);
191  if(m_stereo == 5) viewer->getView(1)->setLight(light);
192  }
193 
194  virtual osg::Light* getLight() {
195  return viewer->getView(0)->getLight();
196  }
197 
198  virtual osg::Camera* getCamera(int screenNum = 0) {
199  return viewer->getView(screenNum)->getCamera();
200  }
201 
202  virtual int getStereoMode() {
203  return m_stereo;
204  }
205 
206 };
207 
208 };