Commit 115bef58 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[MERGE]

parents 700d7150 754fbec6
......@@ -88,7 +88,7 @@ public:
unsigned int getNumberOfDataSets() const;
protected:
private:
WPersonalInformation m_personalInfo; //<! Information on the person represented by this WSubject.
WPersonalInformation m_personalInfo; //!< Information on the person represented by this WSubject.
/**
* A container for all WDataSets belonging to the subject.
......
......@@ -141,7 +141,7 @@ std::string WShader::getIncludeFileName( std::string line )
}
if ( count < 2 )
{
WLogger::getLogger()->addLogMessage( "Missing quotes around file name in include statement of shader.", "Marching Cubes", LL_ERROR );
WLogger::getLogger()->addLogMessage( "Missing quotes around file name in include statement of shader.", "WShader", LL_ERROR );
// TODO(schurade): here we could throw an exception
return 0;
}
......
......@@ -102,7 +102,9 @@ public:
WIconManager* getIconManager();
/**
* Returns a pointer to a signal object which signals a list of filenames to load
*
* \return the signal
*/
boost::signals2::signal1< void, std::vector< std::string > >* getLoaderSignal();
......@@ -114,7 +116,9 @@ public:
boost::signals2::signal2< void, boost::shared_ptr< WModule >, boost::shared_ptr< WModule > >* getModuleButtonSignal();
/**
* Returns a point to a boost signal object which emits the coordinates of a mouseclick
*
* \return the signal
*/
boost::signals2::signal1< void, std::string >* getPickSignal();
......@@ -165,16 +169,17 @@ private:
*/
void setupCompatiblesToolBar();
WIconManager m_iconManager;
WIconManager m_iconManager; //!< manager to provide icons in the gui thread
WPropertyManager m_propertyManager;
WPropertyManager m_propertyManager; //!< transmit gui interactions to connected modules
QWidget* m_centralwidget; //!< the central widget of the docking facility. Thsi can not be moved.
WQtRibbonMenu* m_ribbonMenu; //!< The ribbon menu of the main window.
WQtRibbonMenu* m_compatiblesToolBar; //!< This toolbar shows the compatible modules if a module is selcted in the dataset browser
WQtDatasetBrowser* m_datasetBrowser;
WQtDatasetBrowser* m_datasetBrowser; //!< dataset browser
boost::shared_ptr<WQtGLWidget> m_mainGLWidget; //!< the main GL widget of the GUI
boost::shared_ptr< WQtNavGLWidget > m_navAxial; //!< the axial view widget GL widget of the GUI
......@@ -191,8 +196,11 @@ private:
*/
boost::mutex m_customDockWidgetsLock;
boost::signals2::signal1< void, std::vector< std::string > > m_loaderSignal;
boost::signals2::signal1< void, std::vector< std::string > > m_loaderSignal; //!< boost signal for open file dialog
/**
* boost signal object
*/
boost::signals2::signal2< void, boost::shared_ptr< WModule >, boost::shared_ptr< WModule > > m_moduleButtonSignal;
};
......
......@@ -63,7 +63,8 @@ WMMarchingCubes::WMMarchingCubes():
m_tIsoLevel( 0 ),
m_dataSet(),
m_shaderUseTexture( true ),
m_shaderUseLighting( false )
m_shaderUseLighting( false ),
m_shaderUseTransparency( false )
{
// WARNING: initializing connectors inside the constructor will lead to an exception.
// Implement WModule::initializeConnectors instead.
......@@ -82,7 +83,7 @@ boost::shared_ptr< WModule > WMMarchingCubes::factory() const
const std::string WMMarchingCubes::getName() const
{
return "Marching Cubes";
return "Isosurface";
}
const std::string WMMarchingCubes::getDescription() const
......@@ -129,6 +130,7 @@ void WMMarchingCubes::moduleMain()
// settings for normal isosurface
m_shaderUseLighting = true;
m_shaderUseTransparency = true;
renderSurface();
......@@ -160,6 +162,8 @@ void WMMarchingCubes::properties()
m_properties->addBool( "textureChanged", false, true );
m_properties->addBool( "active", true, true )->connect( boost::bind( &WMMarchingCubes::slotPropertyChanged, this, _1 ) );
m_properties->addDouble( "Iso Value", 100 )->connect( boost::bind( &WMMarchingCubes::slotPropertyChanged, this, _1 ) );
m_properties->addInt( "Opacity %", 100 )->connect( boost::bind( &WMMarchingCubes::slotPropertyChanged, this, _1 ) );
m_properties->setMax( "Opacity %", 100 );
m_properties->addBool( "Use Texture", true )->connect( boost::bind( &WMMarchingCubes::slotPropertyChanged, this, _1 ) );
}
......@@ -180,6 +184,11 @@ void WMMarchingCubes::slotPropertyChanged( std::string propertyName )
m_shaderUseTexture = m_properties->getValue< bool >( propertyName );
updateTextures();
}
else if( propertyName == "Opacity %" )
{
debugLog() << "Change opacity." << std::endl;
updateTextures();
}
else if( propertyName == "active" )
{
if ( m_properties->getValue<bool>( propertyName ) )
......@@ -662,6 +671,7 @@ void WMMarchingCubes::renderMesh( WTriangleMesh* mesh )
osg::ref_ptr<osg::LightModel> lightModel = new osg::LightModel();
lightModel->setTwoSided( true );
state->setAttributeAndModes( lightModel.get(), osg::StateAttribute::ON );
state->setMode( GL_BLEND, osg::StateAttribute::ON );
// ------------------------------------------------
// Shader stuff
......@@ -732,8 +742,23 @@ void WMMarchingCubes::renderMesh( WTriangleMesh* mesh )
state->addUniform( m_samplerUniforms[i] );
}
state->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useTexture", m_shaderUseTexture ) ) );
if( !m_shaderUseTexture )
{
state->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useTexture", m_properties->getValue< bool >( "Use Texture" ) ) ) );
}
else
{
state->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useTexture", true ) ) );
}
state->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useLighting", m_shaderUseLighting ) ) );
if( m_shaderUseTransparency )
{
state->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "opacity", m_properties->getValue< int >( "Opacity %" ) ) ) );
}
else
{
state->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "opacity", 100 ) ) );
}
std::vector< boost::shared_ptr< WDataSet > > dsl = WKernel::getRunningKernel()->getGui()->getDataSetList( 0, true );
if ( dsl.size() > 0 )
......@@ -988,16 +1013,32 @@ void WMMarchingCubes::updateTextures()
m_typeUniforms[i]->set( 0 );
}
osg::StateSet* rootState = m_geode->getOrCreateStateSet();
rootState->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useTexture", m_shaderUseTexture ) ) );
rootState->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useLighting", m_shaderUseLighting ) ) );
osg::StateSet* state = m_geode->getOrCreateStateSet();
if( !m_shaderUseTexture )
{
state->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useTexture", m_properties->getValue< bool >( "Use Texture" ) ) ) );
}
else
{
state->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useTexture", true ) ) );
}
state->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useLighting", m_shaderUseLighting ) ) );
if( m_shaderUseTransparency )
{
state->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "opacity", m_properties->getValue< int >( "Opacity %" ) ) ) );
}
else
{
state->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "opacity", 100 ) ) );
}
int c = 0;
for ( size_t i = 0; i < dsl.size(); ++i )
{
osg::ref_ptr<osg::Texture3D> texture3D = dsl[i]->getTexture()->getTexture();
rootState->setTextureAttributeAndModes( c, texture3D, osg::StateAttribute::ON );
state->setTextureAttributeAndModes( c, texture3D, osg::StateAttribute::ON );
float t = dsl[i]->getTexture()->getThreshold()/ 100.0;
float a = dsl[i]->getTexture()->getAlpha();
......
......@@ -258,6 +258,7 @@ private:
bool m_shaderUseTexture; //!< shall the shader use texturing?
bool m_shaderUseLighting; //!< shall the shader use lighting?
bool m_shaderUseTransparency; //!< shall the shader use transparency?
/**
* Lock to prevent concurrent threads trying to update the osg node
......
......@@ -2,6 +2,7 @@ varying vec4 VaryingTexCoord0;
uniform bool useLighting;
uniform bool useTexture;
uniform int opacity;
uniform sampler3D tex0;
uniform sampler3D tex1;
......@@ -14,6 +15,18 @@ uniform sampler3D tex7;
uniform sampler3D tex8;
uniform sampler3D tex9;
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 float threshold8;
uniform float threshold9;
uniform int type0;
uniform int type1;
uniform int type2;
......@@ -39,14 +52,21 @@ uniform float alpha9;
#include "colorMaps.fs"
#include "lighting.fs"
void lookupTex(inout vec4 col, in int type, in sampler3D tex, in vec3 v, in float alpha)
void lookupTex(inout vec4 col, in int type, in sampler3D tex, in float threshold, in vec3 v, in float alpha)
{
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 ( type == 16 && useColorMap != -1)
{
if (threshold < 1.0)
{
col1.r = (col1.r - threshold) / (1.0 - threshold);
}
colorMap(col1, col1.r);
}
......@@ -55,7 +75,7 @@ void lookupTex(inout vec4 col, in int type, in sampler3D tex, in vec3 v, in floa
void main()
{
vec4 col = vec4(0.3, 0.3, 0.3, 0.0);
vec4 col = vec4(0.3, 0.3, 0.3, 1.0);
vec4 ambient = vec4(0.0);
vec4 diffuse = vec4(0.0);
......@@ -66,27 +86,28 @@ void main()
if( useTexture )
{
if ( type9 > 0 ) lookupTex(col, type9, tex9, VaryingTexCoord0.xyz, alpha9);
if ( type8 > 0 ) lookupTex(col, type8, tex8, VaryingTexCoord0.xyz, alpha8);
if ( type7 > 0 ) lookupTex(col, type7, tex7, VaryingTexCoord0.xyz, alpha7);
if ( type6 > 0 ) lookupTex(col, type6, tex6, VaryingTexCoord0.xyz, alpha6);
if ( type5 > 0 ) lookupTex(col, type5, tex5, VaryingTexCoord0.xyz, alpha5);
if ( type4 > 0 ) lookupTex(col, type4, tex4, VaryingTexCoord0.xyz, alpha4);
if ( type3 > 0 ) lookupTex(col, type3, tex3, VaryingTexCoord0.xyz, alpha3);
if ( type2 > 0 ) lookupTex(col, type2, tex2, VaryingTexCoord0.xyz, alpha2);
if ( type1 > 0 ) lookupTex(col, type1, tex1, VaryingTexCoord0.xyz, alpha1);
if ( type0 > 0 ) lookupTex(col, type0, tex0, VaryingTexCoord0.xyz, alpha0);
if ( type9 > 0 ) lookupTex(col, type9, tex9, threshold9, VaryingTexCoord0.xyz, alpha9);
if ( type8 > 0 ) lookupTex(col, type8, tex8, threshold8, VaryingTexCoord0.xyz, alpha8);
if ( type7 > 0 ) lookupTex(col, type7, tex7, threshold7, VaryingTexCoord0.xyz, alpha7);
if ( type6 > 0 ) lookupTex(col, type6, tex6, threshold6, VaryingTexCoord0.xyz, alpha6);
if ( type5 > 0 ) lookupTex(col, type5, tex5, threshold5, VaryingTexCoord0.xyz, alpha5);
if ( type4 > 0 ) lookupTex(col, type4, tex4, threshold4, VaryingTexCoord0.xyz, alpha4);
if ( type3 > 0 ) lookupTex(col, type3, tex3, threshold3, VaryingTexCoord0.xyz, alpha3);
if ( type2 > 0 ) lookupTex(col, type2, tex2, threshold2, VaryingTexCoord0.xyz, alpha2);
if ( type1 > 0 ) lookupTex(col, type1, tex1, threshold1, VaryingTexCoord0.xyz, alpha1);
if ( type0 > 0 ) lookupTex(col, type0, tex0, threshold0, VaryingTexCoord0.xyz, alpha0);
}
if ( useLighting )
col = col + (ambient * col / 2.0) + (diffuse * col) + (specular * col / 2.0);
col = clamp(col, 0.0, 1.0);
col.a = sqrt( col.r * col.r + col.g * col.g + col.b * col.b);
//discard completely black voxels. So if no texture is active we will see nothing
if ( ( col.r + col.g + col.b ) < 0.01 )
discard;
col.a = opacity * .01;
gl_FragColor = col;
}
......@@ -369,20 +369,6 @@ void WMNavSlices::updateGeometry()
boost::shared_lock<boost::shared_mutex> slock;
slock = boost::shared_lock<boost::shared_mutex>( m_updateLock );
// std::vector< boost::shared_ptr< WModule > > datasetList = WKernel::getRunningKernel()->getGui()->getDataSetList( 0 );
// if ( datasetList.size() > 0 )
// {
// boost::shared_ptr< WDataSetSingle > ds = boost::shared_dynamic_cast< WDataSetSingle >( datasetList[0] );
// boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( ds->getGrid() );
//
// float mx = grid->getNbCoordsX() * grid->getOffsetX();
// float my = grid->getNbCoordsY() * grid->getOffsetY();
// float mz = grid->getNbCoordsZ() * grid->getOffsetZ();
//
// m_properties->setValue( "maxAxial", mx );
// m_properties->setValue( "maxCoronal", my );
// m_properties->setValue( "maxSagittal", mz );
// }
osg::ref_ptr<osg::Geometry> xSliceGeometry = createGeometry( 0 );
osg::ref_ptr<osg::Geometry> ySliceGeometry = createGeometry( 1 );
osg::ref_ptr<osg::Geometry> zSliceGeometry = createGeometry( 2 );
......@@ -394,7 +380,10 @@ void WMNavSlices::updateGeometry()
osg::ref_ptr<osg::Drawable> oldz = osg::ref_ptr<osg::Drawable>( m_zSliceNode->getDrawable( 0 ) );
m_zSliceNode->replaceDrawable( oldz, zSliceGeometry );
if ( m_properties->getValue<bool>( "showAxial" ) )
std::vector< boost::shared_ptr< WDataSet > > dsl = WKernel::getRunningKernel()->getGui()->getDataSetList( 0, true );
bool noTexture = ( dsl.size() == 0 );
if ( m_properties->getValue<bool>( "showAxial" ) && !noTexture )
{
m_zSliceNode->setNodeMask( 0xFFFFFFFF );
}
......@@ -403,7 +392,7 @@ void WMNavSlices::updateGeometry()
m_zSliceNode->setNodeMask( 0x0 );
}
if ( m_properties->getValue<bool>( "showCoronal" ) )
if ( m_properties->getValue<bool>( "showCoronal" ) && !noTexture )
{
m_xSliceNode->setNodeMask( 0xFFFFFFFF );
}
......@@ -412,7 +401,7 @@ void WMNavSlices::updateGeometry()
m_xSliceNode->setNodeMask( 0x0 );
}
if ( m_properties->getValue<bool>( "showSagittal" ) )
if ( m_properties->getValue<bool>( "showSagittal" ) && !noTexture )
{
m_ySliceNode->setNodeMask( 0xFFFFFFFF );
}
......
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