From d7944b6ca9d179ecf59824a90d3152c64aaaa2e4 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 18 Mar 2014 18:14:15 +0000 Subject: [PATCH] Addd ExteriorTransparencyFactorProperty for support of upcomming functionality of rendering a cube volume with a hull volume inside it. --- .../deprecated/SlideShowConstructor | 2 ++ include/osgVolume/Property | 26 ++++++++++++++++++ src/osgPlugins/p3d/ReaderWriterP3D.cpp | 1 + .../deprecated/SlideShowConstructor.cpp | 11 ++++++++ src/osgVolume/MultipassTechnique.cpp | 17 ++++++++++++ src/osgVolume/Property.cpp | 27 ++++++++++++++++++- 6 files changed, 83 insertions(+), 1 deletion(-) diff --git a/include/osgPresentation/deprecated/SlideShowConstructor b/include/osgPresentation/deprecated/SlideShowConstructor index 02afad5d3..941d278d7 100644 --- a/include/osgPresentation/deprecated/SlideShowConstructor +++ b/include/osgPresentation/deprecated/SlideShowConstructor @@ -306,6 +306,7 @@ public: region_in_pixel_coords(false), alphaValue("1.0"), cutoffValue("0.1"), + exteriorTransparencyFactorValue(""), sampleDensityValue("0.005"), sampleRatioValue("1.0"), colorSpaceOperation(osg::NO_COLOR_SPACE_OPERATION), @@ -325,6 +326,7 @@ public: bool region_in_pixel_coords; std::string alphaValue; std::string cutoffValue; + std::string exteriorTransparencyFactorValue; std::string sampleDensityValue; std::string sampleDensityWhenMovingValue; diff --git a/include/osgVolume/Property b/include/osgVolume/Property index 247271f6f..0af6dd8d2 100644 --- a/include/osgVolume/Property +++ b/include/osgVolume/Property @@ -39,6 +39,7 @@ class SampleRatioWhenMovingProperty; class SampleDensityProperty; class SampleDensityWhenMovingProperty; class TransparencyProperty; +class ExteriorTransparencyFactorProperty; class OSGVOLUME_EXPORT PropertyVisitor { @@ -62,6 +63,7 @@ class OSGVOLUME_EXPORT PropertyVisitor virtual void apply(SampleDensityProperty&) {} virtual void apply(SampleDensityWhenMovingProperty&) {} virtual void apply(TransparencyProperty&) {} + virtual void apply(ExteriorTransparencyFactorProperty&) {} bool _traverseOnlyActiveChildren; @@ -385,6 +387,23 @@ class OSGVOLUME_EXPORT TransparencyProperty : public ScalarProperty virtual ~TransparencyProperty() {} }; +class OSGVOLUME_EXPORT ExteriorTransparencyFactorProperty : public ScalarProperty +{ + public: + + ExteriorTransparencyFactorProperty(float value=0.0f); + + ExteriorTransparencyFactorProperty(const ExteriorTransparencyFactorProperty& isp,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + + META_Object(osgVolume, ExteriorTransparencyFactorProperty); + + virtual void accept(PropertyVisitor& pv) { pv.apply(*this); } + + protected: + + virtual ~ExteriorTransparencyFactorProperty() {} +}; + class OSGVOLUME_EXPORT CollectPropertiesVisitor : public osgVolume::PropertyVisitor { @@ -404,6 +423,7 @@ class OSGVOLUME_EXPORT CollectPropertiesVisitor : public osgVolume::PropertyVisi virtual void apply(SampleRatioProperty& sdp); virtual void apply(SampleRatioWhenMovingProperty& sdp); virtual void apply(TransparencyProperty& tp); + virtual void apply(ExteriorTransparencyFactorProperty& tp); osg::ref_ptr _tfProperty; osg::ref_ptr _isoProperty; @@ -415,6 +435,7 @@ class OSGVOLUME_EXPORT CollectPropertiesVisitor : public osgVolume::PropertyVisi osg::ref_ptr _sampleRatioProperty; osg::ref_ptr _sampleRatioWhenMovingProperty; osg::ref_ptr _transparencyProperty; + osg::ref_ptr _exteriorTransparencyFactorProperty; }; @@ -437,6 +458,9 @@ class OSGVOLUME_EXPORT PropertyAdjustmentCallback : public osgGA::GUIEventHandle void setKeyEventActivatesTransparencyAdjustment(int key) { _transparencyKey = key; } int getKeyEventActivatesTransparencyAdjustment() const { return _transparencyKey; } + void setKeyEventActivatesExteriorTransparencyFactorAdjustment(int key) { _exteriorTransparencyFactorKey = key; } + int getKeyEventActivatesExteriorTransparencyFactorAdjustment() const { return _exteriorTransparencyFactorKey; } + void setKeyEventActivatesSampleDensityAdjustment(int key) { _sampleDensityKey = key; } int getKeyEventActivatesSampleDensityAdjustment() const { return _sampleDensityKey; } @@ -448,10 +472,12 @@ class OSGVOLUME_EXPORT PropertyAdjustmentCallback : public osgGA::GUIEventHandle int _cyleForwardKey; int _cyleBackwardKey; int _transparencyKey; + int _exteriorTransparencyFactorKey; int _alphaFuncKey; int _sampleDensityKey; bool _updateTransparency; + bool _updateExteriorTransparencyFactor; bool _updateAlphaCutOff; bool _updateSampleDensity; }; diff --git a/src/osgPlugins/p3d/ReaderWriterP3D.cpp b/src/osgPlugins/p3d/ReaderWriterP3D.cpp index 69dab8dff..a62a89d33 100644 --- a/src/osgPlugins/p3d/ReaderWriterP3D.cpp +++ b/src/osgPlugins/p3d/ReaderWriterP3D.cpp @@ -1454,6 +1454,7 @@ void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& cons } if (getProperty(cur, "alpha", volumeData.alphaValue)) {} + if (getProperty(cur, "exteriorTransparencyFactor", volumeData.exteriorTransparencyFactorValue) || getProperty(cur, "etf", volumeData.exteriorTransparencyFactorValue)) {} if (getProperty(cur, "cutoff", volumeData.cutoffValue)) {} if (getProperty(cur, "region", volumeData.region)) {} if (getProperty(cur, "sampleDensity", volumeData.sampleDensityValue)) {} diff --git a/src/osgPresentation/deprecated/SlideShowConstructor.cpp b/src/osgPresentation/deprecated/SlideShowConstructor.cpp index 56baf0ff6..5ff591498 100644 --- a/src/osgPresentation/deprecated/SlideShowConstructor.cpp +++ b/src/osgPresentation/deprecated/SlideShowConstructor.cpp @@ -2737,6 +2737,13 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position osg::ref_ptr tp = new osgVolume::TransparencyProperty(1.0f); setUpVolumeScalarProperty(tile.get(), tp.get(), volumeData.alphaValue); + osg::ref_ptr etfp; + if (!volumeData.exteriorTransparencyFactorValue.empty()) + { + etfp = new osgVolume::ExteriorTransparencyFactorProperty(0.0f); + setUpVolumeScalarProperty(tile.get(), etfp.get(), volumeData.exteriorTransparencyFactorValue); + } + osg::ref_ptr sd = new osgVolume::SampleDensityProperty(0.005); setUpVolumeScalarProperty(tile.get(), sd.get(), volumeData.sampleDensityValue); @@ -2770,6 +2777,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position if (sr.valid()) cp->addProperty(sr.get()); if (srm.valid()) cp->addProperty(srm.get()); if (tfp.valid()) cp->addProperty(tfp.get()); + if (etfp.valid()) cp->addProperty(etfp.get()); sp->addProperty(cp); } @@ -2785,6 +2793,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position if (sr.valid()) cp->addProperty(sr.get()); if (srm.valid()) cp->addProperty(srm.get()); if (tfp.valid()) cp->addProperty(tfp.get()); + if (etfp.valid()) cp->addProperty(etfp.get()); sp->addProperty(cp); } @@ -2804,6 +2813,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position if (sr.valid()) cp->addProperty(sr.get()); if (srm.valid()) cp->addProperty(srm.get()); if (tfp.valid()) cp->addProperty(tfp.get()); + if (etfp.valid()) cp->addProperty(etfp.get()); sp->addProperty(cp); } @@ -2819,6 +2829,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position if (sr.valid()) cp->addProperty(sr.get()); if (srm.valid()) cp->addProperty(srm.get()); if (tfp.valid()) cp->addProperty(tfp.get()); + if (etfp.valid()) cp->addProperty(etfp.get()); sp->addProperty(cp); } diff --git a/src/osgVolume/MultipassTechnique.cpp b/src/osgVolume/MultipassTechnique.cpp index ac6cc9346..c9f3dd521 100644 --- a/src/osgVolume/MultipassTechnique.cpp +++ b/src/osgVolume/MultipassTechnique.cpp @@ -299,6 +299,17 @@ void MultipassTechnique::init() unsigned int volumeTextureUnit = 3; + bool requiresRenderingOfCubeAndHull = cpv._exteriorTransparencyFactorProperty.valid() && cpv._exteriorTransparencyFactorProperty->getValue()!=0.0f; + if (requiresRenderingOfCubeAndHull) + { + OSG_NOTICE<<"******* We need to set up the rendering of the Cube and Hull, ETF = "<getValue()<addUniform(new osg::Uniform("TransparencyValue",1.0f)); + if (cpv._exteriorTransparencyFactorProperty.valid()) + stateset->addUniform(cpv._exteriorTransparencyFactorProperty->getUniform()); + else + stateset->addUniform(new osg::Uniform("ExteriorTransparencyFactorValue",0.0f)); + if (cpv._afProperty.valid()) stateset->addUniform(cpv._afProperty->getUniform()); @@ -341,6 +357,7 @@ void MultipassTechnique::init() { tf = dynamic_cast(cpv._tfProperty->getTransferFunction()); } + } diff --git a/src/osgVolume/Property.cpp b/src/osgVolume/Property.cpp index 875963125..e4a2bda1b 100644 --- a/src/osgVolume/Property.cpp +++ b/src/osgVolume/Property.cpp @@ -238,6 +238,20 @@ TransparencyProperty::TransparencyProperty(const TransparencyProperty& isp,const { } +///////////////////////////////////////////////////////////////////////////// +// +// ExteriorTransparencyFactorProperty +// +ExteriorTransparencyFactorProperty::ExteriorTransparencyFactorProperty(float value): + ScalarProperty("ExteriorTransparencyFactorValue",value) +{ +} + +ExteriorTransparencyFactorProperty::ExteriorTransparencyFactorProperty(const ExteriorTransparencyFactorProperty& etfp,const osg::CopyOp& copyop): + ScalarProperty(etfp, copyop) +{ +} + ///////////////////////////////////////////////////////////////////////////// // // PropertyVisitor @@ -295,6 +309,7 @@ void CollectPropertiesVisitor::apply(SampleDensityWhenMovingProperty& sdp) { _sa void CollectPropertiesVisitor::apply(SampleRatioProperty& srp) { _sampleRatioProperty = &srp; } void CollectPropertiesVisitor::apply(SampleRatioWhenMovingProperty& srp) { _sampleRatioWhenMovingProperty = &srp; } void CollectPropertiesVisitor::apply(TransparencyProperty& tp) { _transparencyProperty = &tp; } +void CollectPropertiesVisitor::apply(ExteriorTransparencyFactorProperty& etfp) { _exteriorTransparencyFactorProperty = &etfp; } class CycleSwitchVisitor : public osgVolume::PropertyVisitor @@ -355,6 +370,7 @@ PropertyAdjustmentCallback::PropertyAdjustmentCallback(): _cyleForwardKey('v'), _cyleBackwardKey('V'), _transparencyKey('t'), + _exteriorTransparencyFactorKey('T'), _alphaFuncKey('a'), _sampleDensityKey('d'), _updateTransparency(false), @@ -367,6 +383,7 @@ PropertyAdjustmentCallback::PropertyAdjustmentCallback(const PropertyAdjustmentC _cyleForwardKey(pac._cyleForwardKey), _cyleBackwardKey(pac._cyleBackwardKey), _transparencyKey(pac._transparencyKey), + _exteriorTransparencyFactorKey(pac._exteriorTransparencyFactorKey), _alphaFuncKey(pac._alphaFuncKey), _sampleDensityKey(pac._sampleDensityKey), _updateTransparency(false), @@ -410,6 +427,7 @@ bool PropertyAdjustmentCallback::handle(const osgGA::GUIEventAdapter& ea,osgGA:: } } else if (ea.getKey()==_transparencyKey) _updateTransparency = passOnUpdates = true; + else if (ea.getKey()==_exteriorTransparencyFactorKey) _updateExteriorTransparencyFactor = passOnUpdates = true; else if (ea.getKey()==_alphaFuncKey) _updateAlphaCutOff = passOnUpdates = true; else if (ea.getKey()==_sampleDensityKey) _updateSampleDensity = passOnUpdates = true; break; @@ -417,6 +435,7 @@ bool PropertyAdjustmentCallback::handle(const osgGA::GUIEventAdapter& ea,osgGA:: case(osgGA::GUIEventAdapter::KEYUP): { if (ea.getKey()==_transparencyKey) _updateTransparency = false; + else if (ea.getKey()==_exteriorTransparencyFactorKey) _updateExteriorTransparencyFactor = false; else if (ea.getKey()==_alphaFuncKey) _updateAlphaCutOff = false; else if (ea.getKey()==_sampleDensityKey) _updateSampleDensity = false; break; @@ -447,8 +466,14 @@ bool PropertyAdjustmentCallback::handle(const osgGA::GUIEventAdapter& ea,osgGA:: if (_updateTransparency && cpv._transparencyProperty.valid()) { - OSG_NOTICE<<"Setting transparency to "<setValue((1.0f-v2)*2.0f); + OSG_NOTICE<<"Setting transparency to "<getValue()<setValue((1.0f-v)); + OSG_NOTICE<<"Setting exterior transparency factor to "<getValue()<