Orfeo Toolbox  3.16
itkBinaryThresholdImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkBinaryThresholdImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2008-10-09 15:31:36 $
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  Portions of this code are covered under the VTK copyright.
13  See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
14 
15  This software is distributed WITHOUT ANY WARRANTY; without even
16  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17  PURPOSE. See the above copyright notices for more information.
18 
19 =========================================================================*/
20 #ifndef __itkBinaryThresholdImageFilter_txx
21 #define __itkBinaryThresholdImageFilter_txx
22 
24 
25 namespace itk
26 {
27 
31 template <class TInputImage, class TOutputImage>
34 {
35  m_OutsideValue = NumericTraits<OutputPixelType>::Zero;
36  m_InsideValue = NumericTraits<OutputPixelType>::max();
37 
38  // We are going to create the object with a few default inputs to
39  // hold the threshold values.
40 
41  typename InputPixelObjectType::Pointer lower=InputPixelObjectType::New();
43  this->ProcessObject::SetNthInput( 1, lower );
44 
45  typename InputPixelObjectType::Pointer upper=InputPixelObjectType::New();
46  upper->Set( NumericTraits<InputPixelType>::max() );
47  this->ProcessObject::SetNthInput( 2, upper );
48 }
49 
50 
54 template <class TInputImage, class TOutputImage>
55 void
58 {
59  // first check to see if anything changed
60  typename InputPixelObjectType::Pointer lower=this->GetLowerThresholdInput();
61  if (lower && lower->Get() == threshold)
62  {
63  return;
64  }
65 
66  // create a data object to use as the input and to store this
67  // threshold. we always create a new data object to use as the input
68  // since we do not want to change the value in any current input
69  // (the current input could be the output of another filter or the
70  // current input could be used as an input to several filters)
71  lower = InputPixelObjectType::New();
72  this->ProcessObject::SetNthInput(1, lower);
73 
74  lower->Set(threshold);
75  this->Modified();
76 }
77 
78 template <class TInputImage, class TOutputImage>
79 void
82 {
83  if (input != this->GetLowerThresholdInput())
84  {
86  const_cast<InputPixelObjectType*>(input));
87  this->Modified();
88  }
89 }
90 
91 template <class TInputImage, class TOutputImage>
95 {
96  typename InputPixelObjectType::Pointer lower
97  = const_cast<Self*>(this)->GetLowerThresholdInput();
98 
99  return lower->Get();
100 }
101 
102 template <class TInputImage, class TOutputImage>
106 {
107  typename InputPixelObjectType::Pointer lower
108  = static_cast<InputPixelObjectType *>(this->ProcessObject::GetInput(1));
109  if (!lower)
110  {
111  // no input object available, create a new one and set it to the
112  // default threshold
113  lower = InputPixelObjectType::New();
115  this->ProcessObject::SetNthInput( 1, lower );
116  }
117 
118  return lower;
119 }
120 
121 template <class TInputImage, class TOutputImage>
122 const
126 {
127  typename InputPixelObjectType::Pointer lower
128  = const_cast<InputPixelObjectType*>( static_cast<const InputPixelObjectType *>(this->ProcessObject::GetInput(1)) );
129 
130  if (!lower)
131  {
132  // no input object available, create a new one and set it to the
133  // default threshold
134  lower = InputPixelObjectType::New();
136  const_cast<Self*>(this)->ProcessObject::SetNthInput( 1, lower );
137  }
138 
139  return lower;
140 }
141 
142 
146 template <class TInputImage, class TOutputImage>
147 void
150 {
151  // first check to see if anything changed
152  typename InputPixelObjectType::Pointer upper=this->GetUpperThresholdInput();
153  if (upper && upper->Get() == threshold)
154  {
155  return;
156  }
157 
158  // create a data object to use as the input and to store this
159  // threshold. we always create a new data object to use as the input
160  // since we do not want to change the value in any current input
161  // (the current input could be the output of another filter or the
162  // current input could be used as an input to several filters)
163  upper = InputPixelObjectType::New();
164  this->ProcessObject::SetNthInput(2, upper);
165 
166  upper->Set(threshold);
167  this->Modified();
168 }
169 
170 template <class TInputImage, class TOutputImage>
171 void
174 {
175  if (input != this->GetUpperThresholdInput())
176  {
178  const_cast<InputPixelObjectType*>(input));
179  this->Modified();
180  }
181 }
182 
183 template <class TInputImage, class TOutputImage>
187 {
188  typename InputPixelObjectType::Pointer upper
189  = const_cast<Self*>(this)->GetUpperThresholdInput();
190 
191  return upper->Get();
192 }
193 
194 template <class TInputImage, class TOutputImage>
198 {
199  typename InputPixelObjectType::Pointer upper
200  = static_cast<InputPixelObjectType *>(this->ProcessObject::GetInput(2));
201  if (!upper)
202  {
203  // no input object available, create a new one and set it to the
204  // default threshold
205  upper = InputPixelObjectType::New();
206  upper->Set( NumericTraits<InputPixelType>::max() );
207  this->ProcessObject::SetNthInput( 2, upper );
208  }
209 
210  return upper;
211 }
212 
213 template <class TInputImage, class TOutputImage>
214 const
218 {
219  typename InputPixelObjectType::Pointer upper
220  = const_cast<InputPixelObjectType*>( static_cast<const InputPixelObjectType *>(this->ProcessObject::GetInput(2)) );
221 
222  if (!upper)
223  {
224  // no input object available, create a new one and set it to the
225  // default threshold
226  upper = InputPixelObjectType::New();
227  upper->Set( NumericTraits<InputPixelType>::max() );
228  const_cast<Self*>(this)->ProcessObject::SetNthInput( 2, upper );
229  }
230 
231  return upper;
232 }
233 
237 template <class TInputImage, class TOutputImage>
238 void
240 ::PrintSelf(std::ostream& os, Indent indent) const
241 {
242  Superclass::PrintSelf(os,indent);
243 
244  os << indent << "OutsideValue: "
245  << static_cast<typename NumericTraits<OutputPixelType>::PrintType>(m_OutsideValue) << std::endl;
246  os << indent << "InsideValue: "
247  << static_cast<typename NumericTraits<OutputPixelType>::PrintType>(m_InsideValue) << std::endl;
248  os << indent << "LowerThreshold: "
249  << static_cast<typename NumericTraits<InputPixelType>::PrintType>(this->GetLowerThreshold()) << std::endl;
250  os << indent << "UpperThreshold: "
251  << static_cast<typename NumericTraits<InputPixelType>::PrintType>(this->GetUpperThreshold()) << std::endl;
252 }
253 
257 template <class TInputImage, class TOutputImage>
258 void
261 {
262  // set up the functor values
263  typename InputPixelObjectType::Pointer lowerThreshold=this->GetLowerThresholdInput();
264  typename InputPixelObjectType::Pointer upperThreshold=this->GetUpperThresholdInput();
265 
266  if (lowerThreshold->Get() > upperThreshold->Get())
267  {
268  itkExceptionMacro(<<"Lower threshold cannot be greater than upper threshold.");
269  }
270 
271  // Setup up the functor
272  this->GetFunctor().SetLowerThreshold( lowerThreshold->Get() );
273  this->GetFunctor().SetUpperThreshold( upperThreshold->Get() );
274 
275  this->GetFunctor().SetInsideValue( m_InsideValue );
276  this->GetFunctor().SetOutsideValue( m_OutsideValue );
277 
278 }
279 
280 
281 } // end namespace itk
282 
283 #endif

Generated at Sat May 18 2013 23:30:34 for Orfeo Toolbox with doxygen 1.8.3.1