00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkBinaryThresholdImageFilter_h
00018 #define __itkBinaryThresholdImageFilter_h
00019
00020 #include "itkUnaryFunctorImageFilter.h"
00021 #include "itkConceptChecking.h"
00022 #include "itkSimpleDataObjectDecorator.h"
00023
00024 namespace itk
00025 {
00026
00052 namespace Functor {
00053
00054 template< class TInput, class TOutput>
00055 class BinaryThreshold
00056 {
00057 public:
00058 BinaryThreshold()
00059 {
00060 m_LowerThreshold = NumericTraits<TInput>::NonpositiveMin();
00061 m_UpperThreshold = NumericTraits<TInput>::max();
00062 m_OutsideValue = NumericTraits<TOutput>::Zero;
00063 m_InsideValue = NumericTraits<TOutput>::max();
00064 };
00065 ~BinaryThreshold() {};
00066
00067 void SetLowerThreshold( const TInput & thresh )
00068 { m_LowerThreshold = thresh; }
00069 void SetUpperThreshold( const TInput & thresh )
00070 { m_UpperThreshold = thresh; }
00071 void SetInsideValue( const TOutput & value )
00072 { m_InsideValue = value; }
00073 void SetOutsideValue( const TOutput & value )
00074 { m_OutsideValue = value; }
00075
00076 bool operator!=( const BinaryThreshold & other ) const
00077 {
00078 if( m_LowerThreshold != other.m_LowerThreshold ||
00079 m_UpperThreshold != other.m_UpperThreshold ||
00080 m_InsideValue != other.m_InsideValue ||
00081 m_OutsideValue != other.m_OutsideValue )
00082 {
00083 return true;
00084 }
00085 return false;
00086 }
00087 bool operator==( const BinaryThreshold & other ) const
00088 {
00089 return !(*this != other);
00090 }
00091
00092 inline TOutput operator()( const TInput & A )
00093 {
00094 if ( m_LowerThreshold <= A && A <= m_UpperThreshold )
00095 {
00096 return m_InsideValue;
00097 }
00098 return m_OutsideValue;
00099 }
00100
00101 private:
00102 TInput m_LowerThreshold;
00103 TInput m_UpperThreshold;
00104 TOutput m_InsideValue;
00105 TOutput m_OutsideValue;
00106
00107 };
00108 }
00109
00110 template <class TInputImage, class TOutputImage>
00111 class ITK_EXPORT BinaryThresholdImageFilter :
00112 public
00113 UnaryFunctorImageFilter<TInputImage,TOutputImage,
00114 Functor::BinaryThreshold<
00115 typename TInputImage::PixelType,
00116 typename TOutputImage::PixelType> >
00117 {
00118 public:
00120 typedef BinaryThresholdImageFilter Self;
00121 typedef UnaryFunctorImageFilter<TInputImage,TOutputImage,
00122 Functor::BinaryThreshold<
00123 typename TInputImage::PixelType,
00124 typename TOutputImage::PixelType>
00125 > Superclass;
00126 typedef SmartPointer<Self> Pointer;
00127 typedef SmartPointer<const Self> ConstPointer;
00128
00130 itkNewMacro(Self);
00131
00133 itkTypeMacro(BinaryThresholdImageFilter, UnaryFunctorImageFilter);
00134
00136 typedef typename TInputImage::PixelType InputPixelType;
00137 typedef typename TOutputImage::PixelType OutputPixelType;
00138
00140 typedef SimpleDataObjectDecorator<InputPixelType> InputPixelObjectType;
00141
00144 itkSetMacro(OutsideValue,OutputPixelType);
00145
00147 itkGetConstReferenceMacro(OutsideValue,OutputPixelType);
00148
00151 itkSetMacro(InsideValue,OutputPixelType);
00152
00154 itkGetConstReferenceMacro(InsideValue,OutputPixelType);
00155
00160 virtual void SetUpperThreshold(const InputPixelType threshold);
00161 virtual void SetUpperThresholdInput( const InputPixelObjectType *);
00162 virtual void SetLowerThreshold(const InputPixelType threshold);
00163 virtual void SetLowerThresholdInput( const InputPixelObjectType *);
00165
00167 virtual InputPixelType GetUpperThreshold() const;
00168 virtual InputPixelObjectType *GetUpperThresholdInput();
00169 virtual const InputPixelObjectType *GetUpperThresholdInput() const;
00170 virtual InputPixelType GetLowerThreshold() const;
00171 virtual InputPixelObjectType *GetLowerThresholdInput();
00172 virtual const InputPixelObjectType *GetLowerThresholdInput() const;
00174
00175 #ifdef ITK_USE_CONCEPT_CHECKING
00176
00177 itkConceptMacro(OutputEqualityComparableCheck,
00178 (Concept::EqualityComparable<OutputPixelType>));
00179 itkConceptMacro(InputPixelTypeComparable,
00180 (Concept::Comparable<InputPixelType>));
00181 itkConceptMacro(InputOStreamWritableCheck,
00182 (Concept::OStreamWritable<InputPixelType>));
00183 itkConceptMacro(OutputOStreamWritableCheck,
00184 (Concept::OStreamWritable<OutputPixelType>));
00185
00187 #endif
00188
00189 protected:
00190 BinaryThresholdImageFilter();
00191 virtual ~BinaryThresholdImageFilter() {}
00192 void PrintSelf(std::ostream& os, Indent indent) const;
00193
00196 virtual void BeforeThreadedGenerateData();
00197
00198 private:
00199 BinaryThresholdImageFilter(const Self&);
00200 void operator=(const Self&);
00201
00202 OutputPixelType m_InsideValue;
00203 OutputPixelType m_OutsideValue;
00204
00205 };
00206
00207 }
00208
00209 #ifndef ITK_MANUAL_INSTANTIATION
00210 #include "itkBinaryThresholdImageFilter.txx"
00211 #endif
00212
00213 #endif
00214