From 335f2b2d4c6fbfc7207df2be5d9397a195b4b395 Mon Sep 17 00:00:00 2001 From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org> Date: Wed, 14 Jan 2009 17:24:23 +0800 Subject: [PATCH] TEST: add test for TileMapImageIO --- Examples/IO/CMakeLists.txt | 26 ++++++ Examples/IO/TileMapImageIOExample.cxx | 117 ++++++++++++++++++++++++++ Examples/IO/otbIOExamplesTests2.cxx | 35 ++++++++ 3 files changed, 178 insertions(+) create mode 100644 Examples/IO/TileMapImageIOExample.cxx create mode 100644 Examples/IO/otbIOExamplesTests2.cxx diff --git a/Examples/IO/CMakeLists.txt b/Examples/IO/CMakeLists.txt index 3816f54951..450da7b6d2 100644 --- a/Examples/IO/CMakeLists.txt +++ b/Examples/IO/CMakeLists.txt @@ -69,6 +69,12 @@ IF(ITK_USE_REVIEW) TARGET_LINK_LIBRARIES(LidarToImageExample OTBIO OTBCommon ITKCommon ITKIO otbossim ) ENDIF(ITK_USE_REVIEW) +IF( OTB_USE_CURL ) + ADD_EXECUTABLE(TileMapImageIOExample TileMapImageIOExample.cxx) + TARGET_LINK_LIBRARIES(TileMapImageIOExample OTBIO OTBCommon) +ENDIF( OTB_USE_CURL ) + + #ADD_EXECUTABLE(ImageReadExportVTK ImageReadExportVTK.cxx ) #TARGET_LINK_LIBRARIES(ImageReadExportVTK ITKCommon ITKIO) @@ -119,6 +125,7 @@ SET(TEMP ${OTB_BINARY_DIR}/Testing/Temporary) SET(EXE_TESTS1 ${CXX_TEST_PATH}/otbIOExamplesTests1) +SET(EXE_TESTS2 ${CXX_TEST_PATH}/otbIOExamplesTests2) SET(TOL 0.0) @@ -179,8 +186,27 @@ ADD_TEST(LidarToImageExample2Test ${EXE_TESTS1} ) ENDIF(ITK_USE_REVIEW) +IF( OTB_USE_CURL ) +ADD_TEST(TileMapImageIOExampleTest ${EXE_TESTS2} +--compare-image ${TOL} ${BASELINE}/openStreetMap.png + ${TEMP}/openStreetMap.png + TileMapImageIOExampleTest + ${INPUTDATA}/osmfile.otb + ${TEMP}/openStreetMap.png + ${TEMP} + 1.4835345 + 43.55968261 + 12 + ) +ENDIF( OTB_USE_CURL ) + + ADD_EXECUTABLE(otbIOExamplesTests1 otbIOExamplesTests1.cxx) TARGET_LINK_LIBRARIES(otbIOExamplesTests1 otbossim OTBBasicFilters OTBCommon OTBDisparityMap OTBIO OTBSpatialReasoning OTBChangeDetection OTBFeatureExtraction OTBLearning OTBMultiScale OTBProjections ITKIO ITKAlgorithms ITKStatistics ITKCommon ${OTB_IO_UTILITIES_DEPENDENT_LIBRARIES}) +IF( OTB_USE_CURL ) + ADD_EXECUTABLE(otbIOExamplesTests2 otbIOExamplesTests2.cxx) + TARGET_LINK_LIBRARIES(otbIOExamplesTests2 OTBCommon OTBIO ${OTB_IO_UTILITIES_DEPENDENT_LIBRARIES} ${CURL_LIBRARY} ) +ENDIF( OTB_USE_CURL ) ENDIF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING ) diff --git a/Examples/IO/TileMapImageIOExample.cxx b/Examples/IO/TileMapImageIOExample.cxx new file mode 100644 index 0000000000..bfb0be2c4b --- /dev/null +++ b/Examples/IO/TileMapImageIOExample.cxx @@ -0,0 +1,117 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +// Software Guide : BeginCommandLineArgs +// INPUTS: {osmfile.otb} +// OUTPUTS: {openStreetMap.png} +// ${GeneratedFolder} 1.4835345 43.55968261 12 +// Software Guide : EndCommandLineArgs + +#include "itkRGBPixel.h" +#include "otbImage.h" +#include "otbImageFileReader.h" +#include "otbTileMapImageIO.h" +#include "otbInverseSensorModel.h" +#include "otbExtractROI.h" +#include "otbImageFileWriter.h" +#include "ossim/projection/ossimTileMapModel.h" + +int main( int argc, char* argv[] ) +{ + + if(argc!=7) + { + std::cout << argv[0] <<" <inputFilename> <outputFilename> " + << "<cacheDirectory> <lon> <lat> <depth>" + << std::endl; + + return EXIT_FAILURE; + } + + + + char * inputFilename = argv[1]; + char * outputFilename = argv[2]; + char * cacheDirectory = argv[3]; + double lon = atof(argv[4]); + double lat = atof(argv[5]); + int depth = atoi(argv[6]); + + typedef itk::RGBPixel<unsigned char> RGBPixelType; + typedef otb::Image<RGBPixelType, 2> ImageType; + typedef otb::ImageFileReader<ImageType> ReaderType; + typedef otb::TileMapImageIO ImageIOType; + + ImageIOType::Pointer tileIO = ImageIOType::New(); + ReaderType::Pointer readerTile = ReaderType::New(); + tileIO->SetDepth(depth); + tileIO->SetCacheDirectory(cacheDirectory); + readerTile->SetImageIO(tileIO); + readerTile->SetFileName(inputFilename); + readerTile->UpdateOutputInformation(); + + typedef otb::InverseSensorModel<double> ModelType; + ModelType::Pointer model= ModelType::New(); + + model->SetImageGeometry(readerTile->GetOutput()->GetImageKeywordlist()); + dynamic_cast<ossimTileMapModel*>(model->GetOssimModel())->setDepth(depth); + if(!model) + { + std::cerr << "Unable to create a model" << std::endl; + return 1; + } + + typedef itk::Point <double, 2> PointType; + PointType lonLatPoint; + lonLatPoint[0]=lon; + lonLatPoint[1]=lat; + + PointType tilePoint; + tilePoint=model->TransformPoint(lonLatPoint); + + long int startX=static_cast<long int>(tilePoint[0]); + long int startY=static_cast<long int>(tilePoint[1]); + long int sizeX = 500; + long int sizeY = 500; + + std::cerr << startX <<", "<< startY << std::endl; + std::cerr << sizeX <<", "<< sizeY << std::endl; + + typedef otb::ExtractROI< RGBPixelType, RGBPixelType > ExtractROIFilterType; + ExtractROIFilterType::Pointer extractROIOsmFilter = ExtractROIFilterType::New(); + extractROIOsmFilter->SetStartX(startX-sizeX/2); + extractROIOsmFilter->SetStartY(startY-sizeY/2); + extractROIOsmFilter->SetSizeX( sizeX ); + extractROIOsmFilter->SetSizeY( sizeY ); + + extractROIOsmFilter->SetInput(readerTile->GetOutput()); + + + + typedef otb::ImageFileWriter<ImageType> WriterType; + WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(outputFilename); + writer->SetInput(extractROIOsmFilter->GetOutput()); + writer->Update(); + + return EXIT_SUCCESS; + +} diff --git a/Examples/IO/otbIOExamplesTests2.cxx b/Examples/IO/otbIOExamplesTests2.cxx new file mode 100644 index 0000000000..50810e4e71 --- /dev/null +++ b/Examples/IO/otbIOExamplesTests2.cxx @@ -0,0 +1,35 @@ +/*========================================================================= + + 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. + +=========================================================================*/ + +// this file defines the otbMultiScaleTest for the test driver +// and all it expects is that you have a function called RegisterTests +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif +#include <iostream> +#include "otbTestMain.h" + + +void RegisterTests() +{ +REGISTER_TEST(TileMapImageIOExampleTest); + +} + +#undef main +#define main TileMapImageIOExampleTest +#include "TileMapImageIOExample.cxx" -- GitLab