2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2008-07-21 17:46:53 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2008-07-21 17:46:53 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2008-07-21 17:46:53 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2008-07-21 17:46:53 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2008-07-21 18:57:06 +08:00
|
|
|
#include <OpenThreads/ScopedLock>
|
2008-07-21 17:46:53 +08:00
|
|
|
#include <osg/ImageSequence>
|
2008-07-22 01:28:22 +08:00
|
|
|
#include <osg/Notify>
|
|
|
|
#include <osg/Camera>
|
2008-07-22 05:00:57 +08:00
|
|
|
#include <osg/NodeVisitor>
|
|
|
|
#include <osg/Texture2D>
|
2008-07-22 01:28:22 +08:00
|
|
|
|
|
|
|
#include <math.h>
|
2008-07-21 17:46:53 +08:00
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
2012-11-08 19:19:31 +08:00
|
|
|
ImageSequence::ImageData::ImageData()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageSequence::ImageData::ImageData(const ImageData& id):
|
|
|
|
_filename(id._filename),
|
|
|
|
_image(id._image),
|
|
|
|
_imageRequest(id._imageRequest)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageSequence::ImageData& ImageSequence::ImageData::operator = (const ImageSequence::ImageData& rhs)
|
|
|
|
{
|
|
|
|
if (&rhs!=this)
|
|
|
|
{
|
|
|
|
_filename = rhs._filename;
|
|
|
|
_image = rhs._image;
|
|
|
|
_imageRequest = rhs._imageRequest;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2008-07-21 17:46:53 +08:00
|
|
|
ImageSequence::ImageSequence()
|
|
|
|
{
|
2008-07-22 01:28:22 +08:00
|
|
|
_referenceTime = DBL_MAX;
|
2008-07-21 17:46:53 +08:00
|
|
|
_timeMultiplier = 1.0;
|
2008-07-22 05:00:57 +08:00
|
|
|
|
2008-07-26 00:11:51 +08:00
|
|
|
_mode = PRE_LOAD_ALL_IMAGES;
|
2008-08-16 00:21:44 +08:00
|
|
|
_length = 1.0;
|
2008-07-23 00:44:49 +08:00
|
|
|
_timePerImage = 1.0;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-08-15 20:45:20 +08:00
|
|
|
_seekTime = 0.0;
|
|
|
|
_seekTimeSet = false;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-10-07 01:02:20 +08:00
|
|
|
_previousAppliedImageIndex = -1;
|
2008-07-21 17:46:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ImageSequence::ImageSequence(const ImageSequence& is,const CopyOp& copyop):
|
|
|
|
osg::ImageStream(is,copyop),
|
|
|
|
_referenceTime(is._referenceTime),
|
2008-07-22 05:00:57 +08:00
|
|
|
_timeMultiplier(is._timeMultiplier),
|
2008-07-26 00:11:51 +08:00
|
|
|
_mode(is._mode),
|
2008-08-16 00:21:44 +08:00
|
|
|
_length(is._length),
|
2008-07-26 00:11:51 +08:00
|
|
|
_timePerImage(is._timePerImage)
|
2008-07-21 17:46:53 +08:00
|
|
|
{
|
2008-08-15 20:45:20 +08:00
|
|
|
_seekTime = is._seekTime;
|
|
|
|
_seekTimeSet = is._seekTimeSet;
|
2008-10-07 01:02:20 +08:00
|
|
|
|
|
|
|
_previousAppliedImageIndex = -1;
|
2008-07-21 17:46:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int ImageSequence::compare(const Image& rhs) const
|
|
|
|
{
|
|
|
|
return ImageStream::compare(rhs);
|
|
|
|
}
|
|
|
|
|
2008-08-15 20:45:20 +08:00
|
|
|
void ImageSequence::seek(double time)
|
|
|
|
{
|
|
|
|
_seekTime = time;
|
|
|
|
_seekTimeSet = true;
|
|
|
|
}
|
|
|
|
|
2008-08-15 00:29:12 +08:00
|
|
|
void ImageSequence::play()
|
|
|
|
{
|
|
|
|
_status=PLAYING;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImageSequence::pause()
|
|
|
|
{
|
|
|
|
_status=PAUSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImageSequence::rewind()
|
|
|
|
{
|
2008-08-15 20:45:20 +08:00
|
|
|
seek(0.0f);
|
2008-08-15 00:29:12 +08:00
|
|
|
}
|
|
|
|
|
2008-07-26 00:23:00 +08:00
|
|
|
void ImageSequence::setMode(Mode mode)
|
|
|
|
{
|
|
|
|
_mode = mode;
|
|
|
|
}
|
|
|
|
|
2008-08-16 00:21:44 +08:00
|
|
|
void ImageSequence::setLength(double length)
|
2008-07-23 00:44:49 +08:00
|
|
|
{
|
2008-10-07 01:02:20 +08:00
|
|
|
if (length<=0.0)
|
|
|
|
{
|
2010-05-28 23:47:52 +08:00
|
|
|
OSG_NOTICE<<"ImageSequence::setLength("<<length<<") invalid length value, must be greater than 0."<<std::endl;
|
2008-10-07 01:02:20 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-08-16 00:21:44 +08:00
|
|
|
_length = length;
|
2008-07-23 00:44:49 +08:00
|
|
|
computeTimePerImage();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImageSequence::computeTimePerImage()
|
|
|
|
{
|
2012-11-08 19:19:31 +08:00
|
|
|
if (!_imageDataList.empty()) _timePerImage = _length / double(_imageDataList.size());
|
2008-08-16 00:21:44 +08:00
|
|
|
else _timePerImage = _length;
|
2008-07-23 00:44:49 +08:00
|
|
|
}
|
|
|
|
|
2008-10-07 01:02:20 +08:00
|
|
|
void ImageSequence::setImageFile(unsigned int pos, const std::string& fileName)
|
|
|
|
{
|
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
|
|
|
|
2012-11-08 19:19:31 +08:00
|
|
|
if (pos>=_imageDataList.size()) _imageDataList.resize(pos);
|
|
|
|
_imageDataList[pos]._filename = fileName;
|
2008-10-07 01:02:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string ImageSequence::getImageFile(unsigned int pos) const
|
|
|
|
{
|
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
2012-11-08 19:19:31 +08:00
|
|
|
return pos<_imageDataList.size() ? _imageDataList[pos]._filename : std::string();
|
2008-10-07 01:02:20 +08:00
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-07-22 05:00:57 +08:00
|
|
|
void ImageSequence::addImageFile(const std::string& fileName)
|
2008-07-21 17:46:53 +08:00
|
|
|
{
|
2008-07-21 18:57:06 +08:00
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
2012-11-08 19:19:31 +08:00
|
|
|
_imageDataList.push_back(ImageData());
|
|
|
|
_imageDataList.back()._filename = fileName;
|
2008-07-23 00:44:49 +08:00
|
|
|
computeTimePerImage();
|
2008-10-07 01:02:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ImageSequence::setImage(unsigned int pos, osg::Image* image)
|
|
|
|
{
|
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
|
|
|
|
2013-01-19 00:21:17 +08:00
|
|
|
_setImage(pos,image);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImageSequence::_setImage(unsigned int pos, osg::Image* image)
|
|
|
|
{
|
2012-11-08 19:19:31 +08:00
|
|
|
if (pos>=_imageDataList.size()) _imageDataList.resize(pos+1);
|
2008-10-07 01:02:20 +08:00
|
|
|
|
2012-11-08 19:19:31 +08:00
|
|
|
_imageDataList[pos]._image = image;
|
|
|
|
_imageDataList[pos]._filename = image->getFileName();
|
2008-07-21 17:46:53 +08:00
|
|
|
}
|
|
|
|
|
2008-10-07 01:02:20 +08:00
|
|
|
Image* ImageSequence::getImage(unsigned int pos)
|
2008-07-21 17:46:53 +08:00
|
|
|
{
|
2008-07-21 18:57:06 +08:00
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
2012-11-08 19:19:31 +08:00
|
|
|
return pos<_imageDataList.size() ? _imageDataList[pos]._image.get() : 0;
|
2008-10-07 01:02:20 +08:00
|
|
|
}
|
2008-07-22 01:28:22 +08:00
|
|
|
|
2008-10-07 01:02:20 +08:00
|
|
|
const Image* ImageSequence::getImage(unsigned int pos) const
|
|
|
|
{
|
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
2012-11-08 19:19:31 +08:00
|
|
|
return pos<_imageDataList.size() ? _imageDataList[pos]._image.get() : 0;
|
2008-10-07 01:02:20 +08:00
|
|
|
}
|
2008-07-25 21:45:07 +08:00
|
|
|
|
2008-10-07 01:02:20 +08:00
|
|
|
void ImageSequence::addImage(osg::Image* image)
|
|
|
|
{
|
|
|
|
if (image==0) return;
|
|
|
|
|
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
|
|
|
|
2010-05-28 23:47:52 +08:00
|
|
|
// OSG_NOTICE<<"merging image in order expected : "<<image->getFileName()<<std::endl;
|
2012-11-08 19:19:31 +08:00
|
|
|
_imageDataList.push_back(ImageData());
|
|
|
|
_imageDataList.back()._image = image;
|
2008-07-25 21:45:07 +08:00
|
|
|
|
|
|
|
computeTimePerImage();
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-07-25 21:45:07 +08:00
|
|
|
if (data()==0)
|
2008-07-22 01:28:22 +08:00
|
|
|
{
|
2012-11-08 19:19:31 +08:00
|
|
|
setImageToChild(_imageDataList.size()-1);
|
2008-07-22 01:28:22 +08:00
|
|
|
}
|
2008-07-21 17:46:53 +08:00
|
|
|
}
|
|
|
|
|
2012-11-08 19:19:31 +08:00
|
|
|
void ImageSequence::setImageToChild(int pos)
|
2008-07-22 01:28:22 +08:00
|
|
|
{
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2012-11-08 19:19:31 +08:00
|
|
|
const osg::Image* image = (pos>=0 && pos<static_cast<int>(_imageDataList.size())) ? _imageDataList[pos]._image.get() : 0;
|
2008-07-26 00:11:51 +08:00
|
|
|
if (image==0) return;
|
|
|
|
|
2008-10-07 01:02:20 +08:00
|
|
|
// check to see if data is changing, if not don't apply
|
2012-11-08 19:19:31 +08:00
|
|
|
if (image->data() == data())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-19 00:21:17 +08:00
|
|
|
bool discardOldImages = _mode==PAGE_AND_DISCARD_USED_IMAGES || _mode==LOAD_AND_DISCARD_IN_UPDATE_TRAVERSAL;
|
|
|
|
if (discardOldImages && _previousAppliedImageIndex>=0)
|
2012-11-08 19:19:31 +08:00
|
|
|
{
|
|
|
|
if (_previousAppliedImageIndex<pos)
|
|
|
|
{
|
|
|
|
OSG_INFO<<"Moving forward from "<<_previousAppliedImageIndex<<" to "<<pos<<std::endl;
|
|
|
|
while(_previousAppliedImageIndex<pos)
|
|
|
|
{
|
|
|
|
_imageDataList[_previousAppliedImageIndex]._image = 0;
|
|
|
|
OSG_INFO<<" deleting "<<_previousAppliedImageIndex<<std::endl;
|
|
|
|
++_previousAppliedImageIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (_previousAppliedImageIndex>pos)
|
|
|
|
{
|
|
|
|
OSG_INFO<<"Moving back from "<<_previousAppliedImageIndex<<" to "<<pos<<std::endl;
|
|
|
|
while(_previousAppliedImageIndex>pos)
|
|
|
|
{
|
|
|
|
_imageDataList[_previousAppliedImageIndex]._image = 0;
|
|
|
|
OSG_INFO<<" deleting "<<_previousAppliedImageIndex<<std::endl;
|
|
|
|
--_previousAppliedImageIndex;
|
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
}
|
2012-11-08 19:19:31 +08:00
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2012-11-08 19:19:31 +08:00
|
|
|
|
|
|
|
_previousAppliedImageIndex = pos;
|
2008-10-07 01:02:20 +08:00
|
|
|
|
2008-07-22 01:28:22 +08:00
|
|
|
setImage(image->s(),image->t(),image->r(),
|
|
|
|
image->getInternalTextureFormat(),
|
|
|
|
image->getPixelFormat(),image->getDataType(),
|
|
|
|
const_cast<unsigned char*>(image->data()),
|
|
|
|
osg::Image::NO_DELETE,
|
|
|
|
image->getPacking());
|
2016-04-01 00:52:29 +08:00
|
|
|
|
|
|
|
setMipmapLevels(image->getMipmapLevels());
|
2008-07-22 01:28:22 +08:00
|
|
|
}
|
|
|
|
|
2008-10-07 01:02:20 +08:00
|
|
|
void ImageSequence::applyLoopingMode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int ImageSequence::imageIndex(double time)
|
|
|
|
{
|
2012-03-22 01:36:20 +08:00
|
|
|
if (getLoopingMode()==LOOPING)
|
2008-10-07 01:02:20 +08:00
|
|
|
{
|
|
|
|
double positionRatio = time/_length;
|
|
|
|
time = (positionRatio - floor(positionRatio))*_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (time<0.0) return 0;
|
|
|
|
int index = int(time/_timePerImage);
|
2012-11-08 19:19:31 +08:00
|
|
|
if (index>=int(_imageDataList.size())) return int(_imageDataList.size())-1;
|
2008-10-07 01:02:20 +08:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2008-07-22 05:00:57 +08:00
|
|
|
void ImageSequence::update(osg::NodeVisitor* nv)
|
2008-07-21 17:46:53 +08:00
|
|
|
{
|
2008-07-21 18:57:06 +08:00
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2012-11-08 22:15:59 +08:00
|
|
|
// if imageDataList is empty then there is nothing update can do.
|
|
|
|
if (_imageDataList.empty()) return;
|
|
|
|
|
2008-07-22 05:00:57 +08:00
|
|
|
osg::NodeVisitor::ImageRequestHandler* irh = nv->getImageRequestHandler();
|
|
|
|
const osg::FrameStamp* fs = nv->getFrameStamp();
|
|
|
|
|
2010-05-28 23:47:52 +08:00
|
|
|
// OSG_NOTICE<<"ImageSequence::update("<<fs<<", "<<irh<<")"<<std::endl;
|
2008-07-22 01:28:22 +08:00
|
|
|
|
|
|
|
if (_referenceTime == DBL_MAX)
|
|
|
|
{
|
|
|
|
_referenceTime = fs->getSimulationTime();
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-08-15 20:45:20 +08:00
|
|
|
bool looping = getLoopingMode()==LOOPING;
|
|
|
|
double time = (fs->getSimulationTime() - _referenceTime)*_timeMultiplier;
|
2012-10-05 18:37:36 +08:00
|
|
|
bool useDirectTimeRequest = _seekTimeSet;
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2008-08-15 20:45:20 +08:00
|
|
|
if (_seekTimeSet || _status==PAUSED || _status==INVALID)
|
2008-07-22 01:28:22 +08:00
|
|
|
{
|
2012-03-22 01:36:20 +08:00
|
|
|
time = _seekTime;
|
2012-11-08 19:19:31 +08:00
|
|
|
useDirectTimeRequest = true;
|
2008-08-15 20:45:20 +08:00
|
|
|
_referenceTime = fs->getSimulationTime() - time/_timeMultiplier;
|
2008-07-22 01:28:22 +08:00
|
|
|
}
|
2008-10-07 01:02:20 +08:00
|
|
|
else
|
2008-08-15 20:45:20 +08:00
|
|
|
{
|
2008-10-07 01:02:20 +08:00
|
|
|
if (looping)
|
|
|
|
{
|
|
|
|
while (time>_length)
|
|
|
|
{
|
|
|
|
_referenceTime += _length/_timeMultiplier;
|
|
|
|
time -= _length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (time>_length)
|
|
|
|
{
|
|
|
|
_referenceTime = fs->getSimulationTime() - _length/_timeMultiplier;
|
|
|
|
time = _length;
|
|
|
|
}
|
|
|
|
}
|
2008-08-15 20:45:20 +08:00
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-08-15 20:45:20 +08:00
|
|
|
_seekTime = time;
|
2008-10-07 01:02:20 +08:00
|
|
|
_seekTimeSet = false;
|
2008-08-15 20:45:20 +08:00
|
|
|
|
2012-11-08 19:19:31 +08:00
|
|
|
if (irh && _mode==PRE_LOAD_ALL_IMAGES)
|
2008-07-26 00:11:51 +08:00
|
|
|
{
|
2012-11-08 19:19:31 +08:00
|
|
|
for(ImageDataList::iterator itr = _imageDataList.begin();
|
|
|
|
itr != _imageDataList.end();
|
|
|
|
++itr)
|
2008-07-26 00:11:51 +08:00
|
|
|
{
|
2012-11-08 19:19:31 +08:00
|
|
|
if (!(itr->_image) && !(itr->_filename.empty()))
|
2008-07-26 00:11:51 +08:00
|
|
|
{
|
2015-10-22 21:42:19 +08:00
|
|
|
itr->_image = irh->readRefImageFile(itr->_filename, _readOptions.get());
|
2008-07-26 00:11:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-07 01:02:20 +08:00
|
|
|
int index = int(time/_timePerImage);
|
2010-05-28 23:47:52 +08:00
|
|
|
// OSG_NOTICE<<"time= "<<time<<" _timePerImage="<<_timePerImage<<" index="<<index<<" _length="<<_length<<std::endl;
|
2008-07-22 01:28:22 +08:00
|
|
|
|
2012-11-08 19:19:31 +08:00
|
|
|
if (index>=int(_imageDataList.size())) index = int(_imageDataList.size())-1;
|
2008-10-07 01:02:20 +08:00
|
|
|
|
2012-11-08 19:19:31 +08:00
|
|
|
if (index>=0 && index<int(_imageDataList.size()))
|
2008-07-22 01:28:22 +08:00
|
|
|
{
|
2012-11-08 19:19:31 +08:00
|
|
|
// need to find the nearest relevant change.
|
|
|
|
if (!_imageDataList[index]._image)
|
2015-10-22 21:42:19 +08:00
|
|
|
{
|
2012-10-05 18:37:36 +08:00
|
|
|
if (_previousAppliedImageIndex<index)
|
2008-08-16 00:21:44 +08:00
|
|
|
{
|
2012-11-05 20:21:34 +08:00
|
|
|
OSG_DEBUG<<"ImageSequence::update(..) Moving forward by "<<index-_previousAppliedImageIndex<<std::endl;
|
2012-11-08 19:19:31 +08:00
|
|
|
while (index>=0 && !_imageDataList[index]._image.valid())
|
2012-10-05 18:37:36 +08:00
|
|
|
{
|
|
|
|
--index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (_previousAppliedImageIndex>index)
|
|
|
|
{
|
2012-11-05 20:21:34 +08:00
|
|
|
OSG_DEBUG<<"ImageSequence::update(..) Moving back by "<<_previousAppliedImageIndex-index<<std::endl;
|
2012-11-08 19:19:31 +08:00
|
|
|
while (index<static_cast<int>(_imageDataList.size()) && !_imageDataList[index]._image.valid())
|
2012-10-05 18:37:36 +08:00
|
|
|
{
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
}
|
2008-08-16 00:21:44 +08:00
|
|
|
}
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2012-11-08 19:19:31 +08:00
|
|
|
if (index>=0 && index!=_previousAppliedImageIndex)
|
2008-07-22 01:28:22 +08:00
|
|
|
{
|
2012-11-08 19:19:31 +08:00
|
|
|
setImageToChild(index);
|
2008-07-22 01:28:22 +08:00
|
|
|
}
|
|
|
|
}
|
2008-08-15 20:45:20 +08:00
|
|
|
|
2010-05-28 23:47:52 +08:00
|
|
|
// OSG_NOTICE<<"time = "<<time<<std::endl;
|
2008-08-15 20:45:20 +08:00
|
|
|
|
2012-10-05 18:37:36 +08:00
|
|
|
if (!irh) return;
|
|
|
|
|
2013-01-19 00:21:17 +08:00
|
|
|
bool loadDirectly = (_mode==LOAD_AND_RETAIN_IN_UPDATE_TRAVERSAL) || (_mode==LOAD_AND_DISCARD_IN_UPDATE_TRAVERSAL);
|
2015-10-22 21:42:19 +08:00
|
|
|
|
2012-10-05 18:37:36 +08:00
|
|
|
if (useDirectTimeRequest)
|
|
|
|
{
|
2012-11-22 23:13:46 +08:00
|
|
|
int i = osg::maximum<int>(0, int(time/_timePerImage));
|
2012-11-08 19:19:31 +08:00
|
|
|
if ((i>=int(_imageDataList.size()) || !_imageDataList[i]._image))
|
2012-10-05 18:37:36 +08:00
|
|
|
{
|
2012-11-22 23:13:46 +08:00
|
|
|
i = osg::minimum<int>(i, _imageDataList.size()-1);
|
2012-11-08 19:19:31 +08:00
|
|
|
|
2013-01-19 00:21:17 +08:00
|
|
|
if (loadDirectly)
|
|
|
|
{
|
|
|
|
OSG_NOTICE<<"Reading file, entry="<<i<<" : _fileNames[i]="<<_imageDataList[i]._filename<<std::endl;
|
2015-10-22 21:42:19 +08:00
|
|
|
osg::ref_ptr<osg::Image> image = irh->readRefImageFile(_imageDataList[i]._filename, _readOptions.get());
|
2013-01-19 00:21:17 +08:00
|
|
|
if (image.valid())
|
|
|
|
{
|
|
|
|
OSG_NOTICE<<" Assigning image "<<_imageDataList[i]._filename<<std::endl;
|
2013-02-06 02:22:46 +08:00
|
|
|
_setImage(i, image.get());
|
2013-01-19 00:21:17 +08:00
|
|
|
setImageToChild(i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSG_NOTICE<<" Failed to read file "<<_imageDataList[i]._filename<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSG_NOTICE<<"Requesting file, entry="<<i<<" : _fileNames[i]="<<_imageDataList[i]._filename<<std::endl;
|
|
|
|
irh->requestImageFile(_imageDataList[i]._filename, this, i, time, fs, _imageDataList[i]._imageRequest, _readOptions.get());
|
|
|
|
}
|
2012-10-05 18:37:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2008-07-22 01:28:22 +08:00
|
|
|
{
|
2008-10-07 01:02:20 +08:00
|
|
|
double preLoadTime = time + osg::minimum(irh->getPreLoadTime()*_timeMultiplier, _length);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-10-07 01:02:20 +08:00
|
|
|
int startLoadIndex = int(time/_timePerImage);
|
2012-11-08 19:19:31 +08:00
|
|
|
if (startLoadIndex>=int(_imageDataList.size())) startLoadIndex = int(_imageDataList.size())-1;
|
2008-10-07 01:02:20 +08:00
|
|
|
if (startLoadIndex<0) startLoadIndex = 0;
|
2008-08-15 20:45:20 +08:00
|
|
|
|
2008-10-07 01:02:20 +08:00
|
|
|
int endLoadIndex = int(preLoadTime/_timePerImage);
|
2014-06-26 18:24:41 +08:00
|
|
|
if (looping && (endLoadIndex>=int(_imageDataList.size()))) endLoadIndex -= int(_imageDataList.size());
|
|
|
|
if (endLoadIndex>=int(_imageDataList.size())) endLoadIndex = int(_imageDataList.size())-1;
|
2008-10-07 01:02:20 +08:00
|
|
|
if (endLoadIndex<0) endLoadIndex = 0;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-10-07 01:02:20 +08:00
|
|
|
double requestTime = time;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-10-07 01:02:20 +08:00
|
|
|
if (endLoadIndex<startLoadIndex)
|
2008-07-23 04:20:16 +08:00
|
|
|
{
|
2012-11-08 19:19:31 +08:00
|
|
|
for(int i=startLoadIndex; i<int(_imageDataList.size()); ++i)
|
2008-07-23 04:20:16 +08:00
|
|
|
{
|
2012-11-08 19:19:31 +08:00
|
|
|
if (!_imageDataList[i]._image)
|
2008-07-23 04:20:16 +08:00
|
|
|
{
|
2012-11-08 19:19:31 +08:00
|
|
|
irh->requestImageFile(_imageDataList[i]._filename, this, i, requestTime, fs, _imageDataList[i]._imageRequest, _readOptions.get());
|
2008-07-23 04:20:16 +08:00
|
|
|
}
|
2008-10-07 01:02:20 +08:00
|
|
|
requestTime += _timePerImage;
|
2008-07-23 04:20:16 +08:00
|
|
|
}
|
|
|
|
|
2008-10-07 01:02:20 +08:00
|
|
|
for(int i=0; i<=endLoadIndex; ++i)
|
|
|
|
{
|
2012-11-08 19:19:31 +08:00
|
|
|
if (!_imageDataList[i]._image)
|
2008-10-07 01:02:20 +08:00
|
|
|
{
|
2012-11-08 19:19:31 +08:00
|
|
|
irh->requestImageFile(_imageDataList[i]._filename, this, i, requestTime, fs, _imageDataList[i]._imageRequest, _readOptions.get());
|
2008-10-07 01:02:20 +08:00
|
|
|
}
|
|
|
|
requestTime += _timePerImage;
|
|
|
|
}
|
2008-07-23 04:20:16 +08:00
|
|
|
}
|
2008-10-07 01:02:20 +08:00
|
|
|
else
|
2008-07-23 00:44:49 +08:00
|
|
|
{
|
2008-10-07 01:02:20 +08:00
|
|
|
for(int i=startLoadIndex; i<=endLoadIndex; ++i)
|
|
|
|
{
|
2012-11-08 19:19:31 +08:00
|
|
|
if (!_imageDataList[i]._image)
|
2008-10-07 01:02:20 +08:00
|
|
|
{
|
2012-11-08 19:19:31 +08:00
|
|
|
irh->requestImageFile(_imageDataList[i]._filename, this, i, requestTime, fs, _imageDataList[i]._imageRequest, _readOptions.get());
|
2008-10-07 01:02:20 +08:00
|
|
|
}
|
|
|
|
requestTime += _timePerImage;
|
|
|
|
}
|
2008-07-23 00:44:49 +08:00
|
|
|
}
|
2008-10-07 01:02:20 +08:00
|
|
|
|
2008-07-22 01:28:22 +08:00
|
|
|
}
|
2008-10-07 01:02:20 +08:00
|
|
|
|
2008-07-21 17:46:53 +08:00
|
|
|
}
|