Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkGeometryTransformHolder.h
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef MITKGEOMETRYTRANSFORMHOLDER_H_
18 #define MITKGEOMETRYTRANSFORMHOLDER_H_
19 
20 #include <MitkCoreExports.h>
21 #include <mitkAffineTransform3D.h>
22 #include <mitkAffineTransform3D.h>
23 #include <mitkCommon.h>
24 #include <mitkMatrix.h>
25 #include <mitkPoint.h>
26 #include <mitkVector.h>
27 #include <vtkMatrixToLinearTransform.h>
28 #include <vtkTransform.h>
29 
30 namespace mitk
31 {
32  /*
33  GeometryTransformHolder is a helper class which manages the transform related variables.
34  Its job is to keep all information about the transform (as e.g.: spacing, offset, transformation matrices) in
35  consistent states.
36  It provides getters and setters to all transformation related information. Implementation is hidden and may be
37  subject to changes.
38  */
40  {
41  private:
42  //##Documentation
43  //## @brief Index to World Transform, contains a transformation matrix to convert
44  //## points from index coordinates to world coordinates (mm). The Spacing is included in this variable.
45  AffineTransform3D::Pointer m_IndexToWorldTransform;
46 
47  vtkMatrix4x4 *m_VtkMatrix;
48  vtkMatrixToLinearTransform *m_VtkIndexToWorldTransform;
49 
50  static void CopySpacingFromTransform(const mitk::AffineTransform3D *transform, mitk::Vector3D &spacing);
51 
52  //##Documentation
53  //## @brief Copy the ITK transform
54  //## (m_IndexToWorldTransform) to the VTK transform
55  //## \sa SetIndexToWorldTransform
56  void TransferItkToVtkTransform();
57 
58  //##Documentation
59  //## @brief Copy the VTK transform
60  //## to the ITK transform (m_IndexToWorldTransform)
61  //## \sa SetIndexToWorldTransform
62  void TransferVtkToItkTransform();
63 
64  protected:
65  public:
66  typedef itk::ScalableAffineTransform<ScalarType, 3> TransformType;
67 
69 
71 
72  virtual ~GeometryTransformHolder();
73 
74  void Initialize();
75 
76  void Initialize(const GeometryTransformHolder *other);
77 
78  //##Documentation
79  //## @brief Get the origin, e.g. the upper-left corner of the plane
80  const Point3D GetOrigin() const;
81 
82  //##Documentation
83  //## @brief Set the origin, i.e. the upper-left corner of the plane
84  //##
85  void SetOrigin(const Point3D &origin);
86 
87  //##Documentation
88  //## @brief Get the spacing (size of a pixel).
89  //##
90  const mitk::Vector3D GetSpacing() const;
91 
92  //##Documentation
93  //## @brief Set the spacing (m_Spacing).
94  //##
95  //##The spacing is also changed in the IndexToWorldTransform.
96  void SetSpacing(const mitk::Vector3D &aSpacing, bool enforceSetSpacing = false);
97 
98  //##Documentation
99  //## @brief Get the transformation used to convert from index
100  //## to world coordinates
102 
103  //##Documentation
104  //## @brief Get the transformation used to convert from index
105  //## to world coordinates
107 
108  //## @brief Set the transformation used to convert from index
109  //## to world coordinates.This will also change the spacing.
111 
112  //##Documentation
113  //## @brief Convenience method for setting the ITK transform
114  //## (m_IndexToWorldTransform) via an vtkMatrix4x4. This will also change the spacing.
115  //## \sa SetIndexToWorldTransform
116  virtual void SetIndexToWorldTransformByVtkMatrix(vtkMatrix4x4 *vtkmatrix);
117 
118  //## @brief Set the transformation used to convert from index
119  //## to world coordinates.This function keeps the original spacing.
121 
122  //##Documentation
123  //## @brief Convenience method for setting the ITK transform
124  //## (m_IndexToWorldTransform) via an vtkMatrix4x4. This function keeps the original spacing.
125  //## \sa SetIndexToWorldTransform
126  void SetIndexToWorldTransformByVtkMatrixWithoutChangingSpacing(vtkMatrix4x4 *vtkmatrix);
127 
128  //## Get the Vtk Matrix which describes the transform.
129  vtkMatrix4x4 *GetVtkMatrix();
130 
131  //## Get the Vtk Matrix which describes the transform.
132  const vtkMatrix4x4 *GetVtkMatrix() const;
133 
134  //##Documentation
135  //## @brief Get the m_IndexToWorldTransform as a vtkLinearTransform
136  vtkLinearTransform *GetVtkTransform() const;
137 
138  void SetMatrix(Matrix3D &matrix);
139 
140  void SetIdentity();
141 
142  void Compose(const TransformType *other, bool pre = 0);
143 
144  void SetVtkMatrixDeepCopy(vtkTransform *vtktransform);
145 
147 
148  AffineTransform3D::MatrixType::InternalMatrixType GetVnlMatrix();
149  };
150  MITKCORE_EXPORT bool Equal(const mitk::GeometryTransformHolder &leftHandSide,
151  const mitk::GeometryTransformHolder &rightHandSide,
152  ScalarType eps,
153  bool verbose);
154 
155  MITKCORE_EXPORT bool Equal(const mitk::GeometryTransformHolder *leftHandSide,
156  const mitk::GeometryTransformHolder *rightHandSide,
157  ScalarType eps,
158  bool verbose);
159 }
160 #endif /* MITKGEOMETRYTRANSFORMHOLDER_H_ */
void SetVtkMatrixDeepCopy(vtkTransform *vtktransform)
itk::SmartPointer< Self > Pointer
void SetIndexToWorldTransformByVtkMatrixWithoutChangingSpacing(vtkMatrix4x4 *vtkmatrix)
Convenience method for setting the ITK transform (m_IndexToWorldTransform) via an vtkMatrix4x4...
#define MITKCORE_EXPORT
double ScalarType
void Compose(const TransformType *other, bool pre=0)
DataCollection - Class to facilitate loading/accessing structured data.
AffineTransform3D::MatrixType::InternalMatrixType GetVnlMatrix()
vtkLinearTransform * GetVtkTransform() const
Get the m_IndexToWorldTransform as a vtkLinearTransform.
void SetSpacing(const mitk::Vector3D &aSpacing, bool enforceSetSpacing=false)
Set the spacing (m_Spacing).
void SetIndexToWorldTransformWithoutChangingSpacing(mitk::AffineTransform3D *transform)
const Point3D GetOrigin() const
Get the origin, e.g. the upper-left corner of the plane.
itk::ScalableAffineTransform< ScalarType, 3 > TransformType
itk::AffineGeometryFrame< ScalarType, 3 >::TransformType AffineTransform3D
void SetIndexToWorldTransform(mitk::AffineTransform3D *transform)
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
MITKCORE_EXPORT const ScalarType eps
virtual void SetIndexToWorldTransformByVtkMatrix(vtkMatrix4x4 *vtkmatrix)
Convenience method for setting the ITK transform (m_IndexToWorldTransform) via an vtkMatrix4x4...
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.
void SetOrigin(const Point3D &origin)
Set the origin, i.e. the upper-left corner of the plane.