2007-03-10 19:53:31 +08:00
|
|
|
/* -*-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>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
|
|
|
|
2007-07-12 16:29:39 +08:00
|
|
|
/** TransferFunction is a class that provide a 1D,2D or 3D colour look up table
|
|
|
|
* that can be used on the GPU as a 1D, 2D or 3D texture.
|
|
|
|
* Typically uses include mapping heights to colours when contouring terrain,
|
|
|
|
* or mapping intensities to colours when volume rendering.
|
|
|
|
*/
|
2007-03-22 00:34:04 +08:00
|
|
|
class OSG_EXPORT TransferFunction : public osg::Referenced
|
2007-03-10 19:53:31 +08:00
|
|
|
{
|
|
|
|
public :
|
|
|
|
|
|
|
|
TransferFunction();
|
|
|
|
|
|
|
|
osg::Image* getImage() { return _image.get(); }
|
|
|
|
const osg::Image* getImage() const { return _image.get(); }
|
|
|
|
|
|
|
|
osg::Texture* getTexture() { return _texture.get(); }
|
|
|
|
const osg::Texture* getTexture() const { return _texture.get(); }
|
|
|
|
|
|
|
|
osg::Shader* getShader() { return _shader.get(); }
|
|
|
|
const osg::Shader* getShader() const { return _shader.get(); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2007-03-22 00:34:04 +08:00
|
|
|
virtual ~TransferFunction();
|
|
|
|
|
2007-03-10 19:53:31 +08:00
|
|
|
typedef std::vector<osg::Vec4> Colors;
|
|
|
|
Colors _colors;
|
|
|
|
osg::ref_ptr<osg::Image> _image;
|
|
|
|
osg::ref_ptr<osg::Texture> _texture;
|
|
|
|
osg::ref_ptr<osg::Shader> _shader;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2007-07-12 16:29:39 +08:00
|
|
|
/** 1D variant of TransferFunction. */
|
2007-03-10 19:53:31 +08:00
|
|
|
class OSG_EXPORT TransferFunction1D : public osg::TransferFunction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
TransferFunction1D();
|
|
|
|
|
|
|
|
void setInputRange(float minimum, float maximum);
|
2007-04-03 23:39:05 +08:00
|
|
|
|
|
|
|
void setMinimum(float value) { _minimum = value; }
|
|
|
|
float getMinimum() const { return _minimum; }
|
|
|
|
|
|
|
|
void setMaximum(float value) { _maximum = value; }
|
|
|
|
float getMaximum() const { return _maximum; }
|
2007-03-10 19:53:31 +08:00
|
|
|
|
|
|
|
void allocate(unsigned int numX);
|
|
|
|
|
|
|
|
void clear(const osg::Vec4& color = osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
|
|
|
|
|
|
|
unsigned int getNumberCellsX() const { return _colors.size(); }
|
|
|
|
|
2007-04-02 21:06:59 +08:00
|
|
|
void setValue(unsigned int i, const osg::Vec4& color) { _colors[i] = color; if (_image.valid()) _image->dirty(); }
|
2007-03-10 19:53:31 +08:00
|
|
|
const osg::Vec4& getValue(unsigned int i) const { return _colors[i]; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
float _minimum;
|
|
|
|
float _maximum;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|