diff --git a/src/osgPlugins/ive/CMakeLists.txt b/src/osgPlugins/ive/CMakeLists.txt index cd173b48b..1483c3cbc 100644 --- a/src/osgPlugins/ive/CMakeLists.txt +++ b/src/osgPlugins/ive/CMakeLists.txt @@ -124,6 +124,7 @@ SET(TARGET_SRC VolumeCompositeProperty.cpp VolumeSwitchProperty.cpp VolumeScalarProperty.cpp + VolumeTransferFunctionProperty.cpp VolumePropertyAdjustmentCallback.cpp Volume.cpp VolumeImageLayer.cpp @@ -251,6 +252,7 @@ SET(TARGET_H VolumeCompositeProperty.h VolumeSwitchProperty.h VolumeScalarProperty.h + VolumeTransferFunctionProperty.h VolumePropertyAdjustmentCallback.h Volume.h VolumeImageLayer.h diff --git a/src/osgPlugins/ive/VolumeTransferFunctionProperty.cpp b/src/osgPlugins/ive/VolumeTransferFunctionProperty.cpp index 590fc7ed9..06a29c373 100644 --- a/src/osgPlugins/ive/VolumeTransferFunctionProperty.cpp +++ b/src/osgPlugins/ive/VolumeTransferFunctionProperty.cpp @@ -15,6 +15,7 @@ #include "VolumeTransferFunctionProperty.h" #include +#include "Object.h" using namespace ive; @@ -30,7 +31,41 @@ void VolumeTransferFunctionProperty::write(DataOutputStream* out) else throw Exception("VolumeTransferFunctionProperty::write(): Could not cast this osgVolume::TransferFunctionProperty to an osg::Object."); - // out->writeFloat(getValue()); + + osg::TransferFunction1D* tf = dynamic_cast(getTransferFunction()); + if (tf) + { + + out->writeUInt(1); // TransferFunction1D + out->writeUInt(tf->getNumberImageCells()); + + const osg::TransferFunction1D::ColorMap& colourMap = tf->getColorMap(); + + // count the number of colour entries in the map so we can write it to the .ive file + unsigned int numColours = 0; + for(osg::TransferFunction1D::ColorMap::const_iterator itr = colourMap.begin(); + itr != colourMap.end(); + ++itr) + { + ++numColours; + } + + // write out the num of colours + out->writeUInt(numColours); + + // write out the colour map entires + for(osg::TransferFunction1D::ColorMap::const_iterator itr = colourMap.begin(); + itr != colourMap.end(); + ++itr) + { + out->writeFloat(itr->first); + out->writeVec4(itr->second); + } + } + else + { + out->writeUInt(0); + } } void VolumeTransferFunctionProperty::read(DataInputStream* in) @@ -39,7 +74,7 @@ void VolumeTransferFunctionProperty::read(DataInputStream* in) int id = in->peekInt(); if (id != IVEVOLUMETRANSFERFUNCTIONPROPERTY) throw Exception("VolumeTransferFunctionProperty::read(): Expected CompositeProperty identification."); - + // Read Layer's identification. id = in->readInt(); @@ -50,5 +85,29 @@ void VolumeTransferFunctionProperty::read(DataInputStream* in) else throw Exception("VolumeTransferFunctionProperty::write(): Could not cast this osgVolume::TransferFunctionProperty to an osg::Object."); - // setValue(in->readFloat()); + unsigned int numDimensions = in->readUInt(); + if (numDimensions==1) + { + osg::TransferFunction1D* tf = new osg::TransferFunction1D; + setTransferFunction(tf); + + tf->allocate(in->readUInt()); + + osg::TransferFunction1D::ColorMap& colourMap = tf->getColorMap(); + + // count the number of colour entries in the map so we can write it to the .ive file + unsigned int numColours = in->readUInt(); + for(unsigned int i=0; ireadFloat(); + osg::Vec4 colour = in->readVec4(); + colourMap[value] = colour; + } + + tf->updateImage(); + } + else + { + } + }