Fraxinus  2023.01.05-dev+develop.0da12
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  this->getServices()->file());
163 }
164 
165 void USAcquisition::recordStopped()
166 {
167  if (!mBase->getCurrentContext().testFlag(AcquisitionService::tUS))
168  return;
169 
170  mCore->stopRecord();
171 
172  this->sendAcquisitionDataToReconstructer();
173 
174  mCore->set_rMpr(this->getServices()->patient()->get_rMpr());
175  bool compress = settings()->value("Ultrasound/CompressAcquisition", true).toBool();
176  QString baseFolder = this->getServices()->patient()->getActivePatientFolder();
177  mCore->startSaveData(baseFolder, compress);
178 
179  mCore->clearRecording();
180 
181  this->checkIfReadySlot();
182 }
183 
184 void USAcquisition::recordCancelled()
185 {
186  mCore->cancelRecord();
187 }
188 
189 void USAcquisition::sendAcquisitionDataToReconstructer()
190 {
191  mCore->set_rMpr(this->getServices()->patient()->get_rMpr());
192 
193  VideoSourcePtr activeVideoSource = this->getServices()->video()->getActiveVideoSource();
194  if (activeVideoSource)
195  {
196  USReconstructInputData data = mCore->getDataForStream(activeVideoSource->getUid());
197  this->getReconstructer()->selectData(data);
198  emit acquisitionDataReady();
199  }
200 }
201 
202 std::vector<VideoSourcePtr> USAcquisition::getRecordingVideoSources(ToolPtr tool)
203 {
204  std::vector<VideoSourcePtr> retval;
205 
206  if (tool && tool->getProbe())
207  {
208  ProbePtr probe = tool->getProbe();
209  QStringList sources = probe->getAvailableVideoSources();
210  for (unsigned i=0; i<sources.size(); ++i)
211  retval.push_back(probe->getRTSource(sources[i]));
212  }
213  else
214  {
215  retval = this->getServices()->video()->getVideoSources();
216  }
217 
218  return retval;
219 }
220 
221 bool USAcquisition::getWriteColor()
222 {
223  PropertyPtr angio = this->getReconstructer()->getParam("Angio data");
224  bool writeColor = angio->getValueAsVariant().toBool()
225  || !settings()->value("Ultrasound/8bitAcquisitionData").toBool();
226  return writeColor;
227 }
228 
229 }
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