//--- // // License: MIT // // See LICENSE.txt file in the top level directory for more details. // //--- // $Id$ #include #include #include #include #include #include #include #include #include #include #include #include #include #include // #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if OSSIM_HAS_HDF5 #include #endif static const ossimTrace traceDebug("ossimImageHandlerFactory:debug"); RTTI_DEF1(ossimImageHandlerFactory, "ossimImageHandlerFactory", ossimImageHandlerFactoryBase); ossimImageHandlerFactory* ossimImageHandlerFactory::theInstance = 0; ossimImageHandlerFactory::~ossimImageHandlerFactory() { theInstance = (ossimImageHandlerFactory*)0; } ossimImageHandlerFactory* ossimImageHandlerFactory::instance() { if(!theInstance) { theInstance = new ossimImageHandlerFactory; // let's turn off tiff error reporting TIFFSetErrorHandler(0); TIFFSetWarningHandler(0); } return theInstance; } ossimRefPtr ossimImageHandlerFactory::open( std::shared_ptr& str, const std::string& connectionString, bool openOverview ) const { ossimRefPtr result(0); // NITF: ossimRefPtr ih = new ossimNitfTileSource(); ih->setOpenOverviewFlag(openOverview); if ( ih->open( str, connectionString ) ) { result = ih.get(); } if( !result ) { // Reset the stream for downstream code. str->seekg(0, std::ios_base::beg); str->clear(); // TIFF: ossimRefPtr ihTiff = new ossimTiffTileSource(); ihTiff->setOpenOverviewFlag(openOverview); if ( ihTiff->open( str, connectionString ) ) { result = ihTiff.get(); } if(!result) { // Reset the stream for downstream code. str->seekg(0, std::ios_base::beg); str->clear(); // ossim dot.src file: result = openSrcRecord( str, connectionString, openOverview ); if ( !result ) { // Reset the stream for downstream code. str->seekg(0, std::ios_base::beg); str->clear(); } } } return result; } ossimImageHandler* ossimImageHandlerFactory::open(const ossimFilename& fileName, bool openOverview) const { static const char* M = "ossimImageHandlerFactory::open(filename) -- "; if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << M <<" Entering..." << std::endl; ossimFilename copyFilename = fileName; if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "Attempting to open file: " << fileName.c_str() << "\nopen overview flag: " << (openOverview?"true":"false") << "\n"; } ossimRefPtr result = 0; while (true) { // Check for empty file. copyFilename.trim(); if (copyFilename.empty()) break; // for all of our imagehandlers the filename must exist. // if we have any imagehandlers that require an encoded string and is contrlled in this factory then // we need to move this. if (!copyFilename.exists()) break; ossimString ext = copyFilename.ext().downcase(); if(ext == "gz") copyFilename = copyFilename.setExtension(""); // Try opening from extension logic first (this is faster than instantiating each type). // if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); //if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; // this must be checked first before the TIFF handler if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; //--- // The srtm and general raser readers were picking up j2k overviews because the // matching base file has an "omd" file that the raster reader can load // so added extension check. (drb - 20100709) //--- if (copyFilename.ext() != "ovr") { // Note: ENVI should be in front of general raster.. if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; // Note: SRTM should be in front of general raster.. if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; } if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); result = new ossimLasReader(); if (result->open(copyFilename)) break; #if OSSIM_HAS_HDF5 if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<setOpenOverviewFlag(openOverview); if (result->open(copyFilename)) break; #endif result = 0; break; } if (traceDebug()) { if (result.valid()) ossimNotify(ossimNotifyLevel_DEBUG)< result = 0; while (true) { if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << M<< "trying adrg...\n"; result = new ossimAdrgTileSource(); if (result->loadState(kwl, prefix)) break; if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << M<< "trying ccf...\n"; result = new ossimCcfTileSource(); if (result->loadState(kwl, prefix)) break; if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << M << "trying CIB/CADRG...\n"; result = new ossimCibCadrgTileSource(); if (result->loadState(kwl, prefix)) break; if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<loadState(kwl, prefix)) break; if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<loadState(kwl, prefix)) break; if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << M << "trying DOQQ...\n"; result = new ossimDoqqTileSource(); if (result->loadState(kwl, prefix)) break; if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << M<< "trying DTED...\n"; result = new ossimDtedTileSource(); if (result->loadState(kwl, prefix)) break; if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << M<< "trying jpeg...\n"; result = new ossimJpegTileSource(); if (result->loadState(kwl, prefix)) break; //if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << M<< "trying Quickbird NITF...\n"; //result = new ossimQuickbirdNitfTileSource; //if (result->loadState(kwl, prefix)) break; if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << M << "trying Nitf...\n"; result = new ossimNitfTileSource(); if (result->loadState(kwl, prefix)) break; // Must be before tiff... if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << M<< "trying Quickbird TIFF...\n"; result = new ossimQuickbirdTiffTileSource; if (result->loadState(kwl, prefix)) break; if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << M<< "trying tiff...\n"; result = new ossimTiffTileSource(); if (result->loadState(kwl, prefix)) break; if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << M<< "trying USGS Dem...\n"; result = new ossimUsgsDemTileSource(); if (result->loadState(kwl, prefix)) break; if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << M<< "trying Landsat...\n"; result = new ossimLandsatTileSource(); if (result->loadState(kwl, prefix)) break; if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << M<< "trying VPF...\n"; result = new ossimVpfTileSource; if (result->loadState(kwl, prefix)) break; if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << M<< "trying ERS...\n"; result = new ossimERSTileSource; if (result->loadState(kwl, prefix)) break; // Note: ENVI should be in front of general raster... if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << M<< "trying ENVI...\n"<< std::endl; result = new ossimEnviTileSource(); if (result->loadState(kwl, prefix)) break; // Note: SRTM should be in front of general raster... if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << M<< "trying SRTM...\n"<< std::endl; result = new ossimSrtmTileSource(); if (result->loadState(kwl, prefix)) break; if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << M << "trying General Raster...\n"<< std::endl; result = new ossimGeneralRasterTileSource(); if (result->loadState(kwl, prefix)) break; if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<loadState(kwl, prefix)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<loadState(kwl, prefix)) break; if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<loadState(kwl, prefix)) break; #if OSSIM_HAS_HDF5 if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<loadState(kwl, prefix)) break; #endif #ifdef ENABLE_POINT_CLOUD_HANDLER if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<loadState(kwl, prefix)) break; #endif result = 0; break; } if (traceDebug()) { if (result.valid()) ossimNotify(ossimNotifyLevel_DEBUG)< ossimImageHandlerFactory::open(std::shared_ptr state)const { ossimRefPtr result = 0; if(state) { ossimRefPtr obj = createObject(state->getImageHandlerType()); if(obj) { result = dynamic_cast(obj.get()); if(result) { if(!result->open(state)) { result = 0; } } obj = 0; } } return result; } ossimRefPtr ossimImageHandlerFactory::openOverview( const ossimFilename& file ) const { ossimRefPtr result = 0; if ( file.size() ) { result = new ossimTiffTileSource; result->setOpenOverviewFlag( false ); // Always false. if ( result->open( file ) == false ) { result = 0; } } return result; } #if 0 ossimImageHandler* ossimImageHandlerFactory::openFromExtension(const ossimFilename& fileName) const { static const char* M = "ossimImageHandlerFactory::openFromExtension() -- "; if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<"< result = 0; while (true) { // OVR can be combined with "tif" once we get rid of ossimQuickbirdTiffTileSource if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<open(fileName)) break; } if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<open(fileName)) break; result = new ossimTiffTileSource; if(result->open(fileName)) break; } if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<open(fileName)) break; result = new ossimNitfTileSource; if(result->open(fileName)) break; } if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<open(fileName)) break; result = new ossimImagefCacheTileSource; if(result->open(fileName)) break; } if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<open(fileName)) break; } if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<open(fileName)) break; } if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<open(fileName)) break; } if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<open(fileName)) break; } if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<open(fileName)) break; } if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<open(fileName)) break; } if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<open(fileName)) break; } if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<open(fileName)) break; } if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<open(fileName)) break; } if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<open(fileName)) break; } if(traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG)<open(fileName)) break; } result = 0; break; } if (traceDebug()) { if (result.valid()) ossimNotify(ossimNotifyLevel_DEBUG)<open(kwl, prefix);//ossimFilename(lookup)); } } else { result = createObject(ossimString(type)); if(result) { result->loadState(kwl, prefix); } } } if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimImageHandlerFactory::createObject(kwl, prefix) DEBUG: returning result ..." << std::endl; } return result; } void ossimImageHandlerFactory::getTypeNameList(std::vector& typeList)const { typeList.push_back(STATIC_TYPE_NAME(ossimAdrgTileSource)); typeList.push_back(STATIC_TYPE_NAME(ossimCcfTileSource)); typeList.push_back(STATIC_TYPE_NAME(ossimCibCadrgTileSource)); typeList.push_back(STATIC_TYPE_NAME(ossimEnviTileSource)); typeList.push_back(STATIC_TYPE_NAME(ossimRpfCacheTileSource)); typeList.push_back(STATIC_TYPE_NAME(ossimImageCacheTileSource)); typeList.push_back(STATIC_TYPE_NAME(ossimDoqqTileSource)); typeList.push_back(STATIC_TYPE_NAME(ossimDtedTileSource)); typeList.push_back(STATIC_TYPE_NAME(ossimJpegTileSource)); typeList.push_back(STATIC_TYPE_NAME(ossimNitfTileSource)); typeList.push_back(STATIC_TYPE_NAME(ossimTiffTileSource)); typeList.push_back(STATIC_TYPE_NAME(ossimUsgsDemTileSource)); typeList.push_back(STATIC_TYPE_NAME(ossimLandsatTileSource)); typeList.push_back(STATIC_TYPE_NAME(ossimERSTileSource)); typeList.push_back(STATIC_TYPE_NAME(ossimSrtmTileSource)); typeList.push_back(STATIC_TYPE_NAME(ossimGeneralRasterTileSource)); typeList.push_back(STATIC_TYPE_NAME(ossimQuickbirdNitfTileSource)); typeList.push_back(STATIC_TYPE_NAME(ossimQuickbirdTiffTileSource)); typeList.push_back(STATIC_TYPE_NAME(ossimQbTileFilesHandler)); typeList.push_back(STATIC_TYPE_NAME(ossimBitMaskTileSource)); typeList.push_back(STATIC_TYPE_NAME(ossimRangeDomeTileSource)); #if OSSIM_HAS_HDF5 typeList.push_back(STATIC_TYPE_NAME(ossimViirsHandler)); #endif #ifdef ENABLE_POINT_CLOUD_HANDLER typeList.push_back(STATIC_TYPE_NAME(ossimPointCloudImageHandler)); #endif typeList.push_back(STATIC_TYPE_NAME(ossimImageHandlerMtAdaptor)); } ossimRefPtr ossimImageHandlerFactory::openSrcRecord( std::shared_ptr& str, const std::string& connectionString, bool openOverview ) const { ossimRefPtr result = 0; if(!str) return result; // Check the extension for ".src" before going any further: std::size_t found = connectionString.find( std::string(".src") ); if ( found != std::string::npos && ( found == (connectionString.size() - 4) ) ) { ossimKeywordlist kwl; if ( kwl.parseStream( *str ) ) { // Right now only concidering one image, i.e. "image0": std::string prefix = "image0."; ossimSrcRecord src; if ( src.loadState(kwl, prefix.c_str() ) ) { if ( src.getFilename().string().size() ) { // Avoid recursive loop: if (src.getFilename().string() != connectionString ) { result = ossimImageHandlerRegistry::instance()-> openConnection( src.getFilename(), false ); if ( result.valid() ) { ossimFilename supportDir = src.getSupportDir(); if ( supportDir.empty() ) { if ( src.getOverviewPath().size() ) { if ( src.getOverviewPath().isDir() ) { supportDir = src.getOverviewPath(); } else { supportDir = src.getOverviewPath().path(); } } else if ( src.getHistogramPath().size() ) { if ( src.getHistogramPath().isDir() ) { supportDir = src.getHistogramPath(); } else { supportDir = src.getHistogramPath().path(); } } } if ( supportDir.size() && (src.getFilename().path() != supportDir) ) { result->setSupplementaryDirectory( supportDir ); } if ( src.getEntryIndex() > 0 ) // defaulted to -1. { result->setCurrentEntry( static_cast( src.getEntryIndex() ) ); } if ( openOverview && ( result->getOverview() == 0 ) ) { if ( src.getOverviewPath().size() ) { result->openOverview( src.getOverviewPath() ); } else { ossimFilename ovrFile = result-> getFilenameWithThisExtension(ossimString(".ovr")); result->openOverview( ovrFile ); } } } } } } } // Matches: if ( kwl.parseStream( str ) ) if ( !result ) { // Reset the stream for downstream code. str->seekg(0, std::ios_base::beg); str->clear(); } } return result; }