Medical Imaging Interaction Toolkit  2018.4.99-f51274ea
Medical Imaging Interaction Toolkit
QmitkUSNewVideoDeviceWidget.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 //#define _USE_MATH_DEFINES
15 
16 // QT headers
17 #include <QFileDialog>
18 #include <QMessageBox>
19 
20 // mitk headers
21 
22 // itk headers
23 
24 #include <mitkUSDeviceReaderXML.h>
25 #include <mitkUSDeviceWriterXML.h>
26 
27 const std::string QmitkUSNewVideoDeviceWidget::VIEW_ID =
28 "org.mitk.views.QmitkUSNewVideoDeviceWidget";
29 
31  Qt::WindowFlags f)
32  : QWidget(parent, f)
33 {
34  m_Controls = nullptr;
35  CreateQtPartControl(this);
36 }
37 
39 
41 
43 {
44  if (!m_Controls)
45  {
46  // create GUI widgets
47  m_Controls = new Ui::QmitkUSNewVideoDeviceWidgetControls;
48  m_Controls->setupUi(parent);
49  this->CreateConnections();
50  }
51 }
52 
54 {
55  if (m_Controls)
56  {
57  // connect(m_Controls->m_BtnDone, SIGNAL(clicked()), this,
58  // SLOT(OnClickedDone()));
59  connect(m_Controls->m_BtnCancel, SIGNAL(clicked()), this,
60  SLOT(OnClickedCancel()));
61  connect(m_Controls->m_RadioDeviceSource, SIGNAL(clicked()), this,
62  SLOT(OnDeviceTypeSelection()));
63  connect(m_Controls->m_RadioFileSource, SIGNAL(clicked()), this,
64  SLOT(OnDeviceTypeSelection()));
65  connect(m_Controls->m_RadioOIGTLClientSource, SIGNAL(clicked()), this,
66  SLOT(OnDeviceTypeSelection()));
67  connect(m_Controls->m_RadioOIGTLServerSource, SIGNAL(clicked()), this,
68  SLOT(OnDeviceTypeSelection()));
69  connect(m_Controls->m_OpenFileButton, SIGNAL(clicked()), this,
70  SLOT(OnOpenFileButtonClicked()));
71 
72  connect(m_Controls->m_BtnSave, SIGNAL(clicked()), this,
73  SLOT(OnSaveButtonClicked()));
74  connect(m_Controls->m_BtnLoadConfiguration, SIGNAL(clicked()), this,
76 
77  //Connect buttons and functions for editing of probes
78  connect(m_Controls->m_AddNewProbePushButton, SIGNAL(clicked()), this, SLOT(OnAddNewProbeClicked()));
79  connect(m_Controls->m_BtnRemoveProbe, SIGNAL(clicked()), this, SLOT(OnClickedRemoveProbe()));
80  connect(m_Controls->m_BtnRemoveDepth, SIGNAL(clicked()), this, SLOT(OnClickedRemoveDepth()));
81  connect(m_Controls->m_BtnAddDepths, SIGNAL(clicked()), this, SLOT(OnClickedAddDepths()));
82  connect(m_Controls->m_Probes, SIGNAL(currentTextChanged(const QString &)), this, SLOT(OnProbeChanged(const QString &)));
83  connect(m_Controls->m_Depths, SIGNAL(currentTextChanged(const QString &)), this, SLOT(OnDepthChanged(const QString &)));
84 
85  connect(m_Controls->m_XSpacingSpinBox, SIGNAL(valueChanged(double)), this, SLOT(OnXSpacingSpinBoxChanged(double)));
86  connect(m_Controls->m_YSpacingSpinBox, SIGNAL(valueChanged(double)), this, SLOT(OnYSpacingSpinBoxChanged(double)));
87  connect(m_Controls->m_CroppingTopSpinBox, SIGNAL(valueChanged(int)), this, SLOT(OnCroppingTopSpinBoxChanged(int)));
88  connect(m_Controls->m_CroppingRightSpinBox, SIGNAL(valueChanged(int)), this, SLOT(OnCroppingRightSpinBoxChanged(int)));
89  connect(m_Controls->m_CroppingBottomSpinBox, SIGNAL(valueChanged(int)), this, SLOT(OnCroppingBottomSpinBoxChanged(int)));
90  connect(m_Controls->m_CroppingLeftSpinBox, SIGNAL(valueChanged(int)), this, SLOT(OnCroppingLeftSpinBoxChanged(int)));
91  }
92 }
93 
95 
97 {
98  m_Active = false;
99 
100  // Create Device
101  mitk::USDevice::Pointer newDevice;
102  if (m_Controls->m_RadioDeviceSource->isChecked())
103  {
104  newDevice = mitk::USVideoDevice::New(
105  m_Controls->m_DeviceSelector->value(),
106  m_Controls->m_Manufacturer->text().toStdString(),
107  m_Controls->m_Model->text().toStdString());
108  newDevice->SetComment(m_Controls->m_Comment->text().toStdString());
109  }
110  else if (m_Controls->m_RadioFileSource->isChecked())
111  {
112  newDevice = mitk::USVideoDevice::New(
113  m_Controls->m_FilePathSelector->text().toStdString(),
114  m_Controls->m_Manufacturer->text().toStdString(),
115  m_Controls->m_Model->text().toStdString());
116  newDevice->SetComment(m_Controls->m_Comment->text().toStdString());
117  }
118  else if (m_Controls->m_RadioOIGTLClientSource->isChecked())
119  {
120  std::string host = m_Controls->m_OIGTLClientHost->text().toStdString();
121  int port = m_Controls->m_OIGTLClientPort->value();
122 
123  // Create a new USIGTLDevice. The last parameter tells the device that it should be a client.
124  newDevice = mitk::USIGTLDevice::New(m_Controls->m_Manufacturer->text().toStdString(),
125  m_Controls->m_Model->text().toStdString(), host, port, false);
126  //New behavior at this position: do not return immediately as it was done in earlier MITK-versions
127  // The IGTL Device can have different probe configurations, as well.
128  }
129  else
130  {
131  std::string host = m_Controls->m_OIGTLServerHost->text().toStdString();
132  int port = m_Controls->m_OIGTLServerPort->value();
133 
134  // Create a new USIGTLDevice. The last parameter tells the device that it should be a server.
135  newDevice = mitk::USIGTLDevice::New(m_Controls->m_Manufacturer->text().toStdString(),
136  m_Controls->m_Model->text().toStdString(), host, port, true);
137  //New behavior at this position: do not return immediately as it was done in earlier MITK-versions
138  // The IGTL Device can have different probe configurations, as well.
139  }
140 
141  //At first: only ckeck, whether it is a USImageVideoSource or not (--> if it a IGTL Client)
142  // Later: perhaps it would be helpful, if the IGTLMessageToUSImageFilter have a region of interest, as well.
143  mitk::USImageVideoSource::Pointer imageSource =
144  dynamic_cast<mitk::USImageVideoSource*>(
145  newDevice->GetUSImageSource().GetPointer());
146  if (imageSource.IsNotNull())
147  {
148 
149  // Set Video Options
150  imageSource->SetColorOutput(!m_Controls->m_CheckGreyscale->isChecked());
151 
152  // If Resolution override is activated, apply it
153  if (m_Controls->m_CheckResolutionOverride->isChecked())
154  {
155  int width = m_Controls->m_ResolutionWidth->value();
156  int height = m_Controls->m_ResolutionHeight->value();
157  imageSource->OverrideResolution(width, height);
158  imageSource->SetResolutionOverride(true);
159  }
160  }
161 
162  if (m_Controls->m_Probes->count() != 0 ) //there are informations about the probes of the device, so create the probes
163  {
164  this->AddProbesToDevice(newDevice);
165  }
166  else //no information about the probes of the device, so set default value
167  {
168  mitk::USProbe::Pointer probe = mitk::USProbe::New("default");
169  probe->SetDepth(0);
170  newDevice->DeleteAllProbes();
171  newDevice->AddNewProbe(probe);
172  }
173  newDevice->Initialize();
175 
176  emit Finished();
177 }
178 
180 {
181  m_Active = false;
182  m_TargetDevice->SetManufacturer(m_Controls->m_Manufacturer->text().toStdString());
183  m_TargetDevice->SetName(m_Controls->m_Model->text().toStdString());
184  m_TargetDevice->SetComment(m_Controls->m_Comment->text().toStdString());
185 
186  if (m_Controls->m_Probes->count() != 0) //there are informations about the probes of the device, so create the probes
187  {
189  }
190  else //no information about the probes of the device, so set default value
191  {
192  mitk::USProbe::Pointer probe = mitk::USProbe::New("default");
193  probe->SetDepth(0);
194  m_TargetDevice->DeleteAllProbes();
195  m_TargetDevice->AddNewProbe(probe);
196  }
197 
198  //At first: only ckeck, whether it is a USImageVideoSource or not (--> if it a IGTL Client)
199  // Later: perhaps it would be helpful, if the IGTLMessageToUSImageFilter have a region of interest, as well.
200  mitk::USImageVideoSource::Pointer imageSource =
201  dynamic_cast<mitk::USImageVideoSource*>(
202  m_TargetDevice->GetUSImageSource().GetPointer());
203  if (imageSource.IsNotNull())
204  {
205  // Set Video Options
206  imageSource->SetColorOutput(!m_Controls->m_CheckGreyscale->isChecked());
207 
208  // If Resolution override is activated, apply it
209  if (m_Controls->m_CheckResolutionOverride->isChecked())
210  {
211  int width = m_Controls->m_ResolutionWidth->value();
212  int height = m_Controls->m_ResolutionHeight->value();
213  imageSource->OverrideResolution(width, height);
214  imageSource->SetResolutionOverride(true);
215  }
216  }
218  MITK_INFO << "Finished Editing";
219  emit Finished();
220 }
221 
223 {
224  m_TargetDevice = nullptr;
225  m_Active = false;
228  emit Finished();
229 }
230 
232 {
233  m_Controls->m_FilePathSelector->setEnabled(
234  m_Controls->m_RadioFileSource->isChecked());
235  m_Controls->m_DeviceSelector->setEnabled(
236  m_Controls->m_RadioDeviceSource->isChecked());
237  m_Controls->m_OIGTLClientHost->setEnabled(
238  m_Controls->m_RadioOIGTLClientSource->isChecked());
239  m_Controls->m_OIGTLClientPort->setEnabled(
240  m_Controls->m_RadioOIGTLClientSource->isChecked());
241  m_Controls->m_OIGTLServerHost->setEnabled(
242  m_Controls->m_RadioOIGTLServerSource->isChecked());
243  m_Controls->m_OIGTLServerPort->setEnabled(
244  m_Controls->m_RadioOIGTLServerSource->isChecked());
245 }
246 
248 {
249  QString fileName = QFileDialog::getOpenFileName(nullptr, "Open Video File");
250  if (fileName.isNull())
251  {
252  return;
253  } // user pressed cancel
254 
255  m_Controls->m_FilePathSelector->setText(fileName);
256 
257  m_Controls->m_RadioFileSource->setChecked(true);
258  this->OnDeviceTypeSelection();
259 }
260 
262 
264 {
265  // If no VideoDevice is given, throw an exception
266  if (device->GetDeviceClass().compare("org.mitk.modules.us.USVideoDevice") != 0 &&
267  device->GetDeviceClass().compare("IGTL Client") != 0)
268  {
269  // TODO Alert if bad path
270  mitkThrow() << "NewVideoDeviceWidget recieved an incompatible device type "
271  "to edit. Type was: " << device->GetDeviceClass();
272  }
273 
274  m_TargetDevice = device;
275  m_Active = true;
276  m_ConfigProbes.clear();
277  m_ConfigProbes = m_TargetDevice->GetAllProbes();
279 }
280 
282 {
283 
284  //Prevent multiple calls of OnClickedDone()
285  disconnect(m_Controls->m_BtnDone, SIGNAL(clicked()), this, SLOT(OnClickedDone()));
286  //Toggle functionality of Btn_Done
287  connect(m_Controls->m_BtnDone, SIGNAL(clicked()), this, SLOT(OnClickedDone()));
288  m_Controls->m_BtnDone->setText("Add Video Device");
289 
290  //Fill Metadata with default information
291  m_Controls->m_Manufacturer->setText("Unknown Manufacturer");
292  m_Controls->m_Model->setText("Unknown Model");
293  m_Controls->m_Comment->setText("None");
294 
295  m_TargetDevice = nullptr;
296  m_ConfigProbes.clear();
297  m_ConfigProbes.clear();
298  m_Active = true;
299 }
300 
302 
305 {
306  QListWidgetItem* result = new QListWidgetItem;
307  std::string text =
308  device->GetManufacturer() + "|" + device->GetName();
309  result->setText(text.c_str());
310  return result;
311 }
312 
314 {
315  for (std::vector<mitk::USProbe::Pointer>::iterator it = m_ConfigProbes.begin(); it != m_ConfigProbes.end(); it++)
316  {
317  std::string probeName = (*it)->GetName();
318  m_Controls->m_Probes->addItem(QString::fromUtf8(probeName.data(), probeName.size()));
319  }
320  OnProbeChanged(m_Controls->m_Probes->currentText());
321 
322  //Toggle functionality of Btn_Done
323  m_Controls->m_BtnDone->setText("Apply Changes");
324  connect(m_Controls->m_BtnDone, SIGNAL(clicked()), this, SLOT(OnClickedFinishedEditing()));
325 
326  //Fill Metadata with Information provided by the Device selected to edit
327  m_Controls->m_Manufacturer->setText(m_TargetDevice->GetManufacturer().c_str());
328  m_Controls->m_Model->setText(m_TargetDevice->GetName().c_str());
329  m_Controls->m_Comment->setText(m_TargetDevice->GetComment().c_str());
330 }
331 
333 {
334  if (!m_Controls->m_Probes->currentText().isEmpty())
335  {
336  QString depths = m_Controls->m_AddDepths->text();
337  if( depths.isEmpty() )
338  return;
339 
340  std::string probename = m_Controls->m_Probes->currentText().toStdString();
341  mitk::USProbe::Pointer currentProbe = this->CheckIfProbeExistsAlready(probename);
342 
343  QStringList singleDepths = depths.split(',');
344  for (int i = 0; i < singleDepths.size(); i++)
345  {
346  currentProbe->SetDepth(singleDepths.at(i).toInt());
347  }
348  m_Controls->m_AddDepths->clear();
349  m_Controls->m_Depths->setEnabled(true);
350  m_Controls->m_BtnRemoveDepth->setEnabled(true);
351  OnProbeChanged(m_Controls->m_Probes->currentText());
352  }
353 }
354 
356 {
357  if (!m_Controls->m_Probes->currentText().isEmpty() && !m_Controls->m_Depths->currentText().isEmpty())
358  {
359  std::string probename = m_Controls->m_Probes->currentText().toStdString();
360  int indexOfDepthToRemove = m_Controls->m_Depths->currentIndex();
361  mitk::USProbe::Pointer currentProbe = this->CheckIfProbeExistsAlready(probename);
362  currentProbe->RemoveDepth(m_Controls->m_Depths->currentText().toInt());
363  m_Controls->m_Depths->removeItem(indexOfDepthToRemove);
364 
365  if (m_Controls->m_Depths->count() == 0)
366  {
367  m_Controls->m_Depths->setEnabled(false);
368  m_Controls->m_BtnRemoveDepth->setEnabled(false);
369 
370  this->EnableDisableSpacingAndCropping(false);
371  }
372  }
373 }
374 
376 {
377  if (!m_Controls->m_Probes->currentText().isEmpty())
378  {
379  std::string probename = m_Controls->m_Probes->currentText().toStdString();
380  int indexOfProbeToRemove = m_Controls->m_Probes->currentIndex();
381  m_ConfigProbes.erase(m_ConfigProbes.begin() + indexOfProbeToRemove);
382  m_Controls->m_Probes->removeItem(indexOfProbeToRemove);
383  if( m_Controls->m_Probes->count() == 0 )
384  {
385  m_Controls->m_Probes->setEnabled(false);
386  m_Controls->m_BtnRemoveProbe->setEnabled(false);
387  m_Controls->m_BtnAddDepths->setEnabled(false);
388  m_Controls->m_AddDepths->setEnabled(false);
389  m_Controls->m_Depths->setEnabled(false);
390  m_Controls->m_BtnRemoveDepth->setEnabled(false);
391 
392  this->EnableDisableSpacingAndCropping(false);
393  }
394  }
395 }
396 
397 void QmitkUSNewVideoDeviceWidget::OnProbeChanged(const QString & probename)
398 {
399  if (!probename.isEmpty())
400  {
401  std::string name = probename.toStdString();
402  mitk::USProbe::Pointer probe = this->CheckIfProbeExistsAlready(name);
403  if( probe.IsNotNull() )
404  {
405  std::map<int, mitk::Vector3D> depths = probe->GetDepthsAndSpacing();
406  m_Controls->m_Depths->clear();
407  for (std::map<int, mitk::Vector3D>::iterator it = depths.begin(); it != depths.end(); it++)
408  {
409  m_Controls->m_Depths->addItem(QString::number(it->first));
410  }
411 
412  this->OnDepthChanged(m_Controls->m_Depths->currentText().toInt(), probe);
413  }
414  }
415  else
416  {
417  m_Controls->m_Depths->clear();
418  m_Controls->m_Depths->setEnabled(false);
419  m_Controls->m_BtnRemoveDepth->setEnabled(false);
420  }
421 }
422 
423 void QmitkUSNewVideoDeviceWidget::OnDepthChanged(int depth, mitk::USProbe::Pointer probe)
424 {
425  if (m_Controls->m_Depths->count() == 0)
426  {
427  m_Controls->m_Depths->setEnabled(false);
428  m_Controls->m_BtnRemoveDepth->setEnabled(false);
429 
430  this->EnableDisableSpacingAndCropping(false);
431  return;
432  }
433 
434  if (probe.IsNotNull())
435  {
436  mitk::Vector3D spacing = probe->GetSpacingForGivenDepth(depth);
437  m_Controls->m_XSpacingSpinBox->setValue(spacing[0]);
438  m_Controls->m_YSpacingSpinBox->setValue(spacing[1]);
439 
440  mitk::USProbe::USProbeCropping cropping = probe->GetProbeCropping();
441  m_Controls->m_CroppingTopSpinBox->setValue(cropping.top);
442  m_Controls->m_CroppingRightSpinBox->setValue(cropping.right);
443  m_Controls->m_CroppingBottomSpinBox->setValue(cropping.bottom);
444  m_Controls->m_CroppingLeftSpinBox->setValue(cropping.left);
445 
447 
448  m_Controls->m_Depths->setEnabled(true);
449  m_Controls->m_BtnRemoveDepth->setEnabled(true);
450  m_Controls->m_AddDepths->setEnabled(true);
451  m_Controls->m_BtnAddDepths->setEnabled(true);
452  m_Controls->m_Probes->setEnabled(true);
453  m_Controls->m_BtnRemoveProbe->setEnabled(true);
454  }
455 }
456 
458 {
459  MITK_INFO << "OnDepthChanged(int, mitk::USProbe)";
460  if( depth.isEmpty() )
461  {
462  this->EnableDisableSpacingAndCropping(false);
463  return;
464  }
465  QString probeName = m_Controls->m_Probes->currentText();
466 
467  this->OnDepthChanged(depth.toInt(), this->CheckIfProbeExistsAlready(probeName.toStdString()) );
468 }
469 
471 {
472  QString fileName = QFileDialog::getSaveFileName(nullptr, "Save Configuration ...", "", "XML files (*.xml)");
473  if( fileName.isNull() )
474  {
475  return;
476  } // user pressed cancel
477 
478  mitk::USDeviceWriterXML deviceWriter;
479  deviceWriter.SetFilename(fileName.toStdString());
480 
483 
484  if (!deviceWriter.WriteUltrasoundDeviceConfiguration(config))
485  {
486  QMessageBox msgBox;
487  msgBox.setText("Error when writing the configuration to the selected file. Could not write device information.");
488  msgBox.exec();
489  return;
490  }
491 
492 }
493 
495 {
496  QString fileName = QFileDialog::getOpenFileName(this, "Open ultrasound device configuration ...");
497  if (fileName.isNull())
498  {
499  return;
500  } // user pressed cancel
501 
502  mitk::USDeviceReaderXML deviceReader;
503  deviceReader.SetFilename(fileName.toStdString());
504  if (!deviceReader.ReadUltrasoundDeviceConfiguration())
505  {
506  QMessageBox msgBox;
507  msgBox.setText("Error when parsing the selected file. Could not load stored device information.");
508  msgBox.exec();
509  return;
510  }
512 
513  if( config.fileversion == 1.0 )
514  {
515  if (config.deviceType.compare("video") == 0)
516  {
517  //Fill info in metadata groupbox:
518  m_Controls->m_DeviceName->setText(QString::fromStdString(config.deviceName));
519  m_Controls->m_Manufacturer->setText(QString::fromStdString(config.manufacturer));
520  m_Controls->m_Model->setText(QString::fromStdString(config.model));
521  m_Controls->m_Comment->setText(QString::fromStdString(config.comment));
522 
523  //Fill info about video source:
524  m_Controls->m_DeviceSelector->setValue(config.sourceID);
525  m_Controls->m_FilePathSelector->setText(QString::fromStdString(config.filepathVideoSource));
526 
527  //Fill video options:
528  m_Controls->m_CheckGreyscale->setChecked(config.useGreyscale);
529 
530  //Fill override options:
531  m_Controls->m_CheckResolutionOverride->setChecked(config.useResolutionOverride);
532  m_Controls->m_ResolutionWidth->setValue(config.resolutionWidth);
533  m_Controls->m_ResolutionHeight->setValue(config.resolutionHeight);
534 
535  //Fill information about probes:
536  m_ConfigProbes.clear();
537  m_ConfigProbes = config.probes;
538 
539  m_Controls->m_Probes->clear();
540  m_Controls->m_ProbeNameLineEdit->clear();
541  m_Controls->m_AddDepths->clear();
542  m_Controls->m_Depths->clear();
543 
544  for( size_t index = 0; index < m_ConfigProbes.size(); ++index)
545  {
546  m_Controls->m_Probes->addItem(QString::fromStdString(config.probes.at(index)->GetName()));
547  }
548  this->OnProbeChanged(m_Controls->m_Probes->currentText());
549 
550  }
551  else if (config.deviceType.compare("oigtl") == 0)
552  {
553  //Fill info in metadata groupbox:
554  m_Controls->m_DeviceName->setText(QString::fromStdString(config.deviceName));
555  m_Controls->m_Manufacturer->setText(QString::fromStdString(config.manufacturer));
556  m_Controls->m_Model->setText(QString::fromStdString(config.model));
557  m_Controls->m_Comment->setText(QString::fromStdString(config.comment));
558 
559  //Fill info about OpenIGTLink video source:
560  if (config.server)
561  {
562  m_Controls->m_RadioOIGTLServerSource->setChecked(true);
563  m_Controls->m_OIGTLServerHost->setText(QString::fromStdString(config.host));
564  m_Controls->m_OIGTLServerPort->setValue(config.port);
565  }
566  else
567  {
568  m_Controls->m_RadioOIGTLClientSource->setChecked(true);
569  m_Controls->m_OIGTLClientHost->setText(QString::fromStdString(config.host));
570  m_Controls->m_OIGTLClientPort->setValue(config.port);
571  }
572  this->OnDeviceTypeSelection();
573 
574  //Fill video options:
575  m_Controls->m_CheckGreyscale->setChecked(config.useGreyscale);
576 
577  //Fill override options:
578  m_Controls->m_CheckResolutionOverride->setChecked(config.useResolutionOverride);
579  m_Controls->m_ResolutionWidth->setValue(config.resolutionWidth);
580  m_Controls->m_ResolutionHeight->setValue(config.resolutionHeight);
581 
582  //Fill information about probes:
583  m_ConfigProbes.clear();
584  m_ConfigProbes = config.probes;
585 
586  m_Controls->m_Probes->clear();
587  m_Controls->m_ProbeNameLineEdit->clear();
588  m_Controls->m_AddDepths->clear();
589  m_Controls->m_Depths->clear();
590 
591  for (size_t index = 0; index < m_ConfigProbes.size(); ++index)
592  {
593  m_Controls->m_Probes->addItem(QString::fromStdString(config.probes.at(index)->GetName()));
594  }
595  this->OnProbeChanged(m_Controls->m_Probes->currentText());
596  }
597  else
598  {
599  MITK_WARN << "Unknown device type detected. The device type must be of type |video|";
600  }
601  }
602  else
603  {
604  MITK_WARN << "Unknown fileversion. Only fileversion 1.0 is known to the system.";
605  }
606 }
607 
609 {
610  QString probeName = m_Controls->m_ProbeNameLineEdit->text();
611  probeName = probeName.trimmed();
612  if (probeName.isEmpty())
613  {
614  m_Controls->m_ProbeNameLineEdit->clear();
615  return;
616  }
617 
618  if( this->CheckIfProbeExistsAlready(probeName.toStdString() ) != nullptr )
619  {
620  QMessageBox msgBox;
621  msgBox.setText("Probe name already exists. Please choose another name for the probe.");
622  msgBox.exec();
623  m_Controls->m_ProbeNameLineEdit->clear();
624  }
625  else
626  {
627  mitk::USProbe::Pointer newProbe = mitk::USProbe::New(probeName.toStdString());
628  m_ConfigProbes.push_back(newProbe);
629  m_Controls->m_Probes->addItem(QString::fromStdString(probeName.toStdString()));
630 
631  m_Controls->m_Probes->setEnabled(true);
632  m_Controls->m_BtnRemoveProbe->setEnabled(true);
633  m_Controls->m_BtnAddDepths->setEnabled(true);
634  m_Controls->m_AddDepths->setEnabled(true);
635  m_Controls->m_ProbeNameLineEdit->clear();
636  }
637 }
638 
640 {
641  MITK_INFO << "Changing x-spacing to: " << value;
642  QString probeName = m_Controls->m_Probes->currentText();
643  int depth = m_Controls->m_Depths->currentText().toInt();
644 
645  mitk::USProbe::Pointer probe = this->CheckIfProbeExistsAlready(probeName.toStdString());
646  if (probe.IsNull())
647  {
648  QMessageBox msgBox;
649  msgBox.setText("An error occurred when changing the spacing. \
650  The specified probe does not exist. \
651  Please restart the configuration process.");
652  msgBox.exec();
653  return;
654  }
655 
656  mitk::Vector3D spacing = probe->GetSpacingForGivenDepth(depth);
657  spacing[0] = value;
658  probe->SetSpacingForGivenDepth(depth, spacing);
659 }
660 
662 {
663  MITK_INFO << "Changing y-spacing to: " << value;
664  QString probeName = m_Controls->m_Probes->currentText();
665  int depth = m_Controls->m_Depths->currentText().toInt();
666 
667  mitk::USProbe::Pointer probe = this->CheckIfProbeExistsAlready(probeName.toStdString());
668  if (probe.IsNull())
669  {
670  QMessageBox msgBox;
671  msgBox.setText("An error occurred when changing the spacing. \
672  The specified probe does not exist. \
673  Please restart the configuration process.");
674  msgBox.exec();
675  return;
676  }
677 
678  mitk::Vector3D spacing = probe->GetSpacingForGivenDepth(depth);
679  spacing[1] = value;
680  probe->SetSpacingForGivenDepth(depth, spacing);
681 }
682 
684 {
685  MITK_INFO << "Changing cropping top to: " << value;
686  QString probeName = m_Controls->m_Probes->currentText();
687 
688  mitk::USProbe::Pointer probe = this->CheckIfProbeExistsAlready(probeName.toStdString());
689  if (probe.IsNull())
690  {
691  QMessageBox msgBox;
692  msgBox.setText("An error occurred when changing the probe cropping. \
693  The specified probe does not exist. \
694  Please restart the configuration process.");
695  msgBox.exec();
696  return;
697  }
698 
699  mitk::USProbe::USProbeCropping cropping = probe->GetProbeCropping();
700  probe->SetProbeCropping(value, cropping.bottom, cropping.left, cropping.right);
701 }
702 
704 {
705  MITK_INFO << "Changing cropping right to: " << value;
706  QString probeName = m_Controls->m_Probes->currentText();
707 
708  mitk::USProbe::Pointer probe = this->CheckIfProbeExistsAlready(probeName.toStdString());
709  if (probe.IsNull())
710  {
711  QMessageBox msgBox;
712  msgBox.setText("An error occurred when changing the probe cropping. \
713  The specified probe does not exist. \
714  Please restart the configuration process.");
715  msgBox.exec();
716  return;
717  }
718 
719  mitk::USProbe::USProbeCropping cropping = probe->GetProbeCropping();
720  probe->SetProbeCropping(cropping.top, cropping.bottom, cropping.left, value);
721 }
722 
724 {
725  MITK_INFO << "Changing cropping bottom to: " << value;
726  QString probeName = m_Controls->m_Probes->currentText();
727 
728  mitk::USProbe::Pointer probe = this->CheckIfProbeExistsAlready(probeName.toStdString());
729  if (probe.IsNull())
730  {
731  QMessageBox msgBox;
732  msgBox.setText("An error occurred when changing the probe cropping. \
733  The specified probe does not exist. \
734  Please restart the configuration process.");
735  msgBox.exec();
736  return;
737  }
738 
739  mitk::USProbe::USProbeCropping cropping = probe->GetProbeCropping();
740  probe->SetProbeCropping(cropping.top, value, cropping.left, cropping.right);
741 }
742 
744 {
745  MITK_INFO << "Changing cropping left to: " << value;
746  QString probeName = m_Controls->m_Probes->currentText();
747 
748  mitk::USProbe::Pointer probe = this->CheckIfProbeExistsAlready(probeName.toStdString());
749  if (probe.IsNull())
750  {
751  QMessageBox msgBox;
752  msgBox.setText("An error occurred when changing the probe cropping. \
753  The specified probe does not exist. \
754  Please restart the configuration process.");
755  msgBox.exec();
756  return;
757  }
758 
759  mitk::USProbe::USProbeCropping cropping = probe->GetProbeCropping();
760  probe->SetProbeCropping(cropping.top, cropping.bottom, value, cropping.right);
761 }
762 
764 {
765  disconnect(m_Controls->m_BtnDone, SIGNAL(clicked()), this, SLOT(OnClickedDone()));
766  m_Controls->m_Probes->clear();
767  m_Controls->m_Depths->clear();
768  m_Controls->m_AddDepths->clear();
769  m_Controls->m_ProbeNameLineEdit->clear();
770  m_ConfigProbes.clear();
771 }
772 
774 {
775  disconnect(m_Controls->m_BtnDone, SIGNAL(clicked()), this, SLOT(OnClickedFinishedEditing()));
776  m_Controls->m_Probes->clear();
777  m_Controls->m_Depths->clear();
778  m_Controls->m_AddDepths->clear();
779  m_ConfigProbes.clear();
780 }
781 
783 {
784  device->DeleteAllProbes();
785  for( std::vector<mitk::USProbe::Pointer>::iterator it = m_ConfigProbes.begin();
786  it != m_ConfigProbes.end(); it++)
787  {
788  if ((*it)->IsDepthAndSpacingEmpty())
789  {
790  (*it)->SetDepth(0);
791  }
792  device->AddNewProbe((*it));
793  }
794 }
795 
796 mitk::USProbe::Pointer QmitkUSNewVideoDeviceWidget::CheckIfProbeExistsAlready(const std::string &probeName)
797 {
798  for( std::vector<mitk::USProbe::Pointer>::iterator it = m_ConfigProbes.begin();
799  it != m_ConfigProbes.end(); it++ )
800  {
801  if( probeName.compare((*it)->GetName()) == 0)
802  return (*it);
803  }
804  return nullptr; //no matching probe was found so nullptr is returned
805 }
806 
808 {
809  config.fileversion = 1.0;
810  if (m_Controls->m_RadioDeviceSource->isChecked() || m_Controls->m_RadioFileSource->isChecked())
811  {
812  //Fill info about video source:
813  config.deviceType = "video";
814  config.sourceID = m_Controls->m_DeviceSelector->value();
815  config.filepathVideoSource = m_Controls->m_FilePathSelector->text().toStdString();
816  }
817  else
818  {
819  config.deviceType = "oigtl";
820  if (m_Controls->m_RadioOIGTLServerSource->isChecked())
821  {
822  config.server = true;
823  config.host = m_Controls->m_OIGTLServerHost->text().toStdString();
824  config.port = m_Controls->m_OIGTLServerPort->value();
825  }
826  else
827  {
828  config.server = false;
829  config.host = m_Controls->m_OIGTLClientHost->text().toStdString();
830  config.port = m_Controls->m_OIGTLClientPort->value();
831  }
832  }
833 
834  //Fill info in metadata groupbox:
835  config.deviceName = m_Controls->m_DeviceName->text().toStdString();
836  config.manufacturer = m_Controls->m_Manufacturer->text().toStdString();
837  config.model = m_Controls->m_Model->text().toStdString();
838  config.comment = m_Controls->m_Comment->text().toStdString();
839 
840  //Fill video options:
841  config.useGreyscale = m_Controls->m_CheckGreyscale->isChecked();
842 
843  //Fill override options:
844  config.useResolutionOverride = m_Controls->m_CheckResolutionOverride->isChecked();
845  config.resolutionWidth = m_Controls->m_ResolutionWidth->value();
846  config.resolutionHeight = m_Controls->m_ResolutionHeight->value();
847 
848  //Fill information about probes:
849  config.probes = m_ConfigProbes;
850 }
851 
853 {
854  m_Controls->m_XSpacingSpinBox->setEnabled(enable);
855  m_Controls->m_YSpacingSpinBox->setEnabled(enable);
856  m_Controls->m_XSpacingLabel->setEnabled(enable);
857  m_Controls->m_YSpacingLabel->setEnabled(enable);
858 
859  m_Controls->m_CroppingTopSpinBox->setEnabled(enable);
860  m_Controls->m_CroppingRightSpinBox->setEnabled(enable);
861  m_Controls->m_CroppingBottomSpinBox->setEnabled(enable);
862  m_Controls->m_CroppingLeftSpinBox->setEnabled(enable);
863  m_Controls->m_CroppingTopLabel->setEnabled(enable);
864  m_Controls->m_CroppingBottomLabel->setEnabled(enable);
865  m_Controls->m_CroppingLeftLabel->setEnabled(enable);
866  m_Controls->m_CroppingRightLabel->setEnabled(enable);
867 }
std::vector< mitk::USProbe::Pointer > m_ConfigProbes
The config probes are used to have a possibility to configure ultrasound probes without having an exi...
#define MITK_INFO
Definition: mitkLogMacros.h:18
QListWidgetItem * ConstructItemFromDevice(mitk::USDevice::Pointer device)
USDeviceConfigData & GetUSDeviceConfigData()
static Pointer New()
Method for creation through the object factory.
This class can be pointed to a video file or a videodevice and delivers USImages. ...
void EnableDisableSpacingAndCropping(bool enable)
Enables or disables the GUI elements of the spacing and cropping options.
std::vector< mitk::USProbe::Pointer > probes
void CollectUltrasoundDeviceConfigInformation(mitk::USDeviceReaderXML::USDeviceConfigData &config)
virtual void CreateQtPartControl(QWidget *parent)
#define MITK_WARN
Definition: mitkLogMacros.h:19
#define mitkThrow()
mitk::USProbe::Pointer CheckIfProbeExistsAlready(const std::string &probe)
void OnDepthChanged(int depth, mitk::USProbe::Pointer probe)
void SetFilename(std::string filename)
Sets the filename of the ultrasound device configuration file which should be created.
void OnProbeChanged(const QString &probename)
void SetFilename(std::string filename)
static Pointer New()
bool WriteUltrasoundDeviceConfiguration(mitk::USDeviceReaderXML::USDeviceConfigData &config)
Writes the configuration settings of an ultrasound device to a xml-file.
void SetColorOutput(bool isColor)
Sets the output image to rgb or grayscale. Output is color by default and can be set to color by pass...
QmitkUSNewVideoDeviceWidget(QWidget *p=nullptr, Qt::WindowFlags f1=nullptr)
Ui::QmitkUSNewVideoDeviceWidgetControls * m_Controls
member holding the UI elements of this widget
Struct to define a probe specific ultrasound image cropping.
Definition: mitkUSProbe.h:41
mitk::USDevice::Pointer m_TargetDevice
This is the device to edit. It is either the device transmitted in the "EditDevice" signal...
void AddProbesToDevice(mitk::USDevice::Pointer device)
void EditDevice(mitk::USDevice::Pointer device)