Commit 203507e1 by Alexander Wiebel

[FIX #298] implement more useful finders for min/max for textures

parent c31919a5
......@@ -110,6 +110,8 @@ osg::ref_ptr< osg::Texture3D > WDataTexture3D::getTexture()
osg::ref_ptr< osg::Image > WDataTexture3D::createTexture3D( unsigned char* source, int components )
{
findMinMax( source, components );
osg::ref_ptr< osg::Image > ima = new osg::Image;
if ( components == 1 )
......@@ -145,6 +147,8 @@ osg::ref_ptr< osg::Image > WDataTexture3D::createTexture3D( unsigned char* sourc
osg::ref_ptr< osg::Image > WDataTexture3D::createTexture3D( int16_t* source, int components )
{
findMinMax( source, components );
osg::ref_ptr< osg::Image > ima = new osg::Image;
if( components == 1 )
{
......@@ -354,6 +358,50 @@ void WDataTexture3D::findMinMax( double* source, int components )
wlog::debug( "WDataTexture3D" ) << "Calculating min/max values for dataset: done! Values are in [" << m_minValue << "," << m_maxValue << "].";
}
void WDataTexture3D::findMinMax( unsigned char* source, int components )
{
wlog::debug( "WDataTexture3D" ) << "Calculating min/max values for dataset.";
double minV = source[ 0 ];
double maxV = source[ 0 ];
// Go through each value and find min/max
for ( unsigned int i = 0; i < components * m_grid->getNbCoordsX() * m_grid->getNbCoordsY() * m_grid->getNbCoordsZ(); ++i )
{
double val = source[ i ];
minV = val < minV ? val : minV;
maxV = val > maxV ? val : maxV;
}
m_scale = static_cast< float >( maxV - minV );
m_minValue = static_cast< float >( minV );
m_maxValue = static_cast< float >( maxV );
wlog::debug( "WDataTexture3D" ) << "Calculating min/max values for dataset: done! Values are in [" << m_minValue << "," << m_maxValue << "].";
}
void WDataTexture3D::findMinMax( int16_t* source, int components )
{
wlog::debug( "WDataTexture3D" ) << "Calculating min/max values for dataset.";
double minV = source[ 0 ];
double maxV = source[ 0 ];
// Go through each value and find min/max
for ( unsigned int i = 0; i < components * m_grid->getNbCoordsX() * m_grid->getNbCoordsY() * m_grid->getNbCoordsZ(); ++i )
{
double val = source[ i ];
minV = val < minV ? val : minV;
maxV = val > maxV ? val : maxV;
}
m_scale = static_cast< float >( maxV - minV );
m_minValue = static_cast< float >( minV );
m_maxValue = static_cast< float >( maxV );
wlog::debug( "WDataTexture3D" ) << "Calculating min/max values for dataset: done! Values are in [" << m_minValue << "," << m_maxValue << "].";
}
void WDataTexture3D::findMinMax( float* source, int components )
{
wlog::debug( "WDataTexture3D" ) << "Calculating min/max values for dataset.";
......
......@@ -300,6 +300,22 @@ protected:
virtual void findMinMax( double* source, int components );
/**
* This method finds the minimum and maximum value of a dataset. These values get used to scale the texture to use the maximum precision.
*
* \param source the data
* \param components the number of components
*/
virtual void findMinMax( unsigned char* source, int components );
/**
* This method finds the minimum and maximum value of a dataset. These values get used to scale the texture to use the maximum precision.
*
* \param source the data
* \param components the number of components
*/
virtual void findMinMax( int16_t* source, int components );
/**
* The smallest value inside the dataset
*/
float m_minValue;
......
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