SmoothnessConstraint.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2017 Imperial College London
5  * Copyright 2013-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_SmoothnessConstraint_H
21 #define MIRTK_SmoothnessConstraint_H
22 
23 #include "mirtk/TransformationConstraint.h"
24 
25 
26 namespace mirtk {
27 
28 
29 /**
30  * Smoothness term based on bending energy of transformation
31  *
32  * Daniel Rueckert et al., Nonrigid registration using free-form deformations:
33  * Application to breast MR images, IEEE Transactions on Medical Imaging, 18(8),
34  * 712–21 (1999; doi:10.1109/42.796284)
35  */
37 {
38  mirtkEnergyTermMacro(SmoothnessConstraint, EM_BendingEnergy);
39 
40  /// Whether to evaluate derivatives of smoothness term w.r.t. world coordinates.
41  ///
42  /// When \c false, the smoothness penalty is evaluated w.r.t the local lattice coordinates
43  mirtkPublicAttributeMacro(bool, WithRespectToWorld);
44 
45  /// Whether to use control point spacing when derivatives are computed w.r.t. world coordinates
46  mirtkPublicAttributeMacro(bool, UseLatticeSpacing);
47 
48  /// Smoothness penalty annealing rate.
49  /// Used in conjuction with RobustPointMatch.
50  ///
51  /// \attention The use of this option is experimental and it may be removed.
52  mirtkPublicAttributeMacro(double, AnnealingRate);
53 
54  /// Current additional weight factor due to annealing process
55  double _AnnealingWeight;
56 
57 public:
58 
59  /// Constructor
60  SmoothnessConstraint(const char * = "", double = 1.0);
61 
62  // ---------------------------------------------------------------------------
63  // Parameters
64 
65 protected:
66 
67  /// Set parameter value from string
68  virtual bool SetWithoutPrefix(const char *, const char *);
69 
70 public:
71 
72  // Import other overloads
74 
75  /// Get parameter key/value as string map
76  virtual ParameterList Parameter() const;
77 
78  // ---------------------------------------------------------------------------
79  // Evaluation
80 
81  /// Initialize energy term once input and parameters have been set
82  virtual void Initialize();
83 
84  /// Update energy term after convergence
85  virtual bool Upgrade();
86 
87 protected:
88 
89  /// Compute penalty for current transformation estimate
90  virtual double Evaluate();
91 
92  /// Compute gradient of penalty term w.r.t transformation parameters
93  virtual void EvaluateGradient(double *, double, double);
94 
95 public:
96 
97  // ---------------------------------------------------------------------------
98  // Debugging
99 
100  /// Write gradient of penalty term
101  virtual void WriteGradient(const char *, const char *) const;
102 
103 };
104 
105 
106 } // namespace mirtk
107 
108 #endif // MIRTK_SmoothnessConstraint_H
virtual ParameterList Parameter() const
Get parameter key/value as string map.
virtual double Evaluate()
Compute penalty for current transformation estimate.
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
Definition: Object.h:38
virtual void EvaluateGradient(double *, double, double)
Compute gradient of penalty term w.r.t transformation parameters.
virtual bool Upgrade()
Update energy term after convergence.
Definition: IOConfig.h:41
SmoothnessConstraint(const char *="", double=1.0)
Constructor.
Thin-plate spline bending energy.
virtual void Initialize()
Initialize energy term once input and parameters have been set.
virtual ParameterList Parameter() const
Get parameter name/value pairs.
virtual void WriteGradient(const char *, const char *) const
Write gradient of penalty term.
virtual bool SetWithoutPrefix(const char *, const char *)
Set parameter value from string.