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-08-11 21:18:10 $
00007   Version:   $Revision: 1.3 $
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     if( ct != this->GetFunctor().GetConstant() )
00109       {
00110       this->GetFunctor().SetConstant(ct);
00111       this->Modified();
00112       }
00113     }
00114   const TConstant & GetConstant() const
00115     {
00116     return this->GetFunctor().GetConstant();
00117     }
00119 
00120 
00121 #ifdef ITK_USE_CONCEPT_CHECKING
00122 
00123   itkConceptMacro(InputConvertibleToOutputCheck,
00124                    (Concept::Convertible<typename TInputImage::PixelType,
00125                     typename TOutputImage::PixelType>));
00126   // The following concept check doesn't seem to work with vector immages
00127   //itkConceptMacro(Input1Input2OutputDivisionOperatorsCheck,
00128   //                (Concept::DivisionOperators<typename TInputImage::PixelType,
00129   //                 TConstant,
00130   //                 typename TOutputImage::PixelType>));
00131 
00133 #endif
00134 
00135 protected:
00136   DivideByConstantImageFilter() {};
00137   virtual ~DivideByConstantImageFilter() {};
00138    
00139   void PrintSelf(std::ostream &os, Indent indent) const
00140     {
00141     Superclass::PrintSelf(os, indent);
00142     os << indent << "Constant: " 
00143        << static_cast<typename NumericTraits<TConstant>::PrintType>(this->GetConstant())
00144        << std::endl;
00145     }
00146 
00147 private:
00148   DivideByConstantImageFilter(const Self&); //purposely not implemented
00149   void operator=(const Self&); //purposely not implemented
00150 
00151 };
00152 
00153 
00154 } // end namespace itk
00155 
00156 #endif
00157 

Generated at Wed Nov 5 21:11:25 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000