ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkBinaryThresholdImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkBinaryThresholdImageFilter_h
19 #define __itkBinaryThresholdImageFilter_h
20 
22 #include "itkConceptChecking.h"
24 
25 namespace itk
26 {
63 namespace Functor
64 {
65 template< class TInput, class TOutput >
67 {
68 public:
70  {
75  }
76 
78 
79  void SetLowerThreshold(const TInput & thresh)
80  { m_LowerThreshold = thresh; }
81  void SetUpperThreshold(const TInput & thresh)
82  { m_UpperThreshold = thresh; }
83  void SetInsideValue(const TOutput & value)
84  { m_InsideValue = value; }
85  void SetOutsideValue(const TOutput & value)
86  { m_OutsideValue = value; }
87 
88  bool operator!=(const BinaryThreshold & other) const
89  {
92  || m_InsideValue != other.m_InsideValue
93  || m_OutsideValue != other.m_OutsideValue )
94  {
95  return true;
96  }
97  return false;
98  }
99 
100  bool operator==(const BinaryThreshold & other) const
101  {
102  return !( *this != other );
103  }
104 
105  inline TOutput operator()(const TInput & A) const
106  {
107  if ( m_LowerThreshold <= A && A <= m_UpperThreshold )
108  {
109  return m_InsideValue;
110  }
111  return m_OutsideValue;
112  }
113 
114 private:
117  TOutput m_InsideValue;
118  TOutput m_OutsideValue;
119 };
120 }
121 
122 template< class TInputImage, class TOutputImage >
123 class ITK_EXPORT BinaryThresholdImageFilter:
124  public
125  UnaryFunctorImageFilter< TInputImage, TOutputImage,
126  Functor::BinaryThreshold<
127  typename TInputImage::PixelType,
128  typename TOutputImage::PixelType > >
129 {
130 public:
133  typedef UnaryFunctorImageFilter< TInputImage, TOutputImage,
135  typename TInputImage::PixelType,
136  typename TOutputImage::PixelType >
140 
142  itkNewMacro(Self);
143 
146 
148  typedef typename TInputImage::PixelType InputPixelType;
149  typedef typename TOutputImage::PixelType OutputPixelType;
150 
153 
156  itkSetMacro(OutsideValue, OutputPixelType);
157 
159  itkGetConstReferenceMacro(OutsideValue, OutputPixelType);
160 
163  itkSetMacro(InsideValue, OutputPixelType);
164 
166  itkGetConstReferenceMacro(InsideValue, OutputPixelType);
167 
172  virtual void SetUpperThreshold(const InputPixelType threshold);
173 
174  virtual void SetUpperThresholdInput(const InputPixelObjectType *);
175 
176  virtual void SetLowerThreshold(const InputPixelType threshold);
177 
178  virtual void SetLowerThresholdInput(const InputPixelObjectType *);
179 
181  virtual InputPixelType GetUpperThreshold() const;
182 
183  virtual InputPixelObjectType * GetUpperThresholdInput();
184 
185  virtual const InputPixelObjectType * GetUpperThresholdInput() const;
186 
187  virtual InputPixelType GetLowerThreshold() const;
188 
189  virtual InputPixelObjectType * GetLowerThresholdInput();
190 
191  virtual const InputPixelObjectType * GetLowerThresholdInput() const;
192 
193 #ifdef ITK_USE_CONCEPT_CHECKING
194 
195  itkConceptMacro( OutputEqualityComparableCheck,
197  itkConceptMacro( InputPixelTypeComparable,
199  itkConceptMacro( InputOStreamWritableCheck,
201  itkConceptMacro( OutputOStreamWritableCheck,
203 
205 #endif
206 
207 protected:
210  void PrintSelf(std::ostream & os, Indent indent) const;
211 
214  virtual void BeforeThreadedGenerateData();
215 
216 private:
217  BinaryThresholdImageFilter(const Self &); //purposely not implemented
218  void operator=(const Self &); //purposely not implemented
219 
222 };
223 } // end namespace itk
224 
225 #ifndef ITK_MANUAL_INSTANTIATION
226 #include "itkBinaryThresholdImageFilter.hxx"
227 #endif
228 
229 #endif
230