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