00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __itkConstrainedValueAdditionImageFilter_h
00016 #define __itkConstrainedValueAdditionImageFilter_h
00017
00018 #include "itkBinaryFunctorImageFilter.h"
00019 #include "itkNumericTraits.h"
00020
00021 namespace itk
00022 {
00023
00050 namespace Functor {
00051
00052 template< class TInput1, class TInput2, class TOutput>
00053 class ConstrainedValueAddition
00054 {
00055 public:
00056 ConstrainedValueAddition() {};
00057 ~ConstrainedValueAddition() {};
00058 bool operator!=( const ConstrainedValueAddition & ) const
00059 {
00060 return false;
00061 }
00062 bool operator==( const ConstrainedValueAddition & other ) const
00063 {
00064 return !(*this != other);
00065 }
00066 inline TOutput operator()( const TInput1 & A,
00067 const TInput2 & B)
00068 {
00069 const double dA = static_cast<double>( A );
00070 const double dB = static_cast<double>( B );
00071 const double add = dA + dB;
00072 const double cadd = ( add < NumericTraits<TOutput>::max() ) ? add : NumericTraits<TOutput>::max();
00073 return static_cast<TOutput>( cadd );
00074 }
00075 };
00076 }
00077
00078 template <class TInputImage1, class TInputImage2, class TOutputImage>
00079 class ITK_EXPORT ConstrainedValueAdditionImageFilter :
00080 public
00081 BinaryFunctorImageFilter<TInputImage1,TInputImage2,TOutputImage,
00082 Functor::ConstrainedValueAddition<
00083 typename TInputImage1::PixelType,
00084 typename TInputImage2::PixelType,
00085 typename TOutputImage::PixelType> >
00086 {
00087 public:
00089 typedef ConstrainedValueAdditionImageFilter Self;
00090 typedef BinaryFunctorImageFilter<TInputImage1,TInputImage2,TOutputImage,
00091 Functor::ConstrainedValueAddition<
00092 typename TInputImage1::PixelType,
00093 typename TInputImage2::PixelType,
00094 typename TOutputImage::PixelType>
00095 > Superclass;
00096 typedef SmartPointer<Self> Pointer;
00097 typedef SmartPointer<const Self> ConstPointer;
00098
00100 itkNewMacro(Self);
00101
00102 #ifdef ITK_USE_CONCEPT_CHECKING
00103
00104 itkConceptMacro(Input1ConvertibleToDoubleCheck,
00105 (Concept::Convertible<typename TInputImage1::PixelType, double>));
00106 itkConceptMacro(Input2ConvertibleToDoubleCheck,
00107 (Concept::Convertible<typename TInputImage2::PixelType, double>));
00108 itkConceptMacro(DoubleConvertibleToOutputCastCheck,
00109 (Concept::Convertible<double, typename TOutputImage::PixelType>));
00110 itkConceptMacro(DoubleLessThanOutputCheck,
00111 (Concept::LessThanComparable<double, typename TOutputImage::PixelType>));
00112
00114 #endif
00115
00116 protected:
00117 ConstrainedValueAdditionImageFilter() {}
00118 virtual ~ConstrainedValueAdditionImageFilter() {}
00119
00120 private:
00121 ConstrainedValueAdditionImageFilter(const Self&);
00122 void operator=(const Self&);
00123
00124 };
00125
00126 }
00127
00128
00129 #endif
00130