2010-01-26 22:57:44 +08:00
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2006-11-27 22:52:07 +08:00
*
2010-01-26 22:57:44 +08:00
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
2006-11-27 22:52:07 +08:00
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
2010-01-26 22:57:44 +08:00
*
2006-11-27 22:52:07 +08:00
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2010-01-26 22:57:44 +08:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2006-11-27 22:52:07 +08:00
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGVIEWER_VIEW
#define OSGVIEWER_VIEW 1
#include <osg/View>
2007-01-10 01:35:46 +08:00
#include <osgUtil/PolytopeIntersector>
#include <osgUtil/LineSegmentIntersector>
2007-09-30 00:46:08 +08:00
#include <osgUtil/UpdateVisitor>
2006-12-23 01:46:21 +08:00
#include <osgUtil/SceneView>
2010-05-27 23:54:37 +08:00
#include <osgGA/CameraManipulator>
2007-09-30 00:46:08 +08:00
#include <osgGA/EventVisitor>
#include <osgGA/EventQueue>
2012-10-24 00:15:03 +08:00
#include <osgGA/Device>
2007-09-30 00:46:08 +08:00
2007-01-10 01:35:46 +08:00
#include <osgViewer/Scene>
2007-09-30 19:37:00 +08:00
#include <osgViewer/ViewerBase>
2013-05-10 18:00:38 +08:00
#include <osgViewer/Keystone>
2007-01-10 01:35:46 +08:00
2006-11-29 04:35:31 +08:00
namespace osgViewer {
2011-03-03 23:52:19 +08:00
2013-05-16 18:11:06 +08:00
/** Base class for View configurations for setting up Camera and Windowing.*/
class OSGVIEWER_EXPORT ViewConfig : public osg::Object
{
public:
ViewConfig() {}
ViewConfig(const ViewConfig& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osg::Object(rhs,copyop) {}
META_Object(osgViewer,ViewConfig);
2013-10-25 22:54:15 +08:00
2013-05-16 18:11:06 +08:00
/** configure method that is overridden by Config subclasses.*/
virtual void configure(osgViewer::View& /*view*/) const {}
2013-10-25 22:54:15 +08:00
2015-04-08 02:01:12 +08:00
/** convenience method for getting the relavent display settings to use.*/
2013-05-16 18:11:06 +08:00
virtual osg::DisplaySettings* getActiveDisplaySetting(osgViewer::View& view) const;
};
2011-03-03 23:52:19 +08:00
struct OSGVIEWER_EXPORT DepthPartitionSettings : public osg::Referenced
{
enum DepthMode
{
FIXED_RANGE,
BOUNDING_VOLUME
};
DepthPartitionSettings(DepthMode mode=BOUNDING_VOLUME);
virtual bool getDepthRange(osg::View& view, unsigned int partition, double& zNear, double& zFar);
DepthMode _mode;
double _zNear;
double _zMid;
double _zFar;
};
2012-03-22 01:36:20 +08:00
2006-11-27 22:52:07 +08:00
/** View holds a single view on a scene, this view may be composed of one or more slave cameras.*/
2007-01-02 02:20:10 +08:00
class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
2006-11-27 22:52:07 +08:00
{
public:
View();
2007-02-26 04:05:23 +08:00
View(const osgViewer::View& view, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgViewer,View);
2010-01-26 22:57:44 +08:00
2007-12-11 01:30:18 +08:00
/** Provide a mechanism for getting the osg::View associated from the GUIActionAdapter.
2007-10-04 19:20:18 +08:00
* One would use this to case view to osgViewer::View(er) if supported by the subclass.*/
virtual osg::View* asView() { return this; }
2010-01-26 22:57:44 +08:00
2007-10-04 19:20:18 +08:00
/** Provide a mechanism for getting the viewer object from this osgViewer::View.
* In the case of a osgViewer::Viewer the ViewerBase will effectively point to this object as Viewer subclasses from View.
* In the case of a osgViewer::CompsoiteViewer the ViewerBase will point to the CompositeViewer that owns this View. */
2007-09-30 00:46:08 +08:00
ViewerBase* getViewerBase() { return _viewerBase.get(); }
2007-09-21 23:34:25 +08:00
/** Take all the settings, Camera and Slaves from the passed in view, leaving it empty. */
virtual void take(osg::View& rhs);
2007-02-26 04:05:23 +08:00
2007-08-10 18:52:35 +08:00
virtual void setStartTick(osg::Timer_t tick);
osg::Timer_t getStartTick() const { return _startTick; }
2007-01-16 16:56:33 +08:00
Scene* getScene() { return _scene.get(); }
const Scene* getScene() const { return _scene.get(); }
2007-06-07 17:58:49 +08:00
/** Set the scene graph that the View will use.*/
2008-12-20 01:50:58 +08:00
virtual void setSceneData(osg::Node* node);
2007-06-07 17:58:49 +08:00
/** Get the View's scene graph.*/
2006-12-20 00:00:51 +08:00
osg::Node* getSceneData() { return _scene.valid() ? _scene->getSceneData() : 0; }
2007-06-07 17:58:49 +08:00
/** Get the const View's scene graph.*/
2006-12-20 00:00:51 +08:00
const osg::Node* getSceneData() const { return _scene.valid() ? _scene->getSceneData() : 0; }
2006-11-27 22:52:07 +08:00
2008-07-21 17:47:39 +08:00
2007-08-10 18:57:00 +08:00
/** Set the View's database pager.*/
void setDatabasePager(osgDB::DatabasePager* dp);
2007-08-10 18:52:35 +08:00
/** Get the View's database pager.*/
osgDB::DatabasePager* getDatabasePager();
/** Get the const View's database pager.*/
const osgDB::DatabasePager* getDatabasePager() const;
2008-07-21 17:47:39 +08:00
/** Set the View's image pager.*/
void setImagePager(osgDB::ImagePager* ip);
/** Get the View's image pager.*/
osgDB::ImagePager* getImagePager();
/** Get the const View's image pager.*/
const osgDB::ImagePager* getImagePager() const;
2013-10-25 22:54:15 +08:00
2012-10-24 00:15:03 +08:00
/** Add a Device.
* The Device is polled on each new frame via it's Device::checkEvents() method and any events generated then collected via Device::getEventQueue()*/
void addDevice(osgGA::Device* eventSource);
/** Remove a Device. /*/
void removeDevice(osgGA::Device* eventSource);
typedef std::vector< osg::ref_ptr<osgGA::Device> > Devices;
Devices& getDevices() { return _eventSources; }
const Devices& getDevices() const { return _eventSources; }
2008-07-21 17:47:39 +08:00
2011-09-12 20:14:17 +08:00
/* Set the EventQueue that the View uses to integrate external non window related events.*/
2006-12-21 05:13:29 +08:00
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
2007-06-07 17:58:49 +08:00
/* Get the View's EventQueue.*/
2006-12-21 05:13:29 +08:00
osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
2007-06-07 17:58:49 +08:00
/* Get the const View's EventQueue.*/
2006-12-21 05:13:29 +08:00
const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); }
2010-01-26 23:08:25 +08:00
/** Set the CameraManipulator that moves the View's master Camera position in response to events.
* The parameter resetPosition determines whether manipulator is set to its home position.*/
2010-05-27 23:54:37 +08:00
void setCameraManipulator(osgGA::CameraManipulator* manipulator, bool resetPosition = true);
2007-06-07 17:58:49 +08:00
/** Get the View's CameraManipulator.*/
2010-05-27 23:54:37 +08:00
osgGA::CameraManipulator* getCameraManipulator() { return _cameraManipulator.get(); }
2007-06-07 17:58:49 +08:00
/** Get the const View's CameraManipulator.*/
2010-05-27 23:54:37 +08:00
const osgGA::CameraManipulator* getCameraManipulator() const { return _cameraManipulator.get(); }
2006-11-27 22:52:07 +08:00
2011-09-12 20:14:17 +08:00
/** Set the view to the CameraManipulator's home position, if none is attached home() it does nothing.
2007-06-07 17:58:49 +08:00
* Note, to set the home position use getCamaraManipulator()->setHomePosition(...). */
void home();
2010-01-26 22:57:44 +08:00
2007-06-07 17:58:49 +08:00
2013-10-25 22:54:15 +08:00
typedef std::list< osg::ref_ptr<osgGA::EventHandler> > EventHandlers;
2010-01-26 22:57:44 +08:00
2007-06-07 17:58:49 +08:00
/** Add an EventHandler that adds handling of events to the View.*/
2013-10-25 22:54:15 +08:00
void addEventHandler(osgGA::EventHandler* eventHandler);
2007-06-07 17:58:49 +08:00
2009-03-11 22:18:30 +08:00
/** Remove an EventHandler from View.*/
2013-10-25 22:54:15 +08:00
void removeEventHandler(osgGA::EventHandler* eventHandler);
2009-03-11 22:18:30 +08:00
2007-06-07 17:58:49 +08:00
/** Get the View's list of EventHandlers.*/
2006-11-27 22:52:07 +08:00
EventHandlers& getEventHandlers() { return _eventHandlers; }
2007-06-07 17:58:49 +08:00
/** Get the const View's list of EventHandlers.*/
2006-11-27 22:52:07 +08:00
const EventHandlers& getEventHandlers() const { return _eventHandlers; }
2010-01-26 22:57:44 +08:00
2007-05-18 18:33:56 +08:00
2007-06-07 17:58:49 +08:00
/** Set the NodePath to any active CoordinateSystemNode present in the Scene.
2011-09-12 20:14:17 +08:00
* The CoordinateSystemNode path is used to help applications and CamaraManipulators handle geocentric coordinates systems,
* so that the local up direction is known at any position on the whole earth. */
2007-05-18 18:33:56 +08:00
void setCoordinateSystemNodePath(const osg::NodePath& nodePath);
/** Get the NodePath to any active CoordinateSystemNode present in the Scene.*/
osg::NodePath getCoordinateSystemNodePath() const;
/** Compute the NodePath to any active CoordinateSystemNode present in the Scene.*/
void computeActiveCoordinateSystemNodePath();
2010-01-26 22:57:44 +08:00
2007-08-02 19:02:47 +08:00
/** Set the DisplaySettings object associated with this view.*/
2007-01-11 20:06:24 +08:00
void setDisplaySettings(osg::DisplaySettings* ds) { _displaySettings = ds; }
2010-01-26 22:57:44 +08:00
2007-08-02 19:02:47 +08:00
/** Set the DisplaySettings object associated with this view.*/
2007-01-11 20:06:24 +08:00
osg::DisplaySettings* getDisplaySettings() { return _displaySettings.get(); }
2010-01-26 22:57:44 +08:00
2007-08-02 19:02:47 +08:00
/** Set the DisplaySettings object associated with this view.*/
2007-01-11 20:06:24 +08:00
const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
2011-09-12 20:14:17 +08:00
/** Set the FusionDistanceMode and Value. Note, only used when working in stereo.*/
2007-05-18 03:58:57 +08:00
void setFusionDistance(osgUtil::SceneView::FusionDistanceMode mode,float value=1.0f)
{
_fusionDistanceMode = mode;
_fusionDistanceValue = value;
}
/** Get the FusionDistanceMode.*/
osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return _fusionDistanceMode; }
/** Get the FusionDistanceValue. Note, only used for USE_FUSION_DISTANCE_VALUE & PROPORTIONAL_TO_SCREEN_DISTANCE modes.*/
float getFusionDistanceValue() const { return _fusionDistanceValue; }
2013-10-25 22:54:15 +08:00
2013-05-16 18:11:06 +08:00
/** Apply a viewer configuration to set up Cameras and Windowing. */
void apply(ViewConfig* config);
2013-10-25 22:54:15 +08:00
2013-05-16 18:11:06 +08:00
ViewConfig* getLastAppliedViewConfig() { return _lastAppliedViewConfig.get(); }
const ViewConfig* getLastAppliedViewConfig() const { return _lastAppliedViewConfig.get(); }
2013-10-25 22:54:15 +08:00
2013-05-16 18:11:06 +08:00
/** deprecated, use view.apply(new osgViewer::AcrossAllWindows()). */
2006-12-20 00:00:51 +08:00
void setUpViewAcrossAllScreens();
2007-01-07 05:06:35 +08:00
2013-05-16 18:11:06 +08:00
/** depreacted, use view.apply(new osgViewer::SingleWindow(x,y,width,screenNum)). */
2007-06-13 18:38:40 +08:00
void setUpViewInWindow(int x, int y, int width, int height, unsigned int screenNum=0);
2013-05-16 18:11:06 +08:00
/** deprecated, use view.apply(new osgViewer::SingleScreen(screenNum)). */
2007-01-07 05:06:35 +08:00
void setUpViewOnSingleScreen(unsigned int screenNum=0);
2010-01-26 22:57:44 +08:00
2013-05-16 18:11:06 +08:00
/** deprecated, use view.apply(new osgViewer::SphericalDisplay(radius, collar, screenNum, intensityMap, projectorMatrix)). */
2008-01-28 23:41:42 +08:00
void setUpViewFor3DSphericalDisplay(double radius=1.0, double collar=0.45, unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd());
2007-09-02 00:56:53 +08:00
2013-05-16 18:11:06 +08:00
/** depreacted, use view.apply(new osgViewer::PanoramicSphericalDisplay(radius, collar, screenNum, intensityMap, projectorMatrix)). */
2008-01-28 23:41:42 +08:00
void setUpViewForPanoramicSphericalDisplay(double radius=1.0, double collar=0.45, unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd());
2007-09-02 00:56:53 +08:00
2013-05-16 18:11:06 +08:00
/** deprecated. use view.apply(new osgViewer::WoWVxDisplay(type (20 to 42), screenNum). */
2008-05-07 22:17:15 +08:00
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);
2013-10-25 22:54:15 +08:00
2010-01-26 22:57:44 +08:00
2012-03-29 23:08:15 +08:00
/** Convenience method for setting up depth partitioning on the specified camera.*/
2011-03-03 23:52:19 +08:00
bool setUpDepthPartitionForCamera(osg::Camera* cameraToPartition, DepthPartitionSettings* dps=0);
2012-03-29 23:08:15 +08:00
/** Convenience method for setting up multiple slave cameras with depth partitioning on each of the view's active cameras.*/
2011-03-03 23:52:19 +08:00
bool setUpDepthPartition(DepthPartitionSettings* dsp=0);
2007-01-16 16:56:33 +08:00
/** Return true if this view contains a specified camera.*/
bool containsCamera(const osg::Camera* camera) const;
2010-01-26 22:57:44 +08:00
2013-10-25 22:54:15 +08:00
2013-05-04 03:26:27 +08:00
/** deprecated. */
2007-01-16 00:09:32 +08:00
const osg::Camera* getCameraContainingPosition(float x, float y, float& local_x, float& local_y) const;
2008-06-03 01:34:47 +08:00
2013-05-04 03:26:27 +08:00
/** deprecated. */
2007-01-10 01:35:46 +08:00
bool computeIntersections(float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
2010-01-26 22:57:44 +08:00
2013-05-04 03:26:27 +08:00
/** deprecated. */
2008-12-10 19:12:37 +08:00
bool computeIntersections(float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
2008-06-03 01:34:47 +08:00
2013-10-25 22:54:15 +08:00
2013-05-04 03:26:27 +08:00
/** Compute intersections of a ray, starting the current mouse position, through the specified camera. */
bool computeIntersections(const osgGA::GUIEventAdapter& ea, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
/** 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. */
bool computeIntersections(const osgGA::GUIEventAdapter& ea, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
2013-10-25 22:54:15 +08:00
2013-05-04 03:26:27 +08:00
/** Compute intersections of a ray through the specified camera. */
bool computeIntersections(const osg::Camera* camera, osgUtil::Intersector::CoordinateFrame cf, float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
/** Compute intersections of a ray through the specified camera and a specified nodePath's subgraph. */
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);
2010-01-26 22:57:44 +08:00
2007-01-02 02:20:10 +08:00
virtual void requestRedraw();
virtual void requestContinuousUpdate(bool needed=true);
virtual void requestWarpPointer(float x,float y);
2010-01-26 22:57:44 +08:00
2013-05-10 18:00:38 +08:00
public:
2013-10-25 22:54:15 +08:00
2013-05-10 18:00:38 +08:00
osg::Texture* createDistortionTexture(int width, int height);
osg::Camera* assignRenderToTextureCamera(osg::GraphicsContext* gc, int width, int height, osg::Texture* texture);
osg::Camera* assignKeystoneDistortionCamera(osg::DisplaySettings* ds, osg::GraphicsContext* gc, int x, int y, int width, int height, GLenum buffer, osg::Texture* texture, Keystone* keystone);
osg::Camera* assignStereoCamera(osg::DisplaySettings* ds, osg::GraphicsContext* gc, int x, int y, int width, int height, GLenum buffer, double eyeScale);
2013-05-21 03:24:34 +08:00
void assignStereoOrKeystoneToCamera(osg::Camera* camera, osg::DisplaySettings* ds);
2013-05-10 18:00:38 +08:00
struct StereoSlaveCallback : public osg::View::Slave::UpdateSlaveCallback
{
StereoSlaveCallback(osg::DisplaySettings* ds, double eyeScale):_ds(ds), _eyeScale(eyeScale) {}
virtual void updateSlave(osg::View& view, osg::View::Slave& slave);
osg::ref_ptr<osg::DisplaySettings> _ds;
double _eyeScale;
};
2013-10-25 22:54:15 +08:00
2013-05-10 18:00:38 +08:00
2006-11-27 22:52:07 +08:00
public:
2010-01-26 22:57:44 +08:00
2006-12-20 00:00:51 +08:00
void assignSceneDataToCameras();
2007-01-17 00:01:01 +08:00
void init();
2006-11-27 22:52:07 +08:00
protected:
2010-01-26 22:57:44 +08:00
2007-09-30 00:46:08 +08:00
friend class CompositeViewer;
2010-01-26 22:57:44 +08:00
2006-11-29 04:35:31 +08:00
virtual ~View();
2006-11-27 22:52:07 +08:00
2007-08-02 19:02:47 +08:00
virtual osg::GraphicsOperation* createRenderer(osg::Camera* camera);
2007-09-30 00:46:08 +08:00
osg::observer_ptr<ViewerBase> _viewerBase;
2007-08-10 18:52:35 +08:00
osg::Timer_t _startTick;
2013-05-24 17:35:58 +08:00
Devices _eventSources;
2012-10-24 00:15:03 +08:00
2006-11-27 22:52:07 +08:00
osg::ref_ptr<osgViewer::Scene> _scene;
2006-12-21 05:13:29 +08:00
osg::ref_ptr<osgGA::EventQueue> _eventQueue;
2010-05-27 23:54:37 +08:00
osg::ref_ptr<osgGA::CameraManipulator> _cameraManipulator;
2006-11-27 22:52:07 +08:00
EventHandlers _eventHandlers;
2010-01-26 22:57:44 +08:00
2010-02-21 01:36:55 +08:00
osg::ObserverNodePath _coordinateSystemNodePath;
2007-05-18 18:33:56 +08:00
2007-01-11 20:06:24 +08:00
osg::ref_ptr<osg::DisplaySettings> _displaySettings;
2007-05-18 03:58:57 +08:00
osgUtil::SceneView::FusionDistanceMode _fusionDistanceMode;
float _fusionDistanceValue;
2013-05-16 18:11:06 +08:00
osg::ref_ptr<ViewConfig> _lastAppliedViewConfig;
2013-10-25 22:54:15 +08:00
2006-11-27 22:52:07 +08:00
};
2006-11-29 04:35:31 +08:00
}
2006-11-27 22:52:07 +08:00
#endif