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

itkSigmoidImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkSigmoidImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2006/03/31 14:31:04 $
00007   Version:   $Revision: 1.13 $
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 __itkSigmoidImageFilter_h
00018 #define __itkSigmoidImageFilter_h
00019 
00020 #include "itkUnaryFunctorImageFilter.h"
00021 
00022 namespace itk
00023 {
00024   
00042 namespace Function {  
00043 template< class TInput, class TOutput>
00044 class Sigmoid
00045 {
00046 public:
00047   Sigmoid() { 
00048     m_Alpha = 1.0; 
00049     m_Beta =  0.0; 
00050     m_OutputMinimum = NumericTraits< TOutput >::min();
00051     m_OutputMaximum = NumericTraits< TOutput >::max();
00052   }
00053   ~Sigmoid() {};
00054   bool operator!=( const Sigmoid & other ) const
00055   {
00056     if( m_Alpha != other.m_Alpha ||
00057         m_Beta != other.m_Beta ||
00058         m_OutputMaximum != other.m_OutputMaximum    ||
00059         m_OutputMinimum != other.m_OutputMinimum  )
00060       {
00061       return true;
00062       }
00063     return false;
00064   }
00065   bool operator==( const Sigmoid & other ) const
00066   {
00067     return !(*this != other);
00068   }
00069 
00070   inline TOutput operator()( const TInput & A )
00071   {
00072     const double x = ( static_cast<double>(A) - m_Beta ) / m_Alpha;
00073     const double e = 1.0 / ( 1.0 + vcl_exp(- x ) );
00074     const double v = 
00075       (m_OutputMaximum - m_OutputMinimum ) * e + m_OutputMinimum;
00076     return static_cast<TOutput>( v );
00077   }
00078   void SetAlpha( double alpha ) {
00079     m_Alpha = alpha;
00080   }
00081   void SetBeta( double beta ) {
00082     m_Beta = beta;
00083   }
00084   double GetAlpha() const {
00085     return m_Alpha;
00086   }
00087   double GetBeta() const {
00088     return m_Beta;
00089   }
00090   void SetOutputMinimum( TOutput min ) {
00091     m_OutputMinimum = min;
00092   }
00093   void SetOutputMaximum( TOutput max ) {
00094     m_OutputMaximum = max;
00095   }
00096   TOutput GetOutputMinimum() const {
00097     return m_OutputMinimum;
00098   }
00099   TOutput GetOutputMaximum() const {
00100     return m_OutputMaximum;
00101   }
00102 
00103 private:
00104   double  m_Alpha;
00105   double  m_Beta;
00106   TOutput m_OutputMinimum;
00107   TOutput m_OutputMaximum;
00108 }; 
00109 }
00110 
00111 
00112 template <class TInputImage, class TOutputImage>
00113 class ITK_EXPORT SigmoidImageFilter :
00114     public
00115 UnaryFunctorImageFilter<TInputImage,TOutputImage, 
00116                         Function::Sigmoid< 
00117   typename TInputImage::PixelType, 
00118   typename TOutputImage::PixelType>   >
00119 {
00120 public:
00122   typedef SigmoidImageFilter  Self;
00123   typedef UnaryFunctorImageFilter<TInputImage,TOutputImage, 
00124                                   Function::Sigmoid< typename TInputImage::PixelType, 
00125                                                      typename TOutputImage::PixelType> >  Superclass;
00126   typedef SmartPointer<Self>   Pointer;
00127   typedef SmartPointer<const Self>  ConstPointer;
00128 
00129   typedef typename TOutputImage::PixelType OutputPixelType;
00130 
00132   itkNewMacro(Self);
00133 
00134   void SetAlpha( double alpha )
00135   {
00136     if( alpha == this->GetFunctor().GetAlpha() ) 
00137       {
00138       return;
00139       }
00140     this->GetFunctor().SetAlpha( alpha );
00141     this->Modified();
00142   }
00143 
00144   void SetBeta( double beta )
00145   {
00146     if( beta == this->GetFunctor().GetBeta() ) 
00147       {
00148       return;
00149       }
00150     this->GetFunctor().SetBeta( beta );
00151     this->Modified();
00152   }
00153 
00154   void SetOutputMinimum( OutputPixelType min )
00155   {
00156     if( min == this->GetFunctor().GetOutputMinimum() ) 
00157       {
00158       return;
00159       }
00160     this->GetFunctor().SetOutputMinimum( min );
00161     this->Modified();
00162   }
00163 
00164   void SetOutputMaximum( OutputPixelType max )
00165   {
00166     if( max == this->GetFunctor().GetOutputMaximum() ) 
00167       {
00168       return;
00169       }
00170     this->GetFunctor().SetOutputMaximum( max );
00171     this->Modified();
00172   }
00173 
00174 #ifdef ITK_USE_CONCEPT_CHECKING
00175 
00176   itkConceptMacro(InputConvertibleToDoubleCheck,
00177     (Concept::Convertible<typename TInputImage::PixelType, double>));
00178   itkConceptMacro(OutputAdditiveOperatorsCheck,
00179     (Concept::AdditiveOperators<OutputPixelType>));
00180   itkConceptMacro(DoubleConvertibleToOutputCheck,
00181     (Concept::Convertible<double, OutputPixelType>));
00182   itkConceptMacro(OutputTimesDoubleCheck,
00183     (Concept::MultiplyOperator<OutputPixelType, double>));
00184   itkConceptMacro(OutputDoubleAdditiveOperatorsCheck,
00185     (Concept::AdditiveOperators<OutputPixelType, OutputPixelType, double>));
00186 
00188 #endif
00189 
00190 protected:
00191   SigmoidImageFilter() {}
00192   virtual ~SigmoidImageFilter() {}
00193 
00194 private:
00195   SigmoidImageFilter(const Self&); //purposely not implemented
00196   void operator=(const Self&); //purposely not implemented
00197 
00198 };
00199 
00200 } // end namespace itk
00201 
00202 
00203 #endif
00204 

Generated at Mon Mar 12 02:59:46 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000