diff --git a/examples/osgvolume/osgvolume.cpp b/examples/osgvolume/osgvolume.cpp index d561f72e8..4a1a6a71d 100644 --- a/examples/osgvolume/osgvolume.cpp +++ b/examples/osgvolume/osgvolume.cpp @@ -1576,6 +1576,7 @@ int main( int argc, char **argv ) osgVolume::AlphaFuncProperty* ap = new osgVolume::AlphaFuncProperty(alphaFunc); osgVolume::SampleDensityProperty* sd = new osgVolume::SampleDensityProperty(0.005); + osgVolume::SampleDensityWhenMovingProperty* sdwm = new osgVolume::SampleDensityWhenMovingProperty(0.02); osgVolume::TransparencyProperty* tp = new osgVolume::TransparencyProperty(1.0); osgVolume::TransferFunctionProperty* tfp = transferFunction.valid() ? new osgVolume::TransferFunctionProperty(transferFunction.get()) : 0; @@ -1584,6 +1585,7 @@ int main( int argc, char **argv ) osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; cp->addProperty(ap); cp->addProperty(sd); + cp->addProperty(sdwm); cp->addProperty(tp); if (tfp) cp->addProperty(tfp); diff --git a/include/osgVolume/Property b/include/osgVolume/Property index eaf4f866e..44787ff5f 100644 --- a/include/osgVolume/Property +++ b/include/osgVolume/Property @@ -35,6 +35,7 @@ class MaximumIntensityProjectionProperty; class LightingProperty; class AlphaFuncProperty; class SampleDensityProperty; +class SampleDensityWhenMovingProperty; class TransparencyProperty; class OSGVOLUME_EXPORT PropertyVisitor @@ -55,6 +56,7 @@ class OSGVOLUME_EXPORT PropertyVisitor virtual void apply(MaximumIntensityProjectionProperty&) {} virtual void apply(LightingProperty&) {} virtual void apply(SampleDensityProperty&) {} + virtual void apply(SampleDensityWhenMovingProperty&) {} virtual void apply(TransparencyProperty&) {} bool _traverseOnlyActiveChildren; @@ -289,6 +291,7 @@ class OSGVOLUME_EXPORT LightingProperty : public Property }; +/** Sample density to use when the volume is static relative to the eye point or when moving if no SampleDensityWhenMovingProperty is assigned.*/ class OSGVOLUME_EXPORT SampleDensityProperty : public ScalarProperty { public: @@ -306,6 +309,24 @@ class OSGVOLUME_EXPORT SampleDensityProperty : public ScalarProperty virtual ~SampleDensityProperty() {} }; +/** Sample density to use when the volume is moving relative to the eye point.*/ +class OSGVOLUME_EXPORT SampleDensityWhenMovingProperty : public ScalarProperty +{ + public: + + SampleDensityWhenMovingProperty(float value=1.0); + + SampleDensityWhenMovingProperty(const SampleDensityWhenMovingProperty& isp,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + + META_Object(osgVolume, SampleDensityWhenMovingProperty); + + virtual void accept(PropertyVisitor& pv) { pv.apply(*this); } + + protected: + + virtual ~SampleDensityWhenMovingProperty() {} +}; + class OSGVOLUME_EXPORT TransparencyProperty : public ScalarProperty { public: @@ -338,6 +359,7 @@ class OSGVOLUME_EXPORT CollectPropertiesVisitor : public osgVolume::PropertyVisi virtual void apply(MaximumIntensityProjectionProperty& mip); virtual void apply(LightingProperty& lp); virtual void apply(SampleDensityProperty& sdp); + virtual void apply(SampleDensityWhenMovingProperty& sdp); virtual void apply(TransparencyProperty& tp); osg::ref_ptr _tfProperty; @@ -346,6 +368,7 @@ class OSGVOLUME_EXPORT CollectPropertiesVisitor : public osgVolume::PropertyVisi osg::ref_ptr _mipProperty; osg::ref_ptr _lightingProperty; osg::ref_ptr _sampleDensityProperty; + osg::ref_ptr _sampleDensityWhenMovingProperty; osg::ref_ptr _transparencyProperty; }; diff --git a/include/osgVolume/RayTracedTechnique b/include/osgVolume/RayTracedTechnique index 1d3da73a4..fa2a42848 100644 --- a/include/osgVolume/RayTracedTechnique +++ b/include/osgVolume/RayTracedTechnique @@ -52,7 +52,7 @@ class OSGVOLUME_EXPORT RayTracedTechnique : public VolumeTechnique OpenThreads::Mutex _mutex; ModelViewMatrixMap _modelViewMatrixMap; - osg::ref_ptr _lodStateSet; + osg::ref_ptr _whenMovingStateSet; }; } diff --git a/src/osgVolume/Property.cpp b/src/osgVolume/Property.cpp index 84055926d..e3db4f4c7 100644 --- a/src/osgVolume/Property.cpp +++ b/src/osgVolume/Property.cpp @@ -179,6 +179,21 @@ SampleDensityProperty::SampleDensityProperty(const SampleDensityProperty& isp,co } +///////////////////////////////////////////////////////////////////////////// +// +// SampleDensityWhenMovingProperty +// +SampleDensityWhenMovingProperty::SampleDensityWhenMovingProperty(float value): + ScalarProperty("SampleDensityValue",value) +{ +} + +SampleDensityWhenMovingProperty::SampleDensityWhenMovingProperty(const SampleDensityWhenMovingProperty& isp,const osg::CopyOp& copyop): + ScalarProperty(isp, copyop) +{ +} + + ///////////////////////////////////////////////////////////////////////////// // // TransparencyProperty @@ -246,6 +261,7 @@ void CollectPropertiesVisitor::apply(AlphaFuncProperty& af) { _afProperty = ⁡ void CollectPropertiesVisitor::apply(MaximumIntensityProjectionProperty& mip) { _mipProperty = &mip; } void CollectPropertiesVisitor::apply(LightingProperty& lp) { _lightingProperty = &lp; } void CollectPropertiesVisitor::apply(SampleDensityProperty& sdp) { _sampleDensityProperty = &sdp; } +void CollectPropertiesVisitor::apply(SampleDensityWhenMovingProperty& sdp) { _sampleDensityWhenMovingProperty = &sdp; } void CollectPropertiesVisitor::apply(TransparencyProperty& tp) { _transparencyProperty = &tp; } diff --git a/src/osgVolume/RayTracedTechnique.cpp b/src/osgVolume/RayTracedTechnique.cpp index 857e05d96..385996fc9 100644 --- a/src/osgVolume/RayTracedTechnique.cpp +++ b/src/osgVolume/RayTracedTechnique.cpp @@ -534,9 +534,11 @@ void RayTracedTechnique::init() } - _lodStateSet = new osg::StateSet; - _lodStateSet->addUniform(new osg::Uniform("SampleDensityValue",0.01f), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON); - + if (cpv._sampleDensityWhenMovingProperty.valid()) + { + _whenMovingStateSet = new osg::StateSet; + _whenMovingStateSet->addUniform(cpv._sampleDensityWhenMovingProperty->getUniform(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON); + } } void RayTracedTechnique::update(osgUtil::UpdateVisitor* uv) @@ -548,7 +550,7 @@ void RayTracedTechnique::cull(osgUtil::CullVisitor* cv) { if (!_transform.valid()) return; - if (_lodStateSet.valid()) + if (_whenMovingStateSet.valid()) { bool moving = false; { @@ -570,7 +572,7 @@ void RayTracedTechnique::cull(osgUtil::CullVisitor* cv) if (moving) { - cv->pushStateSet(_lodStateSet.get()); + cv->pushStateSet(_whenMovingStateSet.get()); _transform->accept(*cv); cv->popStateSet(); }