OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
View.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 #ifndef OSGVIEWER_VIEW
15 #define OSGVIEWER_VIEW 1
16 
17 #include <osg/View>
18 
19 #include <osgUtil/PolytopeIntersector>
20 #include <osgUtil/LineSegmentIntersector>
21 #include <osgUtil/UpdateVisitor>
22 #include <osgUtil/SceneView>
23 
24 #include <osgGA/CameraManipulator>
25 #include <osgGA/EventVisitor>
26 #include <osgGA/EventQueue>
27 #include <osgGA/Device>
28 
29 #include <osgViewer/Scene>
30 #include <osgViewer/ViewerBase>
31 #include <osgViewer/Keystone>
32 
33 namespace osgViewer {
34 
35 
38 {
39  public:
40 
42 
43  ViewConfig(const ViewConfig& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osg::Object(rhs,copyop) {}
44 
46 
48  virtual void configure(osgViewer::View& /*view*/) const {}
49 
51  virtual osg::DisplaySettings* getActiveDisplaySetting(osgViewer::View& view) const;
52 };
53 
54 
56 {
57  enum DepthMode
58  {
60  BOUNDING_VOLUME
61  };
62 
63  DepthPartitionSettings(DepthMode mode=BOUNDING_VOLUME);
64 
65  virtual bool getDepthRange(osg::View& view, unsigned int partition, double& zNear, double& zFar);
66 
68  double _zNear;
69  double _zMid;
70  double _zFar;
71 };
72 
73 
76 {
77  public:
78 
79  View();
80 
81  View(const osgViewer::View& view, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
82 
84 
87  virtual osg::View* asView() { return this; }
88 
92  ViewerBase* getViewerBase() { return _viewerBase.get(); }
93 
95  virtual void take(osg::View& rhs);
96 
97  virtual void setStartTick(osg::Timer_t tick);
98  osg::Timer_t getStartTick() const { return _startTick; }
99 
100  Scene* getScene() { return _scene.get(); }
101  const Scene* getScene() const { return _scene.get(); }
102 
104  virtual void setSceneData(osg::Node* node);
105 
107  osg::Node* getSceneData() { return _scene.valid() ? _scene->getSceneData() : 0; }
108 
110  const osg::Node* getSceneData() const { return _scene.valid() ? _scene->getSceneData() : 0; }
111 
112 
114  void setDatabasePager(osgDB::DatabasePager* dp);
115 
117  osgDB::DatabasePager* getDatabasePager();
118 
120  const osgDB::DatabasePager* getDatabasePager() const;
121 
122 
124  void setImagePager(osgDB::ImagePager* ip);
125 
127  osgDB::ImagePager* getImagePager();
128 
130  const osgDB::ImagePager* getImagePager() const;
131 
132 
135  void addDevice(osgGA::Device* eventSource);
136 
138  void removeDevice(osgGA::Device* eventSource);
139 
140  typedef std::vector< osg::ref_ptr<osgGA::Device> > Devices;
141 
142  Devices& getDevices() { return _eventSources; }
143  const Devices& getDevices() const { return _eventSources; }
144 
145 
146  /* Set the EventQueue that the View uses to integrate external non window related events.*/
147  void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
148 
149  /* Get the View's EventQueue.*/
150  osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
151 
152  /* Get the const View's EventQueue.*/
153  const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); }
154 
157  void setCameraManipulator(osgGA::CameraManipulator* manipulator, bool resetPosition = true);
158 
160  osgGA::CameraManipulator* getCameraManipulator() { return _cameraManipulator.get(); }
161 
163  const osgGA::CameraManipulator* getCameraManipulator() const { return _cameraManipulator.get(); }
164 
167  void home();
168 
169 
170  typedef std::list< osg::ref_ptr<osgGA::EventHandler> > EventHandlers;
171 
173  void addEventHandler(osgGA::EventHandler* eventHandler);
174 
176  void removeEventHandler(osgGA::EventHandler* eventHandler);
177 
179  EventHandlers& getEventHandlers() { return _eventHandlers; }
180 
182  const EventHandlers& getEventHandlers() const { return _eventHandlers; }
183 
184 
188  void setCoordinateSystemNodePath(const osg::NodePath& nodePath);
189 
191  osg::NodePath getCoordinateSystemNodePath() const;
192 
194  void computeActiveCoordinateSystemNodePath();
195 
196 
198  void setDisplaySettings(osg::DisplaySettings* ds) { _displaySettings = ds; }
199 
201  osg::DisplaySettings* getDisplaySettings() { return _displaySettings.get(); }
202 
204  const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
205 
208  {
209  _fusionDistanceMode = mode;
210  _fusionDistanceValue = value;
211  }
212 
214  osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return _fusionDistanceMode; }
215 
217  float getFusionDistanceValue() const { return _fusionDistanceValue; }
218 
219 
221  void apply(ViewConfig* config);
222 
223  ViewConfig* getLastAppliedViewConfig() { return _lastAppliedViewConfig.get(); }
224  const ViewConfig* getLastAppliedViewConfig() const { return _lastAppliedViewConfig.get(); }
225 
226 
228  void setUpViewAcrossAllScreens();
229 
231  void setUpViewInWindow(int x, int y, int width, int height, unsigned int screenNum=0);
232 
234  void setUpViewOnSingleScreen(unsigned int screenNum=0);
235 
237  void setUpViewFor3DSphericalDisplay(double radius=1.0, double collar=0.45, unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd());
238 
240  void setUpViewForPanoramicSphericalDisplay(double radius=1.0, double collar=0.45, unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd());
241 
243  void setUpViewForWoWVxDisplay(unsigned int screenNum, unsigned char wow_content, unsigned char wow_factor, unsigned char wow_offset, float wow_disparity_Zd, float wow_disparity_vz, float wow_disparity_M, float wow_disparity_C);
244 
245 
246 
248  bool setUpDepthPartitionForCamera(osg::Camera* cameraToPartition, DepthPartitionSettings* dps=0);
249 
251  bool setUpDepthPartition(DepthPartitionSettings* dsp=0);
252 
253 
255  bool containsCamera(const osg::Camera* camera) const;
256 
257 
259  const osg::Camera* getCameraContainingPosition(float x, float y, float& local_x, float& local_y) const;
260 
262  bool computeIntersections(float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
263 
265  bool computeIntersections(float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
266 
267 
269  bool computeIntersections(const osgGA::GUIEventAdapter& ea, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
270 
272  bool computeIntersections(const osgGA::GUIEventAdapter& ea, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
273 
274 
276  bool computeIntersections(const osg::Camera* camera, osgUtil::Intersector::CoordinateFrame cf, float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
277 
279  bool computeIntersections(const osg::Camera* camera, osgUtil::Intersector::CoordinateFrame cf, float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
280 
281  virtual void requestRedraw();
282  virtual void requestContinuousUpdate(bool needed=true);
283  virtual void requestWarpPointer(float x,float y);
284 
285 
286  public:
287 
288  osg::Texture* createDistortionTexture(int width, int height);
289  osg::Camera* assignRenderToTextureCamera(osg::GraphicsContext* gc, int width, int height, osg::Texture* texture);
290  osg::Camera* assignKeystoneDistortionCamera(osg::DisplaySettings* ds, osg::GraphicsContext* gc, int x, int y, int width, int height, GLenum buffer, osg::Texture* texture, Keystone* keystone);
291  osg::Camera* assignStereoCamera(osg::DisplaySettings* ds, osg::GraphicsContext* gc, int x, int y, int width, int height, GLenum buffer, double eyeScale);
292  void assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySettings* ds);
293 
295  {
296  StereoSlaveCallback(osg::DisplaySettings* ds, double eyeScale):_ds(ds), _eyeScale(eyeScale) {}
297 
298  virtual void updateSlave(osg::View& view, osg::View::Slave& slave);
299 
301  double _eyeScale;
302  };
303 
304 
305  public:
306 
307  void assignSceneDataToCameras();
308  void init();
309 
310  protected:
311 
312  friend class CompositeViewer;
313 
314  virtual ~View();
315 
316  virtual osg::GraphicsOperation* createRenderer(osg::Camera* camera);
317 
319 
320 
322 
323  Devices _eventSources;
324 
328  EventHandlers _eventHandlers;
329 
331 
335 
337 
338 };
339 
340 }
341 
342 #endif
float getFusionDistanceValue() const
Definition: View.h:217
osg::ref_ptr< osgViewer::Scene > _scene
Definition: View.h:325
osgUtil::SceneView::FusionDistanceMode _fusionDistanceMode
Definition: View.h:333
const EventHandlers & getEventHandlers() const
Definition: View.h:182
osg::ref_ptr< osgGA::EventQueue > _eventQueue
Definition: View.h:326
osgGA::EventQueue * getEventQueue()
Definition: View.h:150
std::list< osg::ref_ptr< osgGA::EventHandler > > EventHandlers
Definition: View.h:170
#define OSGVIEWER_EXPORT
Definition: Export.h:40
osg::Timer_t _startTick
Definition: View.h:321
const osgGA::CameraManipulator * getCameraManipulator() const
Definition: View.h:163
osg::Node * getSceneData()
Definition: View.h:107
const ViewConfig * getLastAppliedViewConfig() const
Definition: View.h:224
osg::ObserverNodePath _coordinateSystemNodePath
Definition: View.h:330
EventHandlers _eventHandlers
Definition: View.h:328
float _fusionDistanceValue
Definition: View.h:334
const osgGA::EventQueue * getEventQueue() const
Definition: View.h:153
const Scene * getScene() const
Definition: View.h:101
unsigned long long Timer_t
Definition: Timer.h:24
void setDisplaySettings(osg::DisplaySettings *ds)
Definition: View.h:198
#define META_Object(library, name)
Definition: Object.h:42
std::multiset< Intersection > Intersections
GLint GLenum GLsizei width
Definition: GLU.h:71
osg::ref_ptr< osg::DisplaySettings > _ds
Definition: View.h:300
osg::ref_ptr< osgGA::CameraManipulator > _cameraManipulator
Definition: View.h:327
Devices _eventSources
Definition: View.h:323
void setFusionDistance(osgUtil::SceneView::FusionDistanceMode mode, float value=1.0f)
Definition: View.h:207
osg::ref_ptr< osg::DisplaySettings > _displaySettings
Definition: View.h:332
osg::DisplaySettings * getDisplaySettings()
Definition: View.h:201
ViewerBase * getViewerBase()
Definition: View.h:92
const osg::Node * getSceneData() const
Definition: View.h:110
osg::observer_ptr< ViewerBase > _viewerBase
Definition: View.h:318
osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const
Definition: View.h:214
virtual void configure(osgViewer::View &) const
Definition: View.h:48
void setEventQueue(osgGA::EventQueue *eventQueue)
Definition: View.h:147
GLint GLenum GLsizei GLsizei height
Definition: GLU.h:71
Scene * getScene()
Definition: View.h:100
osg::ref_ptr< ViewConfig > _lastAppliedViewConfig
Definition: View.h:336
virtual osg::View * asView()
Definition: View.h:87
EventHandlers & getEventHandlers()
Definition: View.h:179
Definition: Node.h:71
Definition: AlphaFunc.h:19
StereoSlaveCallback(osg::DisplaySettings *ds, double eyeScale)
Definition: View.h:296
const osg::DisplaySettings * getDisplaySettings() const
Definition: View.h:204
osgGA::CameraManipulator * getCameraManipulator()
Definition: View.h:160
osg::Timer_t getStartTick() const
Definition: View.h:98
unsigned int NodeMask
Definition: Node.h:352
ViewConfig(const ViewConfig &rhs, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: View.h:43
Definition: View.h:29
ViewConfig * getLastAppliedViewConfig()
Definition: View.h:223
std::vector< Node * > NodePath
Definition: Node.h:44