ImagePager
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGDB_IMAGEPAGER
#define OSGDB_IMAGEPAGER 1
#include <osg/Image>
#include <osg/NodeVisitor>
#include <osg/observer_ptr>
#include <osg/OperationThread>
#include <osg/FrameStamp>
#include <OpenThreads/Mutex>
#include <OpenThreads/Atomic>
#include <osgDB/ReaderWriter>
#include <osgDB/Options>
namespace osgDB
{
class OSGDB_EXPORT ImagePager : public osg::NodeVisitor::ImageRequestHandler
{
public:
ImagePager();
class OSGDB_EXPORT ImageThread : public osg::Referenced, public OpenThreads::Thread
{
public:
enum Mode
{
HANDLE_ALL_REQUESTS,
HANDLE_NON_HTTP,
HANDLE_ONLY_HTTP
};
ImageThread(ImagePager* pager, Mode mode, const std::string& name);
ImageThread(const ImageThread& dt, ImagePager* pager);
void setDone(bool done) { _done = done; }
bool getDone() const { return _done; }
virtual int cancel();
virtual void run();
protected:
virtual ~ImageThread();
bool _done;
Mode _mode;
ImagePager* _pager;
std::string _name;
};
ImageThread* getImageThread(unsigned int i) { return _imageThreads[i].get(); }
const ImageThread* getImageThread(unsigned int i) const { return _imageThreads[i].get(); }
unsigned int getNumImageThreads() const { return static_cast<unsigned int>(_imageThreads.size()); }
void setPreLoadTime(double preLoadTime) { _preLoadTime=preLoadTime; }
virtual double getPreLoadTime() const { return _preLoadTime; }
virtual osg::ref_ptr<osg::Image> readRefImageFile(const std::string& fileName, const osg::Referenced* options=0);
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);
virtual bool requiresUpdateSceneGraph() const;
virtual void updateSceneGraph(const osg::FrameStamp &frameStamp);
virtual void signalBeginFrame(const osg::FrameStamp* framestamp);
virtual void signalEndFrame();
int cancel();
protected:
virtual ~ImagePager();
// forward declare
struct RequestQueue;
struct SortFileRequestFunctor;
friend struct SortFileRequestFunctor;
struct ImageRequest : public osg::Referenced
{
ImageRequest():
osg::Referenced(true),
_frameNumber(0),
_timeToMergeBy(0.0),
_attachmentIndex(-1),
_requestQueue(0) {}
unsigned int _frameNumber;
double _timeToMergeBy;
std::string _fileName;
osg::ref_ptr<Options> _loadOptions;
osg::observer_ptr<osg::Object> _attachmentPoint;
int _attachmentIndex;
osg::ref_ptr<osg::Image> _loadedImage;
RequestQueue* _requestQueue;
osg::ref_ptr<osgDB::Options> _readOptions;
};
struct RequestQueue : public osg::Referenced
{
typedef std::vector< osg::ref_ptr<ImageRequest> > RequestList;
void sort();
unsigned int size() const;
RequestList _requestList;
mutable OpenThreads::Mutex _requestMutex;
};
struct ReadQueue : public RequestQueue
{
ReadQueue(ImagePager* pager, const std::string& name);
void block() { _block->block(); }
void release() { _block->release(); }
void updateBlock()
{
_block->set((!_requestList.empty() && !_pager->_databasePagerThreadPaused));
}
void clear();
void add(ImageRequest* imageRequest);
void takeFirst(osg::ref_ptr<ImageRequest>& databaseRequest);
osg::ref_ptr<osg::RefBlock> _block;
ImagePager* _pager;
std::string _name;
};
OpenThreads::Mutex _run_mutex;
bool _startThreadCalled;
bool _done;
bool _databasePagerThreadPaused;
OpenThreads::Atomic _frameNumber;
OpenThreads::Mutex _ir_mutex;
osg::ref_ptr<ReadQueue> _readQueue;
typedef std::vector< osg::ref_ptr<ImageThread> > ImageThreads;
ImageThreads _imageThreads;
osg::ref_ptr<RequestQueue> _completedQueue;
double _preLoadTime;
};
}
#endif
Atomic
FrameStamp
Image
Mutex
NodeVisitor
OperationThread
Options
ReaderWriter
OpenThreads::Atomic
This class provides an atomic increment and decrement operation.
Definition Atomic:48
OpenThreads::Mutex
This class provides an object-oriented thread mutex interface.
Definition Mutex:31
OpenThreads::Thread
This class provides an object-oriented thread interface.
Definition Thread:48
osgDB::ImagePager::ImageThread
Definition ImagePager:39
osgDB::ImagePager::ImageThread::ImageThread
ImageThread(const ImageThread &dt, ImagePager *pager)
osgDB::ImagePager::ImageThread::run
virtual void run()
osgDB::ImagePager::ImageThread::_done
bool _done
Definition ImagePager:64
osgDB::ImagePager::ImageThread::_mode
Mode _mode
Definition ImagePager:65
osgDB::ImagePager::ImageThread::getDone
bool getDone() const
Definition ImagePager:54
osgDB::ImagePager::ImageThread::_pager
ImagePager * _pager
Definition ImagePager:66
osgDB::ImagePager::ImageThread::cancel
virtual int cancel()
osgDB::ImagePager::ImageThread::~ImageThread
virtual ~ImageThread()
osgDB::ImagePager::ImageThread::ImageThread
ImageThread(ImagePager *pager, Mode mode, const std::string &name)
osgDB::ImagePager::ImageThread::setDone
void setDone(bool done)
Definition ImagePager:53
osgDB::ImagePager::ImageThread::Mode
Mode
Definition ImagePager:43
osgDB::ImagePager::ImageThread::HANDLE_NON_HTTP
@ HANDLE_NON_HTTP
Definition ImagePager:45
osgDB::ImagePager::ImageThread::HANDLE_ALL_REQUESTS
@ HANDLE_ALL_REQUESTS
Definition ImagePager:44
osgDB::ImagePager::ImageThread::HANDLE_ONLY_HTTP
@ HANDLE_ONLY_HTTP
Definition ImagePager:46
osgDB::ImagePager::ImageThread::_name
std::string _name
Definition ImagePager:67
osgDB::ImagePager::getPreLoadTime
virtual double getPreLoadTime() const
Definition ImagePager:79
osgDB::ImagePager::getImageThread
const ImageThread * getImageThread(unsigned int i) const
Definition ImagePager:73
osgDB::ImagePager::_done
bool _done
Definition ImagePager:172
osgDB::ImagePager::setPreLoadTime
void setPreLoadTime(double preLoadTime)
Definition ImagePager:78
osgDB::ImagePager::requiresUpdateSceneGraph
virtual bool requiresUpdateSceneGraph() const
osgDB::ImagePager::~ImagePager
virtual ~ImagePager()
osgDB::ImagePager::SortFileRequestFunctor
friend struct SortFileRequestFunctor
Definition ImagePager:108
osgDB::ImagePager::signalEndFrame
virtual void signalEndFrame()
osgDB::ImagePager::_completedQueue
osg::ref_ptr< RequestQueue > _completedQueue
Definition ImagePager:183
osgDB::ImagePager::_databasePagerThreadPaused
bool _databasePagerThreadPaused
Definition ImagePager:173
osgDB::ImagePager::_preLoadTime
double _preLoadTime
Definition ImagePager:185
osgDB::ImagePager::readRefImageFile
virtual osg::ref_ptr< osg::Image > readRefImageFile(const std::string &fileName, const osg::Referenced *options=0)
osgDB::ImagePager::_startThreadCalled
bool _startThreadCalled
Definition ImagePager:170
osgDB::ImagePager::_ir_mutex
OpenThreads::Mutex _ir_mutex
Definition ImagePager:177
osgDB::ImagePager::_imageThreads
ImageThreads _imageThreads
Definition ImagePager:181
osgDB::ImagePager::getImageThread
ImageThread * getImageThread(unsigned int i)
Definition ImagePager:71
osgDB::ImagePager::cancel
int cancel()
osgDB::ImagePager::getNumImageThreads
unsigned int getNumImageThreads() const
Definition ImagePager:75
osgDB::ImagePager::ImagePager
ImagePager()
osgDB::ImagePager::signalBeginFrame
virtual void signalBeginFrame(const osg::FrameStamp *framestamp)
osgDB::ImagePager::ImageThreads
std::vector< osg::ref_ptr< ImageThread > > ImageThreads
Definition ImagePager:180
osgDB::ImagePager::updateSceneGraph
virtual void updateSceneGraph(const osg::FrameStamp &frameStamp)
osgDB::ImagePager::_frameNumber
OpenThreads::Atomic _frameNumber
Definition ImagePager:175
osgDB::ImagePager::_run_mutex
OpenThreads::Mutex _run_mutex
Definition ImagePager:169
osgDB::ImagePager::_readQueue
osg::ref_ptr< ReadQueue > _readQueue
Definition ImagePager:178
osgDB::ImagePager::requestImageFile
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)
osg::FrameStamp
Definition FrameStamp:35
osg::NodeVisitor::ImageRequestHandler
Definition NodeVisitor:388
osg::Object
Definition Object:61
osg::Referenced
Definition Referenced:44
osg::Referenced::Referenced
Referenced()
osg::observer_ptr
Definition observer_ptr:39
osg::ref_ptr
Definition ref_ptr:32
osgDB
Definition Archive:24
osg
Definition AlphaFunc:19
observer_ptr
OSGDB_EXPORT
#define OSGDB_EXPORT
Definition osgDB/Export:39
osgDB::ImagePager::ImageRequest
Definition ImagePager:111
osgDB::ImagePager::ImageRequest::_timeToMergeBy
double _timeToMergeBy
Definition ImagePager:120
osgDB::ImagePager::ImageRequest::_attachmentPoint
osg::observer_ptr< osg::Object > _attachmentPoint
Definition ImagePager:123
osgDB::ImagePager::ImageRequest::_readOptions
osg::ref_ptr< osgDB::Options > _readOptions
Definition ImagePager:127
osgDB::ImagePager::ImageRequest::_frameNumber
unsigned int _frameNumber
Definition ImagePager:119
osgDB::ImagePager::ImageRequest::_loadOptions
osg::ref_ptr< Options > _loadOptions
Definition ImagePager:122
osgDB::ImagePager::ImageRequest::_attachmentIndex
int _attachmentIndex
Definition ImagePager:124
osgDB::ImagePager::ImageRequest::_requestQueue
RequestQueue * _requestQueue
Definition ImagePager:126
osgDB::ImagePager::ImageRequest::ImageRequest
ImageRequest()
Definition ImagePager:112
osgDB::ImagePager::ImageRequest::_loadedImage
osg::ref_ptr< osg::Image > _loadedImage
Definition ImagePager:125
osgDB::ImagePager::ImageRequest::_fileName
std::string _fileName
Definition ImagePager:121
osgDB::ImagePager::ReadQueue::_pager
ImagePager * _pager
Definition ImagePager:165
osgDB::ImagePager::ReadQueue::_name
std::string _name
Definition ImagePager:166
osgDB::ImagePager::ReadQueue::add
void add(ImageRequest *imageRequest)
osgDB::ImagePager::ReadQueue::_block
osg::ref_ptr< osg::RefBlock > _block
Definition ImagePager:163
osgDB::ImagePager::ReadQueue::updateBlock
void updateBlock()
Definition ImagePager:152
osgDB::ImagePager::ReadQueue::clear
void clear()
osgDB::ImagePager::ReadQueue::ReadQueue
ReadQueue(ImagePager *pager, const std::string &name)
osgDB::ImagePager::ReadQueue::takeFirst
void takeFirst(osg::ref_ptr< ImageRequest > &databaseRequest)
osgDB::ImagePager::ReadQueue::block
void block()
Definition ImagePager:148
osgDB::ImagePager::ReadQueue::release
void release()
Definition ImagePager:150
osgDB::ImagePager::RequestQueue
Definition ImagePager:132
osgDB::ImagePager::RequestQueue::RequestList
std::vector< osg::ref_ptr< ImageRequest > > RequestList
Definition ImagePager:133
osgDB::ImagePager::RequestQueue::size
unsigned int size() const
osgDB::ImagePager::RequestQueue::_requestMutex
OpenThreads::Mutex _requestMutex
Definition ImagePager:140
osgDB::ImagePager::RequestQueue::sort
void sort()
osgDB::ImagePager::RequestQueue::_requestList
RequestList _requestList
Definition ImagePager:139