MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkVirtualTrackingDeviceTest.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
13//Testing
14#include "mitkTestingMacros.h"
15#include "mitkTestFixture.h"
16
17//Std includes
18#include <iomanip>
19
20//MITK includes
23#include "mitkTrackingTool.h"
24
25//ITK includes
26#include "itksys/SystemTools.hxx"
27
28class mitkVirtualTrackingDeviceTestSuite : public mitk::TestFixture
29{
30 CPPUNIT_TEST_SUITE(mitkVirtualTrackingDeviceTestSuite);
31
34 MITK_TEST(StopTracking);
35 MITK_TEST(StartTracking_Ready_True);
37 MITK_TEST(GetToolCount_NoToolAdded);
39 MITK_TEST(GetTool);
47
48
49 CPPUNIT_TEST_SUITE_END();
50
51private:
52
53 mitk::VirtualTrackingDevice::Pointer m_TestTracker;
54
55public:
56
57 void setUp() override
58 {
59 m_TestTracker = mitk::VirtualTrackingDevice::New();
60 }
61
62 void tearDown() override
63 {
64 m_TestTracker->CloseConnection();
65 }
66
68 {
69 CPPUNIT_ASSERT_EQUAL(mitk::TrackingDevice::Setup, m_TestTracker->GetState());
70 }
71
73 {
74 CPPUNIT_ASSERT_EQUAL(false, m_TestTracker->StartTracking());
75 }
76
78 {
79 CPPUNIT_ASSERT(m_TestTracker->StopTracking());
80 }
81
83 {
84 m_TestTracker->OpenConnection();
85 CPPUNIT_ASSERT(m_TestTracker->StartTracking());
86 }
87
89 {
90 m_TestTracker->OpenConnection();
91 m_TestTracker->CloseConnection();
92 CPPUNIT_ASSERT_EQUAL(false, m_TestTracker->StartTracking());
93 }
94
96 {
97 unsigned int zero = 0;
98 CPPUNIT_ASSERT_EQUAL(zero, m_TestTracker->GetToolCount());
99 }
100
102 {
103 unsigned int one = 1;
104 unsigned int two = 2;
105 unsigned int three = 3;
106 m_TestTracker->AddTool("Tool1");
107 CPPUNIT_ASSERT_EQUAL(one, m_TestTracker->GetToolCount());
108 m_TestTracker->AddTool("Tool2");
109 CPPUNIT_ASSERT_EQUAL(two, m_TestTracker->GetToolCount());
110 m_TestTracker->AddTool("Tool3");
111 CPPUNIT_ASSERT_EQUAL(three, m_TestTracker->GetToolCount());
112 }
113
114 void GetTool()
115 {
116 m_TestTracker->AddTool("Tool1");
117 mitk::TrackingTool::Pointer tool = m_TestTracker->GetTool(0);
118 CPPUNIT_ASSERT_EQUAL(m_TestTracker->GetToolByName("Tool1"), tool.GetPointer());
119 }
120
122 {
123 mitk::ScalarType bounds[6] = { 0.0, 10.0, 1.0, 20.0, 3.0, 30.0 };
124 m_TestTracker->SetBounds(bounds);
125 CPPUNIT_ASSERT_EQUAL(bounds[0], m_TestTracker->GetBounds()[0]);
126 CPPUNIT_ASSERT_EQUAL(bounds[1], m_TestTracker->GetBounds()[1]);
127 CPPUNIT_ASSERT_EQUAL(bounds[2], m_TestTracker->GetBounds()[2]);
128 CPPUNIT_ASSERT_EQUAL(bounds[3], m_TestTracker->GetBounds()[3]);
129 CPPUNIT_ASSERT_EQUAL(bounds[4], m_TestTracker->GetBounds()[4]);
130 CPPUNIT_ASSERT_EQUAL(bounds[5], m_TestTracker->GetBounds()[5]);
131 }
132
134 {
135 m_TestTracker->AddTool("Tool1");
136 CPPUNIT_ASSERT_THROW(m_TestTracker->SetToolSpeed(0, -1), std::invalid_argument);
137 }
138
140 {
141 m_TestTracker->AddTool("Tool1");
142 CPPUNIT_ASSERT_THROW(m_TestTracker->SetToolSpeed(1, 0.1), std::invalid_argument);
143 }
144
146 {
147 m_TestTracker->AddTool("Tool1");
148 mitk::ScalarType lengthBefore = m_TestTracker->GetSplineChordLength(0);
149 m_TestTracker->OpenConnection();
150 m_TestTracker->StartTracking();
151 m_TestTracker->StopTracking();
152 CPPUNIT_ASSERT_EQUAL(lengthBefore, m_TestTracker->GetSplineChordLength(0));
153 }
154
156 {
157 CPPUNIT_ASSERT_THROW(m_TestTracker->GetSplineChordLength(0), std::invalid_argument);
158 }
159
161 {
162 m_TestTracker->AddTool("Tool1");
163 mitk::Point3D posBefore;
164 mitk::Point3D posAfter;
165 mitk::TrackingTool::Pointer tool = m_TestTracker->GetToolByName("Tool1");
166 tool->GetPosition(posBefore);
167 tool->GetPosition(posAfter);
168 CPPUNIT_ASSERT_EQUAL(posBefore, posAfter);
169 m_TestTracker->OpenConnection();
170 m_TestTracker->StartTracking();
171 itksys::SystemTools::Delay(500); //wait for tracking thread to start generating positions
172 tool->GetPosition(posAfter);
173 CPPUNIT_ASSERT(posBefore != posAfter);
174 }
175
177 {
178 double meanDistribution = 2.5;
179 double deviationDistribution = 1.2;
180 m_TestTracker->SetParamsForGaussianNoise(meanDistribution, deviationDistribution);
181 CPPUNIT_ASSERT_EQUAL(meanDistribution, m_TestTracker->GetMeanDistribution());
182 CPPUNIT_ASSERT_EQUAL(deviationDistribution, m_TestTracker->GetDeviationDistribution());
183 }
184
185};
186
187MITK_TEST_SUITE_REGISTRATION(mitkVirtualTrackingDevice)