Commit a73d8acb authored by schurade's avatar schurade

[CHANGE] moved the fiber drawable to graphics engine to make it available for other modules

parent d29d5594
......@@ -24,8 +24,8 @@
#include <vector>
#include "../../dataHandler/WDataSetFibers.h"
#include "../../kernel/WKernel.h"
#include "../kernel/WKernel.h"
#include "WFiberDrawable.h"
// The constructor here does nothing. One thing that may be necessary is
......@@ -35,9 +35,7 @@
// time (that is, the vertices drawn change from time to time).
WFiberDrawable::WFiberDrawable():
osg::Drawable(),
m_useTubes( false ),
m_globalColoring( true ),
m_customColoring( false )
m_useTubes( false )
{
setSupportsDisplayList( false );
// This contructor intentionally left blank. Duh.
......@@ -85,35 +83,17 @@ void WFiberDrawable::drawImplementation( osg::RenderInfo& renderInfo ) const //N
void WFiberDrawable::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 > > tangents = m_dataset->getTangents();
boost::shared_ptr< std::vector< float > > colors;
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();
osg::State& state = *renderInfo.getState();
state.disableAllVertexArrays();
state.setVertexPointer( 3, GL_FLOAT , 0, &( *verts )[0] );
state.setColorPointer( 3 , GL_FLOAT , 0, &( *colors )[0] );
state.setNormalPointer( GL_FLOAT , 0, &( *tangents )[0] );
for ( size_t i = 0; i < active->size(); ++i )
state.setVertexPointer( 3, GL_FLOAT , 0, &( *m_verts )[0] );
state.setColorPointer( 3 , GL_FLOAT , 0, &( *m_colors )[0] );
state.setNormalPointer( GL_FLOAT , 0, &( *m_tangents )[0] );
for ( size_t i = 0; i < m_active->size(); ++i )
{
if ( (*active)[i] )
if ( (*m_active)[i] )
{
state.glDrawArraysInstanced( GL_LINE_STRIP, (*startIndexes)[i], (*pointsPerLine)[i], 1);
state.glDrawArraysInstanced( GL_LINE_STRIP, (*m_startIndexes)[i], (*m_pointsPerLine)[i], 1);
}
}
......@@ -123,38 +103,20 @@ void WFiberDrawable::drawFibers( osg::RenderInfo& renderInfo ) const //NOLINT
void WFiberDrawable::drawTubes() 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 > > tangents = m_dataset->getTangents();
boost::shared_ptr< std::vector< float > > colors;
if ( m_customColoring )
for( size_t i = 0; i < m_active->size(); ++i )
{
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();
for( size_t i = 0; i < active->size(); ++i )
{
if ( active->at( i ) )
if ( (*m_active)[i] )
{
glBegin( GL_QUAD_STRIP );
int idx = startIndexes->at( i ) * 3;
for ( size_t k = 0; k < pointsPerLine->at( i ); ++k )
int idx = m_startIndexes->at( i ) * 3;
for ( size_t k = 0; k < m_pointsPerLine->at( i ); ++k )
{
glNormal3f( tangents->at( idx ), tangents->at( idx + 1 ), tangents->at( idx + 2 ) );
glColor3f( colors->at( idx ), colors->at( idx + 1 ), colors->at( idx + 2 ) );
glNormal3f( m_tangents->at( idx ), m_tangents->at( idx + 1 ), m_tangents->at( idx + 2 ) );
glColor3f( m_colors->at( idx ), m_colors->at( idx + 1 ), m_colors->at( idx + 2 ) );
glTexCoord1f( -1.0f );
glVertex3f( verts->at( idx ), verts->at( idx + 1 ), verts->at( idx + 2 ) );
glVertex3f( m_verts->at( idx ), m_verts->at( idx + 1 ), m_verts->at( idx + 2 ) );
glTexCoord1f( 1.0f );
glVertex3f( verts->at( idx ), verts->at( idx + 1 ), verts->at( idx + 2 ) );
glVertex3f( m_verts->at( idx ), m_verts->at( idx + 1 ), m_verts->at( idx + 2 ) );
idx += 3;
//
}
......@@ -162,3 +124,8 @@ void WFiberDrawable::drawTubes() const
}
}
}
void WFiberDrawable::setDataset( boost::shared_ptr< const WDataSetFibers > dataset )
{
m_dataset = dataset;
}
......@@ -35,12 +35,8 @@
#include <osg/ShapeDrawable>
#include <osg/Group>
#include "../../kernel/WFiberSelector.h"
class WDataSetFibers;
/**
* TODO(schurade): Document this!
* Class implements an osg::Drawable that paints fiber representations either using lines or tubes
*/
class WFiberDrawable: public osg::Drawable
{
......@@ -108,49 +104,46 @@ 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
* Set the bounding box of all fibers.
* \param bb The new bounding box.
*/
void setColoringMode( bool globalColoring );
void setBoundingBox( const osg::BoundingBox & bb );
/**
* Set the use of custom colors
*
* \param custom
* setter
* \param bitField selected fibers to draw
*/
void setCustomColoring( bool custom );
void setBitfield( boost::shared_ptr< std::vector< bool > > bitField );
/**
* In which mode coloring for the fibers is applied.
*
* \return True for global, false for local coloring
* setter
* \param idx
*/
bool getColoringMode() const;
void setStartIndexes( boost::shared_ptr< std::vector< size_t > > idx );
/**
* Set the bounding box of all fibers.
* \param bb The new bounding box.
* setter
* \param ppl
*/
void setBoundingBox( const osg::BoundingBox & bb );
void setPointsPerLine( boost::shared_ptr< std::vector< size_t > > ppl );
/**
* setter
* \param bitField selected fibers to draw
* \param verts
*/
void setBitfield( boost::shared_ptr< std::vector< bool > > bitField );
void setVerts( boost::shared_ptr< std::vector< float > > verts );
/**
* setter
* \param selector the selector object which provides the bitfield for fiber selection
* \param tangents
*/
void setSelector( boost::shared_ptr< WFiberSelector > selector );
void setTangents( boost::shared_ptr< std::vector< float > > tangents );
/**
* setter
* \param colors
* \param color
*/
void setCustomColors( boost::shared_ptr< std::vector< float > > colors );
void setColor( boost::shared_ptr< std::vector< float > > color );
protected:
private:
......@@ -172,54 +165,53 @@ private:
bool m_useTubes; //!< flag
bool m_globalColoring; //!< True indicates global, false local coloring
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
boost::shared_ptr< std::vector< size_t > > m_startIndexes; //!< pointer to the field of line start indexes
boost::shared_ptr< std::vector< size_t > > m_pointsPerLine; //!< pointer to the field of points per line
boost::shared_ptr< std::vector< float > > m_verts; //!< pointer to the field of vertexes
boost::shared_ptr< std::vector< float > > m_tangents; //!< pointer to the field of line tangents
boost::shared_ptr< std::vector< float > > m_colors; //!< pointer to the field of colors per vertex
};
inline void WFiberDrawable::setDataset( boost::shared_ptr< const WDataSetFibers > dataset )
inline void WFiberDrawable::setUseTubes( bool flag )
{
m_dataset = dataset;
m_useTubes = flag;
}
inline void WFiberDrawable::setUseTubes( bool flag )
inline void WFiberDrawable::setBoundingBox( const osg::BoundingBox & bb )
{
m_useTubes = flag;
setBound( bb );
}
inline void WFiberDrawable::setColoringMode( bool globalColoring )
inline void WFiberDrawable::setBitfield( boost::shared_ptr< std::vector< bool > > bitField )
{
m_globalColoring = globalColoring;
m_active = bitField;
}
inline bool WFiberDrawable::getColoringMode() const
inline void WFiberDrawable::setStartIndexes( boost::shared_ptr< std::vector< size_t > > idx )
{
return m_globalColoring;
m_startIndexes = idx;
}
inline void WFiberDrawable::setCustomColoring( bool custom )
inline void WFiberDrawable::setPointsPerLine( boost::shared_ptr< std::vector< size_t > > ppl )
{
m_customColoring = custom;
m_pointsPerLine = ppl;
}
inline void WFiberDrawable::setBoundingBox( const osg::BoundingBox & bb )
inline void WFiberDrawable::setVerts( boost::shared_ptr< std::vector< float > > verts )
{
setBound( bb );
m_verts = verts;
}
inline void WFiberDrawable::setBitfield( boost::shared_ptr< std::vector< bool > > bitField )
inline void WFiberDrawable::setTangents( boost::shared_ptr< std::vector< float > > tangents )
{
m_active = bitField;
m_tangents = tangents;
}
inline void WFiberDrawable::setSelector( boost::shared_ptr< WFiberSelector > selector )
inline void WFiberDrawable::setColor( boost::shared_ptr< std::vector< float > > color )
{
m_fiberSelector = selector;
m_colors = color;
}
#endif // WFIBERDRAWABLE_H
......@@ -136,13 +136,11 @@ void WFiberSelector::recalculate()
{
if ( m_branches.empty() )
{
m_outputBitfield = boost::shared_ptr< std::vector< bool > >( new std::vector< bool >( m_size, true ) );
return;
m_workerBitfield = boost::shared_ptr< std::vector< bool > >( new std::vector< bool >( m_size, true ) );
}
else
{
m_workerBitfield = boost::shared_ptr< std::vector< bool > >( new std::vector< bool >( m_size, false ) );
}
for ( std::list< boost::shared_ptr< WSelectorBranch > >::iterator iter = m_branches.begin(); iter != m_branches.end(); ++iter )
{
......@@ -153,11 +151,18 @@ void WFiberSelector::recalculate()
( *m_workerBitfield )[i] = ( *m_workerBitfield )[i] | ( *bf )[i];
}
}
}
for ( size_t i = 0; i < m_size; ++i )
{
( *m_outputBitfield )[i] = ( *m_workerBitfield )[i];
}
m_dirty = false;
m_outputBitfield = m_workerBitfield;
//m_outputBitfield = m_workerBitfield;
}
void WFiberSelector::setDirty()
{
recalculate();
m_dirty = true;
}
......@@ -102,20 +102,6 @@ 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:
/**
* update the bitfield when there was a change in the roi structure
......
......@@ -282,14 +282,20 @@ void WMFiberDisplay::create()
osg::ref_ptr< osg::Group > osgNodeNew = osg::ref_ptr< osg::Group >( new osg::Group );
m_fiberDrawable = osg::ref_ptr< WFiberDrawable >( new WFiberDrawable );
m_fiberDrawable->setSelector( m_fiberSelector );
m_fiberDrawable->setBoundingBox( osg::BoundingBox( m_dataset->getBoundingBox().first[0],
m_dataset->getBoundingBox().first[1],
m_dataset->getBoundingBox().first[2],
m_dataset->getBoundingBox().second[0],
m_dataset->getBoundingBox().second[1],
m_dataset->getBoundingBox().second[2] ) );
m_fiberDrawable->setDataset( m_dataset );
m_fiberDrawable->setStartIndexes( m_dataset->getLineStartIndexes() );
m_fiberDrawable->setPointsPerLine( m_dataset->getLineLengths() );
m_fiberDrawable->setVerts( m_dataset->getVertices() );
m_fiberDrawable->setTangents( m_dataset->getTangents() );
m_fiberDrawable->setColor( m_dataset->getGlobalColors() );
m_fiberDrawable->setBitfield( m_fiberSelector->getBitfield() );
m_fiberDrawable->setUseDisplayList( false );
m_fiberDrawable->setDataVariance( osg::Object::DYNAMIC );
......@@ -395,8 +401,21 @@ void WMFiberDisplay::toggleColoring()
{
if( m_coloring->changed() || m_customColoring->changed() )
{
m_fiberDrawable->setColoringMode( m_coloring->get( true ) );
m_fiberDrawable->setCustomColoring( m_customColoring->get( true ) );
if ( m_customColoring->get( true ) )
{
m_fiberDrawable->setColor( m_dataset->getColorScheme( "Custom Color" )->getColor() );
}
else
{
if ( m_coloring->get( true ) )
{
m_fiberDrawable->setColor( m_dataset->getGlobalColors() );
}
else
{
m_fiberDrawable->setColor( m_dataset->getLocalColors() );
}
}
}
}
......
......@@ -30,6 +30,8 @@
#include <osg/Geode>
#include "../../dataHandler/WDataSetFibers.h"
#include "../../graphicsEngine/WFiberDrawable.h"
#include "../../graphicsEngine/WROI.h"
#include "../../graphicsEngine/WROIBox.h"
#include "../../graphicsEngine/WShader.h"
......@@ -38,8 +40,6 @@
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleInputData.h"
#include "WFiberDrawable.h"
/**
* Module for drawing fibers
*
......
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