diff --git a/include/itkLabelSetDilateImageFilter.h b/include/itkLabelSetDilateImageFilter.h index d891ae7..7b9b7c6 100644 --- a/include/itkLabelSetDilateImageFilter.h +++ b/include/itkLabelSetDilateImageFilter.h @@ -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; diff --git a/include/itkLabelSetDilateImageFilter.hxx b/include/itkLabelSetDilateImageFilter.hxx index 1e21b26..9213d6c 100644 --- a/include/itkLabelSetDilateImageFilter.hxx +++ b/include/itkLabelSetDilateImageFilter.hxx @@ -31,9 +31,33 @@ namespace itk { template void -LabelSetDilateImageFilter::DynamicThreadedGenerateData( - const OutputImageRegionType & outputRegionForThread) +LabelSetDilateImageFilter::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 @@ -90,6 +114,7 @@ LabelSetDilateImageFilter::DynamicThreadedGenerateDat inputIterator, outputDistIterator, outputIterator, + *progress, LineLength, this->m_CurrentDimension, this->m_MagnitudeSign, @@ -107,6 +132,7 @@ LabelSetDilateImageFilter::DynamicThreadedGenerateDat inputDistIterator, outputDistIterator, outputIterator, + *progress, LineLength, this->m_CurrentDimension, this->m_MagnitudeSign, diff --git a/include/itkLabelSetErodeImageFilter.h b/include/itkLabelSetErodeImageFilter.h index fdc9d25..dbd2181 100644 --- a/include/itkLabelSetErodeImageFilter.h +++ b/include/itkLabelSetErodeImageFilter.h @@ -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: diff --git a/include/itkLabelSetErodeImageFilter.hxx b/include/itkLabelSetErodeImageFilter.hxx index 8cbb732..beacc91 100644 --- a/include/itkLabelSetErodeImageFilter.hxx +++ b/include/itkLabelSetErodeImageFilter.hxx @@ -31,8 +31,8 @@ namespace itk { template void -LabelSetErodeImageFilter::DynamicThreadedGenerateData( - const OutputImageRegionType & outputRegionForThread) +LabelSetErodeImageFilter::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 @@ -43,6 +43,29 @@ LabelSetErodeImageFilter::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; using OutputIteratorType = ImageLinearIteratorWithIndex; @@ -86,6 +109,7 @@ LabelSetErodeImageFilter::DynamicThreadedGenerateData inputIterator, outputDistIterator, outputIterator, + *progress, LineLength, this->m_CurrentDimension, this->m_MagnitudeSign, @@ -105,6 +129,7 @@ LabelSetErodeImageFilter::DynamicThreadedGenerateData inputDistIterator, outputDistIterator, outputIterator, + *progress, LineLength, this->m_CurrentDimension, this->m_MagnitudeSign, diff --git a/include/itkLabelSetMorphBaseImageFilter.h b/include/itkLabelSetMorphBaseImageFilter.h index c4a858a..c192e61 100644 --- a/include/itkLabelSetMorphBaseImageFilter.h +++ b/include/itkLabelSetMorphBaseImageFilter.h @@ -118,7 +118,7 @@ class ITK_EXPORT LabelSetMorphBaseImageFilter : public ImageToImageFilter::LabelSetMorph this->SetRadius(1); - this->DynamicMultiThreadingOn(); + this->DynamicMultiThreadingOff(); } template void -LabelSetMorphBaseImageFilter::DynamicThreadedGenerateData( - const OutputImageRegionType & outputRegionForThread) -{ - // stop warnings - (void)outputRegionForThread; -} +LabelSetMorphBaseImageFilter::ThreadedGenerateData( + const OutputImageRegionType &, ThreadIdType) +{} template RegionIndexType diff --git a/include/itkLabelSetUtils.h b/include/itkLabelSetUtils.h index a263cfc..95abdbc 100644 --- a/include/itkLabelSetUtils.h +++ b/include/itkLabelSetUtils.h @@ -20,6 +20,7 @@ #include +#include "itkProgressReporter.h" #include namespace itk { @@ -236,6 +237,7 @@ void doOneDimensionErodeFirstPass(TInIter & inputIterator, TOutDistIter & outputIterator, TOutLabIter & outputLabIterator, + ProgressReporter & progress, const unsigned LineLength, const unsigned direction, const int m_MagnitudeSign, @@ -364,6 +366,7 @@ doOneDimensionErodeFirstPass(TInIter & inputIterator, // now onto the next line inputIterator.NextLine(); outputIterator.NextLine(); + progress.CompletedPixel(); } } @@ -372,6 +375,7 @@ void doOneDimensionDilateFirstPass(TInIter & inputIterator, TOutDistIter & outputIterator, TOutLabIter & outputLabIterator, + ProgressReporter & progress, const unsigned LineLength, const unsigned direction, const int m_MagnitudeSign, @@ -444,6 +448,7 @@ doOneDimensionDilateFirstPass(TInIter & inputIterator, inputIterator.NextLine(); outputIterator.NextLine(); outputLabIterator.NextLine(); + progress.CompletedPixel(); } } @@ -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, @@ -583,6 +589,7 @@ doOneDimensionErode(TInIter & inputIterator, inputIterator.NextLine(); inputDistIterator.NextLine(); outputDistIterator.NextLine(); + progress.CompletedPixel(); } } @@ -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, @@ -663,6 +671,7 @@ doOneDimensionDilate(TInIter & inputIterator, outputLabIterator.NextLine(); inputDistIterator.NextLine(); outputDistIterator.NextLine(); + progress.CompletedPixel(); } } } // namespace LabSet