From 13064caaeacd9a21c7474c062989c68324e8f433 Mon Sep 17 00:00:00 2001 From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org> Date: Thu, 16 Sep 2010 14:49:05 +0800 Subject: [PATCH] ENH: remove unused class --- Code/IO/CMakeLists.txt | 10 - Code/IO/otbTileMapFetcher.cxx | 573 ---------------------- Code/IO/otbTileMapFetcher.h | 140 ------ Testing/Code/IO/CMakeLists.txt | 16 - Testing/Code/IO/otbIOTests19.cxx | 2 - Testing/Code/IO/otbTileMapFetcherNew.cxx | 30 -- Testing/Code/IO/otbTileMapFetcherTest.cxx | 87 ---- 7 files changed, 858 deletions(-) delete mode 100644 Code/IO/otbTileMapFetcher.cxx delete mode 100644 Code/IO/otbTileMapFetcher.h delete mode 100644 Testing/Code/IO/otbTileMapFetcherNew.cxx delete mode 100644 Testing/Code/IO/otbTileMapFetcherTest.cxx diff --git a/Code/IO/CMakeLists.txt b/Code/IO/CMakeLists.txt index ca46f11944..c678c371d3 100644 --- a/Code/IO/CMakeLists.txt +++ b/Code/IO/CMakeLists.txt @@ -11,11 +11,6 @@ IF(NOT OTB_COMPILE_JPEG2000) ADD_DEFINITIONS(-DOTB_JPEG2000_DISABLED) ENDIF(NOT OTB_COMPILE_JPEG2000) -IF( NOT OTB_USE_CURL ) - LIST(REMOVE_ITEM OTBIO_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/otbTileMapFetcher.cxx" ) -ENDIF( NOT OTB_USE_CURL ) - - # otbopenjpeg IF(OTB_COMPILE_JPEG2000) IF(WIN32) @@ -69,11 +64,6 @@ IF(NOT OTB_INSTALL_NO_DEVELOPMENT) FILE(GLOB __files1 "${CMAKE_CURRENT_SOURCE_DIR}/*.h") FILE(GLOB __files2 "${CMAKE_CURRENT_SOURCE_DIR}/*.txx") - IF( NOT OTB_USE_CURL ) - LIST(REMOVE_ITEM __files1 "${CMAKE_CURRENT_SOURCE_DIR}/otbTileMapFetcher.h" ) - ENDIF( NOT OTB_USE_CURL ) - - IF(NOT OTB_COMPILE_JPEG2000) LIST(REMOVE_ITEM __files1 "${CMAKE_CURRENT_SOURCE_DIR}/otbJpeg2000ImageIOFactory.h" ) LIST(REMOVE_ITEM __files1 "${CMAKE_CURRENT_SOURCE_DIR}/otbJpeg2000ImageIO.h" ) diff --git a/Code/IO/otbTileMapFetcher.cxx b/Code/IO/otbTileMapFetcher.cxx deleted file mode 100644 index e1cae3bd8d..0000000000 --- a/Code/IO/otbTileMapFetcher.cxx +++ /dev/null @@ -1,573 +0,0 @@ -/*========================================================================= - - Program: ORFEO Toolbox - Language: C++ - Date: $Date$ - Version: $Revision$ - - - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. - See OTBCopyright.txt for details. - - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - - =========================================================================*/ - -#include "otbTileMapFetcher.h" -#include "itkImageFileReader.h" - -namespace otb -{ -/** Constructor */ -TileMapFetcher::TileMapFetcher() -{ - // Set server name - m_ServerName = ""; - - // Set Extension - m_FileSuffix = ".png"; - - // Set Cache size - m_CacheSize = 100; - - // Set cache directory - m_CacheDirectory = ""; - - // Set coordinates - m_X = 0; - m_Y = 0; - m_Z = 1; - - // Generate Logo tile - this->GenerateLogoTile(); -} - -/** Destructor */ -TileMapFetcher::~TileMapFetcher() -{ - // Remove all tiles in cache directory - this->UnregisterAllCachedTiles(); -} - -/** FetchTile */ -TileMapFetcher::ImagePointerType TileMapFetcher::FetchTile(unsigned int x, unsigned int y, unsigned int z) -{ - bool isInCache = false; - bool fetchingIsOK = true; - - /* Set coordinates */ - m_X = x; - m_Y = y; - m_Z = z; - - /* Create filename */ - this->GenerateFileName(); - - /* Check if tile is in cache */ - isInCache = this->IsTileInCache(); - - /* Fetch tile from web (check if local tile is out to date) */ - if (!isInCache) - { - // If fetching is ok - if (this->FetchTileFromServer()) - { - fetchingIsOK = true; - // Register tile in cache - this->RegisterTileInCache(); - } - else - { - // Else get tile from cache - fetchingIsOK = false; - } - - } - - /* fetch tile from cache */ - return (this->ReadTileFromCache(fetchingIsOK)); -} - -/** Fetch Tile from Server and set it in cache */ -bool TileMapFetcher::FetchTileFromServer() -{ - bool result = false; - - // Path and filename for this tile - std::ostringstream pathAndFileName; - - pathAndFileName << m_CacheDirectory; - - if (m_CacheDirectory.at(m_CacheDirectory.size() - 1) != '/') pathAndFileName << "/"; - - pathAndFileName << m_FileName; - - // Open file - FILE* output_file = fopen(pathAndFileName.str().c_str(), "w"); - if (output_file == NULL) - { - itkExceptionMacro(<< "FetchTileFromServer : bad file name."); - return result; - } - - // Browser type - std::ostringstream browserStream; - browserStream << "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11"; - - // Init curl - CURL * curl; - CURLcode res; - curl = curl_easy_init(); - - // Generate URL - this->GenerateOSMurl(); - - if (m_OsmUrl == "") - { - itkExceptionMacro(<< "FetchTileFromServer : bad url."); - return false; - } - - char url[200]; - strcpy(url, m_OsmUrl.data()); - - char browser[200]; - strcpy(browser, browserStream.str().data()); - - //Download the file - if (curl) - { - curl_easy_setopt(curl, CURLOPT_USERAGENT, browser); - curl_easy_setopt(curl, CURLOPT_URL, url); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, output_file); - res = curl_easy_perform(curl); - - // If res != 0 there is a problem while downloading (connection error) - if (res != 0) - { - // Close and remove file in cache - fclose(output_file); - if (remove(pathAndFileName.str().c_str()) != 0) - { - itkDebugMacro(<< "FetchTileFromServer : transfert error - Error while deleting tile in cache!"); - } - itkDebugMacro(<< "FetchTileFromServer : transfert error."); - return false; - } - // Else download was proceed - else - { - // Get error code - int code; - curl_easy_getinfo(curl, CURLINFO_HTTP_CODE, &code); - - // 404 Error (not found) - if (code == 404) - { - // Close and remove file in cache - fclose(output_file); - if (remove(pathAndFileName.str().c_str()) != 0) - { - itkDebugMacro(<< "FetchTileFromServer : HTTP Error 404 - Error while deleting tile in cache!"); - } - itkDebugMacro(<< "FetchTileFromServer : HTTP Error 404"); - return false; - } - // Tile is ok - else - { - result = true; - } - } - } - // close file - fclose(output_file); - // Cleanup curl - curl_easy_cleanup(curl); - return result; -} - -/** Generate Tile FileName */ -void TileMapFetcher::GenerateFileName() -{ - std::string server = m_ServerName.substr(7, m_ServerName.size()); // Get online server name without "http://" - - // replace "/" by "_" in server name - for (unsigned int i = 0; i < server.size(); i++) - { - if (server[i] == '/') server[i] = '_'; - } - - std::ostringstream filename; - - // Generate file name : serverName_Z_X_Y.png - filename << server; - filename << m_Z; - filename << "_"; - filename << m_X; - filename << "_"; - filename << m_Y; - filename << m_FileSuffix; - - m_FileName = filename.str(); -} - -/** Generate OSM url */ -void TileMapFetcher::GenerateOSMurl() -{ - /* Check server name */ - if (m_ServerName[0] != 'h' - || m_ServerName[1] != 't' - || m_ServerName[2] != 't' - || m_ServerName[3] != 'p') - { - itkExceptionMacro(<< "Bad server name!"); - } - - /* Generate urlStream */ - std::ostringstream urlStream; - - urlStream << m_ServerName; - if (m_ServerName.at(m_ServerName.size() - 1) != '/') urlStream << "/"; - urlStream << m_Z; - urlStream << "/"; - urlStream << m_X; - urlStream << "/"; - urlStream << m_Y; - urlStream << m_FileSuffix; - - m_OsmUrl = urlStream.str(); -} - -/** Check if tile is in cache */ -bool TileMapFetcher::IsTileInCache() -{ - bool result = false; - - // First if filename exists - if (m_FileName == "") - { - itkDebugMacro(<< "No filename specified."); - return result; - } - - std::deque<otb::TileRecord>::iterator it; - - // Search tile with its filename - for (it = m_CacheManagement.begin(); it != m_CacheManagement.end(); it++) - { - if (it->GetFileName() == m_FileName) - { - result = true; - break; - } - } - return result; -} - -/** Register Tile in cache */ -bool TileMapFetcher::RegisterTileInCache() -{ - otb::TileRecord tr; - - // Configure Record - tr.SetFileName(m_FileName); - tr.SetDate(); - - if (m_CacheManagement.size() > m_CacheSize) - { - this->UnregisterFirstCachedTile(); - } - - // Add record in deque - m_CacheManagement.push_back(tr); - - return true; -} - -/** Unregister Cached Tile */ -bool TileMapFetcher::UnregisterFirstCachedTile() -{ - std::deque<otb::TileRecord>::iterator it; - - it = m_CacheManagement.begin(); - - // Filename of the first input tile - std::string filename = it->GetFileName(); - - // Generate path and filename - std::ostringstream pathAndFileName; - - pathAndFileName << m_CacheDirectory; - - if (m_CacheDirectory.at(m_CacheDirectory.size() - 1) != '/') pathAndFileName << "/"; - - pathAndFileName << filename; - - // Remove tile in deque - m_CacheManagement.pop_front(); - - // Remove tile file on hard drive - if (remove(pathAndFileName.str().c_str()) != 0) - { - itkDebugMacro(<< "Error when deleting tile in cache!"); - return false; - } - return true; -} - -/** Remove all tiles in cache */ -bool TileMapFetcher::UnregisterAllCachedTiles() -{ - bool result = true; - std::deque<otb::TileRecord>::iterator it; - std::string filename; - - /* Loop on deque to get filename and delete file */ - for (it = m_CacheManagement.begin(); it != m_CacheManagement.end(); it++) - { - filename = it->GetFileName(); - - std::ostringstream pathAndFileName; - - pathAndFileName << m_CacheDirectory; - - if (m_CacheDirectory.at(m_CacheDirectory.size() - 1) != '/') pathAndFileName << "/"; - - pathAndFileName << filename; - - if (remove(pathAndFileName.str().c_str()) != 0) - { - itkDebugMacro(<< "Error when deleting tile in cache!"); - result = false; - } - } - // Clear deque - m_CacheManagement.clear(); - return result; -} - -/** Read tile in cache directory */ -TileMapFetcher::ImagePointerType TileMapFetcher::ReadTileFromCache(bool fetchingIsOK) -{ - // Create an output image - ImagePointerType tempImage; - - // If fetch tile from server is ok - if (fetchingIsOK) - { - // Create a reader - itk::ImageFileReader<ImageType>::Pointer reader = itk::ImageFileReader<ImageType>::New(); - - // Create path and filename - std::ostringstream pathAndFileName; - - pathAndFileName << m_CacheDirectory; - - if (m_CacheDirectory.at(m_CacheDirectory.size() - 1) != '/') pathAndFileName << "/"; - - pathAndFileName << m_FileName; - - // Read file in cache directory - reader->SetFileName(pathAndFileName.str()); - reader->Update(); - - tempImage = reader->GetOutput(); - - } - // Else we return logo tile - else - { - // Read logo tile - tempImage = m_LogoTile; - } - - return (tempImage); -} - -/** Generate logo tile */ -void TileMapFetcher::GenerateLogoTile() -{ - // Create image size - ImageType::SizeType size; - size.Fill(256); - - // Create index start - ImageType::IndexType start; - start.Fill(0); - - // Create region size - ImageType::RegionType region; - region.SetIndex(start); - region.SetSize(size); - - // Create image, set properties, and allocate - m_LogoTile = ImageType::New(); - m_LogoTile->SetRegions(region); - m_LogoTile->SetNumberOfComponentsPerPixel(3); - m_LogoTile->Allocate(); - - // Create pixel - ImageType::PixelType white(3); - - // Fill with white - white.Fill(255); - - // Fill image buffer with white pixel - m_LogoTile->FillBuffer(white); -} - -/** Fetch Tile from Server and set it in cache - Check if tile must be update */ -/** Comment because cache is not persistant */ -/* bool TileMapFetcher::FetchTileFromServer(bool isInCache) - { - bool result = false; - - std::ostringstream pathAndFileName; - - pathAndFileName << m_CacheDirectory; - - if (m_CacheDirectory.at(m_CacheDirectory.size()-1) != '/') - pathAndFileName << "/"; - - pathAndFileName << m_FileName; - - FILE* output_file = fopen(pathAndFileName.str().c_str(),"w"); - if (output_file == NULL) - { - itkExceptionMacro(<<"FetchTileFromServer : bad file name."); - return result; - } - - std::ostringstream browserStream; - browserStream << "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11"; - - CURL *curl; - CURLcode res; - curl = curl_easy_init(); - - this->GenerateOSMurl(); - - std::cout<<std::endl; - std::cout<<"URL: "<<m_OsmUrl<<std::endl; - std::cout<<"FILENAME: "<<pathAndFileName.str()<<std::endl; - std::cout<<"IS IN CACHE: "<<isInCache<<std::endl; - std::cout<<std::endl; - - if (m_OsmUrl == "") - { - itkExceptionMacro(<<"FetchTileFromServer : bad url."); - return false; - } - - char url[200]; - strcpy(url,m_OsmUrl.data()); - - char browser[200]; - strcpy(browser,browserStream.str().data()); - - //Download the file - if (curl) - { - curl_easy_setopt(curl, CURLOPT_USERAGENT, browser); - curl_easy_setopt(curl, CURLOPT_URL, url); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, output_file); - - // If tile is in cache, ask curl to check if tile is out to date - if(isInCache) - { - // Search for time condition - long time_condition; - - std::deque<otb::TileRecord>::iterator it; - std::deque<otb::TileRecord>::iterator it2; - - for(it=m_CacheManagement.begin(); it!=m_CacheManagement.end(); it++) - { - if(it->GetFileName() == m_FileName) - { - it2 = it; - break; - } - } - - time_condition = static_cast<long>(it2->GetDate()); - - std::cout<<time_condition<<std::endl; - - curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE); - curl_easy_setopt(curl, CURLOPT_TIMEVALUE, time_condition); - - res = curl_easy_perform(curl); - - if (res == 0) - { - long response; - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response); - // 304 = Not Modified - if (response == 304) - { - std::cout<<"TUILE NON MODIFIEE"<<std::endl; - result = true; - } - // 200 = Ok - else if (response == 200) - { - double size; - // verify if curl sends us any data - this is a workaround on using CURLOPT_TIMECONDITION - // when the server has a (incorrect) time earlier than the time on the file we already have - curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &size); - if (size == 0) - { - itkExceptionMacro(<<"FetchTileFromServer : transfert error - Size == 0."); - return false; - } - else - { - // Update time in cache - std::cout<<"TUILE MODIFIEE MISE A JOUR DU CACHE"<<std::endl; - it2->SetDate(); - result = true; - } - } - else - { - itkExceptionMacro(<<"FetchTileFromServer : transfert error."); - return false; - } - } - else - { - itkExceptionMacro(<<"FetchTileFromServer : transfert error."); - return false; - } - } - // Not in cache - else - { - res = curl_easy_perform(curl); - if (res != 0) - { - itkExceptionMacro(<<"FetchTileFromServer : transfert error."); - return false; - } - else - { - std::cout<<"RECUPERATION DE LA TUILE"<<std::endl; - result = true; - } - } - - fclose(output_file); - // always cleanup - curl_easy_cleanup(curl); - return result; - } - return false; - } - */ - -} diff --git a/Code/IO/otbTileMapFetcher.h b/Code/IO/otbTileMapFetcher.h deleted file mode 100644 index 612ac1f456..0000000000 --- a/Code/IO/otbTileMapFetcher.h +++ /dev/null @@ -1,140 +0,0 @@ -/*========================================================================= - - Program: ORFEO Toolbox - Language: C++ - Date: $Date$ - Version: $Revision$ - - - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. - See OTBCopyright.txt for details. - - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - - =========================================================================*/ -#ifndef __otbTileMapFetcher_h -#define __otbTileMapFetcher_h - -#if defined(_MSC_VER) -#pragma warning ( disable : 4786 ) -#endif - -#include <deque> -#include <string> - -#include "otbVectorImage.h" -#include "otbTileRecord.h" - -/* Curl Library*/ -#include <curl/curl.h> - -namespace otb -{ -/** \class TileMapFetcher - * \brief Get tiles from servers like Open street map. - * - */ -class ITK_EXPORT TileMapFetcher : public itk::Object -{ -public: - /** Standard typedefs */ - typedef TileMapFetcher Self; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - typedef unsigned char PixelType; - typedef otb::VectorImage<PixelType, 2> ImageType; - typedef ImageType::Pointer ImagePointerType; - - itkNewMacro(Self); - - /** Constructor */ - TileMapFetcher(); - - /** Destructor */ - virtual ~TileMapFetcher(); - - /** Accessors */ - itkSetStringMacro(ServerName); - itkGetStringMacro(ServerName); - - itkSetStringMacro(CacheDirectory); - itkGetStringMacro(CacheDirectory); - - itkSetMacro(CacheSize, unsigned int); - itkGetMacro(CacheSize, unsigned int); - - /** Fetcher */ - ImagePointerType FetchTile(unsigned int x, unsigned int y, unsigned int z); - -protected: - -private: - /** Generate filename */ - void GenerateFileName(); - - /** Generate OSM URL */ - void GenerateOSMurl(); - - /** Check if file is in cache */ - bool IsTileInCache(); - - /** Fetch Tile from Server */ -// bool FetchTileFromServer(bool isInCache); // Comment because cache is not persistant - bool FetchTileFromServer(); - - /** Read Tile From Cache */ - ImagePointerType ReadTileFromCache(bool fetchingIsOk); - - /** Register Tile in cache */ - bool RegisterTileInCache(); - - /** Unregister cached tile */ - bool UnregisterFirstCachedTile(); - - /** Unregister All Cached Tiles */ - bool UnregisterAllCachedTiles(); - - /** Generate Tile with logo */ - void GenerateLogoTile(); - - /** Fill buffer with a logo */ - void LogoToBuffer(PixelType* buffer); - - /** File suffix */ - std::string m_FileSuffix; - - /** Server Name */ - std::string m_ServerName; - - /** Cache directory */ - std::string m_CacheDirectory; - - /** Cache Size */ - unsigned int m_CacheSize; - - /** Coordinates */ - unsigned int m_X; - unsigned int m_Y; - unsigned int m_Z; - - /** FileName */ - std::string m_FileName; - - /** OSM Url */ - std::string m_OsmUrl; - - /** Cache Management */ - std::deque<otb::TileRecord> m_CacheManagement; - - /** Logo tile */ - ImagePointerType m_LogoTile; - -}; - -} // end namespace otb - -#endif diff --git a/Testing/Code/IO/CMakeLists.txt b/Testing/Code/IO/CMakeLists.txt index 48d9cae41f..a57438d378 100644 --- a/Testing/Code/IO/CMakeLists.txt +++ b/Testing/Code/IO/CMakeLists.txt @@ -2512,20 +2512,6 @@ ADD_TEST(ioTuTileMapImageSourceNew ${IO_TESTS19} # ${TEMP}/ioTileMapImageSourceToulouse.png # 256) -ADD_TEST(ioTuTileMapFetcherNew ${IO_TESTS19} - otbTileMapFetcherNew ) - -ADD_TEST(ioTvTileMapFetcherTest ${IO_TESTS19} - otbTileMapFetcherTest - 132122 - 95719 - 18 - http://tile.openstreetmap.org/ - #http://andy.sandbox.cloudmade.com/tiles/cycle/ - ${TEMP}/ - 2 - ${TEMP}/) - # We do not perform regression testing here because images on server might change ADD_TEST(ioTvTileMapImageIOFile ${IO_TESTS19} otbTileMapImageIOTest @@ -2811,8 +2797,6 @@ otbIOTests19.cxx otbImageFileReaderServerName.cxx otbTileMapImageSourceNew.cxx otbTileMapImageSource.cxx -otbTileMapFetcherNew.cxx -otbTileMapFetcherTest.cxx otbTileMapImageIOTest.cxx otbTileMapWriter.cxx ) diff --git a/Testing/Code/IO/otbIOTests19.cxx b/Testing/Code/IO/otbIOTests19.cxx index 967b0c3bc5..7804d3612a 100644 --- a/Testing/Code/IO/otbIOTests19.cxx +++ b/Testing/Code/IO/otbIOTests19.cxx @@ -29,8 +29,6 @@ void RegisterTests() REGISTER_TEST(otbImageFileReaderServerName); REGISTER_TEST(otbTileMapImageSourceNew); REGISTER_TEST(otbTileMapImageSource); - REGISTER_TEST(otbTileMapFetcherNew); - REGISTER_TEST(otbTileMapFetcherTest); REGISTER_TEST(otbTileMapImageIOTest); REGISTER_TEST(otbTileMapWriter); } diff --git a/Testing/Code/IO/otbTileMapFetcherNew.cxx b/Testing/Code/IO/otbTileMapFetcherNew.cxx deleted file mode 100644 index 5491e106ff..0000000000 --- a/Testing/Code/IO/otbTileMapFetcherNew.cxx +++ /dev/null @@ -1,30 +0,0 @@ -/*========================================================================= - - Program: ORFEO Toolbox - Language: C++ - Date: $Date$ - Version: $Revision$ - - - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. - See OTBCopyright.txt for details. - - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#include "itkExceptionObject.h" - -#include "otbTileMapFetcher.h" - -int otbTileMapFetcherNew(int argc, char * argv[]) -{ - typedef otb::TileMapFetcher TileMapFetcherType; - typedef TileMapFetcherType::Pointer TileMapFetcherPointerType; - - TileMapFetcherPointerType tmf = TileMapFetcherType::New(); - - return EXIT_SUCCESS; -} diff --git a/Testing/Code/IO/otbTileMapFetcherTest.cxx b/Testing/Code/IO/otbTileMapFetcherTest.cxx deleted file mode 100644 index 272d1665db..0000000000 --- a/Testing/Code/IO/otbTileMapFetcherTest.cxx +++ /dev/null @@ -1,87 +0,0 @@ -/*========================================================================= - - Program: ORFEO Toolbox - Language: C++ - Date: $Date$ - Version: $Revision$ - - - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. - See OTBCopyright.txt for details. - - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#include "itkExceptionObject.h" -#include "otbTileMapFetcher.h" -#include "otbVectorImage.h" -#include "otbImageFileWriter.h" - -#include <stdio.h> - -int otbTileMapFetcherTest(int argc, char * argv[]) -{ - if (argc != 8) - { - std::cout << "<x> <y> <z> <server name> <cache directory> <cache size> <output directory>" << std::endl; - return EXIT_FAILURE; - } - else - { - typedef unsigned char PixelType; - typedef otb::VectorImage<PixelType, 2> ImageType; - typedef otb::ImageFileWriter<ImageType> WriterType; - typedef otb::TileMapFetcher TileMapFetcherType; - typedef TileMapFetcherType::Pointer TileMapFetcherPointerType; - - unsigned int x = static_cast<unsigned int>(atoi(argv[1])); - unsigned int y = static_cast<unsigned int>(atoi(argv[2])); - unsigned int z = static_cast<unsigned int>(atoi(argv[3])); - std::string serverName = argv[4]; - std::string cacheDirectory = argv[5]; - unsigned int cacheSize = static_cast<unsigned int>(atoi(argv[6])); - std::string directory = argv[7]; - - std::ostringstream filename; - std::ostringstream filename2; - std::ostringstream filename3; - - TileMapFetcherPointerType tmf = TileMapFetcherType::New(); - ImageType::Pointer img = ImageType::New(); - WriterType::Pointer writer = WriterType::New(); - - tmf->SetServerName(serverName); - tmf->SetCacheDirectory(cacheDirectory); - tmf->SetCacheSize(cacheSize); - - /** Test fetching tile */ - img = tmf->FetchTile(x, y, z); - - filename << directory; - filename << "otTileMapFetcherTest_Toulouse.png"; - - writer->SetFileName(filename.str()); - writer->SetInput(img); - writer->Update(); - - /** Test out of range */ - img = tmf->FetchTile(x, y, 1); - - filename2 << directory; - filename2 << "otTileMapFetcherTest_OutOfRange.png"; - - writer->SetFileName(filename2.str()); - writer->SetInput(img); - writer->Update(); - - /* Test Cache */ - for (unsigned int i = x; i < x + (5 * cacheSize); i++) - { - img = tmf->FetchTile(i, y, z); - } - } - return EXIT_SUCCESS; -} -- GitLab