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

Revision 13413, 15.0 kB (checked in by robert, 13 days ago)

Moved widgets from VolumeEditorWidget? to TransferFunctionWidget?, and widget utilities into WidgetUtils?.

  • 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#include <osgViewer/Keystone>
32
33namespace osgViewer {
34
35
36/** Base class for View configurations for setting up Camera and Windowing.*/
37class OSGVIEWER_EXPORT ViewConfig : public osg::Object
38{
39    public:
40
41        ViewConfig() {}
42
43        ViewConfig(const ViewConfig& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osg::Object(rhs,copyop) {}
44
45        META_Object(osgViewer,ViewConfig);
46       
47        /** configure method that is overridden by Config subclasses.*/
48        virtual void configure(osgViewer::View& /*view*/) const {}
49       
50        /** convinience method for getting the relavent display settings to use.*/
51        virtual osg::DisplaySettings* getActiveDisplaySetting(osgViewer::View& view) const;
52};
53
54
55struct OSGVIEWER_EXPORT DepthPartitionSettings : public osg::Referenced
56{
57    enum DepthMode
58    {
59        FIXED_RANGE,
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
67    DepthMode _mode;
68    double _zNear;
69    double _zMid;
70    double _zFar;
71};
72
73
74/** View holds a single view on a scene, this view may be composed of one or more slave cameras.*/
75class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
76{
77    public:
78
79        View();
80
81        View(const osgViewer::View& view, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
82
83        META_Object(osgViewer,View);
84
85        /** Provide a mechanism for getting the osg::View associated from the GUIActionAdapter.
86          * One would use this to case view to osgViewer::View(er) if supported by the subclass.*/
87        virtual osg::View* asView() { return this; }
88
89        /** Provide a mechanism for getting the viewer object from this osgViewer::View.
90          * In the case of a osgViewer::Viewer the ViewerBase will effectively point to this object as Viewer subclasses from View.
91          * In the case of a osgViewer::CompsoiteViewer the ViewerBase will point to the CompositeViewer that owns this View. */
92        ViewerBase* getViewerBase() { return _viewerBase.get(); }
93
94        /** Take all the settings, Camera and Slaves from the passed in view, leaving it empty. */
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
103        /** Set the scene graph that the View will use.*/
104        virtual void setSceneData(osg::Node* node);
105
106        /** Get the View's scene graph.*/
107        osg::Node* getSceneData() { return _scene.valid() ? _scene->getSceneData() : 0; }
108
109        /** Get the const View's scene graph.*/
110        const osg::Node* getSceneData() const { return _scene.valid() ? _scene->getSceneData() : 0; }
111
112
113        /** Set the View's database pager.*/
114        void setDatabasePager(osgDB::DatabasePager* dp);
115
116        /** Get the View's database pager.*/
117        osgDB::DatabasePager* getDatabasePager();
118
119        /** Get the const View's database pager.*/
120        const osgDB::DatabasePager* getDatabasePager() const;
121
122
123        /** Set the View's image pager.*/
124        void setImagePager(osgDB::ImagePager* ip);
125
126        /** Get the View's image pager.*/
127        osgDB::ImagePager* getImagePager();
128
129        /** Get the const View's image pager.*/
130        const osgDB::ImagePager* getImagePager() const;
131
132       
133        /** Add a Device.
134         * The Device is polled on each new frame via it's Device::checkEvents() method and any events generated then collected via Device::getEventQueue()*/
135        void addDevice(osgGA::Device* eventSource);
136
137        /** Remove a Device. /*/
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
155        /** Set the CameraManipulator that moves the View's master Camera position in response to events.
156          * The parameter resetPosition determines whether manipulator is set to its home position.*/
157        void setCameraManipulator(osgGA::CameraManipulator* manipulator, bool resetPosition = true);
158
159        /** Get the View's CameraManipulator.*/
160        osgGA::CameraManipulator* getCameraManipulator() { return _cameraManipulator.get(); }
161
162        /** Get the const View's CameraManipulator.*/
163        const osgGA::CameraManipulator* getCameraManipulator() const { return _cameraManipulator.get(); }
164
165        /** Set the view to the CameraManipulator's home position, if none is attached home() it does nothing.
166          * Note, to set the home position use getCamaraManipulator()->setHomePosition(...). */
167        void home();
168
169
170        typedef std::list< osg::ref_ptr<osgGA::GUIEventHandler> > EventHandlers;
171
172        /** Add an EventHandler that adds handling of events to the View.*/
173        void addEventHandler(osgGA::GUIEventHandler* eventHandler);
174
175        /** Remove an EventHandler from View.*/
176        void removeEventHandler(osgGA::GUIEventHandler* eventHandler);
177
178        /** Get the View's list of EventHandlers.*/
179        EventHandlers& getEventHandlers() { return _eventHandlers; }
180
181        /** Get the const View's list of EventHandlers.*/
182        const EventHandlers& getEventHandlers() const { return _eventHandlers; }
183
184
185        /** Set the NodePath to any active CoordinateSystemNode present in the Scene.
186          * The CoordinateSystemNode path is used to help applications and CamaraManipulators handle geocentric coordinates systems,
187          * so that the local up direction is known at any position on the whole earth. */
188        void setCoordinateSystemNodePath(const osg::NodePath& nodePath);
189
190        /** Get the NodePath to any active CoordinateSystemNode present in the Scene.*/
191        osg::NodePath getCoordinateSystemNodePath() const;
192
193        /** Compute the NodePath to any active CoordinateSystemNode present in the Scene.*/
194        void computeActiveCoordinateSystemNodePath();
195
196
197        /** Set the DisplaySettings object associated with this view.*/
198        void setDisplaySettings(osg::DisplaySettings* ds) { _displaySettings = ds; }
199
200        /** Set the DisplaySettings object associated with this view.*/
201        osg::DisplaySettings* getDisplaySettings() { return _displaySettings.get(); }
202
203        /** Set the DisplaySettings object associated with this view.*/
204        const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
205
206        /** Set the FusionDistanceMode and Value. Note, only used when working in stereo.*/
207        void setFusionDistance(osgUtil::SceneView::FusionDistanceMode mode,float value=1.0f)
208        {
209            _fusionDistanceMode = mode;
210            _fusionDistanceValue = value;
211        }
212
213        /** Get the FusionDistanceMode.*/
214        osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return _fusionDistanceMode; }
215
216        /** Get the FusionDistanceValue. Note, only used for USE_FUSION_DISTANCE_VALUE & PROPORTIONAL_TO_SCREEN_DISTANCE modes.*/
217        float getFusionDistanceValue() const { return _fusionDistanceValue; }
218
219       
220        /** Apply a viewer configuration to set up Cameras and Windowing. */
221        void apply(ViewConfig* config);
222       
223        ViewConfig* getLastAppliedViewConfig() { return _lastAppliedViewConfig.get(); }
224        const ViewConfig* getLastAppliedViewConfig() const { return _lastAppliedViewConfig.get(); }
225       
226       
227        /** deprecated, use view.apply(new osgViewer::AcrossAllWindows()). */
228        void setUpViewAcrossAllScreens();
229
230        /** depreacted, use view.apply(new osgViewer::SingleWindow(x,y,width,screenNum)). */
231        void setUpViewInWindow(int x, int y, int width, int height, unsigned int screenNum=0);
232
233        /** deprecated, use view.apply(new osgViewer::SingleScreen(screenNum)). */
234        void setUpViewOnSingleScreen(unsigned int screenNum=0);
235
236        /** deprecated, use view.apply(new osgViewer::SphericalDisplay(radius, collar, screenNum, intensityMap, projectorMatrix)). */
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
239        /** depreacted, use view.apply(new osgViewer::PanoramicSphericalDisplay(radius, collar, screenNum, intensityMap, projectorMatrix)). */
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
242        /** deprecated. use view.apply(new osgViewer::WoWVxDisplay(type (20 to 42), screenNum). */
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
247        /** Convenience method for setting up depth partitioning on the specified camera.*/
248        bool setUpDepthPartitionForCamera(osg::Camera* cameraToPartition, DepthPartitionSettings* dps=0);
249
250        /** Convenience method for setting up multiple slave cameras with depth partitioning on each of the view's active cameras.*/
251        bool setUpDepthPartition(DepthPartitionSettings* dsp=0);
252
253
254        /** Return true if this view contains a specified camera.*/
255        bool containsCamera(const osg::Camera* camera) const;
256
257       
258        /** deprecated. */
259        const osg::Camera* getCameraContainingPosition(float x, float y, float& local_x, float& local_y) const;
260
261        /** deprecated. */
262        bool computeIntersections(float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
263
264        /** deprecated. */
265        bool computeIntersections(float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
266
267       
268        /** Compute intersections of a ray, starting the current mouse position, through the specified camera. */
269        bool computeIntersections(const osgGA::GUIEventAdapter& ea, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
270
271        /** 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. */
272        bool computeIntersections(const osgGA::GUIEventAdapter& ea, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
273
274       
275        /** Compute intersections of a ray through the specified camera. */
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
278        /** Compute intersections of a ray through the specified camera and a specified nodePath's subgraph. */
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
294        struct StereoSlaveCallback : public osg::View::Slave::UpdateSlaveCallback
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
300            osg::ref_ptr<osg::DisplaySettings> _ds;
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
318        osg::observer_ptr<ViewerBase>          _viewerBase;
319
320
321        osg::Timer_t                            _startTick;
322
323        Devices                            _eventSources;
324
325        osg::ref_ptr<osgViewer::Scene>          _scene;
326        osg::ref_ptr<osgGA::EventQueue>         _eventQueue;
327        osg::ref_ptr<osgGA::CameraManipulator>  _cameraManipulator;
328        EventHandlers                           _eventHandlers;
329
330        osg::ObserverNodePath                   _coordinateSystemNodePath;
331
332        osg::ref_ptr<osg::DisplaySettings>      _displaySettings;
333        osgUtil::SceneView::FusionDistanceMode  _fusionDistanceMode;
334        float                                   _fusionDistanceValue;
335
336        osg::ref_ptr<ViewConfig>                _lastAppliedViewConfig;
337       
338};
339
340}
341
342#endif
Note: See TracBrowser for help on using the browser.