Commit a76ab82f authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[FIX #65] - ugly black borders now also removed for interpolated textures

parent 03da07f4
...@@ -213,7 +213,8 @@ osg::ref_ptr< osg::Image > WDataTexture3D::createTexture( T* source, int compone ...@@ -213,7 +213,8 @@ osg::ref_ptr< osg::Image > WDataTexture3D::createTexture( T* source, int compone
for( unsigned int i = 0; i < nbVoxels; ++i ) for( unsigned int i = 0; i < nbVoxels; ++i )
{ {
data[ 2 * i ] = WDataTexture3DScalers::scaleInterval( source[i], min, max, scaler ); data[ 2 * i ] = WDataTexture3DScalers::scaleInterval( source[i], min, max, scaler );
data[ ( 2 * i ) + 1] = source[i] != min; // NOTE: this is done to avoid ugly black borders when interpolation is active.
data[ ( 2 * i ) + 1] = wge::GLType< T >::FullIntensity() * ( source[i] != min );
} }
} }
else if( components == 2) else if( components == 2)
...@@ -228,8 +229,8 @@ osg::ref_ptr< osg::Image > WDataTexture3D::createTexture( T* source, int compone ...@@ -228,8 +229,8 @@ osg::ref_ptr< osg::Image > WDataTexture3D::createTexture( T* source, int compone
{ {
data[ ( 4 * i ) ] = WDataTexture3DScalers::scaleInterval( source[ ( 2 * i ) ], min, max, scaler ); data[ ( 4 * i ) ] = WDataTexture3DScalers::scaleInterval( source[ ( 2 * i ) ], min, max, scaler );
data[ ( 4 * i ) + 1 ] = WDataTexture3DScalers::scaleInterval( source[ ( 2 * i ) + 1 ], min, max, scaler ); data[ ( 4 * i ) + 1 ] = WDataTexture3DScalers::scaleInterval( source[ ( 2 * i ) + 1 ], min, max, scaler );
data[ ( 4 * i ) + 2 ] = 0.0; data[ ( 4 * i ) + 2 ] = 0;
data[ ( 4 * i ) + 3 ] = 1.0; data[ ( 4 * i ) + 3 ] = wge::GLType< T >::FullIntensity();
} }
} }
else if( components == 3) else if( components == 3)
...@@ -245,7 +246,7 @@ osg::ref_ptr< osg::Image > WDataTexture3D::createTexture( T* source, int compone ...@@ -245,7 +246,7 @@ osg::ref_ptr< osg::Image > WDataTexture3D::createTexture( T* source, int compone
data[ ( 4 * i ) ] = WDataTexture3DScalers::scaleInterval( source[ ( 3 * i ) ], min, max, scaler ); data[ ( 4 * i ) ] = WDataTexture3DScalers::scaleInterval( source[ ( 3 * i ) ], min, max, scaler );
data[ ( 4 * i ) + 1 ] = WDataTexture3DScalers::scaleInterval( source[ ( 3 * i ) + 1 ], min, max, scaler ); data[ ( 4 * i ) + 1 ] = WDataTexture3DScalers::scaleInterval( source[ ( 3 * i ) + 1 ], min, max, scaler );
data[ ( 4 * i ) + 2 ] = WDataTexture3DScalers::scaleInterval( source[ ( 3 * i ) + 2 ], min, max, scaler ); data[ ( 4 * i ) + 2 ] = WDataTexture3DScalers::scaleInterval( source[ ( 3 * i ) + 2 ], min, max, scaler );
data[ ( 4 * i ) + 3 ] = 1.0; data[ ( 4 * i ) + 3 ] = wge::GLType< T >::FullIntensity();
} }
} }
else if( components == 4) else if( components == 4)
......
...@@ -67,6 +67,13 @@ namespace wge ...@@ -67,6 +67,13 @@ namespace wge
* The enum type of OpenGL * The enum type of OpenGL
*/ */
static const GLenum TypeEnum = GL_FLOAT; static const GLenum TypeEnum = GL_FLOAT;
/**
* The value for full intensity.
*
* \return the full intensity value
*/
static Type FullIntensity(){ return 1.0; } // NOLINT
}; };
/** /**
...@@ -85,6 +92,13 @@ namespace wge ...@@ -85,6 +92,13 @@ namespace wge
* The enum type of OpenGL * The enum type of OpenGL
*/ */
static const GLenum TypeEnum = GL_FLOAT; static const GLenum TypeEnum = GL_FLOAT;
/**
* The value for full intensity.
*
* \return the full intensity value
*/
static Type FullIntensity(){ return 1.0; } // NOLINT
}; };
/** /**
...@@ -103,6 +117,13 @@ namespace wge ...@@ -103,6 +117,13 @@ namespace wge
* The enum type of OpenGL * The enum type of OpenGL
*/ */
static const GLenum TypeEnum = GL_BYTE; static const GLenum TypeEnum = GL_BYTE;
/**
* The value for full intensity.
*
* \return the full intensity value
*/
static Type FullIntensity(){ return 127; } // NOLINT
}; };
/** /**
...@@ -121,6 +142,13 @@ namespace wge ...@@ -121,6 +142,13 @@ namespace wge
* The enum type of OpenGL * The enum type of OpenGL
*/ */
static const GLenum TypeEnum = GL_UNSIGNED_BYTE; static const GLenum TypeEnum = GL_UNSIGNED_BYTE;
/**
* The value for full intensity.
*
* \return the full intensity value
*/
static Type FullIntensity(){ return 255; } // NOLINT
}; };
/** /**
...@@ -141,6 +169,13 @@ namespace wge ...@@ -141,6 +169,13 @@ namespace wge
* The enum type of OpenGL * The enum type of OpenGL
*/ */
static const GLenum TypeEnum = GL_FLOAT; static const GLenum TypeEnum = GL_FLOAT;
/**
* The value for full intensity.
*
* \return the full intensity value
*/
static Type FullIntensity(){ return 1.0; } // NOLINT
}; };
/** /**
...@@ -161,6 +196,13 @@ namespace wge ...@@ -161,6 +196,13 @@ namespace wge
* The enum type of OpenGL * The enum type of OpenGL
*/ */
static const GLenum TypeEnum = GL_FLOAT; static const GLenum TypeEnum = GL_FLOAT;
/**
* The value for full intensity.
*
* \return the full intensity value
*/
static Type FullIntensity(){ return 1.0; } // NOLINT
}; };
/** /**
...@@ -181,6 +223,13 @@ namespace wge ...@@ -181,6 +223,13 @@ namespace wge
* The enum type of OpenGL * The enum type of OpenGL
*/ */
static const GLenum TypeEnum = GL_FLOAT; static const GLenum TypeEnum = GL_FLOAT;
/**
* The value for full intensity.
*
* \return the full intensity value
*/
static Type FullIntensity(){ return 1.0; } // NOLINT
}; };
/** /**
...@@ -201,6 +250,13 @@ namespace wge ...@@ -201,6 +250,13 @@ namespace wge
* The enum type of OpenGL * The enum type of OpenGL
*/ */
static const GLenum TypeEnum = GL_FLOAT; static const GLenum TypeEnum = GL_FLOAT;
/**
* The value for full intensity.
*
* \return the full intensity value
*/
static Type FullIntensity(){ return 1.0; } // NOLINT
}; };
} }
......
...@@ -427,7 +427,7 @@ vec4 atlas( in float value ) ...@@ -427,7 +427,7 @@ vec4 atlas( in float value )
* This method applies a colormap to the specified value an mixes it with the specified color. It uses the proper colormap and works on scaled * This method applies a colormap to the specified value an mixes it with the specified color. It uses the proper colormap and works on scaled
* values. * values.
* *
* \param color this color gets mixed using alpha value with the new colormap color * \return this color gets mixed using alpha value with the new colormap color
* \param value the value to map, <b>scaled</b> * \param value the value to map, <b>scaled</b>
* \param minV the minimum of the original value * \param minV the minimum of the original value
* \param scaleV the scaler used to downscale the original value to [0-1] * \param scaleV the scaler used to downscale the original value to [0-1]
...@@ -436,13 +436,14 @@ vec4 atlas( in float value ) ...@@ -436,13 +436,14 @@ vec4 atlas( in float value )
* \param alpha the alpha blending value * \param alpha the alpha blending value
* \param colormap the colormap index to use * \param colormap the colormap index to use
*/ */
vec4 colormap( in vec3 value, float minV, float scaleV, float thresholdV, bool thresholdEnabled, float alpha, int colormap, bool active ) vec4 colormap( in vec4 value, float minV, float scaleV, float thresholdV, bool thresholdEnabled, float alpha, int colormap, bool active )
{ {
// descale value // descale value
vec3 valueDescaled = vec3( minV ) + ( value * scaleV ); vec3 valueDescaled = vec3( minV ) + ( value.rgb * scaleV );
float isNotBorder = float( value.a >= 0.75 );
// this is the final color returned by the colormapping algorithm. This is the correct value for the gray colormap // this is the final color returned by the colormapping algorithm. This is the correct value for the gray colormap
vec4 cmapped = grayscale( value ); vec4 cmapped = grayscale( value.rgb );
float clip = clipZero( valueDescaled.r, minV ); float clip = clipZero( valueDescaled.r, minV );
// negative to positive shading in red-blue // negative to positive shading in red-blue
...@@ -474,6 +475,7 @@ vec4 colormap( in vec3 value, float minV, float scaleV, float thresholdV, bool t ...@@ -474,6 +475,7 @@ vec4 colormap( in vec3 value, float minV, float scaleV, float thresholdV, bool t
// build final color // build final color
return vec4( cmapped.rgb, cmapped.a * // did the colormap use a alpha value? return vec4( cmapped.rgb, cmapped.a * // did the colormap use a alpha value?
isNotBorder * // is this a border pixel?
alpha * // did the user specified an alpha? alpha * // did the user specified an alpha?
clip * // value clip? clip * // value clip?
clipThreshold( valueDescaled, colormap, thresholdV, thresholdEnabled ) * // clip due to threshold? clipThreshold( valueDescaled, colormap, thresholdV, thresholdEnabled ) * // clip due to threshold?
......
...@@ -49,7 +49,7 @@ void colormap( inout vec4 color, in sampler3D sampler, in vec3 coord, float minV ...@@ -49,7 +49,7 @@ void colormap( inout vec4 color, in sampler3D sampler, in vec3 coord, float minV
int cmap, bool active ) int cmap, bool active )
{ {
// get the value and descale it // get the value and descale it
vec3 value = texture3D( sampler, coord ).rgb; vec4 value = texture3D( sampler, coord ).rgba;
// let someone else apply the colormap // let someone else apply the colormap
vec4 src = colormap( value, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, active ); vec4 src = colormap( value, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, active );
......
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