From 2c727a4f2152e22b97a586dd1631f18aa06672c9 Mon Sep 17 00:00:00 2001 From: Otmane Lahlou <otmane.lahlou@c-s.fr> Date: Fri, 24 Feb 2012 11:12:18 +0100 Subject: [PATCH] TEST: VectorDataToLabelImage test --- Testing/Code/BasicFilters/CMakeLists.txt | 17 ++++ .../BasicFilters/otbBasicFiltersTests15.cxx | 2 + .../otbVectorDataToLabelImageFilter.cxx | 79 +++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 Testing/Code/BasicFilters/otbVectorDataToLabelImageFilter.cxx diff --git a/Testing/Code/BasicFilters/CMakeLists.txt b/Testing/Code/BasicFilters/CMakeLists.txt index 5d10d5bd5f..64ebb75a8d 100644 --- a/Testing/Code/BasicFilters/CMakeLists.txt +++ b/Testing/Code/BasicFilters/CMakeLists.txt @@ -2503,6 +2503,22 @@ ADD_TEST(bfTvVectorDataRasterizeFilterKML ${BASICFILTERS_TESTS15} ${TEMP}/bfTvVectorDataRasterizeFilter_OutputKML.tif ) +# --------------------- otbRasterizeVectorDataFilter--------------------- +ADD_TEST(bfTuVectorDataToLabelImageFilterNew ${BASICFILTERS_TESTS15} + otbVectorDataToLabelImageFilterNew +) + +ADD_TEST(bfTvVectorDataToLabelImageFilterSHP ${BASICFILTERS_TESTS15} + --compare-image 0.0 + ${INPUTDATA}/QB_Toulouse_ortho_labelImage.tif + ${TEMP}/bfTvVectorDataToLabelImageFilter_Output.tif + otbVectorDataToLabelImageFilter + ${INPUTDATA}/QB_Toulouse_ortho_labelImage.tif + ${INPUTDATA}/QB_Toulouse_ortho.shp + ${TEMP}/bfTvVectorDataToLabelImageFilter_Output.tif +) + + # A enrichir SET(BasicFilters_SRCS1 otbBasicFiltersTests1.cxx @@ -2791,6 +2807,7 @@ otbThresholdVectorImageFilter.cxx otbClampVectorImageFilter.cxx otbClampImageFilter.cxx otbVectorDataRasterizeFilter.cxx +otbVectorDataToLabelImageFilter.cxx ) OTB_ADD_EXECUTABLE(otbBasicFiltersTests1 "${BasicFilters_SRCS1}" "OTBBasicFilters;OTBIO;OTBTesting") diff --git a/Testing/Code/BasicFilters/otbBasicFiltersTests15.cxx b/Testing/Code/BasicFilters/otbBasicFiltersTests15.cxx index 8c8693b413..4cea1f133b 100644 --- a/Testing/Code/BasicFilters/otbBasicFiltersTests15.cxx +++ b/Testing/Code/BasicFilters/otbBasicFiltersTests15.cxx @@ -45,4 +45,6 @@ void RegisterTests() REGISTER_TEST(otbClampImageFilterTest); REGISTER_TEST(otbVectorDataRasterizeFilterNew); REGISTER_TEST(otbVectorDataRasterizeFilter); + REGISTER_TEST(otbVectorDataToLabelImageFilterNew); + REGISTER_TEST(otbVectorDataToLabelImageFilter); } diff --git a/Testing/Code/BasicFilters/otbVectorDataToLabelImageFilter.cxx b/Testing/Code/BasicFilters/otbVectorDataToLabelImageFilter.cxx new file mode 100644 index 0000000000..b41bf35df1 --- /dev/null +++ b/Testing/Code/BasicFilters/otbVectorDataToLabelImageFilter.cxx @@ -0,0 +1,79 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + Copyright (c) Institut Telecom; Telecom Bretagne. All rights reserved. + See ITCopyright.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 "otbImage.h" +#include "otbImageFileReader.h" +#include "otbStreamingImageFileWriter.h" + +#include "otbVectorData.h" +#include "otbVectorDataFileReader.h" +#include "otbVectorDataProjectionFilter.h" + +#include "otbVectorDataToLabelImageFilter.h" +#include "otbStandardOneLineFilterWatcher.h" + +typedef otb::Image<unsigned int, 2> ImageType; +typedef otb::VectorData<> VectorDataType; +typedef otb::ImageFileReader<ImageType> ReaderType; +typedef otb::VectorDataFileReader<VectorDataType> VDReaderType; +typedef otb::VectorDataProjectionFilter<VectorDataType, + VectorDataType> VDProjectionType; +typedef otb::StreamingImageFileWriter<ImageType> WriterType; +typedef otb::VectorDataToLabelImageFilter<VectorDataType, + ImageType> RasterizationFilterType; + +int otbVectorDataToLabelImageFilterNew(int argc, char* argv[]) +{ + RasterizationFilterType::Pointer rasterization = RasterizationFilterType::New(); + return EXIT_SUCCESS; +} + +int otbVectorDataToLabelImageFilter(int argc, char* argv[]) +{ + + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(argv[1]); + reader->UpdateOutputInformation(); + + // Read and project the vd into the raster coordinates images + VDReaderType::Pointer vdreader = VDReaderType::New(); + vdreader->SetFileName(argv[2]); + + VDProjectionType::Pointer vdproj = VDProjectionType::New(); + vdproj->SetInput(vdreader->GetOutput()); + vdproj->SetInputProjectionRef(vdreader->GetOutput()->GetProjectionRef()); + vdproj->SetOutputProjectionRef(reader->GetOutput()->GetProjectionRef()); + vdproj->Update(); + + // rasterize + RasterizationFilterType::Pointer rasterization = RasterizationFilterType::New(); + rasterization->AddVectorData(vdproj->GetOutput()); + rasterization->SetOutputParametersFromImage(reader->GetOutput()); + rasterization->SetBurnAttribute("DN"); + + otb::StandardOneLineFilterWatcher * watch = new otb::StandardOneLineFilterWatcher(rasterization.GetPointer(), + "rasterization"); + + WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(argv[3]); + writer->SetInput(rasterization->GetOutput()); + writer->Update(); + +return EXIT_SUCCESS; +} -- GitLab