Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkInteractiveTransformationWidget.cpp
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 
18 
19 // mitk includes
20 #include "mitkRenderingManager.h"
21 #include "mitkNavigationData.h"
22 
23 // vtk includes
24 #include "vtkMatrix4x4.h"
25 #include "vtkLinearTransform.h"
26 
27 const std::string QmitkInteractiveTransformationWidget::VIEW_ID = "org.mitk.views.interactivetransformationwidget";
28 
30 : QWidget(parent, f), m_Geometry(nullptr), m_ResetGeometry(nullptr), m_Controls(nullptr)
31 {
32  CreateQtPartControl(this);
34  m_TranslationVector.Fill(0.0f);
35  m_RotateSliderPos.Fill(0.0f);
36 }
37 
39 {
40 }
41 
43 {
44  if (!m_Controls)
45  {
46  // create GUI widgets
47  m_Controls = new Ui::QmitkInteractiveTransformationWidgetControls;
48  m_Controls->setupUi(parent);
49  }
50 }
51 
53 {
54  if ( m_Controls )
55  {
56  // translations
57  connect( (QObject*)(m_Controls->m_XTransSlider), SIGNAL(valueChanged(int)), this, SLOT(OnXTranslationValueChanged(int)) );
58  connect( (QObject*)(m_Controls->m_XTransSpinBox), SIGNAL(valueChanged(int)), this, SLOT(OnXTranslationValueChanged(int)) );
59  connect( (QObject*)(m_Controls->m_YTransSlider), SIGNAL(valueChanged(int)), this, SLOT(OnYTranslationValueChanged(int)) );
60  connect( (QObject*)(m_Controls->m_YTransSpinBox), SIGNAL(valueChanged(int)), this, SLOT(OnYTranslationValueChanged(int)) );
61  connect( (QObject*)(m_Controls->m_ZTransSlider), SIGNAL(valueChanged(int)), this, SLOT(OnZTranslationValueChanged(int)) );
62  connect( (QObject*)(m_Controls->m_ZTransSpinBox), SIGNAL(valueChanged(int)), this, SLOT(OnZTranslationValueChanged(int)) );
63 
64  // rotations
65  connect( (QObject*)(m_Controls->m_XRotSlider), SIGNAL(valueChanged(int)), this, SLOT(OnXRotationValueChanged(int)) );
66  connect( (QObject*)(m_Controls->m_XRotSpinBox), SIGNAL(valueChanged(int)), this, SLOT(OnXRotationValueChanged(int)) );
67  connect( (QObject*)(m_Controls->m_YRotSlider), SIGNAL(valueChanged(int)), this, SLOT(OnYRotationValueChanged(int)) );
68  connect( (QObject*)(m_Controls->m_YRotSpinBox), SIGNAL(valueChanged(int)), this, SLOT(OnYRotationValueChanged(int)) );
69  connect( (QObject*)(m_Controls->m_ZRotSlider), SIGNAL(valueChanged(int)), this, SLOT(OnZRotationValueChanged(int)) );
70  connect( (QObject*)(m_Controls->m_ZRotSpinBox), SIGNAL(valueChanged(int)), this, SLOT(OnZRotationValueChanged(int)) );
71 
72  connect( (QObject*)(m_Controls->m_ResetPB), SIGNAL(clicked()), this, SLOT(OnResetGeometry()) );
73  connect( (QObject*)(m_Controls->m_UseManipulatedToolTipPB), SIGNAL(clicked()), this, SLOT(OnApplyManipulatedToolTip()) );
74  }
75 }
76 
78 {
79  m_Geometry = geometry;
80  m_ResetGeometry = geometry->Clone();
81 
82  //set default values
83  if (defaultValues.IsNotNull())
84  {
85  //first: some conversion
86  mitk::NavigationData::Pointer transformConversionHelper = mitk::NavigationData::New(defaultValues->GetIndexToWorldTransform());
87  double eulerAlphaDegrees = transformConversionHelper->GetOrientation().rotation_euler_angles()[0] / vnl_math::pi * 180;
88  double eulerBetaDegrees = transformConversionHelper->GetOrientation().rotation_euler_angles()[1] / vnl_math::pi * 180;
89  double eulerGammaDegrees = transformConversionHelper->GetOrientation().rotation_euler_angles()[2] / vnl_math::pi * 180;
90 
91  //set translation
92  OnXTranslationValueChanged(defaultValues->GetIndexToWorldTransform()->GetOffset()[0]);
93  OnYTranslationValueChanged(defaultValues->GetIndexToWorldTransform()->GetOffset()[1]);
94  OnZTranslationValueChanged(defaultValues->GetIndexToWorldTransform()->GetOffset()[2]);
95 
96  //set rotation
97  OnXRotationValueChanged(eulerAlphaDegrees);
98  OnYRotationValueChanged(eulerBetaDegrees);
99  OnZRotationValueChanged(eulerGammaDegrees);
100  }
101  else
102  {
103  //reset everything
110  }
111 }
112 
114 {
115  return m_Geometry;
116 }
117 
118 
119 
120 
121 
123 // Section to allow interactive positioning of the moving surface
125 
127 {
128  mitk::Vector3D translationParams;
129  translationParams[0] = v;
130  translationParams[1] = m_Controls->m_YTransSlider->value();
131  translationParams[2] = m_Controls->m_ZTransSlider->value();
132  SetSliderX(v);
133  this->Translate(translationParams);
134 }
135 
137 {
138  m_Controls->m_XTransSlider->setValue(v);
139  m_Controls->m_XTransSpinBox->setValue(v);
140 }
141 
143 {
144  mitk::Vector3D translationParams;
145  translationParams[0] = m_Controls->m_XTransSlider->value();
146  translationParams[1] = v;
147  translationParams[2] = m_Controls->m_ZTransSlider->value();
148  SetSliderY(v);
149  this->Translate(translationParams);
150 }
151 
153 {
154  m_Controls->m_YTransSlider->setValue(v);
155  m_Controls->m_YTransSpinBox->setValue(v);
156 }
157 
159 {
160  mitk::Vector3D translationParams;
161  translationParams[0] = m_Controls->m_XTransSlider->value();
162  translationParams[1] = m_Controls->m_YTransSlider->value();
163  translationParams[2] = v;
164  SetSliderZ(v);
165  this->Translate(translationParams);
166 }
167 
169 {
170  m_Controls->m_ZTransSlider->setValue(v);
171  m_Controls->m_ZTransSpinBox->setValue(v);
172 }
173 
175 {
176  mitk::Vector3D translateVec;
177 
178  // transform the translation vector
179  translateVec[0] = translateVector[0] - m_TranslationVector[0];
180  translateVec[1] = translateVector[1] - m_TranslationVector[1];
181  translateVec[2] = translateVector[2] - m_TranslationVector[2];
182 
183  // set the new translation vector to member variable
184  m_TranslationVector[0] = translateVector[0];
185  m_TranslationVector[1] = translateVector[1];
186  m_TranslationVector[2] = translateVector[2];
187 
188  m_Geometry->Translate( translateVec );
189  qApp->processEvents();
191 }
192 
194 {
195  mitk::Vector3D rotationParams;
196  rotationParams[0] = v;
197  rotationParams[1] = m_Controls->m_YRotSlider->value();
198  rotationParams[2] = m_Controls->m_ZRotSlider->value();
199 
200  m_Controls->m_XRotSlider->setValue(v);
201  m_Controls->m_XRotSpinBox->setValue(v);
202 
203  this->Rotate(rotationParams);
204 }
205 
207 {
208  mitk::Vector3D rotationParams;
209  rotationParams[0] = m_Controls->m_XRotSlider->value();
210  rotationParams[1] = v;
211  rotationParams[2] = m_Controls->m_ZRotSlider->value();
212 
213  m_Controls->m_YRotSlider->setValue(v);
214  m_Controls->m_YRotSpinBox->setValue(v);
215 
216  this->Rotate(rotationParams);
217 }
218 
220 {
221  mitk::Vector3D rotationParams;
222  rotationParams[0]=m_Controls->m_XRotSlider->value();
223  rotationParams[1]=m_Controls->m_YRotSlider->value();
224  rotationParams[2]=v;
225  m_Controls->m_ZRotSlider->setValue(v);
226  m_Controls->m_ZRotSpinBox->setValue(v);
227 
228  this->Rotate(rotationParams);
229 }
230 
232 {
233  //0: from degrees to radians
234  double radianX = rotateVector[0] * vnl_math::pi / 180;
235  double radianY = rotateVector[1] * vnl_math::pi / 180;
236  double radianZ = rotateVector[2] * vnl_math::pi / 180;
237 
238  //1: from euler angles to quaternion
239  mitk::Quaternion rotation(radianX,radianY,radianZ);
240 
241  //2: Conversion to navigation data / transform
243  rotationTransform->SetOrientation(rotation);
244 
245  //3: Apply transform
246 
247  //also remember old transform, but without rotation, because rotation is completely stored in the sliders
248  mitk::NavigationData::Pointer oldTransform = mitk::NavigationData::New(m_Geometry->GetIndexToWorldTransform());
249  mitk::Quaternion identity(0,0,0,1);
250  oldTransform->SetOrientation(identity);
251 
252  //compose old transform with the new one
253  rotationTransform->Compose(oldTransform);
254 
255  //and apply it...
256  m_Geometry->SetIndexToWorldTransform(rotationTransform->GetAffineTransform3D());
257  qApp->processEvents();
259 }
260 
262 {
263  m_Controls->m_XRotSlider->setValue(0);
264  m_Controls->m_YRotSlider->setValue(0);
265  m_Controls->m_ZRotSlider->setValue(0);
266  m_Controls->m_XRotSpinBox->setValue(0);
267  m_Controls->m_YRotSpinBox->setValue(0);
268  m_Controls->m_ZRotSpinBox->setValue(0);
269 
270  m_Controls->m_XTransSlider->setValue(0);
271  m_Controls->m_YTransSlider->setValue(0);
272  m_Controls->m_ZTransSlider->setValue(0);
273  m_Controls->m_XTransSpinBox->setValue(0);
274  m_Controls->m_YTransSpinBox->setValue(0);
275  m_Controls->m_ZTransSpinBox->setValue(0);
276  qApp->processEvents();
277 
278  // reset the input to its initial state.
279  m_Geometry->SetIdentity();
280  m_Geometry->Compose(m_ResetGeometry->GetVtkTransform()->GetMatrix());
282 }
283 
285 {
287 }
static Pointer New()
itk::SmartPointer< Self > Pointer
mitk::BaseGeometry::Pointer m_Geometry
Initial geometry that is manipulated.
static Matrix3D rotation
void Rotate(mitk::Vector3D rotateVector)
Method performs the rotation. rotateVector New rotation to be combined with geometry.
QmitkInteractiveTransformationWidget(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
mitk::Vector3D m_TranslationVector
Accumulated translation vector.
void Translate(mitk::Vector3D translateVector)
Method performs the translation. translateVector New translation to be combine with geometry...
void SetGeometry(mitk::BaseGeometry::Pointer geometry, mitk::BaseGeometry::Pointer defaultValues=nullptr)
static RenderingManager * GetInstance()
vnl_quaternion< ScalarType > Quaternion
mitk::Vector3D m_RotateSliderPos
Accumulated rotation vector (holds degree around x,y,z direction)
mitk::BaseGeometry::Pointer m_ResetGeometry
Lifeline to reset to the initial geometry.
Ui::QmitkInteractiveTransformationWidgetControls * m_Controls
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)