Commit 8bef783e authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[MERGE]

parents b6030a2f 3c2dc3c9
......@@ -95,7 +95,7 @@ osg::ref_ptr< osg::Vec3Array > wge::generateCuboidQuadNormals( const std::vector
return vertices;
}
WTriangleMesh wge::triangulate( const std::vector< wmath::WPosition >& points )
WTriangleMesh wge::triangulate( const std::vector< wmath::WPosition >& points, double transformationFactor )
{
WTriangleMesh mesh;
mesh.setVertices( points );
......@@ -104,6 +104,25 @@ WTriangleMesh wge::triangulate( const std::vector< wmath::WPosition >& points )
{
osg::ref_ptr< osg::Vec3Array > osgPoints = wge::osgVec3Array( points );
if( transformationFactor != 0.0 )
{
// Transform the points as described in the Doxygen description of
// this function.
osg::Vec3 centroid;
for( std::size_t pointID = 0; pointID < osgPoints->size(); ++pointID )
{
centroid += (*osgPoints)[pointID];
}
centroid /= osgPoints->size();
for( std::size_t pointID = 0; pointID < osgPoints->size(); ++pointID )
{
const double factor = ( (*osgPoints)[pointID].z() - centroid.z() ) * transformationFactor + 1.0;
(*osgPoints)[pointID].x() = ( (*osgPoints)[pointID].x() - centroid.x() ) * factor + centroid.x();
(*osgPoints)[pointID].y() = ( (*osgPoints)[pointID].y() - centroid.y() ) * factor + centroid.y();
}
}
// The osg triangulator sorts the points and returns the triangles with
// the indizes of the sorted points. Since we don't want to change the
// sequence of the points, we have to save the original index of each
......
......@@ -105,12 +105,25 @@ namespace wge
osg::ref_ptr< osg::Vec3Array > generateCuboidQuadNormals( const std::vector< wmath::WPosition >& corners );
/**
* Calculate the Delaunay Triangulatation of the given points.
* Calculate the Delaunay Triangulation of the given points.
*
* \param points vector of the points to triangulate
* If the parameter transformationFactor is not zero, the points will be
* transformed to calcule the triangles to get a better triangulation, but
* the returned mesh will consist of the original points.
* Every point which lies above the centroid of all points will be put away
* from this centroid by transformationFactor * height above the centroid.
* Any point below the centroid will be drawn to the centroid because its
* height is negative. This effect is inverted with a negative
* transformationFactor.
* This transformation is used to calculate the head surface between several
* electrodes, were a transformationFactor of -0.005 is reasonable.
*
* \param points vector of the points to triangulate
* \param transformationFactor magnitude of the transformation before the
* triangulation
* \return triangulation as WTriangleMesh
*/
WTriangleMesh triangulate( const std::vector< wmath::WPosition >& points );
WTriangleMesh triangulate( const std::vector< wmath::WPosition >& points, double transformationFactor = 0.0 );
}
#endif // WGEGEOMETRYUTILS_H
......@@ -608,7 +608,7 @@ osg::ref_ptr< osg::Node > WMEEGView::drawHeadSurface()
const std::size_t nbPositions = positions.size();
WTriangleMesh mesh = wge::triangulate( positions );
WTriangleMesh mesh = wge::triangulate( positions, -0.005 );
osg::ref_ptr< osg::Geometry > geometry = wge::convertToOsgGeometry( &mesh, true );
osg::Vec4Array* colors = new osg::Vec4Array;
......
......@@ -751,12 +751,24 @@ void WMMarchingCubes::renderMesh( boost::shared_ptr< WTriangleMesh2 > mesh )
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 ( int i = 0; i < 10; ++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] );
}
// TODO(wiebel): used? Not used? Replace by new Property please
......@@ -1038,10 +1050,12 @@ void WMMarchingCubes::updateTextures()
// set threshold/opacity as uniforms
float t = ( *iter )->getThreshold() / 255.0;
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;
}
......
......@@ -313,6 +313,7 @@ private:
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
};
/**
......
varying vec4 VaryingTexCoord0;
varying vec4 VaryingTexCoord1;
varying vec4 VaryingTexCoord2;
varying vec4 VaryingTexCoord3;
varying vec4 VaryingTexCoord4;
varying vec4 VaryingTexCoord5;
varying vec4 VaryingTexCoord6;
varying vec4 VaryingTexCoord7;
varying vec4 VaryingTexCoord8;
varying vec4 VaryingTexCoord9;
uniform bool useLighting;
uniform bool useTexture;
......@@ -49,25 +58,37 @@ uniform float alpha7;
uniform float alpha8;
uniform float alpha9;
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 int useCmap8;
uniform int useCmap9;
#include "colorMaps.fs"
#include "lighting.fs"
void lookupTex(inout vec4 col, in int type, in sampler3D tex, in float threshold, 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, 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( ( col1.r + col1.g + col1.b ) / 3.0 - threshold <= 0.0) return;
if ( type == 16 && useColorMap != -1)
if( cmap != 0 )
{
if (threshold < 1.0)
{
col1.r = (col1.r - threshold) / (1.0 - threshold);
}
colorMap(col1, col1.r, useColorMap );
colorMap(col1, col1.r, cmap );
}
col.rgb = mix( col.rgb, col1.rgb, alpha);
......@@ -86,16 +107,16 @@ void main()
if( useTexture )
{
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 ( type9 > 0 ) lookupTex(col, type9, tex9, threshold9, VaryingTexCoord9.xyz, alpha9, useCmap9);
if ( type8 > 0 ) lookupTex(col, type8, tex8, threshold8, VaryingTexCoord8.xyz, alpha8, useCmap8);
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);
}
if ( useLighting )
col = col + (ambient * col / 2.0) + (diffuse * col) + (specular * col / 2.0);
......
......@@ -263,7 +263,7 @@ private:
std::vector< osg::ref_ptr<osg::Uniform> > m_thresholdUniforms;
/**
* vector of thresholds per texture
* vector of color maps per texture
*/
std::vector< osg::ref_ptr<osg::Uniform> > m_cmapUniforms;
......
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