Refactor Viewer/CompositeViewer so the both inherit from the a ViewerBase class

This commit is contained in:
Robert Osfield
2007-09-29 16:46:08 +00:00
parent 4ef1864432
commit f8729af8b2
18 changed files with 885 additions and 739 deletions

View File

@@ -22,7 +22,7 @@
namespace osgViewer {
/** CompsiteViewer holds a or more views to a one more scenes.*/
class OSGVIEWER_EXPORT CompositeViewer : public osg::Object
class OSGVIEWER_EXPORT CompositeViewer : public ViewerBase, public virtual osg::Object
{
public:
@@ -49,35 +49,25 @@ class OSGVIEWER_EXPORT CompositeViewer : public osg::Object
/** Get whether at least of one of this viewers windows are realized.*/
bool isRealized() const;
virtual bool isRealized() const;
/** set up windows and associated threads.*/
void realize();
virtual void realize();
void setDone(bool done) { _done = done; }
bool done() const { return _done; }
void setStartTick(osg::Timer_t tick);
osg::Timer_t getStartTick() const { return _startTick; }
virtual void setStartTick(osg::Timer_t tick);
void setReferenceTime(double time=0.0);
osg::FrameStamp* getFrameStamp() { return _frameStamp.get(); }
const osg::FrameStamp* getFrameStamp() const { return _frameStamp.get(); }
enum ThreadingModel
{
SingleThreaded,
ThreadPerContext,
ThreadPerCamera
};
/** Set the threading model the rendering traversals will use.*/
void setThreadingModel(ThreadingModel threadingModel);
/** Get the threading model the rendering traversals will use.*/
ThreadingModel getThreadingModel() const { return _threadingModel; }
virtual void setThreadingModel(ThreadingModel threadingModel);
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); }
enum BarrierPosition
{
@@ -97,62 +87,6 @@ class OSGVIEWER_EXPORT CompositeViewer : public osg::Object
/** 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(); }
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
const osgGA::EventQueue* getEventQueue() const { return _eventQueue.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();
@@ -181,30 +115,30 @@ class OSGVIEWER_EXPORT CompositeViewer : public osg::Object
osgViewer::View* getViewWithFocus() { return _viewWithFocus.get(); }
const osgViewer::View* getViewWithFocus() const { return _viewWithFocus.get(); }
typedef std::vector<osg::GraphicsContext*> Contexts;
void getContexts(Contexts& contexts, bool onlyValid=true);
virtual void getCameras(Cameras& cameras, bool onlyActive=true);
typedef std::vector<osgViewer::GraphicsWindow*> Windows;
void getWindows(Windows& windows, bool onlyValid=true);
virtual void getContexts(Contexts& contexts, bool onlyValid=true);
typedef std::vector<osgViewer::Scene*> Scenes;
void getScenes(Scenes& scenes, bool onlyValid=true);
virtual void getWindows(Windows& windows, bool onlyValid=true);
virtual void getAllThreads(Threads& threads, bool onlyActive=true);
virtual void getOperationThreads(OperationThreads& threads, bool onlyActive=true);
virtual void getScenes(Scenes& scenes, bool onlyValid=true);
/** 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(); }
/** Return true if viewer threads are running. */
bool areThreadsRunning() const { return _threadsRunning; }
/** Set up the threading and processor affinity as per the viewers threading model.*/
virtual void setUpThreading();
/** Stop any threads begin run by viewer.*/
void stopThreading();
virtual void stopThreading();
/** Start any threads required by the viewer, as per viewers ThreadingModel.*/
void startThreading();
virtual void startThreading();
/** Get the keyboard and mouse usage of this viewer.*/
virtual void getUsage(osg::ApplicationUsage& usage) const;
protected:
@@ -219,13 +153,6 @@ class OSGVIEWER_EXPORT CompositeViewer : public osg::Object
bool _firstFrame;
bool _done;
int _keyEventSetsDone;
bool _quitEventSetsDone;
ThreadingModel _threadingModel;
bool _threadsRunning;
BarrierPosition _endBarrierPosition;
osg::ref_ptr<osg::BarrierOperation> _startRenderingBarrier;
@@ -242,13 +169,6 @@ class OSGVIEWER_EXPORT CompositeViewer : public osg::Object
osg::observer_ptr<osgViewer::View> _viewWithFocus;
osg::ref_ptr<osgGA::EventQueue> _eventQueue;
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 File

@@ -15,8 +15,6 @@
#ifndef OSGVIEWER_EXPORT_
#define OSGVIEWER_EXPORT_ 1
#define USE_REFERENCE_TIME DBL_MAX
#if defined(WIN32) && !(defined(__CYGWIN__) || defined(__MINGW32__))
#pragma warning( disable : 4244 )
#pragma warning( disable : 4251 )

View File

@@ -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;

View File

@@ -24,7 +24,7 @@
namespace osgViewer {
/** Viewer holds a single view on to a single scene.*/
class OSGVIEWER_EXPORT Viewer : public osgViewer::View
class OSGVIEWER_EXPORT Viewer : public ViewerBase, public osgViewer::View
{
public:
@@ -42,20 +42,15 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
virtual void take(View& rhs);
/** read the viewer configuration from a configuration file.*/
bool readConfiguration(const std::string& filename);
virtual bool readConfiguration(const std::string& filename);
/** Get whether at least of one of this viewers windows are realized.*/
bool isRealized() const;
virtual bool isRealized() const;
/** set up windows and associated threads.*/
void realize();
virtual void realize();
void setDone(bool done) { _done = done; }
bool done() const { return _done; }
virtual void setStartTick(osg::Timer_t tick);
void setReferenceTime(double time=0.0);
/** Set the sene graph data that viewer with view.*/
@@ -66,21 +61,9 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
* Returns the GraphicsWindowEmbedded that can be used by applications to pass in events to the viewer. */
virtual GraphicsWindowEmbedded* setUpViewerAsEmbeddedInWindow(int x, int y, int width, int height);
enum ThreadingModel
{
SingleThreaded,
CullDrawThreadPerContext,
DrawThreadPerContext,
CullThreadPerCameraDrawThreadPerContext,
AutomaticSelection
};
/** Set the threading model the rendering traversals will use.*/
void setThreadingModel(ThreadingModel threadingModel);
virtual void setThreadingModel(ThreadingModel threadingModel);
/** Get the threading model the rendering traversals will use.*/
ThreadingModel getThreadingModel() const { return _threadingModel; }
/** Let the viewer suggest the best threading model for the viewers camera/window setup and the hardware available.*/
ThreadingModel suggestBestThreadingModel();
@@ -102,61 +85,6 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
BarrierPosition getEndBarrierPosition() const { return _endBarrierPosition; }
/** 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,
@@ -180,36 +108,33 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
osg::Camera* getCameraWithFocus() { return _cameraWithFocus.get(); }
const osg::Camera* getCameraWithFocus() const { return _cameraWithFocus.get(); }
typedef std::vector<osgViewer::GraphicsWindow*> Windows;
void getWindows(Windows& windows, bool onlyValid=true);
virtual void getCameras(Cameras& cameras, bool onlyActive=true);
virtual void getContexts(Contexts& contexts, bool onlyValid=true);
typedef std::vector<OpenThreads::Thread*> Threads;
void getAllThreads(Threads& threads, bool onlyActive=true);
virtual void getWindows(Windows& windows, bool onlyValid=true);
typedef std::vector<osg::OperationThread*> OperationThreads;
void getOperationThreads(OperationThreads& threads, bool onlyActive=true);
virtual void getAllThreads(Threads& threads, bool onlyActive=true);
/** Set the graphics operation to call on realization of the viewers graphics windows.*/
void setRealizeOperation(osg::Operation* op) { _realizeOperation = op; }
virtual void getOperationThreads(OperationThreads& threads, bool onlyActive=true);
virtual void getScenes(Scenes& scenes, bool onlyValid=true);
/** 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.*/
void setUpThreading();
/** Return true if viewer threads are running. */
bool areThreadsRunning() const { return _threadsRunning; }
virtual void setUpThreading();
/** Stop any threads begin run by viewer.*/
void stopThreading();
virtual void stopThreading();
/** Start any threads required by the viewer.*/
void startThreading();
virtual void startThreading();
/** Get the keyboard and mouse usage of this viewer.*/
virtual void getUsage(osg::ApplicationUsage& usage) const;
protected:
void constructorInit();
@@ -237,12 +162,6 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
bool _firstFrame;
bool _done;
int _keyEventSetsDone;
bool _quitEventSetsDone;
ThreadingModel _threadingModel;
bool _threadsRunning;
BarrierPosition _endBarrierPosition;
@@ -254,12 +173,6 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
osg::observer_ptr<osg::Camera> _cameraWithFocus;
osg::ref_ptr<osgGA::EventVisitor> _eventVisitor;
osg::ref_ptr<osg::OperationQueue> _updateOperations;
osg::ref_ptr<osgUtil::UpdateVisitor> _updateVisitor;
osg::ref_ptr<osg::Operation> _realizeOperation;
osg::observer_ptr<osg::GraphicsContext> _currentContext;
};

View File

@@ -125,7 +125,7 @@ class OSGVIEWER_EXPORT StatsHandler : public osgGA::GUIEventHandler
osg::ref_ptr<osg::Switch> _switch;
unsigned int _threadingModel;
ViewerBase::ThreadingModel _threadingModel;
osg::ref_ptr<osgText::Text> _threadingModelText;
unsigned int _frameRateChildNum;