21 #ifndef otbUnaryFunctorNeighborhoodWithOffsetImageFilter_hxx
22 #define otbUnaryFunctorNeighborhoodWithOffsetImageFilter_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 m_FunctorList.clear();
46 template <
class TInputImage,
class TOutputImage,
class TFunction>
49 Superclass::BeforeThreadedGenerateData();
51 for (itk::ThreadIdType i = 0; i < this->GetNumberOfThreads(); ++i)
53 m_FunctorList.push_back(m_Functor);
57 template <
class TInputImage,
class TOutputImage,
class TFunction>
61 Superclass::GenerateInputRequestedRegion();
64 typename Superclass::InputImagePointer inputPtr =
const_cast<TInputImage*
>(this->GetInput());
65 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
67 if (!inputPtr || !outputPtr)
73 typename TInputImage::RegionType inputRequestedRegion;
74 inputRequestedRegion = inputPtr->GetRequestedRegion();
78 maxRad[0] = m_Radius[0] + std::abs(m_Offset[0]);
79 maxRad[1] = m_Radius[1] + std::abs(m_Offset[1]);
80 inputRequestedRegion.PadByRadius(maxRad);
83 if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
85 inputPtr->SetRequestedRegion(inputRequestedRegion);
94 inputPtr->SetRequestedRegion(inputRequestedRegion);
97 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
98 std::ostringstream msg;
99 msg << this->GetNameOfClass() <<
"::GenerateInputRequestedRegion()";
100 e.SetLocation(msg.str());
101 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region.");
102 e.SetDataObject(inputPtr);
110 template <
class TInputImage,
class TOutputImage,
class TFunction>
114 itk::ZeroFluxNeumannBoundaryCondition<TInputImage> nbc;
115 itk::ZeroFluxNeumannBoundaryCondition<TInputImage> nbcOff;
119 InputImagePointer inputPtr =
dynamic_cast<const TInputImage*
>(ProcessObjectType::GetInput(0));
123 itk::ImageRegionIterator<TOutputImage> outputIt;
127 rOff[0] = m_Radius[0] + std::abs(m_Offset[0]);
128 rOff[1] = m_Radius[1] + std::abs(m_Offset[1]);
131 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage>::FaceListType faceListOff;
132 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage> bCOff;
133 faceListOff = bCOff(inputPtr, outputRegionForThread, rOff);
134 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage>::FaceListType::iterator fitOff;
137 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
141 fitOff = faceListOff.begin();
143 while (fitOff != faceListOff.end())
146 neighInputOffIt = itk::ConstNeighborhoodIterator<TInputImage>(rOff, inputPtr, *fitOff);
147 neighInputOffIt.OverrideBoundaryCondition(&nbcOff);
148 neighInputOffIt.GoToBegin();
150 outputIt = itk::ImageRegionIterator<TOutputImage>(outputPtr, *fitOff);
152 while (!outputIt.IsAtEnd())
155 outputIt.Set(m_FunctorList[threadId](neighInputOffIt.GetNeighborhood()));
159 progress.CompletedPixel();