Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "itkConstantBoundaryCondition.h"
#include "itkOffset.h"
#include "itkProgressReporter.h"
#include "itkTotalProgressReporter.h"
#include "itkMath.h"
#include "itkPrintHelper.h"

Expand Down Expand Up @@ -75,10 +76,9 @@ BinaryDilateImageFilter<TInputImage, TOutputImage, TKernel>::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());
Comment thread
dzenanz marked this conversation as resolved.
Resolved

// Allocate and reset output. We copy the input to the output,
// except for pixels with DilateValue. These pixels are initially
Expand All @@ -100,8 +100,8 @@ BinaryDilateImageFilter<TInputImage, TOutputImage, TKernel>::GenerateData()
{
outIt.Set(static_cast<OutputPixelType>(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
Expand Down Expand Up @@ -158,8 +158,8 @@ BinaryDilateImageFilter<TInputImage, TOutputImage, TKernel>::GenerateData()
// it as background
tmpRegIt.Set(backgroundTag);
}
progress.CompletedPixel();
}
progress.Completed(requiredInputRegion.GetNumberOfPixels());

// Second stage
// Border tracking and encoding
Expand Down Expand Up @@ -451,6 +451,9 @@ BinaryDilateImageFilter<TInputImage, TOutputImage, TKernel>::GenerateData()
progress.CompletedPixel();
}
}

// The border tracking stage reports fewer pixels than it was allotted.
this->UpdateProgress(1.0f);
Comment on lines +455 to +456

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: two small points on the Greptile fix, which is needed (UpdateOutputData sets 1.0 only after an abort).

  1. progress is destroyed after this call, and ~TotalProgressReporter() then adds its leftover pixels. IncrementProgress wraps past the maximum and clamps back, so observers get a second ProgressEvent at 1.0. Putting the reporter in an inner block that ends before this line would avoid it.
  2. In erode, the tracking stage counts neighbors when it tags them, including ones in the padded band, so it can report more or fewer than its share, not only fewer. The same comment is in both filters:
Suggested change
// The border tracking stage reports fewer pixels than it was allotted.
this->UpdateProgress(1.0f);
// The border tracking stage does not report exactly its allotted pixels.

Reasoned from the code, not run.

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -75,10 +77,9 @@ BinaryErodeImageFilter<TInputImage, TOutputImage, TKernel>::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
Expand All @@ -90,8 +91,8 @@ BinaryErodeImageFilter<TInputImage, TOutputImage, TKernel>::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
Expand Down Expand Up @@ -148,8 +149,8 @@ BinaryErodeImageFilter<TInputImage, TOutputImage, TKernel>::GenerateData()
// it as background
tmpRegIt.Set(backgroundTag);
}
progress.CompletedPixel();
}
progress.Completed(requiredInputRegion.GetNumberOfPixels());

// Second stage
// Border tracking and encoding
Expand Down Expand Up @@ -447,18 +448,25 @@ BinaryErodeImageFilter<TInputImage, TOutputImage, TKernel>::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<OutputPixelType>(inValue));
const InputPixelType inValue = inIt.Get();
const OutputPixelType outValue = outLineIt.Get();
if (Math::ExactlyEquals(outValue, backgroundValue) && Math::NotExactlyEquals(inValue, foregroundValue))
{
outLineIt.Set(static_cast<OutputPixelType>(inValue));
}
}
progress.CompletedPixel();
progress.Completed(outputRegion.GetSize(0));
}

// The border tracking stage reports fewer pixels than it was allotted.
this->UpdateProgress(1.0f);
Comment on lines +468 to +469

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: same as on BinaryDilate: the comment wording, and the second ProgressEvent at 1.0 from the reporter's destructor.

Suggested change
// The border tracking stage reports fewer pixels than it was allotted.
this->UpdateProgress(1.0f);
// The border tracking stage does not report exactly its allotted pixels.

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define itkHessianGaussianImageFilter_hxx

#include "itkImageRegionIteratorWithIndex.h"
#include "itkImageScanlineIterator.h"
#include "itkProgressAccumulator.h"
#include "itkGaussianDerivativeOperator.h"
#include "itkMath.h"
Expand Down Expand Up @@ -230,22 +231,25 @@ HessianGaussianImageFilter<TInputImage, TOutputImage>::GenerateData()
// on the output image of vectors
m_ImageAdaptor->SelectNthElement(element++);

ImageRegionIteratorWithIndex<RealImageType> it(derivativeImage, derivativeImage->GetRequestedRegion());
ImageScanlineConstIterator<RealImageType> it(derivativeImage, derivativeImage->GetRequestedRegion());

ImageRegionIteratorWithIndex<OutputImageAdaptorType> ot(m_ImageAdaptor, m_ImageAdaptor->GetRequestedRegion());
ImageScanlineIterator<OutputImageAdaptorType> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define itkFFTWHalfHermitianToRealInverseFFTImageFilter_hxx

#include "itkImageRegionIterator.h"
#include "itkImageScanlineIterator.h"
#include "itkProgressReporter.h"
#include "itkMultiThreaderBase.h"

Expand Down Expand Up @@ -126,12 +127,16 @@ void
FFTWHalfHermitianToRealInverseFFTImageFilter<TInputImage, TOutputImage>::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();
}
}

Expand Down
13 changes: 9 additions & 4 deletions Modules/Filtering/FFT/include/itkFFTWInverseFFTImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "itkFullToHalfHermitianImageFilter.h"

#include "itkImageRegionIterator.h"
#include "itkImageScanlineIterator.h"
#include "itkProgressReporter.h"
#include "itkMultiThreaderBase.h"

Expand Down Expand Up @@ -104,12 +105,16 @@ void
FFTWInverseFFTImageFilter<TInputImage, TOutputImage>::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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define itkHessianRecursiveGaussianImageFilter_hxx

#include "itkImageRegionIterator.h"
#include "itkImageScanlineIterator.h"
#include "itkProgressAccumulator.h"
#include <algorithm> // For generate.

Expand Down Expand Up @@ -284,9 +285,9 @@ HessianRecursiveGaussianImageFilter<TInputImage, TOutputImage>::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];
Expand All @@ -295,9 +296,14 @@ HessianRecursiveGaussianImageFilter<TInputImage, TOutputImage>::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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "itkImageRegionIterator.h"
#include "itkImageRegionConstIterator.h"
#include "itkImageScanlineIterator.h"
#include "itkPrintHelper.h"
#include <algorithm> // For generate.

Expand Down Expand Up @@ -247,19 +248,24 @@ GradientRecursiveGaussianImageFilter<TInputImage, TOutputImage>::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<OutputComponentType>(
DefaultConvertPixelTraits<InternalRealType>::GetNthComponent(nc, it.Get() / spacing));
ot.Set(outValue);
++it;
++ot;
while (!it.IsAtEndOfLine())
{
auto outValue = static_cast<OutputComponentType>(
DefaultConvertPixelTraits<InternalRealType>::GetNthComponent(nc, it.Get() / spacing));
ot.Set(outValue);
++it;
++ot;
}
it.NextLine();
ot.NextLine();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "itkNumericTraits.h"
#include "itkProgressReporter.h"
#include "itkImageRegionIterator.h"
#include "itkImageScanlineIterator.h"
#include "itkProgressTransformer.h"
#include "itkPrintHelper.h"

Expand Down Expand Up @@ -98,22 +99,29 @@ LabelMapToBinaryImageFilter<TInputImage, TOutputImage>::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
Expand Down
Loading
Loading