25 #ifndef WDATATEXTURE3D_H
26 #define WDATATEXTURE3D_H
33 #include <boost/shared_ptr.hpp>
36 #include <boost/signals2.hpp>
39 #include "../graphicsEngine/WGETexture.h"
40 #include "../graphicsEngine/WGETypeTraits.h"
41 #include "../common/WProperties.h"
42 #include "../common/WLogger.h"
44 #include "WValueSetBase.h"
45 #include "WGridRegular3D.h"
65 template <
typename T >
68 return static_cast< double >( std::min( std::max( value, minimum ), maximum ) - minimum ) / scaler;
90 inline uint8_t
scaleInterval( uint8_t value, uint8_t , uint8_t ,
double )
109 WDataTexture3D( boost::shared_ptr< WValueSetBase > valueSet, boost::shared_ptr< WGridRegular3D > grid );
155 template <
typename T >
156 osg::ref_ptr< osg::Image >
createTexture( T* source,
int components = 1 );
179 void bindTexture( osg::ref_ptr< osg::Node > node, osg::ref_ptr< WDataTexture3D > texture,
180 size_t unit = 0, std::string prefix =
"" );
183 template <
typename T >
190 T min =
static_cast< T
>(
minimum()->get() );
191 double scaler =
scale()->get();
192 T max = min +
static_cast< T
>( scaler );
197 wlog::debug(
"WDataTexture3D" ) <<
"Resolution: " << getTextureWidth() <<
"x" << getTextureHeight() <<
"x" << getTextureDepth();
198 wlog::debug(
"WDataTexture3D" ) <<
"Channels: " << components;
200 wlog::debug(
"WDataTexture3D" ) <<
"Value Range: [" <<
static_cast< float >( min ) <<
"," << static_cast< float >( max ) <<
201 "] - Scaler: " << scaler;
202 osg::ref_ptr< osg::Image > ima =
new osg::Image;
204 size_t nbVoxels = getTextureWidth() * getTextureHeight() * getTextureDepth();
209 ima->allocateImage( getTextureWidth(), getTextureHeight(), getTextureDepth(), GL_LUMINANCE_ALPHA, type );
210 TexType* data =
reinterpret_cast< TexType*
>( ima->data() );
213 for(
unsigned int i = 0; i < nbVoxels; ++i )
220 else if( components == 2)
223 ima->allocateImage( getTextureWidth(), getTextureHeight(), getTextureDepth(), GL_RGBA, type );
224 ima->setInternalTextureFormat( GL_RGBA );
225 TexType* data =
reinterpret_cast< TexType*
>( ima->data() );
228 for(
unsigned int i = 0; i < nbVoxels; ++i )
232 data[ ( 4 * i ) + 2 ] = 0;
236 else if( components == 3)
239 ima->allocateImage( getTextureWidth(), getTextureHeight(), getTextureDepth(), GL_RGBA, type );
240 ima->setInternalTextureFormat( GL_RGBA );
241 TexType* data =
reinterpret_cast< TexType*
>( ima->data() );
244 for(
unsigned int i = 0; i < nbVoxels; ++i )
252 else if( components == 4)
255 ima->allocateImage( getTextureWidth(), getTextureHeight(), getTextureDepth(), GL_RGBA, type );
256 ima->setInternalTextureFormat( GL_RGBA );
257 TexType* data =
reinterpret_cast< TexType*
>( ima->data() );
260 for(
unsigned int i = 0; i < nbVoxels; ++i )
270 wlog::error(
"WDataTexture3D" ) <<
"Did not handle dataset ( components != 1,2,3 or 4 ).";
279 #endif // WDATATEXTURE3D_H
WStreamedLogger error(const std::string &source)
Logging an error message.
boost::shared_ptr< WValueSetBase > m_valueSet
The value set from which the texture gets created.
Class helping to adapt types specified as template parameter into the best matching OpenGL type...
osg::ref_ptr< osg::Image > createTexture(T *source, int components=1)
Creates a properly sized osg::Image from the specified source data.
virtual ~WDataTexture3D()
Destructor.
virtual WBoundingBox getBoundingBox() const
Returns the texture's bounding box.
T Type
The best matching OpenGL type for the specified template parameter.
This calls serves a simple purpose: have a texture and its scaling information together which allows ...
WBoundingBox m_boundingBox
The bounding box of the underlying grid.
Extend the wge utils namespace with additional methods relating WDataTexture3D.
virtual void create()
Creates the texture data.
WPropDouble minimum() const
Get the minimum in the de-scaled value space.
WDataTexture3D(boost::shared_ptr< WValueSetBase > valueSet, boost::shared_ptr< WGridRegular3D > grid)
Constructor.
WPropDouble scale() const
Get the scaling factor for de-scaling the texture.
wge::GLType< T >::Type scaleInterval(T value, T minimum, T maximum, double scaler)
Scales the specified value to the interval [0,1] using m_min and m_scale.
This class allows simple creation of WGETexture3D by using a specified grid and value-set.
boost::shared_mutex m_creationLock
The lock for securing createTexture.
void bindTexture(osg::ref_ptr< osg::Node > node, osg::ref_ptr< WDataTexture3D > texture, size_t unit=0, std::string prefix="")
Binds the specified texture to the specified unit.
Namespace provides some scaling functions for scaling data values to meet the OpenGL requirements...
WStreamedLogger debug(const std::string &source)
Logging a debug message.