Orfeo Toolbox  3.16
itkMinimumMaximumImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkMinimumMaximumImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2008-10-16 19:33:41 $
7  Version: $Revision: 1.20 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkMinimumMaximumImageFilter_txx
18 #define __itkMinimumMaximumImageFilter_txx
20 
21 #include "itkImageRegionIterator.h"
23 #include "itkNumericTraits.h"
24 #include "itkProgressReporter.h"
25 
26 #include <vector>
27 
28 namespace itk {
29 
30 template<class TInputImage>
33 {
34  this->SetNumberOfRequiredOutputs(3);
35  // first output is a copy of the image, DataObject created by
36  // superclass
37  //
38  // allocate the data objects for the remaining outputs which are
39  // just decorators around floating point types
40  for (int i=1; i < 3; ++i)
41  {
42  typename PixelObjectType::Pointer output
43  = static_cast<PixelObjectType*>(this->MakeOutput(i).GetPointer());
44  this->ProcessObject::SetNthOutput(i, output.GetPointer());
45  }
46 
47  this->GetMinimumOutput()->Set( NumericTraits<PixelType>::max() );
48  this->GetMaximumOutput()->Set( NumericTraits<PixelType>::NonpositiveMin() );
49 }
50 
51 
52 template<class TInputImage>
55 ::MakeOutput(unsigned int output)
56 {
57  switch (output)
58  {
59  case 0:
60  return static_cast<DataObject*>(TInputImage::New().GetPointer());
61  break;
62  case 1:
63  case 2:
64  return static_cast<DataObject*>(PixelObjectType::New().GetPointer());
65  break;
66  default:
67  // might as well make an image
68  return static_cast<DataObject*>(TInputImage::New().GetPointer());
69  break;
70  }
71 }
72 
73 
74 template<class TInputImage>
78 {
79  return static_cast<PixelObjectType*>(this->ProcessObject::GetOutput(1));
80 }
81 
82 template<class TInputImage>
86 {
87  return static_cast<const PixelObjectType*>(this->ProcessObject::GetOutput(1));
88 }
89 
90 
91 template<class TInputImage>
95 {
96  return static_cast<PixelObjectType*>(this->ProcessObject::GetOutput(2));
97 }
98 
99 template<class TInputImage>
103 {
104  return static_cast<const PixelObjectType*>(this->ProcessObject::GetOutput(2));
105 }
106 
107 template<class TInputImage>
108 void
111 {
112  Superclass::GenerateInputRequestedRegion();
113  if ( this->GetInput() )
114  {
115  InputImagePointer image =
116  const_cast< typename Superclass::InputImageType * >( this->GetInput() );
117  image->SetRequestedRegionToLargestPossibleRegion();
118  }
119 }
120 
121 template<class TInputImage>
122 void
125 {
126  Superclass::EnlargeOutputRequestedRegion(data);
128 }
129 
130 
131 template<class TInputImage>
132 void
135 {
136  // Pass the input through as the output
137  InputImagePointer image =
138  const_cast< TInputImage * >( this->GetInput() );
139  this->GraftOutput( image );
140 
141  // Nothing that needs to be allocated for the remaining outputs
142 }
143 
144 template<class TInputImage>
145 void
148 {
149  int numberOfThreads = this->GetNumberOfThreads();
150 
151  // Create the thread temporaries
152  m_ThreadMin = std::vector<PixelType>(numberOfThreads,
153  NumericTraits<PixelType>::max());
154  m_ThreadMax = std::vector<PixelType>(numberOfThreads,
155  NumericTraits<PixelType>::NonpositiveMin());
156 }
157 
158 template<class TInputImage>
159 void
162 {
163  int i;
164  int numberOfThreads = this->GetNumberOfThreads();
165 
166  PixelType minimum, maximum;
167 
168  // Find the min/max over all threads
169  minimum = NumericTraits<PixelType>::max();
170  maximum = NumericTraits<PixelType>::NonpositiveMin();
171  for( i = 0; i < numberOfThreads; i++)
172  {
173  if (m_ThreadMin[i] < minimum)
174  {
175  minimum = m_ThreadMin[i];
176  }
177  if (m_ThreadMax[i] > maximum)
178  {
179  maximum = m_ThreadMax[i];
180  }
181  }
182 
183  // Set the outputs
184  this->GetMinimumOutput()->Set( minimum );
185  this->GetMaximumOutput()->Set( maximum );
186 }
187 
188 template<class TInputImage>
189 void
191 ::ThreadedGenerateData(const RegionType& outputRegionForThread,
192  int threadId)
193 {
194  PixelType value;
195  ImageRegionConstIterator<TInputImage> it (this->GetInput(), outputRegionForThread);
196 
197  // support progress methods/callbacks
198  ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
199 
200  // do the work
201  while (!it.IsAtEnd())
202  {
203  value = static_cast<PixelType>(it.Get());
204  if (value < m_ThreadMin[threadId])
205  {
206  m_ThreadMin[threadId] = value;
207  }
208  if (value > m_ThreadMax[threadId])
209  {
210  m_ThreadMax[threadId] = value;
211  }
212  ++it;
213  progress.CompletedPixel();
214  }
215 }
216 
217 template <class TImage>
218 void
220 ::PrintSelf(std::ostream& os, Indent indent) const
221 {
222  Superclass::PrintSelf(os,indent);
223 
224  os << indent << "Minimum: "
225  << static_cast<typename NumericTraits<PixelType>::PrintType>(this->GetMinimum())
226  << std::endl;
227  os << indent << "Maximum: "
228  << static_cast<typename NumericTraits<PixelType>::PrintType>(this->GetMaximum())
229  << std::endl;
230 }
231 
232 
233 }// end namespace itk
234 #endif

Generated at Sat Feb 2 2013 23:52:51 for Orfeo Toolbox with doxygen 1.8.1.1