Medical Imaging Interaction Toolkit  2018.4.99-87d68d9f
Medical Imaging Interaction Toolkit
mitkNDIAuroraTypeInformation.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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 
15 #include "mitkIGTHardwareException.h"
16 #include "mitkNDITrackingDevice.h"
17 
18 namespace mitk
19 {
21  {
22  return "NDI Aurora";
23  }
24 
26  {
27  TrackingDeviceData data = { NDIAuroraTypeInformation::GetTrackingDeviceName(), "Aurora Compact", "NDIAuroraCompactFG_Dome.stl", "A" };
28  return data;
29  }
30 
32  {
33  TrackingDeviceData data = { NDIAuroraTypeInformation::GetTrackingDeviceName(), "Aurora Planar (Cube)", "NDIAurora.stl", "9" };
34  return data;
35  }
36 
38  {
39  TrackingDeviceData data = { NDIAuroraTypeInformation::GetTrackingDeviceName(), "Aurora Planar (Dome)", "NDIAuroraPlanarFG_Dome.stl", "A" };
40  return data;
41  }
42 
44  {
45  TrackingDeviceData data = { NDIAuroraTypeInformation::GetTrackingDeviceName(), "Aurora Tabletop", "NDIAuroraTabletopFG_Dome.stl", "A" };
46  return data;
47  }
48 
50  {
56  }
57 
59  {
60  }
61 
62  mitk::TrackingDeviceSource::Pointer NDIAuroraTypeInformation::CreateTrackingDeviceSource(
63  mitk::TrackingDevice::Pointer trackingDevice,
64  mitk::NavigationToolStorage::Pointer navigationTools,
65  std::string* errorMessage,
66  std::vector<int>* toolCorrespondencesInToolStorage)
67  {
68  MITK_DEBUG << "Creating Aurora tracking device.";
69  mitk::TrackingDeviceSource::Pointer returnValue = mitk::TrackingDeviceSource::New();
70  mitk::NDITrackingDevice::Pointer thisDevice = dynamic_cast<mitk::NDITrackingDevice*>(trackingDevice.GetPointer());
71 
72  try
73  {
74  //connect to aurora to dectect tools automatically
75  thisDevice->OpenConnection();
76  }
78  {
79  errorMessage->append("Hardware error on opening the connection (");
80  errorMessage->append(e.GetDescription());
81  errorMessage->append(")");
82  return nullptr;
83  }
84  catch (mitk::IGTException& e)
85  {
86  errorMessage->append("Error on opening the connection (");
87  errorMessage->append(e.GetDescription());
88  errorMessage->append(")");
89  return nullptr;
90  }
91 
92  //now search for automatically detected tools in the tool storage and save them
93  mitk::NavigationToolStorage::Pointer newToolStorageInRightOrder = mitk::NavigationToolStorage::New();
94  std::vector<unsigned int> alreadyFoundTools = std::vector<unsigned int>();
95  *toolCorrespondencesInToolStorage = std::vector<int>();
96  for (unsigned int i = 0; i < thisDevice->GetToolCount(); i++)
97  {
98  bool toolFound = false;
99  for (unsigned int j = 0; j < navigationTools->GetToolCount(); j++)
100  {
101  //check if the serial number is the same to identify the tool
102  if ((dynamic_cast<mitk::NDIPassiveTool*>(thisDevice->GetTool(i)))->GetSerialNumber() == navigationTools->GetTool(j)->GetSerialNumber())
103  {
104  //check if this tool was already added to make sure that every tool is only added once (in case of same serial numbers)
105  bool toolAlreadyAdded = false;
106  for (unsigned int k = 0; k < alreadyFoundTools.size(); k++)
107  {
108  if (alreadyFoundTools.at(k) == j)
109  {
110  toolAlreadyAdded = true;
111  }
112  }
113 
114  if (!toolAlreadyAdded)
115  {
116  //add tool in right order
117  newToolStorageInRightOrder->AddTool(navigationTools->GetTool(j));
118  toolCorrespondencesInToolStorage->push_back(j);
119  //adapt name of tool
120  dynamic_cast<mitk::NDIPassiveTool*>(thisDevice->GetTool(i))->SetToolName(navigationTools->GetTool(j)->GetToolName());
121  //set tip of tool
122  dynamic_cast<mitk::NDIPassiveTool*>(thisDevice->GetTool(i))->SetToolTipPosition(navigationTools->GetTool(j)->GetToolTipPosition(), navigationTools->GetTool(j)->GetToolAxisOrientation());
123  //rember that this tool was already found
124  alreadyFoundTools.push_back(j);
125 
126  toolFound = true;
127  break;
128  }
129  }
130  }
131  if (!toolFound)
132  {
133  errorMessage->append("Error: did not find every automatically detected tool in the loaded tool storage: aborting initialization.");
134  return nullptr;
135  }
136  }
137 
138  //And resort them (this was done in TrackingToolBoxWorker before).
139  for (unsigned int i = 0; i < newToolStorageInRightOrder->GetToolCount(); i++)
140  {
141  navigationTools->AssignToolNumber(newToolStorageInRightOrder->GetTool(i)->GetIdentifier(), i);
142  }
143 
144  returnValue->SetTrackingDevice(thisDevice);
145  MITK_DEBUG << "Number of tools of created tracking device: " << thisDevice->GetToolCount();
146  MITK_DEBUG << "Number of outputs of created source: " << returnValue->GetNumberOfOutputs();
147  return returnValue;
148  }
149 }
An object of this class represents an exception of the MITK-IGT module which are releated to the hard...
float k(1.0)
bool OpenConnection() override
Set the type of the NDI Tracking Device because it can not jet handle this itself.
An object of this class represents an exception of the MITK-IGT module.
#define MITK_DEBUG
Definition: mitkLogMacros.h:22
DataCollection - Class to facilitate loading/accessing structured data.
static TrackingDeviceData GetDeviceDataAuroraPlanarDome()
static TrackingDeviceData GetDeviceDataAuroraPlanarCube()
static Pointer New()
Constructs a NavigationToolStorage without reference to a DataStorage. The Data Nodes of tools have t...
Implementation of a passive NDI optical tool.
TrackingDeviceSource::Pointer CreateTrackingDeviceSource(mitk::TrackingDevice::Pointer trackingDevice, mitk::NavigationToolStorage::Pointer navigationTools, std::string *errorMessage, std::vector< int > *toolCorrespondencesInToolStorage) override
std::vector< TrackingDeviceData > m_TrackingDeviceData
static TrackingDeviceData GetDeviceDataAuroraCompact()
superclass for specific NDI tracking Devices that use serial communication.
static TrackingDeviceData GetDeviceDataAuroraTabletop()