00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __itkMultiplyByConstantImageFilter_h
00019 #define __itkMultiplyByConstantImageFilter_h
00020
00021 #include "itkUnaryFunctorImageFilter.h"
00022 #include "itkNumericTraits.h"
00023
00024 namespace itk
00025 {
00026
00043 namespace Functor {
00044
00045 template< class TInput, class TConstant, class TOutput>
00046 class MultiplyByConstant
00047 {
00048 public:
00049 MultiplyByConstant() : m_Constant(NumericTraits<TConstant>::One) {};
00050 ~MultiplyByConstant() {};
00051 bool operator!=( const MultiplyByConstant & other ) const
00052 {
00053 return !(*this == other);
00054 }
00055 bool operator==( const MultiplyByConstant & other ) const
00056 {
00057 return other.m_Constant == m_Constant;
00058 }
00059 inline TOutput operator()( const TInput & A ) const
00060 {
00061
00062
00063 return static_cast<TOutput>( A * m_Constant );
00064 }
00065 void SetConstant(TConstant ct) {this->m_Constant = ct; }
00066 const TConstant & GetConstant() const { return m_Constant; }
00067
00068 TConstant m_Constant;
00069 };
00070 }
00071
00072 template <class TInputImage, class TConstant, class TOutputImage>
00073 class ITK_EXPORT MultiplyByConstantImageFilter :
00074 public
00075 UnaryFunctorImageFilter<TInputImage,TOutputImage,
00076 Functor::MultiplyByConstant<
00077 typename TInputImage::PixelType, TConstant,
00078 typename TOutputImage::PixelType> >
00079 {
00080 public:
00082 typedef MultiplyByConstantImageFilter Self;
00083 typedef UnaryFunctorImageFilter<
00084 TInputImage,TOutputImage,
00085 Functor::MultiplyByConstant<
00086 typename TInputImage::PixelType, TConstant,
00087 typename TOutputImage::PixelType> > Superclass;
00088 typedef SmartPointer<Self> Pointer;
00089 typedef SmartPointer<const Self> ConstPointer;
00090
00092 itkNewMacro(Self);
00093
00095 itkTypeMacro(MultiplyByConstantImageFilter, UnaryFunctorImageFilter);
00096
00097
00099 void SetConstant(TConstant ct)
00100 {
00101 if( ct != this->GetFunctor().GetConstant() )
00102 {
00103 this->GetFunctor().SetConstant(ct);
00104 this->Modified();
00105 }
00106 }
00107 const TConstant & GetConstant() const
00108 {
00109 return this->GetFunctor().GetConstant();
00110 }
00112
00113
00114 #ifdef ITK_USE_CONCEPT_CHECKING
00115
00116 itkConceptMacro(InputConvertibleToOutputCheck,
00117 (Concept::Convertible<typename TInputImage::PixelType,
00118 typename TOutputImage::PixelType>));
00119 itkConceptMacro(Input1Input2OutputMultiplyOperatorCheck,
00120 (Concept::MultiplyOperator<typename TInputImage::PixelType,
00121 TConstant,
00122 typename TOutputImage::PixelType>));
00123
00125 #endif
00126
00127 protected:
00128 MultiplyByConstantImageFilter() {};
00129 virtual ~MultiplyByConstantImageFilter() {};
00130
00131 void PrintSelf(std::ostream &os, Indent indent) const
00132 {
00133 Superclass::PrintSelf(os, indent);
00134 os << indent << "Constant: "
00135 << static_cast<typename NumericTraits<TConstant>::PrintType>(this->GetConstant())
00136 << std::endl;
00137 }
00138
00139 private:
00140 MultiplyByConstantImageFilter(const Self&);
00141 void operator=(const Self&);
00142
00143 };
00144
00145
00146 }
00147
00148 #endif
00149