Fraxinus  22.09
An IGT application
cxToolImpl.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 "cxToolImpl.h"
13 
14 #include <vtkSTLReader.h>
15 #include <QDir>
16 #include <vtkConeSource.h>
17 
18 #include "cxTypeConversions.h"
19 #include "cxLogger.h"
20 
21 namespace cx
22 {
23 
24 ToolImpl::ToolImpl(const QString& uid, const QString& name) :
25  Tool(uid, name),
26  mPositionHistory(new TimedTransformMap()),
27  m_prMt(Transform3D::Identity()),
28  mPolyData(NULL),
29  mTooltipOffset(0)
30 {
31 }
32 
34 {
35 
36 }
37 
38 std::set<Tool::Type> ToolImpl::getTypes() const
39 {
41  std::set<Type> retval;
42 
43  if (toolStructure->mIsReference)
44  retval.insert(Tool::TOOL_REFERENCE);
45  if (toolStructure->mIsPointer)
46  retval.insert(Tool::TOOL_POINTER);
47  if (toolStructure->mIsProbe)
48  retval.insert(Tool::TOOL_US_PROBE);
49 
50  return retval;
51 }
52 
54 {
55  if (mMetadata.empty())
56  return ToolPositionMetadata();
57  return mMetadata.rbegin()->second;
58 }
59 
60 const std::map<double, ToolPositionMetadata>& ToolImpl::getMetadataHistory()
61 {
62  return mMetadata;
63 }
64 
66 {
67  return mTooltipOffset;
68 }
69 
71 {
72  if (similar(val, mTooltipOffset))
73  return;
74  mTooltipOffset = val;
75  emit tooltipOffset(mTooltipOffset);
76 }
77 
79 {
80  return mPositionHistory;
81 }
82 
83 TimedTransformMap ToolImpl::getSessionHistory(double startTime, double stopTime)
84 {
85  TimedTransformMap::iterator startIt = mPositionHistory->lower_bound(startTime);
86  TimedTransformMap::iterator stopIt = mPositionHistory->upper_bound(stopTime);
87 
88  TimedTransformMap retval(startIt, stopIt);
89  return retval;
90 }
91 
93 {
94  return m_prMt;
95 }
96 
98 {
99  return ToolPtr();
100 }
101 
102 void ToolImpl::set_prMt(const Transform3D& prMt, double timestamp)
103 {
104  if (mPositionHistory->count(timestamp))
105  {
106  if (similar(mPositionHistory->find(timestamp)->second, prMt))
107  return;
108  }
109 
110  m_prMt = prMt;
111  // Store positions in history, but only if visible - the history has no concept of visibility
112  if (this->getVisible())
113  (*mPositionHistory)[timestamp] = m_prMt;
114  emit toolTransformAndTimestamp(m_prMt, timestamp);
115 }
116 
118 {
119  mTrackingPositionFilter = filter;
120 }
121 
123 {
124  QString toolGraphicsFileName = this->getToolFileToolStructure()->mGraphicsFileName;
125  QDir dir;
126  if (!toolGraphicsFileName.isEmpty()
127  && dir.exists(toolGraphicsFileName))
128  {
129  vtkSTLReaderPtr reader = vtkSTLReaderPtr::New();
130  reader->SetFileName(cstring_cast(toolGraphicsFileName));
131  reader->Update();
132  mPolyData = reader->GetOutput();
133  }
134  else
135  {
137  }
138 }
139 
141 {
142  return mPolyData;
143 }
144 
146 {
147  return this->getReferencePoints().count(id);
148 }
149 
150 std::map<QString, Vector3D> ToolImpl::getReferencePoints() const
151 {
152  return getToolFileToolStructure()->mReferencePoints;
153 }
154 
155 } // namespace cx
156 
TimedTransformMapPtr mPositionHistory
Definition: cxToolImpl.h:60
boost::shared_ptr< ToolInternalStructure > ToolInternalStructurePtr
TrackingPositionFilterPtr mTrackingPositionFilter
Definition: cxToolImpl.h:62
virtual ToolPositionMetadata getMetadata() const
Definition: cxToolImpl.cpp:53
virtual bool getVisible() const =0
virtual ToolPtr getBaseTool()
Definition: cxToolImpl.cpp:97
Interface to a tool, i.e. a pointer, US probe or similar.
Definition: cxTool.h:61
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
vtkPolyDataPtr mPolyData
the polydata used to represent the tool graphically
Definition: cxToolImpl.h:64
virtual double getTooltipOffset() const
get a virtual offset extending from the tool tip.
Definition: cxToolImpl.cpp:65
cstring_cast_Placeholder cstring_cast(const T &val)
void toolTransformAndTimestamp(Transform3D matrix, double timestamp)
virtual void resetTrackingPositionFilter(TrackingPositionFilterPtr filter)
Definition: cxToolImpl.cpp:117
Reference tool.
Definition: cxTool.h:84
virtual const std::map< double, ToolPositionMetadata > & getMetadataHistory()
Definition: cxToolImpl.cpp:60
virtual ToolFileParser::ToolInternalStructurePtr getToolFileToolStructure() const
Definition: cxToolImpl.h:68
virtual TimedTransformMap getSessionHistory(double startTime, double stopTime)
Definition: cxToolImpl.cpp:83
virtual ~ToolImpl()
Definition: cxToolImpl.cpp:33
void tooltipOffset(double offset)
boost::shared_ptr< TimedTransformMap > TimedTransformMapPtr
Definition: cxTool.h:36
vtkSmartPointer< class vtkSTLReader > vtkSTLReaderPtr
virtual TimedTransformMapPtr getPositionHistory()
get historical positions
Definition: cxToolImpl.cpp:78
virtual Transform3D get_prMt() const
Definition: cxToolImpl.cpp:92
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
std::map< double, ToolPositionMetadata > mMetadata
Definition: cxToolImpl.h:63
static vtkPolyDataPtr createDefaultPolyDataCone()
Definition: cxTool.cpp:20
virtual void set_prMt(const Transform3D &prMt, double timestamp)
if available for this type, set pos, ts<0 means use current time
Definition: cxToolImpl.cpp:102
virtual std::map< QString, Vector3D > getReferencePoints() const
Get the optional reference points from this tool.
Definition: cxToolImpl.cpp:150
virtual void setTooltipOffset(double val)
set a virtual offset extending from the tool tip.
Definition: cxToolImpl.cpp:70
boost::shared_ptr< class TrackingPositionFilter > TrackingPositionFilterPtr
Definition: cxTool.h:37
ToolImpl(const QString &uid="", const QString &name="")
Definition: cxToolImpl.cpp:24
virtual std::set< Type > getTypes() const
Definition: cxToolImpl.cpp:38
virtual vtkPolyDataPtr getGraphicsPolyData() const
get geometric 3D description
Definition: cxToolImpl.cpp:140
Ultrasond probe. The tool has a Probe subinterface with a sector and a video stream.
Definition: cxTool.h:87
void createToolGraphic()
Definition: cxToolImpl.cpp:122
Navigation pointer. Pointing functionality such as tool offset.
Definition: cxTool.h:86
virtual bool hasReferencePointWithId(QString id)
Definition: cxToolImpl.cpp:145
std::map< double, Transform3D > TimedTransformMap
Transform3D m_prMt
the transform from the tool to the patient reference
Definition: cxToolImpl.h:61
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr