NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxPlaybackTool.h"
34 #include "cxTime.h"
35 #include "cxTypeConversions.h"
36 #include "cxPlaybackTime.h"
37 #include "cxManualToolAdapter.h"
38 
39 namespace cx
40 {
41 
43  ToolImpl(base->getUid(), "playback "+base->getName()), mBase(base),
44  mTime(time),
45  mVisible(false)
46 {
47  connect(mTime.get(), SIGNAL(changed()), this, SLOT(timeChangedSlot()));
48 
49  connect(mBase.get(), SIGNAL(toolProbeSector()), this, SIGNAL(toolProbeSector()));
50  connect(mBase.get(), SIGNAL(tooltipOffset(double)), this, SIGNAL(tooltipOffset(double)));
51 }
52 
54 {
55 }
56 
57 void PlaybackTool::timeChangedSlot()
58 {
59  QDateTime time = mTime->getTime();
60  qint64 time_ms = time.toMSecsSinceEpoch();
61 
62  TimedTransformMapPtr positions = mBase->getPositionHistory();
63  if (positions->empty())
64  return;
65 
66  // find last stored time before current time.
67  TimedTransformMap::iterator lastSample = positions->lower_bound(time_ms);
68  if (lastSample!=positions->begin())
69  --lastSample;
70 
71  // interpret as hidden if no samples has been received the last time:
72  qint64 timeout = 200;
73  bool visible = (lastSample!=positions->end()) && (fabs(time_ms - lastSample->first) < timeout);
74 
75  // change visibility if applicable
76  if (mVisible!=visible)
77  {
78  mVisible = visible;
79  emit toolVisible(mVisible);
80  }
81 
82  // emit new position if visible
83  if (this->getVisible())
84  {
85  m_rMpr = lastSample->second;
86  mTimestamp = lastSample->first;
87  emit toolTransformAndTimestamp(m_rMpr, mTimestamp);
88  }
89 }
90 
91 std::set<Tool::Type> PlaybackTool::getTypes() const
92 {
93  return mBase->getTypes();
94 }
95 
97 {
98  return mBase->getGraphicsPolyData();
99 }
100 
102 {
103  return m_rMpr;
104 }
105 
107 {
108  return mVisible;
109 }
110 
111 QString PlaybackTool::getUid() const
112 {
113  return mUid;
114 }
115 
116 QString PlaybackTool::getName() const
117 {
118  return mName;
119 }
120 
122 {
123  return mBase->isCalibrated();
124 }
125 
127 {
128  return mTimestamp;
129 }
130 
131 // Just use the tool tip offset from the tool manager
133 {
134  return mBase->getTooltipOffset();
135 }
136 
137 // Just use the tool tip offset from the tool manager
139 {
140  mBase->setTooltipOffset(val);
141 }
142 
144 {
145  return mBase->getCalibration_sMt();
146 }
147 
148 std::map<int, Vector3D> PlaybackTool::getReferencePoints() const
149 {
150  return mBase->getReferencePoints();
151 }
152 
154 {
155  return true;
156 }
157 
158 void PlaybackTool::set_prMt(const Transform3D& prMt, double timestamp)
159 {
160 
161 }
162 
164 {
165 
166 }
167 
168 
169 } /* 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:50
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:168
boost::shared_ptr< class PlaybackTime > PlaybackTimePtr
virtual double getTooltipOffset() const
get a virtual offset extending from the tool tip.
virtual bool isInitialized() const
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
void toolVisible(bool visible)
virtual QString getName() const
QString mName
Definition: cxTool.h:169
void tooltipOffset(double offset)
boost::shared_ptr< TimedTransformMap > TimedTransformMapPtr
Definition: cxTool.h:57
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.
virtual QString getUid() const
virtual bool isCalibrated() const
a tool may not be calibrated, then no tracking i 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
boost::shared_ptr< class Tool > ToolPtr