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