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
This commit is contained in:
Robert Osfield 2009-02-10 18:51:43 +00:00
parent 2fcd7f1d99
commit 51f6fa249f
6 changed files with 103 additions and 2 deletions

View File

@ -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("--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("--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("--shift-min-to-zero","Shift the pixel data so min value is 0.0.");
arguments.getApplicationUsage()->addCommandLineOption("--sequence-length <num>","Set the length of time that a sequence of images with run for.");
arguments.getApplicationUsage()->addCommandLineOption("--sd <num>","Short hand for --sequence-length");
// arguments.getApplicationUsage()->addCommandLineOption("--raw <sizeX> <sizeY> <sizeZ> <numberBytesPerComponent> <numberOfComponents> <endian> <filename>","read a raw image data"); // arguments.getApplicationUsage()->addCommandLineOption("--raw <sizeX> <sizeY> <sizeZ> <numberBytesPerComponent> <numberOfComponents> <endian> <filename>","read a raw image data");
// construct the viewer. // construct the viewer.
@ -960,6 +962,10 @@ int main( int argc, char **argv )
while(arguments.read("--gpu-tf")) { gpuTransferFunction = true; } while(arguments.read("--gpu-tf")) { gpuTransferFunction = true; }
while(arguments.read("--cpu-tf")) { gpuTransferFunction = false; } 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<osg::Image> > Images; typedef std::list< osg::ref_ptr<osg::Image> > Images;
Images images; Images images;
@ -1249,7 +1255,7 @@ int main( int argc, char **argv )
osg::notify(osg::NOTICE)<<"Creating sequence of "<<images.size()<<" volumes."<<std::endl; osg::notify(osg::NOTICE)<<"Creating sequence of "<<images.size()<<" volumes."<<std::endl;
osg::ref_ptr<osg::ImageSequence> imageSequence = new osg::ImageSequence; osg::ref_ptr<osg::ImageSequence> imageSequence = new osg::ImageSequence;
imageSequence->setLength(10.0); imageSequence->setLength(sequenceLength);
image_3d = imageSequence.get(); image_3d = imageSequence.get();
for(Images::iterator itr = images.begin(); for(Images::iterator itr = images.begin();
itr != images.end(); itr != images.end();

View File

@ -78,6 +78,12 @@ class OSGVOLUME_EXPORT Layer : public osg::Object
void addProperty(Property* property); 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."*/ /** increment the modified count."*/
virtual void dirty() {}; 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.*/ /** 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(); void translateMinToZero();
virtual bool requiresUpdateTraversal() const;
virtual void update(osg::NodeVisitor& /*nv*/);
virtual void dirty(); virtual void dirty();
virtual void setModifiedCount(unsigned int value); virtual void setModifiedCount(unsigned int value);
virtual unsigned int getModifiedCount() const; virtual unsigned int getModifiedCount() const;
@ -175,6 +185,10 @@ class OSGVOLUME_EXPORT CompositeLayer : public Layer
unsigned int getNumLayers() const { return _layers.size(); } unsigned int getNumLayers() const { return _layers.size(); }
bool requiresUpdateTraversal() const;
virtual void update(osg::NodeVisitor& /*nv*/);
protected: protected:
virtual ~CompositeLayer() {} virtual ~CompositeLayer() {}

View File

@ -107,7 +107,7 @@ class OSGVOLUME_EXPORT VolumeTile : public osg::Group
const Locator* getLocator() const { return _locator.get(); } const Locator* getLocator() const { return _locator.get(); }
void setLayer(Layer* layer) { _layer = layer; } void setLayer(Layer* layer);
Layer* getLayer() { return _layer.get(); } Layer* getLayer() { return _layer.get(); }
const Layer* getLayer() const { return _layer.get(); } const Layer* getLayer() const { return _layer.get(); }

View File

@ -14,6 +14,7 @@
#include <osgVolume/Layer> #include <osgVolume/Layer>
#include <osg/ImageUtils> #include <osg/ImageUtils>
#include <osg/ImageStream>
#include <osg/Endian> #include <osg/Endian>
#include <osg/Notify> #include <osg/Notify>
#include <osg/io_utils> #include <osg/io_utils>
@ -166,6 +167,16 @@ void ImageLayer::translateMinToZero()
} }
} }
bool ImageLayer::requiresUpdateTraversal() const
{
return dynamic_cast<osg::ImageStream*>(_image.get())!=0;
}
void ImageLayer::update(osg::NodeVisitor& nv)
{
if (_image.valid()) _image->update(&nv);
}
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// //
// CompositeLayer // CompositeLayer
@ -185,6 +196,30 @@ void CompositeLayer::clear()
_layers.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 // createNormalMapTexture

View File

@ -49,6 +49,8 @@ VolumeTile::VolumeTile():
_hasBeenTraversal(false) _hasBeenTraversal(false)
{ {
setThreadSafeRefUnref(true); setThreadSafeRefUnref(true);
setNumChildrenRequiringUpdateTraversal(1);
} }
VolumeTile::VolumeTile(const VolumeTile& volumeTile,const osg::CopyOp& copyop): VolumeTile::VolumeTile(const VolumeTile& volumeTile,const osg::CopyOp& copyop):
@ -58,6 +60,8 @@ VolumeTile::VolumeTile(const VolumeTile& volumeTile,const osg::CopyOp& copyop):
_hasBeenTraversal(false), _hasBeenTraversal(false),
_layer(volumeTile._layer) _layer(volumeTile._layer)
{ {
setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1);
if (volumeTile.getVolumeTechnique()) if (volumeTile.getVolumeTechnique())
{ {
setVolumeTechnique(osg::clone(volumeTile.getVolumeTechnique())); setVolumeTechnique(osg::clone(volumeTile.getVolumeTechnique()));
@ -118,6 +122,12 @@ void VolumeTile::traverse(osg::NodeVisitor& nv)
_hasBeenTraversal = true; _hasBeenTraversal = true;
} }
if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR &&
_layer->requiresUpdateTraversal())
{
_layer->update(nv);
}
if (_volumeTechnique.valid()) if (_volumeTechnique.valid())
{ {
_volumeTechnique->traverse(nv); _volumeTechnique->traverse(nv);
@ -138,6 +148,11 @@ void VolumeTile::init()
} }
} }
void VolumeTile::setLayer(Layer* layer)
{
_layer = layer;
}
void VolumeTile::setVolumeTechnique(VolumeTechnique* volumeTechnique) void VolumeTile::setVolumeTechnique(VolumeTechnique* volumeTechnique)
{ {
if (_volumeTechnique == volumeTechnique) return; if (_volumeTechnique == volumeTechnique) return;

View File

@ -13,6 +13,7 @@
#include <osg/BoundingSphere> #include <osg/BoundingSphere>
#include <osg/CopyOp> #include <osg/CopyOp>
#include <osg/Image> #include <osg/Image>
#include <osg/NodeVisitor>
#include <osg/Object> #include <osg/Object>
#include <osg/Texture> #include <osg/Texture>
#include <osg/Vec4> #include <osg/Vec4>
@ -108,6 +109,16 @@ BEGIN_OBJECT_REFLECTOR(osgVolume::CompositeLayer)
__unsigned_int__getNumLayers, __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, I_IndexedProperty(const std::string &, FileName,
__C5_std_string_R1__getFileName__unsigned_int, __C5_std_string_R1__getFileName__unsigned_int,
__void__setFileName__unsigned_int__C5_std_string_R1, __void__setFileName__unsigned_int__C5_std_string_R1,
@ -203,6 +214,16 @@ BEGIN_OBJECT_REFLECTOR(osgVolume::ImageLayer)
__void__translateMinToZero, __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. ", "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, I_Method0(void, dirty,
Properties::VIRTUAL, Properties::VIRTUAL,
__void__dirty, __void__dirty,
@ -349,6 +370,16 @@ BEGIN_OBJECT_REFLECTOR(osgVolume::Layer)
__void__addProperty__Property_P1, __void__addProperty__Property_P1,
"Add a property, automatically creating a CompositePorperty if one isn't already assigned. ", "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, I_Method0(void, dirty,
Properties::VIRTUAL, Properties::VIRTUAL,
__void__dirty, __void__dirty,