CompositeViewer 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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_CompositeViewer
  14. #define OSGVIEWER_CompositeViewer 1
  15. #include <osg/ArgumentParser>
  16. #include <osgUtil/UpdateVisitor>
  17. #include <osgViewer/GraphicsWindow>
  18. #include <osgViewer/View>
  19. namespace osgViewer {
  20. /** CompositeViewer holds one or more views to one or more scenes.*/
  21. class OSGVIEWER_EXPORT CompositeViewer : public ViewerBase
  22. {
  23. public:
  24. CompositeViewer();
  25. CompositeViewer(const CompositeViewer&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  26. CompositeViewer(osg::ArgumentParser& arguments);
  27. META_Object(osgViewer,CompositeViewer);
  28. virtual ~CompositeViewer();
  29. /** Read the viewer configuration from a configuration file.*/
  30. bool readConfiguration(const std::string& filename);
  31. /** Set the Stats object used to collect various frame related timing and scene graph stats.*/
  32. virtual void setViewerStats(osg::Stats* stats) { _stats = stats; }
  33. /** Get the Viewers Stats object.*/
  34. virtual osg::Stats* getViewerStats() { return _stats.get(); }
  35. /** Get the Viewers Stats object.*/
  36. virtual const osg::Stats* getViewerStats() const { return _stats.get(); }
  37. void addView(osgViewer::View* view);
  38. template<class T> void addView(const osg::ref_ptr<T>& view) { addView(view.get()); }
  39. void removeView(osgViewer::View* view);
  40. template<class T> void removeView(const osg::ref_ptr<T>& view) { removeView(view.get()); }
  41. osgViewer::View* getView(unsigned i) { return _views[i].get(); }
  42. const osgViewer::View* getView(unsigned i) const { return _views[i].get(); }
  43. unsigned int getNumViews() const { return _views.size(); }
  44. /** Get whether at least of one of this viewer's windows are realized.*/
  45. virtual bool isRealized() const;
  46. /** Set up windows and associated threads.*/
  47. virtual void realize();
  48. virtual void setStartTick(osg::Timer_t tick);
  49. void setReferenceTime(double time=0.0);
  50. osg::FrameStamp* getFrameStamp() { return _frameStamp.get(); }
  51. const osg::FrameStamp* getFrameStamp() const { return _frameStamp.get(); }
  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. void setCameraWithFocus(osg::Camera* camera);
  68. osg::Camera* getCameraWithFocus() { return _cameraWithFocus.get(); }
  69. const osg::Camera* getCameraWithFocus() const { return _cameraWithFocus.get(); }
  70. osgViewer::View* getViewWithFocus() { return _viewWithFocus.get(); }
  71. const osgViewer::View* getViewWithFocus() const { return _viewWithFocus.get(); }
  72. virtual void getCameras(Cameras& cameras, bool onlyActive=true);
  73. virtual void getContexts(Contexts& contexts, bool onlyValid=true);
  74. virtual void getAllThreads(Threads& threads, bool onlyActive=true);
  75. virtual void getOperationThreads(OperationThreads& threads, bool onlyActive=true);
  76. virtual void getScenes(Scenes& scenes, bool onlyValid=true);
  77. virtual void getViews(Views& views, bool onlyValid=true);
  78. /** Get the keyboard and mouse usage of this viewer.*/
  79. virtual void getUsage(osg::ApplicationUsage& usage) const;
  80. protected:
  81. void constructorInit();
  82. virtual void viewerInit();
  83. void generateSlavePointerData(osg::Camera* camera, osgGA::GUIEventAdapter& event);
  84. void generatePointerData(osgGA::GUIEventAdapter& event);
  85. void reprojectPointerData(osgGA::GUIEventAdapter& source_event, osgGA::GUIEventAdapter& dest_event);
  86. typedef std::vector< osg::ref_ptr<osgViewer::View> > RefViews;
  87. RefViews _views;
  88. bool _firstFrame;
  89. osg::ref_ptr<osg::Stats> _stats;
  90. osg::Timer_t _startTick;
  91. osg::ref_ptr<osg::FrameStamp> _frameStamp;
  92. osg::observer_ptr<osg::Camera> _cameraWithFocus;
  93. osg::observer_ptr<osgViewer::View> _viewWithFocus;
  94. osg::ref_ptr<osgGA::GUIEventAdapter> _previousEvent;
  95. };
  96. }
  97. #endif