NorMIT-nav  2023.01.05-dev+develop.0da12
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<QString, 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 */
cx::PlaybackTool::getReferencePoints
virtual std::map< QString, Vector3D > getReferencePoints() const
Definition: cxPlaybackTool.cpp:127
cx::PlaybackTool::getVisible
virtual bool getVisible() const
Definition: cxPlaybackTool.cpp:85
cxPlaybackTime.h
cx::Tool::toolTransformAndTimestamp
void toolTransformAndTimestamp(Transform3D matrix, double timestamp)
cx::Tool::toolVisible
void toolVisible(bool visible)
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::PlaybackTool::getTooltipOffset
virtual double getTooltipOffset() const
Definition: cxPlaybackTool.cpp:111
cx::PlaybackTool::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: cxPlaybackTool.cpp:137
cx::PlaybackTool::~PlaybackTool
virtual ~PlaybackTool()
Definition: cxPlaybackTool.cpp:32
cx::PlaybackTimePtr
boost::shared_ptr< class PlaybackTime > PlaybackTimePtr
Definition: cxTrackingSystemBronchoscopyService.h:42
cx::PlaybackTool::getTimestamp
virtual double getTimestamp() const
latest valid timestamp for the position matrix. 0 means indeterminate (for f.ex. manual tools)
Definition: cxPlaybackTool.cpp:105
cx::PlaybackTool::get_prMt
virtual Transform3D get_prMt() const
Definition: cxPlaybackTool.cpp:80
cx::PlaybackTool::getCalibration_sMt
virtual Transform3D getCalibration_sMt() const
get the calibration transform from tool space to sensor space (where the spheres or similar live)
Definition: cxPlaybackTool.cpp:122
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::PlaybackTool::isCalibrated
virtual bool isCalibrated() const
a tool may not be calibrated, then no tracking is allowed
Definition: cxPlaybackTool.cpp:100
cx::Tool::mUid
QString mUid
Definition: cxTool.h:149
cxTypeConversions.h
cx::Tool::toolProbeSector
void toolProbeSector()
cx::PlaybackTool::getUid
virtual QString getUid() const
Definition: cxPlaybackTool.cpp:90
cx::TimedTransformMapPtr
boost::shared_ptr< TimedTransformMap > TimedTransformMapPtr
Definition: cxTool.h:36
cx::vtkPolyDataPtr
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Definition: cxCenterlineRegistration.h:42
cx::Tool::tooltipOffset
void tooltipOffset(double offset)
cxTime.h
cx::PlaybackTool::PlaybackTool
PlaybackTool(ToolPtr base, PlaybackTimePtr time)
Definition: cxPlaybackTool.cpp:21
cx::ToolPtr
boost::shared_ptr< class Tool > ToolPtr
Definition: cxVideoConnectionWidget.h:43
cx::PlaybackTool::getName
virtual QString getName() const
Definition: cxPlaybackTool.cpp:95
cx::PlaybackTool::setVisible
virtual void setVisible(bool vis)
if available for this type, set visibility
Definition: cxPlaybackTool.cpp:142
cx::ToolImpl
Common functionality for Tool subclasses.
Definition: cxToolImpl.h:30
cx::Tool::mName
QString mName
Definition: cxTool.h:150
cx::PlaybackTool::getTypes
virtual std::set< Type > getTypes() const
Definition: cxPlaybackTool.cpp:70
cx::PlaybackTool::isInitialized
virtual bool isInitialized() const
Definition: cxPlaybackTool.cpp:132
cxManualToolAdapter.h
cx::PlaybackTool::setTooltipOffset
virtual void setTooltipOffset(double val)
Definition: cxPlaybackTool.cpp:117
cxPlaybackTool.h
cx::PlaybackTool::getGraphicsPolyData
virtual vtkPolyDataPtr getGraphicsPolyData() const
get geometric 3D description
Definition: cxPlaybackTool.cpp:75