From 6ce027b144c5b166a8dfbf5fa1ae9b785b7aede1 Mon Sep 17 00:00:00 2001
From: Antoine Regimbeau <antoine.regimbeau@c-s.fr>
Date: Fri, 23 Feb 2018 16:47:21 +0100
Subject: [PATCH] REFAC: add register pipeline methode on some application in
 imageutils module

---
 .../AppImageUtils/app/otbCompareImages.cxx    | 15 +++++++------
 .../app/otbConcatenateImages.cxx              | 21 +++++++------------
 .../AppImageUtils/app/otbExtractROI.cxx       |  6 ++----
 .../AppImageUtils/app/otbQuicklook.cxx        | 10 ++++-----
 .../AppImageUtils/app/otbRescale.cxx          | 11 +++++-----
 .../AppImageUtils/app/otbSplitImage.cxx       |  5 ++---
 .../AppImageUtils/app/otbTileFusion.cxx       |  5 ++---
 7 files changed, 30 insertions(+), 43 deletions(-)

diff --git a/Modules/Applications/AppImageUtils/app/otbCompareImages.cxx b/Modules/Applications/AppImageUtils/app/otbCompareImages.cxx
index 2d0d54c83c..4199105b3e 100644
--- a/Modules/Applications/AppImageUtils/app/otbCompareImages.cxx
+++ b/Modules/Applications/AppImageUtils/app/otbCompareImages.cxx
@@ -172,9 +172,12 @@ private:
   void DoExecute() ITK_OVERRIDE
   {
     // Init filters
-    m_ExtractRefFilter = ExtractROIMonoFilterType::New();
-    m_ExtractMeasFilter = ExtractROIMonoFilterType::New();
-    m_CompareFilter = StreamingCompareImageFilterType::New();
+    ExtractROIMonoFilterType::Pointer m_ExtractRefFilter = 
+      ExtractROIMonoFilterType::New();
+    ExtractROIMonoFilterType::Pointer m_ExtractMeasFilter = 
+      ExtractROIMonoFilterType::New();
+    StreamingCompareImageFilterType::Pointer m_CompareFilter = 
+      StreamingCompareImageFilterType::New(); 
 
     // Get input image pointers
     FloatVectorImageType::Pointer refIm = this->GetParameterImage("ref.in");
@@ -229,12 +232,8 @@ private:
     SetParameterFloat( "mae",m_CompareFilter->GetMAE() , false);
     SetParameterFloat( "psnr",m_CompareFilter->GetPSNR() , false);
     SetParameterFloat( "count",m_CompareFilter->GetDiffCount() , false);
+    RegisterPipeline();
   }
-
-
-  ExtractROIMonoFilterType::Pointer m_ExtractRefFilter;
-  ExtractROIMonoFilterType::Pointer m_ExtractMeasFilter;
-  StreamingCompareImageFilterType::Pointer m_CompareFilter;
 };
 
 }
diff --git a/Modules/Applications/AppImageUtils/app/otbConcatenateImages.cxx b/Modules/Applications/AppImageUtils/app/otbConcatenateImages.cxx
index 185872b828..171166b072 100644
--- a/Modules/Applications/AppImageUtils/app/otbConcatenateImages.cxx
+++ b/Modules/Applications/AppImageUtils/app/otbConcatenateImages.cxx
@@ -72,10 +72,6 @@ private:
     AddDocTag("Concatenation");
     AddDocTag("Multi-channel");
 
-    m_Concatener = ListConcatenerFilterType::New();
-    m_ExtractorList = ExtractROIFilterListType::New();
-    m_ImageList = ImageListType::New();
-
     AddParameter(ParameterType_InputImageList,  "il",   "Input images list");
     SetParameterDescription("il", "The list of images to concatenate, must have the same size.");
 
@@ -94,15 +90,16 @@ private:
   void DoUpdateParameters() ITK_OVERRIDE
   {
     // Nothing to do here for the parameters : all are independent
-
-    // Reinitialize the object
-    m_Concatener = ListConcatenerFilterType::New();
-    m_ImageList = ImageListType::New();
-    m_ExtractorList = ExtractROIFilterListType::New();
   }
 
   void DoExecute() ITK_OVERRIDE
   {
+    ListConcatenerFilterType::Pointer m_Concatener =
+      ListConcatenerFilterType::New();
+    ExtractROIFilterListType::Pointer m_ExtractorList = 
+      ExtractROIFilterListType::New();
+    ImageListType::Pointer m_ImageList =
+      ImageListType::New();
     // Get the input image list
     FloatVectorImageListType::Pointer inList = this->GetParameterImageList("il");
 
@@ -140,12 +137,8 @@ private:
     m_Concatener->SetInput( m_ImageList );
 
     SetParameterOutputImage("out", m_Concatener->GetOutput());
+    RegisterPipeline();
   }
-
-
-  ListConcatenerFilterType::Pointer  m_Concatener;
-  ExtractROIFilterListType::Pointer  m_ExtractorList;
-  ImageListType::Pointer        m_ImageList;
 };
 
 }
diff --git a/Modules/Applications/AppImageUtils/app/otbExtractROI.cxx b/Modules/Applications/AppImageUtils/app/otbExtractROI.cxx
index bd6a8d1583..0f20b17664 100644
--- a/Modules/Applications/AppImageUtils/app/otbExtractROI.cxx
+++ b/Modules/Applications/AppImageUtils/app/otbExtractROI.cxx
@@ -828,7 +828,7 @@ private:
 
     this->CropRegionOfInterest();
 
-    m_ExtractROIFilter = ExtractROIFilterType::New();
+    ExtractROIFilterType::Pointer m_ExtractROIFilter = ExtractROIFilterType::New();
     m_ExtractROIFilter->SetInput(inImage);
     m_ExtractROIFilter->SetStartX(GetParameterInt("startx"));
     m_ExtractROIFilter->SetStartY(GetParameterInt("starty"));
@@ -841,10 +841,8 @@ private:
       }
 
     SetParameterOutputImage("out", m_ExtractROIFilter->GetOutput());
+    RegisterPipeline();
   }
-
-  ExtractROIFilterType::Pointer   m_ExtractROIFilter;
-
 };
 
 }
diff --git a/Modules/Applications/AppImageUtils/app/otbQuicklook.cxx b/Modules/Applications/AppImageUtils/app/otbQuicklook.cxx
index dd7134c620..154e2dee7f 100644
--- a/Modules/Applications/AppImageUtils/app/otbQuicklook.cxx
+++ b/Modules/Applications/AppImageUtils/app/otbQuicklook.cxx
@@ -202,8 +202,10 @@ bool CropRegionOfInterest()
   {
     InputImageType::Pointer inImage = GetParameterImage("in");
 
-    m_ExtractROIFilter = ExtractROIFilterType::New();
-    m_ResamplingFilter = ShrinkImageFilterType::New();
+    ExtractROIFilterType::Pointer m_ExtractROIFilter =
+      ExtractROIFilterType::New();
+    ShrinkImageFilterType::Pointer m_ResamplingFilter =
+      ShrinkImageFilterType::New();
 
     // The image on which the quicklook will be generated
     // Will eventually be the m_ExtractROIFilter output
@@ -277,11 +279,9 @@ bool CropRegionOfInterest()
     m_ResamplingFilter->Update();
 
     SetParameterOutputImage("out", m_ResamplingFilter->GetOutput());
+    RegisterPipeline();
   }
 
-  ExtractROIFilterType::Pointer m_ExtractROIFilter;
-  ShrinkImageFilterType::Pointer m_ResamplingFilter;
-
 };
 
 }
diff --git a/Modules/Applications/AppImageUtils/app/otbRescale.cxx b/Modules/Applications/AppImageUtils/app/otbRescale.cxx
index f5c08c80a2..e9f7f2a58d 100644
--- a/Modules/Applications/AppImageUtils/app/otbRescale.cxx
+++ b/Modules/Applications/AppImageUtils/app/otbRescale.cxx
@@ -100,8 +100,8 @@ private:
     FloatVectorImageType::Pointer inImage = GetParameterImage("in");
 
     otbAppLogDEBUG( << "Starting Min/Max computation" )
-
-    m_MinMaxFilter = MinMaxFilterType::New();
+  
+    MinMaxFilterType::Pointer m_MinMaxFilter = MinMaxFilterType::New();
     m_MinMaxFilter->SetInput( inImage );
     m_MinMaxFilter->GetStreamer()->SetAutomaticAdaptativeStreaming(GetParameterInt("ram"));
 
@@ -113,7 +113,8 @@ private:
 
     FloatVectorImageType::PixelType inMin, inMax;
 
-    m_RescaleFilter = RescaleImageFilterType::New();
+    RescaleImageFilterType::Pointer m_RescaleFilter = 
+      RescaleImageFilterType::New();
     m_RescaleFilter->SetInput( inImage );
     m_RescaleFilter->SetAutomaticInputMinMaxComputation(false);
     m_RescaleFilter->SetInputMinimum( m_MinMaxFilter->GetMinimum() );
@@ -130,10 +131,8 @@ private:
     m_RescaleFilter->UpdateOutputInformation();
 
     SetParameterOutputImage("out", m_RescaleFilter->GetOutput());
+    RegisterPipeline();
   }
-
-  RescaleImageFilterType::Pointer m_RescaleFilter;
-  MinMaxFilterType::Pointer       m_MinMaxFilter;
 };
 
 }
diff --git a/Modules/Applications/AppImageUtils/app/otbSplitImage.cxx b/Modules/Applications/AppImageUtils/app/otbSplitImage.cxx
index e23eaa57eb..cda99e6618 100644
--- a/Modules/Applications/AppImageUtils/app/otbSplitImage.cxx
+++ b/Modules/Applications/AppImageUtils/app/otbSplitImage.cxx
@@ -103,7 +103,7 @@ private:
     ext   = itksys::SystemTools::GetFilenameExtension(ofname);
 
     // Set the extract filter input image
-    m_Filter = FilterType::New();
+    FilterType::Pointer m_Filter = FilterType::New();
     m_Filter->SetInput(inImage);
 
     for (unsigned int i = 0; i < inImage->GetNumberOfComponentsPerPixel(); ++i)
@@ -140,9 +140,8 @@ private:
     // Disable the output Image parameter to avoid writing
     // the last image (Application::ExecuteAndWriteOutput method)
     DisableParameter("out");
+    RegisterPipeline();
   }
-
-  FilterType::Pointer        m_Filter;
 };
 }
 }
diff --git a/Modules/Applications/AppImageUtils/app/otbTileFusion.cxx b/Modules/Applications/AppImageUtils/app/otbTileFusion.cxx
index 5dd80bc10e..0b6065b220 100644
--- a/Modules/Applications/AppImageUtils/app/otbTileFusion.cxx
+++ b/Modules/Applications/AppImageUtils/app/otbTileFusion.cxx
@@ -95,7 +95,7 @@ private:
       itkExceptionMacro("No input Image set...");
       }
 
-    m_FusionFilter = TileFilterType::New();
+    TileFilterType::Pointer m_FusionFilter = TileFilterType::New();
 
     TileFilterType::SizeType layout;
     layout[0] = this->GetParameterInt("cols");
@@ -108,10 +108,9 @@ private:
       }
 
     SetParameterOutputImage("out", m_FusionFilter->GetOutput());
+    RegisterPipeline();
   }
 
-  TileFilterType::Pointer m_FusionFilter;
-
 };
 
 }
-- 
GitLab