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/WBoundingBox.h"
42 #include "../common/WProperties.h"
43 #include "../common/WPropertyTypes.h"
44 #include "../common/WPropertyHelper.h"
46 #include "WGETextureUtils.h"
52 template <
typename TextureType = osg::Texture >
59 typedef osg::ref_ptr< WGETexture< TextureType > >
RPtr;
102 WPropString
name()
const;
132 WPropDouble
scale()
const;
139 WPropDouble
alpha()
const;
195 WPropInterval
window()
const;
219 void bind( osg::ref_ptr< osg::Node > node,
size_t unit = 0 );
242 virtual void applyUniforms( std::string prefix, osg::StateSet* states )
const;
256 void setWrapSTR( osg::Texture::WrapMode mode );
293 static void initTextureSize( osg::Texture1D* texture,
int width,
int height,
int depth );
304 static void initTextureSize( osg::Texture2D* texture,
int width,
int height,
int depth );
315 static void initTextureSize( osg::Texture3D* texture,
int width,
int height,
int depth );
447 template <
typename TextureType >
451 m_properties( boost::shared_ptr<
WProperties >( new
WProperties(
"Texture Properties",
"Properties of a texture." ) ) ),
452 m_infoProperties( boost::shared_ptr<
WProperties >( new
WProperties(
"Texture Info Properties",
"Texture's information properties." ) ) ),
458 template <
typename TextureType >
462 m_properties( boost::shared_ptr<
WProperties >( new
WProperties(
"Texture Properties",
"Properties of a texture." ) ) ),
463 m_infoProperties( boost::shared_ptr<
WProperties >( new
WProperties(
"Texture Info Properties",
"Texture's information properties." ) ) ),
470 template <
typename TextureType >
473 m_min( texture.m_min ),
474 m_scale( texture.m_scale )
479 template <
typename TextureType >
484 m_name = m_properties->addProperty(
"Name",
"The name of the texture.", std::string(
"Unnamed" ) );
486 m_sortIdx = m_properties->addProperty(
"Sort Index",
487 "The index specifies the index in the colormapper, used to restore colormapper sorting on load.",
488 getUnsetSortIndex() );
489 m_sortIdx->setHidden(
true );
492 m_min = m_properties->addProperty(
"Minimum",
"The minimum value in the original space.", min,
true );
493 m_min->removeConstraint( m_min->getMin() );
494 m_min->removeConstraint( m_min->getMax() );
496 m_scale = m_properties->addProperty(
"Scale",
"The scaling factor to un-scale the texture values to the original space.", scale,
true );
497 m_scale->removeConstraint( m_scale->getMin() );
498 m_scale->removeConstraint( m_scale->getMax() );
500 m_alpha = m_properties->addProperty(
"Alpha",
"The alpha blending value.", 1.0 );
501 m_alpha->setMin( 0.0 );
502 m_alpha->setMax( 1.0 );
504 m_clipZero = m_properties->addProperty(
"Enable Zero Clip",
"If enabled, zero values are clipped.",
true );
506 m_thresholdEnabled = m_properties->addProperty(
"Enable Threshold",
507 "If enabled, threshold based clipping is used. If not, threshold is ignored.",
false );
509 m_thresholdLower = m_properties->addProperty(
"Lower Threshold",
"The threshold used to clip areas below the specified value.", 0.0 );
510 m_thresholdLower->setMin( min );
511 m_thresholdLower->setMax( min + scale );
513 m_thresholdUpper = m_properties->addProperty(
"Upper Threshold",
"The threshold used to clip areas above the specified value.", 1.0 );
514 m_thresholdUpper->setMin( min );
515 m_thresholdUpper->setMax( min + scale );
517 m_windowEnabled = m_properties->addProperty(
"Enable Windowing",
"If enabled, window level settings are applied.",
false );
518 m_window = m_properties->addProperty(
"Window Level",
"Define the interval in the data which is mapped to the colormap.",
519 make_interval( 0.0, 1.0 ) );
521 m_interpolation = m_properties->addProperty(
"Interpolate",
"Interpolation of the volume data.",
true, m_propCondition );
523 m_colorMapSelectionsList = boost::shared_ptr< WItemSelection >(
new WItemSelection() );
524 m_colorMapSelectionsList->addItem(
"Grayscale",
"" );
525 m_colorMapSelectionsList->addItem(
"Rainbow",
"" );
526 m_colorMapSelectionsList->addItem(
"Hot iron",
"" );
527 m_colorMapSelectionsList->addItem(
"Negative to positive",
"" );
528 m_colorMapSelectionsList->addItem(
"Atlas",
"" );
529 m_colorMapSelectionsList->addItem(
"Blue-Green-Purple",
"" );
530 m_colorMapSelectionsList->addItem(
"Vector",
"" );
532 m_colorMap = m_properties->addProperty(
"Colormap",
"The colormap of this texture.", m_colorMapSelectionsList->getSelectorFirst() );
535 m_active = m_properties->addProperty(
"Active",
"Can dis-enable a texture.",
true );
538 m_texMatrix = m_properties->addProperty(
"Texture Transformation",
"Usable to transform the texture.", m );
539 m_texMatrix->setHidden();
540 m_texMatrix->setPurpose( PV_PURPOSE_INFORMATION );
542 TextureType::setResizeNonPowerOfTwoHint(
false );
548 TextureType::setFilter( osg::Texture::MIN_FILTER, m_interpolation->get(
true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
549 TextureType::setFilter( osg::Texture::MAG_FILTER, m_interpolation->get(
true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
552 template <
typename TextureType >
558 template <
typename TextureType >
564 template <
typename TextureType >
567 return m_infoProperties;
570 template <
typename TextureType >
576 template <
typename TextureType >
582 template <
typename TextureType >
588 template <
typename TextureType >
594 template <
typename TextureType >
600 template <
typename TextureType >
606 template <
typename TextureType >
609 return m_thresholdLower;
612 template <
typename TextureType >
615 return m_thresholdUpper;
618 template <
typename TextureType >
621 return m_thresholdEnabled;
624 template <
typename TextureType >
627 return m_interpolation;
630 template <
typename TextureType >
636 template <
typename TextureType >
642 template <
typename TextureType >
645 return m_windowEnabled;
648 template <
typename TextureType >
654 template <
typename TextureType >
660 template <
typename TextureType >
663 if( m_interpolation->changed() )
665 TextureType::setFilter( osg::Texture::MIN_FILTER, m_interpolation->get(
true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
666 TextureType::setFilter( osg::Texture::MAG_FILTER, m_interpolation->get(
true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
670 template <
typename TextureType >
686 template <
typename TextureType >
693 template <
typename TextureType >
699 template <
typename TextureType >
705 m_needCreate =
false;
707 TextureType::dirtyTextureObject();
711 template <
typename TextureType >
714 this->setFilter( osg::Texture2D::MIN_FILTER, mode );
715 this->setFilter( osg::Texture2D::MAG_FILTER, mode );
718 template <
typename TextureType >
721 this->setWrap( osg::Texture2D::WRAP_S, mode );
722 this->setWrap( osg::Texture2D::WRAP_T, mode );
723 this->setWrap( osg::Texture2D::WRAP_R, mode );
726 template <
typename TextureType >
729 texture->setTextureWidth( width );
732 template <
typename TextureType >
735 texture->setTextureSize( width, height );
738 template <
typename TextureType >
741 texture->setTextureSize( width, height, depth );
744 template <
typename TextureType >
750 template <
typename TextureType >
753 return std::numeric_limits< WPVBaseTypes::PV_INT >::max();
756 #endif // WGETEXTURE_H