]> Creatis software - clitk.git/blob - itk/itkBinaryGuerreroFilter.h
added the new headers
[clitk.git] / itk / itkBinaryGuerreroFilter.h
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
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 copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18 #ifndef __itkBinaryGuerreroFilter_h
19 #define __itkBinaryGuerreroFilter_h
20 #include "itkBinaryFunctorImageFilter.h"
21 #include "itkNumericTraits.h"
22
23 #include <cmath>
24
25 namespace itk
26 {
27   
28 /** \class BinaryGuerreroFilter
29  * \brief  *
30  * The images to be added are set using the methods:
31  * SetInput1( image1 );
32  * SetInput2( image2 );
33  * 
34  * \warning No numeric overflow checking is performed in this filter.
35  *
36  * \ingroup IntensityImageFilters  Multithreaded
37  */
38 namespace Functor {  
39   
40 template< class TInput1, class TInput2=TInput1, class TOutput=TInput1>
41 class GuerreroFunctor
42 {
43     public:
44         GuerreroFunctor() : use_correct_formula(false)
45             {};
46         ~GuerreroFunctor() {};
47         bool operator!=( const GuerreroFunctor & ) const
48         {
49             return false;
50         }
51         bool operator==( const GuerreroFunctor & other ) const
52         {
53             return !(*this != other);
54         }
55         inline TOutput operator() ( const TInput1 & A, const TInput2 & B) const
56         {
57             //A is the reference image
58             TInput2 Bstar = B - 1000.*blood_mass_factor*(1+B/1000.);
59             TOutput vol_change;
60             if (use_correct_formula)
61                 vol_change=static_cast<TOutput>( (A-Bstar) / (1000.+Bstar) );
62             else //Use the original formula as described in Guerrero's paper
63                 vol_change=static_cast<TOutput>( 1000. * (Bstar-A) / (A*(1000.+Bstar)) );
64
65             if (IsNormal(vol_change))
66                 return vol_change;
67             else
68                 return 0.;
69         }
70         double blood_mass_factor;
71         bool use_correct_formula;
72 }; 
73
74 }
75
76 //==========================================================================
77 template <class TInputImage1, class TInputImage2=TInputImage1, class TOutputImage=TInputImage1>
78 class ITK_EXPORT BinaryGuerreroFilter :
79     public
80 BinaryFunctorImageFilter<TInputImage1,TInputImage2,TOutputImage, 
81                          Functor::GuerreroFunctor< 
82   typename TInputImage1::PixelType, 
83   typename TInputImage2::PixelType,
84   typename TOutputImage::PixelType>   >
85
86
87 {
88 public:
89   /** Standard class typedefs. */
90   typedef BinaryGuerreroFilter               Self;
91   typedef BinaryFunctorImageFilter<TInputImage1,TInputImage2,TOutputImage, 
92                                    Functor::GuerreroFunctor< 
93     typename TInputImage1::PixelType, 
94     typename TInputImage2::PixelType,
95     typename TOutputImage::PixelType> > Superclass;
96
97   typedef SmartPointer<Self>        Pointer;
98   typedef SmartPointer<const Self>  ConstPointer;
99
100   /** Method for creation through the object factory. */
101   itkNewMacro(Self);
102
103   /** Runtime information support. */
104   itkTypeMacro(BinaryGuerreroFilter, 
105                BinaryFunctorImageFilter);
106   void SetBloodCorrectionFactor(double f)
107   {
108       this->GetFunctor().blood_mass_factor=f;
109   }
110   void SetUseCorrectFormula(bool use_correct_formula)
111   {
112       this->GetFunctor().use_correct_formula=use_correct_formula;
113   }
114
115
116 protected:
117   BinaryGuerreroFilter() {}
118   virtual ~BinaryGuerreroFilter() {}
119
120 private:
121   BinaryGuerreroFilter(const Self&); //purposely not implemented
122   void operator=(const Self&); //purposely not implemented
123
124 };
125
126 } // end namespace itk
127
128
129 #endif