From a74a269af5b5331cffaeeb166f4e7d9caa68d419 Mon Sep 17 00:00:00 2001
From: Jordi Inglada <jordi.inglada@cesbio.cnes.fr>
Date: Fri, 30 Sep 2016 15:19:52 +0200
Subject: [PATCH] ENH: add const and init to useful values

---
 .../otbNeighborhoodMajorityVotingImageFilter.h      |  2 +-
 .../otbNeighborhoodMajorityVotingImageFilter.txx    | 13 ++++++-------
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.h b/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.h
index 2e05ce8bba..d603a82726 100644
--- a/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.h
+++ b/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.h
@@ -175,7 +175,7 @@ protected:
   unsigned int FillNeighborhoodHistogram(std::vector<std::pair<PixelType, unsigned int> >& histoNeigh, 
                                          const NeighborhoodIteratorType &nit,
                                          const KernelIteratorType kernelBegin,
-                                         const KernelIteratorType kernelEnd);
+                                         const KernelIteratorType kernelEnd) const;
 
   struct CompareHistoFequencies
   {
diff --git a/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx b/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx
index 87d7306857..d4e85ae870 100644
--- a/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx
+++ b/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx
@@ -48,18 +48,17 @@ typename NeighborhoodMajorityVotingImageFilter<TInputImage, TOutputImage,
                                                TKernel>::PixelType NeighborhoodMajorityVotingImageFilter<TInputImage,
                                                                                                          TOutputImage, TKernel>::Evaluate(const NeighborhoodIteratorType &nit,
                                                                                                                                           const KernelIteratorType kernelBegin,
-                                                                                                                                          const KernelIteratorType kernelEnd)
+                                                                                                                                          const KernelIteratorType kernelEnd) 
 {
-  PixelType majorityLabel = 0; //Value of the more representative pixels in the neighborhood
-  unsigned int majorityFreq = 0; //Number of pixels with the more representative value (majorityLabel) in the neighborhood
-  
-  PixelType centerPixel = nit.GetCenterPixel();
+  const PixelType centerPixel = nit.GetCenterPixel();
+  PixelType majorityLabel = centerPixel; //Value of the more representative pixels in the neighborhood
+  unsigned int majorityFreq = 1; //Number of pixels with the more representative value (majorityLabel) in the neighborhood
 
   if (centerPixel != m_LabelForNoDataPixels)
     {
     std::vector< std::pair<PixelType, unsigned int> > histoNeighVec;
     //Get a histogram of label frequencies where the 2 highest are at the beginning and sorted
-    unsigned int freqCenterLabel = this->FillNeighborhoodHistogram(histoNeighVec, nit, kernelBegin, kernelEnd);
+    const unsigned int freqCenterLabel = this->FillNeighborhoodHistogram(histoNeighVec, nit, kernelBegin, kernelEnd);
 
     if(m_OnlyIsolatedPixels && freqCenterLabel > m_IsolatedThreshold)
       {
@@ -106,7 +105,7 @@ unsigned int NeighborhoodMajorityVotingImageFilter<TInputImage,
                                                    TKernel>::FillNeighborhoodHistogram(std::vector<std::pair<PixelType, unsigned int> >& histoNeighVec, 
                                                                                        const NeighborhoodIteratorType &nit,
                                                                                        const KernelIteratorType kernelBegin,
-                                                                                       const KernelIteratorType kernelEnd)
+                                                                                       const KernelIteratorType kernelEnd) const
 {  
   std::map<PixelType, unsigned int> histoNeigh;
   PixelType centerPixel = nit.GetCenterPixel();
-- 
GitLab