Commit c185eae3 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - new WGETexture now supports several colormapping realted features...

[CHANGE] - new WGETexture now supports several colormapping realted features formerly in WDataTexture3D which will be obsolete soon.
parent 582614ba
......@@ -30,7 +30,7 @@
#include "../common/WLimits.h"
#include "../common/WCondition.h"
#include "../graphicsEngine/WGEScaledTexture.h"
#include "../graphicsEngine/WGETexture.h"
#include "WDataTexture3D.h"
WDataTexture3D::WDataTexture3D( boost::shared_ptr<WValueSetBase> valueSet, boost::shared_ptr<WGrid> grid ):
......@@ -38,7 +38,7 @@ WDataTexture3D::WDataTexture3D( boost::shared_ptr<WValueSetBase> valueSet, boost
m_infoProperties( boost::shared_ptr< WProperties >( new WProperties( "Data Texture Info Properties", "Texture's information properties." ) ) ),
m_alpha( 1.0 ),
m_threshold( 0.0 ),
m_texture( osg::ref_ptr< WGEScaledTexture3D >() ),
m_texture( osg::ref_ptr< WGETexture3D >() ),
m_valueSet( valueSet ),
m_grid( boost::shared_dynamic_cast< WGridRegular3D >( grid ) ),
m_changeCondition( new WCondition() ),
......@@ -118,7 +118,7 @@ boost::shared_ptr< WGridRegular3D > WDataTexture3D::getGrid() const
return m_grid;
}
osg::ref_ptr< WGEScaledTexture3D > WDataTexture3D::getTexture()
osg::ref_ptr< WGETexture3D > WDataTexture3D::getTexture()
{
createTexture();
return m_texture;
......@@ -434,7 +434,7 @@ void WDataTexture3D::createTexture()
wlog::error( "WDataTexture3D" ) << "Conversion of this data type to texture not supported yet.";
}
m_texture = osg::ref_ptr< WGEScaledTexture3D >( new WGEScaledTexture3D( m_scale, m_minValue ) );
m_texture = osg::ref_ptr< WGETexture3D >( new WGETexture3D( m_scale, m_minValue ) );
m_texture->setFilter( osg::Texture3D::MIN_FILTER, osg::Texture3D::LINEAR );
m_texture->setFilter( osg::Texture3D::MAG_FILTER, osg::Texture3D::LINEAR );
m_texture->setWrap( osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_BORDER );
......
......@@ -30,7 +30,7 @@
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include "../graphicsEngine/WGEScaledTexture.h"
#include "../graphicsEngine/WGETexture.h"
#include "../common/WProperties.h"
#include "WDataHandlerEnums.h"
......@@ -123,7 +123,7 @@ public:
*
* \return the texture
*/
osg::ref_ptr< WGEScaledTexture3D > getTexture();
osg::ref_ptr< WGETexture3D > getTexture();
/**
* Gets the condition which is fired whenever the texture gets some kind of dirty (threshold, opacity, ...)
......@@ -316,7 +316,7 @@ protected:
/**
* The actual texture.
*/
osg::ref_ptr< WGEScaledTexture3D > m_texture;
osg::ref_ptr< WGETexture3D > m_texture;
/**
* The value set from which the texture gets created.
......
......@@ -24,6 +24,9 @@
#include "WGEColormapping.h"
// instance as singleton
boost::shared_ptr< WGEColormapping > WGEColormapping::m_instance = boost::shared_ptr< WGEColormapping >();
WGEColormapping::WGEColormapping()
{
// initialize members
......@@ -34,3 +37,42 @@ WGEColormapping::~WGEColormapping()
// cleanup
}
boost::shared_ptr< WGEColormapping > WGEColormapping::instance()
{
if ( !m_instance )
{
m_instance = boost::shared_ptr< WGEColormapping >( new WGEColormapping() );
}
return m_instance;
}
void WGEColormapping::apply( osg::ref_ptr< osg::Node > node, bool useDefaultShader )
{
instance()->applyInst( node, useDefaultShader );
}
void WGEColormapping::registerTexture( osg::ref_ptr< WGETexture3D > texture )
{
instance()->registerTextureInst( texture );
}
void WGEColormapping::deregisterTexture( osg::ref_ptr< WGETexture3D > texture )
{
instance()->deregisterTextureInst( texture );
}
void WGEColormapping::applyInst( osg::ref_ptr< osg::Node > node, bool useDefaultShader )
{
}
void WGEColormapping::registerTextureInst( osg::ref_ptr< WGETexture3D > texture )
{
wlog::debug( "WGEColormapping" ) << "Registering texture.";
}
void WGEColormapping::deregisterTextureInst( osg::ref_ptr< WGETexture3D > texture )
{
wlog::debug( "WGEColormapping" ) << "De-registering texture.";
}
......@@ -25,8 +25,16 @@
#ifndef WGECOLORMAPPING_H
#define WGECOLORMAPPING_H
#include <osg/Node>
#include "../common/WLogger.h"
#include "WGETexture.h"
/**
* TODO(ebaum): write.
* Class implements a manager for multiple 3D textures. They can be applied to arbitrary osg::Node. This allows very comfortable use of dataset
* based colormapping. The only requirement is that your geometry/node needs to specify texture coordinates in Object Space. That means: the
* texture coordinates equal the regular 3D grid of the texture.
*/
class WGEColormapping
{
......@@ -42,9 +50,66 @@ public:
*/
virtual ~WGEColormapping();
/**
* Returns instance of the module factory to use to create modules.
*
* \return the running module factory.
*/
static boost::shared_ptr< WGEColormapping > instance();
/**
* Apply the colormapping to the specified node.
*
* \param node the node.
* \param useDefaultShader if true, a standard colormapping shader is used. This is useful for plain geometry.
*/
static void apply( osg::ref_ptr< osg::Node > node, bool useDefaultShader = true );
/**
* Register the specified texture to the colormapper. The registered texture is the automatically applied to all users of WGEColormapping.
*
* \param texture the texture to add
*/
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.
*
* \param texture the texture to remove
*/
static void deregisterTexture( osg::ref_ptr< WGETexture3D > texture );
protected:
/**
* Apply the colormapping to the specified node.
*
* \param node the node.
* \param useDefaultShader if true, a standard colormapping shader is used. This is useful for plain geometry.
*/
void applyInst( osg::ref_ptr< osg::Node > node, bool useDefaultShader = true );
/**
* Register the specified texture to the colormapper. The registered texture is the automatically applied to all users of WGEColormapping.
*
* \param texture the texture to add
*/
void registerTextureInst( osg::ref_ptr< WGETexture3D > texture );
/**
* De-register the specified texture to the colormapper. The texture is the automatically removed from all users of WGEColormapping.
*
* \param texture the texture to remove
*/
void deregisterTextureInst( osg::ref_ptr< WGETexture3D > texture );
private:
/**
* Singleton instance of WGEColormapping
*/
static boost::shared_ptr< WGEColormapping > m_instance;
};
#endif // WGECOLORMAPPING_H
......
......@@ -31,7 +31,7 @@
#include <osg/FrameBufferObject>
#include "WGEUtils.h"
#include "WGEScaledTexture.h"
#include "WGETexture.h"
class WGETextureHud;
......
......@@ -22,5 +22,5 @@
//
//---------------------------------------------------------------------------
#include "WGEScaledTexture.h"
#include "WGETexture.h"
......@@ -22,12 +22,13 @@
//
//---------------------------------------------------------------------------
#ifndef WGESCALEDTEXTURE_H
#define WGESCALEDTEXTURE_H
#ifndef WGETEXTURE_H
#define WGETEXTURE_H
#include <string>
#include <boost/lexical_cast.hpp>
#include <boost/shared_ptr.hpp>
#include <osg/Node>
#include <osg/Texture>
......@@ -35,6 +36,9 @@
#include <osg/Texture2D>
#include <osg/Texture3D>
#include "../common/WProperties.h"
#include "../common/WPropertyHelper.h"
#include "WGEUtils.h"
/**
......@@ -42,7 +46,7 @@
* with associated shaders. When this texture gets bind using the bindTo methods, uniforms get added containing needed scaling information.
*/
template < typename TextureType = osg::Texture >
class WGEScaledTexture: public TextureType
class WGETexture: public TextureType
{
public:
/**
......@@ -51,7 +55,7 @@ public:
* \param scale the scaling factor needed for de-scaling the texture values
* \param min the minimum value allowing negative values too.
*/
WGEScaledTexture( double scale = 1.0, double min = 0.0 );
WGETexture( double scale = 1.0, double min = 0.0 );
/**
* Creates texture from given image. Scaling is set to identity.
......@@ -60,7 +64,7 @@ public:
* \param scale the scaling factor needed for de-scaling the texture values
* \param min the minimum value allowing negative values too.
*/
WGEScaledTexture( osg::Image* image, double scale = 1.0, double min = 0.0 );
WGETexture( osg::Image* image, double scale = 1.0, double min = 0.0 );
/**
* Copy the texture.
......@@ -68,12 +72,12 @@ public:
* \param texture the texture to copy
* \param copyop
*/
WGEScaledTexture( const WGEScaledTexture< TextureType >& texture, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY );
WGETexture( const WGETexture< TextureType >& texture, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY );
/**
* Destructor.
*/
virtual ~WGEScaledTexture();
virtual ~WGETexture();
/**
* Get the minimum in the de-scaled value space.
......@@ -89,6 +93,34 @@ public:
*/
double getScale() const;
/**
* Returns the alpha property. The property can be changed. A change affects all colormaps using this texture.
*
* \return alpha property
*/
WPropDouble alpha() const;
/**
* Returns the threshold property. The property can be changed. A change affects all colormaps using this texture.
*
* \return threshold property
*/
WPropDouble threshold() const;
/**
* Returns the interpolation property. The property can be changed. A change affects all colormaps using this texture.
*
* \return interpolation property
*/
WPropBool interpolation() const;
/**
* Returns the colormap property. The property can be changed. A change affects all colormaps using this texture.
*
* \return colormap property
*/
WPropSelection colormap() const;
/**
* Binds the texture to the specified node and texture unit. It also adds two uniforms: u_textureXMin and u_textureXScale, where X
* is the unit number. This can be used in shaders to unscale it.
......@@ -98,41 +130,148 @@ public:
*/
void bind( osg::ref_ptr< osg::Node > node, size_t unit = 0 );
/**
* Return a pointer to the properties object of the dataset. Add all the modifiable settings here. This allows the user to modify several
* properties of a dataset.
*
* \return the properties.
*/
boost::shared_ptr< WProperties > getProperties() const;
/**
* Return a pointer to the information properties object of the dataset. The dataset intends these properties to not be modified.
*
* \return the properties.
*/
boost::shared_ptr< WProperties > getInformationProperties() const;
protected:
private:
/**
* The property object for the dataset.
*/
boost::shared_ptr< WProperties > m_properties;
/**
* The property object for the dataset containing only props whose purpose is "PV_PURPOSE_INFORMNATION". It is useful to define some property
* to only be of informational nature. The GUI does not modify them. As it is a WProperties instance, you can use it the same way as
* m_properties.
*/
boost::shared_ptr< WProperties > m_infoProperties;
/**
* The minimum of each value in the texture in unscaled space.
*/
double m_min;
WPropDouble m_min;
/**
* The scaling factor to de-scale a [0-1] texture to original space.
*/
double m_scale;
WPropDouble m_scale;
/**
* A list of color map selection types
*/
boost::shared_ptr< WItemSelection > m_colorMapSelectionsList;
/**
* Selection property for color map
*/
WPropSelection m_colorMap;
/**
* Alpha blending value.
*/
WPropDouble m_alpha;
/**
* Threshold for clipping areas.
*/
WPropDouble m_threshold;
/**
* True if interpolation should be used.
*/
WPropBool m_interpolation;
};
// Some convenience typedefs
/**
* OSG's Texture1D with scaling features
*/
typedef WGETexture< osg::Texture1D > WGETexture1D;
/**
* OSG's Texture2D with scaling features
*/
typedef WGETexture< osg::Texture2D > WGETexture2D;
/**
* OSG's Texture3D with scaling features
*/
typedef WGETexture< osg::Texture3D > WGETexture3D;
template < typename TextureType >
WGEScaledTexture< TextureType >::WGEScaledTexture( double scale, double min ):
WGETexture< TextureType >::WGETexture( double scale, double min ):
TextureType(),
m_min( min ),
m_scale( scale )
m_properties( boost::shared_ptr< WProperties >( new WProperties( "Texture Properties", "Properties of a texture." ) ) ),
m_infoProperties( boost::shared_ptr< WProperties >( new WProperties( "Texture Info Properties", "Texture's information properties." ) ) )
{
// initialize members
m_min = m_infoProperties->addProperty( "Minimum", "The minimum value in the original space.", min );
m_scale = m_infoProperties->addProperty( "Scale", "The scaling factor to un-scale the texture values to the original space.", scale );
m_alpha = m_properties->addProperty( "Alpha", "The alpha blending value.", 1.0 );
m_alpha->setMin( 0.0 );
m_alpha->setMax( 1.0 );
m_threshold = m_properties->addProperty( "Threshold", "The threshold used to clip areas.", 0.0 );
m_threshold->setMin( 0.0 );
m_threshold->setMin( 1.0 );
m_interpolation = m_properties->addProperty( "Interpolate", "Interpolation of the volume data.", true );
m_colorMapSelectionsList = boost::shared_ptr< WItemSelection >( new WItemSelection() );
m_colorMapSelectionsList->addItem( "Grayscale", "" );
m_colorMapSelectionsList->addItem( "Rainbow", "" );
m_colorMapSelectionsList->addItem( "Hot iron", "" );
m_colorMapSelectionsList->addItem( "Red-Yellow", "" );
m_colorMapSelectionsList->addItem( "Atlas", "" );
m_colorMapSelectionsList->addItem( "Blue-Green-Purple", "" );
m_colorMap = m_properties->addProperty( "Colormap", "The colormap of this texture.", m_colorMapSelectionsList->getSelectorFirst() );
WPropertyHelper::PC_SELECTONLYONE::addTo( m_colorMap );
}
template < typename TextureType >
WGEScaledTexture< TextureType >::WGEScaledTexture( osg::Image* image, double scale, double min ):
TextureType( image ),
m_min( min ),
m_scale( scale )
WGETexture< TextureType >::WGETexture( osg::Image* image, double scale, double min ):
TextureType( image )
{
// initialize members
m_min = m_infoProperties->addProperty( "Minimum", "The minimum value in the original space.", min );
m_scale = m_infoProperties->addProperty( "Scale", "The scaling factor to unscale the texture values to the original space.", scale );
m_alpha = m_properties->addProperty( "Alpha", "The alpha blending value.", 1.0 );
m_threshold = m_properties->addProperty( "Threshold", "The threshold used to clip areas.", 0.0 );
m_interpolation = m_properties->addProperty( "Interpolate", "Interpolation of the volume data.", true );
m_colorMapSelectionsList = boost::shared_ptr< WItemSelection >( new WItemSelection() );
m_colorMapSelectionsList->addItem( "Grayscale", "" );
m_colorMapSelectionsList->addItem( "Rainbow", "" );
m_colorMapSelectionsList->addItem( "Hot iron", "" );
m_colorMapSelectionsList->addItem( "Red-Yellow", "" );
m_colorMapSelectionsList->addItem( "Atlas", "" );
m_colorMapSelectionsList->addItem( "Blue-Green-Purple", "" );
m_colorMap = m_properties->addProperty( "Colormap", "The colormap of this texture.", m_colorMapSelectionsList->getSelectorFirst() );
WPropertyHelper::PC_SELECTONLYONE::addTo( m_colorMap );
}
template < typename TextureType >
WGEScaledTexture< TextureType >::WGEScaledTexture( const WGEScaledTexture< TextureType >& texture, const osg::CopyOp& copyop ):
WGETexture< TextureType >::WGETexture( const WGETexture< TextureType >& texture, const osg::CopyOp& copyop ):
TextureType( texture, copyop ),
m_min( texture.m_min ),
m_scale( texture.m_scale )
......@@ -141,46 +280,65 @@ WGEScaledTexture< TextureType >::WGEScaledTexture( const WGEScaledTexture< Textu
}
template < typename TextureType >
WGEScaledTexture< TextureType >::~WGEScaledTexture()
WGETexture< TextureType >::~WGETexture()
{
// cleanup.
}
template < typename TextureType >
double WGEScaledTexture< TextureType >::getMin() const
boost::shared_ptr< WProperties > WGETexture< TextureType >::getProperties() const
{
return m_min;
return m_properties;
}
template < typename TextureType >
double WGEScaledTexture< TextureType >::getScale() const
boost::shared_ptr< WProperties > WGETexture< TextureType >::getInformationProperties() const
{
return m_scale;
return m_infoProperties;
}
template < typename TextureType >
void WGEScaledTexture< TextureType >::bind( osg::ref_ptr< osg::Node > node, size_t unit )
double WGETexture< TextureType >::getMin() const
{
// let our utilities do the work
wge::bindTexture( node, this, unit ); // to avoid recursive stuff -> explicitly specify the type
return m_min->get();
}
// Some convenience typedefs
template < typename TextureType >
double WGETexture< TextureType >::getScale() const
{
return m_scale->get();
}
/**
* OSG's Texture1D with scaling features
*/
typedef WGEScaledTexture< osg::Texture1D > WGEScaledTexture1D;
template < typename TextureType >
WPropDouble WGETexture< TextureType >::alpha() const
{
return m_alpha;
}
/**
* OSG's Texture2D with scaling features
*/
typedef WGEScaledTexture< osg::Texture2D > WGEScaledTexture2D;
template < typename TextureType >
WPropDouble WGETexture< TextureType >::threshold() const
{
return m_threshold;
}
/**
* OSG's Texture3D with scaling features
*/
typedef WGEScaledTexture< osg::Texture3D > WGEScaledTexture3D;
template < typename TextureType >
WPropBool WGETexture< TextureType >::interpolation() const
{
return m_interpolation;
}
template < typename TextureType >
WPropSelection WGETexture< TextureType >::colormap() const
{
return m_colorMap;
}
template < typename TextureType >
void WGETexture< TextureType >::bind( osg::ref_ptr< osg::Node > node, size_t unit )
{
// let our utilities do the work
wge::bindTexture( node, this, unit ); // to avoid recursive stuff -> explicitly specify the type
}
#endif // WGESCALEDTEXTURE_H
#endif // WGETEXTURE_H
......@@ -44,6 +44,7 @@
#include "../../../dataHandler/io/WPagerEEGLibeep.h"
#include "../../../dataHandler/io/WReaderELC.h"
#include "../../../dataHandler/io/WReaderFiberVTK.h"
#include "../../../graphicsEngine/WGEColormapping.h"
#include "WMData.h"
#include "data.xpm"
......@@ -421,7 +422,7 @@ void WMData::moduleMain()
m_active->getCondition()->subscribeSignal( boost::bind( &WMData::propertyChanged, this, m_active ) );
// register at datahandler
WDataHandler::registerDataSet( m_dataSet );
WDataHandler::registerDataSet( m_dataSet ); // this will get obsolete soon
// notify
m_output->updateData( m_dataSet );
......
......@@ -35,6 +35,7 @@
#include "../../common/WPropertyHelper.h"
#include "../../dataHandler/WDataSetScalar.h"
#include "../../dataHandler/WDataTexture3D.h"
#include "../../graphicsEngine/WGEColormapping.h"
#include "../../graphicsEngine/WGEGeodeUtils.h"
#include "../../graphicsEngine/WGEManagedGroupNode.h"
#include "../../graphicsEngine/WGEUtils.h"
......@@ -247,6 +248,8 @@ void WMIsosurfaceRaytracer::moduleMain()
rootState->addUniform( steps );
rootState->addUniform( alpha );
WGEColormapping::apply( cube, false );
// update node
debugLog() << "Adding new rendering.";
rootNode->clear();
......
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