Commit 4c60ed8c authored by Cédric Traizet's avatar Cédric Traizet
Browse files

ENH : modern c++ in for loops

No related merge requests found
Showing with 14 additions and 16 deletions
+14 -16
...@@ -128,20 +128,19 @@ private: ...@@ -128,20 +128,19 @@ private:
// Convert Map to Unordered map // Convert Map to Unordered map
auto labelPopulationMap = labelStatsFilter->GetLabelPopulationMap(); auto labelPopulationMap = labelStatsFilter->GetLabelPopulationMap();
std::unordered_map< unsigned int,double> labelPopulation; std::unordered_map< unsigned int,double> labelPopulation;
for (population : labelPopulationMap) for (auto population : labelPopulationMap)
{ {
labelPopulation[population.first]=population.second; labelPopulation[population.first]=population.second;
} }
auto meanValueMap = labelStatsFilter->GetMeanValueMap(); auto meanValueMap = labelStatsFilter->GetMeanValueMap();
std::unordered_map< unsigned int, itk::VariableLengthVector<double> > meanValues; std::unordered_map< unsigned int, itk::VariableLengthVector<double> > meanValues;
for (mean : meanValueMap) for (const auto & mean : meanValueMap)
{ {
meanValues[mean.first] = mean.second; meanValues[mean.first] = mean.second;
} }
// Compute the LUT from the original label image to the merged output label image. // Compute the LUT from the original label image to the merged output label image.
auto regionMergingFilter = LabelImageSmallRegionMergingFilterType::New(); auto regionMergingFilter = LabelImageSmallRegionMergingFilterType::New();
regionMergingFilter->SetInput( labelIn ); regionMergingFilter->SetInput( labelIn );
...@@ -156,15 +155,14 @@ private: ...@@ -156,15 +155,14 @@ private:
// Relabelling using the LUT // Relabelling using the LUT
auto changeLabelFilter = ChangeLabelImageFilterType::New(); auto changeLabelFilter = ChangeLabelImageFilterType::New();
changeLabelFilter->SetInput(labelIn); changeLabelFilter->SetInput(labelIn);
auto LUT = regionMergingFilter->GetLUT();
const auto & LUT = regionMergingFilter->GetLUT();
for(unsigned int i = 0; i<LUT.size(); ++i) for (auto label : LUT)
{ {
if(i!=LUT[i]) if (label.first != label.second)
{ changeLabelFilter->SetChange(label.first, label.second);
changeLabelFilter->SetChange(i,LUT[i]); }
}
}
SetParameterOutputImage("out", changeLabelFilter->GetOutput()); SetParameterOutputImage("out", changeLabelFilter->GetOutput());
RegisterPipeline(); RegisterPipeline();
clock_t toc = clock(); clock_t toc = clock();
......
...@@ -81,7 +81,7 @@ public: ...@@ -81,7 +81,7 @@ public:
typedef std::unordered_map<InputLabelType , RealVectorPixelType > LabelStatisticType; typedef std::unordered_map<InputLabelType , RealVectorPixelType > LabelStatisticType;
typedef std::unordered_map<InputLabelType , double> LabelPopulationType; 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 */ /** Set/Get size of segments to be merged */
itkGetMacro(Size , unsigned int); itkGetMacro(Size , unsigned int);
...@@ -93,7 +93,7 @@ public: ...@@ -93,7 +93,7 @@ public:
m_LabelPopulation = labelPopulation; m_LabelPopulation = labelPopulation;
// Initialize m_CorrespondingMap to the identity (i.e. m[label] = label) // 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; m_LUT[label.first] = label.first;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment