Commit 92f79e56 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[FIX] - arbitraryPlane now uses new colormapping

parent a01ba694
......@@ -29,12 +29,13 @@
#include "../../dataHandler/WDataSet.h"
#include "../../dataHandler/WDataSetScalar.h"
#include "../../dataHandler/WDataSetSingle.h"
#include "../../dataHandler/WDataTexture3D.h"
#include "../../dataHandler/WGridRegular3D.h"
#include "../../dataHandler/WSubject.h"
#include "../../dataHandler/WValueSet.h"
#include "../../graphicsEngine/shaders/WGEShader.h"
#include "../../graphicsEngine/WGEUtils.h"
#include "../../graphicsEngine/WGEColormapping.h"
#include "../../graphicsEngine/shaders/WGEPropertyUniform.h"
#include "../../kernel/WKernel.h"
#include "../../kernel/WSelectionManager.h"
#include "WMArbitraryPlane.h"
......@@ -45,8 +46,7 @@ W_LOADABLE_MODULE( WMArbitraryPlane )
WMArbitraryPlane::WMArbitraryPlane():
WModule(),
m_dirty( false ),
m_textureChanged( true )
m_dirty( false )
{
// initialize members
}
......@@ -106,24 +106,10 @@ void WMArbitraryPlane::properties()
void WMArbitraryPlane::moduleMain()
{
m_shader = osg::ref_ptr< WGEShader > ( new WGEShader( "WMArbitraryPlane", m_localPath ) );
initPlane();
updatePlane();
osg::StateSet* rootState = m_rootNode->getOrCreateStateSet();
initUniforms( rootState );
updateTextures();
m_shader->apply( m_rootNode );
boost::signals2::connection con = WDataHandler::getDefaultSubject()->getChangeCondition()->subscribeSignal(
boost::bind( &WMArbitraryPlane::notifyTextureChange, this ) );
ready();
m_moduleState.setResetable( true, true );
......@@ -218,8 +204,6 @@ void WMArbitraryPlane::moduleMain()
m_s1->removeROIChangeNotifier( m_changeRoiSignal );
m_s2->removeROIChangeNotifier( m_changeRoiSignal );
con.disconnect();
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->remove( m_rootNode );
}
......@@ -229,8 +213,22 @@ void WMArbitraryPlane::initPlane()
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( m_rootNode );
m_geode = new osg::Geode();
m_geode->setName( "_arbitraryPlane" );
m_rootNode->insert( m_geode );
// create shader
m_shader = osg::ref_ptr< WGEShader > ( new WGEShader( "WMArbitraryPlane", m_localPath ) );
m_shader->apply( m_rootNode );
// Apply colormapping
WGEColormapping::apply( m_geode, m_shader );
// bind some uniforms with properties
m_geode->getOrCreateStateSet()->addUniform( new WGEPropertyUniform< WPropBool >( "u_showComplete", m_showComplete ) );
// we need transparency
m_geode->getOrCreateStateSet()->setMode( GL_BLEND, osg::StateAttribute::ON );
m_geode->getOrCreateStateSet()->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
m_rootNode->insert( m_geode );
m_rootNode->addUpdateCallback( new WGEFunctorCallback< osg::Node >( boost::bind( &WMArbitraryPlane::updateCallback, this ) ) );
WPosition center = WKernel::getRunningKernel()->getSelectionManager()->getCrosshair()->getPosition();
......@@ -297,42 +295,6 @@ void WMArbitraryPlane::updatePlane()
quad->push_back( 0 );
planeGeometry->addPrimitiveSet( quad );
// { TODO(all): this is deprecated.
// grab a list of data textures
std::vector< boost::shared_ptr< WDataTexture3D > > tex = WDataHandler::getDefaultSubject()->getDataTextures( true );
int c = 0;
//////////////////////////////////////////////////////////////////////////////////////////////////
if ( WKernel::getRunningKernel()->getSelectionManager()->getUseTexture() )
{
boost::shared_ptr< WGridRegular3D > grid = WKernel::getRunningKernel()->getSelectionManager()->getGrid();
osg::Vec3Array* texCoords = new osg::Vec3Array;
texCoords->push_back( grid->worldCoordToTexCoord( v0 ) );
texCoords->push_back( grid->worldCoordToTexCoord( v1 ) );
texCoords->push_back( grid->worldCoordToTexCoord( v2 ) );
texCoords->push_back( grid->worldCoordToTexCoord( v3 ) );
planeGeometry->setTexCoordArray( c, texCoords );
++c;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
for ( std::vector< boost::shared_ptr< WDataTexture3D > >::const_iterator iter = tex.begin(); iter != tex.end(); ++iter )
{
boost::shared_ptr< WGridRegular3D > grid = ( *iter )->getGrid();
osg::Vec3Array* texCoords = new osg::Vec3Array;
texCoords->push_back( grid->worldCoordToTexCoord( v0 ) );
texCoords->push_back( grid->worldCoordToTexCoord( v1 ) );
texCoords->push_back( grid->worldCoordToTexCoord( v2 ) );
texCoords->push_back( grid->worldCoordToTexCoord( v3 ) );
planeGeometry->setTexCoordArray( c, texCoords );
++c;
}
// }
m_geode->addDrawable( planeGeometry );
m_dirty = false;
......@@ -350,7 +312,6 @@ void WMArbitraryPlane::updateCallback()
if ( isDirty() )
{
updatePlane();
updateTextures();
}
}
......@@ -364,165 +325,6 @@ bool WMArbitraryPlane::isDirty()
return m_dirty;
}
void WMArbitraryPlane::notifyTextureChange()
{
m_textureChanged = true;
m_dirty = true;
}
void WMArbitraryPlane::updateTextures()
{
osg::StateSet* rootState = m_rootNode->getOrCreateStateSet();
if ( m_textureChanged )
{
m_textureChanged = false;
// { TODO(all): this is deprecated.
// grab a list of data textures
std::vector< boost::shared_ptr< WDataTexture3D > > tex = WDataHandler::getDefaultSubject()->getDataTextures( true );
if ( tex.size() > 0 )
{
// reset all uniforms
for ( size_t i = 0; i < wlimits::MAX_NUMBER_OF_TEXTURES; ++i )
{
m_typeUniforms[i]->set( 0 );
}
// for each texture -> apply
size_t c = 0;
//////////////////////////////////////////////////////////////////////////////////////////////////
if ( WKernel::getRunningKernel()->getSelectionManager()->getUseTexture() )
{
osg::ref_ptr<osg::Texture3D> texture3D = WKernel::getRunningKernel()->getSelectionManager()->getTexture();
m_typeUniforms[c]->set( W_DT_UNSIGNED_CHAR );
m_thresholdUniforms[c]->set( 0.0f );
m_alphaUniforms[c]->set( WKernel::getRunningKernel()->getSelectionManager()->getTextureOpacity() );
m_cmapUniforms[c]->set( 4 );
texture3D->setFilter( osg::Texture::MIN_FILTER, osg::Texture::NEAREST );
texture3D->setFilter( osg::Texture::MAG_FILTER, osg::Texture::NEAREST );
rootState->setTextureAttributeAndModes( c, texture3D, osg::StateAttribute::ON );
++c;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
for ( std::vector< boost::shared_ptr< WDataTexture3D > >::const_iterator iter = tex.begin(); iter != tex.end(); ++iter )
{
osg::ref_ptr<osg::Texture3D> texture3D = ( *iter )->getTexture();
if ( ( *iter )->isInterpolated() )
{
texture3D->setFilter( osg::Texture::MIN_FILTER, osg::Texture::LINEAR );
texture3D->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );
}
else
{
texture3D->setFilter( osg::Texture::MIN_FILTER, osg::Texture::NEAREST );
texture3D->setFilter( osg::Texture::MAG_FILTER, osg::Texture::NEAREST );
}
rootState->setTextureAttributeAndModes( c, texture3D, osg::StateAttribute::ON );
// set threshold/opacity as uniforms
float minValue = ( *iter )->getMinValue();
float maxValue = ( *iter )->getMaxValue();
float t = ( ( *iter )->getThreshold() - minValue ) / ( maxValue - minValue ); // rescale to [0,1]
float a = ( *iter )->getAlpha();
int cmap = ( *iter )->getSelectedColormap();
m_typeUniforms[c]->set( ( *iter )->getDataType() );
m_thresholdUniforms[c]->set( t );
m_alphaUniforms[c]->set( a );
m_cmapUniforms[c]->set( cmap );
++c;
if( c == wlimits::MAX_NUMBER_OF_TEXTURES )
{
break;
}
}
}
// }
}
m_showCompleteUniform->set( m_showComplete->get() );
}
void WMArbitraryPlane::initUniforms( osg::StateSet* rootState )
{
m_typeUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "type0", 0 ) ) );
m_typeUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "type1", 0 ) ) );
m_typeUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "type2", 0 ) ) );
m_typeUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "type3", 0 ) ) );
m_typeUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "type4", 0 ) ) );
m_typeUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "type5", 0 ) ) );
m_typeUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "type6", 0 ) ) );
m_typeUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "type7", 0 ) ) );
m_typeUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "type8", 0 ) ) );
m_typeUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "type9", 0 ) ) );
m_alphaUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "alpha0", 1.0f ) ) );
m_alphaUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "alpha1", 1.0f ) ) );
m_alphaUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "alpha2", 1.0f ) ) );
m_alphaUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "alpha3", 1.0f ) ) );
m_alphaUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "alpha4", 1.0f ) ) );
m_alphaUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "alpha5", 1.0f ) ) );
m_alphaUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "alpha6", 1.0f ) ) );
m_alphaUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "alpha7", 1.0f ) ) );
m_alphaUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "alpha8", 1.0f ) ) );
m_alphaUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "alpha9", 1.0f ) ) );
m_thresholdUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "threshold0", 0.0f ) ) );
m_thresholdUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "threshold1", 0.0f ) ) );
m_thresholdUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "threshold2", 0.0f ) ) );
m_thresholdUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "threshold3", 0.0f ) ) );
m_thresholdUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "threshold4", 0.0f ) ) );
m_thresholdUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "threshold5", 0.0f ) ) );
m_thresholdUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "threshold6", 0.0f ) ) );
m_thresholdUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "threshold7", 0.0f ) ) );
m_thresholdUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "threshold8", 0.0f ) ) );
m_thresholdUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "threshold9", 0.0f ) ) );
m_samplerUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "tex0", 0 ) ) );
m_samplerUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "tex1", 1 ) ) );
m_samplerUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "tex2", 2 ) ) );
m_samplerUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "tex3", 3 ) ) );
m_samplerUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "tex4", 4 ) ) );
m_samplerUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "tex5", 5 ) ) );
m_samplerUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "tex6", 6 ) ) );
m_samplerUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "tex7", 7 ) ) );
m_samplerUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "tex8", 8 ) ) );
m_samplerUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "tex9", 9 ) ) );
m_cmapUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useCmap0", 0 ) ) );
m_cmapUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useCmap1", 0 ) ) );
m_cmapUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useCmap2", 0 ) ) );
m_cmapUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useCmap3", 0 ) ) );
m_cmapUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useCmap4", 0 ) ) );
m_cmapUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useCmap5", 0 ) ) );
m_cmapUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useCmap6", 0 ) ) );
m_cmapUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useCmap7", 0 ) ) );
m_cmapUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useCmap8", 0 ) ) );
m_cmapUniforms.push_back( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useCmap9", 0 ) ) );
for ( size_t i = 0; i < wlimits::MAX_NUMBER_OF_TEXTURES; ++i )
{
rootState->addUniform( m_typeUniforms[i] );
rootState->addUniform( m_thresholdUniforms[i] );
rootState->addUniform( m_alphaUniforms[i] );
rootState->addUniform( m_samplerUniforms[i] );
rootState->addUniform( m_cmapUniforms[i] );
}
m_showCompleteUniform = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "showComplete", 0 ) );
rootState->addUniform( m_showCompleteUniform );
}
WPosition WMArbitraryPlane::getCenterPosition()
{
return m_s0->getPosition();
......
......@@ -125,22 +125,6 @@ protected:
*/
bool isDirty();
/**
* updates textures and shader parameters
*/
void updateTextures();
/**
* creates and initializes the uniform parameters for the shader
* \param rootState The uniforms will be applied to this state.
*/
void initUniforms( osg::StateSet* rootState );
/**
* Used as callback which simply sets m_textureChanged to true. Called by WSubject whenever the datasets change.
*/
void notifyTextureChange();
/**
* getter for the position of the center manipulator
*
......@@ -216,41 +200,11 @@ private:
bool m_dirty; //!< dirty flag, used when manipulator positions change
/**
* True when textures have changed.
*/
bool m_textureChanged;
/**
* the shader object for this module
*/
osg::ref_ptr< WGEShader > m_shader;
/**
* vector of uniforms for type of texture
*/
std::vector< osg::ref_ptr<osg::Uniform> > m_typeUniforms;
/**
* vector of alpha values per texture
*/
std::vector< osg::ref_ptr<osg::Uniform> > m_alphaUniforms;
/**
* vector of thresholds per texture
*/
std::vector< osg::ref_ptr<osg::Uniform> > m_thresholdUniforms;
/**
* vector of color maps per texture
*/
std::vector< osg::ref_ptr<osg::Uniform> > m_cmapUniforms;
/**
* vector of samplers
*/
std::vector< osg::ref_ptr<osg::Uniform> > m_samplerUniforms;
osg::ref_ptr<osg::Uniform> m_showCompleteUniform; //!< Determines whether the slice should be drawn completely
boost::shared_ptr< boost::function< void() > > m_changeRoiSignal; //!< Signal that can be used to update the plane
......
......@@ -22,118 +22,22 @@
//
//---------------------------------------------------------------------------
varying vec4 VaryingTexCoord0;
varying vec4 VaryingTexCoord1;
varying vec4 VaryingTexCoord2;
varying vec4 VaryingTexCoord3;
varying vec4 VaryingTexCoord4;
varying vec4 VaryingTexCoord5;
varying vec4 VaryingTexCoord6;
varying vec4 VaryingTexCoord7;
#version 120
uniform sampler3D tex0;
uniform sampler3D tex1;
uniform sampler3D tex2;
uniform sampler3D tex3;
uniform sampler3D tex4;
uniform sampler3D tex5;
uniform sampler3D tex6;
uniform sampler3D tex7;
#include "WGEColormapping-fragment.glsl"
uniform float threshold0;
uniform float threshold1;
uniform float threshold2;
uniform float threshold3;
uniform float threshold4;
uniform float threshold5;
uniform float threshold6;
uniform float threshold7;
uniform int type0;
uniform int type1;
uniform int type2;
uniform int type3;
uniform int type4;
uniform int type5;
uniform int type6;
uniform int type7;
uniform float alpha0;
uniform float alpha1;
uniform float alpha2;
uniform float alpha3;
uniform float alpha4;
uniform float alpha5;
uniform float alpha6;
uniform float alpha7;
uniform int useCmap0;
uniform int useCmap1;
uniform int useCmap2;
uniform int useCmap3;
uniform int useCmap4;
uniform int useCmap5;
uniform int useCmap6;
uniform int useCmap7;
uniform bool highlighted;
uniform bool showComplete;
#include "WGEColorMaps.glsl"
void lookupTex( inout vec4 col, in int type, in sampler3D tex, in float threshold, in vec3 v, in float alpha, in int cmap )
{
vec3 col1 = vec3( 0.0 );
col1 = clamp( texture3D( tex, v ).rgb, 0.0, 1.0 );
if( ( col1.r + col1.g + col1.b ) / 3.0 - threshold <= 0.0 ) return;
if( cmap != 0 )
{
if( threshold < 1.0 )
{
col1.r = ( col1.r - threshold ) / ( 1.0 - threshold );
if( ( col1.r + col1.g + col1.b ) / 3.0 - threshold <= 0.0 ) return;
}
colorMap( col1, col1.r, cmap );
}
col.rgb = mix( col.rgb, col1.rgb, alpha );
}
// If this uniform is true, the plane should not discard fragments
uniform bool u_showComplete;
void main()
{
vec4 col = vec4( 0.0, 0.0, 0.0, 1.0 );
if ( type7 > 0 ) lookupTex( col, type7, tex7, threshold7, VaryingTexCoord7.xyz, alpha7, useCmap7 );
if ( type6 > 0 ) lookupTex( col, type6, tex6, threshold6, VaryingTexCoord6.xyz, alpha6, useCmap6 );
if ( type5 > 0 ) lookupTex( col, type5, tex5, threshold5, VaryingTexCoord5.xyz, alpha5, useCmap5 );
if ( type4 > 0 ) lookupTex( col, type4, tex4, threshold4, VaryingTexCoord4.xyz, alpha4, useCmap4 );
if ( type3 > 0 ) lookupTex( col, type3, tex3, threshold3, VaryingTexCoord3.xyz, alpha3, useCmap3 );
if ( type2 > 0 ) lookupTex( col, type2, tex2, threshold2, VaryingTexCoord2.xyz, alpha2, useCmap2 );
if ( type1 > 0 ) lookupTex( col, type1, tex1, threshold1, VaryingTexCoord1.xyz, alpha1, useCmap1 );
if ( type0 > 0 ) lookupTex( col, type0, tex0, threshold0, VaryingTexCoord0.xyz, alpha0, useCmap0 );
col = clamp( col, 0.0, 1.0 );
vec4 cmap = colormapping();
if ( ( col.r + col.g + col.b ) < 0.01 )
{
if( highlighted )
{
// higlight picked slice in the areas where ther are zero (very small) values
col = vec4( .7, .7, 1, 1 );
}
else
{
if ( !showComplete )
discard;
}
}
// remove transparency?
float removeTransparency = float( u_showComplete );
cmap.a = ( ( 1.0 - removeTransparency ) * cmap.a ) + removeTransparency;
gl_FragColor = col;
// opacity of the surface
gl_FragColor = cmap;
}
......@@ -2,7 +2,7 @@
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-CBS
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
......@@ -22,25 +22,14 @@
//
//---------------------------------------------------------------------------
varying vec4 VaryingTexCoord0;
varying vec4 VaryingTexCoord1;
varying vec4 VaryingTexCoord2;
varying vec4 VaryingTexCoord3;
varying vec4 VaryingTexCoord4;
varying vec4 VaryingTexCoord5;
varying vec4 VaryingTexCoord6;
varying vec4 VaryingTexCoord7;
#version 120
#include "WGEColormapping-vertex.glsl"
void main()
{
VaryingTexCoord0 = gl_MultiTexCoord0;
VaryingTexCoord1 = gl_MultiTexCoord1;
VaryingTexCoord2 = gl_MultiTexCoord2;
VaryingTexCoord3 = gl_MultiTexCoord3;
VaryingTexCoord4 = gl_MultiTexCoord4;
VaryingTexCoord5 = gl_MultiTexCoord5;
VaryingTexCoord6 = gl_MultiTexCoord6;
VaryingTexCoord7 = gl_MultiTexCoord7;
// prepare colormapping
colormapping();
gl_Position = ftransform();
}
ADD_SUBDIRECTORY( applyMask )
# ADD_SUBDIRECTORY( arbitraryPlane )
ADD_SUBDIRECTORY( arbitraryPlane )
ADD_SUBDIRECTORY( atlasCreator )
ADD_SUBDIRECTORY( atlasSurfaces )
ADD_SUBDIRECTORY( calculateGFA )
......
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