14 #include <QPushButton> 15 #include <QDoubleSpinBox> 16 #include <QVBoxLayout> 17 #include <QHBoxLayout> 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)
35 QVBoxLayout* vLayout =
new QVBoxLayout(
this);
36 this->setToolTip(
"Correct the sound speed received from the US scanner");
39 connect(mResetButton, SIGNAL(clicked()),
this, SLOT(resetSlot()));
41 mWaterDegreeSpinBox->setRange(0.0, 50.0);
42 connect(mWaterDegreeSpinBox, SIGNAL(valueChanged(
double)),
this, SLOT(waterDegreeChangedSlot()));
43 mSoundSpeedSpinBox->setRange(1000.0, 2000.0);
44 connect(mSoundSpeedSpinBox, SIGNAL(valueChanged(
double)),
this, SLOT(waterSoundSpeedChangedSlot()));
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")+
""));
53 QHBoxLayout* buttonLayout =
new QHBoxLayout();
54 buttonLayout->addWidget(mApplyButton);
55 buttonLayout->addWidget(mResetButton);
57 vLayout->addLayout(speedLayout);
58 vLayout->addLayout(buttonLayout);
61 this->updateButtons();
73 reportWarning(
"Don't know which probe to set the sound speed compensation for...");
77 double factor = this->getSoundSpeedCompensationFactor();
78 mProbe->setSoundSpeedCompensationFactor(factor);
81 void SoundSpeedConverterWidget::setToolSlot(
const QString& uid)
83 ToolPtr tool = mTrackingService->getTool(uid);
87 this->setProbe(probe);
90 double SoundSpeedConverterWidget::getSoundSpeedCompensationFactor()
92 return mToSoundSpeed/mScannerSoundSpeed;
95 double SoundSpeedConverterWidget::getWaterSoundSpeed()
97 double waterDegree = mWaterDegreeSpinBox->value();
98 double retval = 1402.40 + 5.01*waterDegree - 0.055*pow(waterDegree, 2) + 0.00022*pow(waterDegree, 3);
103 void SoundSpeedConverterWidget::setProbe(
ProbePtr probe)
106 this->updateButtons();
109 void SoundSpeedConverterWidget::waterSoundSpeedChangedSlot()
111 mToSoundSpeed = mSoundSpeedSpinBox->value();
113 QFont font = mWaterDegreeSpinBox->font();
114 font.setStrikeOut(
true);
115 mWaterDegreeSpinBox->setFont(font);
118 void SoundSpeedConverterWidget::waterDegreeChangedSlot()
120 mToSoundSpeed = this->getWaterSoundSpeed();
122 if(mToSoundSpeed != mSoundSpeedSpinBox->value())
123 mSoundSpeedSpinBox->setValue(mToSoundSpeed);
125 QFont font = mWaterDegreeSpinBox->font();
126 font.setStrikeOut(
false);
127 mWaterDegreeSpinBox->setFont(font);
130 void SoundSpeedConverterWidget::resetSlot()
132 this->setSoundSpeed(mScannerSoundSpeed);
139 void SoundSpeedConverterWidget::setSoundSpeed(
double soundspeed)
141 mSoundSpeedSpinBox->setValue(soundspeed);
144 void SoundSpeedConverterWidget::setWaterDegree(
double degree)
146 mWaterDegreeSpinBox->setValue(degree);
149 void SoundSpeedConverterWidget::updateButtons()
151 mApplyButton->setEnabled(mProbe ?
true :
false);
152 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