From 4c60ed8c2b721aebd8445efc3a7be606d2050679 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Traizet?= <cedric.traizet@c-s.fr>
Date: Mon, 17 Sep 2018 13:48:17 +0200
Subject: [PATCH] ENH : modern c++ in for loops

---
 .../app/otbSmallRegionsMerging.cxx            | 26 +++++++++----------
 .../otbLabelImageSmallRegionMergingFilter.h   |  4 +--
 2 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/Modules/Applications/AppSegmentation/app/otbSmallRegionsMerging.cxx b/Modules/Applications/AppSegmentation/app/otbSmallRegionsMerging.cxx
index d7391db9ee..12b73e6beb 100644
--- a/Modules/Applications/AppSegmentation/app/otbSmallRegionsMerging.cxx
+++ b/Modules/Applications/AppSegmentation/app/otbSmallRegionsMerging.cxx
@@ -128,20 +128,19 @@ private:
 
     // Convert Map to Unordered map
 
-    auto labelPopulationMap = labelStatsFilter->GetLabelPopulationMap();
+    auto  labelPopulationMap = labelStatsFilter->GetLabelPopulationMap();
     std::unordered_map< unsigned int,double> labelPopulation;
-    for (population : labelPopulationMap)
+    for (auto population : labelPopulationMap)
       {
       labelPopulation[population.first]=population.second;
       }
-    auto meanValueMap = labelStatsFilter->GetMeanValueMap();
+    auto  meanValueMap = labelStatsFilter->GetMeanValueMap();
     std::unordered_map< unsigned int, itk::VariableLengthVector<double> > meanValues;
-    for (mean : meanValueMap)
+    for (const auto & mean : meanValueMap)
       {
       meanValues[mean.first] = mean.second;
       }  
       
-    
     // Compute the LUT from the original label image to the merged output label image.
     auto regionMergingFilter = LabelImageSmallRegionMergingFilterType::New();
     regionMergingFilter->SetInput( labelIn );
@@ -156,15 +155,14 @@ private:
     // Relabelling using the LUT
     auto changeLabelFilter = ChangeLabelImageFilterType::New();
     changeLabelFilter->SetInput(labelIn);
-    auto LUT = regionMergingFilter->GetLUT();
-
-    for(unsigned int i = 0; i<LUT.size(); ++i)
-      { 
-      if(i!=LUT[i])
-        {
-        changeLabelFilter->SetChange(i,LUT[i]);
-        }
-      }
+    
+    const auto & LUT = regionMergingFilter->GetLUT();
+    for (auto label : LUT)
+    {
+      if (label.first != label.second)
+        changeLabelFilter->SetChange(label.first, label.second);
+    }
+    
     SetParameterOutputImage("out", changeLabelFilter->GetOutput());
     RegisterPipeline();
     clock_t toc = clock();
diff --git a/Modules/Segmentation/Conversion/include/otbLabelImageSmallRegionMergingFilter.h b/Modules/Segmentation/Conversion/include/otbLabelImageSmallRegionMergingFilter.h
index 15a91b8785..c0d1f5887e 100644
--- a/Modules/Segmentation/Conversion/include/otbLabelImageSmallRegionMergingFilter.h
+++ b/Modules/Segmentation/Conversion/include/otbLabelImageSmallRegionMergingFilter.h
@@ -81,7 +81,7 @@ public:
 
   typedef std::unordered_map<InputLabelType , RealVectorPixelType >                                   LabelStatisticType;
   typedef std::unordered_map<InputLabelType , double>                                                 LabelPopulationType;
-  typedef std::unordered_map<InputLabelType , InputLabelType>                                          LUTType;
+  typedef std::unordered_map<InputLabelType , InputLabelType>                                         LUTType;
   
   /** Set/Get size of segments to be merged */
   itkGetMacro(Size , unsigned int);
@@ -93,7 +93,7 @@ public:
     m_LabelPopulation = labelPopulation; 
     
     // Initialize m_CorrespondingMap to the identity (i.e. m[label] = label)
-    for (label : m_LabelPopulation)
+    for (auto label : m_LabelPopulation)
       {
       m_LUT[label.first] = label.first;
       }  
-- 
GitLab