diff --git a/Modules/ToFHardware/Testing/files.cmake b/Modules/ToFHardware/Testing/files.cmake index 67cca63647..aef76fae20 100644 --- a/Modules/ToFHardware/Testing/files.cmake +++ b/Modules/ToFHardware/Testing/files.cmake @@ -1,26 +1,26 @@ set(MODULE_TESTS #mitkThreadedToFRawDataReconstructionTest.cpp mitkAbstractToFDeviceFactoryTest.cpp mitkToFCameraMITKPlayerDeviceTest.cpp mitkToFCameraMITKPlayerDeviceFactoryTest.cpp mitkToFImageCsvWriterTest.cpp mitkToFImageGrabberTest.cpp - #mitkToFImageRecorderTest.cpp + mitkToFImageRecorderTest.cpp #mitkToFImageRecorderFilterTest.cpp mitkToFImageWriterTest.cpp mitkToFNrrdImageWriterTest.cpp mitkToFOpenCVImageGrabberTest.cpp ) set(MODULE_CUSTOM_TESTS mitkPlayerLoadAndRenderDepthDataTest.cpp mitkPlayerLoadAndRenderRGBDataTest.cpp ) # Create an artificial module initializing class for # the mitkToFCameraMITKPlayerDeviceFactoryTest usFunctionGenerateExecutableInit(testdriver_init_file IDENTIFIER ${MODULE_NAME}TestDriver ) set(TEST_CPP_FILES ${testdriver_init_file}) diff --git a/Modules/ToFHardware/Testing/mitkToFImageRecorderTest.cpp b/Modules/ToFHardware/Testing/mitkToFImageRecorderTest.cpp index 3618f8630c..bcfab5ebdb 100644 --- a/Modules/ToFHardware/Testing/mitkToFImageRecorderTest.cpp +++ b/Modules/ToFHardware/Testing/mitkToFImageRecorderTest.cpp @@ -1,249 +1,151 @@ /*=================================================================== 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 +#include - -/**Documentation - * test for the class "ToFImageRecorder". - */ - -static bool CompareImages(mitk::Image::Pointer image1, mitk::Image::Pointer image2) +class mitkToFImageRecorderTestSuite : public mitk::TestFixture { - //check if epsilon is exceeded - unsigned int sliceDimension = image1->GetDimension(0)*image1->GetDimension(1); - bool picturesEqual = true; - int numOfFrames = image1->GetDimension(2); - for (unsigned int i=0; iGetSliceData(i, 0, 0)->GetData(); - float* floatArray2 = (float*)image2->GetSliceData(i, 0, 0)->GetData(); - for(unsigned int j = 0; j < sliceDimension; j++) - { - if(!(mitk::Equal(floatArray1[j], floatArray2[j]))) - { - picturesEqual = false; - } - } - } - - return picturesEqual; -} - -int mitkToFImageRecorderTest(int /* argc */, char* /*argv*/[]) -{ - MITK_TEST_BEGIN("ToFImageRecorder"); - - mitk::ToFImageRecorder::Pointer tofImageRecorder = mitk::ToFImageRecorder::New(); - - MITK_TEST_OUTPUT(<< "Test itk-Set/Get-Makros"); - std::string testFileName_Distance = "test_DistanceImage.nrrd"; - std::string testFileName_Amplitude = "test_AmplitudeImage.nrrd"; - std::string testFileName_Intensity = "test_IntensityImage.nrrd"; - std::string requiredName_Distance; - std::string requiredName_Amplitude; - std::string requiredName_Intensity; - - tofImageRecorder->SetDistanceImageFileName(testFileName_Distance); - requiredName_Distance = tofImageRecorder->GetDistanceImageFileName(); - MITK_TEST_CONDITION_REQUIRED(requiredName_Distance==testFileName_Distance,"Test for distance image file name"); - - tofImageRecorder->SetAmplitudeImageFileName(testFileName_Amplitude); - requiredName_Amplitude = tofImageRecorder->GetAmplitudeImageFileName(); - MITK_TEST_CONDITION_REQUIRED(requiredName_Amplitude==testFileName_Amplitude,"Test for amplitude image file name"); - - tofImageRecorder->SetIntensityImageFileName(testFileName_Intensity); - requiredName_Intensity = tofImageRecorder->GetIntensityImageFileName(); - MITK_TEST_CONDITION_REQUIRED(requiredName_Intensity==testFileName_Intensity,"Test for intensity image file name"); - - bool distanceImageSelected = false; - bool amplitudeImageSelected = false; - bool intensityImageSelected = false; - bool requiredDistanceImageSelected = false; - bool requiredAmplitudeImageSelected = false; - bool requiredIntensityImageSelected = false; - - tofImageRecorder->SetDistanceImageSelected(distanceImageSelected); - requiredDistanceImageSelected = tofImageRecorder->GetDistanceImageSelected(); - MITK_TEST_CONDITION_REQUIRED(distanceImageSelected==requiredDistanceImageSelected,"Test for distance selection"); - - tofImageRecorder->SetAmplitudeImageSelected(amplitudeImageSelected); - requiredAmplitudeImageSelected = tofImageRecorder->GetAmplitudeImageSelected(); - MITK_TEST_CONDITION_REQUIRED(amplitudeImageSelected==requiredAmplitudeImageSelected,"Test for amplitude selection"); - - tofImageRecorder->SetIntensityImageSelected(intensityImageSelected); - requiredIntensityImageSelected = tofImageRecorder->GetIntensityImageSelected(); - MITK_TEST_CONDITION_REQUIRED(intensityImageSelected==requiredIntensityImageSelected,"Test for intensity selection"); - - int numOfFrames = 7; - tofImageRecorder->SetNumOfFrames(numOfFrames); - MITK_TEST_CONDITION_REQUIRED(numOfFrames==tofImageRecorder->GetNumOfFrames(),"Test for get/set number of frames"); - - std::string fileFormat = ".nrrd"; - tofImageRecorder->SetFileFormat(fileFormat); - MITK_TEST_CONDITION_REQUIRED(fileFormat==tofImageRecorder->GetFileFormat(),"Test for get/set the file format"); - - - - MITK_TEST_OUTPUT(<< "Test other methods"); - - tofImageRecorder->SetRecordMode(mitk::ToFImageRecorder::Infinite); - MITK_TEST_CONDITION_REQUIRED(mitk::ToFImageRecorder::Infinite==tofImageRecorder->GetRecordMode(),"Test for get/set the record mode"); - - mitk::ToFCameraDevice* testDevice = NULL; - tofImageRecorder->SetCameraDevice(testDevice); - MITK_TEST_CONDITION_REQUIRED(testDevice == tofImageRecorder->GetCameraDevice(),"Test for get/set the camera device"); - - - tofImageRecorder->SetToFImageType(mitk::ToFImageWriter::ToFImageType2DPlusT); - MITK_TEST_CONDITION_REQUIRED(mitk::ToFImageWriter::ToFImageType2DPlusT==tofImageRecorder->GetToFImageType(), "Testing set/get ToFImageType"); - - tofImageRecorder->SetToFImageType(mitk::ToFImageWriter::ToFImageType3D); - MITK_TEST_CONDITION_REQUIRED(mitk::ToFImageWriter::ToFImageType3D==tofImageRecorder->GetToFImageType(), "Testing set/get ToFImageType"); + m_ToFImageRecorder = mitk::ToFImageRecorder::New(); + m_DistanceImageName = "test_DistanceImage.nrrd"; + m_AmplitudeImageName = "test_AmplitudeImage.nrrd"; + m_IntensityImageName = "test_IntensityImage.nrrd"; + m_PlayerDevice = mitk::ToFCameraMITKPlayerDevice::New(); + m_ToFImageRecorder->SetCameraDevice(m_PlayerDevice); - MITK_TEST_OUTPUT(<< "Test recording"); + //the test data set has 20 frames, so we record 20 per default + m_ToFImageRecorder->SetNumOfFrames(20); + m_ToFImageRecorder->SetRecordMode(mitk::ToFImageRecorder::PerFrames); - tofImageRecorder = mitk::ToFImageRecorder::New(); - std::string dirName = MITK_TOF_DATA_DIR; - mitk::ToFCameraMITKPlayerDevice::Pointer tofCameraMITKPlayerDevice = mitk::ToFCameraMITKPlayerDevice::New(); - tofImageRecorder->SetCameraDevice(tofCameraMITKPlayerDevice); - MITK_TEST_CONDITION_REQUIRED(tofCameraMITKPlayerDevice == tofImageRecorder->GetCameraDevice(), "Testing set/get CameraDevice with ToFCameraPlayerDevice"); + std::string dirName = MITK_TOF_DATA_DIR; + std::string distanceFileName = dirName + "/PMDCamCube2_MF0_IT0_20Images_DistanceImage.pic"; + std::string amplitudeFileName = dirName + "/PMDCamCube2_MF0_IT0_20Images_AmplitudeImage.pic"; + std::string intensityFileName = dirName + "/PMDCamCube2_MF0_IT0_20Images_IntensityImage.pic"; - std::string distanceFileName = dirName + "/PMDCamCube2_MF0_IT0_20Images_DistanceImage.pic"; - std::string amplitudeFileName = dirName + "/PMDCamCube2_MF0_IT0_20Images_AmplitudeImage.pic"; - std::string intensityFileName = dirName + "/PMDCamCube2_MF0_IT0_20Images_IntensityImage.pic"; + m_PlayerDevice->SetProperty("DistanceImageFileName",mitk::StringProperty::New(distanceFileName)); + m_PlayerDevice->SetProperty("AmplitudeImageFileName",mitk::StringProperty::New(amplitudeFileName)); + m_PlayerDevice->SetProperty("IntensityImageFileName",mitk::StringProperty::New(intensityFileName)); - tofCameraMITKPlayerDevice->SetProperty("DistanceImageFileName",mitk::StringProperty::New(distanceFileName)); - tofCameraMITKPlayerDevice->SetProperty("AmplitudeImageFileName",mitk::StringProperty::New(amplitudeFileName)); - tofCameraMITKPlayerDevice->SetProperty("IntensityImageFileName",mitk::StringProperty::New(intensityFileName)); + //comparing against IOUtil seems fair enough + m_GroundTruthDepthImage = mitk::IOUtil::LoadImage(distanceFileName); + m_GroundTruthAmplitudeImage = mitk::IOUtil::LoadImage(amplitudeFileName); + m_GroundTruthIntensityImage = mitk::IOUtil::LoadImage(intensityFileName); - MITK_TEST_OUTPUT(<< "Test ConnectCamera()"); - tofCameraMITKPlayerDevice->ConnectCamera(); - MITK_TEST_OUTPUT(<< "Test StartCamera()"); - tofCameraMITKPlayerDevice->StartCamera(); + m_PlayerDevice->ConnectCamera(); + m_PlayerDevice->StartCamera(); - std::string distanceTestFileName = dirName + "test_distance.nrrd"; - std::string amplitudeTestFileName = dirName + "test_amplitude.nrrd"; - std::string intensityTestFileName = dirName + "test_intensity.nrrd"; - - tofImageRecorder->SetDistanceImageFileName(distanceTestFileName); - MITK_TEST_CONDITION_REQUIRED(tofImageRecorder->GetDistanceImageFileName() == distanceTestFileName, "Testing Set/GetDistanceImageFileName()"); - tofImageRecorder->SetAmplitudeImageFileName(amplitudeTestFileName); - MITK_TEST_CONDITION_REQUIRED(tofImageRecorder->GetAmplitudeImageFileName() == amplitudeTestFileName, "Testing Set/GetAmplitudeImageFileName()"); - tofImageRecorder->SetIntensityImageFileName(intensityTestFileName); - MITK_TEST_CONDITION_REQUIRED(tofImageRecorder->GetIntensityImageFileName() == intensityTestFileName, "Testing Set/GetIntensityImageFileName()"); - tofImageRecorder->SetRecordMode(mitk::ToFImageRecorder::PerFrames); - MITK_TEST_CONDITION_REQUIRED(tofImageRecorder->GetRecordMode() == mitk::ToFImageRecorder::PerFrames, "Testing Set/GetRecordMode()"); - tofImageRecorder->SetNumOfFrames(20); - MITK_TEST_CONDITION_REQUIRED(tofImageRecorder->GetNumOfFrames() == 20, "Testing Set/GetNumOfFrames()"); - tofImageRecorder->SetFileFormat(".nrrd"); - MITK_TEST_OUTPUT(<< "Test StartRecording()"); - tofImageRecorder->StartRecording(); - tofImageRecorder->WaitForThreadBeingTerminated(); // wait to allow recording - MITK_TEST_OUTPUT(<< "Test StopRecording()"); - tofImageRecorder->StopRecording(); - - MITK_TEST_OUTPUT(<< "Test StopCamera()"); - tofCameraMITKPlayerDevice->StopCamera(); - MITK_TEST_OUTPUT(<< "Test DisconnectCamera()"); - tofCameraMITKPlayerDevice->DisconnectCamera(); - - // Load images (recorded and original ones) with PicFileReader for comparison - mitk::ItkImageFileReader::Pointer nrrdReader = mitk::ItkImageFileReader::New(); - mitk::PicFileReader::Pointer picFileReader = mitk::PicFileReader::New(); - mitk::Image::Pointer originalImage = NULL; - mitk::Image::Pointer recordedImage = NULL; - - MITK_TEST_OUTPUT(<< "Read original distance image using PicFileReader"); - picFileReader->SetFileName(distanceFileName); - picFileReader->Update(); - originalImage = picFileReader->GetOutput()->Clone(); - - MITK_TEST_OUTPUT(<< "Read recorded distance image using ItkImageFileReader"); - nrrdReader->SetFileName(distanceTestFileName); - nrrdReader->Update(); - recordedImage = nrrdReader->GetOutput()->Clone(); - - MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(0) == tofImageRecorder->GetToFCaptureWidth(), "Testing capture width"); - MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(1) == tofImageRecorder->GetToFCaptureHeight(), "Testing capture height"); - int numFramesOrig = originalImage->GetDimension(2); - int numFramesRec = recordedImage->GetDimension(2); - MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(2) == recordedImage->GetDimension(2), "Testing number of frames"); + } - MITK_TEST_CONDITION_REQUIRED(CompareImages(originalImage, recordedImage), "Compare original and saved distance image"); + void tearDown() + { + m_PlayerDevice->StopCamera(); + m_PlayerDevice->DisconnectCamera(); + } + void StartRecording_ValidDepthImage_WritesImageToFile() + { + m_ToFImageRecorder->SetDistanceImageFileName(m_DistanceImageName); + m_ToFImageRecorder->StartRecording(); + m_ToFImageRecorder->WaitForThreadBeingTerminated(); // wait to allow recording + m_ToFImageRecorder->StopRecording(); - MITK_TEST_OUTPUT(<< "Read original amplitude image using PicFileReader"); - picFileReader->SetFileName(amplitudeFileName); - picFileReader->Update(); - originalImage = picFileReader->GetOutput()->Clone(); + mitk::Image::Pointer recordedImage = mitk::IOUtil::LoadImage(m_DistanceImageName); + MITK_ASSERT_EQUAL( m_GroundTruthDepthImage, recordedImage, "Recorded image should be equal to the test data."); - MITK_TEST_OUTPUT(<< "Read recorded amplitude image using ItkImageFileReader"); - nrrdReader->SetFileName(amplitudeTestFileName); - nrrdReader->Update(); - recordedImage = nrrdReader->GetOutput()->Clone(); + if( remove( m_DistanceImageName.c_str() ) != 0 ) + { + MITK_ERROR<<"File: test_distance.nrrd not successfully deleted!"; + } + } - MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(0) == tofImageRecorder->GetToFCaptureWidth(), "Testing capture width"); - MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(1) == tofImageRecorder->GetToFCaptureHeight(), "Testing capture height"); - MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(2) == recordedImage->GetDimension(2), "Testing number of frames"); - - MITK_TEST_CONDITION_REQUIRED(CompareImages(originalImage, recordedImage), "Compare original and saved amplitude image"); + void StartRecording_ValidAmplitudeImage_WritesImageToFile() + { + m_ToFImageRecorder->SetAmplitudeImageFileName(m_AmplitudeImageName); + m_ToFImageRecorder->SetAmplitudeImageSelected(true); + m_ToFImageRecorder->SetDistanceImageSelected(false); + m_ToFImageRecorder->StartRecording(); + m_ToFImageRecorder->WaitForThreadBeingTerminated(); // wait to allow recording + m_ToFImageRecorder->StopRecording(); + mitk::Image::Pointer recordedImage = mitk::IOUtil::LoadImage(m_AmplitudeImageName); + MITK_ASSERT_EQUAL( m_GroundTruthAmplitudeImage, recordedImage, "Recorded image should be equal to the test data."); - MITK_TEST_OUTPUT(<< "Read original intensity image using PicFileReader"); - picFileReader->SetFileName(intensityFileName); - picFileReader->Update(); - originalImage = picFileReader->GetOutput()->Clone(); - - MITK_TEST_OUTPUT(<< "Read recorded intensity image using ItkImageFileReader"); - nrrdReader->SetFileName(intensityTestFileName); - nrrdReader->Update(); - recordedImage = nrrdReader->GetOutput()->Clone(); - - MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(0) == tofImageRecorder->GetToFCaptureWidth(), "Testing capture width"); - MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(1) == tofImageRecorder->GetToFCaptureHeight(), "Testing capture height"); - MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(2) == recordedImage->GetDimension(2), "Testing number of frames"); - - MITK_TEST_CONDITION_REQUIRED(CompareImages(originalImage, recordedImage), "Compare original and saved intensity image"); - - //clean up and delete saved image files - if( remove( distanceTestFileName.c_str() ) != 0 ) - { - MITK_ERROR<<"File: test_distance.nrrd not successfully deleted!"; - } - if( remove( amplitudeTestFileName.c_str() ) != 0 ) - { - MITK_ERROR<<"File: test_amplitude.nrrd not successfully deleted!"; + if( remove( m_AmplitudeImageName.c_str() ) != 0 ) + { + MITK_ERROR<<"File: test_amplitude.nrrd not successfully deleted!"; + } } - if( remove( intensityTestFileName.c_str() ) != 0 ) + + void StartRecording_ValidIntensityImage_WritesImageToFile() { - MITK_ERROR<<"File: test_intensity.nrrd not successfully deleted!"; - } + m_ToFImageRecorder->SetIntensityImageFileName(m_IntensityImageName); + m_ToFImageRecorder->SetIntensityImageSelected(true); + m_ToFImageRecorder->SetDistanceImageSelected(false); + m_ToFImageRecorder->StartRecording(); + m_ToFImageRecorder->WaitForThreadBeingTerminated(); // wait to allow recording + m_ToFImageRecorder->StopRecording(); - MITK_TEST_END(); -} + mitk::Image::Pointer recordedImage = mitk::IOUtil::LoadImage(m_IntensityImageName); + MITK_ASSERT_EQUAL( m_GroundTruthIntensityImage, recordedImage, "Recorded image should be equal to the test data."); + if( remove( m_IntensityImageName.c_str() ) != 0 ) + { + MITK_ERROR<<"File: test_intensity.nrrd not successfully deleted!"; + } + } +}; +MITK_TEST_SUITE_REGISTRATION(mitkToFImageRecorder) diff --git a/Modules/ToFHardware/mitkToFImageRecorder.cpp b/Modules/ToFHardware/mitkToFImageRecorder.cpp index c264ceea47..7eb8605e30 100644 --- a/Modules/ToFHardware/mitkToFImageRecorder.cpp +++ b/Modules/ToFHardware/mitkToFImageRecorder.cpp @@ -1,268 +1,268 @@ /*=================================================================== 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 "mitkToFImageRecorder.h" #include "mitkRealTimeClock.h" #include "itkMultiThreader.h" #include #pragma GCC visibility push(default) #include #pragma GCC visibility pop namespace mitk { ToFImageRecorder::ToFImageRecorder() { this->m_ToFCameraDevice = NULL; this->m_MultiThreader = itk::MultiThreader::New(); this->m_AbortMutex = itk::FastMutexLock::New(); this->m_ThreadID = 0; - this->m_NumOfFrames = 0; + this->m_NumOfFrames = 1; //lets record one frame per default this->m_ToFImageWriter = NULL; - this->m_DistanceImageSelected = true; - this->m_AmplitudeImageSelected = true; - this->m_IntensityImageSelected = true; - this->m_RGBImageSelected = true; + this->m_DistanceImageSelected = true; //lets assume a device only has depth data by default + this->m_AmplitudeImageSelected = false; + this->m_IntensityImageSelected = false; + this->m_RGBImageSelected = false; this->m_Abort = false; this->m_ToFCaptureWidth = 0; this->m_ToFCaptureHeight = 0; this->m_RGBCaptureWidth = 0; this->m_RGBCaptureHeight = 0; - this->m_FileFormat = ""; + this->m_FileFormat = ".nrrd"; //lets make nrrd the default this->m_ToFPixelNumber = 0; this->m_RGBPixelNumber = 0; this->m_SourceDataSize = 0; this->m_ToFImageType = ToFImageWriter::ToFImageType3D; this->m_RecordMode = ToFImageRecorder::PerFrames; this->m_DistanceImageFileName = ""; this->m_AmplitudeImageFileName = ""; this->m_IntensityImageFileName = ""; this->m_RGBImageFileName = ""; this->m_ImageSequence = 0; this->m_DistanceArray = NULL; this->m_AmplitudeArray = NULL; this->m_IntensityArray = NULL; this->m_RGBArray = NULL; this->m_SourceDataArray = NULL; } ToFImageRecorder::~ToFImageRecorder() { delete[] m_DistanceArray; delete[] m_AmplitudeArray; delete[] m_IntensityArray; delete[] m_RGBArray; delete[] m_SourceDataArray; } void ToFImageRecorder::StopRecording() { this->m_AbortMutex->Lock(); this->m_Abort = true; this->m_AbortMutex->Unlock(); } void ToFImageRecorder::StartRecording() { if (this->m_ToFCameraDevice.IsNull()) { throw std::invalid_argument("ToFCameraDevice is NULL."); return; } if (this->m_FileFormat.compare(".csv") == 0) { this->m_ToFImageWriter = ToFImageCsvWriter::New(); } else if(this->m_FileFormat.compare(".nrrd") == 0) { this->m_ToFImageWriter = ToFNrrdImageWriter::New(); this->m_ToFImageWriter->SetExtension(m_FileFormat); } else { throw std::logic_error("No file format specified!"); } this->m_RGBCaptureWidth = this->m_ToFCameraDevice->GetRGBCaptureWidth(); this->m_RGBCaptureHeight = this->m_ToFCameraDevice->GetRGBCaptureHeight(); this->m_RGBPixelNumber = this->m_RGBCaptureWidth * this->m_RGBCaptureHeight; this->m_ToFCaptureWidth = this->m_ToFCameraDevice->GetCaptureWidth(); this->m_ToFCaptureHeight = this->m_ToFCameraDevice->GetCaptureHeight(); this->m_ToFPixelNumber = this->m_ToFCaptureWidth * this->m_ToFCaptureHeight; this->m_SourceDataSize = this->m_ToFCameraDevice->GetSourceDataSize(); // allocate buffer if(m_IntensityArray == NULL) { this->m_IntensityArray = new float[m_ToFPixelNumber]; } if(this->m_DistanceArray == NULL) { this->m_DistanceArray = new float[m_ToFPixelNumber]; } if(this->m_AmplitudeArray == NULL) { this->m_AmplitudeArray = new float[m_ToFPixelNumber]; } if(this->m_RGBArray == NULL) { this->m_RGBArray = new unsigned char[m_RGBPixelNumber*3]; } if(this->m_SourceDataArray == NULL) { this->m_SourceDataArray = new char[m_SourceDataSize]; } this->m_ToFImageWriter->SetDistanceImageFileName(this->m_DistanceImageFileName); this->m_ToFImageWriter->SetAmplitudeImageFileName(this->m_AmplitudeImageFileName); this->m_ToFImageWriter->SetIntensityImageFileName(this->m_IntensityImageFileName); this->m_ToFImageWriter->SetRGBImageFileName(this->m_RGBImageFileName); this->m_ToFImageWriter->SetRGBCaptureWidth(this->m_RGBCaptureWidth); this->m_ToFImageWriter->SetRGBCaptureHeight(this->m_RGBCaptureHeight); //this->m_ToFImageWriter->SetToFCaptureHeight(this->m_ToFCaptureHeight); this->m_ToFImageWriter->SetToFCaptureWidth(this->m_ToFCaptureWidth); this->m_ToFImageWriter->SetToFCaptureHeight(this->m_ToFCaptureHeight); this->m_ToFImageWriter->SetToFImageType(this->m_ToFImageType); this->m_ToFImageWriter->SetDistanceImageSelected(this->m_DistanceImageSelected); this->m_ToFImageWriter->SetAmplitudeImageSelected(this->m_AmplitudeImageSelected); this->m_ToFImageWriter->SetIntensityImageSelected(this->m_IntensityImageSelected); this->m_ToFImageWriter->SetRGBImageSelected(this->m_RGBImageSelected); this->m_ToFImageWriter->Open(); this->m_AbortMutex->Lock(); this->m_Abort = false; this->m_AbortMutex->Unlock(); this->m_ThreadID = this->m_MultiThreader->SpawnThread(this->RecordData, this); } void ToFImageRecorder::WaitForThreadBeingTerminated() { this->m_MultiThreader->TerminateThread(this->m_ThreadID); } ITK_THREAD_RETURN_TYPE ToFImageRecorder::RecordData(void* pInfoStruct) { struct itk::MultiThreader::ThreadInfoStruct * pInfo = (struct itk::MultiThreader::ThreadInfoStruct*)pInfoStruct; if (pInfo == NULL) { return ITK_THREAD_RETURN_VALUE; } if (pInfo->UserData == NULL) { return ITK_THREAD_RETURN_VALUE; } ToFImageRecorder* toFImageRecorder = (ToFImageRecorder*)pInfo->UserData; if (toFImageRecorder!=NULL) { ToFCameraDevice::Pointer toFCameraDevice = toFImageRecorder->GetCameraDevice(); mitk::RealTimeClock::Pointer realTimeClock; realTimeClock = mitk::RealTimeClock::New(); int n = 100; double t1 = 0; double t2 = 0; t1 = realTimeClock->GetCurrentStamp(); bool overflow = false; bool printStatus = false; int requiredImageSequence = 0; int numOfFramesRecorded = 0; bool abort = false; toFImageRecorder->m_AbortMutex->Lock(); abort = toFImageRecorder->m_Abort; toFImageRecorder->m_AbortMutex->Unlock(); while ( !abort ) { if ( ((toFImageRecorder->m_RecordMode == ToFImageRecorder::PerFrames) && (numOfFramesRecorded < toFImageRecorder->m_NumOfFrames)) || (toFImageRecorder->m_RecordMode == ToFImageRecorder::Infinite) ) { toFCameraDevice->GetAllImages(toFImageRecorder->m_DistanceArray, toFImageRecorder->m_AmplitudeArray, toFImageRecorder->m_IntensityArray, toFImageRecorder->m_SourceDataArray, requiredImageSequence, toFImageRecorder->m_ImageSequence, toFImageRecorder->m_RGBArray ); if (toFImageRecorder->m_ImageSequence >= requiredImageSequence) { if (toFImageRecorder->m_ImageSequence > requiredImageSequence) { MITK_INFO << "Problem! required: " << requiredImageSequence << " captured: " << toFImageRecorder->m_ImageSequence; } requiredImageSequence = toFImageRecorder->m_ImageSequence + 1; toFImageRecorder->m_ToFImageWriter->Add( toFImageRecorder->m_DistanceArray, toFImageRecorder->m_AmplitudeArray, toFImageRecorder->m_IntensityArray, toFImageRecorder->m_RGBArray ); numOfFramesRecorded++; if (numOfFramesRecorded % n == 0) { printStatus = true; } if (printStatus) { t2 = realTimeClock->GetCurrentStamp() - t1; MITK_INFO << " Framerate (fps): " << n / (t2/1000) << " Sequence: " << toFImageRecorder->m_ImageSequence; t1 = realTimeClock->GetCurrentStamp(); printStatus = false; } } toFImageRecorder->m_AbortMutex->Lock(); abort = toFImageRecorder->m_Abort; toFImageRecorder->m_AbortMutex->Unlock(); } else { abort = true; } } // end of while loop toFImageRecorder->InvokeEvent(itk::AbortEvent()); toFImageRecorder->m_ToFImageWriter->Close(); } return ITK_THREAD_RETURN_VALUE; } void ToFImageRecorder::SetCameraDevice(ToFCameraDevice* aToFCameraDevice) { this->m_ToFCameraDevice = aToFCameraDevice; } ToFCameraDevice* ToFImageRecorder::GetCameraDevice() { return this->m_ToFCameraDevice; } ToFImageWriter::ToFImageType ToFImageRecorder::GetToFImageType() { return this->m_ToFImageType; } void ToFImageRecorder::SetToFImageType(ToFImageWriter::ToFImageType toFImageType) { this->m_ToFImageType = toFImageType; } ToFImageRecorder::RecordMode ToFImageRecorder::GetRecordMode() { return this->m_RecordMode; } void ToFImageRecorder::SetRecordMode(ToFImageRecorder::RecordMode recordMode) { this->m_RecordMode = recordMode; } } diff --git a/Modules/ToFHardware/mitkToFImageWriter.cpp b/Modules/ToFHardware/mitkToFImageWriter.cpp index 6f6c959fbc..e8cde63503 100644 --- a/Modules/ToFHardware/mitkToFImageWriter.cpp +++ b/Modules/ToFHardware/mitkToFImageWriter.cpp @@ -1,67 +1,67 @@ /*=================================================================== 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 // itk includes #include "itksys/SystemTools.hxx" namespace mitk { ToFImageWriter::ToFImageWriter():m_Extension(".nrrd"), m_DistanceImageFileName(), m_AmplitudeImageFileName(), m_IntensityImageFileName(), m_RGBImageFileName(), - m_NumOfFrames(0), m_DistanceImageSelected(true), m_AmplitudeImageSelected(true), - m_IntensityImageSelected(true), m_RGBImageSelected(true), m_ToFCaptureWidth(200),m_ToFCaptureHeight(200), + m_NumOfFrames(0), m_DistanceImageSelected(true), m_AmplitudeImageSelected(false), + m_IntensityImageSelected(false), m_RGBImageSelected(false), m_ToFCaptureWidth(200),m_ToFCaptureHeight(200), m_RGBCaptureWidth(200),m_RGBCaptureHeight(200), m_ToFPixelNumber(0), m_ToFImageSizeInBytes(0), m_RGBPixelNumber(0), m_RGBImageSizeInBytes(0), m_ToFImageType(ToFImageWriter::ToFImageType3D) { } ToFImageWriter::~ToFImageWriter() { } void ToFImageWriter::CheckForFileExtension(std::string& fileName) { std::string baseFilename = itksys::SystemTools::GetFilenameWithoutLastExtension( fileName ); std::string extension = itksys::SystemTools::GetFilenameLastExtension( fileName ); if( extension.length() != 0 && extension != this->m_Extension) { MITK_ERROR << "Wrong file extension! The default extension is " << this->m_Extension.c_str() << ", currently the requested file extension is " << extension.c_str() <<"!"; this->m_Extension = extension; } size_t found = fileName.find( this->m_Extension ); // !!! HAS to be at the very end of the filename (not somewhere in the middle) if( found == std::string::npos) { fileName.append(this->m_Extension); } } ToFImageWriter::ToFImageType ToFImageWriter::GetToFImageType() { return this->m_ToFImageType; } void ToFImageWriter::SetToFImageType(ToFImageWriter::ToFImageType toFImageType) { this->m_ToFImageType = toFImageType; } } // end namespace mitk