From e841e5b21a5346e05a469c70563aff12ec63df49 Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@cnes.fr>
Date: Mon, 14 Mar 2016 15:13:54 +0100
Subject: [PATCH] ENH: Using the new, faster filter for zooming xs image in phr
 mode (in applications Superimpose and BundleToPerfectSensor)

---
 .../app/otbBundleToPerfectSensor.cxx          | 20 ++++++++++++----
 .../AppProjection/app/otbSuperimpose.cxx      | 23 +++++++++++--------
 2 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/Modules/Applications/AppFusion/app/otbBundleToPerfectSensor.cxx b/Modules/Applications/AppFusion/app/otbBundleToPerfectSensor.cxx
index 51b77af142..8fe879ccf4 100644
--- a/Modules/Applications/AppFusion/app/otbBundleToPerfectSensor.cxx
+++ b/Modules/Applications/AppFusion/app/otbBundleToPerfectSensor.cxx
@@ -19,6 +19,7 @@
 
 #include "otbMultiToMonoChannelExtractROI.h"
 #include "otbGenericRSResampleImageFilter.h"
+#include "otbGridResampleImageFilter.h"
 #include "otbImportGeoInformationImageFilter.h"
 #include "otbBCOInterpolateImageFunction.h"
 #include "otbSimpleRcsPanSharpeningFusionImageFilter.h"
@@ -133,7 +134,7 @@ private:
 
     typedef otb::BCOInterpolateImageFunction<FloatVectorImageType> InterpolatorType;
     typedef otb::GenericRSResampleImageFilter<FloatVectorImageType, FloatVectorImageType>  ResamplerType;
-    typedef otb::StreamingResampleImageFilter<FloatVectorImageType, FloatVectorImageType>  BasicResamplerType;
+    typedef otb::GridResampleImageFilter<FloatVectorImageType, FloatVectorImageType>  BasicResamplerType;
     typedef otb::ImportGeoInformationImageFilter<FloatVectorImageType,InternalImageType> ImportGeoInformationFilterType;
     typedef otb::SimpleRcsPanSharpeningFusionImageFilter<InternalImageType, FloatVectorImageType, FloatVectorImageType> FusionFilterType;
 
@@ -204,13 +205,22 @@ private:
       {
       otbAppLogINFO("Using the PHR mode");
       
-      otb::PleiadesPToXSAffineTransformCalculator::TransformType::Pointer transform
-        = otb::PleiadesPToXSAffineTransformCalculator::Compute(panchro, xs);
+      otb::PleiadesPToXSAffineTransformCalculator::TransformType::OffsetType offset
+        = otb::PleiadesPToXSAffineTransformCalculator::ComputeOffset(GetParameterImage("inp"),
+                                                                     GetParameterImage("inxs"));
 
+      origin+=offset;
+      origin[0]=origin[0]/4;
+      origin[1]=origin[1]/4;
+      
+      basicResampler->SetOutputOrigin(origin);
       basicResampler->SetInput(xs);
-      basicResampler->SetTransform(transform);
       basicResampler->SetOutputOrigin(origin);
-      basicResampler->SetOutputSpacing(spacing);
+
+      FloatVectorImageType::SpacingType xsSpacing = GetParameterImage("inxs")->GetSpacing();
+      xsSpacing*=0.25;
+      
+      basicResampler->SetOutputSpacing(xsSpacing);
       basicResampler->SetOutputSize(size);
       basicResampler->SetOutputStartIndex(start);
       basicResampler->SetEdgePaddingValue(defaultValue);
diff --git a/Modules/Applications/AppProjection/app/otbSuperimpose.cxx b/Modules/Applications/AppProjection/app/otbSuperimpose.cxx
index 8063257976..dc8661fd03 100644
--- a/Modules/Applications/AppProjection/app/otbSuperimpose.cxx
+++ b/Modules/Applications/AppProjection/app/otbSuperimpose.cxx
@@ -18,6 +18,7 @@
 #include "otbWrapperApplicationFactory.h"
 
 #include "otbGenericRSResampleImageFilter.h"
+#include "otbGridResampleImageFilter.h"
 #include "otbImportGeoInformationImageFilter.h"
 
 #include "otbBCOInterpolateImageFunction.h"
@@ -72,7 +73,7 @@ public:
 
   typedef itk::ScalableAffineTransform<double, 2>                 TransformType;
   
-  typedef otb::StreamingResampleImageFilter
+  typedef otb::GridResampleImageFilter
     <FloatVectorImageType,
      FloatVectorImageType>                                        BasicResamplerType;
   
@@ -251,19 +252,23 @@ private:
       {
       otbAppLogINFO("Using the PHR mode");
       
-      otb::PleiadesPToXSAffineTransformCalculator::TransformType::Pointer transform
-        = otb::PleiadesPToXSAffineTransformCalculator::Compute(GetParameterImage("inr"),
-                                                               GetParameterImage("inm"));
-
-      m_BasicResampler->SetTransform(transform);
+      otb::PleiadesPToXSAffineTransformCalculator::TransformType::OffsetType offset
+        = otb::PleiadesPToXSAffineTransformCalculator::ComputeOffset(GetParameterImage("inr"),
+                                                                     GetParameterImage("inm"));
       
       m_BasicResampler->SetInput(movingImage);
+      origin+=offset;
+      origin[0]=origin[0]/4;
+      origin[1]=origin[1]/4;
       
       m_BasicResampler->SetOutputOrigin(origin);
-      m_BasicResampler->SetOutputSpacing(spacing);
-      m_BasicResampler->SetOutputSize(size);
-      m_BasicResampler->SetOutputStartIndex(start);
+
+      FloatVectorImageType::SpacingType xsSpacing = GetParameterImage("inm")->GetSpacing();
+      xsSpacing*=0.25;
       
+      m_BasicResampler->SetOutputSpacing(xsSpacing);
+      m_BasicResampler->SetOutputSize(size);
+      m_Resampler->SetOutputStartIndex(start);
       m_BasicResampler->SetEdgePaddingValue(defaultValue);
 
       m_GeoImport->SetInput(m_BasicResampler->GetOutput());
-- 
GitLab