diff --git a/Modules/IGT/DataManagement/mitkTrackingDeviceTypeCollection.cpp b/Modules/IGT/DataManagement/mitkTrackingDeviceTypeCollection.cpp index d81b497f12..fbec3adf31 100644 --- a/Modules/IGT/DataManagement/mitkTrackingDeviceTypeCollection.cpp +++ b/Modules/IGT/DataManagement/mitkTrackingDeviceTypeCollection.cpp @@ -1,116 +1,125 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkTrackingDeviceTypeCollection.h" #include "mitkUnspecifiedTrackingTypeInformation.h" //Microservices #include #include mitk::TrackingDeviceTypeCollection::TrackingDeviceTypeCollection() - : m_TrackingDeviceTypeInformations() + : m_ServiceRegistration() + , m_TrackingDeviceTypeInformations() { } mitk::TrackingDeviceTypeCollection::~TrackingDeviceTypeCollection() { + std::vector::iterator iter = m_TrackingDeviceTypeInformations.begin(); + + for (; iter != m_TrackingDeviceTypeInformations.end(); iter++) + { + delete (*iter); + } + + m_TrackingDeviceTypeInformations.clear(); } void mitk::TrackingDeviceTypeCollection::RegisterAsMicroservice() { us::ModuleContext* context = us::GetModuleContext(); m_ServiceRegistration = context->RegisterService(this); } void mitk::TrackingDeviceTypeCollection::UnRegisterMicroservice() { if (m_ServiceRegistration != nullptr) m_ServiceRegistration.Unregister(); m_ServiceRegistration = 0; } void mitk::TrackingDeviceTypeCollection::RegisterTrackingDeviceType(TrackingDeviceTypeInformation* typeInformation) { if (typeInformation != nullptr) { m_TrackingDeviceTypeInformations.push_back(typeInformation); } } mitk::TrackingDeviceTypeInformation* mitk::TrackingDeviceTypeCollection::GetTrackingDeviceTypeInformation(mitk::TrackingDeviceType type) { for (auto deviceType : m_TrackingDeviceTypeInformations) { if (deviceType->GetTrackingDeviceName() == type) { return deviceType; } } return nullptr; } std::vector mitk::TrackingDeviceTypeCollection::GetDeviceDataForLine(TrackingDeviceType type) { for (auto deviceType : m_TrackingDeviceTypeInformations) { if (deviceType->GetTrackingDeviceName() == type) { return deviceType->m_TrackingDeviceData; } } return std::vector(); } mitk::TrackingDeviceData mitk::TrackingDeviceTypeCollection::GetFirstCompatibleDeviceDataForLine(TrackingDeviceType type) { if (GetDeviceDataForLine(type).empty()) { return mitk::UnspecifiedTrackingTypeInformation::GetDeviceDataInvalid(); } return GetDeviceDataForLine(type).front(); } mitk::TrackingDeviceData mitk::TrackingDeviceTypeCollection::GetDeviceDataByName(const std::string& modelName) { for (auto deviceType : m_TrackingDeviceTypeInformations) { for (auto deviceData : deviceType->m_TrackingDeviceData) { if (deviceData.Model == modelName) { return deviceData; } } } return mitk::UnspecifiedTrackingTypeInformation::GetDeviceDataInvalid(); } std::vector mitk::TrackingDeviceTypeCollection::GetTrackingDeviceTypeNames() { std::vector names; for (auto deviceType : m_TrackingDeviceTypeInformations) { names.push_back(deviceType->GetTrackingDeviceName()); } return names; } diff --git a/Modules/IGT/DataManagement/mitkTrackingDeviceTypeCollection.h b/Modules/IGT/DataManagement/mitkTrackingDeviceTypeCollection.h index fb4c505249..d1bb2971cd 100644 --- a/Modules/IGT/DataManagement/mitkTrackingDeviceTypeCollection.h +++ b/Modules/IGT/DataManagement/mitkTrackingDeviceTypeCollection.h @@ -1,88 +1,87 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef TRACKINGDEVICETYPECOLLECTION_H_INCLUDED #define TRACKINGDEVICETYPECOLLECTION_H_INCLUDED #include -#include "mitkTrackingTypes.h" #include "mitkTrackingDeviceTypeInformation.h" // Microservices #include #include namespace mitk { /** Documentation: * \brief This class is a collection for information of all Tracking Device Types (derived from abstract TrackingDeviceTypeInformation) * The Collection is avaiable via Microservice. * If you want to add your own tracking device (e.g. to the Tracking Toolbox), you should register * information about your tracking device in this collection using the RegisterTrackingDeviceType function. * * The Microservice provides all compatible TrackingDeviceDatas for a requested tracking device type or a list of all available Tracking Devices. * * \ingroup IGTUI */ class MITKIGT_EXPORT TrackingDeviceTypeCollection { public: TrackingDeviceTypeCollection(); ~TrackingDeviceTypeCollection(); /** *\brief Registers this object as a Microservice, making it available to every module and/or plugin. * To unregister, call UnregisterMicroservice(). */ virtual void RegisterAsMicroservice(); /** *\brief Registers this object as a Microservice, making it available to every module and/or plugin. */ virtual void UnRegisterMicroservice(); void RegisterTrackingDeviceType(TrackingDeviceTypeInformation* typeInformation); TrackingDeviceTypeInformation* GetTrackingDeviceTypeInformation(TrackingDeviceType type); std::vector GetTrackingDeviceTypeNames(); /** * /brief Returns all devices compatibel to the given Line of Devices */ std::vector GetDeviceDataForLine(TrackingDeviceType type); /** * /brief Returns the first TrackingDeviceData matching a given line. Useful for backward compatibility * with the old way to manage devices. */ TrackingDeviceData GetFirstCompatibleDeviceDataForLine(TrackingDeviceType type); /** * /brief Returns the device Data set matching the model name or the invalid device, if none was found. */ TrackingDeviceData GetDeviceDataByName(const std::string& modelName); private: us::ServiceRegistration m_ServiceRegistration; std::vector m_TrackingDeviceTypeInformations; }; } // namespace mitk MITK_DECLARE_SERVICE_INTERFACE(mitk::TrackingDeviceTypeCollection, "org.mitk.services.TrackingDeviceTypeCollection") #endif //TRACKINGDEVICETYPECOLLECTION_H_INCLUDED diff --git a/Modules/IGT/TrackingDevices/mitkMicronTrackerTypeInformation.h b/Modules/IGT/TrackingDevices/mitkMicronTrackerTypeInformation.h index 19a368f393..3e30248278 100644 --- a/Modules/IGT/TrackingDevices/mitkMicronTrackerTypeInformation.h +++ b/Modules/IGT/TrackingDevices/mitkMicronTrackerTypeInformation.h @@ -1,47 +1,45 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkMicronTrackerTypeInformation_h #define mitkMicronTrackerTypeInformation_h -#include - #include "mitkTrackingDeviceTypeInformation.h" namespace mitk { /** Documentation: * \brief Type information for Micron Tracking Devices. * * \ingroup IGTUI */ class MITKIGT_EXPORT MicronTrackerTypeInformation : public TrackingDeviceTypeInformation { public: MicronTrackerTypeInformation(); virtual ~MicronTrackerTypeInformation(); virtual TrackingDeviceSource::Pointer CreateTrackingDeviceSource(mitk::TrackingDevice::Pointer trackingDevice, mitk::NavigationToolStorage::Pointer navigationTools, std::string* errorMessage, std::vector* toolCorrespondencesInToolStorage) override; static std::string GetTrackingDeviceName(); static TrackingDeviceData GetDeviceDataMicronTrackerH40(); }; } // namespace mitk #endif //mitkMicronTrackerTypeInformation_h diff --git a/Modules/IGT/TrackingDevices/mitkNDIAuroraTypeInformation.cpp b/Modules/IGT/TrackingDevices/mitkNDIAuroraTypeInformation.cpp index debf5a1631..921083741c 100644 --- a/Modules/IGT/TrackingDevices/mitkNDIAuroraTypeInformation.cpp +++ b/Modules/IGT/TrackingDevices/mitkNDIAuroraTypeInformation.cpp @@ -1,149 +1,149 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkNDIAuroraTypeInformation.h" #include "mitkIGTHardwareException.h" #include "mitkNDITrackingDevice.h" namespace mitk { std::string NDIAuroraTypeInformation::GetTrackingDeviceName() { return "NDI Aurora"; } TrackingDeviceData NDIAuroraTypeInformation::GetDeviceDataAuroraCompact() { TrackingDeviceData data = { NDIAuroraTypeInformation::GetTrackingDeviceName(), "Aurora Compact", "NDIAuroraCompactFG_Dome.stl", "A" }; return data; } TrackingDeviceData NDIAuroraTypeInformation::GetDeviceDataAuroraPlanarCube() { TrackingDeviceData data = { NDIAuroraTypeInformation::GetTrackingDeviceName(), "Aurora Planar (Cube)", "NDIAurora.stl", "9" }; return data; } TrackingDeviceData NDIAuroraTypeInformation::GetDeviceDataAuroraPlanarDome() { TrackingDeviceData data = { NDIAuroraTypeInformation::GetTrackingDeviceName(), "Aurora Planar (Dome)", "NDIAuroraPlanarFG_Dome.stl", "A" }; return data; } TrackingDeviceData NDIAuroraTypeInformation::GetDeviceDataAuroraTabletop() { TrackingDeviceData data = { NDIAuroraTypeInformation::GetTrackingDeviceName(), "Aurora Tabletop", "NDIAuroraTabletopFG_Dome.stl", "A" }; return data; } NDIAuroraTypeInformation::NDIAuroraTypeInformation() { m_DeviceName = NDIAuroraTypeInformation::GetTrackingDeviceName(); m_TrackingDeviceData.push_back(GetDeviceDataAuroraCompact()); m_TrackingDeviceData.push_back(GetDeviceDataAuroraPlanarCube()); m_TrackingDeviceData.push_back(GetDeviceDataAuroraPlanarDome()); m_TrackingDeviceData.push_back(GetDeviceDataAuroraTabletop()); } NDIAuroraTypeInformation::~NDIAuroraTypeInformation() { } mitk::TrackingDeviceSource::Pointer NDIAuroraTypeInformation::CreateTrackingDeviceSource( mitk::TrackingDevice::Pointer trackingDevice, mitk::NavigationToolStorage::Pointer navigationTools, std::string* errorMessage, std::vector* toolCorrespondencesInToolStorage) { MITK_DEBUG << "Creating Aurora tracking device."; mitk::TrackingDeviceSource::Pointer returnValue = mitk::TrackingDeviceSource::New(); mitk::NDITrackingDevice::Pointer thisDevice = dynamic_cast(trackingDevice.GetPointer()); try { //connect to aurora to dectect tools automatically thisDevice->OpenConnection(); } catch (mitk::IGTHardwareException& e) { errorMessage->append("Hardware error on opening the connection ("); errorMessage->append(e.GetDescription()); errorMessage->append(")"); return NULL; } catch (mitk::IGTException& e) { errorMessage->append("Error on opening the connection ("); errorMessage->append(e.GetDescription()); errorMessage->append(")"); return NULL; } //now search for automatically detected tools in the tool storage and save them mitk::NavigationToolStorage::Pointer newToolStorageInRightOrder = mitk::NavigationToolStorage::New(); std::vector alreadyFoundTools = std::vector(); *toolCorrespondencesInToolStorage = std::vector(); for (unsigned int i = 0; i < thisDevice->GetToolCount(); i++) { bool toolFound = false; for (int j = 0; j < navigationTools->GetToolCount(); j++) { //check if the serial number is the same to identify the tool if ((dynamic_cast(thisDevice->GetTool(i)))->GetSerialNumber() == navigationTools->GetTool(j)->GetSerialNumber()) { //check if this tool was already added to make sure that every tool is only added once (in case of same serial numbers) bool toolAlreadyAdded = false; for (unsigned int k = 0; k < alreadyFoundTools.size(); k++) if (alreadyFoundTools.at(k) == j) toolAlreadyAdded = true; if (!toolAlreadyAdded) { //add tool in right order newToolStorageInRightOrder->AddTool(navigationTools->GetTool(j)); toolCorrespondencesInToolStorage->push_back(j); //adapt name of tool dynamic_cast(thisDevice->GetTool(i))->SetToolName(navigationTools->GetTool(j)->GetToolName()); //set tip of tool dynamic_cast(thisDevice->GetTool(i))->SetToolTip(navigationTools->GetTool(j)->GetToolTipPosition(), navigationTools->GetTool(j)->GetToolTipOrientation()); //rember that this tool was already found alreadyFoundTools.push_back(j); toolFound = true; break; } } } if (!toolFound) { errorMessage->append("Error: did not find every automatically detected tool in the loaded tool storage: aborting initialization."); return NULL; } } //delete all tools from the tool storage navigationTools->DeleteAllTools(); //and add only the detected tools in the right order for (int i = 0; i < newToolStorageInRightOrder->GetToolCount(); i++) { navigationTools->AddTool(newToolStorageInRightOrder->GetTool(i)); } returnValue->SetTrackingDevice(thisDevice); MITK_DEBUG << "Number of tools of created tracking device: " << thisDevice->GetToolCount(); MITK_DEBUG << "Number of outputs of created source: " << returnValue->GetNumberOfOutputs(); return returnValue; } -} \ No newline at end of file +} diff --git a/Modules/IGT/TrackingDevices/mitkNDIAuroraTypeInformation.h b/Modules/IGT/TrackingDevices/mitkNDIAuroraTypeInformation.h index ee223f2c87..6a6d73558e 100644 --- a/Modules/IGT/TrackingDevices/mitkNDIAuroraTypeInformation.h +++ b/Modules/IGT/TrackingDevices/mitkNDIAuroraTypeInformation.h @@ -1,51 +1,49 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkNDIAuroraTypeInformation_h #define mitkNDIAuroraTypeInformation_h -#include - #include "mitkTrackingDeviceTypeInformation.h" namespace mitk { /** Documentation: * \brief Type information for NDI Aurora * * \ingroup IGTUI */ class MITKIGT_EXPORT NDIAuroraTypeInformation : public TrackingDeviceTypeInformation { public: NDIAuroraTypeInformation(); virtual ~NDIAuroraTypeInformation(); virtual TrackingDeviceSource::Pointer CreateTrackingDeviceSource(mitk::TrackingDevice::Pointer trackingDevice, mitk::NavigationToolStorage::Pointer navigationTools, std::string* errorMessage, std::vector* toolCorrespondencesInToolStorage) override; static std::string GetTrackingDeviceName(); static TrackingDeviceData GetDeviceDataAuroraCompact(); static TrackingDeviceData GetDeviceDataAuroraPlanarCube(); static TrackingDeviceData GetDeviceDataAuroraPlanarDome(); static TrackingDeviceData GetDeviceDataAuroraTabletop(); }; } // namespace mitk #endif //mitkNDIAuroraTypeInformation_h diff --git a/Modules/IGT/TrackingDevices/mitkNDIPolarisTypeInformation.cpp b/Modules/IGT/TrackingDevices/mitkNDIPolarisTypeInformation.cpp index 6af519ac61..d2aeae0302 100644 --- a/Modules/IGT/TrackingDevices/mitkNDIPolarisTypeInformation.cpp +++ b/Modules/IGT/TrackingDevices/mitkNDIPolarisTypeInformation.cpp @@ -1,92 +1,90 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkNDIPolarisTypeInformation.h" #include "mitkNDITrackingDevice.h" namespace mitk { std::string NDIPolarisTypeInformation::GetTrackingDeviceName() { return "NDI Polaris"; ///< Polaris: optical Tracker from NDI; } TrackingDeviceData NDIPolarisTypeInformation::GetDeviceDataPolarisOldModel() { TrackingDeviceData data = { NDIPolarisTypeInformation::GetTrackingDeviceName(), "Polaris (Old Model)", "NDIPolarisOldModel.stl", "0" }; return data; } TrackingDeviceData NDIPolarisTypeInformation::GetDeviceDataPolarisSpectra() { //full hardware code of polaris spectra: 5-240000-153200-095000+057200+039800+056946+024303+029773+999999+99999924 TrackingDeviceData data = { NDIPolarisTypeInformation::GetTrackingDeviceName(), "Polaris Spectra", "NDIPolarisSpectra.stl", "5-2" }; return data; } TrackingDeviceData NDIPolarisTypeInformation::GetDeviceDataSpectraExtendedPyramid() { //full hardware code of polaris spectra (extended pyramid): 5-300000-153200-095000+057200+039800+056946+024303+029773+999999+07350024 TrackingDeviceData data = { NDIPolarisTypeInformation::GetTrackingDeviceName(), "Polaris Spectra (Extended Pyramid)", "NDIPolarisSpectraExtendedPyramid.stl", "5-3" }; return data; } TrackingDeviceData NDIPolarisTypeInformation::GetDeviceDataPolarisVicra() { TrackingDeviceData data = { NDIPolarisTypeInformation::GetTrackingDeviceName(), "Polaris Vicra", "NDIPolarisVicra.stl", "7" }; return data; } NDIPolarisTypeInformation::NDIPolarisTypeInformation() - //: m_DeviceName("Polaris") - //, m_Widget(nullptr) { m_DeviceName = NDIPolarisTypeInformation::GetTrackingDeviceName(); m_TrackingDeviceData.push_back(GetDeviceDataPolarisOldModel()); m_TrackingDeviceData.push_back(GetDeviceDataSpectraExtendedPyramid()); m_TrackingDeviceData.push_back(GetDeviceDataPolarisSpectra()); m_TrackingDeviceData.push_back(GetDeviceDataPolarisVicra()); } NDIPolarisTypeInformation::~NDIPolarisTypeInformation() { } mitk::TrackingDeviceSource::Pointer NDIPolarisTypeInformation::CreateTrackingDeviceSource( mitk::TrackingDevice::Pointer trackingDevice, mitk::NavigationToolStorage::Pointer navigationTools, std::string* errorMessage, std::vector* toolCorrespondencesInToolStorage) { mitk::TrackingDeviceSource::Pointer returnValue = mitk::TrackingDeviceSource::New(); mitk::NDITrackingDevice::Pointer thisDevice = dynamic_cast(trackingDevice.GetPointer()); *toolCorrespondencesInToolStorage = std::vector(); //add the tools to the tracking device for (int i = 0; i < navigationTools->GetToolCount(); i++) { mitk::NavigationTool::Pointer thisNavigationTool = navigationTools->GetTool(i); toolCorrespondencesInToolStorage->push_back(i); bool toolAddSuccess = thisDevice->AddTool(thisNavigationTool->GetToolName().c_str(), thisNavigationTool->GetCalibrationFile().c_str()); if (!toolAddSuccess) { //todo: error handling errorMessage->append("Can't add tool, is the SROM-file valid?"); return NULL; } thisDevice->GetTool(i)->SetToolTip(thisNavigationTool->GetToolTipPosition(), thisNavigationTool->GetToolTipOrientation()); } returnValue->SetTrackingDevice(thisDevice); return returnValue; } -} \ No newline at end of file +} diff --git a/Modules/IGT/TrackingDevices/mitkNDIPolarisTypeInformation.h b/Modules/IGT/TrackingDevices/mitkNDIPolarisTypeInformation.h index 0648616bd6..dd01472be4 100644 --- a/Modules/IGT/TrackingDevices/mitkNDIPolarisTypeInformation.h +++ b/Modules/IGT/TrackingDevices/mitkNDIPolarisTypeInformation.h @@ -1,50 +1,48 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef NDIPOLARISTYPEINFORMATION_H_INCLUDED #define NDIPOLARISTYPEINFORMATION_H_INCLUDED -#include - #include "mitkTrackingDeviceTypeInformation.h" namespace mitk { /** Documentation: * \brief Type information for NDI Polaris * * \ingroup IGTUI */ class MITKIGT_EXPORT NDIPolarisTypeInformation : public TrackingDeviceTypeInformation { public: NDIPolarisTypeInformation(); virtual ~NDIPolarisTypeInformation(); virtual TrackingDeviceSource::Pointer CreateTrackingDeviceSource(mitk::TrackingDevice::Pointer trackingDevice, mitk::NavigationToolStorage::Pointer navigationTools, std::string* errorMessage, std::vector* toolCorrespondencesInToolStorage) override; static std::string GetTrackingDeviceName(); static TrackingDeviceData GetDeviceDataPolarisOldModel(); static TrackingDeviceData GetDeviceDataSpectraExtendedPyramid(); static TrackingDeviceData GetDeviceDataPolarisSpectra(); static TrackingDeviceData GetDeviceDataPolarisVicra(); }; } // namespace mitk #endif //NDIPOLARISTYPEINFORMATION_H_INCLUDED diff --git a/Modules/IGT/TrackingDevices/mitkNDITrackingDevice.h b/Modules/IGT/TrackingDevices/mitkNDITrackingDevice.h index 592fde0b04..ce05dd0425 100644 --- a/Modules/IGT/TrackingDevices/mitkNDITrackingDevice.h +++ b/Modules/IGT/TrackingDevices/mitkNDITrackingDevice.h @@ -1,325 +1,324 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKNDITRACKINGDEVICE_H_HEADER_INCLUDED_C1C2FCD2 #define MITKNDITRACKINGDEVICE_H_HEADER_INCLUDED_C1C2FCD2 #include "mitkTrackingDevice.h" #include #include #include "itkFastMutexLock.h" #include -#include "mitkTrackingTypes.h" #include "mitkNDIProtocol.h" #include "mitkNDIPassiveTool.h" #include "mitkSerialCommunication.h" namespace mitk { class NDIProtocol; /** Documentation * \brief superclass for specific NDI tracking Devices that use serial communication. * * implements the TrackingDevice interface for NDI tracking devices (POLARIS, AURORA) * * \ingroup IGT */ class MITKIGT_EXPORT NDITrackingDevice : public TrackingDevice { friend class NDIProtocol; public: typedef std::vector Tool6DContainerType; ///< List of 6D tools of the correct type for this tracking device typedef mitk::TrackingDeviceType NDITrackingDeviceType; ///< This enumeration includes the two types of NDI tracking devices (Polaris, Aurora). typedef mitk::SerialCommunication::PortNumber PortNumber; ///< Port number of the serial connection typedef mitk::SerialCommunication::BaudRate BaudRate; ///< Baud rate of the serial connection typedef mitk::SerialCommunication::DataBits DataBits; ///< Number of data bits used in the serial connection typedef mitk::SerialCommunication::Parity Parity; ///< Parity mode used in the serial connection typedef mitk::SerialCommunication::StopBits StopBits; ///< Number of stop bits used in the serial connection typedef mitk::SerialCommunication::HardwareHandshake HardwareHandshake; ///< Hardware handshake mode of the serial connection typedef mitk::NDIPassiveTool::TrackingPriority TrackingPriority; ///< Tracking priority used for tracking a tool mitkClassMacro(NDITrackingDevice, TrackingDevice); itkFactorylessNewMacro(Self) itkCloneMacro(Self) /** * \brief Set the type of the NDI Tracking Device because it can not jet handle this itself */ //itkSetMacro(Type, TrackingDeviceType); /** * \brief initialize the connection to the tracking device * * OpenConnection() establishes the connection to the tracking device by: * - initializing the serial port with the given parameters (port number, baud rate, ...) * - connection to the tracking device * - initializing the device * - initializing all manually added passive tools (user supplied srom file) * - initializing active tools that are connected to the tracking device * @throw mitk::IGTHardwareException Throws an exception if there are errors while connecting to the device. * @throw mitk::IGTException Throws a normal IGT exception if an error occures which is not related to the hardware. */ virtual bool OpenConnection() override; /** * \brief Closes the connection * * CloseConnection() resets the tracking device, invalidates all tools and then closes the serial port. */ virtual bool CloseConnection() override; /** @throw mitk::IGTHardwareException Throws an exception if there are errors while connecting to the device. */ bool InitializeWiredTools(); /** Sets the rotation mode of this class. See documentation of enum RotationMode for details * on the different modes. */ virtual void SetRotationMode(RotationMode r) override; /** * \brief TestConnection() tries to connect to a NDI tracking device on the current port/device and returns which device it has found * * TestConnection() tries to connect to a NDI tracking device on the current port/device. * \return It returns the type of the device that answers at the port/device. Throws an exception if no device is available on that port. * @throw mitk::IGTHardwareException Throws an exception if there are errors while connecting to the device. */ virtual mitk::TrackingDeviceType TestConnection(); /** * \brief retrieves all wired tools from the tracking device * * This method queries the tracking device for all wired tools, initializes them and creates TrackingTool representation objects * for them * \return True if the method was executed successful. * @throw mitk::IGTHardwareException Throws an exception if there are errors while connecting to the device. * @throw mitk::IGTException Throws a normal IGT exception if an error occures which is not related to the hardware. */ bool DiscoverWiredTools(); /** * \brief Start the tracking. * * A new thread is created, which continuously reads the position and orientation information of each tool and stores them inside the tools. * Depending on the current operation mode (see SetOperationMode()), either the 6D tools (ToolTracking6D), 5D tools (ToolTracking5D), * 3D marker positions (MarkerTracking3D) or both 6D tools and 3D markers (HybridTracking) are updated. * Call StopTracking() to stop the tracking thread. */ virtual bool StartTracking() override; /** * \brief return the tool with index toolNumber */ virtual TrackingTool* GetTool(unsigned int toolNumber) const override; virtual mitk::TrackingTool* GetToolByName(std::string name) const override; /** * \brief return current number of tools */ virtual unsigned int GetToolCount() const override; /** * \brief Create a passive 6D tool with toolName and fileName and add it to the list of tools * * This method will create a new NDIPassiveTool object, load the SROM file fileName, * set the tool name toolName and the tracking priority p and then add * it to the list of tools. It returns a pointer of type mitk::TrackingTool to the tool * that can be used to read tracking data from it. * This is the only way to add tools to NDITrackingDevice. * @throw mitk::IGTHardwareException Throws an exception if there are errors while adding the tool. * * \warning adding tools is not possible in tracking mode, only in setup and ready. */ mitk::TrackingTool* AddTool(const char* toolName, const char* fileName, TrackingPriority p = NDIPassiveTool::Dynamic); /** * \brief Remove a passive 6D tool from the list of tracked tools. * * \warning removing tools is not possible in tracking mode, only in setup and ready modes. */ virtual bool RemoveTool(TrackingTool* tool); /** * \brief reloads the srom file and reinitializes the tool */ virtual bool UpdateTool(mitk::TrackingTool* tool); virtual void SetPortNumber(const PortNumber _arg); ///< set port number for serial communication itkGetConstMacro(PortNumber, PortNumber); ///< returns the port number for serial communication virtual void SetDeviceName(std::string _arg); ///< set device name (e.g. COM1, /dev/ttyUSB0). If this is set, PortNumber will be ignored itkGetStringMacro(DeviceName); ///< returns the device name for serial communication virtual void SetBaudRate(const BaudRate _arg); ///< set baud rate for serial communication itkGetConstMacro(BaudRate, BaudRate); ///< returns the baud rate for serial communication virtual void SetDataBits(const DataBits _arg); ///< set number of data bits itkGetConstMacro(DataBits, DataBits); ///< returns the data bits for serial communication virtual void SetParity(const Parity _arg); ///< set parity mode itkGetConstMacro(Parity, Parity); ///< returns the parity mode virtual void SetStopBits(const StopBits _arg); ///< set number of stop bits itkGetConstMacro(StopBits, StopBits); ///< returns the number of stop bits virtual void SetHardwareHandshake(const HardwareHandshake _arg); ///< set use hardware handshake for serial communication itkGetConstMacro(HardwareHandshake, HardwareHandshake); ///< returns the hardware handshake setting virtual void SetIlluminationActivationRate(const IlluminationActivationRate _arg); ///< set activation rate of IR illumator for polaris itkGetConstMacro(IlluminationActivationRate, IlluminationActivationRate); ///< returns the activation rate of IR illumator for polaris virtual void SetDataTransferMode(const DataTransferMode _arg); ///< set data transfer mode to text (TX) or binary (BX). \warning: only TX is supportet at the moment itkGetConstMacro(DataTransferMode, DataTransferMode); ///< returns the data transfer mode virtual bool Beep(unsigned char count); ///< Beep the tracking device 1 to 9 times NDIErrorCode GetErrorCode(const std::string* input); ///< returns the error code for a string that contains an error code in hexadecimal format virtual bool SetOperationMode(OperationMode mode); ///< set operation mode to 6D tool tracking, 3D marker tracking or 6D&3D hybrid tracking (see OperationMode) virtual OperationMode GetOperationMode(); ///< get current operation mode /** * \brief Get 3D marker positions (operation mode must be set to MarkerTracking3D or HybridTracking) */ virtual bool GetMarkerPositions(MarkerPointContainerType* markerpositions); /** * \brief Get major revision number from tracking device * should not be called directly after starting to track **/ virtual int GetMajorFirmwareRevisionNumber(); /** * \brief Get revision number from tracking device as string * should not be called directly after starting to track **/ virtual const char* GetFirmwareRevisionNumber(); protected: typedef std::vector NDITrackingVolumeContainerType; ///< vector of tracking volumes typedef std::vector TrackingVolumeDimensionType; ///< List of the supported tracking volume dimensions. /** * \brief Get number of supported tracking volumes, a vector containing the supported volumes and * a vector containing the signed dimensions in mm. For each volume 10 boundaries are stored in the order of * the supported volumes (see AURORA API GUIDE: SFLIST p.54). **/ virtual bool GetSupportedVolumes(unsigned int* numberOfVolumes, NDITrackingVolumeContainerType* volumes, TrackingVolumeDimensionType* volumesDimensions); /** * \brief Sets the desired tracking volume. Returns true if the volume type could be set. It is set in the OpenConnection() Method and sets the tracking volume out of m_Data. * @throw mitk::IGTHardwareException Throws an IGT hardware exception if the volume could not be set. **/ virtual bool SetVolume(mitk::TrackingDeviceData volume); /** * \brief Add a passive 6D tool to the list of tracked tools. This method is used by AddTool * @throw mitk::IGTHardwareException Throws an exception if there are errors while adding the tool. * \warning adding tools is not possible in tracking mode, only in setup and ready. */ virtual bool InternalAddTool(NDIPassiveTool* tool); /* Methods for NDIProtocol friend class */ virtual void InvalidateAll(); ///< invalidate all tools NDIPassiveTool* GetInternalTool(std::string portHandle); ///< returns the tool object that has been assigned the port handle or NULL if no tool can be found /** * \brief free all port handles that need to be freed * * This method retrieves a list of all port handles that need to be freed (e.g. tool got disconnected) * and frees the handles at the tracking device and it removes the tools from the internal tool list * \warning This method can remove TrackingTools from the tool list! After calling this method, GetTool(i) could return * a different tool, because tool indices could have changed. * @throw mitk::IGTHardwareException Throws an exception if there are errors while communicating with the device. * \return returns NDIOKAY if everything was sucessfull, returns an error code otherwise */ NDIErrorCode FreePortHandles(); NDIErrorCode Send(const std::string* message, bool addCRC = true); ///< Send message to tracking device NDIErrorCode Receive(std::string* answer, unsigned int numberOfBytes); ///< receive numberOfBytes bytes from tracking device NDIErrorCode ReceiveByte(char* answer); ///< lightweight receive function, that reads just one byte NDIErrorCode ReceiveLine(std::string* answer); ///< receive characters until the first LF (The LF is included in the answer string) void ClearSendBuffer(); ///< empty send buffer of serial communication interface void ClearReceiveBuffer(); ///< empty receive buffer of serial communication interface const std::string CalcCRC(const std::string* input); ///< returns the CRC16 for input as a std::string public: /** * \brief TrackTools() continuously polls serial interface for new 6d tool positions until StopTracking is called. * * Continuously tracks the 6D position of all tools until StopTracking() is called. * This function is executed by the tracking thread (through StartTracking() and ThreadStartTracking()). * It should not be called directly. * @throw mitk::IGTHardwareException Throws an exception if there are errors while tracking the tools. */ virtual void TrackTools(); /** * \brief continuously polls serial interface for new 3D marker positions until StopTracking is called. * * Continuously tracks the 3D position of all markers until StopTracking() is called. * This function is executed by the tracking thread (through StartTracking() and ThreadStartTracking()). * It should not be called directly. */ virtual void TrackMarkerPositions(); /** * \brief continuously polls serial interface for new 3D marker positions and 6D tool positions until StopTracking is called. * * Continuously tracks the 3D position of all markers and the 6D position of all tools until StopTracking() is called. * This function is executed by the tracking thread (through StartTracking() and ThreadStartTracking()). * It should not be called directly. */ virtual void TrackToolsAndMarkers(); /** * \brief static start method for the tracking thread. */ static ITK_THREAD_RETURN_TYPE ThreadStartTracking(void* data); protected: NDITrackingDevice(); ///< Constructor virtual ~NDITrackingDevice(); ///< Destructor std::string m_DeviceName;///< Device Name PortNumber m_PortNumber; ///< COM Port Number BaudRate m_BaudRate; ///< COM Port Baud Rate DataBits m_DataBits; ///< Number of Data Bits per token Parity m_Parity; ///< Parity mode for communication StopBits m_StopBits; ///< number of stop bits per token HardwareHandshake m_HardwareHandshake; ///< use hardware handshake for serial port connection ///< which tracking volume is currently used (if device supports multiple volumes) (\warning This parameter is not used yet) IlluminationActivationRate m_IlluminationActivationRate; ///< update rate of IR illuminator for Polaris DataTransferMode m_DataTransferMode; ///< use TX (text) or BX (binary) (\warning currently, only TX mode is supported) Tool6DContainerType m_6DTools; ///< list of 6D tools itk::FastMutexLock::Pointer m_ToolsMutex; ///< mutex for coordinated access of tool container mitk::SerialCommunication::Pointer m_SerialCommunication; ///< serial communication interface itk::FastMutexLock::Pointer m_SerialCommunicationMutex; ///< mutex for coordinated access of serial communication interface NDIProtocol::Pointer m_DeviceProtocol; ///< create and parse NDI protocol strings itk::MultiThreader::Pointer m_MultiThreader; ///< creates tracking thread that continuously polls serial interface for new tracking data int m_ThreadID; ///< ID of tracking thread OperationMode m_OperationMode; ///< tracking mode (6D tool tracking, 3D marker tracking,...) itk::FastMutexLock::Pointer m_MarkerPointsMutex; ///< mutex for marker point data container MarkerPointContainerType m_MarkerPoints; ///< container for markers (3D point tracking mode) }; } // namespace mitk #endif /* MITKNDITRACKINGDEVICE_H_HEADER_INCLUDED_C1C2FCD2 */ diff --git a/Modules/IGT/TrackingDevices/mitkNPOptitrackTrackingTypeInformation.h b/Modules/IGT/TrackingDevices/mitkNPOptitrackTrackingTypeInformation.h index 833731fc7a..23557c9d1a 100644 --- a/Modules/IGT/TrackingDevices/mitkNPOptitrackTrackingTypeInformation.h +++ b/Modules/IGT/TrackingDevices/mitkNPOptitrackTrackingTypeInformation.h @@ -1,48 +1,46 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkNPOptitrackTrackingTypeInformation_h #define mitkNPOptitrackTrackingTypeInformation_h -#include - #include "mitkTrackingDeviceTypeInformation.h" namespace mitk { /** Documentation: * \brief Type information for NP Optitrack * * \ingroup IGTUI */ class MITKIGT_EXPORT NPOptitrackTrackingTypeInformation : public TrackingDeviceTypeInformation { public: NPOptitrackTrackingTypeInformation(); virtual ~NPOptitrackTrackingTypeInformation(); virtual TrackingDeviceSource::Pointer CreateTrackingDeviceSource(TrackingDevice::Pointer trackingDevice, NavigationToolStorage::Pointer navigationTools, std::string* errorMessage, std::vector* toolCorrespondencesInToolStorage) override; static std::string GetTrackingDeviceName(); static TrackingDeviceData GetDeviceDataNPOptitrack(); }; } // namespace mitk #endif //mitkNPOptitrackTrackingTypeInformation_h diff --git a/Modules/IGT/TrackingDevices/mitkOpenIGTLinkTypeInformation.h b/Modules/IGT/TrackingDevices/mitkOpenIGTLinkTypeInformation.h index ef229db055..de1c075767 100644 --- a/Modules/IGT/TrackingDevices/mitkOpenIGTLinkTypeInformation.h +++ b/Modules/IGT/TrackingDevices/mitkOpenIGTLinkTypeInformation.h @@ -1,46 +1,44 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkOpenIGTLinkTypeInformation_h #define mitkOpenIGTLinkTypeInformation_h -#include - #include "mitkTrackingDeviceTypeInformation.h" namespace mitk { /** Documentation: * \brief Type information for tracking devices using OpenIGTLink * * \ingroup IGTUI */ class MITKIGT_EXPORT OpenIGTLinkTypeInformation : public TrackingDeviceTypeInformation { public: OpenIGTLinkTypeInformation(); virtual ~OpenIGTLinkTypeInformation(); virtual TrackingDeviceSource::Pointer CreateTrackingDeviceSource(mitk::TrackingDevice::Pointer trackingDevice, mitk::NavigationToolStorage::Pointer navigationTools, std::string* errorMessage, std::vector*) override; static std::string GetTrackingDeviceName(); static TrackingDeviceData GetDeviceDataOpenIGTLinkTrackingDeviceConnection(); }; } // namespace mitk #endif //mitkOpenIGTLinkTypeInformation_h diff --git a/Modules/IGT/TrackingDevices/mitkUnspecifiedTrackingTypeInformation.cpp b/Modules/IGT/TrackingDevices/mitkUnspecifiedTrackingTypeInformation.cpp index 6dc7b81b65..23f37d17b5 100644 --- a/Modules/IGT/TrackingDevices/mitkUnspecifiedTrackingTypeInformation.cpp +++ b/Modules/IGT/TrackingDevices/mitkUnspecifiedTrackingTypeInformation.cpp @@ -1,60 +1,59 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkUnspecifiedTrackingTypeInformation.h" #include "mitkIGTHardwareException.h" -#include "mitkNDITrackingDevice.h" namespace mitk { std::string UnspecifiedTrackingTypeInformation::GetTrackingDeviceName() { return "Tracking System Not Specified"; } TrackingDeviceData UnspecifiedTrackingTypeInformation::GetDeviceDataUnspecified() { TrackingDeviceData data = { UnspecifiedTrackingTypeInformation::GetTrackingDeviceName(), "Unspecified System", "cube", "X" }; return data; } // Careful when changing the "invalid" device: The mitkTrackingTypeTest is using it's data. TrackingDeviceData UnspecifiedTrackingTypeInformation::GetDeviceDataInvalid() { TrackingDeviceData data = { UnspecifiedTrackingTypeInformation::GetTrackingDeviceName(), "Invalid Tracking System", "", "X" }; return data; } UnspecifiedTrackingTypeInformation::UnspecifiedTrackingTypeInformation() { m_DeviceName = UnspecifiedTrackingTypeInformation::GetTrackingDeviceName(); m_TrackingDeviceData.push_back(GetDeviceDataUnspecified()); m_TrackingDeviceData.push_back(GetDeviceDataInvalid()); } UnspecifiedTrackingTypeInformation::~UnspecifiedTrackingTypeInformation() { } mitk::TrackingDeviceSource::Pointer UnspecifiedTrackingTypeInformation::CreateTrackingDeviceSource( mitk::TrackingDevice::Pointer trackingDevice, mitk::NavigationToolStorage::Pointer navigationTools, std::string* errorMessage, std::vector* toolCorrespondencesInToolStorage) { return nullptr; } -} \ No newline at end of file +} diff --git a/Modules/IGT/TrackingDevices/mitkUnspecifiedTrackingTypeInformation.h b/Modules/IGT/TrackingDevices/mitkUnspecifiedTrackingTypeInformation.h index 568ff021fd..3991163740 100644 --- a/Modules/IGT/TrackingDevices/mitkUnspecifiedTrackingTypeInformation.h +++ b/Modules/IGT/TrackingDevices/mitkUnspecifiedTrackingTypeInformation.h @@ -1,49 +1,47 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkUnspecifiedTrackingTypeInformation_h #define mitkUnspecifiedTrackingTypeInformation_h -#include - #include "mitkTrackingDeviceTypeInformation.h" namespace mitk { /** Documentation: * \brief Type information for unspecified or invalid tracking devices. This is often used as default or for testing. * * \ingroup IGTUI */ class MITKIGT_EXPORT UnspecifiedTrackingTypeInformation : public TrackingDeviceTypeInformation { public: UnspecifiedTrackingTypeInformation(); virtual ~UnspecifiedTrackingTypeInformation(); virtual TrackingDeviceSource::Pointer CreateTrackingDeviceSource(mitk::TrackingDevice::Pointer, mitk::NavigationToolStorage::Pointer, std::string*, std::vector*); static std::string GetTrackingDeviceName(); static TrackingDeviceData GetDeviceDataUnspecified(); static TrackingDeviceData GetDeviceDataInvalid(); }; } // namespace mitk #endif //mitkUnspecifiedTrackingTypeInformation_h diff --git a/Modules/IGT/TrackingDevices/mitkVirtualTrackerTypeInformation.h b/Modules/IGT/TrackingDevices/mitkVirtualTrackerTypeInformation.h index 1df90bb603..3d5e1c73ac 100644 --- a/Modules/IGT/TrackingDevices/mitkVirtualTrackerTypeInformation.h +++ b/Modules/IGT/TrackingDevices/mitkVirtualTrackerTypeInformation.h @@ -1,47 +1,45 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef VIRTUALTRACKERTYPEINFORMATION_H_INCLUDED #define VIRTUALTRACKERTYPEINFORMATION_H_INCLUDED -#include - #include "mitkTrackingDeviceTypeInformation.h" namespace mitk { /** Documentation: * \brief Type information for a virtual tracker * * \ingroup IGTUI */ class MITKIGT_EXPORT VirtualTrackerTypeInformation : public TrackingDeviceTypeInformation { public: VirtualTrackerTypeInformation(); virtual ~VirtualTrackerTypeInformation(); virtual TrackingDeviceSource::Pointer CreateTrackingDeviceSource(mitk::TrackingDevice::Pointer trackingDevice, mitk::NavigationToolStorage::Pointer navigationTools, std::string* errorMessage, std::vector* toolCorrespondencesInToolStorage) override; static std::string GetTrackingDeviceName(); static TrackingDeviceData GetDeviceDataVirtualTracker(); }; } // namespace mitk #endif //VIRTUALTRACKERTYPEINFORMATION_H_INCLUDED