Moved Registry::CacheHintOptions into ReaderWriter::Options

This commit is contained in:
Robert Osfield
2004-11-22 14:10:12 +00:00
parent 1ac452df69
commit a6369da4f4
20 changed files with 205 additions and 152 deletions

View File

@@ -24,12 +24,12 @@ using namespace osgDB;
osgDB::Archive* osgDB::openArchive(const std::string& filename, Archive::ArchiveStatus status, unsigned int indexBlockSizeHint)
{
return openArchive(filename, status, indexBlockSizeHint, Registry::instance()->getUseObjectCacheHint());
return openArchive(filename, status, indexBlockSizeHint, Registry::instance()->getOptions());
}
osgDB::Archive* osgDB::openArchive(const std::string& filename, Archive::ArchiveStatus status, unsigned int indexBlockSizeHint,Registry::CacheHintOptions useObjectCache)
osgDB::Archive* osgDB::openArchive(const std::string& filename, Archive::ArchiveStatus status, unsigned int indexBlockSizeHint,ReaderWriter::Options* options)
{
ReaderWriter::ReadResult result = osgDB::Registry::instance()->openArchive(filename, status, indexBlockSizeHint, useObjectCache);
ReaderWriter::ReadResult result = osgDB::Registry::instance()->openArchive(filename, status, indexBlockSizeHint, options);
return result.takeArchive();
}

View File

@@ -203,19 +203,32 @@ std::string osgDB::findFileInPath(const std::string& filename, const FilePathLis
}
std::string osgDB::findDataFile(const std::string& filename,CaseSensitivity caseSensitivity)
{
return findDataFile(filename,static_cast<ReaderWriter::Options*>(0),caseSensitivity);
}
OSGDB_EXPORT std::string osgDB::findDataFile(const std::string& filename,ReaderWriter::Options* options, CaseSensitivity caseSensitivity)
{
if (filename.empty()) return filename;
std::string fileFound;
if (options && !options->getDatabasePathList().empty())
{
fileFound = findFileInPath(filename, options->getDatabasePathList(), caseSensitivity);
if (!fileFound.empty()) return fileFound;
}
const FilePathList& filepath = Registry::instance()->getDataFilePathList();
std::string fileFound = findFileInPath(filename, filepath,caseSensitivity);
fileFound = findFileInPath(filename, filepath,caseSensitivity);
if (!fileFound.empty()) return fileFound;
// if a directory is included in the filename, get just the (simple) filename itself and try that
std::string simpleFileName = getSimpleFileName(filename);
if (simpleFileName!=filename)
{
std::string fileFound = findFileInPath(simpleFileName, filepath,caseSensitivity);
fileFound = findFileInPath(simpleFileName, filepath,caseSensitivity);
if (!fileFound.empty()) return fileFound;
}

View File

@@ -80,22 +80,16 @@ osg::Node* Input::readNode()
osg::Object* Input::readObject(const std::string& fileName)
{
return readObjectFile(fileName);
return readObjectFile(fileName,_options.get());
}
osg::Image* Input::readImage(const std::string& fileName)
{
if (_options.valid() && !_options->getDatabasePath().empty())
{
osg::Image* image = readImageFile(_options->getDatabasePath()+'/'+fileName);
if (image) return image;
}
return readImageFile(fileName);
return readImageFile(fileName,_options.get());
}
osg::Node* Input::readNode(const std::string& fileName)
{
return readNodeFile(fileName);
return readNodeFile(fileName,_options.get());
}

View File

@@ -24,42 +24,42 @@
using namespace osg;
using namespace osgDB;
Object* osgDB::readObjectFile(const std::string& filename,Registry::CacheHintOptions useObjectCache)
Object* osgDB::readObjectFile(const std::string& filename,const ReaderWriter::Options* options)
{
ReaderWriter::ReadResult rr = Registry::instance()->readObject(filename,useObjectCache);
ReaderWriter::ReadResult rr = Registry::instance()->readObject(filename,options);
if (rr.validObject()) return rr.takeObject();
if (rr.error()) notify(WARN) << rr.message() << std::endl;
return NULL;
}
Image* osgDB::readImageFile(const std::string& filename,Registry::CacheHintOptions useObjectCache)
Image* osgDB::readImageFile(const std::string& filename,const ReaderWriter::Options* options)
{
ReaderWriter::ReadResult rr = Registry::instance()->readImage(filename,useObjectCache);
ReaderWriter::ReadResult rr = Registry::instance()->readImage(filename,options);
if (rr.validImage()) return rr.takeImage();
if (rr.error()) notify(WARN) << rr.message() << std::endl;
return NULL;
}
HeightField* osgDB::readHeightFieldFile(const std::string& filename,Registry::CacheHintOptions useObjectCache)
HeightField* osgDB::readHeightFieldFile(const std::string& filename,const ReaderWriter::Options* options)
{
ReaderWriter::ReadResult rr = Registry::instance()->readHeightField(filename,useObjectCache);
ReaderWriter::ReadResult rr = Registry::instance()->readHeightField(filename,options);
if (rr.validHeightField()) return rr.takeHeightField();
if (rr.error()) notify(WARN) << rr.message() << std::endl;
return NULL;
}
Node* osgDB::readNodeFile(const std::string& filename,Registry::CacheHintOptions useObjectCache)
Node* osgDB::readNodeFile(const std::string& filename,const ReaderWriter::Options* options)
{
ReaderWriter::ReadResult rr = Registry::instance()->readNode(filename,useObjectCache);
ReaderWriter::ReadResult rr = Registry::instance()->readNode(filename,options);
if (rr.validNode()) return rr.takeNode();
if (rr.error()) notify(WARN) << rr.message() << std::endl;
return NULL;
}
Node* osgDB::readNodeFiles(std::vector<std::string>& commandLine,Registry::CacheHintOptions useObjectCache)
Node* osgDB::readNodeFiles(std::vector<std::string>& commandLine,const ReaderWriter::Options* options)
{
typedef std::vector<osg::Node*> NodeList;
NodeList nodeList;
@@ -73,7 +73,7 @@ Node* osgDB::readNodeFiles(std::vector<std::string>& commandLine,Registry::Cache
if ((*itr)[0]!='-')
{
// not an option so assume string is a filename.
osg::Node *node = osgDB::readNodeFile( *itr ,useObjectCache );
osg::Node *node = osgDB::readNodeFile( *itr , options );
if( node != (osg::Node *)0L )
{
@@ -108,7 +108,7 @@ Node* osgDB::readNodeFiles(std::vector<std::string>& commandLine,Registry::Cache
}
Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,Registry::CacheHintOptions useObjectCache)
Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,const ReaderWriter::Options* options)
{
typedef std::vector<osg::Node*> NodeList;
@@ -117,13 +117,13 @@ Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,Registry::CacheHintOpt
std::string filename;
while (arguments.read("--image",filename))
{
osg::Image* image = readImageFile(filename.c_str(), useObjectCache);
osg::Image* image = readImageFile(filename.c_str(), options);
if (image) nodeList.push_back(osg::createGeodeForImage(image));
}
while (arguments.read("--dem",filename))
{
osg::HeightField* hf = readHeightFieldFile(filename.c_str(), useObjectCache);
osg::HeightField* hf = readHeightFieldFile(filename.c_str(), options);
if (hf)
{
osg::Geode* geode = new osg::Geode;
@@ -138,7 +138,7 @@ Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,Registry::CacheHintOpt
if (!arguments.isOption(pos))
{
// not an option so assume string is a filename.
osg::Node *node = osgDB::readNodeFile( arguments[pos], useObjectCache);
osg::Node *node = osgDB::readNodeFile( arguments[pos], options);
if(node)
{

View File

@@ -138,7 +138,7 @@ Registry::Registry()
_createNodeFromImage = false;
_openingLibrary = false;
_useObjectCacheHint = CACHE_ARCHIVES;
_useObjectCacheHint = ReaderWriter::Options::CACHE_ARCHIVES;
initFilePathLists();
@@ -1185,7 +1185,7 @@ ReaderWriter::ReadResult Registry::read(const ReadFunctor& readFunctor)
osg::notify(osg::INFO)<<" archive : "<<archiveName<<std::endl;
osg::notify(osg::INFO)<<" filename : "<<fileName<<std::endl;
ReaderWriter::ReadResult result = openArchiveImplementation(archiveName,ReaderWriter::READ, 4096, CACHE_ARCHIVES);
ReaderWriter::ReadResult result = openArchiveImplementation(archiveName,ReaderWriter::READ, 4096, readFunctor._options);
if (!result.validArchive()) return result;
@@ -1316,8 +1316,6 @@ ReaderWriter::ReadResult Registry::readImplementation(const ReadFunctor& readFun
}
}
PushAndPopDataPath tmpfile(getFilePath(file));
ReaderWriter::ReadResult rr = read(readFunctor);
if (rr.validObject())
{
@@ -1342,8 +1340,6 @@ ReaderWriter::ReadResult Registry::readImplementation(const ReadFunctor& readFun
tmpObjectCache.swap(_objectCache);
}
PushAndPopDataPath tmpfile(getFilePath(file));
ReaderWriter::ReadResult rr = read(readFunctor);
{
@@ -1356,14 +1352,14 @@ ReaderWriter::ReadResult Registry::readImplementation(const ReadFunctor& readFun
}
ReaderWriter::ReadResult Registry::openArchiveImplementation(const std::string& fileName, ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, CacheHintOptions useObjectCache)
ReaderWriter::ReadResult Registry::openArchiveImplementation(const std::string& fileName, ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const ReaderWriter::Options* options)
{
if (useObjectCache&CACHE_ARCHIVES)
if (options && (options->getUseObjectCacheHint() & ReaderWriter::Options::CACHE_ARCHIVES))
{
osgDB::Archive* archive = getFromArchiveCache(fileName);
if (archive) return archive;
ReaderWriter::ReadResult result = readImplementation(ReadArchiveFunctor(fileName, status, indexBlockSizeHint, _options.get()),false);
ReaderWriter::ReadResult result = readImplementation(ReadArchiveFunctor(fileName, status, indexBlockSizeHint, options),false);
if (result.validArchive())
{
addToArchiveCache(fileName,result.getArchive());
@@ -1377,9 +1373,10 @@ ReaderWriter::ReadResult Registry::openArchiveImplementation(const std::string&
}
ReaderWriter::ReadResult Registry::readObjectImplementation(const std::string& fileName,CacheHintOptions useObjectCache)
ReaderWriter::ReadResult Registry::readObjectImplementation(const std::string& fileName,const ReaderWriter::Options* options)
{
return readImplementation(ReadObjectFunctor(fileName, _options.get()),(useObjectCache&CACHE_OBJECTS)!=0);
return readImplementation(ReadObjectFunctor(fileName, options),
options ? (options->getUseObjectCacheHint()&ReaderWriter::Options::CACHE_OBJECTS): false);
}
ReaderWriter::WriteResult Registry::writeObjectImplementation(const Object& obj,const std::string& fileName)
@@ -1419,9 +1416,10 @@ ReaderWriter::WriteResult Registry::writeObjectImplementation(const Object& obj,
ReaderWriter::ReadResult Registry::readImageImplementation(const std::string& fileName,CacheHintOptions useObjectCache)
ReaderWriter::ReadResult Registry::readImageImplementation(const std::string& fileName,const ReaderWriter::Options* options)
{
return readImplementation(ReadImageFunctor(fileName, _options.get()),(useObjectCache&CACHE_IMAGES)!=0);
return readImplementation(ReadImageFunctor(fileName, options),
options ? (options->getUseObjectCacheHint()&ReaderWriter::Options::CACHE_IMAGES): false);
}
ReaderWriter::WriteResult Registry::writeImageImplementation(const Image& image,const std::string& fileName)
@@ -1460,9 +1458,10 @@ ReaderWriter::WriteResult Registry::writeImageImplementation(const Image& image,
}
ReaderWriter::ReadResult Registry::readHeightFieldImplementation(const std::string& fileName,CacheHintOptions useObjectCache)
ReaderWriter::ReadResult Registry::readHeightFieldImplementation(const std::string& fileName,const ReaderWriter::Options* options)
{
return readImplementation(ReadHeightFieldFunctor(fileName, _options.get()),(useObjectCache&CACHE_HEIGHTFIELDS)!=0);
return readImplementation(ReadHeightFieldFunctor(fileName, options),
options ? (options->getUseObjectCacheHint()&ReaderWriter::Options::CACHE_HEIGHTFIELDS): false);
}
ReaderWriter::WriteResult Registry::writeHeightFieldImplementation(const HeightField& HeightField,const std::string& fileName)
@@ -1501,9 +1500,10 @@ ReaderWriter::WriteResult Registry::writeHeightFieldImplementation(const HeightF
}
ReaderWriter::ReadResult Registry::readNodeImplementation(const std::string& fileName,CacheHintOptions useObjectCache)
ReaderWriter::ReadResult Registry::readNodeImplementation(const std::string& fileName,const ReaderWriter::Options* options)
{
return readImplementation(ReadNodeFunctor(fileName, _options.get()),(useObjectCache&CACHE_NODES)!=0);
return readImplementation(ReadNodeFunctor(fileName, options),
options ? (options->getUseObjectCacheHint()&ReaderWriter::Options::CACHE_NODES): false);
}
ReaderWriter::WriteResult Registry::writeNodeImplementation(const Node& node,const std::string& fileName)

View File

@@ -98,9 +98,9 @@ void PagedLOD::read(DataInputStream* in){
throw Exception("Group::read(): Could not cast this osg::Group to an osg::Node.");
if (getDatabasePath().empty() && in->getOptions())
if (getDatabasePath().empty() && in->getOptions() && !in->getOptions()->getDatabasePathList().empty())
{
const std::string& path = in->getOptions()->getDatabasePath();
const std::string& path = in->getOptions()->getDatabasePathList().front();
if (!path.empty())
{
setDatabasePath(path);

View File

@@ -38,7 +38,7 @@ class IVEReaderWriter : public ReaderWriter
osg::ref_ptr<Options> local_opt = const_cast<Options*>(options);
if (!local_opt) local_opt = new Options;
if (local_opt.valid() && local_opt->getDatabasePath().empty())
if (local_opt.valid() && local_opt->getDatabasePathList().empty())
{
local_opt->setDatabasePath(osgDB::getFilePath(fileName));
}

View File

@@ -334,7 +334,7 @@ class NetReader : public osgDB::ReaderWriter
osg::ref_ptr<Options> local_opt = const_cast<Options*>(options);
if (!local_opt) local_opt = new Options;
if (local_opt.valid() && local_opt->getDatabasePath().empty())
if (local_opt.valid() && local_opt->getDatabasePathList().empty())
{
local_opt->setDatabasePath(osgDB::getFilePath(inFileName));
}

View File

@@ -104,7 +104,18 @@ void ReaderWriterOBJ::buildMaterialToStateSetMap(obj::Model& model, MaterialToSt
if (!material.map_Kd.empty())
{
std::string filename = material.map_Kd;
osg::Image* image = osgDB::readImageFile(filename);
osg::Image* image = 0;
if (!model.getDatabasePath().empty())
{
// first try with databasr path of parent.
image = osgDB::readImageFile(model.getDatabasePath()+'/'+filename);
}
if (!image)
{
// if not already set then try the filename as is.
image = osgDB::readImageFile(filename);
}
if (image)
{
osg::Texture2D* texture = new osg::Texture2D(image);
@@ -448,9 +459,8 @@ osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& fil
if (fin)
{
osgDB::PushAndPopDataPath papdp( osgDB::getFilePath(fileName.c_str()) );
obj::Model model;
model.setDatabasePath(osgDB::getFilePath(fileName.c_str()));
model.readOBJ(fin);
osg::Node* node = convertModelToSceneGraph(model);

View File

@@ -153,6 +153,9 @@ public:
Model():
currentElementList(0) {}
void setDatabasePath(const std::string& path) { databasePath = path; }
const std::string& getDatabasePath() const { return databasePath; }
bool readMTL(std::istream& fin);
bool readOBJ(std::istream& fin);
@@ -173,6 +176,8 @@ public:
typedef std::vector< osg::ref_ptr<Element> > ElementList;
typedef std::map< ElementState,ElementList > ElementStateMap;
std::string databasePath;
MaterialMap materialMap;
Vec3Array vertices;

View File

@@ -28,9 +28,9 @@ bool PagedLOD_readLocalData(Object& obj, Input& fr)
PagedLOD& lod = static_cast<PagedLOD&>(obj);
if (lod.getDatabasePath().empty() && fr.getOptions())
if (lod.getDatabasePath().empty() && fr.getOptions() && !fr.getOptions()->getDatabasePathList().empty())
{
const std::string& path = fr.getOptions()->getDatabasePath();
const std::string& path = fr.getOptions()->getDatabasePathList().front();
if (!path.empty())
{
lod.setDatabasePath(path);

View File

@@ -40,7 +40,7 @@ class OSGReaderWriter : public ReaderWriter
osg::ref_ptr<Options> local_opt = const_cast<Options*>(opt);
if (!local_opt) local_opt = new Options;
if (local_opt.valid() && local_opt->getDatabasePath().empty())
if (local_opt.valid() && local_opt->getDatabasePathList().empty())
{
local_opt->setDatabasePath(osgDB::getFilePath(fileName));
}

View File

@@ -66,8 +66,11 @@ osgText::Font* osgText::readFontFile(const std::string& filename)
{
std::string foundFile = findFontFile(filename);
if (foundFile.empty()) return 0;
osg::ref_ptr<osgDB::ReaderWriter::Options> options = new osgDB::ReaderWriter::Options;
options->setUseObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_OBJECTS);
osg::Object* object = osgDB::readObjectFile(foundFile, osgDB::Registry::CACHE_OBJECTS);
osg::Object* object = osgDB::readObjectFile(foundFile, options.get());
// if the object is a font then return it.
osgText::Font* font = dynamic_cast<osgText::Font*>(object);