00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkMaskImageFilter_h
00018 #define __itkMaskImageFilter_h
00019
00020 #include "itkBinaryFunctorImageFilter.h"
00021 #include "itkNumericTraits.h"
00022
00023
00024 namespace itk
00025 {
00026
00053 namespace Functor {
00054
00055 template< class TInput, class TMask, class TOutput >
00056 class MaskInput
00057 {
00058 public:
00059 typedef typename NumericTraits< TInput >::AccumulateType AccumulatorType;
00060
00061 MaskInput(): m_OutsideValue(NumericTraits< TOutput >::ZeroValue()) {};
00062 ~MaskInput() {};
00063 bool operator!=( const MaskInput & ) const
00064 {
00065 return false;
00066 }
00067 bool operator==( const MaskInput & other ) const
00068 {
00069 return !(*this != other);
00070 }
00071
00072 inline TOutput operator()( const TInput & A, const TMask & B)
00073 {
00074 if (B != NumericTraits< TMask >::ZeroValue() )
00075 {
00076 return static_cast<TOutput>( A );
00077 }
00078 else
00079 {
00080 return m_OutsideValue;
00081 }
00082 }
00083
00085 void SetOutsideValue( const TOutput &outsideValue )
00086 {
00087 m_OutsideValue = outsideValue;
00088 }
00089
00091 const TOutput &GetOutsideValue() const
00092 {
00093 return m_OutsideValue;
00094 }
00095
00096 private:
00097 TOutput m_OutsideValue;
00098 };
00099
00100 }
00101 template <class TInputImage, class TMaskImage, class TOutputImage>
00102 class ITK_EXPORT MaskImageFilter :
00103 public
00104 BinaryFunctorImageFilter<TInputImage,TMaskImage,TOutputImage,
00105 Functor::MaskInput<
00106 typename TInputImage::PixelType,
00107 typename TMaskImage::PixelType,
00108 typename TOutputImage::PixelType> >
00109
00110
00111 {
00112 public:
00114 typedef MaskImageFilter Self;
00115 typedef BinaryFunctorImageFilter<TInputImage,TMaskImage,TOutputImage,
00116 Functor::MaskInput<
00117 typename TInputImage::PixelType,
00118 typename TMaskImage::PixelType,
00119 typename TOutputImage::PixelType>
00120 > Superclass;
00121 typedef SmartPointer<Self> Pointer;
00122 typedef SmartPointer<const Self> ConstPointer;
00123
00125 itkNewMacro(Self);
00126
00128 void SetOutsideValue( const typename TOutputImage::PixelType & outsudeValue )
00129 {
00130 this->GetFunctor().SetOutsideValue( outsudeValue );
00131 }
00132
00133 #ifdef ITK_USE_CONCEPT_CHECKING
00134
00135 itkConceptMacro(MaskEqualityComparableCheck,
00136 (Concept::EqualityComparable<typename TMaskImage::PixelType>));
00137 itkConceptMacro(InputConvertibleToOutputCheck,
00138 (Concept::Convertible<typename TInputImage::PixelType,
00139 typename TOutputImage::PixelType>));
00140
00142 #endif
00143
00144 protected:
00145 MaskImageFilter() {}
00146 virtual ~MaskImageFilter() {}
00147
00148 private:
00149 MaskImageFilter(const Self&);
00150 void operator=(const Self&);
00151
00152 };
00153
00154 }
00155
00156
00157 #endif
00158