From 19d146f376c70485436185c402b983e6b0c39f3d Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@orfeo-toolbox.org>
Date: Thu, 6 Dec 2018 16:28:22 +0000
Subject: [PATCH] REFAC: Remove unused functor methods and use the void
 operator() form which is more efficient

---
 ...inclairToCircularCovarianceMatrixFunctor.h | 23 ++++---------------
 .../otbSinclairToCoherencyMatrixFunctor.h     |  9 +-------
 .../otbSinclairToCovarianceMatrixFunctor.h    |  9 ++------
 .../otbSinclairToMuellerMatrixFunctor.h       |  9 +-------
 4 files changed, 9 insertions(+), 41 deletions(-)

diff --git a/Modules/Filtering/Polarimetry/include/otbSinclairToCircularCovarianceMatrixFunctor.h b/Modules/Filtering/Polarimetry/include/otbSinclairToCircularCovarianceMatrixFunctor.h
index cc9c9fe283..54b0945237 100644
--- a/Modules/Filtering/Polarimetry/include/otbSinclairToCircularCovarianceMatrixFunctor.h
+++ b/Modules/Filtering/Polarimetry/include/otbSinclairToCircularCovarianceMatrixFunctor.h
@@ -79,17 +79,14 @@ public:
   typedef std::complex <RealType>                  ComplexType;
   typedef typename TOutput::ValueType              OutputValueType;
   typedef SinclairToCovarianceMatrixFunctor<ComplexType, ComplexType, ComplexType, ComplexType, TOutput> SinclairToCovarianceFunctorType;
-  inline TOutput operator ()(const TInput1& Shh, const TInput2& Shv,
+  inline void operator ()(TOutput & result, const TInput1& Shh, const TInput2& Shv,
                              const TInput3& Svh, const TInput4& Svv)
   {
-    TOutput result;
-
     const ComplexType S_hh = static_cast<ComplexType>(Shh);
     const ComplexType S_hv = static_cast<ComplexType>(Shv);
     const ComplexType S_vh = static_cast<ComplexType>(Svh);
     const ComplexType S_vv = static_cast<ComplexType>(Svv);
 
-    result.SetSize(m_NumberOfComponentsPerPixel);
     const ComplexType jS_hv = S_hv * ComplexType(0., 1.);
     const ComplexType jS_vh = S_vh * ComplexType(0., 1.);
     const ComplexType jS_hh = S_hh * ComplexType(0., 1.);
@@ -102,31 +99,21 @@ public:
     const ComplexType Srl = coef*( jS_hh-S_hv+S_vh+jS_vv );
     const ComplexType Srr = coef*( -S_hh+jS_hv+jS_vh+S_vv );
 
-    //const ComplexType conjSll = std::conj(Sll);
-    //const ComplexType conjSlr = std::conj(Slr);
-    //const ComplexType conjSrl = std::conj(Srl);
-    //const ComplexType conjSrr = std::conj(Srr);
-
     SinclairToCovarianceFunctorType funct;
     return ( funct( Sll, Slr, Srl, Srr ) );
   }
 
-  unsigned int GetNumberOfComponentsPerPixel()
+    constexpr size_t OutputSize(...) const
   {
-    return m_NumberOfComponentsPerPixel;
+    // Size of circular covariance matrix
+    return 10;
   }
 
   /** Constructor */
-  SinclairToCircularCovarianceMatrixFunctor() : m_NumberOfComponentsPerPixel(10) {}
+  SinclairToCircularCovarianceMatrixFunctor() {}
 
   /** Destructor */
   virtual ~SinclairToCircularCovarianceMatrixFunctor() {}
-
-protected:
-
-
-private:
-    unsigned int m_NumberOfComponentsPerPixel;
 };
 
 } // namespace Functor
diff --git a/Modules/Filtering/Polarimetry/include/otbSinclairToCoherencyMatrixFunctor.h b/Modules/Filtering/Polarimetry/include/otbSinclairToCoherencyMatrixFunctor.h
index 1e845bc46d..6b6e75bb53 100644
--- a/Modules/Filtering/Polarimetry/include/otbSinclairToCoherencyMatrixFunctor.h
+++ b/Modules/Filtering/Polarimetry/include/otbSinclairToCoherencyMatrixFunctor.h
@@ -69,11 +69,9 @@ public:
   typedef double                                   RealType;
   typedef std::complex <RealType>                  ComplexType;
   typedef typename TOutput::ValueType              OutputValueType;
-  inline TOutput operator ()(const TInput1& Shh, const TInput2& Shv,
+  inline void operator ()(TOutput & result, const TInput1& Shh, const TInput2& Shv,
                              const TInput3& Svh, const TInput4& Svv)
   {
-    TOutput result(10);
-
     const ComplexType S_hh = static_cast<ComplexType>(Shh);
     const ComplexType S_hv = static_cast<ComplexType>(Shv);
     const ComplexType S_vh = static_cast<ComplexType>(Svh);
@@ -106,11 +104,6 @@ public:
     return 10;
   }
 
-  constexpr size_t GetNumberOfComponentsPerPixel()
-  {
-    return OutputSize();
-  }
-
   /** Constructor */
   SinclairToCoherencyMatrixFunctor() {}
 
diff --git a/Modules/Filtering/Polarimetry/include/otbSinclairToCovarianceMatrixFunctor.h b/Modules/Filtering/Polarimetry/include/otbSinclairToCovarianceMatrixFunctor.h
index 37d9624f5f..47f3ea3dfd 100644
--- a/Modules/Filtering/Polarimetry/include/otbSinclairToCovarianceMatrixFunctor.h
+++ b/Modules/Filtering/Polarimetry/include/otbSinclairToCovarianceMatrixFunctor.h
@@ -68,11 +68,9 @@ public:
   /** Some typedefs. */
   typedef typename std::complex <double>           ComplexType;
   typedef typename TOutput::ValueType              OutputValueType;
-  inline TOutput operator ()(const TInput1& Shh, const TInput2& Shv,
+  inline void operator ()(TOutput & result, const TInput1& Shh, const TInput2& Shv,
                              const TInput3& Svh, const TInput4& Svv)
   {
-    TOutput result(10);
-
     const ComplexType S_hh = static_cast<ComplexType>(Shh);
     const ComplexType S_hv = static_cast<ComplexType>(Shv);
     const ComplexType S_vh = static_cast<ComplexType>(Svh);
@@ -91,10 +89,7 @@ public:
   
     return result;
   }
-  constexpr size_t GetNumberOfComponentsPerPixel()
-  {
-    return OutputSize();
-  }
+
   constexpr size_t OutputSize(...) const
   {
     // Number of components in the covariance matrix
diff --git a/Modules/Filtering/Polarimetry/include/otbSinclairToMuellerMatrixFunctor.h b/Modules/Filtering/Polarimetry/include/otbSinclairToMuellerMatrixFunctor.h
index 500a06769d..fc21f30032 100644
--- a/Modules/Filtering/Polarimetry/include/otbSinclairToMuellerMatrixFunctor.h
+++ b/Modules/Filtering/Polarimetry/include/otbSinclairToMuellerMatrixFunctor.h
@@ -89,11 +89,9 @@ public:
   typedef typename TOutput::ValueType              OutputValueType;
   typedef double                                   RealType;
 
-  inline TOutput operator ()(const TInput1& Shh, const TInput2& Shv,
+  inline void operator ()(TOutput & result, const TInput1& Shh, const TInput2& Shv,
                              const TInput3& Svh, const TInput4& Svv)
   {
-    TOutput result(16);
-
     const ComplexType Txx = static_cast<ComplexType>(-Shh);
     const ComplexType Txy = static_cast<ComplexType>(-Shv);
     const ComplexType Tyx = static_cast<ComplexType>(Svh);
@@ -130,11 +128,6 @@ public:
     return 16;
   }
 
-  constexpr size_t GetNumberOfComponentsPerPixel()
-  {
-    return OutputSize();
-  }
-
   /** Constructor */
   SinclairToMuellerMatrixFunctor() {}
 
-- 
GitLab