root/OpenSceneGraph/trunk/include/osg/ImageSequence @ 10671

Revision 10671, 5.0 kB (checked in by robert, 4 years ago)

From Cedric Pinson, "Here a patch to be able to clone stateattribute, in order to do that i
moved the StateAttribute::Callback structure to a file
StateAttributeCallback? with the same behavior as NodeCallback?.
"

RevLine 
[8632]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>
[8647]19#include <osg/StateAttribute>
[8632]20
[8637]21#include <list>
[8990]22#include <set>
[8632]23
24namespace osg {
25
26/**
27  * Image Buffer class.
28*/
29class OSG_EXPORT ImageSequence : public ImageStream
30{
31    public:
32        ImageSequence();
33
34        /** Copy constructor using CopyOp to manage deep vs shallow copy. */
[8647]35        ImageSequence(const ImageSequence& ImageSequence, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
[8632]36
37        virtual Object* cloneType() const { return new ImageSequence(); }
38        virtual Object* clone(const CopyOp& copyop) const { return new ImageSequence(*this,copyop); }
39        virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const ImageSequence*>(obj)!=0; }
40        virtual const char* libraryName() const { return "osg"; }
41        virtual const char* className() const { return "ImageSequence"; }
42
43        /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
44        virtual int compare(const Image& rhs) const;
45
46        virtual void setReferenceTime(double t) { _referenceTime = t; }
47        virtual double getReferenceTime() const { return _referenceTime; }
48               
49        virtual void setTimeMultiplier(double tm) { _timeMultiplier = tm; }
50        virtual double getTimeMultiplier() const { return _timeMultiplier; }
51
[8990]52        typedef std::vector< osg::ref_ptr<osg::Image> >   Images;
53        typedef std::vector< std::string >                FileNames;
[8685]54       
[8755]55        virtual void seek(double time);
56
[8754]57        virtual void play();
58
59        virtual void pause();
60
61        virtual void rewind();
62       
[8685]63        enum Mode
64        {
65            PRE_LOAD_ALL_IMAGES,
66            PAGE_AND_RETAIN_IMAGES,
67            PAGE_AND_DISCARD_USED_IMAGES
68        };
69       
70        void setMode(Mode mode);
71        Mode getMode() const { return _mode; }
[8632]72
[8758]73        void setLength(double length);
74        virtual double getLength() const { return _length; }
[8754]75       
76
[8647]77        void addImageFile(const std::string& fileName);
[8655]78       
[8990]79        void setImageFile(unsigned int pos, const std::string& fileName);
80        std::string getImageFile(unsigned int pos) const;
81       
82        unsigned int getNumImageFiles() const { return _fileNames.size(); }
83
[8655]84        FileNames& getFileNames() { return _fileNames; }
85        const FileNames& getFileNames() const { return _fileNames; }
[8632]86
[8647]87        void addImage(osg::Image* image);
[8655]88       
[8990]89        void setImage(int s,int t,int r,
90                      GLint internalTextureformat,
91                      GLenum pixelFormat,GLenum type,
92                      unsigned char* data,
93                      AllocationMode mode,
94                      int packing=1) { Image::setImage(s,t,r,internalTextureformat, pixelFormat, type, data, mode, packing); }
95
96        void setImage(unsigned int pos, osg::Image* image);
97        Image* getImage(unsigned int pos);
98        const Image* getImage(unsigned int pos) const;
99       
100        unsigned int getNumImages() const { return _images.size(); }
101
[8655]102        Images& getImages() { return _images; }
103        const Images& getImages() const { return _images; }
104       
[8637]105
[8647]106        virtual void update(NodeVisitor* nv);
[8632]107
[10671]108        struct OSG_EXPORT UpdateCallback : public osg::StateAttributeCallback
[8647]109        {
110            virtual void operator () (osg::StateAttribute* attr, osg::NodeVisitor* nv);
111        };
112
[8632]113    protected:
114
115        virtual ~ImageSequence() {}
116       
[8990]117        virtual void applyLoopingMode();
118
[8642]119        void setImageToChild(const osg::Image* image);
[8660]120       
121        void computeTimePerImage();
[8642]122
[8990]123        int imageIndex(double time);
124
125
[8642]126        double                          _referenceTime;
127        double                          _timeMultiplier;
[8661]128
[8685]129        Mode                            _mode;
[8758]130        double                          _length;
[8661]131
132        double                          _timePerImage;
133
[8990]134        mutable OpenThreads::Mutex      _mutex;
[8647]135        FileNames                       _fileNames;
[8660]136
[8647]137        Images                          _images;
[8682]138       
[8990]139        typedef std::set< std::string > FilesRequested;
140        FilesRequested                  _filesRequested;
141       
142        int                             _previousAppliedImageIndex;
[8755]143               
[8682]144       
[8755]145        bool                            _seekTimeSet;
146        double                          _seekTime;
147       
[8990]148       
[8663]149
[8632]150};
151
152} // namespace
153
154#endif
Note: See TracBrowser for help on using the browser.