MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkTrackingTool.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
13#include "mitkTrackingTool.h"
14
16: itk::Object(),
17 m_ToolName(""),
18 m_ErrorMessage(""),
19 m_IGTTimeStamp(0),
20 m_TrackingError(0.0f),
21 m_Enabled(true),
22 m_DataValid(false),
23 m_ToolTipSet(false)
24{
25 m_Position[0] = 0.0f;
26 m_Position[1] = 0.0f;
27 m_Position[2] = 0.0f;
28 m_Orientation[0] = 0.0f;
29 m_Orientation[1] = 0.0f;
30 m_Orientation[2] = 0.0f;
31 m_Orientation[3] = 0.0f;
32 // this should not be necessary as the tools bring their own tooltip transformation
33 m_ToolTipPosition[0] = 0.0f;
34 m_ToolTipPosition[1] = 0.0f;
35 m_ToolTipPosition[2] = 0.0f;
36 m_ToolAxisOrientation[0] = 0.0f;
37 m_ToolAxisOrientation[1] = 0.0f;
38 m_ToolAxisOrientation[2] = 0.0f;
39 m_ToolAxisOrientation[3] = 1.0f;
40}
41
45
46void mitk::TrackingTool::PrintSelf(std::ostream& os, itk::Indent indent) const
47{
48 Superclass::PrintSelf(os, indent);
49 os << indent << "ToolName: " << m_ToolName << std::endl;
50 os << indent << "ErrorMesage: " << m_ErrorMessage << std::endl;
51 os << indent << "Position: " << m_Position << std::endl;
52 os << indent << "Orientation: " << m_Orientation << std::endl;
53 os << indent << "TrackingError: " << m_TrackingError << std::endl;
54 os << indent << "Enabled: " << m_Enabled << std::endl;
55 os << indent << "DataValid: " << m_DataValid << std::endl;
56 os << indent << "ToolTip: " << m_ToolTipPosition << std::endl;
57 os << indent << "ToolTipRotation: " << m_ToolAxisOrientation << std::endl;
58 os << indent << "ToolTipSet: " << m_ToolTipSet << std::endl;
59}
60
62{
63 std::lock_guard<std::mutex> lock(m_MyMutex);
64 return this->m_ToolName.c_str();
65}
66
67void mitk::TrackingTool::SetToolName(const char* _arg)
68{
69 itkDebugMacro("setting m_ToolName to " << _arg);
70 std::lock_guard<std::mutex> lock(m_MyMutex);
71 if ( _arg && (_arg == this->m_ToolName) )
72 {
73 return;
74 }
75 if (_arg)
76 {
77 this->m_ToolName= _arg;
78 }
79 else
80 {
81 this->m_ToolName= "";
82 }
83 this->Modified();
84}
85
86
87void mitk::TrackingTool::SetToolName( const std::string _arg )
88{
89 this->SetToolName(_arg.c_str());
90}
91
93{
94 std::lock_guard<std::mutex> lock(m_MyMutex);
95 return m_ToolTipPosition;
96}
97
99{
100 std::lock_guard<std::mutex> lock(m_MyMutex);
101 return m_ToolAxisOrientation;
102}
103
104void mitk::TrackingTool::SetToolTipPosition(mitk::Point3D toolTipPosition,
105 mitk::Quaternion orientation,
106 mitk::ScalarType eps)
107{
108 if ( !Equal(m_ToolTipPosition, toolTipPosition, eps) ||
109 !Equal(m_ToolAxisOrientation, orientation, eps) )
110 {
111 if( (toolTipPosition[0] == 0) &&
112 (toolTipPosition[1] == 0) &&
113 (toolTipPosition[2] == 0) &&
114 (orientation.x() == 0) &&
115 (orientation.y() == 0) &&
116 (orientation.z() == 0) &&
117 (orientation.r() == 1))
118 {
119 m_ToolTipSet = false;
120 }
121 else
122 {
123 m_ToolTipSet = true;
124 }
125 m_ToolTipPosition = toolTipPosition;
126 m_ToolAxisOrientation = orientation;
127 this->Modified();
128 }
129}
130
132{
133 std::lock_guard<std::mutex> lock(m_MyMutex);
134 return m_ToolTipSet;
135}
136
137void mitk::TrackingTool::GetPosition(mitk::Point3D& position) const
138{
139 std::lock_guard<std::mutex> lock(m_MyMutex);
140 if (m_ToolTipSet)
141 {
142 // Compute the position of tool tip in the coordinate frame of the
143 // tracking device: Rotate the position of the tip into the tracking
144 // device coordinate frame then add to the position of the tracking
145 // sensor
146 vnl_vector<mitk::ScalarType> pos_vnl = m_Position.GetVnlVector() + m_Orientation.rotate( m_ToolTipPosition.GetVnlVector() ) ;
147
148 position[0] = pos_vnl[0];
149 position[1] = pos_vnl[1];
150 position[2] = pos_vnl[2];
151 }
152 else
153 {
154 position[0] = m_Position[0];
155 position[1] = m_Position[1];
156 position[2] = m_Position[2];
157 }
158 this->Modified();
159}
160
161void mitk::TrackingTool::SetPosition(mitk::Point3D position)
162{
163 itkDebugMacro("setting m_Position to " << position);
164
165 std::lock_guard<std::mutex> lock(m_MyMutex);
166 if (m_Position != position)
167 {
168 m_Position = position;
169 this->Modified();
170 }
171}
172
173void mitk::TrackingTool::GetOrientation(mitk::Quaternion& orientation) const
174{
175 std::lock_guard<std::mutex> lock(m_MyMutex);
176 if (m_ToolTipSet)
177 {
178 // Compute the orientation of the tool tip in the coordinate frame of
179 // the tracking device.
180 //
181 // * m_Orientation is the orientation of the sensor relative to the transmitter
182 // * m_ToolAxisOrientation is the orientation of the tool tip relative to the sensor
183 orientation = m_Orientation * m_ToolAxisOrientation;
184 }
185 else
186 {
187 orientation = m_Orientation;
188 }
189}
190
191void mitk::TrackingTool::SetOrientation(mitk::Quaternion orientation)
192{
193 itkDebugMacro("setting m_Orientation to " << orientation);
194
195 std::lock_guard<std::mutex> lock(m_MyMutex);
196 if (m_Orientation != orientation)
197 {
198 m_Orientation = orientation;
199 this->Modified();
200 }
201}
202
204{
205 std::lock_guard<std::mutex> lock(m_MyMutex);
206 if (m_Enabled == false)
207 {
208 this->m_Enabled = true;
209 this->Modified();
210 }
211 return true;
212}
213
215{
216 std::lock_guard<std::mutex> lock(m_MyMutex);
217 if (m_Enabled == true)
218 {
219 this->m_Enabled = false;
220 this->Modified();
221 }
222 return true;
223}
224
226{
227 std::lock_guard<std::mutex> lock(m_MyMutex);
228 return m_Enabled;
229}
230
232{
233 itkDebugMacro("setting m_DataValid to " << isDataValid);
234 if (this->m_DataValid != isDataValid)
235 {
236 std::lock_guard<std::mutex> lock(m_MyMutex);
237 this->m_DataValid = isDataValid;
238 this->Modified();
239 }
240}
241
243{
244 std::lock_guard<std::mutex> lock(m_MyMutex);
245 return m_DataValid;
246}
247
249{
250 std::lock_guard<std::mutex> lock(m_MyMutex);
251 return m_TrackingError;
252}
253
255{
256 itkDebugMacro("setting m_TrackingError to " << error);
257 std::lock_guard<std::mutex> lock(m_MyMutex);
258 if (m_TrackingError != error)
259 {
260 m_TrackingError = error;
261 this->Modified();
262 }
263}
264
266{
267 std::lock_guard<std::mutex> lock(m_MyMutex);
268 return this->m_ErrorMessage.c_str();
269}
270
272{
273 itkDebugMacro("setting m_ErrorMessage to " << _arg);
274 std::lock_guard<std::mutex> lock(m_MyMutex);
275 if ((_arg == nullptr) || (_arg == this->m_ErrorMessage))
276 return;
277
278 if (_arg != nullptr)
279 this->m_ErrorMessage = _arg;
280 else
281 this->m_ErrorMessage = "";
282 this->Modified();
283}
Point3D GetToolTipPosition() const
returns the tool tip in tool coordinates, which where set by SetToolTip
virtual bool Disable()
disables the tool, so that it will not be tracked anymore
virtual void SetDataValid(bool isDataValid)
sets if the tracking data (position & orientation) is valid
virtual bool Enable()
enables the tool, so that it will be tracked
virtual void GetPosition(Point3D &position) const
returns the current position of the tool as an array of three floats (in the tracking device coordina...
virtual void SetToolName(const std::string _arg)
Sets the name of the tool.
TrackingTool()
< Gets the IGT timestamp of the tracking tool object (time in milliseconds). Returns 0 if the timesta...
Point3D m_Position
holds the position of the tool in global tracking coordinates
virtual void GetOrientation(Quaternion &orientation) const
returns the current orientation of the tool as a quaternion in a mitk::Point4D (in the tracking devic...
Point3D m_ToolTipPosition
holds the position of the tool tip in the coordinate system of the tracking sensor
virtual const char * GetErrorMessage() const
if the data is not valid, ErrorMessage should contain a string explaining why it is invalid (the Set-...
virtual void SetTrackingError(float error)
sets the tracking error
virtual const char * GetToolName() const
every tool has a name thatgit can be used to identify it.
virtual bool IsEnabled() const
returns whether the tool is enabled or disabled
virtual float GetTrackingError() const
returns one value that corresponds to the overall tracking error.
Quaternion m_Orientation
holds the orientation of the tool´in global tracking coordinates
virtual void SetToolTipPosition(Point3D toolTipPosition, Quaternion orientation, ScalarType eps=0.0)
defines a tool tip for this tool in tool coordinates. GetPosition() and GetOrientation() return the d...
virtual void SetOrientation(Quaternion orientation)
sets the orientation as a quaternion
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Quaternion GetToolAxisOrientation() const
returns the transformation of the tool axis with respect to the MITK-IGT main tool axis (0,...
Quaternion m_ToolAxisOrientation
holds the rotation of the sensor coordinate system such that the z-axis coincides with the main tool ...
virtual void SetPosition(Point3D position)
sets the position
virtual void SetErrorMessage(const char *_arg)
sets the error message
virtual bool IsDataValid() const
returns true if the current position data is valid (no error during tracking, tracking error below th...
virtual bool IsToolTipSet() const
returns true if a tool tip is set, false if not
MITKIGTBASE_EXPORT bool Equal(const mitk::NavigationData &leftHandSide, const mitk::NavigationData &rightHandSide, ScalarType eps=mitk::eps, bool verbose=false)
Equal A function comparing two navigation data objects for beeing equal in meta- and imagedata.