21 #ifndef otbUnaryFunctorNeighborhoodImageFilter_hxx
22 #define otbUnaryFunctorNeighborhoodImageFilter_hxx
25 #include "itkImageRegionIterator.h"
26 #include "itkNeighborhoodAlgorithm.h"
27 #include "itkProgressReporter.h"
28 #include "itkZeroFluxNeumannBoundaryCondition.h"
29 #include "itkNeighborhoodAlgorithm.h"
36 template <
class TInputImage,
class TOutputImage,
class TFunction>
39 this->SetNumberOfRequiredInputs(1);
42 template <
class TInputImage,
class TOutputImage,
class TFunction>
46 Superclass::GenerateInputRequestedRegion();
50 typename Superclass::InputImagePointer inputPtr =
const_cast<TInputImage*
>(this->GetInput());
51 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
53 if (!inputPtr || !outputPtr)
59 typename TInputImage::RegionType inputRequestedRegion;
60 inputRequestedRegion = inputPtr->GetRequestedRegion();
63 inputRequestedRegion.PadByRadius(m_Radius);
66 if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
68 inputPtr->SetRequestedRegion(inputRequestedRegion);
77 inputPtr->SetRequestedRegion(inputRequestedRegion);
80 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
81 std::ostringstream msg;
82 msg << this->GetNameOfClass() <<
"::GenerateInputRequestedRegion()";
83 e.SetLocation(msg.str());
84 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region.");
85 e.SetDataObject(inputPtr);
93 template <
class TInputImage,
class TOutputImage,
class TFunction>
95 itk::ThreadIdType threadId)
97 itk::ZeroFluxNeumannBoundaryCondition<TInputImage> nbc;
102 InputImagePointer inputPtr =
dynamic_cast<const TInputImage*
>(ProcessObjectType::GetInput(0));
112 itk::ImageRegionIterator<TOutputImage> outputIt;
115 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage>::FaceListType faceList;
116 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage> bC;
117 faceList = bC(inputPtr, outputRegionForThread, r);
119 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage>::FaceListType::iterator fit;
122 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
126 for (fit = faceList.begin(); fit != faceList.end(); ++fit)
128 neighInputIt = itk::ConstNeighborhoodIterator<TInputImage>(r, inputPtr, *fit);
130 outputIt = itk::ImageRegionIterator<TOutputImage>(outputPtr, *fit);
131 neighInputIt.OverrideBoundaryCondition(&nbc);
132 neighInputIt.GoToBegin();
134 while (!outputIt.IsAtEnd())
137 outputIt.Set(m_Functor(neighInputIt));
141 progress.CompletedPixel();