Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkTrackingDevice.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 
17 #include "mitkTrackingDevice.h"
18 #include "mitkIGTTimeStamp.h"
19 #include "mitkTrackingTool.h"
20 
21 #include <itkMutexLockHolder.h>
22 
23 #include <usModuleContext.h>
24 #include <usGetModuleContext.h>
25 
28 
30 
31 
33 m_Data(mitk::UnspecifiedTrackingTypeInformation::GetDeviceDataUnspecified()),
34  m_State(mitk::TrackingDevice::Setup),
35  m_StopTracking(false),
36  m_RotationMode(mitk::TrackingDevice::RotationStandard)
37 
38 {
42 }
43 
44 
46 {
47 }
48 
50 {
51 return true;
52 //this is the default for all tracking device
53 //If a device needs installation please reimplement
54 //this method in the subclass.
55 }
56 
57 
59 {
60  MutexLockHolder lock(*m_StateMutex);
61  return m_State;
62 }
63 
64 
66 {
67  itkDebugMacro("setting m_State to " << state);
68 
69  MutexLockHolder lock(*m_StateMutex); // lock and unlock the mutex
70  if (m_State == state)
71  {
72  return;
73  }
74  m_State = state;
75  this->Modified();
76 }
77 
79 {
80  MITK_WARN << "Rotation mode switching is not implemented for this device. Leaving it at mitk::TrackingDevice::RotationStandard";
81 }
82 
84  return m_Data.Line;
85 }
86 
88 
89  us::ModuleContext* context = us::GetModuleContext();
90 
91  std::vector<us::ServiceReference<mitk::TrackingDeviceTypeCollection> > refs = context->GetServiceReferences<mitk::TrackingDeviceTypeCollection>();
92  if (refs.empty())
93  {
94  MITK_ERROR << "No tracking device service found!";
95  }
96  mitk::TrackingDeviceTypeCollection* deviceTypeCollection = context->GetService<mitk::TrackingDeviceTypeCollection>(refs.front());
97 
98  m_Data = deviceTypeCollection->GetFirstCompatibleDeviceDataForLine(deviceType);
99 }
100 
102  return m_Data;
103 }
104 
105 
107  m_Data = data;
108 }
109 
110 
112 {
113  if (this->GetState() == Tracking) // Only if the object is in the correct state
114  {
115  m_StopTrackingMutex->Lock(); // m_StopTracking is used by two threads, so we have to ensure correct thread handling
116  m_StopTracking = true;
117  m_StopTrackingMutex->Unlock();
118  //we have to wait here that the other thread recognizes the STOP-command and executes it
119  m_TrackingFinishedMutex->Lock();
120  mitk::IGTTimeStamp::GetInstance()->Stop(this); // notify realtime clock
121  // StopTracking was called, thus the mode should be changed back
122  // to Ready now that the tracking loop has ended.
123  this->SetState(Ready);
124  m_TrackingFinishedMutex->Unlock();
125  }
126  return true;
127 }
128 
129 
131 {
132  unsigned int toolCount = this->GetToolCount();
133  for (unsigned int i = 0; i < toolCount; ++i)
134  if (name == this->GetTool(i)->GetToolName())
135  return this->GetTool(i);
136  return nullptr;
137 }
138 
Interface for all Tracking Tools.
itk::FastMutexLock::Pointer m_TrackingFinishedMutex
mutex to manage control flow of StopTracking()
itk::MutexLockHolder< itk::FastMutexLock > MutexLockHolder
#define MITK_ERROR
Definition: mitkLogMacros.h:24
DataCollection - Class to facilitate loading/accessing structured data.
This class is a collection for information of all Tracking Device Types (derived from abstract Tracki...
TrackingDeviceState GetState() const
return current object state (Setup, Ready or Tracking)
virtual void SetRotationMode(RotationMode r)
TrackingDeviceData GetData() const
return device data
#define MITK_WARN
Definition: mitkLogMacros.h:23
itk::FastMutexLock::Pointer m_StateMutex
mutex to control access to m_State
TrackingDeviceData GetFirstCompatibleDeviceDataForLine(TrackingDeviceType type)
virtual bool StopTracking()
stop retrieving tracking data from the device. stop retrieving tracking data from the device...
Interface for all Tracking Devices.
static IGTTimeStamp * GetInstance()
returns a pointer to the current instance of mitkTimeStamp
virtual bool IsDeviceInstalled()
virtual mitk::TrackingTool * GetToolByName(std::string name) const
Returns the tool with the given tool name.
std::string TrackingDeviceType
Type information for unspecified or invalid tracking devices. This is often used as default or for te...
itk::FastMutexLock::Pointer m_StopTrackingMutex
mutex to control access to m_StopTracking
void Stop(itk::Object::Pointer device)
stops the time-acqusition
void SetData(TrackingDeviceData data)
set device type
static void Setup()
void SetState(TrackingDeviceState state)
change object state
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
TrackingDeviceType GetType() const
Deprecated! Use the more specific getDeviceData instead. return device type identifier.
void SetType(TrackingDeviceType type)
Deprecated! Use the more specific setDeviceData instead. set device type.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.