Added osgVolume .osg plugin

This commit is contained in:
Robert Osfield
2009-01-14 20:32:06 +00:00
parent d87ec7cb18
commit 1a00a2ce3c
9 changed files with 544 additions and 0 deletions

View File

@@ -44,6 +44,7 @@ ADD_SUBDIRECTORY(osgText)
ADD_SUBDIRECTORY(osgViewer)
ADD_SUBDIRECTORY(osgShadow)
ADD_SUBDIRECTORY(osgTerrain)
ADD_SUBDIRECTORY(osgVolume)
ADD_SUBDIRECTORY(osgWidget)
ADD_SUBDIRECTORY(osga)
ADD_SUBDIRECTORY(rot)

View File

@@ -0,0 +1,16 @@
SET(TARGET_SRC
Locator.cpp
ImageLayer.cpp
Layer.cpp
Volume.cpp
VolumeTile.cpp
ShaderTechnique.cpp
FixedFunctionTechnique.cpp
)
SET(TARGET_ADDED_LIBRARIES osgVolume )
#### end var setup ###
SETUP_PLUGIN(osgvolume)

View File

@@ -0,0 +1,40 @@
#include <osgVolume/FixedFunctionTechnique>
#include <iostream>
#include <string>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/io_utils>
#include <osgDB/ReadFile>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
#include <osgDB/ParameterOutput>
bool FixedFunctionTechnique_readLocalData(osg::Object &obj, osgDB::Input &fr);
bool FixedFunctionTechnique_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
osgDB::RegisterDotOsgWrapperProxy FixedFunctionTechnique_Proxy
(
new osgVolume::FixedFunctionTechnique,
"FixedFunctionTechnique",
"FixedFunctionTechnique Object",
FixedFunctionTechnique_readLocalData,
FixedFunctionTechnique_writeLocalData
);
bool FixedFunctionTechnique_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
//osgVolume::FixedFunctionTechnique& fft = static_cast<osgVolume::FixedFunctionTechnique&>(obj);
bool itrAdvanced = false;
return itrAdvanced;
}
bool FixedFunctionTechnique_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
{
//const osgVolume::FixedFunctionTechnique& fft = static_cast<const osgVolume::FixedFunctionTechnique&>(obj);
return true;
}

View File

@@ -0,0 +1,73 @@
#include <osgVolume/Layer>
#include <iostream>
#include <string>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/io_utils>
#include <osgDB/ReadFile>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
#include <osgDB/ParameterOutput>
#include <osgVolume/VolumeTile>
bool ImageLayer_readLocalData(osg::Object &obj, osgDB::Input &fr);
bool ImageLayer_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
osgDB::RegisterDotOsgWrapperProxy ImageLayer_Proxy
(
new osgVolume::ImageLayer,
"ImageLayer",
"Object Layer ImageLayer",
ImageLayer_readLocalData,
ImageLayer_writeLocalData
);
bool ImageLayer_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
osgVolume::ImageLayer& layer = static_cast<osgVolume::ImageLayer&>(obj);
bool itrAdvanced = false;
if (fr.matchSequence("file %w") || fr.matchSequence("file %s"))
{
std::string filename = fr[1].getStr();
if (!filename.empty())
{
bool deferExternalLayerLoading = false;
layer.setFileName(filename);
if (!deferExternalLayerLoading)
{
osg::ref_ptr<osg::Image> image = fr.readImage(filename.c_str());
if (image.valid())
{
layer.setImage(image.get());
}
}
}
fr += 2;
itrAdvanced = true;
}
return itrAdvanced;
}
bool ImageLayer_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
{
const osgVolume::ImageLayer& layer = static_cast<const osgVolume::ImageLayer&>(obj);
if (!layer.getFileName().empty())
{
fw.indent()<<"file "<< layer.getFileName() << std::endl;
}
return true;
}

View File

@@ -0,0 +1,56 @@
#include <osgVolume/Layer>
#include <iostream>
#include <string>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/io_utils>
#include <osgDB/ReadFile>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
#include <osgDB/ParameterOutput>
#include <string.h>
bool Layer_readLocalData(osg::Object &obj, osgDB::Input &fr);
bool Layer_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
bool Layer_matchFilterStr(const char* str, osg::Texture::FilterMode& filter);
const char* Layer_getFilterStr(osg::Texture::FilterMode filter);
osgDB::RegisterDotOsgWrapperProxy Layer_Proxy
(
new osgVolume::Layer,
"Layer",
"Object Layer",
Layer_readLocalData,
Layer_writeLocalData
);
bool Layer_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
osgVolume::Layer& layer = static_cast<osgVolume::Layer&>(obj);
bool itrAdvanced = false;
osg::ref_ptr<osg::Object> readObject = fr.readObjectOfType(osgDB::type_wrapper<osgVolume::Locator>());
osgVolume::Locator* locator = dynamic_cast<osgVolume::Locator*>(readObject.get());
if (locator) layer.setLocator(locator);
return itrAdvanced;
}
bool Layer_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
{
const osgVolume::Layer& layer = static_cast<const osgVolume::Layer&>(obj);
if (layer.getLocator())
{
fw.writeObject(*layer.getLocator());
}
return true;
}

View File

@@ -0,0 +1,85 @@
#include <osgVolume/VolumeTile>
#include <iostream>
#include <string>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/io_utils>
#include <osgDB/ReadFile>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
#include <osgDB/ParameterOutput>
bool Locator_readLocalData(osg::Object &obj, osgDB::Input &fr);
bool Locator_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
osgDB::RegisterDotOsgWrapperProxy Locator_Proxy
(
new osgVolume::Locator,
"Locator",
"Object Locator",
Locator_readLocalData,
Locator_writeLocalData
);
bool Locator_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
osgVolume::Locator& locator = static_cast<osgVolume::Locator&>(obj);
bool itrAdvanced = false;
if (fr.matchSequence("Transform {"))
{
int tansform_entry = fr[0].getNoNestedBrackets();
fr += 2;
int row=0;
int col=0;
double v;
osg::Matrixd matrix;
while (!fr.eof() && fr[0].getNoNestedBrackets()>tansform_entry)
{
if (fr[0].getFloat(v))
{
matrix(row,col)=v;
++col;
if (col>=4)
{
col = 0;
++row;
}
++fr;
}
else fr.advanceOverCurrentFieldOrBlock();
}
locator.setTransform(matrix);
++fr;
itrAdvanced = true;
}
return itrAdvanced;
}
bool Locator_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
{
const osgVolume::Locator& locator = static_cast<const osgVolume::Locator&>(obj);
const osg::Matrixd& matrix = locator.getTransform();
fw.indent() << "Transform {" << std::endl;
fw.moveIn();
fw.indent() << matrix(0,0) << " " << matrix(0,1) << " " << matrix(0,2) << " " << matrix(0,3) << std::endl;
fw.indent() << matrix(1,0) << " " << matrix(1,1) << " " << matrix(1,2) << " " << matrix(1,3) << std::endl;
fw.indent() << matrix(2,0) << " " << matrix(2,1) << " " << matrix(2,2) << " " << matrix(2,3) << std::endl;
fw.indent() << matrix(3,0) << " " << matrix(3,1) << " " << matrix(3,2) << " " << matrix(3,3) << std::endl;
fw.moveOut();
fw.indent() << "}"<< std::endl;
return true;
}

View File

@@ -0,0 +1,40 @@
#include <osgVolume/ShaderTechnique>
#include <iostream>
#include <string>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/io_utils>
#include <osgDB/ReadFile>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
#include <osgDB/ParameterOutput>
bool ShaderTechnique_readLocalData(osg::Object &obj, osgDB::Input &fr);
bool ShaderTechnique_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
osgDB::RegisterDotOsgWrapperProxy ShaderTechnique_Proxy
(
new osgVolume::ShaderTechnique,
"ShaderTechnique",
"ShaderTechnique Object",
ShaderTechnique_readLocalData,
ShaderTechnique_writeLocalData
);
bool ShaderTechnique_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
//osgVolume::ShaderTechnique& st = static_cast<osgVolume::ShaderTechnique&>(obj);
bool itrAdvanced = false;
return itrAdvanced;
}
bool ShaderTechnique_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
{
//const osgVolume::ShaderTechnique& st = static_cast<const osgVolume::ShaderTechnique&>(obj);
return true;
}

View File

@@ -0,0 +1,56 @@
#include <osgVolume/Volume>
#include <iostream>
#include <string>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/io_utils>
#include <osgDB/ReadFile>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
#include <osgDB/ParameterOutput>
bool Volume_readLocalData(osg::Object &obj, osgDB::Input &fr);
bool Volume_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
osgDB::RegisterDotOsgWrapperProxy Volume_Proxy
(
new osgVolume::Volume,
"Volume",
"Object Node Volume Group",
Volume_readLocalData,
Volume_writeLocalData
);
bool Volume_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
osgVolume::Volume& volume = static_cast<osgVolume::Volume&>(obj);
bool itrAdvanced = false;
osg::ref_ptr<osg::Object> readObject = fr.readObjectOfType(osgDB::type_wrapper<osgVolume::VolumeTechnique>());
if (readObject.valid())
{
volume.setVolumeTechnique(dynamic_cast<osgVolume::VolumeTechnique*>(readObject.get()));
itrAdvanced = true;
}
return itrAdvanced;
}
bool Volume_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
{
const osgVolume::Volume& volume = static_cast<const osgVolume::Volume&>(obj);
osg::notify(osg::NOTICE)<<"Volume write"<<std::endl;
if (volume.getVolumeTechnique())
{
fw.writeObject(*volume.getVolumeTechnique());
}
return true;
}

View File

@@ -0,0 +1,177 @@
#include <osgVolume/VolumeTile>
#include <iostream>
#include <string>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/io_utils>
#include <osgDB/ReadFile>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
#include <osgDB/ParameterOutput>
bool VolumeTile_readLocalData(osg::Object &obj, osgDB::Input &fr);
bool VolumeTile_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
osgDB::RegisterDotOsgWrapperProxy VolumeTile_Proxy
(
new osgVolume::VolumeTile,
"VolumeTile",
"Object Node VolumeTile Group",
VolumeTile_readLocalData,
VolumeTile_writeLocalData
);
osg::TransferFunction* readTransferFunction(osgDB::Input& fr)
{
osg::ref_ptr<osg::TransferFunction1D> tf = new osg::TransferFunction1D;
int entry = fr[0].getNoNestedBrackets();
fr += 2;
std::vector<osg::Vec4> colours;
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
bool itrAdvanced = false;
if (fr.matchSequence("range %f %f"))
{
float minValue,maxValue;
fr[1].getFloat(minValue);
fr[2].getFloat(maxValue);
tf->setInputRange(minValue,maxValue);
fr += 3;
itrAdvanced = true;
}
if (fr.matchSequence("color %f %f %f %f"))
{
float r,g,b,a;
fr[1].getFloat(r);
fr[2].getFloat(g);
fr[3].getFloat(b);
fr[4].getFloat(a);
colours.push_back(osg::Vec4(r,g,b,a));
fr += 5;
itrAdvanced = true;
}
if (fr.matchSequence("color %f %f %f"))
{
float r,g,b;
fr[1].getFloat(r);
fr[2].getFloat(g);
fr[3].getFloat(b);
colours.push_back(osg::Vec4(r,g,b,1.0f));
fr += 5;
itrAdvanced = true;
}
if (!itrAdvanced)
{
if (fr[0].getStr()) osg::notify(osg::NOTICE)<<"TransferFunction - unreconised token : "<<fr[0].getStr() << std::endl;
++fr;
}
}
// step over trailing }
++fr;
if (!colours.empty())
{
tf->allocate(colours.size());
for(unsigned int i=0; i<colours.size(); ++i)
{
tf->setValue(i, colours[i]);
}
}
if (tf->getNumberCellsX()==0)
{
tf->allocate(6);
tf->setValue(0, osg::Vec4(1.0,1.0,1.0,1.0));
tf->setValue(1, osg::Vec4(1.0,0.0,1.0,1.0));
tf->setValue(2, osg::Vec4(1.0,0.0,0.0,1.0));
tf->setValue(3, osg::Vec4(1.0,1.0,0.0,1.0));
tf->setValue(4, osg::Vec4(0.0,1.0,1.0,1.0));
tf->setValue(5, osg::Vec4(0.0,1.0,0.0,1.0));
}
return tf.release();
}
bool VolumeTile_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
osgVolume::VolumeTile& volumeTile = static_cast<osgVolume::VolumeTile&>(obj);
bool itrAdvanced = false;
osg::ref_ptr<osg::Object> readObject = fr.readObjectOfType(osgDB::type_wrapper<osgVolume::Locator>());
if (readObject.valid()) itrAdvanced = true;
osgVolume::Locator* locator = dynamic_cast<osgVolume::Locator*>(readObject.get());
if (locator) volumeTile.setLocator(locator);
{
osg::ref_ptr<osg::Object> readObject = fr.readObjectOfType(osgDB::type_wrapper<osgVolume::Layer>());
osgVolume::Layer* readLayer = dynamic_cast<osgVolume::Layer*>(readObject.get());
if (readLayer)
{
volumeTile.setLayer(readLayer);
}
itrAdvanced = true;
}
readObject = fr.readObjectOfType(osgDB::type_wrapper<osgVolume::VolumeTechnique>());
if (readObject.valid())
{
volumeTile.setVolumeTechnique(dynamic_cast<osgVolume::VolumeTechnique*>(readObject.get()));
itrAdvanced = true;
}
return itrAdvanced;
}
bool VolumeTile_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
{
const osgVolume::VolumeTile& volumeTile = static_cast<const osgVolume::VolumeTile&>(obj);
int prec = fw.precision();
fw.precision(15);
if (volumeTile.getLocator())
{
fw.writeObject(*volumeTile.getLocator());
}
{
const osgVolume::Layer* layer = volumeTile.getLayer();
if (layer)
{
fw.writeObject(*layer);
}
}
if (volumeTile.getVolumeTechnique())
{
fw.writeObject(*volumeTile.getVolumeTechnique());
}
fw.precision(prec);
return true;
}