33 #include <osg/StateSet>
34 #include <osg/Texture1D>
35 #include <osg/Texture2D>
36 #include <osg/Texture3D>
37 #include <osg/Texture>
39 #include "../common/WBoundingBox.h"
40 #include "../common/WProperties.h"
41 #include "../common/WPropertyHelper.h"
42 #include "../common/WPropertyTypes.h"
44 #include "WGETextureUtils.h"
45 #include "callbacks/WGEFunctorCallback.h"
51 template <
typename TextureType = osg::Texture >
58 typedef osg::ref_ptr< WGETexture< TextureType > >
RPtr;
63 typedef osg::ref_ptr< WGETexture< TextureType > >
SPtr;
115 WPropString
name()
const;
145 WPropDouble
scale()
const;
152 WPropDouble
alpha()
const;
208 WPropInterval
window()
const;
232 void bind( osg::ref_ptr< osg::Node > node,
size_t unit = 0 );
255 virtual void applyUniforms( std::string prefix, osg::StateSet* states )
const;
269 void setWrapSTR( osg::Texture::WrapMode mode );
313 static void initTextureSize( osg::Texture1D* texture,
int width,
int height,
int depth );
324 static void initTextureSize( osg::Texture2D* texture,
int width,
int height,
int depth );
335 static void initTextureSize( osg::Texture3D* texture,
int width,
int height,
int depth );
467 template <
typename TextureType >
471 m_properties( std::shared_ptr<
WProperties >( new
WProperties(
"Texture Properties",
"Properties of a texture." ) ) ),
472 m_infoProperties( std::shared_ptr<
WProperties >( new
WProperties(
"Texture Info Properties",
"Texture's information properties." ) ) ),
478 template <
typename TextureType >
480 TextureType( image ),
482 m_properties( std::shared_ptr<
WProperties >( new
WProperties(
"Texture Properties",
"Properties of a texture." ) ) ),
483 m_infoProperties( std::shared_ptr<
WProperties >( new
WProperties(
"Texture Info Properties",
"Texture's information properties." ) ) ),
490 template <
typename TextureType >
492 TextureType( image->getAsOSGImage() ),
494 m_properties( std::shared_ptr<
WProperties >( new
WProperties(
"Texture Properties",
"Properties of a texture." ) ) ),
495 m_infoProperties( std::shared_ptr<
WProperties >( new
WProperties(
"Texture Info Properties",
"Texture's information properties." ) ) ),
502 template <
typename TextureType >
504 TextureType( texture, copyop ),
505 m_min( texture.m_min ),
506 m_scale( texture.m_scale )
511 template <
typename TextureType >
516 m_name = m_properties->addProperty(
"Name",
"The name of the texture.", std::string(
"Unnamed" ) );
518 m_sortIdx = m_properties->addProperty(
"Sort Index",
519 "The index specifies the index in the colormapper, used to restore colormapper sorting on load.",
520 getUnsetSortIndex() );
521 m_sortIdx->setHidden(
true );
524 m_min = m_properties->addProperty(
"Minimum",
"The minimum value in the original space.", min,
true );
525 m_min->removeConstraint( m_min->getMin() );
526 m_min->removeConstraint( m_min->getMax() );
528 m_scale = m_properties->addProperty(
"Scale",
"The scaling factor to un-scale the texture values to the original space.", scale,
true );
529 m_scale->removeConstraint( m_scale->getMin() );
530 m_scale->removeConstraint( m_scale->getMax() );
532 m_alpha = m_properties->addProperty(
"Alpha",
"The alpha blending value.", 1.0 );
533 m_alpha->setMin( 0.0 );
534 m_alpha->setMax( 1.0 );
536 m_clipZero = m_properties->addProperty(
"Enable zero clip",
"If enabled, zero values are clipped.",
true );
538 m_thresholdEnabled = m_properties->addProperty(
"Enable threshold",
539 "If enabled, threshold based clipping is used. If not, threshold is ignored.",
false );
541 m_thresholdLower = m_properties->addProperty(
"Lower threshold",
"The threshold used to clip areas below the specified value.", 0.0 );
542 m_thresholdLower->setMin( min );
543 m_thresholdLower->setMax( min + scale );
545 m_thresholdUpper = m_properties->addProperty(
"Upper threshold",
"The threshold used to clip areas above the specified value.", 1.0 );
546 m_thresholdUpper->setMin( min );
547 m_thresholdUpper->setMax( min + scale );
549 m_windowEnabled = m_properties->addProperty(
"Enable windowing",
"If enabled, window level settings are applied.",
false );
550 m_window = m_properties->addProperty(
"Window level",
"Define the interval in the data which is mapped to the colormap.",
551 make_interval( 0.0, 1.0 ) );
553 m_interpolation = m_properties->addProperty(
"Interpolate",
"Interpolation of the volume data.",
true, m_propCondition );
555 m_colorMapSelectionsList = std::shared_ptr< WItemSelection >(
new WItemSelection() );
556 m_colorMapSelectionsList->addItem(
"Grayscale",
"" );
557 m_colorMapSelectionsList->addItem(
"Rainbow",
"" );
558 m_colorMapSelectionsList->addItem(
"Hot iron",
"" );
559 m_colorMapSelectionsList->addItem(
"Negative to positive",
"" );
560 m_colorMapSelectionsList->addItem(
"Atlas",
"" );
561 m_colorMapSelectionsList->addItem(
"Blue-Green-Purple",
"" );
562 m_colorMapSelectionsList->addItem(
"Vector",
"" );
564 m_colorMap = m_properties->addProperty(
"Colormap",
"The colormap of this texture.", m_colorMapSelectionsList->getSelectorFirst() );
567 m_active = m_properties->addProperty(
"Active",
"Can dis-enable a texture.",
true );
570 m_texMatrix = m_properties->addProperty(
"Texture Transformation",
"Usable to transform the texture.", m );
571 m_texMatrix->setHidden();
572 m_texMatrix->setPurpose( PV_PURPOSE_INFORMATION );
574 TextureType::setResizeNonPowerOfTwoHint(
false );
580 TextureType::setFilter( osg::Texture::MIN_FILTER, m_interpolation->get(
true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
581 TextureType::setFilter( osg::Texture::MAG_FILTER, m_interpolation->get(
true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
584 template <
typename TextureType >
590 template <
typename TextureType >
596 template <
typename TextureType >
599 return m_infoProperties;
602 template <
typename TextureType >
608 template <
typename TextureType >
614 template <
typename TextureType >
620 template <
typename TextureType >
626 template <
typename TextureType >
632 template <
typename TextureType >
638 template <
typename TextureType >
641 return m_thresholdLower;
644 template <
typename TextureType >
647 return m_thresholdUpper;
650 template <
typename TextureType >
653 return m_thresholdEnabled;
656 template <
typename TextureType >
659 return m_interpolation;
662 template <
typename TextureType >
668 template <
typename TextureType >
674 template <
typename TextureType >
677 return m_windowEnabled;
680 template <
typename TextureType >
686 template <
typename TextureType >
692 template <
typename TextureType >
695 if( m_interpolation->changed() )
697 TextureType::setFilter( osg::Texture::MIN_FILTER, m_interpolation->get(
true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
698 TextureType::setFilter( osg::Texture::MAG_FILTER, m_interpolation->get(
true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
702 template <
typename TextureType >
718 template <
typename TextureType >
725 template <
typename TextureType >
731 template <
typename TextureType >
737 m_needCreate =
false;
739 TextureType::dirtyTextureObject();
743 template <
typename TextureType >
746 this->setFilter( osg::Texture2D::MIN_FILTER, mode );
747 this->setFilter( osg::Texture2D::MAG_FILTER, mode );
750 template <
typename TextureType >
753 this->setWrap( osg::Texture2D::WRAP_S, mode );
754 this->setWrap( osg::Texture2D::WRAP_T, mode );
755 this->setWrap( osg::Texture2D::WRAP_R, mode );
758 template <
typename TextureType >
761 texture->setTextureWidth( width );
764 template <
typename TextureType >
767 texture->setTextureSize( width, height );
770 template <
typename TextureType >
773 texture->setTextureSize( width, height, depth );
776 template <
typename TextureType >
782 template <
typename TextureType >
785 m_name->set( from->m_name->get() );
786 m_sortIdx->set( from->m_sortIdx->get() );
788 m_min->set( from->m_min->get() );
789 m_scale->set( from->m_scale->get() );
790 m_alpha->set( from->m_alpha->get() );
791 m_clipZero->set( from->m_clipZero->get() );
792 m_thresholdEnabled->set( from->m_thresholdEnabled->get() );
793 m_thresholdLower->set( from->m_thresholdLower->get() );
794 m_thresholdUpper->set( from->m_thresholdUpper->get() );
795 m_windowEnabled->set( from->m_windowEnabled->get() );
796 m_window->set( from->m_window->get() );
797 m_interpolation->set( from->m_interpolation->get() );
799 m_colorMapSelectionsList = from->m_colorMapSelectionsList;
800 m_colorMap->set( from->m_colorMap->get() );
802 m_active->set( from->m_active->get() );
805 template <
typename TextureType >
808 return std::numeric_limits< WPVBaseTypes::PV_INT >::max();
Class to encapsulate boost::condition_variable_any.
This callback allows you a simple usage of callbacks in your module.
std::shared_ptr< WGEImage > SPtr
Convenience typedef for a std::shared_ptr< WGEImage >.
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.
WPropBool m_thresholdEnabled
Threshold-enable flag.
osg::ref_ptr< WGETexture< TextureType > > SPtr
Convenience type for OSG reference pointer on WGETextures.
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_windowEnabled
Window-Level-Setting-enable flag.
bool m_needCreate
If true, the texture gets created.
WPropDouble alpha() const
Returns the alpha property.
WPropDouble m_thresholdLower
Threshold for clipping areas.
static std::size_t const MAX_NUMBER_OF_TEXTURES
We support only 8 textures because some known hardware does not support more texture coordinates.
void setWrapSTR(osg::Texture::WrapMode mode)
For all the lazy guys to set the wrapping for s,t and r directions at once.
WPropDouble minimum() const
Get the minimum in the de-scaled value space.
virtual WBoundingBox getBoundingBox() const
Returns the texture's bounding box.
WPropDouble thresholdUpper() const
Returns the threshold property.
WPropSelection m_colorMap
Selection property for color map.
WPropString name() const
Returns the name property of the texture.
WPropBool m_interpolation
True if interpolation should be used.
virtual ~WGETexture()
Destructor.
WPropBool windowEnabled() const
Returns the property responsible for enabling window based interval scaling.
static std::size_t const MAX_TEXTURE_DIMENSION
The maximum texture dimension.
WPropBool m_active
True if the texture is active.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
std::shared_ptr< WProperties > m_infoProperties
The property object for the dataset containing only props whose purpose is "PV_PURPOSE_INFORMNATION".
WPropDouble m_alpha
Alpha blending value.
virtual void updateCallback(osg::StateAttribute *state)
This method implements an update callback which updates the texture image if needed and several other...
WPropDouble m_thresholdUpper
Threshold for clipping areas.
WPropBool active() const
Returns the active property.
void setupProperties(double scale, double min)
Creates and assigns all properties.
WPropMatrix4X4 transformation() const
Returns the texture transformation matrix.
osg::ref_ptr< WGETexture< TextureType > > RPtr
Convenience type for OSG reference pointer on WGETextures.
WPropBool interpolation() const
Returns the interpolation property.
WPropInterval m_window
Window level setting for the current colormap.
void bind(osg::ref_ptr< osg::Node > node, size_t unit=0)
Binds the texture to the specified node and texture unit.
WPropBool clipZero() const
Clip the values assumed to be zero.
void setFilterMinMag(osg::Texture::FilterMode mode)
For all the lazy guys to set the filter MIN and MAG at once.
WGETexture(double scale=1.0, double min=0.0)
Default constructor.
WPropString m_name
The texture name.
WPropInt m_sortIdx
The sort index of the texture.
std::shared_ptr< WProperties > getProperties() const
Return a pointer to the properties object of the dataset.
WPropDouble thresholdLower() const
Returns the threshold property.
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.
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 WPVBaseTypes::PV_INT getUnsetSortIndex()
Get the index used to refer to an unset sort index.
WPropInt sortIndex() const
The sorting index in the colormapper's texture list.
WPropSelection colormap() const
Returns the colormap property.
virtual void create()
Creates the texture data.
virtual void handleUpdate()
Handles all property updates.
WPropDouble m_scale
The scaling factor to de-scale a [0-1] texture to original space.
std::shared_ptr< WProperties > getInformationProperties() const
Return a pointer to the information properties object of the dataset.
WPropMatrix4X4 m_texMatrix
The texture transformation matrix.
WPropDouble m_min
The minimum of each value in the texture in unscaled space.
std::shared_ptr< WItemSelection > m_colorMapSelectionsList
A list of color map selection types.
std::shared_ptr< WProperties > m_properties
The property object for the dataset.
virtual void copyPropertiesExceptTransformation(osg::ref_ptr< WGETexture< TextureType > > const &from)
Copy the values of all properties except the texture transformation into the properties of this textu...
WPropBool m_clipZero
If set to true, zero values are clipped by making them transparent.
A class containing a list of named items.
static MatrixType identity()
Returns an identity matrix.
Class to manage properties of an object and to provide convenience methods for easy access and manipu...
int32_t PV_INT
base type used for every WPVInt
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.
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.