Medical Imaging Interaction Toolkit  2018.4.99-07c45cb1
Medical Imaging Interaction Toolkit
mitkToFImageCsvWriter.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 #include <mitkToFImageCsvWriter.h>
13 
14 namespace 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 
23  {
24  }
25 
27  {
31 
33  this->m_ToFImageSizeInBytes = this->m_ToFPixelNumber * sizeof(float);
34 
35  if (this->m_DistanceImageSelected)
36  {
37  this->OpenCsvFile(&(this->m_DistanceOutfile), this->m_DistanceImageFileName);
38  }
39  if (this->m_AmplitudeImageSelected)
40  {
41  this->OpenCsvFile(&(this->m_AmplitudeOutfile), this->m_AmplitudeImageFileName);
42  }
43  if (this->m_IntensityImageSelected)
44  {
45  this->OpenCsvFile(&(this->m_IntensityOutfile), this->m_IntensityImageFileName);
46  }
47  this->m_NumOfFrames = 0;
48  }
49 
51  {
52  if (this->m_DistanceImageSelected)
53  {
54  this->CloseCsvFile(this->m_DistanceOutfile);
55  }
56  if (this->m_AmplitudeImageSelected)
57  {
58  this->CloseCsvFile(this->m_AmplitudeOutfile);
59  }
60  if (this->m_IntensityImageSelected)
61  {
62  this->CloseCsvFile(this->m_IntensityOutfile);
63  }
64  }
65 
66  void ToFImageCsvWriter::Add(float* distanceFloatData, float* amplitudeFloatData, float* intensityFloatData, unsigned char*)
67  {
68  if (this->m_DistanceImageSelected)
69  {
70  this->WriteCsvFile(this->m_DistanceOutfile, distanceFloatData);
71  }
72  if (this->m_AmplitudeImageSelected)
73  {
74  this->WriteCsvFile(this->m_AmplitudeOutfile, amplitudeFloatData);
75  }
76  if (this->m_IntensityImageSelected)
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 }
void Open() override
Checks for file extensions and opens the output files.
bool m_AmplitudeImageSelected
flag indicating if amplitude image should be recorded
int m_NumOfFrames
number of frames written to the image. Used for pic header.
bool m_IntensityImageSelected
flag indicating if intensity image should be recorded
void CheckForFileExtension(std::string &fileName)
Checks file name if file extension exists. If not an error message is returned.
#define MITK_ERROR
Definition: mitkLogMacros.h:20
bool m_DistanceImageSelected
flag indicating if distance image should be recorded
DataCollection - Class to facilitate loading/accessing structured data.
FILE * m_IntensityOutfile
file for intensity image
void Close() override
Closes the output files.
int m_ToFCaptureWidth
width (x-dimension) of the images to record.
void Add(float *distanceFloatData, float *amplitudeFloatData, float *intensityFloatData, unsigned char *rgbData=nullptr) override
Pushes the image data to the output files.
int m_ToFCaptureHeight
height (y-dimension) of the images to record.
std::string m_IntensityImageFileName
file name for saving the intensity image
std::string m_AmplitudeImageFileName
file name for saving the amplitude image
int m_ToFPixelNumber
number of pixels (widht*height) of the images to record
std::string m_Extension
file extension used for saving images
Writer class for ToF images.
std::string m_DistanceImageFileName
file name for saving the distance image
FILE * m_DistanceOutfile
file for distance image
int m_ToFImageSizeInBytes
size of the image to save in bytes
FILE * m_AmplitudeOutfile
file for amplitude image
~ToFImageCsvWriter() override
standard ~ctor