diff --git a/Modules/IGT/IO/mitkNavigationDataRecorder.h b/Modules/IGT/IO/mitkNavigationDataRecorder.h index 3414d7f348..8d013cdf9d 100644 --- a/Modules/IGT/IO/mitkNavigationDataRecorder.h +++ b/Modules/IGT/IO/mitkNavigationDataRecorder.h @@ -1,118 +1,119 @@ /*=================================================================== 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. ===================================================================*/ #ifndef _MITK_NavigationDataRecorder_H #define _MITK_NavigationDataRecorder_H #include "mitkNavigationDataToNavigationDataFilter.h" #include "mitkNavigationData.h" #include "mitkNavigationDataSet.h" namespace mitk { /**Documentation * \brief This class records NavigationData objects into NavigationDataSets. * * The recording is started with the call of the method StartRecording(). Now * every Update() stores the current state of the added NavigationDatas into the NavigationDataSet. * With StopRecording() the stream is stopped, but can be resumed anytime. * To start recording to a new NavigationDataSet, call ResetRecording(); * * \warning Do not add inputs while the recorder ist recording. The recorder can't handle that and will cause a nullpointer exception. * \ingroup IGT */ class MitkIGT_EXPORT NavigationDataRecorder : public NavigationDataToNavigationDataFilter { public: mitkClassMacro( NavigationDataRecorder, NavigationDataToNavigationDataFilter ); itkNewMacro( Self ); /** * \brief Returns whether the NavigationDataRecorder is currently recording or not */ itkGetMacro(Recording, bool); /** * \brief Returns the set that contains all of the recorded data. */ itkGetMacro(NavigationDataSet, mitk::NavigationDataSet::Pointer); /** * \brief Sets a limit of recorded data sets / frames. Recording will be stopped if the number is reached. values < 1 disable this behaviour. Default is -1. */ itkSetMacro(RecordCountLimit, int); /** * \brief Returns whether to use the navigationdata's time stamp or to create a new one upon recording. */ itkGetMacro(StandardizeTime, bool); /** * \brief If set to false, the navigationDatas Timestamp will be used. If set to false, the recorder * will generate a timestamp when it copies the data to the navigationdataset. */ itkSetMacro(StandardizeTime, bool); /** * \brief Starts recording NavigationData into the NAvigationDataSet */ virtual void StartRecording(); /** * \brief Stops StopsRecording to the NavigationDataSet. * * Recording can be resumed to the same Dataset by just calling StartRecording() again. * Call ResetRecording() to start recording to a new Dataset; */ virtual void StopRecording(); /** * \brief Resets the Datasets and the timestamp, so a new recording can happen. * * Do not forget to save the old Dataset, it will be lost after calling this function. */ virtual void ResetRecording(); /** * \brief Returns the number of time steps that were recorded in the current set. + * Warning: This Method does NOT Stop Recording! */ virtual int GetNumberOfRecordedSteps(); protected: virtual void GenerateData(); NavigationDataRecorder(); virtual ~NavigationDataRecorder(); unsigned int m_NumberOfInputs; ///< counts the numbers of added input NavigationDatas mitk::NavigationDataSet::Pointer m_NavigationDataSet; bool m_Recording; ///< indicates whether the recording is started or not bool m_StandardizeTime; //< indicates whether one should use the timestamps in NavigationData or create new timestamps upon recording bool m_StandardizedTimeInitialized; //< set to true the first time start recording is called. int m_RecordCountLimit; ///< limits the number of frames, recording will be stopped if the limit is reached. -1 disables the limit }; } #endif // #define _MITK_POINT_SET_SOURCE_H diff --git a/Modules/IGT/Testing/mitkNavigationDataRecorderTest.cpp b/Modules/IGT/Testing/mitkNavigationDataRecorderTest.cpp index 471621101c..94099cc560 100644 --- a/Modules/IGT/Testing/mitkNavigationDataRecorderTest.cpp +++ b/Modules/IGT/Testing/mitkNavigationDataRecorderTest.cpp @@ -1,102 +1,119 @@ /*=================================================================== 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 #include #include #include #include #include #include //for exceptions #include "mitkIGTException.h" #include "mitkIGTIOException.h" class mitkNavigationDataRecorderTestClass { public: static void PlayAndRecord() { // Aim is to read an xml into a pointset, play that set with a sequentialplayer, record it // again, write the result to xml , and compare the output mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); std::string path = "F://Build//MITK-Data//IGT-Data//NavigationDataSet.xml"; mitk::NavigationDataSet::Pointer set = reader->Read(path); mitk::NavigationDataSequentialPlayer::Pointer player = mitk::NavigationDataSequentialPlayer::New(); player->SetNavigationDataSet(set); mitk::NavigationDataRecorder::Pointer recorder = mitk::NavigationDataRecorder::New(); recorder->SetStandardizeTime(false); // connect player to recorder for (int i = 0; i < player->GetNumberOfIndexedOutputs(); i++) { recorder->SetInput(i, player->GetOutput(i)); } recorder->StartRecording(); - int i = 0; while (!player->IsAtEnd()) { recorder->Update(); - i++; } mitk::NavigationDataSetWriterXML writer; writer.Write("F://Build//MITK-Data//IGT-Data//NavigationDataSet2.xml", recorder->GetNavigationDataSet()); MITK_TEST_CONDITION_REQUIRED(mitkNavigationDataRecorderTestClass::CompareFiles("F://Build//MITK-Data//IGT-Data//NavigationDataSet.xml", - "F://Build//MITK-Data//IGT-Data//NavigationDataSet2.xml"), "Asserting that compare function for files works correctly - Negative Test"); + "F://Build//MITK-Data//IGT-Data//NavigationDataSet2.xml"), "Asserting that played back file has been recorded correctly"); + + recorder->StopRecording(); + MITK_TEST_CONDITION_REQUIRED(! recorder->GetRecording(), "Test if StopRecording is working"); + recorder->ResetRecording(); + MITK_TEST_CONDITION_REQUIRED(recorder->GetNavigationDataSet()->Size() == 0, "Test correct reset of recorder"); + + //Reset Player + player = mitk::NavigationDataSequentialPlayer::New(); + player->SetNavigationDataSet(set); + + // Check if Limiting recording works + recorder->SetRecordCountLimit(100); + recorder->StartRecording(); + while (!player->IsAtEnd()) + { + recorder->Update(); + } + + MITK_TEST_CONDITION_REQUIRED(recorder->GetNavigationDataSet()->Size() == 100, "Test if SetRecordCountLimit works as intended."); } static bool mitkNavigationDataRecorderTestClass::CompareFiles(std::string file1, std::string file2) { FILE* f1 = fopen (file1.c_str() , "r"); FILE* f2 = fopen (file2.c_str() , "r"); char buf1[10000]; char buf2[10000]; do { size_t r1 = fread(buf1, 1, 10000, f1); size_t r2 = fread(buf2, 1, 10000, f2); if (r1 != r2 || memcmp(buf1, buf2, r1)) { return false; // Files are not equal } } while (!feof(f1) && !feof(f2)); return feof(f1) && feof(f2); } }; /**Documentation * test for the class "NavigationDataRecorder". */ int mitkNavigationDataRecorderTest(int /* argc */, char* /*argv*/[]) { MITK_TEST_BEGIN("NavigationDataRecorder"); mitkNavigationDataRecorderTestClass::PlayAndRecord(); // always end with this! MITK_TEST_END(); } diff --git a/Modules/IGT/Testing/mitkNavigationDataSetReaderWriterTest.cpp b/Modules/IGT/Testing/mitkNavigationDataSetReaderWriterTest.cpp index 861f79447b..9d46ae4d33 100644 --- a/Modules/IGT/Testing/mitkNavigationDataSetReaderWriterTest.cpp +++ b/Modules/IGT/Testing/mitkNavigationDataSetReaderWriterTest.cpp @@ -1,90 +1,90 @@ /*=================================================================== 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 #include #include #include #include #include #include #include #include #include #include #include //for exceptions #include "mitkIGTException.h" #include "mitkIGTIOException.h" class mitkNavigationDataSetReaderWriterTestClass { public: static void TestReadWrite() { // Aim is to read an xml into a pointset, write that xml again, and compare the output mitk::NavigationDataSetWriterXML writer; mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); std::string path = "F://Build//MITK-Data//IGT-Data//NavigationDataSet.xml"; mitk::NavigationDataSet::Pointer set = reader->Read(path); writer.Write("F://Build//MITK-Data//IGT-Data//NavigationDataSet2.xml", set); MITK_TEST_CONDITION_REQUIRED(mitkNavigationDataSetReaderWriterTestClass::CompareFiles("F://Build//MITK-Data//IGT-Data//NavigationDataSet.xml", - "F://Build//MITK-Data//IGT-Data//NavigationDataSet2.xml"), "Asserting that compare function for files works correctly - Negative Test"); + "F://Build//MITK-Data//IGT-Data//NavigationDataSet2.xml"), "Testing if read/write cycle creates identical files"); } static bool CompareFiles(std::string file1, std::string file2) { FILE* f1 = fopen (file1.c_str() , "r"); FILE* f2 = fopen (file2.c_str() , "r"); char buf1[10000]; char buf2[10000]; do { size_t r1 = fread(buf1, 1, 10000, f1); size_t r2 = fread(buf2, 1, 10000, f2); if (r1 != r2 || memcmp(buf1, buf2, r1)) { return false; // Files are not equal } } while (!feof(f1) && !feof(f2)); return feof(f1) && feof(f2); } }; /**Documentation * test for the class "NavigationDataRecorder". */ int mitkNavigationDataSetReaderWriterTest(int /* argc */, char* /*argv*/[]) { MITK_TEST_BEGIN("NavigationDataRecorder"); MITK_TEST_CONDITION_REQUIRED(mitkNavigationDataSetReaderWriterTestClass::CompareFiles("F://Build//MITK-Data//IGT-Data//NavigationDataSet.xml", "F://Build//MITK-Data//IGT-Data//NavigationDataSet.xml"), "Asserting that compare function for files works correctly - Positive Test"); MITK_TEST_CONDITION_REQUIRED(! mitkNavigationDataSetReaderWriterTestClass::CompareFiles("F://Build//MITK-Data//IGT-Data//NavigationDataSet.xml", "F://Build//MITK-Data//IGT-Data//SROMFile.rom"), "Asserting that compare function for files works correctly - Negative Test"); mitkNavigationDataSetReaderWriterTestClass::TestReadWrite(); MITK_TEST_END(); };