openscenegraph
TransferFunction
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
22namespace osg {
23
24
31{
32 public :
33
35
37 TransferFunction(const TransferFunction& tf, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
38
40
41
42 osg::Image* getImage() { return _image.get(); }
43
45 const osg::Image* getImage() const { return _image.get(); }
46
47 protected:
48
50
52};
53
56{
57 public:
58
60
62 TransferFunction1D(const TransferFunction1D& tf, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
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
121
122 protected:
123
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
Definition CopyOp:41
Definition Image:179
Definition Object:61
Definition TransferFunction:56
void clear(const osg::Vec4 &color=osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f))
osg::Vec4 getPixelValue(unsigned int i) const
Definition TransferFunction:80
unsigned int getNumberImageCells() const
Definition TransferFunction:93
ColorMap & getColorMap()
Definition TransferFunction:111
void setColorMap(const ColorMap &vcm)
Definition TransferFunction:108
ColorMap _colorMap
Definition TransferFunction:124
const ColorMap & getColorMap() const
Definition TransferFunction:114
void setColor(float v, const osg::Vec4 &color, bool updateImage=true)
std::map< float, osg::Vec4 > ColorMap
Definition TransferFunction:105
osg::Vec4 getColor(float v) const
float getMaximum() const
Definition TransferFunction:70
TransferFunction1D(const TransferFunction1D &tf, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
void assignToImage(float lower_v, const osg::Vec4 &lower_c, float upper_v, const osg::Vec4 &upper_c)
META_Object(osg, TransferFunction1D) float getMinimum() const
Definition TransferFunction:64
void allocate(unsigned int numImageCells)
void assign(const ColorMap &vcm)
Definition TransferFunction:31
META_Object(osg, TransferFunction) osg
Definition TransferFunction:39
TransferFunction(const TransferFunction &tf, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
osg::ref_ptr< osg::Image > _image
Definition TransferFunction:51
virtual ~TransferFunction()
const osg::Image * getImage() const
Definition TransferFunction:45
Definition Vec4f:28
Definition ref_ptr:32
author: Julien Valentin 2017 (mp3butcher@hotmail.com)
Definition AlphaFunc:19
Vec4f Vec4
Definition Vec4:21
#define OSG_EXPORT
Definition osg/Export:39