root/OpenSceneGraph/trunk/include/osgViewer/View @ 13376

Revision 13376, 12.9 kB (checked in by robert, 25 hours ago)

Improved support for controlling the ShadingModel? via the VolumeSettings? object

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
32namespace osgViewer {
33
34
35struct OSGVIEWER_EXPORT DepthPartitionSettings : public osg::Referenced
36{
37    enum DepthMode
38    {
39        FIXED_RANGE,
40        BOUNDING_VOLUME
41    };
42
43    DepthPartitionSettings(DepthMode mode=BOUNDING_VOLUME);
44
45    virtual bool getDepthRange(osg::View& view, unsigned int partition, double& zNear, double& zFar);
46
47    DepthMode _mode;
48    double _zNear;
49    double _zMid;
50    double _zFar;
51};
52
53
54/** View holds a single view on a scene, this view may be composed of one or more slave cameras.*/
55class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
56{
57    public:
58
59        View();
60
61        View(const osgViewer::View& view, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
62
63        META_Object(osgViewer,View);
64
65        /** Provide a mechanism for getting the osg::View associated from the GUIActionAdapter.
66          * One would use this to case view to osgViewer::View(er) if supported by the subclass.*/
67        virtual osg::View* asView() { return this; }
68
69        /** Provide a mechanism for getting the viewer object from this osgViewer::View.
70          * In the case of a osgViewer::Viewer the ViewerBase will effectively point to this object as Viewer subclasses from View.
71          * In the case of a osgViewer::CompsoiteViewer the ViewerBase will point to the CompositeViewer that owns this View. */
72        ViewerBase* getViewerBase() { return _viewerBase.get(); }
73
74        /** Take all the settings, Camera and Slaves from the passed in view, leaving it empty. */
75        virtual void take(osg::View& rhs);
76
77        virtual void setStartTick(osg::Timer_t tick);
78        osg::Timer_t getStartTick() const { return _startTick; }
79
80        Scene* getScene() { return _scene.get(); }
81        const Scene* getScene() const { return _scene.get(); }
82
83        /** Set the scene graph that the View will use.*/
84        virtual void setSceneData(osg::Node* node);
85
86        /** Get the View's scene graph.*/
87        osg::Node* getSceneData() { return _scene.valid() ? _scene->getSceneData() : 0; }
88
89        /** Get the const View's scene graph.*/
90        const osg::Node* getSceneData() const { return _scene.valid() ? _scene->getSceneData() : 0; }
91
92
93        /** Set the View's database pager.*/
94        void setDatabasePager(osgDB::DatabasePager* dp);
95
96        /** Get the View's database pager.*/
97        osgDB::DatabasePager* getDatabasePager();
98
99        /** Get the const View's database pager.*/
100        const osgDB::DatabasePager* getDatabasePager() const;
101
102
103        /** Set the View's image pager.*/
104        void setImagePager(osgDB::ImagePager* ip);
105
106        /** Get the View's image pager.*/
107        osgDB::ImagePager* getImagePager();
108
109        /** Get the const View's image pager.*/
110        const osgDB::ImagePager* getImagePager() const;
111
112       
113        /** Add a Device.
114         * The Device is polled on each new frame via it's Device::checkEvents() method and any events generated then collected via Device::getEventQueue()*/
115        void addDevice(osgGA::Device* eventSource);
116
117        /** Remove a Device. /*/
118        void removeDevice(osgGA::Device* eventSource);
119
120        typedef std::vector< osg::ref_ptr<osgGA::Device> > Devices;
121
122        Devices& getDevices() { return _eventSources; }
123        const Devices& getDevices() const { return _eventSources; }
124
125
126        /* Set the EventQueue that the View uses to integrate external non window related events.*/
127        void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
128
129        /* Get the View's EventQueue.*/
130        osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
131
132        /* Get the const View's EventQueue.*/
133        const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); }
134
135        /** Set the CameraManipulator that moves the View's master Camera position in response to events.
136          * The parameter resetPosition determines whether manipulator is set to its home position.*/
137        void setCameraManipulator(osgGA::CameraManipulator* manipulator, bool resetPosition = true);
138
139        /** Get the View's CameraManipulator.*/
140        osgGA::CameraManipulator* getCameraManipulator() { return _cameraManipulator.get(); }
141
142        /** Get the const View's CameraManipulator.*/
143        const osgGA::CameraManipulator* getCameraManipulator() const { return _cameraManipulator.get(); }
144
145        /** Set the view to the CameraManipulator's home position, if none is attached home() it does nothing.
146          * Note, to set the home position use getCamaraManipulator()->setHomePosition(...). */
147        void home();
148
149
150        typedef std::list< osg::ref_ptr<osgGA::GUIEventHandler> > EventHandlers;
151
152        /** Add an EventHandler that adds handling of events to the View.*/
153        void addEventHandler(osgGA::GUIEventHandler* eventHandler);
154
155        /** Remove an EventHandler from View.*/
156        void removeEventHandler(osgGA::GUIEventHandler* eventHandler);
157
158        /** Get the View's list of EventHandlers.*/
159        EventHandlers& getEventHandlers() { return _eventHandlers; }
160
161        /** Get the const View's list of EventHandlers.*/
162        const EventHandlers& getEventHandlers() const { return _eventHandlers; }
163
164
165        /** Set the NodePath to any active CoordinateSystemNode present in the Scene.
166          * The CoordinateSystemNode path is used to help applications and CamaraManipulators handle geocentric coordinates systems,
167          * so that the local up direction is known at any position on the whole earth. */
168        void setCoordinateSystemNodePath(const osg::NodePath& nodePath);
169
170        /** Get the NodePath to any active CoordinateSystemNode present in the Scene.*/
171        osg::NodePath getCoordinateSystemNodePath() const;
172
173        /** Compute the NodePath to any active CoordinateSystemNode present in the Scene.*/
174        void computeActiveCoordinateSystemNodePath();
175
176
177        /** Set the DisplaySettings object associated with this view.*/
178        void setDisplaySettings(osg::DisplaySettings* ds) { _displaySettings = ds; }
179
180        /** Set the DisplaySettings object associated with this view.*/
181        osg::DisplaySettings* getDisplaySettings() { return _displaySettings.get(); }
182
183        /** Set the DisplaySettings object associated with this view.*/
184        const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
185
186        /** Set the FusionDistanceMode and Value. Note, only used when working in stereo.*/
187        void setFusionDistance(osgUtil::SceneView::FusionDistanceMode mode,float value=1.0f)
188        {
189            _fusionDistanceMode = mode;
190            _fusionDistanceValue = value;
191        }
192
193        /** Get the FusionDistanceMode.*/
194        osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return _fusionDistanceMode; }
195
196        /** Get the FusionDistanceValue. Note, only used for USE_FUSION_DISTANCE_VALUE & PROPORTIONAL_TO_SCREEN_DISTANCE modes.*/
197        float getFusionDistanceValue() const { return _fusionDistanceValue; }
198
199
200        /** Convenience method for creating slave Cameras and associated GraphicsWindows across all screens.*/
201        void setUpViewAcrossAllScreens();
202
203        /** Convenience method for a single camera on a single window.*/
204        void setUpViewInWindow(int x, int y, int width, int height, unsigned int screenNum=0);
205
206        /** Convenience method for a single camera associated with a single full screen GraphicsWindow.*/
207        void setUpViewOnSingleScreen(unsigned int screenNum=0);
208
209
210        /** Convenience method for spherical display using 6 slave cameras rendering the 6 sides of a cube map, and 7th camera doing distortion correction to present on a spherical display.*/
211        void setUpViewFor3DSphericalDisplay(double radius=1.0, double collar=0.45, unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd());
212
213        /** Convenience method for spherical display by rendering main scene to a panoramic 2:1 texture and then doing distortion correction to present onto a spherical display.*/
214        void setUpViewForPanoramicSphericalDisplay(double radius=1.0, double collar=0.45, unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd());
215
216        /** Convenience method for autostereoscopic Philips WoWvx display.*/
217        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);
218
219
220        /** Convenience method for setting up depth partitioning on the specified camera.*/
221        bool setUpDepthPartitionForCamera(osg::Camera* cameraToPartition, DepthPartitionSettings* dps=0);
222
223        /** Convenience method for setting up multiple slave cameras with depth partitioning on each of the view's active cameras.*/
224        bool setUpDepthPartition(DepthPartitionSettings* dsp=0);
225
226
227        /** Return true if this view contains a specified camera.*/
228        bool containsCamera(const osg::Camera* camera) const;
229
230       
231        /** deprecated. */
232        const osg::Camera* getCameraContainingPosition(float x, float y, float& local_x, float& local_y) const;
233
234        /** deprecated. */
235        bool computeIntersections(float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
236
237        /** deprecated. */
238        bool computeIntersections(float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
239
240       
241        /** Compute intersections of a ray, starting the current mouse position, through the specified camera. */
242        bool computeIntersections(const osgGA::GUIEventAdapter& ea, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
243
244        /** Compute intersections of a ray, starting the current mouse position, through the specified master camera's window/eye coordinates and a specified nodePath's subgraph. */
245        bool computeIntersections(const osgGA::GUIEventAdapter& ea, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
246
247       
248        /** Compute intersections of a ray through the specified camera. */
249        bool computeIntersections(const osg::Camera* camera, osgUtil::Intersector::CoordinateFrame cf, float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
250
251        /** Compute intersections of a ray through the specified camera and a specified nodePath's subgraph. */
252        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);
253
254        virtual void requestRedraw();
255        virtual void requestContinuousUpdate(bool needed=true);
256        virtual void requestWarpPointer(float x,float y);
257
258    public:
259
260        void assignSceneDataToCameras();
261        void init();
262
263    protected:
264
265        friend class CompositeViewer;
266
267        virtual ~View();
268
269        virtual osg::GraphicsOperation* createRenderer(osg::Camera* camera);
270
271        osg::observer_ptr<ViewerBase>          _viewerBase;
272
273
274        osg::Timer_t                            _startTick;
275
276        Devices                            _eventSources;
277
278        osg::ref_ptr<osgViewer::Scene>          _scene;
279        osg::ref_ptr<osgGA::EventQueue>         _eventQueue;
280        osg::ref_ptr<osgGA::CameraManipulator>  _cameraManipulator;
281        EventHandlers                           _eventHandlers;
282
283        osg::ObserverNodePath                   _coordinateSystemNodePath;
284
285        osg::ref_ptr<osg::DisplaySettings>      _displaySettings;
286        osgUtil::SceneView::FusionDistanceMode  _fusionDistanceMode;
287        float                                   _fusionDistanceValue;
288};
289
290}
291
292#endif
Note: See TracBrowser for help on using the browser.