/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * * 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 * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #include #include #include #include #include #include #include using namespace osg; void ImageSequence::UpdateCallback::operator () (osg::StateAttribute* attr, osg::NodeVisitor* nv) { const osg::FrameStamp* fs = nv!=0 ? nv->getFrameStamp() : 0; osg::Texture2D* texture2D = dynamic_cast(attr); if (texture2D && texture2D->getImage() && fs) { texture2D->getImage()->update(nv); } } ImageSequence::ImageSequence() { _referenceTime = DBL_MAX; _timeMultiplier = 1.0; _duration = 1.0; _pruneOldImages = false; _imageIteratorTime = DBL_MAX; _imageIterator = _images.end(); } ImageSequence::ImageSequence(const ImageSequence& is,const CopyOp& copyop): osg::ImageStream(is,copyop), _referenceTime(is._referenceTime), _timeMultiplier(is._timeMultiplier), _duration(is._duration), _pruneOldImages(is._pruneOldImages) { _imageIteratorTime = DBL_MAX; _imageIterator = _images.end(); } int ImageSequence::compare(const Image& rhs) const { return ImageStream::compare(rhs); } void ImageSequence::addImageFile(const std::string& fileName) { OpenThreads::ScopedLock lock(_mutex); _fileNames.push_back(fileName); } void ImageSequence::addImage(osg::Image* image) { OpenThreads::ScopedLock lock(_mutex); _images.push_back(image); if (_imageIterator==_images.end()) { _imageIterator = _images.begin(); _imageIteratorTime = _referenceTime; setImageToChild(_imageIterator->get()); } } void ImageSequence::setImageToChild(const osg::Image* image) { // osg::notify(osg::NOTICE)<<"setImageToChild("<s(),image->t(),image->r(), image->getInternalTextureFormat(), image->getPixelFormat(),image->getDataType(), const_cast(image->data()), osg::Image::NO_DELETE, image->getPacking()); } void ImageSequence::update(osg::NodeVisitor* nv) { OpenThreads::ScopedLock lock(_mutex); osg::NodeVisitor::ImageRequestHandler* irh = nv->getImageRequestHandler(); const osg::FrameStamp* fs = nv->getFrameStamp(); // osg::notify(osg::NOTICE)<<"ImageSequence::update("<getSimulationTime(); } if (_imageIteratorTime == DBL_MAX) { _imageIteratorTime = _referenceTime; } double time = (fs->getSimulationTime() - _referenceTime)*_timeMultiplier; double delta = _fileNames.empty() ? _duration / _images.size() : _duration / _fileNames.size(); Images::iterator previous_imageIterator = _imageIterator; // osg::notify(osg::NOTICE)<<"time = "<