35 #include <QPushButton> 36 #include <QDoubleSpinBox> 37 #include <QVBoxLayout> 38 #include <QHBoxLayout> 48 BaseWidget(parent,
"sound_speed_converter_widget",
"Sound Speed Converter"),
49 mScannerSoundSpeed(1540.0),
50 mApplyButton(new QPushButton(
"Apply compensation")),
51 mResetButton(new QPushButton(
"Reset")),
52 mSoundSpeedSpinBox(new QDoubleSpinBox()),
53 mWaterDegreeSpinBox(new QDoubleSpinBox()),
54 mTrackingService(trackingService)
56 QVBoxLayout* vLayout =
new QVBoxLayout(
this);
57 this->setToolTip(
"Correct the sound speed received from the US scanner");
60 connect(mResetButton, SIGNAL(clicked()),
this, SLOT(resetSlot()));
62 mWaterDegreeSpinBox->setRange(0.0, 50.0);
63 connect(mWaterDegreeSpinBox, SIGNAL(valueChanged(
double)),
this, SLOT(waterDegreeChangedSlot()));
64 mSoundSpeedSpinBox->setRange(1000.0, 2000.0);
65 connect(mSoundSpeedSpinBox, SIGNAL(valueChanged(
double)),
this, SLOT(waterSoundSpeedChangedSlot()));
67 QHBoxLayout* speedLayout =
new QHBoxLayout();
68 speedLayout->addWidget(
new QLabel(
"Water sound speed: "));
69 speedLayout->addWidget(mSoundSpeedSpinBox);
70 speedLayout->addWidget(
new QLabel(
"m/s, or "));
71 speedLayout->addWidget(mWaterDegreeSpinBox);
72 speedLayout->addWidget(
new QLabel(
"C"+QString::fromUtf8(
"\302\260")+
""));
74 QHBoxLayout* buttonLayout =
new QHBoxLayout();
75 buttonLayout->addWidget(mApplyButton);
76 buttonLayout->addWidget(mResetButton);
78 vLayout->addLayout(speedLayout);
79 vLayout->addLayout(buttonLayout);
82 this->updateButtons();
94 reportWarning(
"Don't know which probe to set the sound speed compensation for...");
98 double factor = this->getSoundSpeedCompensationFactor();
99 mProbe->setSoundSpeedCompensationFactor(factor);
102 void SoundSpeedConverterWidget::setToolSlot(
const QString& uid)
104 ToolPtr tool = mTrackingService->getTool(uid);
108 this->setProbe(probe);
111 double SoundSpeedConverterWidget::getSoundSpeedCompensationFactor()
113 return mToSoundSpeed/mScannerSoundSpeed;
116 double SoundSpeedConverterWidget::getWaterSoundSpeed()
118 double waterDegree = mWaterDegreeSpinBox->value();
119 double retval = 1402.40 + 5.01*waterDegree - 0.055*pow(waterDegree, 2) + 0.00022*pow(waterDegree, 3);
124 void SoundSpeedConverterWidget::setProbe(
ProbePtr probe)
127 this->updateButtons();
130 void SoundSpeedConverterWidget::waterSoundSpeedChangedSlot()
132 mToSoundSpeed = mSoundSpeedSpinBox->value();
134 QFont font = mWaterDegreeSpinBox->font();
135 font.setStrikeOut(
true);
136 mWaterDegreeSpinBox->setFont(font);
139 void SoundSpeedConverterWidget::waterDegreeChangedSlot()
141 mToSoundSpeed = this->getWaterSoundSpeed();
143 if(mToSoundSpeed != mSoundSpeedSpinBox->value())
144 mSoundSpeedSpinBox->setValue(mToSoundSpeed);
146 QFont font = mWaterDegreeSpinBox->font();
147 font.setStrikeOut(
false);
148 mWaterDegreeSpinBox->setFont(font);
151 void SoundSpeedConverterWidget::resetSlot()
153 this->setSoundSpeed(mScannerSoundSpeed);
160 void SoundSpeedConverterWidget::setSoundSpeed(
double soundspeed)
162 mSoundSpeedSpinBox->setValue(soundspeed);
165 void SoundSpeedConverterWidget::setWaterDegree(
double degree)
167 mWaterDegreeSpinBox->setValue(degree);
170 void SoundSpeedConverterWidget::updateButtons()
172 mApplyButton->setEnabled(mProbe ?
true :
false);
173 mResetButton->setEnabled(
true);
boost::shared_ptr< class TrackingService > TrackingServicePtr
boost::shared_ptr< Probe > ProbePtr
void activeToolChanged(const QString &uId)
void reportWarning(QString msg)
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr