OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TransferFunction.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 #ifndef OSG_TRANSFERFUNCTION
15 #define OSG_TRANSFERFUNCTION 1
16 
17 #include <osg/Texture>
18 #include <osg/Shader>
19 
20 #include <map>
21 
22 namespace osg {
23 
24 
31 {
32  public :
33 
35 
38 
40 
41 
42  osg::Image* getImage() { return _image.get(); }
43 
45  const osg::Image* getImage() const { return _image.get(); }
46 
47  protected:
48 
49  virtual ~TransferFunction();
50 
52 };
53 
56 {
57  public:
58 
60 
63 
65 
66 
67  float getMinimum() const { return _colorMap.empty() ? 0.0f : _colorMap.begin()->first; }
68 
70  float getMaximum() const { return _colorMap.empty() ? 0.0f : _colorMap.rbegin()->first; }
71 
74  void allocate(unsigned int numImageCells);
75 
77  void clear(const osg::Vec4& color = osg::Vec4(1.0f,1.0f,1.0f,1.0f));
78 
80  osg::Vec4 getPixelValue(unsigned int i) const
81  {
82  if (_image.valid() && i<static_cast<unsigned int>(_image->s()))
83  {
84  return *reinterpret_cast<osg::Vec4*>(_image->data(i));
85  }
86  else
87  {
88  return osg::Vec4(1.0f,1.0f,1.0f,1.0f);
89  }
90  }
91 
93  unsigned int getNumberImageCells() const { return _image.valid() ? _image->s() : 0; }
94 
100  void setColor(float v, const osg::Vec4& color, bool updateImage=true);
101 
103  osg::Vec4 getColor(float v) const;
104 
105  typedef std::map<float, osg::Vec4> ColorMap;
106 
108  void setColorMap(const ColorMap& vcm) { assign(vcm); }
109 
111  ColorMap& getColorMap() { return _colorMap; }
112 
114  const ColorMap& getColorMap() const { return _colorMap; }
115 
117  void assign(const ColorMap& vcm);
118 
120  void updateImage();
121 
122  protected:
123 
124  ColorMap _colorMap;
125 
126  void assignToImage(float lower_v, const osg::Vec4& lower_c, float upper_v, const osg::Vec4& upper_c);
127 };
128 
129 }
130 
131 #endif
#define OSG_EXPORT
Definition: Export.h:43
const ColorMap & getColorMap() const
std::map< float, osg::Vec4 > ColorMap
Vec4f Vec4
Definition: Vec4.h:21
META_Object(osg, TransferFunction1D) float getMinimum() const
osg::Vec4 getPixelValue(unsigned int i) const
Definition: AlphaFunc.h:19
osg::ref_ptr< osg::Image > _image
unsigned int getNumberImageCells() const
void setColorMap(const ColorMap &vcm)
META_Object(osg, TransferFunction) osg
const osg::Image * getImage() const