21 #ifndef otbUnaryFunctorNeighborhoodWithOffsetImageFilter_hxx
22 #define otbUnaryFunctorNeighborhoodWithOffsetImageFilter_hxx
26 #include "itkImageRegionIterator.h"
27 #include "itkNeighborhoodAlgorithm.h"
28 #include "itkProgressReporter.h"
29 #include "itkZeroFluxNeumannBoundaryCondition.h"
30 #include "itkNeighborhoodAlgorithm.h"
37 template <
class TInputImage,
class TOutputImage,
class TFunction>
40 this->DynamicMultiThreadingOff();
41 this->SetNumberOfRequiredInputs(1);
44 m_FunctorList.clear();
48 template <
class TInputImage,
class TOutputImage,
class TFunction>
51 Superclass::BeforeThreadedGenerateData();
53 for (itk::ThreadIdType i = 0; i < this->GetNumberOfWorkUnits(); ++i)
55 m_FunctorList.push_back(m_Functor);
59 template <
class TInputImage,
class TOutputImage,
class TFunction>
63 Superclass::GenerateInputRequestedRegion();
66 typename Superclass::InputImagePointer inputPtr =
const_cast<TInputImage*
>(this->GetInput());
67 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
69 if (!inputPtr || !outputPtr)
75 typename TInputImage::RegionType inputRequestedRegion;
76 inputRequestedRegion = inputPtr->GetRequestedRegion();
80 maxRad[0] = m_Radius[0] + std::abs(m_Offset[0]);
81 maxRad[1] = m_Radius[1] + std::abs(m_Offset[1]);
82 inputRequestedRegion.PadByRadius(maxRad);
85 if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
87 inputPtr->SetRequestedRegion(inputRequestedRegion);
96 inputPtr->SetRequestedRegion(inputRequestedRegion);
99 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
100 std::ostringstream msg;
101 msg << this->GetNameOfClass() <<
"::GenerateInputRequestedRegion()";
102 e.SetLocation(msg.str());
103 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region.");
104 e.SetDataObject(inputPtr);
112 template <
class TInputImage,
class TOutputImage,
class TFunction>
116 itk::ZeroFluxNeumannBoundaryCondition<TInputImage> nbc;
117 itk::ZeroFluxNeumannBoundaryCondition<TInputImage> nbcOff;
121 InputImagePointer inputPtr =
dynamic_cast<const TInputImage*
>(ProcessObjectType::GetInput(0));
125 itk::ImageRegionIterator<TOutputImage> outputIt;
129 rOff[0] = m_Radius[0] + std::abs(m_Offset[0]);
130 rOff[1] = m_Radius[1] + std::abs(m_Offset[1]);
133 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage>::FaceListType faceListOff;
134 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage> bCOff;
135 faceListOff = bCOff(inputPtr, outputRegionForThread, rOff);
136 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage>::FaceListType::iterator fitOff;
139 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
143 fitOff = faceListOff.begin();
145 while (fitOff != faceListOff.end())
148 neighInputOffIt = itk::ConstNeighborhoodIterator<TInputImage>(rOff, inputPtr, *fitOff);
149 neighInputOffIt.OverrideBoundaryCondition(&nbcOff);
150 neighInputOffIt.GoToBegin();
152 outputIt = itk::ImageRegionIterator<TOutputImage>(outputPtr, *fitOff);
154 while (!outputIt.IsAtEnd())
157 outputIt.Set(m_FunctorList[threadId](neighInputOffIt.GetNeighborhood()));
161 progress.CompletedPixel();
NeighborhoodIteratorType::RadiusType RadiusType
OutputImageType::Pointer OutputImagePointer
UnaryFunctorNeighborhoodWithOffsetImageFilter()
InputImageType::SizeType InputImageSizeType
void GenerateInputRequestedRegion(void) override
itk::ConstNeighborhoodIterator< TInputImage > NeighborhoodIteratorType
OutputImageType::RegionType OutputImageRegionType
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId) override
void BeforeThreadedGenerateData() override
InputImageType::ConstPointer InputImagePointer
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.