21 #ifndef otbPixelSuppressionByDirectionImageFilter_hxx
22 #define otbPixelSuppressionByDirectionImageFilter_hxx
26 #include "itkDataObject.h"
27 #include "itkConstNeighborhoodIterator.h"
28 #include "itkNeighborhoodInnerProduct.h"
29 #include "itkImageRegionIterator.h"
30 #include "itkNeighborhoodAlgorithm.h"
31 #include "itkConstantBoundaryCondition.h"
32 #include "itkOffset.h"
33 #include "itkProgressReporter.h"
42 template <
class TInputImage,
class TOutputImage>
47 m_AngularBeam =
static_cast<double>(0.);
50 template <
class TInputImage,
class TOutputImage>
53 this->SetInput(0, input);
56 template <
class TInputImage,
class TOutputImage>
59 this->SetInput(1, input);
62 template <
class TInputImage,
class TOutputImage>
66 if (this->GetNumberOfInputs() < 1)
71 return static_cast<const TInputImage*
>(this->GetInput(0));
74 template <
class TInputImage,
class TOutputImage>
78 if (this->GetNumberOfInputs() < 1)
83 return static_cast<const TInputImage*
>(this->GetInput(1));
86 template <
class TInputImage,
class TOutputImage>
90 Superclass::GenerateInputRequestedRegion();
93 typename Superclass::InputImagePointer inputPtr =
const_cast<TInputImage*
>(this->GetInputImageDirection());
94 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
96 if (!inputPtr || !outputPtr)
103 typename TInputImage::RegionType inputRequestedRegion;
104 inputRequestedRegion = inputPtr->GetRequestedRegion();
107 inputRequestedRegion.PadByRadius(m_Radius);
110 if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
112 inputPtr->SetRequestedRegion(inputRequestedRegion);
121 inputPtr->SetRequestedRegion(inputRequestedRegion);
124 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
125 std::ostringstream msg;
126 msg << static_cast<const char*>(this->GetNameOfClass()) <<
"::GenerateInputRequestedRegion()";
127 e.SetLocation(msg.str());
128 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region.");
129 e.SetDataObject(inputPtr);
134 template <
class TInputImage,
class TOutputImage>
136 itk::ThreadIdType threadId)
139 itk::ConstantBoundaryCondition<InputImageType> cbc;
141 cbc.SetConstant(cvalue);
143 itk::ConstNeighborhoodIterator<InputImageType> bit;
144 itk::ImageRegionConstIterator<InputImageType> itin;
145 itk::ImageRegionIterator<OutputImageType> itout;
148 typename OutputImageType::Pointer output = this->GetOutput();
149 typename InputImageType::ConstPointer input = this->GetInputImage();
150 typename InputImageType::ConstPointer inputDirection = this->GetInputImageDirection();
153 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType>::FaceListType faceList;
154 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType>::FaceListType::iterator fit;
156 itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType> bC;
157 faceList = bC(inputDirection, outputRegionForThread, m_Radius);
160 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
178 double ThetaXcYc, Thetaxtyt;
184 for (fit = faceList.begin(); fit != faceList.end(); ++fit)
186 bit = itk::ConstNeighborhoodIterator<InputImageType>(m_Radius, inputDirection, *fit);
188 itin = itk::ImageRegionConstIterator<InputImageType>(input, *fit);
189 itout = itk::ImageRegionIterator<OutputImageType>(output, *fit);
191 bit.OverrideBoundaryCondition(&cbc);
194 while (!bit.IsAtEnd())
204 ThetaXcYc =
static_cast<double>(bit.GetCenterPixel());
207 PixelValue = itin.Get();
211 typename itk::ConstNeighborhoodIterator<InputImageType>::OffsetType off;
213 for (
unsigned int i = 0; i < 2 * m_Radius[0] + 1; ++i)
214 for (
unsigned int j = 0; j < 2 * m_Radius[1] + 1; ++j)
217 off[0] = i - m_Radius[0];
218 off[1] = j - m_Radius[1];
224 if ((x == 0) && (y == 0))
227 Thetaxtyt = std::atan2(
static_cast<double>(y),
static_cast<double>(x));
228 while (Thetaxtyt < 0)
234 if ((std::abs(std::cos(Thetaxtyt - ThetaXcYc)) >= std::cos(m_AngularBeam))
240 && (std::abs(std::cos(bit.GetPixel(off) - ThetaXcYc)) >= std::cos(m_AngularBeam)))
268 progress.CompletedPixel();
276 template <
class TInputImage,
class TOutput>
279 Superclass::PrintSelf(os, indent);
280 os << indent <<
"Radius: " << m_Radius << std::endl;