Medical Imaging Interaction Toolkit  2018.4.99-f51274ea
Medical Imaging Interaction Toolkit
QmitkUSControlsCustomVideoDeviceWidget.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 
14 #include "ui_QmitkUSControlsCustomVideoDeviceWidget.h"
15 #include <QMessageBox>
16 
17 #include <mitkException.h>
18 
19 
22 {
23 }
24 
25 
27  : QmitkUSAbstractCustomWidget(parent), ui(new Ui::QmitkUSControlsCustomVideoDeviceWidget)
28 {
29  m_Cropping.left = 0;
30  m_Cropping.top = 0;
31  m_Cropping.right = 0;
32  m_Cropping.bottom = 0;
33 }
34 
36 {
37  delete ui;
38 }
39 
41 {
43 }
44 
46 {
48  clonedWidget->SetDevice(this->GetDevice());
49  return clonedWidget;
50 }
51 
53 {
54  m_ControlInterface = dynamic_cast<mitk::USVideoDeviceCustomControls*>
55  (this->GetDevice()->GetControlInterfaceCustom().GetPointer());
56 
57  if (m_ControlInterface.IsNotNull())
58  {
59  //get all probes and put their names into a combobox
60  std::vector<mitk::USProbe::Pointer> probes = m_ControlInterface->GetProbes();
61  for (std::vector<mitk::USProbe::Pointer>::iterator it = probes.begin(); it != probes.end(); it++)
62  {
63  std::string probeName = (*it)->GetName();
64  ui->m_ProbeIdentifier->addItem(QString::fromUtf8(probeName.data(), probeName.size()));
65  }
66 
67  m_ControlInterface->SetDefaultProbeAsCurrentProbe();
68 
69  SetDepthsForProbe( ui->m_ProbeIdentifier->currentText().toStdString() );
70  m_ControlInterface->SetNewDepth( ui->m_UsDepth->currentText().toDouble() );
71 
72  connect(ui->m_UsDepth, SIGNAL(currentTextChanged(const QString &)), this, SLOT(OnDepthChanged()));
73  connect(ui->m_ProbeIdentifier, SIGNAL(currentTextChanged(const QString &)), this, SLOT(OnProbeChanged()));
74 
75  // Call GetCropArea after the current ultrasound probe was set as default probe:
76  mitk::USProbe::USProbeCropping cropping = m_ControlInterface->GetCropArea();
77  ui->crop_left->setValue(cropping.left);
78  ui->crop_right->setValue(cropping.right);
79  ui->crop_bot->setValue(cropping.bottom);
80  ui->crop_top->setValue(cropping.top);
81 
82  }
83  else
84  {
85  MITK_WARN("QmitkUSAbstractCustomWidget")("QmitkUSControlsCustomVideoDeviceWidget")
86  << "Did not get a custom video device control interface.";
87  }
88 
89  ui->crop_left->setEnabled(m_ControlInterface.IsNotNull());
90  ui->crop_right->setEnabled(m_ControlInterface.IsNotNull());
91  ui->crop_bot->setEnabled(m_ControlInterface.IsNotNull());
92  ui->crop_top->setEnabled(m_ControlInterface.IsNotNull());
93 }
94 
96 {
97  ui->setupUi(this);
98 
99  connect(ui->crop_left, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged()));
100  connect(ui->crop_right, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged()));
101  connect(ui->crop_top, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged()));
102  connect(ui->crop_bot, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged()));
103 
104 }
105 
106 void QmitkUSControlsCustomVideoDeviceWidget::OnCropAreaChanged()
107 {
108  if (m_ControlInterface.IsNull()) { return; }
109 
111  cropping.left = ui->crop_left->value();
112  cropping.top = ui->crop_top->value();
113  cropping.right = ui->crop_right->value();
114  cropping.bottom = ui->crop_bot->value();
115 
116  try
117  {
118  m_ControlInterface->SetCropArea(cropping);
119  m_ControlInterface->UpdateProbeCropping(cropping);
120  m_Cropping = cropping;
121  }
122  catch (mitk::Exception&)
123  {
124  m_ControlInterface->SetCropArea(m_Cropping); // reset to last valid crop
125  m_ControlInterface->UpdateProbeCropping(m_Cropping);
126 
127  //reset values
128  BlockSignalAndSetValue(ui->crop_left, m_Cropping.left);
129  BlockSignalAndSetValue(ui->crop_right, m_Cropping.right);
130  BlockSignalAndSetValue(ui->crop_top, m_Cropping.top);
132 
133  // inform user
134  QMessageBox msgBox;
135  msgBox.setInformativeText("The crop area you specified is invalid.\nPlease make sure that no more pixels are cropped than are available.");
136  msgBox.setStandardButtons(QMessageBox::Ok);
137  msgBox.exec();
138  MITK_WARN << "User tried to crop beyond limits of the image";
139  }
140 }
141 
142 void QmitkUSControlsCustomVideoDeviceWidget::OnDepthChanged()
143 {
144  double depth = ui->m_UsDepth->currentText().toDouble();
145  MITK_INFO << "OnDepthChanged() " << depth;
146  m_ControlInterface->SetNewDepth(depth);
147 }
148 
149 void QmitkUSControlsCustomVideoDeviceWidget::OnProbeChanged()
150 {
151  std::string probename = ui->m_ProbeIdentifier->currentText().toStdString();
152  m_ControlInterface->SetNewProbeIdentifier(probename);
153  SetDepthsForProbe(probename);
154 
155  mitk::USProbe::USProbeCropping cropping = m_ControlInterface->GetCropArea();
156  ui->crop_left->setValue(cropping.left);
157  ui->crop_right->setValue(cropping.right);
158  ui->crop_bot->setValue(cropping.bottom);
159  ui->crop_top->setValue(cropping.top);
160 }
161 
163 {
164  bool oldState = target->blockSignals(true);
165  target->setValue(value);
166  target->blockSignals(oldState);
167 }
168 
169 void QmitkUSControlsCustomVideoDeviceWidget::SetDepthsForProbe(std::string probename)
170 {
171  ui->m_UsDepth->clear();
172  std::vector<int> depths = m_ControlInterface->GetDepthsForProbe(probename);
173  for (std::vector<int>::iterator it = depths.begin(); it != depths.end(); it++)
174  {
175  ui->m_UsDepth->addItem(QString::number(*it));
176  }
177 }
#define MITK_INFO
Definition: mitkLogMacros.h:18
Defines a region of interest by distances to the four image borders.
mitk::USImageVideoSource::USImageCropping m_Cropping
void SetDevice(mitk::USDevice::Pointer device)
void Initialize() override
Method for initializing the Qt stuff of the widget (setupUI, connect). This method will be called in ...
#define MITK_WARN
Definition: mitkLogMacros.h:19
An object of this class represents an exception of MITK. Please don&#39;t instantiate exceptions manually...
Definition: mitkException.h:45
QmitkUSAbstractCustomWidget * Clone(QWidget *parent=nullptr) const override
Abstract superclass for all custom control widgets of mitk::USDevice classes.
QmitkUSAbstractCustomWidget(QWidget *parent=nullptr)
Custom controls for mitk::USVideoDevice. Controls image cropping of the corresponding mitk::USImageVi...
Widget for custom controls of mitk::USVideoDevice. This class handles the itk::USVideoDeviceCustomCon...
static std::string GetDeviceClassStatic()
Struct to define a probe specific ultrasound image cropping.
Definition: mitkUSProbe.h:41
mitk::USDevice::Pointer GetDevice() const