Refactored osg::TransferFunction1D to use an std::map internally which is kept in sync with the actual osg::Image that is passed to the GPU.
Added .osg support for osg::TransferFunction1D. Updated wrappers
This commit is contained in:
@@ -31,22 +31,60 @@ bool TransferFunction1D_readLocalData(osg::Object& obj, osgDB::Input &fr)
|
||||
osg::TransferFunction1D& tf = static_cast<osg::TransferFunction1D&>(obj);
|
||||
|
||||
bool itrAdvanced = false;
|
||||
|
||||
unsigned int numCells;
|
||||
if (fr.read("NumberImageCells ",numCells))
|
||||
{
|
||||
tf.allocate(numCells);
|
||||
itrAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr.matchSequence("Colours {"))
|
||||
{
|
||||
int entry = fr[0].getNoNestedBrackets();
|
||||
|
||||
fr += 2;
|
||||
|
||||
float v;
|
||||
osg::Vec4 color;
|
||||
osg::TransferFunction1D::ColorMap colorMap;
|
||||
|
||||
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
|
||||
{
|
||||
if (fr.read(v, color.r(), color.g(), color.b(), color.a()))
|
||||
{
|
||||
colorMap[v] = color;
|
||||
}
|
||||
else
|
||||
{
|
||||
++fr;
|
||||
}
|
||||
}
|
||||
|
||||
tf.assign(colorMap);
|
||||
|
||||
itrAdvanced = true;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
const osg::TransferFunction1D::ColorMap& colorMap = tf.getColorMap();
|
||||
|
||||
fw.indent()<<"NumberImageCells "<<tf.getNumberImageCells()<<std::endl;
|
||||
fw.indent()<<"Colours {"<<std::endl;
|
||||
|
||||
fw.moveIn();
|
||||
for(unsigned int i = 0; i<tf.getNumberCellsX(); ++i)
|
||||
for(osg::TransferFunction1D::ColorMap::const_iterator itr = colorMap.begin();
|
||||
itr != colorMap.end();
|
||||
++itr)
|
||||
{
|
||||
const osg::Vec4& c = tf.getValue(i);
|
||||
fw.indent()<<c.r()<<" "<<c.g()<<" "<<c.b()<<" "<<c.a()<<std::endl;
|
||||
const osg::Vec4& c = itr->second;
|
||||
fw.indent()<<itr->first<<" "<<c.r()<<" "<<c.g()<<" "<<c.b()<<" "<<c.a()<<std::endl;
|
||||
}
|
||||
fw.moveOut();
|
||||
fw.indent()<<"}"<<std::endl;
|
||||
|
||||
Reference in New Issue
Block a user