Refactor Viewer/CompositeViewer so the both inherit from the a ViewerBase class
This commit is contained in:
@@ -18,13 +18,190 @@
|
||||
|
||||
#include <osgUtil/PolytopeIntersector>
|
||||
#include <osgUtil/LineSegmentIntersector>
|
||||
#include <osgUtil/UpdateVisitor>
|
||||
#include <osgUtil/SceneView>
|
||||
|
||||
#include <osgGA/MatrixManipulator>
|
||||
#include <osgGA/EventVisitor>
|
||||
#include <osgGA/EventQueue>
|
||||
|
||||
#include <osgViewer/Scene>
|
||||
#include <osgViewer/GraphicsWindow>
|
||||
|
||||
namespace osgViewer {
|
||||
|
||||
#define USE_REFERENCE_TIME DBL_MAX
|
||||
|
||||
/** ViewerBase is the view base class that is inhertied by both Viewer and CompositeViewer.*/
|
||||
class OSGVIEWER_EXPORT ViewerBase : public virtual osg::Object
|
||||
{
|
||||
public:
|
||||
|
||||
ViewerBase();
|
||||
ViewerBase(const ViewerBase& vb);
|
||||
|
||||
|
||||
/** read the viewer configuration from a configuration file.*/
|
||||
virtual bool readConfiguration(const std::string& filename) = 0;
|
||||
|
||||
/** Get whether at least of one of this viewers windows are realized.*/
|
||||
virtual bool isRealized() const = 0;
|
||||
|
||||
/** set up windows and associated threads.*/
|
||||
virtual void realize() = 0;
|
||||
|
||||
enum ThreadingModel
|
||||
{
|
||||
SingleThreaded,
|
||||
CullDrawThreadPerContext,
|
||||
ThreadPerContext = CullDrawThreadPerContext,
|
||||
DrawThreadPerContext,
|
||||
CullThreadPerCameraDrawThreadPerContext,
|
||||
ThreadPerCamera = CullThreadPerCameraDrawThreadPerContext,
|
||||
AutomaticSelection
|
||||
};
|
||||
|
||||
/** Set the threading model the rendering traversals will use.*/
|
||||
virtual void setThreadingModel(ThreadingModel threadingModel) = 0;
|
||||
|
||||
/** Get the threading model the rendering traversals will use.*/
|
||||
ThreadingModel getThreadingModel() const { return _threadingModel; }
|
||||
|
||||
|
||||
/** Set the done flag to singnal the viewer's work is done and should exit the frame loop.*/
|
||||
void setDone(bool done) { _done = done; }
|
||||
|
||||
/** Reurn true if viewer's work is done and should exit the frame loop.*/
|
||||
bool done() const { return _done; }
|
||||
|
||||
/** Set the EventVisitor. */
|
||||
void setEventVisitor(osgGA::EventVisitor* eventVisitor) { _eventVisitor = eventVisitor; }
|
||||
|
||||
/** Get the EventVisitor. */
|
||||
osgGA::EventVisitor* getEventVisitor() { return _eventVisitor.get(); }
|
||||
|
||||
/** Get the const EventVisitor. */
|
||||
const osgGA::EventVisitor* getEventVisitor() const { return _eventVisitor.get(); }
|
||||
|
||||
/** Set the key event that the viewer checks on each frame to see if the viewer's done flag should be set to
|
||||
* signal end of viewers main loop.
|
||||
* Default value is Escape (osgGA::GUIEVentAdapter::KEY_Escape).
|
||||
* Setting to 0 switches off the feature.*/
|
||||
void setKeyEventSetsDone(int key) { _keyEventSetsDone = key; }
|
||||
|
||||
/** get the key event that the viewer checks on each frame to see if the viewer's done flag.*/
|
||||
int getKeyEventSetsDone() const { return _keyEventSetsDone; }
|
||||
|
||||
/** if the flag is true, the viewer set its done flag when a QUIT_APPLICATION is received, false disables this feature */
|
||||
void setQuitEventSetsDone(bool flag) { _quitEventSetsDone = flag; }
|
||||
|
||||
/** @return true if the viewer respond to the QUIT_APPLICATION-event */
|
||||
bool getQuitEventSetsDone() const { return _quitEventSetsDone; }
|
||||
|
||||
|
||||
|
||||
/** Set the UpdateVisitor. */
|
||||
void setUpdateVisitor(osgUtil::UpdateVisitor* updateVisitor) { _updateVisitor = updateVisitor; }
|
||||
|
||||
/** Get the UpdateVisitor. */
|
||||
osgUtil::UpdateVisitor* getUpdateVisitor() { return _updateVisitor.get(); }
|
||||
|
||||
/** Get the const UpdateVisitor. */
|
||||
const osgUtil::UpdateVisitor* getUpdateVisitor() const { return _updateVisitor.get(); }
|
||||
|
||||
|
||||
/** Set the Update OperationQueue. */
|
||||
void setUpdateOperations(osg::OperationQueue* operations) { _updateOperations = operations; }
|
||||
|
||||
/** Get the Update OperationQueue. */
|
||||
osg::OperationQueue* getUpdateOperations() { return _updateOperations.get(); }
|
||||
|
||||
/** Get the const Update OperationQueue. */
|
||||
const osg::OperationQueue* getUpdateOperations() const { return _updateOperations.get(); }
|
||||
|
||||
/** Add an update operation.*/
|
||||
void addUpdateOperation(osg::Operation* operation);
|
||||
|
||||
/** Remove an update operation.*/
|
||||
void removeUpdateOperation(osg::Operation* operation);
|
||||
|
||||
|
||||
/** Execute a main frame loop.
|
||||
* Equivialant to while (!viewer.done()) viewer.frame();
|
||||
* Also calls realize() if the viewer is not already realized,
|
||||
* and installs trackball manipulator if one is not already assigned.
|
||||
*/
|
||||
virtual int run() = 0;
|
||||
|
||||
/** Render a complete new frame.
|
||||
* Calls advance(), eventTraversal(), updateTraversal(), renderingTraversals(). */
|
||||
virtual void frame(double simulationTime=USE_REFERENCE_TIME) = 0;
|
||||
|
||||
virtual void advance(double simulationTime=USE_REFERENCE_TIME) = 0;
|
||||
|
||||
virtual void eventTraversal() = 0;
|
||||
|
||||
virtual void updateTraversal() = 0;
|
||||
|
||||
virtual void renderingTraversals() = 0;
|
||||
|
||||
typedef std::vector<osg::Camera*> Cameras;
|
||||
virtual void getCameras(Cameras& cameras, bool onlyActive=true) = 0;
|
||||
|
||||
typedef std::vector<osg::GraphicsContext*> Contexts;
|
||||
virtual void getContexts(Contexts& contexts, bool onlyValid=true) = 0;
|
||||
|
||||
typedef std::vector<osgViewer::GraphicsWindow*> Windows;
|
||||
virtual void getWindows(Windows& windows, bool onlyValid=true) = 0;
|
||||
|
||||
typedef std::vector<OpenThreads::Thread*> Threads;
|
||||
virtual void getAllThreads(Threads& threads, bool onlyActive=true) = 0;
|
||||
|
||||
typedef std::vector<osg::OperationThread*> OperationThreads;
|
||||
virtual void getOperationThreads(OperationThreads& threads, bool onlyActive=true) = 0;
|
||||
|
||||
typedef std::vector<osgViewer::Scene*> Scenes;
|
||||
virtual void getScenes(Scenes& scenes, bool onlyValid=true) = 0;
|
||||
|
||||
/** Set the graphics operation to call on realization of the viewers graphics windows.*/
|
||||
void setRealizeOperation(osg::Operation* op) { _realizeOperation = op; }
|
||||
|
||||
/** Get the graphics operation to call on realization of the viewers graphics windows.*/
|
||||
osg::Operation* getRealizeOperation() { return _realizeOperation.get(); }
|
||||
|
||||
/** Set up the threading and processor affinity as per the viewers threading model.*/
|
||||
virtual void setUpThreading() = 0;
|
||||
|
||||
/** Return true if viewer threads are running. */
|
||||
bool areThreadsRunning() const { return _threadsRunning; }
|
||||
|
||||
/** Stop any threads begin run by viewer.*/
|
||||
virtual void stopThreading() = 0;
|
||||
|
||||
/** Start any threads required by the viewer.*/
|
||||
virtual void startThreading() = 0;
|
||||
|
||||
/** Get the keyboard and mouse usage of this viewer.*/
|
||||
virtual void getUsage(osg::ApplicationUsage& usage) const = 0;
|
||||
|
||||
protected:
|
||||
|
||||
bool _done;
|
||||
int _keyEventSetsDone;
|
||||
bool _quitEventSetsDone;
|
||||
|
||||
ThreadingModel _threadingModel;
|
||||
bool _threadsRunning;
|
||||
|
||||
osg::ref_ptr<osgGA::EventVisitor> _eventVisitor;
|
||||
|
||||
osg::ref_ptr<osg::OperationQueue> _updateOperations;
|
||||
osg::ref_ptr<osgUtil::UpdateVisitor> _updateVisitor;
|
||||
|
||||
osg::ref_ptr<osg::Operation> _realizeOperation;
|
||||
|
||||
};
|
||||
|
||||
/** View holds a single view on a scene, this view may be composed of one or more slave cameras.*/
|
||||
class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
|
||||
{
|
||||
@@ -36,6 +213,8 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
|
||||
|
||||
META_Object(osgViewer,View);
|
||||
|
||||
ViewerBase* getViewerBase() { return _viewerBase.get(); }
|
||||
|
||||
/** Take all the settings, Camera and Slaves from the passed in view, leaving it empty. */
|
||||
virtual void take(osg::View& rhs);
|
||||
|
||||
@@ -176,12 +355,6 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
|
||||
virtual void requestContinuousUpdate(bool needed=true);
|
||||
virtual void requestWarpPointer(float x,float y);
|
||||
|
||||
typedef std::vector<osg::Camera*> Cameras;
|
||||
void getCameras(Cameras& cameras, bool onlyActive=true);
|
||||
|
||||
typedef std::vector<osg::GraphicsContext*> Contexts;
|
||||
void getContexts(Contexts& contexts, bool onlyValid=true);
|
||||
|
||||
public:
|
||||
|
||||
void assignSceneDataToCameras();
|
||||
@@ -189,10 +362,15 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
|
||||
|
||||
protected:
|
||||
|
||||
friend class CompositeViewer;
|
||||
|
||||
virtual ~View();
|
||||
|
||||
virtual osg::GraphicsOperation* createRenderer(osg::Camera* camera);
|
||||
|
||||
osg::observer_ptr<ViewerBase> _viewerBase;
|
||||
|
||||
|
||||
osg::Timer_t _startTick;
|
||||
osg::ref_ptr<osg::FrameStamp> _frameStamp;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user