Added support for ReadResult and WriteResult to the osgDB::ReaderWriter
to allo plugins to pass back more information about the success or failure of a file load. All plugins have been updated to the new convention.
This commit is contained in:
parent
97e4488d80
commit
f0372817b5
@ -41,13 +41,87 @@ class OSGDB_EXPORT ReaderWriter : public osg::Referenced
|
||||
};
|
||||
|
||||
|
||||
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; }
|
||||
class ReadResult
|
||||
{
|
||||
public:
|
||||
|
||||
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; }
|
||||
enum Status
|
||||
{
|
||||
FILE_NOT_HANDLED,
|
||||
FILE_LOADED,
|
||||
ERROR_IN_READING_FILE
|
||||
};
|
||||
|
||||
ReadResult(Status status=FILE_NOT_HANDLED):_status(status) {}
|
||||
ReadResult(const std::string& m):_status(ERROR_IN_READING_FILE),_message(m) {}
|
||||
ReadResult(osg::Object* obj):_status(FILE_LOADED),_object(obj) {}
|
||||
|
||||
ReadResult(const ReadResult& rr):_status(rr._status),_message(rr._message),_object(rr._object) {}
|
||||
ReadResult& operator = (const ReadResult& rr) { if (this==&rr) return *this; _status=rr._status; _message=rr._message;_object=rr._object; return *this; }
|
||||
|
||||
osg::Object* getObject() { return _object.get(); }
|
||||
osg::Image* getImage() { return dynamic_cast<osg::Image*>(_object.get()); }
|
||||
osg::Node* getNode() { return dynamic_cast<osg::Node*>(_object.get()); }
|
||||
|
||||
const bool validObject() { return _object.valid(); }
|
||||
const bool validImage() { return getImage()!=0; }
|
||||
const bool validNode() { return getNode()!=0; }
|
||||
|
||||
osg::Object* takeObject() { osg::Object* obj = _object.get(); if (obj) { obj->ref(); _object=NULL; } return obj; }
|
||||
osg::Image* takeImage() { osg::Image* image=dynamic_cast<osg::Image*>(_object.get()); if (image) { image->ref(); _object==NULL; } return image; }
|
||||
osg::Node* takeNode() { osg::Node* node=dynamic_cast<osg::Node*>(_object.get()); if (node) { node->ref(); _object==NULL; } return node; }
|
||||
|
||||
const std::string& message() const { return _message; }
|
||||
|
||||
const Status status() const { return _status; }
|
||||
const bool success() const { return _status==FILE_LOADED; }
|
||||
const bool error() const { return _status==ERROR_IN_READING_FILE; }
|
||||
const bool notHandled() const { return _status==FILE_NOT_HANDLED; }
|
||||
|
||||
protected:
|
||||
|
||||
Status _status;
|
||||
std::string _message;
|
||||
osg::ref_ptr<osg::Object> _object;
|
||||
};
|
||||
|
||||
class WriteResult
|
||||
{
|
||||
public:
|
||||
|
||||
enum Status
|
||||
{
|
||||
FILE_NOT_HANDLED,
|
||||
FILE_SAVED,
|
||||
ERROR_IN_WRITING_FILE
|
||||
};
|
||||
|
||||
WriteResult(Status status=FILE_NOT_HANDLED):_status(status) {}
|
||||
WriteResult(const std::string& m):_status(ERROR_IN_WRITING_FILE),_message(m) {}
|
||||
|
||||
WriteResult(const WriteResult& rr):_status(rr._status),_message(rr._message) {}
|
||||
WriteResult& operator = (const WriteResult& rr) { if (this==&rr) return *this; _status=rr._status; _message=rr._message; return *this; }
|
||||
|
||||
const std::string& message() const { return _message; }
|
||||
|
||||
const Status status() const { return _status; }
|
||||
const bool success() const { return _status==FILE_SAVED; }
|
||||
const bool error() const { return _status==ERROR_IN_WRITING_FILE; }
|
||||
const bool notHandled() const { return _status==FILE_NOT_HANDLED; }
|
||||
|
||||
protected:
|
||||
|
||||
Status _status;
|
||||
std::string _message;
|
||||
};
|
||||
|
||||
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 readNode(const std::string& /*fileName*/,const Options* =NULL) { 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 writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options* =NULL) { return WriteResult(WriteResult::FILE_NOT_HANDLED); }
|
||||
};
|
||||
|
||||
|
||||
|
@ -561,14 +561,19 @@ Object* Registry::readObject(const std::string& fileName)
|
||||
// record the existing reader writer.
|
||||
std::set<ReaderWriter*> rwOriginal;
|
||||
|
||||
// record the errors reported by readerwriters.
|
||||
typedef std::vector<ReaderWriter::ReadResult> Results;
|
||||
Results results;
|
||||
|
||||
// first attempt to load the file from existing ReaderWriter's
|
||||
for(ReaderWriterList::iterator itr=_rwList.begin();
|
||||
itr!=_rwList.end();
|
||||
++itr)
|
||||
{
|
||||
rwOriginal.insert(itr->get());
|
||||
Object* obj = (*itr)->readObject(file,_options.get());
|
||||
if (obj) return obj;
|
||||
ReaderWriter::ReadResult rr = (*itr)->readObject(file,_options.get());
|
||||
if (rr.validObject()) return rr.takeObject();
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
|
||||
// now look for a plug-in to load the file.
|
||||
@ -581,17 +586,27 @@ Object* Registry::readObject(const std::string& fileName)
|
||||
{
|
||||
if (rwOriginal.find(itr->get())==rwOriginal.end())
|
||||
{
|
||||
Object* obj = (*itr)->readObject(file,_options.get());
|
||||
if (obj) return obj;
|
||||
ReaderWriter::ReadResult rr = (*itr)->readObject(file,_options.get());
|
||||
if (rr.validObject()) return rr.takeObject();
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (results.empty())
|
||||
{
|
||||
notify(NOTICE)<<"Warning: Could not find plugin to read file with extension ."
|
||||
<<getLowerCaseFileExtension(fileName)<<endl;
|
||||
}
|
||||
notify(NOTICE)<<"Warning: Unable to read file "<<fileName<<endl;
|
||||
else
|
||||
{
|
||||
for(Results::iterator itr=results.begin();
|
||||
itr!=results.end();
|
||||
++itr)
|
||||
{
|
||||
notify(NOTICE)<<itr->message()<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -602,13 +617,19 @@ bool Registry::writeObject(const Object& obj,const std::string& fileName)
|
||||
// record the existing reader writer.
|
||||
std::set<ReaderWriter*> rwOriginal;
|
||||
|
||||
// record the errors reported by readerwriters.
|
||||
typedef std::vector<ReaderWriter::WriteResult> Results;
|
||||
Results results;
|
||||
|
||||
// first attempt to load the file from existing ReaderWriter's
|
||||
for(ReaderWriterList::iterator itr=_rwList.begin();
|
||||
itr!=_rwList.end();
|
||||
++itr)
|
||||
{
|
||||
rwOriginal.insert(itr->get());
|
||||
if ((*itr)->writeObject(obj,fileName,_options.get())) return true;
|
||||
ReaderWriter::WriteResult rr = (*itr)->writeObject(obj,fileName,_options.get());
|
||||
if (rr.success()) return true;
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
|
||||
// now look for a plug-in to save the file.
|
||||
@ -621,16 +642,27 @@ bool Registry::writeObject(const Object& obj,const std::string& fileName)
|
||||
{
|
||||
if (rwOriginal.find(itr->get())==rwOriginal.end())
|
||||
{
|
||||
if ((*itr)->writeObject(obj,fileName,_options.get())) return true;
|
||||
ReaderWriter::WriteResult rr = (*itr)->writeObject(obj,fileName,_options.get());
|
||||
if (rr.success()) return true;
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (results.empty())
|
||||
{
|
||||
notify(NOTICE)<<"Warning: Could not find plugin to write file with extension ."
|
||||
<<getLowerCaseFileExtension(fileName)<<endl;
|
||||
}
|
||||
notify(NOTICE)<<"Warning: Unable to write file "<<fileName<<endl;
|
||||
else
|
||||
{
|
||||
for(Results::iterator itr=results.begin();
|
||||
itr!=results.end();
|
||||
++itr)
|
||||
{
|
||||
notify(NOTICE)<<itr->message()<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -645,14 +677,19 @@ Image* Registry::readImage(const std::string& fileName)
|
||||
// record the existing reader writer.
|
||||
std::set<ReaderWriter*> rwOriginal;
|
||||
|
||||
// record the errors reported by readerwriters.
|
||||
typedef std::vector<ReaderWriter::ReadResult> Results;
|
||||
Results results;
|
||||
|
||||
// first attempt to load the file from existing ReaderWriter's
|
||||
for(ReaderWriterList::iterator itr=_rwList.begin();
|
||||
itr!=_rwList.end();
|
||||
++itr)
|
||||
{
|
||||
rwOriginal.insert(itr->get());
|
||||
Image* image = (*itr)->readImage(file,_options.get());
|
||||
if (image) return image;
|
||||
ReaderWriter::ReadResult rr = (*itr)->readImage(file,_options.get());
|
||||
if (rr.validImage()) return rr.takeImage();
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
|
||||
// now look for a plug-in to load the file.
|
||||
@ -665,17 +702,27 @@ Image* Registry::readImage(const std::string& fileName)
|
||||
{
|
||||
if (rwOriginal.find(itr->get())==rwOriginal.end())
|
||||
{
|
||||
Image* image = (*itr)->readImage(file,_options.get());
|
||||
if (image) return image;
|
||||
ReaderWriter::ReadResult rr = (*itr)->readImage(file,_options.get());
|
||||
if (rr.validImage()) return rr.takeImage();
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (results.empty())
|
||||
{
|
||||
notify(NOTICE)<<"Warning: Could not find plugin to read file with extension ."
|
||||
<<getLowerCaseFileExtension(fileName)<<endl;
|
||||
}
|
||||
notify(NOTICE)<<"Warning: Unable to read file "<<fileName<<endl;
|
||||
else
|
||||
{
|
||||
for(Results::iterator itr=results.begin();
|
||||
itr!=results.end();
|
||||
++itr)
|
||||
{
|
||||
notify(NOTICE)<<itr->message()<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -686,13 +733,19 @@ bool Registry::writeImage(const Image& image,const std::string& fileName)
|
||||
// record the existing reader writer.
|
||||
std::set<ReaderWriter*> rwOriginal;
|
||||
|
||||
// record the errors reported by readerwriters.
|
||||
typedef std::vector<ReaderWriter::WriteResult> Results;
|
||||
Results results;
|
||||
|
||||
// first attempt to load the file from existing ReaderWriter's
|
||||
for(ReaderWriterList::iterator itr=_rwList.begin();
|
||||
itr!=_rwList.end();
|
||||
++itr)
|
||||
{
|
||||
rwOriginal.insert(itr->get());
|
||||
if ((*itr)->writeImage(image,fileName,_options.get())) return true;
|
||||
ReaderWriter::WriteResult rr = (*itr)->writeImage(image,fileName,_options.get());
|
||||
if (rr.success()) return true;
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
|
||||
// now look for a plug-in to save the file.
|
||||
@ -705,16 +758,27 @@ bool Registry::writeImage(const Image& image,const std::string& fileName)
|
||||
{
|
||||
if (rwOriginal.find(itr->get())==rwOriginal.end())
|
||||
{
|
||||
if ((*itr)->writeImage(image,fileName,_options.get())) return true;
|
||||
ReaderWriter::WriteResult rr = (*itr)->writeImage(image,fileName,_options.get());
|
||||
if (rr.success()) return true;
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (results.empty())
|
||||
{
|
||||
notify(NOTICE)<<"Warning: Could not find plugin to write file with extension ."
|
||||
<<getLowerCaseFileExtension(fileName)<<endl;
|
||||
}
|
||||
notify(NOTICE)<<"Warning: Unable to write file "<<fileName<<endl;
|
||||
else
|
||||
{
|
||||
for(Results::iterator itr=results.begin();
|
||||
itr!=results.end();
|
||||
++itr)
|
||||
{
|
||||
notify(NOTICE)<<itr->message()<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -729,14 +793,19 @@ Node* Registry::readNode(const std::string& fileName)
|
||||
// record the existing reader writer.
|
||||
std::set<ReaderWriter*> rwOriginal;
|
||||
|
||||
// record the errors reported by readerwriters.
|
||||
typedef std::vector<ReaderWriter::ReadResult> Results;
|
||||
Results results;
|
||||
|
||||
// first attempt to load the file from existing ReaderWriter's
|
||||
for(ReaderWriterList::iterator itr=_rwList.begin();
|
||||
itr!=_rwList.end();
|
||||
++itr)
|
||||
{
|
||||
rwOriginal.insert(itr->get());
|
||||
Node* node = (*itr)->readNode(file,_options.get());
|
||||
if (node) return node;
|
||||
ReaderWriter::ReadResult rr = (*itr)->readNode(file,_options.get());
|
||||
if (rr.validNode()) return rr.takeNode();
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
|
||||
bool couldNotFindPlugin = false;
|
||||
@ -752,8 +821,9 @@ Node* Registry::readNode(const std::string& fileName)
|
||||
{
|
||||
if (rwOriginal.find(itr->get())==rwOriginal.end())
|
||||
{
|
||||
Node* node = (*itr)->readNode(file,_options.get());
|
||||
if (node) return node;
|
||||
ReaderWriter::ReadResult rr = (*itr)->readNode(file,_options.get());
|
||||
if (rr.validNode()) return rr.takeNode();
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -762,22 +832,38 @@ Node* Registry::readNode(const std::string& fileName)
|
||||
couldNotFindPlugin = true;
|
||||
}
|
||||
|
||||
if (_createNodeFromImage)
|
||||
{
|
||||
ref_ptr<Image> image = readImage(fileName);
|
||||
if (image.valid())
|
||||
{
|
||||
return createGeodeForImage(image.get());
|
||||
}
|
||||
}
|
||||
//
|
||||
// if (_createNodeFromImage)
|
||||
// {
|
||||
// ref_ptr<Image> image = readImage(fileName);
|
||||
// if (image.valid())
|
||||
// {
|
||||
// return createGeodeForImage(image.get());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (couldNotFindPlugin)
|
||||
// {
|
||||
// notify(NOTICE)<<"Warning: Could not find plugin to read file with extension ."
|
||||
// <<getLowerCaseFileExtension(fileName)<<endl;
|
||||
// }
|
||||
//
|
||||
// notify(NOTICE)<<"Warning: Unable to read file "<<fileName<<endl;
|
||||
|
||||
if (couldNotFindPlugin)
|
||||
if (results.empty())
|
||||
{
|
||||
notify(NOTICE)<<"Warning: Could not find plugin to read file with extension ."
|
||||
<<getLowerCaseFileExtension(fileName)<<endl;
|
||||
}
|
||||
|
||||
notify(NOTICE)<<"Warning: Unable to read file "<<fileName<<endl;
|
||||
else
|
||||
{
|
||||
for(Results::iterator itr=results.begin();
|
||||
itr!=results.end();
|
||||
++itr)
|
||||
{
|
||||
notify(NOTICE)<<itr->message()<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -788,13 +874,19 @@ bool Registry::writeNode(const Node& node,const std::string& fileName)
|
||||
// record the existing reader writer.
|
||||
std::set<ReaderWriter*> rwOriginal;
|
||||
|
||||
// record the errors reported by readerwriters.
|
||||
typedef std::vector<ReaderWriter::WriteResult> Results;
|
||||
Results results;
|
||||
|
||||
// first attempt to write the file from existing ReaderWriter's
|
||||
for(ReaderWriterList::iterator itr=_rwList.begin();
|
||||
itr!=_rwList.end();
|
||||
++itr)
|
||||
{
|
||||
rwOriginal.insert(itr->get());
|
||||
if ((*itr)->writeNode(node,fileName,_options.get())) return true;
|
||||
ReaderWriter::WriteResult rr = (*itr)->writeNode(node,fileName,_options.get());
|
||||
if (rr.success()) return true;
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
|
||||
// now look for a plug-in to save the file.
|
||||
@ -807,16 +899,27 @@ bool Registry::writeNode(const Node& node,const std::string& fileName)
|
||||
{
|
||||
if (rwOriginal.find(itr->get())==rwOriginal.end())
|
||||
{
|
||||
if ((*itr)->writeNode(node,fileName,_options.get())) return true;
|
||||
ReaderWriter::WriteResult rr = (*itr)->writeNode(node,fileName,_options.get());
|
||||
if (rr.success()) return true;
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (results.empty())
|
||||
{
|
||||
notify(NOTICE)<<"Warning: Could not find plugin to write file with extension ."
|
||||
<<getLowerCaseFileExtension(fileName)<<endl;
|
||||
}
|
||||
notify(NOTICE)<<"Warning: Unable to write file "<<fileName<<endl;
|
||||
else
|
||||
{
|
||||
for(Results::iterator itr=results.begin();
|
||||
itr!=results.end();
|
||||
++itr)
|
||||
{
|
||||
notify(NOTICE)<<itr->message()<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -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, const osgDB::ReaderWriter::Options*)
|
||||
virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
|
||||
unsigned char *imageData = NULL;
|
||||
@ -300,7 +300,7 @@ class ReaderWriterBMP : public osgDB::ReaderWriter
|
||||
|
||||
imageData = bmp_load(fileName.c_str(),&width_ret,&height_ret,&numComponents_ret);
|
||||
|
||||
if (imageData==NULL) return NULL;
|
||||
if (imageData==NULL) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
int s = width_ret;
|
||||
int t = height_ret;
|
||||
|
@ -879,7 +879,7 @@ class ReaderWriterDW : public osgDB::ReaderWriter
|
||||
return osgDB::equalCaseInsensitive(extension,"dw");
|
||||
}
|
||||
|
||||
virtual Node* readNode(const std::string& fileName,const osgDB::ReaderWriter::Options*)
|
||||
virtual ReadResult readNode(const std::string& fileName,const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
_dwobj obj;
|
||||
enum reading {NONE, MATERIAL, OBJECT};
|
||||
@ -891,7 +891,7 @@ class ReaderWriterDW : public osgDB::ReaderWriter
|
||||
reading rdg=NONE;
|
||||
|
||||
std::string ext = osgDB::getFileExtension(fileName);
|
||||
if (!acceptsExtension(ext)) return NULL;
|
||||
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
char buff[256];
|
||||
|
||||
|
@ -14,19 +14,23 @@
|
||||
|
||||
using namespace flt;
|
||||
|
||||
osg::Object* ReaderWriterFLT::readObject(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readObject(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
FltFile read;
|
||||
|
||||
return read.readObject(fileName);
|
||||
osg::Object* obj=read.readObject(fileName);
|
||||
if (obj) return obj;
|
||||
else return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
|
||||
osg::Node* ReaderWriterFLT::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
FltFile read;
|
||||
|
||||
return read.readNode(fileName);
|
||||
osg::Node* obj=read.readNode(fileName);
|
||||
if (obj) return obj;
|
||||
else return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
|
||||
|
@ -54,8 +54,8 @@ public:
|
||||
return osgDB::equalCaseInsensitive(extension,"flt");
|
||||
}
|
||||
|
||||
virtual osg::Object* readObject(const std::string& fileName, const osgDB::ReaderWriter::Options*);
|
||||
virtual osg::Node* readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*);
|
||||
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options*);
|
||||
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*);
|
||||
};
|
||||
|
||||
|
||||
|
@ -323,7 +323,7 @@ class ReaderWriterGIF : public osgDB::ReaderWriter
|
||||
return osgDB::equalCaseInsensitive(extension,"gif");
|
||||
}
|
||||
|
||||
virtual osg::Image* readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
|
||||
unsigned char *imageData = NULL;
|
||||
@ -333,7 +333,17 @@ class ReaderWriterGIF : public osgDB::ReaderWriter
|
||||
|
||||
imageData = simage_gif_load(fileName.c_str(),&width_ret,&height_ret,&numComponents_ret);
|
||||
|
||||
if (imageData==NULL) return NULL;
|
||||
switch (giferror)
|
||||
{
|
||||
case ERR_OPEN:
|
||||
return ReadResult("GIF loader: Error opening file");
|
||||
case ERR_READ:
|
||||
return ReadResult("GIF loader: Error reading file");
|
||||
case ERR_MEM:
|
||||
return ReadResult("GIF loader: Out of memory error");
|
||||
}
|
||||
|
||||
if (imageData==NULL) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
int s = width_ret;
|
||||
int t = height_ret;
|
||||
|
@ -308,7 +308,7 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter
|
||||
return osgDB::equalCaseInsensitive(extension,"jpeg");
|
||||
}
|
||||
|
||||
virtual osg::Image* readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
|
||||
unsigned char *imageData = NULL;
|
||||
@ -318,7 +318,7 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter
|
||||
|
||||
imageData = simage_jpeg_load(fileName.c_str(),&width_ret,&height_ret,&numComponents_ret);
|
||||
|
||||
if (imageData==NULL) return NULL;
|
||||
if (imageData==NULL) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
int s = width_ret;
|
||||
int t = height_ret;
|
||||
|
@ -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, const osgDB::ReaderWriter::Options*);
|
||||
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*);
|
||||
|
||||
typedef std::vector<int> FaceList;
|
||||
typedef std::map<std::string,osg::StateSet*> GeoStateMap;
|
||||
@ -59,11 +59,11 @@ ReaderWriter3DS::ReaderWriter3DS()
|
||||
}
|
||||
|
||||
|
||||
osg::Node* ReaderWriter3DS::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
osgDB::ReaderWriter::ReadResult ReaderWriter3DS::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
|
||||
Lib3dsFile *f = lib3ds_open(fileName.c_str());
|
||||
if (f==NULL) return NULL;
|
||||
if (f==NULL) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
_directory = osgDB::getFilePath(fileName);
|
||||
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
return (extension == "lwo" || extension == "lw" || extension == "geo");
|
||||
}
|
||||
|
||||
virtual osg::Node* readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*);
|
||||
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*);
|
||||
|
||||
protected:
|
||||
};
|
||||
@ -54,11 +54,11 @@ osgDB::RegisterReaderWriterProxy<ReaderWriterLWO> g_lwoReaderWriterProxy;
|
||||
|
||||
|
||||
// read file and convert to OSG.
|
||||
osg::Node* ReaderWriterLWO::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
lwObject* lw = lw_object_read(fileName.c_str());
|
||||
if (!lw)
|
||||
return NULL;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
osg::notify(osg::INFO) << "faces " << lw->face_cnt << endl;
|
||||
osg::notify(osg::INFO) << "materials " << lw->material_cnt << endl;
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
return (extension == "obj");
|
||||
}
|
||||
|
||||
virtual osg::Node* readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*);
|
||||
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*);
|
||||
|
||||
protected:
|
||||
osg::Drawable* makeDrawable(GLMmodel* obj, GLMgroup* grp, osg::StateSet**);
|
||||
@ -60,11 +60,11 @@ osgDB::RegisterReaderWriterProxy<ReaderWriterOBJ> g_objReaderWriterProxy;
|
||||
|
||||
|
||||
// read file and convert to OSG.
|
||||
osg::Node* ReaderWriterOBJ::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
GLMmodel* obj = glmReadOBJ((char*) fileName.c_str());
|
||||
if (!obj)
|
||||
return NULL;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
std::string directory = osgDB::getFilePath(fileName);
|
||||
|
||||
|
@ -19,12 +19,12 @@ class OSGReaderWriter : public ReaderWriter
|
||||
return equalCaseInsensitive(extension,"osg");
|
||||
}
|
||||
|
||||
virtual Object* readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* opt) { return readNode(fileName,opt); }
|
||||
virtual ReadResult readObject(const std::string& fileName, const Options* opt) { return readNode(fileName,opt); }
|
||||
|
||||
virtual Node* readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
virtual ReadResult readNode(const std::string& fileName, const Options*)
|
||||
{
|
||||
std::string ext = getFileExtension(fileName);
|
||||
if (!acceptsExtension(ext)) return NULL;
|
||||
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
ifstream fin(fileName.c_str());
|
||||
if (fin)
|
||||
@ -60,7 +60,7 @@ class OSGReaderWriter : public ReaderWriter
|
||||
} // group->getNumChildren()==0
|
||||
else
|
||||
{
|
||||
return 0L;
|
||||
return ReadResult("No data loaded from "+fileName);
|
||||
}
|
||||
|
||||
}
|
||||
@ -70,7 +70,7 @@ class OSGReaderWriter : public ReaderWriter
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool writeObject(const Object& obj,const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
virtual WriteResult writeObject(const Object& obj,const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
Output fout;
|
||||
fout.open(fileName.c_str());
|
||||
@ -78,12 +78,12 @@ class OSGReaderWriter : public ReaderWriter
|
||||
{
|
||||
fout.writeObject(obj);
|
||||
fout.close();
|
||||
return true;
|
||||
return WriteResult::FILE_SAVED;
|
||||
}
|
||||
return false;
|
||||
return WriteResult("Unable to open file for output");
|
||||
}
|
||||
|
||||
virtual bool writeNode(const Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
virtual WriteResult writeNode(const Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
Output fout;
|
||||
fout.open(fileName.c_str());
|
||||
@ -91,9 +91,9 @@ class OSGReaderWriter : public ReaderWriter
|
||||
{
|
||||
fout.writeObject(node);
|
||||
fout.close();
|
||||
return true;
|
||||
return WriteResult::FILE_SAVED;
|
||||
}
|
||||
return false;
|
||||
return WriteResult("Unable to open file for output");
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -30,10 +30,10 @@ class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter
|
||||
return osgDB::equalCaseInsensitive(extension,"osgtgz");
|
||||
}
|
||||
|
||||
virtual Node* readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
std::string ext = osgDB::getFileExtension(fileName);
|
||||
if (!acceptsExtension(ext)) return NULL;
|
||||
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
osg::notify(osg::INFO)<<"sgReaderWriterOSGTGZ::readNode( "<<fileName.c_str()<<" )\n";
|
||||
|
||||
@ -100,7 +100,7 @@ class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter
|
||||
if( grp->getNumChildren() == 0 )
|
||||
{
|
||||
grp->unref();
|
||||
return NULL;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
return grp;
|
||||
|
@ -95,7 +95,7 @@ class ReaderWriterPFB : public osgDB::ReaderWriter
|
||||
false;
|
||||
}
|
||||
|
||||
virtual osg::Image* readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
osg::notify(osg::INFO)<< "ReaderWriterPFB::readImage( "<<fileName.c_str()<<" )\n";
|
||||
|
||||
@ -133,10 +133,10 @@ class ReaderWriterPFB : public osgDB::ReaderWriter
|
||||
return image;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
virtual osg::Node* readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
osg::notify(osg::INFO)<< "ReaderWriterPFB::readNode( "<<fileName.c_str()<<" )\n";
|
||||
|
||||
@ -144,15 +144,23 @@ class ReaderWriterPFB : public osgDB::ReaderWriter
|
||||
|
||||
pfNode* root = pfdLoadFile(fileName.c_str());
|
||||
|
||||
if (root)
|
||||
{
|
||||
|
||||
ConvertFromPerformer converter;
|
||||
return converter.convert(root);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
virtual bool writeNode(const osg::Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
virtual WriteResult writeNode(const osg::Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
std::string ext = osgDB::getLowerCaseFileExtension(fileName);
|
||||
if (!acceptsExtension(ext)) return false;
|
||||
if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;
|
||||
|
||||
|
||||
osg::notify(osg::INFO)<< "ReaderWriterPFB::writeNode( "<<fileName.c_str()<<" )\n";
|
||||
@ -161,11 +169,12 @@ class ReaderWriterPFB : public osgDB::ReaderWriter
|
||||
pfNode* root = converter.convert(&node);
|
||||
if (root)
|
||||
{
|
||||
return pfdStoreFile(root,fileName.c_str())!=0;
|
||||
if (pfdStoreFile(root,fileName.c_str())!=0) return WriteResult::FILE_SAVED;
|
||||
else return "Unable to write file from performer.";
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
return "Unable to convert scene to performer, cannot write 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, const osgDB::ReaderWriter::Options*)
|
||||
virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
|
||||
unsigned char *imageData = NULL;
|
||||
@ -199,7 +199,7 @@ class ReaderWriterPIC : public osgDB::ReaderWriter
|
||||
|
||||
imageData = simage_pic_load(fileName.c_str(),&width_ret,&height_ret,&numComponents_ret);
|
||||
|
||||
if (imageData==NULL) return NULL;
|
||||
if (imageData==NULL) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
int s = width_ret;
|
||||
int t = height_ret;
|
||||
|
@ -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, const osgDB::ReaderWriter::Options*)
|
||||
virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
|
||||
int trans = PNG_ALPHA;
|
||||
@ -62,7 +62,7 @@ class ReaderWriterPNG : public osgDB::ReaderWriter
|
||||
else
|
||||
{
|
||||
png_destroy_read_struct(&png, &info, &endinfo);
|
||||
return NULL;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
png_set_sig_bytes(png, 8);
|
||||
|
||||
@ -134,7 +134,7 @@ class ReaderWriterPNG : public osgDB::ReaderWriter
|
||||
break;
|
||||
|
||||
default:
|
||||
return NULL;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -286,7 +286,7 @@ class ReaderWriterPNG : public osgDB::ReaderWriter
|
||||
return osgDB::equalCaseInsensitive(extension,"png");
|
||||
}
|
||||
|
||||
virtual osg::Image* readImage(const std::string& fileName,const osgDB::ReaderWriter::Options*)
|
||||
virtual ReadResult readImage(const std::string& fileName,const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
|
||||
unsigned char *imageData = NULL;
|
||||
@ -296,7 +296,7 @@ class ReaderWriterPNG : public osgDB::ReaderWriter
|
||||
|
||||
imageData = simage_png_load(fileName.c_str(),&width_ret,&height_ret,&numComponents_ret);
|
||||
|
||||
if (imageData==NULL) return NULL;
|
||||
if (imageData==NULL) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
int s = width_ret;
|
||||
int t = height_ret;
|
||||
|
@ -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,const osgDB::ReaderWriter::Options*)
|
||||
virtual ReadResult readImage(const std::string& fileName,const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
|
||||
int trans = PNG_ALPHA;
|
||||
@ -62,7 +62,7 @@ class ReaderWriterPNG : public osgDB::ReaderWriter
|
||||
else
|
||||
{
|
||||
png_destroy_read_struct(&png, &info, &endinfo);
|
||||
return NULL;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
png_set_sig_bytes(png, 8);
|
||||
|
||||
@ -134,7 +134,7 @@ class ReaderWriterPNG : public osgDB::ReaderWriter
|
||||
break;
|
||||
|
||||
default:
|
||||
return NULL;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -304,17 +304,16 @@ class ReaderWriterRGB : public osgDB::ReaderWriter
|
||||
osgDB::equalCaseInsensitive(extension,"bw");
|
||||
}
|
||||
|
||||
virtual Image* readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
std::string ext = osgDB::getFileExtension(fileName);
|
||||
if (!acceptsExtension(ext)) return NULL;
|
||||
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
rawImageRec *raw;
|
||||
|
||||
if( (raw = RawImageOpen(fileName.c_str())) == NULL )
|
||||
{
|
||||
notify(FATAL)<< "Unable to open \""<<fileName<<"\""<<endl;
|
||||
return NULL;
|
||||
return "Unable to open \""+fileName+"\"";
|
||||
}
|
||||
|
||||
int s = raw->sizeX;
|
||||
|
@ -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, const osgDB::ReaderWriter::Options*)
|
||||
virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
|
||||
unsigned char *imageData = NULL;
|
||||
@ -479,7 +479,7 @@ class ReaderWriterTGA : public osgDB::ReaderWriter
|
||||
|
||||
imageData = simage_tga_load(fileName.c_str(),&width_ret,&height_ret,&numComponents_ret);
|
||||
|
||||
if (imageData==NULL) return NULL;
|
||||
if (imageData==NULL) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
int s = width_ret;
|
||||
int t = height_ret;
|
||||
|
@ -31,10 +31,10 @@ class ReaderWriterTGZ : public osgDB::ReaderWriter
|
||||
return osgDB::equalCaseInsensitive(extension,"tgz");
|
||||
}
|
||||
|
||||
virtual Node* readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
std::string ext = osgDB::getLowerCaseFileExtension(fileName);
|
||||
if (!acceptsExtension(ext)) return NULL;
|
||||
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
osg::notify(osg::INFO)<< "ReaderWriterTGZ::readNode( "<<fileName.c_str()<<" )\n";
|
||||
|
||||
@ -107,7 +107,7 @@ class ReaderWriterTGZ : public osgDB::ReaderWriter
|
||||
if( grp->getNumChildren() == 0 )
|
||||
{
|
||||
grp->unref();
|
||||
return NULL;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
return grp;
|
||||
|
@ -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, const osgDB::ReaderWriter::Options*)
|
||||
virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
|
||||
unsigned char *imageData = NULL;
|
||||
@ -415,7 +415,7 @@ class ReaderWriterTIFF : public osgDB::ReaderWriter
|
||||
|
||||
imageData = simage_tiff_load(fileName.c_str(),&width_ret,&height_ret,&numComponents_ret);
|
||||
|
||||
if (imageData==NULL) return NULL;
|
||||
if (imageData==NULL) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
int s = width_ret;
|
||||
int t = height_ret;
|
||||
|
@ -29,11 +29,11 @@ class ReaderWriterZIP : public osgDB::ReaderWriter
|
||||
return osgDB::equalCaseInsensitive(extension,"zip");
|
||||
}
|
||||
|
||||
virtual osg::Node* readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
|
||||
std::string ext = osgDB::getLowerCaseFileExtension(fileName);
|
||||
if (!acceptsExtension(ext)) return NULL;
|
||||
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
osg::notify(osg::INFO)<<"ReaderWriterZIP::readNode( "<<fileName.c_str()<<" )\n";
|
||||
|
||||
@ -97,7 +97,7 @@ class ReaderWriterZIP : public osgDB::ReaderWriter
|
||||
if( grp->getNumChildren() == 0 )
|
||||
{
|
||||
grp->unref();
|
||||
return NULL;
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
return grp;
|
||||
|
Loading…
Reference in New Issue
Block a user