OpenWalnut  1.4.0
WGETexture.h
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WGETEXTURE_H
00026 #define WGETEXTURE_H
00027 
00028 #include <string>
00029 #include <limits>
00030 
00031 #include <boost/shared_ptr.hpp>
00032 
00033 #include <osg/Node>
00034 #include <osg/StateSet>
00035 #include <osg/Texture>
00036 #include <osg/Texture1D>
00037 #include <osg/Texture2D>
00038 #include <osg/Texture3D>
00039 
00040 #include "callbacks/WGEFunctorCallback.h"
00041 #include "../common/WBoundingBox.h"
00042 #include "../common/WProperties.h"
00043 #include "../common/WPropertyTypes.h"
00044 #include "../common/WPropertyHelper.h"
00045 
00046 #include "WGETextureUtils.h"
00047 
00048 /**
00049  * This calls serves a simple purpose: have a texture and its scaling information together which allows very easy binding of textures to nodes
00050  * with associated shaders. When this texture gets bind using the bindTo methods, uniforms get added containing needed scaling information.
00051  */
00052 template < typename TextureType = osg::Texture >
00053 class WGETexture: public TextureType
00054 {
00055 public:
00056     /**
00057      * Convenience type for OSG reference pointer on WGETextures.
00058      */
00059     typedef osg::ref_ptr< WGETexture< TextureType > > RPtr;
00060 
00061     //! We support only 8 textures because some known hardware does not support more texture coordinates.
00062     static std::size_t const MAX_NUMBER_OF_TEXTURES = 8;
00063 
00064     //! The maximum texture dimension.
00065     static std::size_t const MAX_TEXTURE_DIMENSION = 2048;
00066 
00067     /**
00068      * Default constructor. Creates an empty instance of the texture.
00069      *
00070      * \param scale the scaling factor needed for de-scaling the texture values
00071      * \param min the minimum value allowing negative values too.
00072      */
00073     WGETexture( double scale = 1.0, double min = 0.0 );
00074 
00075     /**
00076      * Creates texture from given image. Scaling is set to identity.
00077      *
00078      * \param image the image to use as texture
00079      * \param scale the scaling factor needed for de-scaling the texture values
00080      * \param min the minimum value allowing negative values too.
00081      */
00082     WGETexture( osg::Image* image, double scale = 1.0, double min = 0.0 );
00083 
00084     /**
00085      * Copy the texture.
00086      *
00087      * \param texture the texture to copy
00088      * \param copyop
00089      */
00090     WGETexture( const WGETexture< TextureType >& texture, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY );
00091 
00092     /**
00093      * Destructor.
00094      */
00095     virtual ~WGETexture();
00096 
00097     /**
00098      * Returns the name property of the texture. You should set it if you create a texture.
00099      *
00100      * \return texture name property
00101      */
00102     WPropString name() const;
00103 
00104     /**
00105      * The sorting index in the colormapper's texture list.
00106      *
00107      * \return the property.
00108      */
00109     WPropInt sortIndex() const;
00110 
00111     /**
00112      * Get the index used to refer to an unset sort index.
00113      *
00114      * \return the value.
00115      */
00116     static WPVBaseTypes::PV_INT getUnsetSortIndex();
00117 
00118     /**
00119      * Get the minimum in the de-scaled value space. The property can be changed. A change affects all colormaps using this texture. But be
00120      * careful as the texture creating depends on these values.
00121      *
00122      * \return the minimum
00123      */
00124     WPropDouble minimum() const;
00125 
00126     /**
00127      * Get the scaling factor for de-scaling the texture. The property can be changed. A change affects all colormaps using this texture. But be
00128      * careful as the texture creating depends on these values.
00129      *
00130      * \return the scale
00131      */
00132     WPropDouble scale() const;
00133 
00134     /**
00135      * Returns the alpha property. The property can be changed. A change affects all colormaps using this texture.
00136      *
00137      * \return alpha property
00138      */
00139     WPropDouble alpha() const;
00140 
00141     /**
00142      * Clip the values assumed to be zero.
00143      *
00144      * \return true to clip.
00145      */
00146     WPropBool clipZero() const;
00147 
00148     /**
00149      * Returns the threshold property. The property can be changed. A change affects all colormaps using this texture.
00150      *
00151      * \return threshold property
00152      */
00153     WPropDouble thresholdLower() const;
00154 
00155     /**
00156      * Returns the threshold property. The property can be changed. A change affects all colormaps using this texture.
00157      *
00158      * \return threshold property
00159      */
00160     WPropDouble thresholdUpper() const;
00161 
00162     /**
00163      * Returns the property responsible for enabling threshold based clipping. If this is false, the threshold is ignored.
00164      *
00165      * \return threshold-enable property.
00166      */
00167     WPropBool thresholdEnabled() const;
00168 
00169     /**
00170      * Returns the interpolation property. The property can be changed. A change affects all colormaps using this texture.
00171      *
00172      * \return interpolation property
00173      */
00174     WPropBool interpolation() const;
00175 
00176     /**
00177      * Returns the colormap property. The property can be changed. A change affects all colormaps using this texture.
00178      *
00179      * \return colormap property
00180      */
00181     WPropSelection colormap() const;
00182 
00183     /**
00184      * Returns the active property. The property can be changed. A change affects all colormaps using this texture.
00185      *
00186      * \return active property
00187      */
00188     WPropBool active() const;
00189 
00190     /**
00191      * Returns the window level definition for the colormap. The property can be changed. A change affects all colormaps using this texture.
00192      *
00193      * \return window colormap
00194      */
00195     WPropInterval window() const;
00196 
00197     /**
00198      * Returns the property responsible for enabling window based interval scaling. If this is false, the window setting is ignored.
00199      *
00200      * \return windowing-enable property.
00201      */
00202     WPropBool windowEnabled() const;
00203 
00204     /**
00205      * Returns the texture transformation matrix. The property can be changed. A change affects all colormaps using this texture. This matrix
00206      * converts an world-space coordinate to an texture coordinate! This can be seen as a scaled inverse matrix of the grid's transformation.
00207      *
00208      * \return the matrix
00209      */
00210     WPropMatrix4X4 transformation() const;
00211 
00212     /**
00213      * Binds the texture to the specified node and texture unit. It also adds two uniforms: u_textureXMin and u_textureXScale, where X
00214      * is the unit number. This can be used in shaders to unscale it.
00215      *
00216      * \param node the node where to bind the texture to
00217      * \param unit the unit, by default 0
00218      */
00219     void bind( osg::ref_ptr< osg::Node > node, size_t unit = 0 );
00220 
00221     /**
00222      * Return a pointer to the properties object of the dataset. Add all the modifiable settings here. This allows the user to modify several
00223      * properties of a dataset.
00224      *
00225      * \return the properties.
00226      */
00227     boost::shared_ptr< WProperties > getProperties() const;
00228 
00229     /**
00230      * Return a pointer to the information properties object of the dataset. The dataset intends these properties to not be modified.
00231      *
00232      * \return the properties.
00233      */
00234     boost::shared_ptr< WProperties > getInformationProperties() const;
00235 
00236     /**
00237      * Applies some custom uniforms to the specified state-set which directly relate to this texture
00238      *
00239      * \param prefix the prefix used for the uniforms
00240      * \param states the state where to add the uniforms
00241      */
00242     virtual void applyUniforms( std::string prefix, osg::StateSet* states ) const;
00243 
00244     /**
00245      * For all the lazy guys to set the filter MIN and MAG at once.
00246      *
00247      * \param mode the new mode for MIN_FILTER and MAG_FILTER.
00248      */
00249     void setFilterMinMag( osg::Texture::FilterMode mode );
00250 
00251     /**
00252      * For all the lazy guys to set the wrapping for s,t and r directions at once.
00253      *
00254      * \param mode the new mode for WRAP_S, WRAP_T and WRAP_R.
00255      */
00256     void setWrapSTR( osg::Texture::WrapMode mode );
00257 
00258     /**
00259      * Returns the texture's bounding box. This is const. Although there exists the transformation() property, it is an information property and
00260      * can't be changed.
00261      *
00262      * \return the bounding box.
00263      */
00264     virtual WBoundingBox getBoundingBox() const;
00265 
00266 protected:
00267     /**
00268      * Handles all property updates. Called by m_propCondition.
00269      */
00270     virtual void handleUpdate();
00271 
00272     /**
00273      * Creates the texture data. Overwrite this method if you want to provide a custom texture creation procedure.
00274      */
00275     virtual void create();
00276 
00277     /**
00278      * This method implements an update callback which updates the texture image if needed and several other properties like texture matrix.
00279      *
00280      * \param state the state to update
00281      */
00282     virtual void updateCallback( osg::StateAttribute* state );
00283 
00284     /**
00285      * Initialize the size of the texture properly according to real texture type (1D,2D,3D).
00286      * \note This is needed because osg::Texture::setImage is not virtual and does not set the size from the image.
00287      *
00288      * \param texture the texture where to set the size
00289      * \param width the new width
00290      * \param height the new height
00291      * \param depth the new depth
00292      */
00293     static void initTextureSize( osg::Texture1D* texture, int width, int height, int depth );
00294 
00295     /**
00296      * Initialize the size of the texture properly according to real texture type (1D,2D,3D).
00297      * \note This is needed because osg::Texture::setImage is not virtual and does not set the size from the image.
00298      *
00299      * \param texture the texture where to set the size
00300      * \param width the new width
00301      * \param height the new height
00302      * \param depth the new depth
00303      */
00304     static void initTextureSize( osg::Texture2D* texture, int width, int height, int depth );
00305 
00306     /**
00307      * Initialize the size of the texture properly according to real texture type (1D,2D,3D).
00308      * \note This is needed because osg::Texture::setImage is not virtual and does not set the size from the image.
00309      *
00310      * \param texture the texture where to set the size
00311      * \param width the new width
00312      * \param height the new height
00313      * \param depth the new depth
00314      */
00315     static void initTextureSize( osg::Texture3D* texture, int width, int height, int depth );
00316 
00317 private:
00318     /**
00319      * Creates and assigns all properties.
00320      *
00321      * \param min the min value of the texture
00322      * \param scale the scale value of the texture
00323      */
00324     void setupProperties( double scale, double min );
00325 
00326     /**
00327      * A condition used to notify about changes in several properties.
00328      */
00329     boost::shared_ptr< WCondition > m_propCondition;
00330 
00331     /**
00332      * The property object for the dataset.
00333      */
00334     boost::shared_ptr< WProperties > m_properties;
00335 
00336     /**
00337      * The property object for the dataset containing only props whose purpose is "PV_PURPOSE_INFORMNATION". It is useful to define some property
00338      * to only be of informational nature. The GUI does not modify them. As it is a WProperties instance, you can use it the same way as
00339      * m_properties.
00340      */
00341     boost::shared_ptr< WProperties > m_infoProperties;
00342 
00343     /**
00344      * If true, the texture gets created. This is used to create texture on demand.
00345      */
00346     bool m_needCreate;
00347 
00348     /**
00349      * The texture name. This might be useful to identify textures.
00350      */
00351     WPropString m_name;
00352 
00353     /**
00354      * The sort index of the texture. This is important for restoring and saving the colormapper's sorting.
00355      */
00356     WPropInt m_sortIdx;
00357 
00358     /**
00359      * The minimum of each value in the texture in unscaled space.
00360      */
00361     WPropDouble m_min;
00362 
00363     /**
00364      * The scaling factor to de-scale a [0-1] texture to original space.
00365      */
00366     WPropDouble m_scale;
00367 
00368     /**
00369      * A list of color map selection types
00370      */
00371     boost::shared_ptr< WItemSelection > m_colorMapSelectionsList;
00372 
00373     /**
00374      * Selection property for color map
00375      */
00376     WPropSelection m_colorMap;
00377 
00378     /**
00379      * Alpha blending value.
00380      */
00381     WPropDouble m_alpha;
00382 
00383     /**
00384      * If set to true, zero values are clipped by making them transparent
00385      */
00386     WPropBool m_clipZero;
00387 
00388     /**
00389      * Threshold for clipping areas.
00390      */
00391     WPropDouble m_thresholdLower;
00392 
00393     /**
00394      * Threshold for clipping areas.
00395      */
00396     WPropDouble m_thresholdUpper;
00397 
00398     /**
00399      * Threshold-enable flag.
00400      */
00401     WPropBool m_thresholdEnabled;
00402 
00403     /**
00404      * True if interpolation should be used.
00405      */
00406     WPropBool m_interpolation;
00407 
00408     /**
00409      * True if the texture is active.
00410      */
00411     WPropBool m_active;
00412 
00413     /**
00414      * The texture transformation matrix.
00415      */
00416     WPropMatrix4X4 m_texMatrix;
00417 
00418     /**
00419      * Window level setting for the current colormap
00420      */
00421     WPropInterval m_window;
00422 
00423     /**
00424      * Window-Level-Setting-enable flag.
00425      */
00426     WPropBool m_windowEnabled;
00427 };
00428 
00429 // Some convenience typedefs
00430 
00431 /**
00432  * OSG's Texture1D with scaling features
00433  */
00434 typedef WGETexture< osg::Texture1D > WGETexture1D;
00435 
00436 /**
00437  * OSG's Texture2D with scaling features
00438  */
00439 typedef WGETexture< osg::Texture2D > WGETexture2D;
00440 
00441 /**
00442  * OSG's Texture3D with scaling features
00443  */
00444 typedef WGETexture< osg::Texture3D > WGETexture3D;
00445 
00446 
00447 template < typename TextureType >
00448 WGETexture< TextureType >::WGETexture( double scale, double min ):
00449     TextureType(),
00450     m_propCondition( boost::shared_ptr< WCondition >( new WCondition() ) ),
00451     m_properties( boost::shared_ptr< WProperties >( new WProperties( "Texture Properties", "Properties of a texture." ) ) ),
00452     m_infoProperties( boost::shared_ptr< WProperties >( new WProperties( "Texture Info Properties", "Texture's information properties." ) ) ),
00453     m_needCreate( true )
00454 {
00455     setupProperties( scale, min );
00456 }
00457 
00458 template < typename TextureType >
00459 WGETexture< TextureType >::WGETexture( osg::Image* image, double scale, double min ):
00460     TextureType( image ),
00461     m_propCondition( boost::shared_ptr< WCondition >( new WCondition() ) ),
00462     m_properties( boost::shared_ptr< WProperties >( new WProperties( "Texture Properties", "Properties of a texture." ) ) ),
00463     m_infoProperties( boost::shared_ptr< WProperties >( new WProperties( "Texture Info Properties", "Texture's information properties." ) ) ),
00464     m_needCreate( true )
00465 {
00466     setupProperties( scale, min );
00467     WGETexture< TextureType >::initTextureSize( this, image->s(), image->t(), image->r() );
00468 }
00469 
00470 template < typename TextureType >
00471 WGETexture< TextureType >::WGETexture( const WGETexture< TextureType >& texture, const osg::CopyOp& copyop ):
00472     TextureType( texture, copyop ),
00473     m_min( texture.m_min ),
00474     m_scale( texture.m_scale )
00475 {
00476     // initialize members
00477 }
00478 
00479 template < typename TextureType >
00480 void WGETexture< TextureType >::setupProperties( double scale, double min )
00481 {
00482     m_propCondition->subscribeSignal( boost::bind( &WGETexture< TextureType >::handleUpdate, this ) );
00483 
00484     m_name = m_properties->addProperty( "Name", "The name of the texture.", std::string( "Unnamed" ) );
00485 
00486     m_sortIdx = m_properties->addProperty( "Sort Index",
00487                                            "The index specifies the index in the colormapper, used to restore colormapper sorting on load.",
00488                                            getUnsetSortIndex() );
00489     m_sortIdx->setHidden( true );
00490 
00491     // initialize members
00492     m_min = m_properties->addProperty( "Minimum", "The minimum value in the original space.", min, true );
00493     m_min->removeConstraint( m_min->getMin() );
00494     m_min->removeConstraint( m_min->getMax() );
00495 
00496     m_scale = m_properties->addProperty( "Scale", "The scaling factor to un-scale the texture values to the original space.", scale, true );
00497     m_scale->removeConstraint( m_scale->getMin() );
00498     m_scale->removeConstraint( m_scale->getMax() );
00499 
00500     m_alpha = m_properties->addProperty( "Alpha", "The alpha blending value.", 1.0 );
00501     m_alpha->setMin( 0.0 );
00502     m_alpha->setMax( 1.0 );
00503 
00504     m_clipZero = m_properties->addProperty( "Enable Zero Clip", "If enabled, zero values are clipped.", true );
00505 
00506     m_thresholdEnabled = m_properties->addProperty( "Enable Threshold",
00507                                                     "If enabled, threshold based clipping is used. If not, threshold is ignored.", false );
00508 
00509     m_thresholdLower = m_properties->addProperty( "Lower Threshold", "The threshold used to clip areas below the specified value.", 0.0 );
00510     m_thresholdLower->setMin( min );
00511     m_thresholdLower->setMax( min + scale );
00512 
00513     m_thresholdUpper = m_properties->addProperty( "Upper Threshold", "The threshold used to clip areas above the specified value.", 1.0 );
00514     m_thresholdUpper->setMin( min );
00515     m_thresholdUpper->setMax( min + scale );
00516 
00517     m_windowEnabled = m_properties->addProperty( "Enable Windowing", "If enabled, window level settings are applied.", false );
00518     m_window = m_properties->addProperty( "Window Level", "Define the interval in the data which is mapped to the colormap.",
00519                                           make_interval( 0.0, 1.0 ) );
00520 
00521     m_interpolation = m_properties->addProperty( "Interpolate", "Interpolation of the volume data.", true, m_propCondition );
00522 
00523     m_colorMapSelectionsList = boost::shared_ptr< WItemSelection >( new WItemSelection() );
00524     m_colorMapSelectionsList->addItem( "Grayscale", "" );
00525     m_colorMapSelectionsList->addItem( "Rainbow", "" );
00526     m_colorMapSelectionsList->addItem( "Hot iron", "" );
00527     m_colorMapSelectionsList->addItem( "Negative to positive", "" );
00528     m_colorMapSelectionsList->addItem( "Atlas", "" );
00529     m_colorMapSelectionsList->addItem( "Blue-Green-Purple", "" );
00530     m_colorMapSelectionsList->addItem( "Vector", "" );
00531 
00532     m_colorMap = m_properties->addProperty( "Colormap", "The colormap of this texture.", m_colorMapSelectionsList->getSelectorFirst() );
00533     WPropertyHelper::PC_SELECTONLYONE::addTo( m_colorMap );
00534 
00535     m_active = m_properties->addProperty( "Active", "Can dis-enable a texture.", true );
00536 
00537     WMatrix4d m = WMatrix4d::identity();
00538     m_texMatrix = m_properties->addProperty( "Texture Transformation", "Usable to transform the texture.", m );
00539     m_texMatrix->setHidden();
00540     m_texMatrix->setPurpose( PV_PURPOSE_INFORMATION );
00541 
00542     TextureType::setResizeNonPowerOfTwoHint( false );
00543     TextureType::setUpdateCallback( new WGEFunctorCallback< osg::StateAttribute >(
00544         boost::bind( &WGETexture< TextureType >::updateCallback, this, _1 ) )
00545     );
00546 
00547     // init filters
00548     TextureType::setFilter( osg::Texture::MIN_FILTER, m_interpolation->get( true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
00549     TextureType::setFilter( osg::Texture::MAG_FILTER, m_interpolation->get( true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
00550 }
00551 
00552 template < typename TextureType >
00553 WGETexture< TextureType >::~WGETexture()
00554 {
00555     // cleanup.
00556 }
00557 
00558 template < typename TextureType >
00559 boost::shared_ptr< WProperties > WGETexture< TextureType >::getProperties() const
00560 {
00561     return m_properties;
00562 }
00563 
00564 template < typename TextureType >
00565 boost::shared_ptr< WProperties > WGETexture< TextureType >::getInformationProperties() const
00566 {
00567     return m_infoProperties;
00568 }
00569 
00570 template < typename TextureType >
00571 inline WPropString WGETexture< TextureType >::name() const
00572 {
00573     return m_name;
00574 }
00575 
00576 template < typename TextureType >
00577 inline WPropInt WGETexture< TextureType >::sortIndex() const
00578 {
00579     return m_sortIdx;
00580 }
00581 
00582 template < typename TextureType >
00583 inline WPropDouble WGETexture< TextureType >::minimum() const
00584 {
00585     return m_min;
00586 }
00587 
00588 template < typename TextureType >
00589 inline WPropDouble WGETexture< TextureType >::scale() const
00590 {
00591     return m_scale;
00592 }
00593 
00594 template < typename TextureType >
00595 inline WPropDouble WGETexture< TextureType >::alpha() const
00596 {
00597     return m_alpha;
00598 }
00599 
00600 template < typename TextureType >
00601 inline WPropBool WGETexture< TextureType >::clipZero() const
00602 {
00603     return m_clipZero;
00604 }
00605 
00606 template < typename TextureType >
00607 inline WPropDouble WGETexture< TextureType >::thresholdLower() const
00608 {
00609     return m_thresholdLower;
00610 }
00611 
00612 template < typename TextureType >
00613 inline WPropDouble WGETexture< TextureType >::thresholdUpper() const
00614 {
00615     return m_thresholdUpper;
00616 }
00617 
00618 template < typename TextureType >
00619 inline WPropBool WGETexture< TextureType >::thresholdEnabled() const
00620 {
00621     return m_thresholdEnabled;
00622 }
00623 
00624 template < typename TextureType >
00625 inline WPropBool WGETexture< TextureType >::interpolation() const
00626 {
00627     return m_interpolation;
00628 }
00629 
00630 template < typename TextureType >
00631 inline WPropSelection WGETexture< TextureType >::colormap() const
00632 {
00633     return m_colorMap;
00634 }
00635 
00636 template < typename TextureType >
00637 inline WPropBool WGETexture< TextureType >::active() const
00638 {
00639     return m_active;
00640 }
00641 
00642 template < typename TextureType >
00643 inline WPropBool WGETexture< TextureType >::windowEnabled() const
00644 {
00645     return m_windowEnabled;
00646 }
00647 
00648 template < typename TextureType >
00649 inline WPropInterval WGETexture< TextureType >::window() const
00650 {
00651     return m_window;
00652 }
00653 
00654 template < typename TextureType >
00655 inline WPropMatrix4X4 WGETexture< TextureType >::transformation() const
00656 {
00657     return m_texMatrix;
00658 }
00659 
00660 template < typename TextureType >
00661 void  WGETexture< TextureType >::handleUpdate()
00662 {
00663     if( m_interpolation->changed() )
00664     {
00665         TextureType::setFilter( osg::Texture::MIN_FILTER, m_interpolation->get( true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
00666         TextureType::setFilter( osg::Texture::MAG_FILTER, m_interpolation->get( true ) ? osg::Texture::LINEAR : osg::Texture::NEAREST );
00667     }
00668 }
00669 
00670 template < typename TextureType >
00671 void  WGETexture< TextureType >::applyUniforms( std::string prefix, osg::StateSet* states ) const
00672 {
00673     states->addUniform( new WGEPropertyUniform< WPropDouble >( prefix + "Min", minimum() ) );
00674     states->addUniform( new WGEPropertyUniform< WPropDouble >( prefix + "Scale", scale() ) );
00675     states->addUniform( new WGEPropertyUniform< WPropDouble >( prefix + "Alpha", alpha() ) );
00676     states->addUniform( new WGEPropertyUniform< WPropBool >( prefix + "ClipZeroEnabled", clipZero() ) );
00677     states->addUniform( new WGEPropertyUniform< WPropBool >( prefix + "ThresholdEnabled", thresholdEnabled() ) );
00678     states->addUniform( new WGEPropertyUniform< WPropDouble >( prefix + "ThresholdLower", thresholdLower() ) );
00679     states->addUniform( new WGEPropertyUniform< WPropDouble >( prefix + "ThresholdUpper", thresholdUpper() ) );
00680     states->addUniform( new WGEPropertyUniform< WPropSelection >( prefix + "Colormap", colormap() ) );
00681     states->addUniform( new WGEPropertyUniform< WPropBool >( prefix + "Active", active() ) );
00682     states->addUniform( new WGEPropertyUniform< WPropBool >( prefix + "WindowEnabled", windowEnabled() ) );
00683     states->addUniform( new WGEPropertyUniform< WPropInterval >( prefix + "Window", window() ) );
00684 }
00685 
00686 template < typename TextureType >
00687 void WGETexture< TextureType >::bind( osg::ref_ptr< osg::Node > node, size_t unit )
00688 {
00689     // let our utilities do the work
00690     wge::bindTexture( node, osg::ref_ptr< WGETexture< TextureType > >( this ), unit ); // to avoid recursive stuff -> explicitly specify the type
00691 }
00692 
00693 template < typename TextureType >
00694 void WGETexture< TextureType >::create()
00695 {
00696     // do nothing. Derived classes may implement this.
00697 }
00698 
00699 template < typename TextureType >
00700 void WGETexture< TextureType >::updateCallback( osg::StateAttribute* /*state*/ )
00701 {
00702     // create if not done yet
00703     if( m_needCreate )
00704     {
00705         m_needCreate = false;
00706         create();
00707         TextureType::dirtyTextureObject();
00708     }
00709 }
00710 
00711 template < typename TextureType >
00712 void WGETexture< TextureType >::setFilterMinMag( osg::Texture::FilterMode mode )
00713 {
00714     this->setFilter( osg::Texture2D::MIN_FILTER, mode );
00715     this->setFilter( osg::Texture2D::MAG_FILTER, mode );
00716 }
00717 
00718 template < typename TextureType >
00719 void WGETexture< TextureType >::setWrapSTR( osg::Texture::WrapMode mode )
00720 {
00721     this->setWrap( osg::Texture2D::WRAP_S, mode );
00722     this->setWrap( osg::Texture2D::WRAP_T, mode );
00723     this->setWrap( osg::Texture2D::WRAP_R, mode );
00724 }
00725 
00726 template < typename TextureType >
00727 void WGETexture< TextureType >::initTextureSize( osg::Texture1D* texture, int width, int /*height*/, int /*depth*/ )
00728 {
00729     texture->setTextureWidth( width );
00730 }
00731 
00732 template < typename TextureType >
00733 void WGETexture< TextureType >::initTextureSize( osg::Texture2D* texture, int width, int height, int /*depth*/ )
00734 {
00735     texture->setTextureSize( width, height );
00736 }
00737 
00738 template < typename TextureType >
00739 void WGETexture< TextureType >::initTextureSize( osg::Texture3D* texture, int width, int height, int depth )
00740 {
00741     texture->setTextureSize( width, height, depth );
00742 }
00743 
00744 template < typename TextureType >
00745 WBoundingBox WGETexture< TextureType >::getBoundingBox() const
00746 {
00747     return WBoundingBox( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 );
00748 }
00749 
00750 template < typename TextureType >
00751 WPVBaseTypes::PV_INT WGETexture< TextureType >::getUnsetSortIndex()
00752 {
00753     return std::numeric_limits< WPVBaseTypes::PV_INT >::max();
00754 }
00755 
00756 #endif  // WGETEXTURE_H
00757