Orfeo Toolbox  3.16
itkTwoOutputExampleImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkTwoOutputExampleImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2008-10-18 16:11:15 $
7  Version: $Revision: 1.11 $
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 __itkTwoOutputExampleImageFilter_txx
18 #define __itkTwoOutputExampleImageFilter_txx
19 
21 #include "itkImageRegionIterator.h"
23 #include "itkNumericTraits.h"
24 #include "itkObjectFactory.h"
25 #include "itkProgressReporter.h"
26 
27 namespace itk
28 {
29 
33 template <class TImage>
36 {
37  m_OutsideValue = NumericTraits<PixelType>::Zero;
38  m_Lower = NumericTraits<PixelType>::NonpositiveMin();
39  m_Upper = NumericTraits<PixelType>::max();
40 
41  typename TImage::Pointer output = TImage::New();
43  this->ProcessObject::SetNthOutput(1, output.GetPointer());
44 }
45 
46 
50 template <class TImage>
51 void
53 ::PrintSelf(std::ostream& os, Indent indent) const
54 {
55  Superclass::PrintSelf(os,indent);
56 
57  os << indent << "OutsideValue: "
58  << static_cast<typename NumericTraits<PixelType>::PrintType>(m_OutsideValue)
59  << std::endl;
60  os << indent << "Lower: "
61  << static_cast<typename NumericTraits<PixelType>::PrintType>(m_Lower)
62  << std::endl;
63  os << indent << "Upper: "
64  << static_cast<typename NumericTraits<PixelType>::PrintType>(m_Upper)
65  << std::endl;
66 }
67 
71 template <class TImage>
72 void
75 {
76  if (m_Upper != thresh
77  || m_Lower > NumericTraits<PixelType>::NonpositiveMin())
78  {
79  m_Lower = NumericTraits<PixelType>::NonpositiveMin();
80  m_Upper = thresh;
81  this->Modified();
82  }
83 }
84 
88 template <class TImage>
89 void
92 {
93  if (m_Lower != thresh || m_Upper < NumericTraits<PixelType>::max())
94  {
95  m_Lower = thresh;
96  m_Upper = NumericTraits<PixelType>::max();
97  this->Modified();
98  }
99 }
100 
101 
105 template <class TImage>
106 void
109 {
110  if (lower > upper)
111  {
112  itkExceptionMacro(<<"Lower threshold cannot be greater than upper threshold.");
113  return;
114  }
115 
116  if (m_Lower != lower || m_Upper != upper)
117  {
118  m_Lower = lower;
119  m_Upper = upper;
120  this->Modified();
121  }
122 }
123 
124 
128 template <class TImage>
129 void
131 ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
132  int threadId)
133 {
134  itkDebugMacro(<<"Actually executing");
135 
136  // Get the input and output pointers
137  InputImageConstPointer inputPtr = this->GetInput();
138  OutputImagePointer outputPtr = this->GetOutput(0);
139  OutputImagePointer outputInversePtr = this->GetOutput(1);
140 
141  // Define/declare an iterator that will walk the output region for this
142  // thread.
143  typedef ImageRegionConstIterator<TImage> InputIterator;
144  typedef ImageRegionIterator<TImage> OutputIterator;
145 
146  InputIterator inIt(inputPtr, outputRegionForThread);
147  OutputIterator outIt(outputPtr, outputRegionForThread);
148  OutputIterator outInverseIt(outputInversePtr, outputRegionForThread);
149 
150  // support progress methods/callbacks
151  ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
152 
153  // walk the regions, threshold each pixel
154  while( !outIt.IsAtEnd() )
155  {
156  const PixelType value = inIt.Get();
157  if (m_Lower <= value && value <= m_Upper)
158  {
159  // pixel passes to output unchanged and is replaced by m_OutsideValue in
160  // the inverse output image
161  outIt.Set( inIt.Get() );
162  outInverseIt.Set( m_OutsideValue );
163  }
164  else
165  {
166  outIt.Set( m_OutsideValue );
167  outInverseIt.Set( inIt.Get() );
168  }
169  ++inIt;
170  ++outIt;
171  ++outInverseIt;
172  progress.CompletedPixel();
173  }
174 
175 }
176 
177 } // end namespace itk
178 
179 #endif

Generated at Sun Feb 3 2013 00:10:38 for Orfeo Toolbox with doxygen 1.8.1.1