root/OpenSceneGraph/trunk/examples/osgphotoalbum/ImageReaderWriter.h @ 6267

Revision 6267, 3.0 kB (checked in by robert, 7 years ago)

Moved Block, ReentrantMutex? and ReadWriteMutex? into OpenThreads?.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This application is open source and may be redistributed and/or modified under 
4 * the terms of the GNU Public License (GPL) version 1.0 or
5 * (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 * OpenSceneGraph Public License for more details.
11*/
12
13#ifndef IMAGEREADERWRITER_H
14#define IMAGEREADERWRITER_H
15
16#include <osgDB/ReadFile>
17#include <osgDB/WriteFile>
18#include <osgDB/ImageOptions>
19
20#include <OpenThreads/ScopedLock>
21#include <OpenThreads/ReentrantMutex>
22
23#include "PhotoArchive.h"
24
25#define SERIALIZER() OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_serializerMutex) 
26
27class ImageReaderWriter : public osgDB::ReaderWriter
28{
29    public:
30       
31        ImageReaderWriter();
32       
33        virtual const char* className() const { return "ImageReader"; }
34
35        void addPhotoArchive(PhotoArchive* archive) { _photoArchiveList.push_back(archive); }
36
37        std::string insertReference(const std::string& fileName, unsigned int res, float width, float height, bool backPage)
38        {
39            SERIALIZER();
40            return const_cast<ImageReaderWriter*>(this)->local_insertReference(fileName, res, width, height, backPage);
41        }
42
43        virtual ReadResult readNode(const std::string& fileName, const Options* options) const
44        {
45            SERIALIZER();
46            return const_cast<ImageReaderWriter*>(this)->local_readNode(fileName, options);
47        }
48
49       
50    protected:
51
52        std::string local_insertReference(const std::string& fileName, unsigned int res, float width, float height, bool backPage);
53
54        ReadResult local_readNode(const std::string& fileName, const Options*);
55
56        mutable OpenThreads::ReentrantMutex _serializerMutex;
57
58        struct DataReference
59        {
60            DataReference();
61            DataReference(const std::string& fileName, unsigned int res, float width, float height,bool backPage);
62            DataReference(const DataReference& rhs);
63
64            std::string     _fileName;
65            unsigned int    _resolutionX;
66            unsigned int    _resolutionY;
67            osg::Vec3       _center;
68            osg::Vec3       _maximumWidth;
69            osg::Vec3       _maximumHeight;
70            unsigned int    _numPointsAcross;
71            unsigned int    _numPointsUp;
72            bool            _backPage;
73        };
74       
75        osg::Image* readImage_Archive(DataReference& dr, float& s,float& t);
76       
77        osg::Image* readImage_DynamicSampling(DataReference& dr, float& s,float& t);
78
79        typedef std::map< std::string,DataReference > DataReferenceMap;
80        typedef std::vector< osg::ref_ptr<PhotoArchive> > PhotoArchiveList;
81
82        DataReferenceMap            _dataReferences;
83        PhotoArchiveList            _photoArchiveList;
84
85
86};
87
88#endif
Note: See TracBrowser for help on using the browser.