| 1 | #include <osg/TransferFunction> |
|---|
| 2 | |
|---|
| 3 | #include <iostream> |
|---|
| 4 | #include <string> |
|---|
| 5 | |
|---|
| 6 | #include <osg/Vec3> |
|---|
| 7 | #include <osg/Vec4> |
|---|
| 8 | #include <osg/io_utils> |
|---|
| 9 | |
|---|
| 10 | #include <osgDB/ReadFile> |
|---|
| 11 | #include <osgDB/Registry> |
|---|
| 12 | #include <osgDB/Input> |
|---|
| 13 | #include <osgDB/Output> |
|---|
| 14 | #include <osgDB/ParameterOutput> |
|---|
| 15 | |
|---|
| 16 | bool TransferFunction1D_readLocalData(osg::Object &obj, osgDB::Input &fr); |
|---|
| 17 | bool TransferFunction1D_writeLocalData(const osg::Object &obj, osgDB::Output &fw); |
|---|
| 18 | |
|---|
| 19 | REGISTER_DOTOSGWRAPPER(TransferFunction1D_Proxy) |
|---|
| 20 | ( |
|---|
| 21 | new osg::TransferFunction1D, |
|---|
| 22 | "TransferFunction1D", |
|---|
| 23 | "Object TransferFunction1D", |
|---|
| 24 | TransferFunction1D_readLocalData, |
|---|
| 25 | TransferFunction1D_writeLocalData |
|---|
| 26 | ); |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | bool TransferFunction1D_readLocalData(osg::Object& obj, osgDB::Input &fr) |
|---|
| 30 | { |
|---|
| 31 | osg::TransferFunction1D& tf = static_cast<osg::TransferFunction1D&>(obj); |
|---|
| 32 | |
|---|
| 33 | bool itrAdvanced = false; |
|---|
| 34 | |
|---|
| 35 | unsigned int numCells; |
|---|
| 36 | if (fr.read("NumberImageCells ",numCells)) |
|---|
| 37 | { |
|---|
| 38 | tf.allocate(numCells); |
|---|
| 39 | itrAdvanced = true; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | if (fr.matchSequence("Colours {")) |
|---|
| 43 | { |
|---|
| 44 | int entry = fr[0].getNoNestedBrackets(); |
|---|
| 45 | |
|---|
| 46 | fr += 2; |
|---|
| 47 | |
|---|
| 48 | float v; |
|---|
| 49 | osg::Vec4 color; |
|---|
| 50 | osg::TransferFunction1D::ColorMap colorMap; |
|---|
| 51 | |
|---|
| 52 | while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) |
|---|
| 53 | { |
|---|
| 54 | if (fr.read(v, color.r(), color.g(), color.b(), color.a())) |
|---|
| 55 | { |
|---|
| 56 | colorMap[v] = color; |
|---|
| 57 | } |
|---|
| 58 | else |
|---|
| 59 | { |
|---|
| 60 | ++fr; |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | tf.assign(colorMap); |
|---|
| 65 | |
|---|
| 66 | itrAdvanced = true; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | return itrAdvanced; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | bool TransferFunction1D_writeLocalData(const osg::Object& obj, osgDB::Output& fw) |
|---|
| 74 | { |
|---|
| 75 | const osg::TransferFunction1D& tf = static_cast<const osg::TransferFunction1D&>(obj); |
|---|
| 76 | const osg::TransferFunction1D::ColorMap& colorMap = tf.getColorMap(); |
|---|
| 77 | |
|---|
| 78 | fw.indent()<<"NumberImageCells "<<tf.getNumberImageCells()<<std::endl; |
|---|
| 79 | fw.indent()<<"Colours {"<<std::endl; |
|---|
| 80 | |
|---|
| 81 | fw.moveIn(); |
|---|
| 82 | for(osg::TransferFunction1D::ColorMap::const_iterator itr = colorMap.begin(); |
|---|
| 83 | itr != colorMap.end(); |
|---|
| 84 | ++itr) |
|---|
| 85 | { |
|---|
| 86 | const osg::Vec4& c = itr->second; |
|---|
| 87 | fw.indent()<<itr->first<<" "<<c.r()<<" "<<c.g()<<" "<<c.b()<<" "<<c.a()<<std::endl; |
|---|
| 88 | } |
|---|
| 89 | fw.moveOut(); |
|---|
| 90 | fw.indent()<<"}"<<std::endl; |
|---|
| 91 | |
|---|
| 92 | return true; |
|---|
| 93 | } |
|---|