Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxSoundSpeedConversionWidget.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
13 
14 #include <QPushButton>
15 #include <QDoubleSpinBox>
16 #include <QVBoxLayout>
17 #include <QHBoxLayout>
18 #include <QLabel>
19 #include "cxLogger.h"
20 #include "cxTrackingService.h"
21 #include "cxProbe.h"
22 
23 namespace cx
24 {
25 
27  BaseWidget(parent, "sound_speed_converter_widget", "Sound Speed Converter"),
28  mScannerSoundSpeed(1540.0),
29  mApplyButton(new QPushButton("Apply compensation")),
30  mResetButton(new QPushButton("Reset")),
31  mSoundSpeedSpinBox(new QDoubleSpinBox()),
32  mWaterDegreeSpinBox(new QDoubleSpinBox()),
33  mTrackingService(trackingService)
34 {
35  QVBoxLayout* vLayout = new QVBoxLayout(this);
36  this->setToolTip("Correct the sound speed received from the US scanner");
37 
38  connect(mApplyButton, SIGNAL(clicked()), this, SLOT(applySoundSpeedCompensationFactorSlot()));
39  connect(mResetButton, SIGNAL(clicked()), this, SLOT(resetSlot()));
40 
41  mWaterDegreeSpinBox->setRange(0.0, 50.0);
42  connect(mWaterDegreeSpinBox, SIGNAL(valueChanged(double)), this, SLOT(waterDegreeChangedSlot()));
43  mSoundSpeedSpinBox->setRange(1000.0, 2000.0); //what's a suitable range?
44  connect(mSoundSpeedSpinBox, SIGNAL(valueChanged(double)), this, SLOT(waterSoundSpeedChangedSlot()));
45 
46  QHBoxLayout* speedLayout = new QHBoxLayout();
47  speedLayout->addWidget(new QLabel("Water sound speed: "));
48  speedLayout->addWidget(mSoundSpeedSpinBox);
49  speedLayout->addWidget(new QLabel("m/s, or "));
50  speedLayout->addWidget(mWaterDegreeSpinBox);
51  speedLayout->addWidget(new QLabel("C"+QString::fromUtf8("\302\260")+"")); //\302\260 is the degree sign
52 
53  QHBoxLayout* buttonLayout = new QHBoxLayout();
54  buttonLayout->addWidget(mApplyButton);
55  buttonLayout->addWidget(mResetButton);
56 
57  vLayout->addLayout(speedLayout);
58  vLayout->addLayout(buttonLayout);
59 
60  this->resetSlot();
61  this->updateButtons();
62 
63  connect(mTrackingService.get(), &TrackingService::activeToolChanged, this, &SoundSpeedConverterWidget::setToolSlot);
64 }
65 
67 {}
68 
70 {
71  if(!mProbe)
72  {
73  reportWarning("Don't know which probe to set the sound speed compensation for...");
74  return;
75  }
76 
77  double factor = this->getSoundSpeedCompensationFactor();
78  mProbe->setSoundSpeedCompensationFactor(factor);
79 }
80 
81 void SoundSpeedConverterWidget::setToolSlot(const QString& uid)
82 {
83  ToolPtr tool = mTrackingService->getTool(uid);
84  if(!tool)
85  return;
86  ProbePtr probe = tool->getProbe();
87  if(!probe)
88  return;
89  this->setProbe(probe);
90 }
91 
92 double SoundSpeedConverterWidget::getSoundSpeedCompensationFactor()
93 {
94  return mToSoundSpeed/mScannerSoundSpeed;
95 }
96 
97 double SoundSpeedConverterWidget::getWaterSoundSpeed()
98 {
99  double waterDegree = mWaterDegreeSpinBox->value();
100  double retval = 1402.40 + 5.01*waterDegree - 0.055*pow(waterDegree, 2) + 0.00022*pow(waterDegree, 3);
101 
102  return retval;
103 }
104 
105 void SoundSpeedConverterWidget::setProbe(ProbePtr probe)
106 {
107  mProbe = probe;
108  this->updateButtons();
109 }
110 
111 void SoundSpeedConverterWidget::waterSoundSpeedChangedSlot()
112 {
113  mToSoundSpeed = mSoundSpeedSpinBox->value();
114 
115  QFont font = mWaterDegreeSpinBox->font();
116  font.setStrikeOut(true);
117  mWaterDegreeSpinBox->setFont(font);
118 }
119 
120 void SoundSpeedConverterWidget::waterDegreeChangedSlot()
121 {
122  mToSoundSpeed = this->getWaterSoundSpeed();
123 
124  if(mToSoundSpeed != mSoundSpeedSpinBox->value())
125  mSoundSpeedSpinBox->setValue(mToSoundSpeed);
126 
127  QFont font = mWaterDegreeSpinBox->font();
128  font.setStrikeOut(false);
129  mWaterDegreeSpinBox->setFont(font);
130 }
131 
132 void SoundSpeedConverterWidget::resetSlot()
133 {
134  this->setSoundSpeed(mScannerSoundSpeed);
135 
136  if(!mProbe)
137  return;
139 }
140 
141 void SoundSpeedConverterWidget::setSoundSpeed(double soundspeed)
142 {
143  mSoundSpeedSpinBox->setValue(soundspeed);
144 }
145 
146 void SoundSpeedConverterWidget::setWaterDegree(double degree)
147 {
148  mWaterDegreeSpinBox->setValue(degree);
149 }
150 
151 void SoundSpeedConverterWidget::updateButtons()
152 {
153  mApplyButton->setEnabled(mProbe ? true : false);
154  mResetButton->setEnabled(true);
155 }
156 
157 }//namespace cx
boost::shared_ptr< class TrackingService > TrackingServicePtr
boost::shared_ptr< Probe > ProbePtr
Definition: cxProbe.h:72
void activeToolChanged(const QString &uId)
void reportWarning(QString msg)
Definition: cxLogger.cpp:70
void applySoundSpeedCompensationFactorSlot()
sets the sounds speed conversion factor on the rt source
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
SoundSpeedConverterWidget(TrackingServicePtr trackingService, QWidget *parent=NULL)
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr