Commit 966bafc4 authored by Cédric Traizet's avatar Cédric Traizet
Browse files

STYLE : ITK style for loop brackets

No related merge requests found
Showing with 43 additions and 44 deletions
+43 -44
...@@ -149,15 +149,15 @@ private: ...@@ -149,15 +149,15 @@ private:
auto labelPopulationMap = labelStatsFilter->GetLabelPopulationMap(); auto labelPopulationMap = labelStatsFilter->GetLabelPopulationMap();
std::vector<double> labelPopulation; std::vector<double> labelPopulation;
for (unsigned int i =0; i <= labelPopulationMap.rbegin()->first; i++) for (unsigned int i =0; i <= labelPopulationMap.rbegin()->first; i++)
{ {
labelPopulation.push_back(labelPopulationMap[i]); labelPopulation.push_back(labelPopulationMap[i]);
} }
auto meanValueMap = labelStatsFilter->GetMeanValueMap(); auto meanValueMap = labelStatsFilter->GetMeanValueMap();
std::vector<itk::VariableLengthVector<double> > meanValues; std::vector<itk::VariableLengthVector<double> > meanValues;
for (unsigned int i =0; i <= meanValueMap.rbegin()->first; i++) for (unsigned int i =0; i <= meanValueMap.rbegin()->first; i++)
{ {
meanValues.push_back(meanValueMap[i]); meanValues.push_back(meanValueMap[i]);
} }
auto regionMergingFilter = LabelImageSmallRegionMergingFilterType::New(); auto regionMergingFilter = LabelImageSmallRegionMergingFilterType::New();
regionMergingFilter->SetInput( labelIn ); regionMergingFilter->SetInput( labelIn );
...@@ -173,13 +173,12 @@ private: ...@@ -173,13 +173,12 @@ private:
auto LUT = regionMergingFilter->GetLUT(); auto LUT = regionMergingFilter->GetLUT();
for(unsigned int i = 0; i<LUT.size(); ++i) for(unsigned int i = 0; i<LUT.size(); ++i)
{ {
if(i!=LUT[i]) if(i!=LUT[i])
{ {
std::cout << i << " " << LUT[i] << std::endl;
changeLabelFilter->SetChange(i,LUT[i]); changeLabelFilter->SetChange(i,LUT[i]);
}
} }
}
SetParameterOutputImage("out", changeLabelFilter->GetOutput()); SetParameterOutputImage("out", changeLabelFilter->GetOutput());
RegisterPipeline(); RegisterPipeline();
clock_t toc = clock(); clock_t toc = clock();
......
...@@ -91,9 +91,9 @@ public: ...@@ -91,9 +91,9 @@ public:
// Initialize m_CorrespondingMap to the identity (i.e. m[label] = label) // Initialize m_CorrespondingMap to the identity (i.e. m[label] = label)
m_LUT.resize( labelPopulation.size() ); m_LUT.resize( labelPopulation.size() );
for (unsigned int i =0; i <labelPopulation.size(); i++) for (unsigned int i =0; i <labelPopulation.size(); i++)
{ {
m_LUT[ i ] = i; m_LUT[ i ] = i;
} }
} }
/** Get the Label population */ /** Get the Label population */
......
...@@ -61,84 +61,83 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage > ...@@ -61,84 +61,83 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage >
NeigboursMapType neighboursMap; NeigboursMapType neighboursMap;
// Merge the neighbours maps from all threads // Merge the neighbours maps from all threads
for( unsigned int threadId = 0; threadId < this->GetNumberOfThreads(); threadId++) 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() ); neighboursMap[ it->first ].insert( it->second.begin(), it->second.end() );
}
} }
}
// For each label of the label map, find the "closest" connected label, according // For each label of the label map, find the "closest" connected label, according
// to the euclidian distance between the corresponding m_labelStatistic elements. // to the euclidian distance between the corresponding m_labelStatistic elements.
for (auto neighbours : neighboursMap) for (auto neighbours : neighboursMap)
{ {
double proximity = std::numeric_limits<double>::max(); double proximity = std::numeric_limits<double>::max();
InputLabelType label = neighbours.first; InputLabelType label = neighbours.first;
InputLabelType closestNeighbour = label; InputLabelType closestNeighbour = label;
for (auto neighbour : neighbours.second) for (auto neighbour : neighbours.second)
{ {
auto statsLabel = m_LabelStatistic[ label ]; auto statsLabel = m_LabelStatistic[ label ];
auto statsNeighbour = m_LabelStatistic[ neighbour ]; auto statsNeighbour = m_LabelStatistic[ neighbour ];
assert( statsLabel.Size() == statsNeighbour.Size() ); assert( statsLabel.Size() == statsNeighbour.Size() );
double distance = 0; double distance = 0;
for (unsigned int i = 0 ; i < statsLabel.Size(); i++) for (unsigned int i = 0 ; i < statsLabel.Size(); i++)
{ {
distance += pow( statsLabel[i] - statsNeighbour[i] , 2); distance += pow( statsLabel[i] - statsNeighbour[i] , 2);
} }
if (distance < proximity) if (distance < proximity)
{ {
proximity = distance; proximity = distance;
closestNeighbour = neighbour; closestNeighbour = neighbour;
}
} }
}
auto curLabelLUT = label; auto curLabelLUT = label;
auto adjLabelLUT = closestNeighbour; auto adjLabelLUT = closestNeighbour;
while(m_LUT[curLabelLUT] != curLabelLUT) while(m_LUT[curLabelLUT] != curLabelLUT)
{ {
curLabelLUT = m_LUT[curLabelLUT]; curLabelLUT = m_LUT[curLabelLUT];
} }
while(m_LUT[adjLabelLUT] != adjLabelLUT) while(m_LUT[adjLabelLUT] != adjLabelLUT)
{ {
adjLabelLUT = m_LUT[adjLabelLUT]; adjLabelLUT = m_LUT[adjLabelLUT];
} }
if(curLabelLUT < adjLabelLUT) if(curLabelLUT < adjLabelLUT)
{ {
m_LUT[adjLabelLUT] = curLabelLUT; m_LUT[adjLabelLUT] = curLabelLUT;
} }
else else
{ {
m_LUT[m_LUT[curLabelLUT]] = adjLabelLUT; m_LUT[m_LUT[curLabelLUT]] = adjLabelLUT;
m_LUT[curLabelLUT] = adjLabelLUT; m_LUT[curLabelLUT] = adjLabelLUT;
}
} }
}
for(InputLabelType label = 0; label < m_LUT.size(); ++label) for(InputLabelType label = 0; label < m_LUT.size(); ++label)
{ {
InputLabelType can = label; InputLabelType can = label;
while(m_LUT[can] != can) while(m_LUT[can] != can)
{ {
can = m_LUT[can]; can = m_LUT[can];
} }
m_LUT[label] = can; m_LUT[label] = can;
} }
for(InputLabelType label = 0; label < m_LUT.size(); ++label) for(InputLabelType label = 0; label < m_LUT.size(); ++label)
{ {
InputLabelType correspondingLabel = m_LUT[label]; InputLabelType correspondingLabel = m_LUT[label];
if((m_LabelPopulation[label]!=0) && (correspondingLabel != label)) if((m_LabelPopulation[label]!=0) && (correspondingLabel != label))
{ {
m_LabelStatistic[ correspondingLabel ] = (m_LabelStatistic[correspondingLabel]*m_LabelPopulation[correspondingLabel] + m_LabelStatistic[ correspondingLabel ] = (m_LabelStatistic[correspondingLabel]*m_LabelPopulation[correspondingLabel] +
m_LabelStatistic[label]*m_LabelPopulation[label] ) / (m_LabelPopulation[label]+m_LabelPopulation[correspondingLabel]); m_LabelStatistic[label]*m_LabelPopulation[label] ) / (m_LabelPopulation[label]+m_LabelPopulation[correspondingLabel]);
m_LabelPopulation[ correspondingLabel ] += m_LabelPopulation[ label ] ; m_LabelPopulation[ correspondingLabel ] += m_LabelPopulation[ label ] ;
m_LabelPopulation[ label ] = 0; m_LabelPopulation[ label ] = 0;
}
} }
}
} }
template <class TInputLabelImage > template <class TInputLabelImage >
...@@ -149,10 +148,10 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage > ...@@ -149,10 +148,10 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage >
{ {
auto correspondingLabel = m_LUT[label]; auto correspondingLabel = m_LUT[label];
while (label != correspondingLabel) while (label != correspondingLabel)
{ {
label = correspondingLabel; label = correspondingLabel;
correspondingLabel = m_LUT[correspondingLabel]; correspondingLabel = m_LUT[correspondingLabel];
} }
return correspondingLabel; return correspondingLabel;
} }
...@@ -219,7 +218,8 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage > ...@@ -219,7 +218,8 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage >
auto labelImage = this->GetInput(); auto labelImage = this->GetInput();
IteratorType it(labelImage, outputRegionForThread); 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) // 4 connected Neighborhood (top, bottom, left and right)
typename IteratorType::OffsetType top = {{0,-1}}; typename IteratorType::OffsetType top = {{0,-1}};
itN.ActivateOffset(top); itN.ActivateOffset(top);
...@@ -231,20 +231,20 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage > ...@@ -231,20 +231,20 @@ PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage >
itN.ActivateOffset(left); itN.ActivateOffset(left);
for (it.GoToBegin(); ! it.IsAtEnd(); ++it, ++itN) for (it.GoToBegin(); ! it.IsAtEnd(); ++it, ++itN)
{ {
assert( !itN.IsAtEnd() ); assert( !itN.IsAtEnd() );
int currentLabel = FindCorrespondingLabel(it.Get()); int currentLabel = FindCorrespondingLabel(it.Get());
if ( m_LabelPopulation[currentLabel] == m_Size ) 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() ); int neighbourLabel = FindCorrespondingLabel(ci.Get() );
if (neighbourLabel != currentLabel) if (neighbourLabel != currentLabel)
m_NeighboursMapsTmp[threadId][ currentLabel ].insert( neighbourLabel ); m_NeighboursMapsTmp[threadId][ currentLabel ].insert( neighbourLabel );
}
} }
} }
}
} }
template <class TInputLabelImage > template <class TInputLabelImage >
...@@ -271,10 +271,10 @@ LabelImageSmallRegionMergingFilter< TInputLabelImage > ...@@ -271,10 +271,10 @@ LabelImageSmallRegionMergingFilter< TInputLabelImage >
m_SmallRegionMergingFilter->GetFilter()->SetInput( labelImage ); m_SmallRegionMergingFilter->GetFilter()->SetInput( labelImage );
m_SmallRegionMergingFilter->GetStreamer()->SetAutomaticTiledStreaming(); m_SmallRegionMergingFilter->GetStreamer()->SetAutomaticTiledStreaming();
for (unsigned int size = 1; size < m_MinSize; size++) for (unsigned int size = 1; size < m_MinSize; size++)
{ {
m_SmallRegionMergingFilter->GetFilter()->SetSize( size) ; m_SmallRegionMergingFilter->GetFilter()->SetSize( size) ;
m_SmallRegionMergingFilter->Update(); m_SmallRegionMergingFilter->Update();
} }
} }
......
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