Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkIntensityWindowingImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkIntensityWindowingImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/09/27 11:36:40 $
00007   Version:   $Revision: 1.8 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkIntensityWindowingImageFilter_h
00018 #define __itkIntensityWindowingImageFilter_h
00019 
00020 #include "itkUnaryFunctorImageFilter.h"
00021 
00022 namespace itk
00023 {
00024 
00025 // This functor class applies a linear transformation A.x + B inside a specified 
00026 // range. Values below the range are mapped to a constant. Values over the range
00027 // are mapped to another constant.
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 }  // end namespace functor
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&); //purposely not implemented
00189   void operator=(const Self&); //purposely not implemented
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 } // end namespace itk
00205   
00206 #ifndef ITK_MANUAL_INSTANTIATION
00207 #include "itkIntensityWindowingImageFilter.txx"
00208 #endif
00209   
00210 #endif
00211 

Generated at Tue Jul 29 20:53:41 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000