Orfeo Toolbox  4.0
otbStreamingMinMaxVectorImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 Some parts of this code are derived from ITK. See ITKCopyright.txt
13 for details.
14 
15 
16  This software is distributed WITHOUT ANY WARRANTY; without even
17  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18  PURPOSE. See the above copyright notices for more information.
19 
20 =========================================================================*/
21 #ifndef __otbStreamingMinMaxVectorImageFilter_txx
22 #define __otbStreamingMinMaxVectorImageFilter_txx
24 
25 #include "itkImageRegionIterator.h"
27 #include "itkNumericTraits.h"
28 #include "itkProgressReporter.h"
29 #include "otbMacro.h"
30 
31 namespace otb
32 {
33 
34 template<class TInputImage>
37  : m_NoDataFlag(false),
38  m_NoDataValue(itk::NumericTraits<InternalPixelType>::Zero)
39 {
40  // first output is a copy of the image, DataObject created by
41  // superclass
42  //
43  // allocate the data objects for the outputs which are
44  // just decorators around pixel types
45 
46  for (int i = 1; i < 3; ++i)
47  {
48  typename PixelObjectType::Pointer output = static_cast<PixelObjectType*>(this->MakeOutput(i).GetPointer());
50  }
51 }
52 
53 template<class TInputImage>
56 ::MakeOutput(unsigned int output)
57 {
59  switch (output)
60  {
61  case 0:
62  ret = static_cast<itk::DataObject*>(TInputImage::New().GetPointer());
63  break;
64  case 1:
65  case 2:
66  ret = static_cast<itk::DataObject*>(PixelObjectType::New().GetPointer());
67  break;
68  }
69  return ret;
70 }
71 
72 template<class TInputImage>
76 {
77  return static_cast<PixelObjectType*>(this->itk::ProcessObject::GetOutput(1));
78 }
79 
80 template<class TInputImage>
84 {
85  return static_cast<const PixelObjectType*>(this->itk::ProcessObject::GetOutput(1));
86 }
87 
88 template<class TInputImage>
92 {
93  return static_cast<PixelObjectType*>(this->itk::ProcessObject::GetOutput(2));
94 }
95 
96 template<class TInputImage>
100 {
101  return static_cast<const PixelObjectType*>(this->itk::ProcessObject::GetOutput(2));
102 }
103 
104 template<class TInputImage>
105 void
108 {
109  Superclass::GenerateOutputInformation();
110  if (this->GetInput())
111  {
112  this->GetOutput()->CopyInformation(this->GetInput());
113  this->GetOutput()->SetLargestPossibleRegion(this->GetInput()->GetLargestPossibleRegion());
114 
115  if (this->GetOutput()->GetRequestedRegion().GetNumberOfPixels() == 0)
116  {
117  this->GetOutput()->SetRequestedRegion(this->GetOutput()->GetLargestPossibleRegion());
118  }
119  }
120 }
121 
122 template<class TInputImage>
123 void
126 {
127  // This is commented to prevent the streaming of the whole image for the first stream strip
128  // It shall not cause any problem because the output image of this filter is not intended to be used.
129  //InputImagePointer image = const_cast< TInputImage * >( this->GetInput() );
130  //this->GraftOutput( image );
131  // Nothing that needs to be allocated for the remaining outputs
132 }
133 
134 template<class TInputImage>
135 void
138 {
139  TInputImage * inputPtr = const_cast<TInputImage *>(this->GetInput());
140  inputPtr->UpdateOutputInformation();
141 
142  unsigned int numberOfThreads = this->GetNumberOfThreads();
143  unsigned int numberOfComponent = inputPtr->GetNumberOfComponentsPerPixel();
144 
145  // Variable Initialization
146  PixelType tempPixel;
147  tempPixel.SetSize(numberOfComponent);
149  this->GetMaximumOutput()->Set(tempPixel);
150 
152  this->GetMinimumOutput()->Set(tempPixel);
153 
154  PixelType tempTemporiesPixel;
155  tempTemporiesPixel.SetSize(numberOfComponent);
156  tempTemporiesPixel.Fill(itk::NumericTraits<InternalPixelType>::max());
157  m_ThreadMin = ArrayPixelType(numberOfThreads, tempTemporiesPixel);
158 
160  m_ThreadMax = ArrayPixelType(numberOfThreads, tempTemporiesPixel);
161 
162 }
163 
164 template<class TInputImage>
165 void
168 {
169  int i;
170 
171  int numberOfThreads = this->GetNumberOfThreads();
172  unsigned int numberOfComponent = this->GetInput()->GetNumberOfComponentsPerPixel();
173 
174  PixelType minimumVector;
175  minimumVector.SetSize(numberOfComponent);
176  minimumVector.Fill(itk::NumericTraits<InternalPixelType>::max());
177 
178  PixelType maximumVector;
179  maximumVector.SetSize(numberOfComponent);
181 
182  // Find the min/max over all threads and accumulate count, sum and
183  // sum of squares
184  for (i = 0; i < numberOfThreads; ++i)
185  {
186  for (unsigned int j = 0; j < numberOfComponent; ++j)
187  {
188  if (m_ThreadMin[i][j] < minimumVector[j])
189  {
190  minimumVector[j] = m_ThreadMin[i][j];
191  }
192  if (m_ThreadMax[i][j] > maximumVector[j])
193  {
194  maximumVector[j] = m_ThreadMax[i][j];
195  }
196  }
197  } // end for( i = 0; i < numberOfThreads; ++i)
198 
199  // Set the outputs
200  this->GetMinimumOutput()->Set(minimumVector);
201  this->GetMaximumOutput()->Set(maximumVector);
202 }
203 
204 template<class TInputImage>
205 void
207 ::ThreadedGenerateData(const RegionType& outputRegionForThread, itk::ThreadIdType threadId)
208 {
212  InputImagePointer inputPtr = const_cast<TInputImage *>(this->GetInput());
213  // support progress methods/callbacks
214  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
215 
216  itk::ImageRegionConstIteratorWithIndex<TInputImage> it(inputPtr, outputRegionForThread);
217  it.GoToBegin();
218 
219  // do the work
220  while (!it.IsAtEnd())
221  {
222  //IndexType index = it.GetIndex();
223  PixelType vectorValue = it.Get();
224  for (unsigned int j = 0; j < vectorValue.GetSize(); ++j)
225  {
226  InternalPixelType value = vectorValue[j];
227 
228  if( (!m_NoDataFlag) || value!=m_NoDataValue )
229  {
230  if (value < m_ThreadMin[threadId][j])
231  {
232  m_ThreadMin[threadId][j] = value;
233  }
234  if (value > m_ThreadMax[threadId][j])
235  {
236  m_ThreadMax[threadId][j] = value;
237  }
238  }
239  }
240  ++it;
241  progress.CompletedPixel();
242  }
243 }
244 
245 template <class TImage>
246 void
248 ::PrintSelf(std::ostream& os, itk::Indent indent) const
249 {
250  Superclass::PrintSelf(os, indent);
251 
252  os << indent << "Minimum: " << this->GetMinimumOutput()->Get() << std::endl;
253  os << indent << "Maximum: " << this->GetMaximumOutput()->Get() << std::endl;
254 }
255 
256 } // end namespace otb
257 #endif

Generated at Sat Mar 8 2014 16:20:16 for Orfeo Toolbox with doxygen 1.8.3.1