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
itkVtkAbstractTransform.txx
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 #include "itkVtkAbstractTransform.h"
18 #include <mitkNumericTypes.h>
19 #include <vtkAbstractTransform.h>
20 
21 namespace itk
22 {
23  template <class TScalarType>
24  itk::VtkAbstractTransform<TScalarType>::VtkAbstractTransform()
25  : m_VtkAbstractTransform(nullptr), m_InverseVtkAbstractTransform(nullptr), m_LastVtkAbstractTransformTimeStamp(0)
26  {
27  }
28 
29  template <class TScalarType>
30  itk::VtkAbstractTransform<TScalarType>::~VtkAbstractTransform()
31  {
32  if (m_VtkAbstractTransform != nullptr)
33  m_VtkAbstractTransform->UnRegister(nullptr);
34  }
35 
36  template <class TScalarType>
37  vtkAbstractTransform *itk::VtkAbstractTransform<TScalarType>::GetVtkAbstractTransform() const
38  {
39  return m_VtkAbstractTransform;
40  }
41 
42  template <class TScalarType>
43  vtkAbstractTransform *itk::VtkAbstractTransform<TScalarType>::GetInverseVtkAbstractTransform() const
44  {
45  return m_InverseVtkAbstractTransform;
46  }
47 
48  template <class TScalarType>
49  void itk::VtkAbstractTransform<TScalarType>::SetVtkAbstractTransform(vtkAbstractTransform *aVtkAbstractTransform)
50  {
51  if (m_VtkAbstractTransform == aVtkAbstractTransform)
52  return;
53 
54  if (m_VtkAbstractTransform != nullptr)
55  m_VtkAbstractTransform->UnRegister(nullptr);
56 
57  m_VtkAbstractTransform = aVtkAbstractTransform;
58  if (m_VtkAbstractTransform != nullptr)
59  {
60  m_VtkAbstractTransform->Register(nullptr);
61  m_InverseVtkAbstractTransform = m_VtkAbstractTransform->GetInverse(); // memory managed by m_VtkAbstractTransform
62  }
63 
64  m_LastVtkAbstractTransformTimeStamp = m_VtkAbstractTransform->GetMTime();
65 
66  this->Modified();
67  }
68 
69  // Transform a point
70  template <class TScalarType>
71  typename itk::VtkAbstractTransform<TScalarType>::OutputPointType
72  itk::VtkAbstractTransform<TScalarType>::TransformPoint(const InputPointType &point) const
73  {
74  assert(m_VtkAbstractTransform != nullptr);
75 
76  OutputPointType outputpoint;
77  vnl_vector<TScalarType> vnl_vec;
78  mitk::ScalarType vtkpt[3];
79  mitk::itk2vtk(point, vtkpt);
80  m_VtkAbstractTransform->TransformPoint(vtkpt, vtkpt);
81  mitk::vtk2itk(vtkpt, outputpoint);
82  return outputpoint;
83  }
84 
85  // Transform a vector
86  template <class TScalarType>
87  typename itk::VtkAbstractTransform<TScalarType>::OutputVectorType
88  itk::VtkAbstractTransform<TScalarType>::TransformVector(const InputVectorType &vect) const
89  {
90  assert(m_VtkAbstractTransform != nullptr);
91 
92  OutputVectorType outputvector;
93  vnl_vector<TScalarType> vnl_vec;
94  mitk::ScalarType vtkpt[3] = {0, 0, 0};
95  mitk::ScalarType vtkvec[3];
96  mitk::vnl2vtk<TScalarType, mitk::ScalarType>(vect.GetVnlVector(), vtkvec);
97  m_VtkAbstractTransform->TransformVectorAtPoint(vtkpt, vtkvec, vtkvec);
98  mitk::vtk2itk(vtkvec, outputvector);
99  return outputvector;
100  }
101 
102  // Transform a vnl_vector_fixed
103  template <class TScalarType>
104  typename itk::VtkAbstractTransform<TScalarType>::OutputVnlVectorType
105  itk::VtkAbstractTransform<TScalarType>::TransformVector(const InputVnlVectorType &vect) const
106  {
107  assert(m_VtkAbstractTransform != nullptr);
108 
109  OutputVnlVectorType outputvector;
110  mitk::ScalarType vtkpt[3] = {0, 0, 0};
111  mitk::ScalarType vtkvec[3];
112  mitk::vnl2vtk<TScalarType, mitk::ScalarType>(vect, vtkvec);
113  m_VtkAbstractTransform->TransformVectorAtPoint(vtkpt, vtkvec, vtkvec);
114  mitk::vtk2itk(vtkvec, outputvector);
115  return outputvector;
116  }
117 
118  // Transform a CovariantVector
119  template <class TScalarType>
120  typename itk::VtkAbstractTransform<TScalarType>::OutputCovariantVectorType
121  itk::VtkAbstractTransform<TScalarType>::TransformCovariantVector(const InputCovariantVectorType & /*vec*/) const
122  {
123  itkExceptionMacro(<< "implement before using!");
124  OutputCovariantVectorType result; // Converted vector
125 
126  // for (unsigned int i = 0; i < NDimensions; i++)
127  // {
128  // result[i] = NumericTraits<mitk::ScalarType>::Zero;
129  // for (unsigned int j = 0; j < NDimensions; j++)
130  // {
131  // result[i] += m_Inverse[j][i]*vec[j]; // Inverse transposed
132  // }
133  // }
134  return result;
135  }
136 
137  // Back transform a point
138  template <class TScalarType>
139  typename VtkAbstractTransform<TScalarType>::InputPointType itk::VtkAbstractTransform<TScalarType>::BackTransform(
140  const OutputPointType &point) const
141  {
142  assert(m_VtkAbstractTransform != nullptr);
143 
144  OutputPointType outputpoint;
145  mitk::ScalarType vtkpt[3];
146  mitk::itk2vtk(point, vtkpt);
147  m_InverseVtkAbstractTransform->TransformPoint(vtkpt, vtkpt);
148  mitk::vtk2itk(vtkpt, outputpoint);
149  return outputpoint;
150  }
151 
152  // Back transform a vector
153  template <class TScalarType>
154  typename VtkAbstractTransform<TScalarType>::InputVectorType itk::VtkAbstractTransform<TScalarType>::BackTransform(
155  const OutputVectorType &vect) const
156  {
157  assert(m_VtkAbstractTransform != nullptr);
158 
159  OutputVectorType outputvector;
160  mitk::ScalarType vtkpt[3] = {0, 0, 0};
161  mitk::ScalarType vtkvec[3];
162  mitk::itk2vtk(vect, vtkvec);
163  m_InverseVtkAbstractTransform->TransformVectorAtPoint(vtkpt, vtkvec, vtkvec);
164  mitk::vtk2itk(vtkvec, outputvector);
165  return outputvector;
166  }
167 
168  // Back transform a vnl_vector
169  template <class TScalarType>
170  typename VtkAbstractTransform<TScalarType>::InputVnlVectorType itk::VtkAbstractTransform<TScalarType>::BackTransform(
171  const OutputVnlVectorType &vect) const
172  {
173  assert(m_InverseVtkAbstractTransform != nullptr);
174 
175  OutputVnlVectorType outputvector;
176  mitk::ScalarType vtkpt[3] = {0, 0, 0};
177  mitk::ScalarType vtkvec[3];
178  mitk::itk2vtk(vect, vtkvec);
179  m_InverseVtkAbstractTransform->TransformVectorAtPoint(vtkpt, vtkvec, vtkvec);
180  mitk::vtk2itk(vtkvec, outputvector);
181  return outputvector;
182  }
183 
184  // Back Transform a CovariantVector
185  template <class TScalarType>
186  typename VtkAbstractTransform<TScalarType>::InputCovariantVectorType
187  itk::VtkAbstractTransform<TScalarType>::BackTransform(const OutputCovariantVectorType &vec) const
188  {
189  itkExceptionMacro(<< "implement before using!");
190  // for (unsigned int i = 0; i < NDimensions; i++)
191  // {
192  // result[i] = NumericTraits<mitk::ScalarType>::Zero;
193  // for (unsigned int j = 0; j < NDimensions; j++)
194  // {
195  // result[i] += m_Matrix[j][i]*vec[j]; // Direct matrix transposed
196  // }
197  // }
198  return vec;
199  }
200 
201  template <class TScalarType>
202  unsigned long itk::VtkAbstractTransform<TScalarType>::GetMTime() const
203  {
204  if ((m_VtkAbstractTransform != nullptr) &&
205  (m_LastVtkAbstractTransformTimeStamp < m_VtkAbstractTransform->GetMTime()))
206  {
207  m_LastVtkAbstractTransformTimeStamp = m_VtkAbstractTransform->GetMTime();
208  this->Modified();
209  }
210 
211  return Superclass::GetMTime();
212  }
213 
214  template <class TScalarType>
215  void itk::VtkAbstractTransform<TScalarType>::SetParameters(const ParametersType &)
216  {
217  // TODO
218  }
219 
220  template <class TScalarType>
221  void itk::VtkAbstractTransform<TScalarType>::SetFixedParameters(const ParametersType &)
222  {
223  // TODO
224  }
225 
226  template <class TScalarType>
227  void itk::VtkAbstractTransform<TScalarType>::ComputeJacobianWithRespectToParameters(const InputPointType &,
228  JacobianType &) const
229  {
230  // TODO
231  }
232 
233  template <class TScalarType>
234  void itk::VtkAbstractTransform<TScalarType>::ComputeJacobianWithRespectToPosition(const InputPointType &,
235  JacobianType &) const
236  {
237  // TODO
238  }
239 
240 } // namespace itk