MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkToFImageCsvWriter.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
13
14namespace mitk
15{
16 ToFImageCsvWriter::ToFImageCsvWriter(): ToFImageWriter(), m_DistanceOutfile(nullptr),
17 m_AmplitudeOutfile(nullptr), m_IntensityOutfile(nullptr)
18 {
19 this->m_Extension = std::string(".csv");
20 }
21
25
27 {
31
33 this->m_ToFImageSizeInBytes = this->m_ToFPixelNumber * sizeof(float);
34
36 {
37 this->OpenCsvFile(&(this->m_DistanceOutfile), this->m_DistanceImageFileName);
38 }
40 {
41 this->OpenCsvFile(&(this->m_AmplitudeOutfile), this->m_AmplitudeImageFileName);
42 }
44 {
45 this->OpenCsvFile(&(this->m_IntensityOutfile), this->m_IntensityImageFileName);
46 }
47 this->m_NumOfFrames = 0;
48 }
49
51 {
53 {
54 this->CloseCsvFile(this->m_DistanceOutfile);
55 }
57 {
58 this->CloseCsvFile(this->m_AmplitudeOutfile);
59 }
61 {
62 this->CloseCsvFile(this->m_IntensityOutfile);
63 }
64 }
65
66 void ToFImageCsvWriter::Add(float* distanceFloatData, float* amplitudeFloatData, float* intensityFloatData, unsigned char*)
67 {
69 {
70 this->WriteCsvFile(this->m_DistanceOutfile, distanceFloatData);
71 }
73 {
74 this->WriteCsvFile(this->m_AmplitudeOutfile, amplitudeFloatData);
75 }
77 {
78 this->WriteCsvFile(this->m_IntensityOutfile, intensityFloatData);
79 }
80 this->m_NumOfFrames++;
81 }
82
83 void ToFImageCsvWriter::WriteCsvFile(FILE* outfile, float* floatData)
84 {
85 for(int i=0; i<this->m_ToFPixelNumber; i++)
86 {
87 if (this->m_NumOfFrames==0 && i==0)
88 {
89 fprintf(outfile, "%f", floatData[i]);
90 }
91 else
92 {
93 fprintf(outfile, ",%f", floatData[i]);
94 }
95 }
96 }
97
98 void ToFImageCsvWriter::OpenCsvFile(FILE** outfile, std::string outfileName)
99 {
100 (*outfile) = fopen( outfileName.c_str(), "w+" );
101 if( !outfile )
102 {
103 MITK_ERROR << "Error opening outfile: " << outfileName;
104 throw std::logic_error("Error opening outfile.");
105 return;
106 }
107 }
108
109 void ToFImageCsvWriter::CloseCsvFile(FILE* outfile)
110 {
111 if (this->m_NumOfFrames == 0)
112 {
113 fclose(outfile);
114 throw std::logic_error("File is empty.");
115 return;
116 }
117 fclose(outfile);
118 }
119
120}
~ToFImageCsvWriter() override
standard ~ctor
void Add(float *distanceFloatData, float *amplitudeFloatData, float *intensityFloatData, unsigned char *rgbData=nullptr) override
Pushes the image data to the output files.
FILE * m_IntensityOutfile
file for intensity image
FILE * m_AmplitudeOutfile
file for amplitude image
FILE * m_DistanceOutfile
file for distance image
void Close() override
Closes the output files.
Writer class for ToF images.
virtual void Open()
Open file(s) for writing.
std::string m_DistanceImageFileName
file name for saving the distance image
std::string m_IntensityImageFileName
file name for saving the intensity image
bool m_DistanceImageSelected
flag indicating if distance image should be recorded
int m_ToFPixelNumber
number of pixels (widht*height) of the images to record
bool m_AmplitudeImageSelected
flag indicating if amplitude image should be recorded
std::string m_Extension
file extension used for saving images
std::string m_AmplitudeImageFileName
file name for saving the amplitude image
int m_NumOfFrames
number of frames written to the image. Used for pic header.
int m_ToFCaptureWidth
width (x-dimension) of the images to record.
int m_ToFImageSizeInBytes
size of the image to save in bytes
void CheckForFileExtension(std::string &fileName)
Checks file name if file extension exists. If not an error message is returned.
bool m_IntensityImageSelected
flag indicating if intensity image should be recorded
int m_ToFCaptureHeight
height (y-dimension) of the images to record.
IGT Exceptions.