Commit 10fc733c authored by schurade's avatar schurade
Browse files

[CLEANUP] use the functor callback for osg node updates

parent 43ddccf2
......@@ -210,7 +210,8 @@ void WMOverlayAtlas::init()
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( m_rootNode );
m_geode = new osg::Geode();
m_geode->setName( "_atlasSlice" );
m_rootNode->addUpdateCallback( new SafeUpdateCallback( this ) );
m_rootNode->addUpdateCallback( new WGEFunctorCallback< osg::Node >( boost::bind( &WMOverlayAtlas::updateCallback, this ) ) );
m_rootNode->insert( m_geode );
wmath::WPosition center;
......@@ -399,16 +400,6 @@ void WMOverlayAtlas::updatePlane()
m_dirty = false;
}
void WMOverlayAtlas::SafeUpdateCallback::operator()( osg::Node* node, osg::NodeVisitor* nv )
{
if ( m_module->isDirty() )
{
m_module->updatePlane();
m_module->updateTextures();
}
traverse( node, nv );
}
void WMOverlayAtlas::updateTextures()
{
osg::StateSet* rootState = m_rootNode->getOrCreateStateSet();
......@@ -741,3 +732,12 @@ void WMOverlayAtlas::toggleManipulators()
m_s4->hide();
}
}
void WMOverlayAtlas::updateCallback()
{
if ( isDirty() )
{
updatePlane();
updateTextures();
}
}
......@@ -174,6 +174,10 @@ private:
*/
void toggleManipulators();
/**
* update callback for osg node traversal
*/
void updateCallback();
/**
* A condition used to notify about changes in several properties.
......@@ -265,44 +269,6 @@ private:
std::vector< osg::ref_ptr<osg::Uniform> > m_samplerUniforms;
osg::ref_ptr<osg::Uniform> m_showCompleteUniform; //!< Determines whether the slice should be drawn completely
/**
* Node callback to change position and appearance of the plane within the OSG thread
*/
class SafeUpdateCallback : public osg::NodeCallback
{
public: // NOLINT
/**
* Constructor.
*
* \param module just set the creating module as pointer for later reference.
*/
explicit SafeUpdateCallback( WMOverlayAtlas* module ): m_module( module ), m_initialUpdate( true )
{
};
/**
* operator () - called during the update traversal.
*
* \param node the osg node
* \param nv the node visitor
*/
virtual void operator()( osg::Node* node, osg::NodeVisitor* nv );
/**
* Pointer used to access members of the module to modify the node.
* Please do not use shared_ptr here as this would prevent deletion of the module as the callback contains
* a reference to it. It is safe to use a simple pointer here as callback get deleted before the module.
*/
WMOverlayAtlas* m_module;
/**
* Denotes whether the update callback is called the first time. It is especially useful
* to set some initial value even if the property has not yet changed.
*/
bool m_initialUpdate;
};
};
inline float WMOverlayAtlas::s2f( std::string s )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment