From d6b0cd64f104e2d17060bb5d467d5b3ecd2ca7f7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 1 Feb 2009 12:38:55 +0000 Subject: [PATCH] Ground work for full .osg support for osg::TransferFunction* --- include/osg/TransferFunction | 12 +++- src/osg/TransferFunction.cpp | 17 ++++++ src/osgPlugins/osg/CMakeLists.txt | 1 + src/osgPlugins/osg/TransferFunction.cpp | 55 +++++++++++++++++++ .../osgVolume/TransferFunctionProperty.cpp | 9 +++ 5 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/osgPlugins/osg/TransferFunction.cpp diff --git a/include/osg/TransferFunction b/include/osg/TransferFunction index 52efc8695..ce4e0b39d 100644 --- a/include/osg/TransferFunction +++ b/include/osg/TransferFunction @@ -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; } diff --git a/src/osg/TransferFunction.cpp b/src/osg/TransferFunction.cpp index 428283848..7ecdbad45 100644 --- a/src/osg/TransferFunction.cpp +++ b/src/osg/TransferFunction.cpp @@ -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; diff --git a/src/osgPlugins/osg/CMakeLists.txt b/src/osgPlugins/osg/CMakeLists.txt index 3ca0fea70..0e6877aac 100644 --- a/src/osgPlugins/osg/CMakeLists.txt +++ b/src/osgPlugins/osg/CMakeLists.txt @@ -84,6 +84,7 @@ SET(TARGET_SRC Texture.cpp TextureCubeMap.cpp TextureRectangle.cpp + TransferFunction.cpp Transform.cpp Uniform.cpp VertexProgram.cpp diff --git a/src/osgPlugins/osg/TransferFunction.cpp b/src/osgPlugins/osg/TransferFunction.cpp new file mode 100644 index 000000000..f5d3f6c29 --- /dev/null +++ b/src/osgPlugins/osg/TransferFunction.cpp @@ -0,0 +1,55 @@ +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +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(obj); + + bool itrAdvanced = false; + return itrAdvanced; +} + +bool TransferFunction1D_writeLocalData(const osg::Object& obj, osgDB::Output& fw) +{ + const osg::TransferFunction1D& tf = static_cast(obj); + + fw.indent()<<"Minimum "< readObject = fr.readObjectOfType(osgDB::type_wrapper()); + if (readObject.valid()) itrAdvanced = true; + + osg::TransferFunction* tf = dynamic_cast(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(obj); + const osg::TransferFunction* tf = tfp.getTransferFunction(); + if (tf) fw.writeObject(*tf); + return true; }