21 #ifndef otbBinaryImageToDensityImageFilter_hxx
22 #define otbBinaryImageToDensityImageFilter_hxx
25 #include "itkImageRegionIterator.h"
26 #include "itkProgressReporter.h"
27 #include "itkZeroFluxNeumannBoundaryCondition.h"
28 #include "itkNeighborhoodAlgorithm.h"
35 template <
class TInputImage,
class TOutputImage,
class TCountFunction>
38 m_NeighborhoodRadius.Fill(1);
39 m_CountFunction = CountFunctionType::New();
40 this->DynamicMultiThreadingOn();
45 template <
class TInputImage,
class TOutputImage,
class TCountFunction>
50 template <
class TInputImage,
class TOutputImage,
class TCountFunction>
54 Superclass::GenerateInputRequestedRegion();
57 InputImagePointerType inputPtr =
const_cast<TInputImage*
>(this->GetInput());
58 OutputImagePointerType outputPtr = this->GetOutput();
60 if (!inputPtr || !outputPtr)
66 InputImageRegionType inputRequestedRegion = inputPtr->GetRequestedRegion();
69 inputRequestedRegion.PadByRadius(m_NeighborhoodRadius);
72 if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
74 inputPtr->SetRequestedRegion(inputRequestedRegion);
83 inputPtr->SetRequestedRegion(inputRequestedRegion);
86 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
87 std::ostringstream msg;
88 msg << this->GetNameOfClass() <<
"::GenerateInputRequestedRegion()";
89 e.SetLocation(msg.str());
90 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region.");
91 e.SetDataObject(inputPtr);
96 template <
class TInputImage,
class TOutputImage,
class TCountFunction>
99 Superclass::BeforeThreadedGenerateData();
101 m_CountFunction->SetInputImage(this->GetInput());
102 m_CountFunction->SetNeighborhoodRadius(m_NeighborhoodRadius);
106 template <
class TInputImage,
class TOutputImage,
class TCountFunction>
109 InputImagePointerType inputPtr =
const_cast<InputImageType*
>(this->GetInput());
110 OutputImagePointerType outputPtr = this->GetOutput();
113 itk::ZeroFluxNeumannBoundaryCondition<TInputImage> nbc;
115 r[0] = m_NeighborhoodRadius[0];
116 r[1] = m_NeighborhoodRadius[1];
118 NeighborhoodIteratorType it;
119 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage>::FaceListType faceList;
120 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage> bC;
121 faceList = bC(inputPtr, outputRegionForThread, r);
122 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage>::FaceListType::iterator fit;
124 itk::ImageRegionIterator<OutputImageType> itOut(outputPtr, outputRegionForThread);
126 typename InputImageType::IndexType index;
128 for (fit = faceList.begin(); fit != faceList.end(); ++fit)
130 it = itk::ConstNeighborhoodIterator<TInputImage>(r, inputPtr, *fit);
132 itOut = itk::ImageRegionIterator<TOutputImage>(outputPtr, *fit);
133 it.OverrideBoundaryCondition(&nbc);
136 while (!itOut.IsAtEnd())
138 index = it.GetIndex();
140 if (outputRegionForThread.IsInside(index))
142 itOut.Set(m_CountFunction->EvaluateAtIndex(index));
~BinaryImageToDensityImageFilter() override
void DynamicThreadedGenerateData(const InputImageRegionType &outputRegionForThread) override
void GenerateInputRequestedRegion() override
BinaryImageToDensityImageFilter()
void BeforeThreadedGenerateData() override
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.