diff --git a/Modules/ToFHardware/Testing/mitkToFNrrdImageWriterTest.cpp b/Modules/ToFHardware/Testing/mitkToFNrrdImageWriterTest.cpp index 1b9cb6a2dd..57f50ae305 100644 --- a/Modules/ToFHardware/Testing/mitkToFNrrdImageWriterTest.cpp +++ b/Modules/ToFHardware/Testing/mitkToFNrrdImageWriterTest.cpp @@ -1,148 +1,148 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ Version: $Revision: $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include #include #include #include //#include //#include /**Documentation * test for the class "ToFImageWriter". */ int mitkToFNrrdImageWriterTest(int /* argc */, char* /*argv*/[]) { MITK_TEST_BEGIN("ToFNrrdImageWriter"); - //run the test with some unusual parameters - unsigned int dimX = 255; - unsigned int dimY = 188; + ////run the test with some unusual parameters + unsigned int dimX = 25; + unsigned int dimY = 18; unsigned int pixelNumber = dimX*dimY; - unsigned int numOfFrames = 1; //or numberOfSlices + unsigned int numOfFrames = 5; //or numberOfSlices - //create 3 images filled with random values - mitk::Image::Pointer distanceImage = mitk::ImageGenerator::GenerateRandomImage(dimX, dimY, numOfFrames,0, 1.0f, 1.0f); - mitk::Image::Pointer amplitudeImage = mitk::ImageGenerator::GenerateRandomImage(dimX, dimY, numOfFrames,0, 1.0f, 1.0f); - mitk::Image::Pointer intensityImage = mitk::ImageGenerator::GenerateRandomImage(dimX, dimY, numOfFrames,0, 1.0f, 1.0f); + ////create 3 images filled with random values + mitk::Image::Pointer distanceImage = mitk::ImageGenerator::GenerateRandomImage(dimX, dimY, numOfFrames,0, 1.0f, 5.0f); + mitk::Image::Pointer amplitudeImage = mitk::ImageGenerator::GenerateRandomImage(dimX, dimY, numOfFrames,0, 6.0f, 10.0f); + mitk::Image::Pointer intensityImage = mitk::ImageGenerator::GenerateRandomImage(dimX, dimY, numOfFrames,0, 11.0f, 15.0f); mitk::ToFNrrdImageWriter::Pointer tofWriter = mitk::ToFNrrdImageWriter::New(); //file names on the disc std::string distanceImageFileName("E:/distImg.nrrd"); std::string amplitudeImageFileName("E:/amplImg.nrrd"); std::string intensityImageFileName("E:/intImg.nrrd"); tofWriter->SetDistanceImageFileName(distanceImageFileName); tofWriter->SetAmplitudeImageFileName(amplitudeImageFileName); tofWriter->SetIntensityImageFileName(intensityImageFileName); MITK_TEST_CONDITION_REQUIRED(distanceImageFileName==tofWriter->GetDistanceImageFileName(), "Testing set/get distance image file name"); MITK_TEST_CONDITION_REQUIRED(amplitudeImageFileName==tofWriter->GetAmplitudeImageFileName(), "Testing set/get amplitude image file name"); MITK_TEST_CONDITION_REQUIRED(intensityImageFileName==tofWriter->GetIntensityImageFileName(), "Testing set/get intensity image file name"); tofWriter->SetCaptureWidth(dimX); tofWriter->SetCaptureHeight(dimY); MITK_TEST_CONDITION_REQUIRED(dimX==tofWriter->GetCaptureWidth(), "Testing set/get CaptureWidth"); MITK_TEST_CONDITION_REQUIRED(dimY==tofWriter->GetCaptureHeight(), "Testing set/get CaptureHeight"); tofWriter->SetToFImageType(mitk::ToFNrrdImageWriter::ToFImageType2DPlusT); MITK_TEST_CONDITION_REQUIRED(mitk::ToFNrrdImageWriter::ToFImageType2DPlusT==tofWriter->GetToFImageType(), "Testing set/get ToFImageType"); tofWriter->SetToFImageType(mitk::ToFNrrdImageWriter::ToFImageType3D); //buffer for each slice float* distanceArray; float* amplitudeArray; float* intensityArray; float* distanceArrayRead; float* amplitudeArrayRead; float* intensityArrayRead; - tofWriter->Open(); //open file/stream + tofWriter->Open(); //open file/stream //Note: the slices are written out reverse order, because the ToFImageWriter has to write them out immediately. //A PicFileWriter would write them out vice versa and the PicFileWriter reads the slices vice versa. for(unsigned int i = numOfFrames; i > 0 ; i--) { //write values to file/stream //The slice index is "i-1", because "for(unsigned int i = numOfFrames-1; i >= 0 ; i--)" does not work for some reason distanceArray = (float*)distanceImage->GetSliceData(i-1, 0, 0)->GetData(); amplitudeArray = (float*)amplitudeImage->GetSliceData(i-1, 0, 0)->GetData(); intensityArray = (float*)intensityImage->GetSliceData(i-1, 0, 0)->GetData(); //write (or add) the three slices to the file tofWriter->Add(distanceArray, amplitudeArray, intensityArray); } tofWriter->Close(); //close file //read in the three images from disc // mitk::PicFileReader::Pointer fileReader = mitk::PicFileReader::New(); // fileReader->SetFileName(distanceImageFileName); // fileReader->Update(); // mitk::Image::Pointer distanceImageRead = fileReader->GetOutput(); // // fileReader = mitk::PicFileReader::New(); // fileReader->SetFileName(amplitudeImageFileName); // fileReader->Update(); // mitk::Image::Pointer amplitudeImageRead = fileReader->GetOutput(); // // fileReader = mitk::PicFileReader::New(); // fileReader->SetFileName(intensityImageFileName); // fileReader->Update(); // mitk::Image::Pointer intensityImageRead = fileReader->GetOutput(); // // bool readingCorrect = true; // // for all frames... // for(unsigned int j=0; jGetSliceData(j, 0, 0)->GetData(); // amplitudeArray = (float*)amplitudeImage->GetSliceData(j, 0, 0)->GetData(); // intensityArray = (float*)intensityImage->GetSliceData(j, 0, 0)->GetData(); // // //data read from disc // distanceArrayRead = (float*)distanceImageRead->GetSliceData(j, 0, 0)->GetData(); // amplitudeArrayRead = (float*)amplitudeImageRead->GetSliceData(j, 0, 0)->GetData(); // intensityArrayRead = (float*)intensityImageRead->GetSliceData(j, 0, 0)->GetData(); // // //for all pixels //for(unsigned int i=0; i #include #include #include #include //Plugin defines for Camcube 2.0 #define PROC_PARAM "" extern PMDHandle m_PMDHandle; //TODO extern PMDDataDescription m_DataDescription; //TODO struct SourceDataStruct { PMDDataDescription dataDescription; char sourceData; }; namespace mitk { ToFCameraPMDMITKPlayerController::ToFCameraPMDMITKPlayerController() { m_ProcPlugin = MITK_TOF_PMDCAMCUBE_PROCESSING_PLUGIN; //MITK_TOF_PMDFILE_SOURCE_PLUGIN; // m_ProcParam = PROC_PARAM; this->m_CurrentFrame = -1; this->m_NumOfFrames = 0; } ToFCameraPMDMITKPlayerController::~ToFCameraPMDMITKPlayerController() { } bool ToFCameraPMDMITKPlayerController::OpenMITKFile() { if(this->m_InputFileName == "") { return false; } mitk::PicFileReader::Pointer reader = mitk::PicFileReader::New(); reader->SetFileName ( this->m_InputFileName.c_str() ); reader->Update(); if ( reader->GetOutput() == NULL ) { MITK_ERROR << "File " << this->m_InputFileName.c_str() << " could not be read!"; return false; } this->m_MitkImage = reader->GetOutput(); unsigned int dim = this->m_MitkImage->GetDimension(); unsigned int *dims = this->m_MitkImage->GetDimensions(); //TODO if (/*dim != 4 ||*/ dims[1] != 1 || dims[2] != 1) { MITK_ERROR << "File " << this->m_InputFileName.c_str() << " is not a ToF format!"; return false; } this->m_NumOfFrames = dims[3]; return true; } bool ToFCameraPMDMITKPlayerController::ReadFile() { this->m_PMDRes = pmdOpenProcessingPlugin (&m_PMDHandle , this->m_ProcPlugin , this->m_ProcParam ); bool ok = ErrorText(this->m_PMDRes); if (!ok) { return false; } - ok = OpenMITKFile(); + ok = this->OpenMITKFile(); if (!ok) { this->CloseCameraConnection(); return ok; } try { SourceDataStruct* sourceDataStruct = (SourceDataStruct*) this->m_MitkImage->GetSliceData(0, 0, 0)->GetData(); memcpy(&m_DataDescription, &(sourceDataStruct->dataDescription), sizeof(m_DataDescription)); this->m_CaptureWidth = m_DataDescription.img.numColumns; this->m_CaptureHeight = m_DataDescription.img.numRows; if ( this->m_CaptureWidth > 10000 || this->m_CaptureHeight > 10000 ) { MITK_ERROR << "File " << this->m_InputFileName.c_str() << " is not a ToF format!"; return false; } this->m_PixelNumber = this->m_CaptureWidth * this->m_CaptureHeight; this->m_NumberOfBytes = this->m_PixelNumber * sizeof(float); this->m_SourceDataSize = m_DataDescription.size; this->m_SourceDataStructSize = m_DataDescription.size + sizeof(PMDDataDescription); } catch (...) { MITK_ERROR << "File " << this->m_InputFileName.c_str() << " is not a ToF format!"; return false; } MITK_INFO << "Open MITK file: " << this->m_InputFileName.c_str(); return true; } bool ToFCameraPMDMITKPlayerController::OpenCameraConnection() { bool ok = false; ok = ReadFile(); if (ok) { MITK_INFO << "Datasource size: " << this->m_SourceDataSize <GetIntegrationTime(); MITK_INFO << "Modulation Frequence: " << this->GetModulationFrequency(); MITK_INFO << "NumOfFrames: " << this->m_NumOfFrames; } return ok; } bool ToFCameraPMDMITKPlayerController::CloseCameraConnection() { if(m_MitkImage.IsNotNull()) { this->m_MitkImage->ReleaseData(); } this->m_PMDRes = pmdClose(m_PMDHandle); m_ConnectionCheck = ErrorText(this->m_PMDRes); m_PMDHandle = 0; return m_ConnectionCheck; } bool ToFCameraPMDMITKPlayerController::UpdateCamera() { this->m_CurrentFrame = (this->m_CurrentFrame + 1) % this->m_NumOfFrames; itksys::SystemTools::Delay(40); return true; } bool ToFCameraPMDMITKPlayerController::GetSourceData(char* sourceDataArray) { if(this->m_CurrentFrame < 0) { MITK_ERROR<<"Invalid source data request, update camera before data retrieval!"; return false; } SourceDataStruct* sourceDataStruct = (SourceDataStruct*) this->m_MitkImage->GetSliceData(0, this->m_CurrentFrame, 0)->GetData(); if (sourceDataStruct) { memcpy(&m_DataDescription, &(sourceDataStruct->dataDescription), sizeof(m_DataDescription)); memcpy(&((SourceDataStruct*)sourceDataArray)->dataDescription, &m_DataDescription, sizeof(m_DataDescription)); memcpy(&((SourceDataStruct*)sourceDataArray)->sourceData, &sourceDataStruct->sourceData, this->m_SourceDataSize); return true; } else { return false; } } int ToFCameraPMDMITKPlayerController::SetIntegrationTime(unsigned int integrationTime) { return integrationTime; } int ToFCameraPMDMITKPlayerController::GetIntegrationTime() { int integrationTime = m_DataDescription.img.integrationTime[0]; return integrationTime; } int ToFCameraPMDMITKPlayerController::SetModulationFrequency(unsigned int modulationFrequency) { return modulationFrequency; } int ToFCameraPMDMITKPlayerController::GetModulationFrequency() { int modulationFrequency = m_DataDescription.img.modulationFrequency[0]; return (modulationFrequency/1000000); } } diff --git a/Modules/ToFHardware/mitkToFImageCsvWriter.cpp b/Modules/ToFHardware/mitkToFImageCsvWriter.cpp index f8d4e840ea..b21d6e1f5e 100644 --- a/Modules/ToFHardware/mitkToFImageCsvWriter.cpp +++ b/Modules/ToFHardware/mitkToFImageCsvWriter.cpp @@ -1,138 +1,127 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ Version: $Revision: $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include -#include +//#include namespace mitk { - ToFImageCsvWriter::ToFImageCsvWriter() + ToFImageCsvWriter::ToFImageCsvWriter(): ToFImageWriter(), m_DistanceOutfile(NULL), + m_AmplitudeOutfile(NULL), m_IntensityOutfile(NULL) { - this->m_Extension = ".csv"; - this->m_DistanceOutfile = NULL; - this->m_AmplitudeOutfile = NULL; - this->m_IntensityOutfile = NULL; - this->m_NumOfFrames = 0; - this->m_MitkImage = NULL; - this->m_ToFImageType = mitk::ToFImageWriter::ToFImageType3D; - this->m_DistanceImageSelected = true; - this->m_AmplitudeImageSelected = true; - this->m_IntensityImageSelected = true; - this->m_DistanceImageFileName = ""; - this->m_AmplitudeImageFileName = ""; - this->m_IntensityImageFileName = ""; + this->m_Extension = std::string(".csv"); } ToFImageCsvWriter::~ToFImageCsvWriter() { } void ToFImageCsvWriter::Open() { this->CheckForFileExtension(this->m_DistanceImageFileName); this->CheckForFileExtension(this->m_AmplitudeImageFileName); this->CheckForFileExtension(this->m_IntensityImageFileName); this->m_PixelNumber = this->m_CaptureWidth * this->m_CaptureHeight; this->m_ImageSizeInBytes = this->m_PixelNumber * sizeof(float); if (this->m_DistanceImageSelected) { this->OpenCsvFile(&(this->m_DistanceOutfile), this->m_DistanceImageFileName); } if (this->m_AmplitudeImageSelected) { this->OpenCsvFile(&(this->m_AmplitudeOutfile), this->m_AmplitudeImageFileName); } if (this->m_IntensityImageSelected) { this->OpenCsvFile(&(this->m_IntensityOutfile), this->m_IntensityImageFileName); } this->m_NumOfFrames = 0; } void ToFImageCsvWriter::Close() { if (this->m_DistanceImageSelected) { this->CloseCsvFile(this->m_DistanceOutfile); } if (this->m_AmplitudeImageSelected) { this->CloseCsvFile(this->m_AmplitudeOutfile); } if (this->m_IntensityImageSelected) { this->CloseCsvFile(this->m_IntensityOutfile); } } void ToFImageCsvWriter::Add(float* distanceFloatData, float* amplitudeFloatData, float* intensityFloatData) { if (this->m_DistanceImageSelected) { this->WriteCsvFile(this->m_DistanceOutfile, distanceFloatData); } if (this->m_AmplitudeImageSelected) { this->WriteCsvFile(this->m_AmplitudeOutfile, amplitudeFloatData); } if (this->m_IntensityImageSelected) { this->WriteCsvFile(this->m_IntensityOutfile, intensityFloatData); } this->m_NumOfFrames++; } void ToFImageCsvWriter::WriteCsvFile(FILE* outfile, float* floatData) { for(int i=0; im_PixelNumber; i++) { if (this->m_NumOfFrames==0 && i==0) { fprintf(outfile, "%f", floatData[i]); } else { fprintf(outfile, ",%f", floatData[i]); } } } void ToFImageCsvWriter::OpenCsvFile(FILE** outfile, std::string outfileName) { (*outfile) = fopen( outfileName.c_str(), "w+" ); if( !outfile ) { MITK_ERROR << "Error opening outfile: " << outfileName; throw std::logic_error("Error opening outfile."); return; } } void ToFImageCsvWriter::CloseCsvFile(FILE* outfile) { if (this->m_NumOfFrames == 0) { fclose(outfile); throw std::logic_error("File is empty."); return; } fclose(outfile); } } diff --git a/Modules/ToFHardware/mitkToFImageCsvWriter.h b/Modules/ToFHardware/mitkToFImageCsvWriter.h index cab4d3c577..5b6fd29484 100644 --- a/Modules/ToFHardware/mitkToFImageCsvWriter.h +++ b/Modules/ToFHardware/mitkToFImageCsvWriter.h @@ -1,85 +1,90 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ Version: $Revision: $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __mitkToFImageCsvWriter_h #define __mitkToFImageCsvWriter_h #include "mitkToFImageWriter.h" #include "mitkToFHardwareExports.h" -#include "mitkCommon.h" namespace mitk { /** * @brief CSV writer class for ToF image data * * This writer class allows streaming of ToF data into a CSV file. * Writer can simultaneously save "distance", "intensity" and "amplitude" image data. * Output files are written as 1D CSV data stream. * * @ingroup ToFHardware */ class MITK_TOFHARDWARE_EXPORT ToFImageCsvWriter : public ToFImageWriter { public: /*! \brief standard ctor */ ToFImageCsvWriter(); /*! \brief standard ~ctor */ ~ToFImageCsvWriter(); mitkClassMacro( ToFImageCsvWriter , ToFImageWriter ); itkNewMacro( Self ); /*! \brief Checks for file extensions and opens the output files */ void Open(); /*! \brief Closes the output files */ void Close(); /*! \brief Pushes the image data to the output files \param data from distance, amplitude and intensity images as float values */ void Add(float* distanceFloatData, float* amplitudeFloatData, float* intensityFloatData); protected: + Image::Pointer m_MitkImage; ///< mitk image used for pic header creation + FILE* m_DistanceOutfile; ///< file for distance image + FILE* m_AmplitudeOutfile; ///< file for amplitude image + FILE* m_IntensityOutfile; ///< file for intensity image + + private: /*! \brief opens CSV output file \param output file, name of the output file */ void OpenCsvFile(FILE** outfile, std::string outfileName); /*! \brief closes CSV output file \param output file */ void CloseCsvFile(FILE* outfile); /*! \brief writes the data to the CSV output file \param output file, data array of float values */ void WriteCsvFile(FILE* outfile, float* floatData); }; } //END mitk namespace #endif // __mitkToFImageCsvWriter_h diff --git a/Modules/ToFHardware/mitkToFImageRecorder.cpp b/Modules/ToFHardware/mitkToFImageRecorder.cpp index 8f48269697..07b4556dfe 100644 --- a/Modules/ToFHardware/mitkToFImageRecorder.cpp +++ b/Modules/ToFHardware/mitkToFImageRecorder.cpp @@ -1,242 +1,241 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ Version: $Revision: $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkToFImageRecorder.h" #include "mitkRealTimeClock.h" #include "itkMultiThreader.h" #include #include 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_ToFImageWriter = NULL; this->m_DistanceImageSelected = true; this->m_AmplitudeImageSelected = true; this->m_IntensityImageSelected = true; this->m_Abort = true; this->m_CaptureWidth = 0; this->m_CaptureHeight = 0; this->m_FileFormat = ""; this->m_PixelNumber = 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_ImageSequence = 0; this->m_DistanceArray = NULL; this->m_AmplitudeArray = NULL; this->m_IntensityArray = NULL; this->m_SourceDataArray = NULL; } ToFImageRecorder::~ToFImageRecorder() { delete[] m_DistanceArray; delete[] m_AmplitudeArray; delete[] m_IntensityArray; 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) + if (this->m_FileFormat.compare(".csv") == 0) { this->m_ToFImageWriter = ToFImageCsvWriter::New(); } - else if(this->m_FileFormat.compare("nrrd") == 0) + else if(this->m_FileFormat.compare(".nrrd") == 0) { - this->m_ToFImageWriter = ToFImageWriter::New(); + this->m_ToFImageWriter = ToFNrrdImageWriter::New(); this->m_ToFImageWriter->SetExtension(m_FileFormat); } - else if(this->m_FileFormat.compare("pic") == 0) + else if(this->m_FileFormat.compare(".pic") == 0) { - this->m_ToFImageWriter = ToFImageWriter::New(); + this->m_ToFImageWriter = ToFPicImageWriter::New(); this->m_ToFImageWriter->SetExtension(m_FileFormat); - } this->m_CaptureWidth = this->m_ToFCameraDevice->GetCaptureWidth(); this->m_CaptureHeight = this->m_ToFCameraDevice->GetCaptureHeight(); this->m_PixelNumber = this->m_CaptureWidth * this->m_CaptureHeight; this->m_SourceDataSize = this->m_ToFCameraDevice->GetSourceDataSize(); // allocate buffer if(m_IntensityArray == NULL) { this->m_IntensityArray = new float[m_PixelNumber]; } if(this->m_DistanceArray == NULL) { this->m_DistanceArray = new float[m_PixelNumber]; } if(this->m_AmplitudeArray == NULL) { this->m_AmplitudeArray = new float[m_PixelNumber]; } 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->SetCaptureWidth(this->m_CaptureWidth); this->m_ToFImageWriter->SetCaptureHeight(this->m_CaptureHeight); 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->Open(); this->m_AbortMutex->Lock(); this->m_Abort = false; this->m_AbortMutex->Unlock(); this->m_ThreadID = this->m_MultiThreader->SpawnThread(this->RecordData, this); } 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 ); 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 ); 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/mitkToFImageRecorder.h b/Modules/ToFHardware/mitkToFImageRecorder.h index 52876e0337..ace03b6deb 100644 --- a/Modules/ToFHardware/mitkToFImageRecorder.h +++ b/Modules/ToFHardware/mitkToFImageRecorder.h @@ -1,161 +1,162 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ Version: $Revision: $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __mitkToFImageRecorder_h #define __mitkToFImageRecorder_h #include "mitkToFHardwareExports.h" #include "mitkCommon.h" #include "mitkToFCameraDevice.h" -#include "mitkToFImageWriter.h" +#include "mitkToFPicImageWriter.h" #include "mitkToFImageCsvWriter.h" +#include "mitkToFNrrdImageWriter.h" #include "itkObject.h" #include "itkObjectFactory.h" #include "itkFastMutexLock.h" #include "itkCommand.h" namespace mitk { /** * @brief Recorder class for ToF images * * This class represents a recorder for ToF data. A ToFCameraDevice is used to acquire the data. The acquired images * are then added to a ToFImageWriter that performs the actual writing. * * Recording can be performed either frame-based or continuously * * @ingroup ToFHardware */ class MITK_TOFHARDWARE_EXPORT ToFImageRecorder : public itk::Object { public: ToFImageRecorder(); ~ToFImageRecorder(); mitkClassMacro( ToFImageRecorder , itk::Object ); itkNewMacro( Self ); itkGetMacro( DistanceImageFileName, std::string ); itkGetMacro( AmplitudeImageFileName, std::string ); itkGetMacro( IntensityImageFileName, std::string ); itkGetMacro( CaptureWidth, int ); itkGetMacro( CaptureHeight, int ); itkGetMacro( DistanceImageSelected, bool ); itkGetMacro( AmplitudeImageSelected, bool ); itkGetMacro( IntensityImageSelected, bool ); itkGetMacro( NumOfFrames, int ); itkGetMacro( FileFormat, std::string ); itkSetMacro( DistanceImageFileName, std::string ); itkSetMacro( AmplitudeImageFileName, std::string ); itkSetMacro( IntensityImageFileName, std::string ); itkSetMacro( DistanceImageSelected, bool ); itkSetMacro( AmplitudeImageSelected, bool ); itkSetMacro( IntensityImageSelected, bool ); itkSetMacro( NumOfFrames, int ); itkSetMacro( FileFormat, std::string ); enum RecordMode{ PerFrames, Infinite }; /*! \brief Returns the currently set RecordMode \return record mode: PerFrames ("Record specified number of frames"), Infinite ("Record until abort is required") */ ToFImageRecorder::RecordMode GetRecordMode(); /*! \brief Set the RecordMode \param recordMode: PerFrames ("Record specified number of frames"), Infinite ("Record until abort is required") */ void SetRecordMode(ToFImageRecorder::RecordMode recordMode); /*! \brief Set the device used for acquiring ToF images \param aToFCameraDevice ToF camera device used. */ void SetCameraDevice(ToFCameraDevice* aToFCameraDevice); /*! \brief Get the device used for acquiring ToF images \return ToF camera device used. */ ToFCameraDevice* GetCameraDevice(); /*! \brief Get the type of image to be recorded \return ToF image type: ToFImageType3D (0) or ToFImageType2DPlusT (1) */ ToFImageWriter::ToFImageType GetToFImageType(); /*! \brief Set the type of image to be recorded \param toFImageType type of the ToF image: ToFImageType3D (0) or ToFImageType2DPlusT (1) */ void SetToFImageType(ToFImageWriter::ToFImageType toFImageType); /*! \brief Starts the recording by spawning a Thread which streams the data to a file. Aborting of the record process is controlled by the m_Abort flag */ void StartRecording(); /*! \brief Stops the recording by setting the m_Abort flag to false */ void StopRecording(); protected: /*! \brief Thread method acquiring data via the ToFCameraDevice and recording it to file via the ToFImageWriter */ static ITK_THREAD_RETURN_TYPE RecordData(void* pInfoStruct); // data acquisition ToFCameraDevice::Pointer m_ToFCameraDevice; ///< ToFCameraDevice used for acquiring the images int m_CaptureWidth; ///< width (x-dimension) of the images to record. int m_CaptureHeight; ///< height (y-dimension) of the images to record. int m_PixelNumber; ///< number of pixels (widht*height) of the images to record int m_SourceDataSize; ///< size of the source data provided by the device int m_ImageSequence; ///< number of images currently acquired float* m_IntensityArray; ///< array holding the intensity data float* m_DistanceArray; ///< array holding the distance data float* m_AmplitudeArray; ///< array holding the amplitude data char* m_SourceDataArray; ///< array holding the source data // data writing ToFImageWriter::Pointer m_ToFImageWriter; ///< image writer writing the acquired images to a file std::string m_DistanceImageFileName; ///< file name for saving the distance image std::string m_AmplitudeImageFileName; ///< file name for saving the amplitude image std::string m_IntensityImageFileName; ///< file name for saving the intensity image int m_NumOfFrames; ///< number of frames to be recorded by this recorder ToFImageWriter::ToFImageType m_ToFImageType; ///< type of image to be recorded: ToFImageType3D (0) or ToFImageType2DPlusT (1) ToFImageRecorder::RecordMode m_RecordMode; ///< mode of recording the images: specified number of frames (PerFrames) or infinite (Infinite) std::string m_FileFormat; ///< file format for saving images. If .csv is chosen, ToFImageCsvWriter is used bool m_DistanceImageSelected; ///< flag indicating if distance image should be recorded bool m_AmplitudeImageSelected; ///< flag indicating if amplitude image should be recorded bool m_IntensityImageSelected; ///< flag indicating if intensity image should be recorded // threading itk::MultiThreader::Pointer m_MultiThreader; ///< member for thread-handling (ITK-based) int m_ThreadID; ///< ID of the thread recording the data itk::FastMutexLock::Pointer m_AbortMutex; ///< mutex for thread-safe data access of abort flag bool m_Abort; ///< flag controlling the abort mechanism of the recording procedure. For thread-safety only use in combination with m_AbortMutex private: }; } //END mitk namespace #endif diff --git a/Modules/ToFHardware/mitkToFImageWriter.cpp b/Modules/ToFHardware/mitkToFImageWriter.cpp index 06c35b220f..568b41637c 100644 --- a/Modules/ToFHardware/mitkToFImageWriter.cpp +++ b/Modules/ToFHardware/mitkToFImageWriter.cpp @@ -1,256 +1,257 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ Version: $Revision: $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include -#include +//#include #include -#include +//#include // itk includes #include "itksys/SystemTools.hxx" -extern "C" -{ -size_t _mitkIpPicFWrite( const void *ptr, size_t size, size_t nitems, mitkIpPicFile_t stream); -} +//extern "C" +//{ +//size_t _mitkIpPicFWrite( const void *ptr, size_t size, size_t nitems, mitkIpPicFile_t stream); +//} namespace mitk { - ToFImageWriter::ToFImageWriter():m_Extension(".nrrd"),m_DistanceOutfile(NULL), - m_AmplitudeOutfile(NULL), m_IntensityOutfile(NULL),m_NumOfFrames(0), - m_MitkImage(NULL),m_DistanceImageSelected(true), m_AmplitudeImageSelected(true), + ToFImageWriter::ToFImageWriter():m_Extension(".nrrd"),/*m_DistanceOutfile(NULL), + m_AmplitudeOutfile(NULL), m_IntensityOutfile(NULL),*/m_NumOfFrames(0), + /* m_MitkImage(NULL),*/m_DistanceImageSelected(true), m_AmplitudeImageSelected(true), m_IntensityImageSelected(true),m_CaptureWidth(200),m_CaptureHeight(200), m_PixelNumber(0), m_ImageSizeInBytes(0), m_ToFImageType(ToFImageWriter::ToFImageType3D) { } ToFImageWriter::~ToFImageWriter() { } - void ToFImageWriter::Open() - { - this->CheckForFileExtension(this->m_DistanceImageFileName); - this->CheckForFileExtension(this->m_AmplitudeImageFileName); - this->CheckForFileExtension(this->m_IntensityImageFileName); - - this->m_PixelNumber = this->m_CaptureWidth * this->m_CaptureHeight; - this->m_ImageSizeInBytes = this->m_PixelNumber * sizeof(float); - float* floatData = new float[this->m_PixelNumber]; - for(int i=0; im_PixelNumber; i++) - { - floatData[i] = i + 0.0; - } - - this->m_MitkImage = Image::New(); - unsigned int dimensions[4]; - dimensions[0] = this->m_CaptureWidth; - dimensions[1] = this->m_CaptureHeight; - if (this->m_ToFImageType == ToFImageWriter::ToFImageType2DPlusT) - { - dimensions[2] = 1; - dimensions[3] = 2; - this->m_MitkImage->Initialize( PixelType(typeid(float)), 4, dimensions, 1); - } - else - { - dimensions[2] = 2; - dimensions[3] = 1; - this->m_MitkImage->Initialize( PixelType(typeid(float)), 3, dimensions, 1); - } - this->m_MitkImage->SetSlice(floatData, 0, 0, 0); - - - //ImageWriter::Pointer imageWriter = ImageWriter::New(); - // if (this->m_DistanceImageSelected) - // { - // imageWriter->SetFileName(this->m_DistanceImageFileName); - // imageWriter->SetInputImage(); - // imageWriter->SetExtension(this->m_Extension); - // imageWriter->Modified(); - // imageWriter->Update(); - // } - // if (this->m_AmplitudeImageSelected) - // { - // imageWriter->SetFileName(this->m_AmplitudeImageFileName); - // imageWriter->SetInputImage(); - // imageWriter->SetExtension(this->m_Extension); - // imageWriter->Modified(); - // imageWriter->Update(); - // } - // if (this->m_IntensityImageSelected) - // { - // imageWriter->SetFileName(this->m_IntensityImageFileName); - // imageWriter->SetInputImage(); - // imageWriter->SetExtension(this->m_Extension); - // imageWriter->Modified(); - // imageWriter->Update(); - // } - - mitkIpPicDescriptor* pic = this->m_MitkImage->GetPic(); - - if (this->m_DistanceImageSelected) - { - this->OpenPicFile(&(this->m_DistanceOutfile), this->m_DistanceImageFileName); - this->WritePicFileHeader(this->m_DistanceOutfile, pic); - } - if (this->m_AmplitudeImageSelected) - { - this->OpenPicFile(&(this->m_AmplitudeOutfile), this->m_AmplitudeImageFileName); - this->WritePicFileHeader(this->m_AmplitudeOutfile, pic); - } - if (this->m_IntensityImageSelected) - { - this->OpenPicFile(&(this->m_IntensityOutfile), this->m_IntensityImageFileName); - this->WritePicFileHeader(this->m_IntensityOutfile, pic); - } - this->m_NumOfFrames = 0; - delete[] floatData; - } - - void ToFImageWriter::Close() - { - if (this->m_DistanceImageSelected) - { - this->ClosePicFile(this->m_DistanceOutfile); - } - if (this->m_AmplitudeImageSelected) - { - this->ClosePicFile(this->m_AmplitudeOutfile); - } - if (this->m_IntensityImageSelected) - { - this->ClosePicFile(this->m_IntensityOutfile); - } - } - - void ToFImageWriter::Add(float* distanceFloatData, float* amplitudeFloatData, float* intensityFloatData) - { - if (this->m_DistanceImageSelected) - { - fwrite( distanceFloatData, this->m_ImageSizeInBytes, 1, this->m_DistanceOutfile ); - } - if (this->m_AmplitudeImageSelected) - { - fwrite( amplitudeFloatData, this->m_ImageSizeInBytes, 1, this->m_AmplitudeOutfile ); - } - if (this->m_IntensityImageSelected) - { - fwrite( intensityFloatData, this->m_ImageSizeInBytes, 1, this->m_IntensityOutfile ); - } - this->m_NumOfFrames++; - } - - void ToFImageWriter::OpenPicFile(FILE** outfile,std::string outfileName) - { - (*outfile) = fopen( outfileName.c_str(), "w+b" ); - if( !outfile ) // if fopen_s was not successful! - { - MITK_ERROR << "Error opening outfile: " << outfileName; - throw std::logic_error("Error opening outfile."); - return; - } - } - - void ToFImageWriter::ClosePicFile(FILE* outfile) - { - if (this->m_NumOfFrames == 0) - { - fclose(outfile); - throw std::logic_error("File is empty."); - return; - } - this->ReplacePicFileHeader(outfile); - fclose(outfile); - } - - void ToFImageWriter::ReplacePicFileHeader(FILE* outfile) - { - mitkIpPicDescriptor* pic = this->m_MitkImage->GetPic(); - - if (this->m_ToFImageType == ToFImageWriter::ToFImageType2DPlusT) - { - pic->dim = 4; - pic->n[2] = 1; - pic->n[3] = this->m_NumOfFrames; - } - else - { - pic->dim = 3; - pic->n[2] = this->m_NumOfFrames; - pic->n[3] = 1; - } - - fseek ( outfile, 0, SEEK_SET ); - - this->WritePicFileHeader( outfile, pic ); - } - - void ToFImageWriter::WritePicFileHeader(FILE* outfile, mitkIpPicDescriptor* pic) - { - mitkIpUInt4_t len; - mitkIpUInt4_t tagsLen; - - tagsLen = _mitkIpPicTagsSize( pic->info->tags_head ); - len = tagsLen + 3 * sizeof(mitkIpUInt4_t) + pic->dim * sizeof(mitkIpUInt4_t); - /* write oufile */ - if( mitkIpPicEncryptionType(pic) == ' ' ) - mitkIpPicFWrite( mitkIpPicVERSION, 1, sizeof(mitkIpPicTag_t), outfile ); - else - mitkIpPicFWrite( pic->info->version, 1, sizeof(mitkIpPicTag_t), outfile ); - - mitkIpPicFWriteLE( &len, sizeof(mitkIpUInt4_t), 1, outfile ); - - mitkIpPicFWriteLE( &(pic->type), sizeof(mitkIpUInt4_t), 1, outfile ); - mitkIpPicFWriteLE( &(pic->bpe), sizeof(mitkIpUInt4_t), 1, outfile ); - mitkIpPicFWriteLE( &(pic->dim), sizeof(mitkIpUInt4_t), 1, outfile ); - - mitkIpPicFWriteLE( pic->n, sizeof(mitkIpUInt4_t), pic->dim, outfile ); - - _mitkIpPicWriteTags( pic->info->tags_head, outfile, mitkIpPicEncryptionType(pic) ); - pic->info->pixel_start_in_file = ftell( outfile ); - } + //void ToFImageWriter::Open() + //{ + // this->CheckForFileExtension(this->m_DistanceImageFileName); + // this->CheckForFileExtension(this->m_AmplitudeImageFileName); + // this->CheckForFileExtension(this->m_IntensityImageFileName); + + // this->m_PixelNumber = this->m_CaptureWidth * this->m_CaptureHeight; + // this->m_ImageSizeInBytes = this->m_PixelNumber * sizeof(float); + // float* floatData = new float[this->m_PixelNumber]; + // for(int i=0; im_PixelNumber; i++) + // { + // floatData[i] = i + 0.0; + // } + + // this->m_MitkImage = Image::New(); + // unsigned int dimensions[4]; + // dimensions[0] = this->m_CaptureWidth; + // dimensions[1] = this->m_CaptureHeight; + // if (this->m_ToFImageType == ToFImageWriter::ToFImageType2DPlusT) + // { + // dimensions[2] = 1; + // dimensions[3] = 2; + // this->m_MitkImage->Initialize( PixelType(typeid(float)), 4, dimensions, 1); + // } + // else + // { + // dimensions[2] = 2; + // dimensions[3] = 1; + // this->m_MitkImage->Initialize( PixelType(typeid(float)), 3, dimensions, 1); + // } + // this->m_MitkImage->SetSlice(floatData, 0, 0, 0); + + + // //ImageWriter::Pointer imageWriter = ImageWriter::New(); + // // if (this->m_DistanceImageSelected) + // // { + // // imageWriter->SetFileName(this->m_DistanceImageFileName); + // // imageWriter->SetInputImage(); + // // imageWriter->SetExtension(this->m_Extension); + // // imageWriter->Modified(); + // // imageWriter->Update(); + // // } + // // if (this->m_AmplitudeImageSelected) + // // { + // // imageWriter->SetFileName(this->m_AmplitudeImageFileName); + // // imageWriter->SetInputImage(); + // // imageWriter->SetExtension(this->m_Extension); + // // imageWriter->Modified(); + // // imageWriter->Update(); + // // } + // // if (this->m_IntensityImageSelected) + // // { + // // imageWriter->SetFileName(this->m_IntensityImageFileName); + // // imageWriter->SetInputImage(); + // // imageWriter->SetExtension(this->m_Extension); + // // imageWriter->Modified(); + // // imageWriter->Update(); + // // } + + // mitkIpPicDescriptor* pic = this->m_MitkImage->GetPic(); + + // if (this->m_DistanceImageSelected) + // { + // this->OpenPicFile(&(this->m_DistanceOutfile), this->m_DistanceImageFileName); + // this->WritePicFileHeader(this->m_DistanceOutfile, pic); + // } + // if (this->m_AmplitudeImageSelected) + // { + // this->OpenPicFile(&(this->m_AmplitudeOutfile), this->m_AmplitudeImageFileName); + // this->WritePicFileHeader(this->m_AmplitudeOutfile, pic); + // } + // if (this->m_IntensityImageSelected) + // { + // this->OpenPicFile(&(this->m_IntensityOutfile), this->m_IntensityImageFileName); + // this->WritePicFileHeader(this->m_IntensityOutfile, pic); + // } + // this->m_NumOfFrames = 0; + // delete[] floatData; + //} + + //void ToFImageWriter::Close() + //{ + // //if (this->m_DistanceImageSelected) + // //{ + // // this->ClosePicFile(this->m_DistanceOutfile); + // //} + // //if (this->m_AmplitudeImageSelected) + // //{ + // // this->ClosePicFile(this->m_AmplitudeOutfile); + // //} + // //if (this->m_IntensityImageSelected) + // //{ + // // this->ClosePicFile(this->m_IntensityOutfile); + // //} + //} + + //void ToFImageWriter::Add(float* distanceFloatData, float* amplitudeFloatData, float* intensityFloatData) + //{ + // //if (this->m_DistanceImageSelected) + // //{ + // // fwrite( distanceFloatData, this->m_ImageSizeInBytes, 1, this->m_DistanceOutfile ); + // //} + // //if (this->m_AmplitudeImageSelected) + // //{ + // // fwrite( amplitudeFloatData, this->m_ImageSizeInBytes, 1, this->m_AmplitudeOutfile ); + // //} + // //if (this->m_IntensityImageSelected) + // //{ + // // fwrite( intensityFloatData, this->m_ImageSizeInBytes, 1, this->m_IntensityOutfile ); + // //} + // //this->m_NumOfFrames++; + //} + + //void ToFImageWriter::OpenPicFile(FILE** outfile,std::string outfileName) + //{ + // (*outfile) = fopen( outfileName.c_str(), "w+b" ); + // if( !outfile ) // if fopen_s was not successful! + // { + // MITK_ERROR << "Error opening outfile: " << outfileName; + // throw std::logic_error("Error opening outfile."); + // return; + // } + //} + + //void ToFImageWriter::ClosePicFile(FILE* outfile) + //{ + // if (this->m_NumOfFrames == 0) + // { + // fclose(outfile); + // throw std::logic_error("File is empty."); + // return; + // } + // this->ReplacePicFileHeader(outfile); + // fclose(outfile); + //} + + //void ToFImageWriter::ReplacePicFileHeader(FILE* outfile) + //{ + // mitkIpPicDescriptor* pic = this->m_MitkImage->GetPic(); + + // if (this->m_ToFImageType == ToFImageWriter::ToFImageType2DPlusT) + // { + // pic->dim = 4; + // pic->n[2] = 1; + // pic->n[3] = this->m_NumOfFrames; + // } + // else + // { + // pic->dim = 3; + // pic->n[2] = this->m_NumOfFrames; + // pic->n[3] = 1; + // } + + // fseek ( outfile, 0, SEEK_SET ); + + // this->WritePicFileHeader( outfile, pic ); + //} + + //void ToFImageWriter::WritePicFileHeader(FILE* outfile, mitkIpPicDescriptor* pic) + //{ + // mitkIpUInt4_t len; + // mitkIpUInt4_t tagsLen; + + // tagsLen = _mitkIpPicTagsSize( pic->info->tags_head ); + // len = tagsLen + 3 * sizeof(mitkIpUInt4_t) + pic->dim * sizeof(mitkIpUInt4_t); + // /* write oufile */ + // if( mitkIpPicEncryptionType(pic) == ' ' ) + // mitkIpPicFWrite( mitkIpPicVERSION, 1, sizeof(mitkIpPicTag_t), outfile ); + // else + // mitkIpPicFWrite( pic->info->version, 1, sizeof(mitkIpPicTag_t), outfile ); + + // mitkIpPicFWriteLE( &len, sizeof(mitkIpUInt4_t), 1, outfile ); + + // mitkIpPicFWriteLE( &(pic->type), sizeof(mitkIpUInt4_t), 1, outfile ); + // mitkIpPicFWriteLE( &(pic->bpe), sizeof(mitkIpUInt4_t), 1, outfile ); + // mitkIpPicFWriteLE( &(pic->dim), sizeof(mitkIpUInt4_t), 1, outfile ); + + // mitkIpPicFWriteLE( pic->n, sizeof(mitkIpUInt4_t), pic->dim, outfile ); + + // _mitkIpPicWriteTags( pic->info->tags_head, outfile, mitkIpPicEncryptionType(pic) ); + // pic->info->pixel_start_in_file = ftell( outfile ); + //} 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; - found = fileName.find( this->m_Extension ); // !!! HAS to be at the very end of the filename (not somewhere in the middle) - if( fileName.length() > 3 && found != fileName.length() - this->m_Extension.length() ) + 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 diff --git a/Modules/ToFHardware/mitkToFImageWriter.h b/Modules/ToFHardware/mitkToFImageWriter.h index 150aecd154..831521c9f8 100644 --- a/Modules/ToFHardware/mitkToFImageWriter.h +++ b/Modules/ToFHardware/mitkToFImageWriter.h @@ -1,147 +1,146 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ Version: $Revision: $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __mitkToFImageWriter_h #define __mitkToFImageWriter_h #include "mitkToFHardwareExports.h" #include "mitkCommon.h" #include "mitkToFImageGrabber.h" #include "itkObject.h" #include "itkObjectFactory.h" namespace mitk { /** * @brief Writer class for ToF images * * This writer class allows streaming of ToF data into a file. The .pic file format is used for writing the data. * Image information is included in the header of the pic file. * Writer can simultaneously save "distance", "intensity" and "amplitude" image. * Images can be written as 3D volume (ToFImageType::ToFImageType3D) or temporal image stack (ToFImageType::ToFImageType2DPlusT) * * @ingroup ToFHardware */ class MITK_TOFHARDWARE_EXPORT ToFImageWriter : public itk::Object { public: ToFImageWriter(); ~ToFImageWriter(); mitkClassMacro( ToFImageWriter , itk::Object ); itkNewMacro( Self ); itkGetMacro( DistanceImageFileName, std::string ); itkGetMacro( AmplitudeImageFileName, std::string ); itkGetMacro( IntensityImageFileName, std::string ); itkGetMacro( Extension, std::string ); itkGetMacro( CaptureWidth, int ); itkGetMacro( CaptureHeight, int ); itkGetMacro( DistanceImageSelected, bool ); itkGetMacro( AmplitudeImageSelected, bool ); itkGetMacro( IntensityImageSelected, bool ); itkSetMacro( DistanceImageFileName, std::string ); itkSetMacro( AmplitudeImageFileName, std::string ); itkSetMacro( IntensityImageFileName, std::string ); itkSetMacro( Extension, std::string ); itkSetMacro( CaptureWidth, int ); itkSetMacro( CaptureHeight, int ); itkSetMacro( DistanceImageSelected, bool ); itkSetMacro( AmplitudeImageSelected, bool ); itkSetMacro( IntensityImageSelected, bool ); enum ToFImageType{ ToFImageType3D, ToFImageType2DPlusT }; /*! \brief Get the type of image to be written \return ToF image type: ToFImageType3D (0) or ToFImageType2DPlusT (1) */ ToFImageWriter::ToFImageType GetToFImageType(); /*! \brief Set the type of image to be written \param toFImageType type of the ToF image: ToFImageType3D (0) or ToFImageType2DPlusT (1) */ void SetToFImageType(ToFImageWriter::ToFImageType toFImageType); /*! \brief Open file(s) for writing */ - virtual void Open(); + virtual void Open(){}; /*! \brief Close file(s) add .pic header and write */ - virtual void Close(); + virtual void Close(){}; /*! \brief Add new data to file. */ - virtual void Add(float* distanceFloatData, float* amplitudeFloatData, float* intensityFloatData); + virtual void Add(float* distanceFloatData, float* amplitudeFloatData, float* intensityFloatData){}; protected: /*! \brief Checks file name if file extension exists. If not .pic is added to fileName \param fileName file name to be checked */ void CheckForFileExtension(std::string& fileName); std::string m_DistanceImageFileName; ///< file name for saving the distance image std::string m_AmplitudeImageFileName; ///< file name for saving the amplitude image std::string m_IntensityImageFileName; ///< file name for saving the intensity image std::string m_Extension; ///< file extension used for saving images int m_CaptureWidth; ///< width (x-dimension) of the images to record. int m_CaptureHeight; ///< height (y-dimension) of the images to record. int m_PixelNumber; ///< number of pixels (widht*height) of the images to record int m_ImageSizeInBytes; ///< size of the image to save in bytes int m_NumOfFrames; ///< number of frames written to the image. Used for pic header. ToFImageWriter::ToFImageType m_ToFImageType; ///< type of image to be recorded: ToFImageType3D (0) or ToFImageType2DPlusT (1) bool m_DistanceImageSelected; ///< flag indicating if distance image should be recorded bool m_AmplitudeImageSelected; ///< flag indicating if amplitude image should be recorded bool m_IntensityImageSelected; ///< flag indicating if intensity image should be recorded - Image::Pointer m_MitkImage; ///< mitk image used for pic header creation - FILE* m_DistanceOutfile; ///< file for distance image - FILE* m_AmplitudeOutfile; ///< file for amplitude image - FILE* m_IntensityOutfile; ///< file for intensity image + //Image::Pointer m_MitkImage; ///< mitk image used for pic header creation + //FILE* m_DistanceOutfile; ///< file for distance image + //FILE* m_AmplitudeOutfile; ///< file for amplitude image + //FILE* m_IntensityOutfile; ///< file for intensity image private: - /*! - \brief Open file by filename to gain write access to it. - */ - void OpenPicFile(FILE** outfile, std::string outfileName); - /*! - \brief Close file after work on it is finished. - */ - void ClosePicFile(FILE* outfile); - /*! - \brief Replace current PicFileHeader information. - */ - void ReplacePicFileHeader(FILE* outfile); - /*! - \brief Write image information to the PicFileHeader. - */ - void WritePicFileHeader(FILE* outfile, mitkIpPicDescriptor* pic); - + ///*! + //\brief Open file by filename to gain write access to it. + //*/ + //void OpenPicFile(FILE** outfile, std::string outfileName); + ///*! + //\brief Close file after work on it is finished. + //*/ + //void ClosePicFile(FILE* outfile); + ///*! + //\brief Replace current PicFileHeader information. + //*/ + //void ReplacePicFileHeader(FILE* outfile); + ///*! + //\brief Write image information to the PicFileHeader. + //*/ + //void WritePicFileHeader(FILE* outfile, mitkIpPicDescriptor* pic); }; } //END mitk namespace #endif // __mitkToFImageWriter_h diff --git a/Modules/ToFHardware/mitkToFNrrdImageWriter.cpp b/Modules/ToFHardware/mitkToFNrrdImageWriter.cpp index 06e9c778f1..9c2a9c9bf6 100644 --- a/Modules/ToFHardware/mitkToFNrrdImageWriter.cpp +++ b/Modules/ToFHardware/mitkToFNrrdImageWriter.cpp @@ -1,236 +1,251 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ Version: $Revision: $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include -#include +//#include #include -#include +//#include // itk includes #include "itksys/SystemTools.hxx" #include "itkNrrdImageIO.h" - -//extern "C" -//{ -//size_t _mitkIpPicFWrite( const void *ptr, size_t size, size_t nitems, mitkIpPicFile_t stream); -//} +//#include "itkImageIOBase.h" namespace mitk { - ToFNrrdImageWriter::ToFNrrdImageWriter():m_Extension(".nrrd"), - m_DistanceOutfile(), m_AmplitudeOutfile(), m_IntensityOutfile(), - m_NumOfFrames(0), m_DistanceImageSelected(true), m_AmplitudeImageSelected(true), m_IntensityImageSelected(true), - m_CaptureWidth(200), m_CaptureHeight(200), m_PixelNumber(0), m_ImageSizeInBytes(0), - m_ToFImageType(ToFNrrdImageWriter::ToFImageType3D) + ToFNrrdImageWriter::ToFNrrdImageWriter(): ToFImageWriter(), + m_DistanceOutfile(), m_AmplitudeOutfile(), m_IntensityOutfile() { + m_Extension = std::string(".nrrd"); } ToFNrrdImageWriter::~ToFNrrdImageWriter() { } void ToFNrrdImageWriter::Open() { this->CheckForFileExtension(this->m_DistanceImageFileName); this->CheckForFileExtension(this->m_AmplitudeImageFileName); this->CheckForFileExtension(this->m_IntensityImageFileName); this->m_PixelNumber = this->m_CaptureWidth * this->m_CaptureHeight; this->m_ImageSizeInBytes = this->m_PixelNumber * sizeof(float); if (this->m_DistanceImageSelected) { - this->OpenStreamFile(this->m_DistanceOutfile, this->m_DistanceImageFileName); + this->OpenStreamFile( this->m_DistanceOutfile, this->m_DistanceImageFileName); } if (this->m_AmplitudeImageSelected) { this->OpenStreamFile(this->m_AmplitudeOutfile, this->m_AmplitudeImageFileName); } if (this->m_IntensityImageSelected) { this->OpenStreamFile(this->m_IntensityOutfile, this->m_IntensityImageFileName); } this->m_NumOfFrames = 0; } void ToFNrrdImageWriter::Close() { if (this->m_DistanceImageSelected) { this->CloseStreamFile(this->m_DistanceOutfile, this->m_DistanceImageFileName); } if (this->m_AmplitudeImageSelected) { this->CloseStreamFile(this->m_AmplitudeOutfile, this->m_AmplitudeImageFileName); } if (this->m_IntensityImageSelected) { this->CloseStreamFile(this->m_IntensityOutfile, this->m_IntensityImageFileName); } } - void ToFNrrdImageWriter::CheckForFileExtension(std::string& fileName) - { - std::string baseFilename = itksys::SystemTools::GetFilenameWithoutLastExtension( fileName ); - std::string extension = itksys::SystemTools::GetFilenameLastExtension( fileName ); + //void ToFNrrdImageWriter::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) - { - this->m_Extension = extension; - } + // if( extension.length() != 0 && extension != this->m_Extension) + // { + // 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( fileName.length() > 3 && found != fileName.length() - this->m_Extension.length() ) + // { + // fileName.append(this->m_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( fileName.length() > 3 && found != fileName.length() - this->m_Extension.length() ) - { - fileName.append(this->m_Extension); - } - } void ToFNrrdImageWriter::Add(float* distanceFloatData, float* amplitudeFloatData, float* intensityFloatData) { if (this->m_DistanceImageSelected) { - this->m_DistanceOutfile->write(( char* ) distanceFloatData, this->m_ImageSizeInBytes); + this->m_DistanceOutfile.write( (char*) distanceFloatData, this->m_ImageSizeInBytes); } if (this->m_AmplitudeImageSelected) { - this->m_AmplitudeOutfile->write(( char* )amplitudeFloatData, this->m_ImageSizeInBytes); + this->m_AmplitudeOutfile.write( (char*)amplitudeFloatData, this->m_ImageSizeInBytes); } if (this->m_IntensityImageSelected) { - this->m_IntensityOutfile->write(( char* )intensityFloatData, this->m_ImageSizeInBytes); + this->m_IntensityOutfile.write(( char* )intensityFloatData, this->m_ImageSizeInBytes); } this->m_NumOfFrames++; } - void ToFNrrdImageWriter::OpenStreamFile( std::ofstream* &outfile, std::string outfileName ) + void ToFNrrdImageWriter::OpenStreamFile( std::ofstream &outfile, std::string outfileName ) { - outfile = new std::ofstream(outfileName.c_str()); - if(! outfile) + outfile.open(outfileName.c_str(), std::ofstream::binary); + if(!outfile.is_open()) { MITK_ERROR << "Error opening outfile: " << outfileName; throw std::logic_error("Error opening outfile."); return; } } - void ToFNrrdImageWriter::CloseStreamFile( std::ofstream* &outfile, std::string fileName ) + void ToFNrrdImageWriter::CloseStreamFile( std::ofstream &outfile, std::string fileName ) { if (this->m_NumOfFrames == 0) { - outfile->close(); + outfile.close(); throw std::logic_error("File is empty."); return; } - // TODO set data to itk::NrrdImageIO and write it to file! - this->ConvertStreamToNrrdFormat(outfile, fileName); - outfile->close(); + // flush the last data to the file and convert the stream data to Nrrd file + outfile.flush(); + this->ConvertStreamToNrrdFormat( fileName ); + outfile.close(); } - void ToFNrrdImageWriter::ConvertStreamToNrrdFormat(std::ofstream* outfile, std::string fileName) + void ToFNrrdImageWriter::ConvertStreamToNrrdFormat( std::string fileName ) { + float* floatData = new float[this->m_PixelNumber]; for(int i=0; im_PixelNumber; i++) { floatData[i] = i + 0.0; } Image::Pointer imageTemplate = Image::New(); - int dimension ; unsigned int* dimensions; if(m_ToFImageType == ToFImageType2DPlusT) { dimension = 4; dimensions = new unsigned int[dimension]; dimensions[0] = this->m_CaptureWidth; dimensions[1] = this->m_CaptureHeight; dimensions[2] = 1; dimensions[3] = this->m_NumOfFrames; } else if( m_ToFImageType == ToFImageType3D) { dimension = 3; dimensions = new unsigned int[dimension]; dimensions[0] = this->m_CaptureWidth; dimensions[1] = this->m_CaptureHeight; dimensions[2] = this->m_NumOfFrames; } else { throw std::logic_error("No image type set, please choose between 2D+t and 3D!"); } imageTemplate->Initialize( PixelType(typeid(float)),dimension, dimensions, 1); imageTemplate->SetSlice(floatData, 0, 0, 0); itk::NrrdImageIO::Pointer nrrdWriter = itk::NrrdImageIO::New(); nrrdWriter->SetNumberOfDimensions(dimension); nrrdWriter->SetPixelTypeInfo(*(imageTemplate->GetPixelType().GetTypeId())); if(imageTemplate->GetPixelType().GetNumberOfComponents() > 1) { nrrdWriter->SetNumberOfComponents(imageTemplate->GetPixelType().GetNumberOfComponents()); } itk::ImageIORegion ioRegion( dimension ); mitk::Vector3D spacing = imageTemplate->GetGeometry()->GetSpacing(); mitk::Point3D origin = imageTemplate->GetGeometry()->GetOrigin(); - for(unsigned int i=0; iSetDimensions(i,dimensions[i]); nrrdWriter->SetSpacing(i,spacing[i]); nrrdWriter->SetOrigin(i,origin[i]); mitk::Vector3D direction; direction.Set_vnl_vector(imageTemplate->GetGeometry()->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(i)); vnl_vector< double > axisDirection(dimension); - for(unsigned int j=0; jSetDirection( i, axisDirection ); ioRegion.SetSize(i, imageTemplate->GetLargestPossibleRegion().GetSize(i) ); ioRegion.SetIndex(i, imageTemplate->GetLargestPossibleRegion().GetIndex(i) ); } nrrdWriter->SetIORegion(ioRegion); nrrdWriter->SetFileName(fileName); nrrdWriter->SetUseStreamedWriting(true); - const void * data = (void*) outfile; + std::ifstream stream(fileName.c_str(), std::ifstream::binary); + unsigned int size = this->m_PixelNumber * this->m_NumOfFrames; + unsigned int sizeInBytes = size * sizeof(float); + float* data = new float[size]; + + //int count = 0; + //while(count < size) + //{ + // data[count] = 0.0f; + // count++; + //} + stream.read((char*)data, sizeInBytes); + + //count = 0; + //while(count < size) + //{ + // MITK_INFO<< "data at " << count << " = " << data[count]; + // count++; + //} nrrdWriter->Write(data); + stream.close(); + delete[] data; delete[] dimensions; delete[] floatData; - } - ToFNrrdImageWriter::ToFImageType ToFNrrdImageWriter::GetToFImageType() - { - return this->m_ToFImageType; - } + //ToFNrrdImageWriter::ToFImageType ToFNrrdImageWriter::GetToFImageType() + //{ + // return this->m_ToFImageType; + //} - void ToFNrrdImageWriter::SetToFImageType(ToFNrrdImageWriter::ToFImageType toFImageType) - { - this->m_ToFImageType = toFImageType; - } + //void ToFNrrdImageWriter::SetToFImageType(ToFNrrdImageWriter::ToFImageType toFImageType) + //{ + // this->m_ToFImageType = toFImageType; + //} } // end namespace mitk diff --git a/Modules/ToFHardware/mitkToFNrrdImageWriter.h b/Modules/ToFHardware/mitkToFNrrdImageWriter.h index 7dd51b6953..acdc22eef0 100644 --- a/Modules/ToFHardware/mitkToFNrrdImageWriter.h +++ b/Modules/ToFHardware/mitkToFNrrdImageWriter.h @@ -1,146 +1,139 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ Version: $Revision: $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __mitkToFNrrdImageWriter_h #define __mitkToFNrrdImageWriter_h -#include "mitkToFHardwareExports.h" -#include "mitkCommon.h" -#include "mitkToFImageGrabber.h" +//#include "mitkToFHardwareExports.h" +//#include "mitkCommon.h" +//#include "mitkToFImageGrabber.h" +#include "mitkToFImageWriter.h" -#include "itkObject.h" -#include "itkObjectFactory.h" +//#include "itkObject.h" +//#include "itkObjectFactory.h" namespace mitk { /** * @brief Writer class for ToF images * * This writer class allows streaming of ToF data into a file. The .pic file format is used for writing the data. * Image information is included in the header of the pic file. * Writer can simultaneously save "distance", "intensity" and "amplitude" image. * Images can be written as 3D volume (ToFImageType::ToFImageType3D) or temporal image stack (ToFImageType::ToFImageType2DPlusT) * * @ingroup ToFHardware */ - class MITK_TOFHARDWARE_EXPORT ToFNrrdImageWriter : public itk::Object + class MITK_TOFHARDWARE_EXPORT ToFNrrdImageWriter : public ToFImageWriter { public: - mitkClassMacro( ToFNrrdImageWriter , itk::Object ); + mitkClassMacro( ToFNrrdImageWriter , ToFImageWriter ); itkNewMacro( Self ); - itkGetMacro( DistanceImageFileName, std::string ); - itkGetMacro( AmplitudeImageFileName, std::string ); - itkGetMacro( IntensityImageFileName, std::string ); - itkGetMacro( Extension, std::string ); - itkGetMacro( CaptureWidth, int ); - itkGetMacro( CaptureHeight, int ); - itkGetMacro( DistanceImageSelected, bool ); - itkGetMacro( AmplitudeImageSelected, bool ); - itkGetMacro( IntensityImageSelected, bool ); - - itkSetMacro( DistanceImageFileName, std::string ); - itkSetMacro( AmplitudeImageFileName, std::string ); - itkSetMacro( IntensityImageFileName, std::string ); - itkSetMacro( Extension, std::string ); - itkSetMacro( CaptureWidth, int ); - itkSetMacro( CaptureHeight, int ); - itkSetMacro( DistanceImageSelected, bool ); - itkSetMacro( AmplitudeImageSelected, bool ); - itkSetMacro( IntensityImageSelected, bool ); - - enum ToFImageType{ ToFImageType3D, ToFImageType2DPlusT }; - /*! - \brief Get the type of image to be written - \return ToF image type: ToFImageType3D (0) or ToFImageType2DPlusT (1) - */ - ToFNrrdImageWriter::ToFImageType GetToFImageType(); - /*! - \brief Set the type of image to be written - \param toFImageType type of the ToF image: ToFImageType3D (0) or ToFImageType2DPlusT (1) - */ - void SetToFImageType(ToFNrrdImageWriter::ToFImageType toFImageType); + //itkGetMacro( DistanceImageFileName, std::string ); + //itkGetMacro( AmplitudeImageFileName, std::string ); + //itkGetMacro( IntensityImageFileName, std::string ); + //itkGetMacro( Extension, std::string ); + //itkGetMacro( CaptureWidth, int ); + //itkGetMacro( CaptureHeight, int ); + //itkGetMacro( DistanceImageSelected, bool ); + //itkGetMacro( AmplitudeImageSelected, bool ); + //itkGetMacro( IntensityImageSelected, bool ); + + //itkSetMacro( DistanceImageFileName, std::string ); + //itkSetMacro( AmplitudeImageFileName, std::string ); + //itkSetMacro( IntensityImageFileName, std::string ); + //itkSetMacro( Extension, std::string ); + //itkSetMacro( CaptureWidth, int ); + //itkSetMacro( CaptureHeight, int ); + //itkSetMacro( DistanceImageSelected, bool ); + //itkSetMacro( AmplitudeImageSelected, bool ); + //itkSetMacro( IntensityImageSelected, bool ); + + //enum ToFImageType{ ToFImageType3D, ToFImageType2DPlusT }; + ///*! + //\brief Get the type of image to be written + //\return ToF image type: ToFImageType3D (0) or ToFImageType2DPlusT (1) + //*/ + //ToFNrrdImageWriter::ToFImageType GetToFImageType(); + ///*! + //\brief Set the type of image to be written + //\param toFImageType type of the ToF image: ToFImageType3D (0) or ToFImageType2DPlusT (1) + //*/ + //void SetToFImageType(ToFNrrdImageWriter::ToFImageType toFImageType); /*! \brief Open file(s) for writing */ - virtual void Open(); + void Open(); /*! \brief Close file(s) add .pic header and write */ - virtual void Close(); + void Close(); /*! \brief Add new data to file. */ - virtual void Add(float* distanceFloatData, float* amplitudeFloatData, float* intensityFloatData); + void Add(float* distanceFloatData, float* amplitudeFloatData, float* intensityFloatData); protected: /*! \brief Checks file name if file extension exists. If not .pic is added to fileName \param fileName file name to be checked */ - void CheckForFileExtension(std::string& fileName); - - std::string m_DistanceImageFileName; ///< file name for saving the distance image - std::string m_AmplitudeImageFileName; ///< file name for saving the amplitude image - std::string m_IntensityImageFileName; ///< file name for saving the intensity image - std::string m_Extension; ///< file extension used for saving images - - int m_CaptureWidth; ///< width (x-dimension) of the images to record. - int m_CaptureHeight; ///< height (y-dimension) of the images to record. - int m_PixelNumber; ///< number of pixels (widht*height) of the images to record - int m_ImageSizeInBytes; ///< size of the image to save in bytes - int m_NumOfFrames; ///< number of frames written to the image. Used for pic header. - ToFNrrdImageWriter::ToFImageType m_ToFImageType; ///< type of image to be recorded: ToFImageType3D (0) or ToFImageType2DPlusT (1) - - bool m_DistanceImageSelected; ///< flag indicating if distance image should be recorded - bool m_AmplitudeImageSelected; ///< flag indicating if amplitude image should be recorded - bool m_IntensityImageSelected; ///< flag indicating if intensity image should be recorded + //void CheckForFileExtension(std::string& fileName); + + //std::string m_DistanceImageFileName; ///< file name for saving the distance image + //std::string m_AmplitudeImageFileName; ///< file name for saving the amplitude image + //std::string m_IntensityImageFileName; ///< file name for saving the intensity image + //std::string m_Extension; ///< file extension used for saving images + + //int m_CaptureWidth; ///< width (x-dimension) of the images to record. + //int m_CaptureHeight; ///< height (y-dimension) of the images to record. + //int m_PixelNumber; ///< number of pixels (widht*height) of the images to record + //int m_ImageSizeInBytes; ///< size of the image to save in bytes + //int m_NumOfFrames; ///< number of frames written to the image. Used for pic header. + //ToFNrrdImageWriter::ToFImageType m_ToFImageType; ///< type of image to be recorded: ToFImageType3D (0) or ToFImageType2DPlusT (1) + + //bool m_DistanceImageSelected; ///< flag indicating if distance image should be recorded + //bool m_AmplitudeImageSelected; ///< flag indicating if amplitude image should be recorded + //bool m_IntensityImageSelected; ///< flag indicating if intensity image should be recorded //Image::Pointer m_MitkImage; ///< mitk image used for pic header creation - std::ofstream* m_DistanceOutfile; ///< file for distance image - std::ofstream* m_AmplitudeOutfile; ///< file for amplitude image - std::ofstream* m_IntensityOutfile; ///< file for intensity image - + std::ofstream m_DistanceOutfile; ///< file for distance image + std::ofstream m_AmplitudeOutfile; ///< file for amplitude image + std::ofstream m_IntensityOutfile; ///< file for intensity image private: ToFNrrdImageWriter(); ~ToFNrrdImageWriter(); /*! \brief Open file by filename to gain write access to it. */ - void OpenStreamFile(std::ofstream* &outfile, std::string outfileName); + void OpenStreamFile(std::ofstream &outfile, std::string outfileName); /*! \brief Close file after work on it is finished. */ - void CloseStreamFile(std::ofstream* &outfile, std::string fileName); - /*! - \brief Replace current PicFileHeader information. - */ - void ReplacePicFileHeader(FILE* outfile); + void CloseStreamFile(std::ofstream &outfile, std::string fileName); /*! - \brief Write image information to the PicFileHeader. + \brief Write image information to the NrrdFile. */ - //void WritePicFileHeader(FILE* outfile, mitkIpPicDescriptor* pic); - - //void ConvertStreamToNrrdFormat(std::ofstream* outfile); - void ConvertStreamToNrrdFormat(std::ofstream* outfile, std::string fileName); + void ConvertStreamToNrrdFormat( std::string fileName ); }; } //END mitk namespace #endif // __mitkToFNrrdImageWriter_h diff --git a/Modules/ToFHardware/mitkToFImageWriter.cpp b/Modules/ToFHardware/mitkToFPicImageWriter.cpp similarity index 77% copy from Modules/ToFHardware/mitkToFImageWriter.cpp copy to Modules/ToFHardware/mitkToFPicImageWriter.cpp index 06c35b220f..ca5d75584b 100644 --- a/Modules/ToFHardware/mitkToFImageWriter.cpp +++ b/Modules/ToFHardware/mitkToFPicImageWriter.cpp @@ -1,256 +1,252 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ Version: $Revision: $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#include +#include #include #include #include // itk includes #include "itksys/SystemTools.hxx" extern "C" { size_t _mitkIpPicFWrite( const void *ptr, size_t size, size_t nitems, mitkIpPicFile_t stream); } namespace mitk { - ToFImageWriter::ToFImageWriter():m_Extension(".nrrd"),m_DistanceOutfile(NULL), - m_AmplitudeOutfile(NULL), m_IntensityOutfile(NULL),m_NumOfFrames(0), - m_MitkImage(NULL),m_DistanceImageSelected(true), m_AmplitudeImageSelected(true), - m_IntensityImageSelected(true),m_CaptureWidth(200),m_CaptureHeight(200), - m_PixelNumber(0), m_ImageSizeInBytes(0), - m_ToFImageType(ToFImageWriter::ToFImageType3D) + ToFPicImageWriter::ToFPicImageWriter(): ToFImageWriter(), m_DistanceOutfile(NULL), + m_AmplitudeOutfile(NULL), m_IntensityOutfile(NULL) { + m_Extension = std::string(".pic"); } - ToFImageWriter::~ToFImageWriter() + ToFPicImageWriter::~ToFPicImageWriter() { } - void ToFImageWriter::Open() + void ToFPicImageWriter::Open() { this->CheckForFileExtension(this->m_DistanceImageFileName); this->CheckForFileExtension(this->m_AmplitudeImageFileName); this->CheckForFileExtension(this->m_IntensityImageFileName); this->m_PixelNumber = this->m_CaptureWidth * this->m_CaptureHeight; this->m_ImageSizeInBytes = this->m_PixelNumber * sizeof(float); float* floatData = new float[this->m_PixelNumber]; for(int i=0; im_PixelNumber; i++) { floatData[i] = i + 0.0; } this->m_MitkImage = Image::New(); unsigned int dimensions[4]; dimensions[0] = this->m_CaptureWidth; dimensions[1] = this->m_CaptureHeight; if (this->m_ToFImageType == ToFImageWriter::ToFImageType2DPlusT) { dimensions[2] = 1; dimensions[3] = 2; this->m_MitkImage->Initialize( PixelType(typeid(float)), 4, dimensions, 1); } else { dimensions[2] = 2; dimensions[3] = 1; this->m_MitkImage->Initialize( PixelType(typeid(float)), 3, dimensions, 1); } this->m_MitkImage->SetSlice(floatData, 0, 0, 0); //ImageWriter::Pointer imageWriter = ImageWriter::New(); // if (this->m_DistanceImageSelected) // { // imageWriter->SetFileName(this->m_DistanceImageFileName); // imageWriter->SetInputImage(); // imageWriter->SetExtension(this->m_Extension); // imageWriter->Modified(); // imageWriter->Update(); // } // if (this->m_AmplitudeImageSelected) // { // imageWriter->SetFileName(this->m_AmplitudeImageFileName); // imageWriter->SetInputImage(); // imageWriter->SetExtension(this->m_Extension); // imageWriter->Modified(); // imageWriter->Update(); // } // if (this->m_IntensityImageSelected) // { // imageWriter->SetFileName(this->m_IntensityImageFileName); // imageWriter->SetInputImage(); // imageWriter->SetExtension(this->m_Extension); // imageWriter->Modified(); // imageWriter->Update(); // } mitkIpPicDescriptor* pic = this->m_MitkImage->GetPic(); if (this->m_DistanceImageSelected) { this->OpenPicFile(&(this->m_DistanceOutfile), this->m_DistanceImageFileName); this->WritePicFileHeader(this->m_DistanceOutfile, pic); } if (this->m_AmplitudeImageSelected) { this->OpenPicFile(&(this->m_AmplitudeOutfile), this->m_AmplitudeImageFileName); this->WritePicFileHeader(this->m_AmplitudeOutfile, pic); } if (this->m_IntensityImageSelected) { this->OpenPicFile(&(this->m_IntensityOutfile), this->m_IntensityImageFileName); this->WritePicFileHeader(this->m_IntensityOutfile, pic); } this->m_NumOfFrames = 0; delete[] floatData; } - void ToFImageWriter::Close() + void ToFPicImageWriter::Close() { if (this->m_DistanceImageSelected) { this->ClosePicFile(this->m_DistanceOutfile); } if (this->m_AmplitudeImageSelected) { this->ClosePicFile(this->m_AmplitudeOutfile); } if (this->m_IntensityImageSelected) { this->ClosePicFile(this->m_IntensityOutfile); } } - void ToFImageWriter::Add(float* distanceFloatData, float* amplitudeFloatData, float* intensityFloatData) + void ToFPicImageWriter::Add(float* distanceFloatData, float* amplitudeFloatData, float* intensityFloatData) { if (this->m_DistanceImageSelected) { fwrite( distanceFloatData, this->m_ImageSizeInBytes, 1, this->m_DistanceOutfile ); } if (this->m_AmplitudeImageSelected) { fwrite( amplitudeFloatData, this->m_ImageSizeInBytes, 1, this->m_AmplitudeOutfile ); } if (this->m_IntensityImageSelected) { fwrite( intensityFloatData, this->m_ImageSizeInBytes, 1, this->m_IntensityOutfile ); } this->m_NumOfFrames++; } - void ToFImageWriter::OpenPicFile(FILE** outfile,std::string outfileName) + void ToFPicImageWriter::OpenPicFile(FILE** outfile,std::string outfileName) { (*outfile) = fopen( outfileName.c_str(), "w+b" ); if( !outfile ) // if fopen_s was not successful! { MITK_ERROR << "Error opening outfile: " << outfileName; throw std::logic_error("Error opening outfile."); return; } } - void ToFImageWriter::ClosePicFile(FILE* outfile) + void ToFPicImageWriter::ClosePicFile(FILE* outfile) { if (this->m_NumOfFrames == 0) { fclose(outfile); throw std::logic_error("File is empty."); return; } this->ReplacePicFileHeader(outfile); fclose(outfile); } - void ToFImageWriter::ReplacePicFileHeader(FILE* outfile) + void ToFPicImageWriter::ReplacePicFileHeader(FILE* outfile) { mitkIpPicDescriptor* pic = this->m_MitkImage->GetPic(); if (this->m_ToFImageType == ToFImageWriter::ToFImageType2DPlusT) { pic->dim = 4; pic->n[2] = 1; pic->n[3] = this->m_NumOfFrames; } else { pic->dim = 3; pic->n[2] = this->m_NumOfFrames; pic->n[3] = 1; } fseek ( outfile, 0, SEEK_SET ); this->WritePicFileHeader( outfile, pic ); } - void ToFImageWriter::WritePicFileHeader(FILE* outfile, mitkIpPicDescriptor* pic) + void ToFPicImageWriter::WritePicFileHeader(FILE* outfile, mitkIpPicDescriptor* pic) { mitkIpUInt4_t len; mitkIpUInt4_t tagsLen; tagsLen = _mitkIpPicTagsSize( pic->info->tags_head ); len = tagsLen + 3 * sizeof(mitkIpUInt4_t) + pic->dim * sizeof(mitkIpUInt4_t); /* write oufile */ if( mitkIpPicEncryptionType(pic) == ' ' ) mitkIpPicFWrite( mitkIpPicVERSION, 1, sizeof(mitkIpPicTag_t), outfile ); else mitkIpPicFWrite( pic->info->version, 1, sizeof(mitkIpPicTag_t), outfile ); mitkIpPicFWriteLE( &len, sizeof(mitkIpUInt4_t), 1, outfile ); mitkIpPicFWriteLE( &(pic->type), sizeof(mitkIpUInt4_t), 1, outfile ); mitkIpPicFWriteLE( &(pic->bpe), sizeof(mitkIpUInt4_t), 1, outfile ); mitkIpPicFWriteLE( &(pic->dim), sizeof(mitkIpUInt4_t), 1, outfile ); mitkIpPicFWriteLE( pic->n, sizeof(mitkIpUInt4_t), pic->dim, outfile ); _mitkIpPicWriteTags( pic->info->tags_head, outfile, mitkIpPicEncryptionType(pic) ); pic->info->pixel_start_in_file = ftell( outfile ); } - 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) - { - this->m_Extension = extension; - } - - size_t found; - found = fileName.find( this->m_Extension ); // !!! HAS to be at the very end of the filename (not somewhere in the middle) - if( fileName.length() > 3 && found != fileName.length() - this->m_Extension.length() ) - { - fileName.append(this->m_Extension); - } - } - - ToFImageWriter::ToFImageType ToFImageWriter::GetToFImageType() - { - return this->m_ToFImageType; - } - - void ToFImageWriter::SetToFImageType(ToFImageWriter::ToFImageType toFImageType) - { - this->m_ToFImageType = toFImageType; - } + //void ToFPicImageWriter::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) + // { + // 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( fileName.length() > this->m_Extension.length() && found != fileName.length() - this->m_Extension.length() ) + // { + // fileName.append(this->m_Extension); + // } + //} + + //ToFPicImageWriter::ToFImageType ToFImageWriter::GetToFImageType() + //{ + // return this->m_ToFImageType; + //} + + //void ToFPicImageWriter::SetToFImageType(ToFImageWriter::ToFImageType toFImageType) + //{ + // this->m_ToFImageType = toFImageType; + //} } // end namespace mitk diff --git a/Modules/ToFHardware/mitkToFImageWriter.h b/Modules/ToFHardware/mitkToFPicImageWriter.h similarity index 50% copy from Modules/ToFHardware/mitkToFImageWriter.h copy to Modules/ToFHardware/mitkToFPicImageWriter.h index 150aecd154..292bd71866 100644 --- a/Modules/ToFHardware/mitkToFImageWriter.h +++ b/Modules/ToFHardware/mitkToFPicImageWriter.h @@ -1,147 +1,147 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ Version: $Revision: $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#ifndef __mitkToFImageWriter_h -#define __mitkToFImageWriter_h +#ifndef __mitkToFPicImageWriter_h +#define __mitkToFPicImageWriter_h #include "mitkToFHardwareExports.h" #include "mitkCommon.h" #include "mitkToFImageGrabber.h" +#include "mitkToFImageWriter.h" #include "itkObject.h" #include "itkObjectFactory.h" namespace mitk { /** * @brief Writer class for ToF images * * This writer class allows streaming of ToF data into a file. The .pic file format is used for writing the data. * Image information is included in the header of the pic file. * Writer can simultaneously save "distance", "intensity" and "amplitude" image. * Images can be written as 3D volume (ToFImageType::ToFImageType3D) or temporal image stack (ToFImageType::ToFImageType2DPlusT) * * @ingroup ToFHardware */ - class MITK_TOFHARDWARE_EXPORT ToFImageWriter : public itk::Object + class MITK_TOFHARDWARE_EXPORT ToFPicImageWriter : public ToFImageWriter { public: - ToFImageWriter(); + ToFPicImageWriter(); - ~ToFImageWriter(); - - mitkClassMacro( ToFImageWriter , itk::Object ); + ~ToFPicImageWriter(); + mitkClassMacro( ToFPicImageWriter , ToFImageWriter ); itkNewMacro( Self ); - itkGetMacro( DistanceImageFileName, std::string ); - itkGetMacro( AmplitudeImageFileName, std::string ); - itkGetMacro( IntensityImageFileName, std::string ); - itkGetMacro( Extension, std::string ); - itkGetMacro( CaptureWidth, int ); - itkGetMacro( CaptureHeight, int ); - itkGetMacro( DistanceImageSelected, bool ); - itkGetMacro( AmplitudeImageSelected, bool ); - itkGetMacro( IntensityImageSelected, bool ); - - itkSetMacro( DistanceImageFileName, std::string ); - itkSetMacro( AmplitudeImageFileName, std::string ); - itkSetMacro( IntensityImageFileName, std::string ); - itkSetMacro( Extension, std::string ); - itkSetMacro( CaptureWidth, int ); - itkSetMacro( CaptureHeight, int ); - itkSetMacro( DistanceImageSelected, bool ); - itkSetMacro( AmplitudeImageSelected, bool ); - itkSetMacro( IntensityImageSelected, bool ); - - enum ToFImageType{ ToFImageType3D, ToFImageType2DPlusT }; + //itkGetMacro( DistanceImageFileName, std::string ); + //itkGetMacro( AmplitudeImageFileName, std::string ); + //itkGetMacro( IntensityImageFileName, std::string ); + //itkGetMacro( Extension, std::string ); + //itkGetMacro( CaptureWidth, int ); + //itkGetMacro( CaptureHeight, int ); + //itkGetMacro( DistanceImageSelected, bool ); + //itkGetMacro( AmplitudeImageSelected, bool ); + //itkGetMacro( IntensityImageSelected, bool ); + + //itkSetMacro( DistanceImageFileName, std::string ); + //itkSetMacro( AmplitudeImageFileName, std::string ); + //itkSetMacro( IntensityImageFileName, std::string ); + //itkSetMacro( Extension, std::string ); + //itkSetMacro( CaptureWidth, int ); + //itkSetMacro( CaptureHeight, int ); + //itkSetMacro( DistanceImageSelected, bool ); + //itkSetMacro( AmplitudeImageSelected, bool ); + //itkSetMacro( IntensityImageSelected, bool ); + + //enum ToFImageType{ ToFImageType3D, ToFImageType2DPlusT }; /*! \brief Get the type of image to be written \return ToF image type: ToFImageType3D (0) or ToFImageType2DPlusT (1) */ - ToFImageWriter::ToFImageType GetToFImageType(); + //ToFImageWriter::ToFImageType GetToFImageType(); /*! \brief Set the type of image to be written \param toFImageType type of the ToF image: ToFImageType3D (0) or ToFImageType2DPlusT (1) */ - void SetToFImageType(ToFImageWriter::ToFImageType toFImageType); + //void SetToFImageType(ToFImageWriter::ToFImageType toFImageType); /*! \brief Open file(s) for writing */ - virtual void Open(); + void Open(); /*! \brief Close file(s) add .pic header and write */ - virtual void Close(); + void Close(); /*! \brief Add new data to file. */ - virtual void Add(float* distanceFloatData, float* amplitudeFloatData, float* intensityFloatData); + void Add(float* distanceFloatData, float* amplitudeFloatData, float* intensityFloatData); protected: /*! \brief Checks file name if file extension exists. If not .pic is added to fileName \param fileName file name to be checked */ - void CheckForFileExtension(std::string& fileName); - - std::string m_DistanceImageFileName; ///< file name for saving the distance image - std::string m_AmplitudeImageFileName; ///< file name for saving the amplitude image - std::string m_IntensityImageFileName; ///< file name for saving the intensity image - std::string m_Extension; ///< file extension used for saving images - - int m_CaptureWidth; ///< width (x-dimension) of the images to record. - int m_CaptureHeight; ///< height (y-dimension) of the images to record. - int m_PixelNumber; ///< number of pixels (widht*height) of the images to record - int m_ImageSizeInBytes; ///< size of the image to save in bytes - int m_NumOfFrames; ///< number of frames written to the image. Used for pic header. - ToFImageWriter::ToFImageType m_ToFImageType; ///< type of image to be recorded: ToFImageType3D (0) or ToFImageType2DPlusT (1) - - bool m_DistanceImageSelected; ///< flag indicating if distance image should be recorded - bool m_AmplitudeImageSelected; ///< flag indicating if amplitude image should be recorded - bool m_IntensityImageSelected; ///< flag indicating if intensity image should be recorded + //void CheckForFileExtension(std::string& fileName); + + //std::string m_DistanceImageFileName; ///< file name for saving the distance image + //std::string m_AmplitudeImageFileName; ///< file name for saving the amplitude image + //std::string m_IntensityImageFileName; ///< file name for saving the intensity image + //std::string m_Extension; ///< file extension used for saving images + + //int m_CaptureWidth; ///< width (x-dimension) of the images to record. + //int m_CaptureHeight; ///< height (y-dimension) of the images to record. + //int m_PixelNumber; ///< number of pixels (widht*height) of the images to record + //int m_ImageSizeInBytes; ///< size of the image to save in bytes + //int m_NumOfFrames; ///< number of frames written to the image. Used for pic header. + //ToFImageWriter::ToFImageType m_ToFImageType; ///< type of image to be recorded: ToFImageType3D (0) or ToFImageType2DPlusT (1) + + //bool m_DistanceImageSelected; ///< flag indicating if distance image should be recorded + //bool m_AmplitudeImageSelected; ///< flag indicating if amplitude image should be recorded + //bool m_IntensityImageSelected; ///< flag indicating if intensity image should be recorded Image::Pointer m_MitkImage; ///< mitk image used for pic header creation FILE* m_DistanceOutfile; ///< file for distance image FILE* m_AmplitudeOutfile; ///< file for amplitude image FILE* m_IntensityOutfile; ///< file for intensity image private: /*! \brief Open file by filename to gain write access to it. */ void OpenPicFile(FILE** outfile, std::string outfileName); /*! \brief Close file after work on it is finished. */ void ClosePicFile(FILE* outfile); /*! \brief Replace current PicFileHeader information. */ void ReplacePicFileHeader(FILE* outfile); /*! \brief Write image information to the PicFileHeader. */ void WritePicFileHeader(FILE* outfile, mitkIpPicDescriptor* pic); }; } //END mitk namespace -#endif // __mitkToFImageWriter_h +#endif // __mitkToFPicImageWriter_h diff --git a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp b/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp index 684b08fc49..863eb747d0 100644 --- a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp +++ b/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp @@ -1,424 +1,424 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2009-05-20 13:35:09 +0200 (Mi, 20 Mai 2009) $ Version: $Revision: 17332 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ //#define _USE_MATH_DEFINES #include //QT headers #include #include #include //mitk headers #include //itk headers #include const std::string QmitkToFConnectionWidget::VIEW_ID = "org.mitk.views.qmitktofconnectionwidget"; QmitkToFConnectionWidget::QmitkToFConnectionWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f) { this->m_IntegrationTime = 0; this->m_ModulationFrequency = 0; this->m_ToFImageGrabber = NULL; m_Controls = NULL; CreateQtPartControl(this); } QmitkToFConnectionWidget::~QmitkToFConnectionWidget() { } void QmitkToFConnectionWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkToFConnectionWidgetControls; m_Controls->setupUi(parent); this->CreateConnections(); ShowParameterWidget(); } } void QmitkToFConnectionWidget::CreateConnections() { if ( m_Controls ) { connect( (QObject*)(m_Controls->m_ConnectCameraButton), SIGNAL(clicked()),(QObject*) this, SLOT(OnConnectCamera()) ); connect( m_Controls->m_SelectCameraCombobox, SIGNAL(currentIndexChanged(int)), this, SLOT(OnSelectCamera(int)) ); connect( m_Controls->m_SelectCameraCombobox, SIGNAL(activated(int)), this, SLOT(OnSelectCamera(int)) ); connect( m_Controls->m_SelectCameraCombobox, SIGNAL(activated(int)), this, SIGNAL(ToFCameraSelected(int)) ); //connect( m_Controls->m_IntegrationTimeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(OnChangeIntegrationTimeSpinBox(int)) ); //connect( m_Controls->m_ModulationFrequencySpinBox, SIGNAL(valueChanged(int)), this, SLOT(OnChangeModulationFrequencySpinBox(int)) ); } } void QmitkToFConnectionWidget::ShowParameterWidget() { int selectedCamera = m_Controls->m_SelectCameraCombobox->currentIndex(); switch (selectedCamera) { case 0: case 1: case 2: ShowPMDParameterWidget(); break; case 3: ShowMESAParameterWidget(); break; default: this->m_Controls->m_PMDParameterWidget->hide(); this->m_Controls->m_MESAParameterWidget->hide(); } } void QmitkToFConnectionWidget::ShowPMDParameterWidget() { this->m_Controls->m_PMDParameterWidget->show(); this->m_Controls->m_MESAParameterWidget->hide(); } void QmitkToFConnectionWidget::ShowMESAParameterWidget() { this->m_Controls->m_PMDParameterWidget->hide(); this->m_Controls->m_MESAParameterWidget->show(); } void QmitkToFConnectionWidget::ShowPlayerParameterWidget() { this->m_Controls->m_PMDParameterWidget->hide(); this->m_Controls->m_MESAParameterWidget->hide(); } mitk::ToFImageGrabber* QmitkToFConnectionWidget::GetToFImageGrabber() { return m_ToFImageGrabber; } void QmitkToFConnectionWidget::OnSelectCamera(int index) { if (index == 0) // PMD camcube 2 { //m_Controls->m_IntegrationTimeSpinBox->setEnabled(true); //m_Controls->m_ModulationFrequencySpinBox->setEnabled(true); //m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); ShowPMDParameterWidget(); } else if (index == 1) // pmd camboard { //m_Controls->m_IntegrationTimeSpinBox->setEnabled(true); //m_Controls->m_ModulationFrequencySpinBox->setEnabled(true); //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPMDParameterWidget(); } else if (index == 2) // pmd O3d { //m_Controls->m_IntegrationTimeSpinBox->setEnabled(true); //m_Controls->m_ModulationFrequencySpinBox->setEnabled(true); //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPMDParameterWidget(); } else if (index == 3) // MESA 4000 { ShowMESAParameterWidget(); } else if (index == 4) // pmd file player { //m_Controls->m_IntegrationTimeSpinBox->setEnabled(false); //m_Controls->m_ModulationFrequencySpinBox->setEnabled(false); //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPlayerParameterWidget(); } else if (index == 5) // pmd raw data player { //m_Controls->m_IntegrationTimeSpinBox->setEnabled(false); //m_Controls->m_ModulationFrequencySpinBox->setEnabled(false); //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPlayerParameterWidget(); } else if (index == 6) // mitk player { //m_Controls->m_IntegrationTimeSpinBox->setEnabled(false); //m_Controls->m_ModulationFrequencySpinBox->setEnabled(false); //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPlayerParameterWidget(); } } void QmitkToFConnectionWidget::OnConnectCamera() { bool playerMode = false; if (m_Controls->m_ConnectCameraButton->text()=="Connect") { //reset the status of the GUI buttons m_Controls->m_ConnectCameraButton->setEnabled(false); m_Controls->m_SelectCameraCombobox->setEnabled(false); // m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); //repaint the widget this->repaint(); QString tmpFileName(""); QString fileFilter(""); //select the camera to connect with int selectedCamera = m_Controls->m_SelectCameraCombobox->currentIndex(); if (selectedCamera == 0) { //PMD CamCube this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDCamCubeImageGrabber(); } else if (selectedCamera == 1) { //PMD CamBoard this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDCamBoardImageGrabber(); } else if (selectedCamera == 2) {//PMD O3 this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDO3ImageGrabber(); } else if (selectedCamera == 3) {//MESA SR4000 this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetMESASR4000ImageGrabber(); } else if (selectedCamera == 4) {//PMD player playerMode = true; fileFilter.append("PMD Files (*.pmd)"); this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDPlayerImageGrabber(); } else if (selectedCamera == 5) {//PMD MITK player playerMode = true; - fileFilter.append("MITK Images (*.pic)"); + fileFilter.append("MITK Images (*.nrrd);;MITK Images (deprecated) (*.pic)"); this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDMITKPlayerImageGrabber(); } else if (selectedCamera == 6) {//MITK player playerMode = true; - fileFilter.append("MITK Images (*.nrrd);;MITK Images (*.pic) (deprecated)"); + fileFilter.append("MITK Images (*.nrrd);;MITK Images (deprecated) (*.pic)"); this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetMITKPlayerImageGrabber(); } // if a player was selected ... if (playerMode) { //... open a QFileDialog to chose the corresponding file from the disc tmpFileName = QFileDialog::getOpenFileName(NULL, "Play Image From...", "", fileFilter); if (tmpFileName.isEmpty()) { m_Controls->m_ConnectCameraButton->setChecked(false); m_Controls->m_ConnectCameraButton->setEnabled(true); m_Controls->m_SelectCameraCombobox->setEnabled(true); // m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); - OnSelectCamera(m_Controls->m_SelectCameraCombobox->currentIndex()); + this->OnSelectCamera(m_Controls->m_SelectCameraCombobox->currentIndex()); QMessageBox::information( this, "Template functionality", "Please select a valid image before starting some action."); return; } if(selectedCamera == 4) { //set the PMD file name this->m_ToFImageGrabber->SetStringProperty("PMDFileName", tmpFileName.toStdString().c_str() ); } if (selectedCamera == 5 || selectedCamera == 6) { std::string msg = ""; try { //get 3 corresponding file names std::string dir = itksys::SystemTools::GetFilenamePath( tmpFileName.toStdString() ); std::string baseFilename = itksys::SystemTools::GetFilenameWithoutLastExtension( tmpFileName.toStdString() ); std::string extension = itksys::SystemTools::GetFilenameLastExtension( tmpFileName.toStdString() ); if (extension != ".pic" && extension != ".nrrd") { msg = msg + "Invalid file format, please select a \".nrrd\"-file"; throw std::logic_error(msg.c_str()); } int found = baseFilename.rfind("_DistanceImage"); if (found == std::string::npos) { found = baseFilename.rfind("_AmplitudeImage"); } if (found == std::string::npos) { found = baseFilename.rfind("_IntensityImage"); } if (found == std::string::npos) { msg = msg + "Input file name must end with \"_DistanceImage.pic\", \"_AmplitudeImage.pic\" or \"_IntensityImage.pic\"!"; throw std::logic_error(msg.c_str()); } std::string baseFilenamePrefix = baseFilename.substr(0,found); std::string distanceImageFileName = dir + "/" + baseFilenamePrefix + "_DistanceImage" + extension; std::string amplitudeImageFileName = dir + "/" + baseFilenamePrefix + "_AmplitudeImage" + extension; std::string intensityImageFileName = dir + "/" + baseFilenamePrefix + "_IntensityImage" + extension; if (!itksys::SystemTools::FileExists(distanceImageFileName.c_str(), true)) { msg = msg + "Inputfile not exist! " + distanceImageFileName; throw std::logic_error(msg.c_str()); } if (!itksys::SystemTools::FileExists(amplitudeImageFileName.c_str(), true)) { msg = msg + "Inputfile not exist! " + amplitudeImageFileName; throw std::logic_error(msg.c_str()); } if (!itksys::SystemTools::FileExists(intensityImageFileName.c_str(), true)) { msg = msg + "Inputfile not exist! " + intensityImageFileName; throw std::logic_error(msg.c_str()); } //set the file names this->m_ToFImageGrabber->SetStringProperty("DistanceImageFileName", distanceImageFileName.c_str()); this->m_ToFImageGrabber->SetStringProperty("AmplitudeImageFileName", amplitudeImageFileName.c_str()); this->m_ToFImageGrabber->SetStringProperty("IntensityImageFileName", intensityImageFileName.c_str()); } catch (std::exception &e) { MITK_ERROR << e.what(); QMessageBox::critical( this, "Error", e.what() ); m_Controls->m_ConnectCameraButton->setChecked(false); m_Controls->m_ConnectCameraButton->setEnabled(true); m_Controls->m_SelectCameraCombobox->setEnabled(true); // m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); this->OnSelectCamera(m_Controls->m_SelectCameraCombobox->currentIndex()); return; } } } //if a connection could be established if (this->m_ToFImageGrabber->ConnectCamera()) { this->m_Controls->m_PMDParameterWidget->SetToFImageGrabber(this->m_ToFImageGrabber); this->m_Controls->m_MESAParameterWidget->SetToFImageGrabber(this->m_ToFImageGrabber); switch (selectedCamera) { case 0: case 1: case 2: this->m_Controls->m_PMDParameterWidget->ActivateAllParameters(); break; case 3: this->m_Controls->m_MESAParameterWidget->ActivateAllParameters(); break; } /* //get the integration time and modulation frequency this->m_IntegrationTime = m_Controls->m_IntegrationTimeSpinBox->value(); this->m_ModulationFrequency = m_Controls->m_ModulationFrequencySpinBox->value(); //set the integration time and modulation frequency in the grabber this->m_IntegrationTime = this->m_ToFImageGrabber->SetIntegrationTime(this->m_IntegrationTime); this->m_ModulationFrequency = this->m_ToFImageGrabber->SetModulationFrequency(this->m_ModulationFrequency); //set the PMD calibration according to the check boxes bool boolValue = false; boolValue = m_Controls->m_FPNCalibCB->isChecked(); this->m_ToFImageGrabber->SetBoolProperty("SetFPNCalibration", boolValue); boolValue = m_Controls->m_FPPNCalibCB->isChecked(); this->m_ToFImageGrabber->SetBoolProperty("SetFPPNCalibration", boolValue); boolValue = m_Controls->m_LinearityCalibCB->isChecked(); this->m_ToFImageGrabber->SetBoolProperty("SetLinearityCalibration", boolValue); boolValue = m_Controls->m_LensCorrection->isChecked(); this->m_ToFImageGrabber->SetBoolProperty("SetLensCalibration", boolValue); boolValue = m_Controls->m_ExposureModeCB->isChecked(); this->m_ToFImageGrabber->SetBoolProperty("SetExposureMode", boolValue); //reset the GUI elements m_Controls->m_IntegrationTimeSpinBox->setValue(this->m_IntegrationTime); m_Controls->m_ModulationFrequencySpinBox->setValue(this->m_ModulationFrequency); */ m_Controls->m_ConnectCameraButton->setText("Disconnect"); // send connect signal to the caller functionality emit ToFCameraConnected(); } else { QMessageBox::critical( this, "Error", "Connection failed. Check if you have installed the latest driver for your system." ); m_Controls->m_ConnectCameraButton->setChecked(false); m_Controls->m_ConnectCameraButton->setEnabled(true); m_Controls->m_SelectCameraCombobox->setEnabled(true); // m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); this->OnSelectCamera(m_Controls->m_SelectCameraCombobox->currentIndex()); return; } m_Controls->m_ConnectCameraButton->setEnabled(true); } else if (m_Controls->m_ConnectCameraButton->text()=="Disconnect") { //send camera stop to the caller functionality emit ToFCameraStop(); this->m_ToFImageGrabber->StopCamera(); this->m_ToFImageGrabber->DisconnectCamera(); m_Controls->m_ConnectCameraButton->setText("Connect"); m_Controls->m_SelectCameraCombobox->setEnabled(true); // m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); this->OnSelectCamera(m_Controls->m_SelectCameraCombobox->currentIndex()); this->m_ToFImageGrabber = NULL; // send disconnect signal to the caller functionality emit ToFCameraDisconnected(); } } /* void QmitkToFConnectionWidget::OnChangeIntegrationTimeSpinBox(int value) { if (this->m_ToFImageGrabber != NULL) { // stop camera if active bool active = m_ToFImageGrabber->IsCameraActive(); if (active) { m_ToFImageGrabber->StopCamera(); } this->m_IntegrationTime = m_Controls->m_IntegrationTimeSpinBox->value(); this->m_IntegrationTime = this->m_ToFImageGrabber->SetIntegrationTime(this->m_IntegrationTime); if (active) { m_ToFImageGrabber->StartCamera(); } } } void QmitkToFConnectionWidget::OnChangeModulationFrequencySpinBox(int value) { if (this->m_ToFImageGrabber != NULL) { // stop camera if active bool active = m_ToFImageGrabber->IsCameraActive(); if (active) { m_ToFImageGrabber->StopCamera(); } this->m_ModulationFrequency = m_Controls->m_ModulationFrequencySpinBox->value(); this->m_ModulationFrequency = this->m_ToFImageGrabber->SetModulationFrequency(this->m_ModulationFrequency); if (active) { m_ToFImageGrabber->StartCamera(); } } } */ diff --git a/Modules/ToFUI/Qmitk/QmitkToFRecorderWidget.cpp b/Modules/ToFUI/Qmitk/QmitkToFRecorderWidget.cpp index c8936bacb0..5b38364cf6 100644 --- a/Modules/ToFUI/Qmitk/QmitkToFRecorderWidget.cpp +++ b/Modules/ToFUI/Qmitk/QmitkToFRecorderWidget.cpp @@ -1,391 +1,391 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2009-05-20 13:35:09 +0200 (Mi, 20 Mai 2009) $ Version: $Revision: 17332 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #define _USE_MATH_DEFINES #include "QmitkToFRecorderWidget.h" //QT headers #include #include #include #include #include #include //mitk headers #include //itk headers #include #include struct QFileDialogArgs; class QFileDialogPrivate; const std::string QmitkToFRecorderWidget::VIEW_ID = "org.mitk.views.qmitktofrecorderwidget"; QmitkToFRecorderWidget::QmitkToFRecorderWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f) { this->m_ToFImageRecorder = NULL; this->m_ToFImageGrabber = NULL; this->m_RecordMode = mitk::ToFImageRecorder::PerFrames; this-> m_Controls = NULL; CreateQtPartControl(this); } QmitkToFRecorderWidget::~QmitkToFRecorderWidget() { } void QmitkToFRecorderWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets this->m_Controls = new Ui::QmitkToFRecorderWidgetControls; this->m_Controls->setupUi(parent); this->CreateConnections(); } } void QmitkToFRecorderWidget::CreateConnections() { if ( m_Controls ) { connect( (QObject*)(m_Controls->m_PlayButton), SIGNAL(clicked()),(QObject*) this, SLOT(OnPlay()) ); connect( (QObject*)(m_Controls->m_StopButton), SIGNAL(clicked()),(QObject*) this, SLOT(OnStop()) ); connect( (QObject*)(m_Controls->m_StartRecordingButton), SIGNAL(clicked()),(QObject*) this, SLOT(OnStartRecorder()) ); connect( (QObject*)(m_Controls->m_RecordModeComboBox), SIGNAL(currentIndexChanged(int)),(QObject*) this, SLOT(OnChangeRecordModeComboBox(int)) ); connect(this, SIGNAL(RecordingStopped()), this, SLOT(OnRecordingStopped()), Qt::BlockingQueuedConnection); } } void QmitkToFRecorderWidget::SetParameter(mitk::ToFImageGrabber* ToFImageGrabber, mitk::ToFImageRecorder* toFImageRecorder) { this->m_ToFImageGrabber = ToFImageGrabber; this->m_ToFImageRecorder = toFImageRecorder; this->m_StopRecordingCommand = CommandType::New(); this->m_StopRecordingCommand->SetCallbackFunction(this, &QmitkToFRecorderWidget::StopRecordingCallback); this->m_ToFImageRecorder->RemoveAllObservers(); this->m_ToFImageRecorder->AddObserver(itk::AbortEvent(), this->m_StopRecordingCommand); m_Controls->m_PlayButton->setChecked(false); m_Controls->m_PlayButton->setEnabled(true); m_Controls->m_StartRecordingButton->setChecked(false); m_Controls->m_RecorderGroupBox->setEnabled(true); } void QmitkToFRecorderWidget::StopRecordingCallback() { emit RecordingStopped(); } void QmitkToFRecorderWidget::ResetGUIToInitial() { m_Controls->m_PlayButton->setChecked(false); m_Controls->m_PlayButton->setEnabled(true); m_Controls->m_RecorderGroupBox->setEnabled(false); } void QmitkToFRecorderWidget::OnRecordingStopped() { m_Controls->m_StartRecordingButton->setChecked(false); m_Controls->m_RecorderGroupBox->setEnabled(true); } void QmitkToFRecorderWidget::OnStop() { StopCamera(); StopRecorder(); ResetGUIToInitial(); emit ToFCameraStopped(); } void QmitkToFRecorderWidget::OnPlay() { m_Controls->m_PlayButton->setChecked(true); m_Controls->m_PlayButton->setEnabled(false); m_Controls->m_RecorderGroupBox->setEnabled(true); this->repaint(); StartCamera(); emit ToFCameraStarted(); } void QmitkToFRecorderWidget::StartCamera() { bool ok = false; if (!m_ToFImageGrabber->IsCameraActive()) { m_ToFImageGrabber->StartCamera(); } } void QmitkToFRecorderWidget::StopCamera() { m_ToFImageGrabber->StopCamera(); } void QmitkToFRecorderWidget::StopRecorder() { this->m_ToFImageRecorder->StopRecording(); } void QmitkToFRecorderWidget::OnStartRecorder() { m_Controls->m_StartRecordingButton->setChecked(true); m_Controls->m_RecorderGroupBox->setEnabled(false); this->repaint(); int numOfFrames = m_Controls->m_NumOfFramesSpinBox->value(); try { bool fileOK = true; bool distanceImageSelected = true; bool amplitudeImageSelected = true; bool intensityImageSelected = true; bool rawDataSelected = false; QString tmpFileName(""); QString selectedFilter(""); QString imageFileName(""); mitk::ToFImageWriter::ToFImageType tofImageType; tmpFileName = QmitkToFRecorderWidget::getSaveFileName(tofImageType, distanceImageSelected, amplitudeImageSelected, intensityImageSelected, rawDataSelected, NULL, "Save Image To...", imageFileName, "MITK-Images (*.nrrd);;MITK-Images (*.pic)(deprecated);;Text (*.csv)", &selectedFilter); if (tmpFileName.isEmpty()) { fileOK = false; } else { imageFileName = tmpFileName; } if (fileOK) { std::string dir = itksys::SystemTools::GetFilenamePath( imageFileName.toStdString() ); std::string baseFilename = itksys::SystemTools::GetFilenameWithoutLastExtension( imageFileName.toStdString() ); std::string extension = itksys::SystemTools::GetFilenameLastExtension( imageFileName.toStdString() ); int integrationTime = this->m_ToFImageGrabber->GetIntegrationTime(); int modulationFreq = this->m_ToFImageGrabber->GetModulationFrequency(); QString integrationTimeStr; integrationTimeStr.setNum(integrationTime); QString modulationFreqStr; modulationFreqStr.setNum(modulationFreq); QString numOfFramesStr(""); if (this->m_RecordMode == mitk::ToFImageRecorder::PerFrames) { numOfFramesStr.setNum(numOfFrames); } std::string distImageFileName = prepareFilename(dir, baseFilename, modulationFreqStr.toStdString(), integrationTimeStr.toStdString(), numOfFramesStr.toStdString(), extension, "_DistanceImage"); MITK_INFO << "Save distance data to: " << distImageFileName; std::string amplImageFileName = prepareFilename(dir, baseFilename, modulationFreqStr.toStdString(), integrationTimeStr.toStdString(), numOfFramesStr.toStdString(), extension, "_AmplitudeImage"); MITK_INFO << "Save amplitude data to: " << amplImageFileName; std::string intenImageFileName = prepareFilename(dir, baseFilename, modulationFreqStr.toStdString(), integrationTimeStr.toStdString(), numOfFramesStr.toStdString(), extension, "_IntensityImage"); MITK_INFO << "Save intensity data to: " << intenImageFileName; if (selectedFilter.compare("Text (*.csv)") == 0) { - this->m_ToFImageRecorder->SetFileFormat("csv"); + this->m_ToFImageRecorder->SetFileFormat(".csv"); } - else if (selectedFilter.compare("MITK-Images (*.pic)") == 0) + else if (selectedFilter.compare("MITK-Images (*.pic)(deprecated)") == 0) { //default - this->m_ToFImageRecorder->SetFileFormat("pic"); + this->m_ToFImageRecorder->SetFileFormat(".pic"); QMessageBox::warning(NULL, "Deprecated File Format!", "Please note that *.pic file format is deprecated and not longer supported! The suggested file format for images is *.nrrd!"); } else if (selectedFilter.compare("MITK-Images (*.nrrd)") == 0) { - this->m_ToFImageRecorder->SetFileFormat("nrrd"); + this->m_ToFImageRecorder->SetFileFormat(".nrrd"); } else { QMessageBox::warning(NULL, "Unsupported file format!", "Please specify one of the supported file formats *.nrrd, *.csv!"); return; } numOfFrames = m_Controls->m_NumOfFramesSpinBox->value(); this->m_ToFImageRecorder->SetDistanceImageFileName(distImageFileName); this->m_ToFImageRecorder->SetAmplitudeImageFileName(amplImageFileName); this->m_ToFImageRecorder->SetIntensityImageFileName(intenImageFileName); this->m_ToFImageRecorder->SetToFImageType(tofImageType); this->m_ToFImageRecorder->SetDistanceImageSelected(distanceImageSelected); this->m_ToFImageRecorder->SetAmplitudeImageSelected(amplitudeImageSelected); this->m_ToFImageRecorder->SetIntensityImageSelected(intensityImageSelected); this->m_ToFImageRecorder->SetRecordMode(this->m_RecordMode); this->m_ToFImageRecorder->SetNumOfFrames(numOfFrames); this->m_ToFImageRecorder->StartRecording(); } else { this->OnRecordingStopped(); } } catch(std::exception& e) { QMessageBox::critical(NULL, "Error", QString(e.what())); this->OnRecordingStopped(); } } QString QmitkToFRecorderWidget::getSaveFileName(mitk::ToFImageWriter::ToFImageType& tofImageType, bool& distanceImageSelected, bool& amplitudeImageSelected, bool& intensityImageSelected, bool& rawDataSelected, QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options ) { QString selectedFileName = ""; QComboBox* combo = new QComboBox; combo->addItem("3D"); combo->addItem("2D + t"); QHBoxLayout* checkBoxGroup = new QHBoxLayout(); QCheckBox* distanceImageCheckBox = new QCheckBox; distanceImageCheckBox->setText("Distance image"); distanceImageCheckBox->setChecked(true); QCheckBox* amplitudeImageCheckBox = new QCheckBox; amplitudeImageCheckBox->setText("Amplitude image"); amplitudeImageCheckBox->setChecked(true); QCheckBox* intensityImageCheckBox = new QCheckBox; intensityImageCheckBox->setText("Intensity image"); intensityImageCheckBox->setChecked(true); QCheckBox* rawDataCheckBox = new QCheckBox; rawDataCheckBox->setText("Raw data"); rawDataCheckBox->setChecked(false); rawDataCheckBox->setEnabled(false); checkBoxGroup->addWidget(distanceImageCheckBox); checkBoxGroup->addWidget(amplitudeImageCheckBox); checkBoxGroup->addWidget(intensityImageCheckBox); checkBoxGroup->addWidget(rawDataCheckBox); QFileDialog* fileDialog = new QFileDialog(parent, caption, dir, filter); QLayout* layout = fileDialog->layout(); QGridLayout* gridbox = qobject_cast(layout); if (gridbox) { gridbox->addWidget(new QLabel("ToF-Image type:")); gridbox->addWidget(combo); int lastRow = gridbox->rowCount(); gridbox->addLayout(checkBoxGroup, lastRow, 0, 1, -1); } fileDialog->setLayout(gridbox); fileDialog->setAcceptMode(QFileDialog::AcceptSave); if (selectedFilter) { fileDialog->selectNameFilter(*selectedFilter); } if (fileDialog->exec() == QDialog::Accepted) { if (selectedFilter) { *selectedFilter = fileDialog->selectedFilter(); } if (combo->currentIndex() == 0) { tofImageType = mitk::ToFImageWriter::ToFImageType3D; } else { tofImageType = mitk::ToFImageWriter::ToFImageType2DPlusT; } distanceImageSelected = distanceImageCheckBox->isChecked(); amplitudeImageSelected = amplitudeImageCheckBox->isChecked(); intensityImageSelected = intensityImageCheckBox->isChecked(); rawDataSelected = rawDataCheckBox->isChecked(); selectedFileName = fileDialog->selectedFiles().value(0); } delete fileDialog; return selectedFileName; } std::string QmitkToFRecorderWidget::prepareFilename(std::string dir, std::string baseFilename, std::string modulationFreq, std::string integrationTime, std::string numOfFrames, std::string extension, std::string imageType) { std::string filenName(""); filenName.append(dir); filenName.append("/"); filenName.append(baseFilename); filenName.append("_MF"); filenName.append(modulationFreq); filenName.append("_IT"); filenName.append(integrationTime); filenName.append("_"); filenName.append(numOfFrames); filenName.append("Images"); filenName.append(imageType); filenName.append(extension); return filenName; } void QmitkToFRecorderWidget::OnChangeRecordModeComboBox(int index) { if (index == 0) { this->m_RecordMode = mitk::ToFImageRecorder::PerFrames; m_Controls->m_NumOfFramesSpinBox->setEnabled(true); } else { this->m_RecordMode = mitk::ToFImageRecorder::Infinite; m_Controls->m_NumOfFramesSpinBox->setEnabled(false); } }