Added xml defined property/property animation to .p3d format for <volume> propeties:

alpha="$alphaname"
   cutoff="$cutoffname"
   region="$minx $miny $minz $maxx $maxy $maxz"
   sampleDensity="$densityname"
   sampleDensityWhenMoving="$densityname"
This commit is contained in:
Robert Osfield
2012-11-30 14:21:45 +00:00
parent 7ffde8abce
commit 236e75b2be
6 changed files with 274 additions and 30 deletions

View File

@@ -21,6 +21,8 @@
#include <osgPresentation/Export>
#include <sstream>
namespace osgPresentation
{
@@ -62,6 +64,69 @@ protected:
};
const osg::Object* OSGPRESENTATION_EXPORT getUserObject(const osg::NodePath& nodepath, const std::string& name);
template<typename T>
bool getUserValue(const osg::NodePath& nodepath, const std::string& name, T& value)
{
typedef osg::TemplateValueObject<T> UserValueObject;
const osg::Object* object = getUserObject(nodepath, name);
const UserValueObject* uvo = dynamic_cast<const UserValueObject*>(object);
if (uvo)
{
value = uvo->getValue();
return true;
}
else
{
return false;
}
}
bool OSGPRESENTATION_EXPORT containsPropertyReference(const std::string& str);
struct PropertyReader
{
PropertyReader(const osg::NodePath& nodePath, const std::string& str):
_nodePath(nodePath),
_sstream(str) {}
template<typename T>
bool read(T& value)
{
// skip white space.
while(!_sstream.fail() && _sstream.peek()==' ') _sstream.ignore();
// check to see if a &propertyName is used.
if (_sstream.peek()=='$')
{
std::string propertyName;
_sstream.ignore(1);
_sstream >> propertyName;
OSG_NOTICE<<"Reading propertyName="<<propertyName<<std::endl;
if (!_sstream.fail() && !propertyName.empty()) return getUserValue(_nodePath, propertyName, value);
else return false;
}
else
{
_sstream >> value;
OSG_NOTICE<<"Reading value="<<value<<std::endl;
return !_sstream.fail();
}
}
template<typename T>
PropertyReader& operator>>( T& value ) { read(value); return *this; }
bool ok() { return !_sstream.fail(); }
bool fail() { return _sstream.fail(); }
osg::NodePath _nodePath;
std::istringstream _sstream;
};
class OSGPRESENTATION_EXPORT PropertyAnimation : public osg::NodeCallback
{
public:

View File

@@ -28,6 +28,9 @@
#include <osgDB/FileUtils>
#include <osgVolume/VolumeTile>
#include <osgVolume/Property>
#include <osgPresentation/AnimationMaterial>
#include <osgPresentation/SlideEventHandler>
#include <osgPresentation/PropertyManager>
@@ -300,10 +303,9 @@ public:
useTabbedDragger(false),
useTrackballDragger(false),
region_in_pixel_coords(false),
alphaValue(1.0),
cutoffValue(0.1),
sampleDensityValue(0.005),
sampleDensityWhenMovingValue(0.0),
alphaValue("1.0"),
cutoffValue("0.1"),
sampleDensityValue("0.005"),
colorSpaceOperation(osg::NO_COLOR_SPACE_OPERATION),
colorModulate(1.0f,1.0f,1.0f,1.0f)
{
@@ -316,12 +318,12 @@ public:
osg::ref_ptr<osg::TransferFunction1D> transferFunction;
bool useTabbedDragger;
bool useTrackballDragger;
float region[6];
std::string region;
bool region_in_pixel_coords;
float alphaValue;
float cutoffValue;
float sampleDensityValue;
float sampleDensityWhenMovingValue;
std::string alphaValue;
std::string cutoffValue;
std::string sampleDensityValue;
std::string sampleDensityWhenMovingValue;
osg::ColorSpaceOperation colorSpaceOperation;
osg::Vec4 colorModulate;
@@ -461,6 +463,8 @@ public:
void addModel(const std::string& filename, const PositionData& positionData, const ModelData& modelData);
void setUpVolumeScalarProperty(osgVolume::VolumeTile* tile, osgVolume::ScalarProperty* property, const std::string& source);
void addVolume(const std::string& filename, const PositionData& positionData, const VolumeData& volumeData);
osg::Group* takePresentation() { return _root.release(); }

View File

@@ -216,7 +216,7 @@ class OSGVOLUME_EXPORT IsoSurfaceProperty : public ScalarProperty
{
public:
IsoSurfaceProperty(float value=1.0);
IsoSurfaceProperty(float value=1.0f);
IsoSurfaceProperty(const IsoSurfaceProperty& isp,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
@@ -233,7 +233,7 @@ class OSGVOLUME_EXPORT AlphaFuncProperty : public ScalarProperty
{
public:
AlphaFuncProperty(float value=1.0);
AlphaFuncProperty(float value=1.0f);
AlphaFuncProperty(const AlphaFuncProperty& isp,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
@@ -296,7 +296,7 @@ class OSGVOLUME_EXPORT SampleDensityProperty : public ScalarProperty
{
public:
SampleDensityProperty(float value=1.0);
SampleDensityProperty(float value=1.0f);
SampleDensityProperty(const SampleDensityProperty& isp,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
@@ -314,7 +314,7 @@ class OSGVOLUME_EXPORT SampleDensityWhenMovingProperty : public ScalarProperty
{
public:
SampleDensityWhenMovingProperty(float value=1.0);
SampleDensityWhenMovingProperty(float value=1.0f);
SampleDensityWhenMovingProperty(const SampleDensityWhenMovingProperty& isp,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
@@ -331,7 +331,7 @@ class OSGVOLUME_EXPORT TransparencyProperty : public ScalarProperty
{
public:
TransparencyProperty(float value=1.0);
TransparencyProperty(float value=1.0f);
TransparencyProperty(const TransparencyProperty& isp,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);