Merge pull request #760 from LaurensVoerman/readObject

implement readObject for all relevant readerWriters
This commit is contained in:
OpenSceneGraph git repository 2019-06-14 15:28:46 +01:00 committed by GitHub
commit 21c0affe66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 284 additions and 40 deletions

View File

@ -92,6 +92,11 @@ class ReaderWriter3DC : public osgDB::ReaderWriter
virtual const char* className() const { return "3DC point cloud reader"; }
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fileName, options);
}
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);

View File

@ -171,7 +171,18 @@ public:
virtual const char* className() const { return "3DS Auto Studio Reader/Writer"; }
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fileName, options);
}
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const;
virtual ReadResult readObject(std::istream& fin, const Options* options) const
{
return readNode(fin, options);
}
virtual ReadResult readNode(std::istream& fin, const Options* options) const;
virtual ReadResult doReadNode(std::istream& fin, const Options* options, const std::string & fileNamelib3ds) const; ///< Subfunction of readNode()s functions.

View File

@ -19,8 +19,19 @@ class ReaderWriterIV : public osgDB::ReaderWriter
return osgDB::equalCaseInsensitive(extension, "iv") ? true : false;
}
virtual ReadResult readObject(const std::string& filename, const osgDB::ReaderWriter::Options* options) const
{
return readNode(filename, options);
}
virtual ReadResult readNode(const std::string& filename,
const osgDB::ReaderWriter::Options*) const;
virtual ReadResult readObject(std::istream& fin, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fin, options);
}
virtual ReadResult readNode(std::istream& fin,
const osgDB::ReaderWriter::Options* = NULL) const;

View File

@ -78,7 +78,10 @@ class ReaderWriterAC : public osgDB::ReaderWriter
}
virtual const char* className() const { return "AC3D Database Reader"; }
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fileName, options);
}
virtual ReadResult readNode(const std::string& file,const Options* options) const
{
std::string ext = osgDB::getFileExtension(file);
@ -110,6 +113,10 @@ class ReaderWriterAC : public osgDB::ReaderWriter
result.getNode()->setName(fileName);
return result;
}
virtual ReadResult readObject(std::istream& fin, const Options* options) const
{
return readNode(fin, options);
}
virtual ReadResult readNode(std::istream& fin, const Options* options) const
{
std::string header;

View File

@ -18,6 +18,11 @@ public:
virtual bool acceptsExtension(const std::string& extension) const;
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fileName, options);
}
virtual ReadResult readNode(const std::string& file,
const Options* options) const;
};

View File

@ -365,12 +365,22 @@ public:
virtual const char* className() const
{ return "BVH Motion Reader"; }
virtual ReadResult readObject(std::istream& stream, const osgDB::ReaderWriter::Options* options) const
{
return readNode(stream, options);
}
virtual ReadResult readNode(std::istream& stream, const osgDB::ReaderWriter::Options* options) const
{
ReadResult rr = BvhMotionBuilder::instance()->buildBVH( stream, options );
return rr;
}
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fileName, options);
}
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension( file );

View File

@ -40,7 +40,18 @@ public:
const char* className() const { return "COLLADA 1.4.x DAE reader/writer"; }
virtual ReadResult readObject(std::istream& fin, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fin, options);
}
ReadResult readNode(std::istream&, const Options* = NULL) const;
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fileName, options);
}
ReadResult readNode(const std::string&, const Options* = NULL) const;
WriteResult writeNode(const osg::Node&, const std::string&, const Options* = NULL) const;

View File

@ -44,6 +44,11 @@ public:
return "ReaderWriterDirectShow";
}
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
return readImage(file, options);
}
virtual ReadResult readImage(const std::string & filename, const osgDB::ReaderWriter::Options * options) const
{
const std::string ext = osgDB::getLowerCaseFileExtension(filename);

View File

@ -40,6 +40,11 @@ public:
virtual const char* className() const { return "Autodesk DXF Reader/Writer"; }
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fileName, options);
}
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) const;

View File

@ -132,6 +132,11 @@ public:
return "ReaderWriterFFmpeg";
}
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options =NULL) const
{
return readImage(file, options);
}
virtual ReadResult readImage(const std::string & filename, const osgDB::ReaderWriter::Options* options) const
{
const std::string ext = osgDB::getLowerCaseFileExtension(filename);

View File

@ -129,6 +129,10 @@ public:
return model.release();
}
virtual ReadResult readObject(const std::string& filename, const osgDB::ReaderWriter::Options* options) const
{
return readNode(filename, options);
}
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{

View File

@ -52,6 +52,11 @@ public:
return "ReaderWriterGStreamer";
}
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
return readImage(file, options);
}
virtual ReadResult readImage(const std::string & filename, const osgDB::ReaderWriter::Options* options) const
{
const std::string ext = osgDB::getLowerCaseFileExtension(filename);

View File

@ -69,6 +69,11 @@ public:
virtual const char* className() const { return "HDR Image Reader"; }
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
return readImage(file, options);
}
virtual ReadResult readImage(const std::string &_file, const osgDB::ReaderWriter::Options *_opts) const
{
std::string filepath = osgDB::findDataFile(_file, _opts);

View File

@ -43,7 +43,18 @@ public:
ReaderWriterKTX();
virtual const char* className() const;
virtual ReadResult readObject(std::istream& fin, const osgDB::ReaderWriter::Options* options) const
{
return readImage(fin, options);
}
virtual ReadResult readImage(std::istream& fin,const osgDB::ReaderWriter::Options* =NULL) const;
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
return readImage(file, options);
}
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const;
virtual WriteResult writeObject(const osg::Object& object, const std::string& file, const osgDB::ReaderWriter::Options* options) const;

View File

@ -34,6 +34,11 @@ class ReaderWriterLAS : public osgDB::ReaderWriter
virtual const char* className() const { return "LAS point cloud reader"; }
virtual ReadResult readObject(const std::string& filename, const osgDB::ReaderWriter::Options* options) const
{
return readNode(filename, options);
}
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
@ -51,6 +56,11 @@ class ReaderWriterLAS : public osgDB::ReaderWriter
return readNode(ifs, options);
}
virtual ReadResult readObject(std::istream& fin, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fin, options);
}
virtual ReadResult readNode(std::istream& ifs, const Options* options) const {
// Reading options
bool _verbose = false;

View File

@ -231,6 +231,11 @@ class LOGOReaderWriter : public osgDB::ReaderWriter
virtual const char* className() const { return "Logo Database Reader/Writer"; }
virtual ReadResult readObject(const std::string& filename, const osgDB::ReaderWriter::Options* options) const
{
return readNode(filename, options);
}
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);

View File

@ -53,6 +53,11 @@ public:
return "Quake MD2 Reader";
}
virtual ReadResult readObject(const std::string& filename, const osgDB::ReaderWriter::Options* options) const
{
return readNode(filename, options);
}
virtual ReadResult readNode (const std::string& filename, const osgDB::ReaderWriter::Options* options) const;
};

View File

@ -17,6 +17,11 @@ public:
virtual bool acceptsExtension(const std::string& extension) const;
virtual ReadResult readObject(const std::string& filename, const osgDB::ReaderWriter::Options* options) const
{
return readNode(filename, options);
}
virtual ReadResult readNode(const std::string& file,
const Options* options) const;
};

View File

@ -50,60 +50,74 @@ public:
return archive.get();
}
virtual ReadResult readImage(const std::string& file,const Options* options) const
enum ReadType
{
ReadResult result = openArchive(file,osgDB::Archive::READ);
READ_OBJECT,
READ_IMAGE,
READ_HEIGHT_FIELD,
READ_NODE,
READ_SHADER
};
virtual ReadResult readMasterFile(ReadType type, const std::string& file, const Options* options) const
{
ReadResult result = openArchive(file, osgDB::Archive::READ);
if (!result.validArchive()) return result;
// copy the incoming options if possible so that plugin options can be applied to files
// inside the archive
osg::ref_ptr<osgDB::ReaderWriter::Options> local_options =
options?
new osgDB::ReaderWriter::Options( *options ) :
new osgDB::ReaderWriter::Options;
local_options->setDatabasePath(file);
ReadResult result_2 = result.getArchive()->readImage(result.getArchive()->getMasterFileName(),local_options.get());
if (!options || (options->getObjectCacheHint() & osgDB::ReaderWriter::Options::CACHE_ARCHIVES))
{
// register the archive so that it is cached for future use.
osgDB::Registry::instance()->addToArchiveCache(file, result.getArchive());
}
return result_2;
}
virtual ReadResult readNode(const std::string& file,const Options* options) const
{
ReadResult result = openArchive(file,osgDB::Archive::READ);
if (!result.validArchive()) return result;
// copy the incoming options if possible so that plugin options can be applied to files
// inside the archive
osg::ref_ptr<osgDB::ReaderWriter::Options> local_options =
options?
new osgDB::ReaderWriter::Options( *options ) :
options ?
new osgDB::ReaderWriter::Options(*options) :
new osgDB::ReaderWriter::Options;
local_options->setDatabasePath(file);
ReadResult result_2 = result.getArchive()->readNode(result.getArchive()->getMasterFileName(),local_options.get());
if (!options || (options->getObjectCacheHint() & osgDB::ReaderWriter::Options::CACHE_ARCHIVES))
ReadResult result_2;
switch (type) {
default:
case READ_OBJECT:
return result.getArchive()->readObject(result.getArchive()->getMasterFileName(), local_options.get());
case READ_IMAGE:
return result.getArchive()->readImage(result.getArchive()->getMasterFileName(), local_options.get());
case READ_HEIGHT_FIELD:
return result.getArchive()->readHeightField(result.getArchive()->getMasterFileName(), local_options.get());
case READ_NODE:
return result.getArchive()->readNode(result.getArchive()->getMasterFileName(), local_options.get());
case READ_SHADER:
return result.getArchive()->readShader(result.getArchive()->getMasterFileName(), local_options.get());
}
}
virtual ReadResult readObject(const std::string& file, const Options* options) const
{
// register the archive so that it is cached for future use.
osgDB::Registry::instance()->addToArchiveCache(file, result.getArchive());
return readMasterFile(READ_OBJECT, file, options);
}
return result_2;
virtual ReadResult readImage(const std::string& file, const Options* options) const
{
return readMasterFile(READ_IMAGE, file, options);
}
virtual ReadResult readHeightField(const std::string& file, const Options* options) const
{
return readMasterFile(READ_HEIGHT_FIELD, file, options);
}
virtual ReadResult readNode(const std::string& file, const Options* options) const
{
return readMasterFile(READ_IMAGE, file, options);
}
virtual ReadResult readShader(const std::string& file, const Options* options) const
{
return readMasterFile(READ_SHADER, file, options);
}
protected:

View File

@ -76,6 +76,11 @@ public:
virtual const char* className() const { return "OSGJS json Writer"; }
virtual ReadResult readObject(const std::string& filename, const osgDB::ReaderWriter::Options* options) const
{
return readNode(filename, options);
}
virtual ReadResult readNode(const std::string& fileName, const Options* options) const;
virtual WriteResult writeNode(const Node& node,

View File

@ -34,6 +34,11 @@ class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter
virtual const char* className() const { return "OSGTGZ Database Reader/Writer"; }
virtual ReadResult readObject(const std::string& filename, const osgDB::ReaderWriter::Options* options) const
{
return readNode(filename, options);
}
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getFileExtension(file);

View File

@ -163,9 +163,19 @@ public:
osgDB::XmlNode::Properties::const_iterator findProperty(osgDB::XmlNode* cur, const char* token) const;
virtual ReadResult readObject(const std::string& filename, const osgDB::ReaderWriter::Options* options) const
{
return readNode(filename, options);
}
virtual ReadResult readNode(const std::string& fileName,
const osgDB::ReaderWriter::Options* options) const;
virtual ReadResult readObject(std::istream& fin, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fin, options);
}
virtual ReadResult readNode(std::istream& fin, const Options* options) const;
ReadResult readNode(osgDB::XmlNode::Input& input, osgDB::ReaderWriter::Options* options) const;

View File

@ -45,6 +45,12 @@ public:
}
virtual const char* className() const { return "ReaderWriterPLY"; }
virtual ReadResult readObject(const std::string& filename, const osgDB::ReaderWriter::Options* options) const
{
return readNode(filename, options);
}
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) const;
protected:
};

View File

@ -226,6 +226,11 @@ class ReaderWriterPNM : public osgDB::ReaderWriter
virtual const char* className() const { return "PNM Image Reader/Writer"; }
virtual ReadResult readObject(std::istream& fin, const Options* options) const
{
return readImage(fin,options);
}
virtual ReadResult readImage(std::istream& fin, const osgDB::ReaderWriter::Options* options=NULL) const
{
int ppmtype = 0; /* P1, P2, etc. */
@ -375,6 +380,11 @@ class ReaderWriterPNM : public osgDB::ReaderWriter
return pOsgImage;
}
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
return readImage(file,options);
}
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);

View File

@ -209,6 +209,11 @@ public:
acceptsLiveExtension(extension);
}
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
return readImage(file,options);
}
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
@ -364,6 +369,11 @@ public:
return image.release();
}
virtual ReadResult readObject(std::istream& fin, const Options* options) const
{
return readImage(fin,options);
}
virtual ReadResult readImage (std::istream& is, const osgDB::ReaderWriter::Options* options=NULL) const
{
std::string filename = "";

View File

@ -100,6 +100,11 @@ public:
virtual const char* className() const { return "rotation pseudo-loader"; }
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fileName, options);
}
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(fileName);

View File

@ -108,6 +108,11 @@ public:
return osgDB::equalCaseInsensitive( extension, EXTENSION_NAME );
}
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fileName, options);
}
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(fileName);

View File

@ -80,6 +80,11 @@ public:
virtual const char* className() const { return "osgShadow pseudo-loader"; }
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fileName, options);
}
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(fileName);

View File

@ -110,6 +110,11 @@ public:
return "STL Reader";
}
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fileName, options);
}
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) const;
virtual WriteResult writeNode(const osg::Node& node, const std::string& fileName, const Options* = NULL) const;

View File

@ -25,6 +25,11 @@ class ReaderWriterTerrain : public osgDB::ReaderWriter
virtual const char* className() const { return "Terrain ReaderWriter"; }
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fileName, options);
}
virtual osgDB::ReaderWriter::ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* opt) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);

View File

@ -33,6 +33,11 @@ class ReaderWriterTGZ : public osgDB::ReaderWriter
supportsExtension("tgz","Tar gzip'd archive format");
}
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fileName, options);
}
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);

View File

@ -101,6 +101,11 @@ public:
virtual const char* className() const { return "translation pseudo-loader"; }
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fileName, options);
}
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(fileName);

View File

@ -85,6 +85,10 @@ public:
virtual const char* className() const { return "VRML2 Reader/Writer"; }
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fileName, options);
}
virtual ReadResult readNode(const std::string&, const osgDB::Options *options) const;
// virtual ReadResult readNode(std::istream& fin, const osgDB::Options* options) const;

View File

@ -61,7 +61,18 @@ public:
return "DirectX Reader";
}
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fileName, options);
}
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const;
virtual ReadResult readObject(std::istream& fin, const Options* options) const
{
return readNode(fin,options);
}
virtual ReadResult readNode(std::istream& fin, const osgDB::ReaderWriter::Options* options) const;
private:

View File

@ -106,6 +106,10 @@ class ReaderWriterZIP : public osgDB::ReaderWriter
return result;
}
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
return readNode(fileName, options);
}
virtual osgDB::ReaderWriter::ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
@ -132,6 +136,11 @@ class ReaderWriterZIP : public osgDB::ReaderWriter
return readNodeFromArchive(*archive, local_options.get());
}
virtual ReadResult readObject(std::istream& fin, const Options* options) const
{
return readNode(fin,options);
}
virtual ReadResult readNode(std::istream& fin,const osgDB::ReaderWriter::Options* options) const
{
osgDB::ReaderWriter::ReadResult result = openArchive(fin, options);