TransferFunction
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_TRANSFERFUNCTION
#define OSG_TRANSFERFUNCTION 1
#include <osg/Texture>
#include <osg/Shader>
#include <map>
namespace osg {
class OSG_EXPORT TransferFunction : public osg::Object
{
public :
TransferFunction();
TransferFunction(const TransferFunction& tf, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_Object(osg, TransferFunction)
osg::Image* getImage() { return _image.get(); }
const osg::Image* getImage() const { return _image.get(); }
protected:
virtual ~TransferFunction();
osg::ref_ptr<osg::Image> _image;
};
class OSG_EXPORT TransferFunction1D : public osg::TransferFunction
{
public:
TransferFunction1D();
TransferFunction1D(const TransferFunction1D& tf, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_Object(osg, TransferFunction1D)
float getMinimum() const { return _colorMap.empty() ? 0.0f : _colorMap.begin()->first; }
float getMaximum() const { return _colorMap.empty() ? 0.0f : _colorMap.rbegin()->first; }
void allocate(unsigned int numImageCells);
void clear(const osg::Vec4& color = osg::Vec4(1.0f,1.0f,1.0f,1.0f));
osg::Vec4 getPixelValue(unsigned int i) const
{
if (_image.valid() && i<static_cast<unsigned int>(_image->s()))
{
return *reinterpret_cast<osg::Vec4*>(_image->data(i));
}
else
{
return osg::Vec4(1.0f,1.0f,1.0f,1.0f);
}
}
unsigned int getNumberImageCells() const { return _image.valid() ? _image->s() : 0; }
void setColor(float v, const osg::Vec4& color, bool updateImage=true);
osg::Vec4 getColor(float v) const;
typedef std::map<float, osg::Vec4> ColorMap;
void setColorMap(const ColorMap& vcm) { assign(vcm); }
ColorMap& getColorMap() { return _colorMap; }
const ColorMap& getColorMap() const { return _colorMap; }
void assign(const ColorMap& vcm);
void updateImage();
protected:
ColorMap _colorMap;
void assignToImage(float lower_v, const osg::Vec4& lower_c, float upper_v, const osg::Vec4& upper_c);
};
}
#endif
Shader
Texture
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Image
Definition Image:179
osg::Object
Definition Object:61
osg::TransferFunction1D::clear
void clear(const osg::Vec4 &color=osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f))
osg::TransferFunction1D::getPixelValue
osg::Vec4 getPixelValue(unsigned int i) const
Definition TransferFunction:80
osg::TransferFunction1D::getNumberImageCells
unsigned int getNumberImageCells() const
Definition TransferFunction:93
osg::TransferFunction1D::getColorMap
ColorMap & getColorMap()
Definition TransferFunction:111
osg::TransferFunction1D::setColorMap
void setColorMap(const ColorMap &vcm)
Definition TransferFunction:108
osg::TransferFunction1D::_colorMap
ColorMap _colorMap
Definition TransferFunction:124
osg::TransferFunction1D::getColorMap
const ColorMap & getColorMap() const
Definition TransferFunction:114
osg::TransferFunction1D::setColor
void setColor(float v, const osg::Vec4 &color, bool updateImage=true)
osg::TransferFunction1D::ColorMap
std::map< float, osg::Vec4 > ColorMap
Definition TransferFunction:105
osg::TransferFunction1D::TransferFunction1D
TransferFunction1D()
osg::TransferFunction1D::getColor
osg::Vec4 getColor(float v) const
osg::TransferFunction1D::getMaximum
float getMaximum() const
Definition TransferFunction:70
osg::TransferFunction1D::TransferFunction1D
TransferFunction1D(const TransferFunction1D &tf, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
osg::TransferFunction1D::assignToImage
void assignToImage(float lower_v, const osg::Vec4 &lower_c, float upper_v, const osg::Vec4 &upper_c)
osg::TransferFunction1D::updateImage
void updateImage()
osg::TransferFunction1D::META_Object
META_Object(osg, TransferFunction1D) float getMinimum() const
Definition TransferFunction:64
osg::TransferFunction1D::allocate
void allocate(unsigned int numImageCells)
osg::TransferFunction1D::assign
void assign(const ColorMap &vcm)
osg::TransferFunction
Definition TransferFunction:31
osg::TransferFunction::META_Object
META_Object(osg, TransferFunction) osg
Definition TransferFunction:39
osg::TransferFunction::TransferFunction
TransferFunction()
osg::TransferFunction::TransferFunction
TransferFunction(const TransferFunction &tf, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
osg::TransferFunction::_image
osg::ref_ptr< osg::Image > _image
Definition TransferFunction:51
osg::TransferFunction::~TransferFunction
virtual ~TransferFunction()
osg::TransferFunction::getImage
const osg::Image * getImage() const
Definition TransferFunction:45
osg::ref_ptr
Definition ref_ptr:32
osg
Definition AlphaFunc:19
osg::Vec4
Vec4f Vec4
Definition Vec4:21
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39