MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
QmitkNDIPolarisWidget.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
14
17
18#include <QScrollBar>
19#include <QSettings>
20
21const std::string QmitkNDIPolarisWidget::VIEW_ID = "org.mitk.views.NDIPolarisWidget";
22
23QmitkNDIPolarisWidget::QmitkNDIPolarisWidget(QWidget* parent, Qt::WindowFlags f)
25 , m_Controls(nullptr)
26{
27}
28
30{
32 CreateQtPartControl(this);
33 CreateConnections();
34}
35
40
41void QmitkNDIPolarisWidget::CreateQtPartControl(QWidget *parent)
42{
43 if (!m_Controls)
44 {
45 // create GUI widgets
46 m_Controls = new Ui::QmitkNDIPolarisWidget;
47 m_Controls->setupUi(parent);
48 }
49}
50
51void QmitkNDIPolarisWidget::CreateConnections()
52{
53 if (m_Controls)
54 {
55 connect((QObject*)(m_Controls->m_testConnectionPolaris), SIGNAL(clicked()), this, SLOT(TestConnection()));
56 connect((QObject*)(m_Controls->m_AutoScanPolaris), SIGNAL(clicked()), this, SLOT(AutoScanPorts()));
57
58 //set a few UI components depending on Windows / Linux
59#ifdef WIN32
60 m_Controls->portTypeLabelPolaris->setVisible(false);
61 m_Controls->portTypePolaris->setVisible(false);
62
63#else
64 m_Controls->m_comPortLabelPolaris->setText("Port Nr:");
65 m_Controls->m_portSpinBoxPolaris->setPrefix("");
66#endif
67 }
68 }
69
71{
72 m_Controls->m_outputTextPolaris->setHtml("<body style=\" font-family:\'MS Shell Dlg 2\'; font-size:7pt; font-weight:400; font-style:normal;\" bgcolor=black><span style=\"color:#ffffff;\"><u>output:</u>");
73}
74
76{
77 m_Controls->m_outputTextPolaris->setHtml(QString(s.c_str()));
78 m_Controls->m_outputTextPolaris->verticalScrollBar()->setValue(m_Controls->m_outputTextPolaris->verticalScrollBar()->maximum());
79}
80
81mitk::TrackingDevice::Pointer QmitkNDIPolarisWidget::GetTrackingDevice()
82{
83 mitk::NDITrackingDevice::Pointer tempTrackingDevice = mitk::NDITrackingDevice::New();
84
85 //get port
86 int port = 0;
87 port = m_Controls->m_portSpinBoxPolaris->value();
88
89 //build prefix (depends on linux/win)
90 QString prefix = "";
91#ifdef WIN32
92 prefix = "COM";
93 tempTrackingDevice->SetPortNumber(static_cast<mitk::SerialCommunication::PortNumber>(port)); //also set the com port for compatibility
94 tempTrackingDevice->SetIlluminationActivationRate(GetPolarisFrameRate());
95#else
96 prefix = m_Controls->portTypePolaris->currentText();
97 tempTrackingDevice->SetIlluminationActivationRate(GetPolarisFrameRate());
98#endif
99
100 //build port name string
101 QString portName = prefix + QString::number(port);
102
103 tempTrackingDevice->SetDeviceName(portName.toStdString()); //set the port name
104 tempTrackingDevice->SetBaudRate(mitk::SerialCommunication::BaudRate115200);//set baud rate
105 tempTrackingDevice->SetType(mitk::NDIPolarisTypeInformation::GetTrackingDeviceName());
106 return static_cast<mitk::TrackingDevice::Pointer>(tempTrackingDevice);
107}
108
110{
111 std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget";
112 if (this->GetPersistenceService()) // now save the settings using the persistence service
113 {
114 mitk::PropertyList::Pointer propList = this->GetPersistenceService()->GetPropertyList(id);
115 propList->Set("PolarisPortWin", m_Controls->m_portSpinBoxPolaris->value());
116 propList->Set("PortTypePolaris", m_Controls->portTypePolaris->currentIndex());
117 propList->Set("PolarisFrameRate", GetPolarisFrameRate());
118 }
119 else // QSettings as a fallback if the persistence service is not available
120 {
121 QSettings settings;
122 settings.beginGroup(QString::fromStdString(id));
123 settings.setValue("portSpinBoxPolaris", QVariant(m_Controls->m_portSpinBoxPolaris->value()));
124 settings.setValue("portTypePolaris", QVariant(m_Controls->portTypePolaris->currentIndex()));
125 settings.setValue("PolarisFrameRate", QVariant(GetPolarisFrameRate()));
126 settings.endGroup();
127 }
128}
129
131{
132 std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget";
133 if (this->GetPersistenceService())
134 {
135 int port = 0;
136 int portType = 0;
137 int polarisFrameRate = 0;
138
139 mitk::PropertyList::Pointer propList = this->GetPersistenceService()->GetPropertyList(id);
140 if (propList.IsNull())
141 {
142 MITK_ERROR << "Property list for this UI (" << id << ") is not available, could not load UI settings!"; return;
143 }
144
145 propList->Get("PolarisPortWin", port);
146 propList->Get("PortTypePolaris", portType);
147 propList->Get("PolarisFrameRate", polarisFrameRate);
148 this->SetPortTypeToGUI(portType);
149 this->SetPortValueToGUI(port);
150 m_Controls->m_frameRateComboBoxPolaris->setCurrentIndex((int)(polarisFrameRate / 30));
151 }
152 else
153 {
154 // QSettings as a fallback if the persistence service is not available
155 QSettings settings;
156 settings.beginGroup(QString::fromStdString(id));
157
158 m_Controls->m_portSpinBoxPolaris->setValue(settings.value("portSpinBoxPolaris", 0).toInt());
159 m_Controls->portTypePolaris->setCurrentIndex(settings.value("portTypePolaris", 0).toInt());
160 //framerates 20,30,60 --> divided by 30 = 0,1,2 --> index of combobox
161 m_Controls->m_frameRateComboBoxPolaris->setCurrentIndex((int)(settings.value("PolarisFrameRate", 0).toInt() / 30));
162
163 settings.endGroup();
164 }
165}
166
168{
170 QString comboBox = m_Controls->m_frameRateComboBoxPolaris->currentText();
171 if (comboBox == "20 Hz") frameRate = mitk::Hz20;
172 else if (comboBox == "30 Hz") frameRate = mitk::Hz30;
173 else if (comboBox == "60 Hz") frameRate = mitk::Hz60;
174 return frameRate;
175}
176
178 m_Controls->m_portSpinBoxPolaris->setValue(portValue);
179}
181 m_Controls->portTypePolaris->setCurrentIndex(portType);
182}
183
185{
186 QmitkNDIPolarisWidget* clonedWidget = new QmitkNDIPolarisWidget(parent);
187 clonedWidget->Initialize();
188
189 clonedWidget->SetPortTypeToGUI(m_Controls->portTypePolaris->currentIndex());
190 clonedWidget->SetPortValueToGUI(m_Controls->m_portSpinBoxPolaris->value());
191 clonedWidget->m_Controls->m_frameRateComboBoxPolaris->setCurrentIndex(m_Controls->m_frameRateComboBoxPolaris->currentIndex());
192 return clonedWidget;
193}
Abstract class of a configuration widget for NDI Devices. For implementations see NDIAuroraWidget or ...
Implementation of a configuration widget for NDI Polaris Devices.
Ui::QmitkNDIPolarisWidget * m_Controls
void StoreUISettings() override
Optional method to store and load settings of your widget (see QmitkNDIPolarisWidget)
void AddOutput(std::string s) override
Optional method to add output to a small screen in the trackingToolbox (see QmitkNDIPolarisWidget)
void ResetOutput() override
Optional method to add output to a small screen in the trackingToolbox (see QmitkNDIPolarisWidget)
void SetPortValueToGUI(int portValue) override
QmitkNDIPolarisWidget(QWidget *parent=nullptr, Qt::WindowFlags f={})
void Initialize() override
Subclass must implement this method to return a pointer to a copy of the object. Please don't forget ...
static const std::string VIEW_ID
mitk::IlluminationActivationRate GetPolarisFrameRate()
mitk::TrackingDevice::Pointer GetTrackingDevice() override
void LoadUISettings() override
Optional method to store and load settings of your widget (see QmitkNDIPolarisWidget)
void SetPortTypeToGUI(int portType) override
QmitkNDIPolarisWidget * Clone(QWidget *parent) const override
Subclass must implement this method to return a pointer to a copy of the object. Please don't forget ...
IlluminationActivationRate
activation rate of IR illuminator for NDI Polaris tracking device