From 966bafc4b082ea151db7d4cc04d23a97e491e6d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= <cedric.traizet@c-s.fr> Date: Wed, 12 Sep 2018 16:01:39 +0200 Subject: [PATCH] STYLE : ITK style for loop brackets --- .../app/otbSmallRegionsMerging.cxx | 15 ++-- .../otbLabelImageSmallRegionMergingFilter.h | 4 +- .../otbLabelImageSmallRegionMergingFilter.hxx | 68 +++++++++---------- 3 files changed, 43 insertions(+), 44 deletions(-) diff --git a/Modules/Applications/AppSegmentation/app/otbSmallRegionsMerging.cxx b/Modules/Applications/AppSegmentation/app/otbSmallRegionsMerging.cxx index 5c3130d339..009ffdbb5a 100644 --- a/Modules/Applications/AppSegmentation/app/otbSmallRegionsMerging.cxx +++ b/Modules/Applications/AppSegmentation/app/otbSmallRegionsMerging.cxx @@ -149,15 +149,15 @@ private: auto labelPopulationMap = labelStatsFilter->GetLabelPopulationMap(); std::vector<double> labelPopulation; for (unsigned int i =0; i <= labelPopulationMap.rbegin()->first; i++) - { + { labelPopulation.push_back(labelPopulationMap[i]); - } + } auto meanValueMap = labelStatsFilter->GetMeanValueMap(); std::vector<itk::VariableLengthVector<double> > meanValues; for (unsigned int i =0; i <= meanValueMap.rbegin()->first; i++) - { + { meanValues.push_back(meanValueMap[i]); - } + } auto regionMergingFilter = LabelImageSmallRegionMergingFilterType::New(); regionMergingFilter->SetInput( labelIn ); @@ -173,13 +173,12 @@ private: auto LUT = regionMergingFilter->GetLUT(); for(unsigned int i = 0; i<LUT.size(); ++i) - { + { if(i!=LUT[i]) - { - std::cout << i << " " << LUT[i] << std::endl; + { changeLabelFilter->SetChange(i,LUT[i]); + } } - } 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 4d490b61ce..28033f77eb 100644 --- a/Modules/Segmentation/Conversion/include/otbLabelImageSmallRegionMergingFilter.h +++ b/Modules/Segmentation/Conversion/include/otbLabelImageSmallRegionMergingFilter.h @@ -91,9 +91,9 @@ public: // Initialize m_CorrespondingMap to the identity (i.e. m[label] = label) m_LUT.resize( labelPopulation.size() ); for (unsigned int i =0; i <labelPopulation.size(); i++) - { + { m_LUT[ i ] = i; - } + } } /** Get the Label population */ diff --git a/Modules/Segmentation/Conversion/include/otbLabelImageSmallRegionMergingFilter.hxx b/Modules/Segmentation/Conversion/include/otbLabelImageSmallRegionMergingFilter.hxx index 8348150c6e..88df1b3179 100644 --- a/Modules/Segmentation/Conversion/include/otbLabelImageSmallRegionMergingFilter.hxx +++ b/Modules/Segmentation/Conversion/include/otbLabelImageSmallRegionMergingFilter.hxx @@ -61,84 +61,83 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage > NeigboursMapType neighboursMap; // Merge the neighbours maps from all threads for( unsigned int threadId = 0; threadId < this->GetNumberOfThreads(); threadId++) - { - for (auto it = m_NeighboursMapsTmp[threadId].begin(); it != m_NeighboursMapsTmp[threadId].end(); it++) { + for (auto it = m_NeighboursMapsTmp[threadId].begin(); it != m_NeighboursMapsTmp[threadId].end(); it++) + { neighboursMap[ it->first ].insert( it->second.begin(), it->second.end() ); + } } - } // For each label of the label map, find the "closest" connected label, according // to the euclidian distance between the corresponding m_labelStatistic elements. for (auto neighbours : neighboursMap) - { + { double proximity = std::numeric_limits<double>::max(); InputLabelType label = neighbours.first; InputLabelType closestNeighbour = label; for (auto neighbour : neighbours.second) - { + { auto statsLabel = m_LabelStatistic[ label ]; auto statsNeighbour = m_LabelStatistic[ neighbour ]; assert( statsLabel.Size() == statsNeighbour.Size() ); double distance = 0; for (unsigned int i = 0 ; i < statsLabel.Size(); i++) - { + { distance += pow( statsLabel[i] - statsNeighbour[i] , 2); - } + } if (distance < proximity) - { + { proximity = distance; closestNeighbour = neighbour; + } } - } auto curLabelLUT = label; auto adjLabelLUT = closestNeighbour; while(m_LUT[curLabelLUT] != curLabelLUT) - { + { curLabelLUT = m_LUT[curLabelLUT]; - } + } while(m_LUT[adjLabelLUT] != adjLabelLUT) - { + { adjLabelLUT = m_LUT[adjLabelLUT]; - } + } if(curLabelLUT < adjLabelLUT) - { + { m_LUT[adjLabelLUT] = curLabelLUT; - } + } else - { + { m_LUT[m_LUT[curLabelLUT]] = adjLabelLUT; m_LUT[curLabelLUT] = adjLabelLUT; + } } - } for(InputLabelType label = 0; label < m_LUT.size(); ++label) - { + { InputLabelType can = label; while(m_LUT[can] != can) - { + { can = m_LUT[can]; - } + } m_LUT[label] = can; - } + } for(InputLabelType label = 0; label < m_LUT.size(); ++label) - { + { InputLabelType correspondingLabel = m_LUT[label]; if((m_LabelPopulation[label]!=0) && (correspondingLabel != label)) - { + { m_LabelStatistic[ correspondingLabel ] = (m_LabelStatistic[correspondingLabel]*m_LabelPopulation[correspondingLabel] + m_LabelStatistic[label]*m_LabelPopulation[label] ) / (m_LabelPopulation[label]+m_LabelPopulation[correspondingLabel]); m_LabelPopulation[ correspondingLabel ] += m_LabelPopulation[ label ] ; m_LabelPopulation[ label ] = 0; + } } - - } } template <class TInputLabelImage > @@ -149,10 +148,10 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage > { auto correspondingLabel = m_LUT[label]; while (label != correspondingLabel) - { + { label = correspondingLabel; correspondingLabel = m_LUT[correspondingLabel]; - } + } return correspondingLabel; } @@ -219,7 +218,8 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage > auto labelImage = this->GetInput(); IteratorType it(labelImage, outputRegionForThread); - NeighborhoodIteratorType itN(radius, labelImage, outputRegionForThread);outputRegionForThread.GetSize() << std::endl; + NeighborhoodIteratorType itN(radius, labelImage, outputRegionForThread); + // 4 connected Neighborhood (top, bottom, left and right) typename IteratorType::OffsetType top = {{0,-1}}; itN.ActivateOffset(top); @@ -231,20 +231,20 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage > itN.ActivateOffset(left); for (it.GoToBegin(); ! it.IsAtEnd(); ++it, ++itN) - { + { assert( !itN.IsAtEnd() ); int currentLabel = FindCorrespondingLabel(it.Get()); if ( m_LabelPopulation[currentLabel] == m_Size ) - { - for (auto ci = itN.Begin() ; !ci.IsAtEnd(); ci++) { + for (auto ci = itN.Begin() ; !ci.IsAtEnd(); ci++) + { int neighbourLabel = FindCorrespondingLabel(ci.Get() ); if (neighbourLabel != currentLabel) m_NeighboursMapsTmp[threadId][ currentLabel ].insert( neighbourLabel ); + } } } - } } template <class TInputLabelImage > @@ -271,10 +271,10 @@ LabelImageSmallRegionMergingFilter< TInputLabelImage > m_SmallRegionMergingFilter->GetFilter()->SetInput( labelImage ); m_SmallRegionMergingFilter->GetStreamer()->SetAutomaticTiledStreaming(); for (unsigned int size = 1; size < m_MinSize; size++) - { + { m_SmallRegionMergingFilter->GetFilter()->SetSize( size) ; m_SmallRegionMergingFilter->Update(); - } + } } -- GitLab