From 51f6fa249f4e825fddfd8c44f5efc5e26ae96eb7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 10 Feb 2009 18:51:43 +0000 Subject: [PATCH] Merged fixes to osgVolume's handling of ImageSequence animated volumes, merge command: svn merge -r 9746:9747 http://www.openscenegraph.org/svn/osg/OpenSceneGraph/branches/OpenSceneGraph-2.8 --- examples/osgvolume/osgvolume.cpp | 8 ++++++- include/osgVolume/Layer | 14 ++++++++++++ include/osgVolume/VolumeTile | 2 +- src/osgVolume/Layer.cpp | 35 +++++++++++++++++++++++++++++ src/osgVolume/VolumeTile.cpp | 15 +++++++++++++ src/osgWrappers/osgVolume/Layer.cpp | 31 +++++++++++++++++++++++++ 6 files changed, 103 insertions(+), 2 deletions(-) diff --git a/examples/osgvolume/osgvolume.cpp b/examples/osgvolume/osgvolume.cpp index 0d1757cd5..f525e126e 100644 --- a/examples/osgvolume/osgvolume.cpp +++ b/examples/osgvolume/osgvolume.cpp @@ -808,6 +808,8 @@ int main( int argc, char **argv ) arguments.getApplicationUsage()->addCommandLineOption("--no-rescale","Disable the rescaling of the pixel data to 0.0 to 1.0 range"); arguments.getApplicationUsage()->addCommandLineOption("--rescale","Enable the rescale of the pixel data to 0.0 to 1.0 range (default)."); arguments.getApplicationUsage()->addCommandLineOption("--shift-min-to-zero","Shift the pixel data so min value is 0.0."); + arguments.getApplicationUsage()->addCommandLineOption("--sequence-length ","Set the length of time that a sequence of images with run for."); + arguments.getApplicationUsage()->addCommandLineOption("--sd ","Short hand for --sequence-length"); // arguments.getApplicationUsage()->addCommandLineOption("--raw ","read a raw image data"); // construct the viewer. @@ -960,6 +962,10 @@ int main( int argc, char **argv ) while(arguments.read("--gpu-tf")) { gpuTransferFunction = true; } while(arguments.read("--cpu-tf")) { gpuTransferFunction = false; } + double sequenceLength = 10.0; + while(arguments.read("--sequence-duration", sequenceLength) || + arguments.read("--sd", sequenceLength)) {} + typedef std::list< osg::ref_ptr > Images; Images images; @@ -1249,7 +1255,7 @@ int main( int argc, char **argv ) osg::notify(osg::NOTICE)<<"Creating sequence of "< imageSequence = new osg::ImageSequence; - imageSequence->setLength(10.0); + imageSequence->setLength(sequenceLength); image_3d = imageSequence.get(); for(Images::iterator itr = images.begin(); itr != images.end(); diff --git a/include/osgVolume/Layer b/include/osgVolume/Layer index 8fee4f84d..2034ae114 100644 --- a/include/osgVolume/Layer +++ b/include/osgVolume/Layer @@ -78,6 +78,12 @@ class OSGVOLUME_EXPORT Layer : public osg::Object void addProperty(Property* property); + /** Specify whether ImageLayer requires update traversal. */ + virtual bool requiresUpdateTraversal() const { return false; } + + /** Call update on the Layer.*/ + virtual void update(osg::NodeVisitor& /*nv*/) {} + /** increment the modified count."*/ virtual void dirty() {}; @@ -137,6 +143,10 @@ class OSGVOLUME_EXPORT ImageLayer : public Layer /** Compute the min color component of the image and then translate and pixels by this offset to make the new min component 0.*/ void translateMinToZero(); + virtual bool requiresUpdateTraversal() const; + + virtual void update(osg::NodeVisitor& /*nv*/); + virtual void dirty(); virtual void setModifiedCount(unsigned int value); virtual unsigned int getModifiedCount() const; @@ -175,6 +185,10 @@ class OSGVOLUME_EXPORT CompositeLayer : public Layer unsigned int getNumLayers() const { return _layers.size(); } + bool requiresUpdateTraversal() const; + + virtual void update(osg::NodeVisitor& /*nv*/); + protected: virtual ~CompositeLayer() {} diff --git a/include/osgVolume/VolumeTile b/include/osgVolume/VolumeTile index 199435968..88666d211 100644 --- a/include/osgVolume/VolumeTile +++ b/include/osgVolume/VolumeTile @@ -107,7 +107,7 @@ class OSGVOLUME_EXPORT VolumeTile : public osg::Group const Locator* getLocator() const { return _locator.get(); } - void setLayer(Layer* layer) { _layer = layer; } + void setLayer(Layer* layer); Layer* getLayer() { return _layer.get(); } const Layer* getLayer() const { return _layer.get(); } diff --git a/src/osgVolume/Layer.cpp b/src/osgVolume/Layer.cpp index 6f4946be0..552cdbd67 100644 --- a/src/osgVolume/Layer.cpp +++ b/src/osgVolume/Layer.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -166,6 +167,16 @@ void ImageLayer::translateMinToZero() } } +bool ImageLayer::requiresUpdateTraversal() const +{ + return dynamic_cast(_image.get())!=0; +} + +void ImageLayer::update(osg::NodeVisitor& nv) +{ + if (_image.valid()) _image->update(&nv); +} + ///////////////////////////////////////////////////////////////////////////// // // CompositeLayer @@ -185,6 +196,30 @@ void CompositeLayer::clear() _layers.clear(); } +bool CompositeLayer::requiresUpdateTraversal() const +{ + for(Layers::const_iterator itr = _layers.begin(); + itr != _layers.end(); + ++itr) + { + if (itr->layer->requiresUpdateTraversal()) return true; + } + + return false; +} + +void CompositeLayer::update(osg::NodeVisitor& nv) +{ + for(Layers::const_iterator itr = _layers.begin(); + itr != _layers.end(); + ++itr) + { + itr->layer->update(nv); + } + +} + + ///////////////////////////////////////////////////////////////////////////// // // createNormalMapTexture diff --git a/src/osgVolume/VolumeTile.cpp b/src/osgVolume/VolumeTile.cpp index c03450044..da16da6fd 100644 --- a/src/osgVolume/VolumeTile.cpp +++ b/src/osgVolume/VolumeTile.cpp @@ -49,6 +49,8 @@ VolumeTile::VolumeTile(): _hasBeenTraversal(false) { setThreadSafeRefUnref(true); + + setNumChildrenRequiringUpdateTraversal(1); } VolumeTile::VolumeTile(const VolumeTile& volumeTile,const osg::CopyOp& copyop): @@ -58,6 +60,8 @@ VolumeTile::VolumeTile(const VolumeTile& volumeTile,const osg::CopyOp& copyop): _hasBeenTraversal(false), _layer(volumeTile._layer) { + setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1); + if (volumeTile.getVolumeTechnique()) { setVolumeTechnique(osg::clone(volumeTile.getVolumeTechnique())); @@ -117,6 +121,12 @@ void VolumeTile::traverse(osg::NodeVisitor& nv) _hasBeenTraversal = true; } + + if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR && + _layer->requiresUpdateTraversal()) + { + _layer->update(nv); + } if (_volumeTechnique.valid()) { @@ -138,6 +148,11 @@ void VolumeTile::init() } } +void VolumeTile::setLayer(Layer* layer) +{ + _layer = layer; +} + void VolumeTile::setVolumeTechnique(VolumeTechnique* volumeTechnique) { if (_volumeTechnique == volumeTechnique) return; diff --git a/src/osgWrappers/osgVolume/Layer.cpp b/src/osgWrappers/osgVolume/Layer.cpp index 4b8ebb241..38c7ae443 100644 --- a/src/osgWrappers/osgVolume/Layer.cpp +++ b/src/osgWrappers/osgVolume/Layer.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -108,6 +109,16 @@ BEGIN_OBJECT_REFLECTOR(osgVolume::CompositeLayer) __unsigned_int__getNumLayers, "", ""); + I_Method0(bool, requiresUpdateTraversal, + Properties::VIRTUAL, + __bool__requiresUpdateTraversal, + "Specify whether ImageLayer requires update traversal. ", + ""); + I_Method1(void, update, IN, osg::NodeVisitor &, x, + Properties::VIRTUAL, + __void__update__osg_NodeVisitor_R1, + "Call update on the Layer. ", + ""); I_IndexedProperty(const std::string &, FileName, __C5_std_string_R1__getFileName__unsigned_int, __void__setFileName__unsigned_int__C5_std_string_R1, @@ -203,6 +214,16 @@ BEGIN_OBJECT_REFLECTOR(osgVolume::ImageLayer) __void__translateMinToZero, "Compute the min color component of the image and then translate and pixels by this offset to make the new min component 0. ", ""); + I_Method0(bool, requiresUpdateTraversal, + Properties::VIRTUAL, + __bool__requiresUpdateTraversal, + "Specify whether ImageLayer requires update traversal. ", + ""); + I_Method1(void, update, IN, osg::NodeVisitor &, x, + Properties::VIRTUAL, + __void__update__osg_NodeVisitor_R1, + "Call update on the Layer. ", + ""); I_Method0(void, dirty, Properties::VIRTUAL, __void__dirty, @@ -349,6 +370,16 @@ BEGIN_OBJECT_REFLECTOR(osgVolume::Layer) __void__addProperty__Property_P1, "Add a property, automatically creating a CompositePorperty if one isn't already assigned. ", ""); + I_Method0(bool, requiresUpdateTraversal, + Properties::VIRTUAL, + __bool__requiresUpdateTraversal, + "Specify whether ImageLayer requires update traversal. ", + ""); + I_Method1(void, update, IN, osg::NodeVisitor &, x, + Properties::VIRTUAL, + __void__update__osg_NodeVisitor_R1, + "Call update on the Layer. ", + ""); I_Method0(void, dirty, Properties::VIRTUAL, __void__dirty,