Further work on ImageSequence

This commit is contained in:
Robert Osfield 2008-07-22 20:20:16 +00:00
parent c9dc578186
commit cc2af85c96
2 changed files with 84 additions and 26 deletions

View File

@ -53,6 +53,9 @@ class OSG_EXPORT ImageSequence : public ImageStream
void setDuration(double duration);
double getDuration() const { return _duration; }
void setPreLoadTime(double preLoadTime) { _preLoadTime = preLoadTime; }
double getPreLoadTime() const { return _preLoadTime; }
void setPruneOldImages(bool prune) { _pruneOldImages = prune; }
bool getPruneOldImages() const { return _pruneOldImages; }
@ -85,22 +88,23 @@ class OSG_EXPORT ImageSequence : public ImageStream
double _referenceTime;
double _timeMultiplier;
OpenThreads::Mutex _mutex;
FileNames _fileNames;
double _duration;
double _preLoadTime;
bool _pruneOldImages;
double _timePerImage;
OpenThreads::Mutex _mutex;
FileNames _fileNames;
FileNames::iterator _fileNamesIterator;
double _fileNamesIteratorTime;
double _imageHeadTime;
Images _images;
Images::iterator _imageIterator;
double _imageIteratorTime;
};
} // namespace

View File

@ -42,11 +42,15 @@ ImageSequence::ImageSequence()
_timeMultiplier = 1.0;
_duration = 1.0;
_preLoadTime = 1.0;
_timePerImage = 1.0;
_pruneOldImages = false;
_imageIteratorTime = DBL_MAX;
_fileNamesIterator = _fileNames.end();
_fileNamesIteratorTime = DBL_MAX;
_imageIterator = _images.end();
_imageIteratorTime = DBL_MAX;
}
ImageSequence::ImageSequence(const ImageSequence& is,const CopyOp& copyop):
@ -54,8 +58,13 @@ ImageSequence::ImageSequence(const ImageSequence& is,const CopyOp& copyop):
_referenceTime(is._referenceTime),
_timeMultiplier(is._timeMultiplier),
_duration(is._duration),
_timePerImage(is._timePerImage),
_preLoadTime(is._preLoadTime),
_pruneOldImages(is._pruneOldImages)
{
_fileNamesIterator = _fileNames.end();
_fileNamesIteratorTime = DBL_MAX;
_imageIteratorTime = DBL_MAX;
_imageIterator = _images.end();
}
@ -83,6 +92,12 @@ void ImageSequence::addImageFile(const std::string& fileName)
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
_fileNames.push_back(fileName);
computeTimePerImage();
if (_fileNamesIterator==_fileNames.end())
{
_fileNamesIterator = _fileNames.begin();
_fileNamesIteratorTime = _referenceTime;
}
}
void ImageSequence::addImage(osg::Image* image)
@ -125,45 +140,84 @@ void ImageSequence::update(osg::NodeVisitor* nv)
_referenceTime = fs->getSimulationTime();
}
if (_fileNamesIteratorTime == DBL_MAX)
{
_fileNamesIteratorTime = _referenceTime;
}
if (_imageIteratorTime == DBL_MAX)
{
_imageIteratorTime = _referenceTime;
}
double time = (fs->getSimulationTime() - _referenceTime)*_timeMultiplier;
double preLoadTime = (time+_preLoadTime)*_timeMultiplier;
Images::iterator previous_imageIterator = _imageIterator;
// osg::notify(osg::NOTICE)<<"time = "<<time<<std::endl;
if (_imageIterator!=_images.end())
{
// osg::notify(osg::NOTICE)<<" _imageIteratorTime = "<<_imageIteratorTime<<std::endl;
while(time > (_imageIteratorTime + _timePerImage))
//
// Advance imageIterator
//
if (_fileNamesIterator!=_fileNames.end())
{
_imageIteratorTime += _timePerImage;
// osg::notify(osg::NOTICE)<<" _imageIteratorTime = "<<_imageIteratorTime<<std::endl;
++_imageIterator;
if (_imageIterator ==_images.end())
// osg::notify(osg::NOTICE)<<" _fileNamesIteratorTime = "<<_fileNamesIteratorTime<<std::endl;
while(preLoadTime > (_fileNamesIteratorTime + _timePerImage))
{
_fileNamesIteratorTime += _timePerImage;
osg::notify(osg::NOTICE)<<" _fileNamesIteratorTime = "<<_fileNamesIteratorTime<<std::endl;
osg::notify(osg::NOTICE)<<" need to preLoad = "<<*_fileNamesIterator<<std::endl;
++_fileNamesIterator;
if (_pruneOldImages)
if (_fileNamesIterator ==_fileNames.end())
{
_images.erase(previous_imageIterator, _imageIterator);
// return iterator to begining of set.
_fileNamesIterator = _fileNames.begin();
}
// return iterator to begining of set.
_imageIterator = _images.begin();
}
}
if (_fileNamesIterator==_fileNames.end())
{
_fileNamesIterator = _fileNames.begin();
}
}
if (_imageIterator==_images.end())
{
_imageIterator = _images.begin();
//
// Advance imageIterator
//
if (_imageIterator!=_images.end())
{
// osg::notify(osg::NOTICE)<<" _imageIteratorTime = "<<_imageIteratorTime<<std::endl;
while(time > (_imageIteratorTime + _timePerImage))
{
_imageIteratorTime += _timePerImage;
// osg::notify(osg::NOTICE)<<" _imageIteratorTime = "<<_imageIteratorTime<<std::endl;
++_imageIterator;
if (_imageIterator ==_images.end())
{
if (_pruneOldImages)
{
_images.erase(previous_imageIterator, _imageIterator);
}
// return iterator to begining of set.
_imageIterator = _images.begin();
}
}
}
if (_imageIterator==_images.end())
{
_imageIterator = _images.begin();
}
}
if (_imageIterator!=_images.end() && previous_imageIterator != _imageIterator)
{
if (_pruneOldImages)