30 #include <boost/lexical_cast.hpp>
31 #include <boost/shared_ptr.hpp>
34 #include <osg/StateSet>
35 #include <osg/Texture>
36 #include <osg/Texture1D>
37 #include <osg/Texture2D>
38 #include <osg/Texture3D>
40 #include "callbacks/WGEFunctorCallback.h"
41 #include "../common/WLimits.h"
42 #include "../common/WBoundingBox.h"
43 #include "../common/WProperties.h"
44 #include "../common/WPropertyHelper.h"
45 #include "../common/math/linearAlgebra/WLinearAlgebra.h"
47 #include "WGETextureUtils.h"
53 template <
typename TextureType = osg::Texture >
98 WPropString
name()
const;
114 WPropDouble
scale()
const;
121 WPropDouble
alpha()
const;
173 void bind( osg::ref_ptr< osg::Node > node,
size_t unit = 0 );
196 virtual void applyUniforms( std::string prefix, osg::StateSet* states )
const;
210 void setWrapSTR( osg::Texture::WrapMode mode );
248 static void initTextureSize( osg::Texture1D* texture,
int width,
int height,
int depth );
259 static void initTextureSize( osg::Texture2D* texture,
int width,
int height,
int depth );
270 static void initTextureSize( osg::Texture3D* texture,
int width,
int height,
int depth );
377 template <
typename TextureType >
381 m_properties( boost::shared_ptr<
WProperties >( new
WProperties(
"Texture Properties",
"Properties of a texture." ) ) ),
382 m_infoProperties( boost::shared_ptr<
WProperties >( new
WProperties(
"Texture Info Properties",
"Texture's information properties." ) ) ),
388 template <
typename TextureType >
392 m_properties( boost::shared_ptr<
WProperties >( new
WProperties(
"Texture Properties",
"Properties of a texture." ) ) ),
393 m_infoProperties( boost::shared_ptr<
WProperties >( new
WProperties(
"Texture Info Properties",
"Texture's information properties." ) ) ),
400 template <
typename TextureType >
403 m_min( texture.m_min ),
404 m_scale( texture.m_scale )
409 template <
typename TextureType >
414 m_name = m_properties->addProperty(
"Name",
"The name of the texture.", std::string(
"Unnamed" ) );
417 m_min = m_properties->addProperty(
"Minimum",
"The minimum value in the original space.", min,
true );
418 m_min->removeConstraint( m_min->getMin() );
419 m_min->removeConstraint( m_min->getMax() );
421 m_scale = m_properties->addProperty(
"Scale",
"The scaling factor to un-scale the texture values to the original space.", scale,
true );
422 m_scale->removeConstraint( m_scale->getMin() );
423 m_scale->removeConstraint( m_scale->getMax() );
425 m_alpha = m_properties->addProperty(
"Alpha",
"The alpha blending value.", 1.0 );
426 m_alpha->setMin( 0.0 );
427 m_alpha->setMax( 1.0 );
429 m_thresholdEnabled = m_properties->addProperty(
"Enable Threshold",
430 "If enabled, threshold based clipping is used. If not, threshold is ignored.",
false );
432 m_threshold = m_properties->addProperty(
"Threshold",
"The threshold used to clip areas.", 0.0 );
433 m_threshold->setMin( min );
434 m_threshold->setMax( min + scale );
436 m_interpolation = m_properties->addProperty(
"Interpolate",
"Interpolation of the volume data.",
true, m_propCondition );
438 m_colorMapSelectionsList = boost::shared_ptr< WItemSelection >(
new WItemSelection() );
439 m_colorMapSelectionsList->addItem(
"Grayscale",
"" );
440 m_colorMapSelectionsList->addItem(
"Rainbow",
"" );
441 m_colorMapSelectionsList->addItem(
"Hot iron",
"" );
442 m_colorMapSelectionsList->addItem(
"Negative to positive",
"" );
443 m_colorMapSelectionsList->addItem(
"Atlas",
"" );
444 m_colorMapSelectionsList->addItem(
"Blue-Green-Purple",
"" );
445 m_colorMapSelectionsList->addItem(
"Vector",
"" );
447 m_colorMap = m_properties->addProperty(
"Colormap",
"The colormap of this texture.", m_colorMapSelectionsList->getSelectorFirst() );
450 m_active = m_properties->addProperty(
"Active",
"Can dis-enable a texture.",
true );
453 m_texMatrix = m_properties->addProperty(
"Texture Transformation",
"Usable to transform the texture.", m );
454 m_texMatrix->setPurpose( PV_PURPOSE_INFORMATION );
456 TextureType::setResizeNonPowerOfTwoHint(
false );
462 TextureType::setFilter( osg::Texture::MIN_FILTER, m_interpolation->get(
true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
463 TextureType::setFilter( osg::Texture::MAG_FILTER, m_interpolation->get(
true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
466 template <
typename TextureType >
472 template <
typename TextureType >
478 template <
typename TextureType >
481 return m_infoProperties;
484 template <
typename TextureType >
490 template <
typename TextureType >
496 template <
typename TextureType >
502 template <
typename TextureType >
508 template <
typename TextureType >
514 template <
typename TextureType >
517 return m_thresholdEnabled;
520 template <
typename TextureType >
523 return m_interpolation;
526 template <
typename TextureType >
532 template <
typename TextureType >
538 template <
typename TextureType >
544 template <
typename TextureType >
547 if( m_interpolation->changed() )
549 TextureType::setFilter( osg::Texture::MIN_FILTER, m_interpolation->get(
true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
550 TextureType::setFilter( osg::Texture::MAG_FILTER, m_interpolation->get(
true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
554 template <
typename TextureType >
566 template <
typename TextureType >
573 template <
typename TextureType >
579 template <
typename TextureType >
585 m_needCreate =
false;
587 TextureType::dirtyTextureObject();
591 template <
typename TextureType >
594 this->setFilter( osg::Texture2D::MIN_FILTER, mode );
595 this->setFilter( osg::Texture2D::MAG_FILTER, mode );
598 template <
typename TextureType >
601 this->setWrap( osg::Texture2D::WRAP_S, mode );
602 this->setWrap( osg::Texture2D::WRAP_T, mode );
603 this->setWrap( osg::Texture2D::WRAP_R, mode );
606 template <
typename TextureType >
609 texture->setTextureWidth( width );
612 template <
typename TextureType >
615 texture->setTextureSize( width, height );
618 template <
typename TextureType >
621 texture->setTextureSize( width, height, depth );
624 template <
typename TextureType >
630 #endif // WGETEXTURE_H