MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
QmitkPolhemusTrackerWidget.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#include <QFileDialog>
16#include <QScrollBar>
17#include <QMessageBox>
18
19#include <itksys/SystemTools.hxx>
20#include <Poco/Path.h>
21#include <QSettings>
22
23#include <mitkBaseRenderer.h>
24#include <mitkCameraController.h>
25#include "vtkRenderer.h"
26#include "vtkCamera.h"
27
28const std::string QmitkPolhemusTrackerWidget::VIEW_ID = "org.mitk.views.PolhemusTrackerWidget";
29
32 , m_Controls(nullptr)
33{
34}
36{
38 CreateQtPartControl(this);
39
40 SetAdvancedSettingsEnabled(false);
41 on_m_AdvancedSettings_clicked(); //hide advanced settings on setup
42}
43
48
49void QmitkPolhemusTrackerWidget::CreateQtPartControl(QWidget *parent)
50{
51 if (!m_Controls)
52 {
53 // create GUI widgets
54 m_Controls = new Ui::QmitkPolhemusTrackerWidget;
55 m_Controls->setupUi(parent);
56 }
57}
58
60{
61 this->m_TrackingDevice = nullptr;
62 MITK_DEBUG<<"Resetting Polhemus Tracking Device, because tool storage changed.";
63}
64
65void QmitkPolhemusTrackerWidget::CreateConnections()
66{
67 if (m_Controls)
68 {
69 connect((QObject*)(m_Controls->m_hemisphereTracking), SIGNAL(clicked()), this, SLOT(on_m_hemisphereTracking_clicked()));
70 connect((QObject*)(m_Controls->m_ToggleHemisphere), SIGNAL(clicked()), this, SLOT(on_m_ToggleHemisphere_clicked()));
71 connect((QObject*)(m_Controls->m_SetHemisphere), SIGNAL(clicked()), this, SLOT(on_m_SetHemisphere_clicked()));
72 connect((QObject*)(m_Controls->m_GetHemisphere), SIGNAL(clicked()), this, SLOT(on_m_GetHemisphere_clicked()));
73 connect((QObject*)(m_Controls->m_AdjustHemisphere), SIGNAL(clicked()), this, SLOT(on_m_AdjustHemisphere_clicked()));
74 connect((QObject*)(m_Controls->m_AdvancedSettings), SIGNAL(clicked()), this, SLOT(on_m_AdvancedSettings_clicked()));
75 connect((QObject*)(m_Controls->m_ToggleToolTipCalibration), SIGNAL(clicked()), this, SLOT(on_m_ToggleToolTipCalibration_clicked()));
76 }
77}
78
79mitk::TrackingDevice::Pointer QmitkPolhemusTrackerWidget::GetTrackingDevice()
80{
81 if (m_TrackingDevice.IsNull())
82 {
83 m_TrackingDevice = mitk::PolhemusTrackingDevice::New();
84 m_TrackingDevice->SetHemisphereTrackingEnabled(m_Controls->m_hemisphereTracking->isChecked());
85 }
86
87 return static_cast<mitk::TrackingDevice::Pointer>(m_TrackingDevice);
88}
89
91{
93 clonedWidget->Initialize();
94 return clonedWidget;
95}
96
98{
99 m_TrackingDevice->SetHemisphereTrackingEnabled(m_Controls->m_hemisphereTracking->isChecked());
100}
101
103{
104 // Index 0 == All Tools == -1 for Polhemus interface; Index 2 == Tool 2 == 1 for Polhemus; etc...
105 m_TrackingDevice->ToggleHemisphere(GetSelectedToolIndex());
106
107 MITK_INFO << "Toggle Hemisphere for tool " << m_Controls->m_ToolSelection->currentText().toStdString();
108}
109
111{
112 mitk::Vector3D _hemisphere;
113 mitk::FillVector3D(_hemisphere, m_Controls->m_Hemisphere_X->value(), m_Controls->m_Hemisphere_Y->value(), m_Controls->m_Hemisphere_Z->value());
114 m_TrackingDevice->SetHemisphere(GetSelectedToolIndex(), _hemisphere);
115
116 //If you set a hemisphere vector which is unequal (0|0|0), this means, that there is no hemisphere tracking any more
117 //disable the checkbox in case it was on before, so that it can be reactivated...
118 if (_hemisphere.GetNorm() != 0)
119 m_Controls->m_hemisphereTracking->setChecked(false);
120
121 MITK_INFO << "Hemisphere set for tool " << m_Controls->m_ToolSelection->currentText().toStdString();
122}
123
125{
126 mitk::Vector3D _hemisphere = m_TrackingDevice->GetHemisphere(GetSelectedToolIndex());
127 m_Controls->m_Hemisphere_X->setValue(_hemisphere[0]);
128 m_Controls->m_Hemisphere_Y->setValue(_hemisphere[1]);
129 m_Controls->m_Hemisphere_Z->setValue(_hemisphere[2]);
130
131 QString label;
132
133 if (m_TrackingDevice->GetHemisphereTrackingEnabled(GetSelectedToolIndex()))
134 {
135 label = "HemisphereTracking is ON for tool ";
136 label.append(m_Controls->m_ToolSelection->currentText());
137 }
138 else if (GetSelectedToolIndex() == -1)
139 {
140 label = "HemisphereTracking is OFF for at least one tool.";
141 }
142 else
143 {
144 label = "HemisphereTracking is OFF for tool ";
145 label.append(m_Controls->m_ToolSelection->currentText());
146 }
147
148 m_Controls->m_StatusLabelHemisphereTracking->setText(label);
149
150 MITK_INFO << "Updated SpinBox for Hemisphere of tool " << m_Controls->m_ToolSelection->currentText().toStdString();
151}
152
154{
155 int _tool = GetSelectedToolIndex();
156 QMessageBox msgBox;
157 QString _text;
158 if (_tool == -1)
159 {
160 _text.append("Adjusting hemisphere for all tools.");
161 msgBox.setText(_text);
162 _text.clear();
163 _text = tr("Please make sure, that the entire tools (including tool tip AND sensor) are placed in the positive x hemisphere. Press 'Adjust hemisphere' if you are ready.");
164 msgBox.setInformativeText(_text);
165 }
166 else
167 {
168 _text.append("Adjusting hemisphere for tool '");
169 _text.append(m_Controls->m_ToolSelection->currentText());
170 _text.append(tr("' at port %2.").arg(_tool));
171 msgBox.setText(_text);
172 _text.clear();
173 _text = tr("Please make sure, that the entire tool (including tool tip AND sensor) is placed in the positive x hemisphere. Press 'Adjust hemisphere' if you are ready.");
174 msgBox.setInformativeText(_text);
175 }
176
177 QPushButton *adjustButton = msgBox.addButton(tr("Adjust hemisphere"), QMessageBox::ActionRole);
178 QPushButton *cancelButton = msgBox.addButton(QMessageBox::Cancel);
179 msgBox.exec();
180 if (msgBox.clickedButton() == adjustButton) {
181 // adjust
182 m_TrackingDevice->AdjustHemisphere(_tool);
183 MITK_INFO << "Adjusting Hemisphere for tool " << m_Controls->m_ToolSelection->currentText().toStdString();
184 }
185 else if (msgBox.clickedButton() == cancelButton) {
186 // abort
187 MITK_INFO << "Cancel 'Adjust hemisphere'. No harm done...";
188 }
189}
190
192{
193 if (m_Controls->m_ToolSelection->currentIndex() != 0)
194 {
195 mitk::PolhemusTool* _tool = dynamic_cast<mitk::PolhemusTool*> (this->m_TrackingDevice->GetToolByName(m_Controls->m_ToolSelection->currentText().toStdString()));
196 auto tip = _tool->GetToolTipPosition().GetVectorFromOrigin()*(-1.);
197 auto tipPoint = mitk::Point3D(tip);
198 mitk::Quaternion quat = _tool->GetToolAxisOrientation().inverse();
199 _tool->SetToolTipPosition(tipPoint, quat);
200 }
201 else
202 {
203 for (int i = 0; i < m_TrackingDevice->GetToolCount(); ++i)
204 {
205 mitk::PolhemusTool* _tool = dynamic_cast<mitk::PolhemusTool*> (this->m_TrackingDevice->GetTool(i));
206 auto tip = _tool->GetToolTipPosition().GetVectorFromOrigin()*(-1.);
207 auto tipPoint = mitk::Point3D(tip);
208 mitk::Quaternion quat = _tool->GetToolAxisOrientation().inverse();
209 _tool->SetToolTipPosition(tipPoint, quat);
210 }
211 }
212}
213
215{
216 if (!_success)
217 {
218 this->m_TrackingDevice = nullptr;
219 return;
220 }
221
222 SetAdvancedSettingsEnabled(true);
223
224 if (m_TrackingDevice->GetToolCount() != m_Controls->m_ToolSelection->count())
225 {
226 m_Controls->m_ToolSelection->clear();
227
228 m_Controls->m_ToolSelection->addItem("All Tools");
229
230 for (int i = 0; i < m_TrackingDevice->GetToolCount(); ++i)
231 {
232 m_Controls->m_ToolSelection->addItem(m_TrackingDevice->GetTool(i)->GetToolName());
233 }
234 }
235}
236
238{
239 if (!_success)
240 return;
241
242 auto allRenderWindows = mitk::BaseRenderer::GetAll3DRenderWindows();
243 for (auto mapit = allRenderWindows.begin(); mapit != allRenderWindows.end(); ++mapit)
244 {
245 // rotate 3D render windows, so that the view matches the sensor. Positive x == right, y == front, z == down;
246 mapit->second->GetCameraController()->SetViewToPosterior();
247 mapit->second->GetVtkRenderer()->GetActiveCamera()->SetViewUp(0, 0, -1);
248 }
249}
250
252{
253 if (!_success)
254 return;
255 SetAdvancedSettingsEnabled(false);
256}
257
258void QmitkPolhemusTrackerWidget::SetAdvancedSettingsEnabled(bool _enable)
259{
260 m_Controls->m_ToolSelection->setEnabled(_enable);
261 m_Controls->label_toolsToChange->setEnabled(_enable);
262 m_Controls->label_UpdateOnRequest->setEnabled(_enable);
263 m_Controls->m_GetHemisphere->setEnabled(_enable);
264 m_Controls->m_Hemisphere_X->setEnabled(_enable);
265 m_Controls->m_Hemisphere_Y->setEnabled(_enable);
266 m_Controls->m_Hemisphere_Z->setEnabled(_enable);
267 m_Controls->m_SetHemisphere->setEnabled(_enable);
268 m_Controls->m_ToggleHemisphere->setEnabled(_enable);
269 m_Controls->m_AdjustHemisphere->setEnabled(_enable);
270 m_Controls->m_ToggleToolTipCalibration->setEnabled(_enable);
271}
272
274{
275 bool _enable = m_Controls->m_AdvancedSettings->isChecked();
276 m_Controls->m_ToolSelection->setVisible(_enable);
277 m_Controls->label_toolsToChange->setVisible(_enable);
278 m_Controls->label_UpdateOnRequest->setVisible(_enable);
279 m_Controls->m_GetHemisphere->setVisible(_enable);
280 m_Controls->m_Hemisphere_X->setVisible(_enable);
281 m_Controls->m_Hemisphere_Y->setVisible(_enable);
282 m_Controls->m_Hemisphere_Z->setVisible(_enable);
283 m_Controls->m_SetHemisphere->setVisible(_enable);
284 m_Controls->m_ToggleHemisphere->setVisible(_enable);
285 m_Controls->m_AdjustHemisphere->setVisible(_enable);
286 m_Controls->m_ToggleToolTipCalibration->setVisible(_enable);
287 m_Controls->m_StatusLabelHemisphereTracking->setVisible(_enable);
288}
289
290int QmitkPolhemusTrackerWidget::GetSelectedToolIndex()
291{
292 // Index 0 == All Tools == -1 for Polhemus interface; Index 1 == Tool 1 == 1 for Polhemus Interface; etc...
293 int _index = m_Controls->m_ToolSelection->currentIndex() - 1;
294 if (_index != -1)
295 {
296 //we need to find the internal Polhemus index for this tool. This is stored in the identifier of a navigation tool or as Port in PolhemusTool.
297 mitk::PolhemusTool* _tool = dynamic_cast<mitk::PolhemusTool*>(m_TrackingDevice->GetToolByName(m_Controls->m_ToolSelection->currentText().toStdString()));
298 _index = _tool->GetToolPort();
299 }
300 return _index;
301}
Abstract class to configure a tracking device. Inherited widgets should be registered in the Microser...
PERSISTENCE_GET_SERVICE_METHOD_MACRO void InitializeSuperclassWidget()
Implementation of a configuration widget for Polhemus Tracking Devices.
virtual void Initialize()
Subclass must implement this method to return a pointer to a copy of the object. Please don't forget ...
virtual mitk::TrackingDevice::Pointer GetTrackingDevice()
virtual void OnDisconnected(bool _success)
This function is called, when in the TrackingToolboxView "Disconnect" was clicked and the device is s...
virtual QmitkPolhemusTrackerWidget * Clone(QWidget *parent) const
Subclass must implement this method to return a pointer to a copy of the object. Please don't forget ...
Ui::QmitkPolhemusTrackerWidget * m_Controls
virtual void OnConnected(bool _success)
This function is called, when in the TrackingToolboxView "Connect" was clicked and the device is succ...
virtual void OnToolStorageChanged()
This function is called, when anything in the ToolStorage changed, e.g. AddTool or EditTool....
virtual void OnStartTracking(bool _success)
This function is called, when in the TrackingToolboxView "Start Tracking" was clicked and the device ...
mitk::PolhemusTrackingDevice::Pointer m_TrackingDevice
QmitkPolhemusTrackerWidget(QWidget *parent=nullptr, Qt::WindowFlags f={})
An object of this class represents a tool of a Polhemus tracking device. A tool has to be added to a ...
virtual int GetToolPort()
Sets the port of the tool. (e.g. 1 for port "SENS 1" etc.)
Point3D GetToolTipPosition() const
returns the tool tip in tool coordinates, which where set by SetToolTip
virtual void SetToolTipPosition(Point3D toolTipPosition, Quaternion orientation, ScalarType eps=0.0)
defines a tool tip for this tool in tool coordinates. GetPosition() and GetOrientation() return the d...
Quaternion GetToolAxisOrientation() const
returns the transformation of the tool axis with respect to the MITK-IGT main tool axis (0,...