00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkIntensityWindowingImageFilter_h
00018 #define __itkIntensityWindowingImageFilter_h
00019
00020 #include "itkUnaryFunctorImageFilter.h"
00021
00022 namespace itk
00023 {
00024
00025
00026
00027
00028 namespace Functor {
00029
00030 template< typename TInput, typename TOutput>
00031 class IntensityWindowingTransform
00032 {
00033 public:
00034 typedef typename NumericTraits< TInput >::RealType RealType;
00035 IntensityWindowingTransform() {}
00036 ~IntensityWindowingTransform() {}
00037 bool operator!=( const IntensityWindowingTransform & other ) const
00038 {
00039 if( m_Factor != other.m_Factor ||
00040 m_Offset != other.m_Offset ||
00041 m_OutputMaximum != other.m_OutputMaximum ||
00042 m_OutputMinimum != other.m_OutputMinimum ||
00043 m_WindowMaximum != other.m_WindowMaximum ||
00044 m_WindowMinimum != other.m_WindowMinimum )
00045 {
00046 return true;
00047 }
00048 return false;
00049 }
00050 bool operator==( const IntensityWindowingTransform & other ) const
00051 {
00052 return !(*this != other);
00053 }
00054
00055 void SetFactor( RealType a ) { m_Factor = a; }
00056 void SetOffset( RealType b ) { m_Offset = b; }
00057 void SetOutputMinimum( TOutput min ) { m_OutputMinimum = min; }
00058 void SetOutputMaximum( TOutput max ) { m_OutputMaximum = max; }
00059 void SetWindowMinimum( TInput min ) { m_WindowMinimum = min; }
00060 void SetWindowMaximum( TInput max ) { m_WindowMaximum = max; }
00061 inline TOutput operator()( const TInput & x )
00062 {
00063 if( x < m_WindowMinimum )
00064 {
00065 return m_OutputMinimum;
00066 }
00067 if( x > m_WindowMaximum )
00068 {
00069 return m_OutputMaximum;
00070 }
00071 const RealType value = static_cast<RealType>(x) * m_Factor + m_Offset;
00072 const TOutput result = static_cast<TOutput>( value );
00073 return result;
00074 }
00075 private:
00076 RealType m_Factor;
00077 RealType m_Offset;
00078 TOutput m_OutputMaximum;
00079 TOutput m_OutputMinimum;
00080 TInput m_WindowMaximum;
00081 TInput m_WindowMinimum;
00082 };
00083
00084 }
00085
00086
00107 template <typename TInputImage, typename TOutputImage=TInputImage>
00108 class ITK_EXPORT IntensityWindowingImageFilter :
00109 public
00110 UnaryFunctorImageFilter<TInputImage,TOutputImage,
00111 Functor::IntensityWindowingTransform<
00112 typename TInputImage::PixelType,
00113 typename TOutputImage::PixelType> >
00114 {
00115 public:
00117 typedef IntensityWindowingImageFilter Self;
00118 typedef UnaryFunctorImageFilter<TInputImage,TOutputImage,
00119 Functor::IntensityWindowingTransform<
00120 typename TInputImage::PixelType,
00121 typename TOutputImage::PixelType> > Superclass;
00122 typedef SmartPointer<Self> Pointer;
00123 typedef SmartPointer<const Self> ConstPointer;
00124
00125 typedef typename TOutputImage::PixelType OutputPixelType;
00126 typedef typename TInputImage::PixelType InputPixelType;
00127 typedef typename NumericTraits<InputPixelType>::RealType RealType;
00128
00130 itkNewMacro(Self);
00131
00133 itkTypeMacro(IntensityWindowingImageFilter,
00134 UnaryFunctorImageFilter);
00135
00138 itkSetMacro( OutputMinimum, OutputPixelType );
00139 itkSetMacro( OutputMaximum, OutputPixelType );
00140 itkGetConstReferenceMacro( OutputMinimum, OutputPixelType );
00141 itkGetConstReferenceMacro( OutputMaximum, OutputPixelType );
00143
00146 itkSetMacro( WindowMinimum, InputPixelType );
00147 itkSetMacro( WindowMaximum, InputPixelType );
00148 itkGetConstReferenceMacro( WindowMinimum, InputPixelType );
00149 itkGetConstReferenceMacro( WindowMaximum, InputPixelType );
00151
00156 void SetWindowLevel(const InputPixelType& window,
00157 const InputPixelType& level);
00158 InputPixelType GetWindow() const;
00159 InputPixelType GetLevel() const;
00161
00165 itkGetConstReferenceMacro( Scale, RealType );
00166 itkGetConstReferenceMacro( Shift, RealType );
00168
00170 void BeforeThreadedGenerateData(void);
00171
00173 void PrintSelf(std::ostream& os, Indent indent) const;
00174
00175 #ifdef ITK_USE_CONCEPT_CHECKING
00176
00177 itkConceptMacro(InputHasNumericTraitsCheck,
00178 (Concept::HasNumericTraits<InputPixelType>));
00179
00181 #endif
00182
00183 protected:
00184 IntensityWindowingImageFilter();
00185 virtual ~IntensityWindowingImageFilter() {};
00186
00187 private:
00188 IntensityWindowingImageFilter(const Self&);
00189 void operator=(const Self&);
00190
00191 RealType m_Scale;
00192 RealType m_Shift;
00193
00194 InputPixelType m_WindowMinimum;
00195 InputPixelType m_WindowMaximum;
00196
00197 OutputPixelType m_OutputMinimum;
00198 OutputPixelType m_OutputMaximum;
00199
00200 };
00201
00202
00203
00204 }
00205
00206 #ifndef ITK_MANUAL_INSTANTIATION
00207 #include "itkIntensityWindowingImageFilter.txx"
00208 #endif
00209
00210 #endif
00211