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

Revision 9418, 11.0 kB (checked in by robert, 5 years ago)

Moved main setSceneData methods in osgViewer::View::setSceneData()

  • 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/MatrixManipulator>
25#include <osgGA/EventVisitor>
26#include <osgGA/EventQueue>
27
28#include <osgViewer/Scene>
29#include <osgViewer/ViewerBase>
30
31namespace osgViewer {
32
33/** View holds a single view on a scene, this view may be composed of one or more slave cameras.*/
34class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
35{
36    public:
37
38        View();
39
40        View(const osgViewer::View& view, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
41
42        META_Object(osgViewer,View);
43       
44        /** Provide a mechanism for getting the osg::View associated from the GUIActionAdapter.
45          * One would use this to case view to osgViewer::View(er) if supported by the subclass.*/
46        virtual osg::View* asView() { return this; }
47       
48        /** Provide a mechanism for getting the viewer object from this osgViewer::View.
49          * In the case of a osgViewer::Viewer the ViewerBase will effectively point to this object as Viewer subclasses from View.
50          * In the case of a osgViewer::CompsoiteViewer the ViewerBase will point to the CompositeViewer that owns this View. */
51        ViewerBase* getViewerBase() { return _viewerBase.get(); }
52
53        /** Take all the settings, Camera and Slaves from the passed in view, leaving it empty. */
54        virtual void take(osg::View& rhs);
55
56        virtual void setStartTick(osg::Timer_t tick);
57        osg::Timer_t getStartTick() const { return _startTick; }
58
59        Scene* getScene() { return _scene.get(); }
60        const Scene* getScene() const { return _scene.get(); }
61
62        /** Set the scene graph that the View will use.*/
63        virtual void setSceneData(osg::Node* node);
64
65        /** Get the View's scene graph.*/
66        osg::Node* getSceneData() { return _scene.valid() ? _scene->getSceneData() : 0; }
67
68        /** Get the const View's scene graph.*/
69        const osg::Node* getSceneData() const { return _scene.valid() ? _scene->getSceneData() : 0; }
70
71
72        /** Set the View's database pager.*/
73        void setDatabasePager(osgDB::DatabasePager* dp);
74
75        /** Get the View's database pager.*/
76        osgDB::DatabasePager* getDatabasePager();
77
78        /** Get the const View's database pager.*/
79        const osgDB::DatabasePager* getDatabasePager() const;
80
81
82        /** Set the View's image pager.*/
83        void setImagePager(osgDB::ImagePager* ip);
84
85        /** Get the View's image pager.*/
86        osgDB::ImagePager* getImagePager();
87
88        /** Get the const View's image pager.*/
89        const osgDB::ImagePager* getImagePager() const;
90
91
92        /* Set the EventQueue that View uses to integrate external non window related events.*/
93        void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
94
95        /* Get the View's EventQueue.*/
96        osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
97
98        /* Get the const View's EventQueue.*/
99        const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); }
100
101        /** Set the CameraManipulator that moves the View's master Camera position in response to events.*/
102        void setCameraManipulator(osgGA::MatrixManipulator* manipulator);
103
104        /** Get the View's CameraManipulator.*/
105        osgGA::MatrixManipulator* getCameraManipulator() { return _cameraManipulator.get(); }
106
107        /** Get the const View's CameraManipulator.*/
108        const osgGA::MatrixManipulator* getCameraManipulator() const { return _cameraManipulator.get(); }
109
110        /** Set the view to the CameraManipulator's home position, if non is attached home() is does nothing.
111          * Note, to set the home position use getCamaraManipulator()->setHomePosition(...). */
112        void home();
113       
114
115        typedef std::list< osg::ref_ptr<osgGA::GUIEventHandler> > EventHandlers;
116       
117        /** Add an EventHandler that adds handling of events to the View.*/
118        void addEventHandler(osgGA::GUIEventHandler* eventHandler);
119
120        /** Get the View's list of EventHandlers.*/
121        EventHandlers& getEventHandlers() { return _eventHandlers; }
122
123        /** Get the const View's list of EventHandlers.*/
124        const EventHandlers& getEventHandlers() const { return _eventHandlers; }
125       
126
127        /** Set the NodePath to any active CoordinateSystemNode present in the Scene.
128          * The CoordinateSystemNode path is used to help applications and CamaraManipualtors handle geocentric coordinates systems,
129          * such as known which way is the local up at any position on the a whole earth. */
130        void setCoordinateSystemNodePath(const osg::NodePath& nodePath);
131
132        /** Get the NodePath to any active CoordinateSystemNode present in the Scene.*/
133        osg::NodePath getCoordinateSystemNodePath() const;
134
135        /** Compute the NodePath to any active CoordinateSystemNode present in the Scene.*/
136        void computeActiveCoordinateSystemNodePath();
137
138       
139        /** Set the DisplaySettings object associated with this view.*/
140        void setDisplaySettings(osg::DisplaySettings* ds) { _displaySettings = ds; }
141       
142        /** Set the DisplaySettings object associated with this view.*/
143        osg::DisplaySettings* getDisplaySettings() { return _displaySettings.get(); }
144       
145        /** Set the DisplaySettings object associated with this view.*/
146        const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
147
148        /** Set the FusionDistanceMode and Value. Note, is used only when working in stereo.*/
149        void setFusionDistance(osgUtil::SceneView::FusionDistanceMode mode,float value=1.0f)
150        {
151            _fusionDistanceMode = mode;
152            _fusionDistanceValue = value;
153        }
154
155        /** Get the FusionDistanceMode.*/
156        osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return _fusionDistanceMode; }
157
158        /** Get the FusionDistanceValue. Note, only used for USE_FUSION_DISTANCE_VALUE & PROPORTIONAL_TO_SCREEN_DISTANCE modes.*/
159        float getFusionDistanceValue() const { return _fusionDistanceValue; }
160
161       
162        /** Convenience method for creating slave Cameras and associated GraphicsWindows across all screens.*/
163        void setUpViewAcrossAllScreens();
164
165        /** Convenience method for a single camera on a single window.*/
166        void setUpViewInWindow(int x, int y, int width, int height, unsigned int screenNum=0);
167
168        /** Convenience method for a single camera associated with a single full screen GraphicsWindow.*/
169        void setUpViewOnSingleScreen(unsigned int screenNum=0);
170       
171
172        /** 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.*/
173        void setUpViewFor3DSphericalDisplay(double radius=1.0, double collar=0.45, unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd());
174
175        /** Convenience method for spherical display by rendering main scene to as panoramic 2:1 texture and then doing distortion correction to present onto a spherical display.*/
176        void setUpViewForPanoramicSphericalDisplay(double radius=1.0, double collar=0.45, unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd());
177
178        /** Convenience method for autostereoscopic Philips WoWvx display.*/
179        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);
180
181       
182        /** Return true if this view contains a specified camera.*/
183        bool containsCamera(const osg::Camera* camera) const;
184       
185        /** Get the camera which contains the pointer position x,y specified master cameras window/eye coords.
186          * Also passes back the local window coords for the graphics context associated with the camera passed back. */
187        const osg::Camera* getCameraContainingPosition(float x, float y, float& local_x, float& local_y) const;
188
189        /** Compute intersections between a ray through the specified master cameras window/eye coords and a specified node.
190          * Note, when a master cameras has slaves and no viewport itself its coordinate frame will be in clip space i.e. -1,-1 to 1,1,
191          * while if its has a viewport the coordintates will be relative to its viewport dimensions.
192          * Mouse events handled by the view will automatically be attached into the master camera window/clip coords so can be passed
193          * directly on to the computeIntersections method. */
194        bool computeIntersections(float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
195       
196        /** Compute intersections between a ray through the specified master cameras window/eye coords and a specified nodePath's subgraph. */
197        bool computeIntersections(float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
198
199       
200        virtual void requestRedraw();
201        virtual void requestContinuousUpdate(bool needed=true);
202        virtual void requestWarpPointer(float x,float y);
203       
204    public:
205       
206        void assignSceneDataToCameras();
207        void init();
208
209    protected:
210   
211        friend class CompositeViewer;
212   
213        virtual ~View();
214
215        virtual osg::GraphicsOperation* createRenderer(osg::Camera* camera);
216
217        osg::observer_ptr<ViewerBase>          _viewerBase;
218
219
220        osg::Timer_t                            _startTick;
221
222        osg::ref_ptr<osgViewer::Scene>          _scene;
223        osg::ref_ptr<osgGA::EventQueue>         _eventQueue;
224        osg::ref_ptr<osgGA::MatrixManipulator>  _cameraManipulator;
225        EventHandlers                           _eventHandlers;
226   
227        typedef std::vector< osg::observer_ptr<osg::Node> >   ObserverNodePath;
228        ObserverNodePath                        _coordinateSystemNodePath;
229
230        osg::ref_ptr<osg::DisplaySettings>      _displaySettings;
231        osgUtil::SceneView::FusionDistanceMode  _fusionDistanceMode;
232        float                                   _fusionDistanceValue;
233};
234
235}
236
237#endif
Note: See TracBrowser for help on using the browser.