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

itkDivideByConstantImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkDivideByConstantImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2008-06-29 19:53:02 $
00007   Version:   $Revision: 1.2 $
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 
00018 #ifndef __itkDivideByConstantImageFilter_h
00019 #define __itkDivideByConstantImageFilter_h
00020 
00021 #include "itkUnaryFunctorImageFilter.h"
00022 #include "itkNumericTraits.h"
00023 
00024 namespace itk
00025 {
00026   
00042 namespace Functor {  
00043   
00044 template< class TInput, class TConstant, class TOutput>
00045 class DivideByConstant
00046 {
00047 public:
00048   DivideByConstant() : m_Constant(NumericTraits<TConstant>::One) {};
00049   ~DivideByConstant() {};
00050   bool operator!=( const DivideByConstant & other ) const
00051     {
00052     return !(*this == other);
00053     }
00054   bool operator==( const DivideByConstant & other ) const
00055     {
00056     return other.m_Constant == m_Constant;
00057     }
00058   inline TOutput operator()( const TInput & A )
00059     {
00060     // Because the user has to specify the constant we don't
00061     // check if the constant is not too small (i.e. almost equal to zero);
00062     return static_cast<TOutput>( A / m_Constant );
00063     }
00064   void SetConstant(TConstant ct)
00065     {
00066     if( ct == NumericTraits<TConstant>::Zero )
00067       {
00068       itkGenericExceptionMacro(
00069         <<"The constant value used as denominator should not be set to zero");
00070       }
00071 
00072     this->m_Constant = ct;
00073     }
00074   const TConstant GetConstant() const { return m_Constant; }
00075    
00076   TConstant m_Constant;
00077 };
00078 }
00079 
00080 template <class TInputImage, class TConstant, class TOutputImage>
00081 class ITK_EXPORT DivideByConstantImageFilter :
00082       public
00083 UnaryFunctorImageFilter<TInputImage,TOutputImage, 
00084                         Functor::DivideByConstant< 
00085    typename TInputImage::PixelType, TConstant,
00086    typename TOutputImage::PixelType> >
00087 {
00088 public:
00090   typedef DivideByConstantImageFilter                        Self;
00091   typedef UnaryFunctorImageFilter<
00092     TInputImage,TOutputImage, Functor::DivideByConstant< 
00093       typename TInputImage::PixelType, TConstant,
00094       typename TOutputImage::PixelType>   >                  Superclass;
00095   typedef SmartPointer<Self>                                 Pointer;
00096   typedef SmartPointer<const Self>                           ConstPointer;
00097 
00099   itkNewMacro(Self);
00100 
00102   itkTypeMacro(DivideByConstantImageFilter, UnaryFunctorImageFilter);
00103 
00106   void SetConstant( TConstant ct )
00107     {
00108     this->GetFunctor().SetConstant(ct);
00109     this->Modified();
00110     }
00112 
00113 
00114 #ifdef ITK_USE_CONCEPT_CHECKING
00115 
00116   itkConceptMacro(InputConvertibleToOutputCheck,
00117                    (Concept::Convertible<typename TInputImage::PixelType,
00118                     typename TOutputImage::PixelType>));
00119   // The following concept check doesn't seem to work with vector immages
00120   //itkConceptMacro(Input1Input2OutputDivisionOperatorsCheck,
00121   //                (Concept::DivisionOperators<typename TInputImage::PixelType,
00122   //                 TConstant,
00123   //                 typename TOutputImage::PixelType>));
00124 
00126 #endif
00127 
00128 protected:
00129   DivideByConstantImageFilter() {};
00130   virtual ~DivideByConstantImageFilter() {};
00131    
00132   DivideByConstantImageFilter(const Self&); //purposely not implemented
00133   void operator=(const Self&); //purposely not implemented
00134 
00135 };
00136 
00137 
00138 } // end namespace itk
00139 
00140 #endif
00141 

Generated at Tue Jul 29 19:49:06 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000