1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
14#ifndef OSGVIEWER_Viewer
15#define OSGVIEWER_Viewer 1
17#include <osg/ArgumentParser>
18#include <osgGA/EventVisitor>
19#include <osgUtil/UpdateVisitor>
20#include <osgViewer/GraphicsWindow>
21#include <osgViewer/View>
26/** Viewer holds a single view on to a single scene.*/
27class OSGVIEWER_EXPORT Viewer : public ViewerBase, public osgViewer::View
33 Viewer(osg::ArgumentParser& arguments);
35 Viewer(const osgViewer::Viewer& viewer, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
39 META_Object(osgViewer,Viewer);
41 /** Take all the settings, Camera and Slaves from the passed in view(er), leaving it empty. */
42 virtual void take(osg::View& rhs);
45 /** Set the Stats object used to collect various frame related timing and scene graph stats.*/
46 virtual void setViewerStats(osg::Stats* stats) { setStats(stats); }
48 /** Get the Viewers Stats object.*/
49 virtual osg::Stats* getViewerStats() { return getStats(); }
51 /** Get the Viewers Stats object.*/
52 virtual const osg::Stats* getViewerStats() const { return getStats(); }
55 /** read the viewer configuration from a configuration file.*/
56 virtual bool readConfiguration(const std::string& filename);
58 /** Get whether at least of one of this viewers windows are realized.*/
59 virtual bool isRealized() const;
61 /** set up windows and associated threads.*/
62 virtual void realize();
64 virtual void setStartTick(osg::Timer_t tick);
65 void setReferenceTime(double time=0.0);
67 using osgViewer::View::setSceneData;
69 /** Set the sene graph data that viewer with view.*/
70 virtual void setSceneData(osg::Node* node);
73 /** Convenience method for setting up the viewer so it can be used embedded in an external managed window.
74 * Returns the GraphicsWindowEmbedded that can be used by applications to pass in events to the viewer. */
75 virtual GraphicsWindowEmbedded* setUpViewerAsEmbeddedInWindow(int x, int y, int width, int height);
78 virtual double elapsedTime();
80 virtual osg::FrameStamp* getViewerFrameStamp() { return getFrameStamp(); }
82 /** Execute a main frame loop.
83 * Equivalent to while (!viewer.done()) viewer.frame();
84 * Also calls realize() if the viewer is not already realized,
85 * and installs trackball manipulator if one is not already assigned.
89 /** check to see if the new frame is required, called by run(..) when FrameScheme is set to ON_DEMAND.*/
90 virtual bool checkNeedToDoFrame();
92 /** check to see if events have been received, return true if events are now available.*/
93 virtual bool checkEvents();
95 virtual void advance(double simulationTime=USE_REFERENCE_TIME);
97 virtual void eventTraversal();
99 virtual void updateTraversal();
101 virtual void getCameras(Cameras& cameras, bool onlyActive=true);
103 virtual void getContexts(Contexts& contexts, bool onlyValid=true);
105 virtual void getAllThreads(Threads& threads, bool onlyActive=true);
107 virtual void getOperationThreads(OperationThreads& threads, bool onlyActive=true);
109 virtual void getScenes(Scenes& scenes, bool onlyValid=true);
111 virtual void getViews(Views& views, bool onlyValid=true);
113 /** Get the keyboard and mouse usage of this viewer.*/
114 virtual void getUsage(osg::ApplicationUsage& usage) const;
116 // ensure that osg::View provides the reiszerGLObjects and releaseGLObjects methods
117 virtual void resizeGLObjectBuffers(unsigned int maxSize) { osg::View::resizeGLObjectBuffers(maxSize); }
118 virtual void releaseGLObjects(osg::State* state = 0) const { osg::View::releaseGLObjects(state); }
122 void constructorInit();
124 virtual void viewerInit() { init(); }
126 void generateSlavePointerData(osg::Camera* camera, osgGA::GUIEventAdapter& event);
127 void generatePointerData(osgGA::GUIEventAdapter& event);
128 void reprojectPointerData(osgGA::GUIEventAdapter& source_event, osgGA::GUIEventAdapter& dest_event);