| 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield |
|---|
| 2 | * |
|---|
| 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. |
|---|
| 7 | * |
|---|
| 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. |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | #ifndef OSG_IMAGESEQUENCE |
|---|
| 15 | #define OSG_IMAGESEQUENCE 1 |
|---|
| 16 | |
|---|
| 17 | #include <OpenThreads/Mutex> |
|---|
| 18 | #include <osg/ImageStream> |
|---|
| 19 | |
|---|
| 20 | #include <list> |
|---|
| 21 | #include <set> |
|---|
| 22 | |
|---|
| 23 | namespace osg { |
|---|
| 24 | |
|---|
| 25 | /** |
|---|
| 26 | * Image Buffer class. |
|---|
| 27 | */ |
|---|
| 28 | class OSG_EXPORT ImageSequence : public ImageStream |
|---|
| 29 | { |
|---|
| 30 | public: |
|---|
| 31 | ImageSequence(); |
|---|
| 32 | |
|---|
| 33 | /** Copy constructor using CopyOp to manage deep vs shallow copy. */ |
|---|
| 34 | ImageSequence(const ImageSequence& ImageSequence, const CopyOp& copyop=CopyOp::SHALLOW_COPY); |
|---|
| 35 | |
|---|
| 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"; } |
|---|
| 41 | |
|---|
| 42 | /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */ |
|---|
| 43 | virtual int compare(const Image& rhs) const; |
|---|
| 44 | |
|---|
| 45 | virtual void setReferenceTime(double t) { _referenceTime = t; } |
|---|
| 46 | virtual double getReferenceTime() const { return _referenceTime; } |
|---|
| 47 | |
|---|
| 48 | virtual void setTimeMultiplier(double tm) { _timeMultiplier = tm; } |
|---|
| 49 | virtual double getTimeMultiplier() const { return _timeMultiplier; } |
|---|
| 50 | |
|---|
| 51 | struct OSG_EXPORT ImageData |
|---|
| 52 | { |
|---|
| 53 | ImageData(); |
|---|
| 54 | ImageData(const ImageData& id); |
|---|
| 55 | ImageData& operator = (const ImageData& id); |
|---|
| 56 | |
|---|
| 57 | std::string _filename; |
|---|
| 58 | osg::ref_ptr<osg::Image> _image; |
|---|
| 59 | osg::ref_ptr<osg::Referenced> _imageRequest; |
|---|
| 60 | }; |
|---|
| 61 | |
|---|
| 62 | typedef std::vector<ImageData> ImageDataList; |
|---|
| 63 | |
|---|
| 64 | virtual void seek(double time); |
|---|
| 65 | |
|---|
| 66 | virtual void play(); |
|---|
| 67 | |
|---|
| 68 | virtual void pause(); |
|---|
| 69 | |
|---|
| 70 | virtual void rewind(); |
|---|
| 71 | |
|---|
| 72 | enum Mode |
|---|
| 73 | { |
|---|
| 74 | PRE_LOAD_ALL_IMAGES, |
|---|
| 75 | PAGE_AND_RETAIN_IMAGES, |
|---|
| 76 | PAGE_AND_DISCARD_USED_IMAGES |
|---|
| 77 | }; |
|---|
| 78 | |
|---|
| 79 | void setMode(Mode mode); |
|---|
| 80 | Mode getMode() const { return _mode; } |
|---|
| 81 | |
|---|
| 82 | void setLength(double length); |
|---|
| 83 | virtual double getLength() const { return _length; } |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | void addImageFile(const std::string& fileName); |
|---|
| 87 | |
|---|
| 88 | void setImageFile(unsigned int pos, const std::string& fileName); |
|---|
| 89 | std::string getImageFile(unsigned int pos) const; |
|---|
| 90 | |
|---|
| 91 | void addImage(osg::Image* image); |
|---|
| 92 | |
|---|
| 93 | void setImage(int s,int t,int r, |
|---|
| 94 | GLint internalTextureformat, |
|---|
| 95 | GLenum pixelFormat,GLenum type, |
|---|
| 96 | unsigned char* data, |
|---|
| 97 | AllocationMode mode, |
|---|
| 98 | int packing=1) { Image::setImage(s,t,r,internalTextureformat, pixelFormat, type, data, mode, packing); } |
|---|
| 99 | |
|---|
| 100 | void setImage(unsigned int pos, osg::Image* image); |
|---|
| 101 | Image* getImage(unsigned int pos); |
|---|
| 102 | const Image* getImage(unsigned int pos) const; |
|---|
| 103 | |
|---|
| 104 | unsigned int getNumImageData() const { return _imageDataList.size(); } |
|---|
| 105 | |
|---|
| 106 | ImageDataList& getImageDataList() { return _imageDataList; } |
|---|
| 107 | const ImageDataList& getImageDataList() const { return _imageDataList; } |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | /** ImageSequence requires a call to update(NodeVisitor*) during the update traversal so return true.*/ |
|---|
| 111 | virtual bool requiresUpdateCall() const { return true; } |
|---|
| 112 | |
|---|
| 113 | /** update method for osg::Image subclasses that update themselves during the update traversal.*/ |
|---|
| 114 | virtual void update(NodeVisitor* nv); |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | /** Set the optional osgDB::Options object to use when reading images.*/ |
|---|
| 118 | void setReadOptions(osg::Referenced* options) { _readOptions = options; } |
|---|
| 119 | |
|---|
| 120 | /** Get the optional osgDB::Options object used when reading images.*/ |
|---|
| 121 | osg::Referenced* getReadOptions() { return _readOptions.get(); } |
|---|
| 122 | |
|---|
| 123 | /** Get the optional osgDB::Options object used when reading images.*/ |
|---|
| 124 | const osg::Referenced* getReadOptions() const { return _readOptions.get(); } |
|---|
| 125 | |
|---|
| 126 | protected: |
|---|
| 127 | |
|---|
| 128 | virtual ~ImageSequence() {} |
|---|
| 129 | |
|---|
| 130 | virtual void applyLoopingMode(); |
|---|
| 131 | |
|---|
| 132 | void setImageToChild(int pos); |
|---|
| 133 | |
|---|
| 134 | void computeTimePerImage(); |
|---|
| 135 | |
|---|
| 136 | int imageIndex(double time); |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | double _referenceTime; |
|---|
| 140 | double _timeMultiplier; |
|---|
| 141 | |
|---|
| 142 | Mode _mode; |
|---|
| 143 | double _length; |
|---|
| 144 | |
|---|
| 145 | double _timePerImage; |
|---|
| 146 | |
|---|
| 147 | mutable OpenThreads::Mutex _mutex; |
|---|
| 148 | |
|---|
| 149 | ImageDataList _imageDataList; |
|---|
| 150 | |
|---|
| 151 | int _previousAppliedImageIndex; |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | bool _seekTimeSet; |
|---|
| 155 | double _seekTime; |
|---|
| 156 | |
|---|
| 157 | osg::ref_ptr<osg::Referenced> _readOptions; |
|---|
| 158 | |
|---|
| 159 | }; |
|---|
| 160 | |
|---|
| 161 | } // namespace |
|---|
| 162 | |
|---|
| 163 | #endif |
|---|