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: 2009-04-01 14:36:21 $
00007   Version:   $Revision: 1.10 $
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 ) const
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<
00119     TInputImage,TOutputImage, 
00120     Functor::IntensityWindowingTransform< 
00121       typename TInputImage::PixelType, 
00122       typename TOutputImage::PixelType> >  Superclass;
00123   typedef SmartPointer<Self>               Pointer;
00124   typedef SmartPointer<const Self>         ConstPointer;
00125 
00126   typedef typename TOutputImage::PixelType                 OutputPixelType;
00127   typedef typename TInputImage::PixelType                  InputPixelType;
00128   typedef typename NumericTraits<InputPixelType>::RealType RealType;
00129 
00131   itkNewMacro(Self);
00132 
00134   itkTypeMacro(IntensityWindowingImageFilter, 
00135                UnaryFunctorImageFilter);
00136 
00139   itkSetMacro( OutputMinimum, OutputPixelType );
00140   itkSetMacro( OutputMaximum, OutputPixelType );
00141   itkGetConstReferenceMacro( OutputMinimum, OutputPixelType );
00142   itkGetConstReferenceMacro( OutputMaximum, OutputPixelType );
00144 
00147   itkSetMacro( WindowMinimum, InputPixelType );
00148   itkSetMacro( WindowMaximum, InputPixelType );
00149   itkGetConstReferenceMacro( WindowMinimum, InputPixelType );
00150   itkGetConstReferenceMacro( WindowMaximum, InputPixelType );
00152 
00157   void SetWindowLevel(const InputPixelType& window,
00158                       const InputPixelType& level);
00159   InputPixelType GetWindow() const;
00160   InputPixelType GetLevel() const;
00162 
00166   itkGetConstReferenceMacro( Scale, RealType );
00167   itkGetConstReferenceMacro( Shift, RealType );
00169 
00171   void BeforeThreadedGenerateData(void);
00172 
00174   void PrintSelf(std::ostream& os, Indent indent) const;
00175 
00176 #ifdef ITK_USE_CONCEPT_CHECKING
00177 
00178   itkConceptMacro(InputHasNumericTraitsCheck,
00179                   (Concept::HasNumericTraits<InputPixelType>));
00180 
00182 #endif
00183 
00184 protected:
00185   IntensityWindowingImageFilter();
00186   virtual ~IntensityWindowingImageFilter() {};
00187 
00188 private:
00189   IntensityWindowingImageFilter(const Self&); //purposely not implemented
00190   void operator=(const Self&); //purposely not implemented
00191 
00192   RealType m_Scale;
00193   RealType m_Shift;
00194 
00195   InputPixelType        m_WindowMinimum;
00196   InputPixelType        m_WindowMaximum;
00197 
00198   OutputPixelType       m_OutputMinimum;
00199   OutputPixelType       m_OutputMaximum;
00200 
00201 };
00202 
00203 
00204   
00205 } // end namespace itk
00206   
00207 #ifndef ITK_MANUAL_INSTANTIATION
00208 #include "itkIntensityWindowingImageFilter.txx"
00209 #endif
00210   
00211 #endif
00212 

Generated at Tue Sep 15 03:35:46 2009 for ITK by doxygen 1.5.8 written by Dimitri van Heesch, © 1997-2000