21 #ifndef otbPixelSuppressionByDirectionImageFilter_hxx
22 #define otbPixelSuppressionByDirectionImageFilter_hxx
27 #include "itkDataObject.h"
28 #include "itkConstNeighborhoodIterator.h"
29 #include "itkNeighborhoodInnerProduct.h"
30 #include "itkImageRegionIterator.h"
31 #include "itkNeighborhoodAlgorithm.h"
32 #include "itkConstantBoundaryCondition.h"
33 #include "itkOffset.h"
34 #include "itkProgressReporter.h"
43 template <
class TInputImage,
class TOutputImage>
47 m_AngularBeam =
static_cast<double>(0.);
48 this->DynamicMultiThreadingOn();
52 template <
class TInputImage,
class TOutputImage>
55 this->SetInput(0, input);
58 template <
class TInputImage,
class TOutputImage>
61 this->SetInput(1, input);
64 template <
class TInputImage,
class TOutputImage>
68 if (this->GetNumberOfInputs() < 1)
73 return static_cast<const TInputImage*
>(this->GetInput(0));
76 template <
class TInputImage,
class TOutputImage>
80 if (this->GetNumberOfInputs() < 1)
85 return static_cast<const TInputImage*
>(this->GetInput(1));
88 template <
class TInputImage,
class TOutputImage>
92 Superclass::GenerateInputRequestedRegion();
95 typename Superclass::InputImagePointer inputPtr =
const_cast<TInputImage*
>(this->GetInputImageDirection());
96 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
98 if (!inputPtr || !outputPtr)
105 typename TInputImage::RegionType inputRequestedRegion;
106 inputRequestedRegion = inputPtr->GetRequestedRegion();
109 inputRequestedRegion.PadByRadius(m_Radius);
112 if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
114 inputPtr->SetRequestedRegion(inputRequestedRegion);
123 inputPtr->SetRequestedRegion(inputRequestedRegion);
126 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
127 std::ostringstream msg;
128 msg << static_cast<const char*>(this->GetNameOfClass()) <<
"::GenerateInputRequestedRegion()";
129 e.SetLocation(msg.str());
130 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region.");
131 e.SetDataObject(inputPtr);
136 template <
class TInputImage,
class TOutputImage>
140 itk::ConstantBoundaryCondition<InputImageType> cbc;
142 cbc.SetConstant(cvalue);
144 itk::ConstNeighborhoodIterator<InputImageType> bit;
145 itk::ImageRegionConstIterator<InputImageType> itin;
146 itk::ImageRegionIterator<OutputImageType> itout;
149 typename OutputImageType::Pointer output = this->GetOutput();
150 typename InputImageType::ConstPointer input = this->GetInputImage();
151 typename InputImageType::ConstPointer inputDirection = this->GetInputImageDirection();
154 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType>::FaceListType faceList;
155 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType>::FaceListType::iterator fit;
157 itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType> bC;
158 faceList = bC(inputDirection, outputRegionForThread, m_Radius);
176 double ThetaXcYc, Thetaxtyt;
182 for (fit = faceList.begin(); fit != faceList.end(); ++fit)
184 bit = itk::ConstNeighborhoodIterator<InputImageType>(m_Radius, inputDirection, *fit);
186 itin = itk::ImageRegionConstIterator<InputImageType>(input, *fit);
187 itout = itk::ImageRegionIterator<OutputImageType>(output, *fit);
189 bit.OverrideBoundaryCondition(&cbc);
192 while (!bit.IsAtEnd())
202 ThetaXcYc =
static_cast<double>(bit.GetCenterPixel());
205 PixelValue = itin.Get();
209 typename itk::ConstNeighborhoodIterator<InputImageType>::OffsetType off;
211 for (
unsigned int i = 0; i < 2 * m_Radius[0] + 1; ++i)
212 for (
unsigned int j = 0; j < 2 * m_Radius[1] + 1; ++j)
215 off[0] = i - m_Radius[0];
216 off[1] = j - m_Radius[1];
222 if ((x == 0) && (y == 0))
225 Thetaxtyt = std::atan2(
static_cast<double>(y),
static_cast<double>(x));
226 while (Thetaxtyt < 0)
232 if ((std::abs(std::cos(Thetaxtyt - ThetaXcYc)) >= std::cos(m_AngularBeam))
238 && (std::abs(std::cos(bit.GetPixel(off) - ThetaXcYc)) >= std::cos(m_AngularBeam)))
273 template <
class TInputImage,
class TOutput>
276 Superclass::PrintSelf(os, indent);
277 os << indent <<
"Radius: " << m_Radius << std::endl;
PixelSuppressionByDirectionImageFilter()
void GenerateInputRequestedRegion() override
InputImageType::PixelType InputPixelType
OutputImageType::RegionType OutputImageRegionType
OutputImageType::PixelType OutputPixelType
const InputImageType * GetInputImage(void)
void SetInputImageDirection(const InputImageType *image)
void PrintSelf(std::ostream &os, itk::Indent indent) const override
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
void SetInputImage(const InputImageType *image)
TInputImage InputImageType
const InputImageType * GetInputImageDirection(void)
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
constexpr double CONST_PI_2
constexpr double CONST_PI