From 4e14b78789c33e445514474569c3ae51547d56d6 Mon Sep 17 00:00:00 2001
From: Jordi Inglada <jordi.inglada@cesbio.cnes.fr>
Date: Sat, 1 Oct 2016 23:43:36 +0200
Subject: [PATCH] ENH: return as soon as we know the answer

---
 ...bNeighborhoodMajorityVotingImageFilter.txx | 33 +++++++++----------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx b/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx
index 7863338c92..3154646ea2 100644
--- a/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx
+++ b/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx
@@ -52,43 +52,42 @@ NeighborhoodMajorityVotingImageFilter<TInputImage,
                                                                        const KernelIteratorType kernelEnd) 
 {
   const PixelType centerPixel = nit.GetCenterPixel();
-  PixelType result = centerPixel; 
-  if (centerPixel != m_LabelForNoDataPixels)
+  if (centerPixel == m_LabelForNoDataPixels)
+    {
+    return m_LabelForNoDataPixels;
+    }
+  else
     {
     //Get a histogram of label frequencies where the 2 highest are at the beginning and sorted
-    const HistoSummary histoSummary = this->ComputeNeighborhoodHistogramSummary(nit, kernelBegin, kernelEnd);
-
-    if(m_OnlyIsolatedPixels && histoSummary.freqCenterLabel > m_IsolatedThreshold)
+    const HistoSummary histoSummary = 
+      this->ComputeNeighborhoodHistogramSummary(nit, kernelBegin, kernelEnd);
+    if(m_OnlyIsolatedPixels && 
+       histoSummary.freqCenterLabel > m_IsolatedThreshold)
       {
       //If we want to filter only isolated pixels, keep the label if
       //there are enough pixels with the center label to consider that
       //it is not isolated
-      result = centerPixel;
+      return centerPixel;
       }
     else
       {
-      //Extraction of the more representative Label in the neighborhood (majorityLabel)
-      result = histoSummary.majorityLabel;
       //If the majorityLabel is NOT unique in the neighborhood
-      if(histoSummary.secondFreq == histoSummary.majorityFreq && histoSummary.secondLabel != histoSummary.majorityLabel)
+      if(histoSummary.secondFreq == histoSummary.majorityFreq && 
+         histoSummary.secondLabel != histoSummary.majorityLabel)
         {
         if (m_KeepOriginalLabelBool == true)
           {
-          result = centerPixel;
+          return centerPixel;
           }
         else
           {
-          result = m_LabelForUndecidedPixels;
+          return m_LabelForUndecidedPixels;
           }
         }
+      //Extraction of the more representative Label in the neighborhood (majorityLabel)
+      return histoSummary.majorityLabel;
       }
     }//END if (centerPixel != m_LabelForNoDataPixels)
-  //If (centerPixel == m_LabelForNoDataPixels)
-  else
-    {
-    result = m_LabelForNoDataPixels;
-    }
-  return result;
 }
 
 template<class TInputImage, class TOutputImage, class TKernel>
-- 
GitLab