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 inline TOutput operator()( const TInput1 & A,
00059 const TInput2 & B)
00060 {
00061 const double dA = static_cast<double>( A );
00062 const double dB = static_cast<double>( B );
00063 const double add = dA + dB;
00064 const double cadd = ( add < NumericTraits<TOutput>::max() ) ? add : NumericTraits<TOutput>::max();
00065 return static_cast<TOutput>( cadd );
00066 }
00067 };
00068 }
00069
00070 template <class TInputImage1, class TInputImage2, class TOutputImage>
00071 class ITK_EXPORT ConstrainedValueAdditionImageFilter :
00072 public
00073 BinaryFunctorImageFilter<TInputImage1,TInputImage2,TOutputImage,
00074 Functor::ConstrainedValueAddition<
00075 typename TInputImage1::PixelType,
00076 typename TInputImage2::PixelType,
00077 typename TOutputImage::PixelType> >
00078 {
00079 public:
00081 typedef ConstrainedValueAdditionImageFilter Self;
00082 typedef BinaryFunctorImageFilter<TInputImage1,TInputImage2,TOutputImage,
00083 Functor::ConstrainedValueAddition<
00084 typename TInputImage1::PixelType,
00085 typename TInputImage2::PixelType,
00086 typename TOutputImage::PixelType>
00087 > Superclass;
00088 typedef SmartPointer<Self> Pointer;
00089 typedef SmartPointer<const Self> ConstPointer;
00090
00092 itkNewMacro(Self);
00093
00094 protected:
00095 ConstrainedValueAdditionImageFilter() {}
00096 virtual ~ConstrainedValueAdditionImageFilter() {}
00097
00098 private:
00099 ConstrainedValueAdditionImageFilter(const Self&);
00100 void operator=(const Self&);
00101
00102 };
00103
00104 }
00105
00106
00107 #endif