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;
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"));

View File

@ -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;

View File

@ -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 imageIterator
// 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;
}
}
if (_fileNamesIterator!=_fileNames.end())
{
//
// Advance fileNameIterator to encmpass preLoadTime
//
//osg::notify(osg::NOTICE)<<" _fileNamesIteratorTime = "<<_fileNamesIteratorTime<<" "<<_timePerImage<<std::endl;
while(preLoadTime > (_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;
}
}

View File

@ -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)

View File

@ -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 "<<is.getDuration()<<std::endl;
fw.indent()<<"Length "<<is.getLength()<<std::endl;
if (!is.getFileNames().empty())
{

View File

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