22 #ifndef otbClampImageFilter_hxx
23 #define otbClampImageFilter_hxx
26 #include "itkImageScanlineIterator.h"
27 #include "itkImageScanlineConstIterator.h"
28 #include "itkImageRegionIterator.h"
29 #include "itkNumericTraits.h"
30 #include "itkObjectFactory.h"
31 #include "itkProgressReporter.h"
40 template <
class TInputImage,
class TOutputImage>
47 template <
class TInputImage,
class TOutputImage>
50 assert( lowerVal <= upperVal );
51 if ((m_Lower != lowerVal) || (m_Upper != upperVal))
55 this->GetFunctor().SetThresholds(m_Lower, m_Upper);
63 template <
class TInputImage,
class TOutputImage>
66 Superclass::PrintSelf(os, indent);
68 os << indent <<
"Lower: " <<
static_cast<typename itk::NumericTraits<OutputImagePixelType>::PrintType
>(m_Lower) << std::endl;
69 os << indent <<
"Upper: " <<
static_cast<typename itk::NumericTraits<OutputImagePixelType>::PrintType
>(m_Upper) << std::endl;
75 template <
class TInputImage,
class TOutputImage>
78 if (m_Upper != thresh || m_Lower > std::numeric_limits<OutputPixelValueType>::lowest())
80 m_Lower = std::numeric_limits<OutputPixelValueType>::lowest();
82 this->GetFunctor().SetThresholds(m_Lower, m_Upper);
91 template <
class TInputImage,
class TOutputImage>
94 if (m_Lower != thresh || m_Upper < std::numeric_limits<OutputPixelValueType>::max())
96 m_Upper = std::numeric_limits<OutputPixelValueType>::max();
98 this->GetFunctor().SetThresholds(m_Lower, m_Upper);
108 template <
class TInputImage,
class TOutputImage>
113 itkExceptionMacro(<<
"Lower threshold cannot be greater than upper threshold.");
118 if (m_Lower != lower || m_Upper != upper)
122 this->GetFunctor().SetThresholds(m_Lower, m_Upper);
127 template <
class TInputImage,
class TOutputImage>
132 const auto& regionSize = outputRegionForThread.GetSize();
134 if (regionSize[0] == 0)
138 const auto numberOfLinesToProcess = outputRegionForThread.GetNumberOfPixels() / regionSize[0];
139 itk::ProgressReporter p(
this, threadId, numberOfLinesToProcess);
142 itk::ImageScanlineConstIterator<InputImageType> inIt(this->GetInput(), outputRegionForThread);
143 itk::ImageScanlineIterator<OutputImageType> outIt(this->GetOutput(), outputRegionForThread);
146 typename OutputImageType::PixelType outputValueHolder;
149 itk::NumericTraits<typename OutputImageType::PixelType>::SetLength(outputValueHolder, this->GetOutput()->GetNumberOfComponentsPerPixel());
151 while (!outIt.IsAtEnd())
154 for (; !outIt.IsAtEndOfLine(); ++outIt, ++inIt)
158 m_Functor(outputValueHolder, inIt.Get());
159 outIt.Set(outputValueHolder);