diff --git a/Testing/Code/IO/CMakeLists.txt b/Testing/Code/IO/CMakeLists.txt index 4db5a98ffa529ead0c35b66cf03cbd4c20dd98d4..41f81e6f8c31c260c29b885110c333d432d5b54d 100755 --- a/Testing/Code/IO/CMakeLists.txt +++ b/Testing/Code/IO/CMakeLists.txt @@ -1424,6 +1424,19 @@ ADD_TEST(ioTvossimElevManagerTest3 ${IO_TESTS12} # -1.8870830 52.0135758 0.024363378967 -0.018457085039 232 422 ) +#This test investigate the problem with the ossimElevManager +# - differences between plaforms +# - file descriptor leak +ADD_TEST(ioTvossimElevManagerTest4 ${IO_TESTS12} +--compare-image ${EPSILON_9} ${BASELINE}/ioTvossimElevManagerTest3.tif + ${TEMP}/ioTvossimElevManagerTest4.hdr + otbOssimElevManagerTest4 + ${INPUTDATA}/DEM/srtm_directory + ${TEMP}/ioTvossimElevManagerTest4 + -1.8 52 0.02 -0.018 232 422 + ) + + ADD_TEST(ioTvossimElevManagerTest2 ${IO_TESTS12} --compare-ascii ${EPSILON_9} ${BASELINE_FILES}/ioTvossimElevManagerTest2.txt ${TEMP}/ioTvossimElevManagerTest2.txt @@ -2017,6 +2030,7 @@ otbDEMToImageGeneratorNew.cxx otbDEMToImageGeneratorTest.cxx otbOssimElevManagerTest.cxx otbOssimElevManagerTest2.cxx +otbOssimElevManagerTest4.cxx otbDEMToOrthoImageGeneratorNew.cxx otbDEMToOrthoImageGeneratorTest.cxx otbPrepareSRTMDirectoryNew.cxx diff --git a/Testing/Code/IO/otbIOTests12.cxx b/Testing/Code/IO/otbIOTests12.cxx index f861ad8a23c699ab1f90d986a3ce0638a78adc53..cce0b7f8aac52f4c9da1165e2d2ad1b8d3c4469c 100644 --- a/Testing/Code/IO/otbIOTests12.cxx +++ b/Testing/Code/IO/otbIOTests12.cxx @@ -34,6 +34,7 @@ REGISTER_TEST(otbDEMToImageGeneratorNew); REGISTER_TEST(otbDEMToImageGeneratorTest); REGISTER_TEST(otbOssimElevManagerTest); REGISTER_TEST(otbOssimElevManagerTest2); +REGISTER_TEST(otbOssimElevManagerTest4); REGISTER_TEST(otbDEMToOrthoImageGeneratorNew); REGISTER_TEST(otbDEMToOrthoImageGeneratorTest); REGISTER_TEST(otbPrepareSRTMDirectoryNew); diff --git a/Testing/Code/IO/otbOssimElevManagerTest4.cxx b/Testing/Code/IO/otbOssimElevManagerTest4.cxx new file mode 100644 index 0000000000000000000000000000000000000000..cd37ea5c034b091390f411d366616d4425cd736e --- /dev/null +++ b/Testing/Code/IO/otbOssimElevManagerTest4.cxx @@ -0,0 +1,111 @@ +/*========================================================================= + + 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 <cstdlib> +#include <fstream> +#include <sstream> + +#include "elevation/ossimElevManager.h" +#include "base/ossimFilename.h" + + + +int otbOssimElevManagerTest4(int argc,char* argv[]) +{ + + if (argc!=9) + { + std::cout<<"Usage: "<<std::endl; + std::cout<<argv[0]<<" srtmDir outfname originX originY spacingX spacingY sizeX sizeY"<<std::endl; + return EXIT_FAILURE; + } + + const ossimFilename srtmDir(argv[1]); + const char * outfname = argv[2]; + + double origin[2]; + double spacing[2]; + int size[2]; + + origin[0]= atof(argv[3]); + origin[1]= atof(argv[4]); + spacing[0]=atof(argv[5]); + spacing[1]=atof(argv[6]); + size[0]= atoi(argv[7]); + size[1]= atoi(argv[8]); + + double* image = new double[size[0]*size[1]]; + + + ossimElevManager * elevManager = ossimElevManager::instance(); + + elevManager->openDirectory(srtmDir); + + for (int j=0; j<size[1]; ++j) + { + for (int i=0; i<size[0]; ++i) + { + double point[2]; + point[0] = origin[0]+i*spacing[0]; + point[1] = origin[1]+j*spacing[1]; + + ossimGpt ossimWorldPoint; + ossimWorldPoint.lon=point[0]; + ossimWorldPoint.lat=point[1]; + double height = elevManager->getHeightAboveMSL(ossimWorldPoint); + + if (!ossim::isnan(height)) + { + // Fill the image + image[i+j*size[0]] = height; + } + else + { + // Back to the MNT default value + image[i+j*size[0]] = 0; + } + } + } + + std::ofstream file; + file.open(outfname, ios::binary|ios::out); + + file.write(reinterpret_cast<char*>(image), sizeof(image)*size[0]*size[1]); + file.close(); + + + delete[] image; + + //Create the header + std::stringstream headerName; + headerName << outfname << ".hdr"; + std::ofstream headerFile; + headerFile.open(headerName.str().c_str()); + headerFile << "ENVI\n"; + headerFile << "samples = " << size[0] << "\n"; + headerFile << "lines = " << size[1] << "\n"; + headerFile << "bands = 1\n"; + headerFile << "header offset = 0\n"; + headerFile << "file type = ENVI Standard\n"; + headerFile << "data type = 5\n"; + headerFile << "interleave = bsq\n"; + headerFile << "byte order = 0\n"; + headerFile.close(); + + return EXIT_SUCCESS; +}