From 60c43da7468825210919296fd8b772f45d17fff4 Mon Sep 17 00:00:00 2001 From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org> Date: Fri, 18 Dec 2009 17:17:16 +0800 Subject: [PATCH] TEST: add test for vector data conversion to image coordinates --- Testing/Code/Projections/CMakeLists.txt | 12 +++ .../Code/Projections/otbProjectionsTests3.cxx | 1 + ...ctorDataProjectionFilterFromMapToImage.cxx | 75 +++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 Testing/Code/Projections/otbVectorDataProjectionFilterFromMapToImage.cxx diff --git a/Testing/Code/Projections/CMakeLists.txt b/Testing/Code/Projections/CMakeLists.txt index e9357b851f..6bf4561c67 100644 --- a/Testing/Code/Projections/CMakeLists.txt +++ b/Testing/Code/Projections/CMakeLists.txt @@ -457,6 +457,17 @@ ADD_TEST(prTvVectorDataProjectionFilterFromMapToGeo ${PROJECTIONS_TESTS3} ${TEMP}/prTvVectorDataProjectionFilterFromMapToGeo.kml ) +ADD_TEST(prTvVectorDataProjectionFilterFromMapToImage ${PROJECTIONS_TESTS3} + --compare-ascii ${NOTOL} + ${BASELINE_FILES}/prTvVectorDataProjectionFilterFromMapToImage.kml + ${TEMP}/prTvVectorDataProjectionFilterFromMapToImage.kml + otbVectorDataProjectionFilterFromMapToImage + ${INPUTDATA}/ToulousePoints-examples.shp + ${INPUTDATA}/QB_Toulouse_Ortho_PAN.tif + ${TEMP}/prTvVectorDataProjectionFilterFromMapToImage.kml +) + + ADD_TEST(prTuGeocentricTransformNew ${PROJECTIONS_TESTS3} otbGeocentricTransformNew ) @@ -509,6 +520,7 @@ otbVectorDataProjectionFilterNew.cxx otbVectorDataProjectionFilter.cxx otbVectorDataProjectionFilterFromMapToSensor.cxx otbVectorDataProjectionFilterFromMapToGeo.cxx +otbVectorDataProjectionFilterFromMapToImage.cxx otbGeocentricTransformNew.cxx otbGeocentricTransform.cxx otbVectorDataExtractROIandProjection.cxx diff --git a/Testing/Code/Projections/otbProjectionsTests3.cxx b/Testing/Code/Projections/otbProjectionsTests3.cxx index 712ecb957e..00db5e5f43 100644 --- a/Testing/Code/Projections/otbProjectionsTests3.cxx +++ b/Testing/Code/Projections/otbProjectionsTests3.cxx @@ -37,6 +37,7 @@ void RegisterTests() REGISTER_TEST(otbVectorDataProjectionFilter); REGISTER_TEST(otbVectorDataProjectionFilterFromMapToSensor); REGISTER_TEST(otbVectorDataProjectionFilterFromMapToGeo); + REGISTER_TEST(otbVectorDataProjectionFilterFromMapToImage); REGISTER_TEST(otbGeocentricTransformNew); REGISTER_TEST(otbGeocentricTransform); REGISTER_TEST(otbVectorDataExtractROIandProjection); diff --git a/Testing/Code/Projections/otbVectorDataProjectionFilterFromMapToImage.cxx b/Testing/Code/Projections/otbVectorDataProjectionFilterFromMapToImage.cxx new file mode 100644 index 0000000000..df59f989f2 --- /dev/null +++ b/Testing/Code/Projections/otbVectorDataProjectionFilterFromMapToImage.cxx @@ -0,0 +1,75 @@ +/*========================================================================= + + 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 "itkExceptionObject.h" +#include "otbVectorDataProjectionFilter.h" +#include "otbVectorData.h" +#include "otbVectorDataFileReader.h" +#include "otbVectorDataFileWriter.h" + +#include "otbImage.h" +#include "otbImageFileReader.h" + +int otbVectorDataProjectionFilterFromMapToImage(int argc, char * argv[]) +{ + + if (argc < 4 ) + { + std::cout << argv[0] <<" <input vector filename> <input image filename>" + << " <output vector filename> " << std::endl; + + return EXIT_FAILURE; + } + + typedef otb::VectorData<double > InputVectorDataType; + typedef otb::VectorData<double > OutputVectorDataType; + + + typedef otb::VectorDataFileReader<InputVectorDataType> VectorDataFileReaderType; + VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New(); + + reader->SetFileName(argv[1]); + reader->UpdateOutputInformation(); + + + typedef otb::Image<unsigned short int, 2> ImageType; + typedef otb::ImageFileReader<ImageType> ImageReaderType; + ImageReaderType::Pointer imageReader = ImageReaderType::New(); + imageReader->SetFileName(argv[2]); + imageReader->UpdateOutputInformation(); + + + typedef otb::VectorDataProjectionFilter<InputVectorDataType,OutputVectorDataType> VectorDataFilterType; + + VectorDataFilterType::Pointer vectorDataProjection = VectorDataFilterType::New(); + + vectorDataProjection->SetInput(reader->GetOutput()); + + vectorDataProjection->SetOutputProjectionRef(imageReader->GetOutput()->GetProjectionRef()); + vectorDataProjection->SetOutputOrigin(imageReader->GetOutput()->GetOrigin()); + vectorDataProjection->SetOutputSpacing(imageReader->GetOutput()->GetSpacing()); + + + typedef otb::VectorDataFileWriter<OutputVectorDataType> VectorDataFileWriterType; + VectorDataFileWriterType::Pointer writer = VectorDataFileWriterType::New(); + writer->SetFileName(argv[3]); + writer->SetInput(vectorDataProjection->GetOutput()); + writer->Update(); + + + return EXIT_SUCCESS; +} -- GitLab