diff --git a/Modules/IGTUI/Qmitk/QmitkAbstractTrackingDeviceWidget.cpp b/Modules/IGTUI/Qmitk/QmitkAbstractTrackingDeviceWidget.cpp index 2a3d8ce323..229f2bfa13 100644 --- a/Modules/IGTUI/Qmitk/QmitkAbstractTrackingDeviceWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkAbstractTrackingDeviceWidget.cpp @@ -1,77 +1,77 @@ /*=================================================================== 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 "QmitkAbstractTrackingDeviceWidget.h" #include QmitkAbstractTrackingDeviceWidget::QmitkAbstractTrackingDeviceWidget(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f) , isInitialized(false) , m_TestConnectionWorker(NULL) , m_TestConnectionWorkerThread(NULL) , m_ErrorMessage("") { } void QmitkAbstractTrackingDeviceWidget::InitializeSuperclassWidget() { m_TestConnectionWorkerThread = new QThread(); m_TestConnectionWorker = new QmitkTrackingDeviceConfigurationWidgetConnectionWorker(); CreateConnections(); m_ErrorMessage = ""; isInitialized = true; } QmitkAbstractTrackingDeviceWidget::~QmitkAbstractTrackingDeviceWidget(){ if (m_TestConnectionWorker) delete m_TestConnectionWorker; if (m_TestConnectionWorkerThread) delete m_TestConnectionWorkerThread; } void QmitkAbstractTrackingDeviceWidget::TestConnectionFinished(bool connected, QString output) { m_TestConnectionWorkerThread->quit(); AddOutput(output.toStdString()); MITK_INFO << "Test connection: " << connected; this->setEnabled(true); } void QmitkAbstractTrackingDeviceWidget::TestConnection() { this->setEnabled(false); //construct a tracking device: - mitk::TrackingDevice::Pointer testTrackingDevice = ConstructTrackingDevice(); + mitk::TrackingDevice::Pointer testTrackingDevice = GetTrackingDevice(); m_TestConnectionWorker->SetTrackingDevice(testTrackingDevice); m_TestConnectionWorkerThread->start(); } void QmitkAbstractTrackingDeviceWidget::CreateConnections() { connect(m_TestConnectionWorker, SIGNAL(ConnectionTested(bool, QString)), this, SLOT(TestConnectionFinished(bool, QString))); connect(m_TestConnectionWorkerThread, SIGNAL(started()), m_TestConnectionWorker, SLOT(TestConnectionThreadFunc())); //move the worker to the thread m_TestConnectionWorker->moveToThread(m_TestConnectionWorkerThread); } QmitkAbstractTrackingDeviceWidget* QmitkAbstractTrackingDeviceWidget::CloneForQt(QWidget* parent) const { QmitkAbstractTrackingDeviceWidget* clonedWidget = this->Clone(parent); if (!clonedWidget->IsInitialized()) MITK_ERROR << "Your cloned widget is not initialized!"; clonedWidget->create(); return clonedWidget; } diff --git a/Modules/IGTUI/Qmitk/QmitkAbstractTrackingDeviceWidget.h b/Modules/IGTUI/Qmitk/QmitkAbstractTrackingDeviceWidget.h index e68ec07609..bc7410f046 100644 --- a/Modules/IGTUI/Qmitk/QmitkAbstractTrackingDeviceWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkAbstractTrackingDeviceWidget.h @@ -1,165 +1,169 @@ /*=================================================================== 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 QmitkAbstractTrackingDeviceWidget_H #define QmitkAbstractTrackingDeviceWidget_H #include #include "MitkIGTUIExports.h" #include "mitkTrackingDevice.h" #include #include "QmitkTrackingDeviceConfigurationWidgetConnectionWorker.h" //itk headers /** Documentation: * \brief Abstract class to configure a tracking device. * Inherited widgets should be registered in the Microservice (TrackingDeviceCollectionWidget), * If done so, they will be included in the QmitkTrackingDeviceConfigurationWidget of the Tracking Toolbox. * - * - Each implementation of this class must have a method to construct a tracking Device (ConstructTrackingDevice). + * - Each implementation of this class must have a method to get a TrackingDevice + * - Each implementation handles itself, if a new TrackingDevice needs to be constructed. + * Attention: In former MITK versions, there was no pure virtual GetTrackingDevice function but a pure virtual ConstructTrackingDevice function. + * You can simply rename these, but you should give it a thought, if each time "Construct" was called, a new device needs to be constructed, + * or if you can store your TrackingDevice in a member variable and return this. Up to you. * - Please create the UI elements in a function like CreateQtPartControl (e.g. see QmitkVitrualTrackerWidget). * - You might want to use own buttons etc., please connect them in a private CreateConnections (e.g. see QmitkVitrualTrackerWidget). * - Due to initialization of qt during autoloading of the IGT module, you constructor should be as slim as possible and only contain a call * of the QmitkAbstractTrackingDeviceWidget constructor and simple variable initialization. * - For the initialization, you must write an Iniltialize() function, which must include a call of InitializeSuperclassWidget() and should contain * calls of your private CreateConnections / CreateQtPartControl (if you implemented these). * - For integration into the TrackingToolbox, a clone function is needed. Here, a new widget should be created, Initialize() needs to be called, * and all settings of your widget should be copied. * * You can Load and Store previous settings of your GUI elements (e.g. see QmitkNDIPolarisWidget). * Also, you can add an output textbox to your widget to display information about your device status. It's optional, see e.g. QmitkNDIAuroraWidget. * Some Devices need the information if drivers are installed on your computer. If this is necessary for your device to avoid crashes, * please override IsDeviceInstalled. The default return value is true otherwise. * * \ingroup IGTUI */ class MITKIGTUI_EXPORT QmitkAbstractTrackingDeviceWidget : public QWidget { Q_OBJECT public: static const std::string VIEW_ID; QmitkAbstractTrackingDeviceWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); virtual ~QmitkAbstractTrackingDeviceWidget(); /** * \brief Return pointer to copy of the object. * Internally use of QmitkUSAbstractCustomWidget::Clone() with additionaly * setting an internal flag that the object was really cloned. */ QmitkAbstractTrackingDeviceWidget* CloneForQt(QWidget* parent = 0) const; /** * \brief Subclass must implement this method to return a pointer to a copy of the object. * Please don't forget to call InitializeSuperclassWidget(), CreateQtPartControl and optionally CreateConnections during this function. */ virtual void Initialize() = 0; bool IsInitialized() const { return isInitialized; } signals: void ConnectionTested(bool connected, QString output); protected slots: void TestConnectionFinished(bool connected, QString output); /* @brief This method is called when the user presses the button "test connection". The method will then create a temporary tracking device, * try to open a connection and start tracking. The user can see the result of the connection test on the small output window. */ void TestConnection(); private: /// \brief Creation of the connections. You might implement the same function again in your inherited widget. void CreateConnections(); protected: PERSISTENCE_GET_SERVICE_METHOD_MACRO void InitializeSuperclassWidget(); QmitkTrackingDeviceConfigurationWidgetConnectionWorker* m_TestConnectionWorker; QThread* m_TestConnectionWorkerThread; /** * \brief Subclass must implement this method to return a pointer to a copy of the object. * Please don't forget to call Initialize() during this function and copy all of your settings. */ virtual QmitkAbstractTrackingDeviceWidget* Clone(QWidget* parent = 0) const = 0; public: /** * \brief Optional method to add output to a small screen in the trackingToolbox (see QmitkNDIPolarisWidget) */ virtual void ResetOutput() {} /** * \brief Optional method to add output to a small screen in the trackingToolbox (see QmitkNDIPolarisWidget) */ virtual void AddOutput(std::string) {} - virtual mitk::TrackingDevice::Pointer ConstructTrackingDevice() = 0; + virtual mitk::TrackingDevice::Pointer GetTrackingDevice() = 0; /** * \brief Optional method to store and load settings of your widget (see QmitkNDIPolarisWidget) */ virtual void StoreUISettings() {} /** * \brief Optional method to store and load settings of your widget (see QmitkNDIPolarisWidget) */ virtual void LoadUISettings() {} /** * \brief Optional method to investigate if drivers etc for your device are installed. * The default value is "true" as most devices don't need this information. * Others however migth crash, and for these you might implement this function (see QmitkMicronTrackerWidget) */ virtual bool IsDeviceInstalled() { return true; } /** * \brief This function is called, when in the TrackingToolboxView "Connect" was clicked and the device is successful connected. * Can e.g. be used to activate options of a tracking device only when it is connected. */ virtual void OnConnected(bool _success) {}; /** * \brief This function is called, when in the TrackingToolboxView "Disconnect" was clicked and the device is successful disconnected. * Can e.g. be used to activate/disactivate options of a tracking device. */ virtual void OnDisconnected(bool _success) {}; /** * \brief This function is called, when in the TrackingToolboxView "Start Tracking" was clicked and the device successfully started tracking. * Can e.g. be used to activate options of a tracking device only when tracking is started. */ virtual void OnStartTracking(bool _success){}; /** * \brief This function is called, when in the TrackingToolboxView "Stop Tracking" was clicked and the device successful stopped tracking. * Can e.g. be used to activate/disactivate options when device is not tracking. */ virtual void OnStopTracking(bool _success) {}; std::string m_ErrorMessage; ///< current problem description private: /** * \warning Don't touch this variable if you don't know what you are doing! */ bool isInitialized; }; #endif diff --git a/Modules/IGTUI/Qmitk/QmitkMicronTrackerWidget.cpp b/Modules/IGTUI/Qmitk/QmitkMicronTrackerWidget.cpp index 9422e1eeac..380b25a937 100644 --- a/Modules/IGTUI/Qmitk/QmitkMicronTrackerWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkMicronTrackerWidget.cpp @@ -1,171 +1,171 @@ /*=================================================================== 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 "QmitkMicronTrackerWidget.h" #include #include #include #include #include #include #include const std::string QmitkMicronTrackerWidget::VIEW_ID = "org.mitk.views.NDIMicronTrackerWidget"; QmitkMicronTrackerWidget::QmitkMicronTrackerWidget(QWidget* parent, Qt::WindowFlags f) : QmitkAbstractTrackingDeviceWidget(parent, f) , m_Controls(nullptr) { } void QmitkMicronTrackerWidget::Initialize() { InitializeSuperclassWidget(); CreateQtPartControl(this); CreateConnections(); m_MTCalibrationFile = ""; } QmitkMicronTrackerWidget::~QmitkMicronTrackerWidget() { delete m_Controls; } void QmitkMicronTrackerWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkMicronTrackerWidget; m_Controls->setupUi(parent); } } void QmitkMicronTrackerWidget::CreateConnections() { if (m_Controls) { connect((QObject*)(m_Controls->m_testConnectionMicronTracker), SIGNAL(clicked()), this, SLOT(TestConnection())); connect((QObject*)(m_Controls->m_SetMTCalibrationFile), SIGNAL(clicked()), this, SLOT(SetMTCalibrationFileClicked())); } } void QmitkMicronTrackerWidget::ResetOutput() { m_Controls->m_outputTextMicronTracker->setHtml("output:"); } void QmitkMicronTrackerWidget::AddOutput(std::string s) { m_Controls->m_outputTextMicronTracker->setHtml(QString(s.c_str())); m_Controls->m_outputTextMicronTracker->verticalScrollBar()->setValue(m_Controls->m_outputTextMicronTracker->verticalScrollBar()->maximum()); } -mitk::TrackingDevice::Pointer QmitkMicronTrackerWidget::ConstructTrackingDevice() +mitk::TrackingDevice::Pointer QmitkMicronTrackerWidget::GetTrackingDevice() { mitk::ClaronTrackingDevice::Pointer newDevice = mitk::ClaronTrackingDevice::New(); if (this->m_MTCalibrationFile.empty()) //if configuration file for MicronTracker is empty: load default { mitk::ClaronTrackingDevice::Pointer tempDevice = mitk::ClaronTrackingDevice::New(); m_MTCalibrationFile = tempDevice->GetCalibrationDir(); Poco::Path myPath = Poco::Path(m_MTCalibrationFile.c_str()); m_Controls->m_MTCalibrationFile->setText("Calibration File: " + QString(myPath.getFileName().c_str())); } if (!this->m_MTCalibrationFile.empty()) { //extract path from calibration file and set the calibration dir of the device std::string path = itksys::SystemTools::GetFilenamePath(m_MTCalibrationFile); newDevice->SetCalibrationDir(path); } else AddOutput("
Warning: Calibration file is not set!"); return static_cast(newDevice); } void QmitkMicronTrackerWidget::StoreUISettings() { std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget"; if (this->GetPersistenceService()) // now save the settings using the persistence service { mitk::PropertyList::Pointer propList = this->GetPersistenceService()->GetPropertyList(id); propList->Set("MTCalibrationFile", m_MTCalibrationFile); } else // QSettings as a fallback if the persistence service is not available { QSettings settings; settings.beginGroup(QString::fromStdString(id)); settings.setValue("mTCalibrationFile", QVariant(QString::fromStdString(m_MTCalibrationFile))); settings.endGroup(); } } void QmitkMicronTrackerWidget::LoadUISettings() { std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget"; if (this->GetPersistenceService()) { mitk::PropertyList::Pointer propList = this->GetPersistenceService()->GetPropertyList(id); if (propList.IsNull()) { MITK_ERROR << "Property list for this UI (" << id << ") is not available, could not load UI settings!"; return; } propList->Get("MTCalibrationFile", m_MTCalibrationFile); } else { // QSettings as a fallback if the persistence service is not available QSettings settings; settings.beginGroup(QString::fromStdString(id)); m_MTCalibrationFile = settings.value("mTCalibrationFile", "").toString().toStdString(); settings.endGroup(); } m_Controls->m_MTCalibrationFile->setText("Calibration File: " + QString::fromStdString(m_MTCalibrationFile)); } bool QmitkMicronTrackerWidget::IsDeviceInstalled() { return mitk::ClaronTrackingDevice::New()->IsDeviceInstalled(); } void QmitkMicronTrackerWidget::SetMTCalibrationFileClicked() { std::string filename = QFileDialog::getOpenFileName(NULL, tr("Open Calibration File"), QmitkIGTCommonHelper::GetLastFileLoadPath(), "*.*").toLatin1().data(); if (filename == "") { return; } else { QmitkIGTCommonHelper::SetLastFileLoadPathByFileName(QString::fromStdString(filename)); m_MTCalibrationFile = filename; Poco::Path myPath = Poco::Path(m_MTCalibrationFile.c_str()); m_Controls->m_MTCalibrationFile->setText("Calibration File: " + QString(myPath.getFileName().c_str())); } } QmitkMicronTrackerWidget* QmitkMicronTrackerWidget::Clone(QWidget* parent) const { QmitkMicronTrackerWidget* clonedWidget = new QmitkMicronTrackerWidget(parent); clonedWidget->Initialize(); clonedWidget->m_MTCalibrationFile = m_MTCalibrationFile; m_Controls->m_MTCalibrationFile->setText("Calibration File: " + QString::fromStdString(m_MTCalibrationFile)); return clonedWidget; } diff --git a/Modules/IGTUI/Qmitk/QmitkMicronTrackerWidget.h b/Modules/IGTUI/Qmitk/QmitkMicronTrackerWidget.h index 6f304182f1..5190f37db1 100644 --- a/Modules/IGTUI/Qmitk/QmitkMicronTrackerWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkMicronTrackerWidget.h @@ -1,71 +1,71 @@ /*=================================================================== 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 QmitkMicronTrackerWidget_H #define QmitkMicronTrackerWidget_H #include "ui_QmitkMicronTrackerWidget.h" #include "QmitkAbstractTrackingDeviceWidget.h" /** Documentation: * \brief Implementation of a configuration widget for Micron Tracking Devices. * * \ingroup IGTUI */ class MITKIGTUI_EXPORT QmitkMicronTrackerWidget : public QmitkAbstractTrackingDeviceWidget { Q_OBJECT // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) public: static const std::string VIEW_ID; QmitkMicronTrackerWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkMicronTrackerWidget(); virtual void Initialize(); signals: protected slots : /* @brief Opens a file dialog. The users sets the calibration file which location is then stored in the member m_MTCalibrationFile.*/ void SetMTCalibrationFileClicked(); private: /// \brief Creation of the connections void CreateConnections(); void CreateQtPartControl(QWidget *parent); protected: virtual QmitkMicronTrackerWidget* Clone(QWidget* parent) const; std::string m_MTCalibrationFile; Ui::QmitkMicronTrackerWidget* m_Controls; public: virtual void ResetOutput(); virtual void AddOutput(std::string s); - virtual mitk::TrackingDevice::Pointer ConstructTrackingDevice(); + virtual mitk::TrackingDevice::Pointer GetTrackingDevice(); virtual void StoreUISettings(); virtual void LoadUISettings(); virtual bool IsDeviceInstalled(); }; #endif diff --git a/Modules/IGTUI/Qmitk/QmitkNDIAuroraWidget.cpp b/Modules/IGTUI/Qmitk/QmitkNDIAuroraWidget.cpp index a91be96fa8..e225eab219 100644 --- a/Modules/IGTUI/Qmitk/QmitkNDIAuroraWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkNDIAuroraWidget.cpp @@ -1,174 +1,174 @@ /*=================================================================== 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 "QmitkNDIAuroraWidget.h" #include "mitkNDITrackingDevice.h" #include "mitkNDIAuroraTypeInformation.h" #include #include const std::string QmitkNDIAuroraWidget::VIEW_ID = "org.mitk.views.NDIAuroraWidget"; QmitkNDIAuroraWidget::QmitkNDIAuroraWidget(QWidget* parent, Qt::WindowFlags f) : QmitkNDIAbstractDeviceWidget(parent, f) , m_Controls(nullptr) { } void QmitkNDIAuroraWidget::Initialize() { InitializeNDIWidget(); CreateQtPartControl(this); CreateConnections(); } QmitkNDIAuroraWidget::~QmitkNDIAuroraWidget() { delete m_Controls; } void QmitkNDIAuroraWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkNDIAuroraWidget; m_Controls->setupUi(parent); } } void QmitkNDIAuroraWidget::CreateConnections() { if (m_Controls) { connect((QObject*)(m_Controls->m_testConnectionAurora), SIGNAL(clicked()), this, SLOT(TestConnection())); connect((QObject*)(m_Controls->m_AutoScanAurora), SIGNAL(clicked()), this, SLOT(AutoScanPorts())); //set a few UI components depending on Windows / Linux #ifdef WIN32 m_Controls->portTypeLabelAurora->setVisible(false); m_Controls->portTypeAurora->setVisible(false); #else m_Controls->comPortLabelAurora->setText("Port Nr:"); m_Controls->m_portSpinBoxAurora->setPrefix(""); #endif } } void QmitkNDIAuroraWidget::ResetOutput() { m_Controls->m_outputTextAurora->setHtml("output:"); } void QmitkNDIAuroraWidget::AddOutput(std::string s) { m_Controls->m_outputTextAurora->setHtml(QString(s.c_str())); m_Controls->m_outputTextAurora->verticalScrollBar()->setValue(m_Controls->m_outputTextAurora->verticalScrollBar()->maximum()); } -mitk::TrackingDevice::Pointer QmitkNDIAuroraWidget::ConstructTrackingDevice() +mitk::TrackingDevice::Pointer QmitkNDIAuroraWidget::GetTrackingDevice() { mitk::NDITrackingDevice::Pointer tempTrackingDevice = mitk::NDITrackingDevice::New(); //get port int port = 0; port = m_Controls->m_portSpinBoxAurora->value(); //build prefix (depends on linux/win) QString prefix = ""; #ifdef WIN32 prefix = "COM"; tempTrackingDevice->SetPortNumber(static_cast(port)); //also set the com port for compatibility #else prefix = m_Controls->portTypeAurora->currentText(); #endif //build port name string QString portName = prefix + QString::number(port); tempTrackingDevice->SetDeviceName(portName.toStdString()); //set the port name tempTrackingDevice->SetBaudRate(mitk::SerialCommunication::BaudRate115200);//set baud rate tempTrackingDevice->SetType(mitk::NDIAuroraTypeInformation::GetTrackingDeviceName()); return static_cast(tempTrackingDevice); } void QmitkNDIAuroraWidget::StoreUISettings() { std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget"; if (this->GetPersistenceService()) // now save the settings using the persistence service { mitk::PropertyList::Pointer propList = this->GetPersistenceService()->GetPropertyList(id); propList->Set("AuroraPortWin", m_Controls->m_portSpinBoxAurora->value()); propList->Set("PortTypeAurora", m_Controls->portTypeAurora->currentIndex()); } else // QSettings as a fallback if the persistence service is not available { QSettings settings; settings.beginGroup(QString::fromStdString(id)); settings.setValue("portSpinBoxAurora", QVariant(m_Controls->m_portSpinBoxAurora->value())); settings.setValue("portTypeAurora", QVariant(m_Controls->portTypeAurora->currentIndex())); settings.endGroup(); } } void QmitkNDIAuroraWidget::LoadUISettings() { std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget"; if (this->GetPersistenceService()) { int port = 0; int portType = 0; mitk::PropertyList::Pointer propList = this->GetPersistenceService()->GetPropertyList(id); if (propList.IsNull()) { MITK_ERROR << "Property list for this UI (" << id << ") is not available, could not load UI settings!"; return; } propList->Get("AuroraPortWin", port); propList->Get("PortTypeAurora", portType); this->SetPortTypeToGUI(portType); this->SetPortValueToGUI(port); } else { // QSettings as a fallback if the persistence service is not available QSettings settings; settings.beginGroup(QString::fromStdString(id)); m_Controls->m_portSpinBoxAurora->setValue(settings.value("portSpinBoxAurora", 0).toInt()); m_Controls->portTypeAurora->setCurrentIndex(settings.value("portTypeAurora", 0).toInt()); settings.endGroup(); } } void QmitkNDIAuroraWidget::SetPortValueToGUI(int portValue){ m_Controls->m_portSpinBoxAurora->setValue(portValue); } void QmitkNDIAuroraWidget::SetPortTypeToGUI(int portType){ m_Controls->portTypeAurora->setCurrentIndex(portType); } QmitkNDIAuroraWidget* QmitkNDIAuroraWidget::Clone(QWidget* parent) const { QmitkNDIAuroraWidget* clonedWidget = new QmitkNDIAuroraWidget(parent); clonedWidget->Initialize(); clonedWidget->SetPortTypeToGUI(m_Controls->portTypeAurora->currentIndex()); clonedWidget->SetPortValueToGUI(m_Controls->m_portSpinBoxAurora->value()); return clonedWidget; } diff --git a/Modules/IGTUI/Qmitk/QmitkNDIAuroraWidget.h b/Modules/IGTUI/Qmitk/QmitkNDIAuroraWidget.h index f3fd1bea10..00ce26d20d 100644 --- a/Modules/IGTUI/Qmitk/QmitkNDIAuroraWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkNDIAuroraWidget.h @@ -1,62 +1,62 @@ /*=================================================================== 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 QmitkNDIAuroraWidget_H #define QmitkNDIAuroraWidget_H #include "ui_QmitkNDIAuroraWidget.h" #include "QmitkNDIAbstractDeviceWidget.h" /** Documentation: * \brief Implementation of a configuration widget for NDI Aurora Devices. * * \ingroup IGTUI */ class MITKIGTUI_EXPORT QmitkNDIAuroraWidget : public QmitkNDIAbstractDeviceWidget { Q_OBJECT // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) public: static const std::string VIEW_ID; QmitkNDIAuroraWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkNDIAuroraWidget(); virtual void Initialize(); private: /// \brief Creation of the connections void CreateConnections(); void CreateQtPartControl(QWidget *parent); protected: virtual void ResetOutput(); virtual void AddOutput(std::string s); - virtual mitk::TrackingDevice::Pointer ConstructTrackingDevice(); + virtual mitk::TrackingDevice::Pointer GetTrackingDevice(); virtual void StoreUISettings(); virtual void LoadUISettings(); virtual void SetPortValueToGUI(int portValue); virtual void SetPortTypeToGUI(int portType); virtual QmitkNDIAuroraWidget* Clone(QWidget* parent) const; Ui::QmitkNDIAuroraWidget* m_Controls; }; #endif diff --git a/Modules/IGTUI/Qmitk/QmitkNDIPolarisWidget.cpp b/Modules/IGTUI/Qmitk/QmitkNDIPolarisWidget.cpp index 403cebd81b..437576aafa 100644 --- a/Modules/IGTUI/Qmitk/QmitkNDIPolarisWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkNDIPolarisWidget.cpp @@ -1,197 +1,197 @@ /*=================================================================== 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 "QmitkNDIPolarisWidget.h" #include "mitkNDITrackingDevice.h" #include "mitkNDIPolarisTypeInformation.h" #include #include const std::string QmitkNDIPolarisWidget::VIEW_ID = "org.mitk.views.NDIPolarisWidget"; QmitkNDIPolarisWidget::QmitkNDIPolarisWidget(QWidget* parent, Qt::WindowFlags f) : QmitkNDIAbstractDeviceWidget(parent, f) , m_Controls(nullptr) { } void QmitkNDIPolarisWidget::Initialize() { InitializeNDIWidget(); CreateQtPartControl(this); CreateConnections(); } QmitkNDIPolarisWidget::~QmitkNDIPolarisWidget() { delete m_Controls; } void QmitkNDIPolarisWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkNDIPolarisWidget; m_Controls->setupUi(parent); } } void QmitkNDIPolarisWidget::CreateConnections() { if (m_Controls) { connect((QObject*)(m_Controls->m_testConnectionPolaris), SIGNAL(clicked()), this, SLOT(TestConnection())); connect((QObject*)(m_Controls->m_AutoScanPolaris), SIGNAL(clicked()), this, SLOT(AutoScanPorts())); //set a few UI components depending on Windows / Linux #ifdef WIN32 m_Controls->portTypeLabelPolaris->setVisible(false); m_Controls->portTypePolaris->setVisible(false); #else m_Controls->m_comPortLabelPolaris->setText("Port Nr:"); m_Controls->m_portSpinBoxPolaris->setPrefix(""); #endif } } void QmitkNDIPolarisWidget::ResetOutput() { m_Controls->m_outputTextPolaris->setHtml("output:"); } void QmitkNDIPolarisWidget::AddOutput(std::string s) { m_Controls->m_outputTextPolaris->setHtml(QString(s.c_str())); m_Controls->m_outputTextPolaris->verticalScrollBar()->setValue(m_Controls->m_outputTextPolaris->verticalScrollBar()->maximum()); } -mitk::TrackingDevice::Pointer QmitkNDIPolarisWidget::ConstructTrackingDevice() +mitk::TrackingDevice::Pointer QmitkNDIPolarisWidget::GetTrackingDevice() { mitk::NDITrackingDevice::Pointer tempTrackingDevice = mitk::NDITrackingDevice::New(); //get port int port = 0; port = m_Controls->m_portSpinBoxPolaris->value(); //build prefix (depends on linux/win) QString prefix = ""; #ifdef WIN32 prefix = "COM"; tempTrackingDevice->SetPortNumber(static_cast(port)); //also set the com port for compatibility tempTrackingDevice->SetIlluminationActivationRate(GetPolarisFrameRate()); #else prefix = m_Controls->portTypePolaris->currentText(); tempTrackingDevice->SetIlluminationActivationRate(GetPolarisFrameRate()); #endif //build port name string QString portName = prefix + QString::number(port); tempTrackingDevice->SetDeviceName(portName.toStdString()); //set the port name tempTrackingDevice->SetBaudRate(mitk::SerialCommunication::BaudRate115200);//set baud rate tempTrackingDevice->SetType(mitk::NDIPolarisTypeInformation::GetTrackingDeviceName()); return static_cast(tempTrackingDevice); } void QmitkNDIPolarisWidget::StoreUISettings() { std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget"; if (this->GetPersistenceService()) // now save the settings using the persistence service { mitk::PropertyList::Pointer propList = this->GetPersistenceService()->GetPropertyList(id); propList->Set("PolarisPortWin", m_Controls->m_portSpinBoxPolaris->value()); propList->Set("PortTypePolaris", m_Controls->portTypePolaris->currentIndex()); propList->Set("PolarisFrameRate", GetPolarisFrameRate()); } else // QSettings as a fallback if the persistence service is not available { QSettings settings; settings.beginGroup(QString::fromStdString(id)); settings.setValue("portSpinBoxPolaris", QVariant(m_Controls->m_portSpinBoxPolaris->value())); settings.setValue("portTypePolaris", QVariant(m_Controls->portTypePolaris->currentIndex())); settings.setValue("PolarisFrameRate", QVariant(GetPolarisFrameRate())); settings.endGroup(); } } void QmitkNDIPolarisWidget::LoadUISettings() { std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget"; if (this->GetPersistenceService()) { int port = 0; int portType = 0; int polarisFrameRate = 0; mitk::PropertyList::Pointer propList = this->GetPersistenceService()->GetPropertyList(id); if (propList.IsNull()) { MITK_ERROR << "Property list for this UI (" << id << ") is not available, could not load UI settings!"; return; } propList->Get("PolarisPortWin", port); propList->Get("PortTypePolaris", portType); propList->Get("PolarisFrameRate", polarisFrameRate); this->SetPortTypeToGUI(portType); this->SetPortValueToGUI(port); m_Controls->m_frameRateComboBoxPolaris->setCurrentIndex((int)(polarisFrameRate / 30)); } else { // QSettings as a fallback if the persistence service is not available QSettings settings; settings.beginGroup(QString::fromStdString(id)); m_Controls->m_portSpinBoxPolaris->setValue(settings.value("portSpinBoxPolaris", 0).toInt()); m_Controls->portTypePolaris->setCurrentIndex(settings.value("portTypePolaris", 0).toInt()); //framerates 20,30,60 --> divided by 30 = 0,1,2 --> index of combobox m_Controls->m_frameRateComboBoxPolaris->setCurrentIndex((int)(settings.value("PolarisFrameRate", 0).toInt() / 30)); settings.endGroup(); } } mitk::IlluminationActivationRate QmitkNDIPolarisWidget::GetPolarisFrameRate() { mitk::IlluminationActivationRate frameRate; QString comboBox = m_Controls->m_frameRateComboBoxPolaris->currentText(); if (comboBox == "20 Hz") frameRate = mitk::Hz20; else if (comboBox == "30 Hz") frameRate = mitk::Hz30; else if (comboBox == "60 Hz") frameRate = mitk::Hz60; return frameRate; } void QmitkNDIPolarisWidget::SetPortValueToGUI(int portValue){ m_Controls->m_portSpinBoxPolaris->setValue(portValue); } void QmitkNDIPolarisWidget::SetPortTypeToGUI(int portType){ m_Controls->portTypePolaris->setCurrentIndex(portType); } QmitkNDIPolarisWidget* QmitkNDIPolarisWidget::Clone(QWidget* parent) const { QmitkNDIPolarisWidget* clonedWidget = new QmitkNDIPolarisWidget(parent); clonedWidget->Initialize(); clonedWidget->SetPortTypeToGUI(m_Controls->portTypePolaris->currentIndex()); clonedWidget->SetPortValueToGUI(m_Controls->m_portSpinBoxPolaris->value()); clonedWidget->m_Controls->m_frameRateComboBoxPolaris->setCurrentIndex(m_Controls->m_frameRateComboBoxPolaris->currentIndex()); return clonedWidget; } diff --git a/Modules/IGTUI/Qmitk/QmitkNDIPolarisWidget.h b/Modules/IGTUI/Qmitk/QmitkNDIPolarisWidget.h index d201e84349..b6f3060e4b 100644 --- a/Modules/IGTUI/Qmitk/QmitkNDIPolarisWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkNDIPolarisWidget.h @@ -1,71 +1,71 @@ /*=================================================================== 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 QmitkNDIPolarisWidget_H #define QmitkNDIPolarisWidget_H #include "ui_QmitkNDIPolarisWidget.h" #include "QmitkNDIAbstractDeviceWidget.h" /** Documentation: * \brief Implementation of a configuration widget for NDI Polaris Devices. * * \ingroup IGTUI */ class MITKIGTUI_EXPORT QmitkNDIPolarisWidget : public QmitkNDIAbstractDeviceWidget { Q_OBJECT // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) public: static const std::string VIEW_ID; QmitkNDIPolarisWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkNDIPolarisWidget(); virtual void Initialize(); signals: protected slots : private: /// \brief Creation of the connections void CreateConnections(); void CreateQtPartControl(QWidget *parent); protected: /** @return Returns the frame rate set in the m_frameRatePolaris ComboBox */ mitk::IlluminationActivationRate GetPolarisFrameRate(); Ui::QmitkNDIPolarisWidget* m_Controls; virtual void SetPortValueToGUI(int portValue); virtual void SetPortTypeToGUI(int portType); virtual QmitkNDIPolarisWidget* Clone(QWidget* parent) const; public: virtual void ResetOutput(); virtual void AddOutput(std::string s); - virtual mitk::TrackingDevice::Pointer ConstructTrackingDevice(); + virtual mitk::TrackingDevice::Pointer GetTrackingDevice(); virtual void StoreUISettings(); virtual void LoadUISettings(); }; #endif diff --git a/Modules/IGTUI/Qmitk/QmitkNPOptitrackWidget.cpp b/Modules/IGTUI/Qmitk/QmitkNPOptitrackWidget.cpp index a594650739..bec95717f1 100644 --- a/Modules/IGTUI/Qmitk/QmitkNPOptitrackWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkNPOptitrackWidget.cpp @@ -1,122 +1,122 @@ /*=================================================================== 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 "QmitkNPOptitrackWidget.h" #include "mitkOptitrackTrackingDevice.h" #include "mitkNPOptitrackTrackingTypeInformation.h" #include "QmitkIGTCommonHelper.h" #include #include #include const std::string QmitkNPOptitrackWidget::VIEW_ID = "org.mitk.views.NPOptitrackWidget"; QmitkNPOptitrackWidget::QmitkNPOptitrackWidget(QWidget* parent, Qt::WindowFlags f) : QmitkAbstractTrackingDeviceWidget(parent, f) , m_Controls(nullptr) { } void QmitkNPOptitrackWidget::Initialize() { InitializeSuperclassWidget(); CreateQtPartControl(this); CreateConnections(); } QmitkNPOptitrackWidget::~QmitkNPOptitrackWidget() { delete m_Controls; } void QmitkNPOptitrackWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkNPOptitrackWidget; m_Controls->setupUi(parent); } } void QmitkNPOptitrackWidget::CreateConnections() { if (m_Controls) { connect((QObject*)(m_Controls->m_testConnectionOptitrack), SIGNAL(clicked()), this, SLOT(TestConnection())); connect((QObject*)(m_Controls->m_SetOptitrackCalibrationFile), SIGNAL(clicked()), this, SLOT(SetOptitrackCalibrationFileClicked())); } } void QmitkNPOptitrackWidget::ResetOutput() { m_Controls->m_outputTextOptitrack->setHtml("output:"); } void QmitkNPOptitrackWidget::AddOutput(std::string s) { m_Controls->m_outputTextOptitrack->setHtml(QString(s.c_str())); m_Controls->m_outputTextOptitrack->verticalScrollBar()->setValue(m_Controls->m_outputTextOptitrack->verticalScrollBar()->maximum()); } -mitk::TrackingDevice::Pointer QmitkNPOptitrackWidget::ConstructTrackingDevice() +mitk::TrackingDevice::Pointer QmitkNPOptitrackWidget::GetTrackingDevice() { // Create the Tracking Device mitk::OptitrackTrackingDevice::Pointer tempTrackingDevice = mitk::OptitrackTrackingDevice::New(); // Set the calibration File tempTrackingDevice->SetCalibrationPath(m_OptitrackCalibrationFile); //Set the camera parameters tempTrackingDevice->SetExp(m_Controls->m_OptitrackExp->value()); tempTrackingDevice->SetLed(m_Controls->m_OptitrackLed->value()); tempTrackingDevice->SetThr(m_Controls->m_OptitrackThr->value()); tempTrackingDevice->SetType(mitk::NPOptitrackTrackingTypeInformation::GetTrackingDeviceName()); return static_cast(tempTrackingDevice); } bool QmitkNPOptitrackWidget::IsDeviceInstalled() { return mitk::OptitrackTrackingDevice::New()->IsDeviceInstalled(); } void QmitkNPOptitrackWidget::SetOptitrackCalibrationFileClicked() { std::string filename = QFileDialog::getOpenFileName(NULL, tr("Open Calibration File"), QmitkIGTCommonHelper::GetLastFileLoadPath(), "*.*").toLatin1().data(); if (filename == "") { return; } else { QmitkIGTCommonHelper::SetLastFileLoadPathByFileName(QString::fromStdString(filename)); m_OptitrackCalibrationFile = filename; Poco::Path myPath = Poco::Path(m_OptitrackCalibrationFile.c_str()); m_Controls->m_OptitrackCalibrationFile->setText("Calibration File: " + QString(myPath.getFileName().c_str())); } } QmitkNPOptitrackWidget* QmitkNPOptitrackWidget::Clone(QWidget* parent) const { QmitkNPOptitrackWidget* clonedWidget = new QmitkNPOptitrackWidget(parent); clonedWidget->Initialize(); clonedWidget->m_OptitrackCalibrationFile = this->m_OptitrackCalibrationFile; clonedWidget->m_Controls->m_OptitrackCalibrationFile->setText(m_Controls->m_OptitrackCalibrationFile->text()); clonedWidget->m_Controls->m_OptitrackExp->setValue(m_Controls->m_OptitrackExp->value()); clonedWidget->m_Controls->m_OptitrackLed->setValue(m_Controls->m_OptitrackLed->value()); clonedWidget->m_Controls->m_OptitrackThr->setValue(m_Controls->m_OptitrackThr->value()); return clonedWidget; } diff --git a/Modules/IGTUI/Qmitk/QmitkNPOptitrackWidget.h b/Modules/IGTUI/Qmitk/QmitkNPOptitrackWidget.h index 54d8c17088..eef9e52e12 100644 --- a/Modules/IGTUI/Qmitk/QmitkNPOptitrackWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkNPOptitrackWidget.h @@ -1,68 +1,68 @@ /*=================================================================== 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 QmitkNPOptitrackWidget_H #define QmitkNPOptitrackWidget_H #include "ui_QmitkNPOptitrackWidget.h" #include "QmitkAbstractTrackingDeviceWidget.h" /** Documentation: * \brief Implementation of a configuration widget for NP Optitrack Tracking Devices. * * \ingroup IGTUI */ class MITKIGTUI_EXPORT QmitkNPOptitrackWidget : public QmitkAbstractTrackingDeviceWidget { Q_OBJECT // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) public: static const std::string VIEW_ID; QmitkNPOptitrackWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkNPOptitrackWidget(); virtual void Initialize(); signals: protected slots : /* @brief Opens a file dialog. The users sets the calibration file which location is then stored in the member m_OptitrackCalibrationFile.*/ void SetOptitrackCalibrationFileClicked(); private: /// \brief Creation of the connections void CreateConnections(); void CreateQtPartControl(QWidget *parent); protected: virtual QmitkNPOptitrackWidget* Clone(QWidget* parent) const; std::string m_OptitrackCalibrationFile; Ui::QmitkNPOptitrackWidget* m_Controls; public: virtual void ResetOutput(); virtual void AddOutput(std::string s); - virtual mitk::TrackingDevice::Pointer ConstructTrackingDevice(); + virtual mitk::TrackingDevice::Pointer GetTrackingDevice(); virtual bool IsDeviceInstalled(); }; #endif diff --git a/Modules/IGTUI/Qmitk/QmitkOpenIGTLinkWidget.cpp b/Modules/IGTUI/Qmitk/QmitkOpenIGTLinkWidget.cpp index 0a8c3a1ffc..317575e58d 100644 --- a/Modules/IGTUI/Qmitk/QmitkOpenIGTLinkWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkOpenIGTLinkWidget.cpp @@ -1,69 +1,69 @@ /*=================================================================== 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 "QmitkOpenIGTLinkWidget.h" #include "mitkOpenIGTLinkTrackingDevice.h" const std::string QmitkOpenIGTLinkWidget::VIEW_ID = "org.mitk.views.OpenIGTLinkWidget"; QmitkOpenIGTLinkWidget::QmitkOpenIGTLinkWidget(QWidget* parent, Qt::WindowFlags f) : QmitkAbstractTrackingDeviceWidget(parent, f) , m_Controls(nullptr) { } void QmitkOpenIGTLinkWidget::Initialize() { InitializeSuperclassWidget(); CreateQtPartControl(this); } QmitkOpenIGTLinkWidget::~QmitkOpenIGTLinkWidget() { delete m_Controls; } void QmitkOpenIGTLinkWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkOpenIGTLinkWidget; m_Controls->setupUi(parent); } } -mitk::TrackingDevice::Pointer QmitkOpenIGTLinkWidget::ConstructTrackingDevice() +mitk::TrackingDevice::Pointer QmitkOpenIGTLinkWidget::GetTrackingDevice() { // Create the Virtual Tracking Device mitk::OpenIGTLinkTrackingDevice::Pointer OIGTLDevice = mitk::OpenIGTLinkTrackingDevice::New(); OIGTLDevice->SetPortNumber(m_Controls->m_OpenIGTLinkPort->text().toInt()); OIGTLDevice->SetHostname(m_Controls->m_OpenIGTLinkHostname->text().toStdString()); OIGTLDevice->SetUpdateRate(m_Controls->m_UpdateRate->value()); return static_cast(OIGTLDevice); } QmitkOpenIGTLinkWidget* QmitkOpenIGTLinkWidget::Clone(QWidget* parent) const { QmitkOpenIGTLinkWidget* clonedWidget = new QmitkOpenIGTLinkWidget(parent); clonedWidget->Initialize(); clonedWidget->m_Controls->m_OpenIGTLinkPort->setText(m_Controls->m_OpenIGTLinkPort->text()); clonedWidget->m_Controls->m_OpenIGTLinkHostname->setText(m_Controls->m_OpenIGTLinkHostname->text()); return clonedWidget; } diff --git a/Modules/IGTUI/Qmitk/QmitkOpenIGTLinkWidget.h b/Modules/IGTUI/Qmitk/QmitkOpenIGTLinkWidget.h index a0ebfbb3e5..77ee5d390b 100644 --- a/Modules/IGTUI/Qmitk/QmitkOpenIGTLinkWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkOpenIGTLinkWidget.h @@ -1,54 +1,54 @@ /*=================================================================== 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 QmitkOpenIGTLinkWidget_H #define QmitkOpenIGTLinkWidget_H #include "ui_QmitkOpenIGTLinkWidget.h" #include "QmitkAbstractTrackingDeviceWidget.h" /** Documentation: * \brief Implementation of a configuration widget to use an Open IGT Link connection to track any device. * * \ingroup IGTUI */ class MITKIGTUI_EXPORT QmitkOpenIGTLinkWidget : public QmitkAbstractTrackingDeviceWidget { Q_OBJECT // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) public: static const std::string VIEW_ID; QmitkOpenIGTLinkWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkOpenIGTLinkWidget(); virtual void Initialize(); signals: protected slots : private: void CreateQtPartControl(QWidget *parent); protected: virtual QmitkOpenIGTLinkWidget* Clone(QWidget* parent) const; Ui::QmitkOpenIGTLinkWidget* m_Controls; public: - virtual mitk::TrackingDevice::Pointer ConstructTrackingDevice(); + virtual mitk::TrackingDevice::Pointer GetTrackingDevice(); }; #endif diff --git a/Modules/IGTUI/Qmitk/QmitkPolhemusTrackerWidget.cpp b/Modules/IGTUI/Qmitk/QmitkPolhemusTrackerWidget.cpp index 03a15a5285..5cbfd7cf59 100644 --- a/Modules/IGTUI/Qmitk/QmitkPolhemusTrackerWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkPolhemusTrackerWidget.cpp @@ -1,246 +1,246 @@ /*=================================================================== 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 "QmitkPolhemusTrackerWidget.h" #include #include #include #include #include #include #include #include #include "vtkRenderer.h" #include "vtkCamera.h" const std::string QmitkPolhemusTrackerWidget::VIEW_ID = "org.mitk.views.PolhemusTrackerWidget"; QmitkPolhemusTrackerWidget::QmitkPolhemusTrackerWidget(QWidget* parent, Qt::WindowFlags f) : QmitkAbstractTrackingDeviceWidget(parent, f) , m_Controls(nullptr) { } void QmitkPolhemusTrackerWidget::Initialize() { InitializeSuperclassWidget(); CreateQtPartControl(this); SetAdvancedSettingsVisible(false); } QmitkPolhemusTrackerWidget::~QmitkPolhemusTrackerWidget() { delete m_Controls; } void QmitkPolhemusTrackerWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkPolhemusTrackerWidget; m_Controls->setupUi(parent); } } void QmitkPolhemusTrackerWidget::CreateConnections() { if (m_Controls) { connect((QObject*)(m_Controls->m_hemisphereTracking), SIGNAL(clicked()), this, SLOT(on_m_hemisphereTracking_clicked())); connect((QObject*)(m_Controls->m_ToggleHemisphere), SIGNAL(clicked()), this, SLOT(on_m_ToggleHemisphere_clicked())); connect((QObject*)(m_Controls->m_SetHemisphere), SIGNAL(clicked()), this, SLOT(on_m_SetHemisphere_clicked())); connect((QObject*)(m_Controls->m_GetHemisphere), SIGNAL(clicked()), this, SLOT(on_m_GetHemisphere_clicked())); connect((QObject*)(m_Controls->m_AdjustHemisphere), SIGNAL(clicked()), this, SLOT(on_m_AdjustHemisphere_clicked())); } } -mitk::TrackingDevice::Pointer QmitkPolhemusTrackerWidget::ConstructTrackingDevice() +mitk::TrackingDevice::Pointer QmitkPolhemusTrackerWidget::GetTrackingDevice() { if (m_TrackingDevice.IsNull()) { m_TrackingDevice = mitk::PolhemusTrackingDevice::New(); m_TrackingDevice->SetHemisphereTrackingEnabled(m_Controls->m_hemisphereTracking->isChecked()); } return static_cast(m_TrackingDevice); } QmitkPolhemusTrackerWidget* QmitkPolhemusTrackerWidget::Clone(QWidget* parent) const { QmitkPolhemusTrackerWidget* clonedWidget = new QmitkPolhemusTrackerWidget(parent); clonedWidget->Initialize(); return clonedWidget; } void QmitkPolhemusTrackerWidget::on_m_hemisphereTracking_clicked() { m_TrackingDevice->SetHemisphereTrackingEnabled(m_Controls->m_hemisphereTracking->isChecked()); } void QmitkPolhemusTrackerWidget::on_m_ToggleHemisphere_clicked() { // Index 0 == All Tools == -1 for Polhemus interface; Index 2 == Tool 2 == 1 for Polhemus; etc... m_TrackingDevice->ToggleHemisphere(GetSelectedToolIndex()); MITK_INFO << "Toggle Hemisphere for tool " << m_Controls->m_ToolSelection->currentText().toStdString(); } void QmitkPolhemusTrackerWidget::on_m_SetHemisphere_clicked() { mitk::Vector3D _hemisphere; mitk::FillVector3D(_hemisphere, m_Controls->m_Hemisphere_X->value(), m_Controls->m_Hemisphere_Y->value(), m_Controls->m_Hemisphere_Z->value()); m_TrackingDevice->SetHemisphere(GetSelectedToolIndex(), _hemisphere); //If you set a hemisphere vector which is unequal (0|0|0), this means, that there is no hemisphere tracing any more //disable the checkbox in case it was on before, so that it can be reactivated... if (_hemisphere.GetNorm() != 0) m_Controls->m_hemisphereTracking->setChecked(false); MITK_INFO << "Hemisphere set for tool " << m_Controls->m_ToolSelection->currentText().toStdString(); } void QmitkPolhemusTrackerWidget::on_m_GetHemisphere_clicked() { mitk::Vector3D _hemisphere = m_TrackingDevice->GetHemisphere(GetSelectedToolIndex()); m_Controls->m_Hemisphere_X->setValue(_hemisphere[0]); m_Controls->m_Hemisphere_Y->setValue(_hemisphere[1]); m_Controls->m_Hemisphere_Z->setValue(_hemisphere[2]); MITK_INFO << "Updated SpinBox for Hemisphere of tool " << m_Controls->m_ToolSelection->currentText().toStdString(); } void QmitkPolhemusTrackerWidget::on_m_AdjustHemisphere_clicked() { int _tool = GetSelectedToolIndex(); QMessageBox msgBox; QString _text; if (_tool == -1) { _text.append("Adjusting hemisphere for all tools."); msgBox.setText(_text); _text.clear(); _text = tr("Please make sure, that the entire tools (including tool tip AND sensor) are placed in the positive x hemisphere. Press 'Adjust hemisphere' if you are ready."); msgBox.setInformativeText(_text); } else { _text.append("Adjusting hemisphere for tool '"); _text.append(m_Controls->m_ToolSelection->currentText()); _text.append(tr("' at port %2.").arg(_tool)); msgBox.setText(_text); _text.clear(); _text = tr("Please make sure, that the entire tool (including tool tip AND sensor) is placed in the positive x hemisphere. Press 'Adjust hemisphere' if you are ready."); msgBox.setInformativeText(_text); } QPushButton *adjustButton = msgBox.addButton(tr("Adjust hemisphere"), QMessageBox::ActionRole); QPushButton *cancelButton = msgBox.addButton(QMessageBox::Cancel); msgBox.exec(); if (msgBox.clickedButton() == adjustButton) { // adjust mitk::Vector3D _hemisphere; mitk::FillVector3D(_hemisphere, 1, 0, 0); //Was HemiTracking on before? bool _hemiTrack = m_TrackingDevice->GetHemisphereTrackingEnabled(_tool); //Set Hemisphere to (1|0|0) where user placed the tool m_TrackingDevice->SetHemisphere(_tool, _hemisphere); //If HemiTrack was on, switch it on again by setting (0|0|0). Don't use general fuction SetHemisphereTrackingEnabled, as we might only adapt a single tool. if (_hemiTrack) { mitk::FillVector3D(_hemisphere, 0, 0, 0); m_TrackingDevice->SetHemisphere(_tool, _hemisphere); } MITK_INFO << "Adjusting Hemisphere for tool " << m_Controls->m_ToolSelection->currentText().toStdString(); } else if (msgBox.clickedButton() == cancelButton) { // abort MITK_INFO << "Cancel 'Adjust hemisphere'. No harm done..."; } } void QmitkPolhemusTrackerWidget::OnConnected(bool _success) { if (!_success) { this->m_TrackingDevice = nullptr; return; } SetAdvancedSettingsVisible(true); if (m_TrackingDevice->GetToolCount() != m_Controls->m_ToolSelection->count()) { m_Controls->m_ToolSelection->clear(); m_Controls->m_ToolSelection->addItem("All Tools"); for (int i = 0; i < m_TrackingDevice->GetToolCount(); ++i) { m_Controls->m_ToolSelection->addItem(m_TrackingDevice->GetTool(i)->GetToolName()); } } } void QmitkPolhemusTrackerWidget::OnStartTracking(bool _success) { if (!_success) return; //Rotate mitk standard multi widget, so that the view matches the sensor. Positive x == right, y == front, z == down; mitk::BaseRenderer::GetInstance(mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget4"))->GetCameraController()->SetViewToPosterior(); mitk::BaseRenderer::GetInstance(mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget4"))->GetVtkRenderer()->GetActiveCamera()->SetViewUp(0, 0, -1); } void QmitkPolhemusTrackerWidget::OnDisconnected(bool _success) { if (!_success) return; SetAdvancedSettingsVisible(false); } void QmitkPolhemusTrackerWidget::SetAdvancedSettingsVisible(bool _enable) { m_Controls->m_ToolSelection->setVisible(_enable); m_Controls->label_toolsToChange->setVisible(_enable); m_Controls->label_UpdateOnRequest->setVisible(_enable); m_Controls->m_GetHemisphere->setVisible(_enable); m_Controls->m_Hemisphere_X->setVisible(_enable); m_Controls->m_Hemisphere_Y->setVisible(_enable); m_Controls->m_Hemisphere_Z->setVisible(_enable); m_Controls->m_SetHemisphere->setVisible(_enable); m_Controls->m_ToggleHemisphere->setVisible(_enable); m_Controls->m_AdjustHemisphere->setVisible(_enable); } int QmitkPolhemusTrackerWidget::GetSelectedToolIndex() { // Index 0 == All Tools == -1 for Polhemus interface; Index 1 == Tool 1 == 1 for Polhemus Interface; etc... int _index = m_Controls->m_ToolSelection->currentIndex() - 1; if (_index != -1) { //we need to find the internal Polhemus index for this tool. This is stored in the identifier of a navigation tool or as Port in PolhemusTool. mitk::PolhemusTool* _tool = dynamic_cast(m_TrackingDevice->GetToolByName(m_Controls->m_ToolSelection->currentText().toStdString())); _index = _tool->GetToolPort(); } return _index; } \ No newline at end of file diff --git a/Modules/IGTUI/Qmitk/QmitkPolhemusTrackerWidget.h b/Modules/IGTUI/Qmitk/QmitkPolhemusTrackerWidget.h index 3a94895816..03e2886c07 100644 --- a/Modules/IGTUI/Qmitk/QmitkPolhemusTrackerWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkPolhemusTrackerWidget.h @@ -1,89 +1,89 @@ /*=================================================================== 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 QmitkPolhemusTrackerWidget_H #define QmitkPolhemusTrackerWidget_H #include "ui_QmitkPolhemusTrackerWidget.h" #include "QmitkAbstractTrackingDeviceWidget.h" #include /** Documentation: * \brief Implementation of a configuration widget for Polhemus Tracking Devices. * * \ingroup IGTUI */ class MITKIGTUI_EXPORT QmitkPolhemusTrackerWidget : public QmitkAbstractTrackingDeviceWidget { Q_OBJECT // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) public: static const std::string VIEW_ID; QmitkPolhemusTrackerWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkPolhemusTrackerWidget(); virtual void Initialize(); signals: protected slots : void on_m_hemisphereTracking_clicked(); void on_m_ToggleHemisphere_clicked(); void on_m_SetHemisphere_clicked(); void on_m_GetHemisphere_clicked(); void on_m_AdjustHemisphere_clicked(); private: /// \brief Creation of the connections void CreateConnections(); void CreateQtPartControl(QWidget *parent); void SetAdvancedSettingsVisible(bool _enable); int GetSelectedToolIndex(); protected: virtual QmitkPolhemusTrackerWidget* Clone(QWidget* parent) const; Ui::QmitkPolhemusTrackerWidget* m_Controls; mitk::PolhemusTrackingDevice::Pointer m_TrackingDevice; public: - virtual mitk::TrackingDevice::Pointer ConstructTrackingDevice(); + virtual mitk::TrackingDevice::Pointer GetTrackingDevice(); /** * \brief This function is called, when in the TrackingToolboxView "Connect" was clicked and the device is successful connected. * Can e.g. be used to activate options of a tracking device only when it is connected. */ virtual void OnConnected( bool _success); /** * \brief This function is called, when in the TrackingToolboxView "Disconnect" was clicked and the device is successful disconnected. * Can e.g. be used to activate/disactivate options of a tracking device. */ virtual void OnDisconnected(bool _success); /** * \brief This function is called, when in the TrackingToolboxView "Start Tracking" was clicked and the device successfully started tracking. * Can e.g. be used to activate options of a tracking device only when tracking is started. */ virtual void OnStartTracking(bool _success); }; #endif diff --git a/Modules/IGTUI/Qmitk/QmitkTrackingDeviceConfigurationWidget.cpp b/Modules/IGTUI/Qmitk/QmitkTrackingDeviceConfigurationWidget.cpp index 8debf2df40..f54ea62b68 100644 --- a/Modules/IGTUI/Qmitk/QmitkTrackingDeviceConfigurationWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkTrackingDeviceConfigurationWidget.cpp @@ -1,372 +1,357 @@ /*=================================================================== 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 "QmitkTrackingDeviceConfigurationWidget.h" #include "mitkNDIPolarisTypeInformation.h" +#include "mitkNDIAuroraTypeInformation.h" #include const std::string QmitkTrackingDeviceConfigurationWidget::VIEW_ID = "org.mitk.views.trackingdeviceconfigurationwidget"; QmitkTrackingDeviceConfigurationWidget::QmitkTrackingDeviceConfigurationWidget(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f) , m_Controls(nullptr) - , m_TrackingDevice(nullptr) , m_DeviceToWidgetIndexMap() { //initializations CreateQtPartControl(this); CreateConnections(); RefreshTrackingDeviceCollection(); //initialize a few UI elements AddOutput("
First Element selected"); //Order from Collection List //reset a few things ResetOutput(); //restore old UI settings LoadUISettings(); } QmitkTrackingDeviceConfigurationWidget::~QmitkTrackingDeviceConfigurationWidget() { StoreUISettings(); delete m_Controls; - m_TrackingDevice = nullptr; } void QmitkTrackingDeviceConfigurationWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkTrackingDeviceConfigurationWidgetControls; m_Controls->setupUi(parent); } } void QmitkTrackingDeviceConfigurationWidget::CreateConnections() { if (m_Controls) { connect((QObject*)(m_Controls->m_TrackingDeviceChooser), SIGNAL(currentIndexChanged(int)), this, SLOT(TrackingDeviceChanged())); } } void QmitkTrackingDeviceConfigurationWidget::TrackingDeviceChanged() { const std::string currentDevice = this->GetCurrentDeviceName(); //show the correspondig widget m_Controls->m_TrackingSystemWidget->setCurrentIndex(m_DeviceToWidgetIndexMap[currentDevice]); //reset output ResetOutput(); AddOutput("
"); AddOutput(currentDevice); AddOutput(" selected"); QmitkAbstractTrackingDeviceWidget* widget = GetWidget(currentDevice); if (widget == nullptr || !widget->IsDeviceInstalled()) { AddOutput("
ERROR: not installed!"); } emit TrackingDeviceSelectionChanged(); } void QmitkTrackingDeviceConfigurationWidget::RefreshTrackingDeviceCollection() { // clean-up of stacked widget, drop-down box and map for (auto& item : m_DeviceToWidgetIndexMap) { m_Controls->m_TrackingSystemWidget->removeWidget(m_Controls->m_TrackingSystemWidget->widget(item.second)); MITK_INFO << "removing widget for device '" << item.first << "'"; } m_Controls->m_TrackingDeviceChooser->clear(); m_DeviceToWidgetIndexMap.clear(); // get tracking device type service references us::ModuleContext* context = us::GetModuleContext(); std::vector > deviceRefs = context->GetServiceReferences(); if (deviceRefs.empty()) { MITK_ERROR << "No tracking device type service found!"; return; } // get tracking device configuration widget service references std::vector > widgetRefs = context->GetServiceReferences(); if (widgetRefs.empty()) { MITK_ERROR << "No tracking device configuration widget service found!"; return; } const us::ServiceReference& deviceServiceReference = deviceRefs.front(); const us::ServiceReference& widgetServiceReference = widgetRefs.front(); mitk::TrackingDeviceTypeCollection* deviceTypeCollection = context->GetService(deviceServiceReference); mitk::TrackingDeviceWidgetCollection* deviceWidgetCollection = context->GetService(widgetServiceReference); for (auto name : deviceTypeCollection->GetTrackingDeviceTypeNames()) { // if the device is not included yet, add name to comboBox and widget to stackedWidget if (m_Controls->m_TrackingDeviceChooser->findText(QString::fromStdString(name)) == -1) { m_Controls->m_TrackingDeviceChooser->addItem(QString::fromStdString(name)); QWidget* current = deviceWidgetCollection->GetTrackingDeviceWidgetClone(name); if (current == nullptr) { MITK_WARN << "No widget for tracking device type " << name << " available. Please implement and register it!"; current = new QWidget(); } m_DeviceToWidgetIndexMap[name] = m_Controls->m_TrackingSystemWidget->addWidget(current); } } if (!m_DeviceToWidgetIndexMap.empty()) { m_Controls->m_TrackingDeviceChooser->setCurrentIndex(0); m_Controls->m_TrackingSystemWidget->setCurrentIndex(0); } context->UngetService(deviceServiceReference); context->UngetService(widgetServiceReference); } //######################### internal help methods ####################################### void QmitkTrackingDeviceConfigurationWidget::ResetOutput() { QmitkAbstractTrackingDeviceWidget* currentWidget = this->GetWidget(this->GetCurrentDeviceName()); if (currentWidget == nullptr) { return; } currentWidget->ResetOutput(); currentWidget->repaint(); } void QmitkTrackingDeviceConfigurationWidget::AddOutput(std::string s) { QmitkAbstractTrackingDeviceWidget* currentWidget = this->GetWidget(this->GetCurrentDeviceName()); if (currentWidget == nullptr) { return; } currentWidget->AddOutput(s); currentWidget->repaint(); } -mitk::TrackingDevice::Pointer QmitkTrackingDeviceConfigurationWidget::ConstructTrackingDevice() +mitk::TrackingDevice::Pointer QmitkTrackingDeviceConfigurationWidget::GetTrackingDevice() { - MITK_DEBUG << "Construct Tracking Device"; QmitkAbstractTrackingDeviceWidget* currentWidget = this->GetWidget(this->GetCurrentDeviceName()); - if (currentWidget == nullptr) + if (currentWidget == nullptr || !currentWidget->IsDeviceInstalled()) { return nullptr; } - return currentWidget->ConstructTrackingDevice(); -} - -mitk::TrackingDevice::Pointer QmitkTrackingDeviceConfigurationWidget::GetTrackingDevice() -{ - //Only create a new device, if we don't have one yet or if the device selection in the widget has changed. - //otherwise, hundered of devices will be created each time someone calls Get... - if (m_TrackingDevice.IsNull() || m_TrackingDevice->GetTrackingDeviceName() != this->GetCurrentDeviceName()) - m_TrackingDevice = ConstructTrackingDevice(); - - if (m_TrackingDevice.IsNull() || !m_TrackingDevice->IsDeviceInstalled()) return nullptr; - else return this->m_TrackingDevice; + return currentWidget->GetTrackingDevice(); } void QmitkTrackingDeviceConfigurationWidget::StoreUISettings() { std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget"; std::string selectedDevice = this->GetCurrentDeviceName(); //Save settings for every widget //Don't use m_DeviceTypeCollection here, it's already unregistered, when deconstructor is called... for (int index = 0; index < m_Controls->m_TrackingSystemWidget->count(); index++) { QmitkAbstractTrackingDeviceWidget* widget = dynamic_cast(m_Controls->m_TrackingSystemWidget->widget(index)); if (widget != nullptr) { widget->StoreUISettings(); } } if (this->GetPersistenceService()) // now save the settings using the persistence service { mitk::PropertyList::Pointer propList = this->GetPersistenceService()->GetPropertyList(id); propList->Set("SelectedDevice", selectedDevice); } else // QSettings as a fallback if the persistence service is not available { QSettings settings; settings.beginGroup(QString::fromStdString(id)); settings.setValue("trackingDeviceChooser", QVariant(QString::fromStdString(selectedDevice))); settings.endGroup(); } } /** * @brief QmitkTrackingDeviceConfigurationWidget::LoadUISettings * * Precondition: * Make sure that QStackedWidget is already initialized, * e.g. by calling RefreshTrackingDeviceCollection() before. */ void QmitkTrackingDeviceConfigurationWidget::LoadUISettings() { //Load settings for every widget for (int index = 0; index < m_Controls->m_TrackingSystemWidget->count(); index++) { QmitkAbstractTrackingDeviceWidget* widget = dynamic_cast(m_Controls->m_TrackingSystemWidget->widget(index)); if (widget != nullptr) { widget->LoadUISettings(); } } std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget"; std::string selectedDevice; if (this->GetPersistenceService()) { mitk::PropertyList::Pointer propList = this->GetPersistenceService()->GetPropertyList(id); if (propList.IsNull()) { MITK_ERROR << "Property list for this UI (" << id << ") is not available, could not load UI settings!"; return; } propList->Get("SelectedDevice", selectedDevice); if (selectedDevice.empty()) { MITK_ERROR << "Loaded data from persistence service is invalid (SelectedDevice:" << selectedDevice << "): aborted to restore data!"; return; } MITK_INFO << "Successfully restored UI settings"; } else { // QSettings as a fallback if the persistence service is not available QSettings settings; settings.beginGroup(QString::fromStdString(id)); selectedDevice = settings.value("trackingDeviceChooser", "").toString().toStdString(); settings.endGroup(); } // The selected device requires some checks because a device that is not installed should not be restored to avoid bugs. // Use NDI Polaris as default if there's no widget registered for selected device or there's a widget for it but no device installed. const auto& deviceIterator = m_DeviceToWidgetIndexMap.find(selectedDevice); if (deviceIterator != m_DeviceToWidgetIndexMap.end()) { QmitkAbstractTrackingDeviceWidget* widget = dynamic_cast(m_Controls->m_TrackingSystemWidget->widget(deviceIterator->second)); if (widget == nullptr || (widget != nullptr && !widget->IsDeviceInstalled())) { selectedDevice = mitk::NDIPolarisTypeInformation::GetTrackingDeviceName(); } } else { selectedDevice = mitk::NDIPolarisTypeInformation::GetTrackingDeviceName(); } const int index = m_Controls->m_TrackingDeviceChooser->findText(QString::fromStdString(selectedDevice)); if (index >= 0) { m_Controls->m_TrackingDeviceChooser->setCurrentIndex(index); } else { MITK_ERROR << "Failed to load UI setting for tracking device configuration"; return; } m_Controls->m_TrackingSystemWidget->setCurrentIndex(m_DeviceToWidgetIndexMap[selectedDevice]); } std::string QmitkTrackingDeviceConfigurationWidget::GetCurrentDeviceName(void) const { return m_Controls->m_TrackingDeviceChooser->currentText().toStdString(); } QmitkAbstractTrackingDeviceWidget* QmitkTrackingDeviceConfigurationWidget::GetWidget(const std::string& deviceName) const { const auto& deviceIterator = m_DeviceToWidgetIndexMap.find(deviceName); if (deviceIterator != m_DeviceToWidgetIndexMap.end()) { QWidget* widget = m_Controls->m_TrackingSystemWidget->widget(deviceIterator->second); return dynamic_cast(widget); } return nullptr; } void QmitkTrackingDeviceConfigurationWidget::OnConnected(bool _success) { - if (!_success) - this->m_TrackingDevice = nullptr; this->GetWidget(this->GetCurrentDeviceName())->OnConnected(_success); } void QmitkTrackingDeviceConfigurationWidget::OnDisconnected(bool _success) { this->GetWidget(this->GetCurrentDeviceName())->OnDisconnected(_success); } void QmitkTrackingDeviceConfigurationWidget::OnStartTracking(bool _success) { this->GetWidget(this->GetCurrentDeviceName())->OnStartTracking(_success); } void QmitkTrackingDeviceConfigurationWidget::OnStopTracking(bool _success) { this->GetWidget(this->GetCurrentDeviceName())->OnStopTracking(_success); } diff --git a/Modules/IGTUI/Qmitk/QmitkTrackingDeviceConfigurationWidget.h b/Modules/IGTUI/Qmitk/QmitkTrackingDeviceConfigurationWidget.h index ce0992676d..6a968cfdd3 100644 --- a/Modules/IGTUI/Qmitk/QmitkTrackingDeviceConfigurationWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkTrackingDeviceConfigurationWidget.h @@ -1,131 +1,128 @@ /*=================================================================== 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 QMITKTRACKINGDEVICECONFIGURATIONWIDGET_H #define QMITKTRACKINGDEVICECONFIGURATIONWIDGET_H #include #include #include "MitkIGTUIExports.h" #include "ui_QmitkTrackingDeviceConfigurationWidgetControls.h" #include "mitkTrackingDeviceTypeCollection.h" #include "mitkTrackingDeviceWidgetCollection.h" /** Documentation: * \brief An object of this class offers an UI to configurate * a tracking device. If the user finished the configuration process and * a fully configurated tracking device is availiabe the object emits a * signal "TrackingDeviceConfigurationFinished()". You can then get the * tracking device by calling the method GetTrackingDevice(). * * Once the tracking device is configurated there are two ways to reset * the UI to allow the user for configuring a new device. The method Reset() * can be called and there is also a button "reset" which can be pressed by * the user. In both cases a signal "TrackingDeviceConfigurationReseted()" * is emitted and you may wait for a new configurated tracking device. * * * \ingroup IGTUI */ class MITKIGTUI_EXPORT QmitkTrackingDeviceConfigurationWidget : public QWidget { Q_OBJECT public: static const std::string VIEW_ID; QmitkTrackingDeviceConfigurationWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkTrackingDeviceConfigurationWidget(); /* @return Returns the current configurated tracking device. If the user didn't finished the * configuration process or if there is an error during configuration NULL is returned. */ mitk::TrackingDevice::Pointer GetTrackingDevice(); signals: /* @brief This signal is sent if the tracking device was changed. */ void TrackingDeviceSelectionChanged(); public slots: /** * \brief This function is called, when in the TrackingToolboxView "Connect" was clicked and the device is successful connected. * Can e.g. be used to activate options of a tracking device only when it is connected. */ void OnConnected(bool _success); /** * \brief This function is called, when in the TrackingToolboxView "Disconnect" was clicked and the device is successful disconnected. * Can e.g. be used to activate/disactivate options of a tracking device. */ void OnDisconnected(bool _success); /** * \brief This function is called, when in the TrackingToolboxView "Start Tracking" was clicked and the device successfully started tracking. * Can e.g. be used to activate options of a tracking device only when tracking is started. */ void OnStartTracking(bool _success); /** * \brief This function is called, when in the TrackingToolboxView "Stop Tracking" was clicked and the device successful stopped tracking. * Can e.g. be used to activate/disactivate options when device is not tracking. */ void OnStopTracking(bool _success); protected: /// \brief Creation of the connections virtual void CreateConnections(); virtual void CreateQtPartControl(QWidget *parent); Ui::QmitkTrackingDeviceConfigurationWidgetControls* m_Controls; - mitk::TrackingDevice::Pointer m_TrackingDevice; - // key is port name (e.g. "COM1", "/dev/ttyS0"), value will be filled with the type of tracking device at this port typedef QMap PortDeviceMap; //######################### internal help methods ####################################### void ResetOutput(); void AddOutput(std::string s); - mitk::TrackingDevice::Pointer ConstructTrackingDevice(); void StoreUISettings(); void LoadUISettings(); /* @brief This method is called when the user clicks on "Refresh Selection" (m_RefreshTrackingDeviceCollection). It then sets the correct widget for the selected tracking device.*/ void RefreshTrackingDeviceCollection(); 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 TrackingDeviceChanged(); private: PERSISTENCE_GET_SERVICE_METHOD_MACRO std::string GetCurrentDeviceName(void) const; QmitkAbstractTrackingDeviceWidget* GetWidget(const std::string& deviceName) const; /** * @brief Mapping of device type identifier and index of the configuration widget in QStackedWidget. */ std::map m_DeviceToWidgetIndexMap; }; #endif diff --git a/Modules/IGTUI/Qmitk/QmitkVirtualTrackerWidget.cpp b/Modules/IGTUI/Qmitk/QmitkVirtualTrackerWidget.cpp index 4b4a3db625..257b3fe1bc 100644 --- a/Modules/IGTUI/Qmitk/QmitkVirtualTrackerWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkVirtualTrackerWidget.cpp @@ -1,94 +1,94 @@ /*=================================================================== 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 "QmitkVirtualTrackerWidget.h" #include "mitkVirtualTrackingDevice.h" const std::string QmitkVirtualTrackerWidget::VIEW_ID = "org.mitk.views.VirtualTrackerWidget"; QmitkVirtualTrackerWidget::QmitkVirtualTrackerWidget(QWidget* parent, Qt::WindowFlags f) : QmitkAbstractTrackingDeviceWidget(parent, f) , m_Controls(nullptr) { } void QmitkVirtualTrackerWidget::Initialize() { InitializeSuperclassWidget(); CreateQtPartControl(this); CreateConnections(); } QmitkVirtualTrackerWidget::~QmitkVirtualTrackerWidget() { delete m_Controls; } void QmitkVirtualTrackerWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkVirtualTrackerWidget; m_Controls->setupUi(parent); } } void QmitkVirtualTrackerWidget::CreateConnections() { if (m_Controls) { connect((QObject*)(m_Controls->m_EnableGaussianNoise), SIGNAL(clicked()), this, SLOT(EnableGaussianNoise())); } } -mitk::TrackingDevice::Pointer QmitkVirtualTrackerWidget::ConstructTrackingDevice() +mitk::TrackingDevice::Pointer QmitkVirtualTrackerWidget::GetTrackingDevice() { // Create the Virtual Tracking Device mitk::VirtualTrackingDevice::Pointer returnValue = mitk::VirtualTrackingDevice::New(); if (m_Controls->m_EnableGaussianNoise->isChecked()) { returnValue->EnableGaussianNoise(); returnValue->SetParamsForGaussianNoise(m_Controls->m_MeanDistributionParam->value(), m_Controls->m_DeviationDistributionParam->value()); } return static_cast(returnValue); //static_cast necessary for compiling with Linux } void QmitkVirtualTrackerWidget::EnableGaussianNoise() { if (m_Controls->m_EnableGaussianNoise->isChecked()) { m_Controls->m_MeanDistributionParam->setEnabled(true); m_Controls->m_DeviationDistributionParam->setEnabled(true); } else { m_Controls->m_MeanDistributionParam->setEnabled(false); m_Controls->m_DeviationDistributionParam->setEnabled(false); } } QmitkVirtualTrackerWidget* QmitkVirtualTrackerWidget::Clone(QWidget* parent) const { QmitkVirtualTrackerWidget* clonedWidget = new QmitkVirtualTrackerWidget(parent); clonedWidget->Initialize(); clonedWidget->m_Controls->m_EnableGaussianNoise->setEnabled(m_Controls->m_EnableGaussianNoise->isEnabled()); clonedWidget->m_Controls->m_MeanDistributionParam->setValue(m_Controls->m_MeanDistributionParam->value()); clonedWidget->m_Controls->m_DeviationDistributionParam->setValue(m_Controls->m_DeviationDistributionParam->value()); return clonedWidget; } diff --git a/Modules/IGTUI/Qmitk/QmitkVirtualTrackerWidget.h b/Modules/IGTUI/Qmitk/QmitkVirtualTrackerWidget.h index a713d917dc..3864f62fd8 100644 --- a/Modules/IGTUI/Qmitk/QmitkVirtualTrackerWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkVirtualTrackerWidget.h @@ -1,61 +1,61 @@ /*=================================================================== 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 QmitkVirtualTrackerWidget_H #define QmitkVirtualTrackerWidget_H #include "ui_QmitkVirtualTrackerWidget.h" #include "QmitkAbstractTrackingDeviceWidget.h" /** Documentation: * \brief Implementation of a configuration widget for a Vitrual Tracking Device. * * \ingroup IGTUI */ class MITKIGTUI_EXPORT QmitkVirtualTrackerWidget : public QmitkAbstractTrackingDeviceWidget { Q_OBJECT // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) public: static const std::string VIEW_ID; QmitkVirtualTrackerWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkVirtualTrackerWidget(); virtual void Initialize(); signals: protected slots : /* @brief Enables or disables the Gaussian Noise for the VirtualTrackingDevice dependent on the State of the according Checkbox */ void EnableGaussianNoise(); private: /// \brief Creation of the connections void CreateConnections(); void CreateQtPartControl(QWidget *parent); protected: virtual QmitkVirtualTrackerWidget* Clone(QWidget* parent) const; Ui::QmitkVirtualTrackerWidget* m_Controls; public: - virtual mitk::TrackingDevice::Pointer ConstructTrackingDevice(); + virtual mitk::TrackingDevice::Pointer GetTrackingDevice(); }; #endif