28 #include "../graphicsEngine/WGETextureUtils.h"
29 #include "WDataTexture3D.h"
30 #include "WValueSet.h"
33 WGETexture3D( static_cast< float >( valueSet->getMaximumValue() - valueSet->getMinimumValue() ),
34 static_cast< float >( valueSet->getMinimumValue() ) ),
35 m_valueSet( valueSet ),
36 m_boundingBox( grid->getVoxelBoundingBox() )
39 setTextureSize( grid->getNbCoordsX(), grid->getNbCoordsY(), grid->getNbCoordsZ() );
42 setWrap( osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_BORDER );
43 setWrap( osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_BORDER );
44 setWrap( osg::Texture::WRAP_R, osg::Texture::CLAMP_TO_BORDER );
53 window()->set( make_interval( valueSet->getMinimumValue(),
54 valueSet->getMaximumValue() ) );
58 scale( 0, 0 ) = 1.0 / grid->getNbCoordsX();
59 scale( 1, 1 ) = 1.0 / grid->getNbCoordsY();
60 scale( 2, 2 ) = 1.0 / grid->getNbCoordsZ();
65 offset( 3, 0 ) = 0.5 / grid->getNbCoordsX();
66 offset( 3, 1 ) = 0.5 / grid->getNbCoordsY();
67 offset( 3, 2 ) = 0.5 / grid->getNbCoordsZ();
70 Eigen::Matrix4d em = m;
85 osg::ref_ptr< osg::Image > ima;
89 wlog::debug(
"WDataTexture3D" ) <<
"Creating Texture of type W_DT_UINT8";
90 std::shared_ptr< WValueSet< uint8_t > > vs = std::dynamic_pointer_cast< WValueSet< uint8_t > >(
m_valueSet );
91 uint8_t* source =
const_cast< uint8_t*
> ( vs->rawData() );
94 else if(
m_valueSet->getDataType() == W_DT_INT8 )
96 wlog::debug(
"WDataTexture3D" ) <<
"Creating Texture of type W_DT_INT8";
97 std::shared_ptr< WValueSet< int8_t > > vs = std::dynamic_pointer_cast< WValueSet< int8_t > >(
m_valueSet );
98 int8_t* source =
const_cast< int8_t*
> ( vs->rawData() );
101 else if(
m_valueSet->getDataType() == W_DT_INT16 )
103 wlog::debug(
"WDataTexture3D" ) <<
"Creating Texture of type W_DT_INT16";
104 std::shared_ptr< WValueSet< int16_t > > vs = std::dynamic_pointer_cast< WValueSet< int16_t > >(
m_valueSet );
105 int16_t* source =
const_cast< int16_t*
> ( vs->rawData() );
108 else if(
m_valueSet->getDataType() == W_DT_UINT16 )
110 wlog::debug(
"WDataTexture3D" ) <<
"Creating Texture of type W_DT_UINT16";
111 std::shared_ptr< WValueSet< uint16_t > > vs = std::dynamic_pointer_cast< WValueSet< uint16_t > >(
m_valueSet );
112 uint16_t* source =
const_cast< uint16_t*
> ( vs->rawData() );
115 else if(
m_valueSet->getDataType() == W_DT_UINT32 )
117 wlog::debug(
"WDataTexture3D" ) <<
"Creating Texture of type W_DT_UINT32";
118 std::shared_ptr< WValueSet< uint32_t > > vs = std::dynamic_pointer_cast< WValueSet< uint32_t > >(
m_valueSet );
119 uint32_t* source =
const_cast< uint32_t*
> ( vs->rawData() );
122 else if(
m_valueSet->getDataType() == W_DT_INT64 )
124 wlog::debug(
"WDataTexture3D" ) <<
"Creating Texture of type W_DT_INT64";
125 std::shared_ptr< WValueSet< int64_t > > vs = std::dynamic_pointer_cast< WValueSet< int64_t > >(
m_valueSet );
126 int64_t* source =
const_cast< int64_t*
> ( vs->rawData() );
129 else if(
m_valueSet->getDataType() == W_DT_UINT64 )
131 wlog::debug(
"WDataTexture3D" ) <<
"Creating Texture of type W_DT_UINT64";
132 std::shared_ptr< WValueSet< uint64_t > > vs = std::dynamic_pointer_cast< WValueSet< uint64_t > >(
m_valueSet );
133 uint64_t* source =
const_cast< uint64_t*
> ( vs->rawData() );
136 else if(
m_valueSet->getDataType() == W_DT_SIGNED_INT )
138 wlog::debug(
"WDataTexture3D" ) <<
"Creating Texture of type W_DT_SIGNED_INT";
139 std::shared_ptr< WValueSet< int32_t > > vs = std::dynamic_pointer_cast< WValueSet< int32_t > >(
m_valueSet );
140 int* source =
const_cast< int*
> ( vs->rawData() );
143 else if(
m_valueSet->getDataType() == W_DT_FLOAT )
145 wlog::debug(
"WDataTexture3D" ) <<
"Creating Texture of type W_DT_FLOAT";
146 std::shared_ptr< WValueSet< float > > vs = std::dynamic_pointer_cast< WValueSet< float > >(
m_valueSet );
147 float* source =
const_cast< float*
> ( vs->rawData() );
150 else if(
m_valueSet->getDataType() == W_DT_DOUBLE )
152 wlog::debug(
"WDataTexture3D" ) <<
"Creating Texture of type W_DT_DOUBLE";
153 std::shared_ptr< WValueSet< double > > vs = std::dynamic_pointer_cast< WValueSet< double > >(
m_valueSet );
154 double* source =
const_cast< double*
> ( vs->rawData() );
157 else if(
m_valueSet->getDataType() == W_DT_FLOAT128 )
159 wlog::debug(
"WDataTexture3D" ) <<
"Creating Texture of type W_DT_FLOAT128";
160 std::shared_ptr< WValueSet< long double > > vs = std::dynamic_pointer_cast< WValueSet< long double > >(
m_valueSet );
161 long double* source =
const_cast< long double*
> ( vs->rawData() );
167 wlog::error(
"WDataTexture3D" ) <<
"Conversion of this data type to texture not supported yet.";
174 dirtyTextureObject();
182 void wge::bindTexture( osg::ref_ptr< osg::Node > node, osg::ref_ptr< WDataTexture3D > texture,
size_t unit, std::string prefix )
184 wge::bindTexture( node, osg::ref_ptr< WGETexture3D >( texture ), unit, prefix );
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.
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.
WPropInterval window() const
Returns the window level definition for the colormap.
WPropDouble thresholdUpper() const
Returns the threshold property.
WPropMatrix4X4 transformation() const
Returns the texture transformation matrix.
WPropDouble thresholdLower() const
Returns the threshold property.
static void initTextureSize(osg::Texture1D *texture, int width, int height, int depth)
Initialize the size of the texture properly according to real texture type (1D,2D,...
static MatrixType identity()
Returns an identity matrix.
static MatrixType zero()
Returns a zero-initialized matrix.
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.