Viewer 4.8 KB

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