22 #ifndef otbStreamingMinMaxVectorImageFilter_hxx
23 #define otbStreamingMinMaxVectorImageFilter_hxx
26 #include "itkImageRegionIterator.h"
27 #include "itkImageRegionConstIteratorWithIndex.h"
28 #include "itkNumericTraits.h"
29 #include "itkProgressReporter.h"
35 template <
class TInputImage>
45 for (
int i = 1; i < 3; ++i)
48 this->itk::ProcessObject::SetNthOutput(i, output.GetPointer());
52 template <
class TInputImage>
55 itk::DataObject::Pointer ret;
59 ret =
static_cast<itk::DataObject*
>(TInputImage::New().GetPointer());
63 ret =
static_cast<itk::DataObject*
>(PixelObjectType::New().GetPointer());
69 template <
class TInputImage>
72 return static_cast<PixelObjectType*
>(this->itk::ProcessObject::GetOutput(1));
75 template <
class TInputImage>
78 return static_cast<const PixelObjectType*
>(this->itk::ProcessObject::GetOutput(1));
81 template <
class TInputImage>
84 return static_cast<PixelObjectType*
>(this->itk::ProcessObject::GetOutput(2));
87 template <
class TInputImage>
90 return static_cast<const PixelObjectType*
>(this->itk::ProcessObject::GetOutput(2));
93 template <
class TInputImage>
96 Superclass::GenerateOutputInformation();
99 this->GetOutput()->CopyInformation(this->GetInput());
100 this->GetOutput()->SetLargestPossibleRegion(this->GetInput()->GetLargestPossibleRegion());
102 if (this->GetOutput()->GetRequestedRegion().GetNumberOfPixels() == 0)
104 this->GetOutput()->SetRequestedRegion(this->GetOutput()->GetLargestPossibleRegion());
109 template <
class TInputImage>
119 template <
class TInputImage>
122 TInputImage* inputPtr =
const_cast<TInputImage*
>(this->GetInput());
123 inputPtr->UpdateOutputInformation();
125 unsigned int numberOfThreads = this->GetNumberOfThreads();
126 unsigned int numberOfComponent = inputPtr->GetNumberOfComponentsPerPixel();
130 tempPixel.SetSize(numberOfComponent);
131 tempPixel.Fill(itk::NumericTraits<InternalPixelType>::NonpositiveMin());
132 this->GetMaximumOutput()->Set(tempPixel);
134 tempPixel.Fill(itk::NumericTraits<InternalPixelType>::max());
135 this->GetMinimumOutput()->Set(tempPixel);
138 tempTemporariesPixel.SetSize(numberOfComponent);
139 tempTemporariesPixel.Fill(itk::NumericTraits<InternalPixelType>::max());
140 m_ThreadMin =
ArrayPixelType(numberOfThreads, tempTemporariesPixel);
142 tempTemporariesPixel.Fill(itk::NumericTraits<InternalPixelType>::NonpositiveMin());
143 m_ThreadMax =
ArrayPixelType(numberOfThreads, tempTemporariesPixel);
146 template <
class TInputImage>
151 int numberOfThreads = this->GetNumberOfThreads();
152 unsigned int numberOfComponent = this->GetInput()->GetNumberOfComponentsPerPixel();
155 minimumVector.SetSize(numberOfComponent);
156 minimumVector.Fill(itk::NumericTraits<InternalPixelType>::max());
159 maximumVector.SetSize(numberOfComponent);
160 maximumVector.Fill(itk::NumericTraits<InternalPixelType>::NonpositiveMin());
164 for (i = 0; i < numberOfThreads; ++i)
166 for (
unsigned int j = 0; j < numberOfComponent; ++j)
168 if (m_ThreadMin[i][j] < minimumVector[j])
170 minimumVector[j] = m_ThreadMin[i][j];
172 if (m_ThreadMax[i][j] > maximumVector[j])
174 maximumVector[j] = m_ThreadMax[i][j];
180 this->GetMinimumOutput()->Set(minimumVector);
181 this->GetMaximumOutput()->Set(maximumVector);
184 template <
class TInputImage>
192 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
195 itk::ImageRegionConstIteratorWithIndex<TInputImage> it(inputPtr, outputRegionForThread);
199 while (!it.IsAtEnd())
203 for (
unsigned int j = 0; j < vectorValue.GetSize(); ++j)
207 if ((!m_NoDataFlag) || value != m_NoDataValue)
209 if (value < m_ThreadMin[threadId][j])
211 m_ThreadMin[threadId][j] = value;
213 if (value > m_ThreadMax[threadId][j])
215 m_ThreadMax[threadId][j] = value;
220 progress.CompletedPixel();
224 template <
class TImage>
227 Superclass::PrintSelf(os, indent);
229 os << indent <<
"Minimum: " << this->GetMinimumOutput()->Get() << std::endl;
230 os << indent <<
"Maximum: " << this->GetMaximumOutput()->Get() << std::endl;