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