Go to the documentation of this file.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 ) const
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 if( ct != this->GetFunctor().GetConstant() )
00109 {
00110 this->GetFunctor().SetConstant(ct);
00111 this->Modified();
00112 }
00113 }
00114 const TConstant & GetConstant() const
00115 {
00116 return this->GetFunctor().GetConstant();
00117 }
00119
00120
00121 #ifdef ITK_USE_CONCEPT_CHECKING
00122
00123 itkConceptMacro(InputConvertibleToOutputCheck,
00124 (Concept::Convertible<typename TInputImage::PixelType,
00125 typename TOutputImage::PixelType>));
00126
00127
00128
00129
00130
00131
00133 #endif
00134
00135 protected:
00136 DivideByConstantImageFilter() {};
00137 virtual ~DivideByConstantImageFilter() {};
00138
00139 void PrintSelf(std::ostream &os, Indent indent) const
00140 {
00141 Superclass::PrintSelf(os, indent);
00142 os << indent << "Constant: "
00143 << static_cast<typename NumericTraits<TConstant>::PrintType>(this->GetConstant())
00144 << std::endl;
00145 }
00146
00147 private:
00148 DivideByConstantImageFilter(const Self&);
00149 void operator=(const Self&);
00150
00151 };
00152
00153
00154 }
00155
00156 #endif
00157