openscenegraph
Viewer
Go to the documentation of this file.
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_Viewer
15#define OSGVIEWER_Viewer 1
16
17#include <osg/ArgumentParser>
18#include <osgGA/EventVisitor>
19#include <osgUtil/UpdateVisitor>
20#include <osgViewer/GraphicsWindow>
21#include <osgViewer/View>
22
23
24namespace osgViewer {
25
26/** Viewer holds a single view on to a single scene.*/
27class OSGVIEWER_EXPORT Viewer : public ViewerBase, public osgViewer::View
28{
29 public:
30
31 Viewer();
32
33 Viewer(osg::ArgumentParser& arguments);
34
35 Viewer(const osgViewer::Viewer& viewer, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
36
37 virtual ~Viewer();
38
39 META_Object(osgViewer,Viewer);
40
41 /** Take all the settings, Camera and Slaves from the passed in view(er), leaving it empty. */
42 virtual void take(osg::View& rhs);
43
44
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); }
47
48 /** Get the Viewers Stats object.*/
49 virtual osg::Stats* getViewerStats() { return getStats(); }
50
51 /** Get the Viewers Stats object.*/
52 virtual const osg::Stats* getViewerStats() const { return getStats(); }
53
54
55 /** read the viewer configuration from a configuration file.*/
56 virtual bool readConfiguration(const std::string& filename);
57
58 /** Get whether at least of one of this viewers windows are realized.*/
59 virtual bool isRealized() const;
60
61 /** set up windows and associated threads.*/
62 virtual void realize();
63
64 virtual void setStartTick(osg::Timer_t tick);
65 void setReferenceTime(double time=0.0);
66
67 using osgViewer::View::setSceneData;
68
69 /** Set the sene graph data that viewer with view.*/
70 virtual void setSceneData(osg::Node* node);
71
72
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);
76
77
78 virtual double elapsedTime();
79
80 virtual osg::FrameStamp* getViewerFrameStamp() { return getFrameStamp(); }
81
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.
86 */
87 virtual int run();
88
89 /** check to see if the new frame is required, called by run(..) when FrameScheme is set to ON_DEMAND.*/
90 virtual bool checkNeedToDoFrame();
91
92 /** check to see if events have been received, return true if events are now available.*/
93 virtual bool checkEvents();
94
95 virtual void advance(double simulationTime=USE_REFERENCE_TIME);
96
97 virtual void eventTraversal();
98
99 virtual void updateTraversal();
100
101 virtual void getCameras(Cameras& cameras, bool onlyActive=true);
102
103 virtual void getContexts(Contexts& contexts, bool onlyValid=true);
104
105 virtual void getAllThreads(Threads& threads, bool onlyActive=true);
106
107 virtual void getOperationThreads(OperationThreads& threads, bool onlyActive=true);
108
109 virtual void getScenes(Scenes& scenes, bool onlyValid=true);
110
111 virtual void getViews(Views& views, bool onlyValid=true);
112
113 /** Get the keyboard and mouse usage of this viewer.*/
114 virtual void getUsage(osg::ApplicationUsage& usage) const;
115
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); }
119
120 protected:
121
122 void constructorInit();
123
124 virtual void viewerInit() { init(); }
125
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);
129
130};
131
132
133}
134
135#endif