SimilarityTransformation.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_SimilarityTransformation_H
21 #define MIRTK_SimilarityTransformation_H
22 
23 #include "mirtk/RigidTransformation.h"
24 
25 
26 namespace mirtk {
27 
28 
29 /**
30  * Class for similarity transformations.
31  *
32  * This class defines and implements similarity transformations. In addition to
33  * the rigid body transformation parameters, similarity transformations are
34  * parameterized by a global scaling parameter. The scaling parameter defines
35  * the scaling along all axis of the coordinate transformations.
36  */
38 {
39  mirtkTransformationMacro(SimilarityTransformation);
40 
41 protected:
42 
43  /// Update transformation matrix after change of parameter
44  virtual void UpdateMatrix();
45 
46  /// Update transformation parameters after change of matrix
47  virtual void UpdateDOFs();
48 
49  // ---------------------------------------------------------------------------
50  // Construction/Destruction
51 
52  /// Default constructor with given number of parameters
54 
55  /// Copy constructor with given number of parameters
57 
58  /// Copy constructor with given number of parameters
60 
61 public:
62 
63  /// Default constructor
65 
66  /// Copy constructor
68 
69  /// Copy constructor
71 
72  /// Destructor
73  virtual ~SimilarityTransformation();
74 
75  // ---------------------------------------------------------------------------
76  // Approximation
77 
78  /// Approximate displacements: This function takes a set of points and a set
79  /// of displacements and finds !new! parameters such that the resulting
80  /// transformation approximates the displacements as good as possible.
81  virtual void ApproximateDOFs(const double *, const double *, const double *, const double *,
82  const double *, const double *, const double *, int);
83 
84  // ---------------------------------------------------------------------------
85  // Transformation parameters
86 
87  /// Copy active transformation parameters (DoFs) from given
88  /// transformation if possible and return \c false, otherwise
89  virtual bool CopyFrom(const Transformation *);
90 
91  /// Puts scaling factor
92  virtual void PutScale(double);
93 
94  /// Gets scaling factor
95  virtual double GetScale() const;
96 
97  /// Construct a matrix based on parameters passed in the array
98  static Matrix DOFs2Matrix(const double *);
99 
100  // ---------------------------------------------------------------------------
101  // Derivatives
102 
103  // Do not overwrite other base class overloads
105 
106  /// Calculates the Jacobian of the transformation w.r.t the parameters
107  virtual void JacobianDOFs(double [3], int, double, double, double, double = 0, double = -1) const;
108 
109  /// Calculates the derivative of the Jacobian of the transformation (w.r.t. world coordinates) w.r.t. a transformation parameter
110  virtual void DeriveJacobianWrtDOF(Matrix &, int, double, double, double, double = 0, double = -1) const;
111 
112  // ---------------------------------------------------------------------------
113  // I/O
114 
115  // Do not hide methods of base class
118 
119  /// Prints the parameters of the transformation
120  virtual void Print(ostream &, Indent = 0) const;
121 
122  /// Whether this transformation can read a file of specified type (i.e. format)
123  virtual bool CanRead(TransformationType) const;
124 
125  /// Writes transformation to a file stream
126  virtual Cofstream &Write(Cofstream &) const;
127 
128 protected:
129 
130  /// Reads transformation from a file stream
132 
133 };
134 
135 ////////////////////////////////////////////////////////////////////////////////
136 // Inline definitions
137 ////////////////////////////////////////////////////////////////////////////////
138 
139 // =============================================================================
140 // Transformation parameters
141 // =============================================================================
142 
143 // -----------------------------------------------------------------------------
145 {
146  Put(SG, s);
147 }
148 
149 // -----------------------------------------------------------------------------
151 {
152  return Get(SG);
153 }
154 
155 
156 } // namespace mirtk
157 
158 #endif // MIRTK_SimilarityTransformation_H
virtual ~SimilarityTransformation()
Destructor.
virtual void Print(ostream &, Indent=0) const
Prints the parameters of the transformation.
virtual bool CopyFrom(const Transformation *)
virtual void DeriveJacobianWrtDOF(Matrix &, int, double, double, double, double=0, double=-1) const
Calculates the derivative of the Jacobian of the transformation (w.r.t. world coordinates) w...
virtual void JacobianDOFs(double [3], int, double, double, double, double=0, double=NaN) const
Calculates the Jacobian of the transformation w.r.t a transformation parameter.
virtual void Put(int, DOFValue)
Puts a transformation parameter.
virtual Cifstream & ReadDOFs(Cifstream &, TransformationType)
Reads transformation from a file stream.
virtual double GetScale() const
Gets scaling factor.
static Matrix DOFs2Matrix(const double *)
Construct a matrix based on parameters passed in the array.
virtual bool CanRead(TransformationType) const
Whether this transformation can read a file of specified type (i.e. format)
virtual void Write(const char *) const
Writes a transformation to a file.
virtual void PutScale(double)
Puts scaling factor.
Definition: IOConfig.h:41
virtual void JacobianDOFs(double [3], int, double, double, double, double=0, double=-1) const
Calculates the Jacobian of the transformation w.r.t the parameters.
virtual void UpdateMatrix()
Update transformation matrix after change of parameter.
virtual void Print(ostream &, Indent=0) const
Prints the parameters of the transformation.
virtual void ApproximateDOFs(const double *, const double *, const double *, const double *, const double *, const double *, const double *, int)
virtual void UpdateDOFs()
Update transformation parameters after change of matrix.
virtual Cofstream & Write(Cofstream &) const
Writes transformation to a file stream.
SimilarityTransformation()
Default constructor.
virtual double Get(int) const
Get value of transformation parameter.