21 #ifndef otbBinaryFunctorNeighborhoodImageFilter_hxx
22 #define otbBinaryFunctorNeighborhoodImageFilter_hxx
25 #include "itkImageRegionIterator.h"
26 #include "itkNeighborhoodAlgorithm.h"
27 #include "itkProgressReporter.h"
35 template <
class TInputImage1,
class TInputImage2,
class TOutputImage,
class TFunction>
38 this->SetNumberOfRequiredInputs(2);
46 template <
class TInputImage1,
class TInputImage2,
class TOutputImage,
class TFunction>
50 this->SetNthInput(0,
const_cast<TInputImage1*
>(image1));
56 template <
class TInputImage1,
class TInputImage2,
class TOutputImage,
class TFunction>
60 this->SetNthInput(1,
const_cast<TInputImage2*
>(image2));
63 template <
class TInputImage1,
class TInputImage2,
class TOutputImage,
class TFunction>
66 if (this->GetNumberOfInputs() < 1)
70 return static_cast<const TInputImage1*
>(this->itk::ProcessObject::GetInput(0));
73 template <
class TInputImage1,
class TInputImage2,
class TOutputImage,
class TFunction>
76 if (this->GetNumberOfInputs() < 2)
80 return static_cast<const TInputImage2*
>(this->itk::ProcessObject::GetInput(1));
83 template <
class TInputImage1,
class TInputImage2,
class TOutputImage,
class TFunction>
87 Superclass::GenerateInputRequestedRegion();
92 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
94 if (!inputPtr1 || !inputPtr2 || !outputPtr)
100 typename TInputImage1::RegionType inputRequestedRegion1, inputRequestedRegion2;
101 inputRequestedRegion1 = inputPtr1->GetRequestedRegion();
104 inputRequestedRegion1.PadByRadius(m_Radius);
105 inputRequestedRegion2 = inputRequestedRegion1;
108 if (inputRequestedRegion1.Crop(inputPtr1->GetLargestPossibleRegion()))
110 inputPtr1->SetRequestedRegion(inputRequestedRegion1);
118 inputPtr1->SetRequestedRegion(inputRequestedRegion1);
121 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
122 std::ostringstream msg;
123 msg << this->GetNameOfClass() <<
"::GenerateInputRequestedRegion()";
124 e.SetLocation(msg.str());
125 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region of image 1.");
126 e.SetDataObject(inputPtr1);
129 if (inputRequestedRegion2.Crop(inputPtr2->GetLargestPossibleRegion()))
131 inputPtr2->SetRequestedRegion(inputRequestedRegion2);
139 inputPtr2->SetRequestedRegion(inputRequestedRegion2);
142 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
143 std::ostringstream msg;
144 msg << this->GetNameOfClass() <<
"::GenerateInputRequestedRegion()";
145 e.SetLocation(msg.str());
146 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region of image 1.");
147 e.SetDataObject(inputPtr2);
156 template <
class TInputImage1,
class TInputImage2,
class TOutputImage,
class TFunction>
162 itk::ZeroFluxNeumannBoundaryCondition<TInputImage1> nbc1;
163 itk::ZeroFluxNeumannBoundaryCondition<TInputImage2> nbc2;
182 itk::ImageRegionIterator<TOutputImage> outputIt;
185 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage1>::FaceListType faceList1;
186 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage1> bC1;
187 faceList1 = bC1(inputPtr1, outputRegionForThread, r1);
189 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage2>::FaceListType faceList2;
190 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage2> bC2;
191 faceList2 = bC2(inputPtr2, outputRegionForThread, r2);
193 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage1>::FaceListType::iterator fit1;
194 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage2>::FaceListType::iterator fit2;
197 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
201 for (fit1 = faceList1.begin(), fit2 = faceList2.begin(); fit1 != faceList1.end() && fit2 != faceList2.end(); ++fit1, ++fit2)
203 neighInputIt1 = itk::ConstNeighborhoodIterator<TInputImage1>(r1, inputPtr1, *fit1);
204 neighInputIt2 = itk::ConstNeighborhoodIterator<TInputImage2>(r2, inputPtr2, *fit2);
207 outputIt = itk::ImageRegionIterator<TOutputImage>(outputPtr, *fit1);
208 neighInputIt1.OverrideBoundaryCondition(&nbc1);
209 neighInputIt1.GoToBegin();
210 neighInputIt2.OverrideBoundaryCondition(&nbc2);
211 neighInputIt2.GoToBegin();
213 while (!outputIt.IsAtEnd())
216 outputIt.Set(m_Functor(neighInputIt1, neighInputIt2));
221 progress.CompletedPixel();