diff --git a/Modules/IGT/IGTFilters/mitkNavigationDataTransformFilter.cpp b/Modules/IGT/IGTFilters/mitkNavigationDataTransformFilter.cpp index 1208c76c43..6e73df1ada 100644 --- a/Modules/IGT/IGTFilters/mitkNavigationDataTransformFilter.cpp +++ b/Modules/IGT/IGTFilters/mitkNavigationDataTransformFilter.cpp @@ -1,108 +1,106 @@ /*=================================================================== 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 "mitkNavigationDataTransformFilter.h" mitk::NavigationDataTransformFilter::NavigationDataTransformFilter() : mitk::NavigationDataToNavigationDataFilter() { m_Transform = NULL; //transform to rotate orientation m_QuatOrgRigidTransform = itk::QuaternionRigidTransform::New(); m_QuatTmpTransform = itk::QuaternionRigidTransform::New(); } mitk::NavigationDataTransformFilter::~NavigationDataTransformFilter() { m_Transform = NULL; } void mitk::NavigationDataTransformFilter::SetRigid3DTransform( TransformType::Pointer transform ) { m_Transform = transform; this->Modified(); } void mitk::NavigationDataTransformFilter::GenerateData() { // only update data if m_Transform was set if(m_Transform.IsNull()) { itkExceptionMacro("Invalid parameter: Transform was not set! Use SetRigid3DTransform() before updating the filter."); return; } else { this->CreateOutputsForAllInputs(); // make sure that we have the same number of outputs as inputs /* update outputs with tracking data from tools */ for (unsigned int i = 0; i < this->GetNumberOfIndexedOutputs() ; ++i) { mitk::NavigationData* output = this->GetOutput(i); assert(output); const mitk::NavigationData* input = this->GetInput(i); assert(input); if (input->IsDataValid() == false) { output->SetDataValid(false); continue; } mitk::NavigationData::PositionType tempCoordinateIn, tempCoordinateOut; tempCoordinateIn = input->GetPosition(); itk::Point itkPointIn, itkPointOut; itkPointIn[0] = tempCoordinateIn[0]; itkPointIn[1] = tempCoordinateIn[1]; itkPointIn[2] = tempCoordinateIn[2]; //do the transform itkPointOut = m_Transform->TransformPoint( itkPointIn ); tempCoordinateOut[0] = itkPointOut[0]; tempCoordinateOut[1] = itkPointOut[1]; tempCoordinateOut[2] = itkPointOut[2]; output->Graft(input); // First, copy all information from input to output output->SetPosition(tempCoordinateOut);// Then change the member(s): add new position of navigation data after tranformation output->SetDataValid(true); // operation was successful, therefore data of output is valid. //---transform orientation NavigationData::OrientationType quatIn = input->GetOrientation(); vnl_quaternion const vnlQuatIn(quatIn.x(), quatIn.y(), quatIn.z(), quatIn.r()); TransformType::MatrixType rotMatrixD = m_Transform->GetMatrix(); - vnl_quaternion vnlQ = vnl_quaternion(rotMatrixD.GetVnlMatrix()); - - m_QuatOrgRigidTransform->SetRotation(vnlQ); + m_QuatOrgRigidTransform->SetMatrix(rotMatrixD);//SetRotation(vnlQ); m_QuatTmpTransform->SetRotation(vnlQuatIn); m_QuatTmpTransform->Compose(m_QuatOrgRigidTransform,false); vnl_quaternion vnlQuatOut = m_QuatTmpTransform->GetRotation(); NavigationData::OrientationType quatOut(vnlQuatOut[0], vnlQuatOut[1], vnlQuatOut[2], vnlQuatOut[3]); output->SetOrientation(quatOut); } } } diff --git a/Modules/IGT/Testing/files.cmake b/Modules/IGT/Testing/files.cmake index 3d770dcc0f..4fccf20a75 100644 --- a/Modules/IGT/Testing/files.cmake +++ b/Modules/IGT/Testing/files.cmake @@ -1,49 +1,49 @@ 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 mitkNavigationDataSourceTest.cpp mitkNavigationDataToMessageFilterTest.cpp mitkNavigationDataToNavigationDataFilterTest.cpp mitkNavigationDataToPointSetFilterTest.cpp - # mitkNavigationDataTransformFilterTest.cpp commented out because of bug 15023 + mitkNavigationDataTransformFilterTest.cpp mitkNDIPassiveToolTest.cpp mitkNDIProtocolTest.cpp mitkNDITrackingDeviceTest.cpp mitkTimeStampTest.cpp mitkTrackingVolumeGeneratorTest.cpp mitkTrackingDeviceTest.cpp mitkTrackingToolTest.cpp mitkVirtualTrackingDeviceTest.cpp mitkNavigationDataPlayerTest.cpp # see bug 11636 (extend this test by microservices) mitkTrackingDeviceSourceTest.cpp mitkTrackingDeviceSourceConfiguratorTest.cpp mitkNavigationDataEvaluationFilterTest.cpp mitkTrackingTypesTest.cpp # ------------------ Navigation Tool Management Tests ------------------- mitkNavigationToolStorageTest.cpp mitkNavigationToolStorageSerializerAndDeserializerTest.cpp mitkNavigationToolTest.cpp mitkNavigationToolReaderAndWriterTest.cpp # ----------------------------------------------------------------------- # ------------------ Deavtivated Tests ---------------------------------- # ----------------------------------------------------------------------- ) set(MODULE_CUSTOM_TESTS mitkNDIAuroraHardwareTest.cpp mitkNDIPolarisHardwareTest.cpp mitkClaronTrackingDeviceHardwareTest.cpp ) diff --git a/Modules/IGT/Testing/mitkNavigationDataTransformFilterTest.cpp b/Modules/IGT/Testing/mitkNavigationDataTransformFilterTest.cpp index 38d8152b88..4201cbd8cf 100644 --- a/Modules/IGT/Testing/mitkNavigationDataTransformFilterTest.cpp +++ b/Modules/IGT/Testing/mitkNavigationDataTransformFilterTest.cpp @@ -1,223 +1,223 @@ /*=================================================================== 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 "mitkNavigationDataTransformFilter.h" #include "mitkNavigationData.h" #include "mitkTestingMacros.h" #include #include #include /**Documentation * test for the class "NavigationDataTransformFilter". */ typedef itk::VersorRigid3DTransform TransformType; typedef itk::Vector VectorType; int mitkNavigationDataTransformFilterTest(int /* argc */, char* /*argv*/[]) { MITK_TEST_BEGIN("NavigationDataTransformFilter") // let's create an object of our class mitk::NavigationDataTransformFilter::Pointer myFilter = mitk::NavigationDataTransformFilter::New(); // first test: did this work? // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since // it makes no sense to continue without an object. MITK_TEST_CONDITION_REQUIRED(myFilter.IsNotNull(),"Testing instantiation"); /* create helper objects: navigation data with position as origin, zero quaternion, zero error and data valid */ mitk::NavigationData::PositionType initialPos, resultPos; mitk::FillVector3D(initialPos, 1.1, 2.2, 3.3); mitk::FillVector3D(resultPos, 5.0, 5.0,5.0); mitk::NavigationData::OrientationType initialOri(0.0, 0.0, -0.7071, 0.7071); mitk::ScalarType initialError(0.0); bool initialValid(true); mitk::NavigationData::Pointer nd1 = mitk::NavigationData::New(); nd1->SetPosition(initialPos); nd1->SetOrientation(initialOri); nd1->SetPositionAccuracy(initialError); nd1->SetDataValid(initialValid); myFilter->SetInput(nd1); MITK_TEST_CONDITION(myFilter->GetInput() == nd1, "Testing Set-/GetInput()"); mitk::NavigationData* output = myFilter->GetOutput(); /*test case no transform set*/ MITK_TEST_FOR_EXCEPTION(std::exception, output->Update();); /* test transformation */ mitk::NavigationDataTransformFilter::TransformType::Pointer transform = mitk::NavigationDataTransformFilter::TransformType::New(); VectorType translationVector; translationVector[0] = 3.9; translationVector[1] = 2.8; translationVector[2] = 1.7; /* test translation */ - transform->TransformVector(translationVector); + transform->Translate(translationVector); myFilter->SetRigid3DTransform(transform); output = myFilter->GetOutput(); MITK_TEST_CONDITION_REQUIRED(output != NULL, "Testing GetOutput()"); output->Update(); // execute filter MITK_TEST_CONDITION(output->GetPosition() == resultPos, "Testing if translation was calculated correct"); MITK_TEST_CONDITION( mitk::Equal(output->GetOrientation(),initialOri),"Testing if Orientation remains unchanged "); MITK_TEST_CONDITION(output->IsDataValid() == initialValid, "Testing if DataValid remains unchanged"); // test rotation mitk::NavigationDataTransformFilter::Pointer myFilter2 = mitk::NavigationDataTransformFilter::New(); // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since // it makes no sense to continue without an object. MITK_TEST_CONDITION_REQUIRED(myFilter2.IsNotNull(),"Testing instantiation"); mitk::FillVector3D(initialPos, 1.1, 1.1, 1.1); mitk::FillVector3D(resultPos, 1.1, -1.1, 1.1); mitk::NavigationData::OrientationType resultOri(0.0, 0.0, -0.7071, 0.7071); initialOri[0] = 0; initialOri[1] = 0; initialOri[2] = 0; initialOri[3] = 1; nd1->SetPosition(initialPos); nd1->SetOrientation(initialOri); myFilter2->SetInput(nd1); mitk::NavigationDataTransformFilter::TransformType::MatrixType rotMatrix; rotMatrix[0][0] = 0; rotMatrix[0][1] = 1; rotMatrix[0][2] = 0; rotMatrix[1][0] = -1; rotMatrix[1][1] = 0; rotMatrix[1][2] = 0; rotMatrix[2][0] = 0; rotMatrix[2][1] = 0; rotMatrix[2][2] = 1; mitk::NavigationDataTransformFilter::TransformType::Pointer transform2 = mitk::NavigationDataTransformFilter::TransformType::New(); transform2->SetMatrix(rotMatrix); myFilter2->SetRigid3DTransform(transform2); mitk::NavigationData* output2 = myFilter2->GetOutput(); MITK_TEST_CONDITION_REQUIRED(output2 != NULL, "Testing GetOutput()"); output2->Update(); // execute filter MITK_TEST_CONDITION(output2->GetPosition() == resultPos, "Testing if position after rotation is correctly calculated"); MITK_TEST_CONDITION( mitk::Equal(output2->GetOrientation(), resultOri),"Testing if orientation after rotation is correctly caclculated "); MITK_TEST_CONDITION(output2->IsDataValid() == initialValid, "Testing if DataValid remains unchanged"); // test obscure rotation angle vs. ITK precision requirements itk::QuaternionRigidTransform::VnlQuaternionType obscureRotationQuat(37,29,71); obscureRotationQuat.normalize(); // Just to demonstrate that even normalizing doesn't help itk::QuaternionRigidTransform::Pointer rotation = itk::QuaternionRigidTransform::New(); rotation->SetRotation(obscureRotationQuat); mitk::NavigationDataTransformFilter::TransformType::Pointer transform3 = mitk::NavigationDataTransformFilter::TransformType::New(); // For lack of an MITK Test macro that tests for *no* exception try { MITK_TEST_OUTPUT_NO_ENDL(<< "Testing whether NavigationDataTransformFilter's internal transform has sufficient precision for ITK ") transform3->SetMatrix(rotation->GetMatrix()); MITK_TEST_OUTPUT(<< " [PASSED]") mitk::TestManager::GetInstance()->TestPassed(); } catch(std::exception&) { MITK_TEST_OUTPUT(<< " [FAILED]") mitk::TestManager::GetInstance()->TestFailed(); } //----------------------------------------------------------------------------------------------------------- /* now test the filter with multiple inputs */ mitk::NavigationData::PositionType initialPos2, resultPos2; mitk::FillVector3D(initialPos, 1.1, 2.2, 3.3); mitk::FillVector3D(initialPos2, -1000.0, 567.89, 0.0); mitk::FillVector3D(resultPos, 2.2,-1.1, 3.3); mitk::FillVector3D(resultPos2, 567.89, 1000, 0.0); mitk::NavigationData::OrientationType initialOri2(0.5,0.5,0.5,0.5); mitk::NavigationData::OrientationType resultOri2(0.7071,0.0,0.0,0.7071); mitk::NavigationData::Pointer nd2 = mitk::NavigationData::New(); nd1->SetPosition(initialPos); nd1->SetOrientation(initialOri); nd1->SetPositionAccuracy(initialError); nd1->SetDataValid(initialValid); nd2->SetPosition(initialPos2); nd2->SetOrientation(initialOri2); nd2->SetPositionAccuracy(initialError); nd2->SetDataValid(initialValid); myFilter = NULL; myFilter = mitk::NavigationDataTransformFilter::New(); myFilter->SetRigid3DTransform(transform2); myFilter->SetInput(0, nd1); myFilter->SetInput(1, nd2); MITK_TEST_CONDITION(((myFilter->GetInput(0) == nd1) && (myFilter->GetInput(1) == nd2)), "Testing Set-/GetInput(index, data)"); output = NULL; output2 = NULL; output = myFilter->GetOutput(); output2 = myFilter->GetOutput(1); output2->Update(); // execute filter pipeline. this should update both outputs! MITK_TEST_CONDITION_REQUIRED(((output != NULL) && (output2 != NULL)), "Testing GetOutput(index)"); MITK_TEST_CONDITION(output->GetPosition() == resultPos, "Testing if position rotation was calculated correct [output 0]"); MITK_TEST_CONDITION(mitk::Equal(output->GetOrientation(), resultOri),"Testing if orientation rotation was calculated correct [output 0]"); MITK_TEST_CONDITION(output->IsDataValid() == initialValid, "Testing if DataValid remains unchanged for output 0"); MITK_TEST_CONDITION(output2->GetPosition() == resultPos2, "Testing if rotation was calculated correct [output 1]"); MITK_TEST_CONDITION(mitk::Equal(output2->GetOrientation(), resultOri2),"Testing if orientation rotation was calculated correct [output 1]"); MITK_TEST_CONDITION(output2->IsDataValid() == initialValid, "Testing if DataValid remains unchanged for output 1"); // // /* test if anything changes on second ->Update() */ output->Update(); // nothing should change, since inputs remain unchanged MITK_TEST_CONDITION((output->GetPosition() == (resultPos)) && (output2->GetPosition() == (resultPos2)), "Testing translation calculation after second update()"); /* change an input, see if output changes too */ mitk::NavigationData::PositionType pos3, resultPos3; mitk::FillVector3D(pos3, 123.456, -234.567, 789.987); mitk::FillVector3D(resultPos3, -234.567, -123.456, 789.987); nd1->SetPosition(pos3); // nd1 is modified, but nothing should change until pipe gets updated MITK_TEST_CONDITION((output->GetPosition() == (resultPos)) &&(output2->GetPosition() == (resultPos2)), "Testing transfomr calculation after input change, before update()"); output->Update(); // update pipeline. should recalculate positions, because input has changed MITK_TEST_CONDITION((output->GetPosition() == (resultPos3)) && (output2->GetPosition() == (resultPos2)), "Testing transform calculation after input change, after update()"); // always end with this! MITK_TEST_END(); }