NorMIT-nav  2023.01.05-dev+develop.0da12
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 
cx::Tool
Interface to a tool, i.e. a pointer, US probe or similar.
Definition: cxTool.h:61
cxLogger.h
cx::ToolImpl::getBaseTool
virtual ToolPtr getBaseTool()
Definition: cxToolImpl.cpp:97
cx::Tool::getVisible
virtual bool getVisible() const =0
cx::Tool::toolTransformAndTimestamp
void toolTransformAndTimestamp(Transform3D matrix, double timestamp)
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
vtkSTLReaderPtr
vtkSmartPointer< class vtkSTLReader > vtkSTLReaderPtr
Definition: vtkForwardDeclarations.h:131
cx::ToolImpl::getTooltipOffset
virtual double getTooltipOffset() const
Definition: cxToolImpl.cpp:65
cx::ToolImpl::getToolFileToolStructure
virtual ToolFileParser::ToolInternalStructurePtr getToolFileToolStructure() const
Definition: cxToolImpl.h:68
cx::ToolImpl::getMetadataHistory
virtual const std::map< double, ToolPositionMetadata > & getMetadataHistory()
Definition: cxToolImpl.cpp:60
cstring_cast
cstring_cast_Placeholder cstring_cast(const T &val)
Definition: cxTypeConversions.h:69
cx::Tool::TOOL_POINTER
@ TOOL_POINTER
Navigation pointer. Pointing functionality such as tool offset.
Definition: cxTool.h:86
cx::ToolImpl::mPositionHistory
TimedTransformMapPtr mPositionHistory
Definition: cxToolImpl.h:60
cx::ToolImpl::hasReferencePointWithId
virtual bool hasReferencePointWithId(QString id)
Definition: cxToolImpl.cpp:145
cx::ToolImpl::getReferencePoints
virtual std::map< QString, Vector3D > getReferencePoints() const
Definition: cxToolImpl.cpp:150
cx::TrackingPositionFilterPtr
boost::shared_ptr< class TrackingPositionFilter > TrackingPositionFilterPtr
Definition: cxTool.h:37
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::TimedTransformMap
std::map< double, Transform3D > TimedTransformMap
Definition: cxRecordSession.h:36
cx::ToolImpl::ToolImpl
ToolImpl(const QString &uid="", const QString &name="")
Definition: cxToolImpl.cpp:24
cx::ToolImpl::~ToolImpl
virtual ~ToolImpl()
Definition: cxToolImpl.cpp:33
cx::ToolImpl::getPositionHistory
virtual TimedTransformMapPtr getPositionHistory()
get historical positions
Definition: cxToolImpl.cpp:78
cx::ToolImpl::createToolGraphic
void createToolGraphic()
Definition: cxToolImpl.cpp:122
cxTypeConversions.h
cx::Tool::TOOL_US_PROBE
@ TOOL_US_PROBE
Ultrasond probe. The tool has a Probe subinterface with a sector and a video stream.
Definition: cxTool.h:87
cx::ToolImpl::setTooltipOffset
virtual void setTooltipOffset(double val)
Definition: cxToolImpl.cpp:70
cx::ToolImpl::getMetadata
virtual ToolPositionMetadata getMetadata() const
Definition: cxToolImpl.cpp:53
cx::TimedTransformMapPtr
boost::shared_ptr< TimedTransformMap > TimedTransformMapPtr
Definition: cxTool.h:36
cx::ToolImpl::mPolyData
vtkPolyDataPtr mPolyData
the polydata used to represent the tool graphically
Definition: cxToolImpl.h:64
cx::ToolImpl::resetTrackingPositionFilter
virtual void resetTrackingPositionFilter(TrackingPositionFilterPtr filter)
Definition: cxToolImpl.cpp:117
cx::ToolImpl::get_prMt
virtual Transform3D get_prMt() const
Definition: cxToolImpl.cpp:92
cx::vtkPolyDataPtr
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Definition: cxCenterlineRegistration.h:42
cx::ToolImpl::mMetadata
std::map< double, ToolPositionMetadata > mMetadata
Definition: cxToolImpl.h:63
cx::Tool::tooltipOffset
void tooltipOffset(double offset)
cx::ToolImpl::m_prMt
Transform3D m_prMt
the transform from the tool to the patient reference
Definition: cxToolImpl.h:61
cx::ToolImpl::getSessionHistory
virtual TimedTransformMap getSessionHistory(double startTime, double stopTime)
Definition: cxToolImpl.cpp:83
cxToolImpl.h
cx::ToolImpl::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: cxToolImpl.cpp:102
cx::ToolPositionMetadata
Definition: cxTool.h:43
cx::ToolPtr
boost::shared_ptr< class Tool > ToolPtr
Definition: cxVideoConnectionWidget.h:43
cx::Tool::createDefaultPolyDataCone
static vtkPolyDataPtr createDefaultPolyDataCone()
Definition: cxTool.cpp:20
cx::ToolImpl::getGraphicsPolyData
virtual vtkPolyDataPtr getGraphicsPolyData() const
get geometric 3D description
Definition: cxToolImpl.cpp:140
cx::ToolImpl::mTrackingPositionFilter
TrackingPositionFilterPtr mTrackingPositionFilter
Definition: cxToolImpl.h:62
cx::similar
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
Definition: cxCameraStyleForView.cpp:506
cx::ToolFileParser::ToolInternalStructurePtr
boost::shared_ptr< ToolInternalStructure > ToolInternalStructurePtr
Definition: cxToolFileParser.h:99
cx::ToolImpl::getTypes
virtual std::set< Type > getTypes() const
Definition: cxToolImpl.cpp:38
cx::Tool::TOOL_REFERENCE
@ TOOL_REFERENCE
Reference tool.
Definition: cxTool.h:84