NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
itkAffineTransform2D3D.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  NifTK: A software platform for medical image computing.
4 
5  Copyright (c) University College London (UCL). All rights reserved.
6 
7  This software is distributed WITHOUT ANY WARRANTY; without even
8  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9  PURPOSE.
10 
11  See LICENSE.txt in the top level directory for details.
12 
13 =============================================================================*/
14 
15 #ifndef itkAffineTransform2D3D_h
16 #define itkAffineTransform2D3D_h
17 
18 #include <iostream>
19 
20 #include <itkMatrix.h>
21 #include <itkMatrixOffsetTransformBase.h>
22 #include <itkExceptionObject.h>
23 #include <itkMacro.h>
24 
25 namespace itk
26 {
27 
28 template <
29  class TScalarType=double, // Data type for scalars
30  // (e.g. float or double)
31  unsigned int NDimensions=3> // Number of dimensions in the input space
32 class ITK_EXPORT AffineTransform2D3D
33 : public MatrixOffsetTransformBase< TScalarType, NDimensions, NDimensions >
34 {
35 public:
38  typedef MatrixOffsetTransformBase< TScalarType,
39  NDimensions,
40  NDimensions > Superclass;
41  typedef SmartPointer<Self> Pointer;
42  typedef SmartPointer<const Self> ConstPointer;
43 
45  itkTypeMacro( AffineTransform2D3D, MatrixOffsetTransformBase );
46 
48  itkNewMacro( Self );
49 
51  itkStaticConstMacro(InputSpaceDimension, unsigned int, NDimensions);
52  itkStaticConstMacro(OutputSpaceDimension, unsigned int, NDimensions);
53  itkStaticConstMacro(SpaceDimension, unsigned int, NDimensions);
54  itkStaticConstMacro(ParametersDimension, unsigned int,
55  NDimensions*(NDimensions+1));
56 
57 
59  typedef typename Superclass::ParametersType ParametersType;
61  typedef typename Superclass::ScalarType ScalarType;
64  typedef typename Superclass::InputVectorType InputVectorType;
65  typedef typename Superclass::OutputVectorType OutputVectorType;
66  typedef typename Superclass::InputVnlVectorType InputVnlVectorType;
67  typedef typename Superclass::OutputVnlVectorType OutputVnlVectorType;
68  typedef typename Superclass::InputCovariantVectorType
70  typedef typename Superclass::OutputCovariantVectorType
73  typedef typename Superclass::InverseMatrixType InverseMatrixType;
74  typedef typename Superclass::CenterType CenterType;
75  typedef typename Superclass::OffsetType OffsetType;
77 
80  typedef typename Superclass::InverseTransformBaseType InverseTransformBaseType;
81  typedef typename InverseTransformBaseType::Pointer InverseTransformBasePointer;
82 
84  virtual void SetParameters( const ParametersType & parameters );
85 
87  virtual const ParametersType& GetParameters(void) const;
88 
89  void Translate(const OutputVectorType &trans);
90 
91  void Scale(const OutputVectorType &factor);
92 
93  void Rotate(const OutputVectorType &angle);
94 
95  void Shear(const OutputVectorType &coef);
96 
98  bool GetInverse(Self* inverse) const;
99 
101  virtual InverseTransformBasePointer GetInverseTransform() const;
102 
111  inline InputPointType BackTransform(const OutputPointType &point ) const;
112  inline InputVectorType BackTransform(const OutputVectorType &vector) const;
113  inline InputVnlVectorType BackTransform(
114  const OutputVnlVectorType &vector) const;
115  inline InputCovariantVectorType BackTransform(
116  const OutputCovariantVectorType &vector) const;
117 
127  inline InputPointType BackTransformPoint(const OutputPointType &point) const;
128 
140  ScalarType Metric(const Self * other) const;
141 
145  ScalarType Metric(void) const;
146 
147 protected:
155  AffineTransform2D3D(const MatrixType &matrix,
156  const OutputVectorType &offset);
157  AffineTransform2D3D(unsigned int outputDims,
158  unsigned int paramDims);
160 
161  // implementation of the method in the parent class
162  virtual void ComputeMatrixParameters(void);
163 
164  // implementation of the method in the parent class
165  virtual void ComputeMatrix(void);
166 
168  virtual ~AffineTransform2D3D();
169 
171  void PrintSelf(std::ostream &s, Indent indent) const;
172 
173  Matrix<TScalarType,NDimensions+1,NDimensions+1> m_Rotations;
174  Matrix<TScalarType,NDimensions+1,NDimensions+1> m_Scales;
175  Matrix<TScalarType,NDimensions+1,NDimensions+1> m_Shears;
176  Matrix<TScalarType,NDimensions+1,NDimensions+1> m_Translations;
177  Matrix<TScalarType,NDimensions+1,NDimensions+1> m_TranslateToCentre;
178  Matrix<TScalarType,NDimensions+1,NDimensions+1> m_BackTranslateCentre;
179 
180 private:
181 
182  AffineTransform2D3D(const Self & other);
183  const Self & operator=( const Self & );
184 
185 }; //class AffineTransform
186 
188 template<class TScalarType, unsigned int NDimensions>
189 inline
192 BackTransform(const OutputVectorType &vect ) const
193 {
194  return this->GetInverseMatrix() * vect;
195 }
196 
197 
199 template<class TScalarType, unsigned int NDimensions>
200 inline
203 BackTransform(const OutputVnlVectorType &vect ) const
204 {
205  return this->GetInverseMatrix() * vect;
206 }
207 
208 
210 template<class TScalarType, unsigned int NDimensions>
211 inline
215 {
216  InputCovariantVectorType result; // Converted vector
217 
218  for (unsigned int i = 0; i < NDimensions; i++)
219  {
220  result[i] = NumericTraits<ScalarType>::Zero;
221  for (unsigned int j = 0; j < NDimensions; j++)
222  {
223  result[i] += this->GetMatrix()[j][i]*vec[j]; // Direct matrix transposed
224  }
225  }
226  return result;
227 }
228 
229 
231 template<class TScalarType, unsigned int NDimensions>
232 inline
236 {
237  return this->BackTransform(point);
238 }
239 
241 template<class TScalarType, unsigned int NDimensions>
242 inline
245 BackTransform(const OutputPointType &point) const
246 {
247  InputPointType result; // Converted point
248  ScalarType temp[NDimensions];
249  unsigned int i, j;
250 
251  for (j = 0; j < NDimensions; j++)
252  {
253  temp[j] = point[j] - this->GetOffset()[j];
254  }
255 
256  for (i = 0; i < NDimensions; i++)
257  {
258  result[i] = 0.0;
259  for (j = 0; j < NDimensions; j++)
260  {
261  result[i] += this->GetInverseMatrix()[i][j]*temp[j];
262  }
263  }
264  return result;
265 }
266 
267 } // namespace itk
268 
269 // Define instantiation macro for this template.
270 #define ITK_TEMPLATE_AffineTransform2D3D(_, EXPORT, x, y) namespace itk { \
271  _(2(class EXPORT AffineTransform2D3D< ITK_TEMPLATE_2 x >)) \
272  namespace Templates { typedef AffineTransform2D3D< ITK_TEMPLATE_2 x > \
273  AffineTransform2D3D##y; } \
274  }
275 
276 #if ITK_TEMPLATE_EXPLICIT
277 # include "Templates/itkAffineTransform2D3D+-.h"
278 #endif
279 
280 #if ITK_TEMPLATE_TXX
281 # include "itkAffineTransform2D3D.txx"
282 #endif
283 
284 #endif /* __itkAffineTransform2D3D_h */
Superclass::ScalarType ScalarType
Definition: itkAffineTransform2D3D.h:61
Superclass::OutputVnlVectorType OutputVnlVectorType
Definition: itkAffineTransform2D3D.h:67
Superclass::OutputCovariantVectorType OutputCovariantVectorType
Definition: itkAffineTransform2D3D.h:71
SmartPointer< const Self > ConstPointer
Definition: itkAffineTransform2D3D.h:42
Matrix< TScalarType, NDimensions+1, NDimensions+1 > m_Translations
Definition: itkAffineTransform2D3D.h:176
Matrix< TScalarType, NDimensions+1, NDimensions+1 > m_TranslateToCentre
Definition: itkAffineTransform2D3D.h:177
InputPointType BackTransformPoint(const OutputPointType &point) const
Definition: itkAffineTransform2D3D.h:235
InputPointType BackTransform(const OutputPointType &point) const
Definition: itkAffineTransform2D3D.h:245
Superclass::InverseTransformBaseType InverseTransformBaseType
Definition: itkAffineTransform2D3D.h:80
Definition: niftkITKAffineResampleImage.cxx:74
itk::Point< double, 2 > InputPointType
Definition: EulerAffine2DJacobianTest.cxx:34
vnl_matrix< double > MatrixType
Definition: itkSuperEllipseFit.h:32
Matrix< TScalarType, NDimensions+1, NDimensions+1 > m_Scales
Definition: itkAffineTransform2D3D.h:174
Superclass::InputCovariantVectorType InputCovariantVectorType
Definition: itkAffineTransform2D3D.h:69
GLintptr offset
Definition: glew.h:1666
GLuint64EXT * result
Definition: glew.h:12084
Superclass::InputPointType InputPointType
Definition: itkAffineTransform2D3D.h:62
Superclass::InputVectorType InputVectorType
Definition: itkAffineTransform2D3D.h:64
AffineTransform2D3D Self
Definition: itkAffineTransform2D3D.h:37
itk::Array< double > TranslationType
Definition: EulerAffine2DJacobianTest.cxx:30
Superclass::JacobianType JacobianType
Definition: itkAffineTransform2D3D.h:60
Superclass::TranslationType TranslationType
Definition: itkAffineTransform2D3D.h:76
InverseTransformBaseType::Pointer InverseTransformBasePointer
Definition: itkAffineTransform2D3D.h:81
Superclass::OffsetType OffsetType
Definition: itkAffineTransform2D3D.h:75
Superclass::MatrixType MatrixType
Definition: itkAffineTransform2D3D.h:72
Definition: itkAffineTransform2D3D.h:32
GLuint GLenum matrix
Definition: glew.h:12775
Matrix< TScalarType, NDimensions+1, NDimensions+1 > m_Shears
Definition: itkAffineTransform2D3D.h:175
Superclass::CenterType CenterType
Definition: itkAffineTransform2D3D.h:74
Superclass::OutputVectorType OutputVectorType
Definition: itkAffineTransform2D3D.h:65
Superclass::OutputPointType OutputPointType
Definition: itkAffineTransform2D3D.h:63
Superclass::InverseMatrixType InverseMatrixType
Definition: itkAffineTransform2D3D.h:73
Superclass::InputVnlVectorType InputVnlVectorType
Definition: itkAffineTransform2D3D.h:66
SmartPointer< Self > Pointer
Definition: itkAffineTransform2D3D.h:41
GLdouble angle
Definition: glew.h:7898
Superclass::ParametersType ParametersType
Definition: itkAffineTransform2D3D.h:59
GLdouble s
Definition: glew.h:1374
itk::Point< double, 2 > OutputPointType
Definition: EulerAffine2DJacobianTest.cxx:35
Matrix< TScalarType, NDimensions+1, NDimensions+1 > m_BackTranslateCentre
Definition: itkAffineTransform2D3D.h:178
itk::Array2D< double > JacobianType
Definition: EulerAffine2DJacobianTest.cxx:28
Matrix< TScalarType, NDimensions+1, NDimensions+1 > m_Rotations
Definition: itkAffineTransform2D3D.h:173
MatrixOffsetTransformBase< TScalarType, NDimensions, NDimensions > Superclass
Definition: itkAffineTransform2D3D.h:40