MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkTrackingDeviceSourceConfigurator.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
14
20
21#include <mitkIGTException.h>
22#include <mitkIGTHardwareException.h>
23
24#include <usGetModuleContext.h>
25#include <usModule.h>
26#include <usServiceProperties.h>
27#include <usModuleContext.h>
29
30
31mitk::TrackingDeviceSourceConfigurator::TrackingDeviceSourceConfigurator(mitk::NavigationToolStorage::Pointer NavigationTools, mitk::TrackingDevice::Pointer TrackingDevice)
32{
33//make a copy of the navigation tool storage because we will modify the storage
34if (NavigationTools.IsNotNull())
35 {
36 m_NavigationTools = mitk::NavigationToolStorage::New();
37 for (unsigned int i=0; i<NavigationTools->GetToolCount(); i++)
38 {
39 m_NavigationTools->AddTool(NavigationTools->GetTool(i));
40 }
41 }
42
44m_ToolCorrespondencesInToolStorage = std::vector<int>();
46}
47
49{
50return m_NavigationTools;
51}
52
53
57
59{
60if (m_NavigationTools.IsNull())
61 {
62 m_ErrorMessage = "NavigationToolStorage is nullptr!";
63 return false;
64 }
65else if (m_TrackingDevice.IsNull())
66 {
67 m_ErrorMessage = "TrackingDevice is nullptr!";
68 return false;
69 }
70else
71 {
72 for (unsigned int i=0; i<m_NavigationTools->GetToolCount(); i++)
73 {
74 if (m_NavigationTools->GetTool(i)->GetTrackingDeviceType() != m_TrackingDevice->GetType())
75 {
76 m_ErrorMessage = "At least one tool is not of the same type like the tracking device.";
77 return false;
78 }
79 }
80 //TODO in case of Aurora: check if the tools are automatically detected by comparing the serial number
81 return true;
82 }
83}
84
86{
87mitk::NavigationDataObjectVisualizationFilter::Pointer dummy; //this dummy is lost directly after creating the device
88return this->CreateTrackingDeviceSource(dummy);
89}
90
91mitk::TrackingDeviceSource::Pointer mitk::TrackingDeviceSourceConfigurator::CreateTrackingDeviceSource(mitk::NavigationDataObjectVisualizationFilter::Pointer &visualizationFilter)
92{
93 if (!this->IsCreateTrackingDeviceSourcePossible()) {MITK_WARN << "Cannot create tracking decive: " << m_ErrorMessage; return nullptr;}
94
95 mitk::TrackingDeviceSource::Pointer returnValue;
96
97 us::ModuleContext* context = us::GetModuleContext();
98
99 std::vector<us::ServiceReference<mitk::TrackingDeviceTypeCollection> > refs = context->GetServiceReferences<mitk::TrackingDeviceTypeCollection>();
100
101 if (refs.empty())
102 {
103 MITK_ERROR << "No tracking device service found!";
104 }
105
106 mitk::TrackingDeviceTypeCollection* deviceTypeCollection = context->GetService<mitk::TrackingDeviceTypeCollection>(refs.front());
107
108 //create tracking device source
109 returnValue = deviceTypeCollection->GetTrackingDeviceTypeInformation(m_TrackingDevice->GetType())->
110 CreateTrackingDeviceSource(m_TrackingDevice,m_NavigationTools, &m_ErrorMessage, &m_ToolCorrespondencesInToolStorage);
111
112 //TODO: insert other tracking systems?
113 if (returnValue.IsNull()) {MITK_WARN << "Cannot create tracking decive: " << m_ErrorMessage; return nullptr;}
114
115 //create visualization filter
116 visualizationFilter = CreateNavigationDataObjectVisualizationFilter(returnValue,m_NavigationTools);
117 if (visualizationFilter.IsNull()) {MITK_WARN << "Cannot create tracking decive: " << m_ErrorMessage; return nullptr;}
118
119 return returnValue;
120}
121
123{
124 return this->m_ErrorMessage;
125}
126
127//############################ internal help methods ########################################
128
129mitk::NavigationDataObjectVisualizationFilter::Pointer mitk::TrackingDeviceSourceConfigurator::CreateNavigationDataObjectVisualizationFilter(mitk::TrackingDeviceSource::Pointer trackingDeviceSource, mitk::NavigationToolStorage::Pointer navigationTools)
130 {
131 mitk::NavigationDataObjectVisualizationFilter::Pointer returnValue = mitk::NavigationDataObjectVisualizationFilter::New();
132 for (unsigned int i=0; i<trackingDeviceSource->GetNumberOfIndexedOutputs(); i++)
133 {
134 // Note: If all tools have the same name only the first tool will always be returned and
135 // the others won't be updated during rendering.This could potentially lead to inconstencies
136 mitk::NavigationTool::Pointer currentTool = navigationTools->GetToolByName(trackingDeviceSource->GetOutput(i)->GetName());
137 if (currentTool.IsNull())
138 {
139 this->m_ErrorMessage = "Error: did not find corresponding tool in tracking device after initialization.";
140 return nullptr;
141 }
142 returnValue->SetInput(i,trackingDeviceSource->GetOutput(i));
143 returnValue->SetRepresentationObject(i,currentTool->GetDataNode()->GetData());
144 }
145 return returnValue;
146 }
147
149 {
150 if (outputID < m_ToolCorrespondencesInToolStorage.size()) return m_ToolCorrespondencesInToolStorage.at(outputID);
151 else return -1;
152 }
153
155 {
156 if (outputID < m_ToolCorrespondencesInToolStorage.size()) return m_NavigationTools->GetTool(m_ToolCorrespondencesInToolStorage.at(outputID))->GetIdentifier();
157 else return "";
158 }
159
161 {
162 return m_ToolCorrespondencesInToolStorage;
163 }
164
166 {
167 std::vector<std::string> returnValue = std::vector<std::string>();
168 for (unsigned int i=0; i<m_ToolCorrespondencesInToolStorage.size(); i++)
169 {returnValue.push_back(m_NavigationTools->GetTool(m_ToolCorrespondencesInToolStorage.at(i))->GetIdentifier());}
170 return returnValue;
171 }
TrackingDeviceSourceConfigurator(mitk::NavigationToolStorage::Pointer NavigationTools, mitk::TrackingDevice::Pointer TrackingDevice)
std::string GetToolIdentifierInToolStorage(unsigned int outputID)
mitk::NavigationDataObjectVisualizationFilter::Pointer CreateNavigationDataObjectVisualizationFilter(mitk::TrackingDeviceSource::Pointer trackingDeviceSource, mitk::NavigationToolStorage::Pointer navigationTools)
mitk::NavigationToolStorage::Pointer GetUpdatedNavigationToolStorage()
mitk::TrackingDeviceSource::Pointer CreateTrackingDeviceSource()
This class is a collection for information of all Tracking Device Types (derived from abstract Tracki...
TrackingDeviceTypeInformation * GetTrackingDeviceTypeInformation(TrackingDeviceType type)
Interface for all Tracking Devices.