Orfeo Toolbox  3.16
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 {
38  // first output is a copy of the image, DataObject created by
39  // superclass
40  //
41  // allocate the data objects for the outputs which are
42  // just decorators around pixel types
43 
44  for (int i = 1; i < 3; ++i)
45  {
46  typename PixelObjectType::Pointer output = static_cast<PixelObjectType*>(this->MakeOutput(i).GetPointer());
48  }
49 }
50 
51 template<class TInputImage>
54 ::MakeOutput(unsigned int output)
55 {
57  switch (output)
58  {
59  case 0:
60  ret = static_cast<itk::DataObject*>(TInputImage::New().GetPointer());
61  break;
62  case 1:
63  case 2:
64  ret = static_cast<itk::DataObject*>(PixelObjectType::New().GetPointer());
65  break;
66  }
67  return ret;
68 }
69 
70 template<class TInputImage>
74 {
75  return static_cast<PixelObjectType*>(this->itk::ProcessObject::GetOutput(1));
76 }
77 
78 template<class TInputImage>
82 {
83  return static_cast<const PixelObjectType*>(this->itk::ProcessObject::GetOutput(1));
84 }
85 
86 template<class TInputImage>
90 {
91  return static_cast<PixelObjectType*>(this->itk::ProcessObject::GetOutput(2));
92 }
93 
94 template<class TInputImage>
98 {
99  return static_cast<const PixelObjectType*>(this->itk::ProcessObject::GetOutput(2));
100 }
101 
102 template<class TInputImage>
103 void
106 {
107  Superclass::GenerateOutputInformation();
108  if (this->GetInput())
109  {
110  this->GetOutput()->CopyInformation(this->GetInput());
111  this->GetOutput()->SetLargestPossibleRegion(this->GetInput()->GetLargestPossibleRegion());
112 
113  if (this->GetOutput()->GetRequestedRegion().GetNumberOfPixels() == 0)
114  {
115  this->GetOutput()->SetRequestedRegion(this->GetOutput()->GetLargestPossibleRegion());
116  }
117  }
118 }
119 
120 template<class TInputImage>
121 void
124 {
125  // This is commented to prevent the streaming of the whole image for the first stream strip
126  // It shall not cause any problem because the output image of this filter is not intended to be used.
127  //InputImagePointer image = const_cast< TInputImage * >( this->GetInput() );
128  //this->GraftOutput( image );
129  // Nothing that needs to be allocated for the remaining outputs
130 }
131 
132 template<class TInputImage>
133 void
136 {
137  TInputImage * inputPtr = const_cast<TInputImage *>(this->GetInput());
138  inputPtr->UpdateOutputInformation();
139 
140  unsigned int numberOfThreads = this->GetNumberOfThreads();
141  unsigned int numberOfComponent = inputPtr->GetNumberOfComponentsPerPixel();
142 
143  // Variable Initialization
144  PixelType tempPixel;
145  tempPixel.SetSize(numberOfComponent);
146  tempPixel.Fill(itk::NumericTraits<InternalPixelType>::NonpositiveMin());
147  this->GetMaximumOutput()->Set(tempPixel);
148 
149  tempPixel.Fill(itk::NumericTraits<InternalPixelType>::max());
150  this->GetMinimumOutput()->Set(tempPixel);
151 
152  PixelType tempTemporiesPixel;
153  tempTemporiesPixel.SetSize(numberOfComponent);
154  tempTemporiesPixel.Fill(itk::NumericTraits<InternalPixelType>::max());
155  m_ThreadMin = ArrayPixelType(numberOfThreads, tempTemporiesPixel);
156 
157  tempTemporiesPixel.Fill(itk::NumericTraits<InternalPixelType>::NonpositiveMin());
158  m_ThreadMax = ArrayPixelType(numberOfThreads, tempTemporiesPixel);
159 
160 }
161 
162 template<class TInputImage>
163 void
166 {
167  int i;
168 
169  int numberOfThreads = this->GetNumberOfThreads();
170  unsigned int numberOfComponent = this->GetInput()->GetNumberOfComponentsPerPixel();
171 
172  PixelType minimumVector;
173  minimumVector.SetSize(numberOfComponent);
174  minimumVector.Fill(itk::NumericTraits<InternalPixelType>::max());
175 
176  PixelType maximumVector;
177  maximumVector.SetSize(numberOfComponent);
178  maximumVector.Fill(itk::NumericTraits<InternalPixelType>::NonpositiveMin());
179 
180  // Find the min/max over all threads and accumulate count, sum and
181  // sum of squares
182  for (i = 0; i < numberOfThreads; ++i)
183  {
184  for (unsigned int j = 0; j < numberOfComponent; ++j)
185  {
186  if (m_ThreadMin[i][j] < minimumVector[j])
187  {
188  minimumVector[j] = m_ThreadMin[i][j];
189  }
190  if (m_ThreadMax[i][j] > maximumVector[j])
191  {
192  maximumVector[j] = m_ThreadMax[i][j];
193  }
194  }
195  } // end for( i = 0; i < numberOfThreads; ++i)
196 
197  // Set the outputs
198  this->GetMinimumOutput()->Set(minimumVector);
199  this->GetMaximumOutput()->Set(maximumVector);
200 }
201 
202 template<class TInputImage>
203 void
205 ::ThreadedGenerateData(const RegionType& outputRegionForThread, int threadId)
206 {
210  InputImagePointer inputPtr = const_cast<TInputImage *>(this->GetInput());
211  // support progress methods/callbacks
212  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
213 
214  MatrixType pixelVector, pixelTransposeVector, pixelSumVector, tempMatrix;
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  if (value < m_ThreadMin[threadId][j])
228  {
229  m_ThreadMin[threadId][j] = value;
230  }
231  if (value > m_ThreadMax[threadId][j])
232  {
233  m_ThreadMax[threadId][j] = value;
234  }
235  }
236  ++it;
237  progress.CompletedPixel();
238  }
239 }
240 
241 template <class TImage>
242 void
244 ::PrintSelf(std::ostream& os, itk::Indent indent) const
245 {
246  Superclass::PrintSelf(os, indent);
247 
248  os << indent << "Minimum: " << this->GetMinimumOutput()->Get() << std::endl;
249  os << indent << "Maximum: " << this->GetMaximumOutput()->Get() << std::endl;
250 }
251 
252 } // end namespace otb
253 #endif

Generated at Sun Feb 3 2013 00:49:26 for Orfeo Toolbox with doxygen 1.8.1.1