Made read/write methods in ReaderWriter all const to facilate multi-threading

This commit is contained in:
Robert Osfield 2004-11-23 15:29:52 +00:00
parent ffcd95b004
commit d9b9a6f1f8
57 changed files with 556 additions and 997 deletions

View File

@ -58,7 +58,7 @@ ImageReaderWriter::ImageReaderWriter()
{
}
std::string ImageReaderWriter::insertReference(const std::string& fileName, unsigned int res, float width, float height, bool backPage)
std::string ImageReaderWriter::local_insertReference(const std::string& fileName, unsigned int res, float width, float height, bool backPage)
{
std::stringstream ostr;
ostr<<"res_"<<res<<"_"<<fileName;
@ -105,7 +105,7 @@ osg::Image* ImageReaderWriter::readImage_DynamicSampling(DataReference& dr, floa
}
osgDB::ReaderWriter::ReadResult ImageReaderWriter::readNode(const std::string& fileName, const Options*)
osgDB::ReaderWriter::ReadResult ImageReaderWriter::local_readNode(const std::string& fileName, const Options*)
{
DataReferenceMap::iterator itr = _dataReferences.find(fileName);
if (itr==_dataReferences.end()) return osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED;

View File

@ -17,8 +17,13 @@
#include <osgDB/WriteFile>
#include <osgDB/ImageOptions>
#include <OpenThreads/ScopedLock>
#include <osgDB/ReentrantMutex>
#include "PhotoArchive.h"
#define SERIALIZER() OpenThreads::ScopedLock<osgDB::ReentrantMutex> lock(_serializerMutex)
class ImageReaderWriter : public osgDB::ReaderWriter
{
public:
@ -29,12 +34,26 @@ class ImageReaderWriter : public osgDB::ReaderWriter
void addPhotoArchive(PhotoArchive* archive) { _photoArchiveList.push_back(archive); }
std::string insertReference(const std::string& fileName, unsigned int res, float width, float height, bool backPage);
std::string insertReference(const std::string& fileName, unsigned int res, float width, float height, bool backPage)
{
SERIALIZER();
return insertReference(fileName, res, width, height, backPage);
}
virtual ReadResult readNode(const std::string& fileName, const Options* options) const
{
SERIALIZER();
return readNode(fileName, options);
}
virtual ReadResult readNode(const std::string& fileName, const Options*);
protected:
std::string local_insertReference(const std::string& fileName, unsigned int res, float width, float height, bool backPage);
ReadResult local_readNode(const std::string& fileName, const Options*);
mutable osgDB::ReentrantMutex _serializerMutex;
struct DataReference
{

View File

@ -50,15 +50,15 @@ class OSGDB_EXPORT Archive : public ReaderWriter
/** Get the full list of file names available in the archive.*/
virtual bool getFileNames(FileNameList& fileNameList) const = 0;
virtual ReadResult readObject(const std::string& /*fileName*/,const Options* =NULL) = 0;
virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) = 0;
virtual ReadResult readHeightField(const std::string& /*fileName*/,const Options* =NULL) = 0;
virtual ReadResult readNode(const std::string& /*fileName*/,const Options* =NULL) = 0;
virtual ReadResult readObject(const std::string& /*fileName*/,const Options* =NULL) const = 0;
virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) const = 0;
virtual ReadResult readHeightField(const std::string& /*fileName*/,const Options* =NULL) const = 0;
virtual ReadResult readNode(const std::string& /*fileName*/,const Options* =NULL) const = 0;
virtual WriteResult writeObject(const osg::Object& /*obj*/,const std::string& /*fileName*/,const Options* =NULL) = 0;
virtual WriteResult writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const Options* =NULL) = 0;
virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,const std::string& /*fileName*/,const Options* =NULL) = 0;
virtual WriteResult writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options* =NULL) = 0;
virtual WriteResult writeObject(const osg::Object& /*obj*/,const std::string& /*fileName*/,const Options* =NULL) const = 0;
virtual WriteResult writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const Options* =NULL) const = 0;
virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,const std::string& /*fileName*/,const Options* =NULL) const = 0;
virtual WriteResult writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options* =NULL) const = 0;

View File

@ -43,7 +43,7 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
META_Object(osgDB,ReaderWriter);
virtual bool acceptsExtension(const std::string& /*extension*/) { return false; }
virtual bool acceptsExtension(const std::string& /*extension*/) const { return false; }
/** Options base class used for passing options into plugins to control their operation.*/
class Options : public osg::Object
@ -80,14 +80,14 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
};
Options():_useObjectCacheHint(CACHE_ARCHIVES) {}
Options():_objectCacheHint(CACHE_ARCHIVES) {}
Options(const std::string& str):_str(str) {}
Options(const Options& options,const osg::CopyOp copyop=osg::CopyOp::SHALLOW_COPY):
Object(options,copyop),
_str(options._str),
_databasePaths(options._databasePaths),
_useObjectCacheHint(options._useObjectCacheHint) {}
_objectCacheHint(options._objectCacheHint) {}
META_Object(osgDB,Options);
@ -107,10 +107,10 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
const FilePathList& getDatabasePathList() const { return _databasePaths; }
/** Set whether the Registry::ObjectCache should be used by default.*/
void setUseObjectCacheHint(CacheHintOptions useObjectCache) { _useObjectCacheHint = useObjectCache; }
void setObjectCacheHint(CacheHintOptions useObjectCache) { _objectCacheHint = useObjectCache; }
/** Get whether the Registry::ObjectCache should be used by default.*/
CacheHintOptions getUseObjectCacheHint() const { return _useObjectCacheHint; }
CacheHintOptions getObjectCacheHint() const { return _objectCacheHint; }
protected:
@ -119,7 +119,7 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
std::string _str;
FilePathList _databasePaths;
CacheHintOptions _useObjectCacheHint;
CacheHintOptions _objectCacheHint;
};
@ -216,30 +216,30 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
};
/** open an archive for reading, writing or or to create an empty archive for writing to.*/
virtual ReadResult openArchive(const std::string& /*fileName*/,ArchiveStatus, unsigned int =4096, const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult openArchive(const std::string& /*fileName*/,ArchiveStatus, unsigned int =4096, const Options* =NULL) const { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
/** open an archive for reading.*/
virtual ReadResult openArchive(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult openArchive(std::istream& /*fin*/,const Options* =NULL) const { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
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 readHeightField(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 ReadResult readObject(const std::string& /*fileName*/,const Options* =NULL) const { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) const { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readHeightField(const std::string& /*fileName*/,const Options* =NULL) const { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readNode(const std::string& /*fileName*/,const Options* =NULL) const { 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 writeHeightField(const osg::HeightField& /*heightField*/,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); }
virtual WriteResult writeObject(const osg::Object& /*obj*/,const std::string& /*fileName*/,const Options* =NULL) const {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const Options* =NULL) const {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,const std::string& /*fileName*/,const Options* =NULL) const {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options* =NULL) const { return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual ReadResult readObject(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readImage(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readHeightField(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readNode(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readObject(std::istream& /*fin*/,const Options* =NULL) const { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readImage(std::istream& /*fin*/,const Options* =NULL) const { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readHeightField(std::istream& /*fin*/,const Options* =NULL) const { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readNode(std::istream& /*fin*/,const Options* =NULL) const { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual WriteResult writeObject(const osg::Object& /*obj*/,std::ostream& /*fout*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeImage(const osg::Image& /*image*/,std::ostream& /*fout*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,std::ostream& /*fout*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeNode(const osg::Node& /*node*/,std::ostream& /*fout*/,const Options* =NULL) { return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeObject(const osg::Object& /*obj*/,std::ostream& /*fout*/,const Options* =NULL) const { return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeImage(const osg::Image& /*image*/,std::ostream& /*fout*/,const Options* =NULL) const { return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,std::ostream& /*fout*/,const Options* =NULL) const { return WriteResult(WriteResult::FILE_NOT_HANDLED); }
virtual WriteResult writeNode(const osg::Node& /*node*/,std::ostream& /*fout*/,const Options* =NULL) const { return WriteResult(WriteResult::FILE_NOT_HANDLED); }
};

View File

@ -1352,7 +1352,7 @@ ReaderWriter::ReadResult Registry::readImplementation(const ReadFunctor& readFun
ReaderWriter::ReadResult Registry::openArchiveImplementation(const std::string& fileName, ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const ReaderWriter::Options* options)
{
if (options && (options->getUseObjectCacheHint() & ReaderWriter::Options::CACHE_ARCHIVES))
if (options && (options->getObjectCacheHint() & ReaderWriter::Options::CACHE_ARCHIVES))
{
osgDB::Archive* archive = getFromArchiveCache(fileName);
if (archive) return archive;
@ -1374,7 +1374,7 @@ ReaderWriter::ReadResult Registry::openArchiveImplementation(const std::string&
ReaderWriter::ReadResult Registry::readObjectImplementation(const std::string& fileName,const ReaderWriter::Options* options)
{
return readImplementation(ReadObjectFunctor(fileName, options),
options ? (options->getUseObjectCacheHint()&ReaderWriter::Options::CACHE_OBJECTS): false);
options ? (options->getObjectCacheHint()&ReaderWriter::Options::CACHE_OBJECTS): false);
}
ReaderWriter::WriteResult Registry::writeObjectImplementation(const Object& obj,const std::string& fileName)
@ -1417,7 +1417,7 @@ ReaderWriter::WriteResult Registry::writeObjectImplementation(const Object& obj,
ReaderWriter::ReadResult Registry::readImageImplementation(const std::string& fileName,const ReaderWriter::Options* options)
{
return readImplementation(ReadImageFunctor(fileName, options),
options ? (options->getUseObjectCacheHint()&ReaderWriter::Options::CACHE_IMAGES): false);
options ? (options->getObjectCacheHint()&ReaderWriter::Options::CACHE_IMAGES): false);
}
ReaderWriter::WriteResult Registry::writeImageImplementation(const Image& image,const std::string& fileName)
@ -1459,7 +1459,7 @@ ReaderWriter::WriteResult Registry::writeImageImplementation(const Image& image,
ReaderWriter::ReadResult Registry::readHeightFieldImplementation(const std::string& fileName,const ReaderWriter::Options* options)
{
return readImplementation(ReadHeightFieldFunctor(fileName, options),
options ? (options->getUseObjectCacheHint()&ReaderWriter::Options::CACHE_HEIGHTFIELDS): false);
options ? (options->getObjectCacheHint()&ReaderWriter::Options::CACHE_HEIGHTFIELDS): false);
}
ReaderWriter::WriteResult Registry::writeHeightFieldImplementation(const HeightField& HeightField,const std::string& fileName)
@ -1501,7 +1501,7 @@ ReaderWriter::WriteResult Registry::writeHeightFieldImplementation(const HeightF
ReaderWriter::ReadResult Registry::readNodeImplementation(const std::string& fileName,const ReaderWriter::Options* options)
{
return readImplementation(ReadNodeFunctor(fileName, options),
options ? (options->getUseObjectCacheHint()&ReaderWriter::Options::CACHE_NODES): false);
options ? (options->getObjectCacheHint()&ReaderWriter::Options::CACHE_NODES): false);
}
ReaderWriter::WriteResult Registry::writeNodeImplementation(const Node& node,const std::string& fileName)

View File

@ -17,13 +17,13 @@ class ReaderWriter3DC : public osgDB::ReaderWriter
public:
virtual const char* className() const { return "3DC point cloud reader"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"3dc") ||
osgDB::equalCaseInsensitive(extension,"asc");
}
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

View File

@ -22,7 +22,7 @@ ReaderWriterIV::ReaderWriterIV()
// Read file and convert to OSG
osgDB::ReaderWriter::ReadResult
ReaderWriterIV::readNode(const std::string& file,
const osgDB::ReaderWriter::Options* options)
const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

View File

@ -14,14 +14,14 @@ class ReaderWriterIV : public osgDB::ReaderWriter
return "Inventor Reader";
}
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension, "iv") ? true :
osgDB::equalCaseInsensitive(extension, "wrl") ? true : false;
}
virtual ReadResult readNode(const std::string& filename,
const osgDB::ReaderWriter::Options *);
const osgDB::ReaderWriter::Options *) const;
};

View File

@ -72,11 +72,11 @@ class ReaderWriterAC : public osgDB::ReaderWriter
public:
virtual const char* className() const { return "AC3D Database Reader"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"ac");
}
virtual ReadResult readNode(const std::string& file,const osgDB::ReaderWriter::Options* options)
virtual ReadResult readNode(const std::string& file,const osgDB::ReaderWriter::Options* options) const
{
osg::Group *grp; // holder for all loaded objects
// GWM added Dec 2003 - get full path name (change in osgDB handling of files).
@ -92,7 +92,7 @@ class ReaderWriterAC : public osgDB::ReaderWriter
grp=ac_load_ac3d(fileName.c_str(), local_opt.get());
return grp;
};
virtual WriteResult writeNode(const Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options* /*options*/)
virtual WriteResult writeNode(const Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options* /*options*/) const
{
std::string ext = getFileExtension(fileName);
if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;
@ -121,7 +121,7 @@ class ReaderWriterAC : public osgDB::ReaderWriter
return WriteResult::FILE_SAVED;
}
virtual WriteResult writeNode(const Node& node,std::ostream& fout, const osgDB::ReaderWriter::Options* opts)
virtual WriteResult writeNode(const Node& node,std::ostream& fout, const osgDB::ReaderWriter::Options* opts) const
{
try
{

View File

@ -317,9 +317,9 @@ class ReaderWriterBMP : public osgDB::ReaderWriter
{
public:
virtual const char* className() const { return "BMP Image Reader"; }
virtual bool acceptsExtension(const std::string& extension) { return osgDB::equalCaseInsensitive(extension,"bmp"); }
virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"bmp"); }
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
@ -362,7 +362,7 @@ class ReaderWriterBMP : public osgDB::ReaderWriter
return pOsgImage;
}
virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options*)
virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options*) const
{
std::string ext = osgDB::getFileExtension(fileName);
if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;

View File

@ -701,22 +701,22 @@ public:
return "DDS Image Reader/Writer";
}
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"dds");
}
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
return readImage(file,options);
}
virtual ReadResult readObject(std::istream& fin, const Options* options)
virtual ReadResult readObject(std::istream& fin, const Options* options) const
{
return readImage(fin,options);
}
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
@ -731,7 +731,7 @@ public:
return rr;
}
virtual ReadResult readImage(std::istream& fin, const Options* options)
virtual ReadResult readImage(std::istream& fin, const Options* options) const
{
osg::Image* osgImage = ReadDDSFile(fin);
if (osgImage==NULL) return ReadResult::FILE_NOT_HANDLED;
@ -744,7 +744,7 @@ public:
return osgImage;
}
virtual WriteResult writeObject(const osg::Object& object,const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual WriteResult writeObject(const osg::Object& object,const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
const osg::Image* image = dynamic_cast<const osg::Image*>(&object);
if (!image) return WriteResult::FILE_NOT_HANDLED;
@ -752,7 +752,7 @@ public:
return writeImage(*image,file,options);
}
virtual WriteResult writeObject(const osg::Object& object,std::ostream& fout,const Options* options)
virtual WriteResult writeObject(const osg::Object& object,std::ostream& fout,const Options* options) const
{
const osg::Image* image = dynamic_cast<const osg::Image*>(&object);
if (!image) return WriteResult::FILE_NOT_HANDLED;
@ -761,7 +761,7 @@ public:
}
virtual WriteResult writeImage(const osg::Image &image,const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual WriteResult writeImage(const osg::Image &image,const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getFileExtension(file);
if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;
@ -772,7 +772,7 @@ public:
return writeImage(image,fout,options);
}
virtual WriteResult writeImage(const osg::Image& image,std::ostream& fout,const Options*)
virtual WriteResult writeImage(const osg::Image& image,std::ostream& fout,const Options*) const
{
bool success = WriteDDSFile(&image, fout);

View File

@ -54,16 +54,16 @@ public:
return "DirectX Reader/Writer";
}
virtual bool acceptsExtension(const std::string& extension) {
return osgDB::equalCaseInsensitive(extension,"x") ? true : false;
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"x");
}
virtual ReadResult readNode(const std::string& fileName,
const osgDB::ReaderWriter::Options* options);
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const;
private:
osg::Geode* convertFromDX(DX::Object& obj, bool flipTexture, float creaseAngle,
const osgDB::ReaderWriter::Options* options);
const osgDB::ReaderWriter::Options* options) const;
};
// Register with Registry to instantiate the above reader/writer.
@ -71,8 +71,7 @@ osgDB::RegisterReaderWriterProxy<ReaderWriterDirectX> g_readerWriter_DirectX_Pro
// Read node
osgDB::ReaderWriter::ReadResult ReaderWriterDirectX::readNode(const std::string& file,
const osgDB::ReaderWriter::Options* options)
osgDB::ReaderWriter::ReadResult ReaderWriterDirectX::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
@ -118,7 +117,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterDirectX::readNode(const std::string&
// Convert DirectX mesh to osg::Geode
osg::Geode* ReaderWriterDirectX::convertFromDX(DX::Object& obj,
bool flipTexture, float creaseAngle,
const osgDB::ReaderWriter::Options* options)
const osgDB::ReaderWriter::Options* options) const
{
// Fetch mesh
const DX::Mesh* mesh = obj.getMesh();

View File

@ -794,12 +794,12 @@ class ReaderWriterDW : public osgDB::ReaderWriter
public:
virtual const char* className() const { return "Design Workshop Database Reader"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"dw");
}
virtual ReadResult readNode(const std::string& file,const osgDB::ReaderWriter::Options* options)
virtual ReadResult readNode(const std::string& file,const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);

View File

@ -24,10 +24,7 @@
#include "DXWriter.h"
// FIXME: Support options
osgDB::ReaderWriter::WriteResult ReaderWriterDX::writeObject(
const osg::Object &obj,
const std::string &filename,
const Options *options )
osgDB::ReaderWriter::WriteResult ReaderWriterDX::writeObject(const osg::Object &obj, const std::string &filename, const Options *options ) const
{
const osg::Node *node = dynamic_cast<const osg::Node *>(&obj);
@ -39,10 +36,7 @@ osgDB::ReaderWriter::WriteResult ReaderWriterDX::writeObject(
}
osgDB::ReaderWriter::WriteResult ReaderWriterDX::writeNode(
const osg::Node &node,
const std::string &filename,
const Options *)
osgDB::ReaderWriter::WriteResult ReaderWriterDX::writeNode(const osg::Node &node, const std::string &filename, const Options *) const
{
dx::WriterParms parms;
std::string messages;

View File

@ -31,16 +31,12 @@ class ReaderWriterDX : public osgDB::ReaderWriter
public:
virtual const char* className() { return "OpenDX Writer"; }
virtual bool acceptsExtension( const std::string &extension )
virtual bool acceptsExtension( const std::string &extension ) const
{ return osgDB::equalCaseInsensitive( extension, "dx" ); }
virtual WriteResult writeObject( const osg::Object &obj,
const std::string &filename,
const Options *options = NULL );
virtual WriteResult writeObject( const osg::Object &obj, const std::string &filename, const Options *options = NULL ) const;
virtual WriteResult writeNode ( const osg::Node &node,
const std::string &filename,
const Options *options = NULL );
virtual WriteResult writeNode ( const osg::Node&node, const std::string &filename, const Options *options = NULL ) const;
};

View File

@ -744,12 +744,12 @@ class ReaderWriterATTR : public osgDB::ReaderWriter
public:
virtual const char* className() const { return "ATTR Image Attribute Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"attr");
}
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

View File

@ -17,13 +17,13 @@
using namespace flt;
osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* opt)
osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* opt) const
{
return readNode(fileName,opt);
}
osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options)
osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

View File

@ -49,13 +49,13 @@ class ReaderWriterFLT : public osgDB::ReaderWriter
public:
virtual const char* className() const { return "FLT Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"flt");
}
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options*);
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*);
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options*) const;
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) const;
};

View File

@ -9,7 +9,7 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter
public:
virtual const char* className() const { return "FreeType Font Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"ttf") || // true type
osgDB::equalCaseInsensitive(extension,"ttc") || // true type
@ -22,7 +22,7 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter
osgDB::equalCaseInsensitive(extension,"fnt"); // Windows bitmap fonts
}
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

View File

@ -8,18 +8,35 @@
#include <osgDB/FileUtils>
#include <osgDB/ImageOptions>
#include <OpenThreads/ScopedLock>
#include <osgDB/ReentrantMutex>
#include <gdal_priv.h>
#define SERIALIZER() OpenThreads::ScopedLock<osgDB::ReentrantMutex> lock(_serializerMutex)
class ReaderWriterGDAL : public osgDB::ReaderWriter
{
public:
virtual const char* className() const { return "GDAL Image Reader"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"gdal") || osgDB::equalCaseInsensitive(extension,"gdal");
}
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
OpenThreads::ScopedLock<osgDB::ReentrantMutex> lock(_serializerMutex);
return const_cast<ReaderWriterGDAL*>(this)->local_readImage(fileName, options);
}
virtual ReadResult readHeightField(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
OpenThreads::ScopedLock<osgDB::ReentrantMutex> lock(_serializerMutex);
return const_cast<ReaderWriterGDAL*>(this)->local_readHeightField(fileName, options);
}
virtual ReadResult local_readImage(const std::string& file, const osgDB::ReaderWriter::Options* options)
{
// Looks like gdal's GDALRasterBand::GetColorInterpretation()
// is not giving proper values for ecw images. There is small
@ -377,7 +394,8 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
}
virtual ReadResult readHeightField(const std::string& fileName, const osgDB::ReaderWriter::Options* options)
ReadResult local_readHeightField(const std::string& fileName, const osgDB::ReaderWriter::Options* options)
{
//std::string ext = osgDB::getFileExtension(fileName);
//if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
@ -596,6 +614,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
}
}
mutable osgDB::ReentrantMutex _serializerMutex;
};

View File

@ -388,31 +388,20 @@ private:
};
class ReaderWriterGEO : public osgDB::ReaderWriter
class ReaderGEO
{
public:
virtual const char* className() const { return "GEO Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension)
osgDB::ReaderWriter::ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options)
{
return osgDB::equalCaseInsensitive(extension,"gem") || osgDB::equalCaseInsensitive(extension,"geo");
}
virtual ReadResult readObject(const std::string& fileName, const Options* opt) { return readNode(fileName,opt); }
virtual ReadResult readNode(const std::string& file, const Options* options)
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
std::string fileName = osgDB::findDataFile( file, options );
if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;
std::ifstream fin(fileName.c_str(), std::ios::binary | std::ios::in );
if (fin.is_open() )
{ // read the input file.
// code for setting up the database path so that internally referenced file are searched for on relative paths.
osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options;
osg::ref_ptr<osgDB::ReaderWriter::Options> local_opt = options ?
static_cast<osgDB::ReaderWriter::Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) :
new osgDB::ReaderWriter::Options;
local_opt->setDatabasePath(osgDB::getFilePath(fileName));
typedef std::vector<osg::Node*> NodeList;
@ -457,7 +446,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter
osg::Node * groupnode = NULL;
if (nodeList.empty())
{
return ReadResult("No data loaded from "+fileName);
return osgDB::ReaderWriter::ReadResult("No data loaded from "+fileName);
}
else if (nodeList.size()==1)
{
@ -1396,7 +1385,8 @@ class ReaderWriterGEO : public osgDB::ReaderWriter
}
return clp;
}
geoHeader *makeHeader(const georecord *gr, const Options* options) {
geoHeader *makeHeader(const georecord *gr, const osgDB::ReaderWriter::Options* options) {
if (!theHeader.valid()) theHeader=new geoHeaderGeo();
// the header contains variables as well as a transform for the XYZup cases
const geoField *gfd;
@ -1459,7 +1449,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter
}
return theHeader.get();
}
void makeTexture(const georecord *gr, const Options* options) {
void makeTexture(const georecord *gr, const osgDB::ReaderWriter::Options* options) {
// scans the fields of this record and puts a new texture & environment into 'pool' stor
const geoField *gfd=gr->getField(GEO_DB_TEX_FILE_NAME);
const char *name = gfd->getChar();
@ -1697,7 +1687,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter
}
return mtr;
}
std::vector<Node *> makeosg(const std::vector<georecord *> gr, const Options* options) {
std::vector<Node *> makeosg(const std::vector<georecord *> gr, const osgDB::ReaderWriter::Options* options) {
// recursive traversal of records and extract osg::Nodes equivalent
Group *geodeholder=NULL;
std::vector<Node *> nodelist;
@ -2201,6 +2191,33 @@ void geoField::readfile(std::ifstream &fin, const uint id) { // is part of a rec
}
class ReaderWriterGEO : public osgDB::ReaderWriter
{
public:
virtual const char* className() const { return "GEO Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"gem") || osgDB::equalCaseInsensitive(extension,"geo");
}
virtual ReadResult readObject(const std::string& fileName, const Options* opt) const { return readNode(fileName,opt); }
virtual ReadResult readNode(const std::string& file, const Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
std::string fileName = osgDB::findDataFile( file, options );
if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;
ReaderGEO reader;
return reader.readNode(fileName,options);
}
};
// now register with Registry to instantiate the above
// reader/writer.
osgDB::RegisterReaderWriterProxy<ReaderWriterGEO> gReaderWriter_GEO_Proxy;

View File

@ -319,12 +319,12 @@ class ReaderWriterGIF : public osgDB::ReaderWriter
{
public:
virtual const char* className() const { return "GIF Image Reader"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"gif");
}
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

View File

@ -15,17 +15,17 @@ class IVEReaderWriter : public ReaderWriter
public:
virtual const char* className() const { return "IVE Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return equalCaseInsensitive(extension,"ive");
}
virtual ReadResult readObject(const std::string& file, const Options* options)
virtual ReadResult readObject(const std::string& file, const Options* options) const
{
return readNode(file, options);
}
virtual ReadResult readNode(const std::string& file, const Options* options)
virtual ReadResult readNode(const std::string& file, const Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
@ -41,12 +41,12 @@ class IVEReaderWriter : public ReaderWriter
return readNode(istream,local_opt.get());
}
virtual ReadResult readObject(std::istream& fin, const Options* options)
virtual ReadResult readObject(std::istream& fin, const Options* options) const
{
return readNode(fin, options);
}
virtual ReadResult readNode(std::istream& fin, const Options* options)
virtual ReadResult readNode(std::istream& fin, const Options* options) const
{
#define IVE_CATCH_EXCEPTIONS
#ifdef IVE_CATCH_EXCEPTIONS
@ -70,14 +70,14 @@ class IVEReaderWriter : public ReaderWriter
virtual WriteResult writeObject(const Object& object,const std::string& fileName, const osgDB::ReaderWriter::Options* options)
virtual WriteResult writeObject(const Object& object,const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
const Node* node = dynamic_cast<const Node*>(&object);
if (node) return writeNode( *node, fileName, options );
return WriteResult::FILE_NOT_HANDLED;
}
virtual WriteResult writeNode(const Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options* options)
virtual WriteResult writeNode(const Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = getFileExtension(fileName);
if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;
@ -88,14 +88,14 @@ class IVEReaderWriter : public ReaderWriter
return result;
}
virtual WriteResult writeObject(const Object& object,std::ostream& fout, const osgDB::ReaderWriter::Options* options)
virtual WriteResult writeObject(const Object& object,std::ostream& fout, const osgDB::ReaderWriter::Options* options) const
{
const Node* node = dynamic_cast<const Node*>(&object);
if (node) return writeNode( *node, fout, options );
return WriteResult::FILE_NOT_HANDLED;
}
virtual WriteResult writeNode(const Node& node,std::ostream& fout, const osgDB::ReaderWriter::Options* options)
virtual WriteResult writeNode(const Node& node,std::ostream& fout, const osgDB::ReaderWriter::Options* options) const
{
try
{

View File

@ -172,24 +172,24 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter
public:
virtual const char* className() const { return "RGB Image Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"jp2") ||
osgDB::equalCaseInsensitive(extension,"jpc");
}
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
return readImage(file,options);
}
virtual ReadResult readObject(std::istream& fin, const Options* options)
virtual ReadResult readObject(std::istream& fin, const Options* options) const
{
return readImage(fin,options);
}
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
@ -256,7 +256,7 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter
}
virtual ReadResult readImage(std::istream& fin,const Options* options)
virtual ReadResult readImage(std::istream& fin,const Options* options) const
{
char c;
char * sdata;
@ -325,7 +325,7 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter
return image;
}
virtual WriteResult writeObject(const osg::Object& object,const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual WriteResult writeObject(const osg::Object& object,const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
const osg::Image* image = dynamic_cast<const osg::Image*>(&object);
if (!image) return WriteResult::FILE_NOT_HANDLED;
@ -333,7 +333,7 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter
return writeImage(*image,file,options);
}
virtual WriteResult writeObject(const osg::Object& object,std::ostream& fout,const Options* options)
virtual WriteResult writeObject(const osg::Object& object,std::ostream& fout,const Options* options) const
{
const osg::Image* image = dynamic_cast<const osg::Image*>(&object);
if (!image) return WriteResult::FILE_NOT_HANDLED;
@ -341,7 +341,7 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter
return writeImage(*image,fout,options);
}
virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options* options)
virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getFileExtension(fileName);
if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;
@ -423,7 +423,7 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter
return WriteResult::FILE_SAVED;
}
WriteResult writeImage(const osg::Image& img, std::ostream& fout, const Options* options)
WriteResult writeImage(const osg::Image& img, std::ostream& fout, const Options* options) const
{
jas_init();

View File

@ -304,7 +304,7 @@ int *numComponents_ret)
class ReaderWriterJPEG : public osgDB::ReaderWriter
{
WriteResult::WriteStatus write_JPEG_file (const char* filename,int image_width,int image_height,JSAMPLE* image_buffer,int quality = 100)
WriteResult::WriteStatus write_JPEG_file (const char* filename,int image_width,int image_height,JSAMPLE* image_buffer,int quality = 100) const
{
/* This struct contains the JPEG compression parameters and pointers to
* working space (which is allocated as needed by the JPEG library).
@ -412,7 +412,7 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter
/* And we're done! */
return WriteResult::FILE_SAVED;
}
int getQuality(const osgDB::ReaderWriter::Options *options) {
int getQuality(const osgDB::ReaderWriter::Options *options) const {
if(options) {
std::istringstream iss(options->getOptionString());
std::string opt;
@ -429,12 +429,12 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter
}
public:
virtual const char* className() const { return "JPEG Image Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"jpeg") || osgDB::equalCaseInsensitive(extension,"jpg");
}
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
@ -481,7 +481,7 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter
return pOsgImage;
}
virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options *options)
virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options *options) const
{
std::string ext = osgDB::getFileExtension(fileName);
if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;

View File

@ -91,9 +91,9 @@ class ReaderWriter3DS : public osgDB::ReaderWriter
ReaderWriter3DS();
virtual const char* className() const { return "3DS Auto Studio Reader"; }
virtual bool acceptsExtension(const std::string& extension) { return osgDB::equalCaseInsensitive(extension,"3ds"); }
virtual bool accpettsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"3ds"); }
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options);
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const;
protected:
@ -416,7 +416,7 @@ osg::Node* ReaderWriter3DS::ReaderObject::processNode(StateSetMap drawStateMap,L
}
osgDB::ReaderWriter::ReadResult ReaderWriter3DS::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options)
osgDB::ReaderWriter::ReadResult ReaderWriter3DS::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);

View File

@ -186,12 +186,12 @@ class LOGOReaderWriter : public osgDB::ReaderWriter
public:
virtual const char* className() const { return "Logo Database Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"logo");
}
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

View File

@ -47,11 +47,11 @@ public:
ReaderWriterLWO() { }
virtual const char* className() const { return "Lightwave Object Reader"; }
virtual bool acceptsExtension(const std::string& extension) {
virtual bool acceptsExtension(const std::string& extension) const {
return osgDB::equalCaseInsensitive(extension,"lwo") || osgDB::equalCaseInsensitive(extension,"lw") || osgDB::equalCaseInsensitive(extension,"geo");
}
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
@ -76,9 +76,9 @@ public:
lwosg::Converter::Options parse_options(const Options *options) const;
virtual ReadResult readNode_LWO2(const std::string& fileName, const osgDB::ReaderWriter::Options*);
virtual ReadResult readNode_old_LWO2(const std::string& fileName, const osgDB::ReaderWriter::Options*);
virtual ReadResult readNode_LWO1(const std::string& fileName, const osgDB::ReaderWriter::Options*);
virtual ReadResult readNode_LWO2(const std::string& fileName, const osgDB::ReaderWriter::Options*) const;
virtual ReadResult readNode_old_LWO2(const std::string& fileName, const osgDB::ReaderWriter::Options*) const;
virtual ReadResult readNode_LWO1(const std::string& fileName, const osgDB::ReaderWriter::Options*) const;
protected:
@ -113,7 +113,7 @@ lwosg::Converter::Options ReaderWriterLWO::parse_options(const Options *options)
// register with Registry to instantiate the above reader/writer.
osgDB::RegisterReaderWriterProxy<ReaderWriterLWO> g_lwoReaderWriterProxy;
osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO2(const std::string &fileName, const osgDB::ReaderWriter::Options *options)
osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO2(const std::string &fileName, const osgDB::ReaderWriter::Options *options) const
{
lwosg::Converter::Options conv_options = parse_options(options);
@ -127,7 +127,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO2(const std::string
}
osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_old_LWO2(const std::string& fileName, const osgDB::ReaderWriter::Options*)
osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_old_LWO2(const std::string& fileName, const osgDB::ReaderWriter::Options*) const
{
std::auto_ptr<Lwo2> lwo2(new Lwo2());
if (lwo2->ReadFile(fileName))
@ -168,7 +168,7 @@ struct GeometryCollection
// read file and convert to OSG.
osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO1(const std::string& fileName, const osgDB::ReaderWriter::Options*)
osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO1(const std::string& fileName, const osgDB::ReaderWriter::Options*) const
{
lwObject* lw = lw_object_read(fileName.c_str(),osg::notify(osg::INFO));
if (!lw)

View File

@ -27,11 +27,11 @@ public:
virtual const char* className() const { return "ReaderWriterLWS"; }
virtual bool acceptsExtension(const std::string &extension) {
virtual bool acceptsExtension(const std::string &extension) const {
return osgDB::equalCaseInsensitive(extension, "lws");
}
virtual ReadResult readNode(const std::string &file, const osgDB::ReaderWriter::Options *options)
virtual ReadResult readNode(const std::string &file, const osgDB::ReaderWriter::Options *options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

View File

@ -49,19 +49,17 @@ public:
return "Quake MD2 Reader";
}
virtual bool acceptsExtension (const std::string& extension) {
virtual bool acceptsExtension (const std::string& extension) const {
return osgDB::equalCaseInsensitive (extension, "md2") ? true : false;
}
virtual ReadResult readNode (const std::string& filename,
const osgDB::ReaderWriter::Options* options);
virtual ReadResult readNode (const std::string& filename, const osgDB::ReaderWriter::Options* options) const;
};
osgDB::RegisterReaderWriterProxy<ReaderWriterMD2> g_readerWriter_MD2_Proxy;
osgDB::ReaderWriter::ReadResult
ReaderWriterMD2::readNode (const std::string& file,
const osgDB::ReaderWriter::Options* options)
ReaderWriterMD2::readNode (const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

View File

@ -15,13 +15,13 @@ class ReaderWriterMPEG : public osgDB::ReaderWriter
virtual const char* className() const { return "MPEG ImageStream Reader"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"mpg") ||
osgDB::equalCaseInsensitive(extension,"mpv");
}
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

View File

@ -78,7 +78,7 @@ class NetReader : public osgDB::ReaderWriter
virtual const char* className() const { return "HTTP Protocol Model Reader"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"net");
}
@ -92,33 +92,33 @@ class NetReader : public osgDB::ReaderWriter
NODE
};
virtual ReadResult openArchive(const std::string& fileName,ArchiveStatus status, unsigned int , const Options* options)
virtual ReadResult openArchive(const std::string& fileName,ArchiveStatus status, unsigned int , const Options* options) const
{
if (status!=READ) return ReadResult(ReadResult::FILE_NOT_HANDLED);
else return readFile(ARCHIVE,fileName,options);
}
virtual ReadResult readObject(const std::string& fileName, const Options* options)
virtual ReadResult readObject(const std::string& fileName, const Options* options) const
{
return readFile(OBJECT,fileName,options);
}
virtual ReadResult readImage(const std::string& fileName, const Options *options)
virtual ReadResult readImage(const std::string& fileName, const Options *options) const
{
return readFile(IMAGE,fileName,options);
}
virtual ReadResult readHeightField(const std::string& fileName, const Options *options)
virtual ReadResult readHeightField(const std::string& fileName, const Options *options) const
{
return readFile(HEIGHTFIELD,fileName,options);
}
virtual ReadResult readNode(const std::string& fileName, const Options *options)
virtual ReadResult readNode(const std::string& fileName, const Options *options) const
{
return readFile(NODE,fileName,options);
}
ReadResult readFile(ObjectType objectType, ReaderWriter* rw, std::istream& fin, const Options *options)
ReadResult readFile(ObjectType objectType, ReaderWriter* rw, std::istream& fin, const Options *options) const
{
switch(objectType)
{
@ -132,7 +132,7 @@ class NetReader : public osgDB::ReaderWriter
return ReadResult::FILE_NOT_HANDLED;
}
virtual ReadResult readFile(ObjectType objectType, const std::string& inFileName, const Options *options)
virtual ReadResult readFile(ObjectType objectType, const std::string& inFileName, const Options *options) const
{
osg::Timer_t start = osg::Timer::instance()->tick();

View File

@ -51,27 +51,27 @@ public:
ReaderWriterOBJ() { }
virtual const char* className() const { return "Wavefront OBJ Reader"; }
virtual bool acceptsExtension(const std::string& extension) {
virtual bool acceptsExtension(const std::string& extension) const {
return osgDB::equalCaseInsensitive(extension,"obj");
}
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options);
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const;
virtual ReadResult readNode(std::istream& fin, const Options* options);
virtual ReadResult readNode(std::istream& fin, const Options* options) const;
protected:
typedef std::map< std::string, osg::ref_ptr<osg::StateSet> > MaterialToStateSetMap;
void buildMaterialToStateSetMap(obj::Model& model, MaterialToStateSetMap& materialToSetSetMap);
void buildMaterialToStateSetMap(obj::Model& model, MaterialToStateSetMap& materialToSetSetMap) const;
osg::Geometry* convertElementListToGeometry(obj::Model& model, obj::Model::ElementList& elementList);
osg::Geometry* convertElementListToGeometry(obj::Model& model, obj::Model::ElementList& elementList) const;
osg::Node* convertModelToSceneGraph(obj::Model& model);
osg::Node* convertModelToSceneGraph(obj::Model& model) const;
inline osg::Vec3 transformVertex(const osg::Vec3& vec) { return osg::Vec3(vec.x(),-vec.z(),vec.y()); }
inline osg::Vec3 transformNormal(const osg::Vec3& vec) { return osg::Vec3(vec.x(),-vec.z(),vec.y()); }
inline osg::Vec3 transformVertex(const osg::Vec3& vec) const { return osg::Vec3(vec.x(),-vec.z(),vec.y()); }
inline osg::Vec3 transformNormal(const osg::Vec3& vec) const { return osg::Vec3(vec.x(),-vec.z(),vec.y()); }
};
@ -79,7 +79,7 @@ protected:
// register with Registry to instantiate the above reader/writer.
osgDB::RegisterReaderWriterProxy<ReaderWriterOBJ> g_objReaderWriterProxy;
void ReaderWriterOBJ::buildMaterialToStateSetMap(obj::Model& model, MaterialToStateSetMap& materialToStateSetMap)
void ReaderWriterOBJ::buildMaterialToStateSetMap(obj::Model& model, MaterialToStateSetMap& materialToStateSetMap) const
{
for(obj::Model::MaterialMap::iterator itr = model.materialMap.begin();
itr != model.materialMap.end();
@ -136,7 +136,7 @@ void ReaderWriterOBJ::buildMaterialToStateSetMap(obj::Model& model, MaterialToSt
}
}
osg::Geometry* ReaderWriterOBJ::convertElementListToGeometry(obj::Model& model, obj::Model::ElementList& elementList)
osg::Geometry* ReaderWriterOBJ::convertElementListToGeometry(obj::Model& model, obj::Model::ElementList& elementList) const
{
unsigned int numVertexIndices = 0;
@ -389,7 +389,7 @@ osg::Geometry* ReaderWriterOBJ::convertElementListToGeometry(obj::Model& model,
return geometry;
}
osg::Node* ReaderWriterOBJ::convertModelToSceneGraph(obj::Model& model)
osg::Node* ReaderWriterOBJ::convertModelToSceneGraph(obj::Model& model) const
{
if (model.elementStateMap.empty()) return 0;
@ -446,7 +446,7 @@ osg::Node* ReaderWriterOBJ::convertModelToSceneGraph(obj::Model& model)
// read file and convert to OSG.
osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options)
osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
@ -475,7 +475,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& fil
return ReadResult::FILE_NOT_HANDLED;
}
osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(std::istream& fin, const Options* options)
osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(std::istream& fin, const Options* options) const
{
if (fin)
{

View File

@ -18,16 +18,16 @@ class OSGReaderWriter : public ReaderWriter
public:
virtual const char* className() const { return "OSG Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return equalCaseInsensitive(extension,"osg");
}
virtual ReadResult readObject(const std::string& fileName, const Options* opt) { return readNode(fileName, opt); }
virtual ReadResult readObject(const std::string& fileName, const Options* opt) const { return readNode(fileName, opt); }
virtual ReadResult readObject(std::istream& fin, const Options* opt) { return readNode(fin, opt); }
virtual ReadResult readObject(std::istream& fin, const Options* opt) const { return readNode(fin, opt); }
virtual ReadResult readNode(const std::string& file, const Options* opt)
virtual ReadResult readNode(const std::string& file, const Options* opt) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
@ -48,7 +48,7 @@ class OSGReaderWriter : public ReaderWriter
}
virtual ReadResult readNode(std::istream& fin, const Options* options)
virtual ReadResult readNode(std::istream& fin, const Options* options) const
{
Input fr;
@ -89,7 +89,7 @@ class OSGReaderWriter : public ReaderWriter
}
void setPrecision(Output& fout, const osgDB::ReaderWriter::Options* options)
void setPrecision(Output& fout, const osgDB::ReaderWriter::Options* options) const
{
if (options)
{
@ -105,7 +105,7 @@ class OSGReaderWriter : public ReaderWriter
}
}
virtual WriteResult writeObject(const Object& obj,const std::string& fileName, const osgDB::ReaderWriter::Options* options)
virtual WriteResult writeObject(const Object& obj,const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(fileName);
if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;
@ -122,7 +122,7 @@ class OSGReaderWriter : public ReaderWriter
return WriteResult("Unable to open file for output");
}
virtual WriteResult writeObject(const Object& obj,std::ostream& fout, const osgDB::ReaderWriter::Options* options)
virtual WriteResult writeObject(const Object& obj,std::ostream& fout, const osgDB::ReaderWriter::Options* options) const
{
Output foutput;
@ -140,7 +140,7 @@ class OSGReaderWriter : public ReaderWriter
}
virtual WriteResult writeNode(const Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options* options)
virtual WriteResult writeNode(const Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = getFileExtension(fileName);
if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;
@ -158,7 +158,7 @@ class OSGReaderWriter : public ReaderWriter
return WriteResult("Unable to open file for output");
}
virtual WriteResult writeNode(const Node& node,std::ostream& fout, const osgDB::ReaderWriter::Options* options)
virtual WriteResult writeNode(const Node& node,std::ostream& fout, const osgDB::ReaderWriter::Options* options) const
{
Output foutput;

View File

@ -580,24 +580,24 @@ ReaderWriter::ReadResult OSGA_Archive::read(const ReadFunctor& readFunctor)
return result;
}
ReaderWriter::ReadResult OSGA_Archive::readObject(const std::string& fileName,const Options* options)
ReaderWriter::ReadResult OSGA_Archive::readObject(const std::string& fileName,const Options* options) const
{
return read(ReadObjectFunctor(fileName, options));
return const_cast<OSGA_Archive*>(this)->read(ReadObjectFunctor(fileName, options));
}
ReaderWriter::ReadResult OSGA_Archive::readImage(const std::string& fileName,const Options* options)
ReaderWriter::ReadResult OSGA_Archive::readImage(const std::string& fileName,const Options* options) const
{
return read(ReadImageFunctor(fileName, options));
return const_cast<OSGA_Archive*>(this)->read(ReadImageFunctor(fileName, options));
}
ReaderWriter::ReadResult OSGA_Archive::readHeightField(const std::string& fileName,const Options* options)
ReaderWriter::ReadResult OSGA_Archive::readHeightField(const std::string& fileName,const Options* options) const
{
return read(ReadHeightFieldFunctor(fileName, options));
return const_cast<OSGA_Archive*>(this)->read(ReadHeightFieldFunctor(fileName, options));
}
ReaderWriter::ReadResult OSGA_Archive::readNode(const std::string& fileName,const Options* options)
ReaderWriter::ReadResult OSGA_Archive::readNode(const std::string& fileName,const Options* options) const
{
return read(ReadNodeFunctor(fileName, options));
return const_cast<OSGA_Archive*>(this)->read(ReadNodeFunctor(fileName, options));
}
@ -618,7 +618,7 @@ struct OSGA_Archive::WriteImageFunctor : public OSGA_Archive::WriteFunctor
_object(object) {}
const osg::Image& _object;
virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output)const { return rw.writeImage(_object, output, _options); }
virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output) const { return rw.writeImage(_object, output, _options); }
};
struct OSGA_Archive::WriteHeightFieldFunctor : public OSGA_Archive::WriteFunctor
@ -676,27 +676,27 @@ ReaderWriter::WriteResult OSGA_Archive::write(const WriteFunctor& writeFunctor)
}
ReaderWriter::WriteResult OSGA_Archive::writeObject(const osg::Object& obj,const std::string& fileName,const Options* options)
ReaderWriter::WriteResult OSGA_Archive::writeObject(const osg::Object& obj,const std::string& fileName,const Options* options) const
{
osg::notify(osg::INFO)<<"OSGA_Archive::writeObject(obj, "<<fileName<<")"<<std::endl;
return write(WriteObjectFunctor(obj, fileName, options));
return const_cast<OSGA_Archive*>(this)->write(WriteObjectFunctor(obj, fileName, options));
}
ReaderWriter::WriteResult OSGA_Archive::writeImage(const osg::Image& image,const std::string& fileName,const Options* options)
ReaderWriter::WriteResult OSGA_Archive::writeImage(const osg::Image& image,const std::string& fileName,const Options* options) const
{
osg::notify(osg::INFO)<<"OSGA_Archive::writeImage(obj, "<<fileName<<")"<<std::endl;
return write(WriteImageFunctor(image, fileName, options));
return const_cast<OSGA_Archive*>(this)->write(WriteImageFunctor(image, fileName, options));
}
ReaderWriter::WriteResult OSGA_Archive::writeHeightField(const osg::HeightField& heightField,const std::string& fileName,const Options* options)
ReaderWriter::WriteResult OSGA_Archive::writeHeightField(const osg::HeightField& heightField,const std::string& fileName,const Options* options) const
{
osg::notify(osg::INFO)<<"OSGA_Archive::writeHeightField(obj, "<<fileName<<")"<<std::endl;
return write(WriteHeightFieldFunctor(heightField, fileName, options));
return const_cast<OSGA_Archive*>(this)->write(WriteHeightFieldFunctor(heightField, fileName, options));
}
ReaderWriter::WriteResult OSGA_Archive::writeNode(const osg::Node& node,const std::string& fileName,const Options* options)
ReaderWriter::WriteResult OSGA_Archive::writeNode(const osg::Node& node,const std::string& fileName,const Options* options) const
{
osg::notify(osg::INFO)<<"OSGA_Archive::writeNode(obj, "<<fileName<<")"<<std::endl;
return write(WriteNodeFunctor(node, fileName, options));
return const_cast<OSGA_Archive*>(this)->write(WriteNodeFunctor(node, fileName, options));
}

View File

@ -30,7 +30,7 @@ class OSGA_Archive : public osgDB::Archive
virtual const char* className() const { return "Archive"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"osga");
}
@ -57,28 +57,28 @@ class OSGA_Archive : public osgDB::Archive
/** Read an osg::Object of specified file name from the Archive.*/
virtual ReadResult readObject(const std::string& fileName,const Options* options=NULL);
virtual ReadResult readObject(const std::string& fileName,const Options* options=NULL) const;
/** Read an osg::Image of specified file name from the Archive.*/
virtual ReadResult readImage(const std::string& fileName,const Options* options=NULL);
virtual ReadResult readImage(const std::string& fileName,const Options* options=NULL) const;
/** Read an osg::HeightField of specified file name from the Archive.*/
virtual ReadResult readHeightField(const std::string& fileName,const Options* options=NULL);
virtual ReadResult readHeightField(const std::string& fileName,const Options* options=NULL) const;
/** Read an osg::Node of specified file name from the Archive.*/
virtual ReadResult readNode(const std::string& fileName,const Options* options=NULL);
virtual ReadResult readNode(const std::string& fileName,const Options* options=NULL) const;
/** Write an osg::Object with specified file name to the Archive.*/
virtual WriteResult writeObject(const osg::Object& obj,const std::string& fileName,const Options* options=NULL);
virtual WriteResult writeObject(const osg::Object& obj,const std::string& fileName,const Options* options=NULL) const;
/** Write an osg::Image with specified file name to the Archive.*/
virtual WriteResult writeImage(const osg::Image& image,const std::string& fileName,const Options* options=NULL);
virtual WriteResult writeImage(const osg::Image& image,const std::string& fileName,const Options* options=NULL) const;
/** Write an osg::HeightField with specified file name to the Archive.*/
virtual WriteResult writeHeightField(const osg::HeightField& heightField,const std::string& fileName,const Options* options=NULL);
virtual WriteResult writeHeightField(const osg::HeightField& heightField,const std::string& fileName,const Options* options=NULL) const;
/** Write an osg::Node with specified file name to the Archive.*/
virtual WriteResult writeNode(const osg::Node& node,const std::string& fileName,const Options* options=NULL);
virtual WriteResult writeNode(const osg::Node& node,const std::string& fileName,const Options* options=NULL) const;
protected:

View File

@ -12,12 +12,12 @@ public:
ReaderWriterOSGA() { }
virtual const char* className() const { return "OpenSceneGraph Archive Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"osga");
}
virtual ReadResult openArchive(const std::string& file,ArchiveStatus status, unsigned int indexBlockSize = 4096, const Options* options=NULL)
virtual ReadResult openArchive(const std::string& file,ArchiveStatus status, unsigned int indexBlockSize = 4096, const Options* options=NULL) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
@ -40,7 +40,7 @@ public:
}
/** open an archive for reading.*/
virtual ReadResult openArchive(std::istream& fin,const Options*)
virtual ReadResult openArchive(std::istream& fin,const Options*) const
{
osg::ref_ptr<OSGA_Archive> archive = new OSGA_Archive;
if (!archive->open(fin))
@ -51,7 +51,7 @@ public:
return archive.get();
}
virtual ReadResult readImage(const std::string& file,const Options*)
virtual ReadResult readImage(const std::string& file,const Options*) const
{
ReadResult result = openArchive(file,osgDB::Archive::READ);
@ -71,7 +71,7 @@ public:
return result_2;
}
virtual ReadResult readNode(const std::string& file,const Options*)
virtual ReadResult readNode(const std::string& file,const Options*) const
{
ReadResult result = openArchive(file,osgDB::Archive::READ);

View File

@ -25,12 +25,12 @@ class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter
{
public:
virtual const char* className() const { return "OSGTGZ Database Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"osgtgz");
}
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

View File

@ -30,7 +30,7 @@ class ReaderWriterPFB : public osgDB::ReaderWriter
void initPerformer();
virtual const char* className() const { return "Performer Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return
osgDB::equalCaseInsensitive(extension,"3ds") ? true :
@ -95,7 +95,7 @@ class ReaderWriterPFB : public osgDB::ReaderWriter
false;
}
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string fileName = osgDB::findDataFile( file, options );
if (fileName.empty()) fileName = file; // let Peformer see if it can file the filep
@ -150,7 +150,7 @@ class ReaderWriterPFB : public osgDB::ReaderWriter
return ReadResult::FILE_NOT_HANDLED;
}
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

View File

@ -192,9 +192,9 @@ class ReaderWriterPIC : public osgDB::ReaderWriter
{
public:
virtual const char* className() const { return "PIC Image Reader"; }
virtual bool acceptsExtension(const std::string& extension) { return osgDB::equalCaseInsensitive(extension,"pic"); }
virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"pic"); }
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

View File

@ -34,9 +34,9 @@ class ReaderWriterPNG : public osgDB::ReaderWriter
{
public:
virtual const char* className() const { return "PNG Image Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension) { return osgDB::equalCaseInsensitive(extension,"png"); }
virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"png"); }
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

View File

@ -1,330 +0,0 @@
#include <osg/Image>
#include <osg/Notify>
#include <osg/Geode>
#include <osg/GL>
#include <osgDB/Registry>
#include <osgDB/FileNameUtils>
/****************************************************************************
*
* Follows is code extracted from the simage library. Original Authors:
*
* Systems in Motion,
* <URL:http://www.sim.no>
*
* Peder Blekken <pederb@sim.no>
* Morten Eriksen <mortene@sim.no>
* Marius Bugge Monsen <mariusbu@sim.no>
*
* The original COPYING notice
*
* All files in this library are public domain, except simage_rgb.cpp which is
* Copyright (c) Mark J Kilgard <mjk@nvidia.com>. I will contact Mark
* very soon to hear if this source also can become public domain.
*
* Please send patches for bugs and new features to: <pederb@sim.no>.
*
* Peder Blekken
*
*
* Ported into the OSG as a plugin, Robert Osfield Decemeber 2000.
* Note, reference above to license of simage_rgb is not relevent to the OSG
* as the OSG does not use it. Also for patches, bugs and new features
* please send them direct to the OSG dev team rather than address above.
*
**********************************************************************/
/*
* Based on example code found in the libjpeg archive
*
*/
using namespace osg;
extern "C"
{
#include <png.h>
}
#define ERR_NO_ERROR 0
#define ERR_OPEN 1
#define ERR_MEM 2
#define ERR_PNGLIB 3
static int pngerror = ERR_NO_ERROR;
/* my setjmp buffer */
static jmp_buf setjmp_buffer;
/* called my libpng */
static void
warn_callback(png_structp /*ps*/, png_const_charp pc)
{
/*FIXME: notify? */
osg::notify(osg::WARN)<<"Warning in .png reader: ";
if (pc) osg::notify(osg::WARN)<< pc;
osg::notify(osg::WARN)<<std::endl;
}
static void
err_callback(png_structp /*ps*/, png_const_charp pc)
{
/* FIXME: store error message? */
longjmp(setjmp_buffer, 1);
osg::notify(osg::WARN)<<"Error in .png reader: ";
if (pc) osg::notify(osg::WARN)<< pc;
osg::notify(osg::WARN)<<std::endl;
}
int
simage_png_error(char * buffer, int buflen)
{
switch (pngerror) {
case ERR_OPEN:
strncpy(buffer, "PNG loader: Error opening file", buflen);
break;
case ERR_MEM:
strncpy(buffer, "PNG loader: Out of memory error", buflen);
break;
case ERR_PNGLIB:
strncpy(buffer, "PNG loader: Illegal png file", buflen);
break;
}
return pngerror;
}
int
simage_png_identify(const char * /*ptr*/,
const unsigned char *header,
int headerlen)
{
static unsigned char pngcmp[] = {0x89, 'P', 'N', 'G', 0xd, 0xa, 0x1a, 0xa};
if (headerlen < 8) return 0;
if (memcmp((const void*)header,
(const void*)pngcmp, 8) == 0) return 1;
return 0;
}
unsigned char *
simage_png_load(const char *filename,
int *width_ret,
int *height_ret,
int *numComponents_ret)
{
png_structp png_ptr;
png_infop info_ptr;
png_uint_32 width, height;
int bit_depth, color_type, interlace_type;
FILE *fp;
unsigned char *buffer;
int bytes_per_row;
int number_passes;
int channels;
int format;
if ((fp = fopen(filename, "rb")) == NULL) {
pngerror = ERR_OPEN;
return NULL;
}
/* Create and initialize the png_struct with the desired error handler
* functions. If you want to use the default stderr and longjump method,
* you can supply NULL for the last three parameters. We also supply the
* the compiler header file version, so that we know if the application
* was compiled with a compatible version of the library. REQUIRED
*/
/*png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
(void *)user_error_ptr, user_error_fn, user_warning_fn);*/
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
NULL, err_callback, warn_callback);
if (png_ptr == NULL) {
pngerror = ERR_MEM;
fclose(fp);
return 0;
}
/* Allocate/initialize the memory for image information. REQUIRED. */
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
pngerror = ERR_MEM;
fclose(fp);
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
return 0;
}
/* Set error handling if you are using the setjmp/longjmp method (this is
* the normal method of doing things with libpng). REQUIRED unless you
* set up your own error handlers in the png_create_read_struct() earlier.
*/
buffer = NULL;
if (setjmp(setjmp_buffer)) {
pngerror = ERR_PNGLIB;
/* Free all of the memory associated with the png_ptr and info_ptr */
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
fclose(fp);
/* If we get here, we had a problem reading the file */
if (buffer) free(buffer);
return NULL;
}
/* Set up the input control if you are using standard C streams */
png_init_io(png_ptr, fp);
/* The call to png_read_info() gives us all of the information from the
* PNG file before the first IDAT (image data chunk). REQUIRED
*/
png_read_info(png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
&interlace_type, NULL, NULL);
/**** Set up the data transformations you want. Note that these are all
**** optional. Only call them if you want/need them. Many of the
**** transformations only work on specific types of images, and many
**** are mutually exclusive.
****/
/* tell libpng to strip 16 bit/color files down to 8 bits/color */
png_set_strip_16(png_ptr);
/* strip alpha bytes from the input data without combining with th
* background (not recommended) */
/* png_set_strip_alpha(png_ptr); */
/* extract multiple pixels with bit depths of 1, 2, and 4 from a single
* byte into separate bytes (useful for paletted and grayscale images).
*/
/* png_set_packing(png_ptr); */
/* change the order of packed pixels to least significant bit first
* (not useful if you are using png_set_packing). */
/* png_set_packswap(png_ptr); */
/* expand paletted colors into true RGB triplets */
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_expand(png_ptr);
/* expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
png_set_expand(png_ptr);
/* expand paletted or RGB images with transparency to full alpha channels
* so the data will be available as RGBA quartets */
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
png_set_expand(png_ptr);
/* Add filler (or alpha) byte (before/after each RGB triplet) */
/* png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); */
/* Turn on interlace handling. REQUIRED if you are not using
* png_read_image(). To see how to handle interlacing passes,
* see the png_read_row() method below.
*/
png_read_update_info(png_ptr, info_ptr);
number_passes = png_set_interlace_handling(png_ptr);
channels = png_get_channels(png_ptr, info_ptr);
/* allocate the memory to hold the image using the fields of info_ptr. */
bytes_per_row = png_get_rowbytes(png_ptr, info_ptr);
buffer = (unsigned char*) malloc(bytes_per_row*height);
format = channels; /* this is safer than the above */
if (buffer) {
int pass, y;
unsigned char *dummytab[1];
for (pass = 0; pass < number_passes; pass++) {
for ( y = 0; (unsigned int) y < height; y++ ) {
/* flips image upside down */
dummytab[0] = &buffer[bytes_per_row*(height-1-y)];
png_read_rows(png_ptr, dummytab, NULL, 1);
}
}
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
png_read_end(png_ptr, info_ptr);
}
/* clean up after the read, and free any memory allocated - REQUIRED */
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
/* close the file */
fclose(fp);
/* that's it */
if (buffer) {
*width_ret = width;
*height_ret = height;
*numComponents_ret = format;
pngerror = ERR_NO_ERROR;
}
else {
pngerror = ERR_MEM;
}
return buffer;
}
class ReaderWriterPNG : public osgDB::ReaderWriter
{
public:
virtual const char* className() { return "PNG Image Reader"; }
virtual bool acceptsExtension(const std::string& extension)
{
return osgDB::equalCaseInsensitive(extension,"png");
}
virtual ReadResult readImage(const std::string& fileName,const osgDB::ReaderWriter::Options*)
{
unsigned char *imageData = NULL;
int width_ret;
int height_ret;
int numComponents_ret;
imageData = simage_png_load(fileName.c_str(),&width_ret,&height_ret,&numComponents_ret);
if (imageData==NULL) return ReadResult::FILE_NOT_HANDLED;
int s = width_ret;
int t = height_ret;
int r = 1;
int internalFormat = numComponents_ret;
unsigned int pixelFormat =
numComponents_ret == 1 ? GL_LUMINANCE :
numComponents_ret == 2 ? GL_LUMINANCE_ALPHA :
numComponents_ret == 3 ? GL_RGB :
numComponents_ret == 4 ? GL_RGBA : (GLenum)-1;
unsigned int dataType = GL_UNSIGNED_BYTE;
osg::Image* pOsgImage = new osg::Image;
pOsgImage->setFileName(fileName.c_str());
pOsgImage->setImage(s,t,r,
internalFormat,
pixelFormat,
dataType,
imageData);
return pOsgImage;
}
};
// now register with Registry to instantiate the above
// reader/writer.
osgDB::RegisterReaderWriterProxy<ReaderWriterPNG> g_readerWriter_PNG_Proxy;

View File

@ -1,170 +0,0 @@
#include <osg/Image>
#include "osg/Notify"
#include <osg/Geode>
#include "osg/GL"
#include "osgDB/Registry"
using namespace osg;
extern "C"
{
#include <png.h>
}
/* Transparency parameters */
#define PNG_ALPHA -2 /* Use alpha channel in PNG file, if there is one */
#define PNG_SOLID -1 /* No transparency */
#define PNG_STENCIL 0 /* Sets alpha to 0 for r=g=b=0, 1 otherwise */
typedef struct
{
unsigned int Width;
unsigned int Height;
unsigned int Depth;
unsigned int Alpha;
} pngInfo;
class ReaderWriterPNG : public osgDB::ReaderWriter
{
public:
virtual const char* className() { return "PNG Image Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension) { return extension=="png"; }
virtual ReadResult readImage(const std::string& fileName,const osgDB::ReaderWriter::Options*)
{
int trans = PNG_ALPHA;
FILE *fp = NULL;
pngInfo pInfo;
pngInfo *pinfo = &pInfo;
unsigned char header[8];
png_structp png;
png_infop info;
png_infop endinfo;
png_bytep data; //, data2;
png_bytep *row_p;
double fileGamma;
png_uint_32 width, height;
int depth, color;
png_uint_32 i;
png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
info = png_create_info_struct(png);
endinfo = png_create_info_struct(png);
fp = fopen(fileName.c_str(), "rb");
if (fp && fread(header, 1, 8, fp) && png_check_sig(header, 8))
png_init_io(png, fp);
else
{
png_destroy_read_struct(&png, &info, &endinfo);
return ReadResult::FILE_NOT_HANDLED;
}
png_set_sig_bytes(png, 8);
png_read_info(png, info);
png_get_IHDR(png, info, &width, &height, &depth, &color, NULL, NULL, NULL);
if (pinfo != NULL)
{
pinfo->Width = width;
pinfo->Height = height;
pinfo->Depth = depth;
}
if (color == PNG_COLOR_TYPE_GRAY || color == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png);
if (color&PNG_COLOR_MASK_ALPHA && trans != PNG_ALPHA)
{
png_set_strip_alpha(png);
color &= ~PNG_COLOR_MASK_ALPHA;
}
// if (!(PalettedTextures && mipmap >= 0 && trans == PNG_SOLID))
if (color == PNG_COLOR_TYPE_PALETTE)
png_set_expand(png);
/*--GAMMA--*/
// checkForGammaEnv();
double screenGamma = 2.2 / 1.0;
if (png_get_gAMA(png, info, &fileGamma))
png_set_gamma(png, screenGamma, fileGamma);
else
png_set_gamma(png, screenGamma, 1.0/2.2);
png_read_update_info(png, info);
data = (png_bytep) malloc(png_get_rowbytes(png, info)*height);
row_p = (png_bytep *) malloc(sizeof(png_bytep)*height);
bool StandardOrientation = false;
for (i = 0; i < height; i++)
{
if (StandardOrientation)
row_p[height - 1 - i] = &data[png_get_rowbytes(png, info)*i];
else
row_p[i] = &data[png_get_rowbytes(png, info)*i];
}
png_read_image(png, row_p);
free(row_p);
int iBitCount;
if (trans == PNG_SOLID || trans == PNG_ALPHA || color == PNG_COLOR_TYPE_RGB_ALPHA || color == PNG_COLOR_TYPE_GRAY_ALPHA)
{
switch (color)
{
case PNG_COLOR_TYPE_GRAY:
case PNG_COLOR_TYPE_RGB:
case PNG_COLOR_TYPE_PALETTE:
iBitCount = 24;
if (pinfo != NULL) pinfo->Alpha = 0;
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
case PNG_COLOR_TYPE_RGB_ALPHA:
iBitCount = 32;
if (pinfo != NULL) pinfo->Alpha = 8;
break;
default:
return ReadResult::FILE_NOT_HANDLED;
}
}
png_read_end(png, endinfo);
png_destroy_read_struct(&png, &info, &endinfo);
// free(data);
if (fp)
fclose(fp);
osg::Image* pOsgImage = new osg::Image();
pOsgImage->setFileName(fileName.c_str());
if (iBitCount == 24)
pOsgImage->setImage(width, height, 1,
iBitCount / 8,// int internalFormat,
GL_RGB, // unsigned int pixelFormat
GL_UNSIGNED_BYTE,// unsigned int dataType
data);
else
pOsgImage->setImage(width, height, 1,
iBitCount / 8,// int internalFormat,
GL_RGBA, // unsigned int pixelFormat
GL_UNSIGNED_BYTE,// unsigned int dataType
data);
return pOsgImage;
}
};
// now register with Registry to instantiate the above
// reader/writer.
osgDB::RegisterReaderWriterProxy<ReaderWriterPNG> g_readerWriter_PNG_Proxy;

View File

@ -17,15 +17,15 @@ class ReaderWriterPNM : public osgDB::ReaderWriter
{
public:
virtual const char* className() const { return "PNM Image Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension)
{
return osgDB::equalCaseInsensitive(extension, "pnm") ||
osgDB::equalCaseInsensitive(extension, "ppm") ||
osgDB::equalCaseInsensitive(extension, "pgm") ||
osgDB::equalCaseInsensitive(extension, "pbm");
}
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension, "pnm") ||
osgDB::equalCaseInsensitive(extension, "ppm") ||
osgDB::equalCaseInsensitive(extension, "pgm") ||
osgDB::equalCaseInsensitive(extension, "pbm");
}
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
@ -34,227 +34,227 @@ class ReaderWriterPNM : public osgDB::ReaderWriter
if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;
FILE *fp = NULL;
char line[300];
int ppmtype = 0; /* P1, P2, etc. */
int width = 0;
int height = 0;
int max_value = 0;
char line[300];
int ppmtype = 0; /* P1, P2, etc. */
int width = 0;
int height = 0;
int max_value = 0;
bool binary_flag = false;
int shift_value = 0; // if greater than 8 bits
bool binary_flag = false;
int shift_value = 0; // if greater than 8 bits
// Open file.
// Open file.
fp = fopen(fileName.c_str(), "rb");
// Read header items.
int row;
for (row = 1; row <= 3; row++)
{
fgets(line, 300, fp);
// Read header items.
int row;
for (row = 1; row <= 3; row++)
{
fgets(line, 300, fp);
char *cp = line;
while (*cp && isspace(*cp))
cp++;
if (! *cp || *cp == '#')
{
// Skip comment lines.
row--;
}
else if (row == 1)
{
// Get the image type.
if (line[0] == 'p' || line[0] == 'P')
{
ppmtype = line[1] - '0';
}
}
else if (row == 2)
{
// Get the image size.
width = atoi(line);
char *cp = line + strspn(line, "\t \n\r");
cp += strspn(cp, "0123456789");
cp += strspn(line, "\t \n\r");
height = atoi(cp);
char *cp = line;
while (*cp && isspace(*cp))
cp++;
if (! *cp || *cp == '#')
{
// Skip comment lines.
row--;
}
else if (row == 1)
{
// Get the image type.
if (line[0] == 'p' || line[0] == 'P')
{
ppmtype = line[1] - '0';
}
}
else if (row == 2)
{
// Get the image size.
width = atoi(line);
char *cp = line + strspn(line, "\t \n\r");
cp += strspn(cp, "0123456789");
cp += strspn(line, "\t \n\r");
height = atoi(cp);
// pbm files don't have row 3
if (ppmtype == 1 || ppmtype == 4)
{
max_value = 1;
break;
}
}
else if (row == 3)
{
// Get the maximum value
max_value = atoi(line);
}
}
// pbm files don't have row 3
if (ppmtype == 1 || ppmtype == 4)
{
max_value = 1;
break;
}
}
else if (row == 3)
{
// Get the maximum value
max_value = atoi(line);
}
}
// Check for valid values.
if (width <= 0 || height <= 0 || max_value <= 0 || ppmtype < 1 ||
ppmtype > 6)
{
fclose(fp);
// Check for valid values.
if (width <= 0 || height <= 0 || max_value <= 0 || ppmtype < 1 ||
ppmtype > 6)
{
fclose(fp);
return ReadResult::FILE_NOT_HANDLED;
}
}
// Check for binary file.
if (ppmtype >= 4 && ppmtype <= 6)
binary_flag = true;
// Check for binary file.
if (ppmtype >= 4 && ppmtype <= 6)
binary_flag = true;
// Warn the user if the full image cannot be used.
if (max_value > 255)
{
osg::notify(osg::NOTICE) << "PNM file " << fileName <<
" has channels larger than "
" 8 bits. Color resolution will be lost." << std::endl;
// Warn the user if the full image cannot be used.
if (max_value > 255)
{
osg::notify(osg::NOTICE) << "PNM file " << fileName <<
" has channels larger than "
" 8 bits. Color resolution will be lost." << std::endl;
while (max_value > 255)
{
max_value >>= 1;
shift_value++;
}
}
while (max_value > 255)
{
max_value >>= 1;
shift_value++;
}
}
// We always create a RGB image, no matter what type of
// source it was.
// We always create a RGB image, no matter what type of
// source it was.
unsigned char *data = new unsigned char [width * height * 3];
// For the ascii files
if (!binary_flag)
{
unsigned char *end = data + width * height * 3;
unsigned char *dst = data;
// For the ascii files
if (!binary_flag)
{
unsigned char *end = data + width * height * 3;
unsigned char *dst = data;
char s_num[300];
int s_num_count;
int value = fgetc(fp);
char s_num[300];
int s_num_count;
int value = fgetc(fp);
while (dst < end)
{
if (feof(fp) || ferror(fp))
{
fclose(fp);
delete[] data;
return ReadResult::FILE_NOT_HANDLED;
}
while (dst < end)
{
if (feof(fp) || ferror(fp))
{
fclose(fp);
delete[] data;
return ReadResult::FILE_NOT_HANDLED;
}
// Read any extra whitespace
//while (isspace(value))
while (!isdigit(value))
{
value = fgetc(fp);
}
// Read any extra whitespace
//while (isspace(value))
while (!isdigit(value))
{
value = fgetc(fp);
}
// Read any numeric digits
s_num_count = 0;
while (isdigit(value))
{
s_num[s_num_count++] = value;
value = fgetc(fp);
}
// Don't forget to terminate the string!
s_num[s_num_count] = 0;
// Read any numeric digits
s_num_count = 0;
while (isdigit(value))
{
s_num[s_num_count++] = value;
value = fgetc(fp);
}
// Don't forget to terminate the string!
s_num[s_num_count] = 0;
if (s_num_count == 0)
{
fclose(fp);
delete[] data;
return ReadResult::FILE_NOT_HANDLED;
}
if (s_num_count == 0)
{
fclose(fp);
delete[] data;
return ReadResult::FILE_NOT_HANDLED;
}
unsigned int data_value = atoi(s_num) >> shift_value;
unsigned int data_value = atoi(s_num) >> shift_value;
// Now we have our value. Put it into the array
// in the appropriate place.
if (ppmtype == 1)
{
if (data_value == 1)
data_value = 0;
else
data_value = 255;
// Now we have our value. Put it into the array
// in the appropriate place.
if (ppmtype == 1)
{
if (data_value == 1)
data_value = 0;
else
data_value = 255;
*(dst++) = data_value;
*(dst++) = data_value;
*(dst++) = data_value;
}
else if (ppmtype == 2)
{
*(dst++) = data_value;
*(dst++) = data_value;
*(dst++) = data_value;
}
else if (ppmtype == 3)
{
*(dst++) = data_value;
}
}
}
*(dst++) = data_value;
*(dst++) = data_value;
*(dst++) = data_value;
}
else if (ppmtype == 2)
{
*(dst++) = data_value;
*(dst++) = data_value;
*(dst++) = data_value;
}
else if (ppmtype == 3)
{
*(dst++) = data_value;
}
}
}
// If we have a binary bitmap
else if (ppmtype == 4)
{
unsigned char *end = data + width * height * 3;
unsigned char *dst = data;
// If we have a binary bitmap
else if (ppmtype == 4)
{
unsigned char *end = data + width * height * 3;
unsigned char *dst = data;
while (dst < end)
{
unsigned char b = (unsigned char) fgetc(fp);
if (feof(fp) || ferror(fp))
{
fclose(fp);
delete[] data;
return ReadResult::FILE_NOT_HANDLED;
}
while (dst < end)
{
unsigned char b = (unsigned char) fgetc(fp);
if (feof(fp) || ferror(fp))
{
fclose(fp);
delete[] data;
return ReadResult::FILE_NOT_HANDLED;
}
int i;
for (i = 7; i >= 0 && dst < end; i--)
{
// 1 means black, 0 means white
int data_value = (b & (1<<i)) ? 0 : 255;
*(dst++) = data_value;
*(dst++) = data_value;
*(dst++) = data_value;
}
}
}
int i;
for (i = 7; i >= 0 && dst < end; i--)
{
// 1 means black, 0 means white
int data_value = (b & (1<<i)) ? 0 : 255;
*(dst++) = data_value;
*(dst++) = data_value;
*(dst++) = data_value;
}
}
}
// If we have a binary pgm
else if (ppmtype == 5)
{
int result = fread(data, width * height, 1, fp);
if (result != 1)
{
fclose(fp);
delete[] data;
return ReadResult::FILE_NOT_HANDLED;
}
// If we have a binary pgm
else if (ppmtype == 5)
{
int result = fread(data, width * height, 1, fp);
if (result != 1)
{
fclose(fp);
delete[] data;
return ReadResult::FILE_NOT_HANDLED;
}
unsigned char *src = data + width * height;
unsigned char *dst = data + width * height * 3;
while (src >= data)
{
*(--dst) = *(--src);
*(--dst) = *src;
*(--dst) = *src;
}
}
unsigned char *src = data + width * height;
unsigned char *dst = data + width * height * 3;
while (src >= data)
{
*(--dst) = *(--src);
*(--dst) = *src;
*(--dst) = *src;
}
}
// If we have a binary ppm, reading is very easy.
else if (ppmtype == 6)
{
int result = fread(data, width * height * 3, 1, fp);
if (result != 1)
{
fclose(fp);
delete[] data;
return ReadResult::FILE_NOT_HANDLED;
}
}
// If we have a binary ppm, reading is very easy.
else if (ppmtype == 6)
{
int result = fread(data, width * height * 3, 1, fp);
if (result != 1)
{
fclose(fp);
delete[] data;
return ReadResult::FILE_NOT_HANDLED;
}
}
if (fp)
fclose(fp);
@ -268,7 +268,7 @@ class ReaderWriterPNM : public osgDB::ReaderWriter
GL_UNSIGNED_BYTE,// unsigned int dataType
data,
osg::Image::USE_NEW_DELETE);
pOsgImage->flipVertical();
pOsgImage->flipVertical();
return pOsgImage;
}

View File

@ -27,7 +27,7 @@ class ReaderWriterQT : public osgDB::ReaderWriter
public:
virtual const char* className() const { return "Default Quicktime Image Reader/Writer"; }
virtual bool acceptsMovieExtension(const std::string& extension)
virtual bool acceptsMovieExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"mov") ||
osgDB::equalCaseInsensitive(extension,"mpg") ||
@ -35,7 +35,7 @@ class ReaderWriterQT : public osgDB::ReaderWriter
osgDB::equalCaseInsensitive(extension,"dv");
}
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
// this should be the only image importer required on the Mac
// dont know what else it supports, but these will do
@ -54,7 +54,7 @@ class ReaderWriterQT : public osgDB::ReaderWriter
acceptsMovieExtension(extension);
}
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options*)
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options*) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

View File

@ -345,7 +345,7 @@ class ReaderWriterRGB : public osgDB::ReaderWriter
public:
virtual const char* className() const { return "RGB Image Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"rgb") ||
osgDB::equalCaseInsensitive(extension,"sgi") ||
@ -355,7 +355,7 @@ class ReaderWriterRGB : public osgDB::ReaderWriter
osgDB::equalCaseInsensitive(extension,"bw");
}
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
@ -406,7 +406,7 @@ class ReaderWriterRGB : public osgDB::ReaderWriter
}
virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options*)
virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options*) const
{
std::string ext = osgDB::getFileExtension(fileName);
if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;

View File

@ -54,13 +54,12 @@ public:
virtual const char* className() const { return "rotation pseudo-loader"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive( extension, EXTENSION_NAME );
}
virtual ReadResult readNode(const std::string& fileName,
const osgDB::ReaderWriter::Options* /*options*/)
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(fileName);
if( !acceptsExtension(ext) )
@ -98,7 +97,7 @@ public:
}
// recursively load the subfile.
osg::Node *node = osgDB::readNodeFile( subFileName );
osg::Node *node = osgDB::readNodeFile( subFileName, options );
if( !node )
{
// propagate the read failure upwards

View File

@ -56,13 +56,12 @@ public:
virtual const char* className() const { return "scaling pseudo-loader"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive( extension, EXTENSION_NAME );
}
virtual ReadResult readNode(const std::string& fileName,
const osgDB::ReaderWriter::Options* /*options*/)
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(fileName);
if( !acceptsExtension(ext) )
@ -106,7 +105,7 @@ public:
}
// recursively load the subfile.
osg::Node *node = osgDB::readNodeFile( subFileName );
osg::Node *node = osgDB::readNodeFile( subFileName, options );
if( !node )
{
// propagate the read failure upwards

View File

@ -43,33 +43,38 @@
class ReaderWriterSTL : public osgDB::ReaderWriter
{
public:
ReaderWriterSTL() : _generateNormal(true),
_numFacets(0) {
}
ReaderWriterSTL() {}
virtual const char* className() const {
return "STL Reader/Writer";
}
virtual bool acceptsExtension(const std::string& extension) {
virtual bool acceptsExtension(const std::string& extension) const {
return
osgDB::equalCaseInsensitive(extension,"stl") ? true :
osgDB::equalCaseInsensitive(extension,"sta") ? true : false;
}
virtual ReadResult readNode(const std::string& fileName,
const osgDB::ReaderWriter::Options*);
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) const;
private:
bool _generateNormal;
unsigned int _numFacets;
osg::ref_ptr<osg::Vec3Array> _vertex;
osg::ref_ptr<osg::Vec3Array> _normal;
osg::ref_ptr<osg::Vec4Array> _color;
struct ReaderObject
{
ReaderObject():
_generateNormal(true),
_numFacets(0) {}
bool readStlAscii(FILE* fp);
bool readStlBinary(FILE* fp);
bool _generateNormal;
unsigned int _numFacets;
osg::ref_ptr<osg::Vec3Array> _vertex;
osg::ref_ptr<osg::Vec3Array> _normal;
osg::ref_ptr<osg::Vec4Array> _color;
bool readStlAscii(FILE* fp);
bool readStlBinary(FILE* fp);
};
};
@ -102,8 +107,7 @@ const float StlColorDepth = float(StlColorSize); // 2^5 - 1
// Read node
osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& file,
const osgDB::ReaderWriter::Options* options)
osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
@ -119,6 +123,8 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& fil
return ReadResult::FILE_NOT_HANDLED;
}
ReaderObject readerObject;
// assumes "unsigned int" is 4 bytes...
StlHeader header;
if (fread((void*) &header, sizeof(header), 1, fp) != 1) {
@ -142,7 +148,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& fil
}
if (stb.st_size == expectLen) {
// assume binary
_numFacets = expectFacets;
readerObject._numFacets = expectFacets;
isBinary = true;
}
else if (strstr(header.text, "solid") != 0) {
@ -157,30 +163,30 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& fil
// read
rewind(fp);
bool ok = (isBinary ? readStlBinary(fp) : readStlAscii(fp));
bool ok = (isBinary ? readerObject.readStlBinary(fp) : readerObject.readStlAscii(fp));
fclose(fp);
if (!ok) {
return ReadResult::FILE_NOT_HANDLED;
}
osg::notify(osg::NOTICE) << "### found " << _numFacets << " facets" << std::endl;
osg::notify(osg::NOTICE) << "### found " << readerObject._numFacets << " facets" << std::endl;
/*
* setup geometry
*/
osg::Geometry* geom = new osg::Geometry;
geom->setVertexArray(_vertex.get());
geom->setVertexArray(readerObject._vertex.get());
geom->setNormalArray(_normal.get());
geom->setNormalArray(readerObject._normal.get());
geom->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);
if (_color.valid()) {
if (readerObject._color.valid()) {
osg::notify(osg::NOTICE) << "### with color" << std::endl;
geom->setColorArray(_color.get());
geom->setColorArray(readerObject._color.get());
geom->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE);
}
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, _numFacets*3));
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, readerObject._numFacets*3));
osg::Geode* geode = new osg::Geode;
geode->addDrawable(geom);
@ -195,7 +201,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& fil
*
**********************************************************************/
bool ReaderWriterSTL::readStlAscii(FILE* fp)
bool ReaderWriterSTL::ReaderObject::readStlAscii(FILE* fp)
{
unsigned int vertexCount = 0;
unsigned int facetIndex[] = { 0,0,0 };
@ -272,7 +278,7 @@ bool ReaderWriterSTL::readStlAscii(FILE* fp)
return true;
}
bool ReaderWriterSTL::readStlBinary(FILE* fp)
bool ReaderWriterSTL::ReaderObject::readStlBinary(FILE* fp)
{
// seek to beginning of facets
::fseek(fp, sizeof_StlHeader, SEEK_SET);

View File

@ -476,9 +476,9 @@ class ReaderWriterTGA : public osgDB::ReaderWriter
{
public:
virtual const char* className() const { return "TGA Image Reader"; }
virtual bool acceptsExtension(const std::string& extension) { return osgDB::equalCaseInsensitive(extension,"tga"); }
virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"tga"); }
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

View File

@ -26,12 +26,12 @@ class ReaderWriterTGZ : public osgDB::ReaderWriter
public:
virtual const char* className() const { return "TGZ Database Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"tgz");
}
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

View File

@ -413,14 +413,14 @@ class ReaderWriterTIFF : public osgDB::ReaderWriter
{
public:
virtual const char* className() const { return "TIFF Image Reader"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
if( osgDB::equalCaseInsensitive(extension,"tiff")) return true;
if( osgDB::equalCaseInsensitive(extension,"tif") ) return true;
return false;
}
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

View File

@ -54,13 +54,12 @@ public:
virtual const char* className() const { return "translation pseudo-loader"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive( extension, EXTENSION_NAME );
}
virtual ReadResult readNode(const std::string& fileName,
const osgDB::ReaderWriter::Options* /*options*/)
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(fileName);
if( !acceptsExtension(ext) )
@ -98,7 +97,7 @@ public:
}
// recursively load the subfile.
osg::Node *node = osgDB::readNodeFile( subFileName );
osg::Node *node = osgDB::readNodeFile( subFileName, options );
if( !node )
{
// propagate the read failure upwards

View File

@ -19,10 +19,8 @@ using namespace txp;
int ReaderWriterTXP::_archiveId = 0;
osgDB::ReaderWriter::ReadResult ReaderWriterTXP::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options)
osgDB::ReaderWriter::ReadResult ReaderWriterTXP::local_readNode(const std::string& file, const osgDB::ReaderWriter::Options* options)
{
if( !acceptsExtension(osgDB::getFileExtension(file) ))
return ReadResult::FILE_NOT_HANDLED;
std::string name = osgDB::getSimpleFileName(file);

View File

@ -43,6 +43,9 @@
#include <osg/Referenced>
#include <map>
#include <OpenThreads/ScopedLock>
#include <osgDB/ReentrantMutex>
#include "TXPArchive.h"
namespace txp
@ -55,20 +58,33 @@ public:
return "TXP Reader/Writer";
}
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"txp");
}
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*);
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
if( !acceptsExtension(osgDB::getFileExtension(file) ))
return ReadResult::FILE_NOT_HANDLED;
OpenThreads::ScopedLock<osgDB::ReentrantMutex> lock(_serializerMutex);
return const_cast<ReaderWriterTXP*>(this)->local_readNode(file, options);
}
protected:
TXPArchive *getArchive(int id, const std::string&);
std::map< int,osg::ref_ptr<TXPArchive> > _archives;
osg::Node* getTileContent(TXPArchive::TileInfo &info, int x, int y, int lod, TXPArchive* archive);
ReadResult local_readNode(const std::string& file, const osgDB::ReaderWriter::Options* options);
TXPArchive *getArchive(int id, const std::string&);
osg::Node* getTileContent(TXPArchive::TileInfo &info, int x, int y, int lod, TXPArchive* archive);
static int _archiveId;
mutable osgDB::ReentrantMutex _serializerMutex;
std::map< int,osg::ref_ptr<TXPArchive> > _archives;
static int _archiveId;
};
} // namespace

View File

@ -24,12 +24,12 @@ class ReaderWriterZIP : public osgDB::ReaderWriter
public:
virtual const char* className() const { return "ZIP Database Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension)
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive(extension,"zip");
}
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options)
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);

View File

@ -68,7 +68,7 @@ osgText::Font* osgText::readFontFile(const std::string& filename)
if (foundFile.empty()) return 0;
osg::ref_ptr<osgDB::ReaderWriter::Options> options = new osgDB::ReaderWriter::Options;
options->setUseObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_OBJECTS);
options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_OBJECTS);
osg::Object* object = osgDB::readObjectFile(foundFile, options.get());