Commit 7db1cc05 authored by Mathias Goldau's avatar Mathias Goldau

[FIX] Enabled local coloring in huge constructor => we need to fix this design I guess!

parent 59f4c946
......@@ -26,8 +26,9 @@
#include <algorithm>
#include <vector>
#include "../common/WColor.h"
#include "../graphicsEngine/WGEUtils.h"
#include "WDataSet.h"
#include "WDataSetFibers.h"
// prototype instance as singleton
......@@ -61,8 +62,10 @@ WDataSetFibers::WDataSetFibers( boost::shared_ptr< std::vector< float > >vertice
m_tangents = boost::shared_ptr< std::vector< float > >( new std::vector<float>() );
m_tangents->resize( m_vertices->size() );
m_colors = boost::shared_ptr< std::vector< float > >( new std::vector<float>() );
m_colors->resize( m_vertices->size() );
m_globalColors = boost::shared_ptr< std::vector< float > >( new std::vector<float>() );
m_globalColors->resize( m_vertices->size() );
m_localColors = boost::shared_ptr< std::vector< float > >( new std::vector<float>() );
m_localColors->resize( m_vertices->size() );
int pc = 0;
float r, g, b, rr, gg, bb;
......@@ -120,9 +123,34 @@ WDataSetFibers::WDataSetFibers( boost::shared_ptr< std::vector< float > >vertice
m_tangents->at( pc + 1 ) = gg;
m_tangents->at( pc + 2 ) = bb;
m_colors->at( pc ) = r;
m_colors->at( pc + 1 ) = g;
m_colors->at( pc + 2 ) = b;
m_globalColors->at( pc ) = r;
m_globalColors->at( pc + 1 ) = g;
m_globalColors->at( pc + 2 ) = b;
// local color fun:
WColor localColor;
wmath::WPosition currentPos( m_vertices->at( pc ), m_vertices->at( pc + 1 ), m_vertices->at( pc + 2 ) );
wmath::WPosition nextPos;
if( j < m_lineLengths->at( i ) - 1 )
{
nextPos[0] = m_vertices->at( pc + 3 );
nextPos[1] = m_vertices->at( pc + 4 );
nextPos[2] = m_vertices->at( pc + 5 );
localColor = wge::getRGBAColorFromDirection( currentPos, nextPos );
}
else if( m_lineLengths->size() > 1 ) // there was a color in this line before!
{
localColor = WColor( m_localColors->at( pc - 3 ),
m_localColors->at( pc - 2 ),
m_localColors->at( pc - 1 ) );
}
else // there was only one point
{
localColor = WColor( r, g, b ); // same as global color
}
m_localColors->at( pc ) = localColor.getRed();
m_localColors->at( pc + 1 ) = localColor.getGreen();
m_localColors->at( pc + 2 ) = localColor.getBlue();
pc += 3;
}
}
......@@ -188,11 +216,15 @@ boost::shared_ptr< std::vector< float > > WDataSetFibers::getTangents() const
return m_tangents;
}
boost::shared_ptr< std::vector< float > > WDataSetFibers::getColors() const
boost::shared_ptr< std::vector< float > > WDataSetFibers::getGlobalColors() const
{
return m_colors;
return m_globalColors;
}
boost::shared_ptr< std::vector< float > > WDataSetFibers::getLocalColors() const
{
return m_localColors;
}
wmath::WPosition WDataSetFibers::getPosition( size_t fiber, size_t vertex ) const
{
......
......@@ -123,11 +123,18 @@ public:
boost::shared_ptr< std::vector< float > > getTangents() const;
/**
* Getter
* Reference to the vector storing the global colors.
*
* \return Pointer to the float array.
*/
boost::shared_ptr< std::vector< float > > getColors() const;
boost::shared_ptr< std::vector< float > > getGlobalColors() const;
/**
* Reference to the vector storing the local colors.
*
* \return Pointer to the float array.
*/
boost::shared_ptr< std::vector< float > > getLocalColors() const;
/**
* returns the position in space for a vertex of a given fiber
......@@ -164,9 +171,14 @@ private:
boost::shared_ptr< std::vector< float > > m_tangents;
/**
* color vector for tangents at each vertex, used for fake tubes
* Storing the global color value of the fibers for each point.
*/
boost::shared_ptr< std::vector< float > > m_globalColors;
/**
* Storing the local color value of the fibers for each point.
*/
boost::shared_ptr< std::vector< float > > m_colors;
boost::shared_ptr< std::vector< float > > m_localColors;
/**
* Line vector that contains the start index of its first point for each line.
......
......@@ -59,10 +59,6 @@ const char** WMFiberDisplay::getXPMIcon() const
return fiberdisplay_xpm;
}
void WMFiberDisplay::updateColoring()
{
}
void WMFiberDisplay::moduleMain()
{
// additional fire-condition: "data changed" flag
......@@ -176,12 +172,7 @@ void WMFiberDisplay::activate()
void WMFiberDisplay::properties()
{
m_useTubesProp = m_properties2->addProperty( "Use Tubes", "Draw fiber tracts as fake tubes.", false );
// TODO( all ): remove the "true" that hides this property when local coloring is available again.
m_localColorProp = m_properties2->addProperty( "Local Color",
"Use local direction of fiber tract for coloring the line instead of global direction.",
false,
true );
m_coloring = m_properties2->addProperty( "Global/Local coloring", "Switches the coloring between global and local.", true );
}
void WMFiberDisplay::toggleTubes()
......@@ -206,6 +197,15 @@ void WMFiberDisplay::toggleTubes()
}
}
void WMFiberDisplay::toggleColoring()
{
if( m_coloring->changed() )
{
m_tubeDrawable->setColoringMode( m_coloring->get( true ) );
m_tubeDrawable->dirtyDisplayList();
}
}
WColor WMFiberDisplay::getRGBAColorFromDirection( const wmath::WPosition &pos1, const wmath::WPosition &pos2 )
{
wmath::WPosition direction( ( pos2 - pos1 ) );
......
......@@ -113,13 +113,8 @@ protected:
*/
void create();
/**
* Switches the osg to use the appropriate color array
*/
void updateColoring();
private:
WPropBool m_localColorProp; //!< Property indicating whether to use ocal or global coloring of fiber tracts
WPropBool m_coloring; //!< Enable/Disable global (true) or local (false) coloring of the fiber tracts
WPropBool m_useTubesProp; //!< Property indicating whether to use tubes for the fibers tracts.
/**
......@@ -167,6 +162,11 @@ private:
*/
void toggleTubes();
/**
* Enable disable global or local coloring
*/
void toggleColoring();
/**
* Node callback to handle updates properly
*/
......@@ -187,6 +187,7 @@ private:
{
module->update();
module->toggleTubes();
module->toggleColoring();
}
traverse( node, nv );
}
......
......@@ -35,7 +35,8 @@
// time (that is, the vertices drawn change from time to time).
WTubeDrawable::WTubeDrawable():
osg::Drawable(),
m_useTubes( false )
m_useTubes( false ),
m_globalColoring( true )
{
//setSupportsDisplayList (false);
// This contructor intentionally left blank. Duh.
......@@ -91,13 +92,22 @@ void WTubeDrawable::setUseTubes( bool flag )
m_useTubes = flag;
}
void WTubeDrawable::setColoringMode( bool globalColoring )
{
m_globalColoring = globalColoring;
}
bool WTubeDrawable::getColoringMode() const
{
return m_globalColoring;
}
void WTubeDrawable::drawFibers() const
{
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_dataset->getColors();
boost::shared_ptr< std::vector< float > > 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 )
......@@ -123,8 +133,7 @@ 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_dataset->getColors();
boost::shared_ptr< std::vector< float > > 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 )
......
......@@ -102,15 +102,29 @@ public:
*/
void setUseTubes( bool flag );
/**
* Set the coloring modes of the fibers.
*
* \param globalColoring If true is given global coloring is applied ( default ), else local coloring
*/
void setColoringMode( bool globalColoring );
/**
* In which mode coloring for the fibers is applied.
*
* \return True for global, false for local coloring
*/
bool getColoringMode() const;
protected:
private:
/**
* draw function for fibers
* Draw fibers as ordinary lines.
*/
void drawFibers() const;
/**
* draw function for fake tubes
* Draw fibers as fake tubes.
*/
void drawTubes() const;
......@@ -119,6 +133,8 @@ private:
boost::shared_mutex m_recalcLock; //!< lock
bool m_useTubes; //!< flag
bool m_globalColoring; //!< True indicates global, false local coloring
};
#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