Medical Imaging Interaction Toolkit  2016.11.0
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,
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 "mitkIGTHardwareException.h"
20 #include "mitkNDITrackingDevice.h"
21 
22 namespace mitk
23 {
25  {
26  return "NDI Aurora";
27  }
28 
30  {
31  TrackingDeviceData data = { NDIAuroraTypeInformation::GetTrackingDeviceName(), "Aurora Compact", "NDIAuroraCompactFG_Dome.stl", "A" };
32  return data;
33  }
34 
36  {
37  TrackingDeviceData data = { NDIAuroraTypeInformation::GetTrackingDeviceName(), "Aurora Planar (Cube)", "NDIAurora.stl", "9" };
38  return data;
39  }
40 
42  {
43  TrackingDeviceData data = { NDIAuroraTypeInformation::GetTrackingDeviceName(), "Aurora Planar (Dome)", "NDIAuroraPlanarFG_Dome.stl", "A" };
44  return data;
45  }
46 
48  {
49  TrackingDeviceData data = { NDIAuroraTypeInformation::GetTrackingDeviceName(), "Aurora Tabletop", "NDIAuroraTabletopFG_Dome.stl", "A" };
50  return data;
51  }
52 
54  {
60  }
61 
63  {
64  }
65 
67  mitk::TrackingDevice::Pointer trackingDevice,
69  std::string* errorMessage,
70  std::vector<int>* toolCorrespondencesInToolStorage)
71  {
72  MITK_DEBUG << "Creating Aurora tracking device.";
74  mitk::NDITrackingDevice::Pointer thisDevice = dynamic_cast<mitk::NDITrackingDevice*>(trackingDevice.GetPointer());
75 
76  try
77  {
78  //connect to aurora to dectect tools automatically
79  thisDevice->OpenConnection();
80  }
82  {
83  errorMessage->append("Hardware error on opening the connection (");
84  errorMessage->append(e.GetDescription());
85  errorMessage->append(")");
86  return NULL;
87  }
88  catch (mitk::IGTException& e)
89  {
90  errorMessage->append("Error on opening the connection (");
91  errorMessage->append(e.GetDescription());
92  errorMessage->append(")");
93  return NULL;
94  }
95 
96  //now search for automatically detected tools in the tool storage and save them
98  std::vector<int> alreadyFoundTools = std::vector<int>();
99  *toolCorrespondencesInToolStorage = std::vector<int>();
100  for (unsigned int i = 0; i < thisDevice->GetToolCount(); i++)
101  {
102  bool toolFound = false;
103  for (int j = 0; j < navigationTools->GetToolCount(); j++)
104  {
105  //check if the serial number is the same to identify the tool
106  if ((dynamic_cast<mitk::NDIPassiveTool*>(thisDevice->GetTool(i)))->GetSerialNumber() == navigationTools->GetTool(j)->GetSerialNumber())
107  {
108  //check if this tool was already added to make sure that every tool is only added once (in case of same serial numbers)
109  bool toolAlreadyAdded = false;
110  for (unsigned int k = 0; k < alreadyFoundTools.size(); k++) if (alreadyFoundTools.at(k) == j) toolAlreadyAdded = true;
111 
112  if (!toolAlreadyAdded)
113  {
114  //add tool in right order
115  newToolStorageInRightOrder->AddTool(navigationTools->GetTool(j));
116  toolCorrespondencesInToolStorage->push_back(j);
117  //adapt name of tool
118  dynamic_cast<mitk::NDIPassiveTool*>(thisDevice->GetTool(i))->SetToolName(navigationTools->GetTool(j)->GetToolName());
119  //set tip of tool
120  dynamic_cast<mitk::NDIPassiveTool*>(thisDevice->GetTool(i))->SetToolTip(navigationTools->GetTool(j)->GetToolTipPosition(), navigationTools->GetTool(j)->GetToolTipOrientation());
121  //rember that this tool was already found
122  alreadyFoundTools.push_back(j);
123 
124  toolFound = true;
125  break;
126  }
127  }
128  }
129  if (!toolFound)
130  {
131  errorMessage->append("Error: did not find every automatically detected tool in the loaded tool storage: aborting initialization.");
132  return NULL;
133  }
134  }
135 
136  //delete all tools from the tool storage
137  navigationTools->DeleteAllTools();
138 
139  //and add only the detected tools in the right order
140  for (int i = 0; i < newToolStorageInRightOrder->GetToolCount(); i++)
141  {
142  navigationTools->AddTool(newToolStorageInRightOrder->GetTool(i));
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...
itk::SmartPointer< Self > Pointer
virtual 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:26
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.
virtual 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()