MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkNavigationDataSequentialPlayerTest.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
14#include <mitkStandardFileLocations.h>
15#include "mitkTestingMacros.h"
16#include <mitkTestFixture.h>
17#include <mitkIOUtil.h>
18
19#include <iostream>
20#include <sstream>
21
22//foe exceptions
23#include "mitkIGTException.h"
24#include "mitkIGTIOException.h"
25
26class mitkNavigationDataSequentialPlayerTestSuite : public mitk::TestFixture
27{
29 MITK_TEST(TestStandardWorkflow);
32 MITK_TEST(TestDoubleUpdate);
33 CPPUNIT_TEST_SUITE_END();
34
35private:
37 mitk::NavigationDataSet::Pointer NavigationDataSet;
38 mitk::NavigationDataSequentialPlayer::Pointer player;
39
40public:
41
42 void setUp() override{
43 player = mitk::NavigationDataSequentialPlayer::New();
44 std::string file = GetTestDataFilePath("IGT-Data/NavigationDataTestData_2ToolsDouble.xml");
45
46 NavigationDataSet = dynamic_cast<mitk::NavigationDataSet*> (mitk::IOUtil::Load(file)[0].GetPointer());
47 }
48
49 void tearDown() override
50 {
51 }
52
53 bool runLoop()
54 {
55 player->Update();
56 mitk::NavigationData::Pointer nd0;
57 mitk::NavigationData::Pointer nd1;
58 for(unsigned int i=0; i<player->GetNumberOfSnapshots(); ++i)
59 {
60 nd0 = player->GetOutput(0);
61 nd1 = player->GetOutput(1);
62
63 // test some values
64 if(nd0.IsNull() || nd1.IsNull()) return false;
65
66 //Compare data
67 mitk::NavigationData::Pointer ref0 = NavigationDataSet->GetNavigationDataForIndex(i,0);
68 mitk::NavigationData::Pointer ref1 = NavigationDataSet->GetNavigationDataForIndex(i,1);
69 if (!(ref0->GetOrientation().as_vector() == nd0->GetOrientation().as_vector())) {return false;}
70 if (!(ref1->GetOrientation().as_vector() == nd1->GetOrientation().as_vector())) {return false;}
71 if (!(ref0->GetPosition().GetVnlVector() == nd0->GetPosition().GetVnlVector())) {return false;}
72 if (!(ref1->GetPosition().GetVnlVector() == nd1->GetPosition().GetVnlVector())) {return false;}
73
74 // Goto next Snapshot
75 player->GoToNextSnapshot();
76 }
77 return true;
78 }
79
81 {
82 // Set NavigationDatas for player
83 player->SetNavigationDataSet(NavigationDataSet);
84
85 MITK_TEST_CONDITION(player->GetNumberOfSnapshots() == 3,"Testing if player reports correct number of Snapshots");
86 MITK_TEST_CONDITION(player->GetNumberOfIndexedOutputs() == 2,"Testing number of outputs");
87
88 //rest repeat
89 player->SetRepeat(true);
90
91 MITK_TEST_CONDITION(runLoop(),"Testing first run.");
92 MITK_TEST_CONDITION(runLoop(),"Testing second run."); //repeat is on should work a second time
93
94 // now test the go to snapshot function
95 player->GoToSnapshot(2);
96 mitk::NavigationData::Pointer nd1 = player->GetOutput(1);
97 mitk::NavigationData::Pointer ref1 = NavigationDataSet->GetNavigationDataForIndex(2,1);
98 MITK_TEST_CONDITION(ref1->GetPosition().GetVnlVector() == nd1->GetPosition().GetVnlVector(),
99 "Testing GoToSnapshot() [1]");
100
101 //MITK_TEST_OUTPUT( << "Reference:" << ref1->GetPosition().GetVnlVector() << "\tObserved: " << nd1->GetPosition().GetVnlVector());
102
103 player->GoToSnapshot(0);
104 mitk::NavigationData::Pointer nd0 = player->GetOutput();
105 mitk::NavigationData::Pointer ref0 = NavigationDataSet->GetNavigationDataForIndex(0,0);
106 MITK_TEST_CONDITION(ref0->GetOrientation().as_vector() == nd0->GetOrientation().as_vector(),
107 "Testing GoToSnapshot() [2]");
108
109 //MITK_TEST_OUTPUT( << "Reference" << ref0->GetPosition().GetVnlVector() << "\tObserved:" <<nd0->GetOrientation().as_vector() );
110 }
111
113 {
114 player->SetNavigationDataSet(NavigationDataSet);
115 mitk::NavigationData::PositionType nd1 = player->GetOutput(0)->GetPosition();
116 player->SetNavigationDataSet(NavigationDataSet);
117 mitk::NavigationData::PositionType nd2 = player->GetOutput(0)->GetPosition();
118
119 MITK_TEST_CONDITION(nd1 == nd2, "First output must be the same after setting same navigation data again.");
120
121 // setting new NavigationDataSet with different tool count should result in an exception
122 std::string file = GetTestDataFilePath("IGT-Data/NavigationDataTestData.xml");
123 mitk::NavigationDataSet::Pointer dataset = dynamic_cast<mitk::NavigationDataSet*> (mitk::IOUtil::Load(file)[0].GetPointer());
124 MITK_TEST_FOR_EXCEPTION(mitk::IGTException, player->SetNavigationDataSet(dataset));
125 }
126
128 {
129 //testing GoToSnapShot for exception
130 mitk::NavigationDataSequentialPlayer::Pointer myTestPlayer2 = mitk::NavigationDataSequentialPlayer::New();
131 std::string file = GetTestDataFilePath("IGT-Data/NavigationDataTestData_2Tools.xml");
132 mitk::NavigationDataSet::Pointer dataset = dynamic_cast<mitk::NavigationDataSet*> (mitk::IOUtil::Load(file)[0].GetPointer());
133 myTestPlayer2->SetNavigationDataSet(dataset);
134
135 bool exceptionThrown2=false;
136 try
137 {
138 unsigned int invalidSnapshot = 1000;
139 myTestPlayer2->GoToSnapshot(invalidSnapshot);
140 }
141 catch(mitk::IGTException&)
142 {
143 exceptionThrown2=true;
144 }
145 MITK_TEST_CONDITION(exceptionThrown2, "Testing if exception is thrown when GoToSnapShot method is called with an index that doesn't exist.");
146 }
147
149 {
150 //std::string file = GetTestDataFilePath("IGT-Data/NavigationDataTestData_2Tools.xml");
151
152 //mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New();
153 //player->SetNavigationDataSet(reader->Read(file));
154 player->SetNavigationDataSet(NavigationDataSet);
155
156 player->Update();
157 mitk::Quaternion nd1Orientation = player->GetOutput()->GetOrientation();
158
159 player->Update();
160 mitk::Quaternion nd2Orientation = player->GetOutput()->GetOrientation();
161
162 MITK_TEST_CONDITION(nd1Orientation.as_vector() == nd2Orientation.as_vector(), "Output must be the same no matter if Update() was called between.");
163
164 MITK_TEST_CONDITION(player->GoToNextSnapshot(), "There must be a next snapshot available.");
165 player->Update();
166 mitk::Quaternion nd3Orientation = player->GetOutput()->GetOrientation();
167
168 MITK_TEST_CONDITION(nd1Orientation.as_vector() != nd3Orientation.as_vector(), "Output must be different if GoToNextSnapshot() was called between.");
169 }
170};
171MITK_TEST_SUITE_REGISTRATION(mitkNavigationDataSequentialPlayer)
An object of this class represents an exception of the MITK-IGT module.
Data structure which stores streams of mitk::NavigationData for multiple tools.
mitk::Point3D PositionType
Type that holds the position part of the tracking data.