00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date: 2009-05-13 14:52:01 +0200 (Mi, 13. Mai 2009) $ 00006 Version: $Revision: 17230 $ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #include "mitkNavigationDataPlayer.h" 00019 #include "mitkNavigationData.h" 00020 00021 #include "mitkTestingMacros.h" 00022 #include "mitkStandardFileLocations.h" 00023 #include "mitkTimeStamp.h" 00024 00025 #include <iostream> 00026 #include <sstream> 00027 00031 int mitkNavigationDataPlayerTest(int /* argc */, char* /*argv*/[]) 00032 { 00033 MITK_TEST_BEGIN("NavigationDataPlayer"); 00034 std::string tmp = ""; 00035 00036 // let's create an object of our class 00037 mitk::NavigationDataPlayer::Pointer player = mitk::NavigationDataPlayer::New(); 00038 00039 // first test: did this work? 00040 // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since 00041 // it makes no sense to continue without an object. 00042 MITK_TEST_CONDITION_REQUIRED(player.IsNotNull(), "Testing instantiation"); 00043 00044 std::string file = mitk::StandardFileLocations::GetInstance()->FindFile("NavigationDataTestData.xml", "Modules/IGT/Testing/Data"); 00045 00046 player->SetFileName( file ); 00047 00048 MITK_TEST_CONDITION_REQUIRED( strcmp(player->GetFileName(), file.c_str()) == 0, "Testing SetFileName and GetFileName"); 00049 00050 player->SetStream( mitk::NavigationDataPlayer::NormalFile ); 00051 player->StartPlaying(); 00052 player->Update(); 00053 player->StopPlaying(); 00054 00055 mitk::NavigationData::Pointer nd = player->GetOutput(); 00056 mitk::Point3D pnt; 00057 pnt[0] = 1; 00058 pnt[1] = 0; 00059 pnt[2] = 3; 00060 00061 MITK_TEST_CONDITION_REQUIRED( nd->GetPosition() == pnt, "Testing position of replayed NavigaionData" ); 00062 //MITK_TEST_CONDITION_REQUIRED( nd->GetTimeStamp() == 3068.94, "Testing for correct TimeStamp" ); 00063 00064 00065 std::vector<double> times, refTimes; 00066 refTimes.resize(5); 00067 refTimes[0] = 3.9; 00068 refTimes[1] = 83.6; 00069 refTimes[2] = 174.4; 00070 refTimes[3] = 275.0; 00071 refTimes[4] = 385.39; 00072 00073 mitk::TimeStamp::Pointer timer = mitk::TimeStamp::GetInstance(); 00074 timer->Initialize(); 00075 00076 itk::Object::Pointer obj = itk::Object::New(); 00077 timer->Start( obj ); 00078 00079 mitk::Point3D oldPos; 00080 oldPos[0] = 1; 00081 oldPos[1] = 0; 00082 oldPos[2] = 3; 00083 //pnt = oldPos; 00084 player->StartPlaying(); 00085 while( times.size()<5 ) 00086 { 00087 player->Update(); 00088 pnt = nd->GetPosition(); 00089 if ( pnt != oldPos ) 00090 { 00091 times.push_back( timer->GetElapsed(obj) ); 00092 oldPos = pnt; 00093 } 00094 } 00095 00096 // if this test fails, it may be because the dartclient runs on a virtual machine. 00097 // Under these circumstances, it may be impossible to achieve a time-accuracy of 10ms 00098 for ( int i=0;i<5;i++ ) 00099 { 00100 std::cout << "ref: " << refTimes[i] << " / time elapsed: " << times[i] << std::endl; 00101 MITK_TEST_CONDITION_REQUIRED( (times[i]>refTimes[i]-15 && times[i]<refTimes[i]+15), "checking for more or less correct time-line" ); 00102 } 00103 00104 00105 // always end with this! 00106 MITK_TEST_END(); 00107 }