Added new ReaderWriter methods for recording what protocols, extensions and options are
support by ReaderWriters
This commit is contained in:
@@ -30,6 +30,7 @@ extern OSGDB_EXPORT std::string getStrippedName(const std::string& fileName);
|
||||
|
||||
extern OSGDB_EXPORT std::string convertFileNameToWindowsStyle(const std::string& fileName);
|
||||
extern OSGDB_EXPORT std::string convertFileNameToUnixStyle(const std::string& fileName);
|
||||
extern OSGDB_EXPORT std::string convertToLowerCase(const std::string& fileName);
|
||||
|
||||
extern OSGDB_EXPORT bool isFileNameNativeStyle(const std::string& fileName);
|
||||
extern OSGDB_EXPORT std::string convertFileNameToNativeStyle(const std::string& fileName);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <osgDB/Export>
|
||||
|
||||
#include <deque>
|
||||
#include <list>
|
||||
#include <iosfwd>
|
||||
|
||||
namespace osgDB {
|
||||
@@ -47,7 +48,19 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
|
||||
|
||||
META_Object(osgDB,ReaderWriter);
|
||||
|
||||
virtual bool acceptsExtension(const std::string& /*extension*/) const { return false; }
|
||||
typedef std::map<std::string, std::string> FormatDescriptionMap;
|
||||
|
||||
/** return which protocols are supported by ReaderWriter. */
|
||||
virtual const FormatDescriptionMap& supportedProtocols() const { return _supportedProtocols; }
|
||||
|
||||
/** return which list of file extensions supported by ReaderWriter. */
|
||||
virtual const FormatDescriptionMap& supportedExtension() const { return _supportedExtensions; }
|
||||
|
||||
/** return which list of file extensions supported by ReaderWriter. */
|
||||
virtual const FormatDescriptionMap& supportedOptions() const { return _supportedOptions; }
|
||||
|
||||
/** return true if ReaderWriter accepts specified file extension.*/
|
||||
virtual bool acceptsExtension(const std::string& /*extension*/) const;
|
||||
|
||||
/** Options base class used for passing options into plugins to control their operation.*/
|
||||
class Options : public osg::Object
|
||||
@@ -304,6 +317,15 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
|
||||
virtual WriteResult writeNode(const osg::Node& /*node*/,std::ostream& /*fout*/,const Options* =NULL) const { return WriteResult(WriteResult::FILE_NOT_HANDLED); }
|
||||
virtual WriteResult writeShader(const osg::Shader& /*shader*/,std::ostream& /*fout*/,const Options* =NULL) const { return WriteResult(WriteResult::FILE_NOT_HANDLED); }
|
||||
|
||||
protected:
|
||||
|
||||
void supportsProtocol(const std::string& fmt, const std::string& description);
|
||||
void supportsExtension(const std::string& fmt, const std::string& description);
|
||||
void supportsOption(const std::string& fmt, const std::string& description);
|
||||
|
||||
FormatDescriptionMap _supportedProtocols;
|
||||
FormatDescriptionMap _supportedExtensions;
|
||||
FormatDescriptionMap _supportedOptions;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -113,17 +113,21 @@ std::string osgDB::convertFileNameToNativeStyle(const std::string& fileName)
|
||||
|
||||
std::string osgDB::getLowerCaseFileExtension(const std::string& filename)
|
||||
{
|
||||
std::string ext = osgDB::getFileExtension(filename);
|
||||
for(std::string::iterator itr=ext.begin();
|
||||
itr!=ext.end();
|
||||
return convertToLowerCase(osgDB::getFileExtension(filename));
|
||||
}
|
||||
|
||||
std::string osgDB::convertToLowerCase(const std::string& str)
|
||||
{
|
||||
std::string lowcase_str(str);
|
||||
for(std::string::iterator itr=lowcase_str.begin();
|
||||
itr!=lowcase_str.end();
|
||||
++itr)
|
||||
{
|
||||
*itr = tolower(*itr);
|
||||
}
|
||||
return ext;
|
||||
return lowcase_str;
|
||||
}
|
||||
|
||||
|
||||
// strip one level of extension from the filename.
|
||||
std::string osgDB::getNameLessExtension(const std::string& fileName)
|
||||
{
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
|
||||
#include <osgDB/ReaderWriter>
|
||||
#include <osgDB/FileNameUtils>
|
||||
#include <osgDB/Archive>
|
||||
|
||||
using namespace osgDB;
|
||||
@@ -33,3 +34,24 @@ osg::Shader* ReaderWriter::ReadResult::takeShader() { osg::Shader* shader=dynami
|
||||
ReaderWriter::~ReaderWriter()
|
||||
{
|
||||
}
|
||||
|
||||
bool ReaderWriter::acceptsExtension(const std::string& extension) const
|
||||
{
|
||||
std::string lowercase_ext = convertToLowerCase(extension);
|
||||
return (_supportedExtensions.count(lowercase_ext)!=0);
|
||||
}
|
||||
|
||||
void ReaderWriter::supportsProtocol(const std::string& fmt, const std::string& description)
|
||||
{
|
||||
_supportedProtocols[convertToLowerCase(fmt)] = description;
|
||||
}
|
||||
|
||||
void ReaderWriter::supportsExtension(const std::string& fmt, const std::string& description)
|
||||
{
|
||||
_supportedExtensions[convertToLowerCase(fmt)] = description;
|
||||
}
|
||||
|
||||
void ReaderWriter::supportsOption(const std::string& fmt, const std::string& description)
|
||||
{
|
||||
_supportedOptions[fmt] = description;
|
||||
}
|
||||
|
||||
@@ -142,7 +142,10 @@ osgDB::ReaderWriter::ReadResult EasyCurl::read(const std::string& proxyAddress,
|
||||
|
||||
ReaderWriterCURL::ReaderWriterCURL()
|
||||
{
|
||||
//osg::notify(osg::NOTICE)<<"ReaderWriterCURL::ReaderWriterCURL()"<<std::endl;
|
||||
supportsProtocol("http","Read from http port using libcurl.");
|
||||
supportsExtension("curl","Psuedo file extension, used to select curl plugin.");
|
||||
supportsOption("OSG_CURL_PROXY","Specify the http proxy.");
|
||||
supportsOption("OSG_CURL_PROXYPORT","Specify the http proxy oirt.");
|
||||
}
|
||||
|
||||
ReaderWriterCURL::~ReaderWriterCURL()
|
||||
@@ -185,7 +188,6 @@ osgDB::ReaderWriter::ReadResult ReaderWriterCURL::readFile(ObjectType objectType
|
||||
|
||||
osg::notify(osg::INFO)<<"ReaderWriterCURL::readFile("<<fullFileName<<")"<<std::endl;
|
||||
|
||||
std::string cacheFilePath, cacheFileName;
|
||||
std::string proxyAddress, optProxy, optProxyPort;
|
||||
|
||||
if (options)
|
||||
@@ -195,9 +197,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterCURL::readFile(ObjectType objectType
|
||||
while (iss >> opt)
|
||||
{
|
||||
int index = opt.find( "=" );
|
||||
if( opt.substr( 0, index ) == "OSG_FILE_CACHE" )
|
||||
cacheFilePath = opt.substr( index+1 ); //Setting Cache Directory by OSG Options
|
||||
else if( opt.substr( 0, index ) == "OSG_CURL_PROXY" )
|
||||
if( opt.substr( 0, index ) == "OSG_CURL_PROXY" )
|
||||
optProxy = opt.substr( index+1 );
|
||||
else if( opt.substr( 0, index ) == "OSG_CURL_PROXYPORT" )
|
||||
optProxyPort = opt.substr( index+1 );
|
||||
@@ -222,34 +222,6 @@ osgDB::ReaderWriter::ReadResult ReaderWriterCURL::readFile(ObjectType objectType
|
||||
fileName = fullFileName;
|
||||
}
|
||||
|
||||
//Getting CURL Environment Variables (If found rewrite OSG Options)
|
||||
const char* fileCachePath = getenv("OSG_FILE_CACHE");
|
||||
if (fileCachePath) //Env Cache Directory
|
||||
cacheFilePath = std::string(fileCachePath);
|
||||
|
||||
if (!cacheFilePath.empty())
|
||||
{
|
||||
cacheFileName = cacheFilePath + "/" +
|
||||
osgDB::getServerAddress(fileName) + "/" +
|
||||
osgDB::getServerFileName(fileName);
|
||||
|
||||
std::string path = osgDB::getFilePath(cacheFileName);
|
||||
|
||||
if (!osgDB::fileExists(path) && !osgDB::makeDirectory(path))
|
||||
{
|
||||
cacheFileName.clear();
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (!cacheFilePath.empty() && osgDB::fileExists(cacheFileName))
|
||||
{
|
||||
osg::notify(osg::NOTICE) << "Reading cache file " << cacheFileName <<", previous path "<<osgDB::getFilePath(fileName)<<std::endl;
|
||||
ReadResult result = osgDB::Registry::instance()->readObject(cacheFileName,options);
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
osgDB::ReaderWriter *reader =
|
||||
osgDB::Registry::instance()->getReaderWriterForExtension( osgDB::getFileExtension(fileName));
|
||||
@@ -273,11 +245,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterCURL::readFile(ObjectType objectType
|
||||
|
||||
std::stringstream buffer;
|
||||
|
||||
#if 0
|
||||
EasyCurl::StreamObject sp(&buffer, cacheFileName);
|
||||
#else
|
||||
EasyCurl::StreamObject sp(&buffer, std::string());
|
||||
#endif
|
||||
|
||||
ReadResult curlResult = getEasyCurl().read(proxyAddress, fileName, sp);
|
||||
|
||||
@@ -290,21 +258,6 @@ osgDB::ReaderWriter::ReadResult ReaderWriterCURL::readFile(ObjectType objectType
|
||||
|
||||
ReadResult readResult = readFile(objectType, reader, buffer, local_opt.get() );
|
||||
|
||||
#if 0
|
||||
if (!cacheFileName.empty() && readResult.success())
|
||||
{
|
||||
switch(objectType)
|
||||
{
|
||||
case(NODE):
|
||||
osg::notify(osg::NOTICE)<<"Write to cache "<<cacheFileName<<std::endl;
|
||||
reader->writeNode(*readResult.getNode(), cacheFileName, local_opt.get());
|
||||
break;
|
||||
default:
|
||||
osg::notify(osg::NOTICE)<<"Curl plugin write to cache not implemented yet"<<std::endl;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
local_opt->getDatabasePathList().pop_front();
|
||||
|
||||
return readResult;
|
||||
|
||||
@@ -13,6 +13,12 @@ using namespace osgDB;
|
||||
class ReaderWriterIVE : public ReaderWriter
|
||||
{
|
||||
public:
|
||||
|
||||
ReaderWriterIVE()
|
||||
{
|
||||
supportsExtension("ive","OpenSceneGraph native binary format");
|
||||
}
|
||||
|
||||
virtual const char* className() const { return "IVE Reader/Writer"; }
|
||||
|
||||
virtual bool acceptsExtension(const std::string& extension) const
|
||||
|
||||
@@ -16,12 +16,16 @@ using namespace osgDB;
|
||||
class OSGReaderWriter : public ReaderWriter
|
||||
{
|
||||
public:
|
||||
virtual const char* className() const { return "OSG Reader/Writer"; }
|
||||
|
||||
virtual bool acceptsExtension(const std::string& extension) const
|
||||
|
||||
OSGReaderWriter()
|
||||
{
|
||||
return equalCaseInsensitive(extension,"osg");
|
||||
supportsExtension("osg","OpenSceneGraph Ascii file format");
|
||||
supportsExtension("osgs","Psuedo OpenSceneGraph file loaded, with file encoded in filename string");
|
||||
supportsOption("precision","Set the floating point precision when writing out files");
|
||||
supportsOption("OutputTextureFiles","Write out the texture images to file");
|
||||
}
|
||||
|
||||
virtual const char* className() const { return "OSG Reader/Writer"; }
|
||||
|
||||
virtual ReadResult readObject(const std::string& file, const Options* opt) const
|
||||
{
|
||||
|
||||
@@ -443,18 +443,19 @@ static void RawImageGetData(rawImageRec *raw, unsigned char **data )
|
||||
class ReaderWriterRGB : public osgDB::ReaderWriter
|
||||
{
|
||||
public:
|
||||
|
||||
ReaderWriterRGB()
|
||||
{
|
||||
supportsExtension("rgb","rgb image format");
|
||||
supportsExtension("rgba","rgba image format");
|
||||
supportsExtension("sgi","sgi image format");
|
||||
supportsExtension("int","int image format");
|
||||
supportsExtension("inta","inta image format");
|
||||
supportsExtension("bw","bw image format");
|
||||
}
|
||||
|
||||
virtual const char* className() const { return "RGB Image Reader/Writer"; }
|
||||
|
||||
virtual bool acceptsExtension(const std::string& extension) const
|
||||
{
|
||||
return osgDB::equalCaseInsensitive(extension,"rgb") ||
|
||||
osgDB::equalCaseInsensitive(extension,"sgi") ||
|
||||
osgDB::equalCaseInsensitive(extension,"rgba") ||
|
||||
osgDB::equalCaseInsensitive(extension,"int") ||
|
||||
osgDB::equalCaseInsensitive(extension,"inta") ||
|
||||
osgDB::equalCaseInsensitive(extension,"bw");
|
||||
}
|
||||
|
||||
ReadResult readRGBStream(std::istream& fin) const
|
||||
{
|
||||
rawImageRec *raw;
|
||||
|
||||
Reference in New Issue
Block a user