From 7c183326b52832416cc3ea04abaf7e2db65f6cc0 Mon Sep 17 00:00:00 2001 From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org> Date: Tue, 5 May 2009 18:04:27 +0800 Subject: [PATCH] TEST: add test for mapping in sensor geometry (WIP) --- Code/Common/otbVectorDataToImageFilter.txx | 28 +++-- Testing/Code/Common/CMakeLists.txt | 19 +++- Testing/Code/Common/otbCommonTests9.cxx | 1 + .../otbVectorDataToImageFilterSensorModel.cxx | 106 ++++++++++++++++++ 4 files changed, 141 insertions(+), 13 deletions(-) create mode 100644 Testing/Code/Common/otbVectorDataToImageFilterSensorModel.cxx diff --git a/Code/Common/otbVectorDataToImageFilter.txx b/Code/Common/otbVectorDataToImageFilter.txx index b8466970de..f4b1ec1a25 100644 --- a/Code/Common/otbVectorDataToImageFilter.txx +++ b/Code/Common/otbVectorDataToImageFilter.txx @@ -216,16 +216,24 @@ namespace otb //Converting the projection string to the porj.4 format std::string vectorDataProjectionWKT; itk::ExposeMetaData<std::string>(input->GetMetaDataDictionary(), MetaDataKey::ProjectionRefKey, vectorDataProjectionWKT); -// OGRSpatialReference oSRS; -// oSRS.importFromWkt(vectorDataProjectionWKT.c_str()); -// std::cout << "WKT -> " << vectorDataProjectionWKT << std::endl; - OGRSpatialReference oSRS(vectorDataProjectionWKT.c_str()); - char * pszProj4; - oSRS.exportToProj4(&pszProj4); - std::string vectorDataProjectionProj4(pszProj4); - CPLFree(pszProj4); - -// std::cout << "Proj.4 -> " << vectorDataProjectionProj4 << std::endl; + std::cout << "WKT -> " << vectorDataProjectionWKT << std::endl; + std::string vectorDataProjectionProj4; + if (vectorDataProjectionWKT == "") + { + //We assume that it is an image in sensor model geometry + //and tell mapnik that this is utm + //(with a resolution of 1m per unit) + vectorDataProjectionProj4 = "+proj=utm +zone=31 +ellps=WGS84"; + } + else + { + OGRSpatialReference oSRS(vectorDataProjectionWKT.c_str()); + char * pszProj4; + oSRS.exportToProj4(&pszProj4); + vectorDataProjectionProj4 = pszProj4; + CPLFree(pszProj4); + } + std::cout << "Proj.4 -> " << vectorDataProjectionProj4 << std::endl; // std::string vectorDataProjectionProj4 = "+proj=utm +zone=31 +ellps=WGS84"; m_Map.set_srs(vectorDataProjectionProj4); diff --git a/Testing/Code/Common/CMakeLists.txt b/Testing/Code/Common/CMakeLists.txt index 45c9cf3eac..c41d21ef79 100755 --- a/Testing/Code/Common/CMakeLists.txt +++ b/Testing/Code/Common/CMakeLists.txt @@ -7,7 +7,7 @@ SET(TEMP ${OTBTesting_BINARY_DIR}/Temporary) #Remote sensing images (large images ) IF(OTB_DATA_USE_LARGEINPUT) - SET(LARGEDATA ${OTB_DATA_LARGEINPUT_ROOT} ) + SET(LARGEINPUT ${OTB_DATA_LARGEINPUT_ROOT} ) ENDIF(OTB_DATA_USE_LARGEINPUT) #Tolerance sur diff pixel image @@ -141,7 +141,7 @@ ADD_TEST(coTvVectorDataExtractROI ${COMMON_TESTS2} ${BASELINE_FILES}/coVectorDataExtractROIOutput.shp ${TEMP}/coVectorDataExtractROIOutput.shp otbVectorDataExtractROI - ${INPUTDATA}/ToulousePoints-examples.shp #${LARGEDATA}/TOULOUSE/QuickBird/GIS_FILES/000000128955_01_ORDER_SHAPE.shp + ${INPUTDATA}/ToulousePoints-examples.shp #${LARGEINPUT}/TOULOUSE/QuickBird/GIS_FILES/000000128955_01_ORDER_SHAPE.shp ${TEMP}/coVectorDataExtractROIOutput.shp 374369.48850211215904 4828951.58612491376698 # Origin of the RemoteSensingRegion 1000.25 25000.2 # Size of the Cartoregion @@ -720,12 +720,24 @@ ADD_TEST(coTvVectorDataToImageFilter ${COMMON_TESTS9} ${BASELINE}/coTvVectorDataToImageFilter.png ${TEMP}/coTvVectorDataToImageFilter.png otbVectorDataToImageFilter - ${LARGEDATA}/VECTOR/MidiPyrenees/roads.shp + ${LARGEINPUT}/VECTOR/MidiPyrenees/roads.shp ${TEMP}/coTvVectorDataToImageFilter.png ) ENDIF(OTB_DATA_USE_LARGEINPUT) +IF(OTB_DATA_USE_LARGEINPUT) +ADD_TEST(coTvVectorDataToImageFilterSensorModel ${COMMON_TESTS9} + --compare-image ${NOTOL} + ${BASELINE}/coTvVectorDataToImageFilterSensorModel.png + ${TEMP}/coTvVectorDataToImageFilterSensorModel.png + otbVectorDataToImageFilterSensorModel + ${LARGEINPUT}/VECTOR/MidiPyrenees/roads.shp + ${LARGEINPUT}/TOULOUSE/QuickBird/000000128955_01_P001_PAN/02APR01105228-P1BS-000000128955_01_P001.TIF + ${TEMP}/coTvVectorDataToImageFilterSensorModel.png +) +ENDIF(OTB_DATA_USE_LARGEINPUT) + ENDIF(OTB_USE_MAPNIK) # ------- Fichiers sources CXX ----------------------------------- @@ -836,6 +848,7 @@ IF(OTB_USE_MAPNIK) SET(BasicCommon_SRCS9 otbVectorDataToImageFilterNew.cxx otbVectorDataToImageFilter.cxx +otbVectorDataToImageFilterSensorModel.cxx ) ENDIF(OTB_USE_MAPNIK) diff --git a/Testing/Code/Common/otbCommonTests9.cxx b/Testing/Code/Common/otbCommonTests9.cxx index 0ccfd42a0b..f1851edeef 100644 --- a/Testing/Code/Common/otbCommonTests9.cxx +++ b/Testing/Code/Common/otbCommonTests9.cxx @@ -28,4 +28,5 @@ void RegisterTests() { REGISTER_TEST(otbVectorDataToImageFilterNew); REGISTER_TEST(otbVectorDataToImageFilter); +REGISTER_TEST(otbVectorDataToImageFilterSensorModel); } diff --git a/Testing/Code/Common/otbVectorDataToImageFilterSensorModel.cxx b/Testing/Code/Common/otbVectorDataToImageFilterSensorModel.cxx new file mode 100644 index 0000000000..ea167ff15a --- /dev/null +++ b/Testing/Code/Common/otbVectorDataToImageFilterSensorModel.cxx @@ -0,0 +1,106 @@ +/*========================================================================= + + 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 <fstream> +#include <iostream> + +#include "otbVectorDataFileReader.h" +#include "otbImageFileWriter.h" +#include "otbVectorData.h" +#include "otbVectorDataProjectionFilter.h" + +#include "itkRGBAPixel.h" +#include "otbImage.h" +#include "otbImageFileReader.h" +#include "otbVectorDataToImageFilter.h" + +int otbVectorDataToImageFilterSensorModel(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; + } + + //Read the vector data + typedef otb::VectorData<> VectorDataType; + typedef otb::VectorDataFileReader<VectorDataType> VectorDataFileReaderType; + VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New(); + reader->SetFileName(argv[1]); + + //Read the image (only for the information) + typedef otb::Image<unsigned short int, 2> SensorImageType; + typedef otb::ImageFileReader<SensorImageType> ImageReaderType; + ImageReaderType::Pointer imageReader = ImageReaderType::New(); + imageReader->SetFileName(argv[2]); + imageReader->UpdateOutputInformation(); + + + //Reproject the vector data in the proper projection + typedef otb::VectorDataProjectionFilter<VectorDataType, VectorDataType> ProjectionFilterType; + ProjectionFilterType::Pointer projection = ProjectionFilterType::New(); + projection->SetInput(reader->GetOutput()); + + projection->SetOutputKeywordList(imageReader->GetOutput()->GetImageKeywordlist()); + projection->SetOutputOrigin(imageReader->GetOutput()->GetOrigin()); + projection->SetOutputSpacing(imageReader->GetOutput()->GetSpacing()); + + + //Convert the vector data into an image + typedef itk::RGBAPixel< unsigned char > PixelType; + typedef otb::Image<PixelType,2> ImageType; + + ImageType::SizeType size; + size[0] = 500; + size[1] = 500; + + ImageType::PointType origin; + origin[0] = imageReader->GetOutput()->GetOrigin()[0]; + origin[1] = imageReader->GetOutput()->GetOrigin()[1]; + + ImageType::SpacingType spacing; +// spacing[0] = imageReader->GetOutput()->GetSpacing()[0]; +// spacing[1] = imageReader->GetOutput()->GetSpacing()[1]; + spacing[0] = imageReader->GetOutput()->GetLargestPossibleRegion().GetSize()[0]/static_cast<double>(size[0]); +// /imageReader->GetOutput()->GetSpacing()[0]; + spacing[1] = imageReader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]/static_cast<double>(size[1]); +// /imageReader->GetOutput()->GetSpacing()[1]; + + typedef otb::VectorDataToImageFilter<VectorDataType, ImageType> VectorDataToImageFilterType; + VectorDataToImageFilterType::Pointer vectorDataRendering = VectorDataToImageFilterType::New(); + vectorDataRendering->SetInput(projection->GetOutput()); + + vectorDataRendering->SetSize(size); + vectorDataRendering->SetOrigin(origin); + vectorDataRendering->SetSpacing(spacing); + + + //Save the image in a file + typedef otb::ImageFileWriter<ImageType> WriterType; + WriterType::Pointer writer = WriterType::New(); + writer->SetInput(vectorDataRendering->GetOutput()); + writer->SetFileName(argv[3]); + writer->Update(); + + + + return EXIT_SUCCESS; +} -- GitLab