Commit f14d9b6b authored by schurade's avatar schurade

[ADD] fiber culling with a selection box tool

parent 099e89ce
...@@ -93,6 +93,8 @@ void WMFiberDisplay::moduleMain() ...@@ -93,6 +93,8 @@ void WMFiberDisplay::moduleMain()
m_moduleState.wait(); // waits for firing of m_moduleState ( dataChanged, shutdown, etc. ) m_moduleState.wait(); // waits for firing of m_moduleState ( dataChanged, shutdown, etc. )
initCullBox();
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
// what caused wait to return? // what caused wait to return?
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
...@@ -151,6 +153,32 @@ void WMFiberDisplay::update() ...@@ -151,6 +153,32 @@ void WMFiberDisplay::update()
m_osgNode->setNodeMask( 0xFFFFFFFF ); m_osgNode->setNodeMask( 0xFFFFFFFF );
} }
} }
if( !m_showCullBox->get() )
{
m_cullBox->setNodeMask( 0x0 );
}
else
{
m_cullBox->setNodeMask( 0xFFFFFFFF );
}
float xMin = m_cullBox->getMinPos()[0];
float yMin = m_cullBox->getMinPos()[1];
float zMin = m_cullBox->getMinPos()[2];
float xMax = m_cullBox->getMaxPos()[0];
float yMax = m_cullBox->getMaxPos()[1];
float zMax = m_cullBox->getMaxPos()[2];
m_uniformUseCullBox->set( m_activateCullBox->get() );
m_uniformInsideCullBox->set( m_insideCullBox->get() );
m_uniformCullBoxLBX->set( static_cast<float>( xMin ) );
m_uniformCullBoxLBY->set( static_cast<float>( yMin ) );
m_uniformCullBoxLBZ->set( static_cast<float>( zMin ) );
m_uniformCullBoxUBX->set( static_cast<float>( xMax ) );
m_uniformCullBoxUBY->set( static_cast<float>( yMax ) );
m_uniformCullBoxUBZ->set( static_cast<float>( zMax ) );
} }
void WMFiberDisplay::create() void WMFiberDisplay::create()
...@@ -237,9 +265,14 @@ void WMFiberDisplay::properties() ...@@ -237,9 +265,14 @@ void WMFiberDisplay::properties()
"Updates the output connector with the currently selected fibers", "Updates the output connector with the currently selected fibers",
WPVBaseTypes::PV_TRIGGER_READY, WPVBaseTypes::PV_TRIGGER_READY,
boost::bind( &WMFiberDisplay::updateOutput, this ) ); boost::bind( &WMFiberDisplay::updateOutput, this ) );
m_cullBoxGroup = m_properties->addPropertyGroup( "Box Culling", "Properties only related to the box culling." );
m_activateCullBox = m_cullBoxGroup->addProperty( "Activate", "activates the cull box", false );
m_showCullBox = m_cullBoxGroup->addProperty( "Show Cull Box", "shows/hides the cull box", false );
m_insideCullBox = m_cullBoxGroup->addProperty( "Inside - Outside", "show fibers inside or outside the cull box", true );
} }
void WMFiberDisplay::toggleTubes() void WMFiberDisplay::updateRenderModes()
{ {
osg::StateSet* rootState = m_osgNode->getOrCreateStateSet(); osg::StateSet* rootState = m_osgNode->getOrCreateStateSet();
...@@ -249,7 +282,7 @@ void WMFiberDisplay::toggleTubes() ...@@ -249,7 +282,7 @@ void WMFiberDisplay::toggleTubes()
updateTexture(); updateTexture();
} }
if( m_useTubesProp->changed() || m_useTextureProp->changed() ) if( m_useTubesProp->changed() || m_useTextureProp->changed() || m_activateCullBox->changed() )
{ {
if ( m_useTubesProp->get( true ) ) if ( m_useTubesProp->get( true ) )
{ {
...@@ -262,12 +295,13 @@ void WMFiberDisplay::toggleTubes() ...@@ -262,12 +295,13 @@ void WMFiberDisplay::toggleTubes()
rootState->addUniform( m_uniformTubeThickness ); rootState->addUniform( m_uniformTubeThickness );
rootState->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useTexture", m_useTextureProp->get() ) ) ); rootState->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useTexture", m_useTextureProp->get() ) ) );
} }
else if ( m_useTextureProp->get( true ) && !m_useTubesProp->get( true ) ) else if ( ( m_useTextureProp->get( true ) && !m_useTubesProp->get( true ) ) || m_activateCullBox->get( true) )
{ {
m_tubeDrawable->setUseTubes( false ); m_tubeDrawable->setUseTubes( false );
updateTexture(); updateTexture();
m_shaderTubes->deactivate( m_osgNode ); m_shaderTubes->deactivate( m_osgNode );
m_shaderTexturedFibers->apply( m_osgNode ); m_shaderTexturedFibers->apply( m_osgNode );
m_uniformUseTexture->set( m_useTextureProp->get() );
} }
else else
{ {
...@@ -376,6 +410,7 @@ void WMFiberDisplay::updateTexture() ...@@ -376,6 +410,7 @@ void WMFiberDisplay::updateTexture()
void WMFiberDisplay::initUniforms( osg::StateSet* rootState ) void WMFiberDisplay::initUniforms( osg::StateSet* rootState )
{ {
m_uniformUseTexture = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useTexture", false ) );
m_uniformSampler = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "tex", 0 ) ); m_uniformSampler = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "tex", 0 ) );
m_uniformType = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "type", 0 ) ); m_uniformType = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "type", 0 ) );
m_uniformThreshold = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "threshold", 0.0f ) ); m_uniformThreshold = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "threshold", 0.0f ) );
...@@ -385,6 +420,7 @@ void WMFiberDisplay::initUniforms( osg::StateSet* rootState ) ...@@ -385,6 +420,7 @@ void WMFiberDisplay::initUniforms( osg::StateSet* rootState )
m_uniformDimY = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "dimY", 1 ) ); m_uniformDimY = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "dimY", 1 ) );
m_uniformDimZ = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "dimZ", 1 ) ); m_uniformDimZ = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "dimZ", 1 ) );
rootState->addUniform( m_uniformUseTexture );
rootState->addUniform( m_uniformSampler ); rootState->addUniform( m_uniformSampler );
rootState->addUniform( m_uniformType ); rootState->addUniform( m_uniformType );
rootState->addUniform( m_uniformThreshold ); rootState->addUniform( m_uniformThreshold );
...@@ -393,9 +429,48 @@ void WMFiberDisplay::initUniforms( osg::StateSet* rootState ) ...@@ -393,9 +429,48 @@ void WMFiberDisplay::initUniforms( osg::StateSet* rootState )
rootState->addUniform( m_uniformDimX ); rootState->addUniform( m_uniformDimX );
rootState->addUniform( m_uniformDimY ); rootState->addUniform( m_uniformDimY );
rootState->addUniform( m_uniformDimZ ); rootState->addUniform( m_uniformDimZ );
// cull box info
float xMin = m_cullBox->getMinPos()[0];
float yMin = m_cullBox->getMinPos()[1];
float zMin = m_cullBox->getMinPos()[2];
float xMax = m_cullBox->getMaxPos()[0];
float yMax = m_cullBox->getMaxPos()[1];
float zMax = m_cullBox->getMaxPos()[2];
m_uniformUseCullBox = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useCullBox", false ) );
m_uniformInsideCullBox = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "insideCullBox", false ) );
m_uniformCullBoxLBX = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "cullBoxLBX", static_cast<float>( xMin ) ) );
m_uniformCullBoxLBY = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "cullBoxLBY", static_cast<float>( yMin ) ) );
m_uniformCullBoxLBZ = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "cullBoxLBZ", static_cast<float>( zMin ) ) );
m_uniformCullBoxUBX = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "cullBoxUBX", static_cast<float>( xMax ) ) );
m_uniformCullBoxUBY = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "cullBoxUBY", static_cast<float>( yMax ) ) );
m_uniformCullBoxUBZ = osg::ref_ptr<osg::Uniform>( new osg::Uniform( "cullBoxUBZ", static_cast<float>( zMax ) ) );
rootState->addUniform( m_uniformUseCullBox );
rootState->addUniform( m_uniformCullBoxLBX );
rootState->addUniform( m_uniformCullBoxLBY );
rootState->addUniform( m_uniformCullBoxLBZ );
rootState->addUniform( m_uniformCullBoxUBX );
rootState->addUniform( m_uniformCullBoxUBY );
rootState->addUniform( m_uniformCullBoxUBZ );
rootState->addUniform( m_uniformUseCullBox );
rootState->addUniform( m_uniformInsideCullBox );
} }
void WMFiberDisplay::notifyTextureChange() void WMFiberDisplay::notifyTextureChange()
{ {
m_textureChanged = true; m_textureChanged = true;
} }
void WMFiberDisplay::initCullBox()
{
wmath::WPosition crossHairPos = WKernel::getRunningKernel()->getSelectionManager()->getCrosshair()->getPosition();
wmath::WPosition minROIPos = crossHairPos - wmath::WPosition( 10., 10., 10. );
wmath::WPosition maxROIPos = crossHairPos + wmath::WPosition( 10., 10., 10. );
m_cullBox = osg::ref_ptr< WROIBox >( new WROIBox( minROIPos, maxROIPos ) );
m_cullBox->setColor( osg::Vec4( 1.0, 0., 1.0, 0.4 ) );
}
...@@ -31,13 +31,15 @@ ...@@ -31,13 +31,15 @@
#include "../../../dataHandler/datastructures/WFiberCluster.h" #include "../../../dataHandler/datastructures/WFiberCluster.h"
#include "../../../dataHandler/WDataSetFibers.h" #include "../../../dataHandler/WDataSetFibers.h"
#include "../../../graphicsEngine/WROI.h"
#include "../../../graphicsEngine/WROIBox.h"
#include "../../../graphicsEngine/WShader.h" #include "../../../graphicsEngine/WShader.h"
#include "../../WModule.h" #include "../../WModule.h"
#include "../../WModuleInputData.h" #include "../../WModuleInputData.h"
#include "WTubeDrawable.h" #include "WTubeDrawable.h"
/** /**
* Test module for drawing fibers * Module for drawing fibers
* *
* \ingroup modules * \ingroup modules
*/ */
...@@ -142,6 +144,11 @@ private: ...@@ -142,6 +144,11 @@ private:
WBoolFlag m_noData; //!< Flag indicating whether there is data to display. WBoolFlag m_noData; //!< Flag indicating whether there is data to display.
WPropGroup m_cullBoxGroup; //!< property group for box culling
WPropBool m_activateCullBox; //!< if true fibers are culled depending on a cull box
WPropBool m_showCullBox; //!< Enable/Disable showing of the cull box
WPropBool m_insideCullBox; //!< if true fibers inside the cull box are shown, outside if false
/** /**
* Input connector for a fiber dataset. * Input connector for a fiber dataset.
*/ */
...@@ -190,6 +197,11 @@ private: ...@@ -190,6 +197,11 @@ private:
*/ */
bool m_textureChanged; bool m_textureChanged;
/**
* boolean to notify the shader to use the texture instead of glColor
*/
osg::ref_ptr<osg::Uniform> m_uniformUseTexture;
/** /**
* uniform for type of texture * uniform for type of texture
*/ */
...@@ -214,15 +226,30 @@ private: ...@@ -214,15 +226,30 @@ private:
osg::ref_ptr<osg::Uniform> m_uniformDimY; //!< y dimension of the dataset for calculating the texture coord in the shader osg::ref_ptr<osg::Uniform> m_uniformDimY; //!< y dimension of the dataset for calculating the texture coord in the shader
osg::ref_ptr<osg::Uniform> m_uniformDimZ; //!< z dimension of the dataset for calculating the texture coord in the shader osg::ref_ptr<osg::Uniform> m_uniformDimZ; //!< z dimension of the dataset for calculating the texture coord in the shader
osg::ref_ptr<osg::Uniform> m_uniformUseCullBox; //!< notify shader that cull box is activated
osg::ref_ptr<osg::Uniform> m_uniformInsideCullBox; //!< notify shader that fibers insider or outside cull box are shown
osg::ref_ptr<osg::Uniform> m_uniformCullBoxLBX; //!< cull box lower bound
osg::ref_ptr<osg::Uniform> m_uniformCullBoxLBY; //!< cull box lower bound
osg::ref_ptr<osg::Uniform> m_uniformCullBoxLBZ; //!< cull box lower bound
osg::ref_ptr<osg::Uniform> m_uniformCullBoxUBX; //!< cull box upper bound
osg::ref_ptr<osg::Uniform> m_uniformCullBoxUBY; //!< cull box upper bound
osg::ref_ptr<osg::Uniform> m_uniformCullBoxUBZ; //!< cull box upper bound
/** /**
* To avoid multiple instances of the fiber display. * To avoid multiple instances of the fiber display.
*/ */
static bool m_fiberDisplayRunning; static bool m_fiberDisplayRunning;
osg::ref_ptr< WROIBox > m_cullBox; //!< stores a pointer to the cull box
/** /**
* switches between fiber display and tube representation * switches between fiber display and tube representation,
* texturing and box culling
* activates the neccesary shaders
*/ */
void toggleTubes(); void updateRenderModes();
/** /**
* Enable disable global or local coloring * Enable disable global or local coloring
...@@ -250,6 +277,12 @@ private: ...@@ -250,6 +277,12 @@ private:
*/ */
void updateTexture(); void updateTexture();
/**
* create a selection box to cull the fibers
*/
void initCullBox();
/** /**
* Node callback to handle updates properly * Node callback to handle updates properly
*/ */
...@@ -269,7 +302,7 @@ private: ...@@ -269,7 +302,7 @@ private:
if ( module ) if ( module )
{ {
module->update(); module->update();
module->toggleTubes(); module->updateRenderModes();
module->toggleColoring(); module->toggleColoring();
} }
traverse( node, nv ); traverse( node, nv );
......
varying vec4 myColor; varying vec4 myColor;
varying vec4 VaryingTexCoord0; varying vec4 VaryingTexCoord0;
uniform int dimX, dimY, dimZ; uniform int dimX, dimY, dimZ;
uniform sampler3D tex; uniform sampler3D tex;
...@@ -9,6 +8,16 @@ uniform int type; ...@@ -9,6 +8,16 @@ uniform int type;
uniform float threshold; uniform float threshold;
uniform int cMap; uniform int cMap;
uniform bool useTexture;
uniform bool useCullBox;
uniform bool insideCullBox;
uniform float cullBoxLBX;
uniform float cullBoxLBY;
uniform float cullBoxLBZ;
uniform float cullBoxUBX;
uniform float cullBoxUBY;
uniform float cullBoxUBZ;
#include "WGEColorMaps.glsl" #include "WGEColorMaps.glsl"
#include "WGEUtils.glsl" #include "WGEUtils.glsl"
...@@ -31,19 +40,43 @@ float lookupTex() ...@@ -31,19 +40,43 @@ float lookupTex()
return col1.r; return col1.r;
} }
void checkCullBox()
{
vec3 pos = VaryingTexCoord0.xyz;
if ( insideCullBox )
{
if ( pos.x < cullBoxLBX || pos.x > cullBoxUBX )
discard;
if ( pos.y < cullBoxLBY || pos.y > cullBoxUBY )
discard;
if ( pos.z < cullBoxLBZ || pos.z > cullBoxUBZ )
discard;
}
else
{
if ( ( pos.x > cullBoxLBX && pos.x < cullBoxUBX ) && ( pos.y > cullBoxLBY && pos.y < cullBoxUBY ) && ( pos.z > cullBoxLBZ && pos.z < cullBoxUBZ ) )
discard;
}
}
/* /*
* simple fragment shader that uses a texture on fibers * simple fragment shader that uses a texture on fibers
*/ */
void main() void main()
{ {
vec4 color = vec4( 1.0 ); if ( useCullBox )
checkCullBox();
float value = lookupTex();
colorMap(color.rgb, value, cMap ); vec4 color = myColor;
color.a = 1.0; if ( useTexture )
{
float value = lookupTex();
colorMap(color.rgb, value, cMap );
color.a = 1.0;
}
gl_FragColor = color; gl_FragColor = color;
} }
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