Added support to .p3d format's volume tag for the properties:

region="xmin ymin zmin xmax ymax zmax"
   alpha="float_value"
   cutoff="float_value"
   sampleDenstiy="float_value"
This commit is contained in:
Robert Osfield 2009-08-27 16:42:47 +00:00
parent 3f9216800d
commit ca78f3a6bc
3 changed files with 60 additions and 8 deletions

View File

@ -218,12 +218,25 @@ public:
VolumeData():
shadingModel(Standard),
useTabbedDragger(false),
useTrackballDragger(false) {}
useTrackballDragger(false),
region_in_pixel_coords(false),
alphaValue(1.0),
cutoffValue(0.1),
sampleDensityValue(0.005)
{
region[0] = region[1] = region[2] = 0.0f;
region[3] = region[4] = region[5] = 1.0f;
}
ShadingModel shadingModel;
osg::ref_ptr<osg::TransferFunction1D> transferFunction;
bool useTabbedDragger;
bool useTrackballDragger;
float region[6];
bool region_in_pixel_coords;
float alphaValue;
float cutoffValue;
float sampleDensityValue;
};

View File

@ -160,6 +160,7 @@ public:
inline bool read(const char* str, int& value) const;
inline bool read(const char* str, float& value) const;
inline bool read(const char* str, double& value) const;
inline bool read(const char* str, int numberValues, float* values) const;
inline bool read(const char* str, osg::Vec2& value) const;
inline bool read(const char* str, osg::Vec3& value) const;
inline bool read(const char* str, osg::Vec4& value) const;
@ -167,6 +168,7 @@ public:
inline bool read(const std::string& str, int& value) const;
inline bool read(const std::string& str, float& value) const;
inline bool read(const std::string& str, double& value) const;
inline bool read(const std::string& str, int numberValues, float* values) const;
inline bool read(const std::string& str, osg::Vec2& value) const;
inline bool read(const std::string& str, osg::Vec3& value) const;
inline bool read(const std::string& str, osg::Vec4& value) const;
@ -175,6 +177,7 @@ public:
bool getProperty(osgDB::XmlNode*cur, const char* token, int& value) const;
bool getProperty(osgDB::XmlNode*cur, const char* token, float& value) const;
bool getProperty(osgDB::XmlNode*cur, const char* token, double& value) const;
bool getProperty(osgDB::XmlNode*cur, const char* token, int numberValues, float* values) const;
bool getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec2& value) const;
bool getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec3& value) const;
bool getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec4& value) const;
@ -268,6 +271,18 @@ bool ReaderWriterP3DXML::read(const char* str, double& value) const
return !iss.fail();
}
bool ReaderWriterP3DXML::read(const char* str, int numberValues, float* values) const
{
if (!str) return false;
std::istringstream iss((const char*)str);
for(int i=0; i<numberValues && !iss.fail(); i++)
{
iss >> *values;
++values;
}
return !iss.fail();
}
bool ReaderWriterP3DXML::read(const char* str, osg::Vec2& value) const
{
if (!str) return false;
@ -313,6 +328,18 @@ bool ReaderWriterP3DXML::read(const std::string& str, double& value) const
return !iss.fail();
}
bool ReaderWriterP3DXML::read(const std::string& str, int numberValues, float* values) const
{
std::istringstream iss(str);
for(int i=0; i<numberValues && !iss.fail(); i++)
{
iss >> *values;
++values;
}
return !iss.fail();
}
bool ReaderWriterP3DXML::read(const std::string& str, osg::Vec2& value) const
{
std::istringstream iss(str);
@ -360,6 +387,13 @@ bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, doub
return read(itr->second,value);
}
bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, int numberValues, float* values) const
{
osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
if (itr==cur->properties.end()) return false;
return read(itr->second, numberValues, values);
}
bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec2& value) const
{
osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
@ -896,6 +930,11 @@ void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& cons
else if (technique=="light") volumeData.shadingModel = osgPresentation::SlideShowConstructor::VolumeData::Light;
}
if (getProperty(cur, "alpha", volumeData.alphaValue)) {}
if (getProperty(cur, "cutoff", volumeData.cutoffValue)) {}
if (getProperty(cur, "region", 6, volumeData.region)) {}
if (getProperty(cur, "sampleDensity", volumeData.sampleDensityValue)) {}
// check for any transfer function required
std::string transferFunctionFile;
if (getTrimmedProperty(cur, "tf", transferFunctionFile))

View File

@ -1549,19 +1549,19 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
if (matrix)
{
layer->setLocator(new osgVolume::Locator(*matrix));
tile->setLocator(new osgVolume::Locator(*matrix));
osg::Matrix tm = osg::Matrix::scale(volumeData.region[3]-volumeData.region[0], volumeData.region[4]-volumeData.region[1], volumeData.region[5]-volumeData.region[2]) *
osg::Matrix::translate(volumeData.region[0],volumeData.region[1],volumeData.region[2]);
tile->setLocator(new osgVolume::Locator(tm * (*matrix)));
}
tile->setLayer(layer.get());
float alphaFunc = 0.1;
osgVolume::SwitchProperty* sp = new osgVolume::SwitchProperty;
sp->setActiveProperty(0);
osgVolume::AlphaFuncProperty* ap = new osgVolume::AlphaFuncProperty(alphaFunc);
osgVolume::SampleDensityProperty* sd = new osgVolume::SampleDensityProperty(0.005);
osgVolume::TransparencyProperty* tp = new osgVolume::TransparencyProperty(1.0);
osgVolume::AlphaFuncProperty* ap = new osgVolume::AlphaFuncProperty(volumeData.cutoffValue);
osgVolume::TransparencyProperty* tp = new osgVolume::TransparencyProperty(volumeData.alphaValue);
osgVolume::SampleDensityProperty* sd = new osgVolume::SampleDensityProperty(volumeData.sampleDensityValue);
osgVolume::TransferFunctionProperty* tfp = volumeData.transferFunction.valid() ? new osgVolume::TransferFunctionProperty(volumeData.transferFunction.get()) : 0;
{
@ -1592,7 +1592,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty;
cp->addProperty(sd);
cp->addProperty(tp);
cp->addProperty(new osgVolume::IsoSurfaceProperty(alphaFunc));
cp->addProperty(new osgVolume::IsoSurfaceProperty(volumeData.cutoffValue));
if (tfp) cp->addProperty(tfp);
sp->addProperty(cp);