Commit 057cc514 authored by schurade's avatar schurade

[FIX] custom coloring of fiber bundles should work again

parent 291e3a2b
......@@ -63,12 +63,13 @@ WDataSetFibers::WDataSetFibers( WDataSetFibers::VertexArray vertices,
m_bbMax( boundingBox.second )
{
m_tangents = boost::shared_ptr< std::vector< float > >( new std::vector<float>() );
m_tangents->resize( m_vertices->size() );
boost::shared_ptr< std::vector< float > > globalColors = boost::shared_ptr< std::vector< float > >( new std::vector<float>() );
globalColors->resize( m_vertices->size() );
boost::shared_ptr< std::vector< float > > localColors = boost::shared_ptr< std::vector< float > >( new std::vector<float>() );
localColors->resize( m_vertices->size() );
size_t size = m_vertices->size();
m_tangents = boost::shared_ptr< std::vector< float > >( new std::vector<float>( size ) );
boost::shared_ptr< std::vector< float > > globalColors = boost::shared_ptr< std::vector< float > >( new std::vector<float>( size ) );
boost::shared_ptr< std::vector< float > > localColors = boost::shared_ptr< std::vector< float > >( new std::vector<float>( size ) );
boost::shared_ptr< std::vector< float > > customColors = boost::shared_ptr< std::vector< float > >( new std::vector<float>( size ) );
// TODO(all): use the new WThreadedJobs functionality
WCreateColorArraysThread* t1 = new WCreateColorArraysThread( 0, m_lineLengths->size()/4, m_vertices,
......@@ -105,6 +106,16 @@ WDataSetFibers::WDataSetFibers( WDataSetFibers::VertexArray vertices,
)
);
for ( size_t i = 0; i < size; ++i )
{
( *customColors )[i] = ( *globalColors )[i];
}
m_colors->push_back( boost::shared_ptr< WItemSelectionItem >(
new ColorScheme( "Custom Color", "Colors copied from the global colors, will be used for bundle coloring.",
NULL, customColors, ColorScheme::RGB )
)
);
// the colors can be selected by properties
m_colorProp = m_properties->addProperty( "Color Scheme", "Determines the coloring scheme to use for this data.", m_colors->getSelectorFirst() );
WPropertyHelper::PC_SELECTONLYONE::addTo( m_colorProp );
......
......@@ -25,6 +25,8 @@
#include <list>
#include <vector>
#include "../graphicsEngine/WGraphicsEngine.h"
#include "WROIManager.h"
#include "WRMBranch.h"
......@@ -44,6 +46,7 @@ void WRMBranch::properties()
m_properties = boost::shared_ptr< WProperties >( new WProperties( "Properties", "This branch's properties" ) );
m_dirty = m_properties->addProperty( "Dirty", "", true, boost::bind( &WRMBranch::propertyChanged, this ) );
m_dirty->setHidden( true );
m_isNot = m_properties->addProperty( "NOT", "description", false, boost::bind( &WRMBranch::propertyChanged, this ) );
m_bundleColor = m_properties->addProperty( "Bundle Color", "description", WColor( 1.0, 0.0, 0.0, 1.0 ),
boost::bind( &WRMBranch::propertyChanged, this ) );
......@@ -96,6 +99,11 @@ void WRMBranch::getRois( std::vector< osg::ref_ptr< WROI > >& roiVec ) // NOLINT
void WRMBranch::removeAllRois()
{
for( std::list< osg::ref_ptr< WROI > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter )
{
WGraphicsEngine::getGraphicsEngine()->getScene()->remove( ( *iter ) );
}
m_rois.clear();
}
......@@ -103,6 +111,12 @@ void WRMBranch::setDirty()
{
m_dirty->set( true );
m_roiManager->setDirty();
for ( std::list< boost::function< void() > >::iterator iter = m_changeNotifiers.begin();
iter != m_changeNotifiers.end(); ++iter )
{
( *iter )();
}
}
osg::ref_ptr< WROI > WRMBranch::getFirstRoi()
......@@ -119,3 +133,11 @@ boost::shared_ptr< WProperties > WRMBranch::getProperties()
{
return m_properties;
}
void WRMBranch::addChangeNotifier( boost::function< void() > notifier )
{
boost::unique_lock< boost::shared_mutex > lock;
lock = boost::unique_lock< boost::shared_mutex >( m_associatedNotifiersLock );
m_changeNotifiers.push_back( notifier );
lock.unlock();
}
......@@ -132,6 +132,14 @@ public:
*/
void getRois( std::vector< osg::ref_ptr< WROI > >& roiVec ); //NOLINT
/**
* Add a specified notifier to the list of default notifiers which get connected to each branch
*
* \param notifier the notifier function
*/
void addChangeNotifier( boost::function< void() > notifier );
protected:
/**
* initializes properties
......@@ -164,6 +172,16 @@ private:
* The color used when in isosurface mode for blending.
*/
WPropColor m_bundleColor;
/**
* The notifiers connected to added rois by default.
*/
std::list< boost::function< void() > > m_changeNotifiers;
/**
* Lock for associated notifiers set.
*/
boost::shared_mutex m_associatedNotifiersLock;
};
inline bool WRMBranch::empty()
......
......@@ -92,16 +92,14 @@ void WFiberDrawable::drawFibers( osg::RenderInfo& renderInfo ) const //NOLINT
boost::shared_ptr< std::vector< float > > colors;
// TODO(schurade): roi refactoring
// if ( m_customColoring )
// {
// colors = WKernel::getRunningKernel()->getRoiManager()->getCustomColors();
// }
// else
// {
// colors = ( m_globalColoring ? m_dataset->getGlobalColors() : m_dataset->getLocalColors() );
// }
colors = ( m_globalColoring ? m_dataset->getGlobalColors() : m_dataset->getLocalColors() );
if ( m_customColoring )
{
colors = colors = m_dataset->getColorScheme( "Custom Color" )->getColor();
}
else
{
colors = ( m_globalColoring ? m_dataset->getGlobalColors() : m_dataset->getLocalColors() );
}
boost::shared_ptr< std::vector< bool > > active = m_fiberSelector->getBitfield();
......@@ -131,16 +129,15 @@ void WFiberDrawable::drawTubes() const
boost::shared_ptr< std::vector< float > > tangents = m_dataset->getTangents();
boost::shared_ptr< std::vector< float > > colors;
// TODO(schurade): roi refactoring
// if ( m_customColoring )
// {
// colors = WKernel::getRunningKernel()->getRoiManager()->getCustomColors();
// }
// else
// {
//
// }
colors = ( m_globalColoring ? m_dataset->getGlobalColors() : m_dataset->getLocalColors() );
if ( m_customColoring )
{
colors = m_dataset->getColorScheme( "Custom Color" )->getColor();
}
else
{
colors = ( m_globalColoring ? m_dataset->getGlobalColors() : m_dataset->getLocalColors() );
}
boost::shared_ptr< std::vector< bool > > active = m_fiberSelector->getBitfield();
......
......@@ -146,6 +146,12 @@ public:
*/
void setSelector( boost::shared_ptr< WFiberSelector > selector );
/**
* setter
* \param colors
*/
void setCustomColors( boost::shared_ptr< std::vector< float > > colors );
protected:
private:
/**
......@@ -170,6 +176,7 @@ private:
bool m_customColoring; //!< True indicates use of custom colors
boost::shared_ptr< std::vector< bool > > m_active; //!< pointer to the bitfield of active fibers
boost::shared_ptr< WFiberSelector > m_fiberSelector; //!< the selector object which provides the bitfield for fiber selection
......
......@@ -75,7 +75,8 @@ void WFiberSelector::slotAddRoi( osg::ref_ptr< WROI > roi )
}
if ( !( branch.get() ) )
{
branch = boost::shared_ptr<WSelectorBranch>( new WSelectorBranch( m_size, WKernel::getRunningKernel()->getRoiManager()->getBranch( roi ) ) );
branch = boost::shared_ptr<WSelectorBranch>(
new WSelectorBranch( m_fibers, WKernel::getRunningKernel()->getRoiManager()->getBranch( roi ) ) );
m_branches.push_back( branch );
}
......@@ -119,6 +120,11 @@ void WFiberSelector::slotRemoveBranch( boost::shared_ptr< WRMBranch > branch )
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();
......
......@@ -102,6 +102,19 @@ protected:
*/
void slotRemoveBranch( boost::shared_ptr< WRMBranch > branch );
/**
* setter
* \param colors
*/
void setCustomColors( boost::shared_ptr< std::vector< float > > colors );
/**
* getter
* \return colors
*/
boost::shared_ptr< std::vector< float > > getCustomColors();
private:
/**
......
......@@ -24,12 +24,16 @@
#include "WSelectorBranch.h"
WSelectorBranch::WSelectorBranch( size_t size, boost::shared_ptr<WRMBranch> branch ) :
m_size( size ),
WSelectorBranch::WSelectorBranch( boost::shared_ptr< const WDataSetFibers > fibers, boost::shared_ptr<WRMBranch> branch ) :
m_fibers( fibers ),
m_size( fibers->size() ),
m_dirty( true ),
m_branch( branch )
{
m_bitField = boost::shared_ptr< std::vector<bool> >( new std::vector<bool>( m_size, false ) );
boost::function< void() > changeSignal = boost::bind( &WSelectorBranch::setDirty, this );
m_branch->addChangeNotifier( changeSignal );
}
WSelectorBranch::~WSelectorBranch()
......@@ -47,6 +51,11 @@ void WSelectorBranch::addRoi( boost::shared_ptr< WSelectorRoi> roi )
void WSelectorBranch::setDirty()
{
m_dirty = true;
if ( m_branch->getProperties()->getProperty( "Bundle Color" )->toPropColor()->changed() )
{
colorChanged();
}
}
void WSelectorBranch::removeRoi( osg::ref_ptr< WROI > roi )
......@@ -115,3 +124,27 @@ void WSelectorBranch::recalculate()
m_bitField = m_workerBitfield;
}
void WSelectorBranch::colorChanged()
{
WColor color = m_branch->getProperties()->getProperty( "Bundle Color" )->toPropColor()->get( true );
boost::shared_ptr<std::vector<float> > array = m_fibers->getColorScheme( "Custom Color" )->getColor();
boost::shared_ptr< std::vector< size_t > > startIndexes = m_fibers->getLineStartIndexes();
boost::shared_ptr< std::vector< size_t > > pointsPerLine = m_fibers->getLineLengths();
for ( size_t i = 0; i < m_size; ++i )
{
if ( ( *m_bitField )[i] )
{
size_t idx = ( *startIndexes )[i] * 3;
for ( size_t k = 0; k < ( *pointsPerLine )[i]; ++k )
{
( *array )[idx++] = color.getRed();
( *array )[idx++] = color.getGreen();
( *array )[idx++] = color.getBlue();
}
}
}
}
......@@ -39,10 +39,10 @@ class WSelectorBranch
public:
/**
* constructor
* \param size number of fibers int he dataset
* \param fibers pointer to the fiber dataset to work on
* \param branch pointer to the branch object in the roi manager
*/
WSelectorBranch( size_t size, boost::shared_ptr<WRMBranch> branch );
WSelectorBranch( boost::shared_ptr< const WDataSetFibers > fibers, boost::shared_ptr<WRMBranch> branch );
/**
* destructor
......@@ -85,13 +85,28 @@ public:
*/
void setDirty();
/**
* getter
*/
bool dirty();
protected:
/**
* function gets called when the color property of the roi branch has changed, it will write this color
* into the custom color array of the fiber dataset
*/
void colorChanged();
private:
/**
* updates the output bitfield with the information from all rois in this branch
*/
void recalculate();
/**
* Pointer to the fiber data set
*/
boost::shared_ptr< const WDataSetFibers > m_fibers;
/**
* size of the fiber dataset, stored for convinience
*/
......@@ -139,4 +154,9 @@ inline bool WSelectorBranch::empty()
return m_rois.empty();
}
inline bool WSelectorBranch::dirty()
{
return m_dirty;
}
#endif // WSELECTORBRANCH_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