Ground work for full .osg support for osg::TransferFunction*

This commit is contained in:
Robert Osfield
2009-02-01 12:38:55 +00:00
parent a13c6405d8
commit d6b0cd64f1
5 changed files with 93 additions and 1 deletions

View File

@@ -27,12 +27,17 @@ namespace osg {
* Typically uses include mapping heights to colours when contouring terrain,
* or mapping intensities to colours when volume rendering.
*/
class OSG_EXPORT TransferFunction : public osg::Referenced
class OSG_EXPORT TransferFunction : public osg::Object
{
public :
TransferFunction();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
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(); }
@@ -53,6 +58,11 @@ class OSG_EXPORT TransferFunction1D : public osg::TransferFunction
TransferFunction1D();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
TransferFunction1D(const TransferFunction1D& tf, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_Object(osg, TransferFunction1D)
void setInputRange(float minimum, float maximum);
void setMinimum(float value) { _minimum = value; }

View File

@@ -27,6 +27,11 @@ TransferFunction::TransferFunction()
{
}
TransferFunction::TransferFunction(const TransferFunction& tf, const CopyOp& copyop):
Object(tf,copyop)
{
}
TransferFunction::~TransferFunction()
{
}
@@ -41,6 +46,18 @@ TransferFunction1D::TransferFunction1D()
_maximum = 1.0;
}
TransferFunction1D::TransferFunction1D(const TransferFunction1D& tf, const CopyOp& copyop):
TransferFunction(tf,copyop),
_minimum(tf._minimum),
_maximum(tf._maximum)
{
allocate(tf._colors.size());
for(unsigned int i=0; i<_colors.size(); ++i)
{
_colors[i] = tf._colors[i];
}
}
void TransferFunction1D::setInputRange(float minimum, float maximum)
{
_minimum = minimum;

View File

@@ -84,6 +84,7 @@ SET(TARGET_SRC
Texture.cpp
TextureCubeMap.cpp
TextureRectangle.cpp
TransferFunction.cpp
Transform.cpp
Uniform.cpp
VertexProgram.cpp

View File

@@ -0,0 +1,55 @@
#include <osg/TransferFunction>
#include <iostream>
#include <string>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/io_utils>
#include <osgDB/ReadFile>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
#include <osgDB/ParameterOutput>
bool TransferFunction1D_readLocalData(osg::Object &obj, osgDB::Input &fr);
bool TransferFunction1D_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
osgDB::RegisterDotOsgWrapperProxy TransferFunction1D_Proxy
(
new osg::TransferFunction1D,
"TransferFunction1D",
"Object TransferFunction1D",
TransferFunction1D_readLocalData,
TransferFunction1D_writeLocalData
);
bool TransferFunction1D_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
osg::TransferFunction1D& tf = static_cast<osg::TransferFunction1D&>(obj);
bool itrAdvanced = false;
return itrAdvanced;
}
bool TransferFunction1D_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
{
const osg::TransferFunction1D& tf = static_cast<const osg::TransferFunction1D&>(obj);
fw.indent()<<"Minimum "<<tf.getMinimum()<<std::endl;
fw.indent()<<"Maximum "<<tf.getMaximum()<<std::endl;
fw.indent()<<"Colours "<<tf.getNumberCellsX()<<" {"<<std::endl;
fw.moveIn();
for(unsigned int i = 0; i<tf.getNumberCellsX(); ++i)
{
const osg::Vec4& c = tf.getValue(i);
fw.indent()<<c.r()<<" "<<c.g()<<" "<<c.b()<<" "<<c.a()<<std::endl;
}
fw.moveOut();
fw.indent()<<"}"<<std::endl;
return true;
}

View File

@@ -32,6 +32,12 @@ bool TransferFunctionProperty_readLocalData(osg::Object& obj, osgDB::Input &fr)
bool itrAdvanced = false;
osg::ref_ptr<osg::Object> readObject = fr.readObjectOfType(osgDB::type_wrapper<osg::TransferFunction>());
if (readObject.valid()) itrAdvanced = true;
osg::TransferFunction* tf = dynamic_cast<osg::TransferFunction*>(readObject.get());
if (tf) tfp.setTransferFunction(tf);
return itrAdvanced;
}
@@ -39,5 +45,8 @@ bool TransferFunctionProperty_writeLocalData(const osg::Object& obj, osgDB::Outp
{
const osgVolume::TransferFunctionProperty& tfp = static_cast<const osgVolume::TransferFunctionProperty&>(obj);
const osg::TransferFunction* tf = tfp.getTransferFunction();
if (tf) fw.writeObject(*tf);
return true;
}