InternalForce.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2015 Imperial College London
5  * Copyright 2013-2015 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_InternalForce_H
21 #define MIRTK_InternalForce_H
22 
23 #include "mirtk/PointSetForce.h"
24 #include "mirtk/InternalForceTerm.h"
25 
26 
27 namespace mirtk {
28 
29 
30 /**
31  * Base class for a penalty term imposed on a transformed point set
32  *
33  * Subclasses represent in particular internal forces on deformable simplicial
34  * complexes such as elasticity, strain, curvature, non-self-intersection (i.e.
35  * triangle repulsion), and node repulsion.
36  *
37  * The penalty is minimized by the registration using an instance of
38  * RegistrationEnergy with set data similarity and regularization terms.
39  * Higher penalties lead to stronger enforcement of the constraint.
40  *
41  * The same force terms can be used in a "non-parametric" DeformableSurfaceModel
42  * as internal force terms to regularize the evolution of the surface model.
43  */
45 {
46  mirtkAbstractMacro(InternalForce);
47 
48  // ---------------------------------------------------------------------------
49  // Attributes
50 
51  /// Name of point data array with external force magnitude
52  ///
53  /// When specified, the force vectors of the internal force should be
54  /// multiplied by the absolute value of the external force magnitude.
55  /// The internal force is therefore proportional to the external force
56  /// and vanishes at the same time as the external force.
57  ///
58  /// The deformable model has to ensure that the external forces are updated
59  /// before the internal forces such that the magnitude array is up-to-date.
60  mirtkPublicAttributeMacro(string, ExternalMagnitudeArrayName);
61 
62  /// Weight of this internal force when "inside" the object,
63  /// i.e., when the external force magnitude is negative.
64  /// The force _Weight is multiplied by this positive weight.
65  mirtkPublicAttributeMacro(double, WeightInside);
66 
67  /// Weight of this internal force when "outside" the object,
68  /// i.e., when the external force magnitude is positive.
69  /// The force _Weight is multiplied by this positive weight.
70  mirtkPublicAttributeMacro(double, WeightOutside);
71 
72  /// Minimum weight of this internal force when external force magnitude
73  /// is applied to scale the force. It can be used to preserve some internal
74  /// force even when the external force vanishes.
75  mirtkPublicAttributeMacro(double, WeightMinimum);
76 
77  /// Copy attributes of this class from another instance
78  void CopyAttributes(const InternalForce &);
79 
80  // ---------------------------------------------------------------------------
81  // Construction/Destruction
82 
83 protected:
84 
85  /// Constructor
86  InternalForce(const char * = "", double = 1.0);
87 
88  /// Copy constructor
90 
91  /// Assignment operator
93 
94 public:
95 
96  /// Instantiate new constraint representing specified internal forces
97  static InternalForce *New(InternalForceTerm, const char * = "", double = 1.0);
98 
99  /// Destructor
100  virtual ~InternalForce();
101 
102  // ---------------------------------------------------------------------------
103  // Configuration
104 
105 protected:
106 
107  /// Set parameter value from string
108  virtual bool SetWithoutPrefix(const char *, const char *);
109 
110 public:
111 
112  // Import other overloads
114 
115  /// Get parameter key/value as string map
116  virtual ParameterList Parameter() const;
117 
118  // ---------------------------------------------------------------------------
119  // Auxiliaries
120 
121 protected:
122 
123  /// Get magnitude array of external force term
124  vtkDataArray *ExternalMagnitude() const;
125 
126  // ---------------------------------------------------------------------------
127  // Evaluation
128 
129 protected:
130 
131  /// Evaluate gradient of force term
132  ///
133  /// \param[in,out] gradient Gradient to which the computed gradient of the
134  /// force term is added after multiplying by \p weight.
135  /// \param[in] step Step length for finite differences (unused).
136  /// \param[in] weight Weight of force term.
137  virtual void EvaluateGradient(double *gradient, double step, double weight);
138 
139 };
140 
141 
142 } // namespace mirtk
143 
144 #endif // MIRTK_InternalForce_H
virtual bool SetWithoutPrefix(const char *, const char *)
Set parameter value from string.
vtkDataArray * ExternalMagnitude() const
Get magnitude array of external force term.
InternalForce(const char *="", double=1.0)
Constructor.
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
Definition: Object.h:38
virtual ~InternalForce()
Destructor.
virtual ParameterList Parameter() const
Get parameter key/value as string map.
Definition: IOConfig.h:41
virtual void EvaluateGradient(double *gradient, double step, double weight)
static InternalForce * New(InternalForceTerm, const char *="", double=1.0)
Instantiate new constraint representing specified internal forces.
virtual ParameterList Parameter() const
Get parameter key/value as string map.
InternalForce & operator=(const InternalForce &)
Assignment operator.