Medical Imaging Interaction Toolkit  2018.4.99-87d68d9f
Medical Imaging Interaction Toolkit
QmitkUSControlsCustomDiPhASDeviceWidget.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_QmitkUSControlsCustomDiPhASDeviceWidget.h"
15 #include <QMessageBox>
16 
17 
18 #include <mitkException.h>
19 
22 {
23 }
24 
26  : QmitkUSAbstractCustomWidget(parent), ui(new Ui::QmitkUSControlsCustomDiPhASDeviceWidget)
27 {
28 }
29 
31 {
32  delete ui;
33 }
34 
36 {
37  return "org.mitk.modules.us.USDiPhASDevice";
38 }
39 
41 {
43  clonedWidget->SetDevice(this->GetDevice());
44  return clonedWidget;
45 }
46 
48 {
49  m_ControlInterface = dynamic_cast<mitk::USDiPhASDeviceCustomControls*>
50  (this->GetDevice()->GetControlInterfaceCustom().GetPointer());
51 
52  if ( m_ControlInterface.IsNotNull() )
53  {
54  m_ControlInterface->passGUIOut([this](QString str)->void{
55  if (this->ui) {
56  this->ui->CurrentState->setText(str);
57  } });
58  }
59  else
60  {
61  MITK_WARN("QmitkUSAbstractCustomWidget")("QmitkUSControlsCustomDiPhASDeviceWidget")
62  << "Did not get a custom device control interface.";
63  }
64 
65  //now pass the default values
66 
67  m_OldReconstructionLines = 0;
68 
69  m_ControlInterface->SetSilentUpdate(true); // don't update the scanmode everytime
70 
71  OnTransmitPhaseLengthChanged();
72  OnExcitationFrequencyChanged();
73  OnTransmitEventsChanged();
74  OnVoltageChanged();
75  OnScanDepthChanged(); // HERE
76  OnAveragingCountChanged();
77  OnTGCMinChanged();
78  OnTGCMaxChanged();
79  OnDataTypeChanged();
80  OnPitchChanged();
81  OnReconstructedSamplesChanged();
82  OnReconstructedLinesChanged();
83  OnSpeedOfSoundChanged();
84  OnBandpassEnabledChanged();
85  OnLowCutChanged();
86  OnHighCutChanged();
87  OnUseBModeFilterChanged(); // HERE
88  OnVerticalSpacingChanged();
89  OnScatteringCoefficientChanged();
90  OnCompensateScatteringChanged();
91  OnChangedSavingSettings();
92  OnCompensateEnergyChanged();
93 
94  m_ControlInterface->SetSilentUpdate(false); // on the last update pass the scanmode and geometry!
95 
96  OnModeChanged(); // HERE
97 }
98 
100 {
101  ui->setupUi(this);
102 
103  connect(ui->CompensateEnergy, SIGNAL(stateChanged(int)), this, SLOT(OnCompensateEnergyChanged()));
104  connect(ui->UseBModeFilter, SIGNAL(stateChanged(int)), this, SLOT(OnUseBModeFilterChanged()));
105  connect(ui->StartStopRecord, SIGNAL(clicked()), this, SLOT(OnRecordChanged()));
106  connect(ui->ScatteringCoefficient, SIGNAL(valueChanged(int)), this, SLOT(OnScatteringCoefficientChanged()));
107  connect(ui->CompensateScattering, SIGNAL(stateChanged(int)), this, SLOT(OnCompensateScatteringChanged()));
108  connect(ui->VerticalSpacing, SIGNAL(valueChanged(double)), this, SLOT(OnVerticalSpacingChanged()));
109  connect(ui->SaveBeamformed, SIGNAL(stateChanged(int)), this, SLOT(OnChangedSavingSettings()));
110  connect(ui->SaveRaw, SIGNAL(stateChanged(int)), this, SLOT(OnChangedSavingSettings()));
111  //transmit
112  connect(ui->TransmitPhaseLength, SIGNAL(valueChanged(double)), this, SLOT(OnTransmitPhaseLengthChanged()));
113  connect(ui->ExcitationFrequency, SIGNAL(valueChanged(double)), this, SLOT(OnExcitationFrequencyChanged()));
114  connect(ui->TransmitEvents, SIGNAL(valueChanged(int)), this, SLOT(OnTransmitEventsChanged()));
115  connect(ui->Voltage, SIGNAL(valueChanged(int)), this, SLOT(OnVoltageChanged()));
116  connect(ui->Mode, SIGNAL(currentTextChanged(QString)), this, SLOT(OnModeChanged()));
117 
118  //Receive
119  connect(ui->ScanDepth, SIGNAL(valueChanged(double)), this, SLOT(OnScanDepthChanged()));
120  connect(ui->AveragingCount, SIGNAL(valueChanged(int)), this, SLOT(OnAveragingCountChanged()));
121  connect(ui->TimeGainCompensationMinSlider, SIGNAL(valueChanged(int)), this, SLOT(OnTGCMinChanged()));
122  connect(ui->TimeGainCompensationMaxSlider, SIGNAL(valueChanged(int)), this, SLOT(OnTGCMaxChanged()));
123  connect(ui->DataType, SIGNAL(currentTextChanged(QString)), this, SLOT(OnDataTypeChanged()));
124 
125  //Beamforming
126  connect(ui->PitchOfTransducer, SIGNAL(valueChanged(double)), this, SLOT(OnPitchChanged()));
127  connect(ui->ReconstructedSamplesPerLine, SIGNAL(valueChanged(int)), this, SLOT(OnReconstructedSamplesChanged()));
128  connect(ui->ReconstructedLines, SIGNAL(valueChanged(int)), this, SLOT(OnReconstructedLinesChanged()));
129  connect(ui->SpeedOfSound, SIGNAL(valueChanged(int)), this, SLOT(OnSpeedOfSoundChanged()));
130 
131  //Bandpass
132  connect(ui->BandpassEnabled, SIGNAL(currentTextChanged(QString)), this, SLOT(OnBandpassEnabledChanged()));
133  connect(ui->LowCut, SIGNAL(valueChanged(double)), this, SLOT(OnLowCutChanged()));
134  connect(ui->HighCut, SIGNAL(valueChanged(double)), this, SLOT(OnHighCutChanged()));
135 }
136 
137 //slots
138 
139 void QmitkUSControlsCustomDiPhASDeviceWidget::OnCompensateEnergyChanged()
140 {
141  if (m_ControlInterface.IsNull()) { return; }
142  bool CompensateEnergy = ui->CompensateEnergy->isChecked();
143  m_ControlInterface->SetCompensateEnergy(CompensateEnergy);
144 }
145 
146 void QmitkUSControlsCustomDiPhASDeviceWidget::OnUseBModeFilterChanged()
147 {
148  if (m_ControlInterface.IsNull()) { return; }
149  bool UseBModeFilter = ui->UseBModeFilter->isChecked();
150  m_ControlInterface->SetUseBModeFilter(UseBModeFilter);
151 }
152 
153 void QmitkUSControlsCustomDiPhASDeviceWidget::OnRecordChanged()
154 {
155  if (m_ControlInterface.IsNull()) { return; }
156  if (ui->StartStopRecord->text() == "Start Recording")
157  {
158  ui->StartStopRecord->setText("Stop Recording");
159 
160  ui->UseBModeFilter->setEnabled(false);
161  ui->ScatteringCoefficient->setEnabled(false);
162  ui->CompensateScattering->setEnabled(false);
163  ui->VerticalSpacing->setEnabled(false);
164  ui->SaveBeamformed->setEnabled(false);
165  ui->SaveRaw->setEnabled(false);
166  ui->TransmitPhaseLength->setEnabled(false);
167  ui->ExcitationFrequency->setEnabled(false);
168  ui->TransmitEvents->setEnabled(false);
169  ui->Voltage->setEnabled(false);
170  ui->Mode->setEnabled(false);
171  ui->ScanDepth->setEnabled(false);
172  ui->AveragingCount->setEnabled(false);
173  ui->TimeGainCompensationMinSlider->setEnabled(false);
174  ui->TimeGainCompensationMaxSlider->setEnabled(false);
175  ui->DataType->setEnabled(false);
176  ui->PitchOfTransducer->setEnabled(false);
177  ui->ReconstructedSamplesPerLine->setEnabled(false);
178  ui->ReconstructedLines->setEnabled(false);
179  ui->SpeedOfSound->setEnabled(false);
180  ui->BandpassEnabled->setEnabled(false);
181  ui->LowCut->setEnabled(false);
182  ui->HighCut->setEnabled(false);
183  ui->CompensateEnergy->setEnabled(false);
184 
185  m_ControlInterface->SetRecord(true);
186  }
187  else
188  {
189  ui->StartStopRecord->setText("Start Recording");
190 
191  ui->UseBModeFilter->setEnabled(true);
192  ui->CompensateScattering->setEnabled(true);
193  if(ui->CompensateScattering->isChecked())
194  ui->ScatteringCoefficient->setEnabled(true);
195  ui->VerticalSpacing->setEnabled(true);
196  ui->SaveBeamformed->setEnabled(true);
197  ui->SaveRaw->setEnabled(true);
198  ui->TransmitPhaseLength->setEnabled(true);
199  ui->ExcitationFrequency->setEnabled(true);
200  ui->TransmitEvents->setEnabled(true);
201  ui->Voltage->setEnabled(true);
202  ui->Mode->setEnabled(true);
203  ui->ScanDepth->setEnabled(true);
204  ui->AveragingCount->setEnabled(true);
205  ui->TimeGainCompensationMinSlider->setEnabled(true);
206  ui->TimeGainCompensationMaxSlider->setEnabled(true);
207  ui->DataType->setEnabled(true);
208  ui->PitchOfTransducer->setEnabled(true);
209  ui->ReconstructedSamplesPerLine->setEnabled(true);
210  ui->ReconstructedLines->setEnabled(true);
211  ui->SpeedOfSound->setEnabled(true);
212  ui->BandpassEnabled->setEnabled(true);
213  ui->LowCut->setEnabled(true);
214  ui->HighCut->setEnabled(true);
215  ui->CompensateEnergy->setEnabled(true);
216 
217  m_ControlInterface->SetRecord(false);
218  }
219 }
220 
221 void QmitkUSControlsCustomDiPhASDeviceWidget::OnVerticalSpacingChanged()
222 {
223  if (m_ControlInterface.IsNull()) { return; }
224  m_ControlInterface->SetVerticalSpacing(ui->VerticalSpacing->value());
225 }
226 
227 void QmitkUSControlsCustomDiPhASDeviceWidget::OnScatteringCoefficientChanged()
228 {
229  if (m_ControlInterface.IsNull()) { return; }
230  m_ControlInterface->SetScatteringCoefficient(ui->ScatteringCoefficient->value());
231 }
232 
233 void QmitkUSControlsCustomDiPhASDeviceWidget::OnCompensateScatteringChanged()
234 {
235  if (m_ControlInterface.IsNull()) { return; }
236  if (ui->CompensateScattering->isChecked())
237  ui->ScatteringCoefficient->setEnabled(true);
238  else
239  ui->ScatteringCoefficient->setEnabled(false);
240 
241  m_ControlInterface->SetCompensateScattering(ui->CompensateScattering->isChecked());
242 }
243 
244 void QmitkUSControlsCustomDiPhASDeviceWidget::OnChangedSavingSettings()
245 {
246  if (m_ControlInterface.IsNull()) { return; }
247 
249 
250  settings.saveBeamformed = ui->SaveBeamformed->isChecked();
251  settings.saveRaw = ui->SaveRaw->isChecked();
252 
253  m_ControlInterface->SetSavingSettings(settings);
254 }
255 
256 //Transmit
257 void QmitkUSControlsCustomDiPhASDeviceWidget::OnTransmitPhaseLengthChanged()
258 {
259  if (m_ControlInterface.IsNull()) { return; }
260  m_ControlInterface->SetTransmitPhaseLength(ui->TransmitPhaseLength->value());
261 }
262 void QmitkUSControlsCustomDiPhASDeviceWidget::OnExcitationFrequencyChanged()
263 {
264  if (m_ControlInterface.IsNull()) { return; }
265  m_ControlInterface->SetExcitationFrequency(ui->ExcitationFrequency->value());
266 }
267 void QmitkUSControlsCustomDiPhASDeviceWidget::OnTransmitEventsChanged()
268 {
269  if (m_ControlInterface.IsNull()) { return; }
270 
271  m_ControlInterface->SetTransmitEvents(ui->TransmitEvents->value());
272 }
273 void QmitkUSControlsCustomDiPhASDeviceWidget::OnVoltageChanged()
274 {
275  if (m_ControlInterface.IsNull()) { return; }
276  m_ControlInterface->SetVoltage(ui->Voltage->value());
277 }
278 void QmitkUSControlsCustomDiPhASDeviceWidget::OnModeChanged()
279 {
280  if (m_ControlInterface.IsNull()) { return; }
281  QString Mode = ui->Mode->currentText();
282  bool silent = m_ControlInterface->GetSilentUpdate();
283  m_ControlInterface->SetSilentUpdate(true);
284 
285  if (Mode == "Ultrasound only") {
286  m_ControlInterface->SetMode(false);
287  ui->TransmitEvents->setValue(1);
288  }
289  else if (Mode == "Interleaved") {
290  m_ControlInterface->SetMode(true);
291  ui->TransmitEvents->setValue(1);
292  }
293  if (!silent) { m_ControlInterface->SetSilentUpdate(false); }
294  OnTransmitEventsChanged();
295 }
296 
297 //Receive
298 void QmitkUSControlsCustomDiPhASDeviceWidget::OnScanDepthChanged()
299 {
300  if (m_ControlInterface.IsNull()) { return; }
301  m_ControlInterface->SetScanDepth(ui->ScanDepth->value());
302 }
303 void QmitkUSControlsCustomDiPhASDeviceWidget::OnAveragingCountChanged()
304 {
305  if (m_ControlInterface.IsNull()) { return; }
306  m_ControlInterface->SetAveragingCount(ui->AveragingCount->value());
307 }
308 void QmitkUSControlsCustomDiPhASDeviceWidget::OnTGCMinChanged()
309 {
310  if (m_ControlInterface.IsNull()) { return; }
311 
312  int tgcMin = ui->TimeGainCompensationMinSlider->value();
313  int tgcMax = ui->TimeGainCompensationMaxSlider->value();
314  if (tgcMin > tgcMax) {
315  ui->TimeGainCompensationMinSlider->setValue(tgcMax);
316  MITK_INFO << "User tried to set tgcMin>tgcMax.";
317  }
318  QString text("TGC min = " + QString::fromStdString(std::to_string(ui->TimeGainCompensationMinSlider->value())));
319  ui->TimeGainCompensationMinLabel->setText(text);
320  m_ControlInterface->SetTGCMin(ui->TimeGainCompensationMinSlider->value());
321 }
322 void QmitkUSControlsCustomDiPhASDeviceWidget::OnTGCMaxChanged()
323 {
324  if (m_ControlInterface.IsNull()) { return; }
325 
326  int tgcMin = ui->TimeGainCompensationMinSlider->value();
327  int tgcMax = ui->TimeGainCompensationMaxSlider->value();
328  if (tgcMin > tgcMax) {
329  ui->TimeGainCompensationMaxSlider->setValue(tgcMin);
330  MITK_INFO << "User tried to set tgcMin>tgcMax.";
331  }
332  QString text("TGC max = "+QString::fromStdString(std::to_string(ui->TimeGainCompensationMaxSlider->value())));
333  ui->TimeGainCompensationMaxLabel->setText(text);
334  m_ControlInterface->SetTGCMax(ui->TimeGainCompensationMaxSlider->value());
335 }
336 
337 void QmitkUSControlsCustomDiPhASDeviceWidget::OnDataTypeChanged()
338 {
339  if (m_ControlInterface.IsNull()) { return; }
340  QString DataType = ui->DataType->currentText();
341  if (DataType == "Image Data") {
342  m_ControlInterface->SetDataType(mitk::USDiPhASDeviceCustomControls::DataType::Image_uChar);
343  }
344  else if (DataType == "Beamformed Data") {
345  m_ControlInterface->SetDataType(mitk::USDiPhASDeviceCustomControls::DataType::Beamformed_Short);
346  }
347 }
348 
349 //Beamforming
350 void QmitkUSControlsCustomDiPhASDeviceWidget::OnPitchChanged()
351 {
352  if (m_ControlInterface.IsNull()) { return; }
353  m_ControlInterface->SetPitch(ui->PitchOfTransducer->value());
354 }
355 void QmitkUSControlsCustomDiPhASDeviceWidget::OnReconstructedSamplesChanged()
356 {
357  if (m_ControlInterface.IsNull()) { return; }
358  m_ControlInterface->SetReconstructedSamples(ui->ReconstructedSamplesPerLine->value());
359 }
360 void QmitkUSControlsCustomDiPhASDeviceWidget::OnReconstructedLinesChanged()
361 {
362  if (m_ControlInterface.IsNull()) { return; }
363  if (m_OldReconstructionLines == 0)
364  m_OldReconstructionLines = ui->ReconstructedLines->value();
365 
366  m_ControlInterface->SetReconstructedLines(ui->ReconstructedLines->value());
367 
368  ui->PitchOfTransducer->setValue(ui->PitchOfTransducer->value()*((double)m_OldReconstructionLines / (double)ui->ReconstructedLines->value()));
369  m_OldReconstructionLines = ui->ReconstructedLines->value();
370 }
371 void QmitkUSControlsCustomDiPhASDeviceWidget::OnSpeedOfSoundChanged()
372 {
373  if (m_ControlInterface.IsNull()) { return; }
374 
375  m_ControlInterface->SetSpeedOfSound(ui->SpeedOfSound->value());
376 }
377 
378 //Bandpass
379 void QmitkUSControlsCustomDiPhASDeviceWidget::OnBandpassEnabledChanged()
380 {
381  if (m_ControlInterface.IsNull()) { return; }
382 
383  if (ui->BandpassEnabled->currentText() == "On") {
384  m_ControlInterface->SetBandpassEnabled(true);
385  }
386  else {
387  m_ControlInterface->SetBandpassEnabled(false);
388  }
389 }
390 void QmitkUSControlsCustomDiPhASDeviceWidget::OnLowCutChanged()
391 {
392  if (m_ControlInterface.IsNull()) { return; }
393 
394  unsigned int Low = ui->LowCut->value();
395  unsigned int High = ui->HighCut->value();
396  if (Low > High) {
397  ui->LowCut->setValue(High);
398  MITK_INFO << "User tried to set LowCut>HighCut.";
399  }
400 
401  m_ControlInterface->SetLowCut(ui->LowCut->value());
402 }
403 void QmitkUSControlsCustomDiPhASDeviceWidget::OnHighCutChanged()
404 {
405  if (m_ControlInterface.IsNull()) { return; }
406 
407  unsigned int Low = ui->LowCut->value();
408  unsigned int High = ui->HighCut->value();
409  if (Low > High) {
410  ui->HighCut->setValue(Low);
411  MITK_INFO << "User tried to set LowCut>HighCut.";
412  }
413 
414  m_ControlInterface->SetHighCut(ui->HighCut->value());
415 }
#define MITK_INFO
Definition: mitkLogMacros.h:18
QmitkUSAbstractCustomWidget * Clone(QWidget *parent=nullptr) const override
Widget for custom controls of mitk::USDiPhASDevice. This class handles the itk::USDiPhASDeviceCustomC...
Custom controls for mitk::USDiPhASDevice.
void SetDevice(mitk::USDevice::Pointer device)
#define MITK_WARN
Definition: mitkLogMacros.h:19
Abstract superclass for all custom control widgets of mitk::USDevice classes.
void Initialize() override
Method for initializing the Qt stuff of the widget (setupUI, connect). This method will be called in ...
QmitkUSAbstractCustomWidget(QWidget *parent=nullptr)
mitk::USDevice::Pointer GetDevice() const