From 69c460636d2fc79f8416beeab7f348c2fe66f6e4 Mon Sep 17 00:00:00 2001 From: Otmane Lahlou <otmane.lahlou@c-s.fr> Date: Wed, 8 Sep 2010 14:06:47 +0200 Subject: [PATCH] ADD : GenericRSResampler tests --- Testing/Code/Projections/CMakeLists.txt | 20 +++- .../otbGenericRSResampleImageFilter.cxx | 111 ++++++++++++++++++ .../otbGenericRSResampleImageFilterNew.cxx | 38 ++++++ .../Code/Projections/otbProjectionsTests4.cxx | 2 + 4 files changed, 168 insertions(+), 3 deletions(-) create mode 100644 Testing/Code/Projections/otbGenericRSResampleImageFilter.cxx create mode 100644 Testing/Code/Projections/otbGenericRSResampleImageFilterNew.cxx diff --git a/Testing/Code/Projections/CMakeLists.txt b/Testing/Code/Projections/CMakeLists.txt index 548c016444..cd9f63456e 100644 --- a/Testing/Code/Projections/CMakeLists.txt +++ b/Testing/Code/Projections/CMakeLists.txt @@ -602,17 +602,29 @@ ADD_TEST(prTuPhysicalToRPCSensorModelImageFilter ${PROJECTIONS_TESTS4} otbPhysicalToRPCSensorModelImageFilterNew ) -IF(OTB_DATA_USE_LARGEINPUT) ADD_TEST(prTvPhysicalToRPCSensorModelImageFilter ${PROJECTIONS_TESTS4} otbPhysicalToRPCSensorModelImageFilter + ${INPUTDATA}/ToulouseExtract_WithGeom.tif + 15 + ${TEMP}/prTvotbPhysicalToRPCSensorModelImageFilter.tif + ) + +ADD_TEST(prTuotbGenericRSResampleImageFilter ${PROJECTIONS_TESTS4} + otbGenericRSResampleImageFilterNew + ) +IF(OTB_DATA_USE_LARGEINPUT) + + +ADD_TEST(prTvotbGenericRSResampleImageFilter ${PROJECTIONS_TESTS4} + otbGenericRSResampleImageFilter ${LARGEINPUT}/QUICKBIRD/TOULOUSE/000000128955_01_P001_PAN/02APR01105228-P1BS-000000128955_01_P001.TIF 1000 - ${TEMP}/prTvotbPhysicalToRPCSensorModelImageFilter.tif + 15 + ${TEMP}/prTvotbGenericRSResampleImageFilterOutput.tif ) ENDIF(OTB_DATA_USE_LARGEINPUT) - #======================================================================================= SET(Projections_SRCS1 otbProjectionsTests1.cxx @@ -665,6 +677,8 @@ otbOptResampleImageFilterNew.cxx otbOptResampleImageFilter.cxx otbPhysicalToRPCSensorModelImageFilterNew.cxx otbPhysicalToRPCSensorModelImageFilter.cxx +otbGenericRSResampleImageFilterNew.cxx +otbGenericRSResampleImageFilter.cxx ) OTB_ADD_EXECUTABLE(otbProjectionsTests1 "${Projections_SRCS1}" "OTBProjections;OTBIO;OTBTesting") diff --git a/Testing/Code/Projections/otbGenericRSResampleImageFilter.cxx b/Testing/Code/Projections/otbGenericRSResampleImageFilter.cxx new file mode 100644 index 0000000000..3e12c9a79d --- /dev/null +++ b/Testing/Code/Projections/otbGenericRSResampleImageFilter.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 "otbGenericRSResampleImageFilter.h" +#include "otbVectorImage.h" +#include "itkVector.h" +#include "otbImage.h" + +#include "otbImageFileReader.h" +#include "otbStreamingImageFileWriter.h" + +#include <ogr_spatialref.h> + +int otbGenericRSResampleImageFilter(int argc, char* argv[]) +{ + const char * infname = argv[1]; + const char * outfname = argv[4]; + unsigned int isize = atoi(argv[2]); + unsigned int iGridSpacing = atoi(argv[3]); + + // Images definition + const unsigned int Dimension = 2; + typedef double PixelType; + typedef otb::VectorImage<PixelType, Dimension> ImageType; + typedef ImageType::SizeType SizeType; + + typedef itk::Vector<PixelType, 2> DeformationValueType; + typedef otb::Image<DeformationValueType, Dimension> DeformationFieldType; + + typedef otb::GenericRSResampleImageFilter<ImageType, ImageType, DeformationFieldType> ImageResamplerType; + typedef ImageResamplerType::OriginType OriginType; + typedef ImageResamplerType::SpacingType SpacingType; + + typedef otb::ImageFileReader<ImageType> ReaderType; + + ReaderType::Pointer reader = ReaderType::New(); + ImageResamplerType::Pointer resampler = ImageResamplerType::New(); + + // Fill the output size with the size selected by the user + SizeType size; + size.Fill(isize); + + OriginType origin; + origin.Fill(1500); + + // Build the ouput projection ref : Lambert II ref + OGRSpatialReference oSRS; + + // Build UTM ref + oSRS.SetProjCS("UTM"); + oSRS.SetUTM(31, true); + char * utmRef = NULL; + oSRS.exportToWkt(&utmRef); + + SpacingType spacing; + spacing[0] = 0.6; + spacing[1] = -0.6; + + + +// double stdParallel1 = 45.89891944; +// double stdParallel2 = 47.69601389; +// double originLatL2 = 46.8; +// double originLongL2 = 2.33722778; +// double falseEastingL2 = 600000; +// double falseNorthingL2 = 2200000; +// oSRS.SetProjCS("Lambert II "); +// oSRS.SetLCC(stdParallel1, stdParallel2, originLatL2, originLongL2, falseEastingL2, falseNorthingL2); +// char * lambertRef = NULL; +// oSRS.exportToWkt(&lambertRef); + + // Read the input image + reader->SetFileName(infname); + reader->UpdateOutputInformation(); + + // Set the Resampler Parameters + resampler->SetInput(reader->GetOutput()); + resampler->SetDeformationFieldSpacing(iGridSpacing); + resampler->SetOutputParametersFromImage(reader->GetOutput()); + resampler->SetOutputOrigin(origin); + resampler->SetOutputSize(size); + resampler->SetOutputSpacing(spacing); + resampler->SetOutputProjectionRef(utmRef); + + + // Write the resampled image + typedef otb::StreamingImageFileWriter<ImageType> WriterType; + WriterType::Pointer writer= WriterType::New(); + writer->SetTilingStreamDivisions(); + writer->WriteGeomFileOn(); + writer->SetFileName(outfname); + writer->SetInput(resampler->GetOutput()); + writer->Update(); + + return 0; +} diff --git a/Testing/Code/Projections/otbGenericRSResampleImageFilterNew.cxx b/Testing/Code/Projections/otbGenericRSResampleImageFilterNew.cxx new file mode 100644 index 0000000000..8ea8785b9c --- /dev/null +++ b/Testing/Code/Projections/otbGenericRSResampleImageFilterNew.cxx @@ -0,0 +1,38 @@ +/*========================================================================= + + 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 "otbGenericRSResampleImageFilter.h" +#include "otbVectorImage.h" +#include "itkVector.h" +#include "otbImage.h" + +int otbGenericRSResampleImageFilterNew(int argc, char* argv[]) +{ + // Images definition + const unsigned int Dimension = 2; + typedef double PixelType; + typedef otb::VectorImage<PixelType, Dimension> ImageType; + typedef itk::Vector<PixelType, 2> DeformationValueType; + typedef otb::Image<DeformationValueType, Dimension> DeformationFieldType; + typedef otb::GenericRSResampleImageFilter<ImageType, ImageType, DeformationFieldType> ImageResamplerType; + + ImageResamplerType::Pointer resampler = ImageResamplerType::New(); + + + return 0; +} diff --git a/Testing/Code/Projections/otbProjectionsTests4.cxx b/Testing/Code/Projections/otbProjectionsTests4.cxx index aa921f90c5..2d60ff00e1 100644 --- a/Testing/Code/Projections/otbProjectionsTests4.cxx +++ b/Testing/Code/Projections/otbProjectionsTests4.cxx @@ -30,4 +30,6 @@ void RegisterTests() REGISTER_TEST(otbOptResampleImageFilter); REGISTER_TEST(otbPhysicalToRPCSensorModelImageFilterNew); REGISTER_TEST(otbPhysicalToRPCSensorModelImageFilter); + REGISTER_TEST(otbGenericRSResampleImageFilterNew); + REGISTER_TEST(otbGenericRSResampleImageFilter); } -- GitLab