Added Property::getModifiedCount() + dirty() to help with tracking changes. Added VolumeSettings serializers for Property objects

git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14421 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield 2014-08-25 16:56:47 +00:00
parent 6126379362
commit d1bf811331
6 changed files with 44 additions and 17 deletions

View File

@ -511,7 +511,7 @@ public:
: ParentType(name, def), _getter(gf), _setter(sf) {} : ParentType(name, def), _getter(gf), _setter(sf) {}
virtual bool set(osg::Object& obj, void* value) { C& object = OBJECT_CAST<C&>(obj); (object.*_setter)( *(reinterpret_cast<P**>(value)) ); return true; } virtual bool set(osg::Object& obj, void* value) { C& object = OBJECT_CAST<C&>(obj); (object.*_setter)( *(reinterpret_cast<P**>(value)) ); return true; }
virtual bool get(const osg::Object& obj, void* value) { const C& object = OBJECT_CAST<const C&>(obj);*(reinterpret_cast<const P**>(value )) = (object.*_getter)(); return true; } virtual bool get(const osg::Object& obj, void* value) { if (_setter!=0) { const C& object = OBJECT_CAST<const C&>(obj);*(reinterpret_cast<const P**>(value )) = (object.*_getter)(); return true; } else return false;}
virtual bool read( InputStream& is, osg::Object& obj ) virtual bool read( InputStream& is, osg::Object& obj )
{ {
@ -1643,6 +1643,10 @@ public:
wrapper->addSerializer( new osgDB::ObjectSerializer< MyClass, TYPE >( \ wrapper->addSerializer( new osgDB::ObjectSerializer< MyClass, TYPE >( \
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_OBJECT ) #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_OBJECT )
#define ADD_OBJECT_SERIALIZER_NO_SET(PROP, TYPE, DEF) \
wrapper->addSerializer( new osgDB::ObjectSerializer< MyClass, TYPE >( \
#PROP, DEF, &MyClass::get##PROP, 0), osgDB::BaseSerializer::RW_OBJECT )
#define ADD_IMAGE_SERIALIZER(PROP, TYPE, DEF) \ #define ADD_IMAGE_SERIALIZER(PROP, TYPE, DEF) \
wrapper->addSerializer( new osgDB::ImageSerializer< MyClass, TYPE >( \ wrapper->addSerializer( new osgDB::ImageSerializer< MyClass, TYPE >( \
#PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_IMAGE ) #PROP, DEF, &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_IMAGE )

View File

@ -82,12 +82,19 @@ class OSGVOLUME_EXPORT Property : public osg::Object
META_Object(osgVolume, Property); META_Object(osgVolume, Property);
void dirty() { ++_modifiedCount; }
void setModifiedCount(unsigned int c) { _modifiedCount = c; }
unsigned int getModifiedCount() const { return _modifiedCount; }
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); } virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
virtual void traverse(PropertyVisitor& pv) {} virtual void traverse(PropertyVisitor& pv) {}
protected: protected:
virtual ~Property(); virtual ~Property();
unsigned int _modifiedCount;
}; };
class OSGVOLUME_EXPORT CompositeProperty : public Property class OSGVOLUME_EXPORT CompositeProperty : public Property
@ -123,7 +130,7 @@ class OSGVOLUME_EXPORT CompositeProperty : public Property
const Property* getProperty(unsigned int i) const { return i<_properties.size() ? _properties[i].get() : 0; } const Property* getProperty(unsigned int i) const { return i<_properties.size() ? _properties[i].get() : 0; }
void addProperty(Property* property) { _properties.push_back(property); } void addProperty(Property* property) { _properties.push_back(property); dirty(); }
void removeProperty(unsigned int i) { _properties.erase(_properties.begin()+i); } void removeProperty(unsigned int i) { _properties.erase(_properties.begin()+i); }
@ -169,7 +176,7 @@ class OSGVOLUME_EXPORT SwitchProperty : public CompositeProperty
/** Set which child property is active. /** Set which child property is active.
* -1 disables all children.*/ * -1 disables all children.*/
void setActiveProperty(int i) { _activeProperty = i; } void setActiveProperty(int i) { _activeProperty = i; dirty(); }
/** Get the active property.*/ /** Get the active property.*/
int getActiveProperty() const { return _activeProperty; } int getActiveProperty() const { return _activeProperty; }
@ -225,7 +232,7 @@ class OSGVOLUME_EXPORT ScalarProperty : public Property
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); } virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
/** Set the value.*/ /** Set the value.*/
virtual void setValue(float v) { _uniform->set(v); } virtual void setValue(float v) { _uniform->set(v); dirty(); }
/** Get the value.*/ /** Get the value.*/
float getValue() const { float v; _uniform->get(v); return v; } float getValue() const { float v; _uniform->get(v); return v; }

View File

@ -33,7 +33,7 @@ class OSGVOLUME_EXPORT VolumeSettings : public Property
virtual void accept(PropertyVisitor& pv); virtual void accept(PropertyVisitor& pv);
virtual void traverse(PropertyVisitor& pv); virtual void traverse(PropertyVisitor& pv);
void setFilename(const std::string& str) { _filename = str; } void setFilename(const std::string& str) { _filename = str; dirty(); }
const std::string& getFilename() const { return _filename; } const std::string& getFilename() const { return _filename; }
enum Technique enum Technique
@ -43,7 +43,7 @@ class OSGVOLUME_EXPORT VolumeSettings : public Property
MultiPass MultiPass
}; };
void setTechnique(Technique technique) { _technique = technique; } void setTechnique(Technique technique) { _technique = technique; dirty(); }
Technique getTechnique() const { return _technique; } Technique getTechnique() const { return _technique; }
enum ShadingModel enum ShadingModel
@ -54,24 +54,28 @@ class OSGVOLUME_EXPORT VolumeSettings : public Property
MaximumIntensityProjection MaximumIntensityProjection
}; };
void setShadingModel(ShadingModel sm) { _shadingModel = sm; } void setShadingModel(ShadingModel sm) { _shadingModel = sm; dirty(); }
ShadingModel getShadingModel() const { return _shadingModel; } ShadingModel getShadingModel() const { return _shadingModel; }
void setSampleRatio(float sr) { _sampleRatioProperty->setValue(sr); } void setSampleRatio(float sr) { _sampleRatioProperty->setValue(sr); dirty(); }
float getSampleRatio() const { return _sampleRatioProperty->getValue(); } float getSampleRatio() const { return _sampleRatioProperty->getValue(); }
SampleRatioProperty* getSampleRatioProperty() const { return _sampleRatioProperty.get(); } SampleRatioProperty* getSampleRatioProperty() { return _sampleRatioProperty.get(); }
const SampleRatioProperty* getSampleRatioProperty() const { return _sampleRatioProperty.get(); }
void setSampleRatioWhenMoving(float sr) { _sampleRatioWhenMovingProperty->setValue(sr); } void setSampleRatioWhenMoving(float sr) { _sampleRatioWhenMovingProperty->setValue(sr); dirty(); }
float getSampleRatioWhenMoving() const { return _sampleRatioWhenMovingProperty->getValue(); } float getSampleRatioWhenMoving() const { return _sampleRatioWhenMovingProperty->getValue(); }
SampleRatioWhenMovingProperty* getSampleRatioWhenMovingProperty() const { return _sampleRatioWhenMovingProperty.get(); } SampleRatioWhenMovingProperty* getSampleRatioWhenMovingProperty() { return _sampleRatioWhenMovingProperty.get(); }
const SampleRatioWhenMovingProperty* getSampleRatioWhenMovingProperty() const { return _sampleRatioWhenMovingProperty.get(); }
void setCutoff(float co) { _cutoffProperty->setValue(co); } void setCutoff(float co) { _cutoffProperty->setValue(co); dirty(); }
float getCutoff() const { return _cutoffProperty->getValue(); } float getCutoff() const { return _cutoffProperty->getValue(); }
AlphaFuncProperty* getCutoffProperty() const { return _cutoffProperty.get(); } AlphaFuncProperty* getCutoffProperty() { return _cutoffProperty.get(); }
const AlphaFuncProperty* getCutoffProperty() const { return _cutoffProperty.get(); }
void setTransparency(float t) { _transparencyProperty->setValue(t); } void setTransparency(float t) { _transparencyProperty->setValue(t); dirty(); }
float getTransparency() const { return _transparencyProperty->getValue(); } float getTransparency() const { return _transparencyProperty->getValue(); }
TransparencyProperty* getTransparencyProperty() const { return _transparencyProperty.get(); } TransparencyProperty* getTransparencyProperty() { return _transparencyProperty.get(); }
const TransparencyProperty* getTransparencyProperty() const { return _transparencyProperty.get(); }
protected: protected:

View File

@ -19,12 +19,14 @@
using namespace osgVolume; using namespace osgVolume;
Property::Property() Property::Property():
_modifiedCount(0)
{ {
} }
Property::Property(const Property& property,const osg::CopyOp& copyop): Property::Property(const Property& property,const osg::CopyOp& copyop):
osg::Object(property,copyop) osg::Object(property,copyop),
_modifiedCount(0)
{ {
} }
@ -49,6 +51,7 @@ CompositeProperty::CompositeProperty(const CompositeProperty& compositeProperty,
void CompositeProperty::clear() void CompositeProperty::clear()
{ {
_properties.clear(); _properties.clear();
dirty();
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -136,6 +139,7 @@ AlphaFuncProperty::AlphaFuncProperty(const AlphaFuncProperty& afp,const osg::Cop
void AlphaFuncProperty::setValue(float v) void AlphaFuncProperty::setValue(float v)
{ {
dirty();
_uniform->set(v); _uniform->set(v);
_alphaFunc->setReferenceValue(v); _alphaFunc->setReferenceValue(v);
} }

View File

@ -8,4 +8,5 @@ REGISTER_OBJECT_WRAPPER( osgVolume_Property,
osgVolume::Property, osgVolume::Property,
"osg::Object osgVolume::Property" ) "osg::Object osgVolume::Property" )
{ {
ADD_UINT_SERIALIZER_NO_SET( ModifiedCount, 0 );
} }

View File

@ -28,4 +28,11 @@ REGISTER_OBJECT_WRAPPER( osgVolume_VolumeSettings,
ADD_FLOAT_SERIALIZER( SampleRatioWhenMoving, 1.0f ); ADD_FLOAT_SERIALIZER( SampleRatioWhenMoving, 1.0f );
ADD_FLOAT_SERIALIZER( Cutoff, 0.0f ); ADD_FLOAT_SERIALIZER( Cutoff, 0.0f );
ADD_FLOAT_SERIALIZER( Transparency, 1.0f ); ADD_FLOAT_SERIALIZER( Transparency, 1.0f );
ADD_OBJECT_SERIALIZER_NO_SET( SampleRatioProperty, osgVolume::SampleRatioProperty, NULL );
ADD_OBJECT_SERIALIZER_NO_SET( SampleRatioWhenMovingProperty, osgVolume::SampleRatioWhenMovingProperty, NULL );
ADD_OBJECT_SERIALIZER_NO_SET( CutoffProperty, osgVolume::AlphaFuncProperty, NULL );
ADD_OBJECT_SERIALIZER_NO_SET( TransparencyProperty, osgVolume::TransparencyProperty, NULL );
} }