diff --git a/Modules/IGT/Documentation/doxygen/IGTTutorialStep4.dox b/Modules/IGT/Documentation/doxygen/IGTTutorialStep4.dox index 722a4a481b..4953500b3e 100644 --- a/Modules/IGT/Documentation/doxygen/IGTTutorialStep4.dox +++ b/Modules/IGT/Documentation/doxygen/IGTTutorialStep4.dox @@ -1,13 +1,17 @@ /** \page IGTTutorialStepTrackingLab Tracking Lab The tracking lab is an IGT plugin containing various functions. You can enable this example in CMake with the -option: MITK_BUILD_org.mitk.gui.qt.igtexamples. The code of the plugin/view is located in: +option: MITK_BUILD_org.mitk.gui.qt.igtexamples. + +\imageMacro{IGTTutorialStep3_cmake.png,"",15.90} + +The code of the plugin/view is located in: MITK-Source/Plugins/org.mitk.gui.qt.igtexamples/src/internal/QmitkIGTTrackingLabView The plugin will automatically be lodaed in the mitkWorkbench. -More information can be found in the user manual: \ref org_igttrackinglab "Tracking Lab User Manual" +Please read the manual page on how to use this example: \ref org_igttrackinglab \ref Return to the \ref IGTTutorialOverview "[IGT Tutorial Overview]" */ \ No newline at end of file diff --git a/Modules/IGT/Documentation/doxygen/IGTTutorialStep5.dox b/Modules/IGT/Documentation/doxygen/IGTTutorialStep5.dox index 0cc5359246..df22c27f1c 100644 --- a/Modules/IGT/Documentation/doxygen/IGTTutorialStep5.dox +++ b/Modules/IGT/Documentation/doxygen/IGTTutorialStep5.dox @@ -1,16 +1,50 @@ /** \page IGTTutorialStepAdvanced A deeper look into the IGT Plugins -Please have a look at each of these plugins: +We already know the three views of the IGT tracking plugin from the first tutorial step (\ref IGTTutorialStepPluginIntroduction): \ref org_mitk_views_igttrackingtoolbox , \ref org_mitk_views_igtnavigationtoolmanager and \ref org_mitk_views_navigationdataplayer . While the first tutorial step only dealt with the usage of these views, we now want to have a deeper look at some parts of the code. -\li \ref org_mitk_views_igttrackingtoolbox - Connect your tracking device and start tracking +\section AutoLoad Autoload all parameters from last session -\li \ref org_mitk_views_igtnavigationtoolmanager - Edit your tool storage +To increase the usability of the tracking toolbox, all parameters from the last session will be restored. Therefore, we will use the following code to save all parameters. It is also used in the specific tracking device widgets, but we will just have a look at one example, restoring some parameters like the Show-Tracking-Volume-Checkbox, the filename of the autosave path of the tool storage or the index of the tracking volume. -\li \ref org_mitk_views_navigationdataplayer - Play your navigation data, e.g. recorded with the tracking toolbox +To store the settings, the following code is used: -\li not available yet: tutorial to calibration tool manager. Will follow soon. +\snippet QmitkMITKIGTTrackingToolboxView.cpp StoreUISettings + +We will reload it with +\snippet QmitkMITKIGTTrackingToolboxView.cpp LoadUISettings + +\sectionLoadToolStorage Load Tool Storage + +This code will load a previously stored or autosaved tool storage: + +\snippet QmitkMITKIGTTrackingToolboxView.cpp LoadToolStorage + +TODO + +\section ThreadedTracking Threaded Tracking + +Usually, the tracking is done in a separate thread in order to still allow parallel usage of the workbench. If we track the devices in the same thread, the workbench might freeze. +That's why we use thread workers +\snippet QmitkMITKIGTTrackingToolboxView.cpp Thread 1 +...which are connected to functions +\snippet QmitkMITKIGTTrackingToolboxView.cpp Thread 3 + +The thread will be startet, if we connect a tracking device by pushing the connect button or start tracking etc: +\snippet QmitkMITKIGTTrackingToolboxView.cpp Thread 4 + +...and finished afterwards: +\snippet QmitkMITKIGTTrackingToolboxView.cpp Thread 5 + +You can access the data from the worker thread if needed: +\snippet QmitkMITKIGTTrackingToolboxView.cpp Thread 6 + +Which of the functions is finally executed will be chosen in the ThreadFunc: +\snippet QmitkMITKIGTTrackingToolboxView.cpp Thread 7 + +To deconstruct the workers, we first terminate the threads and then delete them +\snippet QmitkMITKIGTTrackingToolboxView.cpp Thread 2 \ref Return to the \ref IGTTutorialOverview "[IGT Tutorial Overview]" */ \ No newline at end of file diff --git a/Modules/IGTUI/Qmitk/QmitkNavigationToolManagementWidget.cpp b/Modules/IGTUI/Qmitk/QmitkNavigationToolManagementWidget.cpp index 8373926f48..a0e0f9d703 100644 --- a/Modules/IGTUI/Qmitk/QmitkNavigationToolManagementWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkNavigationToolManagementWidget.cpp @@ -1,404 +1,396 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkNavigationToolManagementWidget.h" //mitk headers #include "mitkTrackingTypes.h" #include #include #include #include #include #include //qt headers #include #include #include //poco headers #include const std::string QmitkNavigationToolManagementWidget::VIEW_ID = "org.mitk.views.navigationtoolmanagementwidget"; QmitkNavigationToolManagementWidget::QmitkNavigationToolManagementWidget(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f) { m_Controls = NULL; CreateQtPartControl(this); CreateConnections(); } - QmitkNavigationToolManagementWidget::~QmitkNavigationToolManagementWidget() { } void QmitkNavigationToolManagementWidget::CreateQtPartControl(QWidget *parent) +{ + if (!m_Controls) { - if (!m_Controls) - { // create GUI widgets m_Controls = new Ui::QmitkNavigationToolManagementWidgetControls; m_Controls->setupUi(parent); - } - - //Disable StorageControls in the beginning, because there is no storage to edit - DisableStorageControls(); } + //Disable StorageControls in the beginning, because there is no storage to edit + DisableStorageControls(); +} + void QmitkNavigationToolManagementWidget::OnLoadTool() { - if(m_NavigationToolStorage->isLocked()) + if (m_NavigationToolStorage->isLocked()) { MessageBox("Storage is locked, cannot modify it. Maybe the tracking device which uses this storage is connected. If you want to modify the storage please disconnect the device first."); - return; + return; } mitk::NavigationToolReader::Pointer myReader = mitk::NavigationToolReader::New(); - std::string filename = QFileDialog::getOpenFileName(NULL,tr("Add Navigation Tool"), "/", "*.IGTTool").toLatin1().data(); + std::string filename = QFileDialog::getOpenFileName(NULL, tr("Add Navigation Tool"), "/", "*.IGTTool").toLatin1().data(); if (filename == "") return; mitk::NavigationTool::Pointer readTool = myReader->DoRead(filename); if (readTool.IsNull()) MessageBox("Error: " + myReader->GetErrorMessage()); else - { + { if (!m_NavigationToolStorage->AddTool(readTool)) - { + { MessageBox("Error: Can't add tool!"); m_DataStorage->Remove(readTool->GetDataNode()); - } + } UpdateToolTable(); m_NavigationToolStorage->UpdateMicroservice(); - } + } } void QmitkNavigationToolManagementWidget::OnSaveTool() { - //if no item is selected, show error message: - if (m_Controls->m_ToolList->currentItem() == NULL) {MessageBox("Error: Please select tool first!");return;} - - mitk::NavigationToolWriter::Pointer myWriter = mitk::NavigationToolWriter::New(); - std::string filename = QFileDialog::getSaveFileName(NULL,tr("Save Navigation Tool"), "/", "*.IGTTool").toLatin1().data(); - filename.append(".IGTTool"); - if (filename == "") return; - if (!myWriter->DoWrite(filename,m_NavigationToolStorage->GetTool(m_Controls->m_ToolList->currentIndex().row()))) - MessageBox("Error: "+ myWriter->GetErrorMessage()); + //if no item is selected, show error message: + if (m_Controls->m_ToolList->currentItem() == NULL) { MessageBox("Error: Please select tool first!"); return; } + mitk::NavigationToolWriter::Pointer myWriter = mitk::NavigationToolWriter::New(); + std::string filename = QFileDialog::getSaveFileName(NULL, tr("Save Navigation Tool"), "/", "*.IGTTool").toLatin1().data(); + filename.append(".IGTTool"); + if (filename == "") return; + if (!myWriter->DoWrite(filename, m_NavigationToolStorage->GetTool(m_Controls->m_ToolList->currentIndex().row()))) + MessageBox("Error: " + myWriter->GetErrorMessage()); } void QmitkNavigationToolManagementWidget::CreateConnections() +{ + if (m_Controls) { - if ( m_Controls ) - { - //main widget page: - connect( (QObject*)(m_Controls->m_AddTool), SIGNAL(clicked()), this, SLOT(OnAddTool()) ); - connect( (QObject*)(m_Controls->m_DeleteTool), SIGNAL(clicked()), this, SLOT(OnDeleteTool()) ); - connect( (QObject*)(m_Controls->m_EditTool), SIGNAL(clicked()), this, SLOT(OnEditTool()) ); - connect( (QObject*)(m_Controls->m_MoveToolUp), SIGNAL(clicked()), this, SLOT(OnMoveToolUp()) ); - connect( (QObject*)(m_Controls->m_MoveToolDown), SIGNAL(clicked()), this, SLOT(OnMoveToolDown()) ); - connect( (QObject*)(m_Controls->m_LoadStorage), SIGNAL(clicked()), this, SLOT(OnLoadStorage()) ); - connect( (QObject*)(m_Controls->m_SaveStorage), SIGNAL(clicked()), this, SLOT(OnSaveStorage()) ); - connect( (QObject*)(m_Controls->m_LoadTool), SIGNAL(clicked()), this, SLOT(OnLoadTool()) ); - connect( (QObject*)(m_Controls->m_SaveTool), SIGNAL(clicked()), this, SLOT(OnSaveTool()) ); - connect( (QObject*)(m_Controls->m_CreateNewStorage), SIGNAL(clicked()), this, SLOT(OnCreateStorage()) ); - - - //widget page "add tool": - connect( (QObject*)(m_Controls->m_ToolCreationWidget), SIGNAL(Canceled()), this, SLOT(OnAddToolCancel()) ); - connect( (QObject*)(m_Controls->m_ToolCreationWidget), SIGNAL(NavigationToolFinished()), this, SLOT(OnAddToolSave()) ); - } + //main widget page: + connect((QObject*)(m_Controls->m_AddTool), SIGNAL(clicked()), this, SLOT(OnAddTool())); + connect((QObject*)(m_Controls->m_DeleteTool), SIGNAL(clicked()), this, SLOT(OnDeleteTool())); + connect((QObject*)(m_Controls->m_EditTool), SIGNAL(clicked()), this, SLOT(OnEditTool())); + connect((QObject*)(m_Controls->m_MoveToolUp), SIGNAL(clicked()), this, SLOT(OnMoveToolUp())); + connect((QObject*)(m_Controls->m_MoveToolDown), SIGNAL(clicked()), this, SLOT(OnMoveToolDown())); + connect((QObject*)(m_Controls->m_LoadStorage), SIGNAL(clicked()), this, SLOT(OnLoadStorage())); + connect((QObject*)(m_Controls->m_SaveStorage), SIGNAL(clicked()), this, SLOT(OnSaveStorage())); + connect((QObject*)(m_Controls->m_LoadTool), SIGNAL(clicked()), this, SLOT(OnLoadTool())); + connect((QObject*)(m_Controls->m_SaveTool), SIGNAL(clicked()), this, SLOT(OnSaveTool())); + connect((QObject*)(m_Controls->m_CreateNewStorage), SIGNAL(clicked()), this, SLOT(OnCreateStorage())); + + //widget page "add tool": + connect((QObject*)(m_Controls->m_ToolCreationWidget), SIGNAL(Canceled()), this, SLOT(OnAddToolCancel())); + connect((QObject*)(m_Controls->m_ToolCreationWidget), SIGNAL(NavigationToolFinished()), this, SLOT(OnAddToolSave())); } +} void QmitkNavigationToolManagementWidget::Initialize(mitk::DataStorage* dataStorage) - { +{ m_DataStorage = dataStorage; - m_Controls->m_ToolCreationWidget->Initialize(m_DataStorage,"Tool0"); - } + m_Controls->m_ToolCreationWidget->Initialize(m_DataStorage, "Tool0"); +} void QmitkNavigationToolManagementWidget::LoadStorage(mitk::NavigationToolStorage::Pointer storageToLoad) +{ + if (storageToLoad.IsNotNull()) { - if(storageToLoad.IsNotNull()) - { m_NavigationToolStorage = storageToLoad; m_Controls->m_StorageName->setText(m_NavigationToolStorage->GetName().c_str()); EnableStorageControls(); - } + } else - { + { m_NavigationToolStorage = NULL; DisableStorageControls(); - } + } UpdateToolTable(); m_NavigationToolStorage->UpdateMicroservice(); - } +} //################################################################################## //############################## slots: main widget ################################ //################################################################################## void QmitkNavigationToolManagementWidget::OnMoveToolUp() { if (m_NavigationToolStorage.IsNotNull()) { int toolIndex = m_Controls->m_ToolList->currentIndex().row(); if (toolIndex >= 0) { mitk::NavigationTool::Pointer currentNavigationTool = m_NavigationToolStorage->GetTool(toolIndex); if (currentNavigationTool.IsNotNull()) { std::string currentIdentifier = currentNavigationTool->GetIdentifier(); int NewNumber = m_Controls->m_ToolList->currentIndex().row() - 1; if (NewNumber < 0) { MITK_WARN << "Cannot move tool up because it is on the top!"; } else { m_NavigationToolStorage->AssignToolNumber(currentIdentifier, NewNumber); } UpdateToolTable(); m_NavigationToolStorage->UpdateMicroservice(); } } } } void QmitkNavigationToolManagementWidget::OnMoveToolDown() { if (m_NavigationToolStorage.IsNotNull()) { int toolIndex = m_Controls->m_ToolList->currentIndex().row(); if (toolIndex >= 0) { mitk::NavigationTool::Pointer currentNavigationTool = m_NavigationToolStorage->GetTool(toolIndex); if (currentNavigationTool.IsNotNull()) { std::string currentIdentifier = currentNavigationTool->GetIdentifier(); int NewNumber = m_Controls->m_ToolList->currentIndex().row() + 1; if (NewNumber >= m_NavigationToolStorage->GetToolCount()) { MITK_WARN << "Cannot move tool down because it is the last tool in this storage!"; } else { m_NavigationToolStorage->AssignToolNumber(currentIdentifier, NewNumber); } UpdateToolTable(); m_NavigationToolStorage->UpdateMicroservice(); } } } } - void QmitkNavigationToolManagementWidget::OnAddTool() +{ + if (m_NavigationToolStorage->isLocked()) { - if(m_NavigationToolStorage->isLocked()) - { - MessageBox("Storage is locked, cannot modify it. Maybe the tracking device which uses this storage is connected. If you want to modify the storage please disconnect the device first."); - return; - } - QString defaultIdentifier = "NavigationTool#"+QString::number(m_NavigationToolStorage->GetToolCount()); - QString defaultName = "NavigationTool"+QString::number(m_NavigationToolStorage->GetToolCount()); - m_Controls->m_ToolCreationWidget->Initialize(m_DataStorage,defaultIdentifier.toStdString(),defaultName.toStdString()); - m_edit = false; - m_Controls->m_MainWidgets->setCurrentIndex(1); - m_NavigationToolStorage->UpdateMicroservice(); + MessageBox("Storage is locked, cannot modify it. Maybe the tracking device which uses this storage is connected. If you want to modify the storage please disconnect the device first."); + return; } + QString defaultIdentifier = "NavigationTool#" + QString::number(m_NavigationToolStorage->GetToolCount()); + QString defaultName = "NavigationTool" + QString::number(m_NavigationToolStorage->GetToolCount()); + m_Controls->m_ToolCreationWidget->Initialize(m_DataStorage, defaultIdentifier.toStdString(), defaultName.toStdString()); + m_edit = false; + m_Controls->m_MainWidgets->setCurrentIndex(1); + m_NavigationToolStorage->UpdateMicroservice(); +} void QmitkNavigationToolManagementWidget::OnDeleteTool() +{ + //first: some checks + if (m_NavigationToolStorage->isLocked()) { - //first: some checks - if(m_NavigationToolStorage->isLocked()) - { - MessageBox("Storage is locked, cannot modify it. Maybe the tracking device which uses this storage is connected. If you want to modify the storage please disconnect the device first."); - return; - } - else if (m_Controls->m_ToolList->currentItem() == NULL) //if no item is selected, show error message: - { - MessageBox("Error: Please select tool first!"); - return; - } - - m_DataStorage->Remove(m_NavigationToolStorage->GetTool(m_Controls->m_ToolList->currentIndex().row())->GetDataNode()); - m_NavigationToolStorage->DeleteTool(m_Controls->m_ToolList->currentIndex().row()); - UpdateToolTable(); - m_NavigationToolStorage->UpdateMicroservice(); + MessageBox("Storage is locked, cannot modify it. Maybe the tracking device which uses this storage is connected. If you want to modify the storage please disconnect the device first."); + return; } + else if (m_Controls->m_ToolList->currentItem() == NULL) //if no item is selected, show error message: + { + MessageBox("Error: Please select tool first!"); + return; + } + + m_DataStorage->Remove(m_NavigationToolStorage->GetTool(m_Controls->m_ToolList->currentIndex().row())->GetDataNode()); + m_NavigationToolStorage->DeleteTool(m_Controls->m_ToolList->currentIndex().row()); + UpdateToolTable(); + m_NavigationToolStorage->UpdateMicroservice(); +} void QmitkNavigationToolManagementWidget::OnEditTool() +{ + if (m_NavigationToolStorage->isLocked()) { - if(m_NavigationToolStorage->isLocked()) - { - MessageBox("Storage is locked, cannot modify it. Maybe the tracking device which uses this storage is connected. If you want to modify the storage please disconnect the device first."); - return; - } - else if (m_Controls->m_ToolList->currentItem() == NULL) //if no item is selected, show error message: - { - MessageBox("Error: Please select tool first!"); - return; - } - mitk::NavigationTool::Pointer selectedTool = m_NavigationToolStorage->GetTool(m_Controls->m_ToolList->currentIndex().row()); - m_Controls->m_ToolCreationWidget->SetDefaultData(selectedTool); - m_NavigationToolStorage->SetName("test"); - m_edit = true; - m_Controls->m_MainWidgets->setCurrentIndex(1); - m_NavigationToolStorage->UpdateMicroservice(); + MessageBox("Storage is locked, cannot modify it. Maybe the tracking device which uses this storage is connected. If you want to modify the storage please disconnect the device first."); + return; } - -void QmitkNavigationToolManagementWidget::OnCreateStorage() + else if (m_Controls->m_ToolList->currentItem() == NULL) //if no item is selected, show error message: { - QString storageName = QInputDialog::getText(NULL,"Storage Name","Name of the new tool storage:"); - if (storageName.isNull()) return; - m_NavigationToolStorage = mitk::NavigationToolStorage::New(this->m_DataStorage); - m_NavigationToolStorage->SetName(storageName.toStdString()); - m_Controls->m_StorageName->setText(m_NavigationToolStorage->GetName().c_str()); - EnableStorageControls(); - emit NewStorageAdded(m_NavigationToolStorage, storageName.toStdString()); + MessageBox("Error: Please select tool first!"); + return; } + mitk::NavigationTool::Pointer selectedTool = m_NavigationToolStorage->GetTool(m_Controls->m_ToolList->currentIndex().row()); + m_Controls->m_ToolCreationWidget->SetDefaultData(selectedTool); + m_NavigationToolStorage->SetName("test"); + m_edit = true; + m_Controls->m_MainWidgets->setCurrentIndex(1); + m_NavigationToolStorage->UpdateMicroservice(); +} + +void QmitkNavigationToolManagementWidget::OnCreateStorage() +{ + QString storageName = QInputDialog::getText(NULL, "Storage Name", "Name of the new tool storage:"); + if (storageName.isNull()) return; + m_NavigationToolStorage = mitk::NavigationToolStorage::New(this->m_DataStorage); + m_NavigationToolStorage->SetName(storageName.toStdString()); + m_Controls->m_StorageName->setText(m_NavigationToolStorage->GetName().c_str()); + EnableStorageControls(); + emit NewStorageAdded(m_NavigationToolStorage, storageName.toStdString()); +} void QmitkNavigationToolManagementWidget::OnLoadStorage() +{ + mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(m_DataStorage); + std::string filename = QFileDialog::getOpenFileName(NULL, tr("Open Navigation Tool Storage"), "/", tr("IGT Tool Storage (*.IGTToolStorage)")).toStdString(); + if (filename == "") return; + + try { - mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(m_DataStorage); - std::string filename = QFileDialog::getOpenFileName(NULL, tr("Open Navigation Tool Storage"), "/", tr("IGT Tool Storage (*.IGTToolStorage)")).toStdString(); - if (filename == "") return; + mitk::NavigationToolStorage::Pointer tempStorage = myDeserializer->Deserialize(filename); - try + if (tempStorage.IsNull()) MessageBox("Error" + myDeserializer->GetErrorMessage()); + else { - mitk::NavigationToolStorage::Pointer tempStorage = myDeserializer->Deserialize(filename); - - if (tempStorage.IsNull()) MessageBox("Error" + myDeserializer->GetErrorMessage()); - else - { - Poco::Path myPath = Poco::Path(filename.c_str()); - tempStorage->SetName(myPath.getFileName()); //set the filename as name for the storage, so the user can identify it - this->LoadStorage(tempStorage); - emit NewStorageAdded(m_NavigationToolStorage,myPath.getFileName()); - } + Poco::Path myPath = Poco::Path(filename.c_str()); + tempStorage->SetName(myPath.getFileName()); //set the filename as name for the storage, so the user can identify it + this->LoadStorage(tempStorage); + emit NewStorageAdded(m_NavigationToolStorage, myPath.getFileName()); } - catch (const mitk::Exception& exception) - { - MessageBox(exception.GetDescription()); - } - m_NavigationToolStorage->UpdateMicroservice(); } - -void QmitkNavigationToolManagementWidget::OnSaveStorage() + catch (const mitk::Exception& exception) { - //read in filename - QString filename = QFileDialog::getSaveFileName(NULL, tr("Save Navigation Tool Storage"), "/", tr("IGT Tool Storage (*.IGTToolStorage)")); - if (filename.isEmpty()) return; //canceled by the user + MessageBox(exception.GetDescription()); + } + m_NavigationToolStorage->UpdateMicroservice(); +} - // add file extension if it wasn't added by the file dialog - if ( filename.right(15) != ".IGTToolStorage" ) { filename += ".IGTToolStorage"; } +void QmitkNavigationToolManagementWidget::OnSaveStorage() +{ + //read in filename + QString filename = QFileDialog::getSaveFileName(NULL, tr("Save Navigation Tool Storage"), "/", tr("IGT Tool Storage (*.IGTToolStorage)")); + if (filename.isEmpty()) return; //canceled by the user - //serialize tool storage - mitk::NavigationToolStorageSerializer::Pointer mySerializer = mitk::NavigationToolStorageSerializer::New(); - if (!mySerializer->Serialize(filename.toStdString(),m_NavigationToolStorage)) - { - MessageBox("Error: " + mySerializer->GetErrorMessage()); - return; - } - Poco::Path myPath = Poco::Path(filename.toStdString()); - m_Controls->m_StorageName->setText(QString::fromStdString(myPath.getFileName())); + // add file extension if it wasn't added by the file dialog + if (filename.right(15) != ".IGTToolStorage") { filename += ".IGTToolStorage"; } + //serialize tool storage + mitk::NavigationToolStorageSerializer::Pointer mySerializer = mitk::NavigationToolStorageSerializer::New(); + if (!mySerializer->Serialize(filename.toStdString(), m_NavigationToolStorage)) + { + MessageBox("Error: " + mySerializer->GetErrorMessage()); + return; } - + Poco::Path myPath = Poco::Path(filename.toStdString()); + m_Controls->m_StorageName->setText(QString::fromStdString(myPath.getFileName())); +} //################################################################################## //############################## slots: add tool widget ############################ //################################################################################## void QmitkNavigationToolManagementWidget::OnAddToolSave() - { - mitk::NavigationTool::Pointer newTool = m_Controls->m_ToolCreationWidget->GetCreatedTool(); - - if (m_edit) //here we edit a existing tool - { - mitk::NavigationTool::Pointer editedTool = m_NavigationToolStorage->GetTool(m_Controls->m_ToolList->currentIndex().row()); - editedTool->Graft(newTool); - } - else //here we create a new tool - { - m_NavigationToolStorage->AddTool(newTool); - } - - UpdateToolTable(); +{ + mitk::NavigationTool::Pointer newTool = m_Controls->m_ToolCreationWidget->GetCreatedTool(); - m_Controls->m_MainWidgets->setCurrentIndex(0); - m_NavigationToolStorage->UpdateMicroservice(); + if (m_edit) //here we edit a existing tool + { + mitk::NavigationTool::Pointer editedTool = m_NavigationToolStorage->GetTool(m_Controls->m_ToolList->currentIndex().row()); + editedTool->Graft(newTool); } - -void QmitkNavigationToolManagementWidget::OnAddToolCancel() + else //here we create a new tool { - m_Controls->m_MainWidgets->setCurrentIndex(0); + m_NavigationToolStorage->AddTool(newTool); } + UpdateToolTable(); + + m_Controls->m_MainWidgets->setCurrentIndex(0); + m_NavigationToolStorage->UpdateMicroservice(); +} + +void QmitkNavigationToolManagementWidget::OnAddToolCancel() +{ + m_Controls->m_MainWidgets->setCurrentIndex(0); +} //################################################################################## //############################## private help methods ############################## //################################################################################## void QmitkNavigationToolManagementWidget::UpdateToolTable() - { +{ m_Controls->m_ToolList->clear(); - if(m_NavigationToolStorage.IsNull()) return; - for(int i=0; iGetToolCount(); i++) + if (m_NavigationToolStorage.IsNull()) return; + for (int i = 0; i < m_NavigationToolStorage->GetToolCount(); i++) + { + QString currentTool = "Tool" + QString::number(i) + ": " + QString(m_NavigationToolStorage->GetTool(i)->GetDataNode()->GetName().c_str()) + " "; + + currentTool += "(" + QString::fromStdString(m_NavigationToolStorage->GetTool(i)->GetTrackingDeviceType()) + "/"; + + switch (m_NavigationToolStorage->GetTool(i)->GetType()) { - QString currentTool = "Tool" + QString::number(i) + ": " + QString(m_NavigationToolStorage->GetTool(i)->GetDataNode()->GetName().c_str())+ " "; - - currentTool += "(" + QString::fromStdString(m_NavigationToolStorage->GetTool(i)->GetTrackingDeviceType()) + "/"; - - switch (m_NavigationToolStorage->GetTool(i)->GetType()) - { - case mitk::NavigationTool::Instrument: - currentTool += "Instrument)"; break; - case mitk::NavigationTool::Fiducial: - currentTool += "Fiducial)"; break; - case mitk::NavigationTool::Skinmarker: - currentTool += "Skinmarker)"; break; - default: - currentTool += "Unknown)"; - } - m_Controls->m_ToolList->addItem(currentTool); + case mitk::NavigationTool::Instrument: + currentTool += "Instrument)"; break; + case mitk::NavigationTool::Fiducial: + currentTool += "Fiducial)"; break; + case mitk::NavigationTool::Skinmarker: + currentTool += "Skinmarker)"; break; + default: + currentTool += "Unknown)"; } - + m_Controls->m_ToolList->addItem(currentTool); } +} void QmitkNavigationToolManagementWidget::MessageBox(std::string s) - { +{ QMessageBox msgBox; msgBox.setText(s.c_str()); msgBox.exec(); - } +} void QmitkNavigationToolManagementWidget::DisableStorageControls() { m_Controls->m_StorageName->setText(""); m_Controls->m_AddTool->setEnabled(false); m_Controls->m_LoadTool->setEnabled(false); m_Controls->m_MoveToolUp->setEnabled(false); m_Controls->m_MoveToolDown->setEnabled(false); m_Controls->m_selectedLabel->setEnabled(false); m_Controls->m_DeleteTool->setEnabled(false); m_Controls->m_EditTool->setEnabled(false); m_Controls->m_SaveTool->setEnabled(false); m_Controls->m_ToolList->setEnabled(false); m_Controls->m_SaveStorage->setEnabled(false); m_Controls->m_ToolLabel->setEnabled(false); } void QmitkNavigationToolManagementWidget::EnableStorageControls() { m_Controls->m_AddTool->setEnabled(true); m_Controls->m_LoadTool->setEnabled(true); m_Controls->m_MoveToolUp->setEnabled(true); m_Controls->m_MoveToolDown->setEnabled(true); m_Controls->m_selectedLabel->setEnabled(true); m_Controls->m_DeleteTool->setEnabled(true); m_Controls->m_EditTool->setEnabled(true); m_Controls->m_SaveTool->setEnabled(true); m_Controls->m_ToolList->setEnabled(true); m_Controls->m_SaveStorage->setEnabled(true); m_Controls->m_ToolLabel->setEnabled(true); -} +} \ No newline at end of file diff --git a/Modules/IGTUI/Qmitk/QmitkNavigationToolManagementWidget.h b/Modules/IGTUI/Qmitk/QmitkNavigationToolManagementWidget.h index 60e23cd47c..afe0874bcb 100644 --- a/Modules/IGTUI/Qmitk/QmitkNavigationToolManagementWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkNavigationToolManagementWidget.h @@ -1,112 +1,112 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKNAVIGATIONTOOLMANAGEMENTWIDGET_H #define QMITKNAVIGATIONTOOLMANAGEMENTWIDGET_H //QT headers #include //mitk headers #include "MitkIGTUIExports.h" #include "mitkNavigationTool.h" #include //ui header #include "ui_QmitkNavigationToolManagementWidgetControls.h" - /** Documentation: - * \brief An object of this class offers an UI to manage NavigationTools and - * NavigationToolStorages. This means a user may create, save and load - * single NavigationTools and/or NavigationToolStorages with this widget. - * - * Be sure to call the Initialize-methode before you start the widget - * otherwise some errors might occure. - * - * \ingroup IGTUI - */ +/** Documentation: + * \brief An object of this class offers an UI to manage NavigationTools and + * NavigationToolStorages. This means a user may create, save and load + * single NavigationTools and/or NavigationToolStorages with this widget. + * + * Be sure to call the Initialize-methode before you start the widget + * otherwise some errors might occure. + * + * \ingroup IGTUI + */ class MITKIGTUI_EXPORT QmitkNavigationToolManagementWidget : public QWidget { Q_OBJECT - public: - static const std::string VIEW_ID; +public: + static const std::string VIEW_ID; - /** Initializes the widget. Has to be called before any action, otherwise errors might occur. */ - void Initialize(mitk::DataStorage* dataStorage); + /** Initializes the widget. Has to be called before any action, otherwise errors might occur. */ + void Initialize(mitk::DataStorage* dataStorage); - /** Loads a storage to the widget. The old storage storage is dropped, so be careful, if the - * storage is not saved somewhere else it might be lost. You might want to ask the user if he - * wants to save the storage to the harddisk before calling this method. - * @param storageToLoad This storage will be loaded and might be modified by the user. - */ - void LoadStorage(mitk::NavigationToolStorage::Pointer storageToLoad); + /** Loads a storage to the widget. The old storage storage is dropped, so be careful, if the + * storage is not saved somewhere else it might be lost. You might want to ask the user if he + * wants to save the storage to the harddisk before calling this method. + * @param storageToLoad This storage will be loaded and might be modified by the user. + */ + void LoadStorage(mitk::NavigationToolStorage::Pointer storageToLoad); - QmitkNavigationToolManagementWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); - ~QmitkNavigationToolManagementWidget(); + QmitkNavigationToolManagementWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); + ~QmitkNavigationToolManagementWidget(); - signals: +signals: - /** This signal is emmited if a new storage was added by the widget itself, e.g. because - * a storage was loaded from the harddisk. - * @param newStorage Holds the new storage which was added. - * @param storageName Name of the new storage (e.g. filename) - */ - void NewStorageAdded(mitk::NavigationToolStorage::Pointer newStorage, std::string storageName); + /** This signal is emmited if a new storage was added by the widget itself, e.g. because + * a storage was loaded from the harddisk. + * @param newStorage Holds the new storage which was added. + * @param storageName Name of the new storage (e.g. filename) + */ + void NewStorageAdded(mitk::NavigationToolStorage::Pointer newStorage, std::string storageName); protected slots: - //main widget page: - void OnAddTool(); - void OnDeleteTool(); - void OnEditTool(); - void OnLoadTool(); - void OnSaveTool(); - void OnMoveToolUp(); - void OnMoveToolDown(); - void OnLoadStorage(); - void OnSaveStorage(); - void OnCreateStorage(); + //main widget page: + void OnAddTool(); + void OnDeleteTool(); + void OnEditTool(); + void OnLoadTool(); + void OnSaveTool(); + void OnMoveToolUp(); + void OnMoveToolDown(); + void OnLoadStorage(); + void OnSaveStorage(); + void OnCreateStorage(); - //widget page "add tool": - void OnAddToolCancel(); - void OnAddToolSave(); + //widget page "add tool": + void OnAddToolCancel(); + void OnAddToolSave(); - protected: +protected: - /// \brief Creation of the connections - virtual void CreateConnections(); + /// \brief Creation of the connections + virtual void CreateConnections(); - virtual void CreateQtPartControl(QWidget *parent); + virtual void CreateQtPartControl(QWidget *parent); - Ui::QmitkNavigationToolManagementWidgetControls* m_Controls; + Ui::QmitkNavigationToolManagementWidgetControls* m_Controls; - /** @brief holds the DataStorage */ - mitk::DataStorage* m_DataStorage; + /** @brief holds the DataStorage */ + mitk::DataStorage* m_DataStorage; - /** @brief holds the NavigationToolStorage we are working with. */ - mitk::NavigationToolStorage::Pointer m_NavigationToolStorage; + /** @brief holds the NavigationToolStorage we are working with. */ + mitk::NavigationToolStorage::Pointer m_NavigationToolStorage; - /** @brief shows if we are in edit mode, if not we create new navigation tool objects. */ - bool m_edit; + /** @brief shows if we are in edit mode, if not we create new navigation tool objects. */ + bool m_edit; - //############## private help methods ####################### - void MessageBox(std::string s); - void UpdateToolTable(); - void DisableStorageControls(); - void EnableStorageControls(); + //############## private help methods ####################### + void MessageBox(std::string s); + void UpdateToolTable(); + void DisableStorageControls(); + void EnableStorageControls(); }; #endif diff --git a/Plugins/org.mitk.gui.qt.igtexamples/documentation/UserManual/QmitkIGTTrackingLab.dox b/Plugins/org.mitk.gui.qt.igtexamples/documentation/UserManual/QmitkIGTTrackingLab.dox index 9386f91b46..ea52e517f2 100644 --- a/Plugins/org.mitk.gui.qt.igtexamples/documentation/UserManual/QmitkIGTTrackingLab.dox +++ b/Plugins/org.mitk.gui.qt.igtexamples/documentation/UserManual/QmitkIGTTrackingLab.dox @@ -1,56 +1,67 @@ /** \page org_igttrackinglab IGT Tutorial Step 4: The IGT-TrackingLab Available sections: - \ref QmitkIGTTrackingLabUsersManualOverview - \ref QmitkIGTTrackingLabUsersManualPrel - \ref QmitkIGTTrackingLabUsersManualConf - \ref QmitkIGTTrackingLabUsersManualIntialReg - \ref QmitkIGTTrackingLabUsersManualPermReg - \ref QmitkIGTTrackingLabUsersManualPtSetRec - \ref QmitkIGTTrackingLabUsersManualCamView \section QmitkIGTTrackingLabUsersManualOverview Introduction -The IGT-TrackingLab is the last step of the IGT tutorial. It is a plugin which shows examples usage for many IGT classes and is also an example navigation implemented with IGT. In the following you can learn how to use the plugin by reading this manual together with the source code. +The IGT-TrackingLab is the last step of the IGT tutorial. It is a plugin which shows examples usage for many IGT classes and is also an example navigation implemented with IGT. In the following you can learn how to use the plugin by reading this manual together with the source code. Most important code passages are included in this manual. + +The symbol of the Tracking Lab View is the following: + +\imageMacro{../../resources/IgtTrackingLab.png,"",2} + +The view looks like this: +\imageMacro{IGT_TrackingLab_PluginView.png,"",15.90} + +TODO - explain here, what will happen... e.g. register a book, ... \section QmitkIGTTrackingLabUsersManualPrel Preliminaries First connect your tracking device to your PC. Then start the MITK Workbench and configure your tracking device using the \ref org_mitk_views_igttrackingtoolbox "Tracking Toolbox View". +TODO - here should be an option to use previously recorded data. + \section QmitkIGTTrackingLabUsersManualConf Configuration Select the desired Navigation Data Source. Now it's time to define which tool shall be used as object marker and which tool shall be used as pointer. Next load the Book surface provided with the example data (e.g. book.stl from the MITK-Data repository which comes with every superbuild or may also be checked out separately) into MITK. Fixate the object marker on a real book of your choice. Now we need to tell MITK that the object marker has been fixated on a physical object. To do this, select the Book as surface in the Object Selection submenu. \section QmitkIGTTrackingLabUsersManualIntialReg Initial Registration Now we need to register the object marker to the surface it's fixed upon, in our case the book. To do this, first press the initial registration button. For MITK to be able to do this registration, we need to 1. Select landmarks on the virtual object (e.g. the corners of the book) Press the plus button in the Image fiducials column. Shift + click on the corners on the book in the MITK Display. 2. Point to the corresponding landmarks in the real world using the pointer. Now press the plus button in the Real world fiducials column and point to the corners on the real book. Press Add current instrument position whenever you targeted a corner to tell MITK this is the desired landmark. Make sure you select the "real" edges in the same order as the edges in the image. Press Register to finalize the initial registration. Now the object marker is registered onto the book. You can see this in the MITK image. If needed the FRE is shown in the widget. \section QmitkIGTTrackingLabUsersManualPermReg Permanent Registration Now everything is set up and registered. We can thus activate permanent registration to continuously track the object, the object marker and the pointer. For this, simply press the Permanent Registration button and select Activate permanent registration. You can now move the book in the real world and see the same movement in the MITK Display. A nice test to see if everything was correctly registered is to target the corners of the book with the pointer and check if the correct corners are pointed to in the MITK Display. \section QmitkIGTTrackingLabUsersManualPtSetRec PointSet Recording A user might now want to track a tool's trajectory. For this, the PointSet Recording was created. First click on PointSet Recording. Now select your tracking source and the tool whose trajectory shall be recorded. Activate the Point Set Recording checkbox. In the MITK Display little green points will now be drawn for every measured position. Deactivate the checkbox to stop recording. The trajectory is saved in the PointSet Recorded Points visible in the Data Manager. \section QmitkIGTTrackingLabUsersManualCamView Camera View Another possible tracking application is the Camera View. Here, a virtual camera is placed at the pointers tip and its images are shown in the MITK Display. Select Camera View and as usual the Tracking Source and the tool you want to place the virtual camera on. Activate the "Activate Needle View" checkbox and move the pointer around the book. You can now see the book from the pointers perspective. You may need to adjust the Needle View Direction and the View Up Vector. This is always relative to your tools coordinate center origin. An example of the NDI pointer tool coordinate system is shown below: \imageMacro{QmitkIGTExamples_Tool.png,"The coordinate system of the NDI pointing tool",16.00} In the above case, the camera should look in inverse z-direction, and the view up vector should probably be set to positive x. Note this is just an example and may be different depending on your pointer. - -*/ +\ref Return to the \ref IGTTutorialOverview "[IGT Tutorial Overview]" +*/ \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.igtexamples/documentation/UserManual/QmitkIGTTutorial.dox b/Plugins/org.mitk.gui.qt.igtexamples/documentation/UserManual/QmitkIGTTutorial.dox index c9a72db643..6c95608409 100644 --- a/Plugins/org.mitk.gui.qt.igtexamples/documentation/UserManual/QmitkIGTTutorial.dox +++ b/Plugins/org.mitk.gui.qt.igtexamples/documentation/UserManual/QmitkIGTTutorial.dox @@ -1,93 +1,90 @@ /** \page org_imageguidedtherapytutorial The MITK-IGT Tutorial View This view is not meant as an end-user module. It contains tutorial program code that explains how to use the MITK-IGT component. It contains only two buttons. The "Start image guided therapy" button will create a virtual tracking device and a virtual tool. -It will move the tool around on random paths in a tracking volume of 200x200x200 mm. The tool is visualized with a cone. +It will move the tool around on random paths in a tracking volume of 200x200x200 mm. The tool is visualized with a cone. If you do not see a cone moving around, you will need to initialize the rendering views correctly. Use the DataManager view to perform a global reinit. The symbol of this view is the following: \imageMacro{../../resources/IGTTutorial.png,"",2} - In this tutorial we connect to the NDI Polaris tracking system (or alternatively use a virtual tracking device) and we will show the movement of a tool as cone in the StdMultiWidget editor. First of all, you will have to add an IGT dependency to your cmake list. FOr this example, MitkIGTUI would be sufficient, but as the plugin contains several views, we have additional OpenIGTLink and US dependencies: \code{.cpp} project(org_mitk_gui_qt_igtexamples) mitk_create_plugin( EXPORT_DIRECTIVE IGTEXAMPLES_EXPORT EXPORTED_INCLUDE_SUFFIXES src MODULE_DEPENDS MitkQtWidgetsExt MitkIGT MitkIGTUI MitkOpenIGTLink MitkOpenIGTLinkUI MitkUS ) \endcode More information on how to create your own plugin can be found here: \ref NewPluginPage -The view looks like this: -\imageMacro{IGTExampleIGT_QT_Tutorial_PluginView.png,"",15.90} When clicking the start button, a cone should move in the 3D view and stop after clicking the stop button. The view has several fuctions. Most of them deal with the basic functionality with the plugin (e.g. CreateQTPartControl or CreateConnections). For a deeper understanding, you might have a look at the files QmitkIGTTutorialView.cpp and QmitkIGTTutorialView.h For our IGT functionality, the following functions are important: \li OnStartIGT: Starts the navigation pipeline \li OnStopIGT: Disconnect the pipeline \li OnTimer: Updates the view Let's now have a deeper look at these functions. \section OnStartIGT OnStartIGT \snippet ../../src/internal/QmitkIGTTutorialView.cpp OnStart 1 We first check in a try environment, if we should use an NDI tracking device or a virtual device. Let's start with NDI, we hardcode the parameters here and give out a warning. In your propper application, the parameters should be set via the gui aswell (see \ref org_mitk_views_igttrackingtoolbox ), but for simplicity, we just set hardcoded parameters here. If you want to try it with your own NDI device, you need to adapt these parameters here in the code: \snippet ../../src/internal/QmitkIGTTutorialView.cpp OnStart 2 The tracking device has to be set to a source. For more information on the tracking pipeline, please have a look at the \ref IGTTutorialStepFilterPipeline. \snippet QmitkIGTTutorialView.cpp OnStart 3 Alternatively, we can setup a virtual tracking device. We create this device, set the bounds, add a tool and connect it to the source: \snippet QmitkIGTTutorialView.cpp OnStart 4 Now we need to connect the tracking system \snippet QmitkIGTTutorialView.cpp OnStart 5 For the visualisation, we need an object. Here, we create a red cone \snippet QmitkIGTTutorialView.cpp OnStart 6 The visualization filter will actually render the cone \snippet QmitkIGTTutorialView.cpp OnStart 7 For a continuous display, we need to call update, here we decide to do it every 100 ms using a timer. \snippet QmitkIGTTutorialView.cpp OnStart 8 Disable the selection of tracking devices during tracking: \snippet QmitkIGTTutorialView.cpp OnStart 8a For propper coding, you should always catch the exceptions: \snippet QmitkIGTTutorialView.cpp OnStart 9 \section OnTimer OnTimer Each time, the timer is updated, the following code is executed: \snippet QmitkIGTTutorialView.cpp OnTimer \section OnStopIGT OnStopIGT This function will stop the pipeline and clean up everything: \snippet QmitkIGTTutorialView.cpp OnStop You now have a very simple plugin, which creates an own tracking device and starts or stops tracking. Of course, for your more advanced project, you could implement a new tracking device to be available in every plugin (see \ref IGTHowToImplementATrackingDevice) or use already implemented tracking devices via the tracking toolbox and/or microservices. This small example should just show you the most simple way to start tracking. \ref Return to the \ref IGTTutorialOverview "[IGT Tutorial Overview]" -*/ +*/ \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.igtexamples/documentation/doxygen/IGT_TrackingLab_PluginView.png b/Plugins/org.mitk.gui.qt.igtexamples/documentation/doxygen/IGT_TrackingLab_PluginView.png new file mode 100644 index 0000000000..42e03a1b76 Binary files /dev/null and b/Plugins/org.mitk.gui.qt.igtexamples/documentation/doxygen/IGT_TrackingLab_PluginView.png differ diff --git a/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTNavigationToolManagerView.cpp b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTNavigationToolManagerView.cpp index 581d2c53b6..f3205dd8f2 100644 --- a/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTNavigationToolManagerView.cpp +++ b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTNavigationToolManagerView.cpp @@ -1,84 +1,79 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // Blueberry #include #include // Qmitk #include "QmitkMITKIGTNavigationToolManagerView.h" #include "QmitkStdMultiWidget.h" // MITK #include // Qt #include - - const std::string QmitkMITKIGTNavigationToolManagerView::VIEW_ID = "org.mitk.views.mitkigtnavigationtoolmanager"; QmitkMITKIGTNavigationToolManagerView::QmitkMITKIGTNavigationToolManagerView() -: QmitkAbstractView() -, m_Controls( 0 ) + : QmitkAbstractView() + , m_Controls(0) { } QmitkMITKIGTNavigationToolManagerView::~QmitkMITKIGTNavigationToolManagerView() { - for(int i=0; i < m_AllStoragesHandledByThisWidget.size(); i++) + for (int i = 0; i < m_AllStoragesHandledByThisWidget.size(); i++) m_AllStoragesHandledByThisWidget.at(i)->UnRegisterMicroservice(); } - -void QmitkMITKIGTNavigationToolManagerView::CreateQtPartControl( QWidget *parent ) +void QmitkMITKIGTNavigationToolManagerView::CreateQtPartControl(QWidget *parent) { // build up qt view, unless already done - if ( !m_Controls ) + if (!m_Controls) { // create GUI widgets from the Qt Designer's .ui file m_Controls = new Ui::QmitkMITKIGTNavigationToolManagerViewControls; - m_Controls->setupUi( parent ); - connect( (QObject*)(m_Controls->m_toolManagerWidget), SIGNAL(NewStorageAdded(mitk::NavigationToolStorage::Pointer,std::string)), this, SLOT(NewStorageByWidget(mitk::NavigationToolStorage::Pointer,std::string)) ); - connect( (QObject*)(m_Controls->m_ToolStorageListWidget), SIGNAL(NavigationToolStorageSelected(mitk::NavigationToolStorage::Pointer)), this, SLOT(ToolStorageSelected(mitk::NavigationToolStorage::Pointer)) ); + m_Controls->setupUi(parent); + connect((QObject*)(m_Controls->m_toolManagerWidget), SIGNAL(NewStorageAdded(mitk::NavigationToolStorage::Pointer, std::string)), this, SLOT(NewStorageByWidget(mitk::NavigationToolStorage::Pointer, std::string))); + connect((QObject*)(m_Controls->m_ToolStorageListWidget), SIGNAL(NavigationToolStorageSelected(mitk::NavigationToolStorage::Pointer)), this, SLOT(ToolStorageSelected(mitk::NavigationToolStorage::Pointer))); } m_Controls->m_toolManagerWidget->Initialize(this->GetDataStorage()); } void QmitkMITKIGTNavigationToolManagerView::SetFocus() { m_Controls->m_ToolStorageListWidget->setFocus(); } -void QmitkMITKIGTNavigationToolManagerView::NewStorageByWidget(mitk::NavigationToolStorage::Pointer storage,std::string storageName) +void QmitkMITKIGTNavigationToolManagerView::NewStorageByWidget(mitk::NavigationToolStorage::Pointer storage, std::string storageName) { storage->RegisterAsMicroservice(storageName); m_AllStoragesHandledByThisWidget.push_back(storage); } void QmitkMITKIGTNavigationToolManagerView::ToolStorageSelected(mitk::NavigationToolStorage::Pointer storage) { if (storage.IsNull()) //no storage selected - { - //reset everything - return; - } + { + //reset everything + return; + } this->m_Controls->m_toolManagerWidget->LoadStorage(storage); -} - - +} \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTNavigationToolManagerView.h b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTNavigationToolManagerView.h index bbac8e6ad7..c9fff653b4 100644 --- a/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTNavigationToolManagerView.h +++ b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTNavigationToolManagerView.h @@ -1,67 +1,63 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QmitkMITKIGTNavigationToolManagerView_h #define QmitkMITKIGTNavigationToolManagerView_h #include #include #include #include "ui_QmitkMITKIGTNavigationToolManagerViewControls.h" - - /*! \brief QmitkMITKIGTNavigationToolManagerView \warning This application module is not yet documented. Use "svn blame/praise/annotate" and ask the author to provide basic documentation. -*/ + */ class QmitkMITKIGTNavigationToolManagerView : public QmitkAbstractView { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT - public: +public: - static const std::string VIEW_ID; + static const std::string VIEW_ID; - QmitkMITKIGTNavigationToolManagerView(); - virtual ~QmitkMITKIGTNavigationToolManagerView(); + QmitkMITKIGTNavigationToolManagerView(); + virtual ~QmitkMITKIGTNavigationToolManagerView(); - virtual void CreateQtPartControl(QWidget *parent) override; + virtual void CreateQtPartControl(QWidget *parent) override; - virtual void SetFocus() override; + virtual void SetFocus() override; protected slots: - void NewStorageByWidget(mitk::NavigationToolStorage::Pointer storage,std::string); - void ToolStorageSelected(mitk::NavigationToolStorage::Pointer); + void NewStorageByWidget(mitk::NavigationToolStorage::Pointer storage, std::string); + void ToolStorageSelected(mitk::NavigationToolStorage::Pointer); - protected: +protected: - Ui::QmitkMITKIGTNavigationToolManagerViewControls* m_Controls; + Ui::QmitkMITKIGTNavigationToolManagerViewControls* m_Controls; - /** Someone needs to hold the smart pointers of new storages, otherwise the objects will be lost although they are listed as microservice. */ - std::vector m_AllStoragesHandledByThisWidget; + /** Someone needs to hold the smart pointers of new storages, otherwise the objects will be lost although they are listed as microservice. */ + std::vector m_AllStoragesHandledByThisWidget; }; - - #endif // _QMITKMITKIGTNAVIGATIONTOOLMANAGERVIEW_H_INCLUDED diff --git a/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxView.cpp b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxView.cpp index 9393b109f2..198e7fe7da 100644 --- a/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxView.cpp +++ b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxView.cpp @@ -1,1509 +1,1532 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // Blueberry #include #include // Qmitk #include "QmitkMITKIGTTrackingToolboxView.h" #include "QmitkTrackingDeviceConfigurationWidget.h" #include "QmitkStdMultiWidget.h" // Qt #include #include #include // MITK #include #include #include #include #include #include #include #include #include #include #include #include #include #include "mitkNDIAuroraTypeInformation.h" // vtk #include //for exceptions #include #include //for Microservice #include "mitkPluginActivator.h" #include #include #include "usServiceReference.h" const std::string QmitkMITKIGTTrackingToolboxView::VIEW_ID = "org.mitk.views.mitkigttrackingtoolbox"; QmitkMITKIGTTrackingToolboxView::QmitkMITKIGTTrackingToolboxView() : QmitkFunctionality() , m_Controls(nullptr) , m_MultiWidget(nullptr) , m_DeviceTypeCollection(nullptr) { m_TrackingLoggingTimer = new QTimer(this); m_TrackingRenderTimer = new QTimer(this); m_TimeoutTimer = new QTimer(this); m_tracking = false; m_connected = false; m_logging = false; m_loggedFrames = 0; - //create filename for autosaving of tool storage QString loggingPathWithoutFilename = QString(mitk::LoggingBackend::GetLogFile().c_str()); if (!loggingPathWithoutFilename.isEmpty()) //if there already is a path for the MITK logging file use this one - { + { //extract path from path+filename (if someone knows a better way to do this feel free to change it) int lengthOfFilename = QFileInfo(QString::fromStdString(mitk::LoggingBackend::GetLogFile())).fileName().size(); - loggingPathWithoutFilename.resize(loggingPathWithoutFilename.size()-lengthOfFilename); + loggingPathWithoutFilename.resize(loggingPathWithoutFilename.size() - lengthOfFilename); m_AutoSaveFilename = loggingPathWithoutFilename + "TrackingToolboxAutoSave.IGTToolStorage"; - } + } else //if not: use a temporary path from IOUtil - { + { m_AutoSaveFilename = QString(mitk::IOUtil::GetTempPath().c_str()) + "TrackingToolboxAutoSave.IGTToolStorage"; - } + } MITK_INFO("IGT Tracking Toolbox") << "Filename for auto saving of IGT ToolStorages: " << m_AutoSaveFilename.toStdString(); + //! [Thread 1] //initialize worker thread m_WorkerThread = new QThread(); m_Worker = new QmitkMITKIGTTrackingToolboxViewWorker(); + //! [Thread 1] ctkPluginContext* pluginContext = mitk::PluginActivator::GetContext(); if (pluginContext) { QString interfaceName = QString::fromStdString(us_service_interface_iid()); QList serviceReference = pluginContext->getServiceReferences(interfaceName); if (serviceReference.size() > 0) { m_DeviceTypeServiceReference = serviceReference.at(0); const ctkServiceReference& r = serviceReference.at(0); m_DeviceTypeCollection = pluginContext->getService(r); } else { MITK_INFO << "No Tracking Device Collection!"; } - } - } QmitkMITKIGTTrackingToolboxView::~QmitkMITKIGTTrackingToolboxView() { -this->StoreUISettings(); -m_TrackingLoggingTimer->stop(); -m_TrackingRenderTimer->stop(); -m_TimeoutTimer->stop(); -delete m_TrackingLoggingTimer; -delete m_TrackingRenderTimer; -delete m_TimeoutTimer; -try - { - // wait for thread to finish - m_WorkerThread->terminate(); - m_WorkerThread->wait(); - //clean up worker thread - if(m_WorkerThread) {delete m_WorkerThread;} - if(m_Worker) {delete m_Worker;} - //remove the tracking volume - this->GetDataStorage()->Remove(m_TrackingVolumeNode); - //unregister microservices - if(m_toolStorage) {m_toolStorage->UnRegisterMicroservice();} - if(m_TrackingDeviceSource) {m_TrackingDeviceSource->UnRegisterMicroservice();} - if(m_IGTLMessageProvider.IsNotNull()){m_IGTLMessageProvider->UnRegisterMicroservice();} - } - catch(std::exception& e) {MITK_WARN << "Unexpected exception during clean up of tracking toolbox view: " << e.what();} - catch(...) {MITK_WARN << "Unexpected unknown error during clean up of tracking toolbox view!";} -//store tool storage and UI settings for persistence -this->AutoSaveToolStorage(); -this->StoreUISettings(); - -m_DeviceTypeCollection = nullptr; -mitk::PluginActivator::GetContext()->ungetService(m_DeviceTypeServiceReference); - + this->StoreUISettings(); + m_TrackingLoggingTimer->stop(); + m_TrackingRenderTimer->stop(); + m_TimeoutTimer->stop(); + delete m_TrackingLoggingTimer; + delete m_TrackingRenderTimer; + delete m_TimeoutTimer; + try + { + //! [Thread 2] + // wait for thread to finish + m_WorkerThread->terminate(); + m_WorkerThread->wait(); + //clean up worker thread + if (m_WorkerThread) { delete m_WorkerThread; } + if (m_Worker) { delete m_Worker; } + //! [Thread 2] + + //remove the tracking volume + this->GetDataStorage()->Remove(m_TrackingVolumeNode); + //unregister microservices + if (m_toolStorage) { m_toolStorage->UnRegisterMicroservice(); } + if (m_TrackingDeviceSource) { m_TrackingDeviceSource->UnRegisterMicroservice(); } + if (m_IGTLMessageProvider.IsNotNull()){ m_IGTLMessageProvider->UnRegisterMicroservice(); } + } + catch (std::exception& e) { MITK_WARN << "Unexpected exception during clean up of tracking toolbox view: " << e.what(); } + catch (...) { MITK_WARN << "Unexpected unknown error during clean up of tracking toolbox view!"; } + //store tool storage and UI settings for persistence + this->AutoSaveToolStorage(); + this->StoreUISettings(); + + m_DeviceTypeCollection = nullptr; + mitk::PluginActivator::GetContext()->ungetService(m_DeviceTypeServiceReference); } -void QmitkMITKIGTTrackingToolboxView::CreateQtPartControl( QWidget *parent ) +void QmitkMITKIGTTrackingToolboxView::CreateQtPartControl(QWidget *parent) { // build up qt view, unless already done - if ( !m_Controls ) + if (!m_Controls) { // create GUI widgets from the Qt Designer's .ui file m_Controls = new Ui::QmitkMITKIGTTrackingToolboxViewControls; - m_Controls->setupUi( parent ); + m_Controls->setupUi(parent); //create connections - connect( m_Controls->m_LoadTools, SIGNAL(clicked()), this, SLOT(OnLoadTools()) ); - connect( m_Controls->m_ConnectDisconnectButton, SIGNAL(clicked()), this, SLOT(OnConnectDisconnect()) ); - connect( m_Controls->m_StartStopTrackingButton, SIGNAL(clicked()), this, SLOT(OnStartStopTracking()) ); - connect( m_Controls->m_FreezeUnfreezeTrackingButton, SIGNAL(clicked()), this, SLOT(OnFreezeUnfreezeTracking()) ); - connect( m_TrackingLoggingTimer, SIGNAL(timeout()), this, SLOT(UpdateLoggingTrackingTimer())); - connect( m_TrackingRenderTimer, SIGNAL(timeout()), this, SLOT(UpdateRenderTrackingTimer())); - connect( m_TimeoutTimer, SIGNAL(timeout()), this, SLOT(OnTimeOut())); - connect( m_Controls->m_ChooseFile, SIGNAL(clicked()), this, SLOT(OnChooseFileClicked())); - connect( m_Controls->m_StartLogging, SIGNAL(clicked()), this, SLOT(StartLogging())); - connect( m_Controls->m_StopLogging, SIGNAL(clicked()), this, SLOT(StopLogging())); - connect( m_Controls->m_VolumeSelectionBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(OnTrackingVolumeChanged(QString))); - connect( m_Controls->m_ShowTrackingVolume, SIGNAL(clicked()), this, SLOT(OnShowTrackingVolumeChanged())); - connect( m_Controls->m_AutoDetectTools, SIGNAL(clicked()), this, SLOT(OnAutoDetectTools())); - connect( m_Controls->m_ResetTools, SIGNAL(clicked()), this, SLOT(OnResetTools())); - connect( m_Controls->m_AddSingleTool, SIGNAL(clicked()), this, SLOT(OnAddSingleTool())); - connect( m_Controls->m_NavigationToolCreationWidget, SIGNAL(NavigationToolFinished()), this, SLOT(OnAddSingleToolFinished())); - connect( m_Controls->m_NavigationToolCreationWidget, SIGNAL(Canceled()), this, SLOT(OnAddSingleToolCanceled())); - connect( m_Controls->m_csvFormat, SIGNAL(clicked()), this, SLOT(OnToggleFileExtension())); - connect( m_Controls->m_xmlFormat, SIGNAL(clicked()), this, SLOT(OnToggleFileExtension())); - connect( m_Controls->m_UseDifferentUpdateRates, SIGNAL(clicked()), this, SLOT(OnToggleDifferentUpdateRates())); - connect( m_Controls->m_RenderUpdateRate, SIGNAL(valueChanged(int)), this, SLOT(OnChangeRenderUpdateRate())); - connect( m_Controls->m_DisableAllTimers, SIGNAL(stateChanged(int)), this, SLOT(EnableDisableTimerButtons(int))); + connect(m_Controls->m_LoadTools, SIGNAL(clicked()), this, SLOT(OnLoadTools())); + connect(m_Controls->m_ConnectDisconnectButton, SIGNAL(clicked()), this, SLOT(OnConnectDisconnect())); + connect(m_Controls->m_StartStopTrackingButton, SIGNAL(clicked()), this, SLOT(OnStartStopTracking())); + connect(m_Controls->m_FreezeUnfreezeTrackingButton, SIGNAL(clicked()), this, SLOT(OnFreezeUnfreezeTracking())); + connect(m_TrackingLoggingTimer, SIGNAL(timeout()), this, SLOT(UpdateLoggingTrackingTimer())); + connect(m_TrackingRenderTimer, SIGNAL(timeout()), this, SLOT(UpdateRenderTrackingTimer())); + connect(m_TimeoutTimer, SIGNAL(timeout()), this, SLOT(OnTimeOut())); + connect(m_Controls->m_ChooseFile, SIGNAL(clicked()), this, SLOT(OnChooseFileClicked())); + connect(m_Controls->m_StartLogging, SIGNAL(clicked()), this, SLOT(StartLogging())); + connect(m_Controls->m_StopLogging, SIGNAL(clicked()), this, SLOT(StopLogging())); + connect(m_Controls->m_VolumeSelectionBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(OnTrackingVolumeChanged(QString))); + connect(m_Controls->m_ShowTrackingVolume, SIGNAL(clicked()), this, SLOT(OnShowTrackingVolumeChanged())); + connect(m_Controls->m_AutoDetectTools, SIGNAL(clicked()), this, SLOT(OnAutoDetectTools())); + connect(m_Controls->m_ResetTools, SIGNAL(clicked()), this, SLOT(OnResetTools())); + connect(m_Controls->m_AddSingleTool, SIGNAL(clicked()), this, SLOT(OnAddSingleTool())); + connect(m_Controls->m_NavigationToolCreationWidget, SIGNAL(NavigationToolFinished()), this, SLOT(OnAddSingleToolFinished())); + connect(m_Controls->m_NavigationToolCreationWidget, SIGNAL(Canceled()), this, SLOT(OnAddSingleToolCanceled())); + connect(m_Controls->m_csvFormat, SIGNAL(clicked()), this, SLOT(OnToggleFileExtension())); + connect(m_Controls->m_xmlFormat, SIGNAL(clicked()), this, SLOT(OnToggleFileExtension())); + connect(m_Controls->m_UseDifferentUpdateRates, SIGNAL(clicked()), this, SLOT(OnToggleDifferentUpdateRates())); + connect(m_Controls->m_RenderUpdateRate, SIGNAL(valueChanged(int)), this, SLOT(OnChangeRenderUpdateRate())); + connect(m_Controls->m_DisableAllTimers, SIGNAL(stateChanged(int)), this, SLOT(EnableDisableTimerButtons(int))); //connections for the tracking device configuration widget - connect( m_Controls->m_configurationWidget, SIGNAL(TrackingDeviceSelectionChanged()), this, SLOT(OnTrackingDeviceChanged())); - + connect(m_Controls->m_configurationWidget, SIGNAL(TrackingDeviceSelectionChanged()), this, SLOT(OnTrackingDeviceChanged())); + //! [Thread 3] //connect worker thread - connect(m_Worker, SIGNAL(AutoDetectToolsFinished(bool,QString)), this, SLOT(OnAutoDetectToolsFinished(bool,QString)) ); - connect(m_Worker, SIGNAL(ConnectDeviceFinished(bool,QString)), this, SLOT(OnConnectFinished(bool,QString)) ); - connect(m_Worker, SIGNAL(StartTrackingFinished(bool,QString)), this, SLOT(OnStartTrackingFinished(bool,QString)) ); - connect(m_Worker, SIGNAL(StopTrackingFinished(bool,QString)), this, SLOT(OnStopTrackingFinished(bool,QString)) ); - connect(m_Worker, SIGNAL(DisconnectDeviceFinished(bool,QString)), this, SLOT(OnDisconnectFinished(bool,QString)) ); - connect(m_WorkerThread,SIGNAL(started()), m_Worker, SLOT(ThreadFunc()) ); + connect(m_Worker, SIGNAL(AutoDetectToolsFinished(bool, QString)), this, SLOT(OnAutoDetectToolsFinished(bool, QString))); + connect(m_Worker, SIGNAL(ConnectDeviceFinished(bool, QString)), this, SLOT(OnConnectFinished(bool, QString))); + connect(m_Worker, SIGNAL(StartTrackingFinished(bool, QString)), this, SLOT(OnStartTrackingFinished(bool, QString))); + connect(m_Worker, SIGNAL(StopTrackingFinished(bool, QString)), this, SLOT(OnStopTrackingFinished(bool, QString))); + connect(m_Worker, SIGNAL(DisconnectDeviceFinished(bool, QString)), this, SLOT(OnDisconnectFinished(bool, QString))); + connect(m_WorkerThread, SIGNAL(started()), m_Worker, SLOT(ThreadFunc())); //move the worker to the thread m_Worker->moveToThread(m_WorkerThread); + //! [Thread 3] //initialize widgets m_Controls->m_TrackingToolsStatusWidget->SetShowPositions(true); m_Controls->m_TrackingToolsStatusWidget->SetTextAlignment(Qt::AlignLeft); //initialize tracking volume node m_TrackingVolumeNode = mitk::DataNode::New(); m_TrackingVolumeNode->SetName("TrackingVolume"); - m_TrackingVolumeNode->SetBoolProperty("Backface Culling",true); + m_TrackingVolumeNode->SetBoolProperty("Backface Culling", true); mitk::Color red; red.SetRed(1); m_TrackingVolumeNode->SetColor(red); //initialize buttons m_Controls->m_AutoDetectTools->setVisible(false); //only visible if tracking device is Aurora m_Controls->m_StartStopTrackingButton->setEnabled(false); m_Controls->m_FreezeUnfreezeTrackingButton->setEnabled(false); //initialize warning labels m_Controls->m_renderWarningLabel->setVisible(false); m_Controls->m_TrackingFrozenLabel->setVisible(false); //Update List of available models for selected tool. std::vector Compatibles; - if ( (m_Controls == NULL) || //check all these stuff for NULL, latterly this causes crashes from time to time + if ((m_Controls == NULL) || //check all these stuff for NULL, latterly this causes crashes from time to time (m_Controls->m_configurationWidget == NULL) || (m_Controls->m_configurationWidget->GetTrackingDevice().IsNull())) { MITK_ERROR << "Couldn't get current tracking device or an object is NULL, something went wrong!"; return; } else { - Compatibles = m_DeviceTypeCollection->GetDeviceDataForLine( m_Controls->m_configurationWidget->GetTrackingDevice()->GetType()); + Compatibles = m_DeviceTypeCollection->GetDeviceDataForLine(m_Controls->m_configurationWidget->GetTrackingDevice()->GetType()); } m_Controls->m_VolumeSelectionBox->clear(); - for(std::size_t i = 0; i < Compatibles.size(); i++) + for (std::size_t i = 0; i < Compatibles.size(); i++) { m_Controls->m_VolumeSelectionBox->addItem(Compatibles[i].Model.c_str()); } //initialize tool storage m_toolStorage = mitk::NavigationToolStorage::New(GetDataStorage()); m_toolStorage->SetName("TrackingToolbox Default Storage"); m_toolStorage->RegisterAsMicroservice("no tracking device"); //set home directory as default path for logfile m_Controls->m_LoggingFileName->setText(QDir::toNativeSeparators(QDir::homePath()) + QDir::separator() + "logfile.csv"); //tracking device may be changed already by the persistence of the //QmitkTrackingDeciveConfigurationWidget this->OnTrackingDeviceChanged(); this->LoadUISettings(); //add tracking volume node only to data storage this->GetDataStorage()->Add(m_TrackingVolumeNode); if (!m_Controls->m_ShowTrackingVolume->isChecked()) m_TrackingVolumeNode->SetOpacity(0.0); else m_TrackingVolumeNode->SetOpacity(0.25); //Update List of available models for selected tool. m_Controls->m_VolumeSelectionBox->clear(); - for(std::size_t i = 0; i < Compatibles.size(); i++) + for (std::size_t i = 0; i < Compatibles.size(); i++) { m_Controls->m_VolumeSelectionBox->addItem(Compatibles[i].Model.c_str()); } } } -void QmitkMITKIGTTrackingToolboxView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget) +void QmitkMITKIGTTrackingToolboxView::StdMultiWidgetAvailable(QmitkStdMultiWidget &stdMultiWidget) { m_MultiWidget = &stdMultiWidget; } void QmitkMITKIGTTrackingToolboxView::StdMultiWidgetNotAvailable() { m_MultiWidget = NULL; } void QmitkMITKIGTTrackingToolboxView::OnLoadTools() { //read in filename - QString filename = QFileDialog::getOpenFileName(NULL,tr("Open Tool Storage"), "/", tr("Tool Storage Files (*.IGTToolStorage)")); + QString filename = QFileDialog::getOpenFileName(NULL, tr("Open Tool Storage"), "/", tr("Tool Storage Files (*.IGTToolStorage)")); if (filename.isNull()) return; //read tool storage from disk std::string errorMessage = ""; mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(GetDataStorage()); // try-catch block for exceptions try { - this->ReplaceCurrentToolStorage(myDeserializer->Deserialize(filename.toStdString()),filename.toStdString()); + this->ReplaceCurrentToolStorage(myDeserializer->Deserialize(filename.toStdString()), filename.toStdString()); } - catch(mitk::IGTException) + catch (mitk::IGTException) { - std::string errormessage = "Error during loading the tool storage file. Please only load tool storage files created with the NavigationToolManager view."; - QMessageBox::warning(NULL, "Tool Storage Loading Error", errormessage.c_str()); - return; + std::string errormessage = "Error during loading the tool storage file. Please only load tool storage files created with the NavigationToolManager view."; + QMessageBox::warning(NULL, "Tool Storage Loading Error", errormessage.c_str()); + return; } - if(m_toolStorage->isEmpty()) + if (m_toolStorage->isEmpty()) { errorMessage = myDeserializer->GetErrorMessage(); MessageBox(errorMessage); return; } //update label UpdateToolStorageLabel(filename); //update tool preview m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels(); m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage); //save filename for persistent storage m_ToolStorageFilename = filename; } void QmitkMITKIGTTrackingToolboxView::OnResetTools() { - this->ReplaceCurrentToolStorage(mitk::NavigationToolStorage::New(GetDataStorage()),"TrackingToolbox Default Storage"); + this->ReplaceCurrentToolStorage(mitk::NavigationToolStorage::New(GetDataStorage()), "TrackingToolbox Default Storage"); m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels(); QString toolLabel = QString(""); m_Controls->m_toolLabel->setText(toolLabel); m_ToolStorageFilename = ""; } void QmitkMITKIGTTrackingToolboxView::OnStartStopTracking() { - if(!m_connected) - { + if (!m_connected) + { MITK_WARN << "Can't start tracking if no device is connected. Aborting"; return; - } - if(m_tracking) {OnStopTracking();} - else {OnStartTracking();} + } + if (m_tracking) { OnStopTracking(); } + else { OnStartTracking(); } } void QmitkMITKIGTTrackingToolboxView::OnFreezeUnfreezeTracking() { - if( m_Controls->m_FreezeUnfreezeTrackingButton->text() == "Freeze Tracking" ) + if (m_Controls->m_FreezeUnfreezeTrackingButton->text() == "Freeze Tracking") { m_TrackingDeviceSource->Freeze(); m_Controls->m_FreezeUnfreezeTrackingButton->setText("Unfreeze Tracking"); m_Controls->m_TrackingFrozenLabel->setVisible(true); } - else if( m_Controls->m_FreezeUnfreezeTrackingButton->text() == "Unfreeze Tracking" ) + else if (m_Controls->m_FreezeUnfreezeTrackingButton->text() == "Unfreeze Tracking") { m_TrackingDeviceSource->UnFreeze(); m_Controls->m_FreezeUnfreezeTrackingButton->setText("Freeze Tracking"); m_Controls->m_TrackingFrozenLabel->setVisible(false); } } void QmitkMITKIGTTrackingToolboxView::OnConnectDisconnect() { - if(m_connected) {OnDisconnect();} - else {OnConnect();} + if (m_connected) { OnDisconnect(); } + else { OnConnect(); } } void QmitkMITKIGTTrackingToolboxView::OnConnect() { MITK_INFO << "Connect Clicked"; //check if everything is ready to start tracking if (this->m_toolStorage.IsNull()) { MessageBox("Error: No Tools Loaded Yet!"); return; } else if (this->m_toolStorage->GetToolCount() == 0) { MessageBox("Error: No Way To Track Without Tools!"); return; } //parse tracking device data mitk::TrackingDeviceData data = mitk::UnspecifiedTrackingTypeInformation::GetDeviceDataUnspecified(); - QString qstr = m_Controls->m_VolumeSelectionBox->currentText(); - if ( (! qstr.isNull()) || (! qstr.isEmpty()) ) { + QString qstr = m_Controls->m_VolumeSelectionBox->currentText(); + if ((!qstr.isNull()) || (!qstr.isEmpty())) { std::string str = qstr.toStdString(); data = m_DeviceTypeCollection->GetDeviceDataByName(str); //Data will be set later, after device generation } + //! [Thread 4] //initialize worker thread m_Worker->SetWorkerMethod(QmitkMITKIGTTrackingToolboxViewWorker::eConnectDevice); m_Worker->SetTrackingDevice(this->m_Controls->m_configurationWidget->GetTrackingDevice()); m_Worker->SetInverseMode(m_Controls->m_InverseMode->isChecked()); m_Worker->SetNavigationToolStorage(this->m_toolStorage); m_Worker->SetTrackingDeviceData(data); //start worker thread m_WorkerThread->start(); + //! [Thread 4] //disable buttons this->m_Controls->m_MainWidget->setEnabled(false); } void QmitkMITKIGTTrackingToolboxView::EnableDisableTimerButtons(int enable) { bool enableBool = enable; m_Controls->m_UpdateRateOptionsGroupBox->setEnabled(!enableBool); m_Controls->m_renderWarningLabel->setVisible(enableBool); } void QmitkMITKIGTTrackingToolboxView::OnConnectFinished(bool success, QString errorMessage) { m_WorkerThread->quit(); m_WorkerThread->wait(); //enable buttons this->m_Controls->m_MainWidget->setEnabled(true); if (!success) { MITK_WARN << errorMessage.toStdString(); MessageBox(errorMessage.toStdString()); return; } + //! [Thread 6] //get data from worker thread m_TrackingDeviceSource = m_Worker->GetTrackingDeviceSource(); m_TrackingDeviceData = m_Worker->GetTrackingDeviceData(); m_ToolVisualizationFilter = m_Worker->GetToolVisualizationFilter(); + //! [Thread 6] //enable/disable Buttons DisableOptionsButtons(); DisableTrackingConfigurationButtons(); m_Controls->m_TrackingControlLabel->setText("Status: connected"); m_Controls->m_ConnectDisconnectButton->setText("Disconnect"); m_Controls->m_StartStopTrackingButton->setEnabled(true); m_connected = true; - } +} void QmitkMITKIGTTrackingToolboxView::OnDisconnect() { m_Worker->SetWorkerMethod(QmitkMITKIGTTrackingToolboxViewWorker::eDisconnectDevice); m_WorkerThread->start(); m_Controls->m_MainWidget->setEnabled(false); } void QmitkMITKIGTTrackingToolboxView::OnDisconnectFinished(bool success, QString errorMessage) { m_WorkerThread->quit(); m_WorkerThread->wait(); m_Controls->m_MainWidget->setEnabled(true); if (!success) { MITK_WARN << errorMessage.toStdString(); MessageBox(errorMessage.toStdString()); return; } //enable/disable Buttons m_Controls->m_StartStopTrackingButton->setEnabled(false); EnableOptionsButtons(); EnableTrackingConfigurationButtons(); m_Controls->m_TrackingControlLabel->setText("Status: disconnected"); m_Controls->m_ConnectDisconnectButton->setText("Connect"); m_Controls->m_FreezeUnfreezeTrackingButton->setText("Freeze Tracking"); m_Controls->m_TrackingFrozenLabel->setVisible(false); m_connected = false; - } +} void QmitkMITKIGTTrackingToolboxView::OnStartTracking() { m_Worker->SetWorkerMethod(QmitkMITKIGTTrackingToolboxViewWorker::eStartTracking); m_WorkerThread->start(); this->m_Controls->m_MainWidget->setEnabled(false); } void QmitkMITKIGTTrackingToolboxView::OnStartTrackingFinished(bool success, QString errorMessage) { + //! [Thread 5] m_WorkerThread->quit(); m_WorkerThread->wait(); + //! [Thread 5] this->m_Controls->m_MainWidget->setEnabled(true); - if(!success) + if (!success) { MessageBox(errorMessage.toStdString()); MITK_WARN << errorMessage.toStdString(); return; } - if(!(m_Controls->m_DisableAllTimers->isChecked())) + if (!(m_Controls->m_DisableAllTimers->isChecked())) { - if(m_Controls->m_UseDifferentUpdateRates->isChecked()) - { - if(m_Controls->m_RenderUpdateRate->value() != 0) - m_TrackingRenderTimer->start(1000/(m_Controls->m_RenderUpdateRate->value())); - m_TrackingLoggingTimer->start(1000/(m_Controls->m_LogUpdateRate->value())); - } - else - { - m_TrackingRenderTimer->start(1000/(m_Controls->m_UpdateRate->value())); - m_TrackingLoggingTimer->start(1000/(m_Controls->m_UpdateRate->value())); - } + if (m_Controls->m_UseDifferentUpdateRates->isChecked()) + { + if (m_Controls->m_RenderUpdateRate->value() != 0) + m_TrackingRenderTimer->start(1000 / (m_Controls->m_RenderUpdateRate->value())); + m_TrackingLoggingTimer->start(1000 / (m_Controls->m_LogUpdateRate->value())); + } + else + { + m_TrackingRenderTimer->start(1000 / (m_Controls->m_UpdateRate->value())); + m_TrackingLoggingTimer->start(1000 / (m_Controls->m_UpdateRate->value())); + } } m_Controls->m_TrackingControlLabel->setText("Status: tracking"); //connect the tool visualization widget - for(std::size_t i=0; iGetNumberOfOutputs(); i++) + for (std::size_t i = 0; i < m_TrackingDeviceSource->GetNumberOfOutputs(); i++) { m_Controls->m_TrackingToolsStatusWidget->AddNavigationData(m_TrackingDeviceSource->GetOutput(i)); } m_Controls->m_TrackingToolsStatusWidget->ShowStatusLabels(); - if (m_Controls->m_ShowToolQuaternions->isChecked()) {m_Controls->m_TrackingToolsStatusWidget->SetShowQuaternions(true);} - else {m_Controls->m_TrackingToolsStatusWidget->SetShowQuaternions(false);} + if (m_Controls->m_ShowToolQuaternions->isChecked()) { m_Controls->m_TrackingToolsStatusWidget->SetShowQuaternions(true); } + else { m_Controls->m_TrackingToolsStatusWidget->SetShowQuaternions(false); } //if activated enable open IGT link microservice if (m_Controls->m_EnableOpenIGTLinkMicroService->isChecked()) - { + { //create convertion filter - m_IGTLConversionFilter = mitk::NavigationDataToIGTLMessageFilter::New(); + m_IGTLConversionFilter = mitk::NavigationDataToIGTLMessageFilter::New(); m_IGTLConversionFilter->SetName("IGT Tracking Toolbox"); m_IGTLConversionFilter->ConnectTo(m_ToolVisualizationFilter); m_IGTLConversionFilter->SetOperationMode(mitk::NavigationDataToIGTLMessageFilter::ModeSendTDataMsg); m_IGTLConversionFilter->RegisterAsMicroservice(); //create server and message provider m_IGTLServer = mitk::IGTLServer::New(false); m_IGTLServer->SetName("Tracking Toolbox IGTL Server"); m_IGTLMessageProvider = mitk::IGTLMessageProvider::New(); m_IGTLMessageProvider->SetIGTLDevice(m_IGTLServer); m_IGTLMessageProvider->RegisterAsMicroservice(); - } + } //show tracking volume this->OnTrackingVolumeChanged(m_Controls->m_VolumeSelectionBox->currentText()); m_tracking = true; m_Controls->m_ConnectDisconnectButton->setEnabled(false); m_Controls->m_StartStopTrackingButton->setText("Stop Tracking"); m_Controls->m_FreezeUnfreezeTrackingButton->setEnabled(true); this->GlobalReinit(); } void QmitkMITKIGTTrackingToolboxView::OnStopTracking() { if (!m_tracking) return; m_TrackingRenderTimer->stop(); m_TrackingLoggingTimer->stop(); m_Worker->SetWorkerMethod(QmitkMITKIGTTrackingToolboxViewWorker::eStopTracking); m_WorkerThread->start(); m_Controls->m_MainWidget->setEnabled(false); } void QmitkMITKIGTTrackingToolboxView::OnStopTrackingFinished(bool success, QString errorMessage) { m_WorkerThread->quit(); m_WorkerThread->wait(); m_Controls->m_MainWidget->setEnabled(true); - if(!success) + if (!success) { MessageBox(errorMessage.toStdString()); MITK_WARN << errorMessage.toStdString(); return; } m_Controls->m_TrackingControlLabel->setText("Status: connected"); if (m_logging) StopLogging(); m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels(); m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage); m_tracking = false; m_Controls->m_StartStopTrackingButton->setText("Start Tracking"); m_Controls->m_ConnectDisconnectButton->setEnabled(true); m_Controls->m_FreezeUnfreezeTrackingButton->setEnabled(false); //unregister open IGT link micro service if (m_Controls->m_EnableOpenIGTLinkMicroService->isChecked()) - { + { m_IGTLConversionFilter->UnRegisterMicroservice(); m_IGTLMessageProvider->UnRegisterMicroservice(); - } + } this->GlobalReinit(); } void QmitkMITKIGTTrackingToolboxView::OnTrackingDeviceChanged() { mitk::TrackingDeviceType Type; if (m_Controls->m_configurationWidget->GetTrackingDevice().IsNotNull()) { Type = m_Controls->m_configurationWidget->GetTrackingDevice()->GetType(); //enable controls because device is valid m_Controls->m_TrackingToolsGoupBox->setEnabled(true); m_Controls->m_TrackingControlsGroupBox->setEnabled(true); } else { Type = mitk::UnspecifiedTrackingTypeInformation::GetTrackingDeviceName(); 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."); m_Controls->m_TrackingToolsGoupBox->setEnabled(false); m_Controls->m_TrackingControlsGroupBox->setEnabled(false); return; } // Code to enable/disable device specific buttons if (Type == mitk::NDIAuroraTypeInformation::GetTrackingDeviceName()) //Aurora { m_Controls->m_AutoDetectTools->setVisible(true); m_Controls->m_AddSingleTool->setEnabled(false); } else //Polaris or Microntracker { m_Controls->m_AutoDetectTools->setVisible(false); m_Controls->m_AddSingleTool->setEnabled(true); } // Code to select appropriate tracking volume for current type std::vector Compatibles = m_DeviceTypeCollection->GetDeviceDataForLine(Type); m_Controls->m_VolumeSelectionBox->clear(); - for(std::size_t i = 0; i < Compatibles.size(); i++) + for (std::size_t i = 0; i < Compatibles.size(); i++) { m_Controls->m_VolumeSelectionBox->addItem(Compatibles[i].Model.c_str()); } } void QmitkMITKIGTTrackingToolboxView::OnTrackingVolumeChanged(QString qstr) { if (qstr.isNull()) return; if (qstr.isEmpty()) return; mitk::TrackingVolumeGenerator::Pointer volumeGenerator = mitk::TrackingVolumeGenerator::New(); std::string str = qstr.toStdString(); mitk::TrackingDeviceData data = m_DeviceTypeCollection->GetDeviceDataByName(str); m_TrackingDeviceData = data; volumeGenerator->SetTrackingDeviceData(data); volumeGenerator->Update(); mitk::Surface::Pointer volumeSurface = volumeGenerator->GetOutput(); m_TrackingVolumeNode->SetData(volumeSurface); if (!m_Controls->m_ShowTrackingVolume->isChecked()) m_TrackingVolumeNode->SetOpacity(0.0); else m_TrackingVolumeNode->SetOpacity(0.25); GlobalReinit(); } void QmitkMITKIGTTrackingToolboxView::OnShowTrackingVolumeChanged() { if (m_Controls->m_ShowTrackingVolume->isChecked()) { OnTrackingVolumeChanged(m_Controls->m_VolumeSelectionBox->currentText()); m_TrackingVolumeNode->SetOpacity(0.25); } else { m_TrackingVolumeNode->SetOpacity(0.0); } } void QmitkMITKIGTTrackingToolboxView::OnAutoDetectTools() { if (m_Controls->m_configurationWidget->GetTrackingDevice()->GetType() == mitk::NDIAuroraTypeInformation::GetTrackingDeviceName()) { DisableTrackingConfigurationButtons(); m_Worker->SetWorkerMethod(QmitkMITKIGTTrackingToolboxViewWorker::eAutoDetectTools); m_Worker->SetTrackingDevice(m_Controls->m_configurationWidget->GetTrackingDevice().GetPointer()); m_Worker->SetDataStorage(this->GetDataStorage()); m_WorkerThread->start(); m_TimeoutTimer->start(5000); MITK_INFO << "Timeout Timer started"; //disable controls until worker thread is finished this->m_Controls->m_MainWidget->setEnabled(false); } } void QmitkMITKIGTTrackingToolboxView::OnAutoDetectToolsFinished(bool success, QString errorMessage) { - m_TimeoutTimer->stop(); - m_WorkerThread->quit(); - m_WorkerThread->wait(); + m_TimeoutTimer->stop(); + m_WorkerThread->quit(); + m_WorkerThread->wait(); //enable controls again this->m_Controls->m_MainWidget->setEnabled(true); - EnableTrackingConfigurationButtons(); + EnableTrackingConfigurationButtons(); - if(!success) + if (!success) { MITK_WARN << errorMessage.toStdString(); MessageBox(errorMessage.toStdString()); EnableTrackingConfigurationButtons(); return; } mitk::NavigationToolStorage::Pointer autoDetectedStorage = m_Worker->GetNavigationToolStorage(); - //save detected tools - this->ReplaceCurrentToolStorage(autoDetectedStorage,"Autodetected NDI Aurora Storage"); - //auto save the new storage to hard disc (for persistence) - AutoSaveToolStorage(); - //update label - QString toolLabel = QString("Loaded Tools: ") + QString::number(m_toolStorage->GetToolCount()) + " Tools (Auto Detected)"; - m_Controls->m_toolLabel->setText(toolLabel); - //update tool preview - m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels(); + //save detected tools + this->ReplaceCurrentToolStorage(autoDetectedStorage, "Autodetected NDI Aurora Storage"); + //auto save the new storage to hard disc (for persistence) + AutoSaveToolStorage(); + //update label + QString toolLabel = QString("Loaded Tools: ") + QString::number(m_toolStorage->GetToolCount()) + " Tools (Auto Detected)"; + m_Controls->m_toolLabel->setText(toolLabel); + //update tool preview + m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels(); m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage); EnableTrackingConfigurationButtons(); - if (m_toolStorage->GetToolCount()>0) + if (m_toolStorage->GetToolCount() > 0) { //ask the user if he wants to save the detected tools QMessageBox msgBox; - switch(m_toolStorage->GetToolCount()) + switch (m_toolStorage->GetToolCount()) { case 1: msgBox.setText("Found one tool!"); break; default: msgBox.setText("Found " + QString::number(m_toolStorage->GetToolCount()) + " tools!"); } msgBox.setInformativeText("Do you want to save this tools as tool storage, so you can load them again?"); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msgBox.setDefaultButton(QMessageBox::No); int ret = msgBox.exec(); if (ret == 16384) //yes { //ask the user for a filename - QString fileName = QFileDialog::getSaveFileName(NULL, tr("Save File"),"/",tr("*.IGTToolStorage")); + QString fileName = QFileDialog::getSaveFileName(NULL, tr("Save File"), "/", tr("*.IGTToolStorage")); //check for empty filename - if(fileName == "") {return;} + if (fileName == "") { return; } mitk::NavigationToolStorageSerializer::Pointer mySerializer = mitk::NavigationToolStorageSerializer::New(); //when Serialize method is used exceptions are thrown, need to be adapted //try-catch block for exception handling in Serializer try { - mySerializer->Serialize(fileName.toStdString(),m_toolStorage); + mySerializer->Serialize(fileName.toStdString(), m_toolStorage); } - catch(mitk::IGTException) + catch (mitk::IGTException) { std::string errormessage = "Error during serialization. Please check the Zip file."; QMessageBox::warning(NULL, "IGTPlayer: Error", errormessage.c_str()); } return; } else if (ret == 65536) //no { return; } } - //print a logging message about the detected tools - switch(m_toolStorage->GetToolCount()) - { - case 0: - MITK_INFO("IGT Tracking Toolbox") << "Found no tools. Empty ToolStorage was autosaved to " << m_ToolStorageFilename.toStdString(); - break; - case 1: - MITK_INFO("IGT Tracking Toolbox") << "Found one tool. ToolStorage was autosaved to " << m_ToolStorageFilename.toStdString(); - break; - default: - MITK_INFO("IGT Tracking Toolbox") << "Found " << m_toolStorage->GetToolCount() << " tools. ToolStorage was autosaved to " << m_ToolStorageFilename.toStdString(); - } + //print a logging message about the detected tools + switch (m_toolStorage->GetToolCount()) + { + case 0: + MITK_INFO("IGT Tracking Toolbox") << "Found no tools. Empty ToolStorage was autosaved to " << m_ToolStorageFilename.toStdString(); + break; + case 1: + MITK_INFO("IGT Tracking Toolbox") << "Found one tool. ToolStorage was autosaved to " << m_ToolStorageFilename.toStdString(); + break; + default: + MITK_INFO("IGT Tracking Toolbox") << "Found " << m_toolStorage->GetToolCount() << " tools. ToolStorage was autosaved to " << m_ToolStorageFilename.toStdString(); + } } void QmitkMITKIGTTrackingToolboxView::MessageBox(std::string s) { QMessageBox msgBox; msgBox.setText(s.c_str()); msgBox.exec(); } void QmitkMITKIGTTrackingToolboxView::UpdateRenderTrackingTimer() { //update filter m_ToolVisualizationFilter->Update(); MITK_DEBUG << "Number of outputs ToolVisualizationFilter: " << m_ToolVisualizationFilter->GetNumberOfIndexedOutputs(); MITK_DEBUG << "Number of inputs ToolVisualizationFilter: " << m_ToolVisualizationFilter->GetNumberOfIndexedInputs(); //update tool colors to show tool status - for(unsigned int i=0; iGetNumberOfIndexedOutputs(); i++) + for (unsigned int i = 0; i < m_ToolVisualizationFilter->GetNumberOfIndexedOutputs(); i++) { mitk::NavigationData::Pointer currentTool = m_ToolVisualizationFilter->GetOutput(i); - if(currentTool->IsDataValid()) - {this->m_toolStorage->GetTool(i)->GetDataNode()->SetColor(mitk::IGTColor_VALID);} + if (currentTool->IsDataValid()) + { + this->m_toolStorage->GetTool(i)->GetDataNode()->SetColor(mitk::IGTColor_VALID); + } else - {this->m_toolStorage->GetTool(i)->GetDataNode()->SetColor(mitk::IGTColor_WARNING);} + { + this->m_toolStorage->GetTool(i)->GetDataNode()->SetColor(mitk::IGTColor_WARNING); + } } //refresh view and status widget mitk::RenderingManager::GetInstance()->RequestUpdateAll(); m_Controls->m_TrackingToolsStatusWidget->Refresh(); //code to better isolate bug 17713, could be removed when bug 17713 is fixed static int i = 0; static mitk::Point3D lastPositionTool1 = m_ToolVisualizationFilter->GetOutput(0)->GetPosition(); static itk::TimeStamp lastTimeStamp = m_ToolVisualizationFilter->GetOutput(0)->GetTimeStamp(); i++; //every 20 frames: check if tracking is frozen - if(i>20) - { + if (i > 20) + { i = 0; if (m_ToolVisualizationFilter->GetOutput(0)->IsDataValid()) + { + if (mitk::Equal(lastPositionTool1, m_ToolVisualizationFilter->GetOutput(0)->GetPosition(), 0.000000001, false)) { - if (mitk::Equal(lastPositionTool1,m_ToolVisualizationFilter->GetOutput(0)->GetPosition(),0.000000001,false)) - { MITK_WARN << "Seems as tracking (of at least tool 1) is frozen which means that bug 17713 occurred. Restart tracking might help."; //display further information to find the bug MITK_WARN << "Timestamp of current navigation data: " << m_ToolVisualizationFilter->GetOutput(0)->GetTimeStamp(); MITK_WARN << "Timestamp of last navigation data (which holds the same values): " << lastTimeStamp; - } + } lastPositionTool1 = m_ToolVisualizationFilter->GetOutput(0)->GetPosition(); lastTimeStamp = m_ToolVisualizationFilter->GetOutput(0)->GetTimeStamp(); - } } + } } void QmitkMITKIGTTrackingToolboxView::UpdateLoggingTrackingTimer() { //update logging if (m_logging) { this->m_loggingFilter->Update(); m_loggedFrames = this->m_loggingFilter->GetNumberOfRecordedSteps(); - this->m_Controls->m_LoggedFramesLabel->setText("Logged Frames: "+QString::number(m_loggedFrames)); + this->m_Controls->m_LoggedFramesLabel->setText("Logged Frames: " + QString::number(m_loggedFrames)); //check if logging stopped automatically - if((m_loggedFrames>1)&&(!m_loggingFilter->GetRecording())){StopLogging();} + if ((m_loggedFrames > 1) && (!m_loggingFilter->GetRecording())){ StopLogging(); } } //refresh status widget m_Controls->m_TrackingToolsStatusWidget->Refresh(); - } void QmitkMITKIGTTrackingToolboxView::OnChooseFileClicked() { QDir currentPath = QFileInfo(m_Controls->m_LoggingFileName->text()).dir(); // if no path was selected (QDir would select current working dir then) or the // selected path does not exist -> use home directory - if ( currentPath == QDir() || ! currentPath.exists() ) + if (currentPath == QDir() || !currentPath.exists()) { currentPath = QDir(QDir::homePath()); } - QString filename = QFileDialog::getSaveFileName(NULL,tr("Choose Logging File"), currentPath.absolutePath(), "*.*"); + QString filename = QFileDialog::getSaveFileName(NULL, tr("Choose Logging File"), currentPath.absolutePath(), "*.*"); if (filename == "") return; this->m_Controls->m_LoggingFileName->setText(filename); this->OnToggleFileExtension(); } // bug-16470: toggle file extension after clicking on radio button void QmitkMITKIGTTrackingToolboxView::OnToggleFileExtension() { QString currentInputText = this->m_Controls->m_LoggingFileName->text(); QString currentFile = QFileInfo(currentInputText).baseName(); QDir currentPath = QFileInfo(currentInputText).dir(); - if(currentFile.isEmpty()) + if (currentFile.isEmpty()) { currentFile = "logfile"; } // Setting currentPath to default home path when currentPath is empty or it does not exist - if(currentPath == QDir() || !currentPath.exists()) + if (currentPath == QDir() || !currentPath.exists()) { currentPath = QDir::homePath(); } // check if csv radio button is clicked - if(this->m_Controls->m_csvFormat->isChecked()) + if (this->m_Controls->m_csvFormat->isChecked()) { // you needn't add a seperator to the input text when currentpath is the rootpath - if(currentPath.isRoot()) + if (currentPath.isRoot()) { this->m_Controls->m_LoggingFileName->setText(QDir::toNativeSeparators(currentPath.absolutePath()) + currentFile + ".csv"); } else { this->m_Controls->m_LoggingFileName->setText(QDir::toNativeSeparators(currentPath.absolutePath()) + QDir::separator() + currentFile + ".csv"); } } // check if xml radio button is clicked - else if(this->m_Controls->m_xmlFormat->isChecked()) + else if (this->m_Controls->m_xmlFormat->isChecked()) { // you needn't add a seperator to the input text when currentpath is the rootpath - if(currentPath.isRoot()) + if (currentPath.isRoot()) { this->m_Controls->m_LoggingFileName->setText(QDir::toNativeSeparators(currentPath.absolutePath()) + currentFile + ".xml"); } else { this->m_Controls->m_LoggingFileName->setText(QDir::toNativeSeparators(currentPath.absolutePath()) + QDir::separator() + currentFile + ".xml"); } } } void QmitkMITKIGTTrackingToolboxView::OnToggleDifferentUpdateRates() { - if(m_Controls->m_UseDifferentUpdateRates->isChecked()) + if (m_Controls->m_UseDifferentUpdateRates->isChecked()) { - if(m_Controls->m_RenderUpdateRate->value() == 0) + if (m_Controls->m_RenderUpdateRate->value() == 0) m_Controls->m_renderWarningLabel->setVisible(true); else m_Controls->m_renderWarningLabel->setVisible(false); m_Controls->m_UpdateRate->setEnabled(false); m_Controls->m_OptionsUpdateRateLabel->setEnabled(false); m_Controls->m_RenderUpdateRate->setEnabled(true); m_Controls->m_OptionsRenderUpdateRateLabel->setEnabled(true); m_Controls->m_LogUpdateRate->setEnabled(true); m_Controls->m_OptionsLogUpdateRateLabel->setEnabled(true); } else { m_Controls->m_renderWarningLabel->setVisible(false); m_Controls->m_UpdateRate->setEnabled(true); m_Controls->m_OptionsUpdateRateLabel->setEnabled(true); m_Controls->m_RenderUpdateRate->setEnabled(false); m_Controls->m_OptionsRenderUpdateRateLabel->setEnabled(false); m_Controls->m_LogUpdateRate->setEnabled(false); m_Controls->m_OptionsLogUpdateRateLabel->setEnabled(false); } } void QmitkMITKIGTTrackingToolboxView::OnChangeRenderUpdateRate() { - if(m_Controls->m_RenderUpdateRate->value() == 0) + if (m_Controls->m_RenderUpdateRate->value() == 0) m_Controls->m_renderWarningLabel->setVisible(true); else m_Controls->m_renderWarningLabel->setVisible(false); } void QmitkMITKIGTTrackingToolboxView::StartLogging() { if (m_ToolVisualizationFilter.IsNull()) { MessageBox("Cannot activate logging without a connected device. Configure and connect a tracking device first."); return; } if (!m_logging) { //initialize logging filter m_loggingFilter = mitk::NavigationDataRecorder::New(); m_loggingFilter->ConnectTo(m_ToolVisualizationFilter); - if (m_Controls->m_LoggingLimit->isChecked()){m_loggingFilter->SetRecordCountLimit(m_Controls->m_LoggedFramesLimit->value());} + if (m_Controls->m_LoggingLimit->isChecked()){ m_loggingFilter->SetRecordCountLimit(m_Controls->m_LoggedFramesLimit->value()); } //start filter with try-catch block for exceptions try { m_loggingFilter->StartRecording(); } - catch(mitk::IGTException) + catch (mitk::IGTException) { std::string errormessage = "Error during start recording. Recorder already started recording?"; QMessageBox::warning(NULL, "IGTPlayer: Error", errormessage.c_str()); m_loggingFilter->StopRecording(); return; } //update labels / logging variables this->m_Controls->m_LoggingLabel->setText("Logging ON"); this->m_Controls->m_LoggedFramesLabel->setText("Logged Frames: 0"); m_loggedFrames = 0; m_logging = true; DisableLoggingButtons(); } } void QmitkMITKIGTTrackingToolboxView::StopLogging() { if (m_logging) { //stop logging m_loggingFilter->StopRecording(); m_logging = false; //update GUI this->m_Controls->m_LoggingLabel->setText("Logging OFF"); EnableLoggingButtons(); //write the results to a file - if(m_Controls->m_csvFormat->isChecked()) - { - mitk::IOUtil::SaveBaseData(m_loggingFilter->GetNavigationDataSet(), this->m_Controls->m_LoggingFileName->text().toStdString()); - } + if (m_Controls->m_csvFormat->isChecked()) + { + mitk::IOUtil::SaveBaseData(m_loggingFilter->GetNavigationDataSet(), this->m_Controls->m_LoggingFileName->text().toStdString()); + } else if (m_Controls->m_xmlFormat->isChecked()) - { - mitk::IOUtil::SaveBaseData(m_loggingFilter->GetNavigationDataSet(), this->m_Controls->m_LoggingFileName->text().toStdString()); - } + { + mitk::IOUtil::SaveBaseData(m_loggingFilter->GetNavigationDataSet(), this->m_Controls->m_LoggingFileName->text().toStdString()); + } } } void QmitkMITKIGTTrackingToolboxView::OnAddSingleTool() { QString Identifier = "Tool#"; QString Name = "NewTool"; if (m_toolStorage.IsNotNull()) { Identifier += QString::number(m_toolStorage->GetToolCount()); Name += QString::number(m_toolStorage->GetToolCount()); - } else { + } + else { Identifier += "0"; Name += "0"; } - m_Controls->m_NavigationToolCreationWidget->Initialize(GetDataStorage(),Identifier.toStdString(),Name.toStdString()); - m_Controls->m_NavigationToolCreationWidget->SetTrackingDeviceType(m_Controls->m_configurationWidget->GetTrackingDevice()->GetType(),false); + m_Controls->m_NavigationToolCreationWidget->Initialize(GetDataStorage(), Identifier.toStdString(), Name.toStdString()); + m_Controls->m_NavigationToolCreationWidget->SetTrackingDeviceType(m_Controls->m_configurationWidget->GetTrackingDevice()->GetType(), false); m_Controls->m_TrackingToolsWidget->setCurrentIndex(1); //disable tracking volume during tool editing lastTrackingVolumeState = m_Controls->m_ShowTrackingVolume->isChecked(); if (lastTrackingVolumeState) m_Controls->m_ShowTrackingVolume->click(); GlobalReinit(); } void QmitkMITKIGTTrackingToolboxView::OnAddSingleToolFinished() { m_Controls->m_TrackingToolsWidget->setCurrentIndex(0); if (this->m_toolStorage.IsNull()) { //this shouldn't happen! MITK_WARN << "No ToolStorage available, cannot add tool, aborting!"; return; } m_toolStorage->AddTool(m_Controls->m_NavigationToolCreationWidget->GetCreatedTool()); m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage); m_Controls->m_toolLabel->setText(""); //auto save current storage for persistence MITK_INFO << "Auto saving manually added tools for persistence."; AutoSaveToolStorage(); //enable tracking volume again if (lastTrackingVolumeState) m_Controls->m_ShowTrackingVolume->click(); GlobalReinit(); } void QmitkMITKIGTTrackingToolboxView::OnAddSingleToolCanceled() { m_Controls->m_TrackingToolsWidget->setCurrentIndex(0); //enable tracking volume again if (lastTrackingVolumeState) m_Controls->m_ShowTrackingVolume->click(); GlobalReinit(); } void QmitkMITKIGTTrackingToolboxView::GlobalReinit() { // get all nodes that have not set "includeInBoundingBox" to false mitk::NodePredicateNot::Pointer pred = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox", mitk::BoolProperty::New(false))); mitk::DataStorage::SetOfObjects::ConstPointer rs = this->GetDataStorage()->GetSubset(pred); // calculate bounding geometry of these nodes mitk::TimeGeometry::Pointer bounds = this->GetDataStorage()->ComputeBoundingGeometry3D(rs, "visible"); // initialize the views to the bounding geometry mitk::RenderingManager::GetInstance()->InitializeViews(bounds); } void QmitkMITKIGTTrackingToolboxView::DisableLoggingButtons() { m_Controls->m_StartLogging->setEnabled(false); m_Controls->m_LoggingFileName->setEnabled(false); m_Controls->m_ChooseFile->setEnabled(false); m_Controls->m_LoggingLimit->setEnabled(false); m_Controls->m_LoggedFramesLimit->setEnabled(false); m_Controls->m_csvFormat->setEnabled(false); m_Controls->m_xmlFormat->setEnabled(false); m_Controls->m_StopLogging->setEnabled(true); } void QmitkMITKIGTTrackingToolboxView::EnableLoggingButtons() { m_Controls->m_StartLogging->setEnabled(true); m_Controls->m_LoggingFileName->setEnabled(true); m_Controls->m_ChooseFile->setEnabled(true); m_Controls->m_LoggingLimit->setEnabled(true); m_Controls->m_LoggedFramesLimit->setEnabled(true); m_Controls->m_csvFormat->setEnabled(true); m_Controls->m_xmlFormat->setEnabled(true); m_Controls->m_StopLogging->setEnabled(false); } void QmitkMITKIGTTrackingToolboxView::DisableOptionsButtons() { m_Controls->m_ShowTrackingVolume->setEnabled(false); m_Controls->m_UseDifferentUpdateRates->setEnabled(false); m_Controls->m_UpdateRate->setEnabled(false); m_Controls->m_OptionsUpdateRateLabel->setEnabled(false); m_Controls->m_RenderUpdateRate->setEnabled(false); m_Controls->m_OptionsRenderUpdateRateLabel->setEnabled(false); m_Controls->m_LogUpdateRate->setEnabled(false); m_Controls->m_OptionsLogUpdateRateLabel->setEnabled(false); m_Controls->m_DisableAllTimers->setEnabled(false); m_Controls->m_OtherOptionsGroupBox->setEnabled(false); } void QmitkMITKIGTTrackingToolboxView::EnableOptionsButtons() { m_Controls->m_ShowTrackingVolume->setEnabled(true); m_Controls->m_UseDifferentUpdateRates->setEnabled(true); m_Controls->m_DisableAllTimers->setEnabled(true); m_Controls->m_OtherOptionsGroupBox->setEnabled(true); OnToggleDifferentUpdateRates(); } void QmitkMITKIGTTrackingToolboxView::EnableTrackingControls() { m_Controls->m_TrackingControlsGroupBox->setEnabled(true); } void QmitkMITKIGTTrackingToolboxView::DisableTrackingControls() { m_Controls->m_TrackingControlsGroupBox->setEnabled(false); } void QmitkMITKIGTTrackingToolboxView::EnableTrackingConfigurationButtons() { m_Controls->m_AutoDetectTools->setEnabled(true); if (m_Controls->m_configurationWidget->GetTrackingDevice()->GetType() != mitk::NDIAuroraTypeInformation::GetTrackingDeviceName()) m_Controls->m_AddSingleTool->setEnabled(true); m_Controls->m_LoadTools->setEnabled(true); m_Controls->m_ResetTools->setEnabled(true); } void QmitkMITKIGTTrackingToolboxView::DisableTrackingConfigurationButtons() { m_Controls->m_AutoDetectTools->setEnabled(false); if (m_Controls->m_configurationWidget->GetTrackingDevice()->GetType() != mitk::NDIAuroraTypeInformation::GetTrackingDeviceName()) m_Controls->m_AddSingleTool->setEnabled(false); m_Controls->m_LoadTools->setEnabled(false); m_Controls->m_ResetTools->setEnabled(false); } void QmitkMITKIGTTrackingToolboxView::ReplaceCurrentToolStorage(mitk::NavigationToolStorage::Pointer newStorage, std::string newStorageName) { //first: get rid of the old one //don't reset if there is no tool storage. BugFix #17793 - if ( m_toolStorage.IsNotNull() ){ + if (m_toolStorage.IsNotNull()){ m_toolStorage->UnLockStorage(); //only to be sure... m_toolStorage->UnRegisterMicroservice(); m_toolStorage = nullptr; } //now: replace by the new one m_toolStorage = newStorage; m_toolStorage->SetName(newStorageName); m_toolStorage->RegisterAsMicroservice("no tracking device"); } void QmitkMITKIGTTrackingToolboxView::OnTimeOut() { MITK_INFO << "Time Out"; m_WorkerThread->terminate(); m_WorkerThread->wait(); m_TimeoutTimer->stop(); } +//! [StoreUISettings] void QmitkMITKIGTTrackingToolboxView::StoreUISettings() { // persistence service does not directly work in plugins for now // -> using QSettings QSettings settings; settings.beginGroup(QString::fromStdString(VIEW_ID)); // set the values of some widgets and attrbutes to the QSettings settings.setValue("ShowTrackingVolume", QVariant(m_Controls->m_ShowTrackingVolume->isChecked())); settings.setValue("toolStorageFilename", QVariant(m_ToolStorageFilename)); settings.setValue("VolumeSelectionBox", QVariant(m_Controls->m_VolumeSelectionBox->currentIndex())); settings.endGroup(); } +//! [StoreUISettings] +//! [LoadUISettings] void QmitkMITKIGTTrackingToolboxView::LoadUISettings() { // persistence service does not directly work in plugins for now // -> using QSettings QSettings settings; settings.beginGroup(QString::fromStdString(VIEW_ID)); // set some widgets and attributes by the values from the QSettings m_Controls->m_ShowTrackingVolume->setChecked(settings.value("ShowTrackingVolume", true).toBool()); m_Controls->m_VolumeSelectionBox->setCurrentIndex(settings.value("VolumeSelectionBox", 0).toInt()); m_ToolStorageFilename = settings.value("toolStorageFilename", QVariant("")).toString(); settings.endGroup(); + //! [LoadUISettings] - + //! [LoadToolStorage] // try to deserialize the tool storage from the given tool storage file name - if ( ! m_ToolStorageFilename.isEmpty() ) + if (!m_ToolStorageFilename.isEmpty()) { // try-catch block for exceptions try { mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(GetDataStorage()); m_toolStorage->UnRegisterMicroservice(); m_toolStorage = myDeserializer->Deserialize(m_ToolStorageFilename.toStdString()); m_toolStorage->RegisterAsMicroservice("no tracking device"); //update label UpdateToolStorageLabel(m_ToolStorageFilename); //update tool preview m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels(); m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage); } - catch(mitk::IGTException) + catch (mitk::IGTException) { - MITK_WARN("QmitkMITKIGTTrackingToolBoxView") << "Error during restoring tools. Problems with file ("<OnResetTools(); //if there where errors reset the tool storage to avoid problems later on } } + //! [LoadToolStorage] } void QmitkMITKIGTTrackingToolboxView::UpdateToolStorageLabel(QString pathOfLoadedStorage) { QFileInfo myPath(pathOfLoadedStorage); //use this to seperate filename from path QString toolLabel = myPath.fileName(); if (toolLabel.size() > 45) //if the tool storage name is to long trimm the string - { + { toolLabel.resize(40); - toolLabel+="[...]"; - } + toolLabel += "[...]"; + } m_Controls->m_toolLabel->setText(toolLabel); } void QmitkMITKIGTTrackingToolboxView::AutoSaveToolStorage() { m_ToolStorageFilename = m_AutoSaveFilename; mitk::NavigationToolStorageSerializer::Pointer mySerializer = mitk::NavigationToolStorageSerializer::New(); - mySerializer->Serialize(m_ToolStorageFilename.toStdString(),m_toolStorage); + mySerializer->Serialize(m_ToolStorageFilename.toStdString(), m_toolStorage); } - void QmitkMITKIGTTrackingToolboxViewWorker::SetWorkerMethod(WorkerMethod w) { m_WorkerMethod = w; } void QmitkMITKIGTTrackingToolboxViewWorker::SetTrackingDevice(mitk::TrackingDevice::Pointer t) { m_TrackingDevice = t; } void QmitkMITKIGTTrackingToolboxViewWorker::SetDataStorage(mitk::DataStorage::Pointer d) { m_DataStorage = d; } void QmitkMITKIGTTrackingToolboxViewWorker::SetInverseMode(bool mode) { m_InverseMode = mode; } void QmitkMITKIGTTrackingToolboxViewWorker::SetTrackingDeviceData(mitk::TrackingDeviceData d) { m_TrackingDeviceData = d; } void QmitkMITKIGTTrackingToolboxViewWorker::SetNavigationToolStorage(mitk::NavigationToolStorage::Pointer n) { m_NavigationToolStorage = n; } +//! [Thread 7] void QmitkMITKIGTTrackingToolboxViewWorker::ThreadFunc() { - switch(m_WorkerMethod) + switch (m_WorkerMethod) { case eAutoDetectTools: this->AutoDetectTools(); break; case eConnectDevice: this->ConnectDevice(); break; case eStartTracking: this->StartTracking(); break; case eStopTracking: this->StopTracking(); break; case eDisconnectDevice: this->DisconnectDevice(); break; default: MITK_WARN << "Undefined worker method was set ... something went wrong!"; break; - } + } } +//! [Thread 7] void QmitkMITKIGTTrackingToolboxViewWorker::AutoDetectTools() { mitk::ProgressBar::GetInstance()->AddStepsToDo(4); mitk::NavigationToolStorage::Pointer autoDetectedStorage = mitk::NavigationToolStorage::New(m_DataStorage); mitk::NDITrackingDevice::Pointer currentDevice = dynamic_cast(m_TrackingDevice.GetPointer()); try { currentDevice->OpenConnection(); mitk::ProgressBar::GetInstance()->Progress(); currentDevice->StartTracking(); } - catch(mitk::Exception& e) + catch (mitk::Exception& e) { QString message = QString("Warning, can not auto-detect tools! (") + QString(e.GetDescription()) + QString(")"); //MessageBox(message.toStdString()); //TODO: give message to the user here! MITK_WARN << message.toStdString(); mitk::ProgressBar::GetInstance()->Progress(4); - emit AutoDetectToolsFinished(false,message.toStdString().c_str()); + emit AutoDetectToolsFinished(false, message.toStdString().c_str()); return; } - for (unsigned int i=0; iGetToolCount(); i++) + for (unsigned int i = 0; i < currentDevice->GetToolCount(); i++) { //create a navigation tool with sphere as surface std::stringstream toolname; toolname << "AutoDetectedTool" << i; mitk::NavigationTool::Pointer newTool = mitk::NavigationTool::New(); newTool->SetSerialNumber(dynamic_cast(currentDevice->GetTool(i))->GetSerialNumber()); newTool->SetIdentifier(toolname.str()); newTool->SetTrackingDeviceType(mitk::NDIAuroraTypeInformation::GetTrackingDeviceName()); mitk::DataNode::Pointer newNode = mitk::DataNode::New(); mitk::Surface::Pointer mySphere = mitk::Surface::New(); vtkSphereSource *vtkData = vtkSphereSource::New(); vtkData->SetRadius(3.0f); vtkData->SetCenter(0.0, 0.0, 0.0); vtkData->Update(); mySphere->SetVtkPolyData(vtkData->GetOutput()); vtkData->Delete(); newNode->SetData(mySphere); newNode->SetName(toolname.str()); newTool->SetDataNode(newNode); autoDetectedStorage->AddTool(newTool); } m_NavigationToolStorage = autoDetectedStorage; currentDevice->StopTracking(); mitk::ProgressBar::GetInstance()->Progress(); currentDevice->CloseConnection(); - emit AutoDetectToolsFinished(true,""); + emit AutoDetectToolsFinished(true, ""); mitk::ProgressBar::GetInstance()->Progress(4); } void QmitkMITKIGTTrackingToolboxViewWorker::ConnectDevice() { std::string message = ""; mitk::ProgressBar::GetInstance()->AddStepsToDo(10); //build the IGT pipeline mitk::TrackingDevice::Pointer trackingDevice = m_TrackingDevice; trackingDevice->SetData(m_TrackingDeviceData); //set device to rotation mode transposed becaus we are working with VNL style quaternions - if(m_InverseMode) - {trackingDevice->SetRotationMode(mitk::TrackingDevice::RotationTransposed);} + if (m_InverseMode) + { + trackingDevice->SetRotationMode(mitk::TrackingDevice::RotationTransposed); + } //Get Tracking Volume Data mitk::TrackingDeviceData data = m_TrackingDeviceData; mitk::ProgressBar::GetInstance()->Progress(); //Create Navigation Data Source with the factory class - mitk::TrackingDeviceSourceConfigurator::Pointer myTrackingDeviceSourceFactory = mitk::TrackingDeviceSourceConfigurator::New(m_NavigationToolStorage,trackingDevice); + mitk::TrackingDeviceSourceConfigurator::Pointer myTrackingDeviceSourceFactory = mitk::TrackingDeviceSourceConfigurator::New(m_NavigationToolStorage, trackingDevice); m_TrackingDeviceSource = myTrackingDeviceSourceFactory->CreateTrackingDeviceSource(m_ToolVisualizationFilter); mitk::ProgressBar::GetInstance()->Progress(); - if ( m_TrackingDeviceSource.IsNull() ) + if (m_TrackingDeviceSource.IsNull()) { message = std::string("Cannot connect to device: ") + myTrackingDeviceSourceFactory->GetErrorMessage(); - emit ConnectDeviceFinished(false,QString(message.c_str())); + emit ConnectDeviceFinished(false, QString(message.c_str())); return; } //set filter to rotation mode transposed becaus we are working with VNL style quaternions - if(m_InverseMode) + if (m_InverseMode) m_ToolVisualizationFilter->SetRotationMode(mitk::NavigationDataObjectVisualizationFilter::RotationTransposed); //First check if the created object is valid if (m_TrackingDeviceSource.IsNull()) { message = myTrackingDeviceSourceFactory->GetErrorMessage(); - emit ConnectDeviceFinished(false,QString(message.c_str())); + emit ConnectDeviceFinished(false, QString(message.c_str())); return; } MITK_INFO << "Number of tools: " << m_TrackingDeviceSource->GetNumberOfOutputs(); mitk::ProgressBar::GetInstance()->Progress(); //The tools are maybe reordered after initialization, e.g. in case of auto-detected tools of NDI Aurora mitk::NavigationToolStorage::Pointer toolsInNewOrder = myTrackingDeviceSourceFactory->GetUpdatedNavigationToolStorage(); if ((toolsInNewOrder.IsNotNull()) && (toolsInNewOrder->GetToolCount() > 0)) { //so delete the old tools in wrong order and add them in the right order //we cannot simply replace the tool storage because the new storage is //not correctly initialized with the right data storage /* m_NavigationToolStorage->DeleteAllTools(); for (int i=0; i < toolsInNewOrder->GetToolCount(); i++) {m_NavigationToolStorage->AddTool(toolsInNewOrder->GetTool(i));} This was replaced and thereby fixed Bug 18318 DeleteAllTools() is not Threadsafe! */ - for(int i = 0; i < toolsInNewOrder->GetToolCount(); i++ ) + for (int i = 0; i < toolsInNewOrder->GetToolCount(); i++) { - m_NavigationToolStorage->AssignToolNumber(toolsInNewOrder->GetTool(i)->GetIdentifier(),i); + m_NavigationToolStorage->AssignToolNumber(toolsInNewOrder->GetTool(i)->GetIdentifier(), i); } - } mitk::ProgressBar::GetInstance()->Progress(); //connect to device try { m_TrackingDeviceSource->Connect(); mitk::ProgressBar::GetInstance()->Progress(); //Microservice registration: m_TrackingDeviceSource->RegisterAsMicroservice(); m_NavigationToolStorage->UnRegisterMicroservice(); m_NavigationToolStorage->RegisterAsMicroservice(m_TrackingDeviceSource->GetMicroserviceID()); m_NavigationToolStorage->LockStorage(); } catch (...) //todo: change to mitk::IGTException { message = "Error on connecting the tracking device."; - emit ConnectDeviceFinished(false,QString(message.c_str())); + emit ConnectDeviceFinished(false, QString(message.c_str())); return; } - emit ConnectDeviceFinished(true,QString(message.c_str())); + emit ConnectDeviceFinished(true, QString(message.c_str())); mitk::ProgressBar::GetInstance()->Progress(10); } void QmitkMITKIGTTrackingToolboxViewWorker::StartTracking() { QString errorMessage = ""; try { m_TrackingDeviceSource->StartTracking(); } catch (...) //todo: change to mitk::IGTException { errorMessage += "Error while starting the tracking device!"; - emit StartTrackingFinished(false,errorMessage); + emit StartTrackingFinished(false, errorMessage); return; } //remember the original colors of the tools - m_OriginalColors = std::map(); - for(int i=0; im_NavigationToolStorage->GetToolCount(); i++) - { + m_OriginalColors = std::map(); + for (int i = 0; i < this->m_NavigationToolStorage->GetToolCount(); i++) + { mitk::DataNode::Pointer currentToolNode = m_NavigationToolStorage->GetTool(i)->GetDataNode(); float c[3]; currentToolNode->GetColor(c); mitk::Color color; color.SetRed(c[0]); color.SetGreen(c[1]); color.SetBlue(c[2]); m_OriginalColors[currentToolNode] = color; - } + } - emit StartTrackingFinished(true,errorMessage); + emit StartTrackingFinished(true, errorMessage); } void QmitkMITKIGTTrackingToolboxViewWorker::StopTracking() { //stop tracking try { m_TrackingDeviceSource->StopTracking(); } - catch(mitk::Exception& e) + catch (mitk::Exception& e) { emit StopTrackingFinished(false, e.GetDescription()); } //restore the original colors of the tools - for(int i=0; im_NavigationToolStorage->GetToolCount(); i++) + for (int i = 0; i < this->m_NavigationToolStorage->GetToolCount(); i++) { mitk::DataNode::Pointer currentToolNode = m_NavigationToolStorage->GetTool(i)->GetDataNode(); if (m_OriginalColors.find(currentToolNode) == m_OriginalColors.end()) - {MITK_WARN << "Cannot restore original color of tool " << m_NavigationToolStorage->GetTool(i)->GetToolName();} + { + MITK_WARN << "Cannot restore original color of tool " << m_NavigationToolStorage->GetTool(i)->GetToolName(); + } else - {currentToolNode->SetColor(m_OriginalColors[currentToolNode]);} + { + currentToolNode->SetColor(m_OriginalColors[currentToolNode]); + } } //emit signal emit StopTrackingFinished(true, ""); } void QmitkMITKIGTTrackingToolboxViewWorker::DisconnectDevice() { try { - if (m_TrackingDeviceSource->IsTracking()) {m_TrackingDeviceSource->StopTracking();} + if (m_TrackingDeviceSource->IsTracking()) { m_TrackingDeviceSource->StopTracking(); } m_TrackingDeviceSource->Disconnect(); m_TrackingDeviceSource->UnRegisterMicroservice(); m_NavigationToolStorage->UnLockStorage(); } - catch(mitk::Exception& e) + catch (mitk::Exception& e) { emit DisconnectDeviceFinished(false, e.GetDescription()); } emit DisconnectDeviceFinished(true, ""); -} +} \ No newline at end of file