Fraxinus  18.10
An IGT application
cxUSAcquisition.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 
12 #include "cxUSAcquisition.h"
13 
14 #include "cxBoolProperty.h"
15 
16 #include "cxSettings.h"
17 #include "cxVideoService.h"
18 #include "cxTrackingService.h"
19 #include "cxUSSavingRecorder.h"
20 #include "cxAcquisitionData.h"
23 #include "cxPatientModelService.h"
24 #include "cxVideoSource.h"
25 #include "cxAcquisitionService.h"
27 #include "cxVisServices.h"
28 
29 
30 namespace cx
31 {
32 
34  QObject(parent),
35  mBase(base),
36  mReady(true),
37  mInfoText("")
38 {
39  mCore.reset(new USSavingRecorder());
40  connect(mCore.get(), SIGNAL(saveDataCompleted(QString)), this, SLOT(checkIfReadySlot()));
41  connect(mCore.get(), SIGNAL(saveDataCompleted(QString)), this, SIGNAL(saveDataCompleted(QString)));
42 
43 
44  connect(this->getServices()->tracking().get(), &TrackingService::stateChanged, this, &USAcquisition::checkIfReadySlot);
45  connect(this->getServices()->tracking().get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(checkIfReadySlot()));
46  connect(this->getServices()->video().get(), SIGNAL(activeVideoSourceChanged()), this, SLOT(checkIfReadySlot()));
47  connect(this->getServices()->video().get(), &VideoService::connected, this, &USAcquisition::checkIfReadySlot);
48 
49  connect(mBase.get(), SIGNAL(started()), this, SLOT(recordStarted()));
50  connect(mBase.get(), SIGNAL(acquisitionStopped()), this, SLOT(recordStopped()), Qt::QueuedConnection);
51  connect(mBase.get(), SIGNAL(cancelled()), this, SLOT(recordCancelled()));
52 
53  this->checkIfReadySlot();
54 }
55 
57 {
58 
59 }
60 
61 VisServicesPtr USAcquisition::getServices()
62 {
63  return mBase->getPluginData()->getServices();
64 }
65 
66 UsReconstructionServicePtr USAcquisition::getReconstructer()
67 {
68  return mBase->getPluginData()->getReconstructer();
69 }
70 
72 {
73  if (!context.testFlag(AcquisitionService::tUS))
74  return true;
75  return mReady;
76 }
77 
79 {
80  if (!context.testFlag(AcquisitionService::tUS))
81  return "";
82  return mInfoText;
83 }
84 
85 void USAcquisition::checkIfReadySlot()
86 {
87  bool tracking = this->getServices()->tracking()->getState()>=Tool::tsTRACKING;
88  bool streaming = this->getServices()->video()->isConnected();
89  ToolPtr tool = this->getServices()->tracking()->getFirstProbe();
90  ToolPtr reference_frame = this->getServices()->tracking()->getReferenceTool();
91  if(tracking && reference_frame)
92  {
93  QObject::connect(reference_frame.get(), &Tool::toolVisible, this, &USAcquisition::checkIfReadySlot, Qt::UniqueConnection);
94  }
95 
96  QString mWhatsMissing;
97  mWhatsMissing.clear();
98 
99  if(tracking && streaming)
100  {
101  mWhatsMissing = "<font color=green>Ready to record!</font><br>";
102  if (!tool || !tool->getVisible())
103  {
104  mWhatsMissing += "<font color=orange>Probe not visible.</font><br>";
105  }
106  if(!reference_frame || !reference_frame->getVisible())
107  {
108  mWhatsMissing += "<font color=orange>Reference frame not visible.</font><br>";
109  }
110  }
111  else
112  {
113  if(!tracking)
114  mWhatsMissing.append("<font color=red>Need to start tracking.</font><br>");
115  if(!streaming)
116  mWhatsMissing.append("<font color=red>Need to start streaming.</font><br>");
117  }
118 
119  int saving = mCore->getNumberOfSavingThreads();
120 
121  if (saving!=0)
122  mWhatsMissing.append(QString("<font color=orange>Saving %1 acquisition data.</font><br>").arg(saving));
123 
124  // remove redundant line breaks
125  QStringList list = mWhatsMissing.split("<br>", QString::SkipEmptyParts);
126  mWhatsMissing = list.join("<br>");
127 
128  //Make sure we have at least 2 lines to avoid "bouncing buttons"
129  if (list.size() < 2)
130  mWhatsMissing.append("<br>");
131 
132  // do not require tracking to be present in order to perform an acquisition.
133  this->setReady(streaming, mWhatsMissing);
134 }
135 
136 void USAcquisition::setReady(bool val, QString text)
137 {
138  mReady = val;
139  mInfoText = text;
140 
141  emit readinessChanged();
142 }
143 
145 {
146  return mCore->getNumberOfSavingThreads();
147 }
148 
149 void USAcquisition::recordStarted()
150 {
151  if (!mBase->getCurrentContext().testFlag(AcquisitionService::tUS))
152  return;
153 
154  this->getReconstructer()->selectData(USReconstructInputData()); // clear old data in reconstructeer
155 
156  ToolPtr tool = this->getServices()->tracking()->getFirstProbe();
157  mCore->setWriteColor(this->getWriteColor());
158  mCore->startRecord(mBase->getLatestSession(),
159  tool,
160  this->getServices()->tracking()->getReferenceTool(),
161  this->getRecordingVideoSources(tool));
162 }
163 
164 void USAcquisition::recordStopped()
165 {
166  if (!mBase->getCurrentContext().testFlag(AcquisitionService::tUS))
167  return;
168 
169  mCore->stopRecord();
170 
171  this->sendAcquisitionDataToReconstructer();
172 
173  mCore->set_rMpr(this->getServices()->patient()->get_rMpr());
174  bool compress = settings()->value("Ultrasound/CompressAcquisition", true).toBool();
175  QString baseFolder = this->getServices()->patient()->getActivePatientFolder();
176  mCore->startSaveData(baseFolder, compress);
177 
178  mCore->clearRecording();
179 
180  this->checkIfReadySlot();
181 }
182 
183 void USAcquisition::recordCancelled()
184 {
185  mCore->cancelRecord();
186 }
187 
188 void USAcquisition::sendAcquisitionDataToReconstructer()
189 {
190  mCore->set_rMpr(this->getServices()->patient()->get_rMpr());
191 
192  VideoSourcePtr activeVideoSource = this->getServices()->video()->getActiveVideoSource();
193  if (activeVideoSource)
194  {
195  USReconstructInputData data = mCore->getDataForStream(activeVideoSource->getUid());
196  this->getReconstructer()->selectData(data);
197  emit acquisitionDataReady();
198  }
199 }
200 
201 std::vector<VideoSourcePtr> USAcquisition::getRecordingVideoSources(ToolPtr tool)
202 {
203  std::vector<VideoSourcePtr> retval;
204 
205  if (tool && tool->getProbe())
206  {
207  ProbePtr probe = tool->getProbe();
208  QStringList sources = probe->getAvailableVideoSources();
209  for (unsigned i=0; i<sources.size(); ++i)
210  retval.push_back(probe->getRTSource(sources[i]));
211  }
212  else
213  {
214  retval = this->getServices()->video()->getVideoSources();
215  }
216 
217  return retval;
218 }
219 
220 bool USAcquisition::getWriteColor()
221 {
222  PropertyPtr angio = this->getReconstructer()->getParam("Angio data");
223  bool writeColor = angio->getValueAsVariant().toBool()
224  || !settings()->value("Ultrasound/8bitAcquisitionData").toBool();
225  return writeColor;
226 }
227 
228 }
boost::shared_ptr< class UsReconstructionService > UsReconstructionServicePtr
void saveDataCompleted(QString mhdFilename)
emitted when data has been saved to file
void connected(bool on)
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
Record and save ultrasound data.Use the start/stop pair to record video from the input streams during...
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:66
USAcquisition(AcquisitionPtr base, QObject *parent=0)
boost::shared_ptr< class Acquisition > AcquisitionPtr
bool isReady(AcquisitionService::TYPES context) const
boost::shared_ptr< Probe > ProbePtr
Definition: cxProbe.h:72
void toolVisible(bool visible)
boost::shared_ptr< class Property > PropertyPtr
boost::shared_ptr< class VideoSource > VideoSourcePtr
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:21
void acquisitionDataReady()
emitted when data is acquired and sent to the reconstruction module
emitting tracking data
Definition: cxTool.h:77
int getNumberOfSavingThreads() const
QString getInfoText(AcquisitionService::TYPES context) const
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr