Fraxinus  18.10
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  ProbePtr probe = tool->getProbe();
85  if(!probe)
86  return;
87  this->setProbe(probe);
88 }
89 
90 double SoundSpeedConverterWidget::getSoundSpeedCompensationFactor()
91 {
92  return mToSoundSpeed/mScannerSoundSpeed;
93 }
94 
95 double SoundSpeedConverterWidget::getWaterSoundSpeed()
96 {
97  double waterDegree = mWaterDegreeSpinBox->value();
98  double retval = 1402.40 + 5.01*waterDegree - 0.055*pow(waterDegree, 2) + 0.00022*pow(waterDegree, 3);
99 
100  return retval;
101 }
102 
103 void SoundSpeedConverterWidget::setProbe(ProbePtr probe)
104 {
105  mProbe = probe;
106  this->updateButtons();
107 }
108 
109 void SoundSpeedConverterWidget::waterSoundSpeedChangedSlot()
110 {
111  mToSoundSpeed = mSoundSpeedSpinBox->value();
112 
113  QFont font = mWaterDegreeSpinBox->font();
114  font.setStrikeOut(true);
115  mWaterDegreeSpinBox->setFont(font);
116 }
117 
118 void SoundSpeedConverterWidget::waterDegreeChangedSlot()
119 {
120  mToSoundSpeed = this->getWaterSoundSpeed();
121 
122  if(mToSoundSpeed != mSoundSpeedSpinBox->value())
123  mSoundSpeedSpinBox->setValue(mToSoundSpeed);
124 
125  QFont font = mWaterDegreeSpinBox->font();
126  font.setStrikeOut(false);
127  mWaterDegreeSpinBox->setFont(font);
128 }
129 
130 void SoundSpeedConverterWidget::resetSlot()
131 {
132  this->setSoundSpeed(mScannerSoundSpeed);
133 
134  if(!mProbe)
135  return;
137 }
138 
139 void SoundSpeedConverterWidget::setSoundSpeed(double soundspeed)
140 {
141  mSoundSpeedSpinBox->setValue(soundspeed);
142 }
143 
144 void SoundSpeedConverterWidget::setWaterDegree(double degree)
145 {
146  mWaterDegreeSpinBox->setValue(degree);
147 }
148 
149 void SoundSpeedConverterWidget::updateButtons()
150 {
151  mApplyButton->setEnabled(mProbe ? true : false);
152  mResetButton->setEnabled(true);
153 }
154 
155 }//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