1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
14#ifndef OSG_IMAGESEQUENCE
15#define OSG_IMAGESEQUENCE 1
17#include <OpenThreads/Mutex>
18#include <osg/ImageStream>
28class OSG_EXPORT ImageSequence : public ImageStream
33 /** Copy constructor using CopyOp to manage deep vs shallow copy. */
34 ImageSequence(const ImageSequence& ImageSequence, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
36 virtual Object* cloneType() const { return new ImageSequence(); }
37 virtual Object* clone(const CopyOp& copyop) const { return new ImageSequence(*this,copyop); }
38 virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const ImageSequence*>(obj)!=0; }
39 virtual const char* libraryName() const { return "osg"; }
40 virtual const char* className() const { return "ImageSequence"; }
42 /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
43 virtual int compare(const Image& rhs) const;
45 virtual void setReferenceTime(double t) { _referenceTime = t; }
46 virtual double getReferenceTime() const { return _referenceTime; }
48 virtual void setTimeMultiplier(double tm) { _timeMultiplier = tm; }
49 virtual double getTimeMultiplier() const { return _timeMultiplier; }
51 struct OSG_EXPORT ImageData
54 ImageData(const ImageData& id);
55 ImageData& operator = (const ImageData& id);
57 std::string _filename;
58 osg::ref_ptr<osg::Image> _image;
59 osg::ref_ptr<osg::Referenced> _imageRequest;
62 typedef std::vector<ImageData> ImageDataList;
64 virtual void seek(double time);
70 virtual void rewind();
75 PAGE_AND_RETAIN_IMAGES,
76 PAGE_AND_DISCARD_USED_IMAGES,
77 LOAD_AND_RETAIN_IN_UPDATE_TRAVERSAL,
78 LOAD_AND_DISCARD_IN_UPDATE_TRAVERSAL
81 void setMode(Mode mode);
82 Mode getMode() const { return _mode; }
84 void setLength(double length);
85 virtual double getLength() const { return _length; }
88 void addImageFile(const std::string& fileName);
90 void setImageFile(unsigned int pos, const std::string& fileName);
91 std::string getImageFile(unsigned int pos) const;
93 void addImage(osg::Image* image);
95 template<class T> void addImage(const osg::ref_ptr<T>& image) { addImage(image.get()); }
97 void setImage(int s,int t,int r,
98 GLint internalTextureformat,
99 GLenum pixelFormat,GLenum type,
102 int packing=1) { Image::setImage(s,t,r,internalTextureformat, pixelFormat, type, data, mode, packing); }
104 void setImage(unsigned int pos, osg::Image* image);
106 template<class T> void setImage(unsigned int pos, const osg::ref_ptr<T>& image) { setImage(pos, image.get()); }
108 Image* getImage(unsigned int pos);
109 const Image* getImage(unsigned int pos) const;
111 unsigned int getNumImageData() const { return _imageDataList.size(); }
113 ImageDataList& getImageDataList() { return _imageDataList; }
114 const ImageDataList& getImageDataList() const { return _imageDataList; }
117 /** ImageSequence requires a call to update(NodeVisitor*) during the update traversal so return true.*/
118 virtual bool requiresUpdateCall() const { return true; }
120 /** update method for osg::Image subclasses that update themselves during the update traversal.*/
121 virtual void update(NodeVisitor* nv);
124 /** Set the optional osgDB::Options object to use when reading images.*/
125 void setReadOptions(osg::Referenced* options) { _readOptions = options; }
127 /** Get the optional osgDB::Options object used when reading images.*/
128 osg::Referenced* getReadOptions() { return _readOptions.get(); }
130 /** Get the optional osgDB::Options object used when reading images.*/
131 const osg::Referenced* getReadOptions() const { return _readOptions.get(); }
135 virtual ~ImageSequence() {}
137 virtual void applyLoopingMode();
139 void setImageToChild(int pos);
141 void computeTimePerImage();
143 int imageIndex(double time);
145 // setImage without acquiring mutex.
146 void _setImage(unsigned int pos, osg::Image* image);
148 double _referenceTime;
149 double _timeMultiplier;
154 double _timePerImage;
156 mutable OpenThreads::Mutex _mutex;
158 ImageDataList _imageDataList;
160 int _previousAppliedImageIndex;
166 osg::ref_ptr<osg::Referenced> _readOptions;