diff --git a/Modules/Filtering/ImageCompose/include/itkComposeImageFilter.h b/Modules/Filtering/ImageCompose/include/itkComposeImageFilter.h index 8073fd6c8c5..b2329d432fd 100644 --- a/Modules/Filtering/ImageCompose/include/itkComposeImageFilter.h +++ b/Modules/Filtering/ImageCompose/include/itkComposeImageFilter.h @@ -20,7 +20,7 @@ #include "itkImageToImageFilter.h" #include "itkVectorImage.h" -#include "itkImageRegionConstIterator.h" +#include "itkImageScanlineIterator.h" #include namespace itk @@ -108,27 +108,8 @@ class ITK_TEMPLATE_EXPORT ComposeImageFilter : public ImageToImageFilter; + using InputIteratorType = ImageScanlineConstIterator; using InputIteratorContainerType = std::vector; - - template - void - ComputeOutputPixel(std::complex & pix, InputIteratorContainerType & inputItContainer) - { - pix = std::complex(inputItContainer[0].Get(), inputItContainer[1].Get()); - ++(inputItContainer[0]); - ++(inputItContainer[1]); - } - template - void - ComputeOutputPixel(TPixel & pix, InputIteratorContainerType & inputItContainer) - { - for (unsigned int i = 0; i < this->GetNumberOfInputs(); ++i) - { - pix[i] = static_cast::ValueType>(inputItContainer[i].Get()); - ++(inputItContainer[i]); - } - } }; } // namespace itk diff --git a/Modules/Filtering/ImageCompose/include/itkComposeImageFilter.hxx b/Modules/Filtering/ImageCompose/include/itkComposeImageFilter.hxx index d1e786c1a26..60a520f1786 100644 --- a/Modules/Filtering/ImageCompose/include/itkComposeImageFilter.hxx +++ b/Modules/Filtering/ImageCompose/include/itkComposeImageFilter.hxx @@ -87,7 +87,7 @@ ComposeImageFilter::BeforeThreadedGenerateData() for (unsigned int i = 0; i < numberOfInputs; ++i) { - auto * input = itkDynamicCastInDebugMode(this->ProcessObject::GetInput(i)); + auto * input = this->GetInput(i); if (!input) { itkExceptionMacro("Input " << i << " not set!"); @@ -108,33 +108,53 @@ template void ComposeImageFilter::DynamicThreadedGenerateData(const RegionType & outputRegionForThread) { - const typename OutputImageType::Pointer outputImage = - static_cast(this->ProcessObject::GetOutput(0)); - + const typename OutputImageType::Pointer outputImage = this->GetOutput(); TotalProgressReporter progress(this, outputImage->GetRequestedRegion().GetNumberOfPixels()); - ImageRegionIterator oit(outputImage, outputRegionForThread); InputIteratorContainerType inputItContainer; + inputItContainer.reserve(this->GetNumberOfIndexedInputs()); for (unsigned int i = 0; i < this->GetNumberOfIndexedInputs(); ++i) { const InputImageType * inputImage = this->GetInput(i); - InputIteratorType iit(inputImage, outputRegionForThread); - iit.GoToBegin(); - inputItContainer.push_back(iit); + inputItContainer.emplace_back(inputImage, outputRegionForThread); } OutputPixelType pix; NumericTraits::SetLength(pix, static_cast(this->GetNumberOfIndexedInputs())); - while (!oit.IsAtEnd()) + for (ImageScanlineIterator oit(outputImage, outputRegionForThread); !oit.IsAtEnd(); oit.NextLine()) { - ComputeOutputPixel(pix, inputItContainer); - oit.Set(pix); - ++oit; - progress.CompletedPixel(); + while (!oit.IsAtEndOfLine()) + { + if constexpr (std::is_same::ValueType>>::value) + { + oit.Set({ inputItContainer[0].Get(), inputItContainer[1].Get() }); + ++(inputItContainer[0]); + ++(inputItContainer[1]); + } + else + { + unsigned int i = 0; + for (auto & it : inputItContainer) + { + pix[i] = static_cast::ValueType>(it.Get()); + ++i; + ++it; + } + + oit.Set(pix); + } + ++oit; + } + for (auto & it : inputItContainer) + { + it.NextLine(); + } + progress.Completed(outputRegionForThread.GetSize()[0]); } } } // end namespace itk