CustusX  2023.01.05-dev+develop.0da12
An IGT application
cxRecordTrackingWidget.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 #include "cxRecordTrackingWidget.h"
12 
13 #include "cxRecordSessionWidget.h"
14 #include "cxRecordSession.h"
15 #include "cxToolRep3D.h"
16 #include "cxToolTracer.h"
17 #include "cxLogger.h"
18 #include "cxPatientModelService.h"
19 #include "cxViewService.h"
20 #include "cxStringProperty.h"
22 #include "cxTrackingService.h"
23 #include "cxProfile.h"
24 #include "cxHelperWidgets.h"
25 #include "cxRepContainer.h"
28 #include "cxAcquisitionService.h"
30 #include "cxBoolProperty.h"
31 
32 
33 namespace cx
34 {
35 
37  AcquisitionServicePtr acquisitionService,
38  VisServicesPtr services,
39  QString category,
40  QWidget* parent) :
41  QWidget(parent),
42  mServices(services),
43  mOptions(options),
44  mAcquisitionService(acquisitionService),
45  mDrawAqquisitionIn3D(true)
46 {
47  QVBoxLayout* mVerticalLayout = new QVBoxLayout(this);
48 
49  mToolSelector = StringPropertySelectTool::New(services->tracking());
50 
51  mSelectRecordSession.reset(new SelectRecordSession(mOptions, acquisitionService, services));
52  connect(mSelectRecordSession->getSessionSelector().get(), &StringProperty::changed, this, &RecordTrackingWidget::onMergeChanged);
53 
54  mMergeWithExistingSession = BoolProperty::initialize("mergerecording", "Merge",
55  "Merge new recording with selected recorded session",
56  false, QDomNode());
57  connect(mMergeWithExistingSession.get(), &BoolProperty::changed, this, &RecordTrackingWidget::onMergeChanged);
58 
60  mRecordSessionWidget = new RecordSessionWidget(mAcquisitionService, this, context, category);
61 
62  mVerticalLayout->setMargin(0);
63 
64  mToolSelectorWidget = sscCreateDataWidget(this, mToolSelector);
65  mMergeWithExistingSessionWidget = sscCreateDataWidget(this, mMergeWithExistingSession);
66  mVerticalLayout->addWidget(mToolSelectorWidget);
67  mVerticalLayout->addWidget(mRecordSessionWidget);
68  mVerticalLayout->addWidget(mMergeWithExistingSessionWidget);
69  mVerticalLayout->addWidget(new LabeledComboBoxWidget(this, mSelectRecordSession->getSessionSelector()));
70 
71  mObscuredListener.reset(new WidgetObscuredListener(this));
72  connect(mObscuredListener.get(), SIGNAL(obscured(bool)), this, SLOT(obscuredSlot(bool)));
73 }
74 
76 {
77  mToolSelectorWidget->setVisible(on);
78 }
79 
81 {
82  return mSelectRecordSession->getSessionSelector();
83 }
84 
85 void RecordTrackingWidget::acquisitionStarted()
86 {
87  mRecordingTool = this->getSuitableRecordingTool();
88 
89  if(!mDrawAqquisitionIn3D)
90  return;
91 
92  ToolRep3DPtr activeRep3D = this->getToolRepIn3DView();
93  if (activeRep3D)
94  {
95  if (!mMergeWithExistingSession->getValue())
96  activeRep3D->getTracer()->clear();
97  activeRep3D->getTracer()->setColor(QColor("magenta"));
98  activeRep3D->getTracer()->start();
99  }
100 }
101 
102 void RecordTrackingWidget::acquisitionStopped()
103 {
104  QString newUid = mAcquisitionService->getLatestSession()->getUid();
105  mSelectRecordSession->getSessionSelector()->setValue(newUid);
106 
107  mServices->patient()->autoSave();
108 
109  ToolRep3DPtr activeRep3D = this->getToolRepIn3DView();
110  if (activeRep3D)
111  {
112  activeRep3D->getTracer()->stop();
113  }
114  mRecordingTool.reset();
115 
116  emit acquisitionCompleted();
117 }
118 
119 void RecordTrackingWidget::acquisitionCancelled()
120 {
121  ToolRep3DPtr activeRep3D = this->getToolRepIn3DView();
122  if (activeRep3D)
123  {
124  activeRep3D->getTracer()->stop();
125  activeRep3D->getTracer()->clear();
126  }
127  mRecordingTool.reset();
128 }
129 
130 void RecordTrackingWidget::onMergeChanged()
131 {
132  QString mergeSession = "";
133  if (mMergeWithExistingSession->getValue())
134  mergeSession = mSelectRecordSession->getSessionSelector()->getValue();
135 
136  mRecordSessionWidget->setCurrentSession(mergeSession);
137 }
138 
139 ToolRep3DPtr RecordTrackingWidget::getToolRepIn3DView()
140 {
141  return mServices->view()->get3DReps(0, 0)->findFirst<ToolRep3D>(mRecordingTool);
142 }
143 
144 void RecordTrackingWidget::obscuredSlot(bool obscured)
145 {
146  if (obscured)
147  mAcquisitionService->cancelRecord();
148 
149  if (!obscured)
150  {
151  connect(mAcquisitionService.get(), &AcquisitionService::started, this, &RecordTrackingWidget::acquisitionStarted);
152  connect(mAcquisitionService.get(), &AcquisitionService::acquisitionStopped, this, &RecordTrackingWidget::acquisitionStopped, Qt::QueuedConnection);
153  connect(mAcquisitionService.get(), &AcquisitionService::cancelled, this, &RecordTrackingWidget::acquisitionCancelled);
154  connect(mToolSelector.get(), &StringPropertySelectTool::changed, this, &RecordTrackingWidget::onToolChanged);
155  connect(mServices->tracking().get(), &TrackingService::activeToolChanged, this, &RecordTrackingWidget::onToolChanged);
156  }
157  else
158  {
159  disconnect(mAcquisitionService.get(), &AcquisitionService::started, this, &RecordTrackingWidget::acquisitionStarted);
160  disconnect(mAcquisitionService.get(), &AcquisitionService::acquisitionStopped, this, &RecordTrackingWidget::acquisitionStopped);
161  disconnect(mAcquisitionService.get(), &AcquisitionService::cancelled, this, &RecordTrackingWidget::acquisitionCancelled);
162  disconnect(mToolSelector.get(), &StringPropertySelectTool::changed, this, &RecordTrackingWidget::onToolChanged);
163  disconnect(mServices->tracking().get(), &TrackingService::activeToolChanged, this, &RecordTrackingWidget::onToolChanged);
164  }
165 
166  mSelectRecordSession->setVisible(!obscured);
167 }
168 
169 void RecordTrackingWidget::onToolChanged()
170 {
171  mSelectRecordSession->setTool(mToolSelector->getTool());
172 }
173 
174 
176 {
177  ToolPtr retval = mToolSelector->getTool();
178  if(!retval)
179  {
180  retval = mServices->tracking()->getActiveTool();
181  if(retval)
182  mToolSelector->setValue(retval->getUid());
183  }
184  return retval;
185 }
186 
188 //used in bronchoscopy navigation to get raw tool data without projection to centerline.
189 {
190  ToolPtr tool = mToolSelector->getTool();
191  if (!tool)
192  return;
193  mSelectRecordSession->setTool(tool);
194  if(useBaseTool)
195  {
196  ToolPtr baseTool = tool->getBaseTool();
197  if(baseTool)
198  mSelectRecordSession->setTool(baseTool);
199  }
200 }
201 
203 {
204  return mSelectRecordSession->getRecordedTrackerData_prMt();
205 }
206 
208 {
209  TimedTransformMap RecordedTrackerData_prMt = this->getRecordedTrackerData_prMt();
210  ToolPtr tool = mToolSelector->getTool();
211  if(!tool)
212  return RecordedTrackerData_prMt;
213  Transform3D tMs = tool->getCalibration_sMt().inverse();
214 
215  TimedTransformMap RecordedTrackerData_prMs = RecordedTrackerData_prMt;
216  for(TimedTransformMap::iterator iter=RecordedTrackerData_prMs.begin(); iter!=RecordedTrackerData_prMs.end(); ++iter)
217  iter->second = iter->second*tMs;
218 
219  return RecordedTrackerData_prMs;
220 }
221 
223 {
224  if(!mMergeWithExistingSessionWidget->isHidden())
225  mMergeWithExistingSessionWidget->hide();
226 }
227 
229 {
230  mDrawAqquisitionIn3D = draw;
231 }
232 
233 } //namespace cx
static BoolPropertyPtr initialize(const QString &uid, QString name, QString help, bool value, QDomNode root=QDomNode())
boost::shared_ptr< class AcquisitionService > AcquisitionServicePtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
TimedTransformMap getRecordedTrackerData_prMt()
StringPropertyPtr getSessionSelector()
Composite widget for string selection.
Display a Tool in 3D.
Definition: cxToolRep3D.h:51
void activeToolChanged(const QString &uId)
boost::shared_ptr< class StringProperty > StringPropertyPtr
void changed()
emit when the underlying data value is changed: The user interface will be updated.
RecordTrackingWidget(XmlOptionFile options, AcquisitionServicePtr acquisitionService, VisServicesPtr services, QString category, QWidget *parent)
TimedTransformMap getRecordedTrackerData_prMs()
static StringPropertySelectToolPtr New(TrackingServicePtr trackingService)
void useBaseToolIfAvailable(bool useBaseTool)
QWidget * sscCreateDataWidget(QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
void setCurrentSession(QString uid)
set a session that the next recording adds to
boost::shared_ptr< class ToolRep3D > ToolRep3DPtr
void acquisitionCompleted()
aquisition complete, and widget internal state is updated accordingly
Helper class for xml files used to store ssc/cx data.
std::map< double, Transform3D > TimedTransformMap
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr