From 2982fb869162ab6bacf941facdaa7ebf88626e55 Mon Sep 17 00:00:00 2001
From: ctraizet <cedric.traizet@c-s.fr>
Date: Mon, 18 Mar 2019 16:05:23 +0100
Subject: [PATCH] REFAC: replace VectorMapping by a functorImageFilter

---
 .../AppImageUtils/app/otbColorMapping.cxx     | 35 +++++++------------
 1 file changed, 12 insertions(+), 23 deletions(-)

diff --git a/Modules/Applications/AppImageUtils/app/otbColorMapping.cxx b/Modules/Applications/AppImageUtils/app/otbColorMapping.cxx
index 7853e0a17a..fd3f218407 100644
--- a/Modules/Applications/AppImageUtils/app/otbColorMapping.cxx
+++ b/Modules/Applications/AppImageUtils/app/otbColorMapping.cxx
@@ -39,7 +39,7 @@
 #include "itkVariableLengthVector.h"
 
 #include "itkImageRegionConstIterator.h"
-#include "otbUnaryFunctorImageFilter.h"
+#include "otbFunctorImageFilter.h"
 #include "itkBinaryFunctorImageFilter.h"
 
 #include "itkCastImageFilter.h"
@@ -84,7 +84,7 @@ public:
   typedef typename TOutput::ValueType ValueType;
 
   VectorMapping() : m_OutputSize(0) {}
-  virtual ~VectorMapping() {}
+  virtual ~VectorMapping() = default;
 
   typedef std::map<TInput, TOutput, VectorLexicographicCompare<TInput> > ChangeMapType;
 
@@ -92,22 +92,12 @@ public:
   {
     m_OutputSize = nb;
   }
-  unsigned int GetOutputSize()
+  
+  size_t OutputSize(const std::array<size_t,1> & itkNotUsed(nbBands)) const
   {
     return m_OutputSize;
   }
-  bool operator !=(const VectorMapping& other) const
-  {
-    if (m_ChangeMap != other.m_ChangeMap)
-      {
-      return true;
-      }
-    return false;
-  }
-  bool operator ==(const VectorMapping& other) const
-  {
-    return !(*this != other);
-  }
+
   TOutput GetChange(const TInput& original)
   {
     return m_ChangeMap[original];
@@ -234,9 +224,8 @@ public:
     StreamingStatisticsMapFromLabelImageFilterType;
 
   // Inverse mapper for color->label operation
-  typedef otb::UnaryFunctorImageFilter
-    <RGBImageType, LabelVectorImageType,
-     Functor::VectorMapping
+  typedef otb::FunctorImageFilter
+    <Functor::VectorMapping
       <RGBPixelType, LabelVectorType> >               ColorToLabelFilterType;
 
   // Streaming the input image for color->label operation
@@ -685,10 +674,10 @@ private:
     RGBImageType::Pointer input = GetParameterUInt8RGBImage("in");
     m_InverseMapper = ColorToLabelFilterType::New();
     m_InverseMapper->SetInput(input);
-    m_InverseMapper->GetFunctor().SetOutputSize(1);
+    m_InverseMapper->GetModifiableFunctor().SetOutputSize(1);
     LabelVectorType notFoundValue(1);
     notFoundValue[0] = GetParameterInt("op.colortolabel.notfound");
-    m_InverseMapper->GetFunctor().SetNotFoundValue(notFoundValue);
+    m_InverseMapper->GetModifiableFunctor().SetNotFoundValue(notFoundValue);
 
     if(GetParameterInt("method")==0)
       {
@@ -710,7 +699,7 @@ private:
       colorList.insert(background);
       LabelVectorType currentVectorLabel(1);
       currentVectorLabel[0] = currentLabel;
-      m_InverseMapper->GetFunctor().SetChange(background, currentVectorLabel);
+      m_InverseMapper->GetModifiableFunctor().SetChange(background, currentVectorLabel);
       ++currentLabel;
 
       // Setting up local streaming capabilities
@@ -747,7 +736,7 @@ private:
             {
             colorList.insert(it.Get());
             currentVectorLabel[0] = currentLabel;
-            m_InverseMapper->GetFunctor().SetChange(it.Get(), currentVectorLabel);
+            m_InverseMapper->GetModifiableFunctor().SetChange(it.Get(), currentVectorLabel);
             ++currentLabel;
             }
           ++it;
@@ -824,7 +813,7 @@ private:
           rgbcolor[0] = static_cast<int>(color[0]);
           rgbcolor[1] = static_cast<int>(color[1]);
           rgbcolor[2] = static_cast<int>(color[2]);
-          m_InverseMapper->GetFunctor().SetChange(rgbcolor, cvlabel);
+          m_InverseMapper->GetModifiableFunctor().SetChange(rgbcolor, cvlabel);
           }
         }
       }
-- 
GitLab