Commit 1ea58f7c authored by schurade's avatar schurade
Browse files

[CHANGE] cleaned up the texture generation a bit

parent 1ea8e12f
......@@ -33,7 +33,7 @@ WDataTexture3D::WDataTexture3D( boost::shared_ptr<WValueSetBase> valueSet, boost
m_threshold( 0.0 ),
m_texture( osg::ref_ptr< osg::Texture3D >() ),
m_valueSet( valueSet ),
m_grid( grid )
m_grid( boost::shared_dynamic_cast< WGridRegular3D >( grid ) )
{
// initialize members
}
......@@ -79,58 +79,44 @@ osg::ref_ptr< osg::Texture3D > WDataTexture3D::getTexture()
return m_texture;
}
void WDataTexture3D::createTexture3D( unsigned char* source, int components )
osg::ref_ptr< osg::Image > WDataTexture3D::createTexture3D( unsigned char* source, int components )
{
boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( m_grid );
osg::ref_ptr< osg::Image > ima = new osg::Image;
if ( components == 1 )
{
osg::ref_ptr< osg::Image > ima = new osg::Image;
ima->allocateImage( grid->getNbCoordsX(), grid->getNbCoordsY(), grid->getNbCoordsZ(), GL_LUMINANCE, GL_UNSIGNED_BYTE );
ima->allocateImage( m_grid->getNbCoordsX(), m_grid->getNbCoordsY(), m_grid->getNbCoordsZ(), GL_LUMINANCE, GL_UNSIGNED_BYTE );
unsigned char* data = ima->data();
for ( unsigned int i = 0; i < grid->getNbCoordsX() * grid->getNbCoordsY() * grid->getNbCoordsZ(); ++i )
for ( unsigned int i = 0; i < m_grid->getNbCoordsX() * m_grid->getNbCoordsY() * m_grid->getNbCoordsZ(); ++i )
{
data[i] = source[i];
}
m_texture = osg::ref_ptr<osg::Texture3D>( new osg::Texture3D );
m_texture->setFilter( osg::Texture3D::MIN_FILTER, osg::Texture3D::LINEAR );
m_texture->setFilter( osg::Texture3D::MAG_FILTER, osg::Texture3D::LINEAR );
m_texture->setWrap( osg::Texture3D::WRAP_R, osg::Texture3D::REPEAT );
m_texture->setImage( ima );
m_texture->setResizeNonPowerOfTwoHint( false );
}
else if ( components == 3 )
{
osg::ref_ptr< osg::Image > ima = new osg::Image;
ima->allocateImage( grid->getNbCoordsX(), grid->getNbCoordsY(), grid->getNbCoordsZ(), GL_RGB, GL_UNSIGNED_BYTE );
ima->allocateImage( m_grid->getNbCoordsX(), m_grid->getNbCoordsY(), m_grid->getNbCoordsZ(), GL_RGB, GL_UNSIGNED_BYTE );
unsigned char* data = ima->data();
for ( unsigned int i = 0; i < grid->getNbCoordsX() * grid->getNbCoordsY() * grid->getNbCoordsZ() * 3; ++i )
for ( unsigned int i = 0; i < m_grid->getNbCoordsX() * m_grid->getNbCoordsY() * m_grid->getNbCoordsZ() * 3; ++i )
{
data[i] = source[i];
}
m_texture = osg::ref_ptr<osg::Texture3D>( new osg::Texture3D );
m_texture->setFilter( osg::Texture3D::MIN_FILTER, osg::Texture3D::LINEAR );
m_texture->setFilter( osg::Texture3D::MAG_FILTER, osg::Texture3D::LINEAR );
m_texture->setWrap( osg::Texture3D::WRAP_R, osg::Texture3D::REPEAT );
m_texture->setImage( ima );
m_texture->setResizeNonPowerOfTwoHint( false );
}
return ima;
// TODO(seralph): throw exception if components!=1 or 3
}
void WDataTexture3D::createTexture3D( int16_t* source, int components )
osg::ref_ptr< osg::Image > WDataTexture3D::createTexture3D( int16_t* source, int components )
{
boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( m_grid );
osg::ref_ptr< osg::Image > ima = new osg::Image;
// TODO(seralph): throw exception if components!=1 or 3
if ( components == 1)
{
int nSize = grid->getNbCoordsX() * grid->getNbCoordsY() * grid->getNbCoordsZ();
int nSize = m_grid->getNbCoordsX() * m_grid->getNbCoordsY() * m_grid->getNbCoordsZ();
std::vector<int16_t> tempSource( nSize );
......@@ -174,77 +160,72 @@ void WDataTexture3D::createTexture3D( int16_t* source, int components )
tempSource[i] *= mult;
}
osg::ref_ptr< osg::Image > ima = new osg::Image;
ima->allocateImage( grid->getNbCoordsX(), grid->getNbCoordsY(), grid->getNbCoordsZ(), GL_LUMINANCE, GL_UNSIGNED_SHORT );
ima->allocateImage( m_grid->getNbCoordsX(), m_grid->getNbCoordsY(), m_grid->getNbCoordsZ(), GL_LUMINANCE, GL_UNSIGNED_SHORT );
unsigned char* data = ima->data();
unsigned char* charSource = ( unsigned char* )&tempSource[0];
for ( unsigned int i = 0; i < grid->getNbCoordsX() * grid->getNbCoordsY() * grid->getNbCoordsZ() * 2 ; ++i )
for ( unsigned int i = 0; i < m_grid->getNbCoordsX() * m_grid->getNbCoordsY() * m_grid->getNbCoordsZ() * 2 ; ++i )
{
data[i] = charSource[i];
}
m_texture = osg::ref_ptr<osg::Texture3D>( new osg::Texture3D );
m_texture->setFilter( osg::Texture3D::MIN_FILTER, osg::Texture3D::LINEAR );
m_texture->setFilter( osg::Texture3D::MAG_FILTER, osg::Texture3D::LINEAR );
m_texture->setWrap( osg::Texture3D::WRAP_R, osg::Texture3D::REPEAT );
m_texture->setImage( ima );
m_texture->setResizeNonPowerOfTwoHint( false );
}
return ima;
}
void WDataTexture3D::createTexture3D( float* source, int components )
osg::ref_ptr< osg::Image > WDataTexture3D::createTexture3D( float* source, int components )
{
boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( m_grid );
osg::ref_ptr< osg::Image > ima = new osg::Image;
// TODO(seralph): throw exception if texture generation failed
if ( components == 1)
{
osg::ref_ptr< osg::Image > ima = new osg::Image;
ima->allocateImage( grid->getNbCoordsX(), grid->getNbCoordsY(), grid->getNbCoordsZ(), GL_LUMINANCE, GL_FLOAT );
ima->allocateImage( m_grid->getNbCoordsX(), m_grid->getNbCoordsY(), m_grid->getNbCoordsZ(), GL_LUMINANCE, GL_FLOAT );
unsigned char* data = ima->data();
unsigned char* charSource = ( unsigned char* )source;
for ( unsigned int i = 0; i < grid->getNbCoordsX() * grid->getNbCoordsY() * grid->getNbCoordsZ() * 4 ; ++i )
for ( unsigned int i = 0; i < m_grid->getNbCoordsX() * m_grid->getNbCoordsY() * m_grid->getNbCoordsZ() * 4 ; ++i )
{
data[i] = charSource[i];
}
m_texture = osg::ref_ptr<osg::Texture3D>( new osg::Texture3D );
m_texture->setFilter( osg::Texture3D::MIN_FILTER, osg::Texture3D::LINEAR );
m_texture->setFilter( osg::Texture3D::MAG_FILTER, osg::Texture3D::LINEAR );
m_texture->setWrap( osg::Texture3D::WRAP_R, osg::Texture3D::REPEAT );
m_texture->setImage( ima );
m_texture->setResizeNonPowerOfTwoHint( false );
}
return ima;
}
void WDataTexture3D::createTexture()
{
if ( !m_texture )
{
osg::ref_ptr< osg::Image > ima;
if ( m_valueSet->getDataType() == 2 )
{
boost::shared_ptr< WValueSet< unsigned char > > vs = boost::shared_dynamic_cast< WValueSet< unsigned char > >( m_valueSet );
unsigned char* source = const_cast< unsigned char* > ( vs->rawData() );
createTexture3D( source, m_valueSet->dimension() );
ima = createTexture3D( source, m_valueSet->dimension() );
}
else if ( m_valueSet->getDataType() == 4 )
{
boost::shared_ptr< WValueSet< int16_t > > vs = boost::shared_dynamic_cast< WValueSet< int16_t > >( m_valueSet );
int16_t* source = const_cast< int16_t* > ( vs->rawData() );
createTexture3D( source, m_valueSet->dimension() );
ima = createTexture3D( source, m_valueSet->dimension() );
}
else if ( m_valueSet->getDataType() == 16 )
{
boost::shared_ptr< WValueSet< float > > vs = boost::shared_dynamic_cast< WValueSet< float > >( m_valueSet );
float* source = const_cast< float* > ( vs->rawData() );
createTexture3D( source, m_valueSet->dimension() );
ima = createTexture3D( source, m_valueSet->dimension() );
}
m_texture = osg::ref_ptr<osg::Texture3D>( new osg::Texture3D );
m_texture->setFilter( osg::Texture3D::MIN_FILTER, osg::Texture3D::LINEAR );
m_texture->setFilter( osg::Texture3D::MAG_FILTER, osg::Texture3D::LINEAR );
m_texture->setImage( ima );
m_texture->setResizeNonPowerOfTwoHint( false );
}
}
......@@ -29,8 +29,9 @@
#include <osg/Texture3D>
#include "WValueSetBase.h"
#include "WGrid.h"
#include "WGridRegular3D.h"
/**
* Class encapsulating a 3D texture. It is able to use a value set and grid to create an OpenSceneGraph texture, that can be used
......@@ -93,9 +94,9 @@ protected:
* \param source Pointer to the raw data of a dataset
* \param components Number of values used in a Voxel, usually 1, 3 or 4
*/
void createTexture3D( unsigned char* source, int components = 1 );
void createTexture3D( int16_t* source, int components = 1 );
void createTexture3D( float* source, int components = 1 );
osg::ref_ptr< osg::Image > createTexture3D( unsigned char* source, int components = 1 );
osg::ref_ptr< osg::Image > createTexture3D( int16_t* source, int components = 1 );
osg::ref_ptr< osg::Image > createTexture3D( float* source, int components = 1 );
/**
* Creates a 3D texture for the data set.
......@@ -125,7 +126,7 @@ protected:
/**
* The grid used to set up the texture.
*/
boost::shared_ptr<WGrid> m_grid;
boost::shared_ptr< WGridRegular3D > m_grid;
private:
};
......
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