Added osgDB::ReaderWriter::Options class to the ReaderWriter base class, support

for settings options in osgDB::Registry, and added the paramter to all of the
reaader/writer plugins.  The Options structure by default has an string attached
for packing basic options, however, it also can be subclassed to encapsulate
any users defined option data. In the later case both the client code *and*
the plugin need to be aware of subclass, the plugin will need to use
dynamic_cast<> to assertain its type.
This commit is contained in:
Robert Osfield
2001-10-14 17:54:25 +00:00
parent e719569b42
commit 06dafa487e
21 changed files with 75 additions and 42 deletions

View File

@@ -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; }
};

View File

@@ -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<std::string,osg::ref_ptr<DotOsgWrapper> > 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<ReaderWriter::Options> _options;
};

View File

@@ -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();

View File

@@ -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;
}
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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*);
};

View File

@@ -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;

View File

@@ -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;

View File

@@ -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<int> FaceList;
typedef std::map<std::string,osg::StateSet*> 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());

View File

@@ -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<ReaderWriterLWO> 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)

View File

@@ -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<ReaderWriterOBJ> 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)

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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 )

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);