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

itkAddConstantToImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkAddConstantToImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2008-09-29 18:36:37 $
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 __itkAddConstantToImageFilter_h
00019 #define __itkAddConstantToImageFilter_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 AddConstantTo
00046 {
00047 public:
00048   AddConstantTo() : m_Constant(NumericTraits<TConstant>::One) {};
00049   ~AddConstantTo() {};
00050   bool operator!=( const AddConstantTo & other ) const
00051     {
00052     return !(*this == other);
00053     }
00054   bool operator==( const AddConstantTo & 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 cte is not 0;
00062     return static_cast<TOutput>( A + m_Constant );
00063     }
00064   void SetConstant(TConstant ct) {this->m_Constant = ct; }
00065   const TConstant & GetConstant() const { return m_Constant; }
00066   
00067   TConstant m_Constant;
00068 };
00069 }
00070 
00071 template <class TInputImage, class TConstant, class TOutputImage>
00072 class ITK_EXPORT AddConstantToImageFilter :
00073       public
00074 UnaryFunctorImageFilter<TInputImage,TOutputImage, 
00075                         Functor::AddConstantTo< 
00076    typename TInputImage::PixelType, TConstant,
00077    typename TOutputImage::PixelType> >
00078 {
00079 public:
00081   typedef AddConstantToImageFilter                 Self;
00082   typedef UnaryFunctorImageFilter<
00083     TInputImage,TOutputImage, 
00084     Functor::AddConstantTo< 
00085       typename TInputImage::PixelType, TConstant,
00086       typename TOutputImage::PixelType>   >             Superclass;
00087 
00088   typedef SmartPointer<Self>                            Pointer;
00089   typedef SmartPointer<const Self>                      ConstPointer;
00090 
00092   itkNewMacro(Self);
00093 
00095   itkTypeMacro(AddConstantToImageFilter, UnaryFunctorImageFilter);
00096 
00097   
00099   void SetConstant(TConstant ct)
00100     {
00101     if( ct != this->GetFunctor().GetConstant() )
00102       {
00103       this->GetFunctor().SetConstant(ct);
00104       this->Modified();
00105       }
00106     }
00107   const TConstant & GetConstant() const
00108     {
00109     return this->GetFunctor().GetConstant();
00110     }
00112 
00113 #ifdef ITK_USE_CONCEPT_CHECKING
00114 
00115   itkConceptMacro(InputConvertibleToOutputCheck,
00116                   (Concept::Convertible<typename TInputImage::PixelType,
00117                    typename TOutputImage::PixelType>));
00118   itkConceptMacro(Input1Input2OutputAddOperatorCheck,
00119                   (Concept::AdditiveOperators<typename TInputImage::PixelType,
00120                    TConstant,
00121                    typename TOutputImage::PixelType>));
00122 
00124 #endif
00125 
00126 protected:
00127   AddConstantToImageFilter() {};
00128   virtual ~AddConstantToImageFilter() {};
00129    
00130   void PrintSelf(std::ostream &os, Indent indent) const
00131     {
00132     Superclass::PrintSelf(os, indent);
00133     os << indent << "Constant: " 
00134        << static_cast<typename NumericTraits<TConstant>::PrintType>(this->GetConstant())
00135        << std::endl;
00136     }
00137 
00138 private:
00139   AddConstantToImageFilter(const Self&); //purposely not implemented
00140   void operator=(const Self&); //purposely not implemented
00141 
00142 };
00143 
00144 
00145 } // end namespace itk
00146 
00147 #endif
00148 

Generated at Wed Nov 5 20:14:06 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000