Commit e3218b04 authored by Julien Michel's avatar Julien Michel

REFAC: Remove OrthoRectificationFilter and replace by GenericRSResampleImageFilter

parent 8b18cfd7
Pipeline #1099 failed with stages
in 23 minutes and 6 seconds
......@@ -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
......
......@@ -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();
......
/*
* 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
/*
* 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
......@@ -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()
......@@ -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);
......
......@@ -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());