Commit 679a1b8e authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[FIX] adapted spline surface to new collormapping to make it compile again

parent d47a38de
......@@ -29,7 +29,7 @@ ADD_SUBDIRECTORY( probTractDisplay )
ADD_SUBDIRECTORY( probTractDisplaySP )
ADD_SUBDIRECTORY( scalarOperator )
ADD_SUBDIRECTORY( scalarSegmentation )
# ADD_SUBDIRECTORY( splineSurface )
ADD_SUBDIRECTORY( splineSurface )
ADD_SUBDIRECTORY( subtractDataSetScalar )
ADD_SUBDIRECTORY( surfaceParameterAnimator )
ADD_SUBDIRECTORY( vectorOperator )
......
......@@ -49,8 +49,9 @@
#include "../../common/math/WLinearAlgebraFunctions.h"
#include "../../dataHandler/WDataHandler.h"
#include "../../dataHandler/WSubject.h"
#include "../../dataHandler/WDataTexture3D.h"
#include "../../graphicsEngine/WGEColormapping.h"
#include "../../graphicsEngine/WGEUtils.h"
#include "../../graphicsEngine/shaders/WGEShaderPropertyDefineOptions.h"
#include "../../kernel/WKernel.h"
#include "../../graphicsEngine/algorithms/WMarchingCubesAlgorithm.h"
......@@ -61,7 +62,7 @@
W_LOADABLE_MODULE( WMSplineSurface )
WMSplineSurface::WMSplineSurface() :
WModule(), m_recompute( boost::shared_ptr< WCondition >( new WCondition() ) ), m_shaderUseLighting( false ), m_shaderUseTransparency( false ),
WModule(), m_recompute( boost::shared_ptr< WCondition >( new WCondition() ) ),
m_moduleNode( new WGEGroupNode() ), m_surfaceGeode( 0 )
{
// WARNING: initializing connectors inside the constructor will lead to an exception.
......@@ -91,7 +92,7 @@ const std::string WMSplineSurface::getName() const
const std::string WMSplineSurface::getDescription() const
{
return "This module implements the marching cubes"
return "<font color=\"#0000ff\"><b>[Unfinished Status]</b></font> This module implements the marching cubes"
" algorithm with a consistent triangulation. It allows to compute isosurfaces"
" for a given isovalue on data given on a grid only consisting of cubes. It yields"
" the surface as triangle soup.";
......@@ -106,10 +107,6 @@ void WMSplineSurface::moduleMain()
// signal ready state
ready();
// now, to watch changing/new textures use WSubject's change condition
boost::signals2::connection con = WDataHandler::getDefaultSubject()->getChangeCondition()->subscribeSignal( boost::bind(
&WMSplineSurface::notifyTextureChange, this ) );
// loop until the module container requests the module to quit
while ( !m_shutdownFlag() )
{
......@@ -144,10 +141,6 @@ void WMSplineSurface::moduleMain()
debugLog() << "Rendering surface ...";
// settings for normal isosurface
m_shaderUseLighting = true;
m_shaderUseTransparency = true;
renderMesh();
m_output->updateData( m_triMesh );
......@@ -158,8 +151,6 @@ void WMSplineSurface::moduleMain()
m_moduleState.wait();
}
con.disconnect();
WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getScene()->remove( m_moduleNode );
}
......@@ -186,7 +177,7 @@ void WMSplineSurface::properties()
m_opacityProp->setMin( 0 );
m_opacityProp->setMax( 100 );
m_useTextureProp = m_properties->addProperty( "Use texture", "Use texturing of the surface?", false );
m_useTextureProp = m_properties->addProperty( "Use texture", "Use texturing of the surface?", true );
m_surfaceColor = m_properties->addProperty( "Surface color", "Description.", WColor( 0.5, 0.5, 0.5, 1.0 ) );
......@@ -243,99 +234,15 @@ void WMSplineSurface::renderMesh()
state->setAttributeAndModes( lightModel.get(), osg::StateAttribute::ON );
state->setMode( GL_BLEND, osg::StateAttribute::ON );
{
osg::ref_ptr< osg::Material > material = new osg::Material();
material->setDiffuse( osg::Material::FRONT_AND_BACK, osg::Vec4( 1.0, 1.0, 1.0, 1.0 ) );
material->setSpecular( osg::Material::FRONT_AND_BACK, osg::Vec4( 0.0, 0.0, 0.0, 1.0 ) );
material->setAmbient( osg::Material::FRONT_AND_BACK, osg::Vec4( 0.1, 0.1, 0.1, 1.0 ) );
material->setEmission( osg::Material::FRONT_AND_BACK, osg::Vec4( 0.0, 0.0, 0.0, 1.0 ) );
material->setShininess( osg::Material::FRONT_AND_BACK, 25.0 );
state->setAttribute( material );
}
osg::ref_ptr< WGEShader > shader = osg::ref_ptr< WGEShader >( new WGEShader( "WMSplineSurface", m_localPath ) );
shader->addPreprocessor( WGEShaderPreprocessor::SPtr(
new WGEShaderPropertyDefineOptions< WPropBool >( m_useTextureProp, "COLORMAPPING_DISABLED", "COLORMAPPING_ENABLED" ) )
);
state->addUniform( new WGEPropertyUniform< WPropInt >( "u_opacity", m_opacityProp ) );
shader->apply( m_surfaceGeode );
// ------------------------------------------------
// Shader stuff
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 )
{
state->addUniform( m_typeUniforms[i] );
state->addUniform( m_thresholdUniforms[i] );
state->addUniform( m_alphaUniforms[i] );
state->addUniform( m_samplerUniforms[i] );
state->addUniform( m_cmapUniforms[i] );
}
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_opacityProp->get( true ) ) ) );
}
else
{
state->addUniform( osg::ref_ptr< osg::Uniform >( new osg::Uniform( "opacity", 100 ) ) );
}
// NOTE: the following code should not be necessary. The update callback does this job just before the mesh is rendered
// initially. Just set the texture changed flag to true. If this however might be needed use WSubject::getDataTextures.
m_textureChanged = true;
m_shader = osg::ref_ptr< WGEShader >( new WGEShader( "surface", m_localPath ) );
m_shader->apply( m_surfaceGeode );
// Colormapping
WGEColormapping::apply( m_surfaceGeode, shader );
m_moduleNode->insert( m_surfaceGeode );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( m_moduleNode );
......@@ -343,11 +250,6 @@ void WMSplineSurface::renderMesh()
m_moduleNode->addUpdateCallback( new SplineSurfaceNodeCallback( this ) );
}
void WMSplineSurface::notifyTextureChange()
{
m_textureChanged = true;
}
bool WMSplineSurface::save() const
{
// m_saveTriggerProp->set( WPVBaseTypes::PV_TRIGGER_READY, false );
......@@ -441,79 +343,4 @@ void WMSplineSurface::updateGraphics()
surfaceGeometry->setColorArray( colors );
surfaceGeometry->setColorBinding( osg::Geometry::BIND_OVERALL );
}
if ( m_textureChanged || m_opacityProp->changed() || m_useTextureProp->changed() )
{
bool localTextureChangedFlag = m_textureChanged;
m_textureChanged = false;
m_opacityProp->get( true );
m_useTextureProp->get( true );
// { 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 )
{
osg::StateSet* rootState = m_surfaceGeode->getOrCreateStateSet();
// reset all uniforms
for ( size_t i = 0; i < wlimits::MAX_NUMBER_OF_TEXTURES; ++i )
{
m_typeUniforms[i]->set( 0 );
}
rootState->addUniform( osg::ref_ptr< osg::Uniform >( new osg::Uniform( "useTexture", m_useTextureProp->get( true ) ) ) );
rootState->addUniform( osg::ref_ptr< osg::Uniform >( new osg::Uniform( "useLighting", m_shaderUseLighting ) ) );
if ( m_shaderUseTransparency )
{
rootState->addUniform( osg::ref_ptr< osg::Uniform >( new osg::Uniform( "opacity", m_opacityProp->get( true ) ) ) );
}
else
{
rootState->addUniform( osg::ref_ptr< osg::Uniform >( new osg::Uniform( "opacity", 100 ) ) );
}
// for each texture -> apply
size_t c = 0;
for ( std::vector< boost::shared_ptr< WDataTexture3D > >::const_iterator iter = tex.begin(); iter != tex.end(); ++iter )
{
if ( localTextureChangedFlag )
{
osg::ref_ptr< osg::Geometry > surfaceGeometry = m_surfaceGeode->getDrawable( 0 )->asGeometry();
osg::Vec3Array* texCoords = new osg::Vec3Array;
boost::shared_ptr< WGridRegular3D > grid = ( *iter )->getGrid();
for ( size_t i = 0; i < m_triMesh->vertSize(); ++i )
{
osg::Vec3 vertPos = m_triMesh->getVertex( i );
texCoords->push_back( grid->worldCoordToTexCoord( WPosition( vertPos[0], vertPos[1], vertPos[2] ) ) );
}
surfaceGeometry->setTexCoordArray( c, texCoords );
}
osg::ref_ptr< osg::Texture3D > texture3D = ( *iter )->getTexture();
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;
}
}
}
// }
}
}
......@@ -108,12 +108,6 @@ protected:
virtual void properties();
private:
/**
* Used as callback which simply sets m_textureChanged to true. Called by WSubject whenever the datasets change.
*/
void notifyTextureChange();
/**
* Prepares and commits everything for rendering with the OSG
*/
......@@ -132,11 +126,6 @@ private:
WPropTrigger m_saveTriggerProp; //!< This property triggers the actual writing,
WPropFilename m_meshFile; //!< The mesh will be written to this file.
/**
* True when textures have changed.
*/
bool m_textureChanged;
/**
* This condition denotes whether we need to recompute the surface
*/
......@@ -147,23 +136,9 @@ private:
boost::shared_ptr< WTriangleMesh > m_triMesh; //!< This triangle mesh is provided as output through the connector.
bool m_shaderUseLighting; //!< shall the shader use lighting?
bool m_shaderUseTransparency; //!< shall the shader use transparency?
osg::ref_ptr< WGEGroupNode > m_moduleNode; //!< Pointer to the modules group node. We need it to be able to update it when callback is invoked.
osg::ref_ptr< osg::Geode > m_surfaceGeode; //!< Pointer to geode containing the surface.
/**
* The shader used for the iso surface in m_geode
*/
osg::ref_ptr< WGEShader > m_shader;
std::vector< osg::ref_ptr< osg::Uniform > > m_typeUniforms; //!< uniforms for ...... ? for shader
std::vector< osg::ref_ptr< osg::Uniform > > m_alphaUniforms; //!< uniforms for opacities of textures in shader
std::vector< osg::ref_ptr< osg::Uniform > > m_thresholdUniforms; //!< uniforms for thresholds of textures in shader
std::vector< osg::ref_ptr< osg::Uniform > > m_samplerUniforms; //!< uniforms for ids of textures in shader
std::vector< osg::ref_ptr< osg::Uniform > > m_cmapUniforms; //!< uniforms for color maps per texture in shader
};
/**
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// 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.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#version 120
#include "WGEColormapping-fragment.glsl"
#include "WGEShadingTools.glsl"
// opacity in percent
uniform int u_opacity;
// The surface normal
varying vec3 v_normal;
void main()
{
vec4 col = gl_Color;
#ifdef COLORMAPPING_ENABLED
col = colormapping();
#endif
// do light
float light = blinnPhongIlluminationIntensity( normalize( -v_normal ) );
// opacity of the surface
//col.rgb = light * col.rgb; // TODO(wiebel): reenable lighting here
col.a = float( u_opacity ) * 0.01;
gl_FragColor = col;
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// 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.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#version 120
#include "WGEColormapping-vertex.glsl"
// The surface normal
varying vec3 v_normal;
void main()
{
// prepare colormapping
colormapping();
// prepare light
v_normal = gl_NormalMatrix * gl_Normal;
gl_FrontColor = gl_Color;
gl_Position = ftransform();
}
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