21 #ifndef otbUnaryImageFunctorWithVectorImageFilter_hxx
22 #define otbUnaryImageFunctorWithVectorImageFilter_hxx
25 #include "itkImageRegionIterator.h"
26 #include "itkProgressReporter.h"
34 template <
class TInputImage,
class TOutputImage,
class TFunction>
37 this->SetNumberOfRequiredInputs(1);
51 template <
class TInputImage,
class TOutputImage,
class TFunction>
54 Superclass::GenerateOutputInformation();
57 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
58 typename Superclass::InputImageConstPointer inputPtr = this->GetInput();
60 if (!outputPtr || !inputPtr)
64 outputPtr->SetNumberOfComponentsPerPixel(
65 inputPtr->GetNumberOfComponentsPerPixel());
69 for (
unsigned int i = 0; i < inputPtr->GetNumberOfComponentsPerPixel(); ++i)
72 m_FunctorVector.push_back(functor);
79 template <
class TInputImage,
class TOutputImage,
class TFunction>
81 itk::ThreadIdType threadId)
83 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
84 typename Superclass::InputImageConstPointer inputPtr = this->GetInput();
88 itk::ImageRegionConstIterator<InputImageType> inputIt(inputPtr, outputRegionForThread);
89 itk::ImageRegionIterator<OutputImageType> outputIt(outputPtr, outputRegionForThread);
91 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
98 nullPixel.SetSize(inputPtr->GetNumberOfComponentsPerPixel());
99 nullPixel.Fill(itk::NumericTraits<OutputInternalPixelType>::Zero);
101 while (!inputIt.IsAtEnd())
105 outPixel.SetSize(inputPtr->GetNumberOfComponentsPerPixel());
106 outPixel.Fill(itk::NumericTraits<OutputInternalPixelType>::Zero);
108 if (inPixel != nullPixel)
110 for (
unsigned int j = 0; j < inputPtr->GetNumberOfComponentsPerPixel(); ++j)
112 outPixel[j] = m_FunctorVector[j](inPixel[j]);
115 outputIt.Set(outPixel);
118 progress.CompletedPixel();
122 template <
class TInputImage,
class TOutputImage,
class TFunction>
125 this->Superclass::PrintSelf(os, indent);