refactored the getWindows(..) and getContexts(..) methods so that they produce

consistent ordering based on the order Camera/slave camera ordering.
This commit is contained in:
Robert Osfield 2008-09-18 15:18:59 +00:00
parent 8bdb22c22e
commit 91f7895735
6 changed files with 48 additions and 108 deletions

View File

@ -95,8 +95,6 @@ class OSGVIEWER_EXPORT CompositeViewer : public ViewerBase, public virtual osg::
virtual void getContexts(Contexts& contexts, 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);

View File

@ -88,8 +88,6 @@ class OSGVIEWER_EXPORT Viewer : public ViewerBase, public osgViewer::View
virtual void getContexts(Contexts& contexts, 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);

View File

@ -217,7 +217,7 @@ class OSGVIEWER_EXPORT ViewerBase : public virtual osg::Object
virtual void getContexts(Contexts& contexts, bool onlyValid=true) = 0;
typedef std::vector<osgViewer::GraphicsWindow*> Windows;
virtual void getWindows(Windows& windows, bool onlyValid=true) = 0;
virtual void getWindows(Windows& windows, bool onlyValid=true);
typedef std::vector<OpenThreads::Thread*> Threads;
virtual void getAllThreads(Threads& threads, bool onlyActive=true) = 0;

View File

@ -276,39 +276,37 @@ void CompositeViewer::getContexts(Contexts& contexts, bool onlyValid)
typedef std::set<osg::GraphicsContext*> ContextSet;
ContextSet contextSet;
contexts.clear();
for(RefViews::iterator vitr = _views.begin();
vitr != _views.end();
++vitr)
{
osgViewer::View* view = vitr->get();
if (view->getCamera() &&
view->getCamera()->getGraphicsContext() &&
(view->getCamera()->getGraphicsContext()->valid() || !onlyValid))
osg::GraphicsContext* gc = view->getCamera() ? view->getCamera()->getGraphicsContext() : 0;
if (gc && (gc->valid() || !onlyValid))
{
contextSet.insert(view->getCamera()->getGraphicsContext());
if (contextSet.count(gc)==0)
{
contextSet.insert(gc);
contexts.push_back(gc);
}
}
for(unsigned int i=0; i<view->getNumSlaves(); ++i)
{
View::Slave& slave = view->getSlave(i);
if (slave._camera.valid() &&
slave._camera->getGraphicsContext() &&
(slave._camera->getGraphicsContext()->valid() || !onlyValid))
osg::GraphicsContext* sgc = slave._camera.valid() ? slave._camera->getGraphicsContext() : 0;
if (sgc && (sgc->valid() || !onlyValid))
{
contextSet.insert(slave._camera->getGraphicsContext());
if (contextSet.count(sgc)==0)
{
contextSet.insert(sgc);
contexts.push_back(sgc);
}
}
}
}
contexts.clear();
contexts.reserve(contextSet.size());
for(ContextSet::iterator itr = contextSet.begin();
itr != contextSet.end();
++itr)
{
contexts.push_back(const_cast<osg::GraphicsContext*>(*itr));
}
}
void CompositeViewer::getCameras(Cameras& cameras, bool onlyActive)
@ -334,22 +332,6 @@ void CompositeViewer::getCameras(Cameras& cameras, bool onlyActive)
}
}
void CompositeViewer::getWindows(Windows& windows, bool onlyValid)
{
windows.clear();
Contexts contexts;
getContexts(contexts, onlyValid);
for(Contexts::iterator itr = contexts.begin();
itr != contexts.end();
++itr)
{
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(*itr);
if (gw) windows.push_back(gw);
}
}
void CompositeViewer::getScenes(Scenes& scenes, bool onlyValid)
{
typedef std::set<osgViewer::Scene*> SceneSet;
@ -362,16 +344,13 @@ void CompositeViewer::getScenes(Scenes& scenes, bool onlyValid)
osgViewer::View* view = vitr->get();
if (view->getScene() && (!onlyValid || view->getScene()->getSceneData()))
{
sceneSet.insert(view->getScene());
if (sceneSet.count(view->getScene())==0)
{
sceneSet.insert(view->getScene());
scenes.push_back(view->getScene());
}
}
}
for(SceneSet::iterator sitr = sceneSet.begin();
sitr != sceneSet.end();
++sitr)
{
scenes.push_back(const_cast<osgViewer::Scene*>(*sitr));
}
}
void CompositeViewer::getViews(Views& views, bool onlyValid)

View File

@ -951,23 +951,6 @@ void Viewer::getViews(Views& views, bool onlyValid)
views.push_back(this);
}
void Viewer::getWindows(Windows& windows, bool onlyValid)
{
windows.clear();
Contexts contexts;
getContexts(contexts, onlyValid);
for(Contexts::iterator itr = contexts.begin();
itr != contexts.end();
++itr)
{
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(*itr);
if (gw) windows.push_back(gw);
}
}
void Viewer::getAllThreads(Threads& threads, bool onlyActive)
{
OperationThreads operationThreads;
@ -1033,68 +1016,34 @@ void Viewer::getOperationThreads(OperationThreads& threads, bool onlyActive)
}
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;
contexts.clear();
if (_camera.valid() &&
_camera->getGraphicsContext() &&
(_camera->getGraphicsContext()->valid() || !onlyValid))
{
contextSet.insert(_camera->getGraphicsContext());
contexts.push_back(_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))
osg::GraphicsContext* sgc = slave._camera.valid() ? slave._camera->getGraphicsContext() : 0;
if (sgc && (sgc->valid() || !onlyValid))
{
contextSet.insert(slave._camera->getGraphicsContext());
if (contextSet.count(sgc)==0)
{
contextSet.insert(sgc);
contexts.push_back(sgc);
}
}
}
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)

View File

@ -501,6 +501,22 @@ void ViewerBase::startThreading()
osg::notify(osg::INFO)<<"Set up threading"<<std::endl;
}
void ViewerBase::getWindows(Windows& windows, bool onlyValid)
{
windows.clear();
Contexts contexts;
getContexts(contexts, onlyValid);
for(Contexts::iterator itr = contexts.begin();
itr != contexts.end();
++itr)
{
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(*itr);
if (gw) windows.push_back(gw);
}
}
void ViewerBase::checkWindowStatus()
{
Contexts contexts;