Skip to content

Commit

Permalink
BUG: Fix test errors steming from the new multi-threading mechanism.
Browse files Browse the repository at this point in the history
Fix errors steming from the use of the new `itk::PoolMultiThreader`
class for multi-threading.

The solution adopted in this patch set was based on the discussion in:
http://review.source.kitware.com/#/c/23434/
  • Loading branch information
Jon Haitz Legarreta authored and phcerdan committed May 31, 2018
1 parent 75a291d commit b2a06e7
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 54 deletions.
11 changes: 5 additions & 6 deletions include/itkExpandWithZerosImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,16 @@ class ExpandWithZerosImageFilter:
void PrintSelf(std::ostream & os, Indent indent) const override;

/** ExpandWithZerosImageFilter is implemented as a multithreaded filter. Therefore,
* this implementation provides a ThreadedGenerateData() routine which
* this implementation provides a DynamicThreadedGenerateData() routine which
* is called for each processing thread. The output image data is allocated
* automatically by the superclass prior to calling ThreadedGenerateData().
* ThreadedGenerateData can only write to the portion of the output image
* automatically by the superclass prior to calling DynamicThreadedGenerateData().
* DynamicThreadedGenerateData can only write to the portion of the output image
* specified by the parameter "outputRegionForThread"
*
* \sa ImageToImageFilter::ThreadedGenerateData(),
* \sa ImageToImageFilter::DynamicThreadedGenerateData(),
* ImageToImageFilter::GenerateData() */

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

/** This method is used to set the state of the filter before
* multi-threading. */
Expand Down
8 changes: 3 additions & 5 deletions include/itkExpandWithZerosImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "itkImageRegionConstIteratorWithIndex.h"
#include "itkObjectFactory.h"
#include "itkNumericTraits.h"
#include "itkProgressReporter.h"

namespace itk
{
Expand All @@ -39,6 +38,8 @@ ExpandWithZerosImageFilter< TInputImage, TOutputImage >
{
m_ExpandFactors[j] = 1;
}

this->DynamicMultiThreadingOn();
}

/**
Expand Down Expand Up @@ -108,8 +109,7 @@ ExpandWithZerosImageFilter< TInputImage, TOutputImage >
template< typename TInputImage, typename TOutputImage >
void
ExpandWithZerosImageFilter< TInputImage, TOutputImage >
::ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread,
ThreadIdType threadId)
::DynamicThreadedGenerateData( const OutputImageRegionType & outputRegionForThread )
{
// Get the input and output pointers
OutputImagePointer outputPtr = this->GetOutput();
Expand All @@ -127,7 +127,6 @@ ExpandWithZerosImageFilter< TInputImage, TOutputImage >
return;
}
const size_t numberOfLinesToProcess = outputRegionForThread.GetNumberOfPixels() / size0;
ProgressReporter progress( this, threadId, static_cast< SizeValueType >( numberOfLinesToProcess ) );

const typename OutputImageType::IndexType outputOriginIndex = outputPtr->GetLargestPossibleRegion().GetIndex();
// Walk the output region, and interpolate the input image
Expand Down Expand Up @@ -170,7 +169,6 @@ ExpandWithZerosImageFilter< TInputImage, TOutputImage >
}

outIt.NextLine();
progress.CompletedPixel();
}
}

Expand Down
3 changes: 1 addition & 2 deletions include/itkFrequencyBandImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ class FrequencyBandImageFilter:

void BeforeThreadedGenerateData() override;

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

private:
FrequencyValueType m_LowFrequencyThreshold;
Expand Down
5 changes: 2 additions & 3 deletions include/itkFrequencyBandImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ FrequencyBandImageFilter< TImageType, TFrequencyIteratorType >
m_PassNegativeLowFrequencyThreshold(true),
m_PassNegativeHighFrequencyThreshold(true)
{
this->DynamicMultiThreadingOn();
}

template< typename TImageType, typename TFrequencyIteratorType >
Expand Down Expand Up @@ -133,9 +134,7 @@ FrequencyBandImageFilter< TImageType, TFrequencyIteratorType >
template< typename TImageType, typename TFrequencyIteratorType >
void
FrequencyBandImageFilter< TImageType, TFrequencyIteratorType >
::ThreadedGenerateData(
const ImageRegionType & outputRegionForThread,
ThreadIdType )
::DynamicThreadedGenerateData( const ImageRegionType & outputRegionForThread )
{
// outputPtr is a copy of input image from BeforeThreadedGenerateData
ImagePointer outputPtr = this->GetOutput();
Expand Down
1 change: 0 additions & 1 deletion include/itkFrequencyShrinkViaInverseFFTImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#define itkFrequencyShrinkViaInverseFFTImageFilter_hxx

#include <itkFrequencyShrinkViaInverseFFTImageFilter.h>
#include <itkProgressReporter.h>

namespace itk
{
Expand Down
3 changes: 1 addition & 2 deletions include/itkMonogenicSignalFrequencyImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ class MonogenicSignalFrequencyImageFilter:

void GenerateOutputInformation() override;

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

private:
RieszFunctionPointer m_Evaluator;
Expand Down
7 changes: 4 additions & 3 deletions include/itkMonogenicSignalFrequencyImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ namespace itk
{
template< typename TInputImage, typename TFrequencyImageRegionConstIterator >
MonogenicSignalFrequencyImageFilter< TInputImage, TFrequencyImageRegionConstIterator >
::MonogenicSignalFrequencyImageFilter()
::MonogenicSignalFrequencyImageFilter() :
{
m_Evaluator = RieszFunctionType::New();
m_Evaluator->SetOrder(1);

this->DynamicMultiThreadingOn();
}

template< typename TInputImage, typename TFrequencyImageRegionConstIterator >
Expand All @@ -43,8 +45,7 @@ MonogenicSignalFrequencyImageFilter< TInputImage, TFrequencyImageRegionConstIter
template< typename TInputImage, typename TFrequencyImageRegionConstIterator >
void
MonogenicSignalFrequencyImageFilter< TInputImage, TFrequencyImageRegionConstIterator >
::ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread,
ThreadIdType itkNotUsed(threadId))
::DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread)
{
// Allocate the outputs
this->AllocateOutputs();
Expand Down
3 changes: 1 addition & 2 deletions include/itkPhaseAnalysisImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ class PhaseAnalysisImageFilter:

void BeforeThreadedGenerateData() override;

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

inline OutputImagePixelType ComputeFeatureVectorNormSquare( const InputImagePixelType & inputPixel) const
{
Expand Down
11 changes: 3 additions & 8 deletions include/itkPhaseAnalysisImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#ifndef itkPhaseAnalysisImageFilter_hxx
#define itkPhaseAnalysisImageFilter_hxx
#include "itkPhaseAnalysisImageFilter.h"
#include "itkProgressReporter.h"

namespace itk
{
Expand All @@ -32,6 +31,8 @@ PhaseAnalysisImageFilter< TInputImage, TOutputImage >
{
this->SetNthOutput(n_output, this->MakeOutput(n_output));
}

this->DynamicMultiThreadingOn();
}

template< typename TInputImage, typename TOutputImage >
Expand Down Expand Up @@ -60,13 +61,8 @@ PhaseAnalysisImageFilter< TInputImage, TOutputImage >
template< typename TInputImage, typename TOutputImage >
void
PhaseAnalysisImageFilter< TInputImage, TOutputImage >
::ThreadedGenerateData(
const OutputImageRegionType & outputRegionForThread,
ThreadIdType threadId)
::DynamicThreadedGenerateData( const OutputImageRegionType & outputRegionForThread )
{
ProgressReporter progress(this, threadId,
outputRegionForThread.GetNumberOfPixels() / outputRegionForThread.GetSize()[0]);

typename OutputImageType::Pointer phasePtr = this->GetOutputPhase();
typename OutputImageType::Pointer amplitudePtr = this->GetOutputAmplitude();

Expand All @@ -89,7 +85,6 @@ PhaseAnalysisImageFilter< TInputImage, TOutputImage >
}

inputIt.NextLine(); ampIt.NextLine(); phaseIt.NextLine();
progress.CompletedPixel();
}
}

Expand Down
12 changes: 4 additions & 8 deletions include/itkPhaseAnalysisSoftThresholdImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "itkImageScanlineConstIterator.h"
#include "itkImageScanlineIterator.h"

#include "itkProgressReporter.h"
#include "itkStatisticsImageFilter.h"
namespace itk
{
Expand All @@ -40,6 +39,8 @@ PhaseAnalysisSoftThresholdImageFilter< TInputImage, TOutputImage >
{
this->SetNthOutput(n_output, this->MakeOutput(n_output));
}

this->DynamicMultiThreadingOn();
}

template< typename TInputImage, typename TOutputImage >
Expand Down Expand Up @@ -85,13 +86,9 @@ PhaseAnalysisSoftThresholdImageFilter< TInputImage, TOutputImage >
template< typename TInputImage, typename TOutputImage >
void
PhaseAnalysisSoftThresholdImageFilter< TInputImage, TOutputImage >
::ThreadedGenerateData(
const OutputImageRegionType & outputRegionForThread,
ThreadIdType threadId)
::DynamicThreadedGenerateData( const OutputImageRegionType & outputRegionForThread )
{
ProgressReporter progress( this, threadId, outputRegionForThread.GetNumberOfPixels() );

Superclass::ThreadedGenerateData(outputRegionForThread, threadId);
Superclass::DynamicThreadedGenerateData(outputRegionForThread);

auto phasePtr = this->GetOutputPhase();
auto amplitudePtr = this->GetOutputAmplitude();
Expand Down Expand Up @@ -139,7 +136,6 @@ PhaseAnalysisSoftThresholdImageFilter< TInputImage, TOutputImage >
}

outIt.NextLine(), ampIt.NextLine(), phaseIt.NextLine();
progress.CompletedPixel(); // Per line
}
}
} // end namespace itk
Expand Down
3 changes: 1 addition & 2 deletions include/itkShrinkDecimateImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ class ShrinkDecimateImageFilter:
ShrinkDecimateImageFilter();
void PrintSelf(std::ostream & os, Indent indent) const override;

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

private:
ShrinkFactorsType m_ShrinkFactors;
Expand Down
8 changes: 3 additions & 5 deletions include/itkShrinkDecimateImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include "itkShrinkDecimateImageFilter.h"
#include "itkImageScanlineIterator.h"
#include "itkProgressReporter.h"
#include <numeric>
#include <functional>

Expand All @@ -34,6 +33,8 @@ ShrinkDecimateImageFilter< TInputImage, TOutputImage >
{
m_ShrinkFactors[j] = 1;
}

this->DynamicMultiThreadingOn();
}

template< class TInputImage, class TOutputImage >
Expand Down Expand Up @@ -99,8 +100,7 @@ ShrinkDecimateImageFilter< TInputImage, TOutputImage >
template< typename TInputImage, typename TOutputImage >
void
ShrinkDecimateImageFilter< TInputImage, TOutputImage >
::ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread,
ThreadIdType threadId)
::DynamicThreadedGenerateData( const OutputImageRegionType & outputRegionForThread )
{
// Get the input and output pointers
OutputImagePointer outputPtr = this->GetOutput();
Expand All @@ -118,7 +118,6 @@ ShrinkDecimateImageFilter< TInputImage, TOutputImage >
return;
}
const size_t numberOfLinesToProcess = outputRegionForThread.GetNumberOfPixels() / size0;
ProgressReporter progress( this, threadId, static_cast< SizeValueType >( numberOfLinesToProcess ) );

// const typename OutputImageType::IndexType outputOriginIndex = outputPtr->GetLargestPossibleRegion().GetIndex();
// const typename InputImageType::IndexType inputOriginIndex = inputPtr->GetLargestPossibleRegion().GetIndex();
Expand All @@ -145,7 +144,6 @@ ShrinkDecimateImageFilter< TInputImage, TOutputImage >
}

outIt.NextLine();
progress.CompletedPixel();
}
}

Expand Down
3 changes: 1 addition & 2 deletions include/itkStructureTensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ class StructureTensor:

void BeforeThreadedGenerateData() override;

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

/** Assuming that row>=column */
static unsigned int LowerTriangleToLinearIndex(unsigned int r, unsigned int c)
Expand Down
9 changes: 4 additions & 5 deletions include/itkStructureTensor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// Convolution/Neighborhood Operations
#include <itkConvolutionImageFilter.h>
#include <itkConstantBoundaryCondition.h>
#include "itkProgressReporter.h"

namespace itk
{
template< typename TInputImage, typename TOutputImage >
Expand All @@ -38,6 +38,8 @@ StructureTensor< TInputImage, TOutputImage >
m_GaussianWindowSigma(1.0)
{
this->m_GaussianSource = GaussianSourceType::New();

this->DynamicMultiThreadingOn();
}

template< typename TInputImage, typename TOutputImage >
Expand Down Expand Up @@ -151,11 +153,8 @@ StructureTensor< TInputImage, TOutputImage >
template< typename TInputImage, typename TOutputImage >
void
StructureTensor< TInputImage, TOutputImage >
::ThreadedGenerateData(
const OutputImageRegionType & outputRegionForThread,
ThreadIdType threadId)
::DynamicThreadedGenerateData( const OutputImageRegionType & outputRegionForThread )
{
ProgressReporter progress( this, threadId, outputRegionForThread.GetNumberOfPixels() );
unsigned int nInputs = this->GetNumberOfInputs();

auto outputPtr = this->GetOutput();
Expand Down

0 comments on commit b2a06e7

Please sign in to comment.