Fraxinus  18.10
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 
97 void ToolImpl::set_prMt(const Transform3D& prMt, double timestamp)
98 {
99  if (mPositionHistory->count(timestamp))
100  {
101  if (similar(mPositionHistory->find(timestamp)->second, prMt))
102  return;
103  }
104 
105  m_prMt = prMt;
106  // Store positions in history, but only if visible - the history has no concept of visibility
107  if (this->getVisible())
108  (*mPositionHistory)[timestamp] = m_prMt;
109  emit toolTransformAndTimestamp(m_prMt, timestamp);
110 }
111 
113 {
114  mTrackingPositionFilter = filter;
115 }
116 
118 {
119  QString toolGraphicsFileName = this->getToolFileToolStructure()->mGraphicsFileName;
120  QDir dir;
121  if (!toolGraphicsFileName.isEmpty()
122  && dir.exists(toolGraphicsFileName))
123  {
124  vtkSTLReaderPtr reader = vtkSTLReaderPtr::New();
125  reader->SetFileName(cstring_cast(toolGraphicsFileName));
126  reader->Update();
127  mPolyData = reader->GetOutput();
128  }
129  else
130  {
132  }
133 }
134 
136 {
137  return mPolyData;
138 }
139 
141 {
142  return this->getReferencePoints().count(id);
143 }
144 
145 std::map<int, Vector3D> ToolImpl::getReferencePoints() const
146 {
147  return getToolFileToolStructure()->mReferencePoints;
148 }
149 
150 } // namespace cx
151 
TimedTransformMapPtr mPositionHistory
Definition: cxToolImpl.h:59
boost::shared_ptr< ToolInternalStructure > ToolInternalStructurePtr
TrackingPositionFilterPtr mTrackingPositionFilter
Definition: cxToolImpl.h:61
virtual ToolPositionMetadata getMetadata() const
Definition: cxToolImpl.cpp:53
virtual bool getVisible() const =0
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:63
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:112
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:67
virtual std::map< int, Vector3D > getReferencePoints() const
Get the optional reference points from this tool.
Definition: cxToolImpl.cpp:145
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:62
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:97
virtual bool hasReferencePointWithId(int id)
Definition: cxToolImpl.cpp:140
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:135
Ultrasond probe. The tool has a Probe subinterface with a sector and a video stream.
Definition: cxTool.h:87
void createToolGraphic()
Definition: cxToolImpl.cpp:117
Navigation pointer. Pointing functionality such as tool offset.
Definition: cxTool.h:86
std::map< double, Transform3D > TimedTransformMap
Transform3D m_prMt
the transform from the tool to the patient reference
Definition: cxToolImpl.h:60
Namespace for all CustusX production code.