22 #ifndef otbFunctionWithNeighborhoodToImageFilter_hxx
23 #define otbFunctionWithNeighborhoodToImageFilter_hxx
34 template <
class TInputImage,
class TOutputImage,
class TFunction>
38 this->SetNumberOfRequiredInputs(1);
41 m_FunctionList.clear();
42 m_Function = FunctionType::New();
46 template <
class TInputImage,
class TOutputImage,
class TFunction>
49 Superclass::BeforeThreadedGenerateData();
52 if (inputPtr.IsNull())
54 itkExceptionMacro(<<
"At least one input is missing."
55 <<
" Input is missing :" << inputPtr.GetPointer();)
57 m_Function->SetInputImage(inputPtr);
58 for (
unsigned int i = 0; i < static_cast<unsigned int>(this->GetNumberOfThreads()); ++i)
61 m_FunctionList.push_back(func);
65 template <
class TInputImage,
class TOutputImage,
class TFunction>
69 Superclass::GenerateInputRequestedRegion();
75 if (!inputPtr || !outputPtr)
85 maxRad[0] = m_Radius[0] + std::abs(m_Offset[0]);
86 maxRad[1] = m_Radius[0] + std::abs(m_Offset[1]);
87 inputRequestedRegion.PadByRadius(maxRad);
90 if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
92 inputPtr->SetRequestedRegion(inputRequestedRegion);
101 inputPtr->SetRequestedRegion(inputRequestedRegion);
104 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
105 std::ostringstream msg;
106 msg << this->GetNameOfClass() <<
"::GenerateInputRequestedRegion()";
107 e.SetLocation(msg.str());
108 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region.");
109 e.SetDataObject(inputPtr);
117 template <
class TInputImage,
class TOutputImage,
class TFunction>
119 itk::ThreadIdType threadId)
126 itk::ImageRegionConstIterator<TInputImage> inputIt(inputPtr, outputRegionForThread);
127 itk::ImageRegionIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread);
129 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
132 outputIt.GoToBegin();
134 while (!inputIt.IsAtEnd())
136 outputIt.Set(
static_cast<OutputImagePixelType>(m_FunctionList[threadId]->EvaluateAtIndex(inputIt.GetIndex())));
140 progress.CompletedPixel();