22 #ifndef otbFunctionWithNeighborhoodToImageFilter_hxx
23 #define otbFunctionWithNeighborhoodToImageFilter_hxx
34 template <
class TInputImage,
class TOutputImage,
class TFunction>
37 this->DynamicMultiThreadingOff();
39 this->SetNumberOfRequiredInputs(1);
42 m_FunctionList.clear();
43 m_Function = FunctionType::New();
47 template <
class TInputImage,
class TOutputImage,
class TFunction>
50 Superclass::BeforeThreadedGenerateData();
53 if (inputPtr.IsNull())
55 itkExceptionMacro(<<
"At least one input is missing."
56 <<
" Input is missing :" << inputPtr.GetPointer();)
58 m_Function->SetInputImage(inputPtr);
59 for (
unsigned int i = 0; i < static_cast<unsigned int>(this->GetNumberOfWorkUnits()); ++i)
62 m_FunctionList.push_back(func);
66 template <
class TInputImage,
class TOutputImage,
class TFunction>
70 Superclass::GenerateInputRequestedRegion();
76 if (!inputPtr || !outputPtr)
86 maxRad[0] = m_Radius[0] + std::abs(m_Offset[0]);
87 maxRad[1] = m_Radius[0] + std::abs(m_Offset[1]);
88 inputRequestedRegion.PadByRadius(maxRad);
91 if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
93 inputPtr->SetRequestedRegion(inputRequestedRegion);
102 inputPtr->SetRequestedRegion(inputRequestedRegion);
105 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
106 std::ostringstream msg;
107 msg << this->GetNameOfClass() <<
"::GenerateInputRequestedRegion()";
108 e.SetLocation(msg.str());
109 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region.");
110 e.SetDataObject(inputPtr);
118 template <
class TInputImage,
class TOutputImage,
class TFunction>
120 itk::ThreadIdType threadId)
127 itk::ImageRegionConstIterator<TInputImage> inputIt(inputPtr, outputRegionForThread);
128 itk::ImageRegionIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread);
130 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
133 outputIt.GoToBegin();
135 while (!inputIt.IsAtEnd())
137 outputIt.Set(
static_cast<OutputImagePixelType>(m_FunctionList[threadId]->EvaluateAtIndex(inputIt.GetIndex())));
141 progress.CompletedPixel();
OutputImageType::PixelType OutputImagePixelType
OutputImageType::Pointer OutputImagePointer
InputImageType::ConstPointer InputImageConstPointer
void GenerateInputRequestedRegion() override
InputImageType::RegionType InputImageRegionType
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId) override
void BeforeThreadedGenerateData() override
OutputImageType::RegionType OutputImageRegionType
InputImageType::Pointer InputImagePointer
InputImageType::SizeType InputImageSizeType
FunctionWithNeighborhoodToImageFilter()
FunctionType::Pointer FunctionPointerType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.