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"
46 namespace WDataTexture3DScalers
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