diff --git a/Modules/IGT/IGTFilters/mitkTrackingDeviceSourceConfigurator.cpp b/Modules/IGT/IGTFilters/mitkTrackingDeviceSourceConfigurator.cpp index 09a95e7426..bf43af8333 100644 --- a/Modules/IGT/IGTFilters/mitkTrackingDeviceSourceConfigurator.cpp +++ b/Modules/IGT/IGTFilters/mitkTrackingDeviceSourceConfigurator.cpp @@ -1,247 +1,250 @@ /*========================================================================= 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) { //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++) +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)); //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/Testing/files.cmake b/Modules/IGT/Testing/files.cmake index 5495c8a60c..25f0f80f39 100644 --- a/Modules/IGT/Testing/files.cmake +++ b/Modules/IGT/Testing/files.cmake @@ -1,45 +1,46 @@ SET(MODULE_TESTS mitkCameraVisualizationTest.cpp mitkClaronInterfaceTest.cpp mitkClaronToolTest.cpp mitkClaronTrackingDeviceTest.cpp mitkInternalTrackingToolTest.cpp mitkNavigationDataDisplacementFilterTest.cpp mitkNavigationDataLandmarkTransformFilterTest.cpp mitkNavigationDataObjectVisualizationFilterTest.cpp mitkNavigationDataTest.cpp mitkNavigationDataRecorderTest.cpp mitkNavigationDataReferenceTransformFilterTest.cpp mitkNavigationDataSequentialPlayerTest.cpp mitkNavigationDataToMessageFilterTest.cpp mitkNavigationDataToNavigationDataFilterTest.cpp mitkNavigationDataToPointSetFilterTest.cpp mitkNavigationDataTransformFilterTest.cpp mitkNDIPassiveToolTest.cpp mitkNDIProtocolTest.cpp mitkNDITrackingDeviceTest.cpp mitkTimeStampTest.cpp mitkTrackingVolumeGeneratorTest.cpp mitkTrackingDeviceTest.cpp mitkTrackingToolTest.cpp mitkVirtualTrackingDeviceTest.cpp mitkNavigationDataPlayerTest.cpp mitkTrackingDeviceSourceTest.cpp + mitkTrackingDeviceSourceConfiguratorTest.cpp # ------------------ Navigation Tool Management Tests ------------------- mitkNavigationToolStorageTest.cpp mitkNavigationToolStorageSerializerAndDeserializerTest.cpp mitkNavigationToolTest.cpp mitkNavigationToolReaderAndWriterTest.cpp #deactivated, see bug #3461 # ----------------------------------------------------------------------- # ------------------ Deavtivated Tests ---------------------------------- - + # ----------------------------------------------------------------------- ) SET(MODULE_CUSTOM_TESTS mitkNDIAuroraHardwareTest.cpp mitkNDIPolarisHardwareTest.cpp mitkClaronTrackingDeviceHardwareTest.cpp ) \ No newline at end of file diff --git a/Modules/IGT/Testing/mitkTrackingDeviceSourceConfiguratorTest.cpp b/Modules/IGT/Testing/mitkTrackingDeviceSourceConfiguratorTest.cpp new file mode 100644 index 0000000000..29e3fc56c2 --- /dev/null +++ b/Modules/IGT/Testing/mitkTrackingDeviceSourceConfiguratorTest.cpp @@ -0,0 +1,187 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2008-02-25 17:27:17 +0100 (Mo, 25 Feb 2008) $ +Version: $Revision: 7837 $ + +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 +#include +#include +#include +#include + +class mitkTrackingDeviceSourceConfiguratorTestClass +{ +public: + + static void TestInstantiation() + { + // let's create an object of our class + mitk::TrackingDeviceSourceConfigurator::Pointer testInstance; + mitk::NavigationToolStorage::Pointer emptyStorage = mitk::NavigationToolStorage::New(); + mitk::TrackingDevice::Pointer dummyDevice = mitk::ClaronTrackingDevice::New(); + testInstance = mitk::TrackingDeviceSourceConfigurator::New(emptyStorage,dummyDevice); + MITK_TEST_CONDITION_REQUIRED(testInstance.IsNotNull(),"Testing instantiation:"); + } + + static void TestInvalidClaronTrackingDevice() + { + MITK_TEST_OUTPUT(<<"Testing simple claron tracking device with 2 invalid tools"); + + mitk::TrackingDeviceSourceConfigurator::Pointer testInstance; + + mitk::NavigationToolStorage::Pointer claronStorage = mitk::NavigationToolStorage::New(); + + //create invalid tool 1 + mitk::NavigationTool::Pointer firstTool = mitk::NavigationTool::New(); + firstTool->SetTrackingDeviceType(mitk::ClaronMicron); + mitk::DataNode::Pointer firstNode = mitk::DataNode::New(); + firstNode->SetName("Tool1"); + firstTool->SetDataNode(firstNode); + claronStorage->AddTool(firstTool); + + //create invalid tool 2 + mitk::NavigationTool::Pointer secondTool = mitk::NavigationTool::New(); + secondTool->SetTrackingDeviceType(mitk::ClaronMicron); + mitk::DataNode::Pointer secondNode = mitk::DataNode::New(); + secondNode->SetName("Tool2"); + secondTool->SetDataNode(secondNode); + claronStorage->AddTool(secondTool); + + mitk::TrackingDevice::Pointer testDevice = mitk::ClaronTrackingDevice::New(); + + testInstance = mitk::TrackingDeviceSourceConfigurator::New(claronStorage,testDevice); + + mitk::TrackingDeviceSource::Pointer testSource = testInstance->CreateTrackingDeviceSource(); + + MITK_TEST_CONDITION_REQUIRED(testSource.IsNull(),"..testing return value"); + MITK_TEST_CONDITION_REQUIRED(testInstance->GetErrorMessage().size()>1,"..testing if there is an error message"); + + MITK_TEST_OUTPUT(<<"Testing simple claron tracking device with another 2 invalid tools"); + + secondTool->SetTrackingDeviceType(mitk::NDIAurora); + claronStorage = mitk::NavigationToolStorage::New(); + claronStorage->AddTool(secondTool); + + testInstance = mitk::TrackingDeviceSourceConfigurator::New(claronStorage,testDevice); + + MITK_TEST_CONDITION_REQUIRED(!testInstance->IsCreateTrackingDeviceSourcePossible(),"..testing if factory class detects the invalid data"); + + testSource = testInstance->CreateTrackingDeviceSource(); + + MITK_TEST_CONDITION_REQUIRED(testSource.IsNull(),"..testing return value"); + MITK_TEST_CONDITION_REQUIRED(testInstance->GetErrorMessage().size()>1,"..testing if there is an error message"); + MITK_TEST_CONDITION_REQUIRED(testInstance->GetUpdatedNavigationToolStorage()->GetToolCount()==1,"..testing if navigation tool storage is still there"); + + MITK_TEST_OUTPUT(<<"Testing other invalid test cases"); + testInstance = mitk::TrackingDeviceSourceConfigurator::New(claronStorage,NULL); + MITK_TEST_CONDITION_REQUIRED(!testInstance->IsCreateTrackingDeviceSourcePossible(),"..(1) testing if factory class detects the invalid data"); + testInstance = mitk::TrackingDeviceSourceConfigurator::New(NULL,testDevice); + MITK_TEST_CONDITION_REQUIRED(!testInstance->IsCreateTrackingDeviceSourcePossible(),"..(2) testing if factory class detects the invalid data"); + + + + + } + static void TestValidClaronTrackingDevice() + { + MITK_TEST_OUTPUT(<<"Testing simple claron tracking device with 2 valid tools"); + + std::string toolFileName = mitk::StandardFileLocations::GetInstance()->FindFile("ClaronTool", "Modules/IGT/Testing/Data"); + MITK_TEST_CONDITION(toolFileName.empty() == false, "Check if tool calibration of claron tool file exists"); + + mitk::TrackingDeviceSourceConfigurator::Pointer testInstance; + + mitk::NavigationToolStorage::Pointer claronStorage = mitk::NavigationToolStorage::New(); + + //create valid tool 1 + mitk::NavigationTool::Pointer firstTool = mitk::NavigationTool::New(); + firstTool->SetTrackingDeviceType(mitk::ClaronMicron); + mitk::DataNode::Pointer firstNode = mitk::DataNode::New(); + firstNode->SetName("Tool1"); + firstTool->SetDataNode(firstNode); + firstTool->SetCalibrationFile(toolFileName); + firstTool->SetIdentifier("Tool#1"); + claronStorage->AddTool(firstTool); + + //create valid tool 2 + mitk::NavigationTool::Pointer secondTool = mitk::NavigationTool::New(); + secondTool->SetTrackingDeviceType(mitk::ClaronMicron); + mitk::DataNode::Pointer secondNode = mitk::DataNode::New(); + secondNode->SetName("Tool2"); + secondTool->SetDataNode(secondNode); + secondTool->SetCalibrationFile(toolFileName); + secondTool->SetIdentifier("Tool#2"); + claronStorage->AddTool(secondTool); + + mitk::TrackingDevice::Pointer testDevice = mitk::ClaronTrackingDevice::New(); + + testInstance = mitk::TrackingDeviceSourceConfigurator::New(claronStorage,testDevice); + + mitk::TrackingDeviceSource::Pointer testSource = testInstance->CreateTrackingDeviceSource(); + + MITK_TEST_CONDITION_REQUIRED(testSource->GetNumberOfOutputs()==2,"testing number of outputs"); + MITK_TEST_CONDITION_REQUIRED(testSource->GetTrackingDevice()->GetToolCount()==2,"testing tracking device"); + } + + static void TestNDIAuroraTrackingDevice() + { + + } + + static void TestNDIPolarisTrackingDevice() + { + MITK_TEST_OUTPUT(<<"Testing simple NDI Polaris tracking device with 1 valid tool"); + + std::string toolFileName = mitk::StandardFileLocations::GetInstance()->FindFile("SROMFile.rom", "Modules/IGT/Testing/Data"); + MITK_TEST_CONDITION(toolFileName.empty() == false, "..check if tool calibration of claron tool file exists"); + + mitk::TrackingDeviceSourceConfigurator::Pointer testInstance; + + mitk::NavigationToolStorage::Pointer polarisStorage = mitk::NavigationToolStorage::New(); + + //create valid tool 1 + mitk::NavigationTool::Pointer firstTool = mitk::NavigationTool::New(); + firstTool->SetTrackingDeviceType(mitk::NDIPolaris); + mitk::DataNode::Pointer firstNode = mitk::DataNode::New(); + firstNode->SetName("Tool1"); + firstTool->SetDataNode(firstNode); + firstTool->SetCalibrationFile(toolFileName); + firstTool->SetIdentifier("Tool#1"); + polarisStorage->AddTool(firstTool); + + mitk::NDITrackingDevice::Pointer ndiDevice = mitk::NDITrackingDevice::New(); + ndiDevice->SetType(mitk::NDIPolaris); + mitk::TrackingDevice::Pointer testDevice = dynamic_cast(ndiDevice.GetPointer()); + + testInstance = mitk::TrackingDeviceSourceConfigurator::New(polarisStorage,testDevice); + + mitk::TrackingDeviceSource::Pointer testSource = testInstance->CreateTrackingDeviceSource(); + + MITK_TEST_CONDITION_REQUIRED(testSource->GetNumberOfOutputs()==1,"..testing number of outputs"); + MITK_TEST_CONDITION_REQUIRED(testSource->GetTrackingDevice()->GetToolCount()==1,"..testing tracking device"); + } +}; + +int mitkTrackingDeviceSourceConfiguratorTest(int /* argc */, char* /*argv*/[]) +{ + MITK_TEST_BEGIN("TrackingDeviceConfigurator"); + + mitkTrackingDeviceSourceConfiguratorTestClass::TestInstantiation(); + mitkTrackingDeviceSourceConfiguratorTestClass::TestInvalidClaronTrackingDevice(); + mitkTrackingDeviceSourceConfiguratorTestClass::TestValidClaronTrackingDevice(); + + MITK_TEST_END(); +} \ No newline at end of file