diff --git a/Testing/Code/UtilitiesAdapters/CMakeLists.txt b/Testing/Code/UtilitiesAdapters/CMakeLists.txt index 4e70646a26b8ed281490342541b6095881c5e763..9b5b598472b5818c521a036b7b0e12e5576af44d 100644 --- a/Testing/Code/UtilitiesAdapters/CMakeLists.txt +++ b/Testing/Code/UtilitiesAdapters/CMakeLists.txt @@ -74,16 +74,255 @@ ADD_TEST(uaTvRPCSolverAdapterNotEnoughPointsTest ) SET_TESTS_PROPERTIES(uaTvRPCSolverAdapterNotEnoughPointsTest PROPERTIES WILL_FAIL TRUE) - - - ENDIF(OTB_DATA_USE_LARGEINPUT) +# Exhaustive DEM handler testing + +ADD_TEST(uaTvDEMHandler_AboveEllipsoid_SRTM_Geoid + ${UtilitiesAdapters_TESTS1} + otbDEMHandlerTest + ${INPUTDATA}/DEM/srtm_directory/ + ${INPUTDATA}/DEM/egm96.grd + 40 + 8.434583 + 44.647083 + 0 + 383.580313671 + 0.001 +) + +ADD_TEST(uaTvDEMHandler_AboveMSL_SRTM_Geoid + ${UtilitiesAdapters_TESTS1} + otbDEMHandlerTest + ${INPUTDATA}/DEM/srtm_directory/ + ${INPUTDATA}/DEM/egm96.grd + 40 + 8.434583 + 44.647083 + 1 + 339.513 + 0.001 +) + +ADD_TEST(uaTvDEMHandler_AboveEllipsoid_SRTM_NoGeoid + ${UtilitiesAdapters_TESTS1} + otbDEMHandlerTest + ${INPUTDATA}/DEM/srtm_directory/ + no + 40 + 8.434583 + 44.647083 + 0 + 339.513 + 0.001 +) + +ADD_TEST(uaTvDEMHandler_AboveMSL_SRTM_NoGeoid + ${UtilitiesAdapters_TESTS1} + otbDEMHandlerTest + ${INPUTDATA}/DEM/srtm_directory/ + no + 40 + 8.434583 + 44.647083 + 1 + 339.513 + 0.001 +) + +ADD_TEST(uaTvDEMHandler_AboveEllipsoid_NoSRTM_NoGeoid + ${UtilitiesAdapters_TESTS1} + otbDEMHandlerTest + no + no + 40 + 8.434583 + 44.647083 + 0 + 40 + 0.001 +) + +ADD_TEST(uaTvDEMHandler_AboveMSL_NoSRTM_NoGeoid + ${UtilitiesAdapters_TESTS1} + otbDEMHandlerTest + no + no + 40 + 8.434583 + 44.647083 + 1 + 40 + 0.001 +) + + +ADD_TEST(uaTvDEMHandler_AboveEllipsoid_SRTM_Geoid_NoData + ${UtilitiesAdapters_TESTS1} + otbDEMHandlerTest + ${INPUTDATA}/DEM/srtm_directory/ + ${INPUTDATA}/DEM/egm96.grd + 40 + 8.687917 + 44.237917 + 0 + 45.7464 + 0.001 +) + +ADD_TEST(uaTvDEMHandler_AboveMSL_SRTM_Geoid_NoData + ${UtilitiesAdapters_TESTS1} + otbDEMHandlerTest + ${INPUTDATA}/DEM/srtm_directory/ + ${INPUTDATA}/DEM/egm96.grd + 40 + 8.687917 + 44.237917 + 1 + -5.7464 + 0.001 +) + +ADD_TEST(uaTvDEMHandler_AboveEllipsoid_SRTM_NoGeoid_NoData + ${UtilitiesAdapters_TESTS1} + otbDEMHandlerTest + ${INPUTDATA}/DEM/srtm_directory/ + no + 40 + 8.687917 + 44.237917 + 0 + 40 + 0.001 +) + +ADD_TEST(uaTvDEMHandler_AboveMSL_SRTM_NoGeoid_NoData + ${UtilitiesAdapters_TESTS1} + otbDEMHandlerTest + ${INPUTDATA}/DEM/srtm_directory/ + no + 40 + 8.687917 + 44.237917 + 1 + 40 + 0.001 +) + +ADD_TEST(uaTvDEMHandler_AboveEllipsoid_NoSRTM_NoGeoid_NoData + ${UtilitiesAdapters_TESTS1} + otbDEMHandlerTest + no + no + 40 + 8.687917 + 44.237917 + 0 + 40 + 0.001 +) + +ADD_TEST(uaTvDEMHandler_AboveMSL_NoSRTM_NoGeoid_NoData + ${UtilitiesAdapters_TESTS1} + otbDEMHandlerTest + no + no + 40 + 8.687917 + 44.237917 + 1 + 40 + 0.001 +) + + +ADD_TEST(uaTvDEMHandler_AboveEllipsoid_SRTM_Geoid_NoSRTMCoverage + ${UtilitiesAdapters_TESTS1} + otbDEMHandlerTest + ${INPUTDATA}/DEM/srtm_directory/ + ${INPUTDATA}/DEM/egm96.grd + 20 + 10. # Point not covered + 10. # Point not covered + 0 + 21.569 # Geoid offset + 0.001 +) + +ADD_TEST(uaTvDEMHandler_AboveMSL_SRTM_Geoid_NoSRTMCoverage + ${UtilitiesAdapters_TESTS1} + otbDEMHandlerTest + ${INPUTDATA}/DEM/srtm_directory/ + ${INPUTDATA}/DEM/egm96.grd + 20 + 10. # Point not covered + 10. # Point not covered + 1 + -1.569 + 0.001 +) + +ADD_TEST(uaTvDEMHandler_AboveEllipsoid_SRTM_NoGeoid_NoSRTMCoverage + ${UtilitiesAdapters_TESTS1} + otbDEMHandlerTest + ${INPUTDATA}/DEM/srtm_directory/ + no + 20 + 10. # Point not covered + 10. # Point not covered + 0 + 20 + 0.001 +) + +ADD_TEST(uaTvDEMHandler_AboveMSL_SRTM_NoGeoid_NoSRTMCoverage + ${UtilitiesAdapters_TESTS1} + otbDEMHandlerTest + ${INPUTDATA}/DEM/srtm_directory/ + no + 20 + 10. # Point not covered + 10. # Point not covered + 1 + 20 + 0.001 +) + +ADD_TEST(uaTvDEMHandler_AboveEllipsoid_BadSRTM_Geoid + ${UtilitiesAdapters_TESTS1} + otbDEMHandlerTest + ${INPUTDATA}/poupeesTIF/ + ${INPUTDATA}/DEM/egm96.grd + 40 + 8.434583 + 44.647083 + 0 + 383.580313671 + 0.001 +) + +SET_TESTS_PROPERTIES(uaTvDEMHandler_AboveEllipsoid_BadSRTM_Geoid PROPERTIES WILL_FAIL 1) + +ADD_TEST(uaTvDEMHandler_AboveEllipsoid_SRTM_BadGeoid + ${UtilitiesAdapters_TESTS1} + otbDEMHandlerTest + ${INPUTDATA}/DEM/srtm_directory/ + ${INPUTDATA}/poupees.jpg + 40 + 8.434583 + 44.647083 + 0 + 339.513 + 0.001 +) + + SET(UtilitiesAdapters_SRCS1 otbUtilitiesAdaptersTests1.cxx otbPlatformPositionAdapter.cxx otbGeometricSarSensorModelAdapter.cxx otbRPCSolverAdapterTest.cxx +otbDEMHandlerTest.cxx ) diff --git a/Testing/Code/UtilitiesAdapters/otbDEMHandlerTest.cxx b/Testing/Code/UtilitiesAdapters/otbDEMHandlerTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..dc72048d3b0cee3679c85c74aab25e404255835e --- /dev/null +++ b/Testing/Code/UtilitiesAdapters/otbDEMHandlerTest.cxx @@ -0,0 +1,107 @@ +/*========================================================================= + + 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 "itkMacro.h" +#include "otbDEMHandler.h" + +int otbDEMHandlerTest(int argc, char * argv[]) +{ + if(argc!=9) + { + std::cerr<<"Usage: "<<argv[0]<<" demdir[path|no] geoid[path|no] defaultHeight longitude latitude aboveMSLFlag targetValue tolerance"<<std::endl; + return EXIT_FAILURE; + } + + + std::string demdir = argv[1]; + std::string geoid = argv[2]; + double defaultHeight = atof(argv[3]); + double longitude = atof(argv[4]); + double latitude = atof(argv[5]); + bool aboveMSL = atoi(argv[6]); + double target = atof(argv[7]); + double tolerance = atof(argv[8]); + + otb::DEMHandler::Pointer demHandler = otb::DEMHandler::Instance(); + demHandler->SetDefaultHeightAboveEllipsoid(defaultHeight); + + bool fail = false; + + std::cout<<std::fixed; + std::cout.precision(12); + + if(demdir != "no") + { + if(!demHandler->IsValidDEMDirectory(demdir.c_str())) + { + std::cerr<<"IsValidDEMDirectory("<<demdir<<") = false"<<std::endl; + fail = true; + } + + demHandler->OpenDEMDirectory(demdir); + std::cout<<"GetDEMDirectory() = "<<demHandler->GetDEMDirectory()<<std::endl; + } + + if(geoid != "no") + { + demHandler->OpenGeoidFile(geoid); + std::cout<<"GetGeoidFile() = "<<demHandler->GetGeoidFile()<<std::endl; + } + + std::cout<<"PrintSelf: "<<demHandler<<std::endl; + + otb::DEMHandler::PointType point; + point[0] = longitude; + point[1] = latitude; + + double height = -32768; + + if(aboveMSL) + { + height = demHandler->GetHeightAboveMSL(point); + + std::cout<<"height above MSL ("<<longitude<<", "<<latitude<<") = "<<height<<" meters"<<std::endl; + } + else + { + height = demHandler->GetHeightAboveEllipsoid(point); + std::cout<<"height above ellipsoid ("<<longitude<<", "<<latitude<<") = "<<height<<" meters"<<std::endl; + } + + // Check for Nan + if(vnl_math_isnan(height)) + { + std::cerr<<"Computed value is NaN"<<std::endl; + fail = true; + } + + double error = vcl_abs(height-target); + + if(error>tolerance) + { + std::cerr<<"Target value is "<<target<<" meters, computed value is "<<height<<" meters. error ("<<error<<" meters) > tolerance ("<<tolerance<<" meters)"<<std::endl; + fail = true; + } + + if(fail) + { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/UtilitiesAdapters/otbUtilitiesAdaptersTests1.cxx b/Testing/Code/UtilitiesAdapters/otbUtilitiesAdaptersTests1.cxx index 8e1eb88c51d145fc64ff5375865288506b22c932..5965cefb0aee475ca6bd2803dbe00427c47db192 100644 --- a/Testing/Code/UtilitiesAdapters/otbUtilitiesAdaptersTests1.cxx +++ b/Testing/Code/UtilitiesAdapters/otbUtilitiesAdaptersTests1.cxx @@ -28,4 +28,5 @@ void RegisterTests() REGISTER_TEST(otbGeometricSarSensorModelAdapterNewTest); REGISTER_TEST(otbGeometricSarSensorModelAdapterTest); REGISTER_TEST(otbRPCSolverAdapterTest); + REGISTER_TEST(otbDEMHandlerTest); }