Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 #include "ui_QmitkUSControlsCustomVideoDeviceWidget.h"
19 #include <QMessageBox>
20 
21 #include <mitkException.h>
22 
25 {
26  m_Cropping.left = 0;
27  m_Cropping.top = 0;
28  m_Cropping.right = 0;
29  m_Cropping.bottom = 0;
30 }
31 
33 {
34  delete ui;
35 }
36 
38 {
40 }
41 
43 {
45  clonedWidget->SetDevice(this->GetDevice());
46  return clonedWidget;
47 }
48 
50 {
51  m_ControlInterface = dynamic_cast<mitk::USVideoDeviceCustomControls*>
52  (this->GetDevice()->GetControlInterfaceCustom().GetPointer());
53 
54  if (m_ControlInterface.IsNotNull())
55  {
56  mitk::USImageVideoSource::USImageCropping cropping = m_ControlInterface->GetCropArea();
57  ui->crop_left->setValue(cropping.left);
58  ui->crop_right->setValue(cropping.right);
59  ui->crop_bot->setValue(cropping.bottom);
60  ui->crop_top->setValue(cropping.top);
61 
62  //get all probes and put their names into a combobox
63  std::vector<mitk::USProbe::Pointer> probes = m_ControlInterface->GetProbes();
64  for (std::vector<mitk::USProbe::Pointer>::iterator it = probes.begin(); it != probes.end(); it++)
65  {
66  std::string probeName = (*it)->GetName();
67  ui->m_ProbeIdentifier->addItem(QString::fromUtf8(probeName.data(), probeName.size()));
68  }
69  connect(ui->m_UsDepth, SIGNAL(currentTextChanged(const QString &)), this, SLOT(OnDepthChanged()));
70  connect(ui->m_ProbeIdentifier, SIGNAL(currentTextChanged(const QString &)), this, SLOT(OnProbeChanged()));
71 
72  }
73  else
74  {
75  MITK_WARN("QmitkUSAbstractCustomWidget")("QmitkUSControlsCustomVideoDeviceWidget")
76  << "Did not get a custom video device control interface.";
77  }
78 
79  ui->crop_left->setEnabled(m_ControlInterface.IsNotNull());
80  ui->crop_right->setEnabled(m_ControlInterface.IsNotNull());
81  ui->crop_bot->setEnabled(m_ControlInterface.IsNotNull());
82  ui->crop_top->setEnabled(m_ControlInterface.IsNotNull());
83 }
84 
86 {
87  ui->setupUi(this);
88 
89  connect(ui->crop_left, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged()));
90  connect(ui->crop_right, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged()));
91  connect(ui->crop_top, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged()));
92  connect(ui->crop_bot, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged()));
93 
94 }
95 
96 void QmitkUSControlsCustomVideoDeviceWidget::OnCropAreaChanged()
97 {
98  if (m_ControlInterface.IsNull()) { return; }
99 
101  cropping.left = ui->crop_left->value();
102  cropping.top = ui->crop_top->value();
103  cropping.right = ui->crop_right->value();
104  cropping.bottom = ui->crop_bot->value();
105 
106  try
107  {
108  m_ControlInterface->SetCropArea(cropping);
109  m_Cropping = cropping;
110  }
111  catch (mitk::Exception e)
112  {
113  m_ControlInterface->SetCropArea(m_Cropping); // reset to last valid crop
114 
115  //reset values
116  BlockSignalAndSetValue(ui->crop_left, m_Cropping.left);
117  BlockSignalAndSetValue(ui->crop_right, m_Cropping.right);
118  BlockSignalAndSetValue(ui->crop_top, m_Cropping.top);
120 
121  // inform user
122  QMessageBox msgBox;
123  msgBox.setInformativeText("The crop area you specified is invalid.\nPlease make sure that no more pixels are cropped than are available.");
124  msgBox.setStandardButtons(QMessageBox::Ok);
125  msgBox.exec();
126  MITK_WARN << "User tried to crop beyond limits of the image";
127  }
128 }
129 
130 void QmitkUSControlsCustomVideoDeviceWidget::OnDepthChanged()
131 {
132  double depth = ui->m_UsDepth->currentText().toDouble();
133  m_ControlInterface->SetNewDepth(depth);
134 }
135 
136 void QmitkUSControlsCustomVideoDeviceWidget::OnProbeChanged()
137 {
138  std::string probename = ui->m_ProbeIdentifier->currentText().toStdString();
139  m_ControlInterface->SetNewProbeIdentifier(probename);
140  SetDepthsForProbe(probename);
141 }
142 
144 {
145  bool oldState = target->blockSignals(true);
146  target->setValue(value);
147  target->blockSignals(oldState);
148 }
149 
150 void QmitkUSControlsCustomVideoDeviceWidget::SetDepthsForProbe(std::string probename)
151 {
152  ui->m_UsDepth->clear();
153  std::vector<int> depths = m_ControlInterface->GetDepthsForProbe(probename);
154  for (std::vector<int>::iterator it = depths.begin(); it != depths.end(); it++)
155  {
156  ui->m_UsDepth->addItem(QString::number(*it));
157  }
158 }
Defines a region of interest by distances to the four image borders.
mitk::USImageVideoSource::USImageCropping m_Cropping
void SetDevice(mitk::USDevice::Pointer device)
mitk::USDevice::Pointer GetDevice() const
virtual 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:23
virtual QmitkUSAbstractCustomWidget * Clone(QWidget *parent=0) const override
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
Definition: mitkException.h:49
Abstract superclass for all custom control widgets of mitk::USDevice classes.
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()