Permalink
Browse files

Added xml defined property/property animation to .p3d format for <vol…

…ume> propeties:

   alpha="$alphaname"
   cutoff="$cutoffname"
   region="$minx $miny $minz $maxx $maxy $maxz"
   sampleDensity="$densityname"
   sampleDensityWhenMoving="$densityname"
  • Loading branch information...
1 parent 65e17fe commit 1ac223e61382a0d1e8a6f5bb48bada3beed50dae @osg-training-guest osg-training-guest committed Nov 30, 2012
@@ -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:
@@ -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(); }
@@ -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);
@@ -1202,7 +1202,7 @@ void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& cons
if (getProperty(cur, "alpha", volumeData.alphaValue)) {}
if (getProperty(cur, "cutoff", volumeData.cutoffValue)) {}
- if (getProperty(cur, "region", 6, volumeData.region)) {}
+ if (getProperty(cur, "region", volumeData.region)) {}
if (getProperty(cur, "sampleDensity", volumeData.sampleDensityValue)) {}
if (getProperty(cur, "sampleDensityWhenMoving", volumeData.sampleDensityWhenMovingValue)) {}
@@ -15,6 +15,24 @@
using namespace osgPresentation;
+const osg::Object* osgPresentation::getUserObject(const osg::NodePath& nodepath, const std::string& name)
+{
+ for(osg::NodePath::const_reverse_iterator itr = nodepath.rbegin();
+ itr != nodepath.rend();
+ ++itr)
+ {
+ const osg::UserDataContainer* udc = (*itr)->getUserDataContainer();
+ const osg::Object* object = udc ? udc->getUserObject(name) : 0;
+ if (object) return object;
+ }
+ return 0;
+}
+
+bool osgPresentation::containsPropertyReference(const std::string& str)
+{
+ return (str.find('$')!=std::string::npos);
+}
+
void PropertyAnimation::reset()
Oops, something went wrong.

0 comments on commit 1ac223e

Please sign in to comment.