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: 2007-09-16 14:41:02 $
00007   Version:   $Revision: 1.14 $
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 
00135   itkTypeMacro( SigmoidImageFilter, UnaryFunctorImageFilter );
00136 
00137   void SetAlpha( double alpha )
00138   {
00139     if( alpha == this->GetFunctor().GetAlpha() ) 
00140       {
00141       return;
00142       }
00143     this->GetFunctor().SetAlpha( alpha );
00144     this->Modified();
00145   }
00146 
00147   void SetBeta( double beta )
00148   {
00149     if( beta == this->GetFunctor().GetBeta() ) 
00150       {
00151       return;
00152       }
00153     this->GetFunctor().SetBeta( beta );
00154     this->Modified();
00155   }
00156 
00157   void SetOutputMinimum( OutputPixelType min )
00158   {
00159     if( min == this->GetFunctor().GetOutputMinimum() ) 
00160       {
00161       return;
00162       }
00163     this->GetFunctor().SetOutputMinimum( min );
00164     this->Modified();
00165   }
00166 
00167   void SetOutputMaximum( OutputPixelType max )
00168   {
00169     if( max == this->GetFunctor().GetOutputMaximum() ) 
00170       {
00171       return;
00172       }
00173     this->GetFunctor().SetOutputMaximum( max );
00174     this->Modified();
00175   }
00176 
00177 #ifdef ITK_USE_CONCEPT_CHECKING
00178 
00179   itkConceptMacro(InputConvertibleToDoubleCheck,
00180     (Concept::Convertible<typename TInputImage::PixelType, double>));
00181   itkConceptMacro(OutputAdditiveOperatorsCheck,
00182     (Concept::AdditiveOperators<OutputPixelType>));
00183   itkConceptMacro(DoubleConvertibleToOutputCheck,
00184     (Concept::Convertible<double, OutputPixelType>));
00185   itkConceptMacro(OutputTimesDoubleCheck,
00186     (Concept::MultiplyOperator<OutputPixelType, double>));
00187   itkConceptMacro(OutputDoubleAdditiveOperatorsCheck,
00188     (Concept::AdditiveOperators<OutputPixelType, OutputPixelType, double>));
00189 
00191 #endif
00192 
00193 protected:
00194   SigmoidImageFilter() {}
00195   virtual ~SigmoidImageFilter() {}
00196 
00197 private:
00198   SigmoidImageFilter(const Self&); //purposely not implemented
00199   void operator=(const Self&); //purposely not implemented
00200 
00201 };
00202 
00203 } // end namespace itk
00204 
00205 
00206 #endif
00207 

Generated at Mon Apr 14 14:24:45 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000