00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __itkAddConstantToImageFilter_h
00019 #define __itkAddConstantToImageFilter_h
00020
00021 #include "itkUnaryFunctorImageFilter.h"
00022 #include "itkNumericTraits.h"
00023
00024 namespace itk
00025 {
00026
00042 namespace Functor {
00043
00044 template< class TInput, class TConstant, class TOutput>
00045 class AddConstantTo
00046 {
00047 public:
00048 AddConstantTo() : m_Constant(NumericTraits<TConstant>::One) {};
00049 ~AddConstantTo() {};
00050 bool operator!=( const AddConstantTo & other ) const
00051 {
00052 return !(*this == other);
00053 }
00054 bool operator==( const AddConstantTo & other ) const
00055 {
00056 return other.m_Constant == m_Constant;
00057 }
00058 inline TOutput operator()( const TInput & A )
00059 {
00060
00061
00062 return static_cast<TOutput>( A + m_Constant );
00063 }
00064 void SetConstant(TConstant ct) {this->m_Constant = ct; }
00065 const TConstant GetConstant() const { return m_Constant; }
00066
00067 TConstant m_Constant;
00068 };
00069 }
00070
00071 template <class TInputImage, class TConstant, class TOutputImage>
00072 class ITK_EXPORT AddConstantToImageFilter :
00073 public
00074 UnaryFunctorImageFilter<TInputImage,TOutputImage,
00075 Functor::AddConstantTo<
00076 typename TInputImage::PixelType, TConstant,
00077 typename TOutputImage::PixelType> >
00078 {
00079 public:
00081 typedef AddConstantToImageFilter Self;
00082 typedef UnaryFunctorImageFilter<
00083 TInputImage,TOutputImage,
00084 Functor::AddConstantTo<
00085 typename TInputImage::PixelType, TConstant,
00086 typename TOutputImage::PixelType> > Superclass;
00087 typedef SmartPointer<Self> Pointer;
00088 typedef SmartPointer<const Self> ConstPointer;
00089
00091 itkNewMacro(Self);
00092
00094 itkTypeMacro(AddConstantToImageFilter, UnaryFunctorImageFilter);
00095
00096
00098 void SetConstant(TConstant ct)
00099 {
00100 this->GetFunctor().SetConstant(ct);
00101 this->Modified();
00102 }
00104
00105
00106 #ifdef ITK_USE_CONCEPT_CHECKING
00107
00108 itkConceptMacro(InputConvertibleToOutputCheck,
00109 (Concept::Convertible<typename TInputImage::PixelType,
00110 typename TOutputImage::PixelType>));
00111 itkConceptMacro(Input1Input2OutputAddOperatorCheck,
00112 (Concept::AdditiveOperators<typename TInputImage::PixelType,
00113 TConstant,
00114 typename TOutputImage::PixelType>));
00115
00117 #endif
00118
00119 protected:
00120 AddConstantToImageFilter() {};
00121 virtual ~AddConstantToImageFilter() {};
00122
00123 AddConstantToImageFilter(const Self&);
00124 void operator=(const Self&);
00125
00126 };
00127
00128
00129 }
00130
00131 #endif
00132