Commit 90387f13 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE #252] fiberDisplaySimple now is able to handle the ROI mechanism using...

[CHANGE #252] fiberDisplaySimple now is able to handle the ROI mechanism using memory mapped vertex attributes. This is faster than the old way.
parent fbf7d257
...@@ -147,15 +147,6 @@ void WFiberSelector::slotRemoveBranch( boost::shared_ptr< WRMBranch > branch ) ...@@ -147,15 +147,6 @@ void WFiberSelector::slotRemoveBranch( boost::shared_ptr< WRMBranch > branch )
boost::shared_ptr< std::vector< bool > > WFiberSelector::getBitfield() boost::shared_ptr< std::vector< bool > > WFiberSelector::getBitfield()
{ {
for( std::list< boost::shared_ptr< WSelectorBranch > >::iterator iter = m_branches.begin(); iter != m_branches.end(); ++iter )
{
m_dirty = std::max( m_dirty, ( *iter )->dirty() );
}
if( m_dirty )
{
recalculate();
}
return m_outputBitfield; return m_outputBitfield;
} }
...@@ -185,14 +176,18 @@ void WFiberSelector::recalculate() ...@@ -185,14 +176,18 @@ void WFiberSelector::recalculate()
( *m_outputBitfield )[i] = ( *m_workerBitfield )[i]; ( *m_outputBitfield )[i] = ( *m_workerBitfield )[i];
} }
m_dirty = false; m_dirty = false;
//m_outputBitfield = m_workerBitfield;
} }
void WFiberSelector::setDirty() void WFiberSelector::setDirty()
{ {
recalculate();
m_dirty = true; m_dirty = true;
m_dirtyCondition->notify(); m_dirtyCondition->notify();
recalculate();
}
bool WFiberSelector::getDirty()
{
return m_dirty;
} }
WCondition::SPtr WFiberSelector::getDirtyCondition() WCondition::SPtr WFiberSelector::getDirtyCondition()
......
...@@ -86,6 +86,11 @@ public: ...@@ -86,6 +86,11 @@ public:
*/ */
void setDirty(); void setDirty();
/**
* Get the current dirty-state.
*/
bool getDirty();
/** /**
* Condition that fires upon a recalculation of the fiber selection. * Condition that fires upon a recalculation of the fiber selection.
* *
......
...@@ -258,6 +258,8 @@ void WMFiberDisplaySimple::moduleMain() ...@@ -258,6 +258,8 @@ void WMFiberDisplaySimple::moduleMain()
new WGEShaderPropertyDefineOptions< WPropBool >( m_colormapEnabled, "COLORMAPPING_DISABLED", "COLORMAPPING_ENABLED" ) ) new WGEShaderPropertyDefineOptions< WPropBool >( m_colormapEnabled, "COLORMAPPING_DISABLED", "COLORMAPPING_ENABLED" ) )
); );
m_shader->addBindAttribLocation( "a_bitfield", 6 );
// get notified about data changes // get notified about data changes
m_moduleState.setResetable( true, true ); m_moduleState.setResetable( true, true );
m_moduleState.add( m_fiberInput->getDataChangedCondition() ); m_moduleState.add( m_fiberInput->getDataChangedCondition() );
...@@ -373,6 +375,15 @@ void WMFiberDisplaySimple::moduleMain() ...@@ -373,6 +375,15 @@ void WMFiberDisplaySimple::moduleMain()
// add geode to module node // add geode to module node
postNode->clear(); postNode->clear();
// get a new fiber selector
m_fiberSelector = boost::shared_ptr<WFiberSelector>( new WFiberSelector( fibers ) );
// register dirty notifier
m_roiUpdateConnection.disconnect();
m_roiUpdateConnection = m_fiberSelector->getDirtyCondition()->subscribeSignal(
boost::bind( &WMFiberDisplaySimple::roiUpdate, this )
);
// create the fiber geode // create the fiber geode
osg::ref_ptr< osg::Geode > geode = new osg::Geode(); osg::ref_ptr< osg::Geode > geode = new osg::Geode();
osg::ref_ptr< osg::Geode > endCapGeode = new osg::Geode(); osg::ref_ptr< osg::Geode > endCapGeode = new osg::Geode();
...@@ -654,6 +665,14 @@ void WMFiberDisplaySimple::createFiberGeode( boost::shared_ptr< WDataSetFibers > ...@@ -654,6 +665,14 @@ void WMFiberDisplaySimple::createFiberGeode( boost::shared_ptr< WDataSetFibers >
geometry->setUseDisplayList( false ); geometry->setUseDisplayList( false );
geometry->setUseVertexBufferObjects( true ); geometry->setUseVertexBufferObjects( true );
m_bitfieldAttribs = new osg::FloatArray( m_fibers->getLineStartIndexes()->size() );
for( size_t fidx = 0; fidx < m_fibers->getLineStartIndexes()->size() ; ++fidx )
{
( *m_bitfieldAttribs )[ fidx ] = 1;
}
geometry->setVertexAttribArray( 6, m_bitfieldAttribs );
geometry->setVertexAttribBinding( 6, osg::Geometry::BIND_PER_PRIMITIVE_SET );
// add an update callback which later handles several things like the filter attribute array // add an update callback which later handles several things like the filter attribute array
geometry->setUpdateCallback( new WGEFunctorCallback< osg::Drawable >( boost::bind( &WMFiberDisplaySimple::geometryUpdate, this, _1 ) ) ); geometry->setUpdateCallback( new WGEFunctorCallback< osg::Drawable >( boost::bind( &WMFiberDisplaySimple::geometryUpdate, this, _1 ) ) );
...@@ -667,6 +686,18 @@ void WMFiberDisplaySimple::createFiberGeode( boost::shared_ptr< WDataSetFibers > ...@@ -667,6 +686,18 @@ void WMFiberDisplaySimple::createFiberGeode( boost::shared_ptr< WDataSetFibers >
void WMFiberDisplaySimple::geometryUpdate( osg::Drawable* geometry ) void WMFiberDisplaySimple::geometryUpdate( osg::Drawable* geometry )
{ {
osg::Geometry* g = static_cast< osg::Geometry* >( geometry ); osg::Geometry* g = static_cast< osg::Geometry* >( geometry );
if( m_fiberSelectorChanged )
{
m_fiberSelectorChanged = false;
// now initialize attribute array
for( size_t fidx = 0; fidx < m_fibers->getLineStartIndexes()->size() ; ++fidx )
{
( *m_bitfieldAttribs )[ fidx ] = m_fiberSelector->getBitfield()->at( fidx );
}
m_bitfieldAttribs->dirty();
}
if( m_fiberClusteringUpdate && m_fiberClustering ) if( m_fiberClusteringUpdate && m_fiberClustering )
{ {
m_fiberClusteringUpdate = false; m_fiberClusteringUpdate = false;
...@@ -721,3 +752,7 @@ void WMFiberDisplaySimple::lineGeodeStateCallback( osg::StateSet* state ) ...@@ -721,3 +752,7 @@ void WMFiberDisplaySimple::lineGeodeStateCallback( osg::StateSet* state )
} }
} }
void WMFiberDisplaySimple::roiUpdate()
{
m_fiberSelectorChanged = true;
}
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "core/dataHandler/WDataSetFiberClustering.h" #include "core/dataHandler/WDataSetFiberClustering.h"
#include "core/dataHandler/WDataSetFibers.h" #include "core/dataHandler/WDataSetFibers.h"
#include "core/kernel/WFiberSelector.h"
// forward declarations // forward declarations
class WGEShader; class WGEShader;
...@@ -291,6 +292,31 @@ private: ...@@ -291,6 +292,31 @@ private:
* \param state the state * \param state the state
*/ */
void lineGeodeStateCallback( osg::StateSet* state ); void lineGeodeStateCallback( osg::StateSet* state );
/**
* Point to a fiber selector, which is an adapter between the ROI manager and the this module
*/
boost::shared_ptr< WFiberSelector > m_fiberSelector;
/**
* Is true when received a change signal from m_fiberSelector
*/
bool m_fiberSelectorChanged;
/**
* Connection to the roi dirty signal.
*/
boost::signals2::connection m_roiUpdateConnection;
/**
* Called when updating the selection.
*/
void roiUpdate();
/**
* Contains the ROI bitfield
*/
osg::ref_ptr< osg::FloatArray > m_bitfieldAttribs;
}; };
#endif // WMFIBERDISPLAYSIMPLE_H #endif // WMFIBERDISPLAYSIMPLE_H
......
...@@ -63,6 +63,11 @@ uniform float u_colormapRatio = 1.0; ...@@ -63,6 +63,11 @@ uniform float u_colormapRatio = 1.0;
*/ */
void main() void main()
{ {
if( v_discard > 0.0 )
{
discard;
}
#ifdef CLIPPLANE_ENABLED #ifdef CLIPPLANE_ENABLED
// discard fragment if too far from plane // discard fragment if too far from plane
if( abs( v_dist ) >= u_distance ) if( abs( v_dist ) >= u_distance )
......
...@@ -75,3 +75,8 @@ varying float v_worldScale; ...@@ -75,3 +75,8 @@ varying float v_worldScale;
*/ */
varying vec3 v_clusterColor; varying vec3 v_clusterColor;
#endif #endif
/**
* Varying defines wether to discard the fragments or not.
*/
varying float v_discard;
...@@ -49,6 +49,11 @@ uniform vec3 u_planeVector; ...@@ -49,6 +49,11 @@ uniform vec3 u_planeVector;
*/ */
uniform float u_tubeSize; uniform float u_tubeSize;
/**
* This vertex attribute is the bitmask denoting whether to show the fiber or not
*/
in float a_bitfield;
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Attributes // Attributes
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
...@@ -135,6 +140,8 @@ void main() ...@@ -135,6 +140,8 @@ void main()
v_clusterColor = gl_SecondaryColor.rgb; v_clusterColor = gl_SecondaryColor.rgb;
#endif #endif
v_discard = 1.0 - a_bitfield;
// Simply project the vertex afterwards // Simply project the vertex afterwards
gl_Position = gl_ProjectionMatrix * v_vertex; gl_Position = gl_ProjectionMatrix * v_vertex;
gl_FrontColor = gl_Color; gl_FrontColor = gl_Color;
......
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