| 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 | typedef std::vector< osg::ref_ptr<osg::Image> > Images; |
|---|
| 52 | typedef std::vector< std::string > FileNames; |
|---|
| 53 | |
|---|
| 54 | virtual void seek(double time); |
|---|
| 55 | |
|---|
| 56 | virtual void play(); |
|---|
| 57 | |
|---|
| 58 | virtual void pause(); |
|---|
| 59 | |
|---|
| 60 | virtual void rewind(); |
|---|
| 61 | |
|---|
| 62 | enum Mode |
|---|
| 63 | { |
|---|
| 64 | PRE_LOAD_ALL_IMAGES, |
|---|
| 65 | PAGE_AND_RETAIN_IMAGES, |
|---|
| 66 | PAGE_AND_DISCARD_USED_IMAGES |
|---|
| 67 | }; |
|---|
| 68 | |
|---|
| 69 | void setMode(Mode mode); |
|---|
| 70 | Mode getMode() const { return _mode; } |
|---|
| 71 | |
|---|
| 72 | void setLength(double length); |
|---|
| 73 | virtual double getLength() const { return _length; } |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | void addImageFile(const std::string& fileName); |
|---|
| 77 | |
|---|
| 78 | void setImageFile(unsigned int pos, const std::string& fileName); |
|---|
| 79 | std::string getImageFile(unsigned int pos) const; |
|---|
| 80 | |
|---|
| 81 | unsigned int getNumImageFiles() const { return _fileNames.size(); } |
|---|
| 82 | |
|---|
| 83 | FileNames& getFileNames() { return _fileNames; } |
|---|
| 84 | const FileNames& getFileNames() const { return _fileNames; } |
|---|
| 85 | |
|---|
| 86 | void addImage(osg::Image* image); |
|---|
| 87 | |
|---|
| 88 | void setImage(int s,int t,int r, |
|---|
| 89 | GLint internalTextureformat, |
|---|
| 90 | GLenum pixelFormat,GLenum type, |
|---|
| 91 | unsigned char* data, |
|---|
| 92 | AllocationMode mode, |
|---|
| 93 | int packing=1) { Image::setImage(s,t,r,internalTextureformat, pixelFormat, type, data, mode, packing); } |
|---|
| 94 | |
|---|
| 95 | void setImage(unsigned int pos, osg::Image* image); |
|---|
| 96 | Image* getImage(unsigned int pos); |
|---|
| 97 | const Image* getImage(unsigned int pos) const; |
|---|
| 98 | |
|---|
| 99 | unsigned int getNumImages() const { return _images.size(); } |
|---|
| 100 | |
|---|
| 101 | Images& getImages() { return _images; } |
|---|
| 102 | const Images& getImages() const { return _images; } |
|---|
| 103 | |
|---|
| 104 | /** ImageSequence requires a call to update(NodeVisitor*) during the update traversal so return true.*/ |
|---|
| 105 | virtual bool requiresUpdateCall() const { return true; } |
|---|
| 106 | |
|---|
| 107 | /** update method for osg::Image subclasses that update themselves during the update traversal.*/ |
|---|
| 108 | virtual void update(NodeVisitor* nv); |
|---|
| 109 | |
|---|
| 110 | protected: |
|---|
| 111 | |
|---|
| 112 | virtual ~ImageSequence() {} |
|---|
| 113 | |
|---|
| 114 | virtual void applyLoopingMode(); |
|---|
| 115 | |
|---|
| 116 | void setImageToChild(const osg::Image* image); |
|---|
| 117 | |
|---|
| 118 | void computeTimePerImage(); |
|---|
| 119 | |
|---|
| 120 | int imageIndex(double time); |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | double _referenceTime; |
|---|
| 124 | double _timeMultiplier; |
|---|
| 125 | |
|---|
| 126 | Mode _mode; |
|---|
| 127 | double _length; |
|---|
| 128 | |
|---|
| 129 | double _timePerImage; |
|---|
| 130 | |
|---|
| 131 | mutable OpenThreads::Mutex _mutex; |
|---|
| 132 | FileNames _fileNames; |
|---|
| 133 | |
|---|
| 134 | Images _images; |
|---|
| 135 | |
|---|
| 136 | typedef std::set< std::string > FilesRequested; |
|---|
| 137 | FilesRequested _filesRequested; |
|---|
| 138 | |
|---|
| 139 | int _previousAppliedImageIndex; |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | bool _seekTimeSet; |
|---|
| 143 | double _seekTime; |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | }; |
|---|
| 148 | |
|---|
| 149 | } // namespace |
|---|
| 150 | |
|---|
| 151 | #endif |
|---|