Commit de9e2bbc authored by schurade's avatar schurade

[ADD] coloring of fiber bundles

parent 85f7a978
......@@ -197,8 +197,10 @@ void WMFiberDisplay::activate()
void WMFiberDisplay::properties()
{
m_useTubesProp = m_properties2->addProperty( "Use Tubes", "Draw fiber tracts as fake tubes.", false );
m_customColoring = m_properties2->addProperty( "Custom coloring", "Switches the coloring between custom and predefined.", false );
m_coloring = m_properties2->addProperty( "Global/Local coloring", "Switches the coloring between global and local.", true );
m_useTubesProp = m_properties2->addProperty( "Use Tubes", "Draw fiber tracts as fake tubes.", false );
m_tubeThickness = m_properties2->addProperty( "Tube thickness", "Adjusts the thickness of tubes", 50.,
boost::bind( &WMFiberDisplay::adjustTubes, this ) );
m_tubeThickness->setMin( 0 );
......@@ -232,10 +234,10 @@ void WMFiberDisplay::toggleTubes()
void WMFiberDisplay::toggleColoring()
{
if( m_coloring->changed() )
if( m_coloring->changed() || m_customColoring->changed() )
{
m_tubeDrawable->setColoringMode( m_coloring->get( true ) );
m_tubeDrawable->dirtyDisplayList();
m_tubeDrawable->setCustomColoring( m_customColoring->get( true ) );
}
}
......
......@@ -115,6 +115,7 @@ protected:
private:
WPropBool m_coloring; //!< Enable/Disable global (true) or local (false) coloring of the fiber tracts
WPropBool m_customColoring; //!< Enable/Disable custom colors
WPropBool m_useTubesProp; //!< Property indicating whether to use tubes for the fibers tracts.
WPropDouble m_tubeThickness; //!< Property determining the thickness of tubes .
......
......@@ -36,6 +36,8 @@ WRMBranch::WRMBranch( boost::shared_ptr< WROIManagerFibers > roiManager ) :
setDirty();
m_properties = boost::shared_ptr< WProperties2 >( new WProperties2() );
m_isNot = m_properties->addProperty( "NOT", "description", false, boost::bind( &WRMBranch::slotToggleNot, this ) );
m_bundleColor = m_properties->addProperty( "Bundle Color", "description", WColor( 1.0, 0.0, 0.0, 1.0 ),
boost::bind( &WRMBranch::slotChangeBundleColor, this ) );
}
WRMBranch::~WRMBranch()
......@@ -172,3 +174,7 @@ boost::shared_ptr< WProperties2 > WRMBranch::getProperties()
return m_properties;
}
void WRMBranch::slotChangeBundleColor()
{
m_roiManager->updateBundleColor( shared_from_this(), m_bundleColor->get() );
}
......@@ -138,6 +138,13 @@ protected:
*/
void slotToggleNot();
/**
* slot gets called when a property has changed
*
*/
void slotChangeBundleColor();
private:
bool m_dirty; //!< dirty flag to indicate the bit field must be recalculated
......@@ -161,6 +168,11 @@ private:
* indicates if the branch is negated
*/
WPropBool m_isNot;
/**
* The color used when in isosurface mode for blending.
*/
WPropColor m_bundleColor;
};
#endif // WRMBRANCH_H
......@@ -136,6 +136,7 @@ void WROIManagerFibers::addFiberDataset( boost::shared_ptr< const WDataSetFibers
m_kdTree = boost::shared_ptr< WKdTree >( new WKdTree( verts->size() / 3, &( ( *verts )[0] ) ) );
addBitField( fibers->size() );
createCustomColorArray();
setDirty();
}
......@@ -291,3 +292,39 @@ void WROIManagerFibers::addDefaultNotifier( boost::function< void( boost::shared
m_notifiers.push_back( notifier );
lock.unlock();
}
void WROIManagerFibers::createCustomColorArray()
{
boost::shared_ptr< std::vector< float > > colors = m_fibers->getGlobalColors();
m_customColors = boost::shared_ptr< std::vector< float > >( new std::vector< float >( ( *colors ).size() ) );
for ( size_t i = 0; i < ( *colors ).size(); ++i )
{
( *m_customColors )[i] = ( *colors )[i];
}
}
boost::shared_ptr< std::vector< float > >WROIManagerFibers::getCustomColors()
{
return m_customColors;
}
void WROIManagerFibers::updateBundleColor( boost::shared_ptr<WRMBranch> branch, WColor color )
{
boost::shared_ptr< std::vector< bool > > bf = branch->getBitField();
boost::shared_ptr< std::vector< size_t > > starts = m_fibers->getLineStartIndexes();
boost::shared_ptr< std::vector< size_t > > lengths = m_fibers->getLineLengths();
for ( size_t i = 0; i < bf->size(); ++i )
{
if ( (*bf)[i] )
{
for ( size_t k = (*starts)[i]; k < (*starts)[i] + (*lengths)[i]; ++k)
{
(*m_customColors)[k*3] = color.getRed();
(*m_customColors)[k*3+1] = color.getGreen();
(*m_customColors)[k*3+2] = color.getBlue();
}
}
}
}
......@@ -146,6 +146,24 @@ public:
*/
void recalculate();
/**
* creates a color array, that is used for coloring of fibers
*/
void createCustomColorArray();
/**
* getter
*/
boost::shared_ptr< std::vector< float > >getCustomColors();
/**
* updates the custom color array with the color of a selected branch
*
* \param branch
* \param color
*/
void updateBundleColor( boost::shared_ptr<WRMBranch> branch, WColor color );
protected:
private:
bool m_dirty; //!< dirty flag
......@@ -188,6 +206,8 @@ private:
* bool to lock the update function, will be removed again once we found out why the boost lock isnt working
*/
bool m_recalcLock;
boost::shared_ptr< std::vector< float > >m_customColors; //!< vector to store custom colors
};
#endif // WROIMANAGERFIBERS_H
......@@ -36,7 +36,8 @@
WTubeDrawable::WTubeDrawable():
osg::Drawable(),
m_useTubes( false ),
m_globalColoring( true )
m_globalColoring( true ),
m_customColoring( false )
{
setSupportsDisplayList( false );
// This contructor intentionally left blank. Duh.
......@@ -102,12 +103,27 @@ bool WTubeDrawable::getColoringMode() const
return m_globalColoring;
}
void WTubeDrawable::setCustomColoring( bool custom )
{
m_customColoring = custom;
}
void WTubeDrawable::drawFibers( osg::RenderInfo& renderInfo ) const //NOLINT
{
boost::shared_ptr< std::vector< size_t > > startIndexes = m_dataset->getLineStartIndexes();
boost::shared_ptr< std::vector< size_t > > pointsPerLine = m_dataset->getLineLengths();
boost::shared_ptr< std::vector< float > > verts = m_dataset->getVertices();
boost::shared_ptr< std::vector< float > > colors = ( m_globalColoring ? m_dataset->getGlobalColors() : m_dataset->getLocalColors() );
boost::shared_ptr< std::vector< float > > colors;
if ( m_customColoring )
{
colors = WKernel::getRunningKernel()->getRoiManager()->getCustomColors();
}
else
{
colors = ( m_globalColoring ? m_dataset->getGlobalColors() : m_dataset->getLocalColors() );
}
boost::shared_ptr< std::vector< bool > > active = WKernel::getRunningKernel()->getRoiManager()->getBitField();
osg::State& state = *renderInfo.getState();
......@@ -134,7 +150,17 @@ void WTubeDrawable::drawTubes() const
boost::shared_ptr< std::vector< size_t > > pointsPerLine = m_dataset->getLineLengths();
boost::shared_ptr< std::vector< float > > verts = m_dataset->getVertices();
boost::shared_ptr< std::vector< float > > tangents = m_dataset->getTangents();
boost::shared_ptr< std::vector< float > > colors = ( m_globalColoring ? m_dataset->getGlobalColors() : m_dataset->getLocalColors() );
boost::shared_ptr< std::vector< float > > colors;
if ( m_customColoring )
{
colors = WKernel::getRunningKernel()->getRoiManager()->getCustomColors();
}
else
{
colors = ( m_globalColoring ? m_dataset->getGlobalColors() : m_dataset->getLocalColors() );
}
boost::shared_ptr< std::vector< bool > > active = WKernel::getRunningKernel()->getRoiManager()->getBitField();
for( size_t i = 0; i < active->size(); ++i )
......
......@@ -109,6 +109,13 @@ public:
*/
void setColoringMode( bool globalColoring );
/**
* Set the use of custom colors
*
* \param custom
*/
void setCustomColoring( bool custom );
/**
* In which mode coloring for the fibers is applied.
*
......@@ -137,6 +144,8 @@ private:
bool m_useTubes; //!< flag
bool m_globalColoring; //!< True indicates global, false local coloring
bool m_customColoring; //!< True indicates use of custom colors
};
#endif // WTUBEDRAWABLE_H
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