21 #ifndef otbUnaryFunctorWithIndexImageFilter_hxx
22 #define otbUnaryFunctorWithIndexImageFilter_hxx
25 #include "itkImageRegionIterator.h"
26 #include "itkProgressReporter.h"
33 template <
class TInputImage,
class TOutputImage,
class TFunction>
36 this->SetNumberOfRequiredInputs(1);
38 template <
class TInputImage,
class TOutputImage,
class TFunction>
42 Superclass::GenerateInputRequestedRegion();
46 typename Superclass::InputImagePointer inputPtr =
const_cast<TInputImage*
>(this->GetInput());
47 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
49 if (!inputPtr || !outputPtr)
55 typename TInputImage::RegionType inputRequestedRegion;
56 inputRequestedRegion = inputPtr->GetRequestedRegion();
59 if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
61 inputPtr->SetRequestedRegion(inputRequestedRegion);
70 inputPtr->SetRequestedRegion(inputRequestedRegion);
73 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
74 std::ostringstream msg;
75 msg << this->GetNameOfClass() <<
"::GenerateInputRequestedRegion()";
76 e.SetLocation(msg.str());
77 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region.");
78 e.SetDataObject(inputPtr);
86 template <
class TInputImage,
class TOutputImage,
class TFunction>
88 itk::ThreadIdType threadId)
90 InputImagePointer inputPtr =
dynamic_cast<const TInputImage*
>(ProcessObjectType::GetInput(0));
95 this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
99 itk::ImageRegionIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread);
101 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
104 outputIt.GoToBegin();
106 while (!inputIt.IsAtEnd())
108 outputIt.Set(m_Functor(inputIt.Get(), inputIt.GetIndex()));
111 progress.CompletedPixel();