MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
QmitkMITKIGTTrackingToolboxView.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
13// Blueberry
14#include <berryISelectionService.h>
15#include <berryIWorkbenchWindow.h>
16
17// Qmitk
19
20// Qt
21#include <QMessageBox>
22#include <QSettings>
23#include <QFileDialog>
24
25// MITK
28#include <mitkNodePredicateNot.h>
29#include <mitkNodePredicateProperty.h>
31#include <mitkIOUtil.h>
32#include <mitkLogBackend.h>
36
37//for exceptions
38#include <mitkIGTException.h>
39#include <mitkIGTIOException.h>
40
41#include "mitkPluginActivator.h"
42
43const std::string QmitkMITKIGTTrackingToolboxView::VIEW_ID = "org.mitk.views.mitkigttrackingtoolbox";
44
46 : QmitkAbstractView()
47 , m_Controls(nullptr)
48 , m_DeviceTypeCollection(nullptr)
49 , m_ToolProjectionNode(nullptr)
50{
51 m_TrackingLoggingTimer = new QTimer(this);
52 m_TrackingRenderTimer = new QTimer(this);
53 m_TimeoutTimer = new QTimer(this);
54 m_tracking = false;
55 m_connected = false;
56 m_logging = false;
57 m_ShowHideToolAxis = false;
59 m_SimpleModeEnabled = false;
60 m_NeedleProjectionFilter = mitk::NeedleProjectionFilter::New();
61
62 //create filename for autosaving of tool storage
63 auto loggingPathWithoutFilename = QString::fromStdString(mitk::LogBackend::GetLogFile());
64 if (!loggingPathWithoutFilename.isEmpty()) //if there already is a path for the MITK logging file use this one
65 {
66 //extract path from path+filename (if someone knows a better way to do this feel free to change it)
67 int lengthOfFilename = QFileInfo(QString::fromStdString(mitk::LogBackend::GetLogFile())).fileName().size();
68 loggingPathWithoutFilename.resize(loggingPathWithoutFilename.size() - lengthOfFilename);
69 m_AutoSaveFilename = loggingPathWithoutFilename + "TrackingToolboxAutoSave.IGTToolStorage";
70 }
71 else //if not: use a temporary path from IOUtil
72 {
73 m_AutoSaveFilename = QString(mitk::IOUtil::GetTempPath().c_str()) + "TrackingToolboxAutoSave.IGTToolStorage";
74 }
75 MITK_INFO("IGT Tracking Toolbox") << "Filename for auto saving of IGT ToolStorages: " << m_AutoSaveFilename.toStdString();
76
78 //initialize worker thread
79 m_WorkerThread = new QThread();
82
83 ctkPluginContext* pluginContext = mitk::PluginActivator::GetContext();
84 if (pluginContext)
85 {
86 QString interfaceName = QString::fromStdString(us_service_interface_iid<mitk::TrackingDeviceTypeCollection>());
87 QList<ctkServiceReference> serviceReference = pluginContext->getServiceReferences(interfaceName);
88
89 if (serviceReference.size() > 0)
90 {
91 m_DeviceTypeServiceReference = serviceReference.at(0);
92 const ctkServiceReference& r = serviceReference.at(0);
93 m_DeviceTypeCollection = pluginContext->getService<mitk::TrackingDeviceTypeCollection>(r);
94 }
95 else
96 {
97 MITK_INFO << "No Tracking Device Collection!";
98 }
99 }
100}
101
103{
104 this->StoreUISettings();
106 m_TrackingRenderTimer->stop();
107 m_TimeoutTimer->stop();
110 delete m_TimeoutTimer;
111 try
112 {
114 // wait for thread to finish
115 m_WorkerThread->terminate();
116 m_WorkerThread->wait();
117 //clean up worker thread
118 if (m_WorkerThread) { delete m_WorkerThread; }
119 if (m_Worker) { delete m_Worker; }
121
122 //remove the tracking volume
123 this->GetDataStorage()->Remove(m_TrackingVolumeNode);
124 //unregister microservices
125 if (m_toolStorage) { m_toolStorage->UnRegisterMicroservice(); }
126
127 if (m_IGTLMessageProvider.IsNotNull()){ m_IGTLMessageProvider->UnRegisterMicroservice(); }
128 }
129 catch (std::exception& e) { MITK_WARN << "Unexpected exception during clean up of tracking toolbox view: " << e.what(); }
130 catch (...) { MITK_WARN << "Unexpected unknown error during clean up of tracking toolbox view!"; }
131 //store tool storage and UI settings for persistence
132 this->AutoSaveToolStorage();
133 this->StoreUISettings();
134
135 m_DeviceTypeCollection = nullptr;
136 mitk::PluginActivator::GetContext()->ungetService(m_DeviceTypeServiceReference);
137}
138
140{
141 // build up qt view, unless already done
142 if (!m_Controls)
143 {
144 // create GUI widgets from the Qt Designer's .ui file
145 m_Controls = new Ui::QmitkMITKIGTTrackingToolboxViewControls;
146 m_Controls->setupUi(parent);
147
148 //create connections
149 connect(m_Controls->m_LoadTools, SIGNAL(clicked()), this, SLOT(OnLoadTools()));
150 connect(m_Controls->m_ConnectDisconnectButton, SIGNAL(clicked()), this, SLOT(OnConnectDisconnect()));
151 connect(m_Controls->m_StartStopTrackingButton, SIGNAL(clicked()), this, SLOT(OnStartStopTracking()));
152 connect(m_Controls->m_ConnectSimpleMode, SIGNAL(clicked()), this, SLOT(OnConnectDisconnect()));
153 connect(m_Controls->m_StartTrackingSimpleMode, SIGNAL(clicked()), this, SLOT(OnStartStopTracking()));
154 connect(m_Controls->m_FreezeUnfreezeTrackingButton, SIGNAL(clicked()), this, SLOT(OnFreezeUnfreezeTracking()));
155 connect(m_TrackingLoggingTimer, SIGNAL(timeout()), this, SLOT(UpdateLoggingTrackingTimer()));
156 connect(m_TrackingRenderTimer, SIGNAL(timeout()), this, SLOT(UpdateRenderTrackingTimer()));
157 connect(m_TimeoutTimer, SIGNAL(timeout()), this, SLOT(OnTimeOut()));
158 connect(m_Controls->m_ChooseFile, SIGNAL(clicked()), this, SLOT(OnChooseFileClicked()));
159 connect(m_Controls->m_StartLogging, SIGNAL(clicked()), this, SLOT(StartLogging()));
160 connect(m_Controls->m_StopLogging, SIGNAL(clicked()), this, SLOT(StopLogging()));
161 connect(m_Controls->m_VolumeSelectionBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(OnTrackingVolumeChanged(QString)));
162 connect(m_Controls->m_ShowTrackingVolume, SIGNAL(clicked()), this, SLOT(OnShowTrackingVolumeChanged()));
163 connect(m_Controls->m_AutoDetectTools, SIGNAL(clicked()), this, SLOT(OnAutoDetectTools()));
164 connect(m_Controls->m_ResetTools, SIGNAL(clicked()), this, SLOT(OnResetTools()));
165 connect(m_Controls->m_AddSingleTool, SIGNAL(clicked()), this, SLOT(OnAddSingleTool()));
166 connect(m_Controls->m_NavigationToolCreationWidget, SIGNAL(NavigationToolFinished()), this, SLOT(OnAddSingleToolFinished()));
167 connect(m_Controls->m_NavigationToolCreationWidget, SIGNAL(Canceled()), this, SLOT(OnAddSingleToolCanceled()));
168 connect(m_Controls->m_CsvFormat, SIGNAL(clicked()), this, SLOT(OnToggleFileExtension()));
169 connect(m_Controls->m_XmlFormat, SIGNAL(clicked()), this, SLOT(OnToggleFileExtension()));
170 connect(m_Controls->m_UseDifferentUpdateRates, SIGNAL(clicked()), this, SLOT(OnToggleDifferentUpdateRates()));
171 connect(m_Controls->m_RenderUpdateRate, SIGNAL(valueChanged(int)), this, SLOT(OnChangeRenderUpdateRate()));
172 connect(m_Controls->m_DisableAllTimers, SIGNAL(stateChanged(int)), this, SLOT(EnableDisableTimerButtons(int)));
173 connect(m_Controls->m_advancedUI, SIGNAL(clicked()), this, SLOT(OnToggleAdvancedSimpleMode()));
174 connect(m_Controls->m_SimpleUI, SIGNAL(clicked()), this, SLOT(OnToggleAdvancedSimpleMode()));
175 connect(m_Controls->showHideToolProjectionCheckBox, SIGNAL(clicked()), this, SLOT(OnShowHideToolProjectionClicked()));
176 connect(m_Controls->showHideToolAxisCheckBox, SIGNAL(clicked()), this, SLOT(OnShowHideToolAxisClicked()));
177
178 connect(m_Controls->m_toolselector, SIGNAL(currentIndexChanged(int)), this, SLOT(SelectToolProjection(int)));
179
180
181
182
183 //connections for the tracking device configuration widget
184 connect(m_Controls->m_ConfigurationWidget, SIGNAL(TrackingDeviceSelectionChanged()), this, SLOT(OnTrackingDeviceChanged()));
185
186
188 //connect worker thread
189 connect(m_Worker, SIGNAL(AutoDetectToolsFinished(bool, QString)), this, SLOT(OnAutoDetectToolsFinished(bool, QString)));
190 connect(m_Worker, SIGNAL(ConnectDeviceFinished(bool, QString)), this, SLOT(OnConnectFinished(bool, QString)));
191 connect(m_Worker, SIGNAL(StartTrackingFinished(bool, QString)), this, SLOT(OnStartTrackingFinished(bool, QString)));
192 connect(m_Worker, SIGNAL(StopTrackingFinished(bool, QString)), this, SLOT(OnStopTrackingFinished(bool, QString)));
193 connect(m_Worker, SIGNAL(DisconnectDeviceFinished(bool, QString)), this, SLOT(OnDisconnectFinished(bool, QString)));
194 connect(m_WorkerThread, SIGNAL(started()), m_Worker, SLOT(ThreadFunc()));
195
196 connect(m_Worker, SIGNAL(ConnectDeviceFinished(bool, QString)), m_Controls->m_ConfigurationWidget, SLOT(OnConnected(bool)));
197 connect(m_Worker, SIGNAL(DisconnectDeviceFinished(bool, QString)), m_Controls->m_ConfigurationWidget, SLOT(OnDisconnected(bool)));
198 connect(m_Worker, SIGNAL(StartTrackingFinished(bool, QString)), m_Controls->m_ConfigurationWidget, SLOT(OnStartTracking(bool)));
199 connect(m_Worker, SIGNAL(StopTrackingFinished(bool, QString)), m_Controls->m_ConfigurationWidget, SLOT(OnStopTracking(bool)));
200
201
202 //Add Listener, so that we know when the toolStorage changed.
203 std::string m_Filter = "(" + us::ServiceConstants::OBJECTCLASS() + "=" + "org.mitk.services.NavigationToolStorage" + ")";
204 mitk::PluginActivator::GetContext()->connectServiceListener(this, "OnToolStorageChanged", QString(m_Filter.c_str()));
205
206 //move the worker to the thread
207 m_Worker->moveToThread(m_WorkerThread);
209
210 //initialize widgets
211 m_Controls->m_TrackingToolsStatusWidget->SetShowPositions(true);
212 m_Controls->m_TrackingToolsStatusWidget->SetTextAlignment(Qt::AlignLeft);
213 m_Controls->m_simpleWidget->setVisible(false);
214
215 //initialize tracking volume node
216 m_TrackingVolumeNode = mitk::DataNode::New();
217 m_TrackingVolumeNode->SetName("TrackingVolume");
218 m_TrackingVolumeNode->SetBoolProperty("Backface Culling", true);
219 mitk::Color red;
220 red.SetRed(1);
221 m_TrackingVolumeNode->SetColor(red);
222
223 //initialize buttons
224 m_Controls->m_AutoDetectTools->setVisible(false); //only visible if supported by tracking device
225 m_Controls->m_StartStopTrackingButton->setEnabled(false);
226 m_Controls->m_StartTrackingSimpleMode->setEnabled(false);
227 m_Controls->m_FreezeUnfreezeTrackingButton->setEnabled(false);
228
229 //initialize warning labels
230 m_Controls->m_RenderWarningLabel->setVisible(false);
231 m_Controls->m_TrackingFrozenLabel->setVisible(false);
232
233
234 //initialize projection buttons
235 //first it is disabled when the tool is connected check box for projection and axis is enabled
236 m_Controls->showHideToolAxisCheckBox->setEnabled(false);
237 m_Controls->showHideToolProjectionCheckBox->setEnabled(false);
238 m_Controls->m_toolselector->setEnabled(false);
239
240 //Update List of available models for selected tool.
241 std::vector<mitk::TrackingDeviceData> Compatibles;
242 if ((m_Controls == nullptr) || //check all these stuff for NULL, latterly this causes crashes from time to time
243 (m_Controls->m_ConfigurationWidget == nullptr) ||
244 (m_Controls->m_ConfigurationWidget->GetTrackingDevice().IsNull()))
245 {
246 MITK_ERROR << "Couldn't get current tracking device or an object is nullptr, something went wrong!";
247 return;
248 }
249 else
250 {
251 Compatibles = m_DeviceTypeCollection->GetDeviceDataForLine(m_Controls->m_ConfigurationWidget->GetTrackingDevice()->GetType());
252 }
253 m_Controls->m_VolumeSelectionBox->clear();
254 for (std::size_t i = 0; i < Compatibles.size(); i++)
255 {
256 m_Controls->m_VolumeSelectionBox->addItem(Compatibles[i].Model.c_str());
257 }
258
259 //initialize tool storage
260 m_toolStorage = mitk::NavigationToolStorage::New(GetDataStorage());
261 m_toolStorage->SetName("TrackingToolbox Default Storage");
262 m_toolStorage->RegisterAsMicroservice();
263
264 //set home directory as default path for logfile
265 m_Controls->m_LoggingFileName->setText(QDir::toNativeSeparators(QDir::homePath()) + QDir::separator() + "logfile.csv");
266
267 //tracking device may be changed already by the persistence of the
268 //QmitkTrackingDeciveConfigurationWidget
270
271 this->LoadUISettings();
272
273 //add tracking volume node only to data storage
274 this->GetDataStorage()->Add(m_TrackingVolumeNode);
275 if (!m_Controls->m_ShowTrackingVolume->isChecked()) m_TrackingVolumeNode->SetOpacity(0.0);
276 else m_TrackingVolumeNode->SetOpacity(0.25);
277
278 //Update List of available models for selected tool.
279 m_Controls->m_VolumeSelectionBox->clear();
280 for (std::size_t i = 0; i < Compatibles.size(); i++)
281 {
282 m_Controls->m_VolumeSelectionBox->addItem(Compatibles[i].Model.c_str());
283 }
284 }
285}
286
288{
289 //read in filename
290 QString filename = QFileDialog::getOpenFileName(nullptr, tr("Open Tool Storage"), "/", tr("Tool Storage Files (*.IGTToolStorage)"));
291 if (filename.isNull()) return;
292
293 //read tool storage from disk
294 std::string errorMessage = "";
295 mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(GetDataStorage());
296 // try-catch block for exceptions
297 try
298 {
299 this->ReplaceCurrentToolStorage(myDeserializer->Deserialize(filename.toStdString()), filename.toStdString());
300 }
301 catch (mitk::IGTException&)
302 {
303 std::string errormessage = "Error during loading the tool storage file. Please only load tool storage files created with the NavigationToolManager view.";
304 QMessageBox::warning(nullptr, "Tool Storage Loading Error", errormessage.c_str());
305 return;
306 }
307
308 if (m_toolStorage->isEmpty())
309 {
310 errorMessage = myDeserializer->GetErrorMessage();
311 MessageBox(errorMessage);
312 return;
313 }
314
315 //update label
316 UpdateToolStorageLabel(filename);
317
318 //update tool preview
319 m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels();
320 m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage);
321
322 //save filename for persistent storage
323 m_ToolStorageFilename = filename;
324}
325
327{
328 //remove data nodes of surfaces from data storage to clean up
329 for (unsigned int i = 0; i < m_toolStorage->GetToolCount(); i++)
330 {
331 this->GetDataStorage()->Remove(m_toolStorage->GetTool(i)->GetDataNode());
332 }
333 this->ReplaceCurrentToolStorage(mitk::NavigationToolStorage::New(GetDataStorage()), "TrackingToolbox Default Storage");
334 m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels();
335 QString toolLabel = QString("<none>");
336 m_Controls->m_ToolLabel->setText(toolLabel);
338
340}
341
343{
344 if (!m_connected)
345 {
346 MITK_WARN << "Can't start tracking if no device is connected. Aborting";
347 return;
348 }
349 if (m_tracking) { OnStopTracking(); }
350 else { OnStartTracking(); }
351}
352
354{
355 if (m_Controls->m_FreezeUnfreezeTrackingButton->text() == "Freeze Tracking")
356 {
358 m_Controls->m_FreezeUnfreezeTrackingButton->setText("Unfreeze Tracking");
359 m_Controls->m_TrackingFrozenLabel->setVisible(true);
360 }
361 else if (m_Controls->m_FreezeUnfreezeTrackingButton->text() == "Unfreeze Tracking")
362 {
363 m_Worker->GetTrackingDeviceSource()->UnFreeze();
364 m_Controls->m_FreezeUnfreezeTrackingButton->setText("Freeze Tracking");
365 m_Controls->m_TrackingFrozenLabel->setVisible(false);
366 }
367}
368
370{
371 mitk::DataNode::Pointer toolnode = m_toolStorage->GetTool(index)->GetDataNode();
372 QString ToolProjectionName = "ToolProjection" + QString::number(index);
373 m_ToolProjectionNode = this->GetDataStorage()->GetNamedNode(ToolProjectionName.toStdString());
374 //If node does not exist, create the node for the Pointset
375 if (m_ToolProjectionNode.IsNull())
376 {
377 m_ToolProjectionNode = mitk::DataNode::New();
378 m_ToolProjectionNode->SetName(ToolProjectionName.toStdString());
379 if (index < static_cast<int>(m_NeedleProjectionFilter->GetNumberOfInputs()))
380 {
381 m_NeedleProjectionFilter->SelectInput(index);
382 m_NeedleProjectionFilter->Update();
383 m_ToolProjectionNode->SetData(m_NeedleProjectionFilter->GetProjection());
384
385 m_ToolProjectionNode->SetBoolProperty("show contour", true);
386 this->GetDataStorage()->Add(m_ToolProjectionNode, toolnode);
387 }
388 // this->FireNodeSelected(node);
389 }
390 else
391 {
392 m_ToolProjectionNode->SetBoolProperty("show contour", true);
393 }
394}
395
397{
398 for (size_t i = 0; i < m_toolStorage->GetToolCount(); i++)
399 {
400 QString toolProjectionName = "ToolProjection" + QString::number(i);
401
402 mitk::DataNode::Pointer node = this->GetDataStorage()->GetNamedNode(toolProjectionName.toStdString());
403
404 //Deactivate and hide the tool projection
405 if (!node.IsNull())
406 {
407 this->GetDataStorage()->Remove(node);
408 }
409 }
410}
411
413{
414 if (m_Controls->showHideToolProjectionCheckBox->isChecked())
415 {
416 //Deactivate and hide the tool projection
417 if (!m_ToolProjectionNode.IsNull())
418 {
419 this->GetDataStorage()->Remove(m_ToolProjectionNode);
420 }
421
422 if (m_NeedleProjectionFilter.IsNotNull())
423 {
424 m_NeedleProjectionFilter->Update();
425 }
426 //Refresh the view and the status widget
427 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
428 // Show the tool projection for the currently selected tool
430 }
431}
432
434{
435 int index = m_Controls->m_toolselector->currentIndex();
436 //Activate and show the tool projection
437 if (m_Controls->showHideToolProjectionCheckBox->isChecked())
438 {
439 ShowToolProjection(index);
440 m_Controls->showHideToolAxisCheckBox->setEnabled(true);
441 }
442 else
443 {
445 m_Controls->showHideToolAxisCheckBox->setEnabled(false);
446 }
447 if(m_NeedleProjectionFilter->GetNumberOfInputs())
448 {
449 m_NeedleProjectionFilter->Update();
450 }
451 //Refresh the view and the status widget
452 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
453// m_Controls->m_TrackingToolsStatusWidget->Refresh();
454}
455
457{
458 if( !m_ShowHideToolAxis )
459 {
460 //Activate and show the tool axis
461 m_NeedleProjectionFilter->ShowToolAxis(true);
462 m_ShowHideToolAxis = true;
463 }
464 else
465 {
466 //Deactivate and hide the tool axis
467 m_NeedleProjectionFilter->ShowToolAxis(false);
468 m_NeedleProjectionFilter->GetProjection()->RemovePointIfExists(2);
469 m_ShowHideToolAxis = false;
470 }
471 //Update the filter
472 if(m_NeedleProjectionFilter->GetNumberOfInputs())
473 {
474 m_NeedleProjectionFilter->Update();
475 }
476 //Refresh the view and the status widget
477 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
478 // m_Controls->m_TrackingToolsStatusWidget->Refresh();
479}
480
486
488{
489 MITK_DEBUG << "Connect Clicked";
490 //check if everything is ready to start tracking
491 if (this->m_toolStorage.IsNull())
492 {
493 MessageBox("Error: No Tools Loaded Yet!");
494 return;
495 }
496 else if (this->m_toolStorage->GetToolCount() == 0)
497 {
498 MessageBox("Error: No Way To Track Without Tools!");
499 return;
500 }
501
502 //parse tracking device data
504 QString qstr = m_Controls->m_VolumeSelectionBox->currentText();
505 if ((!qstr.isNull()) || (!qstr.isEmpty())) {
506 std::string str = qstr.toStdString();
507 data = m_DeviceTypeCollection->GetDeviceDataByName(str); //Data will be set later, after device generation
508 }
509
511 //initialize worker thread
513 m_Worker->SetTrackingDevice(this->m_Controls->m_ConfigurationWidget->GetTrackingDevice());
514 m_Worker->SetInverseMode(m_Controls->m_InverseMode->isChecked());
517 //start worker thread
518 m_WorkerThread->start();
520
521
522 //enable checkboxes for projection and tool axis
523 m_Controls->showHideToolAxisCheckBox->setEnabled(true);
524 m_Controls->showHideToolProjectionCheckBox->setEnabled(true);
525 m_Controls->m_toolselector->setEnabled(true);
526
527
528
529 //disable buttons
530 this->m_Controls->m_MainWidget->setEnabled(false);
531}
532
534{
535 bool enableBool = enable;
536 m_Controls->m_UpdateRateOptionsGroupBox->setEnabled(!enableBool);
537 m_Controls->m_RenderWarningLabel->setVisible(enableBool);
538}
539
540void QmitkMITKIGTTrackingToolboxView::OnConnectFinished(bool success, QString errorMessage)
541{
542 m_WorkerThread->quit();
543 m_WorkerThread->wait();
544
545 //enable buttons
546 this->m_Controls->m_MainWidget->setEnabled(true);
547
548 if (!success)
549 {
550 MITK_WARN << errorMessage.toStdString();
551 MessageBox(errorMessage.toStdString());
552 return;
553 }
554
556 //get data from worker thread
557 m_TrackingDeviceData = m_Worker->GetTrackingDeviceData();
558 m_ToolVisualizationFilter = m_Worker->GetToolVisualizationFilter();
559 if( m_ToolVisualizationFilter.IsNotNull() )
560 {
561 //Connect the NeedleProjectionFilter to the ToolVisualizationFilter as third filter of the IGT pipeline
563 if (m_Controls->showHideToolProjectionCheckBox->isChecked())
564 {
565 ShowToolProjection(m_Controls->m_toolselector->currentIndex());
566 }
567 }
568
570
571 //enable/disable Buttons
574
575 m_Controls->m_TrackingControlLabel->setText("Status: connected");
576 m_Controls->m_ConnectDisconnectButton->setText("Disconnect");
577 m_Controls->m_ConnectSimpleMode->setText("Disconnect");
578 m_Controls->m_StartStopTrackingButton->setEnabled(true);
579 m_Controls->m_StartTrackingSimpleMode->setEnabled(true);
580 m_connected = true;
581
582 //During connection, the sourceID of the tool storage changed. However, Microservice can't be updated on a different thread.
583 //UpdateMicroservice is necessary to use filter to get the right storage belonging to a source.
584 //Don't do it before m_connected is true, as we don't want to call content of OnToolStorageChanged.
585 m_toolStorage->UpdateMicroservice();
586}
587
594
595void QmitkMITKIGTTrackingToolboxView::OnDisconnectFinished(bool success, QString errorMessage)
596{
597 m_WorkerThread->quit();
598 m_WorkerThread->wait();
599 m_Controls->m_MainWidget->setEnabled(true);
600
601 if (!success)
602 {
603 MITK_WARN << errorMessage.toStdString();
604 MessageBox(errorMessage.toStdString());
605 return;
606 }
607
608 //enable/disable Buttons
609 m_Controls->m_StartStopTrackingButton->setEnabled(false);
610 m_Controls->m_StartTrackingSimpleMode->setEnabled(false);
613 m_Controls->m_TrackingControlLabel->setText("Status: disconnected");
614 m_Controls->m_ConnectDisconnectButton->setText("Connect");
615 m_Controls->m_ConnectSimpleMode->setText("Connect");
616 m_Controls->m_FreezeUnfreezeTrackingButton->setText("Freeze Tracking");
617 m_Controls->m_TrackingFrozenLabel->setVisible(false);
618 m_connected = false;
619}
620
622{
623 //show tracking volume
624 this->OnTrackingVolumeChanged(m_Controls->m_VolumeSelectionBox->currentText());
625 //Reset the view to a defined start. Do it here and not in OnStartTrackingFinished, to give other tracking devices the chance to reset the view to a different direction.
626 this->GlobalReinit();
628 m_WorkerThread->start();
629 this->m_Controls->m_MainWidget->setEnabled(false);
630}
631
632void QmitkMITKIGTTrackingToolboxView::OnStartTrackingFinished(bool success, QString errorMessage)
633{
635 m_WorkerThread->quit();
636 m_WorkerThread->wait();
638 this->m_Controls->m_MainWidget->setEnabled(true);
639
640 if (!success)
641 {
642 MessageBox(errorMessage.toStdString());
643 MITK_WARN << errorMessage.toStdString();
644 return;
645 }
646
647 if (!(m_Controls->m_DisableAllTimers->isChecked()))
648 {
649 if (m_Controls->m_UseDifferentUpdateRates->isChecked())
650 {
651 if (m_Controls->m_RenderUpdateRate->value() != 0)
652 m_TrackingRenderTimer->start(1000 / (m_Controls->m_RenderUpdateRate->value()));
653 m_TrackingLoggingTimer->start(1000 / (m_Controls->m_LogUpdateRate->value()));
654 }
655 else
656 {
657 m_TrackingRenderTimer->start(1000 / (m_Controls->m_UpdateRate->value()));
658 m_TrackingLoggingTimer->start(1000 / (m_Controls->m_UpdateRate->value()));
659 }
660 }
661
662 m_Controls->m_TrackingControlLabel->setText("Status: tracking");
663
664 //connect the tool visualization widget
665 for (std::size_t i = 0; i < m_Worker->GetTrackingDeviceSource()->GetNumberOfOutputs(); i++)
666 {
667 m_Controls->m_TrackingToolsStatusWidget->AddNavigationData(m_Worker->GetTrackingDeviceSource()->GetOutput(i));
668 }
669 m_Controls->m_TrackingToolsStatusWidget->ShowStatusLabels();
670 if (m_Controls->m_ShowToolQuaternions->isChecked()) { m_Controls->m_TrackingToolsStatusWidget->SetShowQuaternions(true); }
671 else { m_Controls->m_TrackingToolsStatusWidget->SetShowQuaternions(false); }
672
673 //if activated enable open IGT link microservice
674 if (m_Controls->m_EnableOpenIGTLinkMicroService->isChecked())
675 {
676 //create conversion filter
677 m_IGTLConversionFilter = mitk::NavigationDataToIGTLMessageFilter::New();
678 m_IGTLConversionFilter->SetName("IGT Tracking Toolbox");
679 QString dataModeSelection = this->m_Controls->m_OpenIGTLinkDataFormat->currentText();
680 if (dataModeSelection == "TDATA")
681 {
683 }
684 else if (dataModeSelection == "TRANSFORM")
685 {
687 }
688 else if (dataModeSelection == "QTDATA")
689 {
691 }
692 else if (dataModeSelection == "POSITION")
693 {
695 }
697 m_IGTLConversionFilter->RegisterAsMicroservice();
698
699 //create server and message provider
700 m_IGTLServer = mitk::IGTLServer::New(false);
701 m_IGTLServer->SetName("Tracking Toolbox IGTL Server");
702 m_IGTLMessageProvider = mitk::IGTLMessageProvider::New();
703 m_IGTLMessageProvider->SetIGTLDevice(m_IGTLServer);
704 m_IGTLMessageProvider->RegisterAsMicroservice();
705 }
706
707 m_tracking = true;
708 m_Controls->m_ConnectDisconnectButton->setEnabled(false);
709 m_Controls->m_StartStopTrackingButton->setText("Stop Tracking");
710 m_Controls->m_StartTrackingSimpleMode->setText("Stop\nTracking");
711 m_Controls->m_FreezeUnfreezeTrackingButton->setEnabled(true);
712}
713
715{
716 if (!m_tracking) return;
717 for (unsigned int i = 0; i < m_ToolVisualizationFilter->GetNumberOfIndexedOutputs(); i++)
718 {
719 mitk::NavigationData::Pointer currentTool = m_ToolVisualizationFilter->GetOutput(i);
720 if (currentTool->IsDataValid())
721 {
722 this->m_toolStorage->GetTool(i)->GetDataNode()->SetColor(mitk::IGTColor_INVALID);
723 }
724 }
725
726 //refresh view and status widget
727 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
728
729
730 m_TrackingRenderTimer->stop();
732
734 m_WorkerThread->start();
735 m_Controls->m_MainWidget->setEnabled(false);
736
737}
738
739void QmitkMITKIGTTrackingToolboxView::OnStopTrackingFinished(bool success, QString errorMessage)
740{
741 m_WorkerThread->quit();
742 m_WorkerThread->wait();
743 m_Controls->m_MainWidget->setEnabled(true);
744 if (!success)
745 {
746 MessageBox(errorMessage.toStdString());
747 MITK_WARN << errorMessage.toStdString();
748 return;
749 }
750
751 m_Controls->m_TrackingControlLabel->setText("Status: connected");
752 if (m_logging) StopLogging();
753 m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels();
754 m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage);
755 m_tracking = false;
756 m_Controls->m_StartStopTrackingButton->setText("Start Tracking");
757 m_Controls->m_StartTrackingSimpleMode->setText("Start\nTracking");
758 m_Controls->m_ConnectDisconnectButton->setEnabled(true);
759 m_Controls->m_FreezeUnfreezeTrackingButton->setEnabled(false);
760
761 //unregister open IGT link micro service
762 if (m_Controls->m_EnableOpenIGTLinkMicroService->isChecked())
763 {
764 m_IGTLConversionFilter->UnRegisterMicroservice();
765 m_IGTLMessageProvider->UnRegisterMicroservice();
766 }
767}
768
770{
772
773 if (m_Controls->m_ConfigurationWidget->GetTrackingDevice().IsNotNull())
774 {
775 Type = m_Controls->m_ConfigurationWidget->GetTrackingDevice()->GetType();
776 //enable controls because device is valid
777 m_Controls->m_TrackingToolsFrame->setEnabled(true);
778 m_Controls->m_TrackingControlsFrame->setEnabled(true);
779 }
780 else
781 {
783 MessageBox("Error: This tracking device is not included in this project. Please make sure that the device is installed and activated in your MITK build.");
784 m_Controls->m_TrackingToolsFrame->setEnabled(false);
785 m_Controls->m_TrackingControlsFrame->setEnabled(false);
786 return;
787 }
788
789 // Code to enable/disable device specific buttons
790 if (m_Controls->m_ConfigurationWidget->GetTrackingDevice()->AutoDetectToolsAvailable())
791 {
792 m_Controls->m_AutoDetectTools->setVisible(true);
793 }
794 else
795 {
796 m_Controls->m_AutoDetectTools->setVisible(false);
797 }
798
799 m_Controls->m_AddSingleTool->setEnabled(this->m_Controls->m_ConfigurationWidget->GetTrackingDevice()->AddSingleToolIsAvailable());
800
801 // Code to select appropriate tracking volume for current type
802 std::vector<mitk::TrackingDeviceData> Compatibles = m_DeviceTypeCollection->GetDeviceDataForLine(Type);
803 m_Controls->m_VolumeSelectionBox->clear();
804 for (std::size_t i = 0; i < Compatibles.size(); i++)
805 {
806 m_Controls->m_VolumeSelectionBox->addItem(Compatibles[i].Model.c_str());
807 }
808}
809
811{
812 if (qstr.isNull()) return;
813 if (qstr.isEmpty()) return;
814
815 mitk::TrackingVolumeGenerator::Pointer volumeGenerator = mitk::TrackingVolumeGenerator::New();
816
817 std::string str = qstr.toStdString();
818
819 mitk::TrackingDeviceData data = m_DeviceTypeCollection->GetDeviceDataByName(str);
821
822 volumeGenerator->SetTrackingDeviceData(data);
823 volumeGenerator->Update();
824
825 mitk::Surface::Pointer volumeSurface = volumeGenerator->GetOutput();
826
827 m_TrackingVolumeNode->SetData(volumeSurface);
828
829 if (!m_Controls->m_ShowTrackingVolume->isChecked()) m_TrackingVolumeNode->SetOpacity(0.0);
830 else m_TrackingVolumeNode->SetOpacity(0.25);
831
832 GlobalReinit();
833}
834
836{
837 if (m_Controls->m_ShowTrackingVolume->isChecked())
838 {
839 OnTrackingVolumeChanged(m_Controls->m_VolumeSelectionBox->currentText());
840 m_TrackingVolumeNode->SetOpacity(0.25);
841 }
842 else
843 {
844 m_TrackingVolumeNode->SetOpacity(0.0);
845 }
846}
847
849{
850 if (m_Controls->m_ConfigurationWidget->GetTrackingDevice()->AutoDetectToolsAvailable())
851 {
854 m_Worker->SetTrackingDevice(m_Controls->m_ConfigurationWidget->GetTrackingDevice().GetPointer());
855 m_Worker->SetDataStorage(this->GetDataStorage());
856 m_WorkerThread->start();
857 m_TimeoutTimer->start(30000);
858 //disable controls until worker thread is finished
859 this->m_Controls->m_MainWidget->setEnabled(false);
860 }
861}
862
864{
865 //Check, if the thread is running. There might have been a timeOut in between and this causes crashes...
866 if (m_WorkerThread->isRunning())
867 {
868 m_TimeoutTimer->stop();
869 m_WorkerThread->quit();
870 m_WorkerThread->wait();
871 }
872
873 //enable controls again
874 this->m_Controls->m_MainWidget->setEnabled(true);
876
877 if (!success)
878 {
879 MITK_WARN << errorMessage.toStdString();
880 MessageBox(errorMessage.toStdString());
882 return;
883 }
884
885 mitk::NavigationToolStorage::Pointer autoDetectedStorage = m_Worker->GetNavigationToolStorage();
886
887 //save detected tools
888 std::string _autoDetectText;
889 _autoDetectText = "Autodetected ";
890 _autoDetectText.append(this->m_TrackingDeviceData.Line); //This is the device name as string of the current TrackingDevice.
891 _autoDetectText.append(" Storage");
892 this->ReplaceCurrentToolStorage(autoDetectedStorage, _autoDetectText);
893 //auto save the new storage to hard disc (for persistence)
895 //update label
896 QString toolLabel = QString("Loaded Tools: ") + QString::number(m_toolStorage->GetToolCount()) + " Tools (Auto Detected)";
897 m_Controls->m_ToolLabel->setText(toolLabel);
898 //update tool preview
899 m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels();
900 m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage);
901
903
904 //print a logging message about the detected tools
905 switch (m_toolStorage->GetToolCount())
906 {
907 case 0:
908 MITK_INFO("IGT Tracking Toolbox") << "Found no tools. Empty ToolStorage was autosaved to " << m_ToolStorageFilename.toStdString();
909 break;
910 case 1:
911 MITK_INFO("IGT Tracking Toolbox") << "Found one tool. ToolStorage was autosaved to " << m_ToolStorageFilename.toStdString();
912 break;
913 default:
914 MITK_INFO("IGT Tracking Toolbox") << "Found " << m_toolStorage->GetToolCount() << " tools. ToolStorage was autosaved to " << m_ToolStorageFilename.toStdString();
915 }
916}
917
919{
920 QMessageBox msgBox;
921 msgBox.setText(s.c_str());
922 msgBox.exec();
923}
924
926{
927 //update filter
929 MITK_DEBUG << "Number of outputs ToolVisualizationFilter: " << m_ToolVisualizationFilter->GetNumberOfIndexedOutputs();
930 MITK_DEBUG << "Number of inputs ToolVisualizationFilter: " << m_ToolVisualizationFilter->GetNumberOfIndexedInputs();
931
932 //update tool colors to show tool status
933 for (unsigned int i = 0; i < m_ToolVisualizationFilter->GetNumberOfIndexedOutputs(); i++)
934 {
935 mitk::NavigationData::Pointer currentTool = m_ToolVisualizationFilter->GetOutput(i);
936 if (currentTool->IsDataValid())
937 {
938
939 this->m_toolStorage->GetTool(i)->GetDataNode()->SetColor(mitk::IGTColor_VALID);
940 }
941 else
942 {
943 this->m_toolStorage->GetTool(i)->GetDataNode()->SetColor(mitk::IGTColor_WARNING);
944 }
945 }
946
947 //Update the NeedleProjectionFilter
948 if( m_NeedleProjectionFilter.IsNotNull() )
949 {
950 m_NeedleProjectionFilter->Update();
951 }
952
953 //refresh view and status widget
954 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
955 m_Controls->m_TrackingToolsStatusWidget->Refresh();
956}
957
959{
960 //update logging
961 if (m_logging)
962 {
963 this->m_loggingFilter->Update();
964 m_loggedFrames = this->m_loggingFilter->GetNumberOfRecordedSteps();
965 this->m_Controls->m_LoggedFramesLabel->setText("Logged Frames: " + QString::number(m_loggedFrames));
966 //check if logging stopped automatically
967 if ((m_loggedFrames > 1) && (!m_loggingFilter->GetRecording())){ StopLogging(); }
968 }
969 //refresh status widget
970 m_Controls->m_TrackingToolsStatusWidget->Refresh();
971}
972
974{
975 QDir currentPath = QFileInfo(m_Controls->m_LoggingFileName->text()).dir();
976
977 // if no path was selected (QDir would select current working dir then) or the
978 // selected path does not exist -> use home directory
979 if (currentPath == QDir() || !currentPath.exists())
980 {
981 currentPath = QDir(QDir::homePath());
982 }
983
984 QString filename = QFileDialog::getSaveFileName(nullptr, tr("Choose Logging File"), currentPath.absolutePath(), "*.*");
985 if (filename == "") return;
986 this->m_Controls->m_LoggingFileName->setText(filename);
987 this->OnToggleFileExtension();
988}
989// bug-16470: toggle file extension after clicking on radio button
991{
992 QString currentInputText = this->m_Controls->m_LoggingFileName->text();
993 QString currentFile = QFileInfo(currentInputText).baseName();
994 QDir currentPath = QFileInfo(currentInputText).dir();
995 if (currentFile.isEmpty())
996 {
997 currentFile = "logfile";
998 }
999 // Setting currentPath to default home path when currentPath is empty or it does not exist
1000 if (currentPath == QDir() || !currentPath.exists())
1001 {
1002 currentPath = QDir::homePath();
1003 }
1004 // check if csv radio button is clicked
1005 if (this->m_Controls->m_CsvFormat->isChecked())
1006 {
1007 // you needn't add a separator to the input text when currentpath is the rootpath
1008 if (currentPath.isRoot())
1009 {
1010 this->m_Controls->m_LoggingFileName->setText(QDir::toNativeSeparators(currentPath.absolutePath()) + currentFile + ".csv");
1011 }
1012
1013 else
1014 {
1015 this->m_Controls->m_LoggingFileName->setText(QDir::toNativeSeparators(currentPath.absolutePath()) + QDir::separator() + currentFile + ".csv");
1016 }
1017 }
1018 // check if xml radio button is clicked
1019 else if (this->m_Controls->m_XmlFormat->isChecked())
1020 {
1021 // you needn't add a separator to the input text when currentpath is the rootpath
1022 if (currentPath.isRoot())
1023 {
1024 this->m_Controls->m_LoggingFileName->setText(QDir::toNativeSeparators(currentPath.absolutePath()) + currentFile + ".xml");
1025 }
1026 else
1027 {
1028 this->m_Controls->m_LoggingFileName->setText(QDir::toNativeSeparators(currentPath.absolutePath()) + QDir::separator() + currentFile + ".xml");
1029 }
1030 }
1031}
1032
1034{
1036 {
1037 m_Controls->m_simpleWidget->setVisible(false);
1038 m_Controls->m_MainWidget->setVisible(true);
1039 m_Controls->m_SimpleUI->setChecked(false);
1040 m_SimpleModeEnabled = false;
1041 }
1042 else
1043 {
1044 m_Controls->m_simpleWidget->setVisible(true);
1045 m_Controls->m_MainWidget->setVisible(false);
1046 m_SimpleModeEnabled = true;
1047 }
1048}
1049
1051{
1052 if (m_Controls->m_UseDifferentUpdateRates->isChecked())
1053 {
1054 if (m_Controls->m_RenderUpdateRate->value() == 0)
1055 m_Controls->m_RenderWarningLabel->setVisible(true);
1056 else
1057 m_Controls->m_RenderWarningLabel->setVisible(false);
1058
1059 m_Controls->m_UpdateRate->setEnabled(false);
1060 m_Controls->m_OptionsUpdateRateLabel->setEnabled(false);
1061
1062 m_Controls->m_RenderUpdateRate->setEnabled(true);
1063 m_Controls->m_OptionsRenderUpdateRateLabel->setEnabled(true);
1064
1065 m_Controls->m_LogUpdateRate->setEnabled(true);
1066 m_Controls->m_OptionsLogUpdateRateLabel->setEnabled(true);
1067 }
1068
1069 else
1070 {
1071 m_Controls->m_RenderWarningLabel->setVisible(false);
1072
1073 m_Controls->m_UpdateRate->setEnabled(true);
1074 m_Controls->m_OptionsUpdateRateLabel->setEnabled(true);
1075
1076 m_Controls->m_RenderUpdateRate->setEnabled(false);
1077 m_Controls->m_OptionsRenderUpdateRateLabel->setEnabled(false);
1078
1079 m_Controls->m_LogUpdateRate->setEnabled(false);
1080 m_Controls->m_OptionsLogUpdateRateLabel->setEnabled(false);
1081 }
1082}
1083
1085{
1086 if (m_Controls->m_RenderUpdateRate->value() == 0)
1087 m_Controls->m_RenderWarningLabel->setVisible(true);
1088 else
1089 m_Controls->m_RenderWarningLabel->setVisible(false);
1090}
1091
1093{
1094 if (m_ToolVisualizationFilter.IsNull())
1095 {
1096 MessageBox("Cannot activate logging without a connected device. Configure and connect a tracking device first.");
1097 return;
1098 }
1099
1100 if (!m_logging)
1101 {
1102 //initialize logging filter
1103 m_loggingFilter = mitk::NavigationDataRecorder::New();
1104 m_loggingFilter->SetRecordOnlyValidData(m_Controls->m_SkipInvalidData->isChecked());
1105
1107
1108 if (m_Controls->m_LoggingLimit->isChecked()){ m_loggingFilter->SetRecordCountLimit(m_Controls->m_LoggedFramesLimit->value()); }
1109
1110 //start filter with try-catch block for exceptions
1111 try
1112 {
1113 m_loggingFilter->StartRecording();
1114 }
1115 catch (mitk::IGTException&)
1116 {
1117 std::string errormessage = "Error during start recording. Recorder already started recording?";
1118 QMessageBox::warning(nullptr, "IGTPlayer: Error", errormessage.c_str());
1119 m_loggingFilter->StopRecording();
1120 return;
1121 }
1122
1123 //update labels / logging variables
1124 this->m_Controls->m_LoggingLabel->setText("Logging ON");
1125 this->m_Controls->m_LoggedFramesLabel->setText("Logged Frames: 0");
1126 m_loggedFrames = 0;
1127 m_logging = true;
1129 }
1130}
1131
1133{
1134 if (m_logging)
1135 {
1136 //stop logging
1137 m_loggingFilter->StopRecording();
1138 m_logging = false;
1139
1140 //update GUI
1141 this->m_Controls->m_LoggingLabel->setText("Logging OFF");
1143
1144 //write the results to a file
1145 if (m_Controls->m_CsvFormat->isChecked())
1146 {
1147 mitk::IOUtil::Save(m_loggingFilter->GetNavigationDataSet(), this->m_Controls->m_LoggingFileName->text().toStdString());
1148 }
1149 else if (m_Controls->m_XmlFormat->isChecked())
1150 {
1151 mitk::IOUtil::Save(m_loggingFilter->GetNavigationDataSet(), this->m_Controls->m_LoggingFileName->text().toStdString());
1152 }
1153 }
1154}
1155
1159
1161{
1162 QString Identifier = "Tool#";
1163 QString Name = "NewTool";
1164 if (m_toolStorage.IsNotNull()) {
1165 Identifier += QString::number(m_toolStorage->GetToolCount());
1166 Name += QString::number(m_toolStorage->GetToolCount());
1167 }
1168 else {
1169 Identifier += "0";
1170 Name += "0";
1171 }
1172 m_Controls->m_NavigationToolCreationWidget->Initialize(GetDataStorage(), Identifier.toStdString(), Name.toStdString());
1173 m_Controls->m_NavigationToolCreationWidget->SetTrackingDeviceType(m_Controls->m_ConfigurationWidget->GetTrackingDevice()->GetType(), false);
1174 m_Controls->m_TrackingToolsWidget->setCurrentIndex(1);
1175
1176 //disable tracking volume during tool editing
1177 lastTrackingVolumeState = m_Controls->m_ShowTrackingVolume->isChecked();
1178 if (lastTrackingVolumeState) m_Controls->m_ShowTrackingVolume->click();
1179 GlobalReinit();
1180}
1181
1183{
1184 m_Controls->m_TrackingToolsWidget->setCurrentIndex(0);
1185 if (this->m_toolStorage.IsNull())
1186 {
1187 //this shouldn't happen!
1188 MITK_WARN << "No ToolStorage available, cannot add tool, aborting!";
1189 return;
1190 }
1191 m_toolStorage->AddTool(m_Controls->m_NavigationToolCreationWidget->GetCreatedTool());
1192 m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage);
1193 m_Controls->m_ToolLabel->setText("<manually added>");
1194
1195 //displya in tool selector
1196 // m_Controls->m_toolselector->addItem(QString::fromStdString(m_Controls->m_NavigationToolCreationWidget->GetCreatedTool()->GetToolName()));
1197
1198
1199 //auto save current storage for persistence
1200 MITK_INFO << "Auto saving manually added tools for persistence.";
1202
1203 //enable tracking volume again
1204 if (lastTrackingVolumeState) m_Controls->m_ShowTrackingVolume->click();
1205 GlobalReinit();
1206}
1207
1209{
1210 m_Controls->m_TrackingToolsWidget->setCurrentIndex(0);
1211
1212 //enable tracking volume again
1213 if (lastTrackingVolumeState) m_Controls->m_ShowTrackingVolume->click();
1214 GlobalReinit();
1215}
1216
1218{
1219 // get all nodes that have not set "includeInBoundingBox" to false
1220 mitk::NodePredicateNot::Pointer pred = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox", mitk::BoolProperty::New(false)));
1221
1222 mitk::DataStorage::SetOfObjects::ConstPointer rs = this->GetDataStorage()->GetSubset(pred);
1223 // calculate bounding geometry of these nodes
1224 auto bounds = this->GetDataStorage()->ComputeBoundingGeometry3D(rs, "visible");
1225
1226 // initialize the views to the bounding geometry
1227 mitk::RenderingManager::GetInstance()->InitializeViews(bounds);
1228}
1229
1231{
1232 m_Controls->m_StartLogging->setEnabled(false);
1233 m_Controls->m_LoggingFileName->setEnabled(false);
1234 m_Controls->m_ChooseFile->setEnabled(false);
1235 m_Controls->m_LoggingLimit->setEnabled(false);
1236 m_Controls->m_LoggedFramesLimit->setEnabled(false);
1237 m_Controls->m_CsvFormat->setEnabled(false);
1238 m_Controls->m_XmlFormat->setEnabled(false);
1239 m_Controls->m_SkipInvalidData->setEnabled(false);
1240 m_Controls->m_StopLogging->setEnabled(true);
1241}
1242
1244{
1245 m_Controls->m_StartLogging->setEnabled(true);
1246 m_Controls->m_LoggingFileName->setEnabled(true);
1247 m_Controls->m_ChooseFile->setEnabled(true);
1248 m_Controls->m_LoggingLimit->setEnabled(true);
1249 m_Controls->m_LoggedFramesLimit->setEnabled(true);
1250 m_Controls->m_CsvFormat->setEnabled(true);
1251 m_Controls->m_XmlFormat->setEnabled(true);
1252 m_Controls->m_SkipInvalidData->setEnabled(true);
1253 m_Controls->m_StopLogging->setEnabled(false);
1254}
1255
1257{
1258 m_Controls->m_ShowTrackingVolume->setEnabled(false);
1259 m_Controls->m_UseDifferentUpdateRates->setEnabled(false);
1260 m_Controls->m_UpdateRate->setEnabled(false);
1261 m_Controls->m_OptionsUpdateRateLabel->setEnabled(false);
1262 m_Controls->m_RenderUpdateRate->setEnabled(false);
1263 m_Controls->m_OptionsRenderUpdateRateLabel->setEnabled(false);
1264 m_Controls->m_LogUpdateRate->setEnabled(false);
1265 m_Controls->m_OptionsLogUpdateRateLabel->setEnabled(false);
1266 m_Controls->m_DisableAllTimers->setEnabled(false);
1267 m_Controls->m_OtherOptionsGroupBox->setEnabled(false);
1268 m_Controls->m_EnableOpenIGTLinkMicroService->setEnabled(false);
1269 m_Controls->m_OpenIGTLinkDataFormat->setEnabled(false);
1270}
1271
1273{
1274 m_Controls->m_ShowTrackingVolume->setEnabled(true);
1275 m_Controls->m_UseDifferentUpdateRates->setEnabled(true);
1276 m_Controls->m_DisableAllTimers->setEnabled(true);
1277 m_Controls->m_OtherOptionsGroupBox->setEnabled(true);
1278 m_Controls->m_EnableOpenIGTLinkMicroService->setEnabled(true);
1279 m_Controls->m_OpenIGTLinkDataFormat->setEnabled(true);
1281}
1282
1284{
1285 m_Controls->m_TrackingControlsFrame->setEnabled(true);
1286}
1287
1289{
1290 m_Controls->m_TrackingControlsFrame->setEnabled(false);
1291}
1292
1294{
1295 m_Controls->m_AutoDetectTools->setEnabled(true);
1296 m_Controls->m_AddSingleTool->setEnabled(this->m_Controls->m_ConfigurationWidget->GetTrackingDevice()->AddSingleToolIsAvailable());
1297 m_Controls->m_LoadTools->setEnabled(true);
1298 m_Controls->m_ResetTools->setEnabled(true);
1299}
1300
1302{
1303 m_Controls->m_AutoDetectTools->setEnabled(false);
1304 m_Controls->m_AddSingleTool->setEnabled(false);
1305 m_Controls->m_LoadTools->setEnabled(false);
1306 m_Controls->m_ResetTools->setEnabled(false);
1307}
1308
1309void QmitkMITKIGTTrackingToolboxView::ReplaceCurrentToolStorage(mitk::NavigationToolStorage::Pointer newStorage, std::string newStorageName)
1310{
1311 //first: get rid of the old one
1312 //don't reset if there is no tool storage. BugFix #17793
1313 if (m_toolStorage.IsNotNull()){
1314 m_toolStorage->UnLockStorage(); //only to be sure...
1315 m_toolStorage->UnRegisterMicroservice();
1316 m_toolStorage = nullptr;
1317 }
1318
1319 //now: replace by the new one
1320 m_toolStorage = newStorage;
1321 m_toolStorage->SetName(newStorageName);
1322 m_toolStorage->RegisterAsMicroservice();
1323}
1324
1326{
1327 MITK_WARN << "TimeOut. Quitting the thread...";
1328 m_WorkerThread->quit();
1329 //only if we can't quit use terminate.
1330 if (!m_WorkerThread->wait(1000))
1331 {
1332 MITK_ERROR << "Can't quit the thread. Terminating... Might cause further problems, be careful!";
1333 m_WorkerThread->terminate();
1334 m_WorkerThread->wait();
1335 }
1336 m_TimeoutTimer->stop();
1337}
1338
1340{
1341 //don't listen to any changes during connection, toolStorage is locked anyway, so this are only changes of e.g. sourceID which are not relevant for the widget.
1342 if (!m_connected && (event.getType() == ctkServiceEvent::MODIFIED))
1343 {
1344 m_Controls->m_ConfigurationWidget->OnToolStorageChanged();
1345
1346 m_Controls->m_toolselector->clear();
1347 for (size_t i = 0; i < m_toolStorage->GetToolCount(); i++)
1348 {
1349 m_Controls->m_toolselector->addItem(QString::fromStdString(m_toolStorage->GetTool(i)->GetToolName()));
1350 }
1351 }
1352}
1353
1356{
1357 // persistence service does not directly work in plugins for now
1358 // -> using QSettings
1359 QSettings settings;
1360
1361 settings.beginGroup(QString::fromStdString(VIEW_ID));
1362 MITK_DEBUG << "Store UI settings";
1363 // set the values of some widgets and attributes to the QSettings
1364 settings.setValue("ShowTrackingVolume", QVariant(m_Controls->m_ShowTrackingVolume->isChecked()));
1365 settings.setValue("toolStorageFilename", QVariant(m_ToolStorageFilename));
1366 settings.setValue("VolumeSelectionBox", QVariant(m_Controls->m_VolumeSelectionBox->currentIndex()));
1367 settings.setValue("SimpleModeEnabled", QVariant(m_SimpleModeEnabled));
1368 settings.setValue("OpenIGTLinkDataFormat", QVariant(m_Controls->m_OpenIGTLinkDataFormat->currentIndex()));
1369 settings.setValue("EnableOpenIGTLinkMicroService", QVariant(m_Controls->m_EnableOpenIGTLinkMicroService->isChecked()));
1370 settings.endGroup();
1371}
1373
1376{
1377 // persistence service does not directly work in plugins for now -> using QSettings
1378 QSettings settings;
1379
1380 settings.beginGroup(QString::fromStdString(VIEW_ID));
1381
1382 // set some widgets and attributes by the values from the QSettings
1383 m_Controls->m_ShowTrackingVolume->setChecked(settings.value("ShowTrackingVolume", false).toBool());
1384 m_Controls->m_EnableOpenIGTLinkMicroService->setChecked(settings.value("EnableOpenIGTLinkMicroService", true).toBool());
1385 m_Controls->m_VolumeSelectionBox->setCurrentIndex(settings.value("VolumeSelectionBox", 0).toInt());
1386 m_Controls->m_OpenIGTLinkDataFormat->setCurrentIndex(settings.value("OpenIGTLinkDataFormat", 0).toInt());
1387 m_ToolStorageFilename = settings.value("toolStorageFilename", QVariant("")).toString();
1388 if (settings.value("SimpleModeEnabled", false).toBool()) { this->OnToggleAdvancedSimpleMode(); }
1389 settings.endGroup();
1391
1393 // try to deserialize the tool storage from the given tool storage file name
1394 if (!m_ToolStorageFilename.isEmpty())
1395 {
1396 // try-catch block for exceptions
1397 try
1398 {
1399 mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(GetDataStorage());
1400 m_toolStorage->UnRegisterMicroservice();
1401 m_toolStorage = myDeserializer->Deserialize(m_ToolStorageFilename.toStdString());
1402 m_toolStorage->RegisterAsMicroservice();
1403
1404 //update label
1406
1407 //update tool preview
1408 m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels();
1409 m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage);
1410 }
1411 catch (const mitk::IGTException& e)
1412 {
1413 MITK_WARN("QmitkMITKIGTTrackingToolBoxView") << "Error during restoring tools. Problems with file (" << m_ToolStorageFilename.toStdString() << "), please check the file? Error message: "<<e.GetDescription();
1414 this->OnResetTools(); //if there where errors reset the tool storage to avoid problems later on
1415 }
1416 }
1418}
1419
1421{
1422 QFileInfo myPath(pathOfLoadedStorage); //use this to separate filename from path
1423 QString toolLabel = myPath.fileName();
1424 if (toolLabel.size() > 45) //if the tool storage name is to long trimm the string
1425 {
1426 toolLabel.resize(40);
1427 toolLabel += "[...]";
1428 }
1429 m_Controls->m_ToolLabel->setText(toolLabel);
1430}
1431
1433{
1435 mitk::NavigationToolStorageSerializer::Pointer mySerializer = mitk::NavigationToolStorageSerializer::New();
1436 mySerializer->Serialize(m_ToolStorageFilename.toStdString(), m_toolStorage);
1437}
mitk::TrackingDeviceSource::Pointer GetTrackingDeviceSource()
void SetNavigationToolStorage(mitk::NavigationToolStorage::Pointer n)
void OnStartTracking()
This slot tries to start tracking with the current device. If start tracking fails the user gets an e...
void StartLogging()
This slot starts logging. Logging is only possible if a device is tracking. If not the logging mechan...
void UpdateToolStorageLabel(QString pathOfLoadedStorage)
void OnChooseFileClicked()
This slot is called if the user wants to choose a file name for logging. A new windows to navigate th...
void StoreUISettings()
Stores the properties of some QWidgets (and the tool storage file name) to QSettings.
mitk::NavigationDataToIGTLMessageFilter::Pointer m_IGTLConversionFilter
QString m_AutoSaveFilename
>stores the filename of the current tool storage
void OnDisconnect()
This slot disconnects from the device.
bool lastTrackingVolumeState
>holds the data node of the tracking volume if volume is visualized
void OnShowHideToolAxisClicked()
Shows or hides the standard tool axis.
void OnStartTrackingFinished(bool success, QString errorMessage)
void CreateQtPartControl(QWidget *parent) override
mitk::NavigationDataObjectVisualizationFilter::Pointer m_ToolVisualizationFilter
void OnShowHideToolProjectionClicked()
Shows or hides the tool projection of the standard tool axis.
QTimer * m_TrackingRenderTimer
This timer updates the IGT pipline and also the logging filter if logging is activated.
void OnChangeRenderUpdateRate()
Slot for showing the rendering disabled warning label.
void OnToolStorageChanged(const ctkServiceEvent event)
This function is called, when anything in the ToolStorage changed, e.g. AddTool or EditTool....
void LoadUISettings()
Loads the properties of some QWidgets (and the tool storage file name) from QSettings.
void OnShowTrackingVolumeChanged()
Shows or hides the tracking volume according to the checkboxe's state.
void OnAutoDetectToolsFinished(bool success, QString errorMessage)
mitk::NavigationDataRecorder::Pointer m_loggingFilter
void OnAddSingleToolCanceled()
This slot is called if the user cancels the creation of a new tool.
void OnDisconnectFinished(bool success, QString errorMessage)
void UpdateRenderTrackingTimer()
Slot for tracking timer. The timer updates the IGT pipline and also the logging filter if logging is ...
void OnStopTrackingFinished(bool success, QString errorMessage)
void OnConnect()
This slot connects to the device. In status "connected" configuration of the device is disabled.
void OnTrackingDeviceChanged()
This slot enables / disables UI elements depending on the tracking device after a device is changed.
Ui::QmitkMITKIGTTrackingToolboxViewControls * m_Controls
void OnAddSingleToolFinished()
This slot is called if the user finishes the creation of a new tool.
void OnToggleFileExtension()
changes name of the filename when switching fileextension by radio button
void OnConnectFinished(bool success, QString errorMessage)
QmitkMITKIGTTrackingToolboxViewWorker * m_Worker
mitk::IGTLMessageProvider::Pointer m_IGTLMessageProvider
void OnTrackingVolumeChanged(QString qstr)
This slot selects the Tracking Volume appropriate for a given model.
void StopLogging()
This slot stops logging. If logging is not running it does nothing.
void OnAutoDetectTools()
This slot auto detects tools of a NDI Aurora tracking device. If tools where found they will be store...
mitk::NavigationToolStorage::Pointer m_toolStorage
void OnLoadTools()
This slot is called if the user wants to load a new tool file. A new window opens where the user can ...
void OnResetTools()
Resets the Tracking Tools: this means all tools are removed.
void MessageBox(std::string s)
>a filename for auto saving tools if no m_ToolStorageFilename was given by the user
void OnStopTracking()
This slot stops tracking. If tracking is not strated it does nothing.
void OnAddSingleTool()
Opens a dialog where a new navigation tool can be created.
mitk::DataNode::Pointer m_TrackingVolumeNode
>stores the loaded tools
itk::SmartPointer< mitk::NeedleProjectionFilter > m_NeedleProjectionFilter
void ReplaceCurrentToolStorage(mitk::NavigationToolStorage::Pointer newStorage, std::string newStorageName)
>Stores if simple UI mode is enabled
QString m_ToolStorageFilename
>temporary holds the state of the tracking volume (activated/not activated) during some methods
An object of this class represents an exception of the MITK-IGT module.
This class is a collection for information of all Tracking Device Types (derived from abstract Tracki...
std::vector< TrackingDeviceData > GetDeviceDataForLine(TrackingDeviceType type)
TrackingDeviceData GetDeviceDataByName(const std::string &modelName)
std::string TrackingDeviceType