Added support for pruning old images, recording the Duration in the .osg file, and -o filename output support in osgimagesequence.
This commit is contained in:
parent
66c2add024
commit
c9dc578186
@ -104,7 +104,11 @@ int main(int argc, char **argv)
|
||||
// create a model from the images and pass it to the viewer.
|
||||
viewer.setSceneData(createModel());
|
||||
|
||||
//osgDB::writeNodeFile(*viewer.getSceneData(),"test.osg");
|
||||
std::string filename;
|
||||
if (arguments.read("-o",filename))
|
||||
{
|
||||
osgDB::writeNodeFile(*viewer.getSceneData(),filename);
|
||||
}
|
||||
|
||||
return viewer.run();
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class OSG_EXPORT ImageSequence : public ImageStream
|
||||
typedef std::list< osg::ref_ptr<osg::Image> > Images;
|
||||
typedef std::list< std::string > FileNames;
|
||||
|
||||
void setDuration(double duration) { _duration = duration; }
|
||||
void setDuration(double duration);
|
||||
double getDuration() const { return _duration; }
|
||||
|
||||
void setPruneOldImages(bool prune) { _pruneOldImages = prune; }
|
||||
@ -80,6 +80,8 @@ class OSG_EXPORT ImageSequence : public ImageStream
|
||||
virtual ~ImageSequence() {}
|
||||
|
||||
void setImageToChild(const osg::Image* image);
|
||||
|
||||
void computeTimePerImage();
|
||||
|
||||
double _referenceTime;
|
||||
double _timeMultiplier;
|
||||
@ -89,6 +91,8 @@ class OSG_EXPORT ImageSequence : public ImageStream
|
||||
|
||||
double _duration;
|
||||
bool _pruneOldImages;
|
||||
|
||||
double _timePerImage;
|
||||
|
||||
double _imageHeadTime;
|
||||
Images _images;
|
||||
|
@ -42,6 +42,7 @@ ImageSequence::ImageSequence()
|
||||
_timeMultiplier = 1.0;
|
||||
|
||||
_duration = 1.0;
|
||||
_timePerImage = 1.0;
|
||||
_pruneOldImages = false;
|
||||
|
||||
_imageIteratorTime = DBL_MAX;
|
||||
@ -64,16 +65,31 @@ int ImageSequence::compare(const Image& rhs) const
|
||||
return ImageStream::compare(rhs);
|
||||
}
|
||||
|
||||
void ImageSequence::setDuration(double duration)
|
||||
{
|
||||
_duration = duration;
|
||||
computeTimePerImage();
|
||||
}
|
||||
|
||||
void ImageSequence::computeTimePerImage()
|
||||
{
|
||||
if (!_fileNames.empty()) _timePerImage = _duration / double(_fileNames.size());
|
||||
else if (!_images.empty()) _timePerImage = _duration / double(_images.size());
|
||||
else _timePerImage = _duration;
|
||||
}
|
||||
|
||||
void ImageSequence::addImageFile(const std::string& fileName)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
_fileNames.push_back(fileName);
|
||||
computeTimePerImage();
|
||||
}
|
||||
|
||||
void ImageSequence::addImage(osg::Image* image)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
_images.push_back(image);
|
||||
computeTimePerImage();
|
||||
|
||||
if (_imageIterator==_images.end())
|
||||
{
|
||||
@ -115,9 +131,6 @@ void ImageSequence::update(osg::NodeVisitor* nv)
|
||||
}
|
||||
|
||||
double time = (fs->getSimulationTime() - _referenceTime)*_timeMultiplier;
|
||||
double delta = _fileNames.empty() ?
|
||||
_duration / _images.size() :
|
||||
_duration / _fileNames.size();
|
||||
|
||||
Images::iterator previous_imageIterator = _imageIterator;
|
||||
|
||||
@ -126,14 +139,20 @@ void ImageSequence::update(osg::NodeVisitor* nv)
|
||||
if (_imageIterator!=_images.end())
|
||||
{
|
||||
// osg::notify(osg::NOTICE)<<" _imageIteratorTime = "<<_imageIteratorTime<<std::endl;
|
||||
while(time > (_imageIteratorTime + delta))
|
||||
while(time > (_imageIteratorTime + _timePerImage))
|
||||
{
|
||||
_imageIteratorTime += delta;
|
||||
_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();
|
||||
}
|
||||
@ -147,6 +166,11 @@ void ImageSequence::update(osg::NodeVisitor* nv)
|
||||
|
||||
if (_imageIterator!=_images.end() && previous_imageIterator != _imageIterator)
|
||||
{
|
||||
if (_pruneOldImages)
|
||||
{
|
||||
_images.erase(previous_imageIterator, _imageIterator);
|
||||
}
|
||||
|
||||
setImageToChild(_imageIterator->get());
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,14 @@ bool ImageSequence_readLocalData(Object& obj, Input& fr)
|
||||
|
||||
ImageSequence& is = static_cast<ImageSequence&>(obj);
|
||||
|
||||
unsigned int numFilesToPreLoad = 1;
|
||||
|
||||
double duration;
|
||||
if (fr.read("Duration", duration))
|
||||
{
|
||||
is.setDuration(duration);
|
||||
}
|
||||
|
||||
if (fr.matchSequence("FileNames {"))
|
||||
{
|
||||
fr += 2;
|
||||
@ -36,12 +44,13 @@ bool ImageSequence_readLocalData(Object& obj, Input& fr)
|
||||
{
|
||||
if (fr[0].getStr())
|
||||
{
|
||||
#if 1
|
||||
is.addImageFile(fr[0].getStr());
|
||||
#else
|
||||
osg::ref_ptr<osg::Image> image = fr.readImage(fr[0].getStr());
|
||||
if (image.valid()) is.addImage(image.get());
|
||||
#endif
|
||||
|
||||
if (is.getImages().size() < numFilesToPreLoad)
|
||||
{
|
||||
osg::ref_ptr<osg::Image> image = fr.readImage(fr[0].getStr());
|
||||
if (image.valid()) is.addImage(image.get());
|
||||
}
|
||||
}
|
||||
++fr;
|
||||
}
|
||||
@ -74,6 +83,8 @@ bool ImageSequence_writeLocalData(const Object& obj, Output& fw)
|
||||
// no current image writing code here
|
||||
// as it is all handled by osg::Registry::writeImage() via plugins.
|
||||
|
||||
fw.indent()<<"Duration "<<is.getDuration()<<std::endl;
|
||||
|
||||
if (!is.getFileNames().empty())
|
||||
{
|
||||
fw.indent()<<"FileNames {"<<std::endl;
|
||||
|
Loading…
Reference in New Issue
Block a user