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
00134 itkSetMacro( OutputMinimum, OutputPixelType );
00135 itkSetMacro( OutputMaximum, OutputPixelType );
00136 itkGetConstReferenceMacro( OutputMinimum, OutputPixelType );
00137 itkGetConstReferenceMacro( OutputMaximum, OutputPixelType );
00139
00142 itkSetMacro( WindowMinimum, InputPixelType );
00143 itkSetMacro( WindowMaximum, InputPixelType );
00144 itkGetConstReferenceMacro( WindowMinimum, InputPixelType );
00145 itkGetConstReferenceMacro( WindowMaximum, InputPixelType );
00147
00152 void SetWindowLevel(const InputPixelType& window,
00153 const InputPixelType& level);
00154 InputPixelType GetWindow() const;
00155 InputPixelType GetLevel() const;
00157
00161 itkGetConstReferenceMacro( Scale, RealType );
00162 itkGetConstReferenceMacro( Shift, RealType );
00164
00166 void BeforeThreadedGenerateData(void);
00167
00169 void PrintSelf(std::ostream& os, Indent indent) const;
00170
00171 #ifdef ITK_USE_CONCEPT_CHECKING
00172
00173 itkConceptMacro(InputHasNumericTraitsCheck,
00174 (Concept::HasNumericTraits<InputPixelType>));
00175
00177 #endif
00178
00179 protected:
00180 IntensityWindowingImageFilter();
00181 virtual ~IntensityWindowingImageFilter() {};
00182
00183 private:
00184 IntensityWindowingImageFilter(const Self&);
00185 void operator=(const Self&);
00186
00187 RealType m_Scale;
00188 RealType m_Shift;
00189
00190 InputPixelType m_WindowMinimum;
00191 InputPixelType m_WindowMaximum;
00192
00193 OutputPixelType m_OutputMinimum;
00194 OutputPixelType m_OutputMaximum;
00195
00196 };
00197
00198
00199
00200 }
00201
00202 #ifndef ITK_MANUAL_INSTANTIATION
00203 #include "itkIntensityWindowingImageFilter.txx"
00204 #endif
00205
00206 #endif
00207