CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
34 
35 #include <QPushButton>
36 #include <QDoubleSpinBox>
37 #include <QVBoxLayout>
38 #include <QHBoxLayout>
39 #include <QLabel>
40 #include "cxLogger.h"
41 #include "cxTrackingService.h"
42 #include "cxProbe.h"
43 
44 namespace cx
45 {
46 
48  BaseWidget(parent, "SoundSpeedConverterWidget", "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)
55 {
56  QVBoxLayout* vLayout = new QVBoxLayout(this);
57 
58  connect(mApplyButton, SIGNAL(clicked()), this, SLOT(applySoundSpeedCompensationFactorSlot()));
59  connect(mResetButton, SIGNAL(clicked()), this, SLOT(resetSlot()));
60 
61  mWaterDegreeSpinBox->setRange(0.0, 50.0);
62  connect(mWaterDegreeSpinBox, SIGNAL(valueChanged(double)), this, SLOT(waterDegreeChangedSlot()));
63  mSoundSpeedSpinBox->setRange(1000.0, 2000.0); //what's a suitable range?
64  connect(mSoundSpeedSpinBox, SIGNAL(valueChanged(double)), this, SLOT(waterSoundSpeedChangedSlot()));
65 
66  QHBoxLayout* speedLayout = new QHBoxLayout();
67  speedLayout->addWidget(new QLabel("Water sound speed: "));
68  speedLayout->addWidget(mSoundSpeedSpinBox);
69  speedLayout->addWidget(new QLabel("m/s, or "));
70  speedLayout->addWidget(mWaterDegreeSpinBox);
71  speedLayout->addWidget(new QLabel("C"+QString::fromUtf8("\302\260")+"")); //\302\260 is the degree sign
72 
73  QHBoxLayout* buttonLayout = new QHBoxLayout();
74  buttonLayout->addWidget(mApplyButton);
75  buttonLayout->addWidget(mResetButton);
76 
77  vLayout->addLayout(speedLayout);
78  vLayout->addLayout(buttonLayout);
79 
80  this->resetSlot();
81  this->updateButtons();
82 
83  connect(mTrackingService.get(), &TrackingService::activeToolChanged, this, &SoundSpeedConverterWidget::setToolSlot);
84 }
85 
87 {}
88 
90 {
91  return "<html>"
92  "<h3>Speed of sound compensation.</h3>"
93  "<p>Calculates a factor to compensate for the difference in sound of speed which a ultrasound machine expects and the medium you are doing ultrasound on.</p>"
94  "<p><i></i></p>"
95  "</html>";
96 }
97 
99 {
100  if(!mProbe)
101  {
102  reportWarning("Don't know which probe to set the sound speed compensation for...");
103  return;
104  }
105 
106  double factor = this->getSoundSpeedCompensationFactor();
107  mProbe->setSoundSpeedCompensationFactor(factor);
108 }
109 
110 void SoundSpeedConverterWidget::setToolSlot(const QString& uid)
111 {
112  ToolPtr tool = mTrackingService->getTool(uid);
113  ProbePtr probe = tool->getProbe();
114  if(!probe)
115  return;
116  this->setProbe(probe);
117 }
118 
119 double SoundSpeedConverterWidget::getSoundSpeedCompensationFactor()
120 {
121  return mToSoundSpeed/mScannerSoundSpeed;
122 }
123 
124 double SoundSpeedConverterWidget::getWaterSoundSpeed()
125 {
126  double waterDegree = mWaterDegreeSpinBox->value();
127  double retval = 1402.40 + 5.01*waterDegree - 0.055*pow(waterDegree, 2) + 0.00022*pow(waterDegree, 3);
128 
129  return retval;
130 }
131 
132 void SoundSpeedConverterWidget::setProbe(ProbePtr probe)
133 {
134  mProbe = probe;
135  this->updateButtons();
136 }
137 
138 void SoundSpeedConverterWidget::waterSoundSpeedChangedSlot()
139 {
140  mToSoundSpeed = mSoundSpeedSpinBox->value();
141 
142  QFont font = mWaterDegreeSpinBox->font();
143  font.setStrikeOut(true);
144  mWaterDegreeSpinBox->setFont(font);
145 }
146 
147 void SoundSpeedConverterWidget::waterDegreeChangedSlot()
148 {
149  mToSoundSpeed = this->getWaterSoundSpeed();
150 
151  if(mToSoundSpeed != mSoundSpeedSpinBox->value())
152  mSoundSpeedSpinBox->setValue(mToSoundSpeed);
153 
154  QFont font = mWaterDegreeSpinBox->font();
155  font.setStrikeOut(false);
156  mWaterDegreeSpinBox->setFont(font);
157 }
158 
159 void SoundSpeedConverterWidget::resetSlot()
160 {
161  this->setSoundSpeed(mScannerSoundSpeed);
162 
163  if(!mProbe)
164  return;
166 }
167 
168 void SoundSpeedConverterWidget::setSoundSpeed(double soundspeed)
169 {
170  mSoundSpeedSpinBox->setValue(soundspeed);
171 }
172 
173 void SoundSpeedConverterWidget::setWaterDegree(double degree)
174 {
175  mWaterDegreeSpinBox->setValue(degree);
176 }
177 
178 void SoundSpeedConverterWidget::updateButtons()
179 {
180  mApplyButton->setEnabled(mProbe ? true : false);
181  mResetButton->setEnabled(true);
182 }
183 
184 }//namespace cx
boost::shared_ptr< class TrackingService > TrackingServicePtr
boost::shared_ptr< Probe > ProbePtr
Definition: cxProbe.h:93
void activeToolChanged(const QString &uId)
void reportWarning(QString msg)
Definition: cxLogger.cpp:91
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:108
SoundSpeedConverterWidget(TrackingServicePtr trackingService, QWidget *parent=NULL)
cxLogicManager_EXPORT TrackingServicePtr trackingService()
virtual QString defaultWhatsThis() const
Returns a short description of what this widget will do for you.
boost::shared_ptr< class Tool > ToolPtr