Fraxinus  16.5.0-fx-rc9
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  this->setToolTip("Correct the sound speed received from the US scanner");
58 
59  connect(mApplyButton, SIGNAL(clicked()), this, SLOT(applySoundSpeedCompensationFactorSlot()));
60  connect(mResetButton, SIGNAL(clicked()), this, SLOT(resetSlot()));
61 
62  mWaterDegreeSpinBox->setRange(0.0, 50.0);
63  connect(mWaterDegreeSpinBox, SIGNAL(valueChanged(double)), this, SLOT(waterDegreeChangedSlot()));
64  mSoundSpeedSpinBox->setRange(1000.0, 2000.0); //what's a suitable range?
65  connect(mSoundSpeedSpinBox, SIGNAL(valueChanged(double)), this, SLOT(waterSoundSpeedChangedSlot()));
66 
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")+"")); //\302\260 is the degree sign
73 
74  QHBoxLayout* buttonLayout = new QHBoxLayout();
75  buttonLayout->addWidget(mApplyButton);
76  buttonLayout->addWidget(mResetButton);
77 
78  vLayout->addLayout(speedLayout);
79  vLayout->addLayout(buttonLayout);
80 
81  this->resetSlot();
82  this->updateButtons();
83 
84  connect(mTrackingService.get(), &TrackingService::activeToolChanged, this, &SoundSpeedConverterWidget::setToolSlot);
85 }
86 
88 {}
89 
91 {
92  if(!mProbe)
93  {
94  reportWarning("Don't know which probe to set the sound speed compensation for...");
95  return;
96  }
97 
98  double factor = this->getSoundSpeedCompensationFactor();
99  mProbe->setSoundSpeedCompensationFactor(factor);
100 }
101 
102 void SoundSpeedConverterWidget::setToolSlot(const QString& uid)
103 {
104  ToolPtr tool = mTrackingService->getTool(uid);
105  ProbePtr probe = tool->getProbe();
106  if(!probe)
107  return;
108  this->setProbe(probe);
109 }
110 
111 double SoundSpeedConverterWidget::getSoundSpeedCompensationFactor()
112 {
113  return mToSoundSpeed/mScannerSoundSpeed;
114 }
115 
116 double SoundSpeedConverterWidget::getWaterSoundSpeed()
117 {
118  double waterDegree = mWaterDegreeSpinBox->value();
119  double retval = 1402.40 + 5.01*waterDegree - 0.055*pow(waterDegree, 2) + 0.00022*pow(waterDegree, 3);
120 
121  return retval;
122 }
123 
124 void SoundSpeedConverterWidget::setProbe(ProbePtr probe)
125 {
126  mProbe = probe;
127  this->updateButtons();
128 }
129 
130 void SoundSpeedConverterWidget::waterSoundSpeedChangedSlot()
131 {
132  mToSoundSpeed = mSoundSpeedSpinBox->value();
133 
134  QFont font = mWaterDegreeSpinBox->font();
135  font.setStrikeOut(true);
136  mWaterDegreeSpinBox->setFont(font);
137 }
138 
139 void SoundSpeedConverterWidget::waterDegreeChangedSlot()
140 {
141  mToSoundSpeed = this->getWaterSoundSpeed();
142 
143  if(mToSoundSpeed != mSoundSpeedSpinBox->value())
144  mSoundSpeedSpinBox->setValue(mToSoundSpeed);
145 
146  QFont font = mWaterDegreeSpinBox->font();
147  font.setStrikeOut(false);
148  mWaterDegreeSpinBox->setFont(font);
149 }
150 
151 void SoundSpeedConverterWidget::resetSlot()
152 {
153  this->setSoundSpeed(mScannerSoundSpeed);
154 
155  if(!mProbe)
156  return;
158 }
159 
160 void SoundSpeedConverterWidget::setSoundSpeed(double soundspeed)
161 {
162  mSoundSpeedSpinBox->setValue(soundspeed);
163 }
164 
165 void SoundSpeedConverterWidget::setWaterDegree(double degree)
166 {
167  mWaterDegreeSpinBox->setValue(degree);
168 }
169 
170 void SoundSpeedConverterWidget::updateButtons()
171 {
172  mApplyButton->setEnabled(mProbe ? true : false);
173  mResetButton->setEnabled(true);
174 }
175 
176 }//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()
boost::shared_ptr< class Tool > ToolPtr