Commit bde5f1ed authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[ADD #196] Now correct clean up of the fiber Display module, as well as...

[ADD #196] Now correct clean up of the fiber Display module, as well as disable module button works and switching of local global coloring scheme.
parent c9ff6390
......@@ -41,7 +41,8 @@
#include "WMFiberDisplay.h"
WMFiberDisplay::WMFiberDisplay()
: WModule()
: WModule(),
m_globalColoring( true )
{
}
......@@ -96,63 +97,47 @@ osg::ref_ptr< osg::Geode > WMFiberDisplay::genFiberGeode( boost::shared_ptr< con
void WMFiberDisplay::moduleMain()
{
// signal ready state
ready();
// additional fire-condition: "data changed" flag
m_moduleState.add( m_fiberInput->getDataChangedCondition() );
// ready();
// while( !m_FinishRequested )
// {
// if( m_fiberInput->getData() != boost::shared_ptr< const WDataSetFibers >() )
// {
// boost::shared_ptr< const WDataSetFibers > fiberDS = m_fiberInput->getData();
//
// osg::ref_ptr< osg::Group > group = osg::ref_ptr< osg::Group >( new osg::Group );
// group->addChild( genFiberGeode( fiberDS, false ).get() );
// group->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
//
// WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->addChild( group.get() );
// }
// // TODO(math): implement some redraw if data has changed
// // - replacing the OSG group node?
// // - using notifyDataChange() method
// while( !m_FinishRequested )
// {
// sleep( 1 );
// }
// }
boost::shared_ptr< WDataHandler > dataHandler;
// TODO(math): fix this hack when possible by using an input connector.
while( !WKernel::getRunningKernel() )
{
sleep( 1 );
}
while( !( dataHandler = WKernel::getRunningKernel()->getDataHandler() ) )
{
sleep( 1 );
}
while( !dataHandler->getNumberOfSubjects() )
{
sleep( 1 );
}
ready();
boost::shared_ptr< const WDataSetFibers > fiberDS;
if( fiberDS = boost::shared_dynamic_cast< const WDataSetFibers >( dataHandler->getSubject( 0 )->getDataSet( 0 ) ) )
while ( !m_shutdownFlag() ) // loop until the module container requests the module to quit
{
osg::ref_ptr< osg::Group > group = osg::ref_ptr< osg::Group >( new osg::Group );
group->addChild( genFiberGeode( fiberDS, false ).get() );
group->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
m_dataset = m_fiberInput->getData();
if ( !m_dataset.get() ) // ok, the output has not yet sent data
{
m_moduleState.wait();
continue;
}
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->addChild( group.get() );
}
m_osgNode = osg::ref_ptr< osg::Group >( new osg::Group );
m_osgNode->addChild( genFiberGeode( m_dataset, m_globalColoring ).get() );
// Since the modules run in a separate thread: such loops are possible
while ( !m_FinishRequested )
{
// do fancy stuff
sleep( 1 );
m_osgNode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->addChild( m_osgNode.get() );
m_moduleState.wait(); // waits for firing of m_moduleState ( dataChanged, shutdown, etc. )
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->removeChild( m_osgNode.get() );
}
}
void WMFiberDisplay::update()
{
// remove nodes if they are any
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->removeChild( m_osgNode.get() );
// create new node
m_osgNode = osg::ref_ptr< osg::Group >( new osg::Group );
m_osgNode->addChild( genFiberGeode( m_dataset, m_globalColoring ).get() );
m_osgNode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->addChild( m_osgNode.get() );
}
void WMFiberDisplay::connectors()
{
using boost::shared_ptr;
......@@ -167,4 +152,35 @@ void WMFiberDisplay::connectors()
void WMFiberDisplay::properties()
{
m_properties->addString( "Fibers Display Module", "Display fibers" );
// this bool is hidden
m_properties->addBool( "active", true, true )->connect( boost::bind( &WMFiberDisplay::slotPropertyChanged, this, _1 ) );
m_properties->addBool( "Local Color", true )->connect( boost::bind( &WMFiberDisplay::slotPropertyChanged, this, _1 ) );
}
void WMFiberDisplay::slotPropertyChanged( std::string propertyName )
{
if( propertyName == "active" )
{
if ( m_properties->getValue< bool >( propertyName ) )
{
m_osgNode->setNodeMask( 0xFFFFFFFF );
}
else
{
m_osgNode->setNodeMask( 0x0 );
}
}
else if ( propertyName == "Local Color" )
{
if( m_properties->getValue< bool >( propertyName ) != m_globalColoring )
{
m_globalColoring = m_properties->getValue< bool >( propertyName );
update();
}
}
else
{
debugLog() << propertyName << std::endl;
assert( 0 && "This property name is not supported by this function yet." );
}
}
......@@ -73,6 +73,12 @@ public:
*/
virtual boost::shared_ptr< WModule > factory() const;
/**
* Determine what to do if a property was changed.
* \param propertyName Name of the property.
*/
void slotPropertyChanged( std::string propertyName );
protected:
/**
* Entry point after loading the module. Runs in separate thread.
......@@ -91,15 +97,44 @@ protected:
boost::shared_ptr< const WDataSetFibers > fibers,
bool globalColoring = true ) const;
/**
* Initialize the connectors this module is using.
*/
virtual void connectors();
/**
* Initialize the properties for this module.
*/
virtual void properties();
/**
* Redraws the scene.
*
* \problem This might take a while with e.g. 70,000 fibers \approx 4 sec
*/
void update();
/**
* If the fibers have to be drawn in global coloring mode this is true, otherwise false.
*/
bool m_globalColoring;
private:
/**
* Input connector for a fiber dataset.
*/
boost::shared_ptr< WModuleInputData< const WDataSetFibers > > m_fiberInput;
/**
* Pointer to the fiber data set
*/
boost::shared_ptr< const WDataSetFibers > m_dataset;
/**
* OSG node for this module. All other OSG nodes of this module should be
* placed as child to this node.
*/
osg::ref_ptr< osg::Group > m_osgNode;
};
inline const std::string WMFiberDisplay::getName() const
......
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