diff --git a/Modules/IGT/IGTFilters/mitkNavigationDataSource.cpp b/Modules/IGT/IGTFilters/mitkNavigationDataSource.cpp index ace64c4a65..75e04649bd 100644 --- a/Modules/IGT/IGTFilters/mitkNavigationDataSource.cpp +++ b/Modules/IGT/IGTFilters/mitkNavigationDataSource.cpp @@ -1,109 +1,140 @@ /*=================================================================== 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 "mitkNavigationDataSource.h" +#include "mitkUIDGenerator.h" +//Microservices +#include +#include +#include +#include "mitkModuleContext.h" +const std::string mitk::NavigationDataSource::US_INTERFACE_NAME = "org.mitk.services.NavigationDataSource"; +const std::string mitk::NavigationDataSource::US_PROPKEY_ID = US_INTERFACE_NAME + ".id"; +const std::string mitk::NavigationDataSource::US_PROPKEY_ISACTIVE = US_INTERFACE_NAME + ".isActive"; mitk::NavigationDataSource::NavigationDataSource() : itk::ProcessObject() { + } mitk::NavigationDataSource::~NavigationDataSource() { } mitk::NavigationData* mitk::NavigationDataSource::GetOutput() { if (this->GetNumberOfOutputs() < 1) return NULL; return static_cast(this->ProcessObject::GetOutput(0)); } mitk::NavigationData* mitk::NavigationDataSource::GetOutput(unsigned int idx) { if (this->GetNumberOfOutputs() < 1) return NULL; return static_cast(this->ProcessObject::GetOutput(idx)); } mitk::NavigationData* mitk::NavigationDataSource::GetOutput(std::string navDataName) { DataObjectPointerArray& outputs = this->GetOutputs(); for (DataObjectPointerArray::iterator it = outputs.begin(); it != outputs.end(); ++it) if (navDataName == (static_cast(it->GetPointer()))->GetName()) return static_cast(it->GetPointer()); return NULL; } itk::ProcessObject::DataObjectPointerArraySizeType mitk::NavigationDataSource::GetOutputIndex( std::string navDataName ) { DataObjectPointerArray& outputs = this->GetOutputs(); for (DataObjectPointerArray::size_type i = 0; i < outputs.size(); ++i) if (navDataName == (static_cast(outputs.at(i).GetPointer()))->GetName()) return i; throw std::invalid_argument("output name does not exist"); } +void mitk::NavigationDataSource::RegisterAsMicroservice(){ + // Get Context + mitk::ModuleContext* context = GetModuleContext(); + + // Define ServiceProps + ServiceProperties props; + mitk::UIDGenerator uidGen = mitk::UIDGenerator ("org.mitk.services.NavigationDataSource.id_", 16); + props[ US_PROPKEY_ID ] = uidGen.GetUID(); + m_ServiceRegistration = context->RegisterService(this, props); +} + + +void mitk::NavigationDataSource::UnRegisterMicroservice(){ + m_ServiceRegistration.Unregister(); + m_ServiceRegistration = 0; +} + +std::string mitk::NavigationDataSource::GetMicroserviceID(){ + return this->m_ServiceRegistration.GetReference().GetProperty(US_PROPKEY_ID).ToString(); +} + void mitk::NavigationDataSource::GraftOutput(itk::DataObject *graft) { this->GraftNthOutput(0, graft); } void mitk::NavigationDataSource::GraftNthOutput(unsigned int idx, itk::DataObject *graft) { if ( idx >= this->GetNumberOfOutputs() ) { itkExceptionMacro(<<"Requested to graft output " << idx << " but this filter only has " << this->GetNumberOfOutputs() << " Outputs."); } if ( !graft ) { itkExceptionMacro(<<"Requested to graft output with a NULL pointer object" ); } itk::DataObject* output = this->GetOutput(idx); if ( !output ) { itkExceptionMacro(<<"Requested to graft output that is a NULL pointer" ); } // Call Graft on NavigationData to copy member data output->Graft( graft ); } itk::ProcessObject::DataObjectPointer mitk::NavigationDataSource::MakeOutput( unsigned int /*idx */) { mitk::NavigationData::Pointer p = mitk::NavigationData::New(); return static_cast(p.GetPointer()); } mitk::PropertyList::ConstPointer mitk::NavigationDataSource::GetParameters() const { mitk::PropertyList::Pointer p = mitk::PropertyList::New(); // add properties to p like this: //p->SetProperty("MyFilter_MyParameter", mitk::PropertyDataType::New(m_MyParameter)); return mitk::PropertyList::ConstPointer(p); } diff --git a/Modules/IGT/IGTFilters/mitkNavigationDataSource.h b/Modules/IGT/IGTFilters/mitkNavigationDataSource.h index e0bfc5cd43..af7d1e708e 100644 --- a/Modules/IGT/IGTFilters/mitkNavigationDataSource.h +++ b/Modules/IGT/IGTFilters/mitkNavigationDataSource.h @@ -1,122 +1,156 @@ /*=================================================================== 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 MITKNAVIGATIONDATASOURCE_H_HEADER_INCLUDED_ #define MITKNAVIGATIONDATASOURCE_H_HEADER_INCLUDED_ #include #include "mitkNavigationData.h" #include "mitkPropertyList.h" +// Microservices +#include +#include + namespace mitk { /**Documentation * \brief Navigation Data source * * Base class for all navigation filters that produce NavigationData objects as output. * This class defines the output-interface for NavigationDataFilters. * \warning: if Update() is called on any output object, all NavigationData filters will * generate new output data for all outputs, not just the one on which Update() was called. * * \ingroup IGT */ class MitkIGT_EXPORT NavigationDataSource : public itk::ProcessObject { public: mitkClassMacro(NavigationDataSource, itk::ProcessObject); /** *\brief return the output (output with id 0) of the filter */ NavigationData* GetOutput(void); /** *\brief return the output with id idx of the filter */ NavigationData* GetOutput(unsigned int idx); /** *\brief return the output with name navDataName of the filter */ NavigationData* GetOutput(std::string navDataName); /** *\brief return the index of the output with name navDataName, -1 if no output with that name was found * * \warning if a subclass has outputs that have different data type than mitk::NavigationData, they have to overwrite this method */ DataObjectPointerArraySizeType GetOutputIndex(std::string navDataName); /** + *\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(); + + /** + *\brief Returns the id that this device is registered with. The id will only be valid, if the + * NavigationDataSource has been registered using RegisterAsMicroservice(). + */ + std::string GetMicroserviceID(); + + /** + *\brief These Constants are used in conjunction with Microservices + */ + static const std::string US_INTERFACE_NAME; + static const std::string US_PROPKEY_ID; + static const std::string US_PROPKEY_ISACTIVE; + + /** *\brief Graft the specified DataObject onto this ProcessObject's output. * * See itk::ImageSource::GraftNthOutput for details */ virtual void GraftNthOutput(unsigned int idx, itk::DataObject *graft); /** * \brief Graft the specified DataObject onto this ProcessObject's output. * * See itk::ImageSource::Graft Output for details */ virtual void GraftOutput(itk::DataObject *graft); /** * \brief Make a DataObject of the correct type to used as the specified output. * * This method is automatically called when DataObject::DisconnectPipeline() * is called. DataObject::DisconnectPipeline, disconnects a data object * from being an output of its current source. When the data object * is disconnected, the ProcessObject needs to construct a replacement * output data object so that the ProcessObject is in a valid state. * Subclasses of NavigationDataSource that have outputs of different * data types must overwrite this method so that proper output objects * are created. */ virtual DataObjectPointer MakeOutput(unsigned int idx); /** * \brief Set all filter parameters as the PropertyList p * * This method allows to set all parameters of a filter with one * method call. For the names of the parameters, take a look at * the GetParameters method of the filter * This method has to be overwritten by each MITK-IGT filter. */ virtual void SetParameters(const mitk::PropertyList*){}; /** * \brief Get all filter parameters as a PropertyList * * This method allows to get all parameters of a filter with one * method call. The returned PropertyList must be assigned to a * SmartPointer immediately, or else it will get destroyed. * Every filter must overwrite this method to create a filter-specific * PropertyList. Note that property names must be unique over all * MITK-IGT filters. Therefore each filter should use its name as a prefix * for each property name. * Secondly, each filter should list the property names and data types * in the method documentation. */ virtual mitk::PropertyList::ConstPointer GetParameters() const; protected: NavigationDataSource(); virtual ~NavigationDataSource(); + + + private: + mitk::ServiceRegistration m_ServiceRegistration; }; } // namespace mitk +// This is the microservice declaration. Do not meddle! +US_DECLARE_SERVICE_INTERFACE(mitk::NavigationDataSource, "org.mitk.services.NavigationDataSource") #endif /* MITKNAVIGATIONDATASOURCE_H_HEADER_INCLUDED_ */ diff --git a/Modules/IGT/IGTFilters/mitkTrackingDeviceSourceConfigurator.cpp b/Modules/IGT/IGTFilters/mitkTrackingDeviceSourceConfigurator.cpp index d9e9326059..ae972a7dbb 100644 --- a/Modules/IGT/IGTFilters/mitkTrackingDeviceSourceConfigurator.cpp +++ b/Modules/IGT/IGTFilters/mitkTrackingDeviceSourceConfigurator.cpp @@ -1,250 +1,249 @@ /*=================================================================== 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 "mitkTrackingDeviceSourceConfigurator.h" #include "mitkNDITrackingDevice.h" #include "mitkClaronTrackingDevice.h" mitk::TrackingDeviceSourceConfigurator::TrackingDeviceSourceConfigurator(mitk::NavigationToolStorage::Pointer NavigationTools, mitk::TrackingDevice::Pointer TrackingDevice) { //make a copy of the navigation tool storage because we will modify the storage if (NavigationTools.IsNotNull()) { m_NavigationTools = mitk::NavigationToolStorage::New(); for (int i=0; iGetToolCount(); i++) { m_NavigationTools->AddTool(NavigationTools->GetTool(i)); } } m_TrackingDevice = TrackingDevice; m_ToolCorrespondencesInToolStorage = std::vector(); m_ErrorMessage = ""; } mitk::NavigationToolStorage::Pointer mitk::TrackingDeviceSourceConfigurator::GetUpdatedNavigationToolStorage() { return m_NavigationTools; } mitk::TrackingDeviceSourceConfigurator::~TrackingDeviceSourceConfigurator() { } bool mitk::TrackingDeviceSourceConfigurator::IsCreateTrackingDeviceSourcePossible() { if (m_NavigationTools.IsNull()) { m_ErrorMessage = "NavigationToolStorage is NULL!"; return false; } else if (m_TrackingDevice.IsNull()) { m_ErrorMessage = "TrackingDevice is NULL!"; return false; } else { for (int i=0; iGetToolCount(); i++) { if (m_NavigationTools->GetTool(i)->GetTrackingDeviceType() != m_TrackingDevice->GetType()) { m_ErrorMessage = "At least one tool is not of the same type like the tracking device."; return false; } } //TODO in case of Aurora: check if the tools are automatically detected by comparing the serial number return true; } } mitk::TrackingDeviceSource::Pointer mitk::TrackingDeviceSourceConfigurator::CreateTrackingDeviceSource() { mitk::NavigationDataObjectVisualizationFilter::Pointer dummy; return this->CreateTrackingDeviceSource(dummy); } mitk::TrackingDeviceSource::Pointer mitk::TrackingDeviceSourceConfigurator::CreateTrackingDeviceSource(mitk::NavigationDataObjectVisualizationFilter::Pointer &visualizationFilter) { if (!this->IsCreateTrackingDeviceSourcePossible()) return NULL; mitk::TrackingDeviceSource::Pointer returnValue; //create tracking device source if (m_TrackingDevice->GetType()==mitk::NDIAurora) {returnValue = CreateNDIAuroraTrackingDeviceSource(m_TrackingDevice,m_NavigationTools);} else if (m_TrackingDevice->GetType()==mitk::NDIPolaris) {returnValue = CreateNDIPolarisTrackingDeviceSource(m_TrackingDevice,m_NavigationTools);} else if (m_TrackingDevice->GetType()==mitk::ClaronMicron) {returnValue = CreateMicronTrackerTrackingDeviceSource(m_TrackingDevice,m_NavigationTools);} //TODO: insert other tracking systems? if (returnValue.IsNull()) return NULL; //create visualization filter visualizationFilter = CreateNavigationDataObjectVisualizationFilter(returnValue,m_NavigationTools); if (visualizationFilter.IsNull()) return NULL; return returnValue; } std::string mitk::TrackingDeviceSourceConfigurator::GetErrorMessage() { return this->m_ErrorMessage; } //############################ internal help methods ######################################## mitk::TrackingDeviceSource::Pointer mitk::TrackingDeviceSourceConfigurator::CreateNDIPolarisTrackingDeviceSource(mitk::TrackingDevice::Pointer trackingDevice, mitk::NavigationToolStorage::Pointer navigationTools) { mitk::TrackingDeviceSource::Pointer returnValue = mitk::TrackingDeviceSource::New(); mitk::NDITrackingDevice::Pointer thisDevice = dynamic_cast(trackingDevice.GetPointer()); m_ToolCorrespondencesInToolStorage = std::vector(); //add the tools to the tracking device for (int i=0; iGetToolCount(); i++) { mitk::NavigationTool::Pointer thisNavigationTool = m_NavigationTools->GetTool(i); m_ToolCorrespondencesInToolStorage.push_back(i); bool toolAddSuccess = thisDevice->AddTool(thisNavigationTool->GetToolName().c_str(),thisNavigationTool->GetCalibrationFile().c_str()); if (!toolAddSuccess) { this->m_ErrorMessage = "Can't add tool, is the SROM-file valid?"; return NULL; } } returnValue->SetTrackingDevice(thisDevice); return returnValue; } mitk::TrackingDeviceSource::Pointer mitk::TrackingDeviceSourceConfigurator::CreateNDIAuroraTrackingDeviceSource(mitk::TrackingDevice::Pointer trackingDevice, mitk::NavigationToolStorage::Pointer navigationTools) { mitk::TrackingDeviceSource::Pointer returnValue = mitk::TrackingDeviceSource::New(); mitk::NDITrackingDevice::Pointer thisDevice = dynamic_cast(trackingDevice.GetPointer()); //connect to aurora to dectect tools automatically thisDevice->OpenConnection(); - thisDevice->StartTracking(); //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(); m_ToolCorrespondencesInToolStorage = std::vector(); for (int i=0; iGetToolCount(); i++) { bool toolFound = false; for (int j=0; jGetToolCount(); 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(int k=0; kAddTool(navigationTools->GetTool(j)); m_ToolCorrespondencesInToolStorage.push_back(j); //adapt name of tool dynamic_cast(thisDevice->GetTool(i))->SetToolName(navigationTools->GetTool(j)->GetToolName()); //rember that this tool was already found alreadyFoundTools.push_back(j); toolFound = true; break; } } } if (!toolFound) { this->m_ErrorMessage = "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; iGetToolCount(); i++) { navigationTools->AddTool(newToolStorageInRightOrder->GetTool(i)); } returnValue->SetTrackingDevice(thisDevice); return returnValue; } mitk::TrackingDeviceSource::Pointer mitk::TrackingDeviceSourceConfigurator::CreateMicronTrackerTrackingDeviceSource(mitk::TrackingDevice::Pointer trackingDevice, mitk::NavigationToolStorage::Pointer navigationTools) { mitk::TrackingDeviceSource::Pointer returnValue = mitk::TrackingDeviceSource::New(); mitk::ClaronTrackingDevice::Pointer thisDevice = dynamic_cast(trackingDevice.GetPointer()); m_ToolCorrespondencesInToolStorage = std::vector(); //add the tools to the tracking device for (int i=0; iGetToolCount(); i++) { mitk::NavigationTool::Pointer thisNavigationTool = m_NavigationTools->GetTool(i); m_ToolCorrespondencesInToolStorage.push_back(i); bool toolAddSuccess = thisDevice->AddTool(thisNavigationTool->GetToolName().c_str(),thisNavigationTool->GetCalibrationFile().c_str()); if (!toolAddSuccess) { this->m_ErrorMessage = "Can't add tool, is the toolfile valid?"; return NULL; } } returnValue->SetTrackingDevice(thisDevice); return returnValue; } mitk::NavigationDataObjectVisualizationFilter::Pointer mitk::TrackingDeviceSourceConfigurator::CreateNavigationDataObjectVisualizationFilter(mitk::TrackingDeviceSource::Pointer trackingDeviceSource, mitk::NavigationToolStorage::Pointer navigationTools) { mitk::NavigationDataObjectVisualizationFilter::Pointer returnValue = mitk::NavigationDataObjectVisualizationFilter::New(); for (int i=0; iGetNumberOfOutputs(); i++) { mitk::NavigationTool::Pointer currentTool = navigationTools->GetToolByName(trackingDeviceSource->GetOutput(i)->GetName()); if (currentTool.IsNull()) { this->m_ErrorMessage = "Error: did not find correspondig tool in tracking device after initialization."; return NULL; } returnValue->SetInput(i,trackingDeviceSource->GetOutput(i)); returnValue->SetRepresentationObject(i,currentTool->GetDataNode()->GetData()); } return returnValue; } int mitk::TrackingDeviceSourceConfigurator::GetToolNumberInToolStorage(int outputID) { if (outputID < m_ToolCorrespondencesInToolStorage.size()) return m_ToolCorrespondencesInToolStorage.at(outputID); else return -1; } std::string mitk::TrackingDeviceSourceConfigurator::GetToolIdentifierInToolStorage(int outputID) { if (outputID < m_ToolCorrespondencesInToolStorage.size()) return m_NavigationTools->GetTool(m_ToolCorrespondencesInToolStorage.at(outputID))->GetIdentifier(); else return ""; } std::vector mitk::TrackingDeviceSourceConfigurator::GetToolNumbersInToolStorage() { return m_ToolCorrespondencesInToolStorage; } std::vector mitk::TrackingDeviceSourceConfigurator::GetToolIdentifiersInToolStorage() { std::vector returnValue = std::vector(); for (int i=0; iGetTool(m_ToolCorrespondencesInToolStorage.at(i))->GetIdentifier());} return returnValue; } diff --git a/Modules/IGT/IGTToolManagement/mitkNavigationToolStorage.cpp b/Modules/IGT/IGTToolManagement/mitkNavigationToolStorage.cpp index d821d9cbee..6aa3f072a7 100644 --- a/Modules/IGT/IGTToolManagement/mitkNavigationToolStorage.cpp +++ b/Modules/IGT/IGTToolManagement/mitkNavigationToolStorage.cpp @@ -1,99 +1,129 @@ /*=================================================================== 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 "mitkNavigationToolStorage.h" +//Microservices +#include +#include +#include +#include "mitkModuleContext.h" + +const std::string mitk::NavigationToolStorage::US_INTERFACE_NAME = "org.mitk.services.NavigationToolStorage"; // Name of the interface +const std::string mitk::NavigationToolStorage::US_PROPKEY_SOURCE_ID = US_INTERFACE_NAME + ".sourceID"; + mitk::NavigationToolStorage::NavigationToolStorage() { m_ToolCollection = std::vector(); this->m_DataStorage = NULL; } mitk::NavigationToolStorage::NavigationToolStorage(mitk::DataStorage::Pointer ds) { m_ToolCollection = std::vector(); this->m_DataStorage = ds; } mitk::NavigationToolStorage::~NavigationToolStorage() { if (m_DataStorage.IsNotNull()) //remove all nodes from the data storage { for(std::vector::iterator it = m_ToolCollection.begin(); it != m_ToolCollection.end(); it++) m_DataStorage->Remove((*it)->GetDataNode()); } } + +void mitk::NavigationToolStorage::RegisterAsMicroservice(std::string sourceID){ + + if ( sourceID.empty() ) mitkThrow() << "Empty or null string passed to NavigationToolStorage::registerAsMicroservice()."; + + // Get Context + mitk::ModuleContext* context = GetModuleContext(); + + // Define ServiceProps + ServiceProperties props; + props[ US_PROPKEY_SOURCE_ID ] = sourceID; + m_ServiceRegistration = context->RegisterService(this, props); +} + + +void mitk::NavigationToolStorage::UnRegisterMicroservice(){ + m_ServiceRegistration.Unregister(); + m_ServiceRegistration = 0; +} + + bool mitk::NavigationToolStorage::DeleteTool(int number) { if ((unsigned int)number > m_ToolCollection.size()) return false; std::vector::iterator it = m_ToolCollection.begin() + number; if(m_DataStorage.IsNotNull()) m_DataStorage->Remove((*it)->GetDataNode()); m_ToolCollection.erase(it); return true; } bool mitk::NavigationToolStorage::DeleteAllTools() { while(m_ToolCollection.size() > 0) if (!DeleteTool(0)) return false; return true; } bool mitk::NavigationToolStorage::AddTool(mitk::NavigationTool::Pointer tool) { if (GetTool(tool->GetIdentifier()).IsNotNull()) return false; else { m_ToolCollection.push_back(tool); if(m_DataStorage.IsNotNull()) { if (!m_DataStorage->Exists(tool->GetDataNode())) m_DataStorage->Add(tool->GetDataNode()); } return true; } } mitk::NavigationTool::Pointer mitk::NavigationToolStorage::GetTool(int number) { return m_ToolCollection.at(number); } mitk::NavigationTool::Pointer mitk::NavigationToolStorage::GetTool(std::string identifier) { for (int i=0; iGetIdentifier())==identifier) return GetTool(i); return NULL; } mitk::NavigationTool::Pointer mitk::NavigationToolStorage::GetToolByName(std::string name) { for (int i=0; iGetToolName())==name) return GetTool(i); return NULL; } int mitk::NavigationToolStorage::GetToolCount() { return m_ToolCollection.size(); } bool mitk::NavigationToolStorage::isEmpty() { return m_ToolCollection.empty(); } diff --git a/Modules/IGT/IGTToolManagement/mitkNavigationToolStorage.h b/Modules/IGT/IGTToolManagement/mitkNavigationToolStorage.h index 68ba521dc8..d56222372a 100644 --- a/Modules/IGT/IGTToolManagement/mitkNavigationToolStorage.h +++ b/Modules/IGT/IGTToolManagement/mitkNavigationToolStorage.h @@ -1,110 +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 NAVIGATIONTOOLSTORAGE_H_INCLUDED #define NAVIGATIONTOOLSTORAGE_H_INCLUDED //itk headers #include //mitk headers #include #include #include "mitkNavigationTool.h" #include +// Microservices +#include +#include + namespace mitk { /**Documentation * \brief An object of this class represents a collection of navigation tools. * You may add/delete navigation tools or store/load the whole collection * to/from the harddisc by using the class NavigationToolStorageSerializer * and NavigationToolStorageDeserializer. * * \ingroup IGT */ class MitkIGT_EXPORT NavigationToolStorage : public itk::Object { public: mitkClassMacro(NavigationToolStorage,itk::Object); /** @brief Constructs a NavigationToolStorage without reference to a DataStorage. The Data Nodes of tools have to be added and removed to a data storage outside this class. * Normaly the other constructor should be used. */ itkNewMacro(Self); /** @brief Constructs a NavigationToolStorage with reference to a DataStorage. The Data Nodes of tools are added and removed automatically to this data storage. */ mitkNewMacro1Param(Self,mitk::DataStorage::Pointer); + + /** + *\brief Registers this object as a Microservice, making it available to every module and/or plugin. + * To unregister, call UnregisterMicroservice(). Make sure to pass the id of the Device that this tool is connected to. + */ + virtual void RegisterAsMicroservice(std::string sourceID); + + /** + *\brief Registers this object as a Microservice, making it available to every module and/or plugin. + */ + virtual void UnRegisterMicroservice(); + + /** + *\brief Returns the id that this device is registered with. The id will only be valid, if the + * NavigationDataSource has been registered using RegisterAsMicroservice(). + */ + std::string GetMicroserviceID(); + + /** + *\brief These constants are used in conjunction with Microservices + */ + static const std::string US_INTERFACE_NAME; // Name of the interface + static const std::string US_PROPKEY_SOURCE_ID; // ID of the device this ToolStorage is associated with + + /** * @brief Adds a tool to the storage. Be sure that the tool has a unique * identifier which is not already part of this storage. * @return Returns true if the tool was added to the storage, false if not * (false can be returned if the identifier already exists in this storage * for example). */ bool AddTool(mitk::NavigationTool::Pointer tool); /** * @return Returns the tracking tool at the position "number" * in the storage. Returns NULL if there is no * tracking tool at this position. */ mitk::NavigationTool::Pointer GetTool(int number); /** * @return Returns the tracking tool with the given identifier. * Returns NULL if there is no * tracking tool with this identifier in the storage. */ mitk::NavigationTool::Pointer GetTool(std::string identifier); /** * @return Returns the tracking tool with the given name. * Returns NULL if there is no * tracking tool with this name in the storage. */ mitk::NavigationTool::Pointer GetToolByName(std::string name); /** * @brief Deletes a tool from the collection. */ bool DeleteTool(int number); /** * @brief Deletes all tools from the collection. */ bool DeleteAllTools(); /** * @return Returns the number of tools stored in the storage. */ int GetToolCount(); /** * @return Returns true if the storage is empty, false if not. */ bool isEmpty(); protected: NavigationToolStorage(); NavigationToolStorage(mitk::DataStorage::Pointer); ~NavigationToolStorage(); std::vector m_ToolCollection; mitk::DataStorage::Pointer m_DataStorage; + private: + mitk::ServiceRegistration m_ServiceRegistration; + }; } // namespace mitk +US_DECLARE_SERVICE_INTERFACE(mitk::NavigationToolStorage, "org.mitk.services.NavigationToolStorage") #endif //NAVIGATIONTOOLSTORAGE diff --git a/Modules/Qmitk/QmitkServiceListWidget.cpp b/Modules/Qmitk/QmitkServiceListWidget.cpp new file mode 100644 index 0000000000..4ae5ba38a6 --- /dev/null +++ b/Modules/Qmitk/QmitkServiceListWidget.cpp @@ -0,0 +1,181 @@ +/*=================================================================== + +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. + +===================================================================*/ + +//#define _USE_MATH_DEFINES +#include + +// STL HEaders +#include + +//QT headers +#include + +//microservices +#include +#include "mitkModuleContext.h" +#include + + +const std::string QmitkServiceListWidget::VIEW_ID = "org.mitk.views.QmitkServiceListWidget"; + +QmitkServiceListWidget::QmitkServiceListWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f) +{ + m_Controls = NULL; + CreateQtPartControl(this); +} + +QmitkServiceListWidget::~QmitkServiceListWidget() +{ + +} + + +//////////////////// INITIALIZATION ///////////////////// + +void QmitkServiceListWidget::CreateQtPartControl(QWidget *parent) +{ + if (!m_Controls) + { + // create GUI widgets + m_Controls = new Ui::QmitkServiceListWidgetControls; + m_Controls->setupUi(parent); + this->CreateConnections(); + } +} + +void QmitkServiceListWidget::CreateConnections() +{ + if ( m_Controls ) + { + connect( m_Controls->m_ServiceList, SIGNAL(currentItemChanged( QListWidgetItem *, QListWidgetItem *)), this, SLOT(OnDeviceSelectionChanged()) ); + } +} + +void QmitkServiceListWidget::Initialize(std::string interfaceName, std::string namingProperty, std::string filter) +{ + m_Context = mitk::GetModuleContext(); + if (filter.empty()) + m_Filter = "(" + mitk::ServiceConstants::OBJECTCLASS() + "=" + interfaceName + ")"; + else + m_Filter = filter; + m_Interface = interfaceName; + m_NamingProperty = namingProperty; + m_Context->RemoveServiceListener(this, &QmitkServiceListWidget::OnServiceEvent); + m_Context->AddServiceListener(this, &QmitkServiceListWidget::OnServiceEvent, m_Filter); + // Empty ListWidget + this->m_ListContent.clear(); + m_Controls->m_ServiceList->clear(); + + // get Services + std::list services = this->GetAllRegisteredServices(); + // Transfer them to the List + for(std::list::iterator it = services.begin(); it != services.end(); ++it) + AddServiceToList(*it); +} + + +///////////////////////// Getter & Setter ///////////////////////////////// + +template +T QmitkServiceListWidget::GetSelectedService() +{ + return this->GetDeviceForListItem(this->m_Controls->m_ServiceList->currentItem()); +} + +///////////// Methods & Slots Handling Direct Interaction ///////////////// + +void QmitkServiceListWidget::OnServiceSelectionChanged(){ + mitk::ServiceReference ref = this->GetServiceForListItem(this->m_Controls->m_ServiceList->currentItem()); + if (! ref) return; + + emit (ServiceSelected(ref)); +} + + +///////////////// Methods & Slots Handling Logic ////////////////////////// + +void QmitkServiceListWidget::OnServiceEvent(const mitk::ServiceEvent event){ + + switch (event.GetType()) + { + case event.MODIFIED: + emit(ServiceModified(event.GetServiceReference())); + RemoveServiceFromList(event.GetServiceReference()); + AddServiceToList(event.GetServiceReference()); + break; + case event.REGISTERED: + emit(ServiceRegistered(event.GetServiceReference())); + AddServiceToList(event.GetServiceReference()); + break; + case event.UNREGISTERING: + emit(ServiceUnregistering(event.GetServiceReference())); + RemoveServiceFromList(event.GetServiceReference()); + break; + //default: + // mitkThrow() << "ServiceListenerWidget recieved an unrecognized event. Please Update Implementation of QmitkServiceListWidget::OnServiceEvent()"; + } +} + + +/////////////////////// HOUSEHOLDING CODE ///////////////////////////////// + +QListWidgetItem* QmitkServiceListWidget::AddServiceToList(mitk::ServiceReference serviceRef){ + QListWidgetItem *newItem = new QListWidgetItem; + std::string caption; + //TODO allow more complex formatting + if (m_NamingProperty.empty()) + caption = m_Interface; + else + caption = serviceRef.GetProperty(m_NamingProperty).ToString(); + + newItem->setText(caption.c_str()); + + //Add new item to QListWidget + m_Controls->m_ServiceList->addItem(newItem); + // Construct link and add to internal List for reference + QmitkServiceListWidget::ServiceListLink link; + link.service = serviceRef; + link.item = newItem; + m_ListContent.push_back(link); + return newItem; +} + +bool QmitkServiceListWidget::RemoveServiceFromList(mitk::ServiceReference serviceRef){ + for(std::vector::iterator it = m_ListContent.begin(); it != m_ListContent.end(); ++it){ + if ( serviceRef == it->service ) + { + int row = m_Controls->m_ServiceList->row(it->item); + QListWidgetItem* oldItem = m_Controls->m_ServiceList->takeItem(row); + delete oldItem; + this->m_ListContent.erase(it); + return true; + } + } + return false; +} + + +mitk::ServiceReference QmitkServiceListWidget::GetServiceForListItem(QListWidgetItem* item) +{ + for(std::vector::iterator it = m_ListContent.begin(); it != m_ListContent.end(); ++it) + if (item == it->item) return it->service; +} + + +std::list QmitkServiceListWidget::GetAllRegisteredServices(){ + //Get Service References + return m_Context->GetServiceReferences(m_Interface, m_Filter); +} diff --git a/Modules/Qmitk/QmitkServiceListWidget.h b/Modules/Qmitk/QmitkServiceListWidget.h new file mode 100644 index 0000000000..78ee2dd070 --- /dev/null +++ b/Modules/Qmitk/QmitkServiceListWidget.h @@ -0,0 +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. + +===================================================================*/ + +#ifndef _QmitkServiceListWidget_H_INCLUDED +#define _QmitkServiceListWidget_H_INCLUDED + +#include "QmitkExports.h" +#include "ui_QmitkServiceListWidgetControls.h" +#include + +//QT headers +#include +#include + +//Microservices +#include "usServiceReference.h" +#include "usModuleContext.h" +#include "usServiceEvent.h" + +/** +* @brief This widget provides abstraction for MicroServices. Place one in your Plugin and set it to a certain interface. +* One can also specify a filter and / or a property to use for captioning of the services. It also offers functionality to be +* informed of ServiceEvents and to return the sctual classes, so only a minimum of interaction with the MicroserviceInterface is required. +* +* @ingroup QMITK +*/ +class QMITK_EXPORT QmitkServiceListWidget :public QWidget +{ + + //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) + Q_OBJECT + + public: + + static const std::string VIEW_ID; + + QmitkServiceListWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); + virtual ~QmitkServiceListWidget(); + + /* @brief This method is part of the widget an needs not to be called seperately. */ + virtual void CreateQtPartControl(QWidget *parent); + /* @brief This method is part of the widget an needs not to be called seperately. (Creation of the connections of main and control widget.)*/ + virtual void CreateConnections(); + + /* + * \brief Initializes the connection to the registry. The string filter is an LDAP parsable String, compare mitk::ModuleContext for examples on filtering. + * interfaceName is the name of the interface that is defined in the classes header file and that is used register it it with the MicroServices. NamingProperty + * is a property that will be used to caption the Items in the list. If no filter is supplied, all matching interfaces are shown. If no namingProperty is supplied, + * the interfaceName will be used to caption Items in the list. + */ + void Initialize(std::string interfaceName, std::string namingProperty, std::string filter); + + /* + * \brief Use this function to returns the currently selected service as a class directly. + * Make sure you pass the appropriate type, or else this call will fail. + */ + template + T GetSelectedService(); + + /* + * \brief Returns the currently selected Service as a ServiceReference. + */ + mitk::ServiceReference GetSelectedService(); + + /* + *\brief This Function listens to ServiceRegistry changes and updates the + * list of services accordingly. The user of this widget does not need to call this method, + * it is instead used to recieve events from the module registry. + */ + void OnServiceEvent(const mitk::ServiceEvent event); + + + + signals: + + /* + *\brief Emitted when a new Service mathing the filter is being registered. + */ + void ServiceRegistered(mitk::ServiceReference); + + /* + *\brief Emitted directly before a Service matching the filter is being unregistered. + */ + void ServiceUnregistering(mitk::ServiceReference); + + /* + *\brief Emitted when a Service matching the filter changes it's properties. + */ + void ServiceModified(mitk::ServiceReference); + + /* + *\brief Emitted the user selects a Service from the list + */ + void ServiceSelected(mitk::ServiceReference); + + public slots: + + protected slots: + + /* + \brief Called, when the selection in the list of Services changes + */ + void OnServiceSelectionChanged(); + + + protected: + + Ui::QmitkServiceListWidgetControls* m_Controls; ///< member holding the UI elements of this widget + + /* + * \brief Internal structure used to link ServiceReferences to their QListWidgetItems + */ + struct ServiceListLink { + mitk::ServiceReference service; + QListWidgetItem* item; + }; + + /* + * \brief Contains a list of currently active services and their entires in the list. This is wiped with every ServiceRegistryEvent. + */ + std::vector m_ListContent; + + /* + * \brief Constructs a ListItem from the given service, displays it, and locally stores the service. + */ + QListWidgetItem* AddServiceToList(mitk::ServiceReference serviceRef); + + /* + * \brief Removes the given service from the list and cleans up. Returns true if successful, false if service was not found. + */ + bool RemoveServiceFromList(mitk::ServiceReference serviceRef); + + /* + * \brief Returns the serviceReference corresponding to the given ListEntry or null if none was found (which really shouldn't happen). + */ + mitk::ServiceReference GetServiceForListItem(QListWidgetItem* item); + + /* + * \brief Returns a list of ServiceReferences matching the filter criteria by querying the service registry. + */ + std::list GetAllRegisteredServices(); + + + private: + + mitk::ModuleContext* m_Context; + /** \brief a filter to further narrow down the list of results **/ + std::string m_Filter; + /** \brief The name of the ServiceInterface that this class should list **/ + std::string m_Interface; + /** \brief The name of the ServiceProperty that will be displayed in the List to represent the service **/ + std::string m_NamingProperty; +}; + +#endif // _QmitkServiceListWidget_H_INCLUDED diff --git a/Modules/Qmitk/QmitkServiceListWidgetControls.ui b/Modules/Qmitk/QmitkServiceListWidgetControls.ui new file mode 100644 index 0000000000..b47307b6bc --- /dev/null +++ b/Modules/Qmitk/QmitkServiceListWidgetControls.ui @@ -0,0 +1,31 @@ + + + QmitkServiceListWidgetControls + + + + 0 + 0 + 323 + 231 + + + + + 0 + 0 + + + + QmitkServiceListWidget + + + + + + + + + + + diff --git a/Modules/Qmitk/files.cmake b/Modules/Qmitk/files.cmake index e43d76ed01..2060c284b0 100644 --- a/Modules/Qmitk/files.cmake +++ b/Modules/Qmitk/files.cmake @@ -1,63 +1,66 @@ set(CPP_FILES QmitkApplicationCursor.cpp QmitkEnums.h QmitkCustomVariants.h QmitkDataStorageComboBox.cpp QmitkDataStorageListModel.cpp QmitkDataStorageTableModel.cpp QmitkDataStorageTreeModel.cpp QmitkEventAdapter.cpp QmitkLevelWindowPresetDefinitionDialog.cpp QmitkLevelWindowRangeChangeDialog.cpp QmitkLevelWindowWidgetContextMenu.cpp QmitkLevelWindowWidget.cpp QmitkLineEditLevelWindowWidget.cpp QmitkMemoryUsageIndicatorView.cpp QmitkNodeDescriptor.cpp QmitkNodeDescriptorManager.cpp QmitkRenderWindowMenu.cpp QmitkProgressBar.cpp QmitkPropertiesTableEditor.cpp QmitkPropertiesTableModel.cpp QmitkPropertyDelegate.cpp QmitkRegisterClasses.cpp QmitkRenderingManager.cpp QmitkRenderingManagerFactory.cpp QmitkRenderWindow.cpp +QmitkServiceListWidget.cpp QmitkSliderLevelWindowWidget.cpp QmitkStdMultiWidget.cpp QmitkMouseModeSwitcher.cpp ) set(MOC_H_FILES QmitkDataStorageComboBox.h QmitkDataStorageTableModel.h QmitkLevelWindowPresetDefinitionDialog.h QmitkLevelWindowRangeChangeDialog.h QmitkLevelWindowWidgetContextMenu.h QmitkLevelWindowWidget.h QmitkLineEditLevelWindowWidget.h QmitkMemoryUsageIndicatorView.h QmitkNodeDescriptor.h QmitkNodeDescriptorManager.h QmitkRenderWindowMenu.h QmitkProgressBar.h QmitkPropertiesTableEditor.h QmitkPropertyDelegate.h QmitkRenderingManager.h QmitkRenderWindow.h +QmitkServiceListWidget.h QmitkSliderLevelWindowWidget.h QmitkStdMultiWidget.h QmitkMouseModeSwitcher.h ) set(UI_FILES QmitkLevelWindowPresetDefinition.ui QmitkLevelWindowWidget.ui QmitkLevelWindowRangeChange.ui QmitkMemoryUsageIndicator.ui +QmitkServiceListWidgetControls.ui ) set(QRC_FILES Qmitk.qrc ) diff --git a/Modules/US/USModel/mitkUSDevice.cpp b/Modules/US/USModel/mitkUSDevice.cpp index e31fbc8a60..b413a1c82b 100644 --- a/Modules/US/USModel/mitkUSDevice.cpp +++ b/Modules/US/USModel/mitkUSDevice.cpp @@ -1,266 +1,253 @@ /*=================================================================== 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 "mitkUSDevice.h" #include "mitkUSImageMetadata.h" //Microservices #include #include #include #include "mitkModuleContext.h" mitk::USDevice::USDevice(std::string manufacturer, std::string model) : mitk::ImageSource() { // Initialize Members m_Metadata = mitk::USImageMetadata::New(); m_Metadata->SetDeviceManufacturer(manufacturer); m_Metadata->SetDeviceModel(model); //m_Metadata->SetDeviceClass(GetDeviceClass()); m_IsActive = false; //set number of outputs this->SetNumberOfOutputs(1); //create a new output mitk::USImage::Pointer newOutput = mitk::USImage::New(); this->SetNthOutput(0,newOutput); } mitk::USDevice::USDevice(mitk::USImageMetadata::Pointer metadata) : mitk::ImageSource() { m_Metadata = metadata; //m_Metadata->SetDeviceClass(GetDeviceClass()); m_IsActive = false; //set number of outputs this->SetNumberOfOutputs(1); //create a new output mitk::USImage::Pointer newOutput = mitk::USImage::New(); this->SetNthOutput(0,newOutput); } mitk::USDevice::~USDevice() { } // Constructing Service Properties for the device mitk::ServiceProperties mitk::USDevice::ConstructServiceProperties() { ServiceProperties props; std::string yes = "true"; std::string no = "false"; if(this->GetIsActive()) props["IsActive"] = yes; else props["IsActive"] = no; props[ "DeviceClass" ] = GetDeviceClass(); props[ mitk::USImageMetadata::PROP_DEV_MANUFACTURER ] = m_Metadata->GetDeviceManufacturer(); props[ mitk::USImageMetadata::PROP_DEV_MODEL ] = m_Metadata->GetDeviceModel(); props[ mitk::USImageMetadata::PROP_DEV_COMMENT ] = m_Metadata->GetDeviceComment(); props[ mitk::USImageMetadata::PROP_PROBE_NAME ] = m_Metadata->GetProbeName(); props[ mitk::USImageMetadata::PROP_PROBE_FREQUENCY ] = m_Metadata->GetProbeFrequency(); props[ mitk::USImageMetadata::PROP_ZOOM ] = m_Metadata->GetZoom(); return props; } bool mitk::USDevice::Connect() { //TODO Throw Exception is already activated before connection // Prepare connection, fail if this fails. if (! this->OnConnection()) return false; // Get Context and Module mitk::ModuleContext* context = GetModuleContext(); ServiceProperties props = ConstructServiceProperties(); m_ServiceRegistration = context->RegisterService(this, props); return true; } bool mitk::USDevice::Disconnect() { // Prepare connection, fail if this fails. if (! this->OnDisconnection()) return false; // Unregister m_ServiceRegistration.Unregister(); m_ServiceRegistration = 0; return true; } -//bool mitk::USDevice::OnConnection() -//{ -// return true; -// // TODO: Make Abstract -//} -// -//bool mitk::USDevice::OnDisconnection() -//{ -// return true; -// // TODO Make Abstract -//} - - //Changed bool mitk::USDevice::Activate() { if (! this->GetIsConnected()) return false; m_IsActive = OnActivation(); ServiceProperties props = ConstructServiceProperties(); this->m_ServiceRegistration.SetProperties(props); return m_IsActive; } void mitk::USDevice::Deactivate() { m_IsActive= false; ServiceProperties props = ConstructServiceProperties(); this->m_ServiceRegistration.SetProperties(props); OnDeactivation(); } void mitk::USDevice::AddProbe(mitk::USProbe::Pointer probe) { for(int i = 0; i < m_ConnectedProbes.size(); i++) { if (m_ConnectedProbes[i]->IsEqualToProbe(probe)) return; } this->m_ConnectedProbes.push_back(probe); } void mitk::USDevice::ActivateProbe(mitk::USProbe::Pointer probe){ // currently, we may just add the probe. This behaviour must be changed, should more complicated SDK applications emerge AddProbe(probe); int index = -1; for(int i = 0; i < m_ConnectedProbes.size(); i++) { if (m_ConnectedProbes[i]->IsEqualToProbe(probe)) index = i; } // index now contains the position of the original instance of this probe m_ActiveProbe = m_ConnectedProbes[index]; } void mitk::USDevice::DeactivateProbe(){ m_ActiveProbe = 0; } void mitk::USDevice::GenerateData() { } mitk::USImage* mitk::USDevice::GetOutput() { if (this->GetNumberOfOutputs() < 1) return NULL; return static_cast(this->ProcessObject::GetOutput(0)); } mitk::USImage* mitk::USDevice::GetOutput(unsigned int idx) { if (this->GetNumberOfOutputs() < 1) return NULL; return static_cast(this->ProcessObject::GetOutput(idx)); } void mitk::USDevice::GraftOutput(itk::DataObject *graft) { this->GraftNthOutput(0, graft); } void mitk::USDevice::GraftNthOutput(unsigned int idx, itk::DataObject *graft) { if ( idx >= this->GetNumberOfOutputs() ) { itkExceptionMacro(<<"Requested to graft output " << idx << " but this filter only has " << this->GetNumberOfOutputs() << " Outputs."); } if ( !graft ) { itkExceptionMacro(<<"Requested to graft output with a NULL pointer object" ); } itk::DataObject* output = this->GetOutput(idx); if ( !output ) { itkExceptionMacro(<<"Requested to graft output that is a NULL pointer" ); } // Call Graft on USImage to copy member data output->Graft( graft ); } itk::ProcessObject::DataObjectPointer mitk::USDevice::MakeOutput( unsigned int /*idx */) { mitk::USImage::Pointer p = mitk::USImage::New(); return static_cast(p.GetPointer()); } //########### GETTER & SETTER ##################// bool mitk::USDevice::GetIsActive() { return m_IsActive; } bool mitk::USDevice::GetIsConnected() { // a device is connected if it is registered with the service return (m_ServiceRegistration != 0); } std::string mitk::USDevice::GetDeviceManufacturer(){ return this->m_Metadata->GetDeviceManufacturer(); } std::string mitk::USDevice::GetDeviceModel(){ return this->m_Metadata->GetDeviceModel(); } std::string mitk::USDevice::GetDeviceComment(){ return this->m_Metadata->GetDeviceComment(); } std::vector mitk::USDevice::GetConnectedProbes() { return m_ConnectedProbes; } diff --git a/Modules/USUI/CMakeLists.txt b/Modules/USUI/CMakeLists.txt index c0ac18187a..10c7fde455 100644 --- a/Modules/USUI/CMakeLists.txt +++ b/Modules/USUI/CMakeLists.txt @@ -1,8 +1,8 @@ MITK_CREATE_MODULE(MitkUSUI #SUBPROJECTS MITK-US INCLUDE_DIRS Qmitk - DEPENDS MitkUS Qmitk QmitkExt + DEPENDS Mitk MitkUS Qmitk QmitkExt QT_MODULE GENERATED_CPP ${TOOL_GUI_CPPS} ${TOOL_CPPS} ) diff --git a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h index 2e8f70d03c..96cdf84c2b 100644 --- a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h +++ b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h @@ -1,135 +1,135 @@ /*=================================================================== 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 _QmitkUSDeviceManagerWidget_H_INCLUDED #define _QmitkUSDeviceManagerWidget_H_INCLUDED #include "MitkUSUIExports.h" #include "ui_QmitkUSDeviceManagerWidgetControls.h" #include "mitkUSDevice.h" #include //QT headers #include #include //mitk header //Microservices #include "usServiceReference.h" #include "usModuleContext.h" #include "usServiceEvent.h" /** -* @brief TODO +* @brief This Widget is used to manage available Ultrasound Devices. * * @ingroup USUI */ class MitkUSUI_EXPORT QmitkUSDeviceManagerWidget :public QWidget //, public mitk::ServiceTrackerCustomizer<> // this extension is necessary if one wants to use ServiceTracking instead of filtering { //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) Q_OBJECT public: static const std::string VIEW_ID; QmitkUSDeviceManagerWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); virtual ~QmitkUSDeviceManagerWidget(); /* @brief This method is part of the widget an needs not to be called seperately. */ virtual void CreateQtPartControl(QWidget *parent); /* @brief This method is part of the widget an needs not to be called seperately. (Creation of the connections of main and control widget.)*/ virtual void CreateConnections(); /* *\brief This Function listens to ServiceRegistry changes and updates the * list of devices accordingly. */ void OnServiceEvent(const mitk::ServiceEvent event); signals: /* \brief Sent, when the user clicks "Activate Device" */ void USDeviceActivated(); public slots: protected slots: /* \brief Called, when the button "Activate Device" was clicked */ void OnClickedActivateDevice(); /* \brief Called, when the button "Disconnect Device" was clicked */ void OnClickedDisconnectDevice(); /* \brief Called, when the selection in the devicelist changes */ void OnDeviceSelectionChanged(); protected: Ui::QmitkUSDeviceManagerWidgetControls* m_Controls; ///< member holding the UI elements of this widget /* * \brief Internal Structure used to link devices to their QListWidget Items */ struct DeviceListLink { mitk::USDevice::Pointer device; QListWidgetItem* item; }; /* * \brief Contains a list of currently active devices and their entires in the list. This is wiped with every ServiceRegistryEvent. */ std::vector m_ListContent; /* * \brief Constructs a ListItem from the given device for display in the list of active devices. */ QListWidgetItem* ConstructItemFromDevice(mitk::USDevice::Pointer device); /* * \brief Returns the device corresponding to the given ListEntry or null if none was found (which really shouldnt happen). */ mitk::USDevice::Pointer GetDeviceForListItem(QListWidgetItem* item); //mitk::ServiceTracker ConstructServiceTracker(); /* * \brief Returns a List of US Devices that are currently connected by querying the service registry. */ std::vector GetAllRegisteredDevices(); private: mitk::ModuleContext* m_MitkUSContext; }; #endif // _QmitkUSDeviceManagerWidget_H_INCLUDED diff --git a/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxView.cpp b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxView.cpp index 128120f7c6..0500b34935 100644 --- a/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxView.cpp +++ b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxView.cpp @@ -1,576 +1,618 @@ /*=================================================================== 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. ===================================================================*/ // Blueberry #include #include // Qmitk #include "QmitkMITKIGTTrackingToolboxView.h" #include "QmitkStdMultiWidget.h" // Qt #include #include // MITK #include #include #include #include #include #include #include // vtk #include const std::string QmitkMITKIGTTrackingToolboxView::VIEW_ID = "org.mitk.views.mitkigttrackingtoolbox"; QmitkMITKIGTTrackingToolboxView::QmitkMITKIGTTrackingToolboxView() : QmitkFunctionality() , m_Controls( 0 ) , m_MultiWidget( NULL ) { m_TrackingTimer = new QTimer(this); m_tracking = false; m_logging = false; m_loggedFrames = 0; } QmitkMITKIGTTrackingToolboxView::~QmitkMITKIGTTrackingToolboxView() { //remove the tracking volume this->GetDataStorage()->Remove(m_TrackingVolumeNode); } void QmitkMITKIGTTrackingToolboxView::CreateQtPartControl( QWidget *parent ) { // build up qt view, unless already done if ( !m_Controls ) { // create GUI widgets from the Qt Designer's .ui file m_Controls = new Ui::QmitkMITKIGTTrackingToolboxViewControls; m_Controls->setupUi( parent ); //create connections connect( m_Controls->m_LoadTools, SIGNAL(clicked()), this, SLOT(OnLoadTools()) ); + connect( m_Controls->m_Connect, SIGNAL(clicked()), this, SLOT(OnConnect()) ); + connect( m_Controls->m_Disconnect, SIGNAL(clicked()), this, SLOT(OnDisconnect()) ); connect( m_Controls->m_StartTracking, SIGNAL(clicked()), this, SLOT(OnStartTracking()) ); connect( m_Controls->m_StopTracking, SIGNAL(clicked()), this, SLOT(OnStopTracking()) ); connect( m_TrackingTimer, SIGNAL(timeout()), this, SLOT(UpdateTrackingTimer())); connect( m_Controls->m_ChooseFile, SIGNAL(clicked()), this, SLOT(OnChooseFileClicked())); connect( m_Controls->m_StartLogging, SIGNAL(clicked()), this, SLOT(StartLogging())); connect( m_Controls->m_StopLogging, SIGNAL(clicked()), this, SLOT(StopLogging())); connect( m_Controls->m_configurationWidget, SIGNAL(TrackingDeviceSelectionChanged()), this, SLOT(OnTrackingDeviceChanged())); connect( m_Controls->m_VolumeSelectionBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(OnTrackingVolumeChanged(QString))); connect( m_Controls->m_ShowTrackingVolume, SIGNAL(clicked()), this, SLOT(OnShowTrackingVolumeChanged())); connect( m_Controls->m_AutoDetectTools, SIGNAL(clicked()), this, SLOT(OnAutoDetectTools())); connect( m_Controls->m_ResetTools, SIGNAL(clicked()), this, SLOT(OnResetTools())); connect( m_Controls->m_AddSingleTool, SIGNAL(clicked()), this, SLOT(OnAddSingleTool())); connect( m_Controls->m_NavigationToolCreationWidget, SIGNAL(NavigationToolFinished()), this, SLOT(OnAddSingleToolFinished())); connect( m_Controls->m_NavigationToolCreationWidget, SIGNAL(Canceled()), this, SLOT(OnAddSingleToolCanceled())); //initialize widgets m_Controls->m_configurationWidget->EnableAdvancedUserControl(false); m_Controls->m_TrackingToolsStatusWidget->SetShowPositions(true); m_Controls->m_TrackingToolsStatusWidget->SetTextAlignment(Qt::AlignLeft); //initialize tracking volume node m_TrackingVolumeNode = mitk::DataNode::New(); m_TrackingVolumeNode->SetName("TrackingVolume"); m_TrackingVolumeNode->SetOpacity(0.25); m_TrackingVolumeNode->SetBoolProperty("Backface Culling",true); mitk::Color red; red.SetRed(1); m_TrackingVolumeNode->SetColor(red); GetDataStorage()->Add(m_TrackingVolumeNode); //initialize buttons + m_Controls->m_Connect->setEnabled(true); + m_Controls->m_Disconnect->setEnabled(false); + m_Controls->m_StartTracking->setEnabled(false); m_Controls->m_StopTracking->setEnabled(false); - m_Controls->m_StopLogging->setEnabled(false); m_Controls->m_AutoDetectTools->setVisible(false); //only visible if tracking device is Aurora //Update List of available models for selected tool. std::vector Compatibles = mitk::GetDeviceDataForLine( m_Controls->m_configurationWidget->GetTrackingDevice()->GetType()); m_Controls->m_VolumeSelectionBox->clear(); for(int i = 0; i < Compatibles.size(); i++) { m_Controls->m_VolumeSelectionBox->addItem(Compatibles[i].Model.c_str()); } } } void QmitkMITKIGTTrackingToolboxView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget) { m_MultiWidget = &stdMultiWidget; } void QmitkMITKIGTTrackingToolboxView::StdMultiWidgetNotAvailable() { m_MultiWidget = NULL; } void QmitkMITKIGTTrackingToolboxView::OnLoadTools() { //read in filename QString filename = QFileDialog::getOpenFileName(NULL,tr("Open Toolfile"), "/", tr("All Files (*.*)")); //later perhaps: tr("Toolfile (*.tfl)" if (filename.isNull()) return; //read tool storage from disk std::string errorMessage = ""; mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(GetDataStorage()); m_toolStorage = myDeserializer->Deserialize(filename.toStdString()); if(m_toolStorage->isEmpty()) { errorMessage = myDeserializer->GetErrorMessage(); MessageBox(errorMessage); return; } //update label Poco::Path myPath = Poco::Path(filename.toStdString()); //use this to seperate filename from path QString toolLabel = QString("Loaded Tools: ") + QString::number(m_toolStorage->GetToolCount()) + " Tools from " + myPath.getFileName().c_str(); m_Controls->m_toolLabel->setText(toolLabel); //update tool preview m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels(); m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage); } void QmitkMITKIGTTrackingToolboxView::OnResetTools() { m_toolStorage = NULL; m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels(); QString toolLabel = QString("Loaded Tools: "); m_Controls->m_toolLabel->setText(toolLabel); } -void QmitkMITKIGTTrackingToolboxView::OnStartTracking() -{ -//check if everything is ready to start tracking -if (this->m_toolStorage.IsNull()) +void QmitkMITKIGTTrackingToolboxView::OnConnect() { - MessageBox("Error: No Tools Loaded Yet!"); - return; + //check if everything is ready to start tracking + if (this->m_toolStorage.IsNull()) + { + MessageBox("Error: No Tools Loaded Yet!"); + return; } -else if (this->m_toolStorage->GetToolCount() == 0) + else if (this->m_toolStorage->GetToolCount() == 0) { - MessageBox("Error: No Way To Track Without Tools!"); - return; + MessageBox("Error: No Way To Track Without Tools!"); + return; } -//build the IGT pipeline -mitk::TrackingDevice::Pointer trackingDevice = this->m_Controls->m_configurationWidget->GetTrackingDevice(); + //build the IGT pipeline + mitk::TrackingDevice::Pointer trackingDevice = this->m_Controls->m_configurationWidget->GetTrackingDevice(); -//Get Tracking Volume Data -mitk::TrackingDeviceData data = mitk::DeviceDataUnspecified; + //Get Tracking Volume Data + mitk::TrackingDeviceData data = mitk::DeviceDataUnspecified; -QString qstr = m_Controls->m_VolumeSelectionBox->currentText(); -if ( (! qstr.isNull()) || (! qstr.isEmpty()) ) { - std::string str = qstr.toStdString(); - data = mitk::GetDeviceDataByName(str); //Data will be set later, after device generation -} + QString qstr = m_Controls->m_VolumeSelectionBox->currentText(); + if ( (! qstr.isNull()) || (! qstr.isEmpty()) ) { + std::string str = qstr.toStdString(); + data = mitk::GetDeviceDataByName(str); //Data will be set later, after device generation + } -mitk::TrackingDeviceSourceConfigurator::Pointer myTrackingDeviceSourceFactory = mitk::TrackingDeviceSourceConfigurator::New(this->m_toolStorage,trackingDevice); -m_TrackingDeviceSource = myTrackingDeviceSourceFactory->CreateTrackingDeviceSource(this->m_ToolVisualizationFilter); -if (m_TrackingDeviceSource.IsNull()) + mitk::TrackingDeviceSourceConfigurator::Pointer myTrackingDeviceSourceFactory = mitk::TrackingDeviceSourceConfigurator::New(this->m_toolStorage,trackingDevice); + m_TrackingDeviceSource = myTrackingDeviceSourceFactory->CreateTrackingDeviceSource(this->m_ToolVisualizationFilter); + + if (m_TrackingDeviceSource.IsNull()) { - MessageBox(myTrackingDeviceSourceFactory->GetErrorMessage()); - return; + MessageBox(myTrackingDeviceSourceFactory->GetErrorMessage()); + return; } -//disable Buttons -m_Controls->m_StopTracking->setEnabled(true); -m_Controls->m_StartTracking->setEnabled(false); -DisableOptionsButtons(); -DisableTrackingConfigurationButtons(); + //connect to device + try + { + m_TrackingDeviceSource->Connect(); + //Microservice registration: + m_TrackingDeviceSource->RegisterAsMicroservice(); + m_toolStorage->RegisterAsMicroservice(m_TrackingDeviceSource->GetMicroserviceID()); + } + catch (...) //todo: change to mitk::IGTException + { + MessageBox("Error while starting the tracking device!"); + return; + } -//initialize tracking -try - { - m_TrackingDeviceSource->Connect(); - m_TrackingDeviceSource->StartTracking(); + //enable/disable Buttons + m_Controls->m_Disconnect->setEnabled(true); + m_Controls->m_StartTracking->setEnabled(true); + m_Controls->m_StopTracking->setEnabled(false); + m_Controls->m_Connect->setEnabled(false); + DisableOptionsButtons(); + DisableTrackingConfigurationButtons(); + m_Controls->m_configurationWidget->ConfigurationFinished(); + + m_Controls->m_TrackingControlLabel->setText("Status: connected"); } -catch (...) + +void QmitkMITKIGTTrackingToolboxView::OnDisconnect() { - MessageBox("Error while starting the tracking device!"); - //enable Buttons + if (m_tracking) this->OnStopTracking(); + + m_TrackingDeviceSource->Disconnect(); + m_TrackingDeviceSource->UnRegisterMicroservice(); + //ToolStorages unregisters automatically + + //enable/disable Buttons + m_Controls->m_Disconnect->setEnabled(false); + m_Controls->m_StartTracking->setEnabled(false); m_Controls->m_StopTracking->setEnabled(false); - m_Controls->m_StartTracking->setEnabled(true); + m_Controls->m_Connect->setEnabled(true); EnableOptionsButtons(); EnableTrackingConfigurationButtons(); - return; + m_Controls->m_configurationWidget->Reset(); + m_Controls->m_TrackingControlLabel->setText("Status: disconnected"); + } -m_TrackingTimer->start(1000/(m_Controls->m_UpdateRate->value())); -m_Controls->m_TrackingControlLabel->setText("Status: tracking"); -//connect the tool visualization widget -for(int i=0; iGetNumberOfOutputs(); i++) +void QmitkMITKIGTTrackingToolboxView::OnStartTracking() +{ + try + { + m_TrackingDeviceSource->StartTracking(); + } + catch (...) //todo: change to mitk::IGTException + { + MessageBox("Error while starting the tracking device!"); + return; + } + + m_TrackingTimer->start(1000/(m_Controls->m_UpdateRate->value())); + m_Controls->m_TrackingControlLabel->setText("Status: tracking"); + + //connect the tool visualization widget + for(int i=0; iGetNumberOfOutputs(); i++) { m_Controls->m_TrackingToolsStatusWidget->AddNavigationData(m_TrackingDeviceSource->GetOutput(i)); } -m_Controls->m_TrackingToolsStatusWidget->ShowStatusLabels(); -if (m_Controls->m_ShowToolQuaternions->isChecked()) {m_Controls->m_TrackingToolsStatusWidget->SetShowQuaternions(true);} -else {m_Controls->m_TrackingToolsStatusWidget->SetShowQuaternions(false);} + m_Controls->m_TrackingToolsStatusWidget->ShowStatusLabels(); + if (m_Controls->m_ShowToolQuaternions->isChecked()) {m_Controls->m_TrackingToolsStatusWidget->SetShowQuaternions(true);} + else {m_Controls->m_TrackingToolsStatusWidget->SetShowQuaternions(false);} -//set configuration finished -this->m_Controls->m_configurationWidget->ConfigurationFinished(); + //show tracking volume + this->OnTrackingVolumeChanged(m_Controls->m_VolumeSelectionBox->currentText()); -//show tracking volume -this->OnTrackingVolumeChanged(m_Controls->m_VolumeSelectionBox->currentText()); + //enable/disable Buttons + m_Controls->m_Disconnect->setEnabled(true); + m_Controls->m_StartTracking->setEnabled(false); + m_Controls->m_StopTracking->setEnabled(true); + m_Controls->m_Connect->setEnabled(false); -m_tracking = true; + m_tracking = true; -this->GlobalReinit(); + this->GlobalReinit(); } void QmitkMITKIGTTrackingToolboxView::OnStopTracking() { -if (!m_tracking) return; -m_TrackingTimer->stop(); -m_TrackingDeviceSource->StopTracking(); -m_TrackingDeviceSource->Disconnect(); -this->m_Controls->m_configurationWidget->Reset(); -m_Controls->m_TrackingControlLabel->setText("Status: stopped"); -if (m_logging) StopLogging(); -m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels(); -m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage); -m_tracking = false; - -//enable Buttons -m_Controls->m_StopTracking->setEnabled(false); -m_Controls->m_StartTracking->setEnabled(true); -EnableOptionsButtons(); -EnableTrackingConfigurationButtons(); - -this->GlobalReinit(); + if (!m_tracking) return; + m_TrackingTimer->stop(); + m_TrackingDeviceSource->StopTracking(); + m_Controls->m_TrackingControlLabel->setText("Status: connected"); + if (m_logging) StopLogging(); + m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels(); + m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage); + m_tracking = false; + + //enable/disable Buttons + m_Controls->m_Disconnect->setEnabled(true); + m_Controls->m_StartTracking->setEnabled(true); + m_Controls->m_StopTracking->setEnabled(false); + m_Controls->m_Connect->setEnabled(false); + + this->GlobalReinit(); } void QmitkMITKIGTTrackingToolboxView::OnTrackingDeviceChanged() { mitk::TrackingDeviceType Type = m_Controls->m_configurationWidget->GetTrackingDevice()->GetType(); // Code to enable/disable device specific buttons if (Type == mitk::NDIAurora) //Aurora { m_Controls->m_AutoDetectTools->setVisible(true); m_Controls->m_AddSingleTool->setEnabled(false); } else //Polaris or Microntracker { m_Controls->m_AutoDetectTools->setVisible(false); m_Controls->m_AddSingleTool->setEnabled(true); } // Code to select appropriate tracking volume for current type std::vector Compatibles = mitk::GetDeviceDataForLine(Type); m_Controls->m_VolumeSelectionBox->clear(); for(int i = 0; i < Compatibles.size(); i++) { m_Controls->m_VolumeSelectionBox->addItem(Compatibles[i].Model.c_str()); } } void QmitkMITKIGTTrackingToolboxView::OnTrackingVolumeChanged(QString qstr) { if (qstr.isNull()) return; if (qstr.isEmpty()) return; if (m_Controls->m_ShowTrackingVolume->isChecked()) { mitk::TrackingVolumeGenerator::Pointer volumeGenerator = mitk::TrackingVolumeGenerator::New(); std::string str = qstr.toStdString(); mitk::TrackingDeviceData data = mitk::GetDeviceDataByName(str); volumeGenerator->SetTrackingDeviceData(data); volumeGenerator->Update(); mitk::Surface::Pointer volumeSurface = volumeGenerator->GetOutput(); m_TrackingVolumeNode->SetData(volumeSurface); GlobalReinit(); } } void QmitkMITKIGTTrackingToolboxView::OnShowTrackingVolumeChanged() { if (m_Controls->m_ShowTrackingVolume->isChecked()) { OnTrackingVolumeChanged(m_Controls->m_VolumeSelectionBox->currentText()); GetDataStorage()->Add(m_TrackingVolumeNode); } else { GetDataStorage()->Remove(m_TrackingVolumeNode); GlobalReinit(); } } void QmitkMITKIGTTrackingToolboxView::OnAutoDetectTools() { if (m_Controls->m_configurationWidget->GetTrackingDevice()->GetType() == mitk::NDIAurora) { DisableTrackingConfigurationButtons(); mitk::NDITrackingDevice::Pointer currentDevice = dynamic_cast(m_Controls->m_configurationWidget->GetTrackingDevice().GetPointer()); currentDevice->OpenConnection(); currentDevice->StartTracking(); mitk::NavigationToolStorage::Pointer autoDetectedStorage = mitk::NavigationToolStorage::New(this->GetDataStorage()); for (int i=0; iGetToolCount(); i++) { //create a navigation tool with sphere as surface std::stringstream toolname; toolname << "AutoDetectedTool" << i; mitk::NavigationTool::Pointer newTool = mitk::NavigationTool::New(); newTool->SetSerialNumber(dynamic_cast(currentDevice->GetTool(i))->GetSerialNumber()); newTool->SetIdentifier(toolname.str()); newTool->SetTrackingDeviceType(mitk::NDIAurora); mitk::DataNode::Pointer newNode = mitk::DataNode::New(); mitk::Surface::Pointer mySphere = mitk::Surface::New(); vtkSphereSource *vtkData = vtkSphereSource::New(); vtkData->SetRadius(3.0f); vtkData->SetCenter(0.0, 0.0, 0.0); vtkData->Update(); mySphere->SetVtkPolyData(vtkData->GetOutput()); vtkData->Delete(); newNode->SetData(mySphere); newNode->SetName(toolname.str()); newTool->SetDataNode(newNode); autoDetectedStorage->AddTool(newTool); } //save detected tools m_toolStorage = autoDetectedStorage; //update label QString toolLabel = QString("Loaded Tools: ") + QString::number(m_toolStorage->GetToolCount()) + " Tools (Auto Detected)"; m_Controls->m_toolLabel->setText(toolLabel); //update tool preview m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels(); m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage); currentDevice->StopTracking(); currentDevice->CloseConnection(); EnableTrackingConfigurationButtons(); if (m_toolStorage->GetToolCount()>0) { //ask the user if he wants to save the detected tools QMessageBox msgBox; switch(m_toolStorage->GetToolCount()) { case 1: msgBox.setText("Found one tool!"); break; default: msgBox.setText("Found " + QString::number(m_toolStorage->GetToolCount()) + " tools!"); } msgBox.setInformativeText("Do you want to save this tools as tool storage, so you can load them again?"); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msgBox.setDefaultButton(QMessageBox::No); int ret = msgBox.exec(); if (ret == 16384) //yes { //ask the user for a filename QString fileName = QFileDialog::getSaveFileName(NULL, tr("Save File"),"/",tr("*.*")); //check for empty filename if(fileName == "") {return;} mitk::NavigationToolStorageSerializer::Pointer mySerializer = mitk::NavigationToolStorageSerializer::New(); if (!mySerializer->Serialize(fileName.toStdString(),m_toolStorage)) MessageBox(mySerializer->GetErrorMessage()); return; } else if (ret == 65536) //no { return; } } } } void QmitkMITKIGTTrackingToolboxView::MessageBox(std::string s) { QMessageBox msgBox; msgBox.setText(s.c_str()); msgBox.exec(); } void QmitkMITKIGTTrackingToolboxView::UpdateTrackingTimer() { m_ToolVisualizationFilter->Update(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); if (m_logging) { this->m_loggingFilter->Update(); m_loggedFrames = this->m_loggingFilter->GetRecordCounter(); this->m_Controls->m_LoggedFramesLabel->setText("Logged Frames: "+QString::number(m_loggedFrames)); //check if logging stopped automatically if((m_loggedFrames>1)&&(!m_loggingFilter->GetRecording())){StopLogging();} } m_Controls->m_TrackingToolsStatusWidget->Refresh(); } void QmitkMITKIGTTrackingToolboxView::OnChooseFileClicked() { QString filename = QFileDialog::getSaveFileName(NULL,tr("Choose Logging File"), "/", "*.*"); if (filename == "") return; this->m_Controls->m_LoggingFileName->setText(filename); } void QmitkMITKIGTTrackingToolboxView::StartLogging() { if (!m_logging) { //initialize logging filter m_loggingFilter = mitk::NavigationDataRecorder::New(); m_loggingFilter->SetRecordingMode(mitk::NavigationDataRecorder::NormalFile); if (m_Controls->m_xmlFormat->isChecked()) m_loggingFilter->SetOutputFormat(mitk::NavigationDataRecorder::xml); else if (m_Controls->m_csvFormat->isChecked()) m_loggingFilter->SetOutputFormat(mitk::NavigationDataRecorder::csv); m_loggingFilter->SetFileName(m_Controls->m_LoggingFileName->text().toStdString().c_str()); if (m_Controls->m_LoggingLimit->isChecked()){m_loggingFilter->SetRecordCountLimit(m_Controls->m_LoggedFramesLimit->value());} //connect filter for(int i=0; iGetNumberOfOutputs(); i++){m_loggingFilter->AddNavigationData(m_ToolVisualizationFilter->GetOutput(i));} //start filter m_loggingFilter->StartRecording(); //update labels / logging variables this->m_Controls->m_LoggingLabel->setText("Logging ON"); this->m_Controls->m_LoggedFramesLabel->setText("Logged Frames: 0"); m_loggedFrames = 0; m_logging = true; DisableLoggingButtons(); } } void QmitkMITKIGTTrackingToolboxView::StopLogging() { if (m_logging) { //update label this->m_Controls->m_LoggingLabel->setText("Logging OFF"); m_loggingFilter->StopRecording(); m_logging = false; EnableLoggingButtons(); } } void QmitkMITKIGTTrackingToolboxView::OnAddSingleTool() { QString Identifier = "Tool#"; if (m_toolStorage.IsNotNull()) Identifier += QString::number(m_toolStorage->GetToolCount()); else Identifier += "0"; m_Controls->m_NavigationToolCreationWidget->Initialize(GetDataStorage(),Identifier.toStdString()); m_Controls->m_NavigationToolCreationWidget->SetTrackingDeviceType(m_Controls->m_configurationWidget->GetTrackingDevice()->GetType(),false); m_Controls->m_TrackingToolsWidget->setCurrentIndex(1); } void QmitkMITKIGTTrackingToolboxView::OnAddSingleToolFinished() { m_Controls->m_TrackingToolsWidget->setCurrentIndex(0); if (this->m_toolStorage.IsNull()) m_toolStorage = mitk::NavigationToolStorage::New(GetDataStorage()); m_toolStorage->AddTool(m_Controls->m_NavigationToolCreationWidget->GetCreatedTool()); m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage); QString toolLabel = QString("Loaded Tools: "); } void QmitkMITKIGTTrackingToolboxView::OnAddSingleToolCanceled() { m_Controls->m_TrackingToolsWidget->setCurrentIndex(0); } void QmitkMITKIGTTrackingToolboxView::GlobalReinit() { // get all nodes that have not set "includeInBoundingBox" to false mitk::NodePredicateNot::Pointer pred = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox", mitk::BoolProperty::New(false))); mitk::DataStorage::SetOfObjects::ConstPointer rs = this->GetDataStorage()->GetSubset(pred); // calculate bounding geometry of these nodes mitk::TimeSlicedGeometry::Pointer bounds = this->GetDataStorage()->ComputeBoundingGeometry3D(rs, "visible"); // initialize the views to the bounding geometry mitk::RenderingManager::GetInstance()->InitializeViews(bounds); } void QmitkMITKIGTTrackingToolboxView::DisableLoggingButtons() { m_Controls->m_StartLogging->setEnabled(false); m_Controls->m_LoggingFileName->setEnabled(false); m_Controls->m_ChooseFile->setEnabled(false); m_Controls->m_LoggingLimit->setEnabled(false); m_Controls->m_LoggedFramesLimit->setEnabled(false); m_Controls->m_csvFormat->setEnabled(false); m_Controls->m_xmlFormat->setEnabled(false); m_Controls->m_StopLogging->setEnabled(true); } void QmitkMITKIGTTrackingToolboxView::EnableLoggingButtons() { m_Controls->m_StartLogging->setEnabled(true); m_Controls->m_LoggingFileName->setEnabled(true); m_Controls->m_ChooseFile->setEnabled(true); m_Controls->m_LoggingLimit->setEnabled(true); m_Controls->m_LoggedFramesLimit->setEnabled(true); m_Controls->m_csvFormat->setEnabled(true); m_Controls->m_xmlFormat->setEnabled(true); m_Controls->m_StopLogging->setEnabled(false); } void QmitkMITKIGTTrackingToolboxView::DisableOptionsButtons() { m_Controls->m_ShowTrackingVolume->setEnabled(false); m_Controls->m_UpdateRate->setEnabled(false); m_Controls->m_ShowToolQuaternions->setEnabled(false); m_Controls->m_OptionsUpdateRateLabel->setEnabled(false); } void QmitkMITKIGTTrackingToolboxView::EnableOptionsButtons() { m_Controls->m_ShowTrackingVolume->setEnabled(true); m_Controls->m_UpdateRate->setEnabled(true); m_Controls->m_ShowToolQuaternions->setEnabled(true); m_Controls->m_OptionsUpdateRateLabel->setEnabled(true); } void QmitkMITKIGTTrackingToolboxView::EnableTrackingConfigurationButtons() { m_Controls->m_AutoDetectTools->setEnabled(true); if (m_Controls->m_configurationWidget->GetTrackingDevice()->GetType() != mitk::NDIAurora) m_Controls->m_AddSingleTool->setEnabled(true); m_Controls->m_LoadTools->setEnabled(true); m_Controls->m_ResetTools->setEnabled(true); } void QmitkMITKIGTTrackingToolboxView::DisableTrackingConfigurationButtons() { m_Controls->m_AutoDetectTools->setEnabled(false); if (m_Controls->m_configurationWidget->GetTrackingDevice()->GetType() != mitk::NDIAurora) m_Controls->m_AddSingleTool->setEnabled(false); m_Controls->m_LoadTools->setEnabled(false); m_Controls->m_ResetTools->setEnabled(false); } diff --git a/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxView.h b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxView.h index e082d4029c..90432663b2 100644 --- a/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxView.h +++ b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxView.h @@ -1,161 +1,167 @@ /*=================================================================== 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 QmitkMITKIGTTrackingToolboxView_h #define QmitkMITKIGTTrackingToolboxView_h #include #include #include "ui_QmitkMITKIGTTrackingToolboxViewControls.h" //mitk headers #include #include #include #include //QT headers #include /*! \brief QmitkMITKIGTTrackingToolboxView This is the view of the bundle IGT Tracking Toolbox. The IGT Tracking Toolbox can be used to access tracking devices with MITK-IGT. The Tracking Toolbox can be used to log tracking data in XML or CSV format for measurement purposes. The Tracking Toolbox further allows for visualization of tools with given surfaces in combination with the NaviagtionToolManager. \sa QmitkFunctionality \ingroup Functionalities */ class QmitkMITKIGTTrackingToolboxView : public QmitkFunctionality { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: static const std::string VIEW_ID; QmitkMITKIGTTrackingToolboxView(); QmitkMITKIGTTrackingToolboxView(const QmitkMITKIGTTrackingToolboxView& other) { Q_UNUSED(other) throw std::runtime_error("Copy constructor not implemented"); } virtual ~QmitkMITKIGTTrackingToolboxView(); virtual void CreateQtPartControl(QWidget *parent); virtual void StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget); virtual void StdMultiWidgetNotAvailable(); protected slots: /** @brief This slot is called if the user wants to load a new tool file. A new window opens where the user can choose a file. If the chosen file is corrupt or not valid the user gets an error message. If the file was loaded successfully the tools are show in the tool status widget. */ void OnLoadTools(); + /** @brief This slot connects to the device. In status "connected" configuration of the device is disabled. */ + void OnConnect(); + + /** @brief This slot disconnects from the device. */ + void OnDisconnect(); + /** @brief This slot tries to start tracking with the current device. If start tracking fails the user gets an error message and tracking stays off.*/ void OnStartTracking(); /** @brief This slot stops tracking. If tracking is not strated it does nothing.*/ void OnStopTracking(); /** @brief This slot is called if the user want's to choose a file name for logging. A new windows to navigate through the file system and choose a file opens.*/ void OnChooseFileClicked(); /** @brief This slot starts logging. Logging is only possible if a device is tracking. If not the logging mechanism start when the start tracking is called.*/ void StartLogging(); /** @brief This slot stops logging. If logging is not running it does nothing.*/ void StopLogging(); /** @brief This slot enables / disables UI elements depending on the tracking device after a device is changed.*/ void OnTrackingDeviceChanged(); /** @brief This slot selects the Tracking Volume appropriate for a given model */ void OnTrackingVolumeChanged(QString qstr); /** @brief Shows or hides the tracking volume according to the checkboxe's state */ void OnShowTrackingVolumeChanged(); /** @brief This slot auto detects tools of a NDI Aurora tracking device. If tools where found they will be stored internally as a tool storage. The user is also asked if he wants to save this tool storage to load it later. Only call it if a Aurora device was configured because other devices don't support auto detection.*/ void OnAutoDetectTools(); /** @brief Slot for tracking timer. The timer updates the IGT pipline and also the logging filter if logging is activated.*/ void UpdateTrackingTimer(); /** @brief Resets the Tracking Tools: this means all tools are removed. */ void OnResetTools(); /** @brief Opens a dialog where a new navigation tool can be created. */ void OnAddSingleTool(); /** @brief This slot is called if the user finishes the creation of a new tool. */ void OnAddSingleToolFinished(); /** @brief This slot is called if the user cancels the creation of a new tool. */ void OnAddSingleToolCanceled(); protected: Ui::QmitkMITKIGTTrackingToolboxViewControls* m_Controls; QmitkStdMultiWidget* m_MultiWidget; bool m_tracking; ///> bool which is true if tracking is running, false if not bool m_logging; ///> bool which is true if logging is running, false if not int m_loggedFrames; ///> stores the current number of logged frames if logging is on mitk::NavigationToolStorage::Pointer m_toolStorage; ///>stores the loaded tools mitk::DataNode::Pointer m_TrackingVolumeNode; ///>holds the data node of the tracking volume if volume is visualized /** @brief Shows a message box with the text given as parameter. */ void MessageBox(std::string s); /** @brief reinits the view globally. */ void GlobalReinit(); //members for the filter pipeline mitk::TrackingDeviceSource::Pointer m_TrackingDeviceSource; ///> member for the source of the IGT pipeline mitk::NavigationDataObjectVisualizationFilter::Pointer m_ToolVisualizationFilter; ///> holds the tool visualization filter (second filter of the IGT pipeline) mitk::NavigationDataRecorder::Pointer m_loggingFilter; ///> holds the logging filter if logging is on (third filter of the IGT pipeline) /** @brief This timer updates the IGT pipline and also the logging filter if logging is activated.*/ QTimer* m_TrackingTimer; //help methods for enable/disable buttons void DisableLoggingButtons(); void EnableLoggingButtons(); void DisableOptionsButtons(); void EnableOptionsButtons(); void EnableTrackingConfigurationButtons(); void DisableTrackingConfigurationButtons(); }; #endif // _QMITKMITKIGTTRACKINGTOOLBOXVIEW_H_INCLUDED diff --git a/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxViewControls.ui b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxViewControls.ui index eeb8f20179..4e728a5482 100644 --- a/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxViewControls.ui +++ b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxViewControls.ui @@ -1,630 +1,690 @@ QmitkMITKIGTTrackingToolboxViewControls 0 0 - 377 - 849 + 428 + 1001 0 0 QmitkTemplate 0 Tracking 0 0 0 300 16777215 280 0 0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:600;">Tracking Tools</span></p></body></html> 0 0 Loaded Tools: <none> Qt::Horizontal 40 20 Auto Detection 200 150 Qt::Horizontal 40 20 - 110 + 120 0 Add Single Tool Qt::Horizontal 40 20 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> <p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt; font-style:italic;">(only load tool storage files created </span></p> <p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt; font-style:italic;">with </span><span style=" font-size:8pt; font-style:italic;">the &quot;NavigationToolManager&quot;)</span></p></body></html> Qt::AlignJustify|Qt::AlignVCenter - 110 + 120 0 Load Tool Storage Qt::Horizontal 40 20 - 110 + 120 0 Reset <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:600;">Tracking Control</span></p></body></html> Status: <not configured> + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 120 + 0 + + + + Connect + + + + + Qt::Horizontal 40 20 - 110 + 120 0 Start Tracking Qt::Horizontal 40 20 - 110 + 120 0 Stop Tracking + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 120 + 0 + + + + Disconnect + + + + + Qt::Vertical 20 40 Options true Show Tracking Volume true Select Model: Qt::Horizontal Update Rate (Times Per Second) Qt::Horizontal 40 20 999 10 Show Tool Quaternions Qt::Vertical 20 597 Logging Filename: C:/logfile.csv Choose File Limit Number Of Logged Frames: Qt::Horizontal 40 20 1 9999 300 CSV format true XML format Logging Status Logging OFF Logged Frames: 0 Qt::Horizontal 40 20 Start Logging Stop Logging Qt::Vertical 20 40 QmitkTrackingDeviceConfigurationWidget QWidget
QmitkTrackingDeviceConfigurationWidget.h
1
QmitkToolTrackingStatusWidget QWidget
QmitkToolTrackingStatusWidget.h
1
QmitkNavigationToolCreationWidget QWidget
QmitkNavigationToolCreationWidget.h
1