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 724034e860..d1bb2971cd 100644 --- a/Modules/IGT/DataManagement/mitkTrackingDeviceTypeCollection.h +++ b/Modules/IGT/DataManagement/mitkTrackingDeviceTypeCollection.h @@ -1,90 +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: - std::string m_Name; - 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 diff --git a/Modules/IGTUI/Qmitk/QmitkAbstractTrackingDeviceWidget.cpp b/Modules/IGTUI/Qmitk/QmitkAbstractTrackingDeviceWidget.cpp index df36176cd3..b1dad757a6 100644 --- a/Modules/IGTUI/Qmitk/QmitkAbstractTrackingDeviceWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkAbstractTrackingDeviceWidget.cpp @@ -1,71 +1,74 @@ /*=================================================================== 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 "QmitkAbstractTrackingDeviceWidget.h" -QmitkAbstractTrackingDeviceWidget::QmitkAbstractTrackingDeviceWidget(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f) +#include + +QmitkAbstractTrackingDeviceWidget::QmitkAbstractTrackingDeviceWidget(QWidget* parent, Qt::WindowFlags f) + : QWidget(parent, f) + , isInitialized(false) { - isInitialized = false; } void QmitkAbstractTrackingDeviceWidget::InitializeSuperclassWidget() { m_TestConnectionWorkerThread = new QThread(); m_TestConnectionWorker = new QmitkTrackingDeviceConfigurationWidgetConnectionWorker(); CreateConnections(); m_ErrorMessage = ""; isInitialized = true; } QmitkAbstractTrackingDeviceWidget::~QmitkAbstractTrackingDeviceWidget(){ if (m_TestConnectionWorker) delete m_TestConnectionWorker; if (m_TestConnectionWorkerThread) delete m_TestConnectionWorkerThread; } void QmitkAbstractTrackingDeviceWidget::TestConnectionFinished(bool connected, QString output) { m_TestConnectionWorkerThread->quit(); AddOutput(output.toStdString()); MITK_INFO << "Test connection: " << connected; this->setEnabled(true); } void QmitkAbstractTrackingDeviceWidget::TestConnection() { this->setEnabled(false); //construct a tracking device: mitk::TrackingDevice::Pointer testTrackingDevice = ConstructTrackingDevice(); m_TestConnectionWorker->SetTrackingDevice(testTrackingDevice); m_TestConnectionWorkerThread->start(); } void QmitkAbstractTrackingDeviceWidget::CreateConnections() { connect(m_TestConnectionWorker, SIGNAL(ConnectionTested(bool, QString)), this, SLOT(TestConnectionFinished(bool, QString))); connect(m_TestConnectionWorkerThread, SIGNAL(started()), m_TestConnectionWorker, SLOT(TestConnectionThreadFunc())); //move the worker to the thread m_TestConnectionWorker->moveToThread(m_TestConnectionWorkerThread); } QmitkAbstractTrackingDeviceWidget* QmitkAbstractTrackingDeviceWidget::CloneForQt(QWidget* parent) const { QmitkAbstractTrackingDeviceWidget* clonedWidget = this->Clone(parent); if (!clonedWidget->IsInitialized()) MITK_ERROR << "Your cloned widget is not initialized!"; clonedWidget->create(); return clonedWidget; -} \ No newline at end of file +} diff --git a/Modules/IGTUI/Qmitk/QmitkAbstractTrackingDeviceWidget.h b/Modules/IGTUI/Qmitk/QmitkAbstractTrackingDeviceWidget.h index 31e5bbfdee..44754bd672 100644 --- a/Modules/IGTUI/Qmitk/QmitkAbstractTrackingDeviceWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkAbstractTrackingDeviceWidget.h @@ -1,146 +1,143 @@ /*=================================================================== 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 QmitkAbstractTrackingDeviceWidget_H #define QmitkAbstractTrackingDeviceWidget_H #include #include "MitkIGTUIExports.h" #include "mitkTrackingDevice.h" -#include -#include - #include #include "QmitkTrackingDeviceConfigurationWidgetConnectionWorker.h" //itk headers /** Documentation: * \brief Abstract class to configure a tracking device. * Inherited widgets should be registered in the Microservice (TrackingDeviceCollectionWidget), * If done so, they will be included in the QmitkTrackingDeviceConfigurationWidget of the Tracking Toolbox. * * - Each implementation of this class must have a method to construct a tracking Device (ConstructTrackingDevice). * - Please create the UI elements in a function like CreateQtPartControl (e.g. see QmitkVitrualTrackerWidget). * - You might want to use own buttons etc., please connect them in a private CreateConnections (e.g. see QmitkVitrualTrackerWidget). * - Due to initialization of qt during autoloading of the IGT module, you constructor should be as slim as possible and only contain a call * of the QmitkAbstractTrackingDeviceWidget constructor and simple variable initialization. * - For the initialization, you must write an Iniltialize() function, which must include a call of InitializeSuperclassWidget() and should contain * calls of your private CreateConnections / CreateQtPartControl (if you implemented these). * - For integration into the TrackingToolbox, a clone function is needed. Here, a new widget should be created, Initialize() needs to be called, * and all settings of your widget should be copied. * * You can Load and Store previous settings of your GUI elements (e.g. see QmitkNDIPolarisWidget). * Also, you can add an output textbox to your widget to display information about your device status. It's optional, see e.g. QmitkNDIAuroraWidget. * Some Devices need the information if drivers are installed on your computer. If this is necessary for your device to avoid crashes, * please override IsDeviceInstalled. The default return value is true otherwise. * * \ingroup IGTUI */ class MITKIGTUI_EXPORT QmitkAbstractTrackingDeviceWidget : public QWidget { Q_OBJECT public: static const std::string VIEW_ID; QmitkAbstractTrackingDeviceWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); virtual ~QmitkAbstractTrackingDeviceWidget(); /** * \brief Return pointer to copy of the object. * Internally use of QmitkUSAbstractCustomWidget::Clone() with additionaly * setting an internal flag that the object was really cloned. */ QmitkAbstractTrackingDeviceWidget* CloneForQt(QWidget* parent = 0) const; /** * \brief Subclass must implement this method to return a pointer to a copy of the object. * Please don't forget to call InitializeSuperclassWidget(), CreateQtPartControl and optionally CreateConnections during this function. */ virtual void Initialize() = 0; bool IsInitialized() const { return isInitialized; } signals: void ConnectionTested(bool connected, QString output); protected slots: void TestConnectionFinished(bool connected, QString output); /* @brief This method is called when the user presses the button "test connection". The method will then create a temporary tracking device, * try to open a connection and start tracking. The user can see the result of the connection test on the small output window. */ void TestConnection(); private: /// \brief Creation of the connections. You might implement the same function again in your inherited widget. void CreateConnections(); protected: PERSISTENCE_GET_SERVICE_METHOD_MACRO void InitializeSuperclassWidget(); QmitkTrackingDeviceConfigurationWidgetConnectionWorker* m_TestConnectionWorker; QThread* m_TestConnectionWorkerThread; /** * \brief Subclass must implement this method to return a pointer to a copy of the object. * Please don't forget to call Initialize() during this function and copy all of your settings. */ virtual QmitkAbstractTrackingDeviceWidget* Clone(QWidget* parent = 0) const = 0; public: /** * \brief Optional method to add output to a small screen in the trackingToolbox (see QmitkNDIPolarisWidget) */ virtual void ResetOutput() {} /** * \brief Optional method to add output to a small screen in the trackingToolbox (see QmitkNDIPolarisWidget) */ virtual void AddOutput(std::string) {} virtual mitk::TrackingDevice::Pointer ConstructTrackingDevice() = 0; /** * \brief Optional method to store and load settings of your widget (see QmitkNDIPolarisWidget) */ virtual void StoreUISettings() {} /** * \brief Optional method to store and load settings of your widget (see QmitkNDIPolarisWidget) */ virtual void LoadUISettings() {} /** * \brief Optional method to investigate if drivers etc for your device are installed. * The default value is "true" as most devices don't need this information. * Others however migth crash, and for these you might implement this function (see QmitkMicronTrackerWidget) */ virtual bool IsDeviceInstalled() { return true; } std::string m_ErrorMessage; ///< current problem description private: /** * \warning Don't touch this variable if you don't know what you are doing! */ bool isInitialized; }; #endif diff --git a/Modules/IGTUI/Qmitk/QmitkMicronTrackerWidget.cpp b/Modules/IGTUI/Qmitk/QmitkMicronTrackerWidget.cpp index ec84b25d9a..cc79711681 100644 --- a/Modules/IGTUI/Qmitk/QmitkMicronTrackerWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkMicronTrackerWidget.cpp @@ -1,168 +1,168 @@ /*=================================================================== 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 "QmitkMicronTrackerWidget.h" -#include "QmitkTrackingDeviceConfigurationWidget.h" #include -#include +#include #include #include #include #include const std::string QmitkMicronTrackerWidget::VIEW_ID = "org.mitk.views.NDIMicronTrackerWidget"; QmitkMicronTrackerWidget::QmitkMicronTrackerWidget(QWidget* parent, Qt::WindowFlags f) : QmitkAbstractTrackingDeviceWidget(parent, f) + , m_Controls(nullptr) { - m_Controls = NULL; } void QmitkMicronTrackerWidget::Initialize() { InitializeSuperclassWidget(); CreateQtPartControl(this); CreateConnections(); m_MTCalibrationFile = ""; } QmitkMicronTrackerWidget::~QmitkMicronTrackerWidget() { + delete m_Controls; } void QmitkMicronTrackerWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkMicronTrackerWidget; m_Controls->setupUi(parent); } } void QmitkMicronTrackerWidget::CreateConnections() { if (m_Controls) { connect((QObject*)(m_Controls->m_testConnectionMicronTracker), SIGNAL(clicked()), this, SLOT(TestConnection())); connect((QObject*)(m_Controls->m_SetMTCalibrationFile), SIGNAL(clicked()), this, SLOT(SetMTCalibrationFileClicked())); } } void QmitkMicronTrackerWidget::ResetOutput() { m_Controls->m_outputTextMicronTracker->setHtml("output:"); } void QmitkMicronTrackerWidget::AddOutput(std::string s) { m_Controls->m_outputTextMicronTracker->setHtml(QString(s.c_str())); m_Controls->m_outputTextMicronTracker->verticalScrollBar()->setValue(m_Controls->m_outputTextMicronTracker->verticalScrollBar()->maximum()); } mitk::TrackingDevice::Pointer QmitkMicronTrackerWidget::ConstructTrackingDevice() { mitk::ClaronTrackingDevice::Pointer newDevice = mitk::ClaronTrackingDevice::New(); if (this->m_MTCalibrationFile.empty()) //if configuration file for MicronTracker is empty: load default { mitk::ClaronTrackingDevice::Pointer tempDevice = mitk::ClaronTrackingDevice::New(); m_MTCalibrationFile = tempDevice->GetCalibrationDir(); Poco::Path myPath = Poco::Path(m_MTCalibrationFile.c_str()); m_Controls->m_MTCalibrationFile->setText("Calibration File: " + QString(myPath.getFileName().c_str())); } if (!this->m_MTCalibrationFile.empty()) { //extract path from calibration file and set the calibration dir of the device std::string path = itksys::SystemTools::GetFilenamePath(m_MTCalibrationFile); newDevice->SetCalibrationDir(path); } else AddOutput("
Warning: Calibration file is not set!"); return static_cast(newDevice); } void QmitkMicronTrackerWidget::StoreUISettings() { std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget"; if (this->GetPeristenceService()) // now save the settings using the persistence service { mitk::PropertyList::Pointer propList = this->GetPeristenceService()->GetPropertyList(id); propList->Set("MTCalibrationFile", m_MTCalibrationFile); } else // QSettings as a fallback if the persistence service is not available { QSettings settings; settings.beginGroup(QString::fromStdString(id)); settings.setValue("mTCalibrationFile", QVariant(QString::fromStdString(m_MTCalibrationFile))); settings.endGroup(); } } void QmitkMicronTrackerWidget::LoadUISettings() { std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget"; if (this->GetPeristenceService()) { mitk::PropertyList::Pointer propList = this->GetPeristenceService()->GetPropertyList(id); if (propList.IsNull()) { MITK_ERROR << "Property list for this UI (" << id << ") is not available, could not load UI settings!"; return; } propList->Get("MTCalibrationFile", m_MTCalibrationFile); } else { // QSettings as a fallback if the persistence service is not available QSettings settings; settings.beginGroup(QString::fromStdString(id)); m_MTCalibrationFile = settings.value("mTCalibrationFile", "").toString().toStdString(); settings.endGroup(); } m_Controls->m_MTCalibrationFile->setText("Calibration File: " + QString::fromStdString(m_MTCalibrationFile)); } bool QmitkMicronTrackerWidget::IsDeviceInstalled() { return mitk::ClaronTrackingDevice::New()->IsDeviceInstalled(); } void QmitkMicronTrackerWidget::SetMTCalibrationFileClicked() { std::string filename = QFileDialog::getOpenFileName(NULL, tr("Open Calibration File"), "/", "*.*").toLatin1().data(); if (filename == "") { return; } else { m_MTCalibrationFile = filename; Poco::Path myPath = Poco::Path(m_MTCalibrationFile.c_str()); m_Controls->m_MTCalibrationFile->setText("Calibration File: " + QString(myPath.getFileName().c_str())); } } QmitkMicronTrackerWidget* QmitkMicronTrackerWidget::Clone(QWidget* parent) const { QmitkMicronTrackerWidget* clonedWidget = new QmitkMicronTrackerWidget(parent); clonedWidget->Initialize(); clonedWidget->m_MTCalibrationFile = m_MTCalibrationFile; m_Controls->m_MTCalibrationFile->setText("Calibration File: " + QString::fromStdString(m_MTCalibrationFile)); return clonedWidget; -} \ No newline at end of file +} diff --git a/Modules/IGTUI/Qmitk/QmitkMicronTrackerWidget.h b/Modules/IGTUI/Qmitk/QmitkMicronTrackerWidget.h index a33fb2805a..6f304182f1 100644 --- a/Modules/IGTUI/Qmitk/QmitkMicronTrackerWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkMicronTrackerWidget.h @@ -1,73 +1,71 @@ /*=================================================================== 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 QmitkMicronTrackerWidget_H #define QmitkMicronTrackerWidget_H -#include -#include "MitkIGTUIExports.h" #include "ui_QmitkMicronTrackerWidget.h" #include "QmitkAbstractTrackingDeviceWidget.h" -//itk headers /** Documentation: * \brief Implementation of a configuration widget for Micron Tracking Devices. * * \ingroup IGTUI */ class MITKIGTUI_EXPORT QmitkMicronTrackerWidget : public QmitkAbstractTrackingDeviceWidget { Q_OBJECT // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) public: static const std::string VIEW_ID; QmitkMicronTrackerWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkMicronTrackerWidget(); virtual void Initialize(); signals: protected slots : /* @brief Opens a file dialog. The users sets the calibration file which location is then stored in the member m_MTCalibrationFile.*/ void SetMTCalibrationFileClicked(); private: /// \brief Creation of the connections void CreateConnections(); void CreateQtPartControl(QWidget *parent); + protected: virtual QmitkMicronTrackerWidget* Clone(QWidget* parent) const; std::string m_MTCalibrationFile; Ui::QmitkMicronTrackerWidget* m_Controls; public: virtual void ResetOutput(); virtual void AddOutput(std::string s); virtual mitk::TrackingDevice::Pointer ConstructTrackingDevice(); virtual void StoreUISettings(); virtual void LoadUISettings(); virtual bool IsDeviceInstalled(); }; #endif diff --git a/Modules/IGTUI/Qmitk/QmitkNDIAbstractDeviceWidget.cpp b/Modules/IGTUI/Qmitk/QmitkNDIAbstractDeviceWidget.cpp index 6c5474993c..ad8d4b758d 100644 --- a/Modules/IGTUI/Qmitk/QmitkNDIAbstractDeviceWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkNDIAbstractDeviceWidget.cpp @@ -1,71 +1,67 @@ /*=================================================================== 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 "QmitkNDIAbstractDeviceWidget.h" -#include "QmitkTrackingDeviceConfigurationWidget.h" -#include -#include -#include +#include const std::string QmitkNDIAbstractDeviceWidget::VIEW_ID = "org.mitk.views.NDIAbstractDeviceWidget"; QmitkNDIAbstractDeviceWidget::QmitkNDIAbstractDeviceWidget(QWidget* parent, Qt::WindowFlags f) : QmitkAbstractTrackingDeviceWidget(parent, f) + , m_ScanPortsWorker(new QmitkTrackingDeviceConfigurationWidgetScanPortsWorker()) + , m_ScanPortsWorkerThread(new QThread()) { - //initialize worker thread - m_ScanPortsWorker = new QmitkTrackingDeviceConfigurationWidgetScanPortsWorker(); - m_ScanPortsWorkerThread = new QThread(); } void QmitkNDIAbstractDeviceWidget::InitializeNDIWidget() { InitializeSuperclassWidget(); CreateConnections(); } QmitkNDIAbstractDeviceWidget::~QmitkNDIAbstractDeviceWidget() { if (m_ScanPortsWorker) delete m_ScanPortsWorker; if (m_ScanPortsWorkerThread) delete m_ScanPortsWorkerThread; } void QmitkNDIAbstractDeviceWidget::CreateConnections() { //slots for the worker thread connect(m_ScanPortsWorker, SIGNAL(PortsScanned(int, QString, int)), this, SLOT(AutoScanPortsFinished(int, QString, int))); connect(m_ScanPortsWorkerThread, SIGNAL(started()), m_ScanPortsWorker, SLOT(ScanPortsThreadFunc())); } void QmitkNDIAbstractDeviceWidget::AutoScanPorts() { this->setEnabled(false); AddOutput("
Scanning..."); m_ScanPortsWorkerThread->start(); } void QmitkNDIAbstractDeviceWidget::AutoScanPortsFinished(int Port, QString result, int PortType) { m_ScanPortsWorkerThread->quit(); #ifdef WIN32 if (PortType != -1) { MITK_WARN << "Port type is specified although this should not be the case for Windows. Ignoring port type."; } #else //linux systems SetPortTypeToGUI(PortType); #endif SetPortValueToGUI(Port); AddOutput(result.toStdString()); this->setEnabled(true); -} \ No newline at end of file +} diff --git a/Modules/IGTUI/Qmitk/QmitkNDIAbstractDeviceWidget.h b/Modules/IGTUI/Qmitk/QmitkNDIAbstractDeviceWidget.h index 4062b31247..c26d46b9c2 100644 --- a/Modules/IGTUI/Qmitk/QmitkNDIAbstractDeviceWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkNDIAbstractDeviceWidget.h @@ -1,74 +1,70 @@ /*=================================================================== 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 QmitkNDIAbstractDeviceWidget_H #define QmitkNDIAbstractDeviceWidget_H -#include #include "MitkIGTUIExports.h" #include "QmitkAbstractTrackingDeviceWidget.h" - #include "QmitkTrackingDeviceConfigurationWidgetScanPortsWorker.h" -//itk headers - /** Documentation: * \brief Abstract class of a configuration widget for NDI Devices. * For implementations see NDIAuroraWidget or NDIPolarisWidget. * * \ingroup IGTUI */ class MITKIGTUI_EXPORT QmitkNDIAbstractDeviceWidget : public QmitkAbstractTrackingDeviceWidget { Q_OBJECT // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) public: static const std::string VIEW_ID; QmitkNDIAbstractDeviceWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkNDIAbstractDeviceWidget(); virtual void Initialize() = 0; virtual void AddOutput(std::string s) = 0; signals: void PortsScanned(int Port, QString result, int PortType); protected slots: /* @brief Scans the serial ports automatically for a connected tracking device. If the method finds a device * it selects the right type and sets the corresponding port in the widget. */ void AutoScanPorts(); /** This slot is called when the port scanning is finished. */ void AutoScanPortsFinished(int Port, QString result, int PortType); private: /// \brief Creation of the connections void CreateConnections(); protected: void InitializeNDIWidget(); QThread* m_ScanPortsWorkerThread; QmitkTrackingDeviceConfigurationWidgetScanPortsWorker* m_ScanPortsWorker; virtual void SetPortValueToGUI(int portValue) = 0; virtual void SetPortTypeToGUI(int portType) = 0; }; #endif diff --git a/Modules/IGTUI/Qmitk/QmitkNDIAuroraWidget.cpp b/Modules/IGTUI/Qmitk/QmitkNDIAuroraWidget.cpp index 220d6e1132..bc00cbfb50 100644 --- a/Modules/IGTUI/Qmitk/QmitkNDIAuroraWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkNDIAuroraWidget.cpp @@ -1,174 +1,174 @@ /*=================================================================== 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 "QmitkNDIAuroraWidget.h" -#include "QmitkTrackingDeviceConfigurationWidget.h" -#include -#include -#include -#include +#include "mitkNDITrackingDevice.h" #include "mitkNDIAuroraTypeInformation.h" +#include +#include + const std::string QmitkNDIAuroraWidget::VIEW_ID = "org.mitk.views.NDIAuroraWidget"; QmitkNDIAuroraWidget::QmitkNDIAuroraWidget(QWidget* parent, Qt::WindowFlags f) : QmitkNDIAbstractDeviceWidget(parent, f) + , m_Controls(nullptr) { - m_Controls = NULL; } void QmitkNDIAuroraWidget::Initialize() { InitializeNDIWidget(); CreateQtPartControl(this); CreateConnections(); } QmitkNDIAuroraWidget::~QmitkNDIAuroraWidget() { + delete m_Controls; } void QmitkNDIAuroraWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkNDIAuroraWidget; m_Controls->setupUi(parent); } } void QmitkNDIAuroraWidget::CreateConnections() { if (m_Controls) { connect((QObject*)(m_Controls->m_testConnectionAurora), SIGNAL(clicked()), this, SLOT(TestConnection())); connect((QObject*)(m_Controls->m_AutoScanAurora), SIGNAL(clicked()), this, SLOT(AutoScanPorts())); //set a few UI components depending on Windows / Linux #ifdef WIN32 m_Controls->portTypeLabelAurora->setVisible(false); m_Controls->portTypeAurora->setVisible(false); #else m_Controls->comPortLabelAurora->setText("Port Nr:"); m_Controls->m_portSpinBoxAurora->setPrefix(""); #endif } } void QmitkNDIAuroraWidget::ResetOutput() { m_Controls->m_outputTextAurora->setHtml("output:"); } void QmitkNDIAuroraWidget::AddOutput(std::string s) { m_Controls->m_outputTextAurora->setHtml(QString(s.c_str())); m_Controls->m_outputTextAurora->verticalScrollBar()->setValue(m_Controls->m_outputTextAurora->verticalScrollBar()->maximum()); } mitk::TrackingDevice::Pointer QmitkNDIAuroraWidget::ConstructTrackingDevice() { mitk::NDITrackingDevice::Pointer tempTrackingDevice = mitk::NDITrackingDevice::New(); //get port int port = 0; port = m_Controls->m_portSpinBoxAurora->value(); //build prefix (depends on linux/win) QString prefix = ""; #ifdef WIN32 prefix = "COM"; tempTrackingDevice->SetPortNumber(static_cast(port)); //also set the com port for compatibility #else prefix = m_Controls->portTypeAurora->currentText(); #endif //build port name string QString portName = prefix + QString::number(port); tempTrackingDevice->SetDeviceName(portName.toStdString()); //set the port name tempTrackingDevice->SetBaudRate(mitk::SerialCommunication::BaudRate115200);//set baud rate tempTrackingDevice->SetType(mitk::NDIAuroraTypeInformation::GetTrackingDeviceName()); return static_cast(tempTrackingDevice); } void QmitkNDIAuroraWidget::StoreUISettings() { std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget"; if (this->GetPeristenceService()) // now save the settings using the persistence service { mitk::PropertyList::Pointer propList = this->GetPeristenceService()->GetPropertyList(id); propList->Set("AuroraPortWin", m_Controls->m_portSpinBoxAurora->value()); propList->Set("PortTypeAurora", m_Controls->portTypeAurora->currentIndex()); } else // QSettings as a fallback if the persistence service is not available { QSettings settings; settings.beginGroup(QString::fromStdString(id)); settings.setValue("portSpinBoxAurora", QVariant(m_Controls->m_portSpinBoxAurora->value())); settings.setValue("portTypeAurora", QVariant(m_Controls->portTypeAurora->currentIndex())); settings.endGroup(); } } void QmitkNDIAuroraWidget::LoadUISettings() { std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget"; if (this->GetPeristenceService()) { int port = 0; int portType = 0; mitk::PropertyList::Pointer propList = this->GetPeristenceService()->GetPropertyList(id); if (propList.IsNull()) { MITK_ERROR << "Property list for this UI (" << id << ") is not available, could not load UI settings!"; return; } propList->Get("AuroraPortWin", port); propList->Get("PortTypeAurora", portType); this->SetPortTypeToGUI(portType); this->SetPortValueToGUI(port); } else { // QSettings as a fallback if the persistence service is not available QSettings settings; settings.beginGroup(QString::fromStdString(id)); m_Controls->m_portSpinBoxAurora->setValue(settings.value("portSpinBoxAurora", 0).toInt()); m_Controls->portTypeAurora->setCurrentIndex(settings.value("portTypeAurora", 0).toInt()); settings.endGroup(); } } void QmitkNDIAuroraWidget::SetPortValueToGUI(int portValue){ m_Controls->m_portSpinBoxAurora->setValue(portValue); } void QmitkNDIAuroraWidget::SetPortTypeToGUI(int portType){ m_Controls->portTypeAurora->setCurrentIndex(portType); } QmitkNDIAuroraWidget* QmitkNDIAuroraWidget::Clone(QWidget* parent) const { QmitkNDIAuroraWidget* clonedWidget = new QmitkNDIAuroraWidget(parent); clonedWidget->Initialize(); clonedWidget->SetPortTypeToGUI(m_Controls->portTypeAurora->currentIndex()); clonedWidget->SetPortValueToGUI(m_Controls->m_portSpinBoxAurora->value()); return clonedWidget; -} \ No newline at end of file +} diff --git a/Modules/IGTUI/Qmitk/QmitkNDIAuroraWidget.h b/Modules/IGTUI/Qmitk/QmitkNDIAuroraWidget.h index 5ad322f912..f3fd1bea10 100644 --- a/Modules/IGTUI/Qmitk/QmitkNDIAuroraWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkNDIAuroraWidget.h @@ -1,65 +1,62 @@ /*=================================================================== 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 QmitkNDIAuroraWidget_H #define QmitkNDIAuroraWidget_H -#include -#include "MitkIGTUIExports.h" #include "ui_QmitkNDIAuroraWidget.h" #include "QmitkNDIAbstractDeviceWidget.h" -//itk headers /** Documentation: * \brief Implementation of a configuration widget for NDI Aurora Devices. * * \ingroup IGTUI */ class MITKIGTUI_EXPORT QmitkNDIAuroraWidget : public QmitkNDIAbstractDeviceWidget { Q_OBJECT // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) public: static const std::string VIEW_ID; QmitkNDIAuroraWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkNDIAuroraWidget(); virtual void Initialize(); private: /// \brief Creation of the connections void CreateConnections(); void CreateQtPartControl(QWidget *parent); protected: virtual void ResetOutput(); virtual void AddOutput(std::string s); virtual mitk::TrackingDevice::Pointer ConstructTrackingDevice(); virtual void StoreUISettings(); virtual void LoadUISettings(); virtual void SetPortValueToGUI(int portValue); virtual void SetPortTypeToGUI(int portType); virtual QmitkNDIAuroraWidget* Clone(QWidget* parent) const; Ui::QmitkNDIAuroraWidget* m_Controls; }; #endif diff --git a/Modules/IGTUI/Qmitk/QmitkNDIPolarisWidget.cpp b/Modules/IGTUI/Qmitk/QmitkNDIPolarisWidget.cpp index 4fc8962f29..1c4d1bd060 100644 --- a/Modules/IGTUI/Qmitk/QmitkNDIPolarisWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkNDIPolarisWidget.cpp @@ -1,199 +1,197 @@ /*=================================================================== 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 "QmitkNDIPolarisWidget.h" -#include "QmitkTrackingDeviceConfigurationWidget.h" - -#include -#include -#include +#include "mitkNDITrackingDevice.h" #include "mitkNDIPolarisTypeInformation.h" +#include #include const std::string QmitkNDIPolarisWidget::VIEW_ID = "org.mitk.views.NDIPolarisWidget"; QmitkNDIPolarisWidget::QmitkNDIPolarisWidget(QWidget* parent, Qt::WindowFlags f) : QmitkNDIAbstractDeviceWidget(parent, f) + , m_Controls(nullptr) { - m_Controls = NULL; } void QmitkNDIPolarisWidget::Initialize() { InitializeNDIWidget(); CreateQtPartControl(this); CreateConnections(); } QmitkNDIPolarisWidget::~QmitkNDIPolarisWidget() { + delete m_Controls; } void QmitkNDIPolarisWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkNDIPolarisWidget; m_Controls->setupUi(parent); } } void QmitkNDIPolarisWidget::CreateConnections() { if (m_Controls) { connect((QObject*)(m_Controls->m_testConnectionPolaris), SIGNAL(clicked()), this, SLOT(TestConnection())); connect((QObject*)(m_Controls->m_AutoScanPolaris), SIGNAL(clicked()), this, SLOT(AutoScanPorts())); //set a few UI components depending on Windows / Linux #ifdef WIN32 m_Controls->portTypeLabelPolaris->setVisible(false); m_Controls->portTypePolaris->setVisible(false); #else m_Controls->m_comPortLabelPolaris->setText("Port Nr:"); m_Controls->m_portSpinBoxPolaris->setPrefix(""); #endif } } void QmitkNDIPolarisWidget::ResetOutput() { m_Controls->m_outputTextPolaris->setHtml("output:"); } void QmitkNDIPolarisWidget::AddOutput(std::string s) { m_Controls->m_outputTextPolaris->setHtml(QString(s.c_str())); m_Controls->m_outputTextPolaris->verticalScrollBar()->setValue(m_Controls->m_outputTextPolaris->verticalScrollBar()->maximum()); } mitk::TrackingDevice::Pointer QmitkNDIPolarisWidget::ConstructTrackingDevice() { mitk::NDITrackingDevice::Pointer tempTrackingDevice = mitk::NDITrackingDevice::New(); //get port int port = 0; port = m_Controls->m_portSpinBoxPolaris->value(); //build prefix (depends on linux/win) QString prefix = ""; #ifdef WIN32 prefix = "COM"; tempTrackingDevice->SetPortNumber(static_cast(port)); //also set the com port for compatibility tempTrackingDevice->SetIlluminationActivationRate(GetPolarisFrameRate()); #else prefix = m_Controls->portTypePolaris->currentText(); tempTrackingDevice->SetIlluminationActivationRate(GetPolarisFrameRate()); #endif //build port name string QString portName = prefix + QString::number(port); tempTrackingDevice->SetDeviceName(portName.toStdString()); //set the port name tempTrackingDevice->SetBaudRate(mitk::SerialCommunication::BaudRate115200);//set baud rate tempTrackingDevice->SetType(mitk::NDIPolarisTypeInformation::GetTrackingDeviceName()); return static_cast(tempTrackingDevice); } void QmitkNDIPolarisWidget::StoreUISettings() { std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget"; if (this->GetPeristenceService()) // now save the settings using the persistence service { mitk::PropertyList::Pointer propList = this->GetPeristenceService()->GetPropertyList(id); propList->Set("PolarisPortWin", m_Controls->m_portSpinBoxPolaris->value()); propList->Set("PortTypePolaris", m_Controls->portTypePolaris->currentIndex()); propList->Set("PolarisFrameRate", GetPolarisFrameRate()); } else // QSettings as a fallback if the persistence service is not available { QSettings settings; settings.beginGroup(QString::fromStdString(id)); settings.setValue("portSpinBoxPolaris", QVariant(m_Controls->m_portSpinBoxPolaris->value())); settings.setValue("portTypePolaris", QVariant(m_Controls->portTypePolaris->currentIndex())); settings.setValue("PolarisFrameRate", QVariant(GetPolarisFrameRate())); settings.endGroup(); } } void QmitkNDIPolarisWidget::LoadUISettings() { std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget"; if (this->GetPeristenceService()) { int port = 0; int portType = 0; int polarisFrameRate = 0; mitk::PropertyList::Pointer propList = this->GetPeristenceService()->GetPropertyList(id); if (propList.IsNull()) { MITK_ERROR << "Property list for this UI (" << id << ") is not available, could not load UI settings!"; return; } propList->Get("PolarisPortWin", port); propList->Get("PortTypePolaris", portType); propList->Get("PolarisFrameRate", polarisFrameRate); this->SetPortTypeToGUI(portType); this->SetPortValueToGUI(port); m_Controls->m_frameRateComboBoxPolaris->setCurrentIndex((int)(polarisFrameRate / 30)); } else { // QSettings as a fallback if the persistence service is not available QSettings settings; settings.beginGroup(QString::fromStdString(id)); m_Controls->m_portSpinBoxPolaris->setValue(settings.value("portSpinBoxPolaris", 0).toInt()); m_Controls->portTypePolaris->setCurrentIndex(settings.value("portTypePolaris", 0).toInt()); //framerates 20,30,60 --> divided by 30 = 0,1,2 --> index of combobox m_Controls->m_frameRateComboBoxPolaris->setCurrentIndex((int)(settings.value("PolarisFrameRate", 0).toInt() / 30)); settings.endGroup(); } } mitk::IlluminationActivationRate QmitkNDIPolarisWidget::GetPolarisFrameRate() { mitk::IlluminationActivationRate frameRate; QString comboBox = m_Controls->m_frameRateComboBoxPolaris->currentText(); if (comboBox == "20 Hz") frameRate = mitk::Hz20; else if (comboBox == "30 Hz") frameRate = mitk::Hz30; else if (comboBox == "60 Hz") frameRate = mitk::Hz60; return frameRate; } void QmitkNDIPolarisWidget::SetPortValueToGUI(int portValue){ m_Controls->m_portSpinBoxPolaris->setValue(portValue); } void QmitkNDIPolarisWidget::SetPortTypeToGUI(int portType){ m_Controls->portTypePolaris->setCurrentIndex(portType); } QmitkNDIPolarisWidget* QmitkNDIPolarisWidget::Clone(QWidget* parent) const { QmitkNDIPolarisWidget* clonedWidget = new QmitkNDIPolarisWidget(parent); clonedWidget->Initialize(); clonedWidget->SetPortTypeToGUI(m_Controls->portTypePolaris->currentIndex()); clonedWidget->SetPortValueToGUI(m_Controls->m_portSpinBoxPolaris->value()); clonedWidget->m_Controls->m_frameRateComboBoxPolaris->setCurrentIndex(m_Controls->m_frameRateComboBoxPolaris->currentIndex()); return clonedWidget; -} \ No newline at end of file +} diff --git a/Modules/IGTUI/Qmitk/QmitkNDIPolarisWidget.h b/Modules/IGTUI/Qmitk/QmitkNDIPolarisWidget.h index 7add00a1be..d201e84349 100644 --- a/Modules/IGTUI/Qmitk/QmitkNDIPolarisWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkNDIPolarisWidget.h @@ -1,74 +1,71 @@ /*=================================================================== 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 QmitkNDIPolarisWidget_H #define QmitkNDIPolarisWidget_H -#include "MitkIGTUIExports.h" #include "ui_QmitkNDIPolarisWidget.h" - #include "QmitkNDIAbstractDeviceWidget.h" -//itk headers /** Documentation: * \brief Implementation of a configuration widget for NDI Polaris Devices. * * \ingroup IGTUI */ class MITKIGTUI_EXPORT QmitkNDIPolarisWidget : public QmitkNDIAbstractDeviceWidget { Q_OBJECT // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) public: static const std::string VIEW_ID; QmitkNDIPolarisWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkNDIPolarisWidget(); virtual void Initialize(); signals: protected slots : private: /// \brief Creation of the connections void CreateConnections(); void CreateQtPartControl(QWidget *parent); protected: /** @return Returns the frame rate set in the m_frameRatePolaris ComboBox */ mitk::IlluminationActivationRate GetPolarisFrameRate(); Ui::QmitkNDIPolarisWidget* m_Controls; virtual void SetPortValueToGUI(int portValue); virtual void SetPortTypeToGUI(int portType); virtual QmitkNDIPolarisWidget* Clone(QWidget* parent) const; public: virtual void ResetOutput(); virtual void AddOutput(std::string s); virtual mitk::TrackingDevice::Pointer ConstructTrackingDevice(); virtual void StoreUISettings(); virtual void LoadUISettings(); }; #endif diff --git a/Modules/IGTUI/Qmitk/QmitkNPOptitrackWidget.cpp b/Modules/IGTUI/Qmitk/QmitkNPOptitrackWidget.cpp index b935f5e161..156ea72622 100644 --- a/Modules/IGTUI/Qmitk/QmitkNPOptitrackWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkNPOptitrackWidget.cpp @@ -1,120 +1,120 @@ /*=================================================================== 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 "QmitkNPOptitrackWidget.h" -#include "QmitkTrackingDeviceConfigurationWidget.h" + +#include "mitkOptitrackTrackingDevice.h" +#include "mitkNPOptitrackTrackingTypeInformation.h" #include -#include +#include #include -#include -#include "mitkNPOptitrackTrackingTypeInformation.h" - const std::string QmitkNPOptitrackWidget::VIEW_ID = "org.mitk.views.NPOptitrackWidget"; QmitkNPOptitrackWidget::QmitkNPOptitrackWidget(QWidget* parent, Qt::WindowFlags f) : QmitkAbstractTrackingDeviceWidget(parent, f) + , m_Controls(nullptr) { - m_Controls = NULL; } void QmitkNPOptitrackWidget::Initialize() { InitializeSuperclassWidget(); CreateQtPartControl(this); CreateConnections(); } QmitkNPOptitrackWidget::~QmitkNPOptitrackWidget() { + delete m_Controls; } void QmitkNPOptitrackWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkNPOptitrackWidget; m_Controls->setupUi(parent); } } void QmitkNPOptitrackWidget::CreateConnections() { if (m_Controls) { connect((QObject*)(m_Controls->m_testConnectionOptitrack), SIGNAL(clicked()), this, SLOT(TestConnection())); connect((QObject*)(m_Controls->m_SetOptitrackCalibrationFile), SIGNAL(clicked()), this, SLOT(SetOptitrackCalibrationFileClicked())); } } void QmitkNPOptitrackWidget::ResetOutput() { m_Controls->m_outputTextOptitrack->setHtml("output:"); } void QmitkNPOptitrackWidget::AddOutput(std::string s) { m_Controls->m_outputTextOptitrack->setHtml(QString(s.c_str())); m_Controls->m_outputTextOptitrack->verticalScrollBar()->setValue(m_Controls->m_outputTextOptitrack->verticalScrollBar()->maximum()); } mitk::TrackingDevice::Pointer QmitkNPOptitrackWidget::ConstructTrackingDevice() { // Create the Tracking Device mitk::OptitrackTrackingDevice::Pointer tempTrackingDevice = mitk::OptitrackTrackingDevice::New(); // Set the calibration File tempTrackingDevice->SetCalibrationPath(m_OptitrackCalibrationFile); //Set the camera parameters tempTrackingDevice->SetExp(m_Controls->m_OptitrackExp->value()); tempTrackingDevice->SetLed(m_Controls->m_OptitrackLed->value()); tempTrackingDevice->SetThr(m_Controls->m_OptitrackThr->value()); tempTrackingDevice->SetType(mitk::NPOptitrackTrackingTypeInformation::GetTrackingDeviceName()); return static_cast(tempTrackingDevice); } bool QmitkNPOptitrackWidget::IsDeviceInstalled() { return mitk::OptitrackTrackingDevice::New()->IsDeviceInstalled(); } void QmitkNPOptitrackWidget::SetOptitrackCalibrationFileClicked() { std::string filename = QFileDialog::getOpenFileName(NULL, tr("Open Calibration File"), "/", "*.*").toLatin1().data(); if (filename == "") { return; } else { m_OptitrackCalibrationFile = filename; Poco::Path myPath = Poco::Path(m_OptitrackCalibrationFile.c_str()); m_Controls->m_OptitrackCalibrationFile->setText("Calibration File: " + QString(myPath.getFileName().c_str())); } } QmitkNPOptitrackWidget* QmitkNPOptitrackWidget::Clone(QWidget* parent) const { QmitkNPOptitrackWidget* clonedWidget = new QmitkNPOptitrackWidget(parent); clonedWidget->Initialize(); clonedWidget->m_OptitrackCalibrationFile = this->m_OptitrackCalibrationFile; clonedWidget->m_Controls->m_OptitrackCalibrationFile->setText(m_Controls->m_OptitrackCalibrationFile->text()); clonedWidget->m_Controls->m_OptitrackExp->setValue(m_Controls->m_OptitrackExp->value()); clonedWidget->m_Controls->m_OptitrackLed->setValue(m_Controls->m_OptitrackLed->value()); clonedWidget->m_Controls->m_OptitrackThr->setValue(m_Controls->m_OptitrackThr->value()); return clonedWidget; -} \ No newline at end of file +} diff --git a/Modules/IGTUI/Qmitk/QmitkNPOptitrackWidget.h b/Modules/IGTUI/Qmitk/QmitkNPOptitrackWidget.h index 2ff9c4e0df..54d8c17088 100644 --- a/Modules/IGTUI/Qmitk/QmitkNPOptitrackWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkNPOptitrackWidget.h @@ -1,72 +1,68 @@ /*=================================================================== 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 QmitkNPOptitrackWidget_H #define QmitkNPOptitrackWidget_H -#include -#include "MitkIGTUIExports.h" #include "ui_QmitkNPOptitrackWidget.h" - #include "QmitkAbstractTrackingDeviceWidget.h" -//itk headers /** Documentation: * \brief Implementation of a configuration widget for NP Optitrack Tracking Devices. * * \ingroup IGTUI */ class MITKIGTUI_EXPORT QmitkNPOptitrackWidget : public QmitkAbstractTrackingDeviceWidget { Q_OBJECT // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) public: static const std::string VIEW_ID; QmitkNPOptitrackWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkNPOptitrackWidget(); virtual void Initialize(); signals: protected slots : /* @brief Opens a file dialog. The users sets the calibration file which location is then stored in the member m_OptitrackCalibrationFile.*/ void SetOptitrackCalibrationFileClicked(); private: /// \brief Creation of the connections void CreateConnections(); void CreateQtPartControl(QWidget *parent); protected: virtual QmitkNPOptitrackWidget* Clone(QWidget* parent) const; std::string m_OptitrackCalibrationFile; Ui::QmitkNPOptitrackWidget* m_Controls; public: virtual void ResetOutput(); virtual void AddOutput(std::string s); virtual mitk::TrackingDevice::Pointer ConstructTrackingDevice(); virtual bool IsDeviceInstalled(); }; #endif diff --git a/Modules/IGTUI/Qmitk/QmitkOpenIGTLinkWidget.cpp b/Modules/IGTUI/Qmitk/QmitkOpenIGTLinkWidget.cpp index 9f7fb17b18..0591f0ba80 100644 --- a/Modules/IGTUI/Qmitk/QmitkOpenIGTLinkWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkOpenIGTLinkWidget.cpp @@ -1,71 +1,68 @@ /*=================================================================== 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 "QmitkOpenIGTLinkWidget.h" -#include "QmitkTrackingDeviceConfigurationWidget.h" -#include -#include - -#include +#include "mitkOpenIGTLinkTrackingDevice.h" const std::string QmitkOpenIGTLinkWidget::VIEW_ID = "org.mitk.views.OpenIGTLinkWidget"; QmitkOpenIGTLinkWidget::QmitkOpenIGTLinkWidget(QWidget* parent, Qt::WindowFlags f) : QmitkAbstractTrackingDeviceWidget(parent, f) + , m_Controls(nullptr) { - m_Controls = NULL; } void QmitkOpenIGTLinkWidget::Initialize() { InitializeSuperclassWidget(); CreateQtPartControl(this); } QmitkOpenIGTLinkWidget::~QmitkOpenIGTLinkWidget() { + delete m_Controls; } void QmitkOpenIGTLinkWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkOpenIGTLinkWidget; m_Controls->setupUi(parent); } } mitk::TrackingDevice::Pointer QmitkOpenIGTLinkWidget::ConstructTrackingDevice() { // Create the Virtual Tracking Device mitk::OpenIGTLinkTrackingDevice::Pointer OIGTLDevice = mitk::OpenIGTLinkTrackingDevice::New(); OIGTLDevice->SetPortNumber(m_Controls->m_OpenIGTLinkPort->text().toInt()); OIGTLDevice->SetHostname(m_Controls->m_OpenIGTLinkHostname->text().toStdString()); return static_cast(OIGTLDevice); } QmitkOpenIGTLinkWidget* QmitkOpenIGTLinkWidget::Clone(QWidget* parent) const { QmitkOpenIGTLinkWidget* clonedWidget = new QmitkOpenIGTLinkWidget(parent); clonedWidget->Initialize(); clonedWidget->m_Controls->m_OpenIGTLinkPort->setText(m_Controls->m_OpenIGTLinkPort->text()); clonedWidget->m_Controls->m_OpenIGTLinkHostname->setText(m_Controls->m_OpenIGTLinkHostname->text()); return clonedWidget; -} \ No newline at end of file +} diff --git a/Modules/IGTUI/Qmitk/QmitkOpenIGTLinkWidget.h b/Modules/IGTUI/Qmitk/QmitkOpenIGTLinkWidget.h index 05ae47c9cb..a0ebfbb3e5 100644 --- a/Modules/IGTUI/Qmitk/QmitkOpenIGTLinkWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkOpenIGTLinkWidget.h @@ -1,58 +1,54 @@ /*=================================================================== 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 QmitkOpenIGTLinkWidget_H #define QmitkOpenIGTLinkWidget_H -#include -#include "MitkIGTUIExports.h" #include "ui_QmitkOpenIGTLinkWidget.h" - #include "QmitkAbstractTrackingDeviceWidget.h" -//itk headers /** Documentation: * \brief Implementation of a configuration widget to use an Open IGT Link connection to track any device. * * \ingroup IGTUI */ class MITKIGTUI_EXPORT QmitkOpenIGTLinkWidget : public QmitkAbstractTrackingDeviceWidget { Q_OBJECT // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) public: static const std::string VIEW_ID; QmitkOpenIGTLinkWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkOpenIGTLinkWidget(); virtual void Initialize(); signals: protected slots : private: void CreateQtPartControl(QWidget *parent); protected: virtual QmitkOpenIGTLinkWidget* Clone(QWidget* parent) const; Ui::QmitkOpenIGTLinkWidget* m_Controls; public: virtual mitk::TrackingDevice::Pointer ConstructTrackingDevice(); }; #endif diff --git a/Modules/IGTUI/Qmitk/QmitkTrackingDeviceConfigurationWidget.cpp b/Modules/IGTUI/Qmitk/QmitkTrackingDeviceConfigurationWidget.cpp index d777a0e612..bdf68cf9ee 100644 --- a/Modules/IGTUI/Qmitk/QmitkTrackingDeviceConfigurationWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkTrackingDeviceConfigurationWidget.cpp @@ -1,366 +1,347 @@ /*=================================================================== 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 "QmitkTrackingDeviceConfigurationWidget.h" -#include -#include -#include -#include -#include -#include - -#include "QmitkAbstractTrackingDeviceWidget.h" - -//All Tracking devices, which should be available by default -#include "mitkNDIAuroraTypeInformation.h" #include "mitkNDIPolarisTypeInformation.h" -#include "mitkVirtualTrackerTypeInformation.h" -#include "mitkMicronTrackerTypeInformation.h" -#include "mitkNPOptitrackTrackingTypeInformation.h" -#include "mitkOpenIGTLinkTypeInformation.h" -//standard tracking devices, which always should be avaiable -#include "QmitkNDIAuroraWidget.h" -#include "QmitkNDIPolarisWidget.h" -#include "QmitkMicronTrackerWidget.h" -#include "QmitkNPOptitrackWidget.h" -#include "QmitkVirtualTrackerWidget.h" -#include "QmitkOpenIGTLinkWidget.h" + +#include const std::string QmitkTrackingDeviceConfigurationWidget::VIEW_ID = "org.mitk.views.trackingdeviceconfigurationwidget"; QmitkTrackingDeviceConfigurationWidget::QmitkTrackingDeviceConfigurationWidget(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f) + , m_Controls(nullptr) + , m_TrackingDevice(nullptr) , m_DeviceToWidgetIndexMap() { //initializations - m_Controls = nullptr; CreateQtPartControl(this); CreateConnections(); RefreshTrackingDeviceCollection(); //initialize a few UI elements AddOutput("
First Element selected"); //Order from Collection List //reset a few things ResetOutput(); //restore old UI settings LoadUISettings(); } QmitkTrackingDeviceConfigurationWidget::~QmitkTrackingDeviceConfigurationWidget() { StoreUISettings(); - m_Controls = nullptr; + delete m_Controls; m_TrackingDevice = nullptr; } void QmitkTrackingDeviceConfigurationWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkTrackingDeviceConfigurationWidgetControls; m_Controls->setupUi(parent); } } void QmitkTrackingDeviceConfigurationWidget::CreateConnections() { if (m_Controls) { connect((QObject*)(m_Controls->m_TrackingDeviceChooser), SIGNAL(currentIndexChanged(int)), this, SLOT(TrackingDeviceChanged())); } } void QmitkTrackingDeviceConfigurationWidget::TrackingDeviceChanged() { const std::string currentDevice = this->GetCurrentDeviceName(); //show the correspondig widget m_Controls->m_TrackingSystemWidget->setCurrentIndex(m_DeviceToWidgetIndexMap[currentDevice]); //reset output ResetOutput(); AddOutput("
"); AddOutput(currentDevice); AddOutput(" selected"); QmitkAbstractTrackingDeviceWidget* widget = GetWidget(currentDevice); if (widget == nullptr || !widget->IsDeviceInstalled()) { AddOutput("
ERROR: not installed!"); } emit TrackingDeviceSelectionChanged(); } void QmitkTrackingDeviceConfigurationWidget::RefreshTrackingDeviceCollection() { // clean-up of stacked widget, drop-down box and map for (auto& item : m_DeviceToWidgetIndexMap) { m_Controls->m_TrackingSystemWidget->removeWidget(m_Controls->m_TrackingSystemWidget->widget(item.second)); MITK_INFO << "removing widget for device '" << item.first << "'"; } m_Controls->m_TrackingDeviceChooser->clear(); m_DeviceToWidgetIndexMap.clear(); // get tracking device type service references us::ModuleContext* context = us::GetModuleContext(); std::vector > deviceRefs = context->GetServiceReferences(); if (deviceRefs.empty()) { MITK_ERROR << "No tracking device type service found!"; return; } // get tracking device configuration widget service references std::vector > widgetRefs = context->GetServiceReferences(); if (widgetRefs.empty()) { MITK_ERROR << "No tracking device configuration widget service found!"; return; } const us::ServiceReference& deviceServiceReference = deviceRefs.front(); const us::ServiceReference& widgetServiceReference = widgetRefs.front(); mitk::TrackingDeviceTypeCollection* deviceTypeCollection = context->GetService(deviceServiceReference); mitk::TrackingDeviceWidgetCollection* deviceWidgetCollection = context->GetService(widgetServiceReference); for (auto name : deviceTypeCollection->GetTrackingDeviceTypeNames()) { // if the device is not included yet, add name to comboBox and widget to stackedWidget if (m_Controls->m_TrackingDeviceChooser->findText(QString::fromStdString(name)) == -1) { m_Controls->m_TrackingDeviceChooser->addItem(QString::fromStdString(name)); QWidget* current = deviceWidgetCollection->GetTrackingDeviceWidgetClone(name); if (current == nullptr) { MITK_WARN << "No widget for tracking device type " << name << " available. Please implement and register it!"; current = new QWidget(); } m_DeviceToWidgetIndexMap[name] = m_Controls->m_TrackingSystemWidget->addWidget(current); } } if (!m_DeviceToWidgetIndexMap.empty()) { m_Controls->m_TrackingDeviceChooser->setCurrentIndex(0); m_Controls->m_TrackingSystemWidget->setCurrentIndex(0); } context->UngetService(deviceServiceReference); context->UngetService(widgetServiceReference); } //######################### internal help methods ####################################### void QmitkTrackingDeviceConfigurationWidget::ResetOutput() { QmitkAbstractTrackingDeviceWidget* currentWidget = this->GetWidget(this->GetCurrentDeviceName()); if (currentWidget == nullptr) { return; } currentWidget->ResetOutput(); currentWidget->repaint(); } void QmitkTrackingDeviceConfigurationWidget::AddOutput(std::string s) { QmitkAbstractTrackingDeviceWidget* currentWidget = this->GetWidget(this->GetCurrentDeviceName()); if (currentWidget == nullptr) { return; } currentWidget->AddOutput(s); currentWidget->repaint(); } mitk::TrackingDevice::Pointer QmitkTrackingDeviceConfigurationWidget::ConstructTrackingDevice() { QmitkAbstractTrackingDeviceWidget* currentWidget = this->GetWidget(this->GetCurrentDeviceName()); if (currentWidget == nullptr) { return nullptr; } return currentWidget->ConstructTrackingDevice(); } mitk::TrackingDevice::Pointer QmitkTrackingDeviceConfigurationWidget::GetTrackingDevice() { m_TrackingDevice = ConstructTrackingDevice(); if (m_TrackingDevice.IsNull() || !m_TrackingDevice->IsDeviceInstalled()) return nullptr; else return this->m_TrackingDevice; } void QmitkTrackingDeviceConfigurationWidget::StoreUISettings() { std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget"; std::string selectedDevice = this->GetCurrentDeviceName(); //Save settings for every widget //Don't use m_DeviceTypeCollection here, it's already unregistered, when deconstructor is called... for (int index = 0; index < m_Controls->m_TrackingSystemWidget->count(); index++) { QmitkAbstractTrackingDeviceWidget* widget = dynamic_cast(m_Controls->m_TrackingSystemWidget->widget(index)); if (widget != nullptr) { widget->StoreUISettings(); } } if (this->GetPeristenceService()) // now save the settings using the persistence service { mitk::PropertyList::Pointer propList = this->GetPeristenceService()->GetPropertyList(id); propList->Set("SelectedDevice", selectedDevice); } else // QSettings as a fallback if the persistence service is not available { QSettings settings; settings.beginGroup(QString::fromStdString(id)); settings.setValue("trackingDeviceChooser", QVariant(QString::fromStdString(selectedDevice))); settings.endGroup(); } } /** * @brief QmitkTrackingDeviceConfigurationWidget::LoadUISettings * * Precondition: * Make sure that QStackedWidget is already initialized, * e.g. by calling RefreshTrackingDeviceCollection() before. */ void QmitkTrackingDeviceConfigurationWidget::LoadUISettings() { //Load settings for every widget for (int index = 0; index < m_Controls->m_TrackingSystemWidget->count(); index++) { QmitkAbstractTrackingDeviceWidget* widget = dynamic_cast(m_Controls->m_TrackingSystemWidget->widget(index)); if (widget != nullptr) { widget->LoadUISettings(); } } std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget"; std::string selectedDevice; if (this->GetPeristenceService()) { mitk::PropertyList::Pointer propList = this->GetPeristenceService()->GetPropertyList(id); if (propList.IsNull()) { MITK_ERROR << "Property list for this UI (" << id << ") is not available, could not load UI settings!"; return; } propList->Get("SelectedDevice", selectedDevice); if (selectedDevice.empty()) { MITK_ERROR << "Loaded data from persistence service is invalid (SelectedDevice:" << selectedDevice << "): aborted to restore data!"; return; } MITK_INFO << "Successfully restored UI settings"; } else { // QSettings as a fallback if the persistence service is not available QSettings settings; settings.beginGroup(QString::fromStdString(id)); selectedDevice = settings.value("trackingDeviceChooser", "").toString().toStdString(); settings.endGroup(); } // The selected device requires some checks because a device that is not installed should not be restored to avoid bugs. // Use NDI Polaris as default if there's no widget registered for selected device or there's a widget for it but no device installed. const auto& deviceIterator = m_DeviceToWidgetIndexMap.find(selectedDevice); if (deviceIterator != m_DeviceToWidgetIndexMap.end()) { QmitkAbstractTrackingDeviceWidget* widget = dynamic_cast(m_Controls->m_TrackingSystemWidget->widget(deviceIterator->second)); if (widget == nullptr || (widget != nullptr && !widget->IsDeviceInstalled())) { selectedDevice = mitk::NDIPolarisTypeInformation::GetTrackingDeviceName(); } } else { selectedDevice = mitk::NDIPolarisTypeInformation::GetTrackingDeviceName(); } const int index = m_Controls->m_TrackingDeviceChooser->findText(QString::fromStdString(selectedDevice)); if (index >= 0) { m_Controls->m_TrackingDeviceChooser->setCurrentIndex(index); } else { MITK_ERROR << "Failed to load UI setting for tracking device configuration"; return; } m_Controls->m_TrackingSystemWidget->setCurrentIndex(m_DeviceToWidgetIndexMap[selectedDevice]); } std::string QmitkTrackingDeviceConfigurationWidget::GetCurrentDeviceName(void) const { return m_Controls->m_TrackingDeviceChooser->currentText().toStdString(); } QmitkAbstractTrackingDeviceWidget* QmitkTrackingDeviceConfigurationWidget::GetWidget(const std::string& deviceName) const { const auto& deviceIterator = m_DeviceToWidgetIndexMap.find(deviceName); if (deviceIterator != m_DeviceToWidgetIndexMap.end()) { QWidget* widget = m_Controls->m_TrackingSystemWidget->widget(deviceIterator->second); return dynamic_cast(widget); } return nullptr; } diff --git a/Modules/IGTUI/Qmitk/QmitkTrackingDeviceConfigurationWidget.h b/Modules/IGTUI/Qmitk/QmitkTrackingDeviceConfigurationWidget.h index 94afdd0bc0..f024a6d923 100644 --- a/Modules/IGTUI/Qmitk/QmitkTrackingDeviceConfigurationWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkTrackingDeviceConfigurationWidget.h @@ -1,112 +1,108 @@ /*=================================================================== 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 QMITKTRACKINGDEVICECONFIGURATIONWIDGET_H #define QMITKTRACKINGDEVICECONFIGURATIONWIDGET_H #include #include #include "MitkIGTUIExports.h" #include "ui_QmitkTrackingDeviceConfigurationWidgetControls.h" -#include "mitkTrackingDevice.h" -#include #include "mitkTrackingDeviceTypeCollection.h" #include "mitkTrackingDeviceWidgetCollection.h" -//itk headers - /** Documentation: * \brief An object of this class offers an UI to configurate * a tracking device. If the user finished the configuration process and * a fully configurated tracking device is availiabe the object emits a * signal "TrackingDeviceConfigurationFinished()". You can then get the * tracking device by calling the method GetTrackingDevice(). * * Once the tracking device is configurated there are two ways to reset * the UI to allow the user for configuring a new device. The method Reset() * can be called and there is also a button "reset" which can be pressed by * the user. In both cases a signal "TrackingDeviceConfigurationReseted()" * is emitted and you may wait for a new configurated tracking device. * * * \ingroup IGTUI */ class MITKIGTUI_EXPORT QmitkTrackingDeviceConfigurationWidget : public QWidget { Q_OBJECT public: static const std::string VIEW_ID; QmitkTrackingDeviceConfigurationWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkTrackingDeviceConfigurationWidget(); /* @return Returns the current configurated tracking device. If the user didn't finished the * configuration process or if there is an error during configuration NULL is returned. */ mitk::TrackingDevice::Pointer GetTrackingDevice(); signals: /* @brief This signal is sent if the tracking device was changed. */ void TrackingDeviceSelectionChanged(); protected: /// \brief Creation of the connections virtual void CreateConnections(); virtual void CreateQtPartControl(QWidget *parent); Ui::QmitkTrackingDeviceConfigurationWidgetControls* m_Controls; mitk::TrackingDevice::Pointer m_TrackingDevice; // key is port name (e.g. "COM1", "/dev/ttyS0"), value will be filled with the type of tracking device at this port typedef QMap PortDeviceMap; //######################### internal help methods ####################################### void ResetOutput(); void AddOutput(std::string s); mitk::TrackingDevice::Pointer ConstructTrackingDevice(); void StoreUISettings(); void LoadUISettings(); /* @brief This method is called when the user clicks on "Refresh Selection" (m_RefreshTrackingDeviceCollection). It then sets the correct widget for the selected tracking device.*/ void RefreshTrackingDeviceCollection(); protected slots: /* @brief This method is called when the user changes the selection of the trackingdevice (m_trackingDeviceChooser). It then sets the correct widget for the selected tracking device.*/ void TrackingDeviceChanged(); private: PERSISTENCE_GET_SERVICE_METHOD_MACRO std::string GetCurrentDeviceName(void) const; QmitkAbstractTrackingDeviceWidget* GetWidget(const std::string& deviceName) const; /** * @brief Mapping of device type identifier and index of the configuration widget in QStackedWidget. */ std::map m_DeviceToWidgetIndexMap; }; #endif diff --git a/Modules/IGTUI/Qmitk/QmitkVirtualTrackerWidget.cpp b/Modules/IGTUI/Qmitk/QmitkVirtualTrackerWidget.cpp index f93eaf6df8..4b4a3db625 100644 --- a/Modules/IGTUI/Qmitk/QmitkVirtualTrackerWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkVirtualTrackerWidget.cpp @@ -1,97 +1,94 @@ /*=================================================================== 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 "QmitkVirtualTrackerWidget.h" -#include "QmitkTrackingDeviceConfigurationWidget.h" -#include - -#include -#include +#include "mitkVirtualTrackingDevice.h" const std::string QmitkVirtualTrackerWidget::VIEW_ID = "org.mitk.views.VirtualTrackerWidget"; QmitkVirtualTrackerWidget::QmitkVirtualTrackerWidget(QWidget* parent, Qt::WindowFlags f) : QmitkAbstractTrackingDeviceWidget(parent, f) + , m_Controls(nullptr) { - m_Controls = NULL; } void QmitkVirtualTrackerWidget::Initialize() { InitializeSuperclassWidget(); CreateQtPartControl(this); CreateConnections(); } QmitkVirtualTrackerWidget::~QmitkVirtualTrackerWidget() { + delete m_Controls; } void QmitkVirtualTrackerWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkVirtualTrackerWidget; m_Controls->setupUi(parent); } } void QmitkVirtualTrackerWidget::CreateConnections() { if (m_Controls) { connect((QObject*)(m_Controls->m_EnableGaussianNoise), SIGNAL(clicked()), this, SLOT(EnableGaussianNoise())); } } mitk::TrackingDevice::Pointer QmitkVirtualTrackerWidget::ConstructTrackingDevice() { // Create the Virtual Tracking Device mitk::VirtualTrackingDevice::Pointer returnValue = mitk::VirtualTrackingDevice::New(); if (m_Controls->m_EnableGaussianNoise->isChecked()) { returnValue->EnableGaussianNoise(); returnValue->SetParamsForGaussianNoise(m_Controls->m_MeanDistributionParam->value(), m_Controls->m_DeviationDistributionParam->value()); } return static_cast(returnValue); //static_cast necessary for compiling with Linux } void QmitkVirtualTrackerWidget::EnableGaussianNoise() { if (m_Controls->m_EnableGaussianNoise->isChecked()) { m_Controls->m_MeanDistributionParam->setEnabled(true); m_Controls->m_DeviationDistributionParam->setEnabled(true); } else { m_Controls->m_MeanDistributionParam->setEnabled(false); m_Controls->m_DeviationDistributionParam->setEnabled(false); } } QmitkVirtualTrackerWidget* QmitkVirtualTrackerWidget::Clone(QWidget* parent) const { QmitkVirtualTrackerWidget* clonedWidget = new QmitkVirtualTrackerWidget(parent); clonedWidget->Initialize(); clonedWidget->m_Controls->m_EnableGaussianNoise->setEnabled(m_Controls->m_EnableGaussianNoise->isEnabled()); clonedWidget->m_Controls->m_MeanDistributionParam->setValue(m_Controls->m_MeanDistributionParam->value()); clonedWidget->m_Controls->m_DeviationDistributionParam->setValue(m_Controls->m_DeviationDistributionParam->value()); return clonedWidget; -} \ No newline at end of file +} diff --git a/Modules/IGTUI/Qmitk/QmitkVirtualTrackerWidget.h b/Modules/IGTUI/Qmitk/QmitkVirtualTrackerWidget.h index 38aa691cc5..a713d917dc 100644 --- a/Modules/IGTUI/Qmitk/QmitkVirtualTrackerWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkVirtualTrackerWidget.h @@ -1,65 +1,61 @@ /*=================================================================== 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 QmitkVirtualTrackerWidget_H #define QmitkVirtualTrackerWidget_H -#include -#include "MitkIGTUIExports.h" #include "ui_QmitkVirtualTrackerWidget.h" - #include "QmitkAbstractTrackingDeviceWidget.h" -//itk headers /** Documentation: * \brief Implementation of a configuration widget for a Vitrual Tracking Device. * * \ingroup IGTUI */ class MITKIGTUI_EXPORT QmitkVirtualTrackerWidget : public QmitkAbstractTrackingDeviceWidget { Q_OBJECT // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) public: static const std::string VIEW_ID; QmitkVirtualTrackerWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkVirtualTrackerWidget(); virtual void Initialize(); signals: protected slots : /* @brief Enables or disables the Gaussian Noise for the VirtualTrackingDevice dependent on the State of the according Checkbox */ void EnableGaussianNoise(); private: /// \brief Creation of the connections void CreateConnections(); void CreateQtPartControl(QWidget *parent); protected: virtual QmitkVirtualTrackerWidget* Clone(QWidget* parent) const; Ui::QmitkVirtualTrackerWidget* m_Controls; public: virtual mitk::TrackingDevice::Pointer ConstructTrackingDevice(); }; #endif diff --git a/Modules/IGTUI/Qmitk/mitkTrackingDeviceWidgetCollection.cpp b/Modules/IGTUI/Qmitk/mitkTrackingDeviceWidgetCollection.cpp index a086879837..596d40caf2 100644 --- a/Modules/IGTUI/Qmitk/mitkTrackingDeviceWidgetCollection.cpp +++ b/Modules/IGTUI/Qmitk/mitkTrackingDeviceWidgetCollection.cpp @@ -1,79 +1,80 @@ /*=================================================================== 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 "mitkTrackingDeviceWidgetCollection.h" -#include "mitkUIDGenerator.h" //Microservices #include -#include -#include #include mitk::TrackingDeviceWidgetCollection::TrackingDeviceWidgetCollection() - : m_TrackingDeviceWidgets() + : m_ServiceRegistration() + , m_TrackingDeviceWidgets() { } mitk::TrackingDeviceWidgetCollection::~TrackingDeviceWidgetCollection() { + for (auto& item : m_TrackingDeviceWidgets) + { + delete item.second; + } } void mitk::TrackingDeviceWidgetCollection::RegisterAsMicroservice() { - // Get Context us::ModuleContext* context = us::GetModuleContext(); m_ServiceRegistration = context->RegisterService(this); } void mitk::TrackingDeviceWidgetCollection::UnRegisterMicroservice() { - if (m_ServiceRegistration != NULL) m_ServiceRegistration.Unregister(); + if (m_ServiceRegistration != nullptr) m_ServiceRegistration.Unregister(); m_ServiceRegistration = 0; } void mitk::TrackingDeviceWidgetCollection::RegisterTrackingDeviceWidget(TrackingDeviceType type, QmitkAbstractTrackingDeviceWidget* widget) { if (widget != nullptr) { //Don't add widget, if it is already included - for (int i = 0; i < m_TrackingDeviceWidgets.size(); i++) + for (unsigned int i = 0; i < m_TrackingDeviceWidgets.size(); i++) { if (m_TrackingDeviceWidgets.at(i).first == type) return; } m_TrackingDeviceWidgets.push_back(std::make_pair(type, widget)); } } QmitkAbstractTrackingDeviceWidget* mitk::TrackingDeviceWidgetCollection::GetTrackingDeviceWidgetClone(TrackingDeviceType type) { - for (int i = 0; i < m_TrackingDeviceWidgets.size(); i++) + for (unsigned int i = 0; i < m_TrackingDeviceWidgets.size(); i++) { if (m_TrackingDeviceWidgets.at(i).first == type) { if (!(m_TrackingDeviceWidgets.at(i).second->IsInitialized())) { m_TrackingDeviceWidgets.at(i).second->Initialize(); if (!(m_TrackingDeviceWidgets.at(i).second->IsInitialized())) //still not initialized? MITK_ERROR << "Something went wrong with initialization of your tracking device widget!"; } return (m_TrackingDeviceWidgets.at(i).second->CloneForQt()); } } return nullptr; -} \ No newline at end of file +} diff --git a/Modules/IGTUI/Qmitk/mitkTrackingDeviceWidgetCollection.h b/Modules/IGTUI/Qmitk/mitkTrackingDeviceWidgetCollection.h index 8159eb7114..2a30e7f1c3 100644 --- a/Modules/IGTUI/Qmitk/mitkTrackingDeviceWidgetCollection.h +++ b/Modules/IGTUI/Qmitk/mitkTrackingDeviceWidgetCollection.h @@ -1,71 +1,68 @@ /*=================================================================== 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 TRACKINGDEVICEWidgetCollection_H_INCLUDED -#define TRACKINGDEVICEWidgetCollection_H_INCLUDED +#ifndef TrackingDeviceWidgetCollection_H_INCLUDED +#define TrackingDeviceWidgetCollection_H_INCLUDED #include -#include "mitkTrackingTypes.h" #include "mitkTrackingDeviceTypeInformation.h" +#include "QmitkAbstractTrackingDeviceWidget.h" // Microservices #include #include -#include "QmitkAbstractTrackingDeviceWidget.h" namespace mitk { /** Documentation: * \brief This class is a collection for all TrackingDeviceWidgets (derived from AbstractTrackingDeviceWidget) * The Collection is avaiable via Microservice. * If you want to add your own tracking device to the Tracking Toolbox, you should register your widget configuring your device * to this collection using the RegisterTrackingDeviceWidget function. * \ingroup IGTUI */ class MITKIGTUI_EXPORT TrackingDeviceWidgetCollection { public: TrackingDeviceWidgetCollection(); ~TrackingDeviceWidgetCollection(); /** *\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 RegisterTrackingDeviceWidget(TrackingDeviceType type, QmitkAbstractTrackingDeviceWidget* widget); QmitkAbstractTrackingDeviceWidget* GetTrackingDeviceWidgetClone(TrackingDeviceType type); private: - std::string m_Name; - us::ServiceRegistration m_ServiceRegistration; - std::vector> m_TrackingDeviceWidgets; + std::vector > m_TrackingDeviceWidgets; }; } // namespace mitk MITK_DECLARE_SERVICE_INTERFACE(mitk::TrackingDeviceWidgetCollection, "org.mitk.services.TrackingDeviceWidgetCollection") -#endif //TRACKINGDEVICEWidgetCollection_H_INCLUDED +#endif //TrackingDeviceWidgetCollection_H_INCLUDED