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