25 #ifndef WDATATEXTURE3D_H
26 #define WDATATEXTURE3D_H
32 #include <boost/shared_ptr.hpp>
33 #include <boost/signals2.hpp>
35 #include "../graphicsEngine/WGETexture.h"
36 #include "../graphicsEngine/WGETypeTraits.h"
37 #include "../common/WProperties.h"
38 #include "../common/WLogger.h"
40 #include "WValueSetBase.h"
41 #include "WGridRegular3D.h"
61 template <
typename T >
64 return static_cast< double >( std::min( std::max( value, minimum ), maximum ) - minimum ) / scaler;
86 inline uint8_t
scaleInterval( uint8_t value, uint8_t , uint8_t ,
double )
105 WDataTexture3D( boost::shared_ptr< WValueSetBase > valueSet, boost::shared_ptr< WGridRegular3D > grid );
151 template <
typename T >
152 osg::ref_ptr< osg::Image >
createTexture( T* source,
int components = 1 );
175 void bindTexture( osg::ref_ptr< osg::Node > node, osg::ref_ptr< WDataTexture3D > texture,
176 size_t unit = 0, std::string prefix =
"" );
179 template <
typename T >
186 T min =
static_cast< T
>(
minimum()->get() );
187 double scaler =
scale()->get();
188 T max = min +
static_cast< T
>( scaler );
193 wlog::debug(
"WDataTexture3D" ) <<
"Resolution: " << getTextureWidth() <<
"x" << getTextureHeight() <<
"x" << getTextureDepth();
194 wlog::debug(
"WDataTexture3D" ) <<
"Channels: " << components;
196 wlog::debug(
"WDataTexture3D" ) <<
"Value Range: [" <<
static_cast< float >( min ) <<
"," << static_cast< float >( max ) <<
197 "] - Scaler: " << scaler;
198 osg::ref_ptr< osg::Image > ima =
new osg::Image;
200 size_t nbVoxels = getTextureWidth() * getTextureHeight() * getTextureDepth();
205 ima->allocateImage( getTextureWidth(), getTextureHeight(), getTextureDepth(), GL_LUMINANCE_ALPHA, type );
206 TexType* data =
reinterpret_cast< TexType*
>( ima->data() );
209 for(
unsigned int i = 0; i < nbVoxels; ++i )
216 else if( components == 2)
219 ima->allocateImage( getTextureWidth(), getTextureHeight(), getTextureDepth(), GL_RGBA, type );
220 ima->setInternalTextureFormat( GL_RGBA );
221 TexType* data =
reinterpret_cast< TexType*
>( ima->data() );
224 for(
unsigned int i = 0; i < nbVoxels; ++i )
228 data[ ( 4 * i ) + 2 ] = 0;
232 else if( components == 3)
235 ima->allocateImage( getTextureWidth(), getTextureHeight(), getTextureDepth(), GL_RGBA, type );
236 ima->setInternalTextureFormat( GL_RGBA );
237 TexType* data =
reinterpret_cast< TexType*
>( ima->data() );
240 for(
unsigned int i = 0; i < nbVoxels; ++i )
248 else if( components == 4)
251 ima->allocateImage( getTextureWidth(), getTextureHeight(), getTextureDepth(), GL_RGBA, type );
252 ima->setInternalTextureFormat( GL_RGBA );
253 TexType* data =
reinterpret_cast< TexType*
>( ima->data() );
256 for(
unsigned int i = 0; i < nbVoxels; ++i )
266 wlog::error(
"WDataTexture3D" ) <<
"Did not handle dataset ( components != 1,2,3 or 4 ).";
275 #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.