Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkInternalTrackingTool.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 #include <itkMutexLockHolder.h>
20 
22 
24 : TrackingTool(),
25 m_TrackingError(0.0f),
26 m_Enabled(true),
27 m_DataValid(false),
28 m_ToolTipSet(false)
29 {
30  m_Position[0] = 0.0f;
31  m_Position[1] = 0.0f;
32  m_Position[2] = 0.0f;
33  m_Orientation[0] = 0.0f;
34  m_Orientation[1] = 0.0f;
35  m_Orientation[2] = 0.0f;
36  m_Orientation[3] = 0.0f;
37  // this should not be necessary as the tools bring their own tooltip transformation
38  m_ToolTip[0] = 0.0f;
39  m_ToolTip[1] = 0.0f;
40  m_ToolTip[2] = 0.0f;
41  m_ToolTipRotation[0] = 0.0f;
42  m_ToolTipRotation[1] = 0.0f;
43  m_ToolTipRotation[2] = 0.0f;
44  m_ToolTipRotation[3] = 1.0f;
45 }
46 
48 {
49 }
50 
51 void mitk::InternalTrackingTool::PrintSelf(std::ostream& os, itk::Indent indent) const
52 {
53  Superclass::PrintSelf(os, indent);
54 
55  os << indent << "Position: " << m_Position << std::endl;
56  os << indent << "Orientation: " << m_Orientation << std::endl;
57  os << indent << "TrackingError: " << m_TrackingError << std::endl;
58  os << indent << "Enabled: " << m_Enabled << std::endl;
59  os << indent << "DataValid: " << m_DataValid << std::endl;
60  os << indent << "ToolTip: " << m_ToolTip << std::endl;
61  os << indent << "ToolTipRotation: " << m_ToolTipRotation << std::endl;
62  os << indent << "ToolTipSet: " << m_ToolTipSet << std::endl;
63 }
64 
66 {
67  itkDebugMacro("setting m_ToolName to " << _arg);
68  MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex
69  if ( _arg && (_arg == this->m_ToolName) )
70  {
71  return;
72  }
73  if (_arg)
74  {
75  this->m_ToolName= _arg;
76  }
77  else
78  {
79  this->m_ToolName= "";
80  }
81  this->Modified();
82 }
83 
84 
85 void mitk::InternalTrackingTool::SetToolName( const std::string _arg )
86 {
87  this->SetToolName(_arg.c_str());
88 }
89 
90 
92 {
93  MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex
94  if (m_ToolTipSet)
95  {
96  // Compute the position of tool tip in the coordinate frame of the
97  // tracking device: Rotate the position of the tip into the tracking
98  // device coordinate frame then add to the position of the tracking
99  // sensor
100  vnl_vector<mitk::ScalarType> pos_vnl = m_Position.GetVnlVector() + m_Orientation.rotate( m_ToolTip.GetVnlVector() ) ;
101 
102  position[0] = pos_vnl[0];
103  position[1] = pos_vnl[1];
104  position[2] = pos_vnl[2];
105  }
106  else
107  {
108  position[0] = m_Position[0];
109  position[1] = m_Position[1];
110  position[2] = m_Position[2];
111  }
112  this->Modified();
113 }
114 
115 
117 {
118  itkDebugMacro("setting m_Position to " << position);
119 
120  MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex
121  m_Position = position;
122  this->Modified();
123 }
124 
125 
127 {
128  MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex
129  if (m_ToolTipSet)
130  {
131  // Compute the orientation of the tool tip in the coordinate frame of
132  // the tracking device.
133  //
134  // * m_Orientation is the orientation of the sensor relative to the transmitter
135  // * m_ToolTipRotation is the orientation of the tool tip relative to the sensor
136  orientation = m_Orientation * m_ToolTipRotation;
137  }
138  else
139  {
140  orientation = m_Orientation;
141  }
142 }
143 
145  mitk::Quaternion orientation,
147 {
148  if ( !Equal(m_ToolTip, toolTipPosition, eps) ||
149  !Equal(m_ToolTipRotation, orientation, eps) )
150  {
151  if( (toolTipPosition[0] == 0) &&
152  (toolTipPosition[1] == 0) &&
153  (toolTipPosition[2] == 0) &&
154  (orientation.x() == 0) &&
155  (orientation.y() == 0) &&
156  (orientation.z() == 0) &&
157  (orientation.r() == 1))
158  {
159  m_ToolTipSet = false;
160  }
161  else
162  {
163  m_ToolTipSet = true;
164  }
165  m_ToolTip = toolTipPosition;
166  m_ToolTipRotation = orientation;
167  this->Modified();
168  }
169 }
170 
172 {
173  itkDebugMacro("setting m_Orientation to " << orientation);
174 
175  MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex
176  m_Orientation = orientation;
177  this->Modified();
178 
179 }
180 
181 
183 {
184  itkDebugMacro("setting m_TrackingError to " << error);
185  MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex
186  if (error == m_TrackingError)
187  {
188  return;
189  }
190  m_TrackingError = error;
191  this->Modified();
192 }
193 
194 
196 {
197  MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex
198  float r = m_TrackingError;
199  return r;
200 }
201 
202 
204 {
205  MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex
206  if (m_Enabled == false)
207  {
208  this->m_Enabled = true;
209  this->Modified();
210  }
211  return true;
212 }
213 
214 
216 {
217  MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex
218  if (m_Enabled == true)
219  {
220  this->m_Enabled = false;
221  this->Modified();
222  }
223  return true;
224 }
225 
226 
228 {
229  MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex
230  return m_Enabled;
231 }
232 
234 {
235  MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex
236  return m_ToolTipSet;
237 }
238 
240 {
241  MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex
242  return m_DataValid;
243 }
244 
245 
247 {
248  itkDebugMacro("setting m_DataValid to " << _arg);
249  if (this->m_DataValid != _arg)
250  {
251  MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex
252  this->m_DataValid = _arg;
253  this->Modified();
254  }
255 }
256 
257 
259 {
260  itkDebugMacro("setting m_ErrorMessage to " << _arg);
261  MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex
262  if ((_arg == nullptr) || (_arg == this->m_ErrorMessage))
263  return;
264 
265  if (_arg != nullptr)
266  this->m_ErrorMessage = _arg;
267  else
268  this->m_ErrorMessage = "";
269  this->Modified();
270 }
virtual void SetToolTip(Point3D toolTipPosition, Quaternion orientation=Quaternion(0, 0, 0, 1), ScalarType eps=0.0) override
defines a tool tip for this tool in tool coordinates. GetPosition() and GetOrientation() return the d...
Interface for all Tracking Tools.
double ScalarType
virtual bool IsTooltipSet() const
returns true if a tooltip is set, false if not
Quaternion m_Orientation
holds the orientation of the tool
virtual void SetDataValid(bool _arg)
sets if the tracking data (position & Orientation) is valid
virtual void GetPosition(Point3D &position) const override
returns the current position of the tool as an array of three floats (in the tracking device coordina...
virtual void SetPosition(Point3D position)
sets the position
itk::MutexLockHolder< itk::FastMutexLock > MutexLockHolder
virtual float GetTrackingError() const override
return one value that corresponds to the overall tracking error. The dimension of this value is speci...
virtual void SetErrorMessage(const char *_arg)
sets the error message
vnl_quaternion< ScalarType > Quaternion
virtual void SetTrackingError(float error)
sets the tracking error
virtual bool IsEnabled() const override
returns whether the tool is enabled or disabled
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const override
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
Point3D m_Position
holds the position of the tool
virtual void GetOrientation(Quaternion &orientation) const override
returns the current orientation of the tool as a quaternion (in the tracking device coordinate system...
virtual void SetOrientation(Quaternion orientation)
sets the orientation as a quaternion
MITKCORE_EXPORT const ScalarType eps
virtual bool Enable() override
enablea the tool, so that it will be tracked. Returns true if enabling was successfull ...
virtual bool IsDataValid() const override
returns true if the current position data is valid (no error during tracking, tracking error below th...
virtual bool Disable() override
disables the tool, so that it will not be tracked anymore. Returns true if disabling was successfull ...
virtual void SetToolName(const std::string _arg)
Sets the name of the tool.