diff --git a/Testing/Code/IO/CMakeLists.txt b/Testing/Code/IO/CMakeLists.txt index ea43f4d9f046f9984a6d5b369168ba0189c892ce..96a18e0b41a39358318ff68ccfab9a7cbd391601 100755 --- a/Testing/Code/IO/CMakeLists.txt +++ b/Testing/Code/IO/CMakeLists.txt @@ -1120,6 +1120,7 @@ ADD_TEST(ioTvDEMHandler ${IO_TESTS} otbDEMHandlerTest ${INPUTDATA}/DEM/srtm_directory ${TEMP}/ioDEMGetHeightAboveMSL.txt + 3.6999 44.08 ) # --- otb::ImageGeometryHandler --- @@ -1143,6 +1144,21 @@ ADD_TEST(ioTvDEMToImageGeneratorTest ${IO_TESTS} ) + +ADD_TEST(ioTvossimElevManagerTest ${IO_TESTS} +--compare-image ${TOL} ${BASELINE}/ioTvossimElevManagerTest.tif + ${TEMP}/ioTvossimElevManagerTest.tif + otbOssimElevManagerTest + ${INPUTDATA}/DEM/srtm_directory + ${TEMP}/ioTvossimElevManagerTest.tif + 6.5 + 44.5 + 0.002 + 0.002 + 500 + 500 + ) + #---------------------------------------------------------------------------------- # Exemples de tests sur les grosses images # Tests non lanc�s pour raison taille des fichiers produits @@ -1211,6 +1227,7 @@ otbDEMToImageGeneratorNew.cxx otbDEMToImageGeneratorTest.cxx otbImageGeometryHandlerNew.cxx otbPipeline.cxx +otbOssimElevManagerTest.cxx ) INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}") diff --git a/Testing/Code/IO/otbDEMHandlerTest.cxx b/Testing/Code/IO/otbDEMHandlerTest.cxx index 4be1556990e94fa0182b765aaf756897adc231da..c5482dca834035f81b404e0b315e6a5247b239c7 100644 --- a/Testing/Code/IO/otbDEMHandlerTest.cxx +++ b/Testing/Code/IO/otbDEMHandlerTest.cxx @@ -42,8 +42,8 @@ int otbDEMHandlerTest(int argc, char * argv[]) typedef otb::UtmInverseProjection utmProjection; typedef utmProjection::InputPointType InputPoint; InputPoint geoPoint; - geoPoint[0] = 3.6999; - geoPoint[1] = 44.08; + geoPoint[0] = atof(argv[3]);//3.6999; + geoPoint[1] = atof(argv[4]);//44.08; height=demHandler->GetHeightAboveMSL(geoPoint); diff --git a/Testing/Code/IO/otbIOTests.cxx b/Testing/Code/IO/otbIOTests.cxx index 4b912add80d06e655f6889c7cecaf8be1586f2ca..6f7a90edff9aeb18f72f6c46c29e0aee806c0a07 100755 --- a/Testing/Code/IO/otbIOTests.cxx +++ b/Testing/Code/IO/otbIOTests.cxx @@ -79,5 +79,6 @@ REGISTER_TEST(otbDEMHandlerTest); REGISTER_TEST(otbImageGeometryHandlerNew); REGISTER_TEST(otbDEMToImageGeneratorNew); REGISTER_TEST(otbDEMToImageGeneratorTest); +REGISTER_TEST(otbOssimElevManagerTest); REGISTER_TEST(otbPipeline); } diff --git a/Testing/Code/IO/otbOssimElevManagerTest.cxx b/Testing/Code/IO/otbOssimElevManagerTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..a8897a9a829112ab91e2e558a961a054a917f59e --- /dev/null +++ b/Testing/Code/IO/otbOssimElevManagerTest.cxx @@ -0,0 +1,98 @@ +#include "otbImage.h" +#include "otbImageFileWriter.h" +#include "elevation/ossimElevManager.h" +#include "base/ossimFilename.h" +#include "itkImageRegionIteratorWithIndex.h" + + +int otbOssimElevManagerTest(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]; + + typedef double PixelType; + const unsigned int Dimension = 2; + + typedef otb::Image<PixelType,Dimension> ImageType; + typedef otb::ImageFileWriter<ImageType> WriterType; + typedef itk::ImageRegionIteratorWithIndex<ImageType> IteratorType; + + typedef ImageType::PointType PoinType; + typedef ImageType::RegionType RegionType; + typedef ImageType::SpacingType SpacingType; + typedef RegionType::IndexType IndexType; + typedef RegionType::SizeType SizeType; + typedef ImageType::PointType PointType; + + PointType origin; + SpacingType spacing; + SizeType size; + + 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]); + + IndexType index; + index.Fill(0); + + RegionType region; + region.SetIndex(index); + region.SetSize(size); + + ImageType::Pointer image = ImageType::New(); + image->SetRegions(region); + image->Allocate(); + image->FillBuffer(0); + + image->SetOrigin(origin); + image->SetSpacing(spacing); + + ossimElevManager * elevManager = ossimElevManager::instance(); + + int error = elevManager->openDirectory(srtmDir); + + std::cout<<"Opening srtmDir : "<<error<<std::endl; + + + IteratorType it(image,image->GetLargestPossibleRegion()); + + for(it.GoToBegin();!it.IsAtEnd();++it) + { + PointType point; + image->TransformIndexToPhysicalPoint(it.GetIndex(),point); + ossimGpt ossimWorldPoint; + ossimWorldPoint.lon=point[0]; + ossimWorldPoint.lat=point[1]; + double height = elevManager->getHeightAboveMSL(ossimWorldPoint); + if (height!=static_cast<double>(OSSIM_DBL_NAN)) + { + // Fill the image + it.Set(height); + } + else + { + // Back to the MNT default value + it.Set(0); + } + } + + WriterType::Pointer writer = WriterType::New(); + writer->SetInput(image); + writer->SetFileName(outfname); + writer->Update(); + + + + return EXIT_SUCCESS; +}