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

Revision 6941, 3.4 kB (checked in by robert, 7 years ago)

From Martin Lavery and Robert Osfield, Updated examples to use a variation of the MIT License

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*-
2*
3*  OpenSceneGraph example, osgphotoalbum.
4*
5*  Permission is hereby granted, free of charge, to any person obtaining a copy
6*  of this software and associated documentation files (the "Software"), to deal
7*  in the Software without restriction, including without limitation the rights
8*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9*  copies of the Software, and to permit persons to whom the Software is
10*  furnished to do so, subject to the following conditions:
11*
12*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13*  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14*  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15*  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16*  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18*  THE SOFTWARE.
19*/
20
21#ifndef IMAGEREADERWRITER_H
22#define IMAGEREADERWRITER_H
23
24#include <osgDB/ReadFile>
25#include <osgDB/WriteFile>
26#include <osgDB/ImageOptions>
27
28#include <OpenThreads/ScopedLock>
29#include <OpenThreads/ReentrantMutex>
30
31#include "PhotoArchive.h"
32
33#define SERIALIZER() OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_serializerMutex) 
34
35class ImageReaderWriter : public osgDB::ReaderWriter
36{
37    public:
38       
39        ImageReaderWriter();
40       
41        virtual const char* className() const { return "ImageReader"; }
42
43        void addPhotoArchive(PhotoArchive* archive) { _photoArchiveList.push_back(archive); }
44
45        std::string insertReference(const std::string& fileName, unsigned int res, float width, float height, bool backPage)
46        {
47            SERIALIZER();
48            return const_cast<ImageReaderWriter*>(this)->local_insertReference(fileName, res, width, height, backPage);
49        }
50
51        virtual ReadResult readNode(const std::string& fileName, const Options* options) const
52        {
53            SERIALIZER();
54            return const_cast<ImageReaderWriter*>(this)->local_readNode(fileName, options);
55        }
56
57       
58    protected:
59
60        std::string local_insertReference(const std::string& fileName, unsigned int res, float width, float height, bool backPage);
61
62        ReadResult local_readNode(const std::string& fileName, const Options*);
63
64        mutable OpenThreads::ReentrantMutex _serializerMutex;
65
66        struct DataReference
67        {
68            DataReference();
69            DataReference(const std::string& fileName, unsigned int res, float width, float height,bool backPage);
70            DataReference(const DataReference& rhs);
71
72            std::string     _fileName;
73            unsigned int    _resolutionX;
74            unsigned int    _resolutionY;
75            osg::Vec3       _center;
76            osg::Vec3       _maximumWidth;
77            osg::Vec3       _maximumHeight;
78            unsigned int    _numPointsAcross;
79            unsigned int    _numPointsUp;
80            bool            _backPage;
81        };
82       
83        osg::Image* readImage_Archive(DataReference& dr, float& s,float& t);
84       
85        osg::Image* readImage_DynamicSampling(DataReference& dr, float& s,float& t);
86
87        typedef std::map< std::string,DataReference > DataReferenceMap;
88        typedef std::vector< osg::ref_ptr<PhotoArchive> > PhotoArchiveList;
89
90        DataReferenceMap            _dataReferences;
91        PhotoArchiveList            _photoArchiveList;
92
93
94};
95
96#endif
Note: See TracBrowser for help on using the browser.