From e3218b04186546bfd95feecf08182f5992eca05c Mon Sep 17 00:00:00 2001 From: Julien Michel <julien.michel@orfeo-toolbox.org> Date: Thu, 18 Apr 2019 11:41:14 +0000 Subject: [PATCH] REFAC: Remove OrthoRectificationFilter and replace by GenericRSResampleImageFilter --- ...votbGenericRSResampleImageFilterOutput.tif | 3 - ...esampleImageFilterOutputFromMap_GEOEYE.tif | 3 - ...mpleImageFilterOutputFromMap_QUICKBIRD.tif | 3 - ...pleImageFilterOutputFromMap_WORLDVIEW2.tif | 3 - .../Projections/OrthoRectificationExample.cxx | 28 +- Examples/Tutorials/OrthoFusion.cxx | 20 +- .../include/otbOrthoRectificationFilter.h | 116 -------- .../include/otbOrthoRectificationFilter.hxx | 79 ------ .../Filtering/Projection/test/CMakeLists.txt | 41 +-- ...CPsToRPCSensorModelImageFilterAndOrtho.cxx | 13 +- .../test/otbGenericRSResampleImageFilter.cxx | 255 +++++++----------- .../test/otbOrthoRectificationFilter.cxx | 144 ---------- .../test/otbProjectionTestDriver.cxx | 2 - 13 files changed, 121 insertions(+), 589 deletions(-) delete mode 100644 Data/Baseline/OTB/Images/prTvotbGenericRSResampleImageFilterOutput.tif delete mode 100644 Data/Baseline/OTB/Images/prTvotbGenericRSResampleImageFilterOutputFromMap_GEOEYE.tif delete mode 100644 Data/Baseline/OTB/Images/prTvotbGenericRSResampleImageFilterOutputFromMap_QUICKBIRD.tif delete mode 100644 Data/Baseline/OTB/Images/prTvotbGenericRSResampleImageFilterOutputFromMap_WORLDVIEW2.tif delete mode 100644 Modules/Filtering/Projection/include/otbOrthoRectificationFilter.h delete mode 100644 Modules/Filtering/Projection/include/otbOrthoRectificationFilter.hxx delete mode 100644 Modules/Filtering/Projection/test/otbOrthoRectificationFilter.cxx diff --git a/Data/Baseline/OTB/Images/prTvotbGenericRSResampleImageFilterOutput.tif b/Data/Baseline/OTB/Images/prTvotbGenericRSResampleImageFilterOutput.tif deleted file mode 100644 index 1582d4104b..0000000000 --- a/Data/Baseline/OTB/Images/prTvotbGenericRSResampleImageFilterOutput.tif +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:e6946443c79f0ee5e07b3c653958ce13e5d97e87cc9958cb13051c9d3d07e416 -size 9378087 diff --git a/Data/Baseline/OTB/Images/prTvotbGenericRSResampleImageFilterOutputFromMap_GEOEYE.tif b/Data/Baseline/OTB/Images/prTvotbGenericRSResampleImageFilterOutputFromMap_GEOEYE.tif deleted file mode 100644 index 5b30246782..0000000000 --- a/Data/Baseline/OTB/Images/prTvotbGenericRSResampleImageFilterOutputFromMap_GEOEYE.tif +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:8fb50d087c6620f8836274927849326dc2fb77a592ca64a2a3f116236248fd03 -size 59434 diff --git a/Data/Baseline/OTB/Images/prTvotbGenericRSResampleImageFilterOutputFromMap_QUICKBIRD.tif b/Data/Baseline/OTB/Images/prTvotbGenericRSResampleImageFilterOutputFromMap_QUICKBIRD.tif deleted file mode 100644 index ca2897289d..0000000000 --- a/Data/Baseline/OTB/Images/prTvotbGenericRSResampleImageFilterOutputFromMap_QUICKBIRD.tif +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:89fb4f4c776f753b71e48c74b4c46231a03ae57451ccfc87903b0b0cb4b7ad7c -size 41907 diff --git a/Data/Baseline/OTB/Images/prTvotbGenericRSResampleImageFilterOutputFromMap_WORLDVIEW2.tif b/Data/Baseline/OTB/Images/prTvotbGenericRSResampleImageFilterOutputFromMap_WORLDVIEW2.tif deleted file mode 100644 index 68f813382b..0000000000 --- a/Data/Baseline/OTB/Images/prTvotbGenericRSResampleImageFilterOutputFromMap_WORLDVIEW2.tif +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:cad5f798ddae790efa1d14ff57f7d0c25d5fd89f125961c0ba68c3923568ba05 -size 2656332 diff --git a/Examples/Projections/OrthoRectificationExample.cxx b/Examples/Projections/OrthoRectificationExample.cxx index 93bfecc168..e3a2f4d1c5 100644 --- a/Examples/Projections/OrthoRectificationExample.cxx +++ b/Examples/Projections/OrthoRectificationExample.cxx @@ -23,7 +23,7 @@ #include "otbImageFileWriter.h" // This example demonstrates the use of the -// \doxygen{otb}{OrthoRectificationFilter}. This filter is intended to +// \doxygen{otb}{GenericRSResampleImageFilter}. This filter is intended to // orthorectify images which are in a distributor format with the // appropriate meta-data describing the sensor model. In this example, // we will choose to use an UTM projection for the output image. @@ -32,7 +32,7 @@ // proper header files: the one for the ortho-rectification filter and // the one defining the different projections available in OTB. -#include "otbOrthoRectificationFilter.h" +#include "otbGenericRSResampleImageFilter.h" #include "otbSpatialReference.h" int main(int argc, char* argv[]) @@ -66,15 +66,12 @@ int main(int argc, char* argv[]) writer->SetFileName(argv[2]); // We can now proceed to declare the type for the ortho-rectification - // filter. The class \doxygen{otb}{OrthoRectificationFilter} is - // templated over the input and the output image types as well as over - // the cartographic projection. We define therefore the - // type of the projection we want, which is an UTM projection for this case. - -// Software Guide : BeginCodeSnippet - typedef otb::GenericMapProjection<otb::TransformDirection::FORWARD> MapProjectionType; - typedef otb::OrthoRectificationFilter<VectorImageType, VectorImageType, - MapProjectionType> + // filter. The class \doxygen{otb}{GenericRSResampleImageFilter} is + // templated over the input and the output image types. + + // Software Guide : BeginCodeSnippet + + typedef otb::GenericRSResampleImageFilter<VectorImageType, VectorImageType> OrthoRectifFilterType; OrthoRectifFilterType::Pointer orthoRectifFilter = OrthoRectifFilterType::New(); @@ -83,10 +80,9 @@ int main(int argc, char* argv[]) // instantiate the map projection, set the {\em zone} and {\em hemisphere} // parameters and pass this projection to the orthorectification filter. - MapProjectionType::Pointer utmMapProjection = MapProjectionType::New(); - utmMapProjection->SetWkt(otb::SpatialReference::FromUTM(atoi(argv[3]),*argv[4]=='N'? otb::SpatialReference::hemisphere::north : otb::SpatialReference::hemisphere::south).ToWkt()); - std::cout<<utmMapProjection->GetWkt()<<std::endl; - orthoRectifFilter->SetMapProjection(utmMapProjection); + std::string wkt = otb::SpatialReference::FromUTM(atoi(argv[3]),*argv[4]=='N'? otb::SpatialReference::hemisphere::north : otb::SpatialReference::hemisphere::south).ToWkt(); + std::cout<<wkt<<std::endl; + orthoRectifFilter->SetOutputProjectionRef(wkt); // We then wire the input image to the orthorectification filter. @@ -129,8 +125,6 @@ int main(int argc, char* argv[]) writer->SetInput(orthoRectifFilter->GetOutput()); - writer->SetAutomaticTiledStreaming(); - // Finally, we trigger the pipeline execution by calling the // \code{Update()} method on the writer. Please note that the // ortho-rectification filter is derived from the diff --git a/Examples/Tutorials/OrthoFusion.cxx b/Examples/Tutorials/OrthoFusion.cxx index a94f608086..c0ead29574 100644 --- a/Examples/Tutorials/OrthoFusion.cxx +++ b/Examples/Tutorials/OrthoFusion.cxx @@ -28,8 +28,7 @@ #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -#include "otbOrthoRectificationFilter.h" -#include "otbGenericMapProjection.h" +#include "otbGenericRSResampleImageFilter.h" #include "otbSimpleRcsPanSharpeningFusionImageFilter.h" #include "otbStandardFilterWatcher.h" @@ -89,12 +88,9 @@ int main(int argc, char* argv[]) // \item the hemisphere // \end{itemize} - typedef otb::GenericMapProjection<otb::TransformDirection::INVERSE> InverseProjectionType; - InverseProjectionType::Pointer utmMapProjection = InverseProjectionType::New(); - utmMapProjection->SetWkt( - otb::SpatialReference::FromUTM(atoi(argv[4]),argv[5][0]=='N' ? + std::string wkt = otb::SpatialReference::FromUTM(atoi(argv[4]),argv[5][0]=='N' ? otb::SpatialReference::hemisphere::north : - otb::SpatialReference::hemisphere::south).ToWkt()); + otb::SpatialReference::hemisphere::south).ToWkt(); // We will need to pass several parameters to the orthorectification // concerning the desired output region: @@ -118,10 +114,10 @@ int main(int argc, char* argv[]) // We declare the orthorectification filter. And provide the different // parameters: - typedef otb::OrthoRectificationFilter<ImageType, DoubleImageType, InverseProjectionType> OrthoRectifFilterType; + typedef otb::GenericRSResampleImageFilter<ImageType, DoubleImageType> OrthoRectifFilterType; OrthoRectifFilterType::Pointer orthoRectifPAN = OrthoRectifFilterType::New(); - orthoRectifPAN->SetMapProjection(utmMapProjection); + orthoRectifPAN->SetOutputProjectionRef(wkt); orthoRectifPAN->SetInput(readerPAN->GetOutput()); @@ -133,12 +129,12 @@ int main(int argc, char* argv[]) // Now we are able to have the orthorectified area from the PAN image. We just // have to follow a similar process for the XS image. - typedef otb::OrthoRectificationFilter<VectorImageType, DoubleVectorImageType, InverseProjectionType> VectorOrthoRectifFilterType; + typedef otb::GenericRSResampleImageFilter<VectorImageType, DoubleVectorImageType> VectorOrthoRectifFilterType; VectorOrthoRectifFilterType::Pointer orthoRectifXS = VectorOrthoRectifFilterType::New(); - orthoRectifXS->SetMapProjection(utmMapProjection); + orthoRectifXS->SetOutputProjectionRef(wkt); orthoRectifXS->SetInput(readerXS->GetOutput()); @@ -160,8 +156,6 @@ int main(int argc, char* argv[]) writer->SetInput(fusion->GetOutput()); - writer->SetAutomaticTiledStreaming(); - otb::StandardFilterWatcher watcher(writer, "OrthoFusion"); writer->Update(); diff --git a/Modules/Filtering/Projection/include/otbOrthoRectificationFilter.h b/Modules/Filtering/Projection/include/otbOrthoRectificationFilter.h deleted file mode 100644 index 056a1003cb..0000000000 --- a/Modules/Filtering/Projection/include/otbOrthoRectificationFilter.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef otbOrthoRectificationFilter_h -#define otbOrthoRectificationFilter_h - -#include <sstream> -#include <stdio.h> - -#include "otbGenericRSResampleImageFilter.h" -#include "otbCompositeTransform.h" -#include "otbInverseSensorModel.h" - -#include "otbVectorImage.h" -#include "otbImage.h" - -namespace otb -{ -/** \class OrthoRectificationFilter - * - * \brief Class for Orthorectifying an image - * - * This class is used to apply map projection and sensor model transformation - * to orthorectify an image, with or without DEM. - * - * \ingroup Projection - * - * \example Projections/OrthoRectificationExample.cxx - * - * - * \ingroup OTBProjection - */ - -template <class TInputImage, class TOutputImage, class TMapProjection, class TInterpolatorPrecision = double> -class ITK_EXPORT OrthoRectificationFilter : - public GenericRSResampleImageFilter<TInputImage, TOutputImage> -{ -public: - /** Standard class typedefs */ - typedef GenericRSResampleImageFilter<TInputImage, - TOutputImage> Superclass; - typedef OrthoRectificationFilter Self; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - /** types definitions */ - typedef typename TInputImage::IndexType IndexType; - typedef typename TInputImage::SizeType SizeType; - typedef typename TInputImage::SpacingType SpacingType; - typedef typename TInputImage::PointType PointType; - typedef typename TInputImage::RegionType RegionType; - - typedef typename TOutputImage::PixelType OutputPixelType; - - /** output map projection */ - typedef TMapProjection MapProjectionType; - typedef typename TMapProjection::Pointer MapProjectionPointerType; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** Run-time type information (and related methods). */ - itkTypeMacro(OrthoRectificationFilter, GenericRSResampleImageFilter); - - /** Accessors */ - virtual void SetMapProjection(MapProjectionType* arg) - { - if (this->m_MapProjection != arg) - { - this->m_MapProjection = arg; - this->Modified(); - } - } - itkGetObjectMacro(MapProjection, MapProjectionType); - -protected: - OrthoRectificationFilter(); - ~OrthoRectificationFilter() override; - void PrintSelf(std::ostream& os, itk::Indent indent) const override; - - void GenerateInputRequestedRegion() override; - void GenerateOutputInformation(void) override; - -private: - OrthoRectificationFilter(const Self &) = delete; - void operator =(const Self&) = delete; - - /** Map Projection used to transform cartographic coordinates in geographic coordinates */ - MapProjectionPointerType m_MapProjection; - -}; - -} // namespace otb - -#ifndef OTB_MANUAL_INSTANTIATION -#include "otbOrthoRectificationFilter.hxx" -#endif - -#endif diff --git a/Modules/Filtering/Projection/include/otbOrthoRectificationFilter.hxx b/Modules/Filtering/Projection/include/otbOrthoRectificationFilter.hxx deleted file mode 100644 index c383f86a9c..0000000000 --- a/Modules/Filtering/Projection/include/otbOrthoRectificationFilter.hxx +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef otbOrthoRectificationFilter_hxx -#define otbOrthoRectificationFilter_hxx - -#include "otbOrthoRectificationFilter.h" -#include "itkMetaDataObject.h" - -namespace otb -{ - -template <class TInputImage, class TOutputImage, class TMapProjection, class TInterpolatorPrecision> -OrthoRectificationFilter<TInputImage, TOutputImage, TMapProjection, TInterpolatorPrecision> -::OrthoRectificationFilter(): m_MapProjection(nullptr) -{} - -template <class TInputImage, class TOutputImage, class TMapProjection, class TInterpolatorPrecision> -OrthoRectificationFilter<TInputImage, TOutputImage, TMapProjection, TInterpolatorPrecision> -::~OrthoRectificationFilter() -{} - -template <class TInputImage, class TOutputImage, class TMapProjection, class TInterpolatorPrecision> -void OrthoRectificationFilter<TInputImage, TOutputImage, TMapProjection, TInterpolatorPrecision> -::PrintSelf(std::ostream& os, itk::Indent indent) const -{ - Superclass::PrintSelf(os, indent); - os << indent << "OrthoRectification" << "\n"; -} - -template <class TInputImage, class TOutputImage, class TMapProjection, class TInterpolatorPrecision> -void -OrthoRectificationFilter<TInputImage, TOutputImage, TMapProjection, TInterpolatorPrecision> -::GenerateInputRequestedRegion() -{ - Superclass::GenerateInputRequestedRegion(); -} - -template <class TInputImage, class TOutputImage, class TMapProjection, class TInterpolatorPrecision> -void -OrthoRectificationFilter<TInputImage, TOutputImage, TMapProjection, TInterpolatorPrecision> -::GenerateOutputInformation() -{ - // call the superclass' implementation of this method - Superclass::GenerateOutputInformation(); - - if(!m_MapProjection.IsNull() && !m_MapProjection->GetWkt().empty()) - { - // fill up the metadata information for ProjectionRef - itk::MetaDataDictionary& dict = this->GetOutput()->GetMetaDataDictionary(); - std::string projectionRef = m_MapProjection->GetWkt(); - itk::EncapsulateMetaData<std::string>(dict, MetaDataKey::ProjectionRefKey, projectionRef); - - // Fill the GenericRSTransform with those information - this->SetOutputProjectionRef(projectionRef); - this->UpdateTransform(); - } -} - -} //namespace otb - -#endif diff --git a/Modules/Filtering/Projection/test/CMakeLists.txt b/Modules/Filtering/Projection/test/CMakeLists.txt index 7a8ba7c02d..6600aad060 100644 --- a/Modules/Filtering/Projection/test/CMakeLists.txt +++ b/Modules/Filtering/Projection/test/CMakeLists.txt @@ -24,7 +24,6 @@ set(OTBProjectionTests otbSensorModel.cxx otbProjectionTestDriver.cxx otbVectorDataProjectionFilterFromGeoToMap.cxx -otbOrthoRectificationFilter.cxx otbGenericRSResampleImageFilter.cxx otbGeometriesProjectionFilter.cxx otbGenericRSTransformGenericTest.cxx @@ -312,7 +311,7 @@ foreach(current_img ${IMG_TEST_ORTHO}) otb_add_test(NAME prTvOrthoRectification_${current_imgtype}_${current_mode} COMMAND otbProjectionTestDriver --compare-image ${EPSILON_4} ${BASELINE}/prTvOrthoRectification_${current_imgtype}_${current_mode}.tif ${TEMP}/prTvOrthoRectification_${current_imgtype}_${current_mode}.tif - otbOrthoRectificationFilter + otbGenericRSResampleImageFilter LARGEINPUT{${current_img}?&geom=${INPUTDATA}/${current_geomgcp}.geom} ${TEMP}/prTvOrthoRectification_${current_imgtype}_${current_mode}.tif ${current_originx} @@ -335,19 +334,6 @@ endforeach() #----------------- OrthoRectification tests (end) ----------------------- #------------------------------------------------------------------------ -otb_add_test(NAME prTvotbGenericRSResampleImageFilter COMMAND otbProjectionTestDriver - --compare-image ${EPSILON_4} - ${BASELINE}/prTvotbGenericRSResampleImageFilterOutput.tif - ${TEMP}/prTvotbGenericRSResampleImageFilterOutput.tif - otbGenericRSResampleImageFilter - LARGEINPUT{QUICKBIRD/TOULOUSE/000000128955_01_P001_PAN/02APR01105228-P1BS-000000128955_01_P001.TIF} - 1000 - 15 - 0 - 1 - ${TEMP}/prTvotbGenericRSResampleImageFilterOutput.tif - ) - otb_add_test(NAME prTvGeometriesProjectionFilterLines COMMAND otbProjectionTestDriver --compare-ogr ${EPSILON_9} ${BASELINE_FILES}/prTvVectorDataProjectionFilterLines.shp @@ -1185,28 +1171,3 @@ set(GenericConversionChecking_INPUTS #${INPUTDATA}/DEM/srtm_directory #3 ) #endforeach() - - - - set(SENSOR_TYPES - "QUICKBIRD/TOULOUSE/000000128955_01_P001_PAN/02APR01105228-P1BS-000000128955_01_P001.TIF" - "GEOEYE/LES_ROCHES/po_350134_bgrn_0000000.tif" - "WORLDVIEW2/ROME/WV-2_standard_8band_bundle_16bit/052298844010_01_P001_MUL/09DEC10103019-M2AS-052298844010_01_P001.TIF" - ) - - foreach( file ${SENSOR_TYPES}) - # Get the sensor name - set(sharp_regexp "([0-9A-Za-z_]*)[ ]*/[ ]*(.*)") - string(REGEX REPLACE "${sharp_regexp}" "\\1" sensor_name "${file}") - # Tests - otb_add_test(NAME prTvotbGenericRSResampleImageFilterFromMap_${sensor_name} COMMAND otbProjectionTestDriver - --compare-image ${EPSILON_4} - ${BASELINE}/prTvotbGenericRSResampleImageFilterOutputFromMap_${sensor_name}.tif - ${TEMP}/prTvotbGenericRSResampleImageFilterOutputFromMap_${sensor_name}.tif - otbGenericRSResampleImageFilterFromMap - LARGEINPUT{${file}} - 15 - 0 - ${TEMP}/prTvotbGenericRSResampleImageFilterOutputFromMap_${sensor_name}.tif - ) - endforeach() diff --git a/Modules/Filtering/Projection/test/otbGCPsToRPCSensorModelImageFilterAndOrtho.cxx b/Modules/Filtering/Projection/test/otbGCPsToRPCSensorModelImageFilterAndOrtho.cxx index 20dc63f23e..f9eb115fcf 100644 --- a/Modules/Filtering/Projection/test/otbGCPsToRPCSensorModelImageFilterAndOrtho.cxx +++ b/Modules/Filtering/Projection/test/otbGCPsToRPCSensorModelImageFilterAndOrtho.cxx @@ -21,8 +21,7 @@ #include "otbImageFileReader.h" #include "otbGCPsToRPCSensorModelImageFilter.h" #include "otbImageFileWriter.h" -#include "otbGenericMapProjection.h" -#include "otbOrthoRectificationFilter.h" +#include "otbGenericRSResampleImageFilter.h" #include "otbMacro.h" int otbGCPsToRPCSensorModelImageFilterAndOrtho(int argc, char* argv[]) @@ -47,8 +46,7 @@ int otbGCPsToRPCSensorModelImageFilterAndOrtho(int argc, char* argv[]) typedef GCPsToSensorModelFilterType::Point2DType Point2DType; typedef GCPsToSensorModelFilterType::Point3DType Point3DType; typedef otb::ImageFileWriter<ImageType> WriterType; - typedef otb::GenericMapProjection<otb::TransformDirection::INVERSE> MapProjectionType; - typedef otb::OrthoRectificationFilter<ImageType, ImageType, MapProjectionType> OrthoRectifFilterType; + typedef otb::GenericRSResampleImageFilter<ImageType, ImageType> OrthoRectifFilterType; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(infname); @@ -91,9 +89,6 @@ int otbGCPsToRPCSensorModelImageFilterAndOrtho(int argc, char* argv[]) OrthoRectifFilterType::Pointer orthoRectifFilter = OrthoRectifFilterType::New(); - - MapProjectionType::Pointer utmMapProjection = MapProjectionType::New(); - orthoRectifFilter->SetInput(rpcEstimator->GetOutput()); ImageType::IndexType start; @@ -116,9 +111,9 @@ int otbGCPsToRPCSensorModelImageFilterAndOrtho(int argc, char* argv[]) origin[1] = strtod(argv[4], nullptr); //Origin northing orthoRectifFilter->SetOutputOrigin(origin); - utmMapProjection->SetWkt(otb::SpatialReference::FromUTM(atoi(argv[9]),argv[10][0]=='N'?otb::SpatialReference::hemisphere::north : otb::SpatialReference::hemisphere::south).ToWkt()); + std::string wkt = otb::SpatialReference::FromUTM(atoi(argv[9]),argv[10][0]=='N'?otb::SpatialReference::hemisphere::north : otb::SpatialReference::hemisphere::south).ToWkt(); - orthoRectifFilter->SetMapProjection(utmMapProjection); + orthoRectifFilter->SetOutputProjectionRef(wkt); ImageType::PixelType no_data(reader->GetOutput()->GetNumberOfComponentsPerPixel()); no_data.Fill(0.0); diff --git a/Modules/Filtering/Projection/test/otbGenericRSResampleImageFilter.cxx b/Modules/Filtering/Projection/test/otbGenericRSResampleImageFilter.cxx index c61ad46200..31027d1eae 100644 --- a/Modules/Filtering/Projection/test/otbGenericRSResampleImageFilter.cxx +++ b/Modules/Filtering/Projection/test/otbGenericRSResampleImageFilter.cxx @@ -19,183 +19,124 @@ */ -#include "otbGenericRSResampleImageFilter.h" + +// iostream is used for general output +#include <iostream> +#include <stdlib.h> +#include <complex> #include "otbImageFileReader.h" #include "otbImageFileWriter.h" +#include "otbGenericMapProjection.h" +#include "itkUnaryFunctorImageFilter.h" -#include <ogr_spatialref.h> - -// Extract ROI -#include "otbMultiChannelExtractROI.h" - -// Images definition -const unsigned int Dimension = 2; -typedef double PixelType; -typedef otb::VectorImage<PixelType, Dimension> ImageType; -typedef ImageType::SizeType SizeType; - -typedef otb::GenericRSResampleImageFilter<ImageType, - ImageType> ImageResamplerType; -typedef ImageResamplerType::OriginType OriginType; -typedef ImageResamplerType::SpacingType SpacingType; - -typedef otb::ImageFileReader<ImageType> ReaderType; -typedef otb::ImageFileWriter<ImageType> WriterType; - +#include "otbDEMHandler.h" +#include "otbUnaryImageFunctorWithVectorImageFilter.h" +#include "otbGenericRSResampleImageFilter.h" +#include "otbComplexToIntensityImageFilter.h" +#include "otbPerBandVectorImageFilter.h" -int otbGenericRSResampleImageFilter(int itkNotUsed(argc), char* argv[]) +int otbGenericRSResampleImageFilter(int argc, char* argv[]) { + if (argc != 15) + { + std::cout << argv[0] << + " <input filename> <output filename> <origin easting> <origin northing>" + " <x size> <y size> <x spacing> <y spacing> <UTM zone> <UTM hemisphere>" + " <grid_spacing> <mode> <mode.info> <is_complex>" + << std::endl; - // SmartPointer instantiation - ImageResamplerType::Pointer resampler = ImageResamplerType::New(); - - const char * infname = argv[1]; - const char * outfname = argv[6]; - unsigned int isize = atoi(argv[2]); - double iGridSpacing = atof(argv[3]); - int useInRpc = atoi(argv[4]); - int useOutRpc = atoi(argv[5]); - - - ReaderType::Pointer reader = ReaderType::New(); - - // Read the input image - reader->SetFileName(infname); - reader->UpdateOutputInformation(); - - // Fill the output size with the user selection - SizeType size; - size.Fill(isize); - - // Set the origin & the spacing of the output - OriginType origin; - origin[0] = 367340; - origin[1] = 4.83467e+06; - - SpacingType spacing; - spacing[0] = 0.6; - spacing[1] = -0.6; - - // Build the output projection ref : UTM ref - OGRSpatialReference oSRS; - oSRS.SetProjCS("UTM"); - oSRS.SetUTM(31, true); - char * utmRef = nullptr; - oSRS.exportToWkt(&utmRef); + return EXIT_FAILURE; + } - // Displacement Field spacing - SpacingType gridSpacing; - gridSpacing[0] = iGridSpacing; - gridSpacing[1] = -iGridSpacing; - - // Default value builder - ImageType::PixelType defaultValue; - itk::NumericTraits<ImageType::PixelType>::SetLength(defaultValue, reader->GetOutput()->GetNumberOfComponentsPerPixel()); - - // Set the Resampler Parameters - resampler->SetInput(reader->GetOutput()); - resampler->SetDisplacementFieldSpacing(gridSpacing); - resampler->SetOutputOrigin(origin); - resampler->SetOutputSize(size); - resampler->SetOutputSpacing(spacing); - resampler->SetOutputProjectionRef(utmRef); - resampler->SetEdgePaddingValue(defaultValue); - if (useInRpc) + typedef std::complex<double> ComplexPixelType; + typedef otb::VectorImage<ComplexPixelType,2> ComplexVectorImageType; + typedef otb::VectorImage<double, 2> VectorImageType; + typedef otb::ImageFileReader<VectorImageType> ReaderType; + typedef otb::ImageFileReader<ComplexVectorImageType> ComplexReaderType; + typedef otb::ImageFileWriter<VectorImageType> WriterType; + + // Handling of complex images + typedef otb::Image<ComplexPixelType> ComplexImageType; + typedef otb::Image<double> ImageType; + typedef otb::ComplexToIntensityImageFilter<ComplexImageType, ImageType> IntensityFilterType; + typedef otb::PerBandVectorImageFilter<ComplexVectorImageType,VectorImageType,IntensityFilterType> PerBandIntensityFilterType; + typedef otb::GenericRSResampleImageFilter<VectorImageType, VectorImageType> OrthoRectifFilterType; + + //Allocate pointer + ReaderType::Pointer reader = ReaderType::New(); + ComplexReaderType::Pointer cReader = ComplexReaderType::New(); + WriterType::Pointer writer = WriterType::New(); + PerBandIntensityFilterType::Pointer intensityFilter = PerBandIntensityFilterType::New(); + + OrthoRectifFilterType::Pointer orthoRectifFilter = OrthoRectifFilterType::New(); + + writer->SetFileName(argv[2]); + + bool isComplex = atoi(argv[14]); + + if(isComplex) { - resampler->SetInputRpcGridSize(20); - resampler->EstimateInputRpcModelOn(); + cReader->SetFileName(argv[1]); + cReader->GenerateOutputInformation(); + intensityFilter->SetInput(cReader->GetOutput()); + VectorImageType::PixelType no_data(cReader->GetOutput()->GetNumberOfComponentsPerPixel()); + no_data.Fill(0); + orthoRectifFilter->SetEdgePaddingValue(no_data); + orthoRectifFilter->SetInput(intensityFilter->GetOutput()); } - - if (useOutRpc) + else { - resampler->SetOutputRpcGridSize(20); - resampler->EstimateOutputRpcModelOn(); + reader->SetFileName(argv[1]); + reader->GenerateOutputInformation(); + VectorImageType::PixelType no_data(reader->GetOutput()->GetNumberOfComponentsPerPixel()); + no_data.Fill(0); + orthoRectifFilter->SetEdgePaddingValue(no_data); + orthoRectifFilter->SetInput(reader->GetOutput()); } + VectorImageType::IndexType start; + start[0] = 0; + start[1] = 0; + orthoRectifFilter->SetOutputStartIndex(start); - // Write the resampled image - WriterType::Pointer writer= WriterType::New(); - writer->SetNumberOfDivisionsTiledStreaming(4); - writer->SetFileName(outfname); - writer->SetInput(resampler->GetOutput()); - writer->Update(); + VectorImageType::SizeType size; + size[0] = atoi(argv[5]); // X size + size[1] = atoi(argv[6]); //Y size + orthoRectifFilter->SetOutputSize(size); - std::cout << resampler << std::endl; + VectorImageType::SpacingType spacing; + spacing[0] = atof(argv[7]); + spacing[1] = atof(argv[8]); + orthoRectifFilter->SetOutputSpacing(spacing); - return EXIT_SUCCESS; -} - - -int otbGenericRSResampleImageFilterFromMap(int itkNotUsed(argc), char* argv[]) -{ - typedef otb::MultiChannelExtractROI<PixelType, PixelType> ExtractROIType; - - // SmartPointer instantiation - ExtractROIType::Pointer extractor = ExtractROIType::New(); - ImageResamplerType::Pointer resampler = ImageResamplerType::New(); + VectorImageType::PointType origin; + origin[0] = strtod(argv[3], nullptr); //Origin easting + origin[1] = strtod(argv[4], nullptr); //Origin northing + orthoRectifFilter->SetOutputOrigin(origin); - const char * infname = argv[1]; - const char * outfname = argv[4]; - double iGridSpacing = atof(argv[2]); - int useInRpc = atoi(argv[3]); - - // Reader Instantiation - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(infname); - reader->UpdateOutputInformation(); - - SpacingType spacing; - spacing[0] = 2.5; - spacing[1] = -2.5; + std::string wkt = otb::SpatialReference::FromUTM(atoi(argv[9]),atoi(argv[10]) ? otb::SpatialReference::hemisphere::north : otb::SpatialReference::hemisphere::south).ToWkt(); + orthoRectifFilter->SetOutputProjectionRef(wkt); // Displacement Field spacing - SpacingType gridSpacing; - gridSpacing[0] = iGridSpacing; - gridSpacing[1] = -iGridSpacing; - - // Default value builder - ImageType::PixelType defaultValue; - itk::NumericTraits<ImageType::PixelType>::SetLength(defaultValue, reader->GetOutput()->GetNumberOfComponentsPerPixel()); - - // Extract a roi centered on the input center - ImageType::RegionType roi; - ImageType::IndexType roiIndex; - SizeType roiSize; - - // Fill the size - roiSize.Fill(250); - - // Fill the start index - roiIndex[0] = (unsigned int)((reader->GetOutput()->GetLargestPossibleRegion().GetSize()[0] - roiSize[0]) /2); - roiIndex[1] = (unsigned int)((reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1] - roiSize[1]) /2); - - roi.SetIndex(roiIndex); - roi.SetSize(roiSize); - - extractor->SetExtractionRegion(roi); - extractor->SetInput(reader->GetOutput()); - extractor->UpdateOutputInformation(); - - // Set the Resampler Parameters - resampler->SetInput(extractor->GetOutput()); - resampler->SetDisplacementFieldSpacing(gridSpacing); - resampler->SetOutputParametersFromMap("UTM", spacing); - - if (useInRpc) - { - resampler->SetInputRpcGridSize(20); - resampler->EstimateInputRpcModelOn(); - } - - // Write the resampled image - WriterType::Pointer writer= WriterType::New(); - writer->SetAutomaticTiledStreaming(); - writer->SetFileName(outfname); - writer->SetInput(resampler->GetOutput()); + VectorImageType::SpacingType gridSpacing; + gridSpacing[0] = atof(argv[11]); + gridSpacing[1] = -atof(argv[11]); + orthoRectifFilter->SetDisplacementFieldSpacing(gridSpacing); + + // manage demHandler + if (atoi(argv[12])==1) //mode = no DEM + { + otb::DEMHandler::Instance()->SetDefaultHeightAboveEllipsoid(135.8); + } + else if ( (atoi(argv[12])==2) || (atoi(argv[12])==3) ) //mode = DEM SRTM || DEM GTIFF + { + otb::DEMHandler::Instance()->OpenDEMDirectory(argv[13]); + } + + writer->SetInput(orthoRectifFilter->GetOutput()); + writer->SetNumberOfDivisionsTiledStreaming(4); writer->Update(); - std::cout << resampler << std::endl; - return EXIT_SUCCESS; } diff --git a/Modules/Filtering/Projection/test/otbOrthoRectificationFilter.cxx b/Modules/Filtering/Projection/test/otbOrthoRectificationFilter.cxx deleted file mode 100644 index e832b5dc0f..0000000000 --- a/Modules/Filtering/Projection/test/otbOrthoRectificationFilter.cxx +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - - -// iostream is used for general output -#include <iostream> -#include <stdlib.h> -#include <complex> - -#include "otbImageFileReader.h" -#include "otbImageFileWriter.h" -#include "otbGenericMapProjection.h" -#include "itkUnaryFunctorImageFilter.h" -//#include "itkComplexToModulusImageFilter.h" -#include "otbDEMHandler.h" -#include "otbUnaryImageFunctorWithVectorImageFilter.h" -#include "otbOrthoRectificationFilter.h" -#include "otbComplexToIntensityImageFilter.h" -#include "otbPerBandVectorImageFilter.h" - -int otbOrthoRectificationFilter(int argc, char* argv[]) -{ - if (argc != 15) - { - std::cout << argv[0] << - " <input filename> <output filename> <origin easting> <origin northing>" - " <x size> <y size> <x spacing> <y spacing> <UTM zone> <UTM hemisphere>" - " <grid_spacing> <mode> <mode.info> <is_complex>" - << std::endl; - - return EXIT_FAILURE; - } - - typedef std::complex<double> ComplexPixelType; - typedef otb::VectorImage<ComplexPixelType,2> ComplexVectorImageType; - typedef otb::VectorImage<double, 2> VectorImageType; - typedef otb::ImageFileReader<VectorImageType> ReaderType; - typedef otb::ImageFileReader<ComplexVectorImageType> ComplexReaderType; - typedef otb::ImageFileWriter<VectorImageType> WriterType; - - // Handling of complex images - typedef otb::Image<ComplexPixelType> ComplexImageType; - typedef otb::Image<double> ImageType; - typedef otb::ComplexToIntensityImageFilter<ComplexImageType, ImageType> IntensityFilterType; - typedef otb::PerBandVectorImageFilter<ComplexVectorImageType,VectorImageType,IntensityFilterType> PerBandIntensityFilterType; - typedef otb::GenericMapProjection<otb::TransformDirection::INVERSE> MapProjectionType; - typedef otb::OrthoRectificationFilter<VectorImageType, VectorImageType, MapProjectionType> OrthoRectifFilterType; - - //Allocate pointer - ReaderType::Pointer reader = ReaderType::New(); - ComplexReaderType::Pointer cReader = ComplexReaderType::New(); - WriterType::Pointer writer = WriterType::New(); - PerBandIntensityFilterType::Pointer intensityFilter = PerBandIntensityFilterType::New(); - - OrthoRectifFilterType::Pointer orthoRectifFilter = OrthoRectifFilterType::New(); - - writer->SetFileName(argv[2]); - - bool isComplex = atoi(argv[14]); - - if(isComplex) - { - cReader->SetFileName(argv[1]); - cReader->GenerateOutputInformation(); - intensityFilter->SetInput(cReader->GetOutput()); - VectorImageType::PixelType no_data(cReader->GetOutput()->GetNumberOfComponentsPerPixel()); - no_data.Fill(0); - orthoRectifFilter->SetEdgePaddingValue(no_data); - orthoRectifFilter->SetInput(intensityFilter->GetOutput()); - } - else - { - reader->SetFileName(argv[1]); - reader->GenerateOutputInformation(); - VectorImageType::PixelType no_data(reader->GetOutput()->GetNumberOfComponentsPerPixel()); - no_data.Fill(0); - orthoRectifFilter->SetEdgePaddingValue(no_data); - orthoRectifFilter->SetInput(reader->GetOutput()); - } - - VectorImageType::IndexType start; - start[0] = 0; - start[1] = 0; - orthoRectifFilter->SetOutputStartIndex(start); - - VectorImageType::SizeType size; - size[0] = atoi(argv[5]); // X size - size[1] = atoi(argv[6]); //Y size - orthoRectifFilter->SetOutputSize(size); - - VectorImageType::SpacingType spacing; - spacing[0] = atof(argv[7]); - spacing[1] = atof(argv[8]); - orthoRectifFilter->SetOutputSpacing(spacing); - - VectorImageType::PointType origin; - origin[0] = strtod(argv[3], nullptr); //Origin easting - origin[1] = strtod(argv[4], nullptr); //Origin northing - orthoRectifFilter->SetOutputOrigin(origin); - - MapProjectionType::Pointer utmMapProjection = MapProjectionType::New(); - utmMapProjection->SetWkt(otb::SpatialReference::FromUTM(atoi(argv[9]),atoi(argv[10]) ? otb::SpatialReference::hemisphere::north : otb::SpatialReference::hemisphere::south).ToWkt()); - orthoRectifFilter->SetMapProjection(utmMapProjection); - - // Displacement Field spacing - VectorImageType::SpacingType gridSpacing; - gridSpacing[0] = atof(argv[11]); - gridSpacing[1] = -atof(argv[11]); - orthoRectifFilter->SetDisplacementFieldSpacing(gridSpacing); - - // manage demHandler - if (atoi(argv[12])==1) //mode = no DEM - { - otb::DEMHandler::Instance()->SetDefaultHeightAboveEllipsoid(135.8); - } - else if ( (atoi(argv[12])==2) || (atoi(argv[12])==3) ) //mode = DEM SRTM || DEM GTIFF - { - otb::DEMHandler::Instance()->OpenDEMDirectory(argv[13]); - } - - writer->SetInput(orthoRectifFilter->GetOutput()); - writer->SetNumberOfDivisionsTiledStreaming(4); - writer->Update(); - - return EXIT_SUCCESS; -} diff --git a/Modules/Filtering/Projection/test/otbProjectionTestDriver.cxx b/Modules/Filtering/Projection/test/otbProjectionTestDriver.cxx index 6a0d8992d5..acbe2a1640 100644 --- a/Modules/Filtering/Projection/test/otbProjectionTestDriver.cxx +++ b/Modules/Filtering/Projection/test/otbProjectionTestDriver.cxx @@ -24,9 +24,7 @@ void RegisterTests() { REGISTER_TEST(otbSensorModel); REGISTER_TEST(otbVectorDataProjectionFilterFromGeoToMap); - REGISTER_TEST(otbOrthoRectificationFilter); REGISTER_TEST(otbGenericRSResampleImageFilter); - REGISTER_TEST(otbGenericRSResampleImageFilterFromMap); REGISTER_TEST(otbGeometriesProjectionFilter); REGISTER_TEST(otbGenericRSTransformGenericTest); REGISTER_TEST(otbVectorDataTransformFilter); -- GitLab