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

@@ -38,11 +38,15 @@ static osg::ApplicationUsageProxy Viewer_e3(osg::ApplicationUsage::ENVIRONMENTAL
Viewer::Viewer()
{
_viewerBase = this;
constructorInit();
}
Viewer::Viewer(osg::ArgumentParser& arguments)
{
_viewerBase = this;
constructorInit();
std::string filename;
@@ -119,16 +123,12 @@ Viewer::Viewer(osg::ArgumentParser& arguments)
Viewer::Viewer(const osgViewer::Viewer& viewer, const osg::CopyOp& copyop):
View(viewer,copyop)
{
_viewerBase = this;
}
void Viewer::constructorInit()
{
_firstFrame = true;
_done = false;
_keyEventSetsDone = osgGA::GUIEventAdapter::KEY_Escape;
_quitEventSetsDone = true;
_threadingModel = AutomaticSelection;
_threadsRunning = false;
_endBarrierPosition = AfterSwapBuffers;
_numWindowsOpenAtLastSetUpThreading = 0;
@@ -343,7 +343,6 @@ void Viewer::setStartTick(osg::Timer_t tick)
}
}
void Viewer::setReferenceTime(double time)
{
osg::Timer_t tick = osg::Timer::instance()->tick();
@@ -1412,25 +1411,6 @@ void Viewer::eventTraversal()
}
void Viewer::addUpdateOperation(osg::Operation* operation)
{
if (!operation) return;
if (!_updateOperations) _updateOperations = new osg::OperationQueue;
_updateOperations->add(operation);
}
void Viewer::removeUpdateOperation(osg::Operation* operation)
{
if (!operation) return;
if (_updateOperations.valid())
{
_updateOperations->remove(operation);
}
}
void Viewer::updateTraversal()
{
if (_done) return;
@@ -1600,6 +1580,93 @@ void Viewer::renderingTraversals()
}
}
void Viewer::getScenes(Scenes& scenes, bool onlyValid)
{
scenes.push_back(_scene.get());
}
struct LessGraphicsContext
{
bool operator () (const osg::GraphicsContext* lhs, const osg::GraphicsContext* rhs) const
{
int screenLeft = lhs->getTraits()? lhs->getTraits()->screenNum : 0;
int screenRight = rhs->getTraits()? rhs->getTraits()->screenNum : 0;
if (screenLeft < screenRight) return true;
if (screenLeft > screenRight) return false;
screenLeft = lhs->getTraits()? lhs->getTraits()->x : 0;
screenRight = rhs->getTraits()? rhs->getTraits()->x : 0;
if (screenLeft < screenRight) return true;
if (screenLeft > screenRight) return false;
screenLeft = lhs->getTraits()? lhs->getTraits()->y : 0;
screenRight = rhs->getTraits()? rhs->getTraits()->y : 0;
if (screenLeft < screenRight) return true;
if (screenLeft > screenRight) return false;
return lhs < rhs;
}
};
void Viewer::getContexts(Contexts& contexts, bool onlyValid)
{
typedef std::set<osg::GraphicsContext*> ContextSet;
ContextSet contextSet;
if (_camera.valid() &&
_camera->getGraphicsContext() &&
(_camera->getGraphicsContext()->valid() || !onlyValid))
{
contextSet.insert(_camera->getGraphicsContext());
}
for(unsigned int i=0; i<getNumSlaves(); ++i)
{
Slave& slave = getSlave(i);
if (slave._camera.valid() &&
slave._camera->getGraphicsContext() &&
(slave._camera->getGraphicsContext()->valid() || !onlyValid))
{
contextSet.insert(slave._camera->getGraphicsContext());
}
}
contexts.clear();
contexts.reserve(contextSet.size());
for(ContextSet::iterator itr = contextSet.begin();
itr != contextSet.end();
++itr)
{
contexts.push_back(const_cast<osg::GraphicsContext*>(*itr));
}
if (contexts.size()>=2)
{
std::sort(contexts.begin(), contexts.end(), LessGraphicsContext());
}
}
void Viewer::getCameras(Cameras& cameras, bool onlyActive)
{
cameras.clear();
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 (itr->_camera.valid() &&
(!onlyActive || (itr->_camera->getGraphicsContext() && itr->_camera->getGraphicsContext()->valid())) ) cameras.push_back(itr->_camera.get());
}
}
void Viewer::getUsage(osg::ApplicationUsage& usage) const
{
if (_cameraManipulator.valid())
@@ -1613,5 +1680,6 @@ void Viewer::getUsage(osg::ApplicationUsage& usage) const
{
(*hitr)->getUsage(usage);
}
}