diff --git a/Modules/ToFHardware/Testing/files.cmake b/Modules/ToFHardware/Testing/files.cmake index 10d288bdc2..f82fc2349b 100644 --- a/Modules/ToFHardware/Testing/files.cmake +++ b/Modules/ToFHardware/Testing/files.cmake @@ -1,32 +1,31 @@ SET(MODULE_TESTS mitkThreadedToFRawDataReconstructionTest.cpp mitkToFCameraMITKPlayerControllerTest.cpp mitkToFCameraMITKPlayerDeviceTest.cpp mitkToFCameraPMDCamBoardControllerTest.cpp mitkToFCameraPMDCamBoardDeviceTest.cpp #mitkToFCameraPMDRawDataCamBoardDeviceTest.cpp mitkToFCameraPMDCamCubeControllerTest.cpp mitkToFCameraPMDCamCubeDeviceTest.cpp #mitkToFCameraPMDRawDataCamCubeDeviceTest.cpp mitkToFCameraPMDControllerTest.cpp mitkToFCameraPMDDeviceTest.cpp mitkToFCameraPMDRawDataDeviceTest.cpp mitkToFCameraPMDMITKPlayerControllerTest.cpp mitkToFCameraPMDMITKPlayerDeviceTest.cpp mitkToFCameraPMDO3ControllerTest.cpp mitkToFCameraPMDO3DeviceTest.cpp mitkToFCameraPMDPlayerControllerTest.cpp mitkToFCameraPMDPlayerDeviceTest.cpp mitkToFImageCsvWriterTest.cpp mitkToFImageGrabberTest.cpp mitkToFImageGrabberCreatorTest.cpp mitkToFImageRecorderTest.cpp mitkToFImageRecorderFilterTest.cpp mitkToFImageWriterTest.cpp mitkToFNrrdImageWriterTest.cpp - mitkToFPicImageWriterTest.cpp mitkToFOpenCVImageGrabberTest.cpp mitkKinectControllerTest.cpp mitkKinectDeviceTest.cpp ) diff --git a/Modules/ToFHardware/Testing/mitkToFPicImageWriterTest.cpp b/Modules/ToFHardware/Testing/mitkToFPicImageWriterTest.cpp deleted file mode 100644 index 9247a2fbbe..0000000000 --- a/Modules/ToFHardware/Testing/mitkToFPicImageWriterTest.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/*========================================================================= - -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 "ToFPicImageWriter". - */ -int mitkToFPicImageWriterTest(int /* argc */, char* /*argv*/[]) -{ - MITK_TEST_BEGIN("ToFPicImageWriter"); - - mitk::ToFPicImageWriter::Pointer tofPicWriter = mitk::ToFPicImageWriter::New(); - MITK_TEST_CONDITION_REQUIRED(tofPicWriter.GetPointer(), "Testing initialization of test object!"); - MITK_TEST_CONDITION_REQUIRED(tofPicWriter->GetExtension() == ".pic", "Testing initialization of extension member variable!"); - - //run the test with some unusual parameters - unsigned int dimX = 255; - unsigned int dimY = 188; - unsigned int pixelNumber = dimX*dimY; - unsigned int numOfFrames = 117; //or numberOfSlices - - //create 3 images filled with random values - mitk::Image::Pointer distanceImage = mitk::ImageGenerator::GenerateRandomImage(dimX, dimY, numOfFrames,0); - mitk::Image::Pointer amplitudeImage = mitk::ImageGenerator::GenerateRandomImage(dimX, dimY, numOfFrames,0); - mitk::Image::Pointer intensityImage = mitk::ImageGenerator::GenerateRandomImage(dimX, dimY, numOfFrames,0); - - //file names on the disc - std::string distanceImageFileName("distImg.pic"); - std::string amplitudeImageFileName("amplImg.pic"); - std::string intensityImageFileName("intImg.pic"); - - tofPicWriter->SetDistanceImageFileName(distanceImageFileName); - tofPicWriter->SetAmplitudeImageFileName(amplitudeImageFileName); - tofPicWriter->SetIntensityImageFileName(intensityImageFileName); - tofPicWriter->SetCaptureWidth(dimX); - tofPicWriter->SetCaptureHeight(dimY); - tofPicWriter->SetToFImageType(mitk::ToFImageWriter::ToFImageType3D); - - //buffer for each slice - float* distanceArray; - float* amplitudeArray; - float* intensityArray; - - float* distanceArrayRead; - float* amplitudeArrayRead; - float* intensityArrayRead; - - tofPicWriter->Open(); //open file/stream - //Note: the slices are written out reverse order, because the ToFPicImageWriter 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 - tofPicWriter->Add(distanceArray, amplitudeArray, intensityArray); - } - tofPicWriter->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 #pragma GCC visibility push(default) #include #pragma GCC visibility pop namespace mitk { ToFImageRecorder::ToFImageRecorder() { this->m_ToFCameraDevice = NULL; this->m_MultiThreader = itk::MultiThreader::New(); this->m_AbortMutex = itk::FastMutexLock::New(); this->m_ThreadID = 0; this->m_NumOfFrames = 0; this->m_ToFImageWriter = NULL; this->m_DistanceImageSelected = true; this->m_AmplitudeImageSelected = true; this->m_IntensityImageSelected = true; this->m_RGBImageSelected = 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_RGBImageFileName = ""; this->m_ImageSequence = 0; this->m_DistanceArray = NULL; this->m_AmplitudeArray = NULL; this->m_IntensityArray = NULL; this->m_RGBArray = NULL; this->m_SourceDataArray = NULL; } ToFImageRecorder::~ToFImageRecorder() { delete[] m_DistanceArray; delete[] m_AmplitudeArray; delete[] m_IntensityArray; delete[] m_RGBArray; delete[] m_SourceDataArray; } void ToFImageRecorder::StopRecording() { this->m_AbortMutex->Lock(); this->m_Abort = true; this->m_AbortMutex->Unlock(); } void ToFImageRecorder::StartRecording() { if (this->m_ToFCameraDevice.IsNull()) { throw std::invalid_argument("ToFCameraDevice is NULL."); return; } if (this->m_FileFormat.compare(".csv") == 0) { this->m_ToFImageWriter = ToFImageCsvWriter::New(); } else if(this->m_FileFormat.compare(".nrrd") == 0) { this->m_ToFImageWriter = ToFNrrdImageWriter::New(); this->m_ToFImageWriter->SetExtension(m_FileFormat); } - else if(this->m_FileFormat.compare(".pic") == 0) - { - this->m_ToFImageWriter = ToFPicImageWriter::New(); - this->m_ToFImageWriter->SetExtension(m_FileFormat); - } else { throw std::logic_error("No file format specified!"); } 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_RGBArray == NULL) { this->m_RGBArray = new unsigned char[m_PixelNumber*3]; } if(this->m_SourceDataArray == NULL) { this->m_SourceDataArray = new char[m_SourceDataSize]; } this->m_ToFImageWriter->SetDistanceImageFileName(this->m_DistanceImageFileName); this->m_ToFImageWriter->SetAmplitudeImageFileName(this->m_AmplitudeImageFileName); this->m_ToFImageWriter->SetIntensityImageFileName(this->m_IntensityImageFileName); this->m_ToFImageWriter->SetRGBImageFileName(this->m_RGBImageFileName); this->m_ToFImageWriter->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->SetRGBImageSelected(this->m_RGBImageSelected); this->m_ToFImageWriter->Open(); this->m_AbortMutex->Lock(); this->m_Abort = false; this->m_AbortMutex->Unlock(); this->m_ThreadID = this->m_MultiThreader->SpawnThread(this->RecordData, this); } ITK_THREAD_RETURN_TYPE ToFImageRecorder::RecordData(void* pInfoStruct) { struct itk::MultiThreader::ThreadInfoStruct * pInfo = (struct itk::MultiThreader::ThreadInfoStruct*)pInfoStruct; if (pInfo == NULL) { return ITK_THREAD_RETURN_VALUE; } if (pInfo->UserData == NULL) { return ITK_THREAD_RETURN_VALUE; } ToFImageRecorder* toFImageRecorder = (ToFImageRecorder*)pInfo->UserData; if (toFImageRecorder!=NULL) { ToFCameraDevice::Pointer toFCameraDevice = toFImageRecorder->GetCameraDevice(); mitk::RealTimeClock::Pointer realTimeClock; realTimeClock = mitk::RealTimeClock::New(); int n = 100; double t1 = 0; double t2 = 0; t1 = realTimeClock->GetCurrentStamp(); bool overflow = false; bool printStatus = false; int requiredImageSequence = 0; int numOfFramesRecorded = 0; bool abort = false; toFImageRecorder->m_AbortMutex->Lock(); abort = toFImageRecorder->m_Abort; toFImageRecorder->m_AbortMutex->Unlock(); while ( !abort ) { if ( ((toFImageRecorder->m_RecordMode == ToFImageRecorder::PerFrames) && (numOfFramesRecorded < toFImageRecorder->m_NumOfFrames)) || (toFImageRecorder->m_RecordMode == ToFImageRecorder::Infinite) ) { toFCameraDevice->GetAllImages(toFImageRecorder->m_DistanceArray, toFImageRecorder->m_AmplitudeArray, toFImageRecorder->m_IntensityArray, toFImageRecorder->m_SourceDataArray, requiredImageSequence, toFImageRecorder->m_ImageSequence, toFImageRecorder->m_RGBArray ); if (toFImageRecorder->m_ImageSequence >= requiredImageSequence) { if (toFImageRecorder->m_ImageSequence > requiredImageSequence) { MITK_INFO << "Problem! required: " << requiredImageSequence << " captured: " << toFImageRecorder->m_ImageSequence; } requiredImageSequence = toFImageRecorder->m_ImageSequence + 1; toFImageRecorder->m_ToFImageWriter->Add( toFImageRecorder->m_DistanceArray, toFImageRecorder->m_AmplitudeArray, toFImageRecorder->m_IntensityArray, toFImageRecorder->m_RGBArray ); numOfFramesRecorded++; if (numOfFramesRecorded % n == 0) { printStatus = true; } if (printStatus) { t2 = realTimeClock->GetCurrentStamp() - t1; MITK_INFO << " Framerate (fps): " << n / (t2/1000) << " Sequence: " << toFImageRecorder->m_ImageSequence; t1 = realTimeClock->GetCurrentStamp(); printStatus = false; } } toFImageRecorder->m_AbortMutex->Lock(); abort = toFImageRecorder->m_Abort; toFImageRecorder->m_AbortMutex->Unlock(); } else { abort = true; } } // end of while loop toFImageRecorder->InvokeEvent(itk::AbortEvent()); toFImageRecorder->m_ToFImageWriter->Close(); } return ITK_THREAD_RETURN_VALUE; } void ToFImageRecorder::SetCameraDevice(ToFCameraDevice* aToFCameraDevice) { this->m_ToFCameraDevice = aToFCameraDevice; } ToFCameraDevice* ToFImageRecorder::GetCameraDevice() { return this->m_ToFCameraDevice; } ToFImageWriter::ToFImageType ToFImageRecorder::GetToFImageType() { return this->m_ToFImageType; } void ToFImageRecorder::SetToFImageType(ToFImageWriter::ToFImageType toFImageType) { this->m_ToFImageType = toFImageType; } ToFImageRecorder::RecordMode ToFImageRecorder::GetRecordMode() { return this->m_RecordMode; } void ToFImageRecorder::SetRecordMode(ToFImageRecorder::RecordMode recordMode) { this->m_RecordMode = recordMode; } } diff --git a/Modules/ToFHardware/mitkToFImageRecorder.h b/Modules/ToFHardware/mitkToFImageRecorder.h index d03404774e..607db7f0eb 100644 --- a/Modules/ToFHardware/mitkToFImageRecorder.h +++ b/Modules/ToFHardware/mitkToFImageRecorder.h @@ -1,169 +1,168 @@ /*========================================================================= 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 "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( RGBImageFileName, std::string ); itkGetMacro( CaptureWidth, int ); itkGetMacro( CaptureHeight, int ); itkGetMacro( DistanceImageSelected, bool ); itkGetMacro( AmplitudeImageSelected, bool ); itkGetMacro( IntensityImageSelected, bool ); itkGetMacro( RGBImageSelected, bool ); itkGetMacro( NumOfFrames, int ); itkGetMacro( FileFormat, std::string ); itkSetMacro( DistanceImageFileName, std::string ); itkSetMacro( AmplitudeImageFileName, std::string ); itkSetMacro( IntensityImageFileName, std::string ); itkSetMacro(RGBImageFileName, std::string ); itkSetMacro( DistanceImageSelected, bool ); itkSetMacro( AmplitudeImageSelected, bool ); itkSetMacro( IntensityImageSelected, bool ); itkSetMacro( RGBImageSelected, 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 unsigned char* m_RGBArray; ///< array holding the RGB data if available (e.g. for Kinect) 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 std::string m_RGBImageFileName; ///< file name for saving the rgb 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 bool m_RGBImageSelected; ///< flag indicating if rgb 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/mitkToFImageRecorderFilter.cpp b/Modules/ToFHardware/mitkToFImageRecorderFilter.cpp index 06cc48af9d..cb21b27ab2 100644 --- a/Modules/ToFHardware/mitkToFImageRecorderFilter.cpp +++ b/Modules/ToFHardware/mitkToFImageRecorderFilter.cpp @@ -1,170 +1,165 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date $ 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 "mitkToFNrrdImageWriter.h" -#include "mitkToFPicImageWriter.h" #include "mitkToFImageCsvWriter.h" // itk includes #include "itksys/SystemTools.hxx" mitk::ToFImageRecorderFilter::ToFImageRecorderFilter(): m_RecordingStarted(false), m_ToFImageWriter(0) { m_FileExtension = ""; } mitk::ToFImageRecorderFilter::~ToFImageRecorderFilter() { } void mitk::ToFImageRecorderFilter::SetFileName(std::string fileName) { std::string name = fileName; m_FileExtension = itksys::SystemTools::GetFilenameLastExtension( fileName ); if(m_FileExtension == ".nrrd") { m_ToFImageWriter = mitk::ToFNrrdImageWriter::New(); } - else if(m_FileExtension == ".pic") - { - m_ToFImageWriter = mitk::ToFPicImageWriter::New(); - } else if(m_FileExtension == ".csv") { m_ToFImageWriter = mitk::ToFImageCsvWriter::New(); } else { throw std::logic_error("The specified file type is not supported, standard file type is .nrrd!"); } int pos = name.find_last_of("."); name.insert(pos,"_DistanceImage"); m_ToFImageWriter->SetDistanceImageFileName(name); name = fileName; name.insert(pos,"_AmplitudeImage"); m_ToFImageWriter->SetAmplitudeImageFileName(name); name = fileName; name.insert(pos,"_IntensityImage"); m_ToFImageWriter->SetIntensityImageFileName(name); } void mitk::ToFImageRecorderFilter::SetImageType(mitk::ToFImageWriter::ToFImageType tofImageType) { m_ToFImageWriter->SetToFImageType(tofImageType); } void mitk::ToFImageRecorderFilter::GenerateData() { mitk::Image::Pointer distanceImageInput = this->GetInput(0); assert(distanceImageInput); mitk::Image::Pointer amplitudeImageInput = this->GetInput(1); assert(amplitudeImageInput); mitk::Image::Pointer intensityImageInput = this->GetInput(2); assert(intensityImageInput); // add current data to file stream float* distanceFloatData = (float*)distanceImageInput->GetSliceData(0, 0, 0)->GetData(); float* amplitudeFloatData = (float*)amplitudeImageInput->GetSliceData(0, 0, 0)->GetData(); float* intensityFloatData = (float*)intensityImageInput->GetSliceData(0, 0, 0)->GetData(); if (m_RecordingStarted) { m_ToFImageWriter->Add(distanceFloatData,amplitudeFloatData,intensityFloatData); } // set outputs to inputs this->SetNthOutput(0,distanceImageInput); this->SetNthOutput(1,amplitudeImageInput); this->SetNthOutput(2,intensityImageInput); } void mitk::ToFImageRecorderFilter::StartRecording() { if(m_ToFImageWriter.IsNull()) { throw std::logic_error("ToFImageWriter is unitialized, set filename first!"); return; } m_ToFImageWriter->Open(); m_RecordingStarted = true; } void mitk::ToFImageRecorderFilter::StopRecording() { m_ToFImageWriter->Close(); m_RecordingStarted = false; } mitk::ToFImageWriter::Pointer mitk::ToFImageRecorderFilter::GetToFImageWriter() { return m_ToFImageWriter; } void mitk::ToFImageRecorderFilter::SetToFImageWriter(mitk::ToFImageWriter::Pointer tofImageWriter) { m_ToFImageWriter = tofImageWriter; } void mitk::ToFImageRecorderFilter::SetInput( mitk::Image* input ) { this->SetInput(0,input); } void mitk::ToFImageRecorderFilter::SetInput( unsigned int idx, mitk::Image* input ) { if ((input == NULL) && (idx == this->GetNumberOfInputs() - 1)) // if the last input is set to NULL, reduce the number of inputs by one { this->SetNumberOfInputs(this->GetNumberOfInputs() - 1); } else { this->ProcessObject::SetNthInput(idx, input); // Process object is not const-correct so the const_cast is required here unsigned int xDim = input->GetDimension(0); unsigned int yDim = input->GetDimension(1); m_ToFImageWriter->SetCaptureWidth(xDim); m_ToFImageWriter->SetCaptureWidth(yDim); } this->CreateOutputsForAllInputs(); } mitk::Image* mitk::ToFImageRecorderFilter::GetInput() { return this->GetInput(0); } mitk::Image* mitk::ToFImageRecorderFilter::GetInput( unsigned int idx ) { if (this->GetNumberOfInputs() < 1) return NULL; return static_cast< mitk::Image*>(this->ProcessObject::GetInput(idx)); } void mitk::ToFImageRecorderFilter::CreateOutputsForAllInputs() { this->SetNumberOfOutputs(this->GetNumberOfInputs()); // create outputs for all inputs for (unsigned int idx = 0; idx < this->GetNumberOfOutputs(); ++idx) if (this->GetOutput(idx) == NULL) { DataObjectPointer newOutput = this->MakeOutput(idx); this->SetNthOutput(idx, newOutput); } this->Modified(); } diff --git a/Modules/ToFHardware/mitkToFPicImageWriter.cpp b/Modules/ToFHardware/mitkToFPicImageWriter.cpp deleted file mode 100644 index 6d67ddd37b..0000000000 --- a/Modules/ToFHardware/mitkToFPicImageWriter.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/*========================================================================= - -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 - -// deprecated support of mitkIpPic -#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 -{ - ToFPicImageWriter::ToFPicImageWriter(): ToFImageWriter(), m_DistanceOutfile(NULL), - m_AmplitudeOutfile(NULL), m_IntensityOutfile(NULL) - { - m_Extension = std::string(".pic"); - } - - ToFPicImageWriter::~ToFPicImageWriter() - { - } - - 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; - - mitk::PixelType FloatType = MakeScalarPixelType(); - if (this->m_ToFImageType == ToFImageWriter::ToFImageType2DPlusT) - { - dimensions[2] = 1; - dimensions[3] = 2; - this->m_MitkImage->Initialize( FloatType, 4, dimensions, 1); - } - else - { - dimensions[2] = 2; - dimensions[3] = 1; - this->m_MitkImage->Initialize( FloatType, 3, dimensions, 1); - } - this->m_MitkImage->SetSlice(floatData, 0, 0, 0); - - mitkIpPicDescriptor* pic = mitkIpPicNew(); - CastToIpPicDescriptor( this->m_MitkImage, pic); - - 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 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 ToFPicImageWriter::Add(float* distanceFloatData, float* amplitudeFloatData, float* intensityFloatData, unsigned char* rgbData) - { - 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 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 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 ToFPicImageWriter::ReplacePicFileHeader(FILE* outfile) - { - mitkIpPicDescriptor* pic = mitkIpPicNew(); - CastToIpPicDescriptor( this->m_MitkImage, pic); - - 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 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 ); - } - -} // end namespace mitk diff --git a/Modules/ToFHardware/mitkToFPicImageWriter.h b/Modules/ToFHardware/mitkToFPicImageWriter.h deleted file mode 100644 index a12140ccb5..0000000000 --- a/Modules/ToFHardware/mitkToFPicImageWriter.h +++ /dev/null @@ -1,91 +0,0 @@ -/*========================================================================= - -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 __mitkToFPicImageWriter_h -#define __mitkToFPicImageWriter_h - -#include "mitkToFHardwareExports.h" -#include "mitkToFImageWriter.h" - -#include - -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 ToFPicImageWriter : public ToFImageWriter - { - public: - - ToFPicImageWriter(); - - ~ToFPicImageWriter(); - - mitkClassMacro( ToFPicImageWriter , ToFImageWriter ); - itkNewMacro( Self ); - - /*! - \brief Open file(s) for writing - */ - void Open(); - /*! - \brief Close file(s) add .pic header and write - */ - void Close(); - /*! - \brief Add new data to file. - */ - void Add(float* distanceFloatData, float* amplitudeFloatData, float* intensityFloatData, unsigned char* rgbData=0); - - 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 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 // __mitkToFPicImageWriter_h