diff --git a/Modules/Filtering/BinaryMathematicalMorphology/include/itkBinaryDilateImageFilter.hxx b/Modules/Filtering/BinaryMathematicalMorphology/include/itkBinaryDilateImageFilter.hxx index 5772fc2e4a5..5b1387abf2b 100644 --- a/Modules/Filtering/BinaryMathematicalMorphology/include/itkBinaryDilateImageFilter.hxx +++ b/Modules/Filtering/BinaryMathematicalMorphology/include/itkBinaryDilateImageFilter.hxx @@ -25,6 +25,7 @@ #include "itkConstantBoundaryCondition.h" #include "itkOffset.h" #include "itkProgressReporter.h" +#include "itkTotalProgressReporter.h" #include "itkMath.h" #include "itkPrintHelper.h" @@ -75,10 +76,9 @@ BinaryDilateImageFilter::GenerateData() // Support progress methods/callbacks // Setup a progress reporter. We have 4 stages to the algorithm so // pretend we have 4 times the number of pixels - ProgressReporter progress(this, - 0, - outputRegion.GetNumberOfPixels() * 2 + tmpRequestedRegion.GetNumberOfPixels() + - requiredInputRegion.GetNumberOfPixels()); + TotalProgressReporter progress(this, + outputRegion.GetNumberOfPixels() * 2 + tmpRequestedRegion.GetNumberOfPixels() + + requiredInputRegion.GetNumberOfPixels()); // Allocate and reset output. We copy the input to the output, // except for pixels with DilateValue. These pixels are initially @@ -100,8 +100,8 @@ BinaryDilateImageFilter::GenerateData() { outIt.Set(static_cast(value)); } - progress.CompletedPixel(); } + progress.Completed(outputRegion.GetNumberOfPixels()); // Create the temp image for surface encoding // The temp image size is equal to the output requested region for thread @@ -158,8 +158,8 @@ BinaryDilateImageFilter::GenerateData() // it as background tmpRegIt.Set(backgroundTag); } - progress.CompletedPixel(); } + progress.Completed(requiredInputRegion.GetNumberOfPixels()); // Second stage // Border tracking and encoding @@ -451,6 +451,9 @@ BinaryDilateImageFilter::GenerateData() progress.CompletedPixel(); } } + + // The border tracking stage reports fewer pixels than it was allotted. + this->UpdateProgress(1.0f); } /** diff --git a/Modules/Filtering/BinaryMathematicalMorphology/include/itkBinaryErodeImageFilter.hxx b/Modules/Filtering/BinaryMathematicalMorphology/include/itkBinaryErodeImageFilter.hxx index c07d8181a78..90c86350546 100644 --- a/Modules/Filtering/BinaryMathematicalMorphology/include/itkBinaryErodeImageFilter.hxx +++ b/Modules/Filtering/BinaryMathematicalMorphology/include/itkBinaryErodeImageFilter.hxx @@ -21,10 +21,12 @@ #include "itkImageRegionIteratorWithIndex.h" #include "itkNeighborhoodInnerProduct.h" #include "itkImageRegionConstIterator.h" +#include "itkImageScanlineIterator.h" #include "itkNeighborhoodAlgorithm.h" #include "itkConstantBoundaryCondition.h" #include "itkOffset.h" #include "itkProgressReporter.h" +#include "itkTotalProgressReporter.h" #include "itkMath.h" #include "itkPrintHelper.h" @@ -75,10 +77,9 @@ BinaryErodeImageFilter::GenerateData() // Support progress methods/callbacks // Setup a progress reporter. We have 4 stages to the algorithm so // pretend we have 4 times the number of pixels - ProgressReporter progress(this, - 0, - outputRegion.GetNumberOfPixels() * 3 + tmpRequestedRegion.GetNumberOfPixels() + - requiredInputRegion.GetNumberOfPixels()); + TotalProgressReporter progress(this, + outputRegion.GetNumberOfPixels() * 3 + tmpRequestedRegion.GetNumberOfPixels() + + requiredInputRegion.GetNumberOfPixels()); // Allocate and reset output. We copy the input to the output, // except for pixels with DilateValue. These pixels are initially @@ -90,8 +91,8 @@ BinaryErodeImageFilter::GenerateData() for (outIt.GoToBegin(); !outIt.IsAtEnd(); ++outIt) { outIt.Set(foregroundValue); - progress.CompletedPixel(); } + progress.Completed(outputRegion.GetNumberOfPixels()); // Create the temp image for surface encoding // The temp image size is equal to the output requested region for thread @@ -148,8 +149,8 @@ BinaryErodeImageFilter::GenerateData() // it as background tmpRegIt.Set(backgroundTag); } - progress.CompletedPixel(); } + progress.Completed(requiredInputRegion.GetNumberOfPixels()); // Second stage // Border tracking and encoding @@ -447,18 +448,25 @@ BinaryErodeImageFilter::GenerateData() } // now, we must to restore the background values - ImageRegionConstIterator inIt(input, outputRegion); + ImageScanlineConstIterator inIt(input, outputRegion); + ImageScanlineIterator outLineIt(output, outputRegion); - for (inIt.GoToBegin(), outIt.GoToBegin(); !outIt.IsAtEnd(); ++outIt, ++inIt) + for (; !outLineIt.IsAtEnd(); outLineIt.NextLine(), inIt.NextLine()) { - const InputPixelType inValue = inIt.Get(); - const OutputPixelType outValue = outIt.Get(); - if (Math::ExactlyEquals(outValue, backgroundValue) && Math::NotExactlyEquals(inValue, foregroundValue)) + for (; !outLineIt.IsAtEndOfLine(); ++outLineIt, ++inIt) { - outIt.Set(static_cast(inValue)); + const InputPixelType inValue = inIt.Get(); + const OutputPixelType outValue = outLineIt.Get(); + if (Math::ExactlyEquals(outValue, backgroundValue) && Math::NotExactlyEquals(inValue, foregroundValue)) + { + outLineIt.Set(static_cast(inValue)); + } } - progress.CompletedPixel(); + progress.Completed(outputRegion.GetSize(0)); } + + // The border tracking stage reports fewer pixels than it was allotted. + this->UpdateProgress(1.0f); } /** diff --git a/Modules/Filtering/BoneEnhancement/include/itkHessianGaussianImageFilter.hxx b/Modules/Filtering/BoneEnhancement/include/itkHessianGaussianImageFilter.hxx index a53289a4b6e..dd47d397f00 100644 --- a/Modules/Filtering/BoneEnhancement/include/itkHessianGaussianImageFilter.hxx +++ b/Modules/Filtering/BoneEnhancement/include/itkHessianGaussianImageFilter.hxx @@ -20,6 +20,7 @@ #define itkHessianGaussianImageFilter_hxx #include "itkImageRegionIteratorWithIndex.h" +#include "itkImageScanlineIterator.h" #include "itkProgressAccumulator.h" #include "itkGaussianDerivativeOperator.h" #include "itkMath.h" @@ -230,22 +231,25 @@ HessianGaussianImageFilter::GenerateData() // on the output image of vectors m_ImageAdaptor->SelectNthElement(element++); - ImageRegionIteratorWithIndex it(derivativeImage, derivativeImage->GetRequestedRegion()); + ImageScanlineConstIterator it(derivativeImage, derivativeImage->GetRequestedRegion()); - ImageRegionIteratorWithIndex ot(m_ImageAdaptor, m_ImageAdaptor->GetRequestedRegion()); + ImageScanlineIterator ot(m_ImageAdaptor, m_ImageAdaptor->GetRequestedRegion()); const RealType spacingA = inputImage->GetSpacing()[dima]; const RealType spacingB = inputImage->GetSpacing()[dimb]; const RealType factor = spacingA * spacingB; - it.GoToBegin(); - ot.GoToBegin(); while (!it.IsAtEnd()) { - ot.Set(it.Get() / factor); - ++it; - ++ot; + while (!it.IsAtEndOfLine()) + { + ot.Set(it.Get() / factor); + ++it; + ++ot; + } + it.NextLine(); + ot.NextLine(); } derivativeImage->ReleaseData(); diff --git a/Modules/Filtering/FFT/include/itkFFTWHalfHermitianToRealInverseFFTImageFilter.hxx b/Modules/Filtering/FFT/include/itkFFTWHalfHermitianToRealInverseFFTImageFilter.hxx index d1b988bc343..ed2f3c6f830 100644 --- a/Modules/Filtering/FFT/include/itkFFTWHalfHermitianToRealInverseFFTImageFilter.hxx +++ b/Modules/Filtering/FFT/include/itkFFTWHalfHermitianToRealInverseFFTImageFilter.hxx @@ -19,6 +19,7 @@ #define itkFFTWHalfHermitianToRealInverseFFTImageFilter_hxx #include "itkImageRegionIterator.h" +#include "itkImageScanlineIterator.h" #include "itkProgressReporter.h" #include "itkMultiThreaderBase.h" @@ -126,12 +127,16 @@ void FFTWHalfHermitianToRealInverseFFTImageFilter::DynamicThreadedGenerateData( const OutputRegionType & outputRegionForThread) { - const unsigned long totalOutputSize = this->GetOutput()->GetRequestedRegion().GetNumberOfPixels(); - ImageRegionIterator it(this->GetOutput(), outputRegionForThread); + const unsigned long totalOutputSize = this->GetOutput()->GetRequestedRegion().GetNumberOfPixels(); + ImageScanlineIterator it(this->GetOutput(), outputRegionForThread); while (!it.IsAtEnd()) { - it.Set(it.Value() / totalOutputSize); - ++it; + while (!it.IsAtEndOfLine()) + { + it.Set(it.Value() / totalOutputSize); + ++it; + } + it.NextLine(); } } diff --git a/Modules/Filtering/FFT/include/itkFFTWInverseFFTImageFilter.hxx b/Modules/Filtering/FFT/include/itkFFTWInverseFFTImageFilter.hxx index cd869d1caab..5d1b215e6ad 100644 --- a/Modules/Filtering/FFT/include/itkFFTWInverseFFTImageFilter.hxx +++ b/Modules/Filtering/FFT/include/itkFFTWInverseFFTImageFilter.hxx @@ -21,6 +21,7 @@ #include "itkFullToHalfHermitianImageFilter.h" #include "itkImageRegionIterator.h" +#include "itkImageScanlineIterator.h" #include "itkProgressReporter.h" #include "itkMultiThreaderBase.h" @@ -104,12 +105,16 @@ void FFTWInverseFFTImageFilter::DynamicThreadedGenerateData( const OutputImageRegionType & outputRegionForThread) { - const unsigned long totalOutputSize = this->GetOutput()->GetRequestedRegion().GetNumberOfPixels(); - ImageRegionIterator it(this->GetOutput(), outputRegionForThread); + const unsigned long totalOutputSize = this->GetOutput()->GetRequestedRegion().GetNumberOfPixels(); + ImageScanlineIterator it(this->GetOutput(), outputRegionForThread); while (!it.IsAtEnd()) { - it.Set(it.Value() / totalOutputSize); - ++it; + while (!it.IsAtEndOfLine()) + { + it.Set(it.Value() / totalOutputSize); + ++it; + } + it.NextLine(); } } diff --git a/Modules/Filtering/ImageFeature/include/itkHessianRecursiveGaussianImageFilter.hxx b/Modules/Filtering/ImageFeature/include/itkHessianRecursiveGaussianImageFilter.hxx index e9a51bc52da..bd6d2df98bb 100644 --- a/Modules/Filtering/ImageFeature/include/itkHessianRecursiveGaussianImageFilter.hxx +++ b/Modules/Filtering/ImageFeature/include/itkHessianRecursiveGaussianImageFilter.hxx @@ -19,6 +19,7 @@ #define itkHessianRecursiveGaussianImageFilter_hxx #include "itkImageRegionIterator.h" +#include "itkImageScanlineIterator.h" #include "itkProgressAccumulator.h" #include // For generate. @@ -284,9 +285,9 @@ HessianRecursiveGaussianImageFilter::GenerateData() // on the output image of vectors m_ImageAdaptor->SelectNthElement(element++); - ImageRegionIterator it(derivativeImage, derivativeImage->GetRequestedRegion()); + ImageScanlineConstIterator it(derivativeImage, derivativeImage->GetRequestedRegion()); - ImageRegionIterator ot(m_ImageAdaptor, m_ImageAdaptor->GetRequestedRegion()); + ImageScanlineIterator ot(m_ImageAdaptor, m_ImageAdaptor->GetRequestedRegion()); const RealType spacingA = inputImage->GetSpacing()[dima]; const RealType spacingB = inputImage->GetSpacing()[dimb]; @@ -295,9 +296,14 @@ HessianRecursiveGaussianImageFilter::GenerateData() while (!it.IsAtEnd()) { - ot.Set(it.Get() / factor); - ++it; - ++ot; + while (!it.IsAtEndOfLine()) + { + ot.Set(it.Get() / factor); + ++it; + ++ot; + } + it.NextLine(); + ot.NextLine(); } derivativeImage->ReleaseData(); diff --git a/Modules/Filtering/ImageGradient/include/itkGradientRecursiveGaussianImageFilter.hxx b/Modules/Filtering/ImageGradient/include/itkGradientRecursiveGaussianImageFilter.hxx index b0d55c223c4..6474fe64170 100644 --- a/Modules/Filtering/ImageGradient/include/itkGradientRecursiveGaussianImageFilter.hxx +++ b/Modules/Filtering/ImageGradient/include/itkGradientRecursiveGaussianImageFilter.hxx @@ -20,6 +20,7 @@ #include "itkImageRegionIterator.h" #include "itkImageRegionConstIterator.h" +#include "itkImageScanlineIterator.h" #include "itkPrintHelper.h" #include // For generate. @@ -247,19 +248,24 @@ GradientRecursiveGaussianImageFilter::GenerateData() // on the output image of vectors m_ImageAdaptor->SelectNthElement(nc * ImageDimension + dim); - ImageRegionIterator it(derivativeImage, derivativeImage->GetRequestedRegion()); + ImageScanlineConstIterator it(derivativeImage, derivativeImage->GetRequestedRegion()); - ImageRegionIterator ot(m_ImageAdaptor, m_ImageAdaptor->GetRequestedRegion()); + ImageScanlineIterator ot(m_ImageAdaptor, m_ImageAdaptor->GetRequestedRegion()); const ScalarRealType spacing = inputImage->GetSpacing()[dim]; while (!it.IsAtEnd()) { - auto outValue = static_cast( - DefaultConvertPixelTraits::GetNthComponent(nc, it.Get() / spacing)); - ot.Set(outValue); - ++it; - ++ot; + while (!it.IsAtEndOfLine()) + { + auto outValue = static_cast( + DefaultConvertPixelTraits::GetNthComponent(nc, it.Get() / spacing)); + ot.Set(outValue); + ++it; + ++ot; + } + it.NextLine(); + ot.NextLine(); } } } diff --git a/Modules/Filtering/LabelMap/include/itkLabelMapToBinaryImageFilter.hxx b/Modules/Filtering/LabelMap/include/itkLabelMapToBinaryImageFilter.hxx index 975072aec26..8b25cb79b05 100644 --- a/Modules/Filtering/LabelMap/include/itkLabelMapToBinaryImageFilter.hxx +++ b/Modules/Filtering/LabelMap/include/itkLabelMapToBinaryImageFilter.hxx @@ -21,6 +21,7 @@ #include "itkNumericTraits.h" #include "itkProgressReporter.h" #include "itkImageRegionIterator.h" +#include "itkImageScanlineIterator.h" #include "itkProgressTransformer.h" #include "itkPrintHelper.h" @@ -98,22 +99,29 @@ LabelMapToBinaryImageFilter::DynamicThreadedGenerateD if (this->GetNumberOfIndexedInputs() == 2) { // fill the background with the background values from the background image - ImageRegionConstIterator bgIt(this->GetBackgroundImage(), outputRegionForThread); - ImageRegionIterator oIt(output, outputRegionForThread); + ImageScanlineConstIterator bgIt(this->GetBackgroundImage(), outputRegionForThread); + ImageScanlineIterator oIt(output, outputRegionForThread); + const OutputImagePixelType foregroundValue = this->m_ForegroundValue; + const OutputImagePixelType backgroundValue = this->m_BackgroundValue; while (!oIt.IsAtEnd()) { - const OutputImagePixelType & bg = bgIt.Get(); - if (bg != this->m_ForegroundValue) + while (!oIt.IsAtEndOfLine()) { - oIt.Set(bg); + const OutputImagePixelType & bg = bgIt.Get(); + if (bg != foregroundValue) + { + oIt.Set(bg); + } + else + { + oIt.Set(backgroundValue); + } + ++oIt; + ++bgIt; } - else - { - oIt.Set(this->m_BackgroundValue); - } - ++oIt; - ++bgIt; + oIt.NextLine(); + bgIt.NextLine(); } } else diff --git a/Modules/Video/Filtering/include/itkFrameAverageVideoFilter.hxx b/Modules/Video/Filtering/include/itkFrameAverageVideoFilter.hxx index 491caf18055..22735d41c05 100644 --- a/Modules/Video/Filtering/include/itkFrameAverageVideoFilter.hxx +++ b/Modules/Video/Filtering/include/itkFrameAverageVideoFilter.hxx @@ -21,6 +21,7 @@ #include "itkImageRegionConstIterator.h" #include "itkImageRegionIterator.h" +#include "itkImageScanlineIterator.h" #include "itkNumericTraits.h" namespace itk @@ -110,35 +111,43 @@ FrameAverageVideoFilter::ThreadedGenerate } // Get iterators for the input frames - std::vector> inputIters; + std::vector> inputIters; for (SizeValueType i = inputStart; i < inputStart + numFrames; ++i) { inputIters.emplace_back(input->GetFrame(i), outputRegionForThread); } // Get the output frame and its iterator - OutputFrameType * outFrame = output->GetFrame(outputFrameNumber); - ImageRegionIterator outIter(outFrame, outputRegionForThread); + OutputFrameType * outFrame = output->GetFrame(outputFrameNumber); + ImageScanlineIterator outIter(outFrame, outputRegionForThread); // Average the input frames at each pixel of the output region using OutputPixelRealType = typename NumericTraits::RealType; while (!outIter.IsAtEnd()) { - // Get values for each input frame - OutputPixelRealType val = 0; - for (SizeValueType i = 0; i < numFrames; ++i) + while (!outIter.IsAtEndOfLine()) { - val += (OutputPixelRealType)(inputIters[i].Get()) / (OutputPixelRealType)numFrames; + // Get values for each input frame + OutputPixelRealType val = 0; + for (SizeValueType i = 0; i < numFrames; ++i) + { + val += (OutputPixelRealType)(inputIters[i].Get()) / (OutputPixelRealType)numFrames; + } + + // Compute the average and set the output pixel's value + outIter.Set((OutputPixelType)val); + + // Update the iterators + ++outIter; + for (SizeValueType i = 0; i < numFrames; ++i) + { + ++inputIters[i]; + } } - - // Compute the average and set the output pixel's value - outIter.Set((OutputPixelType)val); - - // Update the iterators - ++outIter; + outIter.NextLine(); for (SizeValueType i = 0; i < numFrames; ++i) { - ++inputIters[i]; + inputIters[i].NextLine(); } } } diff --git a/Modules/Video/Filtering/include/itkFrameDifferenceVideoFilter.hxx b/Modules/Video/Filtering/include/itkFrameDifferenceVideoFilter.hxx index abde2a5c854..d3c1ef886a3 100644 --- a/Modules/Video/Filtering/include/itkFrameDifferenceVideoFilter.hxx +++ b/Modules/Video/Filtering/include/itkFrameDifferenceVideoFilter.hxx @@ -21,6 +21,7 @@ #include "itkImageRegionConstIterator.h" #include "itkImageRegionIterator.h" +#include "itkImageScanlineIterator.h" #include "itkNumericTraits.h" namespace itk @@ -113,31 +114,37 @@ FrameDifferenceVideoFilter::ThreadedGener } // Get iterators for the input frames - ImageRegionConstIterator I0Iter(input->GetFrame(inputStart), outputRegionForThread); - ImageRegionConstIterator I1Iter(input->GetFrame(inputStart + numFrames - 1), outputRegionForThread); + ImageScanlineConstIterator I0Iter(input->GetFrame(inputStart), outputRegionForThread); + ImageScanlineConstIterator I1Iter(input->GetFrame(inputStart + numFrames - 1), outputRegionForThread); // Get the output frame and its iterator - OutputFrameType * outFrame = output->GetFrame(outputFrameNumber); - ImageRegionIterator outIter(outFrame, outputRegionForThread); + OutputFrameType * outFrame = output->GetFrame(outputFrameNumber); + ImageScanlineIterator outIter(outFrame, outputRegionForThread); // Average the input frames at each pixel of the output region using InputPixelRealType = typename NumericTraits::RealType; while (!outIter.IsAtEnd()) { - // Compute the signed difference as a real value - InputPixelRealType val = - static_cast(I0Iter.Get()) - static_cast(I1Iter.Get()); - - // Square it - val *= val; - - // Set the output - outIter.Set(static_cast(val)); - - // Update the iterators - ++outIter; - ++I0Iter; - ++I1Iter; + while (!outIter.IsAtEndOfLine()) + { + // Compute the signed difference as a real value + InputPixelRealType val = + static_cast(I0Iter.Get()) - static_cast(I1Iter.Get()); + + // Square it + val *= val; + + // Set the output + outIter.Set(static_cast(val)); + + // Update the iterators + ++outIter; + ++I0Iter; + ++I1Iter; + } + outIter.NextLine(); + I0Iter.NextLine(); + I1Iter.NextLine(); } }