Fraxinus  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
virtual void setCalibration_sMt(Transform3D calibration)
requests to use the calibration and replaces the tools calibration file
virtual const std::map< double, ToolPositionMetadata > & getMetadataHistory()
Definition: cxToolProxy.cpp:85
virtual Transform3D get_prMt() const
virtual double getTooltipOffset() const
get a virtual offset extending from the tool tip.
virtual TimedTransformMapPtr getPositionHistory()
get historical positions
Definition: cxToolProxy.cpp:75
virtual vtkPolyDataPtr getGraphicsPolyData() const
get geometric 3D description
Definition: cxToolProxy.cpp:70
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
virtual void set_prMt(const Transform3D &prMt, double timestamp)
if available for this type, set pos, ts<0 means use current time
virtual void setVisible(bool vis)
if available for this type, set visibility
virtual bool getVisible() const
Definition: cxToolProxy.cpp:90
virtual bool hasReferencePointWithId(QString id)
virtual TimedTransformMap getSessionHistory(double startTime, double stopTime)
virtual QString getUid() const
static ToolPtr getNullObject()
Definition: cxTool.cpp:44
virtual QString getName() const
static TrackingServicePtr getNullObject()
virtual bool isNull()
boost::shared_ptr< Probe > ProbePtr
Definition: cxProbe.h:72
virtual std::set< Type > getTypes() const
Definition: cxToolProxy.cpp:65
boost::shared_ptr< TimedTransformMap > TimedTransformMapPtr
Definition: cxTool.h:36
virtual void resetTrackingPositionFilter(TrackingPositionFilterPtr filter)
Formatting class for debug printing of the ssc library.
Definition: cxIndent.h:28
virtual void setTooltipOffset(double val)
set a virtual offset extending from the tool tip.
virtual double getTimestamp() const
latest valid timestamp for the position matrix. 0 means indeterminate (for f.ex. manual tools) ...
Service providing tools and tracking systems.
virtual ToolPtr getBaseTool()
virtual ToolPositionMetadata getMetadata() const
Definition: cxToolProxy.cpp:80
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Helper class for listening to services being added, modified and removed.
virtual bool isInitialized() const
Definition: cxToolProxy.cpp:95
virtual Transform3D getCalibration_sMt() const
get the calibration transform from tool space to sensor space (where the spheres or similar live) ...
virtual ProbePtr getProbe() const
additional information if the tool represents an US Probe. Extends getProbeSector() ...
static ToolPtr create(ToolPtr base, ctkPluginContext *pluginContext)
Definition: cxToolProxy.cpp:10
boost::shared_ptr< class TrackingPositionFilter > TrackingPositionFilterPtr
Definition: cxTool.h:37
virtual void printSelf(std::ostream &os, Indent indent)
dump internal debug data
virtual std::map< QString, Vector3D > getReferencePoints() const
Get the optional reference points from this tool.
virtual bool isCalibrated() const
a tool may not be calibrated, then no tracking is allowed
std::map< double, Transform3D > TimedTransformMap
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr