]> Creatis software - clitk.git/blob - registration/clitkOptNormalizedCorrelationImageToImageMetricFor3DBLUTFFD.h
min max (to remove)
[clitk.git] / registration / clitkOptNormalizedCorrelationImageToImageMetricFor3DBLUTFFD.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
19 #ifndef __clitkOptNormalizedCorrelationImageToImageMetricFor3DBLUTFFD_h
20 #define __clitkOptNormalizedCorrelationImageToImageMetricFor3DBLUTFFD_h
21
22 #include "itkOptImageToImageMetric.h"
23 #include "itkCovariantVector.h"
24 #include "itkPoint.h"
25 #include "itkIndex.h"
26
27 #include "itkMultiThreader.h"
28
29 namespace clitk
30 {
31
32 template <class TFixedImage,class TMovingImage >
33 class ITK_EXPORT NormalizedCorrelationImageToImageMetricFor3DBLUTFFD :
34   public itk::ImageToImageMetric< TFixedImage, TMovingImage >
35 {
36 public:
37
38   /** Standard class typedefs. */
39   typedef NormalizedCorrelationImageToImageMetricFor3DBLUTFFD                     Self;
40   typedef itk::ImageToImageMetric< TFixedImage, TMovingImage >   Superclass;
41   typedef itk::SmartPointer<Self>                                Pointer;
42   typedef itk::SmartPointer<const Self>                          ConstPointer;
43
44   /** Method for creation through the object factory. */
45   itkNewMacro(Self);
46
47   /** Run-time type information (and related methods). */
48   itkTypeMacro(NormalizedCorrelationImageToImageMetricFor3DBLUTFFD, ImageToImageMetric);
49
50   /** Types inherited from Superclass. */
51   typedef typename Superclass::RealType                 RealType;
52   typedef typename Superclass::TransformType            TransformType;
53   typedef typename Superclass::TransformPointer         TransformPointer;
54   typedef typename Superclass::TransformJacobianType    TransformJacobianType;
55   typedef typename Superclass::InterpolatorType         InterpolatorType;
56   typedef typename Superclass::MeasureType              MeasureType;
57   typedef typename Superclass::DerivativeType           DerivativeType;
58   typedef typename Superclass::ParametersType           ParametersType;
59   typedef typename Superclass::FixedImageType           FixedImageType;
60   typedef typename Superclass::MovingImageType          MovingImageType;
61   typedef typename Superclass::MovingImagePointType     MovingImagePointType;
62   typedef typename Superclass::FixedImageConstPointer   FixedImageConstPointer;
63   typedef typename Superclass::MovingImageConstPointer  MovingImageConstPointer;
64   typedef typename Superclass::CoordinateRepresentationType
65   CoordinateRepresentationType;
66   typedef typename Superclass::FixedImageSampleContainer
67   FixedImageSampleContainer;
68   typedef typename Superclass::ImageDerivativesType     ImageDerivativesType;
69   typedef typename Superclass::WeightsValueType         WeightsValueType;
70   typedef typename Superclass::IndexValueType           IndexValueType;
71
72   // Needed for evaluation of Jacobian.
73   typedef typename Superclass::FixedImagePointType     FixedImagePointType;
74
75   //Accumulators
76   typedef  typename itk::NumericTraits< MeasureType >::AccumulateType AccumulateType;
77
78   /** The moving image dimension. */
79   itkStaticConstMacro( MovingImageDimension, unsigned int,
80                        MovingImageType::ImageDimension );
81
82
83   /** Set/Get SubtractMean boolean. If true, the sample mean is subtracted
84    * from the sample values in the cross-correlation formula and
85    * typically results in narrower valleys in the cost fucntion.
86    * Default value is false. */
87   itkSetMacro( SubtractMean, bool );
88   itkGetConstReferenceMacro( SubtractMean, bool );
89   itkBooleanMacro( SubtractMean );
90
91   /**
92    *  Initialize the Metric by
93    *  (1) making sure that all the components are present and plugged
94    *      together correctly,
95    *  (2) uniformly select NumberOfSpatialSamples within
96    *      the FixedImageRegion, and
97    *  (3) allocate memory for pdf data structures. */
98   virtual void Initialize(void) throw ( itk::ExceptionObject );
99
100   /**  Get the value. */
101   MeasureType GetValue( const ParametersType & parameters ) const;
102
103   /** Get the derivatives of the match measure. */
104   void GetDerivative( const ParametersType & parameters,
105                       DerivativeType & Derivative ) const;
106
107   /**  Get the value and derivatives for single valued optimizers. */
108   void GetValueAndDerivative( const ParametersType & parameters,
109                               MeasureType & Value,
110                               DerivativeType & Derivative ) const;
111
112 protected:
113
114   NormalizedCorrelationImageToImageMetricFor3DBLUTFFD();
115   virtual ~NormalizedCorrelationImageToImageMetricFor3DBLUTFFD();
116   void PrintSelf(std::ostream& os, itk::Indent indent) const;
117
118 private:
119
120   //purposely not implemented
121   NormalizedCorrelationImageToImageMetricFor3DBLUTFFD(const Self &);
122   //purposely not implemented
123   void operator=(const Self &);
124
125   /**  Get the value for the derivative computation. */
126   MeasureType ComputeSums( const ParametersType & parameters ) const;
127
128
129   inline bool GetValueThreadProcessSample( unsigned int threadID,
130       unsigned long fixedImageSample,
131       const MovingImagePointType & mappedPoint,
132       double movingImageValue ) const;
133
134
135   inline bool GetValueAndDerivativeThreadProcessSample( unsigned int threadID,
136       unsigned long fixedImageSample,
137       const MovingImagePointType & mappedPoint,
138       double movingImageValue,
139       const ImageDerivativesType &
140       movingImageGradientValue ) const;
141
142   AccumulateType *m_ThreaderSFF, *m_ThreaderSMM, *m_ThreaderSFM, *m_ThreaderSF, *m_ThreaderSM;
143   mutable AccumulateType m_SFF, m_SMM, m_SFM, m_SF, m_SM;
144   mutable RealType m_Denom, m_FixedMean, m_MovingMean;
145   DerivativeType * m_ThreaderDerivativeF, *m_ThreaderDerivativeM;
146
147
148   bool m_SubtractMean;
149 };
150
151 } // end namespace clitk
152
153 #ifndef ITK_MANUAL_INSTANTIATION
154 #include "clitkOptNormalizedCorrelationImageToImageMetricFor3DBLUTFFD.txx"
155 #endif
156
157 #endif
158
159