Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxRecordSessionSelector.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 =========================================================================*/
33 
34 #include "cxRecordSessionWidget.h"
35 #include "cxRecordSession.h"
36 #include "cxToolRep3D.h"
37 #include "cxToolTracer.h"
38 #include "cxLogger.h"
39 #include "cxPatientModelService.h"
40 #include "cxViewService.h"
41 #include "cxStringProperty.h"
43 #include "cxTrackingService.h"
44 #include "cxProfile.h"
45 #include "cxHelperWidgets.h"
46 #include "cxRepContainer.h"
49 #include "cxAcquisitionService.h"
50 
51 
52 namespace cx
53 {
54 
57  VisServicesPtr services) :
58  mServices(services),
59  mOptions(options),
60  mAcquisitionService(acquisitionService),
61  mVisible(true)
62 {
63  mSessionSelector = StringProperty::initialize("tracking_session",
64  "Tracking Data",
65  "Select tracker data", "", QStringList(),
66  mOptions.getElement());
67  connect(mAcquisitionService.get(), &AcquisitionService::recordedSessionsChanged, this, &SelectRecordSession::recordedSessionsChanged);
68  connect(mSessionSelector.get(), &StringProperty::changed, this, &SelectRecordSession::showSelectedRecordingInView);
69 
70  this->recordedSessionsChanged();
71 }
72 
74 {
75  this->clearTracer();
76 }
77 
79 {
80  if (tool==mToolOverride)
81  return;
82 
83  mToolOverride = tool;
84 
85  this->showSelectedRecordingInView();
86 }
87 
88 void SelectRecordSession::recordedSessionsChanged()
89 {
90  std::vector<RecordSessionPtr> sessions = mAcquisitionService->getSessions();
91  QStringList uids;
92  std::map<QString, QString> names;
93  for(unsigned i=0; i<sessions.size(); ++i)
94  {
95  QString uid = sessions[i]->getUid();
96  uids << uid;
97  names[uid] = sessions[i]->getHumanDescription();
98  }
99  uids << "";
100  names[""] = "<none>";
101 
102  mSessionSelector->setValueRange(uids);
103  mSessionSelector->setDisplayNames(names);
104 
105  if(mSessionSelector->getValue().isEmpty() && !uids.isEmpty())
106  mSessionSelector->setValue(uids.last());
107 
108  this->showSelectedRecordingInView();
109 }
110 
111 void SelectRecordSession::warnIfNoTrackingDataInSession()
112 {
113  RecordSessionPtr session = this->getSession();
114  ToolPtr tool = this->getTool();
115  if (session && !tool)
116  {
117  CX_LOG_WARNING() << QString("Could not find any tracking data for any loaded tools in session [%2]. ")
118  .arg(session.get() ? session->getHumanDescription() : "NULL");
119  }
120 }
121 
122 RecordSessionPtr SelectRecordSession::getSession()
123 {
124  QString uid = mSessionSelector->getValue();
125  if(!uid.isEmpty())
126  return mAcquisitionService->getSession(uid);
127  return RecordSessionPtr();
128 }
129 
131 {
132  RecordSessionPtr session = this->getSession();
133  ToolPtr tool = this->getTool();
134 
135  TimedTransformMap trackerRecordedData_prMt = RecordSession::getToolHistory_prMt(tool, session, false);
136 
137  return trackerRecordedData_prMt;
138 }
139 
141 {
142  if (mToolOverride)
143  return mToolOverride;
144 
145  RecordSessionPtr session = this->getSession();
146  TrackingService::ToolMap tools = mServices->tracking()->getTools();
147 
148  ToolPtr tool = this->findToolContainingMostDataForSession(tools, session);
149  return tool;
150 }
151 
153 {
154  mVisible = on;
155  this->showSelectedRecordingInView();
156 }
157 
158 ToolPtr SelectRecordSession::findToolContainingMostDataForSession(std::map<QString, ToolPtr> tools, RecordSessionPtr session)
159 {
160  std::map<int,ToolPtr> tooldata;
161 
162  for (TrackingService::ToolMap::iterator i=tools.begin(); i!=tools.end(); ++i)
163  {
164  TimedTransformMap trackerRecordedData_prMt = RecordSession::getToolHistory_prMt(i->second, session, false);
165  tooldata[trackerRecordedData_prMt.size()] = i->second;
166  }
167 
168  if (!tooldata.empty() && (tooldata.rbegin()->first!=0))
169  return tooldata.rbegin()->second;
170 
171  return ToolPtr();
172 }
173 
174 ToolRep3DPtr SelectRecordSession::getToolRepIn3DView(ToolPtr tool)
175 {
176  return mServices->view()->get3DReps(0, 0)->findFirst<ToolRep3D>(tool);
177 }
178 
179 void SelectRecordSession::showSelectedRecordingInView()
180 {
181  this->clearTracer();
182  if (!mVisible)
183  return;
184 
185  this->warnIfNoTrackingDataInSession();
186 
187  TimedTransformMap trackerRecordedData_prMt = this->getRecordedTrackerData_prMt();
188  if (trackerRecordedData_prMt.empty())
189  return;
190 
191  mCurrentTracedTool = this->getTool();
192 
193  ToolRep3DPtr activeRep3D = this->getToolRepIn3DView(mCurrentTracedTool);
194  if(!activeRep3D)
195  return;
196 
197  if(!trackerRecordedData_prMt.empty())
198  {
199  activeRep3D->getTracer()->clear();
200  activeRep3D->getTracer()->setColor(QColor("green"));
201  activeRep3D->getTracer()->addManyPositions(trackerRecordedData_prMt);
202  }
203  else
204  {
205  activeRep3D->getTracer()->clear();
206  }
207 }
208 
209 void SelectRecordSession::clearTracer()
210 {
211  ToolRep3DPtr activeRep3D = this->getToolRepIn3DView(mCurrentTracedTool);
212 
213  if(activeRep3D)
214  {
215  activeRep3D->getTracer()->clear();
216  }
217 
218  mCurrentTracedTool.reset();
219 }
220 
221 } //namespace cx
SelectRecordSession(XmlOptionFile options, AcquisitionServicePtr acquisitionService, VisServicesPtr services)
boost::shared_ptr< class AcquisitionService > AcquisitionServicePtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
QDomElement getElement()
return the current element
static TimedTransformMap getToolHistory_prMt(ToolPtr tool, RecordSessionPtr session, bool verbose)
boost::shared_ptr< class RecordSession > RecordSessionPtr
TimedTransformMap getRecordedTrackerData_prMt()
cxLogicManager_EXPORT AcquisitionServicePtr acquisitionService()
void changed()
emit when the underlying data value is changed: The user interface will be updated.
static StringPropertyPtr initialize(const QString &uid, QString name, QString help, QString value, QStringList range, QDomNode root=QDomNode())
std::map< QString, ToolPtr > ToolMap
#define CX_LOG_WARNING
Definition: cxLogger.h:113
boost::shared_ptr< class ToolRep3D > ToolRep3DPtr
Helper class for xml files used to store ssc/cx data.
std::map< double, Transform3D > TimedTransformMap
boost::shared_ptr< class Tool > ToolPtr