MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkTrackingDevice.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 "mitkTrackingDevice.h"
14#include "mitkIGTTimeStamp.h"
15#include "mitkTrackingTool.h"
16
17#include <usModuleContext.h>
18#include <usGetModuleContext.h>
19
22
23
25 m_State(mitk::TrackingDevice::Setup),
26 m_Data(mitk::UnspecifiedTrackingTypeInformation::GetDeviceDataUnspecified()),
27 m_StopTracking(false),
28 m_RotationMode(mitk::TrackingDevice::RotationStandard)
29
30{
31}
32
33
37
39{
40return true;
41//this is the default for all tracking device
42//If a device needs installation please reimplement
43//this method in the subclass.
44}
45
47{
48 return false;
49}
50
55
56mitk::NavigationToolStorage::Pointer mitk::TrackingDevice::AutoDetectTools()
57{
58 return mitk::NavigationToolStorage::New();
59}
60
61
63{
64 std::lock_guard<std::mutex> lock(m_StateMutex);
65 return m_State;
66}
67
68
70{
71 itkDebugMacro("setting m_State to " << state);
72
73 std::lock_guard<std::mutex> lock(m_StateMutex);
74 if (m_State == state)
75 {
76 return;
77 }
78 m_State = state;
79 this->Modified();
80}
81
83{
84 MITK_WARN << "Rotation mode switching is not implemented for this device. Leaving it at mitk::TrackingDevice::RotationStandard";
85}
86
88 return m_Data.Line;
89}
90
92
93 us::ModuleContext* context = us::GetModuleContext();
94
95 std::vector<us::ServiceReference<mitk::TrackingDeviceTypeCollection> > refs = context->GetServiceReferences<mitk::TrackingDeviceTypeCollection>();
96 if (refs.empty())
97 {
98 MITK_ERROR << "No tracking device service found!";
99 }
100 mitk::TrackingDeviceTypeCollection* deviceTypeCollection = context->GetService<mitk::TrackingDeviceTypeCollection>(refs.front());
101
102 m_Data = deviceTypeCollection->GetFirstCompatibleDeviceDataForLine(deviceType);
103}
104
108
109
111 m_Data = data;
112}
113
114
116{
117 if (this->GetState() == Tracking) // Only if the object is in the correct state
118 {
119 m_StopTrackingMutex.lock(); // m_StopTracking is used by two threads, so we have to ensure correct thread handling
120 m_StopTracking = true;
121 m_StopTrackingMutex.unlock();
122 //we have to wait here that the other thread recognizes the STOP-command and executes it
123 m_TrackingFinishedMutex.lock();
124 mitk::IGTTimeStamp::GetInstance()->Stop(this); // notify realtime clock
125 // StopTracking was called, thus the mode should be changed back
126 // to Ready now that the tracking loop has ended.
127 this->SetState(Ready);
128 m_TrackingFinishedMutex.unlock();
129 }
130 return true;
131}
132
133
135{
136 unsigned int toolCount = this->GetToolCount();
137 for (unsigned int i = 0; i < toolCount; ++i)
138 if (name == this->GetTool(i)->GetToolName())
139 return this->GetTool(i);
140 return nullptr;
141}
142
144{
145 return this->GetData().Line;
146}
static IGTTimeStamp * GetInstance()
returns a pointer to the current instance of mitkTimeStamp
void Stop(itk::Object::Pointer device)
stops the time-acqusition
This class is a collection for information of all Tracking Device Types (derived from abstract Tracki...
TrackingDeviceData GetFirstCompatibleDeviceDataForLine(TrackingDeviceType type)
Interface for all Tracking Devices.
TrackingDeviceData GetData() const
return device data
std::string GetTrackingDeviceName()
Convenient Method to get the Name of the Tracking Device. This is identical with GetData()....
void SetState(TrackingDeviceState state)
change object state
virtual mitk::TrackingTool * GetToolByName(std::string name) const
Returns the tool with the given tool name.
virtual mitk::NavigationToolStorage::Pointer AutoDetectTools()
TrackingDeviceState GetState() const
return current object state (Setup, Ready or Tracking)
TrackingDeviceType GetType() const
Deprecated! Use the more specific getData or GetTrackingDeviceName instead. return device type identi...
void SetType(TrackingDeviceType type)
Deprecated! Use the more specific setDeviceData instead. set device type.
virtual bool IsDeviceInstalled()
virtual bool StopTracking()
stop retrieving tracking data from the device. stop retrieving tracking data from the device....
virtual bool AutoDetectToolsAvailable()
virtual void SetRotationMode(RotationMode r)
virtual bool AddSingleToolIsAvailable()
void SetData(TrackingDeviceData data)
set device type
Interface for all Tracking Tools.
Type information for unspecified or invalid tracking devices. This is often used as default or for te...
IGT Exceptions.
std::string TrackingDeviceType