Medical Imaging Interaction Toolkit  2018.04.99-74b4982f
Medical Imaging Interaction Toolkit
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef MITKGEOMETRYTRANSFORMHOLDER_H_
14 #define MITKGEOMETRYTRANSFORMHOLDER_H_
15 
16 #include <MitkCoreExports.h>
17 #include <mitkAffineTransform3D.h>
18 #include <mitkAffineTransform3D.h>
19 #include <mitkCommon.h>
20 #include <mitkMatrix.h>
21 #include <mitkPoint.h>
22 #include <mitkVector.h>
23 #include <vtkMatrixToLinearTransform.h>
24 #include <vtkTransform.h>
25 
26 namespace mitk
27 {
28  /*
29  GeometryTransformHolder is a helper class which manages the transform related variables.
30  Its job is to keep all information about the transform (as e.g.: spacing, offset, transformation matrices) in
31  consistent states.
32  It provides getters and setters to all transformation related information. Implementation is hidden and may be
33  subject to changes.
34  */
36  {
37  private:
38  //##Documentation
39  //## @brief Index to World Transform, contains a transformation matrix to convert
40  //## points from index coordinates to world coordinates (mm). The Spacing is included in this variable.
41  AffineTransform3D::Pointer m_IndexToWorldTransform;
42 
43  vtkMatrix4x4 *m_VtkMatrix;
44  vtkMatrixToLinearTransform *m_VtkIndexToWorldTransform;
45 
46  static void CopySpacingFromTransform(const mitk::AffineTransform3D *transform, mitk::Vector3D &spacing);
47 
48  //##Documentation
49  //## @brief Copy the ITK transform
50  //## (m_IndexToWorldTransform) to the VTK transform
51  //## \sa SetIndexToWorldTransform
52  void TransferItkToVtkTransform();
53 
54  //##Documentation
55  //## @brief Copy the VTK transform
56  //## to the ITK transform (m_IndexToWorldTransform)
57  //## \sa SetIndexToWorldTransform
58  void TransferVtkToItkTransform();
59 
60  protected:
61  public:
62  typedef itk::ScalableAffineTransform<ScalarType, 3> TransformType;
63 
65 
67 
68  virtual ~GeometryTransformHolder();
69 
70  void Initialize();
71 
72  void Initialize(const GeometryTransformHolder *other);
73 
74  //##Documentation
75  //## @brief Get the origin, e.g. the upper-left corner of the plane
76  const Point3D GetOrigin() const;
77 
78  //##Documentation
79  //## @brief Set the origin, i.e. the upper-left corner of the plane
80  //##
81  void SetOrigin(const Point3D &origin);
82 
83  //##Documentation
84  //## @brief Get the spacing (size of a pixel).
85  //##
86  const mitk::Vector3D GetSpacing() const;
87 
88  //##Documentation
89  //## @brief Set the spacing (m_Spacing).
90  //##
91  //##The spacing is also changed in the IndexToWorldTransform.
92  void SetSpacing(const mitk::Vector3D &aSpacing, bool enforceSetSpacing = false);
93 
94  //##Documentation
95  //## @brief Get the transformation used to convert from index
96  //## to world coordinates
98 
99  //##Documentation
100  //## @brief Get the transformation used to convert from index
101  //## to world coordinates
103 
104  //## @brief Set the transformation used to convert from index
105  //## to world coordinates.This will also change the spacing.
107 
108  //##Documentation
109  //## @brief Convenience method for setting the ITK transform
110  //## (m_IndexToWorldTransform) via an vtkMatrix4x4. This will also change the spacing.
111  //## \sa SetIndexToWorldTransform
112  virtual void SetIndexToWorldTransformByVtkMatrix(vtkMatrix4x4 *vtkmatrix);
113 
114  //## @brief Set the transformation used to convert from index
115  //## to world coordinates.This function keeps the original spacing.
117 
118  //##Documentation
119  //## @brief Convenience method for setting the ITK transform
120  //## (m_IndexToWorldTransform) via an vtkMatrix4x4. This function keeps the original spacing.
121  //## \sa SetIndexToWorldTransform
122  void SetIndexToWorldTransformByVtkMatrixWithoutChangingSpacing(vtkMatrix4x4 *vtkmatrix);
123 
124  //## Get the Vtk Matrix which describes the transform.
125  vtkMatrix4x4 *GetVtkMatrix();
126 
127  //## Get the Vtk Matrix which describes the transform.
128  const vtkMatrix4x4 *GetVtkMatrix() const;
129 
130  //##Documentation
131  //## @brief Get the m_IndexToWorldTransform as a vtkLinearTransform
132  vtkLinearTransform *GetVtkTransform() const;
133 
134  void SetMatrix(Matrix3D &matrix);
135 
136  void SetIdentity();
137 
138  void Compose(const TransformType *other, bool pre = false);
139 
140  void SetVtkMatrixDeepCopy(vtkTransform *vtktransform);
141 
143 
144  AffineTransform3D::MatrixType::InternalMatrixType GetVnlMatrix();
145  };
146  MITKCORE_EXPORT bool Equal(const mitk::GeometryTransformHolder &leftHandSide,
147  const mitk::GeometryTransformHolder &rightHandSide,
148  ScalarType eps,
149  bool verbose);
150 
151  MITKCORE_EXPORT bool Equal(const mitk::GeometryTransformHolder *leftHandSide,
152  const mitk::GeometryTransformHolder *rightHandSide,
153  ScalarType eps,
154  bool verbose);
155 }
156 #endif /* MITKGEOMETRYTRANSFORMHOLDER_H_ */
void SetVtkMatrixDeepCopy(vtkTransform *vtktransform)
MITKCORE_EXPORT const ScalarType eps
void SetIndexToWorldTransformByVtkMatrixWithoutChangingSpacing(vtkMatrix4x4 *vtkmatrix)
Convenience method for setting the ITK transform (m_IndexToWorldTransform) via an vtkMatrix4x4...
#define MITKCORE_EXPORT
double ScalarType
DataCollection - Class to facilitate loading/accessing structured data.
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.
AffineTransform3D::MatrixType::InternalMatrixType GetVnlMatrix()
virtual void SetIndexToWorldTransformByVtkMatrix(vtkMatrix4x4 *vtkmatrix)
Convenience method for setting the ITK transform (m_IndexToWorldTransform) via an vtkMatrix4x4...
void SetSpacing(const mitk::Vector3D &aSpacing, bool enforceSetSpacing=false)
Set the spacing (m_Spacing).
void SetIndexToWorldTransformWithoutChangingSpacing(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.
void Compose(const TransformType *other, bool pre=false)
vtkMatrix4x4 * GetVtkMatrix()
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
itk::ScalableAffineTransform< ScalarType, 3 > TransformType
vtkLinearTransform * GetVtkTransform() const
Get the m_IndexToWorldTransform as a vtkLinearTransform.
itk::AffineGeometryFrame< ScalarType, 3 >::TransformType AffineTransform3D
void SetIndexToWorldTransform(mitk::AffineTransform3D *transform)
void SetOrigin(const Point3D &origin)
Set the origin, i.e. the upper-left corner of the plane.
void SetMatrix(Matrix3D &matrix)
const Point3D GetOrigin() const
Get the origin, e.g. the upper-left corner of the plane.