NorMIT-nav  22.09
An IGT application
cxTrackingServiceProxy.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 "cxTrackingServiceProxy.h"
13 
14 #include <boost/bind.hpp>
15 #include <ctkPluginContext.h>
16 #include "cxNullDeleter.h"
17 
18 
19 namespace cx
20 {
21 
22 TrackingServicePtr TrackingServiceProxy::create(ctkPluginContext *pluginContext)
23 {
24  return TrackingServicePtr(new TrackingServiceProxy(pluginContext));
25 }
26 
27 TrackingServiceProxy::TrackingServiceProxy(ctkPluginContext *pluginContext) :
28  mPluginContext(pluginContext),
29  mTrackingService(TrackingService::getNullObject())
30 {
31  this->initServiceListener();
32 }
33 
34 void TrackingServiceProxy::initServiceListener()
35 {
36  mServiceListener.reset(new ServiceTrackerListener<TrackingService>(
37  mPluginContext,
38  boost::bind(&TrackingServiceProxy::onServiceAdded, this, _1),
39  boost::function<void (TrackingService*)>(),
40  boost::bind(&TrackingServiceProxy::onServiceRemoved, this, _1)
41  ));
42  mServiceListener->open();
43 }
44 void TrackingServiceProxy::onServiceAdded(TrackingService* service)
45 {
46  mTrackingService.reset(service, null_deleter());
47 
48  connect(mTrackingService.get(), &TrackingService::stateChanged, this, &TrackingService::stateChanged);
49  connect(mTrackingService.get(), &TrackingService::activeToolChanged, this, &TrackingService::activeToolChanged);
50 
51  emit stateChanged();
52  emit activeToolChanged(mTrackingService->getActiveTool()->getUid());
53 }
54 
55 void TrackingServiceProxy::onServiceRemoved(TrackingService *service)
56 {
57  disconnect(mTrackingService.get(), &TrackingService::stateChanged, this, &TrackingService::stateChanged);
58  disconnect(mTrackingService.get(), &TrackingService::activeToolChanged, this, &TrackingService::activeToolChanged);
59 
60  mTrackingService = TrackingService::getNullObject();
61 
62  emit stateChanged();
63  emit activeToolChanged("");
64 }
65 
67 {
68  return mTrackingService->isNull();
69 }
70 
72 {
73  return mTrackingService->getState();
74 }
75 
77 {
78  mTrackingService->setState(val);
79 }
80 
82 {
83  return mTrackingService->getTool(uid);
84 }
85 
87 {
88  return mTrackingService->getActiveTool();
89 }
90 
91 void TrackingServiceProxy::setActiveTool(const QString& uid)
92 {
93  mTrackingService->setActiveTool(uid);
94 }
95 
97 {
98  mTrackingService->clearActiveTool();
99 }
100 
102 {
103  return mTrackingService->getFirstProbe();
104 }
105 
107 {
108  return mTrackingService->getReferenceTool();
109 }
110 
112 {
113  return mTrackingService->getManualTool();
114 }
115 
117 {
118  return mTrackingService->getTools();
119 }
120 
122 {
123  return mTrackingService->isPlaybackMode();
124 }
125 
127 {
128  mTrackingService->setPlaybackMode(controller);
129 }
130 
132 {
133  return mTrackingService->getSessionHistory(startTime, stopTime);
134 }
135 
137 {
138  mTrackingService->runDummyTool(tool);
139 }
140 
141 std::vector<TrackerConfigurationPtr> TrackingServiceProxy::getConfigurations()
142 {
143  return mTrackingService->getConfigurations();
144 }
145 
146 /*TrackerConfigurationPtr TrackingServiceProxy::getConfiguration(QString trackingSystemImplementation)
147 {
148  return mTrackingService->getConfiguration(trackingSystemImplementation);
149 }*/
150 
152 {
153  return mTrackingService->getConfiguration();
154 }
155 
156 void TrackingServiceProxy::setCurrentTrackingSystemImplementation(QString trackingSystemImplementation)
157 {
158  mTrackingService->setCurrentTrackingSystemImplementation(trackingSystemImplementation);
159 }
160 
162 {
163  return mTrackingService->getCurrentTrackingSystemImplementation();
164 }
165 
167 {
168  mTrackingService->installTrackingSystem(system);
169 }
170 
172 {
173  mTrackingService->unInstallTrackingSystem(system);
174 }
175 
176 std::vector<TrackingSystemServicePtr> TrackingServiceProxy::getTrackingSystems()
177 {
178  return mTrackingService->getTrackingSystems();
179 }
180 
182 {
183  return mTrackingService->resetTimeSynchronization();
184 }
185 
186 } //cx
cx::TrackingServiceProxy::getTrackingSystems
virtual std::vector< TrackingSystemServicePtr > getTrackingSystems()
Definition: cxTrackingServiceProxy.cpp:176
cx::TrackingServiceProxy::clearActiveTool
virtual void clearActiveTool()
Deselect active tool.
Definition: cxTrackingServiceProxy.cpp:96
cx::TrackingServiceProxy::runDummyTool
virtual void runDummyTool(DummyToolPtr tool)
Definition: cxTrackingServiceProxy.cpp:136
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::ServiceTrackerListener
Helper class for listening to services being added, modified and removed.
Definition: cxServiceTrackerListener.h:53
cx::TrackerConfigurationPtr
boost::shared_ptr< class TrackerConfiguration > TrackerConfigurationPtr
Definition: cxTrackerConfiguration.h:24
cx::TrackingService::getNullObject
static TrackingServicePtr getNullObject()
Definition: cxTrackingService.cpp:18
cx::TrackingServiceProxy::setState
virtual void setState(const Tool::State val)
Definition: cxTrackingServiceProxy.cpp:76
cx::TrackingServiceProxy::getSessionHistory
virtual SessionToolHistoryMap getSessionHistory(double startTime, double stopTime)
Definition: cxTrackingServiceProxy.cpp:131
cx::PlaybackTimePtr
boost::shared_ptr< class PlaybackTime > PlaybackTimePtr
Definition: cxTrackingSystemBronchoscopyService.h:42
cx::SessionToolHistoryMap
std::map< ToolPtr, TimedTransformMap > SessionToolHistoryMap
Definition: cxTrackingService.h:31
cx::TrackingServiceProxy::getConfigurations
virtual std::vector< TrackerConfigurationPtr > getConfigurations()
Definition: cxTrackingServiceProxy.cpp:141
cx::TrackingServiceProxy::resetTimeSynchronization
virtual void resetTimeSynchronization()
Reset time synchronization. Used for resetting time synchronization of incoming timestamps in OpenIGT...
Definition: cxTrackingServiceProxy.cpp:181
cx::TrackingServiceProxy::getConfiguration
virtual TrackerConfigurationPtr getConfiguration()
Definition: cxTrackingServiceProxy.cpp:151
cxNullDeleter.h
cx::TrackingServicePtr
boost::shared_ptr< class TrackingService > TrackingServicePtr
Definition: cxToolFilterWidget.h:27
cx::TrackingSystemServicePtr
boost::shared_ptr< class TrackingSystemService > TrackingSystemServicePtr
Definition: cxTrackingImplService.h:36
cx::TrackingServiceProxy::getActiveTool
virtual ToolPtr getActiveTool()
get the tool that has higest priority when tracking
Definition: cxTrackingServiceProxy.cpp:86
cx::TrackingServiceProxy::installTrackingSystem
virtual void installTrackingSystem(TrackingSystemServicePtr system)
Definition: cxTrackingServiceProxy.cpp:166
cx::Tool::State
State
Definition: cxTool.h:72
cx::TrackingService::stateChanged
void stateChanged()
cx::TrackingService::activeToolChanged
void activeToolChanged(const QString &uId)
cx::TrackingServiceProxy::getReferenceTool
virtual ToolPtr getReferenceTool() const
tool used as patient reference
Definition: cxTrackingServiceProxy.cpp:106
cx::TrackingServiceProxy::getTools
virtual ToolMap getTools()
get configured and initialized tools
Definition: cxTrackingServiceProxy.cpp:116
cx::TrackingServiceProxy::getFirstProbe
virtual ToolPtr getFirstProbe()
get the active probe or any if none active
Definition: cxTrackingServiceProxy.cpp:101
cx::TrackingServiceProxy::setActiveTool
virtual void setActiveTool(const QString &uid)
set a tool to be the active tool
Definition: cxTrackingServiceProxy.cpp:91
cx::TrackingServiceProxy::getTool
virtual ToolPtr getTool(const QString &uid)
get a tool
Definition: cxTrackingServiceProxy.cpp:81
cx::TrackingServiceProxy::TrackingServiceProxy
TrackingServiceProxy(ctkPluginContext *pluginContext)
Definition: cxTrackingServiceProxy.cpp:27
cx::ToolPtr
boost::shared_ptr< class Tool > ToolPtr
Definition: cxVideoConnectionWidget.h:43
cx::TrackingServiceProxy::create
static TrackingServicePtr create(ctkPluginContext *pluginContext)
Definition: cxTrackingServiceProxy.cpp:22
cxTrackingServiceProxy.h
cx::TrackingService
Service providing tools and tracking systems.
Definition: cxTrackingService.h:49
cx::TrackingServiceProxy::setCurrentTrackingSystemImplementation
virtual void setCurrentTrackingSystemImplementation(QString trackingSystemImplementation)
Definition: cxTrackingServiceProxy.cpp:156
cx::TrackingServiceProxy::getManualTool
virtual ToolPtr getManualTool()
a mouse-controllable virtual tool that is available even when not tracking.
Definition: cxTrackingServiceProxy.cpp:111
cx::TrackingServiceProxy::setPlaybackMode
virtual void setPlaybackMode(PlaybackTimePtr controller)
Definition: cxTrackingServiceProxy.cpp:126
cx::TrackingServiceProxy::unInstallTrackingSystem
virtual void unInstallTrackingSystem(TrackingSystemServicePtr system)
Definition: cxTrackingServiceProxy.cpp:171
cx::TrackingServiceProxy::isPlaybackMode
virtual bool isPlaybackMode() const
Definition: cxTrackingServiceProxy.cpp:121
cx::DummyToolPtr
boost::shared_ptr< class DummyTool > DummyToolPtr
Definition: cxForwardDeclarations.h:44
cx::TrackingServiceProxy::isNull
bool isNull()
Definition: cxTrackingServiceProxy.cpp:66
cx::TrackingServiceProxy::getState
virtual Tool::State getState() const
Definition: cxTrackingServiceProxy.cpp:71
cx::TrackingServiceProxy::getCurrentTrackingSystemImplementation
virtual QString getCurrentTrackingSystemImplementation()
Definition: cxTrackingServiceProxy.cpp:161
cx::TrackingService::ToolMap
std::map< QString, ToolPtr > ToolMap
Definition: cxTrackingService.h:54