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