EulerMethod.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_EulerMethod_H
21 #define MIRTK_EulerMethod_H
22 
23 #include "mirtk/LocalOptimizer.h"
24 
25 #include "vtkSmartPointer.h"
26 #include "vtkDataArray.h"
27 
28 
29 namespace mirtk {
30 
31 
32 class DeformableSurfaceModel;
33 
34 
35 /**
36  * Minimizes deformable surface model using Euler's method
37  */
39 {
40  mirtkOptimizerMacro(EulerMethod, OM_EulerMethod);
41 
42  // ---------------------------------------------------------------------------
43  // Attributes
44 
45  /// Deformable surface model
46  mirtkReadOnlyAggregateMacro(DeformableSurfaceModel, Model);
47 
48  /// Length of each integration step (\f$\delta t\f$)
49  ///
50  /// When _NormalizeStepLength is \c true, the step length is divided by the
51  /// maximum magnitude of the computed node forces at a given iteration.
52  /// Otherwise it is divided by the number of deformable surface points to
53  /// remove the normalization of the gradient of the deformable surface terms
54  /// and the resulting node forces are multplied by the unnormalized step length.
55  /// Use _MaximumDisplacement in this case to limit the maximum allowed
56  /// displacement of each node in this case.
57  mirtkPublicAttributeMacro(double, StepLength);
58 
59  /// Whether to normalize the step length using the magnitude of the maximum force
60  mirtkPublicAttributeMacro(bool, NormalizeStepLength);
61 
62  /// Maximum node displacement
63  ///
64  /// Maximum allowed magnitude of a node displacement, i.e., node force times
65  /// current time step. When _NormalizeStepLength is \c true (default), the
66  /// maximum displacement is naturally limited to 1 [mm]. When set to a value
67  /// less than one in this case, the node displacements are further restricted.
68  /// This parameter is in particular useful to limit the maximum node displacement
69  /// when _NormalizeStepLength is \c false. The default value is 1 [mm].
70  mirtkPublicAttributeMacro(double, MaximumDisplacement);
71 
72  /// Point data array of current node displacement
73  mirtkPublicAttributeMacro(vtkSmartPointer<vtkDataArray>, Displacement);
74 
75  /// Point data array used to track node displacement in normal direction (optional)
76  mirtkPublicAttributeMacro(vtkSmartPointer<vtkDataArray>, NormalDisplacement);
77 
78  /// Current negated force acting on each node
79  mirtkReadOnlyComponentMacro(double, Gradient);
80 
81  /// Last maximum node displacement
82  mirtkReadOnlyAttributeMacro(double, LastDelta);
83 
84 private:
85 
86  /// Size of allocated vectors, may be larger than actual number of model DoFs!
87  int _NumberOfDOFs;
88 
89  /// Copy attributes of this class from another instance
90  void CopyAttributes(const EulerMethod &);
91 
92  // ---------------------------------------------------------------------------
93  // Construction/Destruction
94 public:
95 
96  /// Constructor
98 
99  /// Copy constructor
100  EulerMethod(const EulerMethod &);
101 
102  /// Assignment operator
104 
105  /// Destructor
106  virtual ~EulerMethod();
107 
108  // ---------------------------------------------------------------------------
109  // Parameters
111 
112  /// Set parameter value from string
113  virtual bool Set(const char *, const char *);
114 
115  /// Get parameters as key/value as string map
116  virtual ParameterList Parameter() const;
117 
118  // ---------------------------------------------------------------------------
119  // Execution
120 
121  /// Initialize optimization
122  ///
123  /// This member funtion is implicitly called by Run.
124  virtual void Initialize();
125 
126  /// Integrate deformable surface model
127  virtual double Run();
128 
129 protected:
130 
131  /// Perform local adaptive remeshing (optional)
132  virtual bool RemeshModel();
133 
134  /// Get node force normalization factor
135  virtual double GradientNorm() const;
136 
137  /// Update node displacements
138  virtual void UpdateDisplacement();
139 
140  /// Truncate magnitude of node displacements to the range [0, max]
141  ///
142  /// \param[in] force Force truncation of displacements. If \c false, the
143  /// function does nothing if the step length was normalized
144  /// and the maximum displacement is greater or equal one.
145  virtual void TruncateDisplacement(bool force = false);
146 
147  /// Update recorded node displacement in normal direction
148  virtual void UpdateNormalDisplacement();
149 
150  /// Finalize optimization
151  virtual void Finalize();
152 
153 };
154 
155 
156 } // namespace mirtk
157 
158 #endif // MIRTK_EulerMethod_H
virtual void Initialize()
EulerMethod & operator=(const EulerMethod &)
Assignment operator.
virtual double Run()
Integrate deformable surface model.
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
Definition: Object.h:38
virtual ParameterList Parameter() const
Get parameters as key/value as string map.
Definition: IOConfig.h:41
virtual bool Set(const char *, const char *)
Set parameter value from string.
Explicit Euler method for deformable surface models.
virtual void Finalize()
Finalize optimization.
virtual void TruncateDisplacement(bool force=false)
virtual ~EulerMethod()
Destructor.
virtual ParameterList Parameter() const
Get parameters as key/value as string map.
virtual void UpdateDisplacement()
Update node displacements.
EulerMethod(ObjectiveFunction *=NULL)
Constructor.
virtual double GradientNorm() const
Get node force normalization factor.
virtual bool RemeshModel()
Perform local adaptive remeshing (optional)
virtual void UpdateNormalDisplacement()
Update recorded node displacement in normal direction.