Further updates to the ReaderWriter support in osgDB, and a fix to a small warning
in Matrix.cpp.
This commit is contained in:
@@ -73,14 +73,14 @@ class OSGDB_EXPORT Registry
|
||||
bool writeObject(const osg::Object& obj,Output& fw);
|
||||
|
||||
|
||||
osg::Object* readObject(const std::string& fileName);
|
||||
bool writeObject(const osg::Object& obj, const std::string& fileName);
|
||||
ReaderWriter::ReadResult readObject(const std::string& fileName);
|
||||
ReaderWriter::WriteResult writeObject(const osg::Object& obj, const std::string& fileName);
|
||||
|
||||
osg::Image* readImage(const std::string& fileName);
|
||||
bool writeImage(const osg::Image& obj, const std::string& fileName);
|
||||
ReaderWriter::ReadResult readImage(const std::string& fileName);
|
||||
ReaderWriter::WriteResult writeImage(const osg::Image& obj, const std::string& fileName);
|
||||
|
||||
osg::Node* readNode(const std::string& fileName);
|
||||
bool writeNode(const osg::Node& node, const std::string& fileName);
|
||||
ReaderWriter::ReadResult readNode(const std::string& fileName);
|
||||
ReaderWriter::WriteResult writeNode(const osg::Node& node, const std::string& fileName);
|
||||
|
||||
void setCreateNodeFromImage(bool flag) { _createNodeFromImage = flag; }
|
||||
bool getCreateNodeFromImage() const { return _createNodeFromImage; }
|
||||
|
||||
@@ -50,11 +50,11 @@ class ReaderWriterFLY : public osgDB::ReaderWriter
|
||||
return osgDB::equalCaseInsensitive(extension,"fly");
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
char buff[256];
|
||||
|
||||
@@ -95,7 +95,7 @@ class ReaderWriterFLY : public osgDB::ReaderWriter
|
||||
|
||||
};
|
||||
|
||||
// now register with osg::Registry to instantiate the above
|
||||
// now register with osgDB::Registry to instantiate the above
|
||||
// reader/writer.
|
||||
osgDB::RegisterReaderWriterProxy<ReaderWriterFLY> g_readerWriter_FLY_Proxy;
|
||||
|
||||
|
||||
@@ -483,7 +483,7 @@ bool Matrix::invertAffine( const Matrix& _m )
|
||||
|
||||
det_1 = pos + neg;
|
||||
|
||||
if( (det_1 == 0.0) || (abs(det_1/(pos-neg)) < PRECISION_LIMIT )) {
|
||||
if( (det_1 == 0.0) || (fabs(det_1/(pos-neg)) < PRECISION_LIMIT )) {
|
||||
// _m has no inverse
|
||||
notify(WARN) << "Matrix::invert(): Matrix has no inverse." << endl;
|
||||
return false;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <osg/Object>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/Input>
|
||||
|
||||
using namespace osgDB;
|
||||
@@ -62,15 +63,15 @@ osg::Node* Input::readNode()
|
||||
|
||||
osg::Object* Input::readObject(const std::string& fileName)
|
||||
{
|
||||
return Registry::instance()->readObject(fileName);
|
||||
return readObjectFile(fileName);
|
||||
}
|
||||
|
||||
osg::Image* Input::readImage(const std::string& fileName)
|
||||
{
|
||||
return Registry::instance()->readImage(fileName);
|
||||
return readImageFile(fileName);
|
||||
}
|
||||
|
||||
osg::Node* Input::readNode(const std::string& fileName)
|
||||
{
|
||||
return Registry::instance()->readNode(fileName);
|
||||
return readNodeFile(fileName);
|
||||
}
|
||||
|
||||
@@ -11,17 +11,26 @@ using namespace osgDB;
|
||||
|
||||
Object* osgDB::readObjectFile(const std::string& filename)
|
||||
{
|
||||
return Registry::instance()->readObject(filename);
|
||||
ReaderWriter::ReadResult rr = Registry::instance()->readObject(filename);
|
||||
if (rr.validObject()) return rr.takeObject();
|
||||
if (rr.error()) notify(WARN) << rr.message() << endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Image* osgDB::readImageFile(const std::string& filename)
|
||||
Image* osgDB::readImageFile(const std::string& filename)
|
||||
{
|
||||
return Registry::instance()->readImage(filename);
|
||||
ReaderWriter::ReadResult rr = Registry::instance()->readImage(filename);
|
||||
if (rr.validImage()) return rr.takeImage();
|
||||
if (rr.error()) notify(WARN) << rr.message() << endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Node* osgDB::readNodeFile(const std::string& filename)
|
||||
Node* osgDB::readNodeFile(const std::string& filename)
|
||||
{
|
||||
return Registry::instance()->readNode(filename);
|
||||
ReaderWriter::ReadResult rr = Registry::instance()->readNode(filename);
|
||||
if (rr.validNode()) return rr.takeNode();
|
||||
if (rr.error()) notify(WARN) << rr.message() << endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -553,10 +553,10 @@ bool Registry::writeObject(const osg::Object& obj,Output& fw)
|
||||
//
|
||||
// read object from specified file.
|
||||
//
|
||||
Object* Registry::readObject(const std::string& fileName)
|
||||
ReaderWriter::ReadResult Registry::readObject(const std::string& fileName)
|
||||
{
|
||||
char *file = findFile( fileName.c_str() );
|
||||
if (file==NULL) return NULL;
|
||||
if (file==NULL) return ReaderWriter::ReadResult("Warning: file \""+fileName+"\" not found.");
|
||||
|
||||
// record the existing reader writer.
|
||||
std::set<ReaderWriter*> rwOriginal;
|
||||
@@ -572,7 +572,7 @@ Object* Registry::readObject(const std::string& fileName)
|
||||
{
|
||||
rwOriginal.insert(itr->get());
|
||||
ReaderWriter::ReadResult rr = (*itr)->readObject(file,_options.get());
|
||||
if (rr.validObject()) return rr.takeObject();
|
||||
if (rr.validObject()) return rr;
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
|
||||
@@ -587,7 +587,7 @@ Object* Registry::readObject(const std::string& fileName)
|
||||
if (rwOriginal.find(itr->get())==rwOriginal.end())
|
||||
{
|
||||
ReaderWriter::ReadResult rr = (*itr)->readObject(file,_options.get());
|
||||
if (rr.validObject()) return rr.takeObject();
|
||||
if (rr.validObject()) return rr;
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
}
|
||||
@@ -595,24 +595,16 @@ Object* Registry::readObject(const std::string& fileName)
|
||||
|
||||
if (results.empty())
|
||||
{
|
||||
notify(NOTICE)<<"Warning: Could not find plugin to read file with extension ."
|
||||
<<getLowerCaseFileExtension(fileName)<<endl;
|
||||
return ReaderWriter::ReadResult("Warning: Could not find plugin to read objects from file \""+fileName+"\".");
|
||||
}
|
||||
else
|
||||
{
|
||||
for(Results::iterator itr=results.begin();
|
||||
itr!=results.end();
|
||||
++itr)
|
||||
{
|
||||
notify(NOTICE)<<itr->message()<<endl;
|
||||
}
|
||||
return results.front();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
bool Registry::writeObject(const Object& obj,const std::string& fileName)
|
||||
ReaderWriter::WriteResult Registry::writeObject(const Object& obj,const std::string& fileName)
|
||||
{
|
||||
// record the existing reader writer.
|
||||
std::set<ReaderWriter*> rwOriginal;
|
||||
@@ -628,7 +620,7 @@ bool Registry::writeObject(const Object& obj,const std::string& fileName)
|
||||
{
|
||||
rwOriginal.insert(itr->get());
|
||||
ReaderWriter::WriteResult rr = (*itr)->writeObject(obj,fileName,_options.get());
|
||||
if (rr.success()) return true;
|
||||
if (rr.success()) return rr;
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
|
||||
@@ -643,7 +635,7 @@ bool Registry::writeObject(const Object& obj,const std::string& fileName)
|
||||
if (rwOriginal.find(itr->get())==rwOriginal.end())
|
||||
{
|
||||
ReaderWriter::WriteResult rr = (*itr)->writeObject(obj,fileName,_options.get());
|
||||
if (rr.success()) return true;
|
||||
if (rr.success()) return rr;
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
}
|
||||
@@ -651,28 +643,20 @@ bool Registry::writeObject(const Object& obj,const std::string& fileName)
|
||||
|
||||
if (results.empty())
|
||||
{
|
||||
notify(NOTICE)<<"Warning: Could not find plugin to write file with extension ."
|
||||
<<getLowerCaseFileExtension(fileName)<<endl;
|
||||
return ReaderWriter::WriteResult("Warning: Could not find plugin to write objects to file \""+fileName+"\".");
|
||||
}
|
||||
else
|
||||
{
|
||||
for(Results::iterator itr=results.begin();
|
||||
itr!=results.end();
|
||||
++itr)
|
||||
{
|
||||
notify(NOTICE)<<itr->message()<<endl;
|
||||
}
|
||||
return results.front();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Image* Registry::readImage(const std::string& fileName)
|
||||
ReaderWriter::ReadResult Registry::readImage(const std::string& fileName)
|
||||
{
|
||||
char *file = findFile( fileName.c_str() );
|
||||
if (file==NULL) return NULL;
|
||||
if (file==NULL) return ReaderWriter::ReadResult("Warning: file \""+fileName+"\" not found.");
|
||||
|
||||
// record the existing reader writer.
|
||||
std::set<ReaderWriter*> rwOriginal;
|
||||
@@ -688,7 +672,7 @@ Image* Registry::readImage(const std::string& fileName)
|
||||
{
|
||||
rwOriginal.insert(itr->get());
|
||||
ReaderWriter::ReadResult rr = (*itr)->readImage(file,_options.get());
|
||||
if (rr.validImage()) return rr.takeImage();
|
||||
if (rr.validImage()) return rr;
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
|
||||
@@ -703,7 +687,7 @@ Image* Registry::readImage(const std::string& fileName)
|
||||
if (rwOriginal.find(itr->get())==rwOriginal.end())
|
||||
{
|
||||
ReaderWriter::ReadResult rr = (*itr)->readImage(file,_options.get());
|
||||
if (rr.validImage()) return rr.takeImage();
|
||||
if (rr.validImage()) return rr;
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
}
|
||||
@@ -711,24 +695,16 @@ Image* Registry::readImage(const std::string& fileName)
|
||||
|
||||
if (results.empty())
|
||||
{
|
||||
notify(NOTICE)<<"Warning: Could not find plugin to read file with extension ."
|
||||
<<getLowerCaseFileExtension(fileName)<<endl;
|
||||
return ReaderWriter::ReadResult("Warning: Could not find plugin to read image from file \""+fileName+"\".");
|
||||
}
|
||||
else
|
||||
{
|
||||
for(Results::iterator itr=results.begin();
|
||||
itr!=results.end();
|
||||
++itr)
|
||||
{
|
||||
notify(NOTICE)<<itr->message()<<endl;
|
||||
}
|
||||
return results.front();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
bool Registry::writeImage(const Image& image,const std::string& fileName)
|
||||
ReaderWriter::WriteResult Registry::writeImage(const Image& image,const std::string& fileName)
|
||||
{
|
||||
// record the existing reader writer.
|
||||
std::set<ReaderWriter*> rwOriginal;
|
||||
@@ -744,7 +720,7 @@ bool Registry::writeImage(const Image& image,const std::string& fileName)
|
||||
{
|
||||
rwOriginal.insert(itr->get());
|
||||
ReaderWriter::WriteResult rr = (*itr)->writeImage(image,fileName,_options.get());
|
||||
if (rr.success()) return true;
|
||||
if (rr.success()) return rr;
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
|
||||
@@ -759,7 +735,7 @@ bool Registry::writeImage(const Image& image,const std::string& fileName)
|
||||
if (rwOriginal.find(itr->get())==rwOriginal.end())
|
||||
{
|
||||
ReaderWriter::WriteResult rr = (*itr)->writeImage(image,fileName,_options.get());
|
||||
if (rr.success()) return true;
|
||||
if (rr.success()) return rr;
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
}
|
||||
@@ -767,28 +743,20 @@ bool Registry::writeImage(const Image& image,const std::string& fileName)
|
||||
|
||||
if (results.empty())
|
||||
{
|
||||
notify(NOTICE)<<"Warning: Could not find plugin to write file with extension ."
|
||||
<<getLowerCaseFileExtension(fileName)<<endl;
|
||||
return ReaderWriter::WriteResult("Warning: Could not find plugin to write image to file \""+fileName+"\".");
|
||||
}
|
||||
else
|
||||
{
|
||||
for(Results::iterator itr=results.begin();
|
||||
itr!=results.end();
|
||||
++itr)
|
||||
{
|
||||
notify(NOTICE)<<itr->message()<<endl;
|
||||
}
|
||||
return results.front();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Node* Registry::readNode(const std::string& fileName)
|
||||
ReaderWriter::ReadResult Registry::readNode(const std::string& fileName)
|
||||
{
|
||||
|
||||
char *file = findFile( fileName.c_str() );
|
||||
if (file==NULL) return NULL;
|
||||
if (file==NULL) return ReaderWriter::ReadResult("Warning: file \""+fileName+"\" not found.");
|
||||
|
||||
// record the existing reader writer.
|
||||
std::set<ReaderWriter*> rwOriginal;
|
||||
@@ -804,12 +772,10 @@ Node* Registry::readNode(const std::string& fileName)
|
||||
{
|
||||
rwOriginal.insert(itr->get());
|
||||
ReaderWriter::ReadResult rr = (*itr)->readNode(file,_options.get());
|
||||
if (rr.validNode()) return rr.takeNode();
|
||||
if (rr.validNode()) return rr;
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
|
||||
bool couldNotFindPlugin = false;
|
||||
|
||||
// now look for a plug-in to load the file.
|
||||
std::string libraryName = createLibraryNameForFile(fileName);
|
||||
notify(INFO) << "Now checking for plug-in "<<libraryName<<endl;
|
||||
@@ -822,54 +788,32 @@ Node* Registry::readNode(const std::string& fileName)
|
||||
if (rwOriginal.find(itr->get())==rwOriginal.end())
|
||||
{
|
||||
ReaderWriter::ReadResult rr = (*itr)->readNode(file,_options.get());
|
||||
if (rr.validNode()) return rr.takeNode();
|
||||
if (rr.validNode()) return rr;
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
couldNotFindPlugin = true;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 (_createNodeFromImage)
|
||||
{
|
||||
ReaderWriter::ReadResult rr = readImage(file);
|
||||
if (rr.validImage()) return createGeodeForImage(rr.takeImage());
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
|
||||
if (results.empty())
|
||||
{
|
||||
notify(NOTICE)<<"Warning: Could not find plugin to read file with extension ."
|
||||
<<getLowerCaseFileExtension(fileName)<<endl;
|
||||
return ReaderWriter::ReadResult("Warning: Could not find plugin to read nodes from file \""+fileName+"\".");
|
||||
}
|
||||
else
|
||||
{
|
||||
for(Results::iterator itr=results.begin();
|
||||
itr!=results.end();
|
||||
++itr)
|
||||
{
|
||||
notify(NOTICE)<<itr->message()<<endl;
|
||||
}
|
||||
return results.front();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
bool Registry::writeNode(const Node& node,const std::string& fileName)
|
||||
ReaderWriter::WriteResult Registry::writeNode(const Node& node,const std::string& fileName)
|
||||
{
|
||||
// record the existing reader writer.
|
||||
std::set<ReaderWriter*> rwOriginal;
|
||||
@@ -885,7 +829,7 @@ bool Registry::writeNode(const Node& node,const std::string& fileName)
|
||||
{
|
||||
rwOriginal.insert(itr->get());
|
||||
ReaderWriter::WriteResult rr = (*itr)->writeNode(node,fileName,_options.get());
|
||||
if (rr.success()) return true;
|
||||
if (rr.success()) return rr;
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
|
||||
@@ -900,7 +844,7 @@ bool Registry::writeNode(const Node& node,const std::string& fileName)
|
||||
if (rwOriginal.find(itr->get())==rwOriginal.end())
|
||||
{
|
||||
ReaderWriter::WriteResult rr = (*itr)->writeNode(node,fileName,_options.get());
|
||||
if (rr.success()) return true;
|
||||
if (rr.success()) return rr;
|
||||
else if (rr.error()) results.push_back(rr);
|
||||
}
|
||||
}
|
||||
@@ -908,18 +852,10 @@ bool Registry::writeNode(const Node& node,const std::string& fileName)
|
||||
|
||||
if (results.empty())
|
||||
{
|
||||
notify(NOTICE)<<"Warning: Could not find plugin to write file with extension ."
|
||||
<<getLowerCaseFileExtension(fileName)<<endl;
|
||||
return ReaderWriter::WriteResult("Warning: Could not find plugin to write nodes to file \""+fileName+"\".");
|
||||
}
|
||||
else
|
||||
{
|
||||
for(Results::iterator itr=results.begin();
|
||||
itr!=results.end();
|
||||
++itr)
|
||||
{
|
||||
notify(NOTICE)<<itr->message()<<endl;
|
||||
}
|
||||
return results.front();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -14,17 +14,23 @@ using namespace osgDB;
|
||||
|
||||
bool osgDB::writeObjectFile(const Object& object,const std::string& filename)
|
||||
{
|
||||
return Registry::instance()->writeObject(object,filename);
|
||||
ReaderWriter::WriteResult wr = Registry::instance()->writeObject(object,filename);
|
||||
if (wr.error()) notify(WARN) << wr.message() << endl;
|
||||
return wr.success();
|
||||
}
|
||||
|
||||
|
||||
bool osgDB::writeImageFile(const Image& image,const std::string& filename)
|
||||
{
|
||||
return Registry::instance()->writeImage(image,filename);
|
||||
ReaderWriter::WriteResult wr = Registry::instance()->writeImage(image,filename);
|
||||
if (wr.error()) notify(WARN) << wr.message() << endl;
|
||||
return wr.success();
|
||||
}
|
||||
|
||||
|
||||
bool osgDB::writeNodeFile(const Node& node,const std::string& filename)
|
||||
{
|
||||
return Registry::instance()->writeNode(node,filename);
|
||||
ReaderWriter::WriteResult wr = Registry::instance()->writeNode(node,filename);
|
||||
if (wr.error()) notify(WARN) << wr.message() << endl;
|
||||
return wr.success();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user