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

Revision 13172, 12.4 kB (checked in by robert, 3 hours ago)

From Mattias Helsing, "Seems I was only half right given what you asked for. CMP0017 only
says that modules that are found and ran from cmake modules dir should
prefer cmake-provided modules. find_package() and include() still look
in CMAKE_MODULE_PATH first.

After some investigating I've come up with a proposal examplified in
the attached FindGDAL.cmake script. It simply calls the cmake provided
FindGDAL.cmake if it exists and returns if it succeeds in finding GDAL
using that, otherwise continue with our local cmake code.
Pro: Wont clutter our root CMakeLists.txt
Con: If we begin to write more advanced Findxxx modules (using
COMPONENTS, REQUIRED etc.) we may have to revise this scheme.
"

  • 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        /** Get the camera which contains the pointer position x,y specified in the master camera's window/eye coordinates.
231          * Also passes back the local window coordinatess for the graphics context associated with the camera. */
232        const osg::Camera* getCameraContainingPosition(float x, float y, float& local_x, float& local_y) const;
233
234        /** Compute intersections between a ray through the specified master camera's window/eye coordinates and a specified node.
235          * Note, when a master camera has slaves and no viewport itself, its coordinate frame will be in clip space i.e. -1,-1 to 1,1,
236          * while if it has a viewport the coordintates will be relative to its viewport dimensions.
237          * Mouse events handled by the view will automatically be attached to the master camera window/clip coordinates so that they can be passed
238          * directly to the computeIntersections method. */
239        bool computeIntersections(float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
240
241        /** Compute intersections between a ray through the specified master camera's window/eye coordinates and a specified nodePath's subgraph. */
242        bool computeIntersections(float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
243
244
245        virtual void requestRedraw();
246        virtual void requestContinuousUpdate(bool needed=true);
247        virtual void requestWarpPointer(float x,float y);
248
249    public:
250
251        void assignSceneDataToCameras();
252        void init();
253
254    protected:
255
256        friend class CompositeViewer;
257
258        virtual ~View();
259
260        virtual osg::GraphicsOperation* createRenderer(osg::Camera* camera);
261
262        osg::observer_ptr<ViewerBase>          _viewerBase;
263
264
265        osg::Timer_t                            _startTick;
266
267        Devices                            _eventSources;
268
269        osg::ref_ptr<osgViewer::Scene>          _scene;
270        osg::ref_ptr<osgGA::EventQueue>         _eventQueue;
271        osg::ref_ptr<osgGA::CameraManipulator>  _cameraManipulator;
272        EventHandlers                           _eventHandlers;
273
274        osg::ObserverNodePath                   _coordinateSystemNodePath;
275
276        osg::ref_ptr<osg::DisplaySettings>      _displaySettings;
277        osgUtil::SceneView::FusionDistanceMode  _fusionDistanceMode;
278        float                                   _fusionDistanceValue;
279};
280
281}
282
283#endif
Note: See TracBrowser for help on using the browser.