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);
41 this->DynamicMultiThreadingOn();
43 template <
class TInputImage,
class TOutputImage,
class TFunction>
47 Superclass::GenerateInputRequestedRegion();
51 typename Superclass::InputImagePointer inputPtr =
const_cast<TInputImage*
>(this->GetInput());
52 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
54 if (!inputPtr || !outputPtr)
60 typename TInputImage::RegionType inputRequestedRegion;
61 inputRequestedRegion = inputPtr->GetRequestedRegion();
64 inputRequestedRegion.PadByRadius(m_Radius);
67 if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
69 inputPtr->SetRequestedRegion(inputRequestedRegion);
78 inputPtr->SetRequestedRegion(inputRequestedRegion);
81 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
82 std::ostringstream msg;
83 msg << this->GetNameOfClass() <<
"::GenerateInputRequestedRegion()";
84 e.SetLocation(msg.str());
85 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region.");
86 e.SetDataObject(inputPtr);
94 template <
class TInputImage,
class TOutputImage,
class TFunction>
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;
123 for (fit = faceList.begin(); fit != faceList.end(); ++fit)
125 neighInputIt = itk::ConstNeighborhoodIterator<TInputImage>(r, inputPtr, *fit);
127 outputIt = itk::ImageRegionIterator<TOutputImage>(outputPtr, *fit);
128 neighInputIt.OverrideBoundaryCondition(&nbc);
129 neighInputIt.GoToBegin();
131 while (!outputIt.IsAtEnd())
134 outputIt.Set(m_Functor(neighInputIt));
InputImageType::ConstPointer InputImagePointer
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
void GenerateInputRequestedRegion(void) override
OutputImageType::Pointer OutputImagePointer
itk::ConstNeighborhoodIterator< TInputImage > NeighborhoodIteratorType
OutputImageType::RegionType OutputImageRegionType
UnaryFunctorNeighborhoodImageFilter()
NeighborhoodIteratorType::RadiusType RadiusType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.