From 38f6cddc2c959fef3f7261f5fefbd2c6e5760752 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 15 Aug 2008 16:21:44 +0000 Subject: [PATCH] Changed osg::ImageSequence::set/getDuration to set/getLength() to be in keeping with the osg::ImageStream's getLength(). --- .../osgimagesequence/osgimagesequence.cpp | 2 +- include/osg/ImageSequence | 8 +-- src/osg/ImageSequence.cpp | 70 +++++++++++++------ src/osgPlugins/ive/ImageSequence.cpp | 4 +- src/osgPlugins/osg/ImageSequence.cpp | 8 +-- src/osgWrappers/osg/ImageSequence.cpp | 14 +--- 6 files changed, 60 insertions(+), 46 deletions(-) diff --git a/examples/osgimagesequence/osgimagesequence.cpp b/examples/osgimagesequence/osgimagesequence.cpp index 47f0844bd..f7f8614a3 100644 --- a/examples/osgimagesequence/osgimagesequence.cpp +++ b/examples/osgimagesequence/osgimagesequence.cpp @@ -45,7 +45,7 @@ osg::StateSet* createState() { osg::ref_ptr imageSequence = new osg::ImageSequence; - imageSequence->setDuration(2.0); + imageSequence->setLength(4.0); imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posx.png")); imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negx.png")); imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posy.png")); diff --git a/include/osg/ImageSequence b/include/osg/ImageSequence index 31726c0e7..1db9baba7 100644 --- a/include/osg/ImageSequence +++ b/include/osg/ImageSequence @@ -69,10 +69,8 @@ class OSG_EXPORT ImageSequence : public ImageStream void setMode(Mode mode); Mode getMode() const { return _mode; } - void setDuration(double duration); - double getDuration() const { return _duration; } - - virtual double getLength() const { return getDuration(); } + void setLength(double length); + virtual double getLength() const { return _length; } void addImageFile(const std::string& fileName); @@ -105,7 +103,7 @@ class OSG_EXPORT ImageSequence : public ImageStream double _timeMultiplier; Mode _mode; - double _duration; + double _length; double _timePerImage; diff --git a/src/osg/ImageSequence.cpp b/src/osg/ImageSequence.cpp index ce5333f5f..b5dd69bb6 100644 --- a/src/osg/ImageSequence.cpp +++ b/src/osg/ImageSequence.cpp @@ -42,11 +42,11 @@ ImageSequence::ImageSequence() _timeMultiplier = 1.0; _mode = PRE_LOAD_ALL_IMAGES; - _duration = 1.0; + _length = 1.0; _timePerImage = 1.0; _fileNamesIterator = _fileNames.end(); - _fileNamesIteratorTime = DBL_MAX; + _fileNamesIteratorTime = 0.0; _imageIterator = _images.end(); _imageIteratorTime = 0.0; @@ -60,14 +60,14 @@ ImageSequence::ImageSequence(const ImageSequence& is,const CopyOp& copyop): _referenceTime(is._referenceTime), _timeMultiplier(is._timeMultiplier), _mode(is._mode), - _duration(is._duration), + _length(is._length), _timePerImage(is._timePerImage) { _fileNamesIterator = _fileNames.end(); - _fileNamesIteratorTime = DBL_MAX; + _fileNamesIteratorTime = 0.0; - _imageIteratorTime = 0.0; _imageIterator = _images.end(); + _imageIteratorTime = 0.0; _seekTime = is._seekTime; _seekTimeSet = is._seekTimeSet; @@ -104,17 +104,17 @@ void ImageSequence::setMode(Mode mode) _mode = mode; } -void ImageSequence::setDuration(double duration) +void ImageSequence::setLength(double length) { - _duration = duration; + _length = length; computeTimePerImage(); } void ImageSequence::computeTimePerImage() { - if (!_fileNames.empty()) _timePerImage = _duration / double(_fileNames.size()); - else if (!_images.empty()) _timePerImage = _duration / double(_images.size()); - else _timePerImage = _duration; + if (!_fileNames.empty()) _timePerImage = _length / double(_fileNames.size()); + else if (!_images.empty()) _timePerImage = _length / double(_images.size()); + else _timePerImage = _length; } void ImageSequence::addImageFile(const std::string& fileName) @@ -216,11 +216,6 @@ void ImageSequence::update(osg::NodeVisitor* nv) _referenceTime = fs->getSimulationTime(); } - if (_fileNamesIteratorTime == DBL_MAX) - { - _fileNamesIteratorTime = _referenceTime; - } - bool looping = getLoopingMode()==LOOPING; double time = (fs->getSimulationTime() - _referenceTime)*_timeMultiplier; @@ -230,9 +225,9 @@ void ImageSequence::update(osg::NodeVisitor* nv) _referenceTime = fs->getSimulationTime() - time/_timeMultiplier; } - if (time>_duration) + if (time>_length) { - time -= floor(time/_duration)*_duration; + time -= floor(time/_length)*_length; } _seekTime = time; @@ -278,13 +273,41 @@ void ImageSequence::update(osg::NodeVisitor* nv) if (irh && _images.size()<_fileNames.size()) { - double preLoadTime = (time+irh->getPreLoadTime())*_timeMultiplier; + double preLoadTime = time + osg::minimum(irh->getPreLoadTime()*_timeMultiplier, _length); + + if (preLoadTime>=_length) + { + // + // Advance fileNameIterator to end and wrap around + // + for(; + _fileNamesIterator != _fileNames.end(); + ++_fileNamesIterator) + { + _fileNamesIteratorTime += _timePerImage; + + double effectTime = fs->getSimulationTime() + (preLoadTime - _fileNamesIteratorTime); + _filesRequested.push_back(FileNameImagePair(*_fileNamesIterator,0)); + irh->requestImageFile(*_fileNamesIterator, this, effectTime, fs); + + } + + preLoadTime -= _length; + + if (looping) + { + _fileNamesIterator = _fileNames.begin(); + _fileNamesIteratorTime = 0.0; + } + } + - // - // Advance imageIterator - // if (_fileNamesIterator!=_fileNames.end()) { + // + // Advance fileNameIterator to encmpass preLoadTime + // + //osg::notify(osg::NOTICE)<<" _fileNamesIteratorTime = "<<_fileNamesIteratorTime<<" "<<_timePerImage< (_fileNamesIteratorTime + _timePerImage)) { @@ -302,15 +325,16 @@ void ImageSequence::update(osg::NodeVisitor* nv) else break; } + double effectTime = fs->getSimulationTime() + (preLoadTime - _fileNamesIteratorTime); _filesRequested.push_back(FileNameImagePair(*_fileNamesIterator,0)); - irh->requestImageFile(*_fileNamesIterator, this, _fileNamesIteratorTime, fs); - + irh->requestImageFile(*_fileNamesIterator, this, effectTime, fs); } } if (looping && _fileNamesIterator==_fileNames.end()) { _fileNamesIterator = _fileNames.begin(); + _fileNamesIteratorTime = 0.0; } } diff --git a/src/osgPlugins/ive/ImageSequence.cpp b/src/osgPlugins/ive/ImageSequence.cpp index d182fb3e1..dac7f4e91 100644 --- a/src/osgPlugins/ive/ImageSequence.cpp +++ b/src/osgPlugins/ive/ImageSequence.cpp @@ -35,7 +35,7 @@ void ImageSequence::write(DataOutputStream* out) out->writeInt(getMode()); - out->writeDouble(getDuration()); + out->writeDouble(getLength()); out->writeUInt(getFileNames().size()); for(FileNames::iterator itr = getFileNames().begin(); @@ -76,7 +76,7 @@ void ImageSequence::read(DataInputStream* in) setMode((osg::ImageSequence::Mode)(in->readInt())); - setDuration(in->readDouble()); + setLength(in->readDouble()); unsigned int numFileNames = in->readUInt(); if (numFileNames>0) diff --git a/src/osgPlugins/osg/ImageSequence.cpp b/src/osgPlugins/osg/ImageSequence.cpp index 4265f469a..ce2ef79a7 100644 --- a/src/osgPlugins/osg/ImageSequence.cpp +++ b/src/osgPlugins/osg/ImageSequence.cpp @@ -47,10 +47,10 @@ bool ImageSequence_readLocalData(Object& obj, Input& fr) } } - double duration; - if (fr.read("Duration", duration)) + double length; + if (fr.read("Duration", length) || fr.read("Length", length) ) { - is.setDuration(duration); + is.setLength(length); } if (fr.matchSequence("FileNames {")) @@ -108,7 +108,7 @@ bool ImageSequence_writeLocalData(const Object& obj, Output& fw) break; } - fw.indent()<<"Duration "<