Changed osg::ImageSequence::set/getDuration to set/getLength() to be in keeping with the

osg::ImageStream's getLength().
This commit is contained in:
Robert Osfield 2008-08-15 16:21:44 +00:00
parent b6292f4537
commit 38f6cddc2c
6 changed files with 60 additions and 46 deletions

View File

@ -45,7 +45,7 @@ osg::StateSet* createState()
{ {
osg::ref_ptr<osg::ImageSequence> imageSequence = new osg::ImageSequence; osg::ref_ptr<osg::ImageSequence> 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/posx.png"));
imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negx.png")); imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negx.png"));
imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posy.png")); imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posy.png"));

View File

@ -69,10 +69,8 @@ class OSG_EXPORT ImageSequence : public ImageStream
void setMode(Mode mode); void setMode(Mode mode);
Mode getMode() const { return _mode; } Mode getMode() const { return _mode; }
void setDuration(double duration); void setLength(double length);
double getDuration() const { return _duration; } virtual double getLength() const { return _length; }
virtual double getLength() const { return getDuration(); }
void addImageFile(const std::string& fileName); void addImageFile(const std::string& fileName);
@ -105,7 +103,7 @@ class OSG_EXPORT ImageSequence : public ImageStream
double _timeMultiplier; double _timeMultiplier;
Mode _mode; Mode _mode;
double _duration; double _length;
double _timePerImage; double _timePerImage;

View File

@ -42,11 +42,11 @@ ImageSequence::ImageSequence()
_timeMultiplier = 1.0; _timeMultiplier = 1.0;
_mode = PRE_LOAD_ALL_IMAGES; _mode = PRE_LOAD_ALL_IMAGES;
_duration = 1.0; _length = 1.0;
_timePerImage = 1.0; _timePerImage = 1.0;
_fileNamesIterator = _fileNames.end(); _fileNamesIterator = _fileNames.end();
_fileNamesIteratorTime = DBL_MAX; _fileNamesIteratorTime = 0.0;
_imageIterator = _images.end(); _imageIterator = _images.end();
_imageIteratorTime = 0.0; _imageIteratorTime = 0.0;
@ -60,14 +60,14 @@ ImageSequence::ImageSequence(const ImageSequence& is,const CopyOp& copyop):
_referenceTime(is._referenceTime), _referenceTime(is._referenceTime),
_timeMultiplier(is._timeMultiplier), _timeMultiplier(is._timeMultiplier),
_mode(is._mode), _mode(is._mode),
_duration(is._duration), _length(is._length),
_timePerImage(is._timePerImage) _timePerImage(is._timePerImage)
{ {
_fileNamesIterator = _fileNames.end(); _fileNamesIterator = _fileNames.end();
_fileNamesIteratorTime = DBL_MAX; _fileNamesIteratorTime = 0.0;
_imageIteratorTime = 0.0;
_imageIterator = _images.end(); _imageIterator = _images.end();
_imageIteratorTime = 0.0;
_seekTime = is._seekTime; _seekTime = is._seekTime;
_seekTimeSet = is._seekTimeSet; _seekTimeSet = is._seekTimeSet;
@ -104,17 +104,17 @@ void ImageSequence::setMode(Mode mode)
_mode = mode; _mode = mode;
} }
void ImageSequence::setDuration(double duration) void ImageSequence::setLength(double length)
{ {
_duration = duration; _length = length;
computeTimePerImage(); computeTimePerImage();
} }
void ImageSequence::computeTimePerImage() void ImageSequence::computeTimePerImage()
{ {
if (!_fileNames.empty()) _timePerImage = _duration / double(_fileNames.size()); if (!_fileNames.empty()) _timePerImage = _length / double(_fileNames.size());
else if (!_images.empty()) _timePerImage = _duration / double(_images.size()); else if (!_images.empty()) _timePerImage = _length / double(_images.size());
else _timePerImage = _duration; else _timePerImage = _length;
} }
void ImageSequence::addImageFile(const std::string& fileName) void ImageSequence::addImageFile(const std::string& fileName)
@ -216,11 +216,6 @@ void ImageSequence::update(osg::NodeVisitor* nv)
_referenceTime = fs->getSimulationTime(); _referenceTime = fs->getSimulationTime();
} }
if (_fileNamesIteratorTime == DBL_MAX)
{
_fileNamesIteratorTime = _referenceTime;
}
bool looping = getLoopingMode()==LOOPING; bool looping = getLoopingMode()==LOOPING;
double time = (fs->getSimulationTime() - _referenceTime)*_timeMultiplier; double time = (fs->getSimulationTime() - _referenceTime)*_timeMultiplier;
@ -230,9 +225,9 @@ void ImageSequence::update(osg::NodeVisitor* nv)
_referenceTime = fs->getSimulationTime() - time/_timeMultiplier; _referenceTime = fs->getSimulationTime() - time/_timeMultiplier;
} }
if (time>_duration) if (time>_length)
{ {
time -= floor(time/_duration)*_duration; time -= floor(time/_length)*_length;
} }
_seekTime = time; _seekTime = time;
@ -278,13 +273,41 @@ void ImageSequence::update(osg::NodeVisitor* nv)
if (irh && _images.size()<_fileNames.size()) 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()) if (_fileNamesIterator!=_fileNames.end())
{ {
//
// Advance fileNameIterator to encmpass preLoadTime
//
//osg::notify(osg::NOTICE)<<" _fileNamesIteratorTime = "<<_fileNamesIteratorTime<<" "<<_timePerImage<<std::endl; //osg::notify(osg::NOTICE)<<" _fileNamesIteratorTime = "<<_fileNamesIteratorTime<<" "<<_timePerImage<<std::endl;
while(preLoadTime > (_fileNamesIteratorTime + _timePerImage)) while(preLoadTime > (_fileNamesIteratorTime + _timePerImage))
{ {
@ -302,15 +325,16 @@ void ImageSequence::update(osg::NodeVisitor* nv)
else break; else break;
} }
double effectTime = fs->getSimulationTime() + (preLoadTime - _fileNamesIteratorTime);
_filesRequested.push_back(FileNameImagePair(*_fileNamesIterator,0)); _filesRequested.push_back(FileNameImagePair(*_fileNamesIterator,0));
irh->requestImageFile(*_fileNamesIterator, this, _fileNamesIteratorTime, fs); irh->requestImageFile(*_fileNamesIterator, this, effectTime, fs);
} }
} }
if (looping && _fileNamesIterator==_fileNames.end()) if (looping && _fileNamesIterator==_fileNames.end())
{ {
_fileNamesIterator = _fileNames.begin(); _fileNamesIterator = _fileNames.begin();
_fileNamesIteratorTime = 0.0;
} }
} }

View File

@ -35,7 +35,7 @@ void ImageSequence::write(DataOutputStream* out)
out->writeInt(getMode()); out->writeInt(getMode());
out->writeDouble(getDuration()); out->writeDouble(getLength());
out->writeUInt(getFileNames().size()); out->writeUInt(getFileNames().size());
for(FileNames::iterator itr = getFileNames().begin(); for(FileNames::iterator itr = getFileNames().begin();
@ -76,7 +76,7 @@ void ImageSequence::read(DataInputStream* in)
setMode((osg::ImageSequence::Mode)(in->readInt())); setMode((osg::ImageSequence::Mode)(in->readInt()));
setDuration(in->readDouble()); setLength(in->readDouble());
unsigned int numFileNames = in->readUInt(); unsigned int numFileNames = in->readUInt();
if (numFileNames>0) if (numFileNames>0)

View File

@ -47,10 +47,10 @@ bool ImageSequence_readLocalData(Object& obj, Input& fr)
} }
} }
double duration; double length;
if (fr.read("Duration", duration)) if (fr.read("Duration", length) || fr.read("Length", length) )
{ {
is.setDuration(duration); is.setLength(length);
} }
if (fr.matchSequence("FileNames {")) if (fr.matchSequence("FileNames {"))
@ -108,7 +108,7 @@ bool ImageSequence_writeLocalData(const Object& obj, Output& fw)
break; break;
} }
fw.indent()<<"Duration "<<is.getDuration()<<std::endl; fw.indent()<<"Length "<<is.getLength()<<std::endl;
if (!is.getFileNames().empty()) if (!is.getFileNames().empty())
{ {

View File

@ -126,14 +126,9 @@ BEGIN_OBJECT_REFLECTOR(osg::ImageSequence)
__Mode__getMode, __Mode__getMode,
"", "",
""); "");
I_Method1(void, setDuration, IN, double, duration, I_Method1(void, setLength, IN, double, length,
Properties::NON_VIRTUAL, Properties::NON_VIRTUAL,
__void__setDuration__double, __void__setLength__double,
"",
"");
I_Method0(double, getDuration,
Properties::NON_VIRTUAL,
__double__getDuration,
"", "",
""); "");
I_Method0(double, getLength, I_Method0(double, getLength,
@ -188,9 +183,6 @@ BEGIN_OBJECT_REFLECTOR(osg::ImageSequence)
__void__computeTimePerImage, __void__computeTimePerImage,
"", "",
""); "");
I_SimpleProperty(double, Duration,
__double__getDuration,
__void__setDuration__double);
I_SimpleProperty(osg::ImageSequence::FileNames &, FileNames, I_SimpleProperty(osg::ImageSequence::FileNames &, FileNames,
__FileNames_R1__getFileNames, __FileNames_R1__getFileNames,
0); 0);
@ -199,7 +191,7 @@ BEGIN_OBJECT_REFLECTOR(osg::ImageSequence)
0); 0);
I_SimpleProperty(double, Length, I_SimpleProperty(double, Length,
__double__getLength, __double__getLength,
0); __void__setLength__double);
I_SimpleProperty(osg::ImageSequence::Mode, Mode, I_SimpleProperty(osg::ImageSequence::Mode, Mode,
__Mode__getMode, __Mode__getMode,
__void__setMode__Mode); __void__setMode__Mode);