LinearElasticityConstraint.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_LinearElasticityConstraint_H
21 #define MIRTK_LinearElasticityConstraint_H
22 
23 #include "mirtk/TransformationConstraint.h"
24 
25 
26 namespace mirtk {
27 
28 
29 /**
30  * Linear elasticity constraint
31  *
32  * \todo Generalize implementation and extend FreeFormTransformation API such that this
33  * constraint can be used with any deformable transformation model. The current
34  * implementation is specific to the 3D cubic B-spline FFD.
35  */
37 {
38  mirtkEnergyTermMacro(SmoothnessConstraint, EM_LinearElasticity);
39 
40  /// Whether to integrate linear elasticity energy over control point lattice only
41  mirtkPublicAttributeMacro(bool, Approximate);
42 
43  /// Whether to evaluate derivatives of smoothness term w.r.t. world coordinates.
44  ///
45  /// When \c false, the smoothness penalty is evaluated w.r.t the local lattice coordinates
46  mirtkPublicAttributeMacro(bool, WithRespectToWorld);
47 
48  /// Whether to use control point spacing when derivatives are computed w.r.t. world coordinates
49  mirtkPublicAttributeMacro(bool, UseLatticeSpacing);
50 
51  /// Whether to include rotation component (default: true)
52  mirtkPublicAttributeMacro(bool, ConstrainRotation);
53 
54  /// Lame's first parameter (default: 0)
55  ///
56  /// This parameter is multiplied with the constraint weight.
57  mirtkPublicAttributeMacro(double, Lambda);
58 
59  /// Lame's second parameter (default: 1)
60  ///
61  /// This parameter is multiplied with the constraint weight.
62  mirtkPublicAttributeMacro(double, Mu);
63 
64  /// Jacobian matrices of transformation
65  mirtkAttributeMacro(Array<Matrix>, Jacobian);
66 
67 public:
68 
69  /// Constructor
70  LinearElasticityConstraint(const char * = "", double = 1.);
71 
72  // ---------------------------------------------------------------------------
73  // Parameters
74 
75 protected:
76 
77  /// Set parameter value from string
78  virtual bool SetWithoutPrefix(const char *, const char *);
79 
80 public:
81 
82  // Import other overloads
84 
85  /// Get parameter key/value as string map
86  virtual ParameterList Parameter() const;
87 
88  // ---------------------------------------------------------------------------
89  // Evaluation
90 
91  /// Initialize energy term once input and parameters have been set
92  virtual void Initialize();
93 
94  /// Update internal state upon change of input
95  virtual void Update(bool = true);
96 
97 protected:
98 
99  /// Compute penalty for current transformation estimate
100  virtual double Evaluate();
101 
102  /// Compute gradient of penalty term w.r.t transformation parameters
103  virtual void EvaluateGradient(double *, double, double);
104 
105 public:
106 
107  // ---------------------------------------------------------------------------
108  // Debugging
109 
110  /// Write gradient of penalty term
111  virtual void WriteGradient(const char *, const char *) const;
112 
113 };
114 
115 
116 } // namespace mirtk
117 
118 #endif // MIRTK_LinearElasticityConstraint_H
virtual ParameterList Parameter() const
Get parameter key/value as string map.
virtual void Initialize()
Initialize energy term once input and parameters have been set.
virtual void WriteGradient(const char *, const char *) const
Write gradient of penalty term.
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
Definition: Object.h:38
virtual bool SetWithoutPrefix(const char *, const char *)
Set parameter value from string.
Definition: IOConfig.h:41
virtual void EvaluateGradient(double *, double, double)
Compute gradient of penalty term w.r.t transformation parameters.
virtual double Evaluate()
Compute penalty for current transformation estimate.
virtual void Update(bool=true)
Update internal state upon change of input.
virtual ParameterList Parameter() const
Get parameter name/value pairs.
Linear elastic energy.
LinearElasticityConstraint(const char *="", double=1.)
Constructor.