DisplacementToVelocityFieldBCH.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_DisplacementToVelocityFieldBCH_H
21 #define MIRTK_DisplacementToVelocityFieldBCH_H
22 
23 #include "mirtk/GenericImage.h"
24 #include "mirtk/DisplacementToVelocityField.h"
25 #include "mirtk/VelocityToDisplacementField.h"
26 
27 
28 namespace mirtk {
29 
30 
31 /**
32  * Computes a stationary velocity field from a given displacement field.
33  *
34  * This class implements an image filter which computes the group logarithm
35  * of a (diffeomorphic) displacement field using the Baker-Campbell-Hausdorff (BCH)
36  * formula. The result is a stationary velocity field. Integrating this velocity
37  * field from 0 to _T, e.g., using N forward Euler integration steps or the
38  * scaling and squaring (SS) method, yields the original displacement field
39  * (with an approximation error).
40  *
41  * M. Bossa and S. Olmos, "A new algorithm for the computation of the group
42  * logarithm of diffeomorphisms", MFCA'08
43  */
44 template <class VoxelType>
46 {
47  mirtkObjectMacro(DisplacementToVelocityFieldBCH);
48 
49  // ---------------------------------------------------------------------------
50  // Types
51 public:
52 
53  /// Type of internal images
55 
56  /// Type of exponential filter
58 
59  // ---------------------------------------------------------------------------
60  // Attributes
61 private:
62 
63  /// Image filter for computation of exponential map of inverse velocities
64  mirtkReadOnlyAggregateMacro(ExponentialFilterType, ExponentialFilter);
65 
66  /// Whether exponential image filter was set by user
67  bool _CustomExponentialFilter;
68 
69  /// Number of update steps
70  mirtkPublicAttributeMacro(int, NumberOfIterations);
71 
72  /// Number of terms to use
73  mirtkPublicAttributeMacro(int, NumberOfTerms);
74 
75  /// Whether to use the Jacobian for the Lie bracket computation
76  mirtkPublicAttributeMacro(bool, UseJacobian);
77 
78  /// Whether to smooth the velocity fields to stabilize the computation
79  mirtkPublicAttributeMacro(bool, SmoothVelocities);
80 
81  /// Result of composition: exp(-v) ° phi
82  ImageType *_dv;
83 
84  /// Result of Lie bracket: [v, dv]
85  ImageType *_l1;
86 
87  /// Result of Lie bracket: [v, [v, dv]]
88  ImageType *_l2;
89 
90  /// Result of Lie bracket: [dv, [v, dv]]
91  ImageType *_l3;
92 
93  /// Result of Lie bracket: [dv, [v, [v, dv]]]
94  ImageType *_l4;
95 
96  // ---------------------------------------------------------------------------
97  // Construction/Destruction
98 public:
99 
100  /// Constructor
102 
103  /// Destructor
105 
106  // ---------------------------------------------------------------------------
107  // Setter/Getters
108 
109  /// Set image filter for computation of exponential map of inverse velocities
110  void ExponentialFilter(ExponentialFilterType *);
111 
112  /// Set upper integration limit of exponential filter
113  void UpperIntegrationLimit(double);
114 
115  /// Get upper integration limit of exponential filter
116  double UpperIntegrationLimit();
117 
118  /// Set number of integration steps
119  void NumberOfSteps(int);
120 
121  /// Get number of integration steps
122  int NumberOfSteps();
123 
124  // ---------------------------------------------------------------------------
125  // Execution
126 
127  /// Compute output = log(input)
128  virtual void Run();
129 
130 protected:
131 
132  /// Initialize filter
133  virtual void Initialize();
134 
135  /// Finalize filter
136  virtual void Finalize();
137 
138 };
139 
140 
141 } // namespace mirtk
142 
143 #endif // MIRTK_DisplacementToVelocityFieldBCH_H
double UpperIntegrationLimit()
Get upper integration limit of exponential filter.
virtual void Initialize()
Initialize filter.
virtual ~DisplacementToVelocityFieldBCH()
Destructor.
Definition: IOConfig.h:41
virtual void Finalize()
Finalize filter.
virtual void Run()
Compute output = log(input)
void ExponentialFilter(ExponentialFilterType *)
Set image filter for computation of exponential map of inverse velocities.
VelocityToDisplacementField< VoxelType > ExponentialFilterType
Type of exponential filter.
int NumberOfSteps()
Get number of integration steps.
GenericImage< VoxelType > ImageType
Type of internal images.