25 #ifndef WDATATEXTURE3D_H
26 #define WDATATEXTURE3D_H
31 #include <shared_mutex>
34 #include <boost/signals2.hpp>
36 #include "../common/WLogger.h"
37 #include "../common/WProperties.h"
38 #include "../graphicsEngine/WGETexture.h"
39 #include "../graphicsEngine/WGETypeTraits.h"
40 #include "WGridRegular3D.h"
41 #include "WValueSetBase.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( std::shared_ptr< WValueSetBase > valueSet, std::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();
202 if( components == 1 )
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 ).";
This class allows simple creation of WGETexture3D by using a specified grid and value-set.
WBoundingBox m_boundingBox
The bounding box of the underlying grid.
virtual WBoundingBox getBoundingBox() const
Returns the texture's bounding box.
osg::ref_ptr< osg::Image > createTexture(T *source, int components=1)
Creates a properly sized osg::Image from the specified source data.
std::shared_ptr< WValueSetBase > m_valueSet
The value set from which the texture gets created.
virtual ~WDataTexture3D()
Destructor.
WDataTexture3D(std::shared_ptr< WValueSetBase > valueSet, std::shared_ptr< WGridRegular3D > grid)
Constructor.
std::shared_mutex m_creationLock
The lock for securing createTexture.
virtual void create()
Creates the texture data.
This calls serves a simple purpose: have a texture and its scaling information together which allows ...
WPropDouble scale() const
Get the scaling factor for de-scaling the texture.
WPropDouble minimum() const
Get the minimum in the de-scaled value space.
Class helping to adapt types specified as template parameter into the best matching OpenGL type.
T Type
The best matching OpenGL type for the specified template parameter.
Namespace provides some scaling functions for scaling data values to meet the OpenGL requirements.
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.
Extend the wge utils namespace with additional methods relating WDataTexture3D.
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.
WStreamedLogger debug(const std::string &source)
Logging a debug message.
WStreamedLogger error(const std::string &source)
Logging an error message.