PartialMultiLevelStationaryVelocityTransformation.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_PartialMultiLevelStationaryVelocityTransformation_H
21 #define MIRTK_PartialMultiLevelStationaryVelocityTransformation_H
22 
23 #include "mirtk/MultiLevelTransformation.h"
24 #include "mirtk/MultiLevelStationaryVelocityTransformation.h"
25 
26 
27 namespace mirtk {
28 
29 
30 class MultiLevelStationaryVelocityTransformation;
31 
32 
33 /**
34  * Decorator for SV MFFD transformation.
35  *
36  * This decorator wraps a SV MFFD transformation but defines its own attributes
37  * regarding integration and whether or not to invert the transformation by
38  * default. As the SV MFFD is parameterized by a sum of stationary velocities,
39  * inverting the transformation is simply achieved by a negative upper
40  * integration limit.
41  */
43 {
44  mirtkTransformationMacro(PartialMultiLevelStationaryVelocityTransformation);
45 
46  // ---------------------------------------------------------------------------
47  // Attributes
48 
49  /// Pointer to decorated transformation
51 
52  /// Fraction of decorated transformation, negative value corresponds to inverse
53  mirtkPublicAttributeMacro(double, Fraction);
54 
55  // ---------------------------------------------------------------------------
56  // Construction/Destruction
57 
58 public:
59 
60  /// Constructor
62 
63  /// Copy constructor
65 
66  /// Destructor
68 
69  // ---------------------------------------------------------------------------
70  // Levels
71 
72  /// Returns the number of levels
73  int NumberOfLevels() const;
74 
75  /// Gets global transformation
77 
78  // Get global transformation
80 
81  /// Gets local transformation
83 
84  /// Gets local transformation
86 
87  /// Put local transformation and return pointer to previous one (needs to be deleted if not used)
89 
90  /// Push local transformation on stack (append transformation)
92 
93  /// Insert local transformation
94  void InsertLocalTransformation(FreeFormTransformation *, int = 0, bool = true);
95 
96  /// Pop local transformation from stack (remove last transformation)
98 
99  /// Remove local transformation and return the pointer (need to be deleted if not used)
101 
102  /// Combine local transformations on stack
103  virtual void CombineLocalTransformation();
104 
105  /// Convert the global transformation from a matrix representation to a
106  /// FFD and incorporate it with any existing local transformation
107  virtual void MergeGlobalIntoLocalDisplacement();
108 
109  // ---------------------------------------------------------------------------
110  // Transformation parameters (DoFs)
111 
112  /// Copy active transformation parameters (DoFs) from given
113  /// transformation if possible and return \c false, otherwise
114  virtual bool CopyFrom(const class Transformation *);
115 
116  /// Get number of transformation parameters
117  virtual int NumberOfDOFs() const;
118 
119  /// Put value of transformation parameter
120  virtual void Put(int, double);
121 
122  /// Put values of transformation parameters
123  virtual void Put(const DOFValue *);
124 
125  /// Add change to transformation parameters
126  virtual void Add(const DOFValue *);
127 
128  /// Update transformation parameters given parametric gradient
129  virtual double Update(const DOFValue *);
130 
131  /// Get value of transformation parameter
132  virtual double Get(int) const;
133 
134  /// Get values of transformation parameters
135  virtual void Get(DOFValue *) const;
136 
137  /// Put status of transformation parameter
138  virtual void PutStatus(int, DOFStatus);
139 
140  /// Get status of transformation parameter
141  virtual DOFStatus GetStatus(int) const;
142 
143  /// Checks whether transformation depends on the same vector of parameters
144  virtual bool HasSameDOFsAs(const class Transformation *) const;
145 
146  /// Checks whether the transformation is an identity mapping
147  virtual bool IsIdentity() const;
148 
149  // ---------------------------------------------------------------------------
150  // Parameters (non-DoFs)
151 
152  // Import other overloads
154 
155  /// Set named (non-DoF) parameter from value as string
156  virtual bool Set(const char *, const char *);
157 
158  /// Get (non-DoF) parameters as key/value as string map
159  virtual ParameterList Parameter() const;
160 
161  // ---------------------------------------------------------------------------
162  // Point transformation
169 
170  /// Whether the caching of the transformation displacements is required
171  /// (or preferred) by this transformation. For some transformations such as
172  /// those parameterized by velocities, caching of the displacements for
173  /// each target voxel results in better performance or is needed for example
174  /// for the scaling and squaring method.
175  virtual bool RequiresCachingOfDisplacements() const;
176 
177  /// Transforms a single point using the global transformation component only
178  virtual void GlobalTransform(double &, double &, double &, double = 0, double = NaN) const;
179 
180  /// Transforms a single point using the local transformation component only
181  virtual void LocalTransform(int, int, double &, double &, double &, double = 0, double = NaN) const;
182 
183  /// Transforms a single point
184  virtual void Transform(int, int, double &, double &, double &, double = 0, double = NaN) const;
185 
186  /// Transforms a single point using the inverse of the global transformation only
187  virtual void GlobalInverse(double &, double &, double &, double = 0, double = NaN) const;
188 
189  /// Transforms a single point using the inverse of the local transformation only
190  virtual bool LocalInverse(int, int, double &, double &, double &, double = 0, double = NaN) const;
191 
192  /// Transforms a single point using the inverse of the transformation
193  virtual bool Inverse(int, int, double &, double &, double &, double = 0, double = NaN) const;
194 
195  /// Calculates the displacement vectors for a whole image domain
196  ///
197  /// \attention The displacements are computed at the positions after applying the
198  /// current displacements at each voxel. These displacements are then
199  /// added to the current displacements. Therefore, set the input
200  /// displacements to zero if only interested in the displacements of
201  /// this transformation at the voxel positions.
202  virtual void Displacement(int, int, GenericImage<double> &, double, double = 1, const WorldCoordsImage * = NULL) const;
203 
204  /// Calculates the displacement vectors for a whole image domain
205  ///
206  /// \attention The displacements are computed at the positions after applying the
207  /// current displacements at each voxel. These displacements are then
208  /// added to the current displacements. Therefore, set the input
209  /// displacements to zero if only interested in the displacements of
210  /// this transformation at the voxel positions.
211  virtual void Displacement(int, int, GenericImage<float> &, double, double = 1, const WorldCoordsImage * = NULL) const;
212 
213  /// Calculates the inverse displacement vectors for a whole image domain
214  ///
215  /// \attention The displacements are computed at the positions after applying the
216  /// current displacements at each voxel. These displacements are then
217  /// added to the current displacements. Therefore, set the input
218  /// displacements to zero if only interested in the displacements of
219  /// this transformation at the voxel positions.
220  ///
221  /// \returns Always zero.
222  virtual int InverseDisplacement(int, int, GenericImage<double> &, double, double = 1, const WorldCoordsImage * = NULL) const;
223 
224  /// Calculates the inverse displacement vectors for a whole image domain
225  ///
226  /// \attention The displacements are computed at the positions after applying the
227  /// current displacements at each voxel. These displacements are then
228  /// added to the current displacements. Therefore, set the input
229  /// displacements to zero if only interested in the displacements of
230  /// this transformation at the voxel positions.
231  ///
232  /// \returns Always zero.
233  virtual int InverseDisplacement(int, int, GenericImage<float> &, double, double = 1, const WorldCoordsImage * = NULL) const;
234 
235  // ---------------------------------------------------------------------------
236  // Derivatives
238 
239  /// Applies the chain rule to convert spatial non-parametric gradient
240  /// to a gradient w.r.t the parameters of this transformation.
241  virtual void ParametricGradient(const GenericImage<double> *, double *,
242  const WorldCoordsImage *,
243  const WorldCoordsImage *,
244  double = NaN, double = 1) const;
245 
246 
247  /// Applies the chain rule to convert spatial non-parametric gradient
248  /// to a gradient w.r.t the parameters of this transformation.
249  virtual void ParametricGradient(const GenericImage<double> **, int, double *,
250  const WorldCoordsImage *,
251  const WorldCoordsImage *,
252  const double * = NULL, double = 1) const;
253 
254  // ---------------------------------------------------------------------------
255  // I/O
256 
257  // Do not hide methods of base class
261 
262  /// Prints information about the transformation
263  virtual void Print(ostream &, Indent = 0) const;
264 
265  /// Reads a transformation from a file stream
266  virtual Cifstream &Read(Cifstream &);
267 
268  /// Writes a transformation to a file stream
269  virtual Cofstream &Write(Cofstream &) const;
270 
271 };
272 
273 
274 } // namespace mirtk
275 
276 #endif // MIRTK_PartialMultiLevelStationaryVelocityTransformation_H
virtual void CombineLocalTransformation()
Combine local transformations on stack.
virtual ParameterList Parameter() const
Get (non-DoF) parameters as key/value as string map.
virtual void Displacement(int, int, double &, double &, double &, double=0, double=NaN) const
Calculates the displacement of a single point.
virtual bool HasSameDOFsAs(const class Transformation *) const
Checks whether transformation depends on the same vector of parameters.
virtual void Transform(int, int, double &, double &, double &, double=0, double=NaN) const
Transforms a single point.
virtual void Put(int, double)
Put value of transformation parameter.
virtual bool Inverse(int, int, double &, double &, double &, double=0, double=NaN) const
Transforms a single point using the inverse of the transformation.
double DOFValue
Type of transformation parameter value.
FreeFormTransformation * PutLocalTransformation(FreeFormTransformation *, int, bool=true)
Put local transformation and return pointer to previous one (needs to be deleted if not used) ...
virtual void PutStatus(int, DOFStatus)
Put status of transformation parameter.
virtual bool CopyFrom(const class Transformation *)
virtual bool LocalInverse(int, int, double &, double &, double &, double=0, double=NaN) const
Transforms a single point using the inverse of the local transformation only.
virtual ParameterList Parameter() const
Get (non-DoF) parameters as key/value as string map.
virtual bool InverseDisplacement(int, int, double &, double &, double &, double=0, double=NaN) const
Calculates the displacement of a single point using the inverse of the transformation.
virtual double Update(const DOFValue *)
Update transformation parameters given parametric gradient.
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
Definition: Object.h:38
void InsertLocalTransformation(FreeFormTransformation *, int=0, bool=true)
Insert local transformation.
virtual Cifstream & Read(Cifstream &)
Reads a transformation from a file stream.
FreeFormTransformation * PopLocalTransformation()
Pop local transformation from stack (remove last transformation)
virtual Cofstream & Write(Cofstream &) const
Writes a transformation to a file stream.
int NumberOfLevels() const
Returns the number of levels.
virtual void Write(const char *) const
Writes a transformation to a file.
Status
Enumeration of common states for entities such as objective function parameters.
Definition: Status.h:28
Definition: IOConfig.h:41
virtual void Add(const DOFValue *)
Add change to transformation parameters.
virtual bool IsIdentity() const
Checks whether the transformation is an identity mapping.
virtual DOFStatus GetStatus(int) const
Get status of transformation parameter.
void PushLocalTransformation(FreeFormTransformation *, bool=true)
Push local transformation on stack (append transformation)
virtual void ParametricGradient(const GenericImage< double > *, double *, const WorldCoordsImage *, const WorldCoordsImage *, double=NaN, double=1) const
virtual void Print(ostream &, Indent=0) const
Prints the parameters of the transformation.
AffineTransformation * GetGlobalTransformation()
Gets global transformation.
FreeFormTransformation * RemoveLocalTransformation(int=0)
Remove local transformation and return the pointer (need to be deleted if not used) ...
virtual int InverseDisplacement(int, int, GenericImage< double > &, double, double=1, const WorldCoordsImage *=NULL) const
virtual bool LocalInverse(int, int, double &, double &, double &, double=0, double=NaN) const
Transforms a single point using the inverse of the local transformation only.
virtual double Get(int) const
Get value of transformation parameter.
virtual int NumberOfDOFs() const
Get number of transformation parameters.
virtual void Read(const char *)
Reads a transformation from a file.
virtual void GlobalTransform(double &, double &, double &, double=0, double=NaN) const
Transforms a single point using the global transformation component only.
virtual void Displacement(int, int, GenericImage< double > &, double, double=1, const WorldCoordsImage *=NULL) const
FreeFormTransformation * GetLocalTransformation(int)
Gets local transformation.
virtual bool Inverse(int, int, double &, double &, double &, double=0, double=NaN) const
Transforms a single point using the inverse of the transformation.
virtual void GlobalInverse(double &, double &, double &, double=0, double=NaN) const
Transforms a single point using the inverse of the global transformation only.
virtual void LocalTransform(int, int, double &, double &, double &, double=0, double=NaN) const
Transforms a single point using the local transformation component only.
PartialMultiLevelStationaryVelocityTransformation(MultiLevelStationaryVelocityTransformation *=NULL, double=1.0)
Constructor.
virtual void Transform(int, int, double &, double &, double &, double=0, double=NaN) const =0
Transforms a single point.
virtual ~PartialMultiLevelStationaryVelocityTransformation()
Destructor.
virtual void Print(ostream &, Indent=0) const
Prints information about the transformation.
virtual bool Set(const char *, const char *)
Set named (non-DoF) parameter from value as string.
virtual void LocalTransform(int, int, double &, double &, double &, double=0, double=NaN) const
Transforms a single point using the local transformation component only.
virtual void ParametricGradient(const GenericImage< double > *, double *, const WorldCoordsImage *, const WorldCoordsImage *, double=NaN, double=1) const