MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
QmitkUSControlsCustomVideoDeviceWidget.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#include "ui_QmitkUSControlsCustomVideoDeviceWidget.h"
15#include <QMessageBox>
16
17#include <mitkException.h>
18
19
24
25
28{
29 m_Cropping.left = 0;
30 m_Cropping.top = 0;
31 m_Cropping.right = 0;
33}
34
39
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
106void 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);
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
142void QmitkUSControlsCustomVideoDeviceWidget::OnDepthChanged()
143{
144 double depth = ui->m_UsDepth->currentText().toDouble();
145 MITK_INFO << "OnDepthChanged() " << depth;
146 m_ControlInterface->SetNewDepth(depth);
147}
148
149void 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
169void 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}
Abstract superclass for all custom control widgets of mitk::USDevice classes.
void SetDevice(mitk::USDevice::Pointer device)
mitk::USDevice::Pointer GetDevice() const
Widget for custom controls of mitk::USVideoDevice. This class handles the itk::USVideoDeviceCustomCon...
QmitkUSAbstractCustomWidget * Clone(QWidget *parent=nullptr) const override
void Initialize() override
Method for initializing the Qt stuff of the widget (setupUI, connect). This method will be called in ...
mitk::USImageVideoSource::USImageCropping m_Cropping
Custom controls for mitk::USVideoDevice. Controls image cropping of the corresponding mitk::USImageVi...
static std::string GetDeviceClassStatic()
Defines a region of interest by distances to the four image borders.
Struct to define a probe specific ultrasound image cropping.
Definition mitkUSProbe.h:42