Commit 90e3052b authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - WDataTexture3D_2 now also included in WDataSet

parent 4d4550db
......@@ -31,6 +31,7 @@
#include "WDataSet.h"
#include "WDataSetVector.h"
#include "WDataTexture3D.h"
#include "WDataTexture3D_2.h"
// prototype instance as singleton
boost::shared_ptr< WPrototyped > WDataSet::m_prototype = boost::shared_ptr< WPrototyped >();
......@@ -65,6 +66,11 @@ boost::shared_ptr< WDataTexture3D > WDataSet::getTexture()
throw WDHException( std::string( "This dataset does not provide a texture." ) );
}
osg::ref_ptr< WDataTexture3D_2 > WDataSet::getTexture2()
{
throw WDHException( std::string( "This dataset does not provide a texture." ) );
}
const std::string WDataSet::getName() const
{
return "WDataSet";
......
......@@ -26,13 +26,18 @@
#define WDATASET_H
#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <osg/ref_ptr>
#include "../common/WProperties.h"
#include "../common/WTransferable.h"
#include "WExportDataHandler.h"
class WDataTexture3D;
class WDataTexture3D_2;
class WCondition;
class WDataSetVector;
......@@ -93,6 +98,13 @@ public:
*/
virtual boost::shared_ptr< WDataTexture3D > getTexture();
/**
* Returns the texture- representation of the dataset. May throw an exception if no texture is available.
*
* \return The texture.
*/
virtual osg::ref_ptr< WDataTexture3D_2 > getTexture2();
/**
* Gets the name of this prototype.
*
......
......@@ -26,8 +26,11 @@
#include <vector>
#include "WDataTexture3D.h"
#include "WDataTexture3D_2.h"
#include "WValueSet.h"
#include "WGrid.h"
#include "WGridRegular3D.h"
#include "../common/WAssert.h"
#include "../common/WPrototyped.h"
#include "../common/WException.h"
......@@ -39,7 +42,8 @@ boost::shared_ptr< WPrototyped > WDataSetSingle::m_prototype = boost::shared_ptr
WDataSetSingle::WDataSetSingle( boost::shared_ptr< WValueSetBase > newValueSet,
boost::shared_ptr< WGrid > newGrid )
: WDataSet()
: WDataSet(),
m_texture()
{
WAssert( newValueSet, "Need a value set for new data set." );
WAssert( newGrid, "Need a grid for new data set." );
......@@ -49,13 +53,21 @@ WDataSetSingle::WDataSetSingle( boost::shared_ptr< WValueSetBase > newValueSet,
m_valueSet = newValueSet;
m_grid = newGrid;
m_texture3D = boost::shared_ptr< WDataTexture3D >( new WDataTexture3D( m_valueSet, m_grid ) );
// technically this should be placed into the WDataSetScalar, WDataSetVector and so on
boost::shared_ptr< WGridRegular3D > regGrid = boost::shared_dynamic_cast< WGridRegular3D >( m_grid );
if ( regGrid )
{
m_texture = osg::ref_ptr< WDataTexture3D_2 >( new WDataTexture3D_2( m_valueSet, regGrid ) );
}
}
WDataSetSingle::WDataSetSingle()
: WDataSet(),
m_grid(),
m_valueSet(),
m_texture3D()
m_texture3D(),
m_texture()
{
// default constructor used by the prototype mechanism
}
......@@ -85,6 +97,11 @@ boost::shared_ptr< WDataTexture3D > WDataSetSingle::getTexture()
return m_texture3D;
}
osg::ref_ptr< WDataTexture3D_2 > WDataSetSingle::getTexture2()
{
return m_texture;
}
const std::string WDataSetSingle::getName() const
{
return "WDataSetSingle";
......
......@@ -27,6 +27,8 @@
#include <string>
#include <osg/ref_ptr>
#include <boost/shared_ptr.hpp>
#include "WGrid.h"
......@@ -37,6 +39,7 @@
#include "WExportDataHandler.h"
class WDataTexture3D;
class WDataTexture3D_2;
/**
* A data set consisting of a set of values based on a grid.
......@@ -106,6 +109,13 @@ public:
*/
virtual boost::shared_ptr< WDataTexture3D > getTexture();
/**
* Returns the texture representation of the dataset. May throw an exception if no texture is available.
*
* \return the texture.
*/
virtual osg::ref_ptr< WDataTexture3D_2 > getTexture2();
/**
* Gets the name of this prototype.
*
......@@ -149,6 +159,11 @@ private:
* The 3D texture representing this dataset.
*/
boost::shared_ptr< WDataTexture3D > m_texture3D;
/**
* The 3D texture representing this dataset.
*/
osg::ref_ptr< WDataTexture3D_2 > m_texture;
};
template< typename T > T WDataSetSingle::getValueAt( size_t id )
......
......@@ -38,6 +38,8 @@ WDataTexture3D_2::WDataTexture3D_2( boost::shared_ptr< WValueSetBase > valueSet,
setWrap( osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_BORDER );
setWrap( osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_BORDER );
setWrap( osg::Texture::WRAP_R, osg::Texture::CLAMP_TO_BORDER );
create();
}
WDataTexture3D_2::~WDataTexture3D_2()
......@@ -53,46 +55,46 @@ osg::Matrix WDataTexture3D_2::getTexMatrix() const
void WDataTexture3D_2::create()
{
osg::ref_ptr< osg::Image > ima;
osg::ref_ptr< osg::Image > ima;
if ( m_valueSet->getDataType() == W_DT_UINT8 )
{
wlog::debug( "WDataTexture3D_2" ) << "Handling W_DT_UINT8";
wlog::debug( "WDataTexture3D_2" ) << "Creating Texture of type W_DT_UINT8";
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() );
ima = createTexture( source, m_valueSet->dimension() );
}
else if ( m_valueSet->getDataType() == W_DT_INT16 )
{
wlog::debug( "WDataTexture3D_2" ) << "Handling W_DT_INT16";
wlog::debug( "WDataTexture3D_2" ) << "Creating Texture of type W_DT_INT16";
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() );
ima = createTexture( source, m_valueSet->dimension() );
}
else if ( m_valueSet->getDataType() == W_DT_SIGNED_INT )
{
wlog::debug( "WDataTexture3D_2" ) << "Handling W_DT_SIGNED_INT";
wlog::debug( "WDataTexture3D_2" ) << "Creating Texture of type W_DT_SIGNED_INT";
boost::shared_ptr< WValueSet< int32_t > > vs = boost::shared_dynamic_cast< WValueSet< int32_t > >( m_valueSet );
int* source = const_cast< int* > ( vs->rawData() );
ima = createTexture( source, m_valueSet->dimension() );
}
else if ( m_valueSet->getDataType() == W_DT_FLOAT )
{
wlog::debug( "WDataTexture3D_2" ) << "Handling W_DT_FLOAT";
wlog::debug( "WDataTexture3D_2" ) << "Creating Texture of type W_DT_FLOAT";
boost::shared_ptr< WValueSet< float > > vs = boost::shared_dynamic_cast< WValueSet< float > >( m_valueSet );
float* source = const_cast< float* > ( vs->rawData() );
ima = createTexture( source, m_valueSet->dimension() );
}
else if ( m_valueSet->getDataType() == W_DT_DOUBLE )
{
wlog::debug( "WDataTexture3D_2" ) << "Handling W_DT_DOUBLE";
wlog::debug( "WDataTexture3D_2" ) << "Creating Texture of type W_DT_DOUBLE";
boost::shared_ptr< WValueSet< double > > vs = boost::shared_dynamic_cast< WValueSet< double > >( m_valueSet );
double* source = const_cast< double* > ( vs->rawData() );
ima = createTexture( source, m_valueSet->dimension() );
}
else
{
wlog::debug( "WDataTexture3D_2" ) << "Handling" << m_valueSet->getDataType();
wlog::debug( "WDataTexture3D_2" ) << "Creating Texture of type" << m_valueSet->getDataType();
wlog::error( "WDataTexture3D_2" ) << "Conversion of this data type to texture not supported yet.";
}
......
......@@ -140,6 +140,9 @@ 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" ) << "Colordepth: " << components;
osg::ref_ptr< osg::Image > ima = new osg::Image;
if ( components == 1)
{
......
......@@ -69,9 +69,15 @@ void WGEColormapping::applyInst( osg::ref_ptr< osg::Node > node, bool useDefault
void WGEColormapping::registerTextureInst( osg::ref_ptr< WGETexture3D > texture )
{
wlog::debug( "WGEColormapping" ) << "Registering texture.";
if ( !m_textures.count( texture ) )
{
m_textures.push_back( texture );
}
}
void WGEColormapping::deregisterTextureInst( osg::ref_ptr< WGETexture3D > texture )
{
wlog::debug( "WGEColormapping" ) << "De-registering texture.";
m_textures.remove( texture );
}
......@@ -28,6 +28,7 @@
#include <osg/Node>
#include "../common/WLogger.h"
#include "../common/WSharedSequenceContainer.h"
#include "WGETexture.h"
......@@ -73,7 +74,8 @@ public:
static void registerTexture( osg::ref_ptr< WGETexture3D > texture );
/**
* De-register the specified texture to the colormapper. The texture is the automatically removed from all users of WGEColormapping.
* De-register the specified texture to the colormapper. The texture is the automatically removed from all users of WGEColormapping. If the
* texture is not in the list, nothing happens.
*
* \param texture the texture to remove
*/
......@@ -109,6 +111,16 @@ private:
* Singleton instance of WGEColormapping
*/
static boost::shared_ptr< WGEColormapping > m_instance;
/**
* The alias for a shared container.
*/
typedef WSharedSequenceContainer< std::vector< osg::ref_ptr< WGETexture3D > > > TextureSharedContainerType;
/**
* The textures managed by this instance.
*/
TextureSharedContainerType m_textures;
};
#endif // WGECOLORMAPPING_H
......
......@@ -163,6 +163,14 @@ public:
*/
boost::shared_ptr< WProperties > getInformationProperties() const;
/**
* Applies some custom uniforms to the specified state-set which directly relate to this texture
*
* \param prefix the prefix used for the uniforms
* \param states the state where to add the uniforms
*/
virtual void applyUniforms( std::string prefix, osg::StateSet* states ) const;
protected:
/**
......@@ -433,6 +441,17 @@ void WGETexture< TextureType >::handleUpdate()
}
}
template < typename TextureType >
void WGETexture< TextureType >::applyUniforms( std::string prefix, osg::StateSet* states ) const
{
states->addUniform( new WGEPropertyUniform< WPropDouble >( prefix + "Min", minimum() ) );
states->addUniform( new WGEPropertyUniform< WPropDouble >( prefix + "Scale", scale() ) );
states->addUniform( new WGEPropertyUniform< WPropDouble >( prefix + "Alpha", alpha() ) );
states->addUniform( new WGEPropertyUniform< WPropDouble >( prefix + "Threshold", threshold() ) );
states->addUniform( new WGEPropertyUniform< WPropSelection >( prefix + "Colormap", colormap() ) );
states->addUniform( new WGEPropertyUniform< WPropBool >( prefix + "Active", active() ) );
}
template < typename TextureType >
void WGETexture< TextureType >::bind( osg::ref_ptr< osg::Node > node, size_t unit )
{
......
......@@ -231,13 +231,7 @@ void wge::bindTexture( osg::ref_ptr< osg::Node > node, osg::ref_ptr< WGETexture<
std::string prefix = "u_texture" + boost::lexical_cast< std::string >( unit );
// add some additional uniforms containing scaling information
osg::StateSet* state = node->getOrCreateStateSet();
state->addUniform( new WGEPropertyUniform< WPropDouble >( prefix + "Min", texture->minimum() ) );
state->addUniform( new WGEPropertyUniform< WPropDouble >( prefix + "Scale", texture->scale() ) );
state->addUniform( new WGEPropertyUniform< WPropDouble >( prefix + "Alpha", texture->alpha() ) );
state->addUniform( new WGEPropertyUniform< WPropDouble >( prefix + "Threshold", texture->threshold() ) );
state->addUniform( new WGEPropertyUniform< WPropSelection >( prefix + "Colormap", texture->colormap() ) );
state->addUniform( new WGEPropertyUniform< WPropBool >( prefix + "Active", texture->active() ) );
texture->applyUniforms( prefix, node->getOrCreateStateSet() );
}
#endif // WGEUTILS_H
......
......@@ -35,6 +35,7 @@
#include "../../../dataHandler/WSubject.h"
#include "../../../dataHandler/WDataHandler.h"
#include "../../../dataHandler/WDataTexture3D.h"
#include "../../../dataHandler/WDataTexture3D_2.h"
#include "../../../dataHandler/WEEG2.h"
#include "../../../dataHandler/exceptions/WDHException.h"
#include "../../../dataHandler/io/WReaderBiosig.h"
......@@ -423,6 +424,7 @@ void WMData::moduleMain()
// register at datahandler
WDataHandler::registerDataSet( m_dataSet ); // this will get obsolete soon
WGEColormapping::registerTexture( m_dataSet->getTexture2() );
// notify
m_output->updateData( m_dataSet );
......
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