]> Creatis software - clitk.git/blob - itk/itkBinaryGuerreroFilter.h
again
[clitk.git] / itk / itkBinaryGuerreroFilter.h
1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Language:  C++
5
6   Copyright (c) Insight Software Consortium. All rights reserved.
7   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
8
9      This software is distributed WITHOUT ANY WARRANTY; without even 
10      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
11      PURPOSE.  See the above copyright notices for more information.
12
13 =========================================================================*/
14 #ifndef __itkBinaryGuerreroFilter_h
15 #define __itkBinaryGuerreroFilter_h
16
17 #include "itkBinaryFunctorImageFilter.h"
18 #include "itkNumericTraits.h"
19
20 #include <cmath>
21
22 namespace itk
23 {
24   
25 /** \class BinaryGuerreroFilter
26  * \brief  *
27  * The images to be added are set using the methods:
28  * SetInput1( image1 );
29  * SetInput2( image2 );
30  * 
31  * \warning No numeric overflow checking is performed in this filter.
32  *
33  * \ingroup IntensityImageFilters  Multithreaded
34  */
35 namespace Functor {  
36   
37 template< class TInput1, class TInput2=TInput1, class TOutput=TInput1>
38 class GuerreroFunctor
39 {
40     public:
41         GuerreroFunctor() : use_correct_formula(false)
42             {};
43         ~GuerreroFunctor() {};
44         bool operator!=( const GuerreroFunctor & ) const
45         {
46             return false;
47         }
48         bool operator==( const GuerreroFunctor & other ) const
49         {
50             return !(*this != other);
51         }
52         inline TOutput operator() ( const TInput1 & A, const TInput2 & B) const
53         {
54             //A is the reference image
55             TInput2 Bstar = B - 1000.*blood_mass_factor*(1+B/1000.);
56             TOutput vol_change;
57             if (use_correct_formula)
58                 vol_change=static_cast<TOutput>( (A-Bstar) / (1000.+Bstar) );
59             else //Use the original formula as described in Guerrero's paper
60                 vol_change=static_cast<TOutput>( 1000. * (Bstar-A) / (A*(1000.+Bstar)) );
61
62             if (std::isnormal(vol_change))
63                 return vol_change;
64             else
65                 return 0.;
66         }
67         double blood_mass_factor;
68         bool use_correct_formula;
69 }; 
70
71 }
72
73 //==========================================================================
74 template <class TInputImage1, class TInputImage2=TInputImage1, class TOutputImage=TInputImage1>
75 class ITK_EXPORT BinaryGuerreroFilter :
76     public
77 BinaryFunctorImageFilter<TInputImage1,TInputImage2,TOutputImage, 
78                          Functor::GuerreroFunctor< 
79   typename TInputImage1::PixelType, 
80   typename TInputImage2::PixelType,
81   typename TOutputImage::PixelType>   >
82
83
84 {
85 public:
86   /** Standard class typedefs. */
87   typedef BinaryGuerreroFilter               Self;
88   typedef BinaryFunctorImageFilter<TInputImage1,TInputImage2,TOutputImage, 
89                                    Functor::GuerreroFunctor< 
90     typename TInputImage1::PixelType, 
91     typename TInputImage2::PixelType,
92     typename TOutputImage::PixelType> > Superclass;
93
94   typedef SmartPointer<Self>        Pointer;
95   typedef SmartPointer<const Self>  ConstPointer;
96
97   /** Method for creation through the object factory. */
98   itkNewMacro(Self);
99
100   /** Runtime information support. */
101   itkTypeMacro(BinaryGuerreroFilter, 
102                BinaryFunctorImageFilter);
103   void SetBloodCorrectionFactor(double f)
104   {
105       this->GetFunctor().blood_mass_factor=f;
106   }
107   void SetUseCorrectFormula(bool use_correct_formula)
108   {
109       this->GetFunctor().use_correct_formula=use_correct_formula;
110   }
111
112
113 protected:
114   BinaryGuerreroFilter() {}
115   virtual ~BinaryGuerreroFilter() {}
116
117 private:
118   BinaryGuerreroFilter(const Self&); //purposely not implemented
119   void operator=(const Self&); //purposely not implemented
120
121 };
122
123 } // end namespace itk
124
125
126 #endif