From f2d11bb46ee4d17edfb6d347863726d0ae38cb02 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 4 Jul 2014 16:45:05 +0000 Subject: [PATCH] Added preliminary support for writing VolumeSettings to disk from within Present3D in response to pressing and releasing 'Ctrl-S'. git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14363 16af8721-9629-0410-8352-f15c8da7e697 --- .../deprecated/SlideShowConstructor | 10 +- include/osgVolume/Property | 57 ++++-- include/osgVolume/VolumeSettings | 1 + src/osgPlugins/p3d/ReaderWriterP3D.cpp | 13 +- .../deprecated/SlideShowConstructor.cpp | 176 ++++++++++++++++-- src/osgVolume/Property.cpp | 45 ++--- src/osgVolume/VolumeSettings.cpp | 5 + 7 files changed, 238 insertions(+), 69 deletions(-) diff --git a/include/osgPresentation/deprecated/SlideShowConstructor b/include/osgPresentation/deprecated/SlideShowConstructor index b78d1ba9a..f86df6953 100644 --- a/include/osgPresentation/deprecated/SlideShowConstructor +++ b/include/osgPresentation/deprecated/SlideShowConstructor @@ -292,11 +292,11 @@ public: useTabbedDragger(false), useTrackballDragger(false), region_in_pixel_coords(false), - alphaValue("1.0"), - cutoffValue("0.1"), - exteriorTransparencyFactorValue(""), - sampleDensityValue("0.005"), - sampleRatioValue("1.0"), + alphaValue(), + cutoffValue(), + exteriorTransparencyFactorValue(), + sampleDensityValue(), + sampleRatioValue(), colorSpaceOperation(osg::NO_COLOR_SPACE_OPERATION), colorModulate(1.0f,1.0f,1.0f,1.0f), technique(osgVolume::VolumeSettings::RayTraced) diff --git a/include/osgVolume/Property b/include/osgVolume/Property index 9a6743b2a..a7e0ecc01 100644 --- a/include/osgVolume/Property +++ b/include/osgVolume/Property @@ -40,6 +40,7 @@ class SampleDensityProperty; class SampleDensityWhenMovingProperty; class TransparencyProperty; class ExteriorTransparencyFactorProperty; +class VolumeSettings; class OSGVOLUME_EXPORT PropertyVisitor { @@ -49,24 +50,24 @@ class OSGVOLUME_EXPORT PropertyVisitor virtual ~PropertyVisitor() {} - virtual void apply(Property&) {} + virtual void apply(Property&); virtual void apply(CompositeProperty&); virtual void apply(SwitchProperty&); - virtual void apply(TransferFunctionProperty&) {} - virtual void apply(ScalarProperty&) {} - virtual void apply(IsoSurfaceProperty&) {} - virtual void apply(AlphaFuncProperty&) {} - virtual void apply(MaximumIntensityProjectionProperty&) {} - virtual void apply(LightingProperty&) {} - virtual void apply(SampleRatioProperty&) {} - virtual void apply(SampleRatioWhenMovingProperty&) {} - virtual void apply(SampleDensityProperty&) {} - virtual void apply(SampleDensityWhenMovingProperty&) {} - virtual void apply(TransparencyProperty&) {} - virtual void apply(ExteriorTransparencyFactorProperty&) {} + virtual void apply(TransferFunctionProperty&); + virtual void apply(ScalarProperty&); + virtual void apply(IsoSurfaceProperty&); + virtual void apply(AlphaFuncProperty&); + virtual void apply(MaximumIntensityProjectionProperty&); + virtual void apply(LightingProperty&); + virtual void apply(SampleRatioProperty&); + virtual void apply(SampleRatioWhenMovingProperty&); + virtual void apply(SampleDensityProperty&); + virtual void apply(SampleDensityWhenMovingProperty&); + virtual void apply(TransparencyProperty&); + virtual void apply(ExteriorTransparencyFactorProperty&); + virtual void apply(VolumeSettings&); bool _traverseOnlyActiveChildren; - }; @@ -82,6 +83,7 @@ class OSGVOLUME_EXPORT Property : public osg::Object META_Object(osgVolume, Property); virtual void accept(PropertyVisitor& pv) { pv.apply(*this); } + virtual void traverse(PropertyVisitor& pv) {} protected: @@ -101,6 +103,16 @@ class OSGVOLUME_EXPORT CompositeProperty : public Property virtual void accept(PropertyVisitor& pv) { pv.apply(*this); } + virtual void traverse(PropertyVisitor& pv) + { + for(Properties::iterator itr = _properties.begin(); + itr != _properties.end(); + ++itr) + { + (*itr)->accept(pv); + } + } + void clear(); typedef std::vector< osg::ref_ptr > Properties; @@ -139,6 +151,22 @@ class OSGVOLUME_EXPORT SwitchProperty : public CompositeProperty virtual void accept(PropertyVisitor& pv) { pv.apply(*this); } + virtual void traverse(PropertyVisitor& pv) + { + if (pv._traverseOnlyActiveChildren) + { + if (_activeProperty>=0 && static_cast(_activeProperty)<=getNumProperties()) + { + _properties[_activeProperty]->accept(pv); + } + } + else + { + CompositeProperty::traverse(pv); + } + } + + /** Set which child property is active. * -1 disables all children.*/ void setActiveProperty(int i) { _activeProperty = i; } @@ -411,7 +439,6 @@ class OSGVOLUME_EXPORT CollectPropertiesVisitor : public osgVolume::PropertyVisi CollectPropertiesVisitor(bool traverseOnlyActiveChildren=true); - virtual void apply(Property&); virtual void apply(TransferFunctionProperty&); virtual void apply(ScalarProperty&); virtual void apply(IsoSurfaceProperty& iso); diff --git a/include/osgVolume/VolumeSettings b/include/osgVolume/VolumeSettings index 609afdaa7..9e3e8a5a8 100644 --- a/include/osgVolume/VolumeSettings +++ b/include/osgVolume/VolumeSettings @@ -31,6 +31,7 @@ class OSGVOLUME_EXPORT VolumeSettings : public Property META_Object(osgVolume, VolumeSettings); virtual void accept(PropertyVisitor& pv); + virtual void traverse(PropertyVisitor& pv); enum Technique { diff --git a/src/osgPlugins/p3d/ReaderWriterP3D.cpp b/src/osgPlugins/p3d/ReaderWriterP3D.cpp index a96f25250..2775ccaa2 100644 --- a/src/osgPlugins/p3d/ReaderWriterP3D.cpp +++ b/src/osgPlugins/p3d/ReaderWriterP3D.cpp @@ -1432,10 +1432,19 @@ void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& cons if (getProperty(cur, "vs", vs) || getProperty(cur, "VolumeSettings", vs)) { volumeData.volumeSettings = osgDB::readFile(vs); - OSG_NOTICE<<"VolumeSetting read "<setName(vs); + OSG_NOTICE<<" assigned name to VS "<getName()< > VolumeSettingsList; + VolumeSettingsList _vsList; +}; + +struct VolumeSettingsCallback : public osgGA::GUIEventHandler +{ + + VolumeSettingsCallback(): + _saveKey(19), // Ctril-S + _editKey(05) // Ctrl-E + { + } + + int _saveKey; + int _editKey; + + bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv) + { + if (ea.getHandled()) return false; + + osgVolume::VolumeTile* tile = dynamic_cast(object); + if (!tile) + { + OSG_NOTICE<<"Warning: VolumeSettingsCallback assigned to a node other than VolumeTile, cannot operate edit/save."<getLayer()->getProperty()->accept(cvsv); + + for(CollectVolumeSettingsVisitor::VolumeSettingsList::iterator itr = cvsv._vsList.begin(); + itr != cvsv._vsList.end(); + ++itr) + { + osgVolume::VolumeSettings* vs = itr->get(); + std::string filename = vs->getName(); + if (!filename.empty()) + { + OSG_NOTICE<<"Save VolumeSettings "<setLayer(layer.get()); + osg::ref_ptr groupPropetry = new osgVolume::CompositeProperty; + osg::ref_ptr sp = new osgVolume::SwitchProperty; sp->setActiveProperty(0); + groupPropetry->addProperty(sp.get()); + osg::ref_ptr vs = volumeData.volumeSettings; - osg::ref_ptr ap = new osgVolume::AlphaFuncProperty(0.1f); + osg::ref_ptr ap = vs.valid() ? vs->getCutoffProperty() : new osgVolume::AlphaFuncProperty(0.1f); setUpVolumeScalarProperty(tile.get(), ap.get(), volumeData.cutoffValue); - osg::ref_ptr tp = new osgVolume::TransparencyProperty(1.0f); + osg::ref_ptr tp = vs.valid() ? vs->getTransparencyProperty() : new osgVolume::TransparencyProperty(1.0f); setUpVolumeScalarProperty(tile.get(), tp.get(), volumeData.alphaValue); + osg::ref_ptr sr = vs.valid() ? vs->getSampleRatioProperty() : new osgVolume::SampleRatioProperty(1.0); + setUpVolumeScalarProperty(tile.get(), sr.get(), volumeData.sampleRatioValue); + + osg::ref_ptr srm = vs.valid() ? vs->getSampleRatioWhenMovingProperty() : 0; + if (!volumeData.sampleRatioWhenMovingValue.empty()) + { + srm = new osgVolume::SampleRatioWhenMovingProperty(0.5); + setUpVolumeScalarProperty(tile.get(), srm.get(), volumeData.sampleRatioWhenMovingValue); + } + + + // part of hull implementation. osg::ref_ptr etfp; if (!volumeData.exteriorTransparencyFactorValue.empty()) { @@ -2744,6 +2836,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position setUpVolumeScalarProperty(tile.get(), etfp.get(), volumeData.exteriorTransparencyFactorValue); } + // deprecated, used by old RayTracedTechnique osg::ref_ptr sd = new osgVolume::SampleDensityProperty(0.005); setUpVolumeScalarProperty(tile.get(), sd.get(), volumeData.sampleDensityValue); @@ -2754,30 +2847,67 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position setUpVolumeScalarProperty(tile.get(), sdm.get(), volumeData.sampleDensityWhenMovingValue); } - - osg::ref_ptr sr = new osgVolume::SampleRatioProperty(1.0); - setUpVolumeScalarProperty(tile.get(), sr.get(), volumeData.sampleRatioValue); - - osg::ref_ptr srm; - if (!volumeData.sampleRatioWhenMovingValue.empty()) - { - srm = new osgVolume::SampleRatioWhenMovingProperty(0.5); - setUpVolumeScalarProperty(tile.get(), srm.get(), volumeData.sampleRatioWhenMovingValue); - } - osg::ref_ptr tfp = volumeData.transferFunction.valid() ? new osgVolume::TransferFunctionProperty(volumeData.transferFunction.get()) : 0; + if (volumeData.volumeSettings.valid()) + { + groupPropetry->addProperty(volumeData.volumeSettings.get()); + } + else + { + if (ap.valid()) groupPropetry->addProperty(ap.get()); + if (tp.valid()) groupPropetry->addProperty(tp.get()); + + if (sr.valid()) groupPropetry->addProperty(sr.get()); + if (srm.valid()) groupPropetry->addProperty(srm.get()); + } + + + if (sd.valid()) groupPropetry->addProperty(sd.get()); + if (sdm.valid()) groupPropetry->addProperty(sdm.get()); + + if (tfp.valid()) groupPropetry->addProperty(tfp.get()); + if (etfp.valid()) groupPropetry->addProperty(etfp.get()); + +#if 1 + { + // Standard + osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; + + sp->addProperty(cp); + } + + { + // Light + sp->addProperty(new osgVolume::LightingProperty); + } + + { + // Isosurface + osgVolume::IsoSurfaceProperty* isp = new osgVolume::IsoSurfaceProperty(0.1); + setUpVolumeScalarProperty(tile.get(), isp, volumeData.alphaValue); + + sp->addProperty(isp); + } + + { + // MaximumIntensityProjection + sp->addProperty(new osgVolume::MaximumIntensityProjectionProperty); + } + + switch(volumeData.shadingModel) + { + case(osgVolume::VolumeSettings::Standard): sp->setActiveProperty(0); break; + case(osgVolume::VolumeSettings::Light): sp->setActiveProperty(1); break; + case(osgVolume::VolumeSettings::Isosurface): sp->setActiveProperty(2); break; + case(osgVolume::VolumeSettings::MaximumIntensityProjection): sp->setActiveProperty(3); break; + } +#else { // Standard osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; cp->addProperty(ap.get()); cp->addProperty(tp.get()); - if (sd.valid()) cp->addProperty(sd.get()); - if (sdm.valid()) cp->addProperty(sdm.get()); - 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); } @@ -2841,9 +2971,13 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position case(osgVolume::VolumeSettings::Isosurface): sp->setActiveProperty(2); break; case(osgVolume::VolumeSettings::MaximumIntensityProjection): sp->setActiveProperty(3); break; } +#endif +#if 1 + layer->addProperty(groupPropetry.get()); +#else layer->addProperty(sp.get()); - +#endif switch(volumeData.technique) { case(osgVolume::VolumeSettings::FixedFunction): @@ -2914,6 +3048,8 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position model = group.get(); } + tile->addEventCallback(new VolumeSettingsCallback()); + ModelData modelData; addModel(model.get(), positionData, modelData, scriptData); } diff --git a/src/osgVolume/Property.cpp b/src/osgVolume/Property.cpp index de688ddd0..5f607bdde 100644 --- a/src/osgVolume/Property.cpp +++ b/src/osgVolume/Property.cpp @@ -14,9 +14,11 @@ #include #include #include +#include using namespace osgVolume; + Property::Property() { } @@ -261,31 +263,22 @@ PropertyVisitor::PropertyVisitor(bool traverseOnlyActiveChildren): { } -void PropertyVisitor::apply(CompositeProperty& cp) -{ - for(unsigned int i=0; iaccept(*this); - } -} - -void PropertyVisitor::apply(SwitchProperty& sp) -{ - if (_traverseOnlyActiveChildren) - { - if (sp.getActiveProperty()>=0 && sp.getActiveProperty()(sp.getNumProperties())) - { - sp.getProperty(sp.getActiveProperty())->accept(*this); - } - } - else - { - for(unsigned int i=0; iaccept(*this); - } - } -} +void PropertyVisitor::apply(Property& p) { p.traverse(*this); } +void PropertyVisitor::apply(CompositeProperty& p) { apply(static_cast(p)); } +void PropertyVisitor::apply(SwitchProperty& p) { apply(static_cast(p)); } +void PropertyVisitor::apply(TransferFunctionProperty& p) { apply(static_cast(p)); } +void PropertyVisitor::apply(ScalarProperty& p) { apply(static_cast(p)); } +void PropertyVisitor::apply(IsoSurfaceProperty& p) { apply(static_cast(p)); } +void PropertyVisitor::apply(AlphaFuncProperty& p) { apply(static_cast(p)); } +void PropertyVisitor::apply(MaximumIntensityProjectionProperty& p) { apply(static_cast(p)); } +void PropertyVisitor::apply(LightingProperty& p) { apply(static_cast(p)); } +void PropertyVisitor::apply(SampleRatioProperty& p) { apply(static_cast(p)); } +void PropertyVisitor::apply(SampleRatioWhenMovingProperty& p) { apply(static_cast(p)); } +void PropertyVisitor::apply(SampleDensityProperty& p) { apply(static_cast(p)); } +void PropertyVisitor::apply(SampleDensityWhenMovingProperty& p) { apply(static_cast(p)); } +void PropertyVisitor::apply(TransparencyProperty& p) { apply(static_cast(p)); } +void PropertyVisitor::apply(ExteriorTransparencyFactorProperty& p) { apply(static_cast(p)); } +void PropertyVisitor::apply(VolumeSettings& p) { apply(static_cast(p)); } ///////////////////////////////////////////////////////////////////////////// @@ -297,7 +290,6 @@ CollectPropertiesVisitor::CollectPropertiesVisitor(bool traverseOnlyActiveChildr { } -void CollectPropertiesVisitor::apply(Property&) {} void CollectPropertiesVisitor::apply(TransferFunctionProperty& tf) { _tfProperty = &tf; } void CollectPropertiesVisitor::apply(ScalarProperty&) {} void CollectPropertiesVisitor::apply(IsoSurfaceProperty& iso) { _isoProperty = &iso; } @@ -311,7 +303,6 @@ void CollectPropertiesVisitor::apply(SampleRatioWhenMovingProperty& srp) { _samp void CollectPropertiesVisitor::apply(TransparencyProperty& tp) { _transparencyProperty = &tp; } void CollectPropertiesVisitor::apply(ExteriorTransparencyFactorProperty& etfp) { _exteriorTransparencyFactorProperty = &etfp; } - class CycleSwitchVisitor : public osgVolume::PropertyVisitor { public: diff --git a/src/osgVolume/VolumeSettings.cpp b/src/osgVolume/VolumeSettings.cpp index 343ca464e..22137c6ee 100644 --- a/src/osgVolume/VolumeSettings.cpp +++ b/src/osgVolume/VolumeSettings.cpp @@ -37,6 +37,11 @@ VolumeSettings::VolumeSettings(const VolumeSettings& vs,const osg::CopyOp& copyo } void VolumeSettings::accept(PropertyVisitor& pv) +{ + pv.apply(*this); +} + +void VolumeSettings::traverse(PropertyVisitor& pv) { _sampleRatioProperty->accept(pv); _sampleRatioWhenMovingProperty->accept(pv);