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"
39 #include "WValueSetBase.h"
40 #include "WGridRegular3D.h"
42 #include "WExportDataHandler.h"
47 namespace WDataTexture3DScalers
62 template <
typename T >
65 return static_cast< double >( std::min( std::max( value, minimum ), maximum ) - minimum ) / scaler;
87 inline uint8_t
scaleInterval( uint8_t value, uint8_t , uint8_t ,
double )
107 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 );
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