| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include "Exception.h" |
|---|
| 15 | #include "VolumeTransferFunctionProperty.h" |
|---|
| 16 | |
|---|
| 17 | #include <osgDB/ReadFile> |
|---|
| 18 | #include "Object.h" |
|---|
| 19 | |
|---|
| 20 | using namespace ive; |
|---|
| 21 | |
|---|
| 22 | void VolumeTransferFunctionProperty::write(DataOutputStream* out) |
|---|
| 23 | { |
|---|
| 24 | |
|---|
| 25 | out->writeInt(IVEVOLUMETRANSFERFUNCTIONPROPERTY); |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | osg::Object* object = dynamic_cast<osg::Object*>(this); |
|---|
| 29 | if (object) |
|---|
| 30 | ((ive::Object*)(object))->write(out); |
|---|
| 31 | else |
|---|
| 32 | out_THROW_EXCEPTION("VolumeTransferFunctionProperty::write(): Could not cast this osgVolume::TransferFunctionProperty to an osg::Object."); |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | osg::TransferFunction1D* tf = dynamic_cast<osg::TransferFunction1D*>(getTransferFunction()); |
|---|
| 36 | if (tf) |
|---|
| 37 | { |
|---|
| 38 | |
|---|
| 39 | out->writeUInt(1); |
|---|
| 40 | out->writeUInt(tf->getNumberImageCells()); |
|---|
| 41 | |
|---|
| 42 | const osg::TransferFunction1D::ColorMap& colourMap = tf->getColorMap(); |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | unsigned int numColours = 0; |
|---|
| 46 | for(osg::TransferFunction1D::ColorMap::const_iterator itr = colourMap.begin(); |
|---|
| 47 | itr != colourMap.end(); |
|---|
| 48 | ++itr) |
|---|
| 49 | { |
|---|
| 50 | ++numColours; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | out->writeUInt(numColours); |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | for(osg::TransferFunction1D::ColorMap::const_iterator itr = colourMap.begin(); |
|---|
| 58 | itr != colourMap.end(); |
|---|
| 59 | ++itr) |
|---|
| 60 | { |
|---|
| 61 | out->writeFloat(itr->first); |
|---|
| 62 | out->writeVec4(itr->second); |
|---|
| 63 | } |
|---|
| 64 | } |
|---|
| 65 | else |
|---|
| 66 | { |
|---|
| 67 | out->writeUInt(0); |
|---|
| 68 | } |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | void VolumeTransferFunctionProperty::read(DataInputStream* in) |
|---|
| 72 | { |
|---|
| 73 | |
|---|
| 74 | int id = in->peekInt(); |
|---|
| 75 | if (id != IVEVOLUMETRANSFERFUNCTIONPROPERTY) |
|---|
| 76 | in_THROW_EXCEPTION("VolumeTransferFunctionProperty::read(): Expected CompositeProperty identification."); |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | id = in->readInt(); |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | osg::Object* object = dynamic_cast<osg::Object*>(this); |
|---|
| 83 | if (object) |
|---|
| 84 | ((ive::Object*)(object))->read(in); |
|---|
| 85 | else |
|---|
| 86 | in_THROW_EXCEPTION("VolumeTransferFunctionProperty::write(): Could not cast this osgVolume::TransferFunctionProperty to an osg::Object."); |
|---|
| 87 | |
|---|
| 88 | unsigned int numDimensions = in->readUInt(); |
|---|
| 89 | if (numDimensions==1) |
|---|
| 90 | { |
|---|
| 91 | osg::TransferFunction1D* tf = new osg::TransferFunction1D; |
|---|
| 92 | setTransferFunction(tf); |
|---|
| 93 | |
|---|
| 94 | tf->allocate(in->readUInt()); |
|---|
| 95 | |
|---|
| 96 | osg::TransferFunction1D::ColorMap& colourMap = tf->getColorMap(); |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | unsigned int numColours = in->readUInt(); |
|---|
| 100 | for(unsigned int i=0; i<numColours; ++i) |
|---|
| 101 | { |
|---|
| 102 | float value = in->readFloat(); |
|---|
| 103 | osg::Vec4 colour = in->readVec4(); |
|---|
| 104 | colourMap[value] = colour; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | tf->updateImage(); |
|---|
| 108 | } |
|---|
| 109 | else |
|---|
| 110 | { |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | } |
|---|