MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
QmitkInteractiveTransformationWidget.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
14
15// mitk includes
16#include "mitkRenderingManager.h"
17#include "mitkBaseRenderer.h"
18#include "mitkNavigationData.h"
19
20// vtk includes
21#include "vtkMatrix4x4.h"
22#include "vtkLinearTransform.h"
23
24const std::string QmitkInteractiveTransformationWidget::VIEW_ID = "org.mitk.views.interactivetransformationwidget";
25
27 : QDialog(parent, f), m_Controls(nullptr), m_Geometry(nullptr)
28{
31
32 m_ResetGeometry = mitk::Geometry3D::New();
33
34
35 this->setWindowTitle("Edit Tool Tip and Tool Orientation");
36}
37
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(m_Controls->m_XTransSpinBox, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &QmitkInteractiveTransformationWidget::OnXTranslationValueChanged);
58 connect(m_Controls->m_XTransSlider, &QSlider::valueChanged, this, &QmitkInteractiveTransformationWidget::OnXTranslationValueChanged);
59
60 connect(m_Controls->m_YTransSpinBox, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &QmitkInteractiveTransformationWidget::OnYTranslationValueChanged);
61 connect(m_Controls->m_YTransSlider, &QSlider::valueChanged, this, &QmitkInteractiveTransformationWidget::OnYTranslationValueChanged);
62
63 connect(m_Controls->m_ZTransSpinBox, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &QmitkInteractiveTransformationWidget::OnZTranslationValueChanged);
64 connect(m_Controls->m_ZTransSlider, &QSlider::valueChanged, this, &QmitkInteractiveTransformationWidget::OnZTranslationValueChanged);
65
66 // rotations
67 connect(m_Controls->m_XRotSpinBox, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &QmitkInteractiveTransformationWidget::OnXRotationValueChanged);
68 connect(m_Controls->m_XRotSlider, &QSlider::valueChanged, this, &QmitkInteractiveTransformationWidget::OnXRotationValueChanged);
69
70 connect(m_Controls->m_YRotSpinBox, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &QmitkInteractiveTransformationWidget::OnYRotationValueChanged);
71 connect(m_Controls->m_YRotSlider, &QSlider::valueChanged, this, &QmitkInteractiveTransformationWidget::OnYRotationValueChanged);
72
73 connect(m_Controls->m_ZRotSpinBox, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &QmitkInteractiveTransformationWidget::OnZRotationValueChanged);
74 connect(m_Controls->m_ZRotSlider, &QSlider::valueChanged, this, &QmitkInteractiveTransformationWidget::OnZRotationValueChanged);
75
76 connect((QObject*)(m_Controls->m_ResetPB), SIGNAL(clicked()), this, SLOT(OnResetGeometryToIdentity()));
77 connect((QObject*)(m_Controls->m_RevertChanges), SIGNAL(clicked()), this, SLOT(OnRevertChanges()));
78 connect((QObject*)(m_Controls->m_UseManipulatedToolTipPB), SIGNAL(clicked()), this, SLOT(OnApplyManipulatedToolTip()));
79 connect((QObject*)(m_Controls->m_Cancel), SIGNAL(clicked()), this, SLOT(OnCancel()));
80 }
81}
82
83void QmitkInteractiveTransformationWidget::SetToolToEdit(const mitk::NavigationTool::Pointer _tool)
84{
85 //If there is already a tool, remove it's node first.
86 if (m_ToolToEdit)
87 mitk::RenderingManager::GetInstance()->GetDataStorage()->Remove(m_ToolToEdit->GetDataNode());
88
89 m_ToolToEdit = _tool->Clone();
90 mitk::RenderingManager::GetInstance()->GetDataStorage()->Add(m_ToolToEdit->GetDataNode());
91 m_ToolToEdit->GetDataNode()->SetName("Tool Tip to be edited");
92
93 //change color to red
94 m_ToolToEdit->GetDataNode()->SetProperty("color", mitk::ColorProperty::New(1, 0, 0));
95
96 //use the set-function via vtk matrix, 'cause this guarantees a deep copy and not just sharing a pointer.
97 m_Geometry = m_ToolToEdit->GetDataNode()->GetData()->GetGeometry();
98 m_ResetGeometry->SetIndexToWorldTransformByVtkMatrix(m_Geometry->GetVtkMatrix()); //Remember the original values to be able to reset and abort everything
99}
100
101void QmitkInteractiveTransformationWidget::SetDefaultOffset(const mitk::Point3D _defaultValues)
102{
103 m_Geometry->SetOrigin(_defaultValues);
104 m_ResetGeometry->SetOrigin(_defaultValues); //Remember the original values to be able to reset and abort everything
105 SetValuesToGUI(m_Geometry->GetIndexToWorldTransform());
106}
107
108void QmitkInteractiveTransformationWidget::SetDefaultRotation(const mitk::Quaternion _defaultValues)
109{
110 // Conversion to navigation data / transform
111 mitk::NavigationData::Pointer rotationTransform = mitk::NavigationData::New(m_Geometry->GetIndexToWorldTransform());
112 rotationTransform->SetOrientation(_defaultValues);
113 m_Geometry->SetIndexToWorldTransform(rotationTransform->GetAffineTransform3D());
114
115 //For ResetGeometry, use the set-function via vtk matrix, 'cause this guarantees a deep copy and not just sharing a pointer.
116 m_ResetGeometry->SetIndexToWorldTransformByVtkMatrix(m_Geometry->GetVtkMatrix()); //Remember the original values to be able to reset and abort everything
117 SetValuesToGUI(m_Geometry->GetIndexToWorldTransform());
118}
119
120void QmitkInteractiveTransformationWidget::SetValuesToGUI(const mitk::AffineTransform3D::Pointer _defaultValues)
121{
122
123 //Set toolTip values in gui
124 m_Controls->m_XTransSlider->setValue(_defaultValues->GetOffset()[0]);
125 m_Controls->m_YTransSlider->setValue(_defaultValues->GetOffset()[1]);
126 m_Controls->m_ZTransSlider->setValue(_defaultValues->GetOffset()[2]);
127
128 //first: some conversion
129 mitk::NavigationData::Pointer transformConversionHelper = mitk::NavigationData::New(_defaultValues);
130 double eulerAlphaDegrees = transformConversionHelper->GetOrientation().rotation_euler_angles()[0] / vnl_math::pi * 180;
131 double eulerBetaDegrees = transformConversionHelper->GetOrientation().rotation_euler_angles()[1] / vnl_math::pi * 180;
132 double eulerGammaDegrees = transformConversionHelper->GetOrientation().rotation_euler_angles()[2] / vnl_math::pi * 180;
133
134 m_Controls->m_XRotSpinBox->setValue(eulerAlphaDegrees);
135 m_Controls->m_YRotSpinBox->setValue(eulerBetaDegrees);
136 m_Controls->m_ZRotSpinBox->setValue(eulerGammaDegrees);
137
138 //Update view
139 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
140}
141
142void QmitkInteractiveTransformationWidget::SetSynchronizedValuesToSliderAndSpinbox(QDoubleSpinBox* _spinbox, QSlider* _slider, double _value)
143{
144//block signals to avoid loop between slider and spinbox. Unblock at the end of the function!
145 _spinbox->blockSignals(true);
146 _slider->blockSignals(true);
147 _spinbox->setValue(_value);
148 _slider->setValue(_value);
149//unblock signals. See above, don't remove this line. Unblock at the end of the function!
150 _spinbox->blockSignals(false);//
151 _slider->blockSignals(false);//
152}
153
155{
156 //Set values to member variable
157 mitk::Point3D translationParams = m_Geometry->GetOrigin();
158 translationParams[0] = v;
159 m_Geometry->SetOrigin(translationParams);
160
161 SetSynchronizedValuesToSliderAndSpinbox(m_Controls->m_XTransSpinBox, m_Controls->m_XTransSlider, v);
162
163 //Update view
164 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
165
166}
167
169{
170 //Set values to member variable
171 mitk::Point3D translationParams = m_Geometry->GetOrigin();
172 translationParams[1] = v;
173 m_Geometry->SetOrigin(translationParams);
174
175 SetSynchronizedValuesToSliderAndSpinbox(m_Controls->m_YTransSpinBox, m_Controls->m_YTransSlider, v);
176
177 //Update view
178 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
179}
180
182{
183 //Set values to member variable
184 mitk::Point3D translationParams = m_Geometry->GetOrigin();
185 translationParams[2] = v;
186 m_Geometry->SetOrigin(translationParams);
187
188 SetSynchronizedValuesToSliderAndSpinbox(m_Controls->m_ZTransSpinBox, m_Controls->m_ZTransSlider, v);
189
190 //Update view
191 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
192}
193
195{
196 mitk::Vector3D rotationParams;
197 rotationParams[0] = v;
198 rotationParams[1] = m_Controls->m_YRotSpinBox->value();
199 rotationParams[2] = m_Controls->m_ZRotSpinBox->value();
200
201 SetSynchronizedValuesToSliderAndSpinbox(m_Controls->m_XRotSpinBox, m_Controls->m_XRotSlider, v);
202
203 this->Rotate(rotationParams);
204}
205
207{
208 mitk::Vector3D rotationParams;
209 rotationParams[0] = m_Controls->m_XRotSpinBox->value();
210 rotationParams[1] = v;
211 rotationParams[2] = m_Controls->m_ZRotSpinBox->value();
212
213 SetSynchronizedValuesToSliderAndSpinbox(m_Controls->m_YRotSpinBox, m_Controls->m_YRotSlider, v);
214
215 this->Rotate(rotationParams);
216}
217
219{
220 mitk::Vector3D rotationParams;
221 rotationParams[0] = m_Controls->m_XRotSpinBox->value();
222 rotationParams[1] = m_Controls->m_YRotSpinBox->value();
223 rotationParams[2] = v;
224
225 SetSynchronizedValuesToSliderAndSpinbox(m_Controls->m_ZRotSpinBox, m_Controls->m_ZRotSlider, v);
226
227 this->Rotate(rotationParams);
228}
229
230void QmitkInteractiveTransformationWidget::Rotate(mitk::Vector3D rotateVector)
231{
232 //0: from degrees to radians
233 double radianX = rotateVector[0] * vnl_math::pi / 180;
234 double radianY = rotateVector[1] * vnl_math::pi / 180;
235 double radianZ = rotateVector[2] * vnl_math::pi / 180;
236
237 //1: from euler angles to quaternion
238 mitk::Quaternion rotation(radianX, radianY, radianZ);
239
240 //2: Conversion to navigation data / transform
241 mitk::NavigationData::Pointer rotationTransform = mitk::NavigationData::New(m_Geometry->GetIndexToWorldTransform());
242 rotationTransform->SetOrientation(rotation);
243
244 m_Geometry->SetIndexToWorldTransform(rotationTransform->GetAffineTransform3D());
245
246 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
247}
248
250{
251 // reset the input to its initial state.
252 m_Geometry->SetIdentity();
253
254 //Update Sliders
255 this->SetValuesToGUI(m_Geometry->GetIndexToWorldTransform());
256 //Refresh view
257 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
258}
259
261{
262 // reset the input to its initial state.
263 m_Geometry->SetIndexToWorldTransformByVtkMatrix(m_ResetGeometry->GetVtkMatrix());
264
265 //Update Sliders
266 this->SetValuesToGUI(m_Geometry->GetIndexToWorldTransform());
267 //Refresh view
268 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
269}
270
272{
273 mitk::RenderingManager::GetInstance()->GetDataStorage()->Remove(m_ToolToEdit->GetDataNode());
274
275 mitk::AffineTransform3D::Pointer toolTip = m_Geometry->GetIndexToWorldTransform();
276 emit EditToolTipFinished(toolTip);
277 this->close();
278}
279
284
286{
287 QDialog::reject();
288
289 mitk::RenderingManager::GetInstance()->GetDataStorage()->Remove(m_ToolToEdit->GetDataNode());
290
291 emit EditToolTipFinished(nullptr);
292}
Ui::QmitkInteractiveTransformationWidgetControls * m_Controls
void SetDefaultRotation(const mitk::Quaternion _defaultValues)
void Rotate(mitk::Vector3D rotateVector)
Method performs the rotation.
QmitkInteractiveTransformationWidget(QWidget *parent=nullptr, Qt::WindowFlags f={})
mitk::BaseGeometry::Pointer m_Geometry
The geometry that is manipulated.
mitk::NavigationTool::Pointer m_ToolToEdit
this member holds a copy of the tool that should be edited for visualization
void EditToolTipFinished(mitk::AffineTransform3D::Pointer toolTip)
mitk::BaseGeometry::Pointer m_ResetGeometry
Lifeline to reset to the original geometry.
void SetDefaultOffset(const mitk::Point3D _defaultValues)
void SetToolToEdit(const mitk::NavigationTool::Pointer _tool)
int close(int)
Closes the file descriptor fd.