Skip to content

Commit

Permalink
BUG: Fix test errors resulting from incorrect multi-threading format.
Browse files Browse the repository at this point in the history
The filters were originlly setup to utilize the new Multi-threader format. However, these filters utilize a custom region splitter that requires the classic multi-threader.
The changes required changing:

 - DynamiicMultThreadingOn() to DynamiicMultThreadingOff() in filter's constructor, in order to utilize classic multi-threader

 - DynamicThreadedGenerateData() to ThreadedGenerateData with theadId passed as a parameter

 - Add ProgressReporter object as parameter to doOneDimension methods.
  • Loading branch information
mseng10 authored and mseng_l committed Apr 22, 2020
1 parent b26d7ab commit 38b50c4
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 16 deletions.
4 changes: 2 additions & 2 deletions include/itkLabelSetDilateImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ class ITK_EXPORT LabelSetDilateImageFilter : public LabelSetMorphBaseImageFilter
static constexpr unsigned int InputImageDimension = TInputImage::ImageDimension;

protected:
LabelSetDilateImageFilter() { this->DynamicMultiThreadingOn(); }
LabelSetDilateImageFilter() { this->DynamicMultiThreadingOff(); }
~LabelSetDilateImageFilter() override = default;

void
DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override;
ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, ThreadIdType threadId) override;

private:
using DistanceImageType = typename Superclass::DistanceImageType;
Expand Down
30 changes: 28 additions & 2 deletions include/itkLabelSetDilateImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,33 @@ namespace itk
{
template <typename TInputImage, typename TOutputImage>
void
LabelSetDilateImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenerateData(
const OutputImageRegionType & outputRegionForThread)
LabelSetDilateImageFilter<TInputImage, TOutputImage>::ThreadedGenerateData(
const OutputImageRegionType & outputRegionForThread, ThreadIdType threadId)
{
// compute the number of rows first, so we can setup a progress reporter
typename std::vector< unsigned int > NumberOfRows;
InputSizeType size = outputRegionForThread.GetSize();

for ( unsigned int i = 0; i < InputImageDimension; i++ )
{
NumberOfRows.push_back(1);
for ( unsigned int d = 0; d < InputImageDimension; d++ )
{
if ( d != i )
{
NumberOfRows[i] *= size[d];
}
}
}
float progressPerDimension = 1.0 / ImageDimension;

auto *progress = new ProgressReporter(this,
threadId,
NumberOfRows[this->m_CurrentDimension],
30,
this->m_CurrentDimension * progressPerDimension,
progressPerDimension);

// this is where the work happens. We use a distance image with
// floating point pixel to perform the parabolic operations. The
// input image specifies the size of the SE at each location. These
Expand Down Expand Up @@ -90,6 +114,7 @@ LabelSetDilateImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenerateDat
inputIterator,
outputDistIterator,
outputIterator,
*progress,
LineLength,
this->m_CurrentDimension,
this->m_MagnitudeSign,
Expand All @@ -107,6 +132,7 @@ LabelSetDilateImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenerateDat
inputDistIterator,
outputDistIterator,
outputIterator,
*progress,
LineLength,
this->m_CurrentDimension,
this->m_MagnitudeSign,
Expand Down
4 changes: 2 additions & 2 deletions include/itkLabelSetErodeImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ class ITK_EXPORT LabelSetErodeImageFilter : public LabelSetMorphBaseImageFilter<
static constexpr unsigned int InputImageDimension = TInputImage::ImageDimension;

protected:
LabelSetErodeImageFilter() { this->DynamicMultiThreadingOn(); }
LabelSetErodeImageFilter() { this->DynamicMultiThreadingOff(); }
~LabelSetErodeImageFilter() override = default;

void
DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override;
ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, ThreadIdType threadId) override;

// Override since the filter produces the entire dataset.
private:
Expand Down
29 changes: 27 additions & 2 deletions include/itkLabelSetErodeImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ namespace itk
{
template <typename TInputImage, typename TOutputImage>
void
LabelSetErodeImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenerateData(
const OutputImageRegionType & outputRegionForThread)
LabelSetErodeImageFilter<TInputImage, TOutputImage>::ThreadedGenerateData(
const OutputImageRegionType & outputRegionForThread, ThreadIdType threadId)
{
// this is where the work happens. We use a distance image with
// floating point pixel to perform the parabolic operations. The
Expand All @@ -43,6 +43,29 @@ LabelSetErodeImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenerateData
// Similarly, the thresholding on output needs to be integrated
// with the last processing stage.

typename std::vector< unsigned int > NumberOfRows;
InputSizeType size = outputRegionForThread.GetSize();

for ( unsigned int i = 0; i < InputImageDimension; i++ )
{
NumberOfRows.push_back(1);
for ( unsigned int d = 0; d < InputImageDimension; d++ )
{
if ( d != i )
{
NumberOfRows[i] *= size[d];
}
}
}
float progressPerDimension = 1.0 / ImageDimension;

auto *progress = new ProgressReporter(this,
threadId,
NumberOfRows[this->m_CurrentDimension],
30,
this->m_CurrentDimension * progressPerDimension,
progressPerDimension);

using InputConstIteratorType = ImageLinearConstIteratorWithIndex<TInputImage>;
using OutputIteratorType = ImageLinearIteratorWithIndex<TOutputImage>;

Expand Down Expand Up @@ -86,6 +109,7 @@ LabelSetErodeImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenerateData
inputIterator,
outputDistIterator,
outputIterator,
*progress,
LineLength,
this->m_CurrentDimension,
this->m_MagnitudeSign,
Expand All @@ -105,6 +129,7 @@ LabelSetErodeImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenerateData
inputDistIterator,
outputDistIterator,
outputIterator,
*progress,
LineLength,
this->m_CurrentDimension,
this->m_MagnitudeSign,
Expand Down
2 changes: 1 addition & 1 deletion include/itkLabelSetMorphBaseImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class ITK_EXPORT LabelSetMorphBaseImageFilter : public ImageToImageFilter<TInput
SplitRequestedRegion(RegionIndexType i, RegionIndexType num, OutputImageRegionType & splitRegion) override;

void
DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override;
ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, ThreadIdType threadId) override;

void
GenerateData() override;
Expand Down
11 changes: 4 additions & 7 deletions include/itkLabelSetMorphBaseImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,14 @@ LabelSetMorphBaseImageFilter<TInputImage, doDilate, TOutputImage>::LabelSetMorph

this->SetRadius(1);

this->DynamicMultiThreadingOn();
this->DynamicMultiThreadingOff();
}

template <typename TInputImage, bool doDilate, typename TOutputImage>
void
LabelSetMorphBaseImageFilter<TInputImage, doDilate, TOutputImage>::DynamicThreadedGenerateData(
const OutputImageRegionType & outputRegionForThread)
{
// stop warnings
(void)outputRegionForThread;
}
LabelSetMorphBaseImageFilter<TInputImage, doDilate, TOutputImage>::ThreadedGenerateData(
const OutputImageRegionType &, ThreadIdType)
{}

template <typename TInputImage, bool doDilate, typename TOutputImage>
RegionIndexType
Expand Down
9 changes: 9 additions & 0 deletions include/itkLabelSetUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <itkArray.h>

#include "itkProgressReporter.h"
#include <vector>
namespace itk
{
Expand Down Expand Up @@ -236,6 +237,7 @@ void
doOneDimensionErodeFirstPass(TInIter & inputIterator,
TOutDistIter & outputIterator,
TOutLabIter & outputLabIterator,
ProgressReporter & progress,
const unsigned LineLength,
const unsigned direction,
const int m_MagnitudeSign,
Expand Down Expand Up @@ -364,6 +366,7 @@ doOneDimensionErodeFirstPass(TInIter & inputIterator,
// now onto the next line
inputIterator.NextLine();
outputIterator.NextLine();
progress.CompletedPixel();
}
}

Expand All @@ -372,6 +375,7 @@ void
doOneDimensionDilateFirstPass(TInIter & inputIterator,
TOutDistIter & outputIterator,
TOutLabIter & outputLabIterator,
ProgressReporter & progress,
const unsigned LineLength,
const unsigned direction,
const int m_MagnitudeSign,
Expand Down Expand Up @@ -444,6 +448,7 @@ doOneDimensionDilateFirstPass(TInIter & inputIterator,
inputIterator.NextLine();
outputIterator.NextLine();
outputLabIterator.NextLine();
progress.CompletedPixel();
}
}

Expand All @@ -453,6 +458,7 @@ doOneDimensionErode(TInIter & inputIterator,
TDistIter & inputDistIterator,
TOutDistIter & outputDistIterator,
TOutLabIter & outputLabIterator,
ProgressReporter & progress,
const unsigned LineLength,
const unsigned direction,
const int m_MagnitudeSign,
Expand Down Expand Up @@ -583,6 +589,7 @@ doOneDimensionErode(TInIter & inputIterator,
inputIterator.NextLine();
inputDistIterator.NextLine();
outputDistIterator.NextLine();
progress.CompletedPixel();
}
}

Expand All @@ -592,6 +599,7 @@ doOneDimensionDilate(TInIter & inputIterator,
TDistIter & inputDistIterator,
TOutDistIter & outputDistIterator,
TOutLabIter & outputLabIterator,
ProgressReporter & progress,
const unsigned LineLength,
const unsigned direction,
const int m_MagnitudeSign,
Expand Down Expand Up @@ -663,6 +671,7 @@ doOneDimensionDilate(TInIter & inputIterator,
outputLabIterator.NextLine();
inputDistIterator.NextLine();
outputDistIterator.NextLine();
progress.CompletedPixel();
}
}
} // namespace LabSet
Expand Down

0 comments on commit 38b50c4

Please sign in to comment.