Added support for basic viewer configuration files
This commit is contained in:
parent
ece7b57df2
commit
3bfaee3654
@ -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; }
|
||||
|
@ -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; }
|
||||
|
@ -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);
|
||||
|
||||
|
@ -85,6 +85,29 @@ View::~View()
|
||||
osg::notify(osg::INFO)<<"Done destructing osg::View"<<std::endl;
|
||||
}
|
||||
|
||||
void View::take(osg::View& rhs)
|
||||
{
|
||||
// copy across the contents first
|
||||
_lightingMode = rhs._lightingMode;
|
||||
_light = rhs._light;
|
||||
_camera = rhs._camera;
|
||||
_slaves = rhs._slaves;
|
||||
|
||||
// update the cameras so they all now see this View as their parent View
|
||||
if (_camera.valid()) _camera->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;
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/Input>
|
||||
#include <osgDB/Output>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/ParameterOutput>
|
||||
|
||||
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<osgViewer::View&>(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<osg::Object> readObject;
|
||||
while((readObject=fr.readObjectOfType(osgDB::type_wrapper<osg::Camera>())).valid())
|
||||
{
|
||||
@ -52,7 +120,6 @@ bool View_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
|
||||
}
|
||||
|
||||
|
||||
return iteratorAdvanced;
|
||||
}
|
||||
|
||||
|
@ -164,6 +164,40 @@ View::~View()
|
||||
osg::notify(osg::INFO)<<"Destructing osgViewer::View"<<std::endl;
|
||||
}
|
||||
|
||||
void View::take(osg::View& rhs)
|
||||
{
|
||||
osg::View::take(rhs);
|
||||
|
||||
osgViewer::View* rhs_osgViewer = dynamic_cast<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)
|
||||
{
|
||||
|
@ -178,9 +178,54 @@ Viewer::~Viewer()
|
||||
|
||||
}
|
||||
|
||||
void Viewer::take(View& rhs)
|
||||
{
|
||||
osgViewer::View::take(rhs);
|
||||
|
||||
osgViewer::Viewer* rhs_viewer = dynamic_cast<osgViewer::Viewer*>(&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("<<filename<<")"<<std::endl;
|
||||
osg::notify(osg::INFO)<<"Viewer::readConfiguration("<<filename<<")"<<std::endl;
|
||||
|
||||
osg::ref_ptr<osg::Object> 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 = "<<object->className()<<std::endl;
|
||||
|
||||
View* view = dynamic_cast<osgViewer::View*>(object.get());
|
||||
if (view)
|
||||
{
|
||||
Viewer* viewer = dynamic_cast<Viewer*>(object.get());
|
||||
osg::notify(osg::NOTICE)<<" ViewerPtr = "<<viewer<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<" ViewPtr = "<<view<<std::endl;
|
||||
take(*view);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -864,13 +906,15 @@ void Viewer::getCameras(Cameras& cameras, bool onlyActive)
|
||||
{
|
||||
cameras.clear();
|
||||
|
||||
if (!onlyActive || (_camera->getGraphicsContext() && _camera->getGraphicsContext()->valid()) ) cameras.push_back(_camera.get());
|
||||
if (_camera.valid() &&
|
||||
(!onlyActive || (_camera->getGraphicsContext() && _camera->getGraphicsContext()->valid())) ) cameras.push_back(_camera.get());
|
||||
|
||||
for(Slaves::iterator itr = _slaves.begin();
|
||||
itr != _slaves.end();
|
||||
++itr)
|
||||
{
|
||||
if (!onlyActive || (itr->_camera->getGraphicsContext() && itr->_camera->getGraphicsContext()->valid()) ) cameras.push_back(itr->_camera.get());
|
||||
if (itr->_camera.valid() &&
|
||||
(!onlyActive || (itr->_camera->getGraphicsContext() && itr->_camera->getGraphicsContext()->valid())) ) cameras.push_back(itr->_camera.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user