ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkBinaryThresholdImageFilter.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkBinaryThresholdImageFilter_h
00019 #define __itkBinaryThresholdImageFilter_h
00020 
00021 #include "itkUnaryFunctorImageFilter.h"
00022 #include "itkConceptChecking.h"
00023 #include "itkSimpleDataObjectDecorator.h"
00024 
00025 namespace itk
00026 {
00063 namespace Functor
00064 {
00065 template< class TInput, class TOutput >
00066 class BinaryThreshold
00067 {
00068 public:
00069   BinaryThreshold()
00070   {
00071     m_LowerThreshold = NumericTraits< TInput >::NonpositiveMin();
00072     m_UpperThreshold = NumericTraits< TInput >::max();
00073     m_OutsideValue   = NumericTraits< TOutput >::Zero;
00074     m_InsideValue    = NumericTraits< TOutput >::max();
00075   }
00076 
00077   ~BinaryThreshold() {}
00078 
00079   void SetLowerThreshold(const TInput & thresh)
00080   { m_LowerThreshold = thresh; }
00081   void SetUpperThreshold(const TInput & thresh)
00082   { m_UpperThreshold = thresh; }
00083   void SetInsideValue(const TOutput & value)
00084   { m_InsideValue = value; }
00085   void SetOutsideValue(const TOutput & value)
00086   { m_OutsideValue = value; }
00087 
00088   bool operator!=(const BinaryThreshold & other) const
00089   {
00090     if ( m_LowerThreshold != other.m_LowerThreshold
00091          || m_UpperThreshold != other.m_UpperThreshold
00092          || m_InsideValue    != other.m_InsideValue
00093          || m_OutsideValue   != other.m_OutsideValue  )
00094       {
00095       return true;
00096       }
00097     return false;
00098   }
00099 
00100   bool operator==(const BinaryThreshold & other) const
00101   {
00102     return !( *this != other );
00103   }
00104 
00105   inline TOutput operator()(const TInput & A) const
00106   {
00107     if ( m_LowerThreshold <= A && A <= m_UpperThreshold )
00108       {
00109       return m_InsideValue;
00110       }
00111     return m_OutsideValue;
00112   }
00113 
00114 private:
00115   TInput  m_LowerThreshold;
00116   TInput  m_UpperThreshold;
00117   TOutput m_InsideValue;
00118   TOutput m_OutsideValue;
00119 };
00120 }
00121 
00122 template< class TInputImage, class TOutputImage >
00123 class ITK_EXPORT BinaryThresholdImageFilter:
00124   public
00125   UnaryFunctorImageFilter< TInputImage, TOutputImage,
00126                            Functor::BinaryThreshold<
00127                              typename TInputImage::PixelType,
00128                              typename TOutputImage::PixelType > >
00129 {
00130 public:
00132   typedef BinaryThresholdImageFilter Self;
00133   typedef UnaryFunctorImageFilter< TInputImage, TOutputImage,
00134                                    Functor::BinaryThreshold<
00135                                      typename TInputImage::PixelType,
00136                                      typename TOutputImage::PixelType >
00137                                    >                                   Superclass;
00138   typedef SmartPointer< Self >       Pointer;
00139   typedef SmartPointer< const Self > ConstPointer;
00140 
00142   itkNewMacro(Self);
00143 
00145   itkTypeMacro(BinaryThresholdImageFilter, UnaryFunctorImageFilter);
00146 
00148   typedef typename TInputImage::PixelType  InputPixelType;
00149   typedef typename TOutputImage::PixelType OutputPixelType;
00150 
00152   typedef SimpleDataObjectDecorator< InputPixelType > InputPixelObjectType;
00153 
00156   itkSetMacro(OutsideValue, OutputPixelType);
00157 
00159   itkGetConstReferenceMacro(OutsideValue, OutputPixelType);
00160 
00163   itkSetMacro(InsideValue, OutputPixelType);
00164 
00166   itkGetConstReferenceMacro(InsideValue, OutputPixelType);
00167 
00172   virtual void SetUpperThreshold(const InputPixelType threshold);
00173 
00174   virtual void SetUpperThresholdInput(const InputPixelObjectType *);
00175 
00176   virtual void SetLowerThreshold(const InputPixelType threshold);
00177 
00178   virtual void SetLowerThresholdInput(const InputPixelObjectType *);
00179 
00181   virtual InputPixelType GetUpperThreshold() const;
00182 
00183   virtual InputPixelObjectType * GetUpperThresholdInput();
00184 
00185   virtual const InputPixelObjectType * GetUpperThresholdInput() const;
00186 
00187   virtual InputPixelType GetLowerThreshold() const;
00188 
00189   virtual InputPixelObjectType * GetLowerThresholdInput();
00190 
00191   virtual const InputPixelObjectType * GetLowerThresholdInput() const;
00192 
00193 #ifdef ITK_USE_CONCEPT_CHECKING
00194 
00195   itkConceptMacro( OutputEqualityComparableCheck,
00196                    ( Concept::EqualityComparable< OutputPixelType > ) );
00197   itkConceptMacro( InputPixelTypeComparable,
00198                    ( Concept::Comparable< InputPixelType > ) );
00199   itkConceptMacro( InputOStreamWritableCheck,
00200                    ( Concept::OStreamWritable< InputPixelType > ) );
00201   itkConceptMacro( OutputOStreamWritableCheck,
00202                    ( Concept::OStreamWritable< OutputPixelType > ) );
00203 
00205 #endif
00206 protected:
00207   BinaryThresholdImageFilter();
00208   virtual ~BinaryThresholdImageFilter() {}
00209   void PrintSelf(std::ostream & os, Indent indent) const;
00211 
00214   virtual void BeforeThreadedGenerateData();
00215 
00216 private:
00217   BinaryThresholdImageFilter(const Self &); //purposely not implemented
00218   void operator=(const Self &);             //purposely not implemented
00219 
00220   OutputPixelType m_InsideValue;
00221   OutputPixelType m_OutsideValue;
00222 };
00223 } // end namespace itk
00224 
00225 #ifndef ITK_MANUAL_INSTANTIATION
00226 #include "itkBinaryThresholdImageFilter.hxx"
00227 #endif
00228 
00229 #endif
00230