Commit 12e1f0f5 by Sebastian Eichelbaum

[ADD] - re-added transformation to texture since it was removed. This now makes…

[ADD] - re-added transformation to texture since it was removed. This now makes colormapping and imagespaceLIC work again.
parent 38502fca
......@@ -39,7 +39,7 @@ boost::shared_ptr< WPrototyped > WDataSet::m_prototype = boost::shared_ptr< WPro
WDataSet::WDataSet()
: WTransferable(),
m_properties( boost::shared_ptr< WProperties >( new WProperties( "Data-Set Properties", "Properties of a data-set" ) ) ),
m_infoProperties( boost::shared_ptr< WProperties >( new WProperties( "Informational Properties", "Data-set's information properties" ) ) ),
m_infoProperties( boost::shared_ptr< WProperties >( new WProperties( "Data-Set Info Properties", "Data-set's information properties" ) ) ),
m_fileName( "" )
{
m_infoProperties->setPurpose( PV_PURPOSE_INFORMATION );
......
......@@ -22,6 +22,8 @@
//
//---------------------------------------------------------------------------
#include "../common/math/WMatrix4x4.h"
#include "WValueSet.h"
#include "../graphicsEngine/WGETextureUtils.h"
......@@ -31,11 +33,10 @@
WDataTexture3D_2::WDataTexture3D_2( boost::shared_ptr< WValueSetBase > valueSet, boost::shared_ptr< WGridRegular3D > grid ):
WGETexture3D( static_cast< float >( valueSet->getMaximumValue() - valueSet->getMinimumValue() ),
static_cast< float >( valueSet->getMinimumValue() ) ),
m_valueSet( valueSet ),
m_grid( grid )
m_valueSet( valueSet )
{
// initialize members
setTextureSize( m_grid->getNbCoordsX(), m_grid->getNbCoordsY(), m_grid->getNbCoordsZ() );
setTextureSize( grid->getNbCoordsX(), grid->getNbCoordsY(), grid->getNbCoordsZ() );
// data textures do not repeat or something
setWrap( osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_BORDER );
......@@ -45,6 +46,24 @@ WDataTexture3D_2::WDataTexture3D_2( boost::shared_ptr< WValueSetBase > valueSet,
threshold()->setMin( valueSet->getMinimumValue() );
threshold()->setMax( valueSet->getMaximumValue() );
threshold()->set( valueSet->getMinimumValue() );
// Scale according to bbox. This scaling is NOT included in the grid's transform, so we need to add it here
wmath::WMatrix4x4 scale;
scale( 0, 0 ) = 1.0 / grid->getNbCoordsX();
scale( 1, 1 ) = 1.0 / grid->getNbCoordsY();
scale( 2, 2 ) = 1.0 / grid->getNbCoordsZ();
scale( 3, 3 ) = 1.0;
// Move to voxel center. This scaling is NOT included in the grid's transform, so we need to add it here
wmath::WMatrix4x4 offset = wmath::WMatrix4x4::identity();
offset( 0, 3 ) = 0.5 / grid->getNbCoordsX();
offset( 1, 3 ) = 0.5 / grid->getNbCoordsY();
offset( 2, 3 ) = 0.5 / grid->getNbCoordsZ();
transformation()->set( wmath::WMatrix4x4::inverse( grid->getTransform() ) * scale * offset );
// set the size
WGETexture3D::initTextureSize( this, grid->getNbCoordsX(), grid->getNbCoordsY(), grid->getNbCoordsZ() );
}
WDataTexture3D_2::~WDataTexture3D_2()
......@@ -111,6 +130,9 @@ void WDataTexture3D_2::create()
wlog::error( "WDataTexture3D_2" ) << "Conversion of this data type to texture not supported yet.";
}
// remove our link to the value set here. It can be free'd now if no one else uses it anymore
m_valueSet.reset();
setImage( ima );
dirtyTextureObject();
}
......@@ -120,8 +142,3 @@ void wge::bindTexture( osg::ref_ptr< osg::Node > node, osg::ref_ptr< WDataTextur
wge::bindTexture( node, osg::ref_ptr< WGETexture3D >( texture ), unit, prefix );
}
boost::shared_ptr< WGridRegular3D > WDataTexture3D_2::getGrid() const
{
return m_grid;
}
......@@ -91,7 +91,7 @@ namespace WDataTexture3D_2Scalers
}
/**
* This class allows simple creation of WGETexture3D by using a specified grid and value-set. It also automates grid changes. Ony advantage: the
* This class allows simple creation of WGETexture3D by using a specified grid and value-set. One advantage: the
* first call to the texture's update callback ensures texture creation. It is not created earlier.
*/
class OWDATAHANDLER_EXPORT WDataTexture3D_2: public WGETexture3D
......@@ -111,14 +111,6 @@ public:
*/
virtual ~WDataTexture3D_2();
/**
* The texture got created using this grid. It can help to translate coordinates into the texture coordinate space relating to
* the grid.
*
* \return the grid.
*/
boost::shared_ptr< WGridRegular3D > getGrid() const;
protected:
/**
......@@ -134,11 +126,6 @@ private:
boost::shared_ptr< WValueSetBase > m_valueSet;
/**
* The grid used to set up the texture.
*/
boost::shared_ptr< WGridRegular3D > m_grid;
/**
* The lock for securing createTexture.
*/
boost::shared_mutex m_creationLock;
......@@ -194,21 +181,23 @@ osg::ref_ptr< osg::Image > WDataTexture3D_2::createTexture( T* source, int compo
typedef typename wge::GLType< T >::Type TexType;
GLenum type = wge::GLType< T >::TypeEnum;
wlog::debug( "WDataTexture3D_2" ) << "Resolution: " << m_grid->getNbCoordsX() << "x" << m_grid->getNbCoordsY() << "x" << m_grid->getNbCoordsZ();
wlog::debug( "WDataTexture3D_2" ) << "Resolution: " << getTextureWidth() << "x" << getTextureHeight() << "x" << getTextureDepth();
wlog::debug( "WDataTexture3D_2" ) << "Channels: " << components;
// NOTE: the casting is needed as if T == uint8_t -> it will be interpreted as ASCII code -> bad.
wlog::debug( "WDataTexture3D_2" ) << "Value Range: [" << static_cast< float >( min ) << "," << static_cast< float >( max ) <<
"] - Scaler: " << scaler;
osg::ref_ptr< osg::Image > ima = new osg::Image;
size_t nbVoxels = getTextureWidth() * getTextureHeight() * getTextureDepth();
if ( components == 1)
{
// OpenGL just supports float textures
ima->allocateImage( m_grid->getNbCoordsX(), m_grid->getNbCoordsY(), m_grid->getNbCoordsZ(), GL_LUMINANCE_ALPHA, type );
ima->allocateImage( getTextureWidth(), getTextureHeight(), getTextureDepth(), GL_LUMINANCE_ALPHA, type );
TexType* data = reinterpret_cast< TexType* >( ima->data() );
// Copy the data pixel wise and convert to float
for ( unsigned int i = 0; i < m_grid->getNbCoordsX() * m_grid->getNbCoordsY() * m_grid->getNbCoordsZ() ; ++i )
for ( unsigned int i = 0; i < nbVoxels; ++i )
{
data[ 2 * i ] = WDataTexture3D_2Scalers::scaleInterval( source[i], min, max, scaler );
data[ ( 2 * i ) + 1] = source[i] != min;
......@@ -217,12 +206,12 @@ osg::ref_ptr< osg::Image > WDataTexture3D_2::createTexture( T* source, int compo
else if ( components == 2)
{
// OpenGL just supports float textures
ima->allocateImage( m_grid->getNbCoordsX(), m_grid->getNbCoordsY(), m_grid->getNbCoordsZ(), GL_RGBA, type );
ima->allocateImage( getTextureWidth(), getTextureHeight(), getTextureDepth(), GL_RGBA, type );
ima->setInternalTextureFormat( GL_RGBA );
TexType* data = reinterpret_cast< TexType* >( ima->data() );
// Copy the data pixel wise and convert to float
for ( unsigned int i = 0; i < m_grid->getNbCoordsX() * m_grid->getNbCoordsY() * m_grid->getNbCoordsZ() ; ++i )
for ( unsigned int i = 0; i < nbVoxels; ++i )
{
data[ ( 4 * i ) ] = WDataTexture3D_2Scalers::scaleInterval( source[ ( 2 * i ) ], min, max, scaler );
data[ ( 4 * i ) + 1 ] = WDataTexture3D_2Scalers::scaleInterval( source[ ( 2 * i ) + 1 ], min, max, scaler );
......@@ -233,12 +222,12 @@ osg::ref_ptr< osg::Image > WDataTexture3D_2::createTexture( T* source, int compo
else if ( components == 3)
{
// OpenGL just supports float textures
ima->allocateImage( m_grid->getNbCoordsX(), m_grid->getNbCoordsY(), m_grid->getNbCoordsZ(), GL_RGBA, type );
ima->allocateImage( getTextureWidth(), getTextureHeight(), getTextureDepth(), GL_RGBA, type );
ima->setInternalTextureFormat( GL_RGBA );
TexType* data = reinterpret_cast< TexType* >( ima->data() );
// Copy the data pixel wise and convert to float
for ( unsigned int i = 0; i < m_grid->getNbCoordsX() * m_grid->getNbCoordsY() * m_grid->getNbCoordsZ() ; ++i )
for ( unsigned int i = 0; i < nbVoxels; ++i )
{
data[ ( 4 * i ) ] = WDataTexture3D_2Scalers::scaleInterval( source[ ( 3 * i ) ], min, max, scaler );
data[ ( 4 * i ) + 1 ] = WDataTexture3D_2Scalers::scaleInterval( source[ ( 3 * i ) + 1 ], min, max, scaler );
......@@ -249,12 +238,12 @@ osg::ref_ptr< osg::Image > WDataTexture3D_2::createTexture( T* source, int compo
else if ( components == 4)
{
// OpenGL just supports float textures
ima->allocateImage( m_grid->getNbCoordsX(), m_grid->getNbCoordsY(), m_grid->getNbCoordsZ(), GL_RGBA, type );
ima->allocateImage( getTextureWidth(), getTextureHeight(), getTextureDepth(), GL_RGBA, type );
ima->setInternalTextureFormat( GL_RGBA );
TexType* data = reinterpret_cast< TexType* >( ima->data() );
// Copy the data pixel wise and convert to float
for ( unsigned int i = 0; i < m_grid->getNbCoordsX() * m_grid->getNbCoordsY() * m_grid->getNbCoordsZ() ; ++i )
for ( unsigned int i = 0; i < nbVoxels; ++i )
{
data[ ( 4 * i ) ] = WDataTexture3D_2Scalers::scaleInterval( source[ ( 4 * i ) ], min, max, scaler );
data[ ( 4 * i ) + 1 ] = WDataTexture3D_2Scalers::scaleInterval( source[ ( 4 * i ) + 1 ], min, max, scaler );
......
......@@ -122,6 +122,8 @@ void WGridRegular3D::initInformationProperties()
WPropDouble xOffset = m_infoProperties->addProperty( "X offset: ", "The distance between samples in x direction", getOffsetX() );
WPropDouble yOffset = m_infoProperties->addProperty( "Y offset: ", "The distance between samples in y direction", getOffsetY() );
WPropDouble zOffset = m_infoProperties->addProperty( "Z offset: ", "The distance between samples in z direction", getOffsetZ() );
WPropMatrix4X4 transformation = m_infoProperties->addProperty( "Transformation", "The transformation of this grid.",
static_cast< WMatrix4x4 >( getTransform() ) );
}
int WGridRegular3D::getXVoxelCoord( const wmath::WPosition& pos ) const
......
......@@ -214,6 +214,39 @@ protected:
*/
virtual void updateCallback( osg::StateAttribute* state );
/**
* Initialize the size of the texture properly according to real texture type (1D,2D,3D).
* \note This is needed because osg::Texture::setImage is not virtual and does not set the size from the image.
*
* \param texture the texture where to set the size
* \param width the new width
* \param height the new height
* \param depth the new depth
*/
static void initTextureSize( osg::Texture1D* texture, int width, int height, int depth );
/**
* Initialize the size of the texture properly according to real texture type (1D,2D,3D).
* \note This is needed because osg::Texture::setImage is not virtual and does not set the size from the image.
*
* \param texture the texture where to set the size
* \param width the new width
* \param height the new height
* \param depth the new depth
*/
static void initTextureSize( osg::Texture2D* texture, int width, int height, int depth );
/**
* Initialize the size of the texture properly according to real texture type (1D,2D,3D).
* \note This is needed because osg::Texture::setImage is not virtual and does not set the size from the image.
*
* \param texture the texture where to set the size
* \param width the new width
* \param height the new height
* \param depth the new depth
*/
static void initTextureSize( osg::Texture3D* texture, int width, int height, int depth );
private:
/**
* Creates and assigns all properties.
......@@ -294,39 +327,6 @@ private:
* The texture transformation matrix.
*/
WPropMatrix4X4 m_texMatrix;
/**
* Initialize the size of the texture properly according to real texture type (1D,2D,3D).
* \note This is needed because osg::Texture::setImage is not virtual and does not set the size from the image.
*
* \param texture the texture where to set the size
* \param width the new width
* \param height the new height
* \param depth the new depth
*/
static void initTextureSize( osg::Texture1D* texture, int width, int height, int depth );
/**
* Initialize the size of the texture properly according to real texture type (1D,2D,3D).
* \note This is needed because osg::Texture::setImage is not virtual and does not set the size from the image.
*
* \param texture the texture where to set the size
* \param width the new width
* \param height the new height
* \param depth the new depth
*/
static void initTextureSize( osg::Texture2D* texture, int width, int height, int depth );
/**
* Initialize the size of the texture properly according to real texture type (1D,2D,3D).
* \note This is needed because osg::Texture::setImage is not virtual and does not set the size from the image.
*
* \param texture the texture where to set the size
* \param width the new width
* \param height the new height
* \param depth the new depth
*/
static void initTextureSize( osg::Texture3D* texture, int width, int height, int depth );
};
// Some convenience typedefs
......@@ -420,6 +420,7 @@ void WGETexture< TextureType >::setupProperties( double scale, double min )
m_active = m_properties->addProperty( "Active", "Can dis-enable a texture.", true );
m_texMatrix = m_properties->addProperty( "Texture Transformation", "Usable to transform the texture.", osg::Matrix::identity() );
m_texMatrix->setPurpose( PV_PURPOSE_INFORMATION );
TextureType::setResizeNonPowerOfTwoHint( false );
TextureType::setUpdateCallback( new WGEFunctorCallback< osg::StateAttribute >(
......
......@@ -171,7 +171,7 @@ void wge::bindTexture( osg::ref_ptr< osg::Node > node, osg::ref_ptr< WGETexture<
wge::bindTexture< T >( node, osg::ref_ptr< T >( texture ), unit, prefix );
// set the texture matrix to the stateset
osg::TexMat* texMat = new osg::TexMat( osg::Matrix::identity() );
osg::TexMat* texMat = new osg::TexMat( texture->transformation()->get() );
// use a callback to update the tex matrix if needed according to transformation property of texture
texMat->setUpdateCallback( new WGEPropertyTransformationCallback< osg::StateAttribute, osg::TexMat >( texture->transformation() ) );
node->getOrCreateStateSet()->setTextureAttributeAndModes( unit, texMat, osg::StateAttribute::ON );
......
......@@ -138,7 +138,8 @@ void WMDatasetManipulator::properties()
void WMDatasetManipulator::init()
{
m_grid = m_input->getData()->getTexture2()->getGrid();
m_grid = boost::shared_dynamic_cast< WGridRegular3D >( m_input->getData()->getGrid() );
WAssert( m_grid, "The grid needs to be a regular 3D grid." );
m_transform = boost::shared_ptr< WGridTransformOrtho >( new WGridTransformOrtho( m_grid->getTransform() ) );
WBoundingBox bb = m_grid->getBoundingBox();
......
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