00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __itkDivideByConstantImageFilter_h
00019 #define __itkDivideByConstantImageFilter_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 DivideByConstant
00046 {
00047 public:
00048 DivideByConstant() : m_Constant(NumericTraits<TConstant>::One) {};
00049 ~DivideByConstant() {};
00050 bool operator!=( const DivideByConstant & other ) const
00051 {
00052 return !(*this == other);
00053 }
00054 bool operator==( const DivideByConstant & 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)
00065 {
00066 if( ct == NumericTraits<TConstant>::Zero )
00067 {
00068 itkGenericExceptionMacro(
00069 <<"The constant value used as denominator should not be set to zero");
00070 }
00071
00072 this->m_Constant = ct;
00073 }
00074 const TConstant GetConstant() const { return m_Constant; }
00075
00076 TConstant m_Constant;
00077 };
00078 }
00079
00080 template <class TInputImage, class TConstant, class TOutputImage>
00081 class ITK_EXPORT DivideByConstantImageFilter :
00082 public
00083 UnaryFunctorImageFilter<TInputImage,TOutputImage,
00084 Functor::DivideByConstant<
00085 typename TInputImage::PixelType, TConstant,
00086 typename TOutputImage::PixelType> >
00087 {
00088 public:
00090 typedef DivideByConstantImageFilter Self;
00091 typedef UnaryFunctorImageFilter<
00092 TInputImage,TOutputImage, Functor::DivideByConstant<
00093 typename TInputImage::PixelType, TConstant,
00094 typename TOutputImage::PixelType> > Superclass;
00095 typedef SmartPointer<Self> Pointer;
00096 typedef SmartPointer<const Self> ConstPointer;
00097
00099 itkNewMacro(Self);
00100
00102 itkTypeMacro(DivideByConstantImageFilter, UnaryFunctorImageFilter);
00103
00106 void SetConstant( TConstant ct )
00107 {
00108 this->GetFunctor().SetConstant(ct);
00109 this->Modified();
00110 }
00112
00113
00114 #ifdef ITK_USE_CONCEPT_CHECKING
00115
00116 itkConceptMacro(InputConvertibleToOutputCheck,
00117 (Concept::Convertible<typename TInputImage::PixelType,
00118 typename TOutputImage::PixelType>));
00119
00120
00121
00122
00123
00124
00126 #endif
00127
00128 protected:
00129 DivideByConstantImageFilter() {};
00130 virtual ~DivideByConstantImageFilter() {};
00131
00132 DivideByConstantImageFilter(const Self&);
00133 void operator=(const Self&);
00134
00135 };
00136
00137
00138 }
00139
00140 #endif
00141