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
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.