From 83bf813e58f609940fcadecc8eefa6c12d3d547e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 8 Dec 2003 11:24:43 +0000 Subject: [PATCH] Moved the responsibility for finding file to load on to the ReaderWriter plugins, instead of osgDB::Registry where it original lay. This has been done to allow fileName strings to be encode data rather than just file names, such as one requires when using PagedLOD along with plugins for doing dynamic tesselation. --- Make/makedirdefs | 1 + examples/slideshow3D/ReaderWriterXML.cpp | 11 +- include/osgDB/ReaderWriter | 2 + include/osgUtil/TriStripVisitor | 2 +- src/osgDB/FileUtils.cpp | 3 - src/osgDB/Registry.cpp | 66 +++--- src/osgPlugins/3dc/ReaderWriter3DC.cpp | 8 +- src/osgPlugins/Inventor/ReaderWriterIV.cpp | 10 +- src/osgPlugins/bmp/ReaderWriterBMP.cpp | 9 +- src/osgPlugins/dds/ReaderWriterDDS.cpp | 9 +- .../directx/ReaderWriterDirectX.cpp | 11 +- src/osgPlugins/dw/ReaderWriterDW.cpp | 25 ++- src/osgPlugins/flt/ReaderWriterATTR.cpp | 8 +- src/osgPlugins/flt/ReaderWriterFLT.cpp | 10 +- .../freetype/ReaderWriterFreeType.cpp | 8 +- src/osgPlugins/gdal/ReaderWriterGDAL.cpp | 161 +++++++------- src/osgPlugins/geo/ReaderWriterGEO.cpp | 8 +- src/osgPlugins/gif/ReaderWriterGIF.cpp | 9 +- src/osgPlugins/ive/ReaderWriterIVE.cpp | 8 +- src/osgPlugins/jp2/ReaderWriterJP2.cpp | 9 +- src/osgPlugins/jpeg/ReaderWriterJPEG.cpp | 8 +- src/osgPlugins/lib3ds/ReaderWriter3DS.cpp | 10 +- src/osgPlugins/logo/ReaderWriterLOGO.cpp | 8 +- src/osgPlugins/lwo/ReaderWriterLWO.cpp | 9 +- src/osgPlugins/md2/ReaderWriterMD2.cpp | 9 +- src/osgPlugins/obj/ReaderWriterOBJ.cpp | 6 +- src/osgPlugins/osg/ReaderWriterOSG.cpp | 20 +- src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp | 7 +- src/osgPlugins/pfb/ReaderWriterPFB.cpp | 12 +- src/osgPlugins/pic/ReaderWriterPIC.cpp | 8 +- src/osgPlugins/png/ReaderWriterPNG.cpp | 9 +- src/osgPlugins/pnm/ReaderWriterPNM.cpp | 10 +- src/osgPlugins/quicktime/ReaderWriterQT.cpp | 209 +++++++++--------- src/osgPlugins/rgb/ReaderWriterRGB.cpp | 18 +- src/osgPlugins/tga/ReaderWriterTGA.cpp | 8 +- src/osgPlugins/tgz/ReaderWriterTGZ.cpp | 7 +- src/osgPlugins/tiff/ReaderWriterTIFF.cpp | 9 +- src/osgPlugins/txp/ReaderWriterTXP.cpp | 2 +- src/osgPlugins/zip/ReaderWriterZIP.cpp | 7 +- src/osgUtil/Optimizer.cpp | 2 +- src/osgUtil/TriStripVisitor.cpp | 100 ++++----- 41 files changed, 489 insertions(+), 367 deletions(-) diff --git a/Make/makedirdefs b/Make/makedirdefs index 806b0b06a..c75091e41 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -153,6 +153,7 @@ EXAMPLE_DIRS = \ osgpagedlod\ osgpick\ osgpoints\ +# osgphotoalbum\ osgprerender\ osgprerendercubemap\ osgreflect\ diff --git a/examples/slideshow3D/ReaderWriterXML.cpp b/examples/slideshow3D/ReaderWriterXML.cpp index 619e3034c..ab290275b 100644 --- a/examples/slideshow3D/ReaderWriterXML.cpp +++ b/examples/slideshow3D/ReaderWriterXML.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include "SlideShowConstructor.h" @@ -442,12 +443,14 @@ void ReaderWriterSS3D::parseSlide (SlideShowConstructor& constructor, xmlDocPtr return; } -osgDB::ReaderWriter::ReadResult ReaderWriterSS3D::readNode(const std::string& fileName, +osgDB::ReaderWriter::ReadResult ReaderWriterSS3D::readNode(const std::string& file, const osgDB::ReaderWriter::Options*) { - std::string ext = osgDB::getLowerCaseFileExtension(fileName); - if (!acceptsExtension(ext)) - return ReadResult::FILE_NOT_HANDLED; + std::string ext = osgDB::getLowerCaseFileExtension(file); + if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; diff --git a/include/osgDB/ReaderWriter b/include/osgDB/ReaderWriter index 057b4f022..105456fb0 100644 --- a/include/osgDB/ReaderWriter +++ b/include/osgDB/ReaderWriter @@ -61,6 +61,7 @@ class OSGDB_EXPORT ReaderWriter : public osg::Referenced enum ReadStatus { FILE_NOT_HANDLED, + FILE_NOT_FOUND, FILE_LOADED, ERROR_IN_READING_FILE }; @@ -93,6 +94,7 @@ class OSGDB_EXPORT ReaderWriter : public osg::Referenced bool success() const { return _status==FILE_LOADED; } bool error() const { return _status==ERROR_IN_READING_FILE; } bool notHandled() const { return _status==FILE_NOT_HANDLED; } + bool notFound() const { return _status==FILE_NOT_FOUND; } protected: diff --git a/include/osgUtil/TriStripVisitor b/include/osgUtil/TriStripVisitor index c3acb1f6e..079251809 100644 --- a/include/osgUtil/TriStripVisitor +++ b/include/osgUtil/TriStripVisitor @@ -34,7 +34,7 @@ class OSGUTIL_EXPORT TriStripVisitor : public osg::NodeVisitor /// default to traversing all children. TriStripVisitor() : osg::NodeVisitor( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN ), - _cacheSize( 24 ), + _cacheSize( 16 ), _minStripSize( 2 ) {} diff --git a/src/osgDB/FileUtils.cpp b/src/osgDB/FileUtils.cpp index 27a25b99a..17e712f26 100644 --- a/src/osgDB/FileUtils.cpp +++ b/src/osgDB/FileUtils.cpp @@ -37,9 +37,6 @@ bool osgDB::fileExists(const std::string& filename) { - // hack for getting TXP plugin to utilise PagedLOD. - if (getLowerCaseFileExtension(filename)=="txp") return true; - return access( filename.c_str(), F_OK ) == 0; } diff --git a/src/osgDB/Registry.cpp b/src/osgDB/Registry.cpp index 65cad928b..c1d8606de 100644 --- a/src/osgDB/Registry.cpp +++ b/src/osgDB/Registry.cpp @@ -325,7 +325,7 @@ void Registry::addDotOsgWrapper(DotOsgWrapper* wrapper) const osg::Object* proto = wrapper->getPrototype(); _objectWrapperMap[name] = wrapper; - if (wrapper->getReadWriteMode()==DotOsgWrapper::READ_AND_WRITE) _classNameWrapperMap[name] = wrapper; + if (wrapper->getReadWriteMode()==DotOsgWrapper::READ_AND_WRITE) _classNameWrapperMap[name] = wrapper; if (proto) { @@ -468,7 +468,7 @@ std::string Registry::createLibraryNameForNodeKit(const std::string& name) #if defined(WIN32) // !! recheck evolving Cygwin DLL extension naming protocols !! NHV #ifdef __CYGWIN__ // [ - return "cyg"+name+".dll"; + return "cyg"+name+".dll"; #elif defined(__MINGW32__) return "lib"+name+".dll"; #else @@ -570,17 +570,17 @@ ReaderWriter* Registry::getReaderWriterForExtension(const std::string& ext) struct concrete_wrapper: basic_type_wrapper { - concrete_wrapper(const osg::Object *myobj) : myobj_(myobj) {} - bool matches(const osg::Object *proto) const - { - return myobj_->isSameKindAs(proto); - } - const osg::Object *myobj_; + concrete_wrapper(const osg::Object *myobj) : myobj_(myobj) {} + bool matches(const osg::Object *proto) const + { + return myobj_->isSameKindAs(proto); + } + const osg::Object *myobj_; }; osg::Object* Registry::readObjectOfType(const osg::Object& compObj,Input& fr) { - return readObjectOfType(concrete_wrapper(&compObj), fr); + return readObjectOfType(concrete_wrapper(&compObj), fr); } osg::Object* Registry::readObjectOfType(const basic_type_wrapper &btw,Input& fr) @@ -980,16 +980,16 @@ bool Registry::writeObject(const osg::Object& obj,Output& fw) } std::string classname = obj.className(); - std::string libraryName = obj.libraryName(); - std::string compositeName = libraryName + "::" + classname; + std::string libraryName = obj.libraryName(); + std::string compositeName = libraryName + "::" + classname; - // try composite name first - DotOsgWrapperMap::iterator itr = _classNameWrapperMap.find(compositeName); + // try composite name first + DotOsgWrapperMap::iterator itr = _classNameWrapperMap.find(compositeName); - // composite name not found, try simple class name - if (itr == _classNameWrapperMap.end()) { - itr = _classNameWrapperMap.find(classname); - } + // composite name not found, try simple class name + if (itr == _classNameWrapperMap.end()) { + itr = _classNameWrapperMap.find(classname); + } if (itr==_classNameWrapperMap.end()) { @@ -1148,11 +1148,8 @@ ReaderWriter::ReadResult Registry::readObject(const std::string& fileName) return results.front(); } -ReaderWriter::ReadResult Registry::readObject(const std::string& fileName,bool useObjectCache) +ReaderWriter::ReadResult Registry::readObject(const std::string& file,bool useObjectCache) { - std::string file = findDataFile( fileName ); - if (file.empty()) return ReaderWriter::ReadResult("Warning: file \""+fileName+"\" not found."); - if (useObjectCache) { // search for entry in the object cache. @@ -1286,12 +1283,8 @@ ReaderWriter::ReadResult Registry::readImage(const std::string& fileName) } -ReaderWriter::ReadResult Registry::readImage(const std::string& fileName,bool useObjectCache) +ReaderWriter::ReadResult Registry::readImage(const std::string& file,bool useObjectCache) { - std::string file = findDataFile( fileName ); - if (file.empty()) - file = fileName; -// return ReaderWriter::ReadResult("Warning: file \""+fileName+"\" not found."); if (useObjectCache) { @@ -1314,8 +1307,8 @@ ReaderWriter::ReadResult Registry::readImage(const std::string& fileName,bool us notify(INFO)<<"Adding to cache image "< #include +#include #include #include @@ -22,10 +23,13 @@ class ReaderWriter3DC : public osgDB::ReaderWriter osgDB::equalCaseInsensitive(extension,"asc"); } - virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options*) { - std::string ext = osgDB::getFileExtension(fileName); + std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; std::cout << "try to read file "< #include +#include /**************************************************************************** * @@ -318,12 +319,14 @@ class ReaderWriterBMP : public osgDB::ReaderWriter virtual const char* className() { return "BMP Image Reader"; } virtual bool acceptsExtension(const std::string& extension) { return osgDB::equalCaseInsensitive(extension,"bmp"); } - virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options*) { - - std::string ext = osgDB::getFileExtension(fileName); + std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + unsigned char *imageData = NULL; int width_ret; int height_ret; diff --git a/src/osgPlugins/dds/ReaderWriterDDS.cpp b/src/osgPlugins/dds/ReaderWriterDDS.cpp index 4968f244a..9b53ab2b7 100644 --- a/src/osgPlugins/dds/ReaderWriterDDS.cpp +++ b/src/osgPlugins/dds/ReaderWriterDDS.cpp @@ -20,6 +20,7 @@ #include #include +#include #include @@ -324,8 +325,14 @@ class ReaderWriterDDS : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"dds"); } - virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options*) { + std::string ext = osgDB::getLowerCaseFileExtension(file); + if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + osg::Image* osgImage = ReadDDSFile(fileName.c_str()); if (osgImage==NULL) return ReadResult::FILE_NOT_HANDLED; return osgImage; diff --git a/src/osgPlugins/directx/ReaderWriterDirectX.cpp b/src/osgPlugins/directx/ReaderWriterDirectX.cpp index 950c99c3d..ef30c5ef1 100644 --- a/src/osgPlugins/directx/ReaderWriterDirectX.cpp +++ b/src/osgPlugins/directx/ReaderWriterDirectX.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -69,12 +70,14 @@ osgDB::RegisterReaderWriterProxy g_readerWriter_DirectX_Pro // Read node -osgDB::ReaderWriter::ReadResult ReaderWriterDirectX::readNode(const std::string& fileName, +osgDB::ReaderWriter::ReadResult ReaderWriterDirectX::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) { - std::string ext = osgDB::getLowerCaseFileExtension(fileName); - if (!acceptsExtension(ext)) - return ReadResult::FILE_NOT_HANDLED; + std::string ext = osgDB::getLowerCaseFileExtension(file); + if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; osg::notify(osg::INFO) << "ReaderWriterDirectX::readNode(" << fileName.c_str() << ")\n"; diff --git a/src/osgPlugins/dw/ReaderWriterDW.cpp b/src/osgPlugins/dw/ReaderWriterDW.cpp index 91271e666..971c538b1 100644 --- a/src/osgPlugins/dw/ReaderWriterDW.cpp +++ b/src/osgPlugins/dw/ReaderWriterDW.cpp @@ -799,20 +799,25 @@ class ReaderWriterDW : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"dw"); } - virtual ReadResult readNode(const std::string& fileName,const osgDB::ReaderWriter::Options*) + virtual ReadResult readNode(const std::string& file,const osgDB::ReaderWriter::Options*) { - _dwobj obj; - enum reading {NONE, MATERIAL, OBJECT}; - //unsigned short nrecs=0; // number of records read after a divider (numVerts, numFaces, numOpenings...) - int nexpected=0; // number of records to be read in a block - dwmaterial *matpalet=NULL; - int nmat=-1; // current element of matpalet being modified - int nmn=0; // number of materials found - reading rdg=NONE; - std::string ext = osgDB::getFileExtension(fileName); + std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + + + _dwobj obj; + enum reading {NONE, MATERIAL, OBJECT}; + //unsigned short nrecs=0; // number of records read after a divider (numVerts, numFaces, numOpenings...) + int nexpected=0; // number of records to be read in a block + dwmaterial *matpalet=NULL; + int nmat=-1; // current element of matpalet being modified + int nmn=0; // number of materials found + reading rdg=NONE; + char buff[256]; notify(INFO)<< "ReaderWriterDW::readNode( "< #include +#include #include #include @@ -748,11 +749,14 @@ class ReaderWriterATTR : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"attr"); } - virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options*) { - std::string ext = osgDB::getFileExtension(fileName); + std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + // options char buf[256]; int version=0; diff --git a/src/osgPlugins/flt/ReaderWriterFLT.cpp b/src/osgPlugins/flt/ReaderWriterFLT.cpp index f37e7b42c..ea0c3e56b 100644 --- a/src/osgPlugins/flt/ReaderWriterFLT.cpp +++ b/src/osgPlugins/flt/ReaderWriterFLT.cpp @@ -13,6 +13,7 @@ #include #include +#include using namespace flt; @@ -22,10 +23,13 @@ osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readObject(const std::string& f } -osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) +osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) { - if( !acceptsExtension(osgDB::getFileExtension(fileName) )) - return ReadResult::FILE_NOT_HANDLED; + std::string ext = osgDB::getLowerCaseFileExtension(file); + if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; osg::ref_ptr read = new FltFile; diff --git a/src/osgPlugins/freetype/ReaderWriterFreeType.cpp b/src/osgPlugins/freetype/ReaderWriterFreeType.cpp index 3410e67be..85993f561 100644 --- a/src/osgPlugins/freetype/ReaderWriterFreeType.cpp +++ b/src/osgPlugins/freetype/ReaderWriterFreeType.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "FreeTypeLibrary.h" @@ -21,10 +22,13 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter osgDB::equalCaseInsensitive(extension,"fnt"); // Windows bitmap fonts } - virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options*) { - std::string ext = osgDB::getFileExtension(fileName); + std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; osgText::Font* font = FreeTypeLibrary::instance()->getFont(fileName,0); diff --git a/src/osgPlugins/gdal/ReaderWriterGDAL.cpp b/src/osgPlugins/gdal/ReaderWriterGDAL.cpp index 0150aeb66..152c88c49 100644 --- a/src/osgPlugins/gdal/ReaderWriterGDAL.cpp +++ b/src/osgPlugins/gdal/ReaderWriterGDAL.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -18,11 +19,14 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"gdal") || osgDB::equalCaseInsensitive(extension,"gdal"); } - virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) { - //std::string ext = osgDB::getFileExtension(fileName); + //std::string ext = osgDB::getFileExtension(file); //if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + initGDAL(); std::auto_ptr dataset((GDALDataset*)GDALOpen(fileName.c_str(),GA_ReadOnly)); @@ -46,10 +50,10 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter osgDB::ImageOptions::TexCoordRange* texCoordRange = 0; - const osgDB::ImageOptions* imageOptions = dynamic_cast(options); + osgDB::ImageOptions* imageOptions = dynamic_cast(const_cast(options)); if (imageOptions) { - std::cout<<"Got ImageOptions"<_sourceImageWindowMode) @@ -71,7 +75,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter ((double)(windowY+windowHeight) -(desiredY+desiredHeight))/(double)windowHeight, (desiredWidth)/(double)windowWidth, (desiredHeight)/(double)windowHeight); - std::cout<<"tex coord range "<_x<<" "<_y<<" "<_w<<" "<_h<_x<<" "<_y<<" "<_w<<" "<_h<_sourcePixelWindow.windowX = windowX; + imageOptions->_sourcePixelWindow.windowY = windowY; + imageOptions->_sourcePixelWindow.windowWidth = windowWidth; + imageOptions->_sourcePixelWindow.windowHeight = windowHeight; + switch(imageOptions->_destinationImageWindowMode) { case(osgDB::ImageOptions::RATIO_WINDOW): @@ -111,31 +122,31 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter // windowWidth = destWidth; // windowHeight = destHeight; - std::cout << " windowX = "<GetRasterCount()<GetProjectionRef()<GetRasterCount()<GetProjectionRef()<GetGeoTransform(geoTransform)==CE_None) { - std::cout << " GetGeoTransform "<< std::endl; - std::cout << " Origin = "<GetRasterCount(); @@ -159,12 +170,12 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter GDALRasterBand* band = dataset->GetRasterBand(b); - std::cout << " Band "<RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+0),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); bandGreen->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+1),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); @@ -251,7 +262,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter pixelFormat = GL_RGB; internalFormat = GL_RGB; - std::cout << "reading RGB"<RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+0),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); bandGreen->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+1),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); @@ -270,7 +281,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter pixelFormat = GL_LUMINANCE_ALPHA; internalFormat = GL_LUMINANCE_ALPHA; - std::cout << "reading grey + alpha"<RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+0),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); bandAlpha->RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+1),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); @@ -285,7 +296,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter pixelFormat = GL_LUMINANCE; internalFormat = GL_LUMINANCE; - std::cout << "reading grey"<RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+0),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); } @@ -299,7 +310,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter pixelFormat = GL_ALPHA; internalFormat = GL_ALPHA; - std::cout << "reading alpha"<RasterIO(GF_Read,windowX,windowY,windowWidth,windowHeight,(void*)(imageData+0),destWidth,destHeight,targetGDALType,pixelSpace,lineSpace); @@ -307,7 +318,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter } else { - std::cout << "not found any usable bands in file."<(options); if (imageOptions) { - std::cout<<"Got ImageOptions"<_sourceImageWindowMode) @@ -386,7 +397,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter ((double)(windowY+windowHeight) -(desiredY+desiredHeight))/(double)windowHeight, (desiredWidth)/(double)windowWidth, (desiredHeight)/(double)windowHeight); - std::cout<<"tex coord range "<_x<<" "<_y<<" "<_w<<" "<_h<_x<<" "<_y<<" "<_w<<" "<_h<GetRasterCount()<GetProjectionRef()<GetRasterCount()<GetProjectionRef()<GetGeoTransform(geoTransform)<<" == CE_None"<GetGeoTransform(geoTransform)<<" == CE_None"<GetGCPCount()<GetGCPCount()<GetRasterCount(); @@ -484,21 +495,21 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter GDALRasterBand* band = dataset->GetRasterBand(b); - std::cout << " Band "<GetColorInterpretation()==GCI_GrayIndex) bandGray = band; @@ -515,12 +526,12 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter // minmax[1] = band->GetMaximum(&gotMax); // if (!(gotMin && gotMax)) // { -// std::cout<<" computing min max"<getNumRows()-1; for(unsigned int r=0;r #include +#include #include #include #include @@ -399,11 +400,14 @@ class ReaderWriterGEO : public osgDB::ReaderWriter virtual ReadResult readObject(const std::string& fileName, const Options* opt) { return readNode(fileName,opt); } - virtual ReadResult readNode(const std::string& fileName, const Options*) + virtual ReadResult readNode(const std::string& file, const Options*) { - std::string ext = osgDB::getFileExtension(fileName); + std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + std::string fileName = osgDB::findDataFile( file ); + 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. diff --git a/src/osgPlugins/gif/ReaderWriterGIF.cpp b/src/osgPlugins/gif/ReaderWriterGIF.cpp index dd7c8c5b3..52e11cb6c 100644 --- a/src/osgPlugins/gif/ReaderWriterGIF.cpp +++ b/src/osgPlugins/gif/ReaderWriterGIF.cpp @@ -4,6 +4,7 @@ #include #include +#include #include @@ -323,12 +324,14 @@ class ReaderWriterGIF : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"gif"); } - virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options*) { - - std::string ext = osgDB::getFileExtension(fileName); + std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + unsigned char *imageData = NULL; int width_ret; int height_ret; diff --git a/src/osgPlugins/ive/ReaderWriterIVE.cpp b/src/osgPlugins/ive/ReaderWriterIVE.cpp index 025b619e8..fd59dae8a 100644 --- a/src/osgPlugins/ive/ReaderWriterIVE.cpp +++ b/src/osgPlugins/ive/ReaderWriterIVE.cpp @@ -4,6 +4,7 @@ #include #include +#include #include using namespace osg; @@ -19,10 +20,13 @@ class IVEReaderWriter : public ReaderWriter return equalCaseInsensitive(extension,"ive"); } - virtual ReadResult readNode(const std::string& fileName, const Options* options) + virtual ReadResult readNode(const std::string& file, const Options* options) { - std::string ext = getFileExtension(fileName); + std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; std::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); return readNode(istream,options); diff --git a/src/osgPlugins/jp2/ReaderWriterJP2.cpp b/src/osgPlugins/jp2/ReaderWriterJP2.cpp index 2b7b26f3b..7df3a7be5 100644 --- a/src/osgPlugins/jp2/ReaderWriterJP2.cpp +++ b/src/osgPlugins/jp2/ReaderWriterJP2.cpp @@ -178,13 +178,16 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter osgDB::equalCaseInsensitive(extension,"jpc"); } - virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) { - std::string ext = osgDB::getFileExtension(fileName); + std::string ext = osgDB::getFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - if(!osgDB::fileExists(fileName)) + std::string fileName = osgDB::findDataFile( file ); + if(fileName.empty()) { + // note from Robert, Dec03, I find returning a valid image when no + // file exists a bit odd... osg::Image *img = new osg::Image; img->setFileName(fileName); return img; diff --git a/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp b/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp index 2be04291e..db0a2ec75 100644 --- a/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp +++ b/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp @@ -5,6 +5,7 @@ #include #include +#include /**************************************************************************** * @@ -279,11 +280,14 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"jpeg") || osgDB::equalCaseInsensitive(extension,"jpg"); } - virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options*) { - std::string ext = osgDB::getFileExtension(fileName); + std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + unsigned char *imageData = NULL; int width_ret; int height_ret; diff --git a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp index 2b81c649a..b0a7ad4e6 100644 --- a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp +++ b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp @@ -86,7 +86,7 @@ class ReaderWriter3DS : public osgDB::ReaderWriter virtual const char* className() { return "3DS Auto Studio Reader"; } virtual bool acceptsExtension(const std::string& extension) { return osgDB::equalCaseInsensitive(extension,"3ds"); } - virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*); + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options*); typedef std::vector FaceList; typedef std::map GeoStateMap; @@ -394,9 +394,15 @@ osg::Node* ReaderWriter3DS::processNode(StateSetMap drawStateMap,Lib3dsFile *f,L } -osgDB::ReaderWriter::ReadResult ReaderWriter3DS::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) +osgDB::ReaderWriter::ReadResult ReaderWriter3DS::readNode(const std::string& file, const osgDB::ReaderWriter::Options*) { + std::string ext = osgDB::getLowerCaseFileExtension(file); + if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + Lib3dsFile *f = lib3ds_file_load(fileName.c_str()); if (f==NULL) return ReadResult::FILE_NOT_HANDLED; diff --git a/src/osgPlugins/logo/ReaderWriterLOGO.cpp b/src/osgPlugins/logo/ReaderWriterLOGO.cpp index a20fdc522..dfad3db34 100644 --- a/src/osgPlugins/logo/ReaderWriterLOGO.cpp +++ b/src/osgPlugins/logo/ReaderWriterLOGO.cpp @@ -191,10 +191,14 @@ public: return osgDB::equalCaseInsensitive(extension,"logo"); } - virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options*) { - std::string ext = osgDB::getLowerCaseFileExtension(fileName); + std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + osg::notify(osg::INFO)<< "ReaderWriterLOGO::readNode( "< #include #include +#include #include #include @@ -46,8 +47,14 @@ public: return osgDB::equalCaseInsensitive(extension,"lwo") || osgDB::equalCaseInsensitive(extension,"lw") || osgDB::equalCaseInsensitive(extension,"geo"); } - virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) { + std::string ext = osgDB::getLowerCaseFileExtension(file); + if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + ReadResult result = readNode_LWO1(fileName,options); if (result.success()) return result; diff --git a/src/osgPlugins/md2/ReaderWriterMD2.cpp b/src/osgPlugins/md2/ReaderWriterMD2.cpp index 0b55455d1..d6c2029c4 100644 --- a/src/osgPlugins/md2/ReaderWriterMD2.cpp +++ b/src/osgPlugins/md2/ReaderWriterMD2.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -59,9 +60,15 @@ public: osgDB::RegisterReaderWriterProxy g_readerWriter_MD2_Proxy; osgDB::ReaderWriter::ReadResult -ReaderWriterMD2::readNode (const std::string& filename, +ReaderWriterMD2::readNode (const std::string& file, const osgDB::ReaderWriter::Options*) { + std::string ext = osgDB::getLowerCaseFileExtension(file); + if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + + std::string filename = osgDB::findDataFile( file ); + if (filename.empty()) return ReadResult::FILE_NOT_FOUND; + return load_md2 (filename.data()); } diff --git a/src/osgPlugins/obj/ReaderWriterOBJ.cpp b/src/osgPlugins/obj/ReaderWriterOBJ.cpp index da068c728..d5bcc4a15 100644 --- a/src/osgPlugins/obj/ReaderWriterOBJ.cpp +++ b/src/osgPlugins/obj/ReaderWriterOBJ.cpp @@ -152,11 +152,13 @@ osgDB::RegisterReaderWriterProxy g_objReaderWriterProxy; // read file and convert to OSG. -osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) +osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& file, const osgDB::ReaderWriter::Options*) { - std::string ext = osgDB::getFileExtension(fileName); + std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; GLMmodel* obj = glmReadOBJ((char*) fileName.c_str()); if (!obj) diff --git a/src/osgPlugins/osg/ReaderWriterOSG.cpp b/src/osgPlugins/osg/ReaderWriterOSG.cpp index cb1ecb5dc..aa7a9c2db 100644 --- a/src/osgPlugins/osg/ReaderWriterOSG.cpp +++ b/src/osgPlugins/osg/ReaderWriterOSG.cpp @@ -1,10 +1,11 @@ -#include "osg/Image" -#include "osg/Group" +#include +#include -#include "osgDB/FileNameUtils" -#include "osgDB/Registry" -#include "osgDB/Input" -#include "osgDB/Output" +#include +#include +#include +#include +#include using namespace osg; using namespace osgDB; @@ -21,11 +22,14 @@ class OSGReaderWriter : public ReaderWriter virtual ReadResult readObject(const std::string& fileName, const Options* opt) { return readNode(fileName,opt); } - virtual ReadResult readNode(const std::string& fileName, const Options* opt) + virtual ReadResult readNode(const std::string& file, const Options* opt) { - std::string ext = getFileExtension(fileName); + std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + std::ifstream fin(fileName.c_str()); if (fin) { diff --git a/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp b/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp index 6ad4dee17..05b0b1461 100644 --- a/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp +++ b/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp @@ -30,11 +30,14 @@ class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"osgtgz"); } - virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options*) { - std::string ext = osgDB::getFileExtension(fileName); + std::string ext = osgDB::getFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + osg::notify(osg::INFO)<<"sgReaderWriterOSGTGZ::readNode( "< #include +#include /**************************************************************************** * @@ -193,8 +194,13 @@ class ReaderWriterPIC : public osgDB::ReaderWriter virtual const char* className() { return "PIC Image Reader"; } virtual bool acceptsExtension(const std::string& extension) { return osgDB::equalCaseInsensitive(extension,"pic"); } - virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options*) { + std::string ext = osgDB::getLowerCaseFileExtension(file); + if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; unsigned char *imageData = NULL; int width_ret; diff --git a/src/osgPlugins/png/ReaderWriterPNG.cpp b/src/osgPlugins/png/ReaderWriterPNG.cpp index af6cd5488..c35d61e18 100644 --- a/src/osgPlugins/png/ReaderWriterPNG.cpp +++ b/src/osgPlugins/png/ReaderWriterPNG.cpp @@ -5,6 +5,7 @@ #include #include +#include #include using namespace osg; @@ -35,11 +36,13 @@ class ReaderWriterPNG : public osgDB::ReaderWriter virtual const char* className() { return "PNG Image Reader/Writer"; } virtual bool acceptsExtension(const std::string& extension) { return osgDB::equalCaseInsensitive(extension,"png"); } - virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options*) { + std::string ext = osgDB::getLowerCaseFileExtension(file); + if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - if( !acceptsExtension(osgDB::getFileExtension(fileName) )) - return ReadResult::FILE_NOT_HANDLED; + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; int trans = PNG_ALPHA; FILE *fp = NULL; diff --git a/src/osgPlugins/pnm/ReaderWriterPNM.cpp b/src/osgPlugins/pnm/ReaderWriterPNM.cpp index a23c90e10..4e78fb323 100644 --- a/src/osgPlugins/pnm/ReaderWriterPNM.cpp +++ b/src/osgPlugins/pnm/ReaderWriterPNM.cpp @@ -6,6 +6,7 @@ #include #include +#include #include @@ -24,10 +25,13 @@ class ReaderWriterPNM : public osgDB::ReaderWriter osgDB::equalCaseInsensitive(extension, "pbm"); } - virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options*) { - if( !acceptsExtension(osgDB::getFileExtension(fileName) )) - return ReadResult::FILE_NOT_HANDLED; + std::string ext = osgDB::getLowerCaseFileExtension(file); + if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; FILE *fp = NULL; char line[300]; diff --git a/src/osgPlugins/quicktime/ReaderWriterQT.cpp b/src/osgPlugins/quicktime/ReaderWriterQT.cpp index cd6a0f16c..ec6a99afc 100644 --- a/src/osgPlugins/quicktime/ReaderWriterQT.cpp +++ b/src/osgPlugins/quicktime/ReaderWriterQT.cpp @@ -28,7 +28,7 @@ class ReaderWriterQT : public osgDB::ReaderWriter virtual bool acceptsExtension(const std::string& extension) { // this should be the only image importer required on the Mac - // dont know what else it supports, but these will do + // dont know what else it supports, but these will do return osgDB::equalCaseInsensitive(extension,"rgb") || osgDB::equalCaseInsensitive(extension,"rgba") || osgDB::equalCaseInsensitive(extension,"jpg") || @@ -43,110 +43,113 @@ class ReaderWriterQT : public osgDB::ReaderWriter } virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) - { - std::string ext = osgDB::getFileExtension(fileName); + { + std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - - long origWidth, origHeight,buffWidth,buffHeight,buffDepth,origDepth; - - // NOTE - implememntation means that this will always return 32 bits, so it is hard to work out if - // an image was monochrome. So it will waste texture memory unless it gets a monochrome hint. - - unsigned char *pixels = LoadBufferFromDarwinPath ( fileName.c_str(), &origWidth,&origHeight,&origDepth, - &buffWidth,&buffHeight, - &buffDepth); - - // IMPORTANT - - // origDepth in BYTES, buffDepth in BITS - - if (pixels == 0) { - std::cerr << "LoadBufferFromDarwinPath failed " << fileName.c_str() << QTfailureMessage() << std::endl; - return 0; - } + + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + + long origWidth, origHeight,buffWidth,buffHeight,buffDepth,origDepth; + + // NOTE - implememntation means that this will always return 32 bits, so it is hard to work out if + // an image was monochrome. So it will waste texture memory unless it gets a monochrome hint. - unsigned int pixelFormat; - - switch(origDepth) { - case 1 : - pixelFormat = GL_RGB; - break; - case 2 : - pixelFormat = GL_LUMINANCE_ALPHA; - break; - case 3 : - pixelFormat = GL_RGB; - break; - case 4 : - pixelFormat = GL_RGBA; - break; - default : - std::cerr << "Unknown file type in " << fileName.c_str() << " with " << origDepth << std::endl; - pixelFormat = (GLenum)-1; - return 0; - break; - } - - { - unsigned char *srcp=pixels, *dstp=pixels; + unsigned char *pixels = LoadBufferFromDarwinPath ( fileName.c_str(), &origWidth,&origHeight,&origDepth, + &buffWidth,&buffHeight, + &buffDepth); + + // IMPORTANT - + // origDepth in BYTES, buffDepth in BITS + + if (pixels == 0) { + std::cerr << "LoadBufferFromDarwinPath failed " << fileName.c_str() << QTfailureMessage() << std::endl; + return 0; + } + + unsigned int pixelFormat; + + switch(origDepth) { + case 1 : + pixelFormat = GL_RGB; + break; + case 2 : + pixelFormat = GL_LUMINANCE_ALPHA; + break; + case 3 : + pixelFormat = GL_RGB; + break; + case 4 : + pixelFormat = GL_RGBA; + break; + default : + std::cerr << "Unknown file type in " << fileName.c_str() << " with " << origDepth << std::endl; + pixelFormat = (GLenum)-1; + return 0; + break; + } + + { + unsigned char *srcp=pixels, *dstp=pixels; - int i, j; + int i, j; - // swizzle entire image in-place - for (i=0; isetFileName(fileName.c_str()); @@ -155,8 +158,8 @@ class ReaderWriterQT : public osgDB::ReaderWriter pixelFormat, GL_UNSIGNED_BYTE, pixels, - osg::Image::USE_NEW_DELETE ); - + osg::Image::USE_NEW_DELETE ); + notify(INFO) << "image read ok "< +#include #include -#include "osg/GL" +#include -#include "osgDB/FileNameUtils" -#include "osgDB/Registry" +#include +#include +#include #include #include @@ -354,10 +355,13 @@ class ReaderWriterRGB : public osgDB::ReaderWriter osgDB::equalCaseInsensitive(extension,"bw"); } - virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options*) { - std::string ext = osgDB::getFileExtension(fileName); + std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; rawImageRec *raw; diff --git a/src/osgPlugins/tga/ReaderWriterTGA.cpp b/src/osgPlugins/tga/ReaderWriterTGA.cpp index 6a1da70ad..9820e1e4e 100644 --- a/src/osgPlugins/tga/ReaderWriterTGA.cpp +++ b/src/osgPlugins/tga/ReaderWriterTGA.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -477,8 +478,13 @@ class ReaderWriterTGA : public osgDB::ReaderWriter virtual const char* className() { return "TGA Image Reader"; } virtual bool acceptsExtension(const std::string& extension) { return osgDB::equalCaseInsensitive(extension,"tga"); } - virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options*) { + std::string ext = osgDB::getLowerCaseFileExtension(file); + if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; unsigned char *imageData = NULL; int width_ret; diff --git a/src/osgPlugins/tgz/ReaderWriterTGZ.cpp b/src/osgPlugins/tgz/ReaderWriterTGZ.cpp index fbdf2d69a..73cbc5496 100644 --- a/src/osgPlugins/tgz/ReaderWriterTGZ.cpp +++ b/src/osgPlugins/tgz/ReaderWriterTGZ.cpp @@ -31,11 +31,14 @@ class ReaderWriterTGZ : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"tgz"); } - virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options*) { - std::string ext = osgDB::getLowerCaseFileExtension(fileName); + std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + osg::notify(osg::INFO)<< "ReaderWriterTGZ::readNode( "< #include +#include #include #include @@ -411,8 +412,14 @@ class ReaderWriterTIFF : public osgDB::ReaderWriter return false; } - virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options*) { + std::string ext = osgDB::getLowerCaseFileExtension(file); + if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + unsigned char *imageData = NULL; int width_ret; int height_ret; diff --git a/src/osgPlugins/txp/ReaderWriterTXP.cpp b/src/osgPlugins/txp/ReaderWriterTXP.cpp index 603d8717e..f10c16e1b 100644 --- a/src/osgPlugins/txp/ReaderWriterTXP.cpp +++ b/src/osgPlugins/txp/ReaderWriterTXP.cpp @@ -21,7 +21,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterTXP::readNode(const std::string& fil if( !acceptsExtension(osgDB::getFileExtension(fileName) )) return ReadResult::FILE_NOT_HANDLED; - osg::ref_ptr pager = new TerrapageNode; + osg::ref_ptr pager = new TerrapageNode; pager->setDatabaseName(fileName); diff --git a/src/osgPlugins/zip/ReaderWriterZIP.cpp b/src/osgPlugins/zip/ReaderWriterZIP.cpp index 24a6697b8..3a74a9fe2 100644 --- a/src/osgPlugins/zip/ReaderWriterZIP.cpp +++ b/src/osgPlugins/zip/ReaderWriterZIP.cpp @@ -29,12 +29,15 @@ class ReaderWriterZIP : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"zip"); } - virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options*) { - std::string ext = osgDB::getLowerCaseFileExtension(fileName); + std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + std::string fileName = osgDB::findDataFile( file ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + osg::notify(osg::INFO)<<"ReaderWriterZIP::readNode( "<getNumElements()<3) return; + + + // check to see if vertex attributes indices exists, if so expand them to remove them if (geom.suitableForOptimization()) { // removing coord indices @@ -553,9 +531,10 @@ void TriStripVisitor::stripify(Geometry& geom) } + + // check for the existance of surface primitives unsigned int numSurfacePrimitives = 0; unsigned int numNonSurfacePrimitives = 0; - Geometry::PrimitiveSetList& primitives = geom.getPrimitiveSetList(); Geometry::PrimitiveSetList::iterator itr; for(itr=primitives.begin(); @@ -579,6 +558,7 @@ void TriStripVisitor::stripify(Geometry& geom) } } + // nothitng to tri strip leave. if (!numSurfacePrimitives) return; // compute duplicate vertices @@ -673,17 +653,8 @@ void TriStripVisitor::stripify(Geometry& geom) } } - for(i=0;i=minimum_ratio_of_indices_to_unique_vertices) { - int in_numVertices = -1; + std::cout<<" doing tri strip"<< std::endl; + + unsigned int in_numVertices = 0; for(triangle_stripper::tri_stripper::indices::iterator itr=taf._in_indices.begin(); itr!=taf._in_indices.end(); ++itr) { - if ((int)*itr>in_numVertices) in_numVertices=*itr; + if (*itr>in_numVertices) in_numVertices=*itr; } // the largest indice is in_numVertices, but indices start at 0 // so increment to give to the corrent number of verticies. - ++in_numVertices; + ++in_numVertices; + + // remap any shared vertex attributes + RemapArray ra(copyMapping); + arrayComparitor.accept(ra); triangle_stripper::tri_stripper stripifier(taf._in_indices); stripifier.SetCacheSize(_cacheSize); @@ -760,20 +744,28 @@ void TriStripVisitor::stripify(Geometry& geom) } geom.setPrimitiveSetList(new_primitives); -#if 0 -// debugging code for indentifying the tri-strips. - osg::Vec4Array* colors = new osg::Vec4Array(new_primitives.size()); - for(i=0;isize();++i) - { - (*colors)[i].set(((float)rand()/(float)RAND_MAX), - ((float)rand()/(float)RAND_MAX), - ((float)rand()/(float)RAND_MAX), - 1.0f); - } - geom.setColorArray(colors); - geom.setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET); -#endif + #if 0 + // debugging code for indentifying the tri-strips. + osg::Vec4Array* colors = new osg::Vec4Array(new_primitives.size()); + for(i=0;isize();++i) + { + (*colors)[i].set(((float)rand()/(float)RAND_MAX), + ((float)rand()/(float)RAND_MAX), + ((float)rand()/(float)RAND_MAX), + 1.0f); + } + geom.setColorArray(colors); + geom.setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET); + #endif + + geom.setPrimitiveSetList(new_primitives); + } + else + { + std::cout<<" not doing tri strip *****************"<< std::endl; + } + } void TriStripVisitor::stripify()