From d9b9a6f1f83437f25887b31113527c24e7513f5e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 23 Nov 2004 15:29:52 +0000 Subject: [PATCH] Made read/write methods in ReaderWriter all const to facilate multi-threading --- examples/osgphotoalbum/ImageReaderWriter.cpp | 4 +- examples/osgphotoalbum/ImageReaderWriter.h | 23 +- include/osgDB/Archive | 16 +- include/osgDB/ReaderWriter | 48 +-- src/osgDB/Registry.cpp | 10 +- src/osgPlugins/3dc/ReaderWriter3DC.cpp | 4 +- src/osgPlugins/Inventor/ReaderWriterIV.cpp | 2 +- src/osgPlugins/Inventor/ReaderWriterIV.h | 4 +- src/osgPlugins/ac3d/ac3d.cpp | 8 +- src/osgPlugins/bmp/ReaderWriterBMP.cpp | 6 +- src/osgPlugins/dds/ReaderWriterDDS.cpp | 18 +- .../directx/ReaderWriterDirectX.cpp | 15 +- src/osgPlugins/dw/ReaderWriterDW.cpp | 4 +- src/osgPlugins/dx/ReaderWriterDX.cpp | 10 +- src/osgPlugins/dx/ReaderWriterDX.h | 10 +- src/osgPlugins/flt/ReaderWriterATTR.cpp | 4 +- src/osgPlugins/flt/ReaderWriterFLT.cpp | 4 +- src/osgPlugins/flt/ReaderWriterFLT.h | 6 +- .../freetype/ReaderWriterFreeType.cpp | 4 +- src/osgPlugins/gdal/ReaderWriterGDAL.cpp | 25 +- src/osgPlugins/geo/ReaderWriterGEO.cpp | 57 ++- src/osgPlugins/gif/ReaderWriterGIF.cpp | 4 +- src/osgPlugins/ive/ReaderWriterIVE.cpp | 18 +- src/osgPlugins/jp2/ReaderWriterJP2.cpp | 18 +- src/osgPlugins/jpeg/ReaderWriterJPEG.cpp | 10 +- src/osgPlugins/lib3ds/ReaderWriter3DS.cpp | 6 +- src/osgPlugins/logo/ReaderWriterLOGO.cpp | 4 +- src/osgPlugins/lwo/ReaderWriterLWO.cpp | 16 +- src/osgPlugins/lws/ReaderWriterLWS.cpp | 4 +- src/osgPlugins/md2/ReaderWriterMD2.cpp | 8 +- src/osgPlugins/mpeg/ReaderWriterMPEG.cpp | 4 +- src/osgPlugins/net/ReaderWriterNET.cpp | 16 +- src/osgPlugins/obj/ReaderWriterOBJ.cpp | 26 +- src/osgPlugins/osg/ReaderWriterOSG.cpp | 20 +- src/osgPlugins/osga/OSGA_Archive.cpp | 34 +- src/osgPlugins/osga/OSGA_Archive.h | 18 +- src/osgPlugins/osga/ReaderWriterOSGA.cpp | 10 +- src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp | 4 +- src/osgPlugins/pfb/ReaderWriterPFB.cpp | 6 +- src/osgPlugins/pic/ReaderWriterPIC.cpp | 4 +- src/osgPlugins/png/ReaderWriterPNG.cpp | 4 +- src/osgPlugins/png/new_ReaderWriterPNG.cpp | 330 --------------- src/osgPlugins/png/prev_ReaderWriterPNG.cpp | 170 -------- src/osgPlugins/pnm/ReaderWriterPNM.cpp | 398 +++++++++--------- src/osgPlugins/quicktime/ReaderWriterQT.cpp | 6 +- src/osgPlugins/rgb/ReaderWriterRGB.cpp | 6 +- src/osgPlugins/rot/ReaderWriterROT.cpp | 7 +- src/osgPlugins/scale/ReaderWriterSCALE.cpp | 7 +- src/osgPlugins/stl/ReaderWriterSTL.cpp | 56 +-- src/osgPlugins/tga/ReaderWriterTGA.cpp | 4 +- src/osgPlugins/tgz/ReaderWriterTGZ.cpp | 4 +- src/osgPlugins/tiff/ReaderWriterTIFF.cpp | 4 +- src/osgPlugins/trans/ReaderWriterTRANS.cpp | 7 +- src/osgPlugins/txp/ReaderWriterTXP.cpp | 4 +- src/osgPlugins/txp/ReaderWriterTXP.h | 28 +- src/osgPlugins/zip/ReaderWriterZIP.cpp | 4 +- src/osgText/Font.cpp | 2 +- 57 files changed, 556 insertions(+), 997 deletions(-) delete mode 100644 src/osgPlugins/png/new_ReaderWriterPNG.cpp delete mode 100644 src/osgPlugins/png/prev_ReaderWriterPNG.cpp diff --git a/examples/osgphotoalbum/ImageReaderWriter.cpp b/examples/osgphotoalbum/ImageReaderWriter.cpp index f99e102ec..138d3fb1c 100644 --- a/examples/osgphotoalbum/ImageReaderWriter.cpp +++ b/examples/osgphotoalbum/ImageReaderWriter.cpp @@ -58,7 +58,7 @@ ImageReaderWriter::ImageReaderWriter() { } -std::string ImageReaderWriter::insertReference(const std::string& fileName, unsigned int res, float width, float height, bool backPage) +std::string ImageReaderWriter::local_insertReference(const std::string& fileName, unsigned int res, float width, float height, bool backPage) { std::stringstream ostr; ostr<<"res_"< #include +#include +#include + #include "PhotoArchive.h" +#define SERIALIZER() OpenThreads::ScopedLock lock(_serializerMutex) + class ImageReaderWriter : public osgDB::ReaderWriter { public: @@ -29,12 +34,26 @@ class ImageReaderWriter : public osgDB::ReaderWriter void addPhotoArchive(PhotoArchive* archive) { _photoArchiveList.push_back(archive); } - std::string insertReference(const std::string& fileName, unsigned int res, float width, float height, bool backPage); + std::string insertReference(const std::string& fileName, unsigned int res, float width, float height, bool backPage) + { + SERIALIZER(); + return insertReference(fileName, res, width, height, backPage); + } + + virtual ReadResult readNode(const std::string& fileName, const Options* options) const + { + SERIALIZER(); + return readNode(fileName, options); + } - virtual ReadResult readNode(const std::string& fileName, const Options*); protected: + std::string local_insertReference(const std::string& fileName, unsigned int res, float width, float height, bool backPage); + + ReadResult local_readNode(const std::string& fileName, const Options*); + + mutable osgDB::ReentrantMutex _serializerMutex; struct DataReference { diff --git a/include/osgDB/Archive b/include/osgDB/Archive index 859e514e6..41a23fe61 100644 --- a/include/osgDB/Archive +++ b/include/osgDB/Archive @@ -50,15 +50,15 @@ class OSGDB_EXPORT Archive : public ReaderWriter /** Get the full list of file names available in the archive.*/ virtual bool getFileNames(FileNameList& fileNameList) const = 0; - virtual ReadResult readObject(const std::string& /*fileName*/,const Options* =NULL) = 0; - virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) = 0; - virtual ReadResult readHeightField(const std::string& /*fileName*/,const Options* =NULL) = 0; - virtual ReadResult readNode(const std::string& /*fileName*/,const Options* =NULL) = 0; + virtual ReadResult readObject(const std::string& /*fileName*/,const Options* =NULL) const = 0; + virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) const = 0; + virtual ReadResult readHeightField(const std::string& /*fileName*/,const Options* =NULL) const = 0; + virtual ReadResult readNode(const std::string& /*fileName*/,const Options* =NULL) const = 0; - virtual WriteResult writeObject(const osg::Object& /*obj*/,const std::string& /*fileName*/,const Options* =NULL) = 0; - virtual WriteResult writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const Options* =NULL) = 0; - virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,const std::string& /*fileName*/,const Options* =NULL) = 0; - virtual WriteResult writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options* =NULL) = 0; + virtual WriteResult writeObject(const osg::Object& /*obj*/,const std::string& /*fileName*/,const Options* =NULL) const = 0; + virtual WriteResult writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const Options* =NULL) const = 0; + virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,const std::string& /*fileName*/,const Options* =NULL) const = 0; + virtual WriteResult writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options* =NULL) const = 0; diff --git a/include/osgDB/ReaderWriter b/include/osgDB/ReaderWriter index 0789e9586..1d250bf6f 100644 --- a/include/osgDB/ReaderWriter +++ b/include/osgDB/ReaderWriter @@ -43,7 +43,7 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object META_Object(osgDB,ReaderWriter); - virtual bool acceptsExtension(const std::string& /*extension*/) { return false; } + virtual bool acceptsExtension(const std::string& /*extension*/) const { return false; } /** Options base class used for passing options into plugins to control their operation.*/ class Options : public osg::Object @@ -80,14 +80,14 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object }; - Options():_useObjectCacheHint(CACHE_ARCHIVES) {} + Options():_objectCacheHint(CACHE_ARCHIVES) {} Options(const std::string& str):_str(str) {} Options(const Options& options,const osg::CopyOp copyop=osg::CopyOp::SHALLOW_COPY): Object(options,copyop), _str(options._str), _databasePaths(options._databasePaths), - _useObjectCacheHint(options._useObjectCacheHint) {} + _objectCacheHint(options._objectCacheHint) {} META_Object(osgDB,Options); @@ -107,10 +107,10 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object const FilePathList& getDatabasePathList() const { return _databasePaths; } /** Set whether the Registry::ObjectCache should be used by default.*/ - void setUseObjectCacheHint(CacheHintOptions useObjectCache) { _useObjectCacheHint = useObjectCache; } + void setObjectCacheHint(CacheHintOptions useObjectCache) { _objectCacheHint = useObjectCache; } /** Get whether the Registry::ObjectCache should be used by default.*/ - CacheHintOptions getUseObjectCacheHint() const { return _useObjectCacheHint; } + CacheHintOptions getObjectCacheHint() const { return _objectCacheHint; } protected: @@ -119,7 +119,7 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object std::string _str; FilePathList _databasePaths; - CacheHintOptions _useObjectCacheHint; + CacheHintOptions _objectCacheHint; }; @@ -216,30 +216,30 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object }; /** open an archive for reading, writing or or to create an empty archive for writing to.*/ - virtual ReadResult openArchive(const std::string& /*fileName*/,ArchiveStatus, unsigned int =4096, const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } + virtual ReadResult openArchive(const std::string& /*fileName*/,ArchiveStatus, unsigned int =4096, const Options* =NULL) const { return ReadResult(ReadResult::FILE_NOT_HANDLED); } /** open an archive for reading.*/ - virtual ReadResult openArchive(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } + virtual ReadResult openArchive(std::istream& /*fin*/,const Options* =NULL) const { return ReadResult(ReadResult::FILE_NOT_HANDLED); } - virtual ReadResult readObject(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } - virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } - virtual ReadResult readHeightField(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } - virtual ReadResult readNode(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } + virtual ReadResult readObject(const std::string& /*fileName*/,const Options* =NULL) const { return ReadResult(ReadResult::FILE_NOT_HANDLED); } + virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) const { return ReadResult(ReadResult::FILE_NOT_HANDLED); } + virtual ReadResult readHeightField(const std::string& /*fileName*/,const Options* =NULL) const { return ReadResult(ReadResult::FILE_NOT_HANDLED); } + virtual ReadResult readNode(const std::string& /*fileName*/,const Options* =NULL) const { return ReadResult(ReadResult::FILE_NOT_HANDLED); } - virtual WriteResult writeObject(const osg::Object& /*obj*/,const std::string& /*fileName*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); } - virtual WriteResult writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); } - virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,const std::string& /*fileName*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); } - virtual WriteResult writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options* =NULL) { return WriteResult(WriteResult::FILE_NOT_HANDLED); } + virtual WriteResult writeObject(const osg::Object& /*obj*/,const std::string& /*fileName*/,const Options* =NULL) const {return WriteResult(WriteResult::FILE_NOT_HANDLED); } + virtual WriteResult writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const Options* =NULL) const {return WriteResult(WriteResult::FILE_NOT_HANDLED); } + virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,const std::string& /*fileName*/,const Options* =NULL) const {return WriteResult(WriteResult::FILE_NOT_HANDLED); } + virtual WriteResult writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options* =NULL) const { return WriteResult(WriteResult::FILE_NOT_HANDLED); } - virtual ReadResult readObject(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } - virtual ReadResult readImage(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } - virtual ReadResult readHeightField(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } - virtual ReadResult readNode(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } + virtual ReadResult readObject(std::istream& /*fin*/,const Options* =NULL) const { return ReadResult(ReadResult::FILE_NOT_HANDLED); } + virtual ReadResult readImage(std::istream& /*fin*/,const Options* =NULL) const { return ReadResult(ReadResult::FILE_NOT_HANDLED); } + virtual ReadResult readHeightField(std::istream& /*fin*/,const Options* =NULL) const { return ReadResult(ReadResult::FILE_NOT_HANDLED); } + virtual ReadResult readNode(std::istream& /*fin*/,const Options* =NULL) const { return ReadResult(ReadResult::FILE_NOT_HANDLED); } - virtual WriteResult writeObject(const osg::Object& /*obj*/,std::ostream& /*fout*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); } - virtual WriteResult writeImage(const osg::Image& /*image*/,std::ostream& /*fout*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); } - virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,std::ostream& /*fout*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); } - virtual WriteResult writeNode(const osg::Node& /*node*/,std::ostream& /*fout*/,const Options* =NULL) { return WriteResult(WriteResult::FILE_NOT_HANDLED); } + virtual WriteResult writeObject(const osg::Object& /*obj*/,std::ostream& /*fout*/,const Options* =NULL) const { return WriteResult(WriteResult::FILE_NOT_HANDLED); } + virtual WriteResult writeImage(const osg::Image& /*image*/,std::ostream& /*fout*/,const Options* =NULL) const { return WriteResult(WriteResult::FILE_NOT_HANDLED); } + virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,std::ostream& /*fout*/,const Options* =NULL) const { return WriteResult(WriteResult::FILE_NOT_HANDLED); } + virtual WriteResult writeNode(const osg::Node& /*node*/,std::ostream& /*fout*/,const Options* =NULL) const { return WriteResult(WriteResult::FILE_NOT_HANDLED); } }; diff --git a/src/osgDB/Registry.cpp b/src/osgDB/Registry.cpp index efea88e92..8cf09c7c5 100644 --- a/src/osgDB/Registry.cpp +++ b/src/osgDB/Registry.cpp @@ -1352,7 +1352,7 @@ ReaderWriter::ReadResult Registry::readImplementation(const ReadFunctor& readFun ReaderWriter::ReadResult Registry::openArchiveImplementation(const std::string& fileName, ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const ReaderWriter::Options* options) { - if (options && (options->getUseObjectCacheHint() & ReaderWriter::Options::CACHE_ARCHIVES)) + if (options && (options->getObjectCacheHint() & ReaderWriter::Options::CACHE_ARCHIVES)) { osgDB::Archive* archive = getFromArchiveCache(fileName); if (archive) return archive; @@ -1374,7 +1374,7 @@ ReaderWriter::ReadResult Registry::openArchiveImplementation(const std::string& ReaderWriter::ReadResult Registry::readObjectImplementation(const std::string& fileName,const ReaderWriter::Options* options) { return readImplementation(ReadObjectFunctor(fileName, options), - options ? (options->getUseObjectCacheHint()&ReaderWriter::Options::CACHE_OBJECTS): false); + options ? (options->getObjectCacheHint()&ReaderWriter::Options::CACHE_OBJECTS): false); } ReaderWriter::WriteResult Registry::writeObjectImplementation(const Object& obj,const std::string& fileName) @@ -1417,7 +1417,7 @@ ReaderWriter::WriteResult Registry::writeObjectImplementation(const Object& obj, ReaderWriter::ReadResult Registry::readImageImplementation(const std::string& fileName,const ReaderWriter::Options* options) { return readImplementation(ReadImageFunctor(fileName, options), - options ? (options->getUseObjectCacheHint()&ReaderWriter::Options::CACHE_IMAGES): false); + options ? (options->getObjectCacheHint()&ReaderWriter::Options::CACHE_IMAGES): false); } ReaderWriter::WriteResult Registry::writeImageImplementation(const Image& image,const std::string& fileName) @@ -1459,7 +1459,7 @@ ReaderWriter::WriteResult Registry::writeImageImplementation(const Image& image, ReaderWriter::ReadResult Registry::readHeightFieldImplementation(const std::string& fileName,const ReaderWriter::Options* options) { return readImplementation(ReadHeightFieldFunctor(fileName, options), - options ? (options->getUseObjectCacheHint()&ReaderWriter::Options::CACHE_HEIGHTFIELDS): false); + options ? (options->getObjectCacheHint()&ReaderWriter::Options::CACHE_HEIGHTFIELDS): false); } ReaderWriter::WriteResult Registry::writeHeightFieldImplementation(const HeightField& HeightField,const std::string& fileName) @@ -1501,7 +1501,7 @@ ReaderWriter::WriteResult Registry::writeHeightFieldImplementation(const HeightF ReaderWriter::ReadResult Registry::readNodeImplementation(const std::string& fileName,const ReaderWriter::Options* options) { return readImplementation(ReadNodeFunctor(fileName, options), - options ? (options->getUseObjectCacheHint()&ReaderWriter::Options::CACHE_NODES): false); + options ? (options->getObjectCacheHint()&ReaderWriter::Options::CACHE_NODES): false); } ReaderWriter::WriteResult Registry::writeNodeImplementation(const Node& node,const std::string& fileName) diff --git a/src/osgPlugins/3dc/ReaderWriter3DC.cpp b/src/osgPlugins/3dc/ReaderWriter3DC.cpp index 1886f3e70..c299d5413 100644 --- a/src/osgPlugins/3dc/ReaderWriter3DC.cpp +++ b/src/osgPlugins/3dc/ReaderWriter3DC.cpp @@ -17,13 +17,13 @@ class ReaderWriter3DC : public osgDB::ReaderWriter public: virtual const char* className() const { return "3DC point cloud reader"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"3dc") || osgDB::equalCaseInsensitive(extension,"asc"); } - virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/Inventor/ReaderWriterIV.cpp b/src/osgPlugins/Inventor/ReaderWriterIV.cpp index 4e0fd8f6b..a9431f7aa 100644 --- a/src/osgPlugins/Inventor/ReaderWriterIV.cpp +++ b/src/osgPlugins/Inventor/ReaderWriterIV.cpp @@ -22,7 +22,7 @@ ReaderWriterIV::ReaderWriterIV() // Read file and convert to OSG osgDB::ReaderWriter::ReadResult ReaderWriterIV::readNode(const std::string& file, - const osgDB::ReaderWriter::Options* options) + const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/Inventor/ReaderWriterIV.h b/src/osgPlugins/Inventor/ReaderWriterIV.h index bb708441a..932fdcf7c 100644 --- a/src/osgPlugins/Inventor/ReaderWriterIV.h +++ b/src/osgPlugins/Inventor/ReaderWriterIV.h @@ -14,14 +14,14 @@ class ReaderWriterIV : public osgDB::ReaderWriter return "Inventor Reader"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension, "iv") ? true : osgDB::equalCaseInsensitive(extension, "wrl") ? true : false; } virtual ReadResult readNode(const std::string& filename, - const osgDB::ReaderWriter::Options *); + const osgDB::ReaderWriter::Options *) const; }; diff --git a/src/osgPlugins/ac3d/ac3d.cpp b/src/osgPlugins/ac3d/ac3d.cpp index 19d08a188..6b1497d06 100644 --- a/src/osgPlugins/ac3d/ac3d.cpp +++ b/src/osgPlugins/ac3d/ac3d.cpp @@ -72,11 +72,11 @@ class ReaderWriterAC : public osgDB::ReaderWriter public: virtual const char* className() const { return "AC3D Database Reader"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"ac"); } - virtual ReadResult readNode(const std::string& file,const osgDB::ReaderWriter::Options* options) + virtual ReadResult readNode(const std::string& file,const osgDB::ReaderWriter::Options* options) const { osg::Group *grp; // holder for all loaded objects // GWM added Dec 2003 - get full path name (change in osgDB handling of files). @@ -92,7 +92,7 @@ class ReaderWriterAC : public osgDB::ReaderWriter grp=ac_load_ac3d(fileName.c_str(), local_opt.get()); return grp; }; - virtual WriteResult writeNode(const Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options* /*options*/) + virtual WriteResult writeNode(const Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options* /*options*/) const { std::string ext = getFileExtension(fileName); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; @@ -121,7 +121,7 @@ class ReaderWriterAC : public osgDB::ReaderWriter return WriteResult::FILE_SAVED; } - virtual WriteResult writeNode(const Node& node,std::ostream& fout, const osgDB::ReaderWriter::Options* opts) + virtual WriteResult writeNode(const Node& node,std::ostream& fout, const osgDB::ReaderWriter::Options* opts) const { try { diff --git a/src/osgPlugins/bmp/ReaderWriterBMP.cpp b/src/osgPlugins/bmp/ReaderWriterBMP.cpp index 7fe07f34f..888fc17c1 100644 --- a/src/osgPlugins/bmp/ReaderWriterBMP.cpp +++ b/src/osgPlugins/bmp/ReaderWriterBMP.cpp @@ -317,9 +317,9 @@ class ReaderWriterBMP : public osgDB::ReaderWriter { public: virtual const char* className() const { return "BMP Image Reader"; } - virtual bool acceptsExtension(const std::string& extension) { return osgDB::equalCaseInsensitive(extension,"bmp"); } + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"bmp"); } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; @@ -362,7 +362,7 @@ class ReaderWriterBMP : public osgDB::ReaderWriter return pOsgImage; } - virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options*) const { std::string ext = osgDB::getFileExtension(fileName); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/dds/ReaderWriterDDS.cpp b/src/osgPlugins/dds/ReaderWriterDDS.cpp index a780d8be2..b21a798e2 100644 --- a/src/osgPlugins/dds/ReaderWriterDDS.cpp +++ b/src/osgPlugins/dds/ReaderWriterDDS.cpp @@ -701,22 +701,22 @@ public: return "DDS Image Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"dds"); } - virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const { return readImage(file,options); } - virtual ReadResult readObject(std::istream& fin, const Options* options) + virtual ReadResult readObject(std::istream& fin, const Options* options) const { return readImage(fin,options); } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; @@ -731,7 +731,7 @@ public: return rr; } - virtual ReadResult readImage(std::istream& fin, const Options* options) + virtual ReadResult readImage(std::istream& fin, const Options* options) const { osg::Image* osgImage = ReadDDSFile(fin); if (osgImage==NULL) return ReadResult::FILE_NOT_HANDLED; @@ -744,7 +744,7 @@ public: return osgImage; } - virtual WriteResult writeObject(const osg::Object& object,const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual WriteResult writeObject(const osg::Object& object,const std::string& file, const osgDB::ReaderWriter::Options* options) const { const osg::Image* image = dynamic_cast(&object); if (!image) return WriteResult::FILE_NOT_HANDLED; @@ -752,7 +752,7 @@ public: return writeImage(*image,file,options); } - virtual WriteResult writeObject(const osg::Object& object,std::ostream& fout,const Options* options) + virtual WriteResult writeObject(const osg::Object& object,std::ostream& fout,const Options* options) const { const osg::Image* image = dynamic_cast(&object); if (!image) return WriteResult::FILE_NOT_HANDLED; @@ -761,7 +761,7 @@ public: } - virtual WriteResult writeImage(const osg::Image &image,const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual WriteResult writeImage(const osg::Image &image,const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getFileExtension(file); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; @@ -772,7 +772,7 @@ public: return writeImage(image,fout,options); } - virtual WriteResult writeImage(const osg::Image& image,std::ostream& fout,const Options*) + virtual WriteResult writeImage(const osg::Image& image,std::ostream& fout,const Options*) const { bool success = WriteDDSFile(&image, fout); diff --git a/src/osgPlugins/directx/ReaderWriterDirectX.cpp b/src/osgPlugins/directx/ReaderWriterDirectX.cpp index 64a574201..0a0524d33 100644 --- a/src/osgPlugins/directx/ReaderWriterDirectX.cpp +++ b/src/osgPlugins/directx/ReaderWriterDirectX.cpp @@ -54,16 +54,16 @@ public: return "DirectX Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) { - return osgDB::equalCaseInsensitive(extension,"x") ? true : false; + virtual bool acceptsExtension(const std::string& extension) const + { + return osgDB::equalCaseInsensitive(extension,"x"); } - virtual ReadResult readNode(const std::string& fileName, - const osgDB::ReaderWriter::Options* options); + virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const; private: osg::Geode* convertFromDX(DX::Object& obj, bool flipTexture, float creaseAngle, - const osgDB::ReaderWriter::Options* options); + const osgDB::ReaderWriter::Options* options) const; }; // Register with Registry to instantiate the above reader/writer. @@ -71,8 +71,7 @@ osgDB::RegisterReaderWriterProxy g_readerWriter_DirectX_Pro // Read node -osgDB::ReaderWriter::ReadResult ReaderWriterDirectX::readNode(const std::string& file, - const osgDB::ReaderWriter::Options* options) +osgDB::ReaderWriter::ReadResult ReaderWriterDirectX::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; @@ -118,7 +117,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterDirectX::readNode(const std::string& // Convert DirectX mesh to osg::Geode osg::Geode* ReaderWriterDirectX::convertFromDX(DX::Object& obj, bool flipTexture, float creaseAngle, - const osgDB::ReaderWriter::Options* options) + const osgDB::ReaderWriter::Options* options) const { // Fetch mesh const DX::Mesh* mesh = obj.getMesh(); diff --git a/src/osgPlugins/dw/ReaderWriterDW.cpp b/src/osgPlugins/dw/ReaderWriterDW.cpp index a663c76a8..d4cb54e61 100644 --- a/src/osgPlugins/dw/ReaderWriterDW.cpp +++ b/src/osgPlugins/dw/ReaderWriterDW.cpp @@ -794,12 +794,12 @@ class ReaderWriterDW : public osgDB::ReaderWriter public: virtual const char* className() const { return "Design Workshop Database Reader"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"dw"); } - virtual ReadResult readNode(const std::string& file,const osgDB::ReaderWriter::Options* options) + virtual ReadResult readNode(const std::string& file,const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); diff --git a/src/osgPlugins/dx/ReaderWriterDX.cpp b/src/osgPlugins/dx/ReaderWriterDX.cpp index 87b7709c0..8a669fb35 100644 --- a/src/osgPlugins/dx/ReaderWriterDX.cpp +++ b/src/osgPlugins/dx/ReaderWriterDX.cpp @@ -24,10 +24,7 @@ #include "DXWriter.h" // FIXME: Support options -osgDB::ReaderWriter::WriteResult ReaderWriterDX::writeObject( - const osg::Object &obj, - const std::string &filename, - const Options *options ) +osgDB::ReaderWriter::WriteResult ReaderWriterDX::writeObject(const osg::Object &obj, const std::string &filename, const Options *options ) const { const osg::Node *node = dynamic_cast(&obj); @@ -39,10 +36,7 @@ osgDB::ReaderWriter::WriteResult ReaderWriterDX::writeObject( } -osgDB::ReaderWriter::WriteResult ReaderWriterDX::writeNode( - const osg::Node &node, - const std::string &filename, - const Options *) +osgDB::ReaderWriter::WriteResult ReaderWriterDX::writeNode(const osg::Node &node, const std::string &filename, const Options *) const { dx::WriterParms parms; std::string messages; diff --git a/src/osgPlugins/dx/ReaderWriterDX.h b/src/osgPlugins/dx/ReaderWriterDX.h index bb8921c44..ec4619aa1 100644 --- a/src/osgPlugins/dx/ReaderWriterDX.h +++ b/src/osgPlugins/dx/ReaderWriterDX.h @@ -31,16 +31,12 @@ class ReaderWriterDX : public osgDB::ReaderWriter public: virtual const char* className() { return "OpenDX Writer"; } - virtual bool acceptsExtension( const std::string &extension ) + virtual bool acceptsExtension( const std::string &extension ) const { return osgDB::equalCaseInsensitive( extension, "dx" ); } - virtual WriteResult writeObject( const osg::Object &obj, - const std::string &filename, - const Options *options = NULL ); + virtual WriteResult writeObject( const osg::Object &obj, const std::string &filename, const Options *options = NULL ) const; - virtual WriteResult writeNode ( const osg::Node &node, - const std::string &filename, - const Options *options = NULL ); + virtual WriteResult writeNode ( const osg::Node&node, const std::string &filename, const Options *options = NULL ) const; }; diff --git a/src/osgPlugins/flt/ReaderWriterATTR.cpp b/src/osgPlugins/flt/ReaderWriterATTR.cpp index f0c81a6e4..6a017e3c1 100644 --- a/src/osgPlugins/flt/ReaderWriterATTR.cpp +++ b/src/osgPlugins/flt/ReaderWriterATTR.cpp @@ -744,12 +744,12 @@ class ReaderWriterATTR : public osgDB::ReaderWriter public: virtual const char* className() const { return "ATTR Image Attribute Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"attr"); } - virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/flt/ReaderWriterFLT.cpp b/src/osgPlugins/flt/ReaderWriterFLT.cpp index e2e144122..02f4e0b07 100644 --- a/src/osgPlugins/flt/ReaderWriterFLT.cpp +++ b/src/osgPlugins/flt/ReaderWriterFLT.cpp @@ -17,13 +17,13 @@ using namespace flt; -osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* opt) +osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* opt) const { return readNode(fileName,opt); } -osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) +osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/flt/ReaderWriterFLT.h b/src/osgPlugins/flt/ReaderWriterFLT.h index 908222526..01f3cde57 100644 --- a/src/osgPlugins/flt/ReaderWriterFLT.h +++ b/src/osgPlugins/flt/ReaderWriterFLT.h @@ -49,13 +49,13 @@ class ReaderWriterFLT : public osgDB::ReaderWriter public: virtual const char* className() const { return "FLT Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"flt"); } - virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options*); - virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*); + virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options*) const; + virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) const; }; diff --git a/src/osgPlugins/freetype/ReaderWriterFreeType.cpp b/src/osgPlugins/freetype/ReaderWriterFreeType.cpp index 2566cae42..d65fc618e 100644 --- a/src/osgPlugins/freetype/ReaderWriterFreeType.cpp +++ b/src/osgPlugins/freetype/ReaderWriterFreeType.cpp @@ -9,7 +9,7 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter public: virtual const char* className() const { return "FreeType Font Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"ttf") || // true type osgDB::equalCaseInsensitive(extension,"ttc") || // true type @@ -22,7 +22,7 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter osgDB::equalCaseInsensitive(extension,"fnt"); // Windows bitmap fonts } - virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/gdal/ReaderWriterGDAL.cpp b/src/osgPlugins/gdal/ReaderWriterGDAL.cpp index 78f92954f..a047319d4 100644 --- a/src/osgPlugins/gdal/ReaderWriterGDAL.cpp +++ b/src/osgPlugins/gdal/ReaderWriterGDAL.cpp @@ -8,18 +8,35 @@ #include #include +#include +#include + #include +#define SERIALIZER() OpenThreads::ScopedLock lock(_serializerMutex) + class ReaderWriterGDAL : public osgDB::ReaderWriter { public: virtual const char* className() const { return "GDAL Image Reader"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"gdal") || osgDB::equalCaseInsensitive(extension,"gdal"); } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const + { + OpenThreads::ScopedLock lock(_serializerMutex); + return const_cast(this)->local_readImage(fileName, options); + } + + virtual ReadResult readHeightField(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const + { + OpenThreads::ScopedLock lock(_serializerMutex); + return const_cast(this)->local_readHeightField(fileName, options); + } + + virtual ReadResult local_readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) { // Looks like gdal's GDALRasterBand::GetColorInterpretation() // is not giving proper values for ecw images. There is small @@ -377,7 +394,8 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter } - virtual ReadResult readHeightField(const std::string& fileName, const osgDB::ReaderWriter::Options* options) + + ReadResult local_readHeightField(const std::string& fileName, const osgDB::ReaderWriter::Options* options) { //std::string ext = osgDB::getFileExtension(fileName); //if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; @@ -596,6 +614,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter } } + mutable osgDB::ReentrantMutex _serializerMutex; }; diff --git a/src/osgPlugins/geo/ReaderWriterGEO.cpp b/src/osgPlugins/geo/ReaderWriterGEO.cpp index abe98079f..976233c9f 100644 --- a/src/osgPlugins/geo/ReaderWriterGEO.cpp +++ b/src/osgPlugins/geo/ReaderWriterGEO.cpp @@ -388,31 +388,20 @@ private: }; -class ReaderWriterGEO : public osgDB::ReaderWriter +class ReaderGEO { public: - virtual const char* className() const { return "GEO Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) + osgDB::ReaderWriter::ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) { - return osgDB::equalCaseInsensitive(extension,"gem") || osgDB::equalCaseInsensitive(extension,"geo"); - } - - virtual ReadResult readObject(const std::string& fileName, const Options* opt) { return readNode(fileName,opt); } - - virtual ReadResult readNode(const std::string& file, const Options* options) - { - std::string ext = osgDB::getLowerCaseFileExtension(file); - if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - - std::string fileName = osgDB::findDataFile( file, options ); - if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; std::ifstream fin(fileName.c_str(), std::ios::binary | std::ios::in ); if (fin.is_open() ) { // read the input file. // code for setting up the database path so that internally referenced file are searched for on relative paths. - osg::ref_ptr local_opt = options ? static_cast(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; + osg::ref_ptr local_opt = options ? + static_cast(options->clone(osg::CopyOp::SHALLOW_COPY)) : + new osgDB::ReaderWriter::Options; local_opt->setDatabasePath(osgDB::getFilePath(fileName)); typedef std::vector NodeList; @@ -457,7 +446,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter osg::Node * groupnode = NULL; if (nodeList.empty()) { - return ReadResult("No data loaded from "+fileName); + return osgDB::ReaderWriter::ReadResult("No data loaded from "+fileName); } else if (nodeList.size()==1) { @@ -1396,7 +1385,8 @@ class ReaderWriterGEO : public osgDB::ReaderWriter } return clp; } - geoHeader *makeHeader(const georecord *gr, const Options* options) { + + geoHeader *makeHeader(const georecord *gr, const osgDB::ReaderWriter::Options* options) { if (!theHeader.valid()) theHeader=new geoHeaderGeo(); // the header contains variables as well as a transform for the XYZup cases const geoField *gfd; @@ -1459,7 +1449,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter } return theHeader.get(); } - void makeTexture(const georecord *gr, const Options* options) { + void makeTexture(const georecord *gr, const osgDB::ReaderWriter::Options* options) { // scans the fields of this record and puts a new texture & environment into 'pool' stor const geoField *gfd=gr->getField(GEO_DB_TEX_FILE_NAME); const char *name = gfd->getChar(); @@ -1697,7 +1687,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter } return mtr; } - std::vector makeosg(const std::vector gr, const Options* options) { + std::vector makeosg(const std::vector gr, const osgDB::ReaderWriter::Options* options) { // recursive traversal of records and extract osg::Nodes equivalent Group *geodeholder=NULL; std::vector nodelist; @@ -2201,6 +2191,33 @@ void geoField::readfile(std::ifstream &fin, const uint id) { // is part of a rec } +class ReaderWriterGEO : public osgDB::ReaderWriter +{ + public: + virtual const char* className() const { return "GEO Reader/Writer"; } + + virtual bool acceptsExtension(const std::string& extension) const + { + return osgDB::equalCaseInsensitive(extension,"gem") || osgDB::equalCaseInsensitive(extension,"geo"); + } + + virtual ReadResult readObject(const std::string& fileName, const Options* opt) const { return readNode(fileName,opt); } + + virtual ReadResult readNode(const std::string& file, const Options* options) const + { + std::string ext = osgDB::getLowerCaseFileExtension(file); + if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + + std::string fileName = osgDB::findDataFile( file, options ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + + ReaderGEO reader; + return reader.readNode(fileName,options); + } + +}; + + // now register with Registry to instantiate the above // reader/writer. osgDB::RegisterReaderWriterProxy gReaderWriter_GEO_Proxy; diff --git a/src/osgPlugins/gif/ReaderWriterGIF.cpp b/src/osgPlugins/gif/ReaderWriterGIF.cpp index 75d7de3c3..d8ff75694 100644 --- a/src/osgPlugins/gif/ReaderWriterGIF.cpp +++ b/src/osgPlugins/gif/ReaderWriterGIF.cpp @@ -319,12 +319,12 @@ class ReaderWriterGIF : public osgDB::ReaderWriter { public: virtual const char* className() const { return "GIF Image Reader"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"gif"); } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/ive/ReaderWriterIVE.cpp b/src/osgPlugins/ive/ReaderWriterIVE.cpp index 3aa4aa3ae..5cdaae3db 100644 --- a/src/osgPlugins/ive/ReaderWriterIVE.cpp +++ b/src/osgPlugins/ive/ReaderWriterIVE.cpp @@ -15,17 +15,17 @@ class IVEReaderWriter : public ReaderWriter public: virtual const char* className() const { return "IVE Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return equalCaseInsensitive(extension,"ive"); } - virtual ReadResult readObject(const std::string& file, const Options* options) + virtual ReadResult readObject(const std::string& file, const Options* options) const { return readNode(file, options); } - virtual ReadResult readNode(const std::string& file, const Options* options) + virtual ReadResult readNode(const std::string& file, const Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; @@ -41,12 +41,12 @@ class IVEReaderWriter : public ReaderWriter return readNode(istream,local_opt.get()); } - virtual ReadResult readObject(std::istream& fin, const Options* options) + virtual ReadResult readObject(std::istream& fin, const Options* options) const { return readNode(fin, options); } - virtual ReadResult readNode(std::istream& fin, const Options* options) + virtual ReadResult readNode(std::istream& fin, const Options* options) const { #define IVE_CATCH_EXCEPTIONS #ifdef IVE_CATCH_EXCEPTIONS @@ -70,14 +70,14 @@ class IVEReaderWriter : public ReaderWriter - virtual WriteResult writeObject(const Object& object,const std::string& fileName, const osgDB::ReaderWriter::Options* options) + virtual WriteResult writeObject(const Object& object,const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { const Node* node = dynamic_cast(&object); if (node) return writeNode( *node, fileName, options ); return WriteResult::FILE_NOT_HANDLED; } - virtual WriteResult writeNode(const Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options* options) + virtual WriteResult writeNode(const Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { std::string ext = getFileExtension(fileName); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; @@ -88,14 +88,14 @@ class IVEReaderWriter : public ReaderWriter return result; } - virtual WriteResult writeObject(const Object& object,std::ostream& fout, const osgDB::ReaderWriter::Options* options) + virtual WriteResult writeObject(const Object& object,std::ostream& fout, const osgDB::ReaderWriter::Options* options) const { const Node* node = dynamic_cast(&object); if (node) return writeNode( *node, fout, options ); return WriteResult::FILE_NOT_HANDLED; } - virtual WriteResult writeNode(const Node& node,std::ostream& fout, const osgDB::ReaderWriter::Options* options) + virtual WriteResult writeNode(const Node& node,std::ostream& fout, const osgDB::ReaderWriter::Options* options) const { try { diff --git a/src/osgPlugins/jp2/ReaderWriterJP2.cpp b/src/osgPlugins/jp2/ReaderWriterJP2.cpp index b02b5e4f8..90de11c5e 100644 --- a/src/osgPlugins/jp2/ReaderWriterJP2.cpp +++ b/src/osgPlugins/jp2/ReaderWriterJP2.cpp @@ -172,24 +172,24 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter public: virtual const char* className() const { return "RGB Image Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"jp2") || osgDB::equalCaseInsensitive(extension,"jpc"); } - virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const { return readImage(file,options); } - virtual ReadResult readObject(std::istream& fin, const Options* options) + virtual ReadResult readObject(std::istream& fin, const Options* options) const { return readImage(fin,options); } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; @@ -256,7 +256,7 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter } - virtual ReadResult readImage(std::istream& fin,const Options* options) + virtual ReadResult readImage(std::istream& fin,const Options* options) const { char c; char * sdata; @@ -325,7 +325,7 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter return image; } - virtual WriteResult writeObject(const osg::Object& object,const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual WriteResult writeObject(const osg::Object& object,const std::string& file, const osgDB::ReaderWriter::Options* options) const { const osg::Image* image = dynamic_cast(&object); if (!image) return WriteResult::FILE_NOT_HANDLED; @@ -333,7 +333,7 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter return writeImage(*image,file,options); } - virtual WriteResult writeObject(const osg::Object& object,std::ostream& fout,const Options* options) + virtual WriteResult writeObject(const osg::Object& object,std::ostream& fout,const Options* options) const { const osg::Image* image = dynamic_cast(&object); if (!image) return WriteResult::FILE_NOT_HANDLED; @@ -341,7 +341,7 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter return writeImage(*image,fout,options); } - virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options* options) + virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getFileExtension(fileName); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; @@ -423,7 +423,7 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter return WriteResult::FILE_SAVED; } - WriteResult writeImage(const osg::Image& img, std::ostream& fout, const Options* options) + WriteResult writeImage(const osg::Image& img, std::ostream& fout, const Options* options) const { jas_init(); diff --git a/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp b/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp index 9b75aeefe..7c57d20ea 100644 --- a/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp +++ b/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp @@ -304,7 +304,7 @@ int *numComponents_ret) class ReaderWriterJPEG : public osgDB::ReaderWriter { - WriteResult::WriteStatus write_JPEG_file (const char* filename,int image_width,int image_height,JSAMPLE* image_buffer,int quality = 100) + WriteResult::WriteStatus write_JPEG_file (const char* filename,int image_width,int image_height,JSAMPLE* image_buffer,int quality = 100) const { /* This struct contains the JPEG compression parameters and pointers to * working space (which is allocated as needed by the JPEG library). @@ -412,7 +412,7 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter /* And we're done! */ return WriteResult::FILE_SAVED; } - int getQuality(const osgDB::ReaderWriter::Options *options) { + int getQuality(const osgDB::ReaderWriter::Options *options) const { if(options) { std::istringstream iss(options->getOptionString()); std::string opt; @@ -429,12 +429,12 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter } public: virtual const char* className() const { return "JPEG Image Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"jpeg") || osgDB::equalCaseInsensitive(extension,"jpg"); } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; @@ -481,7 +481,7 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter return pOsgImage; } - virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options *options) + virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options *options) const { std::string ext = osgDB::getFileExtension(fileName); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp index e9ec6fdad..0ad10dd02 100644 --- a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp +++ b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp @@ -91,9 +91,9 @@ class ReaderWriter3DS : public osgDB::ReaderWriter ReaderWriter3DS(); virtual const char* className() const { return "3DS Auto Studio Reader"; } - virtual bool acceptsExtension(const std::string& extension) { return osgDB::equalCaseInsensitive(extension,"3ds"); } + virtual bool accpettsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"3ds"); } - virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options); + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const; protected: @@ -416,7 +416,7 @@ osg::Node* ReaderWriter3DS::ReaderObject::processNode(StateSetMap drawStateMap,L } -osgDB::ReaderWriter::ReadResult ReaderWriter3DS::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) +osgDB::ReaderWriter::ReadResult ReaderWriter3DS::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); diff --git a/src/osgPlugins/logo/ReaderWriterLOGO.cpp b/src/osgPlugins/logo/ReaderWriterLOGO.cpp index 6629216a3..be5fd8aba 100644 --- a/src/osgPlugins/logo/ReaderWriterLOGO.cpp +++ b/src/osgPlugins/logo/ReaderWriterLOGO.cpp @@ -186,12 +186,12 @@ class LOGOReaderWriter : public osgDB::ReaderWriter public: virtual const char* className() const { return "Logo Database Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"logo"); } - virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/lwo/ReaderWriterLWO.cpp b/src/osgPlugins/lwo/ReaderWriterLWO.cpp index 6f46abb43..78698052e 100644 --- a/src/osgPlugins/lwo/ReaderWriterLWO.cpp +++ b/src/osgPlugins/lwo/ReaderWriterLWO.cpp @@ -47,11 +47,11 @@ public: ReaderWriterLWO() { } virtual const char* className() const { return "Lightwave Object Reader"; } - virtual bool acceptsExtension(const std::string& extension) { + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"lwo") || osgDB::equalCaseInsensitive(extension,"lw") || osgDB::equalCaseInsensitive(extension,"geo"); } - virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; @@ -76,9 +76,9 @@ public: lwosg::Converter::Options parse_options(const Options *options) const; - virtual ReadResult readNode_LWO2(const std::string& fileName, const osgDB::ReaderWriter::Options*); - virtual ReadResult readNode_old_LWO2(const std::string& fileName, const osgDB::ReaderWriter::Options*); - virtual ReadResult readNode_LWO1(const std::string& fileName, const osgDB::ReaderWriter::Options*); + virtual ReadResult readNode_LWO2(const std::string& fileName, const osgDB::ReaderWriter::Options*) const; + virtual ReadResult readNode_old_LWO2(const std::string& fileName, const osgDB::ReaderWriter::Options*) const; + virtual ReadResult readNode_LWO1(const std::string& fileName, const osgDB::ReaderWriter::Options*) const; protected: @@ -113,7 +113,7 @@ lwosg::Converter::Options ReaderWriterLWO::parse_options(const Options *options) // register with Registry to instantiate the above reader/writer. osgDB::RegisterReaderWriterProxy g_lwoReaderWriterProxy; -osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO2(const std::string &fileName, const osgDB::ReaderWriter::Options *options) +osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO2(const std::string &fileName, const osgDB::ReaderWriter::Options *options) const { lwosg::Converter::Options conv_options = parse_options(options); @@ -127,7 +127,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO2(const std::string } -osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_old_LWO2(const std::string& fileName, const osgDB::ReaderWriter::Options*) +osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_old_LWO2(const std::string& fileName, const osgDB::ReaderWriter::Options*) const { std::auto_ptr lwo2(new Lwo2()); if (lwo2->ReadFile(fileName)) @@ -168,7 +168,7 @@ struct GeometryCollection // read file and convert to OSG. -osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO1(const std::string& fileName, const osgDB::ReaderWriter::Options*) +osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO1(const std::string& fileName, const osgDB::ReaderWriter::Options*) const { lwObject* lw = lw_object_read(fileName.c_str(),osg::notify(osg::INFO)); if (!lw) diff --git a/src/osgPlugins/lws/ReaderWriterLWS.cpp b/src/osgPlugins/lws/ReaderWriterLWS.cpp index b09f8cb60..1cdbc437f 100644 --- a/src/osgPlugins/lws/ReaderWriterLWS.cpp +++ b/src/osgPlugins/lws/ReaderWriterLWS.cpp @@ -27,11 +27,11 @@ public: virtual const char* className() const { return "ReaderWriterLWS"; } - virtual bool acceptsExtension(const std::string &extension) { + virtual bool acceptsExtension(const std::string &extension) const { return osgDB::equalCaseInsensitive(extension, "lws"); } - virtual ReadResult readNode(const std::string &file, const osgDB::ReaderWriter::Options *options) + virtual ReadResult readNode(const std::string &file, const osgDB::ReaderWriter::Options *options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/md2/ReaderWriterMD2.cpp b/src/osgPlugins/md2/ReaderWriterMD2.cpp index c68475885..673b43917 100644 --- a/src/osgPlugins/md2/ReaderWriterMD2.cpp +++ b/src/osgPlugins/md2/ReaderWriterMD2.cpp @@ -49,19 +49,17 @@ public: return "Quake MD2 Reader"; } - virtual bool acceptsExtension (const std::string& extension) { + virtual bool acceptsExtension (const std::string& extension) const { return osgDB::equalCaseInsensitive (extension, "md2") ? true : false; } - virtual ReadResult readNode (const std::string& filename, - const osgDB::ReaderWriter::Options* options); + virtual ReadResult readNode (const std::string& filename, const osgDB::ReaderWriter::Options* options) const; }; osgDB::RegisterReaderWriterProxy g_readerWriter_MD2_Proxy; osgDB::ReaderWriter::ReadResult -ReaderWriterMD2::readNode (const std::string& file, - const osgDB::ReaderWriter::Options* options) +ReaderWriterMD2::readNode (const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/mpeg/ReaderWriterMPEG.cpp b/src/osgPlugins/mpeg/ReaderWriterMPEG.cpp index 1eee1b918..07a615033 100644 --- a/src/osgPlugins/mpeg/ReaderWriterMPEG.cpp +++ b/src/osgPlugins/mpeg/ReaderWriterMPEG.cpp @@ -15,13 +15,13 @@ class ReaderWriterMPEG : public osgDB::ReaderWriter virtual const char* className() const { return "MPEG ImageStream Reader"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"mpg") || osgDB::equalCaseInsensitive(extension,"mpv"); } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/net/ReaderWriterNET.cpp b/src/osgPlugins/net/ReaderWriterNET.cpp index c2e2b4d48..c23b167a1 100644 --- a/src/osgPlugins/net/ReaderWriterNET.cpp +++ b/src/osgPlugins/net/ReaderWriterNET.cpp @@ -78,7 +78,7 @@ class NetReader : public osgDB::ReaderWriter virtual const char* className() const { return "HTTP Protocol Model Reader"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"net"); } @@ -92,33 +92,33 @@ class NetReader : public osgDB::ReaderWriter NODE }; - virtual ReadResult openArchive(const std::string& fileName,ArchiveStatus status, unsigned int , const Options* options) + virtual ReadResult openArchive(const std::string& fileName,ArchiveStatus status, unsigned int , const Options* options) const { if (status!=READ) return ReadResult(ReadResult::FILE_NOT_HANDLED); else return readFile(ARCHIVE,fileName,options); } - virtual ReadResult readObject(const std::string& fileName, const Options* options) + virtual ReadResult readObject(const std::string& fileName, const Options* options) const { return readFile(OBJECT,fileName,options); } - virtual ReadResult readImage(const std::string& fileName, const Options *options) + virtual ReadResult readImage(const std::string& fileName, const Options *options) const { return readFile(IMAGE,fileName,options); } - virtual ReadResult readHeightField(const std::string& fileName, const Options *options) + virtual ReadResult readHeightField(const std::string& fileName, const Options *options) const { return readFile(HEIGHTFIELD,fileName,options); } - virtual ReadResult readNode(const std::string& fileName, const Options *options) + virtual ReadResult readNode(const std::string& fileName, const Options *options) const { return readFile(NODE,fileName,options); } - ReadResult readFile(ObjectType objectType, ReaderWriter* rw, std::istream& fin, const Options *options) + ReadResult readFile(ObjectType objectType, ReaderWriter* rw, std::istream& fin, const Options *options) const { switch(objectType) { @@ -132,7 +132,7 @@ class NetReader : public osgDB::ReaderWriter return ReadResult::FILE_NOT_HANDLED; } - virtual ReadResult readFile(ObjectType objectType, const std::string& inFileName, const Options *options) + virtual ReadResult readFile(ObjectType objectType, const std::string& inFileName, const Options *options) const { osg::Timer_t start = osg::Timer::instance()->tick(); diff --git a/src/osgPlugins/obj/ReaderWriterOBJ.cpp b/src/osgPlugins/obj/ReaderWriterOBJ.cpp index a5b764725..36fae3731 100644 --- a/src/osgPlugins/obj/ReaderWriterOBJ.cpp +++ b/src/osgPlugins/obj/ReaderWriterOBJ.cpp @@ -51,27 +51,27 @@ public: ReaderWriterOBJ() { } virtual const char* className() const { return "Wavefront OBJ Reader"; } - virtual bool acceptsExtension(const std::string& extension) { + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"obj"); } - virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options); + virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const; - virtual ReadResult readNode(std::istream& fin, const Options* options); + virtual ReadResult readNode(std::istream& fin, const Options* options) const; protected: typedef std::map< std::string, osg::ref_ptr > MaterialToStateSetMap; - void buildMaterialToStateSetMap(obj::Model& model, MaterialToStateSetMap& materialToSetSetMap); + void buildMaterialToStateSetMap(obj::Model& model, MaterialToStateSetMap& materialToSetSetMap) const; - osg::Geometry* convertElementListToGeometry(obj::Model& model, obj::Model::ElementList& elementList); + osg::Geometry* convertElementListToGeometry(obj::Model& model, obj::Model::ElementList& elementList) const; - osg::Node* convertModelToSceneGraph(obj::Model& model); + osg::Node* convertModelToSceneGraph(obj::Model& model) const; - inline osg::Vec3 transformVertex(const osg::Vec3& vec) { return osg::Vec3(vec.x(),-vec.z(),vec.y()); } - inline osg::Vec3 transformNormal(const osg::Vec3& vec) { return osg::Vec3(vec.x(),-vec.z(),vec.y()); } + inline osg::Vec3 transformVertex(const osg::Vec3& vec) const { return osg::Vec3(vec.x(),-vec.z(),vec.y()); } + inline osg::Vec3 transformNormal(const osg::Vec3& vec) const { return osg::Vec3(vec.x(),-vec.z(),vec.y()); } }; @@ -79,7 +79,7 @@ protected: // register with Registry to instantiate the above reader/writer. osgDB::RegisterReaderWriterProxy g_objReaderWriterProxy; -void ReaderWriterOBJ::buildMaterialToStateSetMap(obj::Model& model, MaterialToStateSetMap& materialToStateSetMap) +void ReaderWriterOBJ::buildMaterialToStateSetMap(obj::Model& model, MaterialToStateSetMap& materialToStateSetMap) const { for(obj::Model::MaterialMap::iterator itr = model.materialMap.begin(); itr != model.materialMap.end(); @@ -136,7 +136,7 @@ void ReaderWriterOBJ::buildMaterialToStateSetMap(obj::Model& model, MaterialToSt } } -osg::Geometry* ReaderWriterOBJ::convertElementListToGeometry(obj::Model& model, obj::Model::ElementList& elementList) +osg::Geometry* ReaderWriterOBJ::convertElementListToGeometry(obj::Model& model, obj::Model::ElementList& elementList) const { unsigned int numVertexIndices = 0; @@ -389,7 +389,7 @@ osg::Geometry* ReaderWriterOBJ::convertElementListToGeometry(obj::Model& model, return geometry; } -osg::Node* ReaderWriterOBJ::convertModelToSceneGraph(obj::Model& model) +osg::Node* ReaderWriterOBJ::convertModelToSceneGraph(obj::Model& model) const { if (model.elementStateMap.empty()) return 0; @@ -446,7 +446,7 @@ osg::Node* ReaderWriterOBJ::convertModelToSceneGraph(obj::Model& model) // read file and convert to OSG. -osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) +osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; @@ -475,7 +475,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& fil return ReadResult::FILE_NOT_HANDLED; } -osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(std::istream& fin, const Options* options) +osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(std::istream& fin, const Options* options) const { if (fin) { diff --git a/src/osgPlugins/osg/ReaderWriterOSG.cpp b/src/osgPlugins/osg/ReaderWriterOSG.cpp index 4f9dd3bb4..ca4f877db 100644 --- a/src/osgPlugins/osg/ReaderWriterOSG.cpp +++ b/src/osgPlugins/osg/ReaderWriterOSG.cpp @@ -18,16 +18,16 @@ class OSGReaderWriter : public ReaderWriter public: virtual const char* className() const { return "OSG Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return equalCaseInsensitive(extension,"osg"); } - virtual ReadResult readObject(const std::string& fileName, const Options* opt) { return readNode(fileName, opt); } + virtual ReadResult readObject(const std::string& fileName, const Options* opt) const { return readNode(fileName, opt); } - virtual ReadResult readObject(std::istream& fin, const Options* opt) { return readNode(fin, opt); } + virtual ReadResult readObject(std::istream& fin, const Options* opt) const { return readNode(fin, opt); } - virtual ReadResult readNode(const std::string& file, const Options* opt) + virtual ReadResult readNode(const std::string& file, const Options* opt) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; @@ -48,7 +48,7 @@ class OSGReaderWriter : public ReaderWriter } - virtual ReadResult readNode(std::istream& fin, const Options* options) + virtual ReadResult readNode(std::istream& fin, const Options* options) const { Input fr; @@ -89,7 +89,7 @@ class OSGReaderWriter : public ReaderWriter } - void setPrecision(Output& fout, const osgDB::ReaderWriter::Options* options) + void setPrecision(Output& fout, const osgDB::ReaderWriter::Options* options) const { if (options) { @@ -105,7 +105,7 @@ class OSGReaderWriter : public ReaderWriter } } - virtual WriteResult writeObject(const Object& obj,const std::string& fileName, const osgDB::ReaderWriter::Options* options) + virtual WriteResult writeObject(const Object& obj,const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(fileName); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; @@ -122,7 +122,7 @@ class OSGReaderWriter : public ReaderWriter return WriteResult("Unable to open file for output"); } - virtual WriteResult writeObject(const Object& obj,std::ostream& fout, const osgDB::ReaderWriter::Options* options) + virtual WriteResult writeObject(const Object& obj,std::ostream& fout, const osgDB::ReaderWriter::Options* options) const { Output foutput; @@ -140,7 +140,7 @@ class OSGReaderWriter : public ReaderWriter } - virtual WriteResult writeNode(const Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options* options) + virtual WriteResult writeNode(const Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { std::string ext = getFileExtension(fileName); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; @@ -158,7 +158,7 @@ class OSGReaderWriter : public ReaderWriter return WriteResult("Unable to open file for output"); } - virtual WriteResult writeNode(const Node& node,std::ostream& fout, const osgDB::ReaderWriter::Options* options) + virtual WriteResult writeNode(const Node& node,std::ostream& fout, const osgDB::ReaderWriter::Options* options) const { Output foutput; diff --git a/src/osgPlugins/osga/OSGA_Archive.cpp b/src/osgPlugins/osga/OSGA_Archive.cpp index f1cd1dbad..3bfb00263 100644 --- a/src/osgPlugins/osga/OSGA_Archive.cpp +++ b/src/osgPlugins/osga/OSGA_Archive.cpp @@ -580,24 +580,24 @@ ReaderWriter::ReadResult OSGA_Archive::read(const ReadFunctor& readFunctor) return result; } -ReaderWriter::ReadResult OSGA_Archive::readObject(const std::string& fileName,const Options* options) +ReaderWriter::ReadResult OSGA_Archive::readObject(const std::string& fileName,const Options* options) const { - return read(ReadObjectFunctor(fileName, options)); + return const_cast(this)->read(ReadObjectFunctor(fileName, options)); } -ReaderWriter::ReadResult OSGA_Archive::readImage(const std::string& fileName,const Options* options) +ReaderWriter::ReadResult OSGA_Archive::readImage(const std::string& fileName,const Options* options) const { - return read(ReadImageFunctor(fileName, options)); + return const_cast(this)->read(ReadImageFunctor(fileName, options)); } -ReaderWriter::ReadResult OSGA_Archive::readHeightField(const std::string& fileName,const Options* options) +ReaderWriter::ReadResult OSGA_Archive::readHeightField(const std::string& fileName,const Options* options) const { - return read(ReadHeightFieldFunctor(fileName, options)); + return const_cast(this)->read(ReadHeightFieldFunctor(fileName, options)); } -ReaderWriter::ReadResult OSGA_Archive::readNode(const std::string& fileName,const Options* options) +ReaderWriter::ReadResult OSGA_Archive::readNode(const std::string& fileName,const Options* options) const { - return read(ReadNodeFunctor(fileName, options)); + return const_cast(this)->read(ReadNodeFunctor(fileName, options)); } @@ -618,7 +618,7 @@ struct OSGA_Archive::WriteImageFunctor : public OSGA_Archive::WriteFunctor _object(object) {} const osg::Image& _object; - virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output)const { return rw.writeImage(_object, output, _options); } + virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output) const { return rw.writeImage(_object, output, _options); } }; struct OSGA_Archive::WriteHeightFieldFunctor : public OSGA_Archive::WriteFunctor @@ -676,27 +676,27 @@ ReaderWriter::WriteResult OSGA_Archive::write(const WriteFunctor& writeFunctor) } -ReaderWriter::WriteResult OSGA_Archive::writeObject(const osg::Object& obj,const std::string& fileName,const Options* options) +ReaderWriter::WriteResult OSGA_Archive::writeObject(const osg::Object& obj,const std::string& fileName,const Options* options) const { osg::notify(osg::INFO)<<"OSGA_Archive::writeObject(obj, "<(this)->write(WriteObjectFunctor(obj, fileName, options)); } -ReaderWriter::WriteResult OSGA_Archive::writeImage(const osg::Image& image,const std::string& fileName,const Options* options) +ReaderWriter::WriteResult OSGA_Archive::writeImage(const osg::Image& image,const std::string& fileName,const Options* options) const { osg::notify(osg::INFO)<<"OSGA_Archive::writeImage(obj, "<(this)->write(WriteImageFunctor(image, fileName, options)); } -ReaderWriter::WriteResult OSGA_Archive::writeHeightField(const osg::HeightField& heightField,const std::string& fileName,const Options* options) +ReaderWriter::WriteResult OSGA_Archive::writeHeightField(const osg::HeightField& heightField,const std::string& fileName,const Options* options) const { osg::notify(osg::INFO)<<"OSGA_Archive::writeHeightField(obj, "<(this)->write(WriteHeightFieldFunctor(heightField, fileName, options)); } -ReaderWriter::WriteResult OSGA_Archive::writeNode(const osg::Node& node,const std::string& fileName,const Options* options) +ReaderWriter::WriteResult OSGA_Archive::writeNode(const osg::Node& node,const std::string& fileName,const Options* options) const { osg::notify(osg::INFO)<<"OSGA_Archive::writeNode(obj, "<(this)->write(WriteNodeFunctor(node, fileName, options)); } diff --git a/src/osgPlugins/osga/OSGA_Archive.h b/src/osgPlugins/osga/OSGA_Archive.h index 018921617..80b34065e 100644 --- a/src/osgPlugins/osga/OSGA_Archive.h +++ b/src/osgPlugins/osga/OSGA_Archive.h @@ -30,7 +30,7 @@ class OSGA_Archive : public osgDB::Archive virtual const char* className() const { return "Archive"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"osga"); } @@ -57,28 +57,28 @@ class OSGA_Archive : public osgDB::Archive /** Read an osg::Object of specified file name from the Archive.*/ - virtual ReadResult readObject(const std::string& fileName,const Options* options=NULL); + virtual ReadResult readObject(const std::string& fileName,const Options* options=NULL) const; /** Read an osg::Image of specified file name from the Archive.*/ - virtual ReadResult readImage(const std::string& fileName,const Options* options=NULL); + virtual ReadResult readImage(const std::string& fileName,const Options* options=NULL) const; /** Read an osg::HeightField of specified file name from the Archive.*/ - virtual ReadResult readHeightField(const std::string& fileName,const Options* options=NULL); + virtual ReadResult readHeightField(const std::string& fileName,const Options* options=NULL) const; /** Read an osg::Node of specified file name from the Archive.*/ - virtual ReadResult readNode(const std::string& fileName,const Options* options=NULL); + virtual ReadResult readNode(const std::string& fileName,const Options* options=NULL) const; /** Write an osg::Object with specified file name to the Archive.*/ - virtual WriteResult writeObject(const osg::Object& obj,const std::string& fileName,const Options* options=NULL); + virtual WriteResult writeObject(const osg::Object& obj,const std::string& fileName,const Options* options=NULL) const; /** Write an osg::Image with specified file name to the Archive.*/ - virtual WriteResult writeImage(const osg::Image& image,const std::string& fileName,const Options* options=NULL); + virtual WriteResult writeImage(const osg::Image& image,const std::string& fileName,const Options* options=NULL) const; /** Write an osg::HeightField with specified file name to the Archive.*/ - virtual WriteResult writeHeightField(const osg::HeightField& heightField,const std::string& fileName,const Options* options=NULL); + virtual WriteResult writeHeightField(const osg::HeightField& heightField,const std::string& fileName,const Options* options=NULL) const; /** Write an osg::Node with specified file name to the Archive.*/ - virtual WriteResult writeNode(const osg::Node& node,const std::string& fileName,const Options* options=NULL); + virtual WriteResult writeNode(const osg::Node& node,const std::string& fileName,const Options* options=NULL) const; protected: diff --git a/src/osgPlugins/osga/ReaderWriterOSGA.cpp b/src/osgPlugins/osga/ReaderWriterOSGA.cpp index 84483ce70..5288251bb 100644 --- a/src/osgPlugins/osga/ReaderWriterOSGA.cpp +++ b/src/osgPlugins/osga/ReaderWriterOSGA.cpp @@ -12,12 +12,12 @@ public: ReaderWriterOSGA() { } virtual const char* className() const { return "OpenSceneGraph Archive Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"osga"); } - virtual ReadResult openArchive(const std::string& file,ArchiveStatus status, unsigned int indexBlockSize = 4096, const Options* options=NULL) + virtual ReadResult openArchive(const std::string& file,ArchiveStatus status, unsigned int indexBlockSize = 4096, const Options* options=NULL) const { std::string ext = osgDB::getLowerCaseFileExtension(file); @@ -40,7 +40,7 @@ public: } /** open an archive for reading.*/ - virtual ReadResult openArchive(std::istream& fin,const Options*) + virtual ReadResult openArchive(std::istream& fin,const Options*) const { osg::ref_ptr archive = new OSGA_Archive; if (!archive->open(fin)) @@ -51,7 +51,7 @@ public: return archive.get(); } - virtual ReadResult readImage(const std::string& file,const Options*) + virtual ReadResult readImage(const std::string& file,const Options*) const { ReadResult result = openArchive(file,osgDB::Archive::READ); @@ -71,7 +71,7 @@ public: return result_2; } - virtual ReadResult readNode(const std::string& file,const Options*) + virtual ReadResult readNode(const std::string& file,const Options*) const { ReadResult result = openArchive(file,osgDB::Archive::READ); diff --git a/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp b/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp index ff9620ad2..f2691c238 100644 --- a/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp +++ b/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp @@ -25,12 +25,12 @@ class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter { public: virtual const char* className() const { return "OSGTGZ Database Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"osgtgz"); } - virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/pfb/ReaderWriterPFB.cpp b/src/osgPlugins/pfb/ReaderWriterPFB.cpp index 62488cb7c..faeaeed33 100644 --- a/src/osgPlugins/pfb/ReaderWriterPFB.cpp +++ b/src/osgPlugins/pfb/ReaderWriterPFB.cpp @@ -30,7 +30,7 @@ class ReaderWriterPFB : public osgDB::ReaderWriter void initPerformer(); virtual const char* className() const { return "Performer Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"3ds") ? true : @@ -95,7 +95,7 @@ class ReaderWriterPFB : public osgDB::ReaderWriter false; } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) fileName = file; // let Peformer see if it can file the filep @@ -150,7 +150,7 @@ class ReaderWriterPFB : public osgDB::ReaderWriter return ReadResult::FILE_NOT_HANDLED; } - virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/pic/ReaderWriterPIC.cpp b/src/osgPlugins/pic/ReaderWriterPIC.cpp index c72863738..bf64a4e0a 100644 --- a/src/osgPlugins/pic/ReaderWriterPIC.cpp +++ b/src/osgPlugins/pic/ReaderWriterPIC.cpp @@ -192,9 +192,9 @@ class ReaderWriterPIC : public osgDB::ReaderWriter { public: virtual const char* className() const { return "PIC Image Reader"; } - virtual bool acceptsExtension(const std::string& extension) { return osgDB::equalCaseInsensitive(extension,"pic"); } + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"pic"); } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/png/ReaderWriterPNG.cpp b/src/osgPlugins/png/ReaderWriterPNG.cpp index 955976b97..57a0f0c67 100644 --- a/src/osgPlugins/png/ReaderWriterPNG.cpp +++ b/src/osgPlugins/png/ReaderWriterPNG.cpp @@ -34,9 +34,9 @@ class ReaderWriterPNG : public osgDB::ReaderWriter { public: virtual const char* className() const { return "PNG Image Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) { return osgDB::equalCaseInsensitive(extension,"png"); } + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"png"); } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/png/new_ReaderWriterPNG.cpp b/src/osgPlugins/png/new_ReaderWriterPNG.cpp deleted file mode 100644 index 0623f94db..000000000 --- a/src/osgPlugins/png/new_ReaderWriterPNG.cpp +++ /dev/null @@ -1,330 +0,0 @@ -#include -#include -#include -#include - -#include -#include - -/**************************************************************************** - * - * Follows is code extracted from the simage library. Original Authors: - * - * Systems in Motion, - * - * - * Peder Blekken - * Morten Eriksen - * Marius Bugge Monsen - * - * The original COPYING notice - * - * All files in this library are public domain, except simage_rgb.cpp which is - * Copyright (c) Mark J Kilgard . I will contact Mark - * very soon to hear if this source also can become public domain. - * - * Please send patches for bugs and new features to: . - * - * Peder Blekken - * - * - * Ported into the OSG as a plugin, Robert Osfield Decemeber 2000. - * Note, reference above to license of simage_rgb is not relevent to the OSG - * as the OSG does not use it. Also for patches, bugs and new features - * please send them direct to the OSG dev team rather than address above. - * - **********************************************************************/ - -/* - * Based on example code found in the libjpeg archive - * - */ - -using namespace osg; - -extern "C" -{ - #include -} - -#define ERR_NO_ERROR 0 -#define ERR_OPEN 1 -#define ERR_MEM 2 -#define ERR_PNGLIB 3 - -static int pngerror = ERR_NO_ERROR; - -/* my setjmp buffer */ -static jmp_buf setjmp_buffer; - -/* called my libpng */ -static void -warn_callback(png_structp /*ps*/, png_const_charp pc) -{ - /*FIXME: notify? */ - osg::notify(osg::WARN)<<"Warning in .png reader: "; - if (pc) osg::notify(osg::WARN)<< pc; - osg::notify(osg::WARN)<setFileName(fileName.c_str()); - pOsgImage->setImage(s,t,r, - internalFormat, - pixelFormat, - dataType, - imageData); - - return pOsgImage; - - } -}; - -// now register with Registry to instantiate the above -// reader/writer. -osgDB::RegisterReaderWriterProxy g_readerWriter_PNG_Proxy; diff --git a/src/osgPlugins/png/prev_ReaderWriterPNG.cpp b/src/osgPlugins/png/prev_ReaderWriterPNG.cpp deleted file mode 100644 index 342668a07..000000000 --- a/src/osgPlugins/png/prev_ReaderWriterPNG.cpp +++ /dev/null @@ -1,170 +0,0 @@ -#include -#include "osg/Notify" -#include -#include "osg/GL" - -#include "osgDB/Registry" - -using namespace osg; - -extern "C" -{ - #include -} - - -/* Transparency parameters */ -#define PNG_ALPHA -2 /* Use alpha channel in PNG file, if there is one */ -#define PNG_SOLID -1 /* No transparency */ -#define PNG_STENCIL 0 /* Sets alpha to 0 for r=g=b=0, 1 otherwise */ - -typedef struct -{ - unsigned int Width; - unsigned int Height; - unsigned int Depth; - unsigned int Alpha; -} pngInfo; - -class ReaderWriterPNG : public osgDB::ReaderWriter -{ - public: - virtual const char* className() { return "PNG Image Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) { return extension=="png"; } - - virtual ReadResult readImage(const std::string& fileName,const osgDB::ReaderWriter::Options*) - { - - int trans = PNG_ALPHA; - FILE *fp = NULL; - pngInfo pInfo; - pngInfo *pinfo = &pInfo; - - unsigned char header[8]; - png_structp png; - png_infop info; - png_infop endinfo; - png_bytep data; //, data2; - png_bytep *row_p; - double fileGamma; - - png_uint_32 width, height; - int depth, color; - - png_uint_32 i; - png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - info = png_create_info_struct(png); - endinfo = png_create_info_struct(png); - - fp = fopen(fileName.c_str(), "rb"); - if (fp && fread(header, 1, 8, fp) && png_check_sig(header, 8)) - png_init_io(png, fp); - else - { - png_destroy_read_struct(&png, &info, &endinfo); - return ReadResult::FILE_NOT_HANDLED; - } - png_set_sig_bytes(png, 8); - - png_read_info(png, info); - png_get_IHDR(png, info, &width, &height, &depth, &color, NULL, NULL, NULL); - - if (pinfo != NULL) - { - pinfo->Width = width; - pinfo->Height = height; - pinfo->Depth = depth; - } - - if (color == PNG_COLOR_TYPE_GRAY || color == PNG_COLOR_TYPE_GRAY_ALPHA) - png_set_gray_to_rgb(png); - - if (color&PNG_COLOR_MASK_ALPHA && trans != PNG_ALPHA) - { - png_set_strip_alpha(png); - color &= ~PNG_COLOR_MASK_ALPHA; - } - - // if (!(PalettedTextures && mipmap >= 0 && trans == PNG_SOLID)) - if (color == PNG_COLOR_TYPE_PALETTE) - png_set_expand(png); - - /*--GAMMA--*/ - // checkForGammaEnv(); - double screenGamma = 2.2 / 1.0; - if (png_get_gAMA(png, info, &fileGamma)) - png_set_gamma(png, screenGamma, fileGamma); - else - png_set_gamma(png, screenGamma, 1.0/2.2); - - png_read_update_info(png, info); - - data = (png_bytep) malloc(png_get_rowbytes(png, info)*height); - row_p = (png_bytep *) malloc(sizeof(png_bytep)*height); - - bool StandardOrientation = false; - for (i = 0; i < height; i++) - { - if (StandardOrientation) - row_p[height - 1 - i] = &data[png_get_rowbytes(png, info)*i]; - else - row_p[i] = &data[png_get_rowbytes(png, info)*i]; - } - - png_read_image(png, row_p); - free(row_p); - - int iBitCount; - - if (trans == PNG_SOLID || trans == PNG_ALPHA || color == PNG_COLOR_TYPE_RGB_ALPHA || color == PNG_COLOR_TYPE_GRAY_ALPHA) - { - switch (color) - { - case PNG_COLOR_TYPE_GRAY: - case PNG_COLOR_TYPE_RGB: - case PNG_COLOR_TYPE_PALETTE: - iBitCount = 24; - if (pinfo != NULL) pinfo->Alpha = 0; - break; - - case PNG_COLOR_TYPE_GRAY_ALPHA: - case PNG_COLOR_TYPE_RGB_ALPHA: - iBitCount = 32; - if (pinfo != NULL) pinfo->Alpha = 8; - break; - - default: - return ReadResult::FILE_NOT_HANDLED; - } - } - - png_read_end(png, endinfo); - png_destroy_read_struct(&png, &info, &endinfo); - - // free(data); - - if (fp) - fclose(fp); - - osg::Image* pOsgImage = new osg::Image(); - - pOsgImage->setFileName(fileName.c_str()); - if (iBitCount == 24) - pOsgImage->setImage(width, height, 1, - iBitCount / 8,// int internalFormat, - GL_RGB, // unsigned int pixelFormat - GL_UNSIGNED_BYTE,// unsigned int dataType - data); - else - pOsgImage->setImage(width, height, 1, - iBitCount / 8,// int internalFormat, - GL_RGBA, // unsigned int pixelFormat - GL_UNSIGNED_BYTE,// unsigned int dataType - data); - return pOsgImage; - } -}; - -// now register with Registry to instantiate the above -// reader/writer. -osgDB::RegisterReaderWriterProxy g_readerWriter_PNG_Proxy; diff --git a/src/osgPlugins/pnm/ReaderWriterPNM.cpp b/src/osgPlugins/pnm/ReaderWriterPNM.cpp index 77b3d6fd1..ed83d98f4 100644 --- a/src/osgPlugins/pnm/ReaderWriterPNM.cpp +++ b/src/osgPlugins/pnm/ReaderWriterPNM.cpp @@ -17,15 +17,15 @@ class ReaderWriterPNM : public osgDB::ReaderWriter { public: virtual const char* className() const { return "PNM Image Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) - { - return osgDB::equalCaseInsensitive(extension, "pnm") || - osgDB::equalCaseInsensitive(extension, "ppm") || - osgDB::equalCaseInsensitive(extension, "pgm") || - osgDB::equalCaseInsensitive(extension, "pbm"); - } + virtual bool acceptsExtension(const std::string& extension) const + { + return osgDB::equalCaseInsensitive(extension, "pnm") || + osgDB::equalCaseInsensitive(extension, "ppm") || + osgDB::equalCaseInsensitive(extension, "pgm") || + osgDB::equalCaseInsensitive(extension, "pbm"); + } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; @@ -34,227 +34,227 @@ class ReaderWriterPNM : public osgDB::ReaderWriter if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; FILE *fp = NULL; - char line[300]; - int ppmtype = 0; /* P1, P2, etc. */ - int width = 0; - int height = 0; - int max_value = 0; + char line[300]; + int ppmtype = 0; /* P1, P2, etc. */ + int width = 0; + int height = 0; + int max_value = 0; - bool binary_flag = false; - int shift_value = 0; // if greater than 8 bits + bool binary_flag = false; + int shift_value = 0; // if greater than 8 bits - // Open file. + // Open file. fp = fopen(fileName.c_str(), "rb"); - // Read header items. - int row; - for (row = 1; row <= 3; row++) - { - fgets(line, 300, fp); + // Read header items. + int row; + for (row = 1; row <= 3; row++) + { + fgets(line, 300, fp); - char *cp = line; - while (*cp && isspace(*cp)) - cp++; - if (! *cp || *cp == '#') - { - // Skip comment lines. - row--; - } - else if (row == 1) - { - // Get the image type. - if (line[0] == 'p' || line[0] == 'P') - { - ppmtype = line[1] - '0'; - } - } - else if (row == 2) - { - // Get the image size. - width = atoi(line); - char *cp = line + strspn(line, "\t \n\r"); - cp += strspn(cp, "0123456789"); - cp += strspn(line, "\t \n\r"); - height = atoi(cp); + char *cp = line; + while (*cp && isspace(*cp)) + cp++; + if (! *cp || *cp == '#') + { + // Skip comment lines. + row--; + } + else if (row == 1) + { + // Get the image type. + if (line[0] == 'p' || line[0] == 'P') + { + ppmtype = line[1] - '0'; + } + } + else if (row == 2) + { + // Get the image size. + width = atoi(line); + char *cp = line + strspn(line, "\t \n\r"); + cp += strspn(cp, "0123456789"); + cp += strspn(line, "\t \n\r"); + height = atoi(cp); - // pbm files don't have row 3 - if (ppmtype == 1 || ppmtype == 4) - { - max_value = 1; - break; - } - } - else if (row == 3) - { - // Get the maximum value - max_value = atoi(line); - } - } + // pbm files don't have row 3 + if (ppmtype == 1 || ppmtype == 4) + { + max_value = 1; + break; + } + } + else if (row == 3) + { + // Get the maximum value + max_value = atoi(line); + } + } - // Check for valid values. - if (width <= 0 || height <= 0 || max_value <= 0 || ppmtype < 1 || - ppmtype > 6) - { - fclose(fp); + // Check for valid values. + if (width <= 0 || height <= 0 || max_value <= 0 || ppmtype < 1 || + ppmtype > 6) + { + fclose(fp); return ReadResult::FILE_NOT_HANDLED; - } + } - // Check for binary file. - if (ppmtype >= 4 && ppmtype <= 6) - binary_flag = true; + // Check for binary file. + if (ppmtype >= 4 && ppmtype <= 6) + binary_flag = true; - // Warn the user if the full image cannot be used. - if (max_value > 255) - { - osg::notify(osg::NOTICE) << "PNM file " << fileName << - " has channels larger than " - " 8 bits. Color resolution will be lost." << std::endl; + // Warn the user if the full image cannot be used. + if (max_value > 255) + { + osg::notify(osg::NOTICE) << "PNM file " << fileName << + " has channels larger than " + " 8 bits. Color resolution will be lost." << std::endl; - while (max_value > 255) - { - max_value >>= 1; - shift_value++; - } - } + while (max_value > 255) + { + max_value >>= 1; + shift_value++; + } + } - // We always create a RGB image, no matter what type of - // source it was. + // We always create a RGB image, no matter what type of + // source it was. unsigned char *data = new unsigned char [width * height * 3]; - // For the ascii files - if (!binary_flag) - { - unsigned char *end = data + width * height * 3; - unsigned char *dst = data; + // For the ascii files + if (!binary_flag) + { + unsigned char *end = data + width * height * 3; + unsigned char *dst = data; - char s_num[300]; - int s_num_count; - int value = fgetc(fp); + char s_num[300]; + int s_num_count; + int value = fgetc(fp); - while (dst < end) - { - if (feof(fp) || ferror(fp)) - { - fclose(fp); - delete[] data; - return ReadResult::FILE_NOT_HANDLED; - } + while (dst < end) + { + if (feof(fp) || ferror(fp)) + { + fclose(fp); + delete[] data; + return ReadResult::FILE_NOT_HANDLED; + } - // Read any extra whitespace - //while (isspace(value)) - while (!isdigit(value)) - { - value = fgetc(fp); - } + // Read any extra whitespace + //while (isspace(value)) + while (!isdigit(value)) + { + value = fgetc(fp); + } - // Read any numeric digits - s_num_count = 0; - while (isdigit(value)) - { - s_num[s_num_count++] = value; - value = fgetc(fp); - } - // Don't forget to terminate the string! - s_num[s_num_count] = 0; + // Read any numeric digits + s_num_count = 0; + while (isdigit(value)) + { + s_num[s_num_count++] = value; + value = fgetc(fp); + } + // Don't forget to terminate the string! + s_num[s_num_count] = 0; - if (s_num_count == 0) - { - fclose(fp); - delete[] data; - return ReadResult::FILE_NOT_HANDLED; - } + if (s_num_count == 0) + { + fclose(fp); + delete[] data; + return ReadResult::FILE_NOT_HANDLED; + } - unsigned int data_value = atoi(s_num) >> shift_value; + unsigned int data_value = atoi(s_num) >> shift_value; - // Now we have our value. Put it into the array - // in the appropriate place. - if (ppmtype == 1) - { - if (data_value == 1) - data_value = 0; - else - data_value = 255; + // Now we have our value. Put it into the array + // in the appropriate place. + if (ppmtype == 1) + { + if (data_value == 1) + data_value = 0; + else + data_value = 255; - *(dst++) = data_value; - *(dst++) = data_value; - *(dst++) = data_value; - } - else if (ppmtype == 2) - { - *(dst++) = data_value; - *(dst++) = data_value; - *(dst++) = data_value; - } - else if (ppmtype == 3) - { - *(dst++) = data_value; - } - } - } + *(dst++) = data_value; + *(dst++) = data_value; + *(dst++) = data_value; + } + else if (ppmtype == 2) + { + *(dst++) = data_value; + *(dst++) = data_value; + *(dst++) = data_value; + } + else if (ppmtype == 3) + { + *(dst++) = data_value; + } + } + } - // If we have a binary bitmap - else if (ppmtype == 4) - { - unsigned char *end = data + width * height * 3; - unsigned char *dst = data; + // If we have a binary bitmap + else if (ppmtype == 4) + { + unsigned char *end = data + width * height * 3; + unsigned char *dst = data; - while (dst < end) - { - unsigned char b = (unsigned char) fgetc(fp); - if (feof(fp) || ferror(fp)) - { - fclose(fp); - delete[] data; - return ReadResult::FILE_NOT_HANDLED; - } + while (dst < end) + { + unsigned char b = (unsigned char) fgetc(fp); + if (feof(fp) || ferror(fp)) + { + fclose(fp); + delete[] data; + return ReadResult::FILE_NOT_HANDLED; + } - int i; - for (i = 7; i >= 0 && dst < end; i--) - { - // 1 means black, 0 means white - int data_value = (b & (1<= 0 && dst < end; i--) + { + // 1 means black, 0 means white + int data_value = (b & (1<= data) - { - *(--dst) = *(--src); - *(--dst) = *src; - *(--dst) = *src; - } - } + unsigned char *src = data + width * height; + unsigned char *dst = data + width * height * 3; + while (src >= data) + { + *(--dst) = *(--src); + *(--dst) = *src; + *(--dst) = *src; + } + } - // If we have a binary ppm, reading is very easy. - else if (ppmtype == 6) - { - int result = fread(data, width * height * 3, 1, fp); - if (result != 1) - { - fclose(fp); - delete[] data; - return ReadResult::FILE_NOT_HANDLED; - } - } + // If we have a binary ppm, reading is very easy. + else if (ppmtype == 6) + { + int result = fread(data, width * height * 3, 1, fp); + if (result != 1) + { + fclose(fp); + delete[] data; + return ReadResult::FILE_NOT_HANDLED; + } + } if (fp) fclose(fp); @@ -268,7 +268,7 @@ class ReaderWriterPNM : public osgDB::ReaderWriter GL_UNSIGNED_BYTE,// unsigned int dataType data, osg::Image::USE_NEW_DELETE); - pOsgImage->flipVertical(); + pOsgImage->flipVertical(); return pOsgImage; } diff --git a/src/osgPlugins/quicktime/ReaderWriterQT.cpp b/src/osgPlugins/quicktime/ReaderWriterQT.cpp index 91a8d1f83..33c2a2dcf 100644 --- a/src/osgPlugins/quicktime/ReaderWriterQT.cpp +++ b/src/osgPlugins/quicktime/ReaderWriterQT.cpp @@ -27,7 +27,7 @@ class ReaderWriterQT : public osgDB::ReaderWriter public: virtual const char* className() const { return "Default Quicktime Image Reader/Writer"; } - virtual bool acceptsMovieExtension(const std::string& extension) + virtual bool acceptsMovieExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"mov") || osgDB::equalCaseInsensitive(extension,"mpg") || @@ -35,7 +35,7 @@ class ReaderWriterQT : public osgDB::ReaderWriter osgDB::equalCaseInsensitive(extension,"dv"); } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { // this should be the only image importer required on the Mac // dont know what else it supports, but these will do @@ -54,7 +54,7 @@ class ReaderWriterQT : public osgDB::ReaderWriter acceptsMovieExtension(extension); } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options*) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options*) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/rgb/ReaderWriterRGB.cpp b/src/osgPlugins/rgb/ReaderWriterRGB.cpp index d4540919f..b2684bee3 100644 --- a/src/osgPlugins/rgb/ReaderWriterRGB.cpp +++ b/src/osgPlugins/rgb/ReaderWriterRGB.cpp @@ -345,7 +345,7 @@ class ReaderWriterRGB : public osgDB::ReaderWriter public: virtual const char* className() const { return "RGB Image Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"rgb") || osgDB::equalCaseInsensitive(extension,"sgi") || @@ -355,7 +355,7 @@ class ReaderWriterRGB : public osgDB::ReaderWriter osgDB::equalCaseInsensitive(extension,"bw"); } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; @@ -406,7 +406,7 @@ class ReaderWriterRGB : public osgDB::ReaderWriter } - virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options*) const { std::string ext = osgDB::getFileExtension(fileName); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/rot/ReaderWriterROT.cpp b/src/osgPlugins/rot/ReaderWriterROT.cpp index b977e22eb..969427ef5 100644 --- a/src/osgPlugins/rot/ReaderWriterROT.cpp +++ b/src/osgPlugins/rot/ReaderWriterROT.cpp @@ -54,13 +54,12 @@ public: virtual const char* className() const { return "rotation pseudo-loader"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive( extension, EXTENSION_NAME ); } - virtual ReadResult readNode(const std::string& fileName, - const osgDB::ReaderWriter::Options* /*options*/) + virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(fileName); if( !acceptsExtension(ext) ) @@ -98,7 +97,7 @@ public: } // recursively load the subfile. - osg::Node *node = osgDB::readNodeFile( subFileName ); + osg::Node *node = osgDB::readNodeFile( subFileName, options ); if( !node ) { // propagate the read failure upwards diff --git a/src/osgPlugins/scale/ReaderWriterSCALE.cpp b/src/osgPlugins/scale/ReaderWriterSCALE.cpp index 03ec9a544..7498e3157 100644 --- a/src/osgPlugins/scale/ReaderWriterSCALE.cpp +++ b/src/osgPlugins/scale/ReaderWriterSCALE.cpp @@ -56,13 +56,12 @@ public: virtual const char* className() const { return "scaling pseudo-loader"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive( extension, EXTENSION_NAME ); } - virtual ReadResult readNode(const std::string& fileName, - const osgDB::ReaderWriter::Options* /*options*/) + virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(fileName); if( !acceptsExtension(ext) ) @@ -106,7 +105,7 @@ public: } // recursively load the subfile. - osg::Node *node = osgDB::readNodeFile( subFileName ); + osg::Node *node = osgDB::readNodeFile( subFileName, options ); if( !node ) { // propagate the read failure upwards diff --git a/src/osgPlugins/stl/ReaderWriterSTL.cpp b/src/osgPlugins/stl/ReaderWriterSTL.cpp index b3f4b032d..3ff97151c 100644 --- a/src/osgPlugins/stl/ReaderWriterSTL.cpp +++ b/src/osgPlugins/stl/ReaderWriterSTL.cpp @@ -43,33 +43,38 @@ class ReaderWriterSTL : public osgDB::ReaderWriter { public: - ReaderWriterSTL() : _generateNormal(true), - _numFacets(0) { - } + ReaderWriterSTL() {} virtual const char* className() const { return "STL Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) { + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"stl") ? true : osgDB::equalCaseInsensitive(extension,"sta") ? true : false; } - virtual ReadResult readNode(const std::string& fileName, - const osgDB::ReaderWriter::Options*); + virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) const; private: - bool _generateNormal; - unsigned int _numFacets; - osg::ref_ptr _vertex; - osg::ref_ptr _normal; - osg::ref_ptr _color; + struct ReaderObject + { + ReaderObject(): + _generateNormal(true), + _numFacets(0) {} - bool readStlAscii(FILE* fp); - bool readStlBinary(FILE* fp); + bool _generateNormal; + unsigned int _numFacets; + + osg::ref_ptr _vertex; + osg::ref_ptr _normal; + osg::ref_ptr _color; + + bool readStlAscii(FILE* fp); + bool readStlBinary(FILE* fp); + }; }; @@ -102,8 +107,7 @@ const float StlColorDepth = float(StlColorSize); // 2^5 - 1 // Read node -osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& file, - const osgDB::ReaderWriter::Options* options) +osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; @@ -119,6 +123,8 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& fil return ReadResult::FILE_NOT_HANDLED; } + ReaderObject readerObject; + // assumes "unsigned int" is 4 bytes... StlHeader header; if (fread((void*) &header, sizeof(header), 1, fp) != 1) { @@ -142,7 +148,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& fil } if (stb.st_size == expectLen) { // assume binary - _numFacets = expectFacets; + readerObject._numFacets = expectFacets; isBinary = true; } else if (strstr(header.text, "solid") != 0) { @@ -157,30 +163,30 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& fil // read rewind(fp); - bool ok = (isBinary ? readStlBinary(fp) : readStlAscii(fp)); + bool ok = (isBinary ? readerObject.readStlBinary(fp) : readerObject.readStlAscii(fp)); fclose(fp); if (!ok) { return ReadResult::FILE_NOT_HANDLED; } - osg::notify(osg::NOTICE) << "### found " << _numFacets << " facets" << std::endl; + osg::notify(osg::NOTICE) << "### found " << readerObject._numFacets << " facets" << std::endl; /* * setup geometry */ osg::Geometry* geom = new osg::Geometry; - geom->setVertexArray(_vertex.get()); + geom->setVertexArray(readerObject._vertex.get()); - geom->setNormalArray(_normal.get()); + geom->setNormalArray(readerObject._normal.get()); geom->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE); - if (_color.valid()) { + if (readerObject._color.valid()) { osg::notify(osg::NOTICE) << "### with color" << std::endl; - geom->setColorArray(_color.get()); + geom->setColorArray(readerObject._color.get()); geom->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE); } - geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, _numFacets*3)); + geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, readerObject._numFacets*3)); osg::Geode* geode = new osg::Geode; geode->addDrawable(geom); @@ -195,7 +201,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& fil * **********************************************************************/ -bool ReaderWriterSTL::readStlAscii(FILE* fp) +bool ReaderWriterSTL::ReaderObject::readStlAscii(FILE* fp) { unsigned int vertexCount = 0; unsigned int facetIndex[] = { 0,0,0 }; @@ -272,7 +278,7 @@ bool ReaderWriterSTL::readStlAscii(FILE* fp) return true; } -bool ReaderWriterSTL::readStlBinary(FILE* fp) +bool ReaderWriterSTL::ReaderObject::readStlBinary(FILE* fp) { // seek to beginning of facets ::fseek(fp, sizeof_StlHeader, SEEK_SET); diff --git a/src/osgPlugins/tga/ReaderWriterTGA.cpp b/src/osgPlugins/tga/ReaderWriterTGA.cpp index 9fc6c1c41..1cb8a13bc 100644 --- a/src/osgPlugins/tga/ReaderWriterTGA.cpp +++ b/src/osgPlugins/tga/ReaderWriterTGA.cpp @@ -476,9 +476,9 @@ class ReaderWriterTGA : public osgDB::ReaderWriter { public: virtual const char* className() const { return "TGA Image Reader"; } - virtual bool acceptsExtension(const std::string& extension) { return osgDB::equalCaseInsensitive(extension,"tga"); } + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"tga"); } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/tgz/ReaderWriterTGZ.cpp b/src/osgPlugins/tgz/ReaderWriterTGZ.cpp index 4cfb701ba..2fcbfbe9b 100644 --- a/src/osgPlugins/tgz/ReaderWriterTGZ.cpp +++ b/src/osgPlugins/tgz/ReaderWriterTGZ.cpp @@ -26,12 +26,12 @@ class ReaderWriterTGZ : public osgDB::ReaderWriter public: virtual const char* className() const { return "TGZ Database Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"tgz"); } - virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/tiff/ReaderWriterTIFF.cpp b/src/osgPlugins/tiff/ReaderWriterTIFF.cpp index 9d9c1d559..7ecc1f4f1 100644 --- a/src/osgPlugins/tiff/ReaderWriterTIFF.cpp +++ b/src/osgPlugins/tiff/ReaderWriterTIFF.cpp @@ -413,14 +413,14 @@ class ReaderWriterTIFF : public osgDB::ReaderWriter { public: virtual const char* className() const { return "TIFF Image Reader"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { if( osgDB::equalCaseInsensitive(extension,"tiff")) return true; if( osgDB::equalCaseInsensitive(extension,"tif") ) return true; return false; } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/trans/ReaderWriterTRANS.cpp b/src/osgPlugins/trans/ReaderWriterTRANS.cpp index 516be5f10..4d9050f0b 100644 --- a/src/osgPlugins/trans/ReaderWriterTRANS.cpp +++ b/src/osgPlugins/trans/ReaderWriterTRANS.cpp @@ -54,13 +54,12 @@ public: virtual const char* className() const { return "translation pseudo-loader"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive( extension, EXTENSION_NAME ); } - virtual ReadResult readNode(const std::string& fileName, - const osgDB::ReaderWriter::Options* /*options*/) + virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(fileName); if( !acceptsExtension(ext) ) @@ -98,7 +97,7 @@ public: } // recursively load the subfile. - osg::Node *node = osgDB::readNodeFile( subFileName ); + osg::Node *node = osgDB::readNodeFile( subFileName, options ); if( !node ) { // propagate the read failure upwards diff --git a/src/osgPlugins/txp/ReaderWriterTXP.cpp b/src/osgPlugins/txp/ReaderWriterTXP.cpp index f4a586430..8ac256da7 100644 --- a/src/osgPlugins/txp/ReaderWriterTXP.cpp +++ b/src/osgPlugins/txp/ReaderWriterTXP.cpp @@ -19,10 +19,8 @@ using namespace txp; int ReaderWriterTXP::_archiveId = 0; -osgDB::ReaderWriter::ReadResult ReaderWriterTXP::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) +osgDB::ReaderWriter::ReadResult ReaderWriterTXP::local_readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) { - if( !acceptsExtension(osgDB::getFileExtension(file) )) - return ReadResult::FILE_NOT_HANDLED; std::string name = osgDB::getSimpleFileName(file); diff --git a/src/osgPlugins/txp/ReaderWriterTXP.h b/src/osgPlugins/txp/ReaderWriterTXP.h index 1ad48807b..73514d49c 100644 --- a/src/osgPlugins/txp/ReaderWriterTXP.h +++ b/src/osgPlugins/txp/ReaderWriterTXP.h @@ -43,6 +43,9 @@ #include #include +#include +#include + #include "TXPArchive.h" namespace txp @@ -55,20 +58,33 @@ public: return "TXP Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"txp"); } - virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*); + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const + { + if( !acceptsExtension(osgDB::getFileExtension(file) )) + return ReadResult::FILE_NOT_HANDLED; + + OpenThreads::ScopedLock lock(_serializerMutex); + + return const_cast(this)->local_readNode(file, options); + } protected: - TXPArchive *getArchive(int id, const std::string&); - std::map< int,osg::ref_ptr > _archives; - osg::Node* getTileContent(TXPArchive::TileInfo &info, int x, int y, int lod, TXPArchive* archive); + + ReadResult local_readNode(const std::string& file, const osgDB::ReaderWriter::Options* options); + + TXPArchive *getArchive(int id, const std::string&); + + osg::Node* getTileContent(TXPArchive::TileInfo &info, int x, int y, int lod, TXPArchive* archive); - static int _archiveId; + mutable osgDB::ReentrantMutex _serializerMutex; + std::map< int,osg::ref_ptr > _archives; + static int _archiveId; }; } // namespace diff --git a/src/osgPlugins/zip/ReaderWriterZIP.cpp b/src/osgPlugins/zip/ReaderWriterZIP.cpp index 2a09fdba3..bab820254 100644 --- a/src/osgPlugins/zip/ReaderWriterZIP.cpp +++ b/src/osgPlugins/zip/ReaderWriterZIP.cpp @@ -24,12 +24,12 @@ class ReaderWriterZIP : public osgDB::ReaderWriter public: virtual const char* className() const { return "ZIP Database Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) + virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"zip"); } - virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(file); diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index 6377fdef6..e335ffff4 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -68,7 +68,7 @@ osgText::Font* osgText::readFontFile(const std::string& filename) if (foundFile.empty()) return 0; osg::ref_ptr options = new osgDB::ReaderWriter::Options; - options->setUseObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_OBJECTS); + options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_OBJECTS); osg::Object* object = osgDB::readObjectFile(foundFile, options.get());