Refactored ImageSequence to better handle random access usage.

This commit is contained in:
Robert Osfield
2012-11-08 11:19:31 +00:00
parent 17b372ec38
commit 014f13f774
12 changed files with 228 additions and 191 deletions

View File

@@ -48,8 +48,18 @@ class OSG_EXPORT ImageSequence : public ImageStream
virtual void setTimeMultiplier(double tm) { _timeMultiplier = tm; }
virtual double getTimeMultiplier() const { return _timeMultiplier; }
typedef std::vector< osg::ref_ptr<osg::Image> > Images;
typedef std::vector< std::string > FileNames;
struct OSG_EXPORT ImageData
{
ImageData();
ImageData(const ImageData& id);
ImageData& operator = (const ImageData& id);
std::string _filename;
osg::ref_ptr<osg::Image> _image;
osg::ref_ptr<osg::Referenced> _imageRequest;
};
typedef std::vector<ImageData> ImageDataList;
virtual void seek(double time);
@@ -78,11 +88,6 @@ class OSG_EXPORT ImageSequence : public ImageStream
void setImageFile(unsigned int pos, const std::string& fileName);
std::string getImageFile(unsigned int pos) const;
unsigned int getNumImageFiles() const { return _fileNames.size(); }
FileNames& getFileNames() { return _fileNames; }
const FileNames& getFileNames() const { return _fileNames; }
void addImage(osg::Image* image);
void setImage(int s,int t,int r,
@@ -96,24 +101,35 @@ class OSG_EXPORT ImageSequence : public ImageStream
Image* getImage(unsigned int pos);
const Image* getImage(unsigned int pos) const;
unsigned int getNumImages() const { return _images.size(); }
unsigned int getNumImageData() const { return _imageDataList.size(); }
Images& getImages() { return _images; }
const Images& getImages() const { return _images; }
ImageDataList& getImageDataList() { return _imageDataList; }
const ImageDataList& getImageDataList() const { return _imageDataList; }
/** ImageSequence requires a call to update(NodeVisitor*) during the update traversal so return true.*/
virtual bool requiresUpdateCall() const { return true; }
/** update method for osg::Image subclasses that update themselves during the update traversal.*/
virtual void update(NodeVisitor* nv);
protected:
/** Set the optional osgDB::Options object to use when reading images.*/
void setReadOptions(osg::Referenced* options) { _readOptions = options; }
/** Get the optional osgDB::Options object used when reading images.*/
osg::Referenced* getReadOptions() { return _readOptions.get(); }
/** Get the optional osgDB::Options object used when reading images.*/
const osg::Referenced* getReadOptions() const { return _readOptions.get(); }
protected:
virtual ~ImageSequence() {}
virtual void applyLoopingMode();
void setImageToChild(const osg::Image* image);
void setImageToChild(int pos);
void computeTimePerImage();
@@ -129,12 +145,8 @@ class OSG_EXPORT ImageSequence : public ImageStream
double _timePerImage;
mutable OpenThreads::Mutex _mutex;
FileNames _fileNames;
Images _images;
typedef std::set< std::string > FilesRequested;
FilesRequested _filesRequested;
ImageDataList _imageDataList;
int _previousAppliedImageIndex;
@@ -142,7 +154,7 @@ class OSG_EXPORT ImageSequence : public ImageStream
bool _seekTimeSet;
double _seekTime;
osg::ref_ptr<osg::Referenced> _readOptions;
};

View File

@@ -308,7 +308,7 @@ class OSG_EXPORT NodeVisitor : public virtual Referenced
virtual osg::Image* readImageFile(const std::string& fileName) = 0;
virtual void requestImageFile(const std::string& fileName,osg::Object* attachmentPoint, int attachmentIndex, double timeToMergeBy, const FrameStamp* framestamp) = 0;
virtual void requestImageFile(const std::string& fileName,osg::Object* attachmentPoint, int attachmentIndex, double timeToMergeBy, const FrameStamp* framestamp, osg::ref_ptr<osg::Referenced>& imageRequest, const osg::Referenced* options=0) = 0;
protected:
virtual ~ImageRequestHandler() {}

View File

@@ -44,13 +44,13 @@ class OSG_EXPORT PagedLOD : public LOD
virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove=1);
/** Set the optional database osgDB::Options object to use when loaded children.*/
/** Set the optional database osgDB::Options object to use when reading children.*/
void setDatabaseOptions(osg::Referenced* options) { _databaseOptions = options; }
/** Get the optional database osgDB::Options object used when loaded children.*/
/** Get the optional database osgDB::Options object used when reading children.*/
osg::Referenced* getDatabaseOptions() { return _databaseOptions.get(); }
/** Get the optional database osgDB::Options object used when loaded children.*/
/** Get the optional database osgDB::Options object used when reading children.*/
const osg::Referenced* getDatabaseOptions() const { return _databaseOptions.get(); }

View File

@@ -60,10 +60,10 @@ class OSGDB_EXPORT ImagePager : public osg::NodeVisitor::ImageRequestHandler
virtual ~ImageThread();
bool _done;
Mode _mode;
ImagePager* _pager;
std::string _name;
bool _done;
Mode _mode;
ImagePager* _pager;
std::string _name;
};
@@ -79,8 +79,7 @@ class OSGDB_EXPORT ImagePager : public osg::NodeVisitor::ImageRequestHandler
virtual osg::Image* readImageFile(const std::string& fileName);
virtual void requestImageFile(const std::string& fileName,osg::Object* attachmentPoint, int attachmentIndex, double timeToMergeBy, const osg::FrameStamp* framestamp);
virtual void requestImageFile(const std::string& fileName, osg::Object* attachmentPoint, int attachmentIndex, double timeToMergeBy, const osg::FrameStamp* framestamp, osg::ref_ptr<osg::Referenced>& imageRequest, const osg::Referenced* options);
/** Return true if there are pending updates to the scene graph that require a call to updateSceneGraph(double). */
virtual bool requiresUpdateSceneGraph() const;
@@ -113,6 +112,7 @@ class OSGDB_EXPORT ImagePager : public osg::NodeVisitor::ImageRequestHandler
int _attachmentIndex;
osg::ref_ptr<osg::Image> _loadedImage;
RequestQueue* _requestQueue;
osg::ref_ptr<osgDB::Options> _readOptions;
};