OpenSceneGraph 3.6.5
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
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
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
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
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
Vec4f Vec4
Definition Vec4:21
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Image class for encapsulating the storage texture image data.
Definition Image:179
Base class/standard interface for objects which require IO support, cloning and reference counting.
Definition Object:61
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
TransferFunction is a class that provide a 1D,2D or 3D colour look up table that can be used on the G...
Definition TransferFunction:31
META_Object(osg, TransferFunction) osg
Get the image that is used for passing the transfer function data to the GPU.
Definition TransferFunction:39
TransferFunction(const TransferFunction &tf, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
osg::ref_ptr< osg::Image > _image
Definition TransferFunction:51
virtual ~TransferFunction()
const osg::Image * getImage() const
Get the const image that is used for passing the transfer function data to the GPU.
Definition TransferFunction:45
void clear(const osg::Vec4 &color=osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f))
Clear the whole range to just represent a single color.
osg::Vec4 getPixelValue(unsigned int i) const
Get pixel value from the image.
Definition TransferFunction:80
unsigned int getNumberImageCells() const
Get the number of image cells that are assigned to the represent the transfer function when download ...
Definition TransferFunction:93
ColorMap & getColorMap()
Get the color map that stores the mapping between the transfer function value and the colour it maps ...
Definition TransferFunction:111
void setColorMap(const ColorMap &vcm)
set the color map and automatically update the image to make sure they are in sync.
Definition TransferFunction:108
ColorMap _colorMap
Definition TransferFunction:124
const ColorMap & getColorMap() const
Get the const color map that stores the mapping between the transfer function value and the colour it...
Definition TransferFunction:114
void setColor(float v, const osg::Vec4 &color, bool updateImage=true)
Set the color for a specified transfer function value.
std::map< float, osg::Vec4 > ColorMap
Definition TransferFunction:105
osg::Vec4 getColor(float v) const
Get the color for a specified transfer function value, interpolating the value if no exact match is f...
float getMaximum() const
Get the maximum transfer function value.
Definition TransferFunction:70
TransferFunction1D(const TransferFunction1D &tf, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
void assignToImage(float lower_v, const osg::Vec4 &lower_c, float upper_v, const osg::Vec4 &upper_c)
void updateImage()
Manually update the associate osg::Image to represent the colors assigned in the color map.
META_Object(osg, TransferFunction1D) float getMinimum() const
Get the minimum transfer function value.
Definition TransferFunction:64
void allocate(unsigned int numImageCells)
allocate the osg::Image with specified dimension.
void assign(const ColorMap &vcm)
Assign a color map and automatically update the image to make sure they are in sync.
#define OSG_EXPORT
Definition Export:39

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.