Commit fb089425 authored by Laurentiu Nicola's avatar Laurentiu Nicola
Browse files

PERF: reduce copying in StreamingStatisticsMapFromLabelImageFilter

parent 97cb1ea7
......@@ -155,20 +155,21 @@ PersistentStreamingStatisticsMapFromLabelImageFilter<TInputVectorImage, TLabelIm
{
// Update temporary accumulator
AccumulatorMapType outputAcc;
auto endAcc = outputAcc.end();
for (auto const& threadAccMap: m_AccumulatorMaps)
{
for(auto const& it: threadAccMap)
{
const LabelPixelType label = it.first;
if (outputAcc.count(label) <= 0)
auto itAcc = outputAcc.find(label);
if (itAcc == endAcc)
{
AccumulatorType newAcc(it.second);
outputAcc[label] = newAcc;
outputAcc.emplace(label, AccumulatorType(it.second));
}
else
{
outputAcc[label].Update(it.second);
itAcc->second.Update(it.second);
}
}
}
......@@ -267,26 +268,26 @@ PersistentStreamingStatisticsMapFromLabelImageFilter<TInputVectorImage, TLabelIm
itk::ImageRegionConstIterator<TLabelImage> labelIt(labelInputPtr, outputRegionForThread);
itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
typename VectorImageType::PixelType value;
typename LabelImageType::PixelType label;
auto &acc = m_AccumulatorMaps[threadId];
auto endAcc = acc.end();
// do the work
for (inIt.GoToBegin(), labelIt.GoToBegin();
!inIt.IsAtEnd() && !labelIt.IsAtEnd();
++inIt, ++labelIt)
{
value = inIt.Get();
label = labelIt.Get();
const auto &value = inIt.Get();
auto label = labelIt.Get();
// Update the accumulator
if (m_AccumulatorMaps[threadId].count(label) <= 0) //add new element to the map
auto itAcc = acc.find(label);
if (itAcc == endAcc)
{
AccumulatorType newAcc(value);
m_AccumulatorMaps[threadId][label] = newAcc;
acc.emplace(label, AccumulatorType(value));
}
else
{
m_AccumulatorMaps[threadId][label].Update(value);
itAcc->second.Update(value);
}
progress.CompletedPixel();
......
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