diff --git a/Modules/IGTUI/Qmitk/QmitkIGTConnectionWidget.cpp b/Modules/IGTUI/Qmitk/QmitkIGTConnectionWidget.cpp new file mode 100644 index 0000000000..d66ef80b97 --- /dev/null +++ b/Modules/IGTUI/Qmitk/QmitkIGTConnectionWidget.cpp @@ -0,0 +1,279 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2009-05-12 19:14:45 +0200 (Di, 12 Mai 2009) $ +Version: $Revision: 1.12 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include "QmitkIGTConnectionWidget.h" +#include "mitkClaronTrackingDevice.h" +#include "mitkNDITrackingDevice.h" + +#include "mitkNavigationToolStorageDeserializer.h" +#include "mitkTrackingDeviceSourceConfigurator.h" + +#include +#include + +const std::string QmitkIGTConnectionWidget::VIEW_ID = "org.mitk.views.igtconnectionwidget"; + +QmitkIGTConnectionWidget::QmitkIGTConnectionWidget(QWidget* parent, Qt::WindowFlags f) + : QWidget(parent, f) +{ + m_Controls = NULL; + CreateQtPartControl(this); + CreateConnections(); + m_TrackingDevice = NULL; + m_TrackingDeviceSource = NULL; + m_NavigationToolStorage = NULL; + m_DataStorage = NULL; + m_ErrorMessage = ""; +} + + +QmitkIGTConnectionWidget::~QmitkIGTConnectionWidget() +{ +} + +void QmitkIGTConnectionWidget::CreateQtPartControl(QWidget *parent) +{ + if (!m_Controls) + { + // create GUI widgets + m_Controls = new Ui::QmitkIGTConnectionWidgetControls; + m_Controls->setupUi(parent); + } +} + +void QmitkIGTConnectionWidget::CreateConnections() +{ + if ( m_Controls ) + { + connect( (QObject*)(m_Controls->selectTrackingDeviceComboBox), SIGNAL(currentIndexChanged(int)), this, SLOT(OnTrackingDeviceChanged()) ); + connect( (QObject*)(m_Controls->connectButton), SIGNAL(clicked()), this, SLOT(OnConnect()) ); + + //set a few UI components depending on Windows / Linux + #ifdef WIN32 + m_Controls->portTypeLabelPolaris->setVisible(false); + m_Controls->portTypePolaris->setVisible(false); + m_Controls->portTypeLabelAurora->setVisible(false); + m_Controls->portTypeAurora->setVisible(false); + #else + m_Controls->comPortLabelAurora->setText("Port Nr:"); + m_Controls->comPortLabelPolaris->setText("Port Nr:"); + m_Controls->comPortAurora->setPrefix(""); + m_Controls->comPortPolaris->setPrefix(""); + #endif + } +} + +void QmitkIGTConnectionWidget::OnTrackingDeviceChanged() +{ + //show the correspondig widget for configuring the TrackingDevice + m_Controls->deviceConfigurationWidget->setCurrentIndex(m_Controls->selectTrackingDeviceComboBox->currentIndex()); +} + +void QmitkIGTConnectionWidget::OnConnect() +{ + if (m_Controls->connectButton->isChecked()) // Load tools and connect tracking device + { + m_Controls->connectButton->setChecked(false); + QString fileName = QFileDialog::getOpenFileName(NULL,tr("Open Navigation tool storage"), "/", tr("Toolfile (*.tfl)")); + if (LoadToolfile(fileName)) + { + // create TrackingDevice + m_TrackingDevice = this->ConstructTrackingDevice(); + if (m_TrackingDevice.IsNotNull()) + { + // Create TrackingDeviceSource and add tools + mitk::TrackingDeviceSourceConfigurator::Pointer myTrackingDeviceSourceFactory = + mitk::TrackingDeviceSourceConfigurator::New(this->m_NavigationToolStorage,m_TrackingDevice); + m_TrackingDeviceSource = myTrackingDeviceSourceFactory->CreateTrackingDeviceSource(); + m_TrackingDeviceSource->Connect(); + m_TrackingDeviceSource->StartTracking(); + // change button text + m_Controls->connectButton->setText("Disconnect"); + m_Controls->connectButton->setChecked(true); + } + else + { + // reset button to unchecked + m_Controls->connectButton->setChecked(false); + MITK_ERROR<<"Could not create TrackingDevice"; + } + } + else + { + QString error(m_ErrorMessage.c_str()); + QMessageBox::warning(NULL,"Warning",error); + // reset button to unchecked + m_Controls->connectButton->setChecked(false); + } + } + else // Disconnect tracking device + { + // disconnect TrackingDeviceSource + if (m_TrackingDeviceSource.IsNotNull()) + { + m_TrackingDeviceSource->StopTracking(); + m_TrackingDeviceSource->Disconnect(); + } + // remove tool nodes from DataStorage + this->RemoveToolNodes(); + // change button text + m_Controls->connectButton->setText("Connect"); + } +} + +bool QmitkIGTConnectionWidget::LoadToolfile(QString qFilename) +{ + if (m_DataStorage.IsNotNull()) + { + std::string filename = qFilename.toStdString(); + mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(this->m_DataStorage); + mitk::NavigationToolStorage::Pointer tempStorage = myDeserializer->Deserialize(filename); + + if (tempStorage.IsNull()) + { + m_ErrorMessage = myDeserializer->GetErrorMessage(); + return false; + } + + // check if there are tools in the storage + mitk::TrackingDeviceType lastDevice; + if (tempStorage->GetToolCount()>0) + { + lastDevice = tempStorage->GetTool(0)->GetTrackingDeviceType(); + } + else + { + m_ErrorMessage = "Error: Didn't find a tool in the storage. Do you want to navigate without even an instrument?"; + return false; + } + //check if all tools are from the same device + for (int i=1; iGetToolCount(); i++) + { + if (lastDevice!=tempStorage->GetTool(i)->GetTrackingDeviceType()) + { + m_ErrorMessage = "Error: Toolfile contains tools of different tracking devices which is not acceptable for this application."; + return false; + } + else lastDevice = tempStorage->GetTool(i)->GetTrackingDeviceType(); + } + // check if tool device type and tracking device type are equal + if (lastDevice!=m_Controls->selectTrackingDeviceComboBox->currentIndex()) + { + m_ErrorMessage = "Error: Tools are not applicable for the chosen device"; + return false; + } + + m_NavigationToolStorage = tempStorage; + return true; + } + else + { + m_ErrorMessage = "Error: No DataStorage available! Make sure the widget is initialized with a DataStorage"; + return false; + } +} + +void QmitkIGTConnectionWidget::RemoveToolNodes() +{ + for (int i=0; iGetToolCount(); i++) + { + mitk::DataNode::Pointer currentNode = m_NavigationToolStorage->GetTool(i)->GetDataNode(); + if (currentNode.IsNotNull()) + { + m_DataStorage->Remove(currentNode); + } + } +} + +mitk::TrackingDeviceSource::Pointer QmitkIGTConnectionWidget::GetTrackingDeviceSource() +{ + return m_TrackingDeviceSource; +} + +void QmitkIGTConnectionWidget::SetDataStorage( mitk::DataStorage::Pointer dataStorage ) +{ + m_DataStorage = dataStorage; +} + +mitk::TrackingDevice::Pointer QmitkIGTConnectionWidget::ConstructTrackingDevice() + { + mitk::TrackingDevice::Pointer returnValue; + //#### Step 1: configure tracking device: + if (m_Controls->selectTrackingDeviceComboBox->currentIndex()==0)//NDI Polaris + { + if(m_Controls->polarisMode5D->isChecked()) //5D Tracking + { + //not yet in the open source part so we'll only get NULL here. + returnValue = ConfigureNDI5DTrackingDevice(); + } + else //6D Tracking + { + returnValue = ConfigureNDI6DTrackingDevice(); + returnValue->SetType(mitk::NDIPolaris); + } + } + else if (m_Controls->selectTrackingDeviceComboBox->currentIndex()==1)//NDI Aurora + { + returnValue = ConfigureNDI6DTrackingDevice(); + returnValue->SetType(mitk::NDIAurora); + } + else if (m_Controls->selectTrackingDeviceComboBox->currentIndex()==2)//ClaronTechnology MicronTracker 2 + { + returnValue = mitk::ClaronTrackingDevice::New(); + } + else + { + returnValue = NULL; + } + return returnValue; + } + +mitk::TrackingDevice::Pointer QmitkIGTConnectionWidget::ConfigureNDI5DTrackingDevice() + { + return NULL; + } + +mitk::TrackingDevice::Pointer QmitkIGTConnectionWidget::ConfigureNDI6DTrackingDevice() + { + mitk::NDITrackingDevice::Pointer tempTrackingDevice = mitk::NDITrackingDevice::New(); + + //build prefix (depends on linux/win) + QString prefix = ""; + #ifdef WIN32 + prefix ="COM"; + #else + if (m_Controls->selectTrackingDeviceComboBox->currentIndex()==1) //Aurora + prefix = m_Controls->portTypeAurora->currentText(); + else //Polaris + prefix = m_Controls->portTypePolaris->currentText(); + #endif + //get port + int port = 0; + if (m_Controls->selectTrackingDeviceComboBox->currentIndex()==1) port = m_Controls->comPortAurora->value(); + else port = m_Controls->comPortPolaris->value(); + //build port name string + QString portName = prefix + QString::number(port); + + tempTrackingDevice->SetDeviceName(portName.toStdString()); //set the port name + mitk::TrackingDevice::Pointer returnValue = static_cast(tempTrackingDevice); + return returnValue; + } + +mitk::NavigationToolStorage::Pointer QmitkIGTConnectionWidget::GetNavigationToolStorage() +{ + return m_NavigationToolStorage; +} diff --git a/Modules/IGTUI/Qmitk/QmitkIGTConnectionWidget.h b/Modules/IGTUI/Qmitk/QmitkIGTConnectionWidget.h new file mode 100644 index 0000000000..f6ec42d084 --- /dev/null +++ b/Modules/IGTUI/Qmitk/QmitkIGTConnectionWidget.h @@ -0,0 +1,119 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2009-05-12 19:14:45 +0200 (Di, 12 Mai 2009) $ +Version: $Revision: 1.12 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef QmitkIGTConnectionWidget_H +#define QmitkIGTConnectionWidget_H + +#include +#include "MitkIGTUIExports.h" +#include "ui_QmitkIGTConnectionWidgetControls.h" + +#include "mitkDataStorage.h" +#include "mitkNavigationToolStorage.h" +#include "mitkTrackingDevice.h" +#include "mitkTrackingDeviceSource.h" + + +//itk headers + + /** Documentation: + * \brief Simple and fast access to a pre-configured TrackingDeviceSource. + * + * This widget creates a fully configured, connected and started TrackingDeviceSource. + * Clicking connect requires to specify a NavigationToolStorage that holds all tools to be used + * in the application. Corresponding surfaces are added to the DataStorage that has to be set for + * the widget. + * + * \ingroup IGTUI + */ +class MitkIGTUI_EXPORT QmitkIGTConnectionWidget : public QWidget +{ + Q_OBJECT + + public: + static const std::string VIEW_ID; + + QmitkIGTConnectionWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); + ~QmitkIGTConnectionWidget(); + + /* @return Returns the preconfigured and connected TrackingDeviceSource ready to use in an IGT pipeline. + */ + mitk::TrackingDeviceSource::Pointer GetTrackingDeviceSource(); + /*! + \brief Get the NavigationToolStorage holding all tools with corresponding surface objects + */ + mitk::NavigationToolStorage::Pointer GetNavigationToolStorage(); + /*! + \brief set DataStorage that is used to put the navigation tools + */ + void SetDataStorage(mitk::DataStorage::Pointer dataStorage); + + + signals: + + protected slots: + /* @brief This method is called when the user changes the selection of the trackingdevice (m_trackingDeviceChooser). + It then sets the correct widget for the selected tracking device.*/ + void OnTrackingDeviceChanged(); + /*! + \brief Asks the user to specify a tool file and finally connects the TrackingDeviceSource + */ + void OnConnect(); + + protected: + + /// \brief Creation of the connections + virtual void CreateConnections(); + + virtual void CreateQtPartControl(QWidget *parent); + + /*! + \brief Load NavigationToolStorage from given filename and set according member + \param qFilename file location of the NavigationToolStorage + \return success of load operation (true if load successful, false otherwise) m_ErrorMessage holds the problem description + */ + bool LoadToolfile(QString qFilename); + + /*! + \brief Remove the tool nodes currently associated to the tools hold in the NavigationToolStorage from the DataStorage + */ + void RemoveToolNodes(); + /*! + \brief Construct TrackingDevice according to the selection in the ComboBox. + \return Preconfigured TrackingDevice to be used in a TrackingDeviceSource + */ + mitk::TrackingDevice::Pointer ConstructTrackingDevice(); + /* @return Returns a configured NDI 5D tracking device. Unfortunately the NDI 5D tracking device is not yet in the open source part + * so this method only returns NULL at the moment. + */ + virtual mitk::TrackingDevice::Pointer ConfigureNDI5DTrackingDevice(); + + /* @return Returns a configured NDI 6D tracking device. + * The type (which means Aurora/Polaris) will not be set in the returnvalue. You have to this later. + */ + mitk::TrackingDevice::Pointer ConfigureNDI6DTrackingDevice(); + + Ui::QmitkIGTConnectionWidgetControls* m_Controls; + + mitk::DataStorage::Pointer m_DataStorage; ///< data storage to put navigation tools + mitk::TrackingDevice::Pointer m_TrackingDevice; ///< holds an instance of the currently chosen tracking device which may be of type NDI Polaris, NDI Aurora or Claron MicronTracker + mitk::TrackingDeviceSource::Pointer m_TrackingDeviceSource; ///< holds the preconfigured source of the IGT pipeline which is provided by this widget for further processing + mitk::NavigationToolStorage::Pointer m_NavigationToolStorage; ///< holds all navigation tools currently loaded + + std::string m_ErrorMessage; ///< current problem description +}; +#endif \ No newline at end of file diff --git a/Modules/IGTUI/Qmitk/QmitkIGTConnectionWidgetControls.ui b/Modules/IGTUI/Qmitk/QmitkIGTConnectionWidgetControls.ui new file mode 100644 index 0000000000..5e3916f47e --- /dev/null +++ b/Modules/IGTUI/Qmitk/QmitkIGTConnectionWidgetControls.ui @@ -0,0 +1,318 @@ + + + QmitkIGTConnectionWidgetControls + + + + 0 + 0 + 443 + 180 + + + + + 0 + 0 + + + + QmitkIGTConnection + + + + + + + 11 + 50 + false + + + + Connect Tracking Device + + + + + + + + + + 0 + 0 + + + + + 10 + + + + 0 + + + 7 + + + QComboBox::InsertAtBottom + + + QComboBox::AdjustToContents + + + true + + + + NDI Polaris + + + + + NDI Aurora + + + + + Micron Tracker + + + + + + + + true + + + + 0 + 0 + + + + + 0 + 50 + + + + + 10 + + + + Connect to camera + + + Connect + + + + :/IGTUI/powerRed.png + :/IGTUI/powerGreen.png:/IGTUI/powerRed.png + + + + 30 + 30 + + + + true + + + + + + + + + 0 + + + + + + + NDI Polaris configuration + + + + + + COM Port: + + + + + + + COM + + + + + + + Port type: + + + + + + + + /dev/ttyUSB + + + + + /dev/ttyS + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Mode: + + + + + + + 5D + + + + + + + 6D + + + true + + + + + portTypeLabelPolaris + comPortPolaris + portTypePolaris + comPortLabelPolaris + horizontalSpacer_2 + comPortLabelPolaris + comPortPolaris + portTypeLabelPolaris + portTypePolaris + horizontalSpacer_2 + label_4 + polarisMode5D + polarisMode6D + + + + + + + + + + NDI Aurora configuration + + + + + + COM Port: + + + + + + + COM + + + + + + + Port type: + + + + + + + + /dev/ttyUSB + + + + + /dev/ttyS + + + + + + + + Qt::Horizontal + + + + 213 + 20 + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + + + + + + + + diff --git a/Modules/IGTUI/files.cmake b/Modules/IGTUI/files.cmake index c22c31f423..96cf6a9ef8 100644 --- a/Modules/IGTUI/files.cmake +++ b/Modules/IGTUI/files.cmake @@ -1,51 +1,54 @@ SET(CPP_FILES Qmitk/QmitkTrackingDeviceWidget.cpp Qmitk/QmitkTrackingDeviceConfigurationWidget.cpp Qmitk/QmitkNDIConfigurationWidget.cpp Qmitk/QmitkFiducialRegistrationWidget.cpp Qmitk/QmitkNDIToolDelegate.cpp Qmitk/QmitkNavigationToolManagementWidget.cpp Qmitk/QmitkIGTLoggerWidget.cpp Qmitk/QmitkUpdateTimerWidget.cpp Qmitk/QmitkToolDistanceWidget.cpp Qmitk/QmitkToolTrackingStatusWidget.cpp Qmitk/QmitkTrackingSourcesCheckBoxPanelWidget.cpp Qmitk/QmitkIGTPlayerWidget.cpp + Qmitk/QmitkIGTConnectionWidget.cpp ) SET(UI_FILES Qmitk/QmitkNavigationToolManagementWidgetControls.ui Qmitk/QmitkTrackingDeviceConfigurationWidgetControls.ui Qmitk/QmitkNDIConfigurationWidget.ui Qmitk/QmitkFiducialRegistrationWidget.ui Qmitk/QmitkIGTLoggerWidgetControls.ui Qmitk/QmitkUpdateTimerWidgetControls.ui Qmitk/QmitkToolDistanceWidgetControls.ui Qmitk/QmitkToolTrackingStatusWidgetControls.ui Qmitk/QmitkTrackingSourcesCheckBoxPanelWidgetControls.ui Qmitk/QmitkIGTPlayerWidgetControls.ui + Qmitk/QmitkIGTConnectionWidgetControls.ui ) SET(MOC_H_FILES Qmitk/QmitkNavigationToolManagementWidget.h Qmitk/QmitkTrackingDeviceWidget.h Qmitk/QmitkTrackingDeviceConfigurationWidget.h Qmitk/QmitkNDIConfigurationWidget.h Qmitk/QmitkFiducialRegistrationWidget.h Qmitk/QmitkNDIToolDelegate.h Qmitk/QmitkIGTLoggerWidget.h Qmitk/QmitkUpdateTimerWidget.h Qmitk/QmitkToolDistanceWidget.h Qmitk/QmitkToolTrackingStatusWidget.h Qmitk/QmitkTrackingSourcesCheckBoxPanelWidget.h Qmitk/QmitkIGTPlayerWidget.h + Qmitk/QmitkIGTConnectionWidget.h ) SET(QRC_FILES resources/IGTUI.qrc ) diff --git a/Modules/IGTUI/resources/IGTUI.qrc b/Modules/IGTUI/resources/IGTUI.qrc index 9c7ceb2b28..f1dd28ecda 100644 --- a/Modules/IGTUI/resources/IGTUI.qrc +++ b/Modules/IGTUI/resources/IGTUI.qrc @@ -1,15 +1,17 @@ record.png stop_recording.png play.png pause.png fastbackward.png fastforward.png previousframe.png nextframe.png firstframe.png lastframe.png stop.png + powerGreen.png + powerRed.png diff --git a/Modules/IGTUI/resources/powerGreen.png b/Modules/IGTUI/resources/powerGreen.png new file mode 100644 index 0000000000..9e8e0903d9 Binary files /dev/null and b/Modules/IGTUI/resources/powerGreen.png differ diff --git a/Modules/IGTUI/resources/powerRed.png b/Modules/IGTUI/resources/powerRed.png new file mode 100644 index 0000000000..bb3f33bef5 Binary files /dev/null and b/Modules/IGTUI/resources/powerRed.png differ