NorMIT-nav  18.04-rc6
An IGT application
cxPlaybackTool.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 "cxPlaybackTool.h"
13 #include "cxTime.h"
14 #include "cxTypeConversions.h"
15 #include "cxPlaybackTime.h"
16 #include "cxManualToolAdapter.h"
17 
18 namespace cx
19 {
20 
22  ToolImpl(base->getUid(), "playback "+base->getName()), mBase(base),
23  mTime(time),
24  mVisible(false)
25 {
26  connect(mTime.get(), SIGNAL(changed()), this, SLOT(timeChangedSlot()));
27 
28  connect(mBase.get(), SIGNAL(toolProbeSector()), this, SIGNAL(toolProbeSector()));
29  connect(mBase.get(), SIGNAL(tooltipOffset(double)), this, SIGNAL(tooltipOffset(double)));
30 }
31 
33 {
34 }
35 
36 void PlaybackTool::timeChangedSlot()
37 {
38  QDateTime time = mTime->getTime();
39  qint64 time_ms = time.toMSecsSinceEpoch();
40 
41  TimedTransformMapPtr positions = mBase->getPositionHistory();
42  if (positions->empty())
43  return;
44 
45  // find last stored time before current time.
46  TimedTransformMap::iterator lastSample = positions->lower_bound(time_ms);
47  if (lastSample!=positions->begin())
48  --lastSample;
49 
50  // interpret as hidden if no samples has been received the last time:
51  qint64 timeout = 200;
52  bool visible = (lastSample!=positions->end()) && (fabs(time_ms - lastSample->first) < timeout);
53 
54  // change visibility if applicable
55  if (mVisible!=visible)
56  {
57  mVisible = visible;
58  emit toolVisible(mVisible);
59  }
60 
61  // emit new position if visible
62  if (this->getVisible())
63  {
64  m_rMpr = lastSample->second;
65  mTimestamp = lastSample->first;
66  emit toolTransformAndTimestamp(m_rMpr, mTimestamp);
67  }
68 }
69 
70 std::set<Tool::Type> PlaybackTool::getTypes() const
71 {
72  return mBase->getTypes();
73 }
74 
76 {
77  return mBase->getGraphicsPolyData();
78 }
79 
81 {
82  return m_rMpr;
83 }
84 
86 {
87  return mVisible;
88 }
89 
90 QString PlaybackTool::getUid() const
91 {
92  return mUid;
93 }
94 
95 QString PlaybackTool::getName() const
96 {
97  return mName;
98 }
99 
101 {
102  return mBase->isCalibrated();
103 }
104 
106 {
107  return mTimestamp;
108 }
109 
110 // Just use the tool tip offset from the tool manager
112 {
113  return mBase->getTooltipOffset();
114 }
115 
116 // Just use the tool tip offset from the tool manager
118 {
119  mBase->setTooltipOffset(val);
120 }
121 
123 {
124  return mBase->getCalibration_sMt();
125 }
126 
127 std::map<int, Vector3D> PlaybackTool::getReferencePoints() const
128 {
129  return mBase->getReferencePoints();
130 }
131 
133 {
134  return true;
135 }
136 
137 void PlaybackTool::set_prMt(const Transform3D& prMt, double timestamp)
138 {
139 
140 }
141 
143 {
144 
145 }
146 
147 
148 } /* namespace cx */
virtual Transform3D get_prMt() const
virtual bool getVisible() const
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Common functionality for Tool subclasses.
Definition: cxToolImpl.h:30
void toolProbeSector()
void toolTransformAndTimestamp(Transform3D matrix, double timestamp)
virtual std::set< Type > getTypes() const
virtual void setVisible(bool vis)
if available for this type, set visibility
QString mUid
Definition: cxTool.h:147
boost::shared_ptr< class PlaybackTime > PlaybackTimePtr
virtual double getTooltipOffset() const
get a virtual offset extending from the tool tip.
virtual bool isInitialized() const
void toolVisible(bool visible)
virtual QString getName() const
QString mName
Definition: cxTool.h:148
void tooltipOffset(double offset)
boost::shared_ptr< TimedTransformMap > TimedTransformMapPtr
Definition: cxTool.h:36
virtual Transform3D getCalibration_sMt() const
get the calibration transform from tool space to sensor space (where the spheres or similar live) ...
virtual ~PlaybackTool()
virtual double getTimestamp() const
latest valid timestamp for the position matrix. 0 means indeterminate (for f.ex. manual tools) ...
virtual void setTooltipOffset(double val)
set a virtual offset extending from the tool tip.
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
virtual QString getUid() const
virtual bool isCalibrated() const
a tool may not be calibrated, then no tracking is allowed
virtual std::map< int, Vector3D > getReferencePoints() const
Get the optional reference points from this tool.
virtual void set_prMt(const Transform3D &prMt, double timestamp)
if available for this type, set pos, ts<0 means use current time
PlaybackTool(ToolPtr base, PlaybackTimePtr time)
virtual vtkPolyDataPtr getGraphicsPolyData() const
get geometric 3D description
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr