diff --git a/examples/osgvolume/osgvolume.cpp b/examples/osgvolume/osgvolume.cpp index 584774ad2..37d333655 100644 --- a/examples/osgvolume/osgvolume.cpp +++ b/examples/osgvolume/osgvolume.cpp @@ -1067,8 +1067,14 @@ int main( int argc, char **argv ) sp->setActiveProperty(0); osgVolume::AlphaFuncProperty* ap = new osgVolume::AlphaFuncProperty(alphaFunc); - osgVolume::SampleDensityProperty* sd = new osgVolume::SampleDensityProperty(0.005); + + // SampleDensity is now deprecated + osgVolume::SampleDensityProperty* sd = new osgVolume::SampleDensityProperty(0.005f); osgVolume::SampleDensityWhenMovingProperty* sdwm = sampleDensityWhenMoving!=0.0 ? new osgVolume::SampleDensityWhenMovingProperty(sampleDensityWhenMoving) : 0; + + // use SampleRatio in place of SampleDensity + osgVolume::SampleRatioProperty* sr = new osgVolume::SampleRatioProperty(1.0f); + osgVolume::TransparencyProperty* tp = new osgVolume::TransparencyProperty(1.0); osgVolume::TransferFunctionProperty* tfp = transferFunction.valid() ? new osgVolume::TransferFunctionProperty(transferFunction.get()) : 0; @@ -1076,8 +1082,10 @@ int main( int argc, char **argv ) // Standard osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; cp->addProperty(ap); - cp->addProperty(sd); + if (useMultipass) cp->addProperty(sr); + else cp->addProperty(sd); cp->addProperty(tp); + if (sdwm) cp->addProperty(sdwm); if (tfp) cp->addProperty(tfp); @@ -1088,7 +1096,8 @@ int main( int argc, char **argv ) // Light osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; cp->addProperty(ap); - cp->addProperty(sd); + if (useMultipass) cp->addProperty(sr); + else cp->addProperty(sd); cp->addProperty(tp); cp->addProperty(new osgVolume::LightingProperty); if (sdwm) cp->addProperty(sdwm); @@ -1100,7 +1109,8 @@ int main( int argc, char **argv ) { // Isosurface osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; - cp->addProperty(sd); + if (useMultipass) cp->addProperty(sr); + else cp->addProperty(sd); cp->addProperty(tp); cp->addProperty(new osgVolume::IsoSurfaceProperty(alphaFunc)); if (sdwm) cp->addProperty(sdwm); @@ -1113,7 +1123,10 @@ int main( int argc, char **argv ) // MaximumIntensityProjection osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; cp->addProperty(ap); - cp->addProperty(sd); + + if (useMultipass) cp->addProperty(sr); + else cp->addProperty(sd); + cp->addProperty(tp); cp->addProperty(new osgVolume::MaximumIntensityProjectionProperty); if (sdwm) cp->addProperty(sdwm); diff --git a/include/osgVolume/Property b/include/osgVolume/Property index 5c2c955e0..ef6cba779 100644 --- a/include/osgVolume/Property +++ b/include/osgVolume/Property @@ -34,6 +34,7 @@ class IsoSurfaceProperty; class MaximumIntensityProjectionProperty; class LightingProperty; class AlphaFuncProperty; +class SampleRatioProperty; class SampleDensityProperty; class SampleDensityWhenMovingProperty; class TransparencyProperty; @@ -55,6 +56,7 @@ class OSGVOLUME_EXPORT PropertyVisitor virtual void apply(AlphaFuncProperty&) {} virtual void apply(MaximumIntensityProjectionProperty&) {} virtual void apply(LightingProperty&) {} + virtual void apply(SampleRatioProperty&) {} virtual void apply(SampleDensityProperty&) {} virtual void apply(SampleDensityWhenMovingProperty&) {} virtual void apply(TransparencyProperty&) {} @@ -327,6 +329,25 @@ class OSGVOLUME_EXPORT SampleDensityWhenMovingProperty : public ScalarProperty virtual ~SampleDensityWhenMovingProperty() {} }; +/** 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 SampleRatioProperty : public ScalarProperty +{ + public: + + SampleRatioProperty(float value=1.0f); + + SampleRatioProperty(const SampleRatioProperty& isp,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + + META_Object(osgVolume, SampleRatioProperty); + + virtual void accept(PropertyVisitor& pv) { pv.apply(*this); } + + protected: + + virtual ~SampleRatioProperty() {} +}; + + class OSGVOLUME_EXPORT TransparencyProperty : public ScalarProperty { public: @@ -360,6 +381,7 @@ class OSGVOLUME_EXPORT CollectPropertiesVisitor : public osgVolume::PropertyVisi virtual void apply(LightingProperty& lp); virtual void apply(SampleDensityProperty& sdp); virtual void apply(SampleDensityWhenMovingProperty& sdp); + virtual void apply(SampleRatioProperty& sdp); virtual void apply(TransparencyProperty& tp); osg::ref_ptr _tfProperty; @@ -369,6 +391,7 @@ class OSGVOLUME_EXPORT CollectPropertiesVisitor : public osgVolume::PropertyVisi osg::ref_ptr _lightingProperty; osg::ref_ptr _sampleDensityProperty; osg::ref_ptr _sampleDensityWhenMovingProperty; + osg::ref_ptr _sampleRatioProperty; osg::ref_ptr _transparencyProperty; }; diff --git a/src/osgVolume/MultipassTechnique.cpp b/src/osgVolume/MultipassTechnique.cpp index 3d2d066e8..5bd822169 100644 --- a/src/osgVolume/MultipassTechnique.cpp +++ b/src/osgVolume/MultipassTechnique.cpp @@ -185,10 +185,10 @@ void MultipassTechnique::init() alphaFuncValue = cpv._isoProperty->getValue(); } - if (cpv._sampleDensityProperty.valid()) - stateset->addUniform(cpv._sampleDensityProperty->getUniform()); + if (cpv._sampleRatioProperty.valid()) + stateset->addUniform(cpv._sampleRatioProperty->getUniform()); else - stateset->addUniform(new osg::Uniform("SampleDensityValue",0.0005f)); + stateset->addUniform(new osg::Uniform("SampleRatioValue",1.0f)); if (cpv._transparencyProperty.valid()) @@ -265,6 +265,8 @@ void MultipassTechnique::init() osg::ref_ptr volumeCellSize = new osg::Uniform("volumeCellSize", osg::Vec3(1.0f/static_cast(image_3d->s()),1.0f/static_cast(image_3d->t()),1.0f/static_cast(image_3d->r()))); stateset->addUniform(volumeCellSize.get()); + + OSG_NOTICE<<"Texture Dimensions "<s()<<", "<t()<<", "<r()<setValue(v); } if (_updateAlphaCutOff && cpv._afProperty.valid()) { - OSG_INFO<<"Setting afProperty to "<setValue(v2); } if (_updateTransparency && cpv._transparencyProperty.valid()) { - OSG_INFO<<"Setting transparency to "<setValue(1.0f-v2); } if (_updateSampleDensity && cpv._sampleDensityProperty.valid()) { - OSG_INFO<<"Setting sample density to "<setValue(v4); } if (_updateSampleDensity && cpv._sampleDensityWhenMovingProperty.valid()) @@ -426,6 +442,13 @@ bool PropertyAdjustmentCallback::handle(const osgGA::GUIEventAdapter& ea,osgGA:: OSG_INFO<<"Setting sample density when moving to "<setValue(v4); } + + if (_updateSampleDensity && cpv._sampleRatioProperty.valid()) + { + float sampleRatio = v2*4; + OSG_NOTICE<<"Setting sample ratio to "<setValue(sampleRatio); + } }