LogJacobianConstraint.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_LogJacobianConstraint_H
21 #define MIRTK_LogJacobianConstraint_H
22 
23 #include "mirtk/JacobianConstraint.h"
24 
25 
26 namespace mirtk {
27 
28 
29 class FreeFormTransformation;
30 
31 
32 /**
33  * Constrains log of Jacobian determinant of FFD parameterization
34  *
35  * This constraint is based on a penalty imposed by the squared logarithm of
36  * the Jacobian determinant. It strongly penalizes small and negative
37  * Jacobian determinant values, and slowly increases for large Jacobian
38  * determinant values. It therefore locally preserves volume because the
39  * penalty is zero only for a Jacobian determinant value of one.
40  * Volume increase is however less penalized than volume reduction.
41  *
42  * By default, the Jacobian determinant of the spline function is penalised
43  * by this class. For a classic FFD model parameterized by control point
44  * displacements, this is identical to the VolumePreservationConstraint.
45  * For a velocity based model, the Jacobian of the velocity field is constraint.
46  *
47  * Torsten Rohlfing and Calvin R. Maurer, Jr., Intensity-Based Non-rigid
48  * Registration Using Adaptive Multilevel Free-Form Deformation with an
49  * Incompressibility Constraint, MICCAI 2001.
50  *
51  * @sa VolumePreservationConstraint
52  */
54 {
55  mirtkEnergyTermMacro(LogJacobianConstraint, EM_SqLogDetJac);
56 
57  /// Small value below which Jacobian determinant is penalised linearly
58  /// with increasing smaller (i.e., negative) value
59  ///
60  /// The penalty implemented in IRTK can be used with _Epsilon set to a very
61  /// negative value, i.e., negative with great magnitude, -inf, or NaN.
62  mirtkPublicAttributeMacro(double, Epsilon);
63 
64 public:
65 
66  /// Constructor
67  LogJacobianConstraint(const char * = "", bool = true);
68 
69  /// Destructor
70  virtual ~LogJacobianConstraint();
71 
72 protected:
73 
74  /// Set parameter value from string
75  virtual bool SetWithPrefix(const char *, const char *);
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  // Penalty
90 
91 public:
92 
93  /// Evaluate penalty at control point location given Jacobian determinant value
94  virtual double Penalty(double det) const
95  {
96  if (det < _Epsilon) {
97  double l = log(_Epsilon);
98  double m = 2. * log(_Epsilon) / _Epsilon;
99  double t = l * l - m * _Epsilon;
100  return m * det + t;
101  } else {
102  double l = log(det);
103  return l * l;
104  }
105  }
106 
107  /// Evaluate penalty derivative at control point location w.r.t. Jacobian determinant value
108  virtual double DerivativeWrtJacobianDet(double det) const
109  {
110  if (det < _Epsilon) det = _Epsilon;
111  return 2. * log(det) / det;
112  }
113 
114 };
115 
116 
117 } // namespace mirtk
118 
119 #endif // MIRTK_LogJacobianConstraint_H
virtual double DerivativeWrtJacobianDet(double det) const
Evaluate penalty derivative at control point location w.r.t. Jacobian determinant value...
virtual ParameterList Parameter() const
Get parameter key/value as string map.
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.
virtual ~LogJacobianConstraint()
Destructor.
Definition: IOConfig.h:41
virtual ParameterList Parameter() const
Get parameter key/value as string map.
Squared logarithm of the Jacobian determinant.
virtual double Penalty(double det) const
Evaluate penalty at control point location given Jacobian determinant value.
LogJacobianConstraint(const char *="", bool=true)
Constructor.
virtual bool SetWithPrefix(const char *, const char *)
Set parameter value from string.