diff --git a/include/osgDB/ReaderWriter b/include/osgDB/ReaderWriter index 718d90a1c..77c8b54e1 100644 --- a/include/osgDB/ReaderWriter +++ b/include/osgDB/ReaderWriter @@ -22,13 +22,32 @@ class OSGDB_EXPORT ReaderWriter : public osg::Referenced virtual const char* className() = 0; virtual bool acceptsExtension(const std::string& /*extension*/) { return false; } - virtual osg::Object* readObject(const std::string& /*fileName*/) { return NULL; } - virtual osg::Image* readImage(const std::string& /*fileName*/) { return NULL; } - virtual osg::Node* readNode(const std::string& /*fileName*/) { return NULL; } + class Options : public osg::Referenced + { + public: - virtual bool writeObject(const osg::Object& /*obj*/,const std::string& /*fileName*/) {return false; } - virtual bool writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/) {return false; } - virtual bool writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/) { return false; } + Options() {} + Options(const std::string& str):_str(str) {} + + void setOptionString(const std::string& str) { _str = str; } + const std::string& getOptionString() const { return _str; } + + protected: + + virtual ~Options() {} + + std::string _str; + + }; + + + virtual osg::Object* readObject(const std::string& /*fileName*/,const Options* =NULL) { return NULL; } + virtual osg::Image* readImage(const std::string& /*fileName*/,const Options* =NULL) { return NULL; } + virtual osg::Node* readNode(const std::string& /*fileName*/,const Options* =NULL) { return NULL; } + + virtual bool writeObject(const osg::Object& /*obj*/,const std::string& /*fileName*/,const Options* =NULL) {return false; } + virtual bool writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const Options* =NULL) {return false; } + virtual bool writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options* =NULL) { return false; } }; diff --git a/include/osgDB/Registry b/include/osgDB/Registry index 69aed3199..ba1255e91 100644 --- a/include/osgDB/Registry +++ b/include/osgDB/Registry @@ -85,6 +85,11 @@ class OSGDB_EXPORT Registry void setCreateNodeFromImage(bool flag) { _createNodeFromImage = flag; } bool getCreateNodeFromImage() const { return _createNodeFromImage; } + void setOptions(ReaderWriter::Options* opt) { _options = opt; } + ReaderWriter::Options* getOptions() { return _options.get(); } + const ReaderWriter::Options* getOptions() const { return _options.get(); } + + private: typedef std::map > DotOsgWrapperMap; @@ -120,6 +125,9 @@ class OSGDB_EXPORT Registry // map to alias to extensions to plugins. ExtensionAliasMap _extAliasMap; + + // options to pass to reader writers. + osg::ref_ptr _options; }; diff --git a/src/Demos/sgv/sgv.cpp b/src/Demos/sgv/sgv.cpp index d872c63bd..4fbc081e9 100644 --- a/src/Demos/sgv/sgv.cpp +++ b/src/Demos/sgv/sgv.cpp @@ -298,6 +298,12 @@ int main( int argc, char **argv ) osg::Timer timer; osg::Timer_t before_load = timer.tick(); + // comment out right now, but the following allos users to pass option data to + // the ReaderWriter plugins. By default the options are set to NULL. The basic + // osgDB::ReaderWriter::Options stucture has just a string, but this can be + // subclassed to extend it to handle any options that a user desires. + // osgDB::Registry::instance()->setOptions(new osgDB::ReaderWriter::Options("test options")); + osg::Node* rootnode = getNodeFromFiles( argc, argv); osg::Timer_t after_load = timer.tick(); diff --git a/src/osgDB/Registry.cpp b/src/osgDB/Registry.cpp index 93d02da30..7f21a2f7e 100644 --- a/src/osgDB/Registry.cpp +++ b/src/osgDB/Registry.cpp @@ -567,7 +567,7 @@ Object* Registry::readObject(const std::string& fileName) ++itr) { rwOriginal.insert(itr->get()); - Object* obj = (*itr)->readObject(file); + Object* obj = (*itr)->readObject(file,_options.get()); if (obj) return obj; } @@ -581,7 +581,7 @@ Object* Registry::readObject(const std::string& fileName) { if (rwOriginal.find(itr->get())==rwOriginal.end()) { - Object* obj = (*itr)->readObject(file); + Object* obj = (*itr)->readObject(file,_options.get()); if (obj) return obj; } } @@ -608,7 +608,7 @@ bool Registry::writeObject(const Object& obj,const std::string& fileName) ++itr) { rwOriginal.insert(itr->get()); - if ((*itr)->writeObject(obj,fileName)) return true; + if ((*itr)->writeObject(obj,fileName,_options.get())) return true; } // now look for a plug-in to save the file. @@ -621,7 +621,7 @@ bool Registry::writeObject(const Object& obj,const std::string& fileName) { if (rwOriginal.find(itr->get())==rwOriginal.end()) { - if ((*itr)->writeObject(obj,fileName)) return true; + if ((*itr)->writeObject(obj,fileName,_options.get())) return true; } } } @@ -651,7 +651,7 @@ Image* Registry::readImage(const std::string& fileName) ++itr) { rwOriginal.insert(itr->get()); - Image* image = (*itr)->readImage(file); + Image* image = (*itr)->readImage(file,_options.get()); if (image) return image; } @@ -665,7 +665,7 @@ Image* Registry::readImage(const std::string& fileName) { if (rwOriginal.find(itr->get())==rwOriginal.end()) { - Image* image = (*itr)->readImage(file); + Image* image = (*itr)->readImage(file,_options.get()); if (image) return image; } } @@ -692,7 +692,7 @@ bool Registry::writeImage(const Image& image,const std::string& fileName) ++itr) { rwOriginal.insert(itr->get()); - if ((*itr)->writeImage(image,fileName)) return true; + if ((*itr)->writeImage(image,fileName,_options.get())) return true; } // now look for a plug-in to save the file. @@ -705,7 +705,7 @@ bool Registry::writeImage(const Image& image,const std::string& fileName) { if (rwOriginal.find(itr->get())==rwOriginal.end()) { - if ((*itr)->writeImage(image,fileName)) return true; + if ((*itr)->writeImage(image,fileName,_options.get())) return true; } } } @@ -735,7 +735,7 @@ Node* Registry::readNode(const std::string& fileName) ++itr) { rwOriginal.insert(itr->get()); - Node* node = (*itr)->readNode(file); + Node* node = (*itr)->readNode(file,_options.get()); if (node) return node; } @@ -752,7 +752,7 @@ Node* Registry::readNode(const std::string& fileName) { if (rwOriginal.find(itr->get())==rwOriginal.end()) { - Node* node = (*itr)->readNode(file); + Node* node = (*itr)->readNode(file,_options.get()); if (node) return node; } } @@ -794,7 +794,7 @@ bool Registry::writeNode(const Node& node,const std::string& fileName) ++itr) { rwOriginal.insert(itr->get()); - if ((*itr)->writeNode(node,fileName)) return true; + if ((*itr)->writeNode(node,fileName,_options.get())) return true; } // now look for a plug-in to save the file. @@ -807,7 +807,7 @@ bool Registry::writeNode(const Node& node,const std::string& fileName) { if (rwOriginal.find(itr->get())==rwOriginal.end()) { - if ((*itr)->writeNode(node,fileName)) return true; + if ((*itr)->writeNode(node,fileName,_options.get())) return true; } } } diff --git a/src/osgPlugins/bmp/ReaderWriterBMP.cpp b/src/osgPlugins/bmp/ReaderWriterBMP.cpp index 6c66aea2a..78b522b02 100644 --- a/src/osgPlugins/bmp/ReaderWriterBMP.cpp +++ b/src/osgPlugins/bmp/ReaderWriterBMP.cpp @@ -290,7 +290,7 @@ class ReaderWriterBMP : public osgDB::ReaderWriter virtual const char* className() { return "BMP Image Reader"; } virtual bool acceptsExtension(const std::string& extension) { return extension=="bmp"; } - virtual osg::Image* readImage(const std::string& fileName) + virtual osg::Image* readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) { unsigned char *imageData = NULL; diff --git a/src/osgPlugins/flt/ReaderWriterFLT.cpp b/src/osgPlugins/flt/ReaderWriterFLT.cpp index 24f522aba..471d046da 100644 --- a/src/osgPlugins/flt/ReaderWriterFLT.cpp +++ b/src/osgPlugins/flt/ReaderWriterFLT.cpp @@ -14,7 +14,7 @@ using namespace flt; -osg::Object* ReaderWriterFLT::readObject(const std::string& fileName) +osg::Object* ReaderWriterFLT::readObject(const std::string& fileName, const osgDB::ReaderWriter::Options*) { FltFile read; @@ -22,7 +22,7 @@ osg::Object* ReaderWriterFLT::readObject(const std::string& fileName) } -osg::Node* ReaderWriterFLT::readNode(const std::string& fileName) +osg::Node* ReaderWriterFLT::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) { FltFile read; diff --git a/src/osgPlugins/flt/ReaderWriterFLT.h b/src/osgPlugins/flt/ReaderWriterFLT.h index 8d86644e3..d930d5bde 100644 --- a/src/osgPlugins/flt/ReaderWriterFLT.h +++ b/src/osgPlugins/flt/ReaderWriterFLT.h @@ -54,8 +54,8 @@ public: return osgDB::equalCaseInsensitive(extension,"flt"); } - virtual osg::Object* readObject(const std::string& fileName); - virtual osg::Node* readNode(const std::string& fileName); + virtual osg::Object* readObject(const std::string& fileName, const ReaderWriter::Options*); + virtual osg::Node* readNode(const std::string& fileName, const ReaderWriter::Options*); }; diff --git a/src/osgPlugins/gif/ReaderWriterGIF.cpp b/src/osgPlugins/gif/ReaderWriterGIF.cpp index 2be1b9e59..8b143ba51 100644 --- a/src/osgPlugins/gif/ReaderWriterGIF.cpp +++ b/src/osgPlugins/gif/ReaderWriterGIF.cpp @@ -323,7 +323,7 @@ class ReaderWriterGIF : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"gif"); } - virtual osg::Image* readImage(const std::string& fileName) + virtual osg::Image* readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) { unsigned char *imageData = NULL; diff --git a/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp b/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp index 56f6a7cbb..53595e7f5 100644 --- a/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp +++ b/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp @@ -308,7 +308,7 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"jpeg"); } - virtual osg::Image* readImage(const std::string& fileName) + virtual osg::Image* readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) { unsigned char *imageData = NULL; diff --git a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp index 0ffe0108f..0c086a78c 100644 --- a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp +++ b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp @@ -32,7 +32,7 @@ class ReaderWriter3DS : public osgDB::ReaderWriter virtual const char* className() { return "3DS Auto Studio Reader"; } virtual bool acceptsExtension(const std::string& extension) { return extension=="3ds"; } - virtual osg::Node* readNode(const std::string& fileName); + virtual osg::Node* readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*); typedef std::vector FaceList; typedef std::map GeoStateMap; @@ -59,7 +59,7 @@ ReaderWriter3DS::ReaderWriter3DS() } -osg::Node* ReaderWriter3DS::readNode(const std::string& fileName) +osg::Node* ReaderWriter3DS::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) { Lib3dsFile *f = lib3ds_open(fileName.c_str()); diff --git a/src/osgPlugins/lwo/ReaderWriterLWO.cpp b/src/osgPlugins/lwo/ReaderWriterLWO.cpp index db84673bb..8398f3df9 100644 --- a/src/osgPlugins/lwo/ReaderWriterLWO.cpp +++ b/src/osgPlugins/lwo/ReaderWriterLWO.cpp @@ -43,7 +43,7 @@ public: return (extension == "lwo" || extension == "lw" || extension == "geo"); } - virtual osg::Node* readNode(const std::string& fileName); + virtual osg::Node* readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*); protected: }; @@ -54,7 +54,7 @@ osgDB::RegisterReaderWriterProxy g_lwoReaderWriterProxy; // read file and convert to OSG. -osg::Node* ReaderWriterLWO::readNode(const std::string& fileName) +osg::Node* ReaderWriterLWO::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) { lwObject* lw = lw_object_read(fileName.c_str()); if (!lw) diff --git a/src/osgPlugins/obj/ReaderWriterOBJ.cpp b/src/osgPlugins/obj/ReaderWriterOBJ.cpp index 7e114be3e..8aa194703 100644 --- a/src/osgPlugins/obj/ReaderWriterOBJ.cpp +++ b/src/osgPlugins/obj/ReaderWriterOBJ.cpp @@ -48,7 +48,7 @@ public: return (extension == "obj"); } - virtual osg::Node* readNode(const std::string& fileName); + virtual osg::Node* readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*); protected: osg::Drawable* makeDrawable(GLMmodel* obj, GLMgroup* grp, osg::StateSet**); @@ -60,7 +60,7 @@ osgDB::RegisterReaderWriterProxy g_objReaderWriterProxy; // read file and convert to OSG. -osg::Node* ReaderWriterOBJ::readNode(const std::string& fileName) +osg::Node* ReaderWriterOBJ::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) { GLMmodel* obj = glmReadOBJ((char*) fileName.c_str()); if (!obj) diff --git a/src/osgPlugins/osg/ReaderWriterOSG.cpp b/src/osgPlugins/osg/ReaderWriterOSG.cpp index 843a36fb4..c4186db23 100644 --- a/src/osgPlugins/osg/ReaderWriterOSG.cpp +++ b/src/osgPlugins/osg/ReaderWriterOSG.cpp @@ -19,9 +19,9 @@ class OSGReaderWriter : public ReaderWriter return equalCaseInsensitive(extension,"osg"); } - virtual Object* readObject(const std::string& fileName) { return readNode(fileName); } + virtual Object* readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* opt) { return readNode(fileName,opt); } - virtual Node* readNode(const std::string& fileName) + virtual Node* readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) { std::string ext = getFileExtension(fileName); if (!acceptsExtension(ext)) return NULL; diff --git a/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp b/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp index 4835e274c..e0f449e1e 100644 --- a/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp +++ b/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp @@ -30,7 +30,7 @@ class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"osgtgz"); } - virtual Node* readNode(const std::string& fileName) + virtual Node* readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) { std::string ext = osgDB::getFileExtension(fileName); if (!acceptsExtension(ext)) return NULL; diff --git a/src/osgPlugins/pic/ReaderWriterPIC.cpp b/src/osgPlugins/pic/ReaderWriterPIC.cpp index 2b00ea377..5bb22d52a 100644 --- a/src/osgPlugins/pic/ReaderWriterPIC.cpp +++ b/src/osgPlugins/pic/ReaderWriterPIC.cpp @@ -189,7 +189,7 @@ class ReaderWriterPIC : public osgDB::ReaderWriter virtual const char* className() { return "PIC Image Reader"; } virtual bool acceptsExtension(const std::string& extension) { return extension=="pic"; } - virtual osg::Image* readImage(const std::string& fileName) + virtual osg::Image* readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) { unsigned char *imageData = NULL; diff --git a/src/osgPlugins/png/ReaderWriterPNG.cpp b/src/osgPlugins/png/ReaderWriterPNG.cpp index 03ee1da1e..5fe5497d1 100644 --- a/src/osgPlugins/png/ReaderWriterPNG.cpp +++ b/src/osgPlugins/png/ReaderWriterPNG.cpp @@ -32,7 +32,7 @@ class ReaderWriterPNG : public osgDB::ReaderWriter virtual const char* className() { return "PNG Image Reader/Writer"; } virtual bool acceptsExtension(const std::string& extension) { return extension=="png"; } - virtual Image* readImage(const std::string& fileName) + virtual Image* readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) { int trans = PNG_ALPHA; diff --git a/src/osgPlugins/rgb/ReaderWriterRGB.cpp b/src/osgPlugins/rgb/ReaderWriterRGB.cpp index 0e1119f10..603e7a6d8 100644 --- a/src/osgPlugins/rgb/ReaderWriterRGB.cpp +++ b/src/osgPlugins/rgb/ReaderWriterRGB.cpp @@ -304,11 +304,11 @@ class ReaderWriterRGB : public osgDB::ReaderWriter osgDB::equalCaseInsensitive(extension,"bw"); } - virtual Image* readImage(const std::string& fileName) + virtual Image* readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) { std::string ext = osgDB::getFileExtension(fileName); if (!acceptsExtension(ext)) return NULL; - + rawImageRec *raw; if( (raw = RawImageOpen(fileName.c_str())) == NULL ) diff --git a/src/osgPlugins/tga/ReaderWriterTGA.cpp b/src/osgPlugins/tga/ReaderWriterTGA.cpp index e34056430..6b5c67a6f 100644 --- a/src/osgPlugins/tga/ReaderWriterTGA.cpp +++ b/src/osgPlugins/tga/ReaderWriterTGA.cpp @@ -469,7 +469,7 @@ class ReaderWriterTGA : public osgDB::ReaderWriter virtual const char* className() { return "TGA Image Reader"; } virtual bool acceptsExtension(const std::string& extension) { return extension=="tga"; } - virtual osg::Image* readImage(const std::string& fileName) + virtual osg::Image* readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) { unsigned char *imageData = NULL; diff --git a/src/osgPlugins/tgz/ReaderWriterTGZ.cpp b/src/osgPlugins/tgz/ReaderWriterTGZ.cpp index a78139665..ba12b147a 100644 --- a/src/osgPlugins/tgz/ReaderWriterTGZ.cpp +++ b/src/osgPlugins/tgz/ReaderWriterTGZ.cpp @@ -31,7 +31,7 @@ class ReaderWriterTGZ : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"tgz"); } - virtual Node* readNode(const std::string& fileName) + virtual Node* readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) { std::string ext = osgDB::getLowerCaseFileExtension(fileName); if (!acceptsExtension(ext)) return NULL; diff --git a/src/osgPlugins/tiff/ReaderWriterTIFF.cpp b/src/osgPlugins/tiff/ReaderWriterTIFF.cpp index be96c1788..5ee9e5d14 100644 --- a/src/osgPlugins/tiff/ReaderWriterTIFF.cpp +++ b/src/osgPlugins/tiff/ReaderWriterTIFF.cpp @@ -405,7 +405,7 @@ class ReaderWriterTIFF : public osgDB::ReaderWriter virtual const char* className() { return "TIFF Image Reader"; } virtual bool acceptsExtension(const std::string& extension) { return extension=="tiff"; } - virtual osg::Image* readImage(const std::string& fileName) + virtual osg::Image* readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) { unsigned char *imageData = NULL; diff --git a/src/osgPlugins/zip/ReaderWriterZIP.cpp b/src/osgPlugins/zip/ReaderWriterZIP.cpp index 98ff4e6b8..9daf1c38f 100644 --- a/src/osgPlugins/zip/ReaderWriterZIP.cpp +++ b/src/osgPlugins/zip/ReaderWriterZIP.cpp @@ -29,7 +29,7 @@ class ReaderWriterZIP : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"zip"); } - virtual osg::Node* readNode(const std::string& fileName) + virtual osg::Node* readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) { std::string ext = osgDB::getLowerCaseFileExtension(fileName);