NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxToolProxy.cpp
Go to the documentation of this file.
1 #include "cxToolProxy.h"
2 #include "boost/bind.hpp"
3 #include "cxNullDeleter.h"
4 #include "cxTrackingService.h"
5 #include "cxTypeConversions.h"
6 
7 namespace cx
8 {
9 
10 ToolPtr ToolProxy::create(ToolPtr base, ctkPluginContext *pluginContext)
11 {
12  return boost::shared_ptr<ToolProxy>(new ToolProxy(base, pluginContext));
13 }
14 
15 ToolProxy::ToolProxy(ToolPtr base, ctkPluginContext *pluginContext)
16 {
17  mTool = base;
18  mPluginContext = pluginContext;
19  this->initServiceListener();
20 }
21 
22 void ToolProxy::initServiceListener()
23 {
24  mServiceListener.reset(new ServiceTrackerListener<TrackingService>(
25  mPluginContext,
26  boost::bind(&ToolProxy::onServiceAdded, this, _1),
27  boost::function<void (TrackingService*)>(),
28  boost::bind(&ToolProxy::onServiceRemoved, this, _1)
29  ));
30  mServiceListener->open();
31 }
32 
33 void ToolProxy::onServiceAdded(TrackingService* service)
34 {
35  mTrackingService.reset(service, null_deleter());
36 
37  connect(mTrackingService.get(), &TrackingService::stateChanged, this, &ToolProxy::onStateChanged);
38 
39  this->checkToolValidity();
40 }
41 
42 void ToolProxy::onServiceRemoved(TrackingService *service)
43 {
44  mTrackingService = TrackingService::getNullObject();
45  mTool = Tool::getNullObject();
46  // emit changed signals
47 }
48 
49 void ToolProxy::onStateChanged()
50 {
51  this->checkToolValidity();
52 }
53 
54 void ToolProxy::checkToolValidity()
55 {
56  if (mTool != mTrackingService->getTool(mTool->getUid()))
57  {
58  std::cout << "disabling tool reference for " << mTool->getUid() << ", [currently disabled]" << std::endl;
59  // enable this when tool manager is a first-class plugin
60  // mTool = Tool::getNullObject();
61  // emit changed signals
62  }
63 }
64 
65 std::set<Tool::Type> ToolProxy::getTypes() const
66 {
67  return mTool->getTypes();
68 }
69 
71 {
72  return mTool->getGraphicsPolyData();
73 }
74 
76 {
77  return mTool->getPositionHistory();
78 }
79 
81 {
82  return mTool->getMetadata();
83 }
84 
85 const std::map<double, ToolPositionMetadata>& ToolProxy::getMetadataHistory()
86 {
87  return mTool->getMetadataHistory();
88 }
89 
91 {
92  return mTool->getVisible();
93 }
94 
96 {
97  return mTool->isInitialized();
98 }
99 
100 QString ToolProxy::getUid() const
101 {
102  return mTool->getUid();
103 }
104 
105 
106 QString ToolProxy::getName() const
107 {
108  return mTool->getName();
109 }
110 
112 {
113  return mTool->isCalibrated();
114 }
116 {
117  return mTool->getCalibration_sMt();
118 }
119 
121 {
122  mTool->setCalibration_sMt(calibration);
123 }
124 
126 {
127  return mTool->getProbe();
128 }
129 
131 {
132  return mTool->getTimestamp();
133 }
134 
135 void ToolProxy::printSelf(std::ostream &os, Indent indent)
136 {
137  mTool->printSelf(os, indent);
138 }
139 
141 {
142  return mTool->getTooltipOffset();
143 }
144 
146 {
147  mTool->setTooltipOffset(val);
148 }
149 
150 std::map<QString, Vector3D> ToolProxy::getReferencePoints() const
151 {
152  return mTool->getReferencePoints();
153 }
154 
156 {
157  return mTool->hasReferencePointWithId(id);
158 }
159 
160 TimedTransformMap ToolProxy::getSessionHistory(double startTime, double stopTime)
161 {
162  return mTool->getSessionHistory(startTime, stopTime);
163 }
164 
166 {
167  return mTool->get_prMt();
168 }
169 
171 {
172  mTool->resetTrackingPositionFilter(filter);
173 }
174 
175 void ToolProxy::set_prMt(const Transform3D& prMt, double timestamp)
176 {
177  mTool->set_prMt(prMt, timestamp);
178 }
179 
180 void ToolProxy::setVisible(bool vis)
181 {
182  mTool->setVisible(vis);
183 }
184 
186 {
187  return mTool->getBaseTool();
188 }
189 
190 
192 {
193  return mTool->isNull();
194 }
195 
196 } // namespace cx
cx::ToolProxy::get_prMt
virtual Transform3D get_prMt() const
Definition: cxToolProxy.cpp:165
cx::ToolProxy::create
static ToolPtr create(ToolPtr base, ctkPluginContext *pluginContext)
Definition: cxToolProxy.cpp:10
cx::ToolProxy::getBaseTool
virtual ToolPtr getBaseTool()
Definition: cxToolProxy.cpp:185
cx::ToolProxy::getProbe
virtual ProbePtr getProbe() const
Definition: cxToolProxy.cpp:125
cx::ToolProxy::isNull
virtual bool isNull()
Definition: cxToolProxy.cpp:191
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::ToolProxy::getVisible
virtual bool getVisible() const
Definition: cxToolProxy.cpp:90
cx::ToolProxy::getUid
virtual QString getUid() const
Definition: cxToolProxy.cpp:100
cx::TrackingService::getNullObject
static TrackingServicePtr getNullObject()
Definition: cxTrackingService.cpp:18
cx::ToolProxy::resetTrackingPositionFilter
virtual void resetTrackingPositionFilter(TrackingPositionFilterPtr filter)
Definition: cxToolProxy.cpp:170
cx::ToolProxy::getReferencePoints
virtual std::map< QString, Vector3D > getReferencePoints() const
Definition: cxToolProxy.cpp:150
cx::TrackingPositionFilterPtr
boost::shared_ptr< class TrackingPositionFilter > TrackingPositionFilterPtr
Definition: cxTool.h:37
cx::ToolProxy::getMetadataHistory
virtual const std::map< double, ToolPositionMetadata > & getMetadataHistory()
Definition: cxToolProxy.cpp:85
cx::ToolProxy::getTypes
virtual std::set< Type > getTypes() const
Definition: cxToolProxy.cpp:65
cx::ToolProxy::getName
virtual QString getName() const
Definition: cxToolProxy.cpp:106
cx::ToolProxy::getMetadata
virtual ToolPositionMetadata getMetadata() const
Definition: cxToolProxy.cpp:80
cx::ToolProxy::isInitialized
virtual bool isInitialized() const
Definition: cxToolProxy.cpp:95
cxToolProxy.h
cx::ToolProxy::getGraphicsPolyData
virtual vtkPolyDataPtr getGraphicsPolyData() const
get geometric 3D description
Definition: cxToolProxy.cpp:70
cx::ToolProxy::set_prMt
virtual void set_prMt(const Transform3D &prMt, double timestamp)
if available for this type, set pos, ts<0 means use current time
Definition: cxToolProxy.cpp:175
cx::ToolProxy::isCalibrated
virtual bool isCalibrated() const
a tool may not be calibrated, then no tracking is allowed
Definition: cxToolProxy.cpp:111
cx::ToolProxy
Definition: cxToolProxy.h:27
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cxNullDeleter.h
cx::ToolProxy::setVisible
virtual void setVisible(bool vis)
if available for this type, set visibility
Definition: cxToolProxy.cpp:180
cx::Tool::getNullObject
static ToolPtr getNullObject()
Definition: cxTool.cpp:44
cx::TimedTransformMap
std::map< double, Transform3D > TimedTransformMap
Definition: cxRecordSession.h:36
cxTypeConversions.h
cx::TrackingService::stateChanged
void stateChanged()
cx::ToolProxy::getTimestamp
virtual double getTimestamp() const
latest valid timestamp for the position matrix. 0 means indeterminate (for f.ex. manual tools)
Definition: cxToolProxy.cpp:130
cx::TimedTransformMapPtr
boost::shared_ptr< TimedTransformMap > TimedTransformMapPtr
Definition: cxTool.h:36
cx::vtkPolyDataPtr
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Definition: cxCenterlineRegistration.h:42
cx::ToolProxy::setCalibration_sMt
virtual void setCalibration_sMt(Transform3D calibration)
Definition: cxToolProxy.cpp:120
cx::ToolPositionMetadata
Definition: cxTool.h:43
cx::ToolProxy::getSessionHistory
virtual TimedTransformMap getSessionHistory(double startTime, double stopTime)
Definition: cxToolProxy.cpp:160
cx::ToolPtr
boost::shared_ptr< class Tool > ToolPtr
Definition: cxVideoConnectionWidget.h:43
cx::ToolProxy::getPositionHistory
virtual TimedTransformMapPtr getPositionHistory()
get historical positions
Definition: cxToolProxy.cpp:75
cx::ToolProxy::printSelf
virtual void printSelf(std::ostream &os, Indent indent)
Definition: cxToolProxy.cpp:135
cx::ToolProxy::getCalibration_sMt
virtual Transform3D getCalibration_sMt() const
get the calibration transform from tool space to sensor space (where the spheres or similar live)
Definition: cxToolProxy.cpp:115
cx::Indent
Formatting class for debug printing of the ssc library.
Definition: cxIndent.h:28
cxTrackingService.h
cx::ToolProxy::hasReferencePointWithId
virtual bool hasReferencePointWithId(QString id)
Definition: cxToolProxy.cpp:155
cx::ToolProxy::getTooltipOffset
virtual double getTooltipOffset() const
Definition: cxToolProxy.cpp:140
cx::ProbePtr
boost::shared_ptr< Probe > ProbePtr
Definition: cxProbe.h:72
cx::ToolProxy::setTooltipOffset
virtual void setTooltipOffset(double val)
Definition: cxToolProxy.cpp:145