MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
QmitkIGTConnectionWidget.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
15
19
23
24#include <QFileDialog>
25#include <QMessageBox>
26
27const std::string QmitkIGTConnectionWidget::VIEW_ID = "org.mitk.views.igtconnectionwidget";
28
29QmitkIGTConnectionWidget::QmitkIGTConnectionWidget(QWidget* parent, Qt::WindowFlags f)
30 : QWidget(parent, f)
31{
32 m_Controls = nullptr;
35 m_TrackingDevice = nullptr;
36 m_TrackingDeviceSource = nullptr;
38 m_DataStorage = nullptr;
39 m_ErrorMessage = "";
40}
41
42
46
48{
49 if (!m_Controls)
50 {
51 // create GUI widgets
52 m_Controls = new Ui::QmitkIGTConnectionWidgetControls;
53 m_Controls->setupUi(parent);
54 }
55}
56
58{
59 if ( m_Controls )
60 {
61 connect( (QObject*)(m_Controls->connectButton), SIGNAL(clicked()), this, SLOT(OnConnect()) );
62 }
63}
64
66{
67 if (m_Controls->connectButton->isChecked()) // Load tools and connect tracking device
68 {
69 m_Controls->connectButton->setChecked(false);
70 // create TrackingDevice
71 m_TrackingDevice = m_Controls->trackingDeviceConfigurationWidget->GetTrackingDevice();
72 if (m_TrackingDevice.IsNotNull())
73 {
74 QString fileName = QFileDialog::getOpenFileName(nullptr,tr("Open Navigation tool storage"), QmitkIGTCommonHelper::GetLastFileLoadPath(), tr("Toolfile (*.tfl)"));
76 if (LoadToolfile(fileName))
77 {
78 // Create TrackingDeviceSource and add tools
79 mitk::TrackingDeviceSourceConfigurator::Pointer myTrackingDeviceSourceFactory =
80 mitk::TrackingDeviceSourceConfigurator::New(this->m_NavigationToolStorage,m_TrackingDevice);
81 m_TrackingDeviceSource = myTrackingDeviceSourceFactory->CreateTrackingDeviceSource();
82 m_TrackingDeviceSource->Connect();
83 m_TrackingDeviceSource->StartTracking();
84 // change button text
85 m_Controls->connectButton->setText("Disconnect");
86 m_Controls->connectButton->setChecked(true);
87 // disable configuration widget
88 m_Controls->trackingDeviceConfigurationWidget->setEnabled(false);
89 // emit connected signal
91 }
92 else
93 {
94 QString error(m_ErrorMessage.c_str());
95 QMessageBox::warning(nullptr,"Warning",error);
96 // reset button to unchecked
97 m_Controls->connectButton->setChecked(false);
98 // remove tool nodes from DataStorage
99 this->RemoveToolNodes();
100 // reset NavigationToolStorage
101 m_NavigationToolStorage = nullptr;
102 }
103 }
104 else
105 {
106 // reset button to unchecked
107 m_Controls->connectButton->setChecked(false);
108 MITK_ERROR<<"Could not create TrackingDevice";
109 }
110 }
111 else // Disconnect tracking device
112 {
113 // disconnect TrackingDeviceSource
114 if (m_TrackingDeviceSource.IsNotNull())
115 {
116 m_TrackingDeviceSource->StopTracking();
117 m_TrackingDeviceSource->Disconnect();
118 }
119 // remove tool nodes from DataStorage
120 this->RemoveToolNodes();
121 // reset members
122 m_NavigationToolStorage = nullptr;
123 m_TrackingDevice = nullptr;
124 m_TrackingDeviceSource = nullptr;
125 // change button text
126 m_Controls->connectButton->setText("Connect");
127 // enable configuration widget
128 m_Controls->trackingDeviceConfigurationWidget->setEnabled(true);
129 // emit disconnected signal
131 }
132}
133
135{
136 if (m_DataStorage.IsNotNull())
137 {
138 std::string filename = qFilename.toStdString();
139 mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(this->m_DataStorage);
140 mitk::NavigationToolStorage::Pointer tempStorage = myDeserializer->Deserialize(filename);
141 m_NavigationToolStorage = tempStorage;
142
143 if (tempStorage.IsNull())
144 {
145 m_ErrorMessage = myDeserializer->GetErrorMessage();
146 return false;
147 }
148
149 // check if there are tools in the storage
150 mitk::TrackingDeviceType lastDevice;
151 if (tempStorage->GetToolCount()>0)
152 {
153 lastDevice = tempStorage->GetTool(0)->GetTrackingDeviceType();
154 }
155 else
156 {
157 m_ErrorMessage = "Error: Didn't find a tool in the storage. Do you want to navigate without even an instrument?";
158 return false;
159 }
160 //check if all tools are from the same device
161 for (unsigned int i=1; i<tempStorage->GetToolCount(); i++)
162 {
163 if (lastDevice!=tempStorage->GetTool(i)->GetTrackingDeviceType())
164 {
165 m_ErrorMessage = "Error: Toolfile contains tools of different tracking devices which is not acceptable for this application.";
166 return false;
167 }
168 else lastDevice = tempStorage->GetTool(i)->GetTrackingDeviceType();
169 }
170 // check if tracking device typ of tools corresponds with chosen tracking device
171 if (m_TrackingDevice->GetType()!=tempStorage->GetTool(0)->GetTrackingDeviceType())
172 {
173 m_ErrorMessage = "Tools are not compliant with this tracking device. Please use correct toolfile for specified device.";
174 return false;
175 }
176 m_NavigationToolStorage = tempStorage;
177 return true;
178 }
179 else
180 {
181 m_ErrorMessage = "Error: No DataStorage available! Make sure the widget is initialized with a DataStorage";
182 return false;
183 }
184}
185
187{
188 for (unsigned int i=0; i<m_NavigationToolStorage->GetToolCount(); i++)
189 {
190 mitk::DataNode::Pointer currentNode = m_NavigationToolStorage->GetTool(i)->GetDataNode();
191 if (currentNode.IsNotNull())
192 {
193 m_DataStorage->Remove(currentNode);
194 }
195 }
196}
197
198mitk::TrackingDeviceSource::Pointer QmitkIGTConnectionWidget::GetTrackingDeviceSource()
199{
201}
202
203void QmitkIGTConnectionWidget::SetDataStorage( mitk::DataStorage::Pointer dataStorage )
204{
205 m_DataStorage = dataStorage;
206}
207
208mitk::NavigationToolStorage::Pointer QmitkIGTConnectionWidget::GetNavigationToolStorage()
209{
211}
static void SetLastFileLoadPathByFileName(const QString &str)
static const QString GetLastFileLoadPath()
void RemoveToolNodes()
Remove the tool nodes currently associated to the tools hold in the NavigationToolStorage from the Da...
void TrackingDeviceDisconnected()
signal emitted when TrackingDevice was successfully disconnected
std::string m_ErrorMessage
current problem description
bool LoadToolfile(QString qFilename)
Load NavigationToolStorage from given filename and set according member.
static const std::string VIEW_ID
mitk::TrackingDeviceSource::Pointer GetTrackingDeviceSource()
void OnConnect()
Asks the user to specify a tool file and finally connects the TrackingDeviceSource.
mitk::NavigationToolStorage::Pointer m_NavigationToolStorage
holds all navigation tools currently loaded
virtual void CreateConnections()
Creation of the connections.
mitk::TrackingDevice::Pointer m_TrackingDevice
tracking device currently connected
QmitkIGTConnectionWidget(QWidget *parent=nullptr, Qt::WindowFlags f={})
mitk::NavigationToolStorage::Pointer GetNavigationToolStorage()
Get the NavigationToolStorage holding all tools with corresponding surface objects.
mitk::DataStorage::Pointer m_DataStorage
data storage to put navigation tools
void SetDataStorage(mitk::DataStorage::Pointer dataStorage)
set DataStorage that is used to put the navigation tools
virtual void CreateQtPartControl(QWidget *parent)
void TrackingDeviceConnected()
signal emitted when TrackingDevice was successfully connected
Ui::QmitkIGTConnectionWidgetControls * m_Controls
mitk::TrackingDeviceSource::Pointer m_TrackingDeviceSource
holds the preconfigured source of the IGT pipeline which is provided by this widget for further proce...
std::string TrackingDeviceType