MeanSquaredDisplacementError.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2017 Imperial College London
5  * Copyright 2017 Andreas Schuh
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef MIRTK_MeanSquaredDisplacementError_H
21 #define MIRTK_MeanSquaredDisplacementError_H
22 
23 #include "mirtk/DataFidelity.h"
24 #include "mirtk/RegisteredImage.h"
25 
26 
27 namespace mirtk {
28 
29 
30 /**
31  * Constrains displacement of each target voxel to be close to another transformation
32  *
33  * This constraint can be used to enforce some consistency of the optimized
34  * displacements with a given mean or pre-composed target displacement.
35  * The constraint may be relaxed for voxels with a stronger misalignment.
36  */
38 {
39  mirtkEnergyTermMacro(DisplacementConstraint, EM_MeanSquaredDisplacementError);
40 
41  // ---------------------------------------------------------------------------
42  // Types
43 public:
44 
45  /// Type of non-parametric gradient components
46  typedef double GradientType;
47 
48  /// Type of non-parametric gradient image
50 
51  /// Type of cached displacement fields
53 
54  // ---------------------------------------------------------------------------
55  // Attributes
56 protected:
57 
58  /// Finite regular grid over which to integrate error
60 
61  /// Target transformation
62  mirtkPublicAggregateMacro(const class Transformation, TargetTransformation);
63 
64  /// Target displacements
65  mirtkAttributeMacro(DisplacementImageType, TargetDisplacement);
66 
67  /// Current displacements
68  ///
69  /// This displacement field is used only when the transformation requires
70  /// the caching of the entire dense displacements for efficienty reasons
71  /// such as the scaling and squaring of a SV FFD. When an externally
72  /// computed/updated displacement field is given, it is used instead.
73  mirtkAttributeMacro(DisplacementImageType, CurrentDisplacement);
74 
75  /// Pre-computed displacements which are updated by an external process
76  ///
77  /// When this displacement field is given, it is used instead of the
78  /// current transformation. The external process managing the optimization
79  /// has to ensure that the displacement field is updated whenever the
80  /// transformation changes.
81  mirtkPublicAggregateMacro(DisplacementImageType, ExternalDisplacement);
82 
83  /// Non-parametric gradient
84  mirtkAttributeMacro(GradientImageType, NonParametricGradient);
85 
86  // ---------------------------------------------------------------------------
87  // Construction/Destruction
88 public:
89 
90  /// Constructor
91  MeanSquaredDisplacementError(const char * = "", double = 1.);
92 
93  // ---------------------------------------------------------------------------
94  // Evaluation
95 
96  /// Initialize energy term once input and parameters have been set
97  virtual void Initialize();
98 
99  /// Update internal state after change of DoFs
100  ///
101  /// \param[in] gradient Whether to also update internal state for evaluation
102  /// of energy gradient. If \c false, only the internal state
103  /// required for the energy evaluation need to be updated.
104  virtual void Update(bool gradient = true);
105 
106 protected:
107 
108  /// Compute penalty for current transformation estimate
109  virtual double Evaluate();
110 
111  /// Compute gradient of penalty term w.r.t transformation parameters
112  virtual void EvaluateGradient(double *, double, double);
113 
114 };
115 
116 
117 } // namespace mirtk
118 
119 #endif // MIRTK_MeanSquaredDisplacementError_H
virtual void Initialize()
Initialize energy term once input and parameters have been set.
virtual void Update(bool gradient=true)
Mean squared deviation from given deformation.
double GradientType
Type of non-parametric gradient components.
mirtkPublicAggregateMacro(const class Transformation, TargetTransformation)
Target transformation.
Definition: IOConfig.h:41
virtual void EvaluateGradient(double *, double, double)
Compute gradient of penalty term w.r.t transformation parameters.
mirtkAttributeMacro(DisplacementImageType, TargetDisplacement)
Target displacements.
MeanSquaredDisplacementError(const char *="", double=1.)
Constructor.
RegisteredImage::DisplacementImageType DisplacementImageType
Type of cached displacement fields.
GenericImage< GradientType > GradientImageType
Type of non-parametric gradient image.
virtual double Evaluate()
Compute penalty for current transformation estimate.
mirtkPublicAttributeMacro(ImageAttributes, Domain)
Finite regular grid over which to integrate error.