32 #include <boost/shared_ptr.hpp>
36 #include <osg/StateSet>
37 #include <osg/Texture>
38 #include <osg/Texture1D>
39 #include <osg/Texture2D>
40 #include <osg/Texture3D>
42 #include "callbacks/WGEFunctorCallback.h"
43 #include "../common/WBoundingBox.h"
44 #include "../common/WProperties.h"
45 #include "../common/WPropertyTypes.h"
46 #include "../common/WPropertyHelper.h"
48 #include "WGETextureUtils.h"
54 template <
typename TextureType = osg::Texture >
61 typedef osg::ref_ptr< WGETexture< TextureType > >
RPtr;
104 WPropString
name()
const;
134 WPropDouble
scale()
const;
141 WPropDouble
alpha()
const;
197 WPropInterval
window()
const;
221 void bind( osg::ref_ptr< osg::Node > node,
size_t unit = 0 );
244 virtual void applyUniforms( std::string prefix, osg::StateSet* states )
const;
258 void setWrapSTR( osg::Texture::WrapMode mode );
295 static void initTextureSize( osg::Texture1D* texture,
int width,
int height,
int depth );
306 static void initTextureSize( osg::Texture2D* texture,
int width,
int height,
int depth );
317 static void initTextureSize( osg::Texture3D* texture,
int width,
int height,
int depth );
449 template <
typename TextureType >
453 m_properties( boost::shared_ptr<
WProperties >( new
WProperties(
"Texture Properties",
"Properties of a texture." ) ) ),
454 m_infoProperties( boost::shared_ptr<
WProperties >( new
WProperties(
"Texture Info Properties",
"Texture's information properties." ) ) ),
460 template <
typename TextureType >
464 m_properties( boost::shared_ptr<
WProperties >( new
WProperties(
"Texture Properties",
"Properties of a texture." ) ) ),
465 m_infoProperties( boost::shared_ptr<
WProperties >( new
WProperties(
"Texture Info Properties",
"Texture's information properties." ) ) ),
472 template <
typename TextureType >
475 m_min( texture.m_min ),
476 m_scale( texture.m_scale )
481 template <
typename TextureType >
486 m_name = m_properties->addProperty(
"Name",
"The name of the texture.", std::string(
"Unnamed" ) );
488 m_sortIdx = m_properties->addProperty(
"Sort Index",
489 "The index specifies the index in the colormapper, used to restore colormapper sorting on load.",
490 getUnsetSortIndex() );
491 m_sortIdx->setHidden(
true );
494 m_min = m_properties->addProperty(
"Minimum",
"The minimum value in the original space.", min,
true );
495 m_min->removeConstraint( m_min->getMin() );
496 m_min->removeConstraint( m_min->getMax() );
498 m_scale = m_properties->addProperty(
"Scale",
"The scaling factor to un-scale the texture values to the original space.", scale,
true );
499 m_scale->removeConstraint( m_scale->getMin() );
500 m_scale->removeConstraint( m_scale->getMax() );
502 m_alpha = m_properties->addProperty(
"Alpha",
"The alpha blending value.", 1.0 );
503 m_alpha->setMin( 0.0 );
504 m_alpha->setMax( 1.0 );
506 m_clipZero = m_properties->addProperty(
"Enable Zero Clip",
"If enabled, zero values are clipped.",
true );
508 m_thresholdEnabled = m_properties->addProperty(
"Enable Threshold",
509 "If enabled, threshold based clipping is used. If not, threshold is ignored.",
false );
511 m_thresholdLower = m_properties->addProperty(
"Lower Threshold",
"The threshold used to clip areas below the specified value.", 0.0 );
512 m_thresholdLower->setMin( min );
513 m_thresholdLower->setMax( min + scale );
515 m_thresholdUpper = m_properties->addProperty(
"Upper Threshold",
"The threshold used to clip areas above the specified value.", 1.0 );
516 m_thresholdUpper->setMin( min );
517 m_thresholdUpper->setMax( min + scale );
519 m_windowEnabled = m_properties->addProperty(
"Enable Windowing",
"If enabled, window level settings are applied.",
false );
520 m_window = m_properties->addProperty(
"Window Level",
"Define the interval in the data which is mapped to the colormap.",
521 make_interval( 0.0, 1.0 ) );
523 m_interpolation = m_properties->addProperty(
"Interpolate",
"Interpolation of the volume data.",
true, m_propCondition );
525 m_colorMapSelectionsList = boost::shared_ptr< WItemSelection >(
new WItemSelection() );
526 m_colorMapSelectionsList->addItem(
"Grayscale",
"" );
527 m_colorMapSelectionsList->addItem(
"Rainbow",
"" );
528 m_colorMapSelectionsList->addItem(
"Hot iron",
"" );
529 m_colorMapSelectionsList->addItem(
"Negative to positive",
"" );
530 m_colorMapSelectionsList->addItem(
"Atlas",
"" );
531 m_colorMapSelectionsList->addItem(
"Blue-Green-Purple",
"" );
532 m_colorMapSelectionsList->addItem(
"Vector",
"" );
534 m_colorMap = m_properties->addProperty(
"Colormap",
"The colormap of this texture.", m_colorMapSelectionsList->getSelectorFirst() );
537 m_active = m_properties->addProperty(
"Active",
"Can dis-enable a texture.",
true );
540 m_texMatrix = m_properties->addProperty(
"Texture Transformation",
"Usable to transform the texture.", m );
541 m_texMatrix->setHidden();
542 m_texMatrix->setPurpose( PV_PURPOSE_INFORMATION );
544 TextureType::setResizeNonPowerOfTwoHint(
false );
550 TextureType::setFilter( osg::Texture::MIN_FILTER, m_interpolation->get(
true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
551 TextureType::setFilter( osg::Texture::MAG_FILTER, m_interpolation->get(
true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
554 template <
typename TextureType >
560 template <
typename TextureType >
566 template <
typename TextureType >
569 return m_infoProperties;
572 template <
typename TextureType >
578 template <
typename TextureType >
584 template <
typename TextureType >
590 template <
typename TextureType >
596 template <
typename TextureType >
602 template <
typename TextureType >
608 template <
typename TextureType >
611 return m_thresholdLower;
614 template <
typename TextureType >
617 return m_thresholdUpper;
620 template <
typename TextureType >
623 return m_thresholdEnabled;
626 template <
typename TextureType >
629 return m_interpolation;
632 template <
typename TextureType >
638 template <
typename TextureType >
644 template <
typename TextureType >
647 return m_windowEnabled;
650 template <
typename TextureType >
656 template <
typename TextureType >
662 template <
typename TextureType >
665 if( m_interpolation->changed() )
667 TextureType::setFilter( osg::Texture::MIN_FILTER, m_interpolation->get(
true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
668 TextureType::setFilter( osg::Texture::MAG_FILTER, m_interpolation->get(
true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
672 template <
typename TextureType >
688 template <
typename TextureType >
695 template <
typename TextureType >
701 template <
typename TextureType >
707 m_needCreate =
false;
709 TextureType::dirtyTextureObject();
713 template <
typename TextureType >
716 this->setFilter( osg::Texture2D::MIN_FILTER, mode );
717 this->setFilter( osg::Texture2D::MAG_FILTER, mode );
720 template <
typename TextureType >
723 this->setWrap( osg::Texture2D::WRAP_S, mode );
724 this->setWrap( osg::Texture2D::WRAP_T, mode );
725 this->setWrap( osg::Texture2D::WRAP_R, mode );
728 template <
typename TextureType >
731 texture->setTextureWidth( width );
734 template <
typename TextureType >
737 texture->setTextureSize( width, height );
740 template <
typename TextureType >
743 texture->setTextureSize( width, height, depth );
746 template <
typename TextureType >
752 template <
typename TextureType >
755 return std::numeric_limits< WPVBaseTypes::PV_INT >::max();
758 #endif // WGETEXTURE_H
boost::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
boost::shared_ptr< WItemSelection > m_colorMapSelectionsList
A list of color map selection types.
int32_t PV_INT
base type used for every WPVInt
virtual void handleUpdate()
Handles all property updates.
static WPVBaseTypes::PV_INT getUnsetSortIndex()
Get the index used to refer to an unset sort index.
WGETexture(double scale=1.0, double min=0.0)
Default constructor.
WPropInterval window() const
Returns the window level definition for the colormap.
WPropBool thresholdEnabled() const
Returns the property responsible for enabling threshold based clipping.
WPropBool m_active
True if the texture is active.
WPropDouble m_thresholdUpper
Threshold for clipping areas.
WPropInterval m_window
Window level setting for the current colormap.
boost::shared_ptr< WProperties > m_properties
The property object for the dataset.
WPropBool clipZero() const
Clip the values assumed to be zero.
WPropDouble thresholdUpper() const
Returns the threshold property.
virtual void create()
Creates the texture data.
virtual ~WGETexture()
Destructor.
WPropBool windowEnabled() const
Returns the property responsible for enabling window based interval scaling.
This callback allows you a simple usage of callbacks in your module.
This calls serves a simple purpose: have a texture and its scaling information together which allows ...
WPropInt sortIndex() const
The sorting index in the colormapper's texture list.
WPropString name() const
Returns the name property of the texture.
WPropBool m_clipZero
If set to true, zero values are clipped by making them transparent.
WPropMatrix4X4 m_texMatrix
The texture transformation matrix.
WPropBool m_windowEnabled
Window-Level-Setting-enable flag.
WPropBool interpolation() const
Returns the interpolation property.
boost::shared_ptr< WProperties > m_infoProperties
The property object for the dataset containing only props whose purpose is "PV_PURPOSE_INFORMNATION"...
WPropString m_name
The texture name.
osg::ref_ptr< WGETexture< TextureType > > RPtr
Convenience type for OSG reference pointer on WGETextures.
WPropDouble minimum() const
Get the minimum in the de-scaled value space.
boost::shared_ptr< WProperties > getInformationProperties() const
Return a pointer to the information properties object of the dataset.
WPropSelection colormap() const
Returns the colormap property.
void setWrapSTR(osg::Texture::WrapMode mode)
For all the lazy guys to set the wrapping for s,t and r directions at once.
Class to manage properties of an object and to provide convenience methods for easy access and manipu...
A class containing a list of named items.
WPropDouble thresholdLower() const
Returns the threshold property.
void setupProperties(double scale, double min)
Creates and assigns all properties.
static MatrixType identity()
Returns an identity matrix.
virtual WBoundingBox getBoundingBox() const
Returns the texture's bounding box.
void bind(osg::ref_ptr< osg::Node > node, size_t unit=0)
Binds the texture to the specified node and texture unit.
Class to encapsulate boost::condition_variable_any.
WPropDouble alpha() const
Returns the alpha property.
WPropDouble m_scale
The scaling factor to de-scale a [0-1] texture to original space.
WPropInt m_sortIdx
The sort index of the texture.
WPropDouble scale() const
Get the scaling factor for de-scaling the texture.
boost::shared_ptr< WProperties > getProperties() const
Return a pointer to the properties object of the dataset.
WPropDouble m_thresholdLower
Threshold for clipping areas.
WPropSelection m_colorMap
Selection property for color map.
WPropBool active() const
Returns the active property.
bool m_needCreate
If true, the texture gets created.
virtual void applyUniforms(std::string prefix, osg::StateSet *states) const
Applies some custom uniforms to the specified state-set which directly relate to this texture...
WPropBool m_interpolation
True if interpolation should be used.
virtual void updateCallback(osg::StateAttribute *state)
This method implements an update callback which updates the texture image if needed and several other...
WPropBool m_thresholdEnabled
Threshold-enable flag.
static std::size_t const MAX_TEXTURE_DIMENSION
The maximum texture dimension.
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.
static std::size_t const MAX_NUMBER_OF_TEXTURES
We support only 8 textures because some known hardware does not support more texture coordinates...
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,3D).
void setFilterMinMag(osg::Texture::FilterMode mode)
For all the lazy guys to set the filter MIN and MAG at once.
WPropDouble m_alpha
Alpha blending value.
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.
WPropMatrix4X4 transformation() const
Returns the texture transformation matrix.
WPropDouble m_min
The minimum of each value in the texture in unscaled space.