NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxAcquisitionData.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 "cxAcquisitionData.h"
13 
14 //#include "cxAcquisitionManager.h"
15 #include <vector>
16 #include <QDomNode>
17 #include <QDateTime>
18 #include <QStringList>
19 #include "cxTime.h"
20 #include "cxLogger.h"
21 #include "cxTrackingService.h"
22 #include "cxSettings.h"
24 #include "cxReporter.h"
25 #include "cxVisServices.h"
26 
27 
28 namespace cx
29 {
31 {}
32 
34  mServices(services),
35  mReconstructer(reconstructer)
36 {
37 
38 }
39 
41 {
42 }
43 
45 {
46  mRecordSessions.clear();
48 }
49 
51 {
52  mRecordSessions.push_back(session);
54 }
55 
57 {
58  for(int i = 0; i < mRecordSessions.size(); ++i)
59  {
60  if(mRecordSessions[i]->getUid() == session->getUid())
61  mRecordSessions.erase(mRecordSessions.begin() + i);
62  }
64 }
65 
66 std::vector<RecordSessionPtr> AcquisitionData::getRecordSessions()
67 {
68  return mRecordSessions;
69 }
70 
72 {
73  RecordSessionPtr retval;
74  std::vector<RecordSessionPtr>::iterator it = mRecordSessions.begin();
75  for(; it != mRecordSessions.end(); ++it)
76  {
77  if((*it)->getUid() == uid)
78  retval = (*it);
79  }
80  return retval;
81 }
82 
83 void AcquisitionData::addXml(QDomNode& parentNode)
84 {
85  QDomDocument doc = parentNode.ownerDocument();
86  QDomElement base = doc.createElement("stateManager");
87  parentNode.appendChild(base);
88 
89  QDomElement sessionsNode = doc.createElement("recordSessions");
90  std::vector<RecordSessionPtr>::iterator it = mRecordSessions.begin();
91  for(; it != mRecordSessions.end(); ++it)
92  {
93  QDomElement sessionNode = doc.createElement("recordSession");
94  (*it)->addXml(sessionNode);
95  sessionsNode.appendChild(sessionNode);
96  }
97  base.appendChild(sessionsNode);
98 }
99 
100 void AcquisitionData::parseXml(QDomNode& dataNode)
101 {
102  QDomNode recordsessionsNode = dataNode.namedItem("recordSessions");
103  QDomElement recodesessionNode = recordsessionsNode.firstChildElement("recordSession");
104  for (; !recodesessionNode.isNull(); recodesessionNode = recodesessionNode.nextSiblingElement("recordSession"))
105  {
106 // RecordSessionPtr session(new RecordSession("", 0,0,""));
107  RecordSessionPtr session(new RecordSession());
108  session->parseXml(recodesessionNode);
109  this->addRecordSession(session);
110  }
111 }
112 
117 {
118  QString retval;
119  int max = 0;
120  std::vector<RecordSessionPtr> recordsessions = this->getRecordSessions();
121  std::vector<RecordSessionPtr>::iterator iter;
122  for (iter = recordsessions.begin(); iter != recordsessions.end(); ++iter)
123  {
124  QString index = (*iter)->getUid().split("_").front();
125  max = std::max(max, index.toInt());
126  }
127 
128  return max+1;
129 }
130 
134 
135 Acquisition::Acquisition(AcquisitionDataPtr pluginData, QObject* parent) :
136  QObject(parent), mPluginData(pluginData), mCurrentState(AcquisitionService::sNOT_RUNNING),
137  mReady(true),
138  mInfoText("")
139 {
140  connect(this->getServices()->tracking().get(), &TrackingService::stateChanged, this, &Acquisition::checkIfReadySlot);
141  connect(this->getServices()->tracking().get(), &TrackingService::activeToolChanged, this, &Acquisition::checkIfReadySlot);
142  this->checkIfReadySlot();
143 }
144 
146 {
147 }
148 
150 {
151  return true;
152  if (!context.testFlag(AcquisitionService::tTRACKING))
153  return true;
154  return mReady;
155 }
156 
158 {
159  if (!context.testFlag(AcquisitionService::tTRACKING))
160  return "";
161  return mInfoText;
162 }
163 
164 void Acquisition::checkIfReadySlot()
165 {
166  bool tracking = this->getServices()->tracking()->getState()>=Tool::tsTRACKING;
167  ToolPtr tool = this->getServices()->tracking()->getActiveTool();
168  ToolPtr reference_frame = this->getServices()->tracking()->getReferenceTool();
169  if(tracking && reference_frame)
170  {
171  connect(reference_frame.get(), &Tool::toolVisible, this, &Acquisition::checkIfReadySlot, Qt::UniqueConnection);
172  }
173  QString mWhatsMissing;
174  mWhatsMissing.clear();
175 
176  if(tracking)
177  {
178  mWhatsMissing = "<font color=green>Ready to record!</font><br>";
179  if (!tool || !tool->getVisible())
180  {
181  mWhatsMissing += "<font color=orange>Tool not visible</font><br>";
182  }
183  if(!reference_frame || !reference_frame->getVisible())
184  {
185  mWhatsMissing += "<font color=orange>Reference frame not visible.</font><br>";
186  }
187  }
188  else
189  {
190  mWhatsMissing.append("<font color=red>Need to start tracking.</font><br>");
191  }
192 
193  // do not require tracking to be present in order to perform an acquisition.
194  this->setReady(tracking, mWhatsMissing);
195 }
196 
197 void Acquisition::setReady(bool val, QString text)
198 {
199  mReady = val;
200  mInfoText = text;
201 
202  emit readinessChanged();
203 }
204 
206 {
208  {
209  report("Already recording a session, stop before trying to start a new record session.");
210  return;
211  }
212 
213  mCurrentContext = context;
214 
215  if (session)
216  mLatestSession = session;
217  else
218  mLatestSession.reset(new cx::RecordSession(mPluginData->getNewSessionId(), category));
219 
220  mLatestSession->startNewInterval();
221 
222  reporter()->playStartSound();
223  this->setState(AcquisitionService::sRUNNING);
224  emit started();
225 }
226 
228 {
230  {
231  return;
232  }
233 
234  mLatestSession->stopLastInterval();
235  if (!mPluginData->getRecordSession(mLatestSession->getUid()))
236  mPluginData->addRecordSession(mLatestSession);
237  reporter()->playStopSound();
238  this->setState(AcquisitionService::sNOT_RUNNING);
239  emit acquisitionStopped();
240 }
241 
243 {
245  {
246  return;
247  }
248  reporter()->playCancelSound();
249  mLatestSession->cancelLastInterval();
250  mLatestSession.reset();
251  mCurrentContext = AcquisitionService::TYPES();
252  this->setState(AcquisitionService::sNOT_RUNNING);
253  emit cancelled();
254 }
255 
257 {
258  this->setState(AcquisitionService::sPOST_PROCESSING);
259 }
260 
262 {
263  this->setState(AcquisitionService::sNOT_RUNNING);
264 }
265 
266 void Acquisition::setState(AcquisitionService::STATE newState)
267 {
268  AcquisitionService::STATE lastState = mCurrentState;
269  mCurrentState = newState;
270 
271 // // emit some helper signals
272 // if (lastState!=AcquisitionService::sRUNNING && newState==AcquisitionService::sRUNNING)
273 // emit started();
274 // else if (lastState==AcquisitionService::sRUNNING && newState!=AcquisitionService::sRUNNING && mLatestSession)
275 // emit acquisitionStopped();
276 // else if (lastState==AcquisitionService::sRUNNING && newState!=AcquisitionService::sRUNNING && !mLatestSession)
277 // emit cancelled();
278 
279  emit stateChanged();
280 }
281 
282 VisServicesPtr Acquisition::getServices()
283 {
284  return this->getPluginData()->getServices();
285 }
286 
287 }
cx::Acquisition::getPluginData
AcquisitionDataPtr getPluginData()
Definition: cxAcquisitionData.h:123
cx::RecordSession
Definition: cxRecordSession.h:46
cxUsReconstructionService.h
cx::AcquisitionService::sRUNNING
@ sRUNNING
Definition: cxAcquisitionService.h:53
cxLogger.h
cx::Acquisition::started
void started()
cx::AcquisitionData::addRecordSession
void addRecordSession(RecordSessionPtr session)
Definition: cxAcquisitionData.cpp:50
cx::Tool::toolVisible
void toolVisible(bool visible)
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::Acquisition::stopPostProcessing
void stopPostProcessing()
Definition: cxAcquisitionData.cpp:261
cx::UsReconstructionServicePtr
boost::shared_ptr< class UsReconstructionService > UsReconstructionServicePtr
Definition: cxAcquisitionImplService.h:24
cx::AcquisitionData::clear
void clear()
Definition: cxAcquisitionData.cpp:44
cx::report
void report(QString msg)
Definition: cxLogger.cpp:69
cx::AcquisitionData::AcquisitionData
AcquisitionData()
Definition: cxAcquisitionData.cpp:30
cx::Acquisition::~Acquisition
virtual ~Acquisition()
Definition: cxAcquisitionData.cpp:145
cx::VisServicesPtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
cx::AcquisitionData::getRecordSessions
std::vector< RecordSessionPtr > getRecordSessions()
Definition: cxAcquisitionData.cpp:66
cx::Acquisition::isReady
bool isReady(AcquisitionService::TYPES) const
Definition: cxAcquisitionData.cpp:149
cx::AcquisitionService::sNOT_RUNNING
@ sNOT_RUNNING
Definition: cxAcquisitionService.h:55
cx::AcquisitionService::tTRACKING
@ tTRACKING
Definition: cxAcquisitionService.h:44
cxReporter.h
cx::reporter
ReporterPtr reporter()
Definition: cxReporter.cpp:36
cx::Acquisition::getInfoText
QString getInfoText(AcquisitionService::TYPES) const
Definition: cxAcquisitionData.cpp:157
cx::AcquisitionData::~AcquisitionData
virtual ~AcquisitionData()
Definition: cxAcquisitionData.cpp:40
cx::AcquisitionData::parseXml
void parseXml(QDomNode &dataNode)
Definition: cxAcquisitionData.cpp:100
cx::Acquisition::Acquisition
Acquisition(AcquisitionDataPtr pluginData, QObject *parent=0)
Definition: cxAcquisitionData.cpp:135
cx::Acquisition::startRecord
void startRecord(AcquisitionService::TYPES context, QString category, RecordSessionPtr session)
Definition: cxAcquisitionData.cpp:205
cx::AcquisitionData::removeRecordSession
void removeRecordSession(RecordSessionPtr session)
Definition: cxAcquisitionData.cpp:56
cx::AcquisitionData::getRecordSession
RecordSessionPtr getRecordSession(QString uid)
Definition: cxAcquisitionData.cpp:71
cx::AcquisitionService
Acqusition services abstract interface.
Definition: cxAcquisitionService.h:36
cx::TrackingService::stateChanged
void stateChanged()
cx::TrackingService::activeToolChanged
void activeToolChanged(const QString &uId)
cxSettings.h
cx::Acquisition::getState
AcquisitionService::STATE getState() const
Definition: cxAcquisitionData.h:122
cx::Acquisition::stateChanged
void stateChanged()
cxTime.h
cx::AcquisitionService::TYPES
QFlags< TYPE > TYPES
Definition: cxAcquisitionService.h:48
cx::ToolPtr
boost::shared_ptr< class Tool > ToolPtr
Definition: cxVideoConnectionWidget.h:43
cx::Acquisition::stopRecord
void stopRecord()
Definition: cxAcquisitionData.cpp:227
cx::AcquisitionData::recordedSessionsChanged
void recordedSessionsChanged()
cx::Acquisition::cancelRecord
void cancelRecord()
Definition: cxAcquisitionData.cpp:242
cx::AcquisitionData::addXml
void addXml(QDomNode &dataNode)
Definition: cxAcquisitionData.cpp:83
cx::AcquisitionService::sPOST_PROCESSING
@ sPOST_PROCESSING
Definition: cxAcquisitionService.h:54
cx::Acquisition::readinessChanged
void readinessChanged()
cx::Tool::tsTRACKING
@ tsTRACKING
emitting tracking data
Definition: cxTool.h:77
cx::AcquisitionDataPtr
boost::shared_ptr< class AcquisitionData > AcquisitionDataPtr
Definition: cxAcquisitionImplService.h:22
cxTrackingService.h
cx::Acquisition::cancelled
void cancelled()
cxAcquisitionData.h
cx::Acquisition::acquisitionStopped
void acquisitionStopped()
cx::RecordSessionPtr
boost::shared_ptr< class RecordSession > RecordSessionPtr
Definition: cxAcquisitionService.h:28
cx::AcquisitionService::STATE
STATE
Definition: cxAcquisitionService.h:51
cx::Acquisition::startPostProcessing
void startPostProcessing()
Definition: cxAcquisitionData.cpp:256
cx::AcquisitionData::getNewSessionId
int getNewSessionId()
Definition: cxAcquisitionData.cpp:116
cxVisServices.h