diff --git a/Modules/IGT/IGTFilters/mitkTrackingDeviceSourceConfigurator.cpp b/Modules/IGT/IGTFilters/mitkTrackingDeviceSourceConfigurator.cpp index 1bec50f53e..09a95e7426 100644 --- a/Modules/IGT/IGTFilters/mitkTrackingDeviceSourceConfigurator.cpp +++ b/Modules/IGT/IGTFilters/mitkTrackingDeviceSourceConfigurator.cpp @@ -1,207 +1,247 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2011-01-18 13:22:38 +0100 (Di, 18 Jan 2011) $ Version: $Revision: 28959 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkTrackingDeviceSourceConfigurator.h" #include "mitkNDITrackingDevice.h" #include "mitkClaronTrackingDevice.h" mitk::TrackingDeviceSourceConfigurator::TrackingDeviceSourceConfigurator(mitk::NavigationToolStorage::Pointer NavigationTools, mitk::TrackingDevice::Pointer TrackingDevice) { -m_NavigationTools = NavigationTools; +//make a copy of the navigation tool storage because we will modify the storage +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(); - //thisDevice->StopTracking(); - //thisDevice->CloseConnection(); //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)); //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; + } \ No newline at end of file diff --git a/Modules/IGT/IGTFilters/mitkTrackingDeviceSourceConfigurator.h b/Modules/IGT/IGTFilters/mitkTrackingDeviceSourceConfigurator.h index 523297c53b..371acf2587 100644 --- a/Modules/IGT/IGTFilters/mitkTrackingDeviceSourceConfigurator.h +++ b/Modules/IGT/IGTFilters/mitkTrackingDeviceSourceConfigurator.h @@ -1,84 +1,106 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2011-01-18 13:22:38 +0100 (Di, 18 Jan 2011) $ Version: $Revision: 28959 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKTRACKINGDEVICESOURCECONFIGURATOR_H_HEADER_INCLUDED_ #define MITKTRACKINGDEVICESOURCECONFIGURATOR_H_HEADER_INCLUDED_ #include //itk includes #include //mitk IGT includes #include "mitkTrackingDeviceSource.h" #include "mitkNavigationToolStorage.h" #include "mitkNavigationDataObjectVisualizationFilter.h" namespace mitk { /**Documentation * \brief This class offers a factory method for objects of the class TrackingDeviceSource. It initializes this TrackingDeviceSource with * the given navigation tools and the given tracking device. The factory method also checks if all tools are valid and of the same * type like the TrackingDevice. You can do this check before trying to create the TrackingDeviceSource by calling the method * IsCreateTrackingDeviceSourcePossible(), if it returns false you might want to get the error message by calling the method * GetErrorMessage(). * \ingroup IGT */ class MitkIGT_EXPORT TrackingDeviceSourceConfigurator : public itk::Object { public: mitkClassMacro(TrackingDeviceSourceConfigurator, itk::Object); mitkNewMacro2Param(Self,mitk::NavigationToolStorage::Pointer,mitk::TrackingDevice::Pointer); /** @return Returns if it's possible to create a tracking device source, which means the tools are checked * if they are of the same type like the tracking device, etc. If it returns false you can get * the reason for this by getting the error message. */ bool IsCreateTrackingDeviceSourcePossible(); /** @return Returns a new TrackingDeviceSource. Returns NULL if there was an error on creating the * TrackingDeviceSource. If there was an error it's availiable as error message. */ mitk::TrackingDeviceSource::Pointer CreateTrackingDeviceSource(); /** @return Returns a new TrackingDeviceSource. Returns NULL if there was an error on creating the * TrackingDeviceSource. If there was an error it's availiable as error message. * @param visualizationFilter (return value) returns a visualization filter which is already connected to the tracking device source. * This filter visualises the surfaces which are availiable by the navigation tool storage. */ mitk::TrackingDeviceSource::Pointer CreateTrackingDeviceSource(mitk::NavigationDataObjectVisualizationFilter::Pointer &visualizationFilter); + /** @return Returns the internal number of the corresponding tool in the tool storage of a output navigation data. Returns -1 if there was an error. */ + int GetToolNumberInToolStorage(int outputID); + + /** @return Returns the identifier of the corresponding tool in the tool storage of a output navigation data. Returns an empty string if there was an error.*/ + std::string GetToolIdentifierInToolStorage(int outputID); + + /** @return Returns a vector with all internal numbers of the corresponding tools in the tool storage of all outputs. + * The order is the same like the order of the outputs. Returns an empty vector if there was an error. + */ + std::vector GetToolNumbersInToolStorage(); + + /** @return Returns a vector with all identifier of the corresponding tools in the tool storage of all outputs. + * The order is the same like the order of the outputs. Returns an empty vector if there was an error. + */ + std::vector GetToolIdentifiersInToolStorage(); + + /** @return Returns a modified navigation tool storage which holds the tools currently in use in + * the same order like the output ids of the pipline. + */ + mitk::NavigationToolStorage::Pointer GetUpdatedNavigationToolStorage(); + /** @return Returns the current error message. Returns an empty string if there was no error. */ std::string GetErrorMessage(); protected: TrackingDeviceSourceConfigurator(mitk::NavigationToolStorage::Pointer NavigationTools, mitk::TrackingDevice::Pointer TrackingDevice); virtual ~TrackingDeviceSourceConfigurator(); mitk::NavigationToolStorage::Pointer m_NavigationTools; mitk::TrackingDevice::Pointer m_TrackingDevice; std::string m_ErrorMessage; + std::vector m_ToolCorrespondencesInToolStorage; mitk::TrackingDeviceSource::Pointer CreateNDIPolarisTrackingDeviceSource(mitk::TrackingDevice::Pointer trackingDevice, mitk::NavigationToolStorage::Pointer navigationTools); mitk::TrackingDeviceSource::Pointer CreateNDIAuroraTrackingDeviceSource(mitk::TrackingDevice::Pointer trackingDevice, mitk::NavigationToolStorage::Pointer navigationTools); mitk::TrackingDeviceSource::Pointer CreateMicronTrackerTrackingDeviceSource(mitk::TrackingDevice::Pointer trackingDevice, mitk::NavigationToolStorage::Pointer navigationTools); mitk::NavigationDataObjectVisualizationFilter::Pointer CreateNavigationDataObjectVisualizationFilter(mitk::TrackingDeviceSource::Pointer trackingDeviceSource, mitk::NavigationToolStorage::Pointer navigationTools); }; } // namespace mitk #endif /* MITKTrackingDeviceSource_H_HEADER_INCLUDED_ */ \ No newline at end of file