MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkNavigationDataSetReaderWriterCSVTest.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 headers
14//#include <mitkTestingMacros.h>
15#include <mitkTestFixture.h>
16
19#include <mitkNavigationData.h>
20#include <mitkStandardFileLocations.h>
21#include <mitkTestingMacros.h>
22#include <mitkIOUtil.h>
23
24#include <Poco/Path.h>
25#include <Poco/File.h>
26
27#include <iostream>
28#include <sstream>
29#include <fstream>
30
31//for exceptions
32#include "mitkIGTException.h"
33#include "mitkIGTIOException.h"
34
35class mitkNavigationDataSetReaderWriterCSVTestSuite : public mitk::TestFixture
36{
38 // MITK_TEST(TestCompareFunction);
39 MITK_TEST(TestReadWrite);
40 CPPUNIT_TEST_SUITE_END();
41
42private:
43
44 std::string pathRead;
45 std::string pathWrite;
46 std::string pathWrong;
47
48 mitk::NavigationDataSet::Pointer set;
49
50public:
51
52 void setUp() override
53 {
54 pathRead = GetTestDataFilePath("IGT-Data/RecordedNavigationData.xml");
55
56 pathWrong = GetTestDataFilePath("IGT-Data/NavigationDataTestData.CSV");
57 pathWrite="C:\\test.csv";
58 }
59
60 void tearDown() override
61 {
62 }
63
64
66 {
67 // Aim is to read an CSV into a pointset, write that CSV again, and compare the output
68
69 set = mitk::IOUtil::Load<mitk::NavigationDataSet>(pathRead);
70 CPPUNIT_ASSERT_MESSAGE("Testing whether something was read at all", set != nullptr);
71
72 mitk::IOUtil::Save(set, pathWrite);
73
74 //FIXME: Commented out, because test fails under linux. binary comparison of files is probably not the wa to go
75 // See Bug 17775
76 //CPPUNIT_ASSERT_MESSAGE( "Testing if read/write cycle creates identical files", CompareFiles(pathRead, pathWrite));
77 //remove(pathWrite.c_str());
78 }
79
80
81
82
83
84 bool CompareFiles(std::string file)
85 {
86 set = mitk::IOUtil::Load<mitk::NavigationDataSet>(file);
87
88 double sample[2][30] ={
89 {5134019.44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5134019.44, 0, 1, 101.2300034, -62.63999939, -203.2400055, -0.3059000075, 0.5752000213, 0, 0.7585999966, 5134019.44, 0, 0, 0, 0, 0, 0, 0, 0, 0},
90 {5134082.84, 5134073.64, 1, -172.6100006, 12.60999966, -299.4500122, -0.1588999927, 0.4370000064, 0, 0.8852000237, 5134082.84, 5134073.64, 1, 101.2300034, -62.63999939, -203.2400055, -0.3059000075, 0.5752000213, 0, 0.7585999966, 5134082.84, 5134073.64, 0, 0, 0, 0, 0, 0, 0, 0}
91 };
92
93 bool returnValue = true;
94 for(int line = 0 ; line < 2; line++)
95 {
96
97 for (int tool =0; tool < 3; tool ++)
98 {
99 mitk::NavigationData::Pointer testline = set->GetNavigationDataForIndex(line,tool) ;
100
101 returnValue = returnValue && mitk::Equal( testline->GetIGTTimeStamp() , sample [line] [(tool*10)] );
102 returnValue = returnValue && mitk::Equal( testline->IsDataValid() , sample [line] [(tool*10)+1] );
103
104 mitk::NavigationData::PositionType pos = testline->GetPosition();
105 returnValue = returnValue && mitk::Equal( pos[0] , sample [line] [(tool*10)+2] );
106 returnValue = returnValue && mitk::Equal( pos[1] , sample [line] [(tool*10)+3] );
107 returnValue = returnValue && mitk::Equal( pos[2] , sample [line] [(tool*10)+4] );
108
109 mitk::NavigationData::OrientationType ori = testline->GetOrientation();
110 returnValue = returnValue && mitk::Equal( ori[0] , sample [line] [(tool*10)+5] );
111 returnValue = returnValue && mitk::Equal( ori[1] , sample [line] [(tool*10)+6] );
112 returnValue = returnValue && mitk::Equal( ori[2] , sample [line] [(tool*10)+7] );
113 returnValue = returnValue && mitk::Equal( ori[3] , sample [line] [(tool*10)+8] );
114 }
115 }
116 return returnValue;
117 }
118
119
121 {
122 CPPUNIT_ASSERT_MESSAGE("Checking if csv-file reader is working properly", CompareFiles(pathRead));
123 //CPPUNIT_ASSERT_MESSAGE("Asserting that compare function for files works correctly - Negative Test", ! CompareFiles(pathWrong) );
124 }
125
126};
127
128MITK_TEST_SUITE_REGISTRATION(mitkNavigationDataSetReaderWriterCSV)
mitk::Quaternion OrientationType
Type that holds the orientation part of the tracking data.
mitk::Point3D PositionType
Type that holds the position part of the tracking data.
MITKIGTBASE_EXPORT bool Equal(const mitk::NavigationData &leftHandSide, const mitk::NavigationData &rightHandSide, ScalarType eps=mitk::eps, bool verbose=false)
Equal A function comparing two navigation data objects for beeing equal in meta- and imagedata.