Commit e8db3f86 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] minor performance issue fixed

parent 3fe95a1e
......@@ -108,15 +108,24 @@ boost::shared_ptr< WGEColormapping > WGEColormapping::instance()
void WGEColormapping::apply( osg::ref_ptr< osg::Node > node, osg::ref_ptr< WGEShader > shader, size_t startTexUnit )
{
instance()->applyInst( node, WMatrix4d( WMatrix4d::identity() ), shader, startTexUnit );
instance()->applyInst( NodeList( 1, node ), WMatrix4d( WMatrix4d::identity() ), shader, startTexUnit );
}
void WGEColormapping::apply( osg::ref_ptr< osg::Node > node, WMatrix4d preTransform, osg::ref_ptr< WGEShader > shader,
size_t startTexUnit )
{
instance()->applyInst( node, preTransform, shader, startTexUnit );
instance()->applyInst( NodeList( 1, node ), preTransform, shader, startTexUnit );
}
void WGEColormapping::apply( NodeList nodes, WMatrix4d preTransform, osg::ref_ptr< WGEShader > shader, size_t startTexUnit )
{
instance()->applyInst( nodes, preTransform, shader, startTexUnit );
}
void WGEColormapping::apply( NodeList nodes, osg::ref_ptr< WGEShader > shader, size_t startTexUnit )
{
instance()->applyInst( nodes, WMatrix4d( WMatrix4d::identity() ), shader, startTexUnit );
}
void WGEColormapping::registerTexture( osg::ref_ptr< WGETexture3D > texture, std::string name )
{
......@@ -133,32 +142,33 @@ void WGEColormapping::replaceTexture( osg::ref_ptr< WGETexture3D > old, osg::ref
instance()->replaceTextureInst( old, newTex, name );
}
void WGEColormapping::applyInst( osg::ref_ptr< osg::Node > node, WMatrix4d preTransform, osg::ref_ptr< WGEShader > shader,
void WGEColormapping::applyInst( NodeList nodes, WMatrix4d preTransform, osg::ref_ptr< WGEShader > shader,
size_t startTexUnit )
{
// applying to a node simply means adding a callback :-)
NodeInfo* info = new NodeInfo;
info->m_rebind = true;
info->m_texUnitStart = startTexUnit;
info->m_preTransform = preTransform;
m_nodeInfo.insert( std::make_pair( node, info ) );
node->addUpdateCallback( m_callback );
// add the default shader if no other shader has been specified.
if( !shader )
// init shader
osg::ref_ptr< WGEShader > s = shader;
if( !s )
{
// we use a new instance of the default shader here because the preTransform is varying between several nodes.
osg::ref_ptr< WGEShader > s = new WGEShader( "WGEDefaultColormapper" );
setDefines( s, 0 );
setPreTransform( s, preTransform );
s->apply( node );
s = new WGEShader( "WGEDefaultColormapper" );
}
else
setDefines( s, startTexUnit );
setPreTransform( s, preTransform );
// do this for each node
for( NodeList::const_iterator i = nodes.begin(); i != nodes.end(); ++i )
{
setDefines( shader, startTexUnit );
setPreTransform( shader, preTransform );
shader->apply( node );
// applying to a node simply means adding a callback :-)
NodeInfo* info = new NodeInfo;
info->m_rebind = true;
info->m_texUnitStart = startTexUnit;
info->m_preTransform = preTransform;
m_nodeInfo.insert( std::make_pair( *i, info ) );
( *i )->addUpdateCallback( m_callback );
// add the default shader if no other shader has been specified.
s->apply( *i );
}
}
......
......@@ -102,6 +102,11 @@ public:
*/
static boost::shared_ptr< WGEColormapping > instance();
/**
* a bunch of nodes.
*/
typedef std::vector< osg::ref_ptr< osg::Node > > NodeList;
/**
* Apply the colormapping to the specified node.
*
......@@ -115,6 +120,19 @@ public:
static void apply( osg::ref_ptr< osg::Node > node, WMatrix4d preTransform = WMatrix4d::identity(),
osg::ref_ptr< WGEShader > shader = osg::ref_ptr< WGEShader >(), size_t startTexUnit = 0 );
/**
* Apply the colormapping to a list of nodes using the same shader.
*
* \param nodes the node-list.
* \param shader the shader to use for colormapping. Provide your own shader here to let WGEColormap set some defines needed. If not
* specified, a default shader is used.
* \param preTransform Transformation matrix getting applied to your texture coordinates before applying texture matrices. This allows you to
* specify any kind of texture coordinates as long as you use this matrix to transform them to the right space.
* \param startTexUnit the first texture unit allowed to be used
*/
static void apply( NodeList nodes, WMatrix4d preTransform = WMatrix4d::identity(),
osg::ref_ptr< WGEShader > shader = osg::ref_ptr< WGEShader >(), size_t startTexUnit = 0 );
/**
* Apply the colormapping to the specified node.
*
......@@ -125,6 +143,17 @@ public:
*/
static void apply( osg::ref_ptr< osg::Node > node, osg::ref_ptr< WGEShader > shader = osg::ref_ptr< WGEShader >(), size_t startTexUnit = 0 );
/**
* Apply the colormapping to a list of nodes which all use the same shader.
*
* \param nodes the node list.
* \param shader the shader to use for colormapping. Provide your own shader here to let WGEColormap set some defines needed. If not
* specified, a default shader is used.
* \param startTexUnit the first texture unit allowed to be used
*/
static void apply( NodeList nodes,
osg::ref_ptr< WGEShader > shader = osg::ref_ptr< WGEShader >(), size_t startTexUnit = 0 );
/**
* Register the specified texture to the colormapper. The registered texture is the automatically applied to all users of WGEColormapping.
* The texture gets inserted at the beginning of the texture list.
......@@ -257,16 +286,16 @@ protected:
WGEColormapping();
/**
* Apply the colormapping to the specified node.
* Apply the colormapping to the specified nodes.
*
* \param node the node.
* \param nodes the nodes.
* \param preTransform Transformation matrix getting applied to your texture coordinates before applying texture matrices. This allows you to
* specify any kind of texture coordinates as long as you use this matrix to transform them to the right space.
* \param shader the shader to use for colormapping. Provide your own shader here to let WGEColormap set some defines needed. If not
* specified, a default shader is used.
* \param startTexUnit the first texture unit allowed to be used
*/
void applyInst( osg::ref_ptr< osg::Node > node, WMatrix4d preTransform = WMatrix4d::identity(),
void applyInst( NodeList nodes, WMatrix4d preTransform = WMatrix4d::identity(),
osg::ref_ptr< WGEShader > shader = osg::ref_ptr< WGEShader >(), size_t startTexUnit = 0 );
/**
......
......@@ -247,7 +247,6 @@ void WMNavigationSlices::initOSG()
///////////////////////////////////////////////////////////////////////////////////////////////
osg::ref_ptr< osg::StateSet > state = m_output->getOrCreateStateSet();
state->setMode( GL_BLEND, osg::StateAttribute::ON );
state->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
// we want some nice animations: add timer
......@@ -266,9 +265,9 @@ void WMNavigationSlices::initOSG()
m_output->insert( mZ );
m_output->dirtyBound();
m_axialOutput->insert( m_output );
m_sagittalOutput->insert( m_output );
m_coronalOutput->insert( m_output );
m_axialOutput->insert( mZ );
m_sagittalOutput->insert( mX );
m_coronalOutput->insert( mY );
}
WMNavigationSlices::PickCallback::PickCallback( osg::ref_ptr< osg::Node > node, WPropDouble property, bool negateDirection ):
......@@ -326,10 +325,6 @@ void WMNavigationSlices::moduleMain()
// create the root node for all the geometry
m_output = osg::ref_ptr< WGEManagedGroupNode > ( new WGEManagedGroupNode( m_active ) );
m_output->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
// apply colormapping to transformation
osg::ref_ptr< WGEShader > shader = new WGEShader( "WMNavigationSlices", m_localPath );
WGEColormapping::apply( m_output, shader ); // this automatically applies the shader
// create the roots for the nav-views
m_sagittalOutput = osg::ref_ptr< WGEGroupNode > ( new WGEGroupNode() );
......@@ -341,6 +336,20 @@ void WMNavigationSlices::moduleMain()
WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "Coronal View" )->getScene()->insert( m_coronalOutput );
WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "Sagittal View" )->getScene()->insert( m_sagittalOutput );
m_output->getOrCreateStateSet()->setMode( GL_BLEND, osg::StateAttribute::ON );
m_axialOutput->getOrCreateStateSet()->setMode( GL_BLEND, osg::StateAttribute::ON );
m_sagittalOutput->getOrCreateStateSet()->setMode( GL_BLEND, osg::StateAttribute::ON );
m_coronalOutput->getOrCreateStateSet()->setMode( GL_BLEND, osg::StateAttribute::ON );
// apply colormapping to all the nodes
osg::ref_ptr< WGEShader > shader = new WGEShader( "WMNavigationSlices", m_localPath );
WGEColormapping::NodeList nodes;
nodes.push_back( m_output );
nodes.push_back( m_axialOutput );
nodes.push_back( m_sagittalOutput );
nodes.push_back( m_coronalOutput );
WGEColormapping::apply( nodes, shader ); // this automatically applies the shader
// we need to be informed if the bounding box of the volume containing all the data changes.
m_moduleState.add( WGEColormapping::instance()->getChangeCondition() );
......
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