diff --git a/include/osg/View b/include/osg/View index dca402e83..0e869c303 100644 --- a/include/osg/View +++ b/include/osg/View @@ -34,6 +34,9 @@ class OSG_EXPORT View : public osg::Object View(const osg::View& view, const osg::CopyOp& copyop=CopyOp::SHALLOW_COPY); META_Object(osg,View); + + /** Take all the settings, Camera and Slaves from the passed in view, leaving it empty. */ + virtual void take(View& rhs); /** Set the Stats object used for collect various frame related timing and scene graph stats.*/ void setStats(osg::Stats* stats) { _stats = stats; } diff --git a/include/osgViewer/View b/include/osgViewer/View index b0b83de2d..b82cb7662 100644 --- a/include/osgViewer/View +++ b/include/osgViewer/View @@ -35,6 +35,9 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter View(const osgViewer::View& view, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); META_Object(osgViewer,View); + + /** Take all the settings, Camera and Slaves from the passed in view, leaving it empty. */ + virtual void take(osg::View& rhs); virtual void setStartTick(osg::Timer_t tick); osg::Timer_t getStartTick() const { return _startTick; } diff --git a/include/osgViewer/Viewer b/include/osgViewer/Viewer index 4cefa02fc..62bde08b3 100644 --- a/include/osgViewer/Viewer +++ b/include/osgViewer/Viewer @@ -38,6 +38,9 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View META_Object(osgViewer,Viewer); + /** Take all the settings, Camera and Slaves from the passed in view(er), leaving it empty. */ + virtual void take(View& rhs); + /** read the viewer configuration from a configuration file.*/ bool readConfiguration(const std::string& filename); diff --git a/src/osg/View.cpp b/src/osg/View.cpp index 7303d34e8..a9f1b3cf2 100644 --- a/src/osg/View.cpp +++ b/src/osg/View.cpp @@ -85,6 +85,29 @@ View::~View() osg::notify(osg::INFO)<<"Done destructing osg::View"<setView(this); + + for(unsigned int i=0; i<_slaves.size(); ++i) + { + if (_slaves[i]._camera.valid()) _slaves[i]._camera->setView(this); + } + + // then clear the passing in view. + rhs._light = 0; + rhs._camera = 0; + rhs._slaves.clear(); +} + + void View::setLightingMode(LightingMode lightingMode) { _lightingMode = lightingMode; diff --git a/src/osgPlugins/osgViewer/View.cpp b/src/osgPlugins/osgViewer/View.cpp index 91d6177a6..da0cc4de1 100644 --- a/src/osgPlugins/osgViewer/View.cpp +++ b/src/osgPlugins/osgViewer/View.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include bool View_readLocalData(osg::Object &obj, osgDB::Input &fr); @@ -25,6 +26,73 @@ bool View_readLocalData(osg::Object &obj, osgDB::Input &fr) osgViewer::View& view = static_cast(obj); bool iteratorAdvanced = false; + bool matchedFirst = false; + if ((matchedFirst = fr.matchSequence("setUpViewFor3DSphericalDisplay {")) || + fr.matchSequence("setUpViewForPanoramicSphericalDisplay {")) + { + double radius=1.0; + double collar=0.45; + unsigned int screenNum=0; + std::string filename; + osg::Image* intensityMap=0; + int entry = fr[0].getNoNestedBrackets(); + + fr += 2; + + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + bool local_itrAdvanced = false; + if (fr.read("radius",radius)) local_itrAdvanced = true; + if (fr.read("collar",collar)) local_itrAdvanced = true; + if (fr.read("screenNum",screenNum)) local_itrAdvanced = true; + if (fr.read("intensityMap",filename)) local_itrAdvanced = true; + + if (!local_itrAdvanced) ++fr; + } + + // skip trainling '}' + ++fr; + + iteratorAdvanced = true; + + if (!filename.empty()) + { + intensityMap = osgDB::readImageFile(filename); + } + + if (matchedFirst) view.setUpViewFor3DSphericalDisplay(radius, collar, screenNum, intensityMap); + else view.setUpViewForPanoramicSphericalDisplay(radius, collar, screenNum, intensityMap); + } + + int x = 0; + int y = 0; + int width = 128; + int height = 1024; + unsigned int screenNum = 0; + + if (fr.read("setUpViewOnSingleScreen",screenNum)) + { + view.setUpViewOnSingleScreen(screenNum); + iteratorAdvanced = true; + } + + if (fr.read("setUpViewAcrossAllScreens")) + { + view.setUpViewAcrossAllScreens(); + iteratorAdvanced = true; + } + + if (fr.read("setUpViewInWindow",x,y,width,height,screenNum)) + { + view.setUpViewInWindow(x, y, width, height, screenNum); + } + + if (fr.read("setUpViewInWindow",x,y,width,height)) + { + view.setUpViewInWindow(x, y, width, height); + } + + osg::ref_ptr readObject; while((readObject=fr.readObjectOfType(osgDB::type_wrapper())).valid()) { @@ -52,7 +120,6 @@ bool View_readLocalData(osg::Object &obj, osgDB::Input &fr) } - return iteratorAdvanced; } diff --git a/src/osgViewer/View.cpp b/src/osgViewer/View.cpp index 37cee2d76..024e73a09 100644 --- a/src/osgViewer/View.cpp +++ b/src/osgViewer/View.cpp @@ -164,6 +164,40 @@ View::~View() osg::notify(osg::INFO)<<"Destructing osgViewer::View"<(&rhs); + if (rhs_osgViewer) + { + // copy across rhs + _startTick = rhs_osgViewer->_startTick; + _frameStamp = rhs_osgViewer->_frameStamp; + + _scene = rhs_osgViewer->_scene; + _cameraManipulator = rhs_osgViewer->_cameraManipulator; + _eventHandlers = rhs_osgViewer->_eventHandlers; + + _coordinateSystemNodePath = rhs_osgViewer->_coordinateSystemNodePath; + + _displaySettings = rhs_osgViewer->_displaySettings; + _fusionDistanceMode = rhs_osgViewer->_fusionDistanceMode; + _fusionDistanceValue = rhs_osgViewer->_fusionDistanceValue; + + + // clear rhs + rhs_osgViewer->_frameStamp = 0; + rhs_osgViewer->_scene = 0; + rhs_osgViewer->_cameraManipulator = 0; + rhs_osgViewer->_eventHandlers.clear(); + + rhs_osgViewer->_coordinateSystemNodePath.clear(); + + rhs_osgViewer->_displaySettings; + } + +} osg::GraphicsOperation* View::createRenderer(osg::Camera* camera) { diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index 04d5e6241..ebebc0eb0 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -178,9 +178,54 @@ Viewer::~Viewer() } +void Viewer::take(View& rhs) +{ + osgViewer::View::take(rhs); + + osgViewer::Viewer* rhs_viewer = dynamic_cast(&rhs); + if (rhs_viewer) + { +#if 1 + // variables left to take. + _firstFrame = rhs_viewer->_firstFrame; + _done = rhs_viewer->_done; + _keyEventSetsDone = rhs_viewer->_keyEventSetsDone; + _quitEventSetsDone = rhs_viewer->_quitEventSetsDone; + _threadingModel = rhs_viewer->_threadingModel; + _threadsRunning = rhs_viewer->_threadsRunning; + _endBarrierPosition = rhs_viewer->_endBarrierPosition; + _startRenderingBarrier = rhs_viewer->_startRenderingBarrier; + _endRenderingDispatchBarrier = rhs_viewer->_endRenderingDispatchBarrier; + _endDynamicDrawBlock = rhs_viewer->_endDynamicDrawBlock; + _numWindowsOpenAtLastSetUpThreading = rhs_viewer->_numWindowsOpenAtLastSetUpThreading; + _cameraWithFocus = rhs_viewer->_cameraWithFocus; + _eventVisitor = rhs_viewer->_eventVisitor; + _updateOperations = rhs_viewer->_updateOperations; + _updateVisitor = rhs_viewer->_updateVisitor; + _realizeOperation = rhs_viewer->_realizeOperation; + _currentContext = rhs_viewer->_currentContext; + + + // objects to clear + rhs_viewer->_done = true; + rhs_viewer->_startRenderingBarrier = 0; + rhs_viewer->_endRenderingDispatchBarrier = 0; + rhs_viewer->_endDynamicDrawBlock = 0; + rhs_viewer->_numWindowsOpenAtLastSetUpThreading = 0; + rhs_viewer->_cameraWithFocus = 0; + rhs_viewer->_eventVisitor = 0; + rhs_viewer->_updateOperations = 0; + rhs_viewer->_updateVisitor = 0; + rhs_viewer->_realizeOperation = 0; + rhs_viewer->_currentContext = 0; + +#endif + } +} + bool Viewer::readConfiguration(const std::string& filename) { - osg::notify(osg::NOTICE)<<"Viewer::readConfiguration("< object = osgDB::readObjectFile(filename); if (!object) @@ -196,14 +241,11 @@ bool Viewer::readConfiguration(const std::string& filename) return false; } - osg::notify(osg::NOTICE)<<"Loaded object = "<className()<(object.get()); if (view) { - Viewer* viewer = dynamic_cast(object.get()); - osg::notify(osg::NOTICE)<<" ViewerPtr = "<