OpenWalnut  1.5.0dev
WGETexture.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WGETEXTURE_H
26 #define WGETEXTURE_H
27 
28 #include <limits>
29 #include <memory>
30 #include <string>
31 
32 #include <osg/Node>
33 #include <osg/StateSet>
34 #include <osg/Texture1D>
35 #include <osg/Texture2D>
36 #include <osg/Texture3D>
37 #include <osg/Texture>
38 
39 #include "../common/WBoundingBox.h"
40 #include "../common/WProperties.h"
41 #include "../common/WPropertyHelper.h"
42 #include "../common/WPropertyTypes.h"
43 #include "WGEImage.h"
44 #include "WGETextureUtils.h"
45 #include "callbacks/WGEFunctorCallback.h"
46 
47 /**
48  * This calls serves a simple purpose: have a texture and its scaling information together which allows very easy binding of textures to nodes
49  * with associated shaders. When this texture gets bind using the bindTo methods, uniforms get added containing needed scaling information.
50  */
51 template < typename TextureType = osg::Texture >
52 class WGETexture: public TextureType
53 {
54 public:
55  /**
56  * Convenience type for OSG reference pointer on WGETextures.
57  */
58  typedef osg::ref_ptr< WGETexture< TextureType > > RPtr;
59 
60  /**
61  * Convenience type for OSG reference pointer on WGETextures. OW conform name.
62  */
63  typedef osg::ref_ptr< WGETexture< TextureType > > SPtr;
64 
65  //! We support only 8 textures because some known hardware does not support more texture coordinates.
66  static std::size_t const MAX_NUMBER_OF_TEXTURES = 8;
67 
68  //! The maximum texture dimension.
69  static std::size_t const MAX_TEXTURE_DIMENSION = 2048;
70 
71  /**
72  * Default constructor. Creates an empty instance of the texture.
73  *
74  * \param scale the scaling factor needed for de-scaling the texture values
75  * \param min the minimum value allowing negative values too.
76  */
77  WGETexture( double scale = 1.0, double min = 0.0 );
78 
79  /**
80  * Creates texture from given image. Scaling is set to identity.
81  *
82  * \param image the image to use as texture
83  * \param scale the scaling factor needed for de-scaling the texture values
84  * \param min the minimum value allowing negative values too.
85  */
86  WGETexture( WGEImage::SPtr image, double scale = 1.0, double min = 0.0 );
87 
88  /**
89  * Creates texture from given image. Scaling is set to identity.
90  *
91  * \param image the image to use as texture
92  * \param scale the scaling factor needed for de-scaling the texture values
93  * \param min the minimum value allowing negative values too.
94  */
95  WGETexture( osg::Image* image, double scale = 1.0, double min = 0.0 );
96 
97  /**
98  * Copy the texture.
99  *
100  * \param texture the texture to copy
101  * \param copyop
102  */
103  WGETexture( const WGETexture< TextureType >& texture, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY );
104 
105  /**
106  * Destructor.
107  */
108  virtual ~WGETexture();
109 
110  /**
111  * Returns the name property of the texture. You should set it if you create a texture.
112  *
113  * \return texture name property
114  */
115  WPropString name() const;
116 
117  /**
118  * The sorting index in the colormapper's texture list.
119  *
120  * \return the property.
121  */
122  WPropInt sortIndex() const;
123 
124  /**
125  * Get the index used to refer to an unset sort index.
126  *
127  * \return the value.
128  */
130 
131  /**
132  * Get the minimum in the de-scaled value space. The property can be changed. A change affects all colormaps using this texture. But be
133  * careful as the texture creating depends on these values.
134  *
135  * \return the minimum
136  */
137  WPropDouble minimum() const;
138 
139  /**
140  * Get the scaling factor for de-scaling the texture. The property can be changed. A change affects all colormaps using this texture. But be
141  * careful as the texture creating depends on these values.
142  *
143  * \return the scale
144  */
145  WPropDouble scale() const;
146 
147  /**
148  * Returns the alpha property. The property can be changed. A change affects all colormaps using this texture.
149  *
150  * \return alpha property
151  */
152  WPropDouble alpha() const;
153 
154  /**
155  * Clip the values assumed to be zero.
156  *
157  * \return true to clip.
158  */
159  WPropBool clipZero() const;
160 
161  /**
162  * Returns the threshold property. The property can be changed. A change affects all colormaps using this texture.
163  *
164  * \return threshold property
165  */
166  WPropDouble thresholdLower() const;
167 
168  /**
169  * Returns the threshold property. The property can be changed. A change affects all colormaps using this texture.
170  *
171  * \return threshold property
172  */
173  WPropDouble thresholdUpper() const;
174 
175  /**
176  * Returns the property responsible for enabling threshold based clipping. If this is false, the threshold is ignored.
177  *
178  * \return threshold-enable property.
179  */
180  WPropBool thresholdEnabled() const;
181 
182  /**
183  * Returns the interpolation property. The property can be changed. A change affects all colormaps using this texture.
184  *
185  * \return interpolation property
186  */
187  WPropBool interpolation() const;
188 
189  /**
190  * Returns the colormap property. The property can be changed. A change affects all colormaps using this texture.
191  *
192  * \return colormap property
193  */
194  WPropSelection colormap() const;
195 
196  /**
197  * Returns the active property. The property can be changed. A change affects all colormaps using this texture.
198  *
199  * \return active property
200  */
201  WPropBool active() const;
202 
203  /**
204  * Returns the window level definition for the colormap. The property can be changed. A change affects all colormaps using this texture.
205  *
206  * \return window colormap
207  */
208  WPropInterval window() const;
209 
210  /**
211  * Returns the property responsible for enabling window based interval scaling. If this is false, the window setting is ignored.
212  *
213  * \return windowing-enable property.
214  */
215  WPropBool windowEnabled() const;
216 
217  /**
218  * Returns the texture transformation matrix. The property can be changed. A change affects all colormaps using this texture. This matrix
219  * converts an world-space coordinate to an texture coordinate! This can be seen as a scaled inverse matrix of the grid's transformation.
220  *
221  * \return the matrix
222  */
223  WPropMatrix4X4 transformation() const;
224 
225  /**
226  * Binds the texture to the specified node and texture unit. It also adds two uniforms: u_textureXMin and u_textureXScale, where X
227  * is the unit number. This can be used in shaders to unscale it.
228  *
229  * \param node the node where to bind the texture to
230  * \param unit the unit, by default 0
231  */
232  void bind( osg::ref_ptr< osg::Node > node, size_t unit = 0 );
233 
234  /**
235  * Return a pointer to the properties object of the dataset. Add all the modifiable settings here. This allows the user to modify several
236  * properties of a dataset.
237  *
238  * \return the properties.
239  */
240  std::shared_ptr< WProperties > getProperties() const;
241 
242  /**
243  * Return a pointer to the information properties object of the dataset. The dataset intends these properties to not be modified.
244  *
245  * \return the properties.
246  */
247  std::shared_ptr< WProperties > getInformationProperties() const;
248 
249  /**
250  * Applies some custom uniforms to the specified state-set which directly relate to this texture
251  *
252  * \param prefix the prefix used for the uniforms
253  * \param states the state where to add the uniforms
254  */
255  virtual void applyUniforms( std::string prefix, osg::StateSet* states ) const;
256 
257  /**
258  * For all the lazy guys to set the filter MIN and MAG at once.
259  *
260  * \param mode the new mode for MIN_FILTER and MAG_FILTER.
261  */
262  void setFilterMinMag( osg::Texture::FilterMode mode );
263 
264  /**
265  * For all the lazy guys to set the wrapping for s,t and r directions at once.
266  *
267  * \param mode the new mode for WRAP_S, WRAP_T and WRAP_R.
268  */
269  void setWrapSTR( osg::Texture::WrapMode mode );
270 
271  /**
272  * Returns the texture's bounding box. This is const. Although there exists the transformation() property, it is an information property and
273  * can't be changed.
274  *
275  * \return the bounding box.
276  */
277  virtual WBoundingBox getBoundingBox() const;
278 
279  /**
280  * Copy the values of all properties except the texture transformation into the properties of this texture.
281  *
282  * \param from The texture to copy property values from.
283  */
284  virtual void copyPropertiesExceptTransformation( osg::ref_ptr< WGETexture< TextureType > > const& from );
285 
286 protected:
287  /**
288  * Handles all property updates. Called by m_propCondition.
289  */
290  virtual void handleUpdate();
291 
292  /**
293  * Creates the texture data. Overwrite this method if you want to provide a custom texture creation procedure.
294  */
295  virtual void create();
296 
297  /**
298  * This method implements an update callback which updates the texture image if needed and several other properties like texture matrix.
299  *
300  * \param state the state to update
301  */
302  virtual void updateCallback( osg::StateAttribute* state );
303 
304  /**
305  * Initialize the size of the texture properly according to real texture type (1D,2D,3D).
306  * \note This is needed because osg::Texture::setImage is not virtual and does not set the size from the image.
307  *
308  * \param texture the texture where to set the size
309  * \param width the new width
310  * \param height the new height
311  * \param depth the new depth
312  */
313  static void initTextureSize( osg::Texture1D* texture, int width, int height, int depth );
314 
315  /**
316  * Initialize the size of the texture properly according to real texture type (1D,2D,3D).
317  * \note This is needed because osg::Texture::setImage is not virtual and does not set the size from the image.
318  *
319  * \param texture the texture where to set the size
320  * \param width the new width
321  * \param height the new height
322  * \param depth the new depth
323  */
324  static void initTextureSize( osg::Texture2D* texture, int width, int height, int depth );
325 
326  /**
327  * Initialize the size of the texture properly according to real texture type (1D,2D,3D).
328  * \note This is needed because osg::Texture::setImage is not virtual and does not set the size from the image.
329  *
330  * \param texture the texture where to set the size
331  * \param width the new width
332  * \param height the new height
333  * \param depth the new depth
334  */
335  static void initTextureSize( osg::Texture3D* texture, int width, int height, int depth );
336 
337 private:
338  /**
339  * Creates and assigns all properties.
340  *
341  * \param min the min value of the texture
342  * \param scale the scale value of the texture
343  */
344  void setupProperties( double scale, double min );
345 
346  /**
347  * A condition used to notify about changes in several properties.
348  */
349  std::shared_ptr< WCondition > m_propCondition;
350 
351  /**
352  * The property object for the dataset.
353  */
354  std::shared_ptr< WProperties > m_properties;
355 
356  /**
357  * The property object for the dataset containing only props whose purpose is "PV_PURPOSE_INFORMNATION". It is useful to define some property
358  * 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
359  * m_properties.
360  */
361  std::shared_ptr< WProperties > m_infoProperties;
362 
363  /**
364  * If true, the texture gets created. This is used to create texture on demand.
365  */
367 
368  /**
369  * The texture name. This might be useful to identify textures.
370  */
371  WPropString m_name;
372 
373  /**
374  * The sort index of the texture. This is important for restoring and saving the colormapper's sorting.
375  */
376  WPropInt m_sortIdx;
377 
378  /**
379  * The minimum of each value in the texture in unscaled space.
380  */
381  WPropDouble m_min;
382 
383  /**
384  * The scaling factor to de-scale a [0-1] texture to original space.
385  */
386  WPropDouble m_scale;
387 
388  /**
389  * A list of color map selection types
390  */
391  std::shared_ptr< WItemSelection > m_colorMapSelectionsList;
392 
393  /**
394  * Selection property for color map
395  */
396  WPropSelection m_colorMap;
397 
398  /**
399  * Alpha blending value.
400  */
401  WPropDouble m_alpha;
402 
403  /**
404  * If set to true, zero values are clipped by making them transparent
405  */
406  WPropBool m_clipZero;
407 
408  /**
409  * Threshold for clipping areas.
410  */
411  WPropDouble m_thresholdLower;
412 
413  /**
414  * Threshold for clipping areas.
415  */
416  WPropDouble m_thresholdUpper;
417 
418  /**
419  * Threshold-enable flag.
420  */
422 
423  /**
424  * True if interpolation should be used.
425  */
426  WPropBool m_interpolation;
427 
428  /**
429  * True if the texture is active.
430  */
431  WPropBool m_active;
432 
433  /**
434  * The texture transformation matrix.
435  */
436  WPropMatrix4X4 m_texMatrix;
437 
438  /**
439  * Window level setting for the current colormap
440  */
441  WPropInterval m_window;
442 
443  /**
444  * Window-Level-Setting-enable flag.
445  */
446  WPropBool m_windowEnabled;
447 };
448 
449 // Some convenience typedefs
450 
451 /**
452  * OSG's Texture1D with scaling features
453  */
455 
456 /**
457  * OSG's Texture2D with scaling features
458  */
460 
461 /**
462  * OSG's Texture3D with scaling features
463  */
465 
466 
467 template < typename TextureType >
468 WGETexture< TextureType >::WGETexture( double scale, double min ):
469  TextureType(),
470  m_propCondition( std::shared_ptr< WCondition >( new WCondition() ) ),
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." ) ) ),
473  m_needCreate( true )
474 {
475  setupProperties( scale, min );
476 }
477 
478 template < typename TextureType >
479 WGETexture< TextureType >::WGETexture( osg::Image* image, double scale, double min ):
480  TextureType( image ),
481  m_propCondition( std::shared_ptr< WCondition >( new WCondition() ) ),
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." ) ) ),
484  m_needCreate( true )
485 {
486  setupProperties( scale, min );
487  WGETexture< TextureType >::initTextureSize( this, image->s(), image->t(), image->r() );
488 }
489 
490 template < typename TextureType >
491 WGETexture< TextureType >::WGETexture( WGEImage::SPtr image, double scale, double min ):
492  TextureType( image->getAsOSGImage() ),
493  m_propCondition( std::shared_ptr< WCondition >( new WCondition() ) ),
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." ) ) ),
496  m_needCreate( true )
497 {
498  setupProperties( scale, min );
499  WGETexture< TextureType >::initTextureSize( this, image->getWidth(), image->getHeight(), image->getDepth() );
500 }
501 
502 template < typename TextureType >
503 WGETexture< TextureType >::WGETexture( const WGETexture< TextureType >& texture, const osg::CopyOp& copyop ):
504  TextureType( texture, copyop ),
505  m_min( texture.m_min ),
506  m_scale( texture.m_scale )
507 {
508  // initialize members
509 }
510 
511 template < typename TextureType >
512 void WGETexture< TextureType >::setupProperties( double scale, double min )
513 {
514  m_propCondition->subscribeSignal( boost::bind( &WGETexture< TextureType >::handleUpdate, this ) );
515 
516  m_name = m_properties->addProperty( "Name", "The name of the texture.", std::string( "Unnamed" ) );
517 
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 );
522 
523  // initialize members
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() );
527 
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() );
531 
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 );
535 
536  m_clipZero = m_properties->addProperty( "Enable zero clip", "If enabled, zero values are clipped.", true );
537 
538  m_thresholdEnabled = m_properties->addProperty( "Enable threshold",
539  "If enabled, threshold based clipping is used. If not, threshold is ignored.", false );
540 
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 );
544 
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 );
548 
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 ) );
552 
553  m_interpolation = m_properties->addProperty( "Interpolate", "Interpolation of the volume data.", true, m_propCondition );
554 
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", "" );
563 
564  m_colorMap = m_properties->addProperty( "Colormap", "The colormap of this texture.", m_colorMapSelectionsList->getSelectorFirst() );
566 
567  m_active = m_properties->addProperty( "Active", "Can dis-enable a texture.", true );
568 
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 );
573 
574  TextureType::setResizeNonPowerOfTwoHint( false );
575  TextureType::setUpdateCallback( new WGEFunctorCallback< osg::StateAttribute >(
576  boost::bind( &WGETexture< TextureType >::updateCallback, this, boost::placeholders::_1 ) )
577  );
578 
579  // init filters
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 );
582 }
583 
584 template < typename TextureType >
586 {
587  // cleanup.
588 }
589 
590 template < typename TextureType >
591 std::shared_ptr< WProperties > WGETexture< TextureType >::getProperties() const
592 {
593  return m_properties;
594 }
595 
596 template < typename TextureType >
597 std::shared_ptr< WProperties > WGETexture< TextureType >::getInformationProperties() const
598 {
599  return m_infoProperties;
600 }
601 
602 template < typename TextureType >
603 inline WPropString WGETexture< TextureType >::name() const
604 {
605  return m_name;
606 }
607 
608 template < typename TextureType >
610 {
611  return m_sortIdx;
612 }
613 
614 template < typename TextureType >
615 inline WPropDouble WGETexture< TextureType >::minimum() const
616 {
617  return m_min;
618 }
619 
620 template < typename TextureType >
621 inline WPropDouble WGETexture< TextureType >::scale() const
622 {
623  return m_scale;
624 }
625 
626 template < typename TextureType >
627 inline WPropDouble WGETexture< TextureType >::alpha() const
628 {
629  return m_alpha;
630 }
631 
632 template < typename TextureType >
633 inline WPropBool WGETexture< TextureType >::clipZero() const
634 {
635  return m_clipZero;
636 }
637 
638 template < typename TextureType >
640 {
641  return m_thresholdLower;
642 }
643 
644 template < typename TextureType >
646 {
647  return m_thresholdUpper;
648 }
649 
650 template < typename TextureType >
652 {
653  return m_thresholdEnabled;
654 }
655 
656 template < typename TextureType >
658 {
659  return m_interpolation;
660 }
661 
662 template < typename TextureType >
663 inline WPropSelection WGETexture< TextureType >::colormap() const
664 {
665  return m_colorMap;
666 }
667 
668 template < typename TextureType >
669 inline WPropBool WGETexture< TextureType >::active() const
670 {
671  return m_active;
672 }
673 
674 template < typename TextureType >
676 {
677  return m_windowEnabled;
678 }
679 
680 template < typename TextureType >
681 inline WPropInterval WGETexture< TextureType >::window() const
682 {
683  return m_window;
684 }
685 
686 template < typename TextureType >
687 inline WPropMatrix4X4 WGETexture< TextureType >::transformation() const
688 {
689  return m_texMatrix;
690 }
691 
692 template < typename TextureType >
694 {
695  if( m_interpolation->changed() )
696  {
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 );
699  }
700 }
701 
702 template < typename TextureType >
703 void WGETexture< TextureType >::applyUniforms( std::string prefix, osg::StateSet* states ) const
704 {
705  states->addUniform( new WGEPropertyUniform< WPropDouble >( prefix + "Min", minimum() ) );
706  states->addUniform( new WGEPropertyUniform< WPropDouble >( prefix + "Scale", scale() ) );
707  states->addUniform( new WGEPropertyUniform< WPropDouble >( prefix + "Alpha", alpha() ) );
708  states->addUniform( new WGEPropertyUniform< WPropBool >( prefix + "ClipZeroEnabled", clipZero() ) );
709  states->addUniform( new WGEPropertyUniform< WPropBool >( prefix + "ThresholdEnabled", thresholdEnabled() ) );
710  states->addUniform( new WGEPropertyUniform< WPropDouble >( prefix + "ThresholdLower", thresholdLower() ) );
711  states->addUniform( new WGEPropertyUniform< WPropDouble >( prefix + "ThresholdUpper", thresholdUpper() ) );
712  states->addUniform( new WGEPropertyUniform< WPropSelection >( prefix + "Colormap", colormap() ) );
713  states->addUniform( new WGEPropertyUniform< WPropBool >( prefix + "Active", active() ) );
714  states->addUniform( new WGEPropertyUniform< WPropBool >( prefix + "WindowEnabled", windowEnabled() ) );
715  states->addUniform( new WGEPropertyUniform< WPropInterval >( prefix + "Window", window() ) );
716 }
717 
718 template < typename TextureType >
719 void WGETexture< TextureType >::bind( osg::ref_ptr< osg::Node > node, size_t unit )
720 {
721  // let our utilities do the work
722  wge::bindTexture( node, osg::ref_ptr< WGETexture< TextureType > >( this ), unit ); // to avoid recursive stuff -> explicitly specify the type
723 }
724 
725 template < typename TextureType >
727 {
728  // do nothing. Derived classes may implement this.
729 }
730 
731 template < typename TextureType >
732 void WGETexture< TextureType >::updateCallback( osg::StateAttribute* /*state*/ )
733 {
734  // create if not done yet
735  if( m_needCreate )
736  {
737  m_needCreate = false;
738  create();
739  TextureType::dirtyTextureObject();
740  }
741 }
742 
743 template < typename TextureType >
744 void WGETexture< TextureType >::setFilterMinMag( osg::Texture::FilterMode mode )
745 {
746  this->setFilter( osg::Texture2D::MIN_FILTER, mode );
747  this->setFilter( osg::Texture2D::MAG_FILTER, mode );
748 }
749 
750 template < typename TextureType >
751 void WGETexture< TextureType >::setWrapSTR( osg::Texture::WrapMode mode )
752 {
753  this->setWrap( osg::Texture2D::WRAP_S, mode );
754  this->setWrap( osg::Texture2D::WRAP_T, mode );
755  this->setWrap( osg::Texture2D::WRAP_R, mode );
756 }
757 
758 template < typename TextureType >
759 void WGETexture< TextureType >::initTextureSize( osg::Texture1D* texture, int width, int /*height*/, int /*depth*/ )
760 {
761  texture->setTextureWidth( width );
762 }
763 
764 template < typename TextureType >
765 void WGETexture< TextureType >::initTextureSize( osg::Texture2D* texture, int width, int height, int /*depth*/ )
766 {
767  texture->setTextureSize( width, height );
768 }
769 
770 template < typename TextureType >
771 void WGETexture< TextureType >::initTextureSize( osg::Texture3D* texture, int width, int height, int depth )
772 {
773  texture->setTextureSize( width, height, depth );
774 }
775 
776 template < typename TextureType >
778 {
779  return WBoundingBox( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 );
780 }
781 
782 template < typename TextureType >
784 {
785  m_name->set( from->m_name->get() );
786  m_sortIdx->set( from->m_sortIdx->get() );
787 
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() );
798 
799  m_colorMapSelectionsList = from->m_colorMapSelectionsList;
800  m_colorMap->set( from->m_colorMap->get() );
801 
802  m_active->set( from->m_active->get() );
803 }
804 
805 template < typename TextureType >
807 {
808  return std::numeric_limits< WPVBaseTypes::PV_INT >::max();
809 }
810 
811 #endif // WGETEXTURE_H
812 
Class to encapsulate boost::condition_variable_any.
Definition: WCondition.h:42
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 >.
Definition: WGEImage.h:48
Class implementing a uniform which can be controlled by a property instance.
This calls serves a simple purpose: have a texture and its scaling information together which allows ...
Definition: WGETexture.h:53
WPropDouble scale() const
Get the scaling factor for de-scaling the texture.
Definition: WGETexture.h:621
WPropBool m_thresholdEnabled
Threshold-enable flag.
Definition: WGETexture.h:421
osg::ref_ptr< WGETexture< TextureType > > SPtr
Convenience type for OSG reference pointer on WGETextures.
Definition: WGETexture.h:63
WPropInterval window() const
Returns the window level definition for the colormap.
Definition: WGETexture.h:681
WPropBool thresholdEnabled() const
Returns the property responsible for enabling threshold based clipping.
Definition: WGETexture.h:651
WPropBool m_windowEnabled
Window-Level-Setting-enable flag.
Definition: WGETexture.h:446
bool m_needCreate
If true, the texture gets created.
Definition: WGETexture.h:366
WPropDouble alpha() const
Returns the alpha property.
Definition: WGETexture.h:627
WPropDouble m_thresholdLower
Threshold for clipping areas.
Definition: WGETexture.h:411
static std::size_t const MAX_NUMBER_OF_TEXTURES
We support only 8 textures because some known hardware does not support more texture coordinates.
Definition: WGETexture.h:66
void setWrapSTR(osg::Texture::WrapMode mode)
For all the lazy guys to set the wrapping for s,t and r directions at once.
Definition: WGETexture.h:751
WPropDouble minimum() const
Get the minimum in the de-scaled value space.
Definition: WGETexture.h:615
virtual WBoundingBox getBoundingBox() const
Returns the texture's bounding box.
Definition: WGETexture.h:777
WPropDouble thresholdUpper() const
Returns the threshold property.
Definition: WGETexture.h:645
WPropSelection m_colorMap
Selection property for color map.
Definition: WGETexture.h:396
WPropString name() const
Returns the name property of the texture.
Definition: WGETexture.h:603
WPropBool m_interpolation
True if interpolation should be used.
Definition: WGETexture.h:426
virtual ~WGETexture()
Destructor.
Definition: WGETexture.h:585
WPropBool windowEnabled() const
Returns the property responsible for enabling window based interval scaling.
Definition: WGETexture.h:675
static std::size_t const MAX_TEXTURE_DIMENSION
The maximum texture dimension.
Definition: WGETexture.h:69
WPropBool m_active
True if the texture is active.
Definition: WGETexture.h:431
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
Definition: WGETexture.h:349
std::shared_ptr< WProperties > m_infoProperties
The property object for the dataset containing only props whose purpose is "PV_PURPOSE_INFORMNATION".
Definition: WGETexture.h:361
WPropDouble m_alpha
Alpha blending value.
Definition: WGETexture.h:401
virtual void updateCallback(osg::StateAttribute *state)
This method implements an update callback which updates the texture image if needed and several other...
Definition: WGETexture.h:732
WPropDouble m_thresholdUpper
Threshold for clipping areas.
Definition: WGETexture.h:416
WPropBool active() const
Returns the active property.
Definition: WGETexture.h:669
void setupProperties(double scale, double min)
Creates and assigns all properties.
Definition: WGETexture.h:512
WPropMatrix4X4 transformation() const
Returns the texture transformation matrix.
Definition: WGETexture.h:687
osg::ref_ptr< WGETexture< TextureType > > RPtr
Convenience type for OSG reference pointer on WGETextures.
Definition: WGETexture.h:58
WPropBool interpolation() const
Returns the interpolation property.
Definition: WGETexture.h:657
WPropInterval m_window
Window level setting for the current colormap.
Definition: WGETexture.h:441
void bind(osg::ref_ptr< osg::Node > node, size_t unit=0)
Binds the texture to the specified node and texture unit.
Definition: WGETexture.h:719
WPropBool clipZero() const
Clip the values assumed to be zero.
Definition: WGETexture.h:633
void setFilterMinMag(osg::Texture::FilterMode mode)
For all the lazy guys to set the filter MIN and MAG at once.
Definition: WGETexture.h:744
WGETexture(double scale=1.0, double min=0.0)
Default constructor.
Definition: WGETexture.h:468
WPropString m_name
The texture name.
Definition: WGETexture.h:371
WPropInt m_sortIdx
The sort index of the texture.
Definition: WGETexture.h:376
std::shared_ptr< WProperties > getProperties() const
Return a pointer to the properties object of the dataset.
Definition: WGETexture.h:591
WPropDouble thresholdLower() const
Returns the threshold property.
Definition: WGETexture.h:639
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.
Definition: WGETexture.h:703
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,...
Definition: WGETexture.h:759
static WPVBaseTypes::PV_INT getUnsetSortIndex()
Get the index used to refer to an unset sort index.
Definition: WGETexture.h:806
WPropInt sortIndex() const
The sorting index in the colormapper's texture list.
Definition: WGETexture.h:609
WPropSelection colormap() const
Returns the colormap property.
Definition: WGETexture.h:663
virtual void create()
Creates the texture data.
Definition: WGETexture.h:726
virtual void handleUpdate()
Handles all property updates.
Definition: WGETexture.h:693
WPropDouble m_scale
The scaling factor to de-scale a [0-1] texture to original space.
Definition: WGETexture.h:386
std::shared_ptr< WProperties > getInformationProperties() const
Return a pointer to the information properties object of the dataset.
Definition: WGETexture.h:597
WPropMatrix4X4 m_texMatrix
The texture transformation matrix.
Definition: WGETexture.h:436
WPropDouble m_min
The minimum of each value in the texture in unscaled space.
Definition: WGETexture.h:381
std::shared_ptr< WItemSelection > m_colorMapSelectionsList
A list of color map selection types.
Definition: WGETexture.h:391
std::shared_ptr< WProperties > m_properties
The property object for the dataset.
Definition: WGETexture.h:354
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...
Definition: WGETexture.h:783
WPropBool m_clipZero
If set to true, zero values are clipped by making them transparent.
Definition: WGETexture.h:406
A class containing a list of named items.
static MatrixType identity()
Returns an identity matrix.
Definition: WMatrixFixed.h:310
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.