1 #include "clitkDicomWave2Text.h"
2 #include "clitkDicomWave2Text_ggo.h"
4 #include "clitkCommon.h"
7 #if GDCM_MAJOR_VERSION < 2
8 #include "gdcmBinEntry.h"
10 #include "gdcmReader.h"
11 #include "gdcmPrivateTag.h"
18 bool wave2stream( std::ostream &text_file, const short *buffer, int length )
21 text_file << "COMPLETE_WAVE" << '\t' << "MASK" << '\t' << "AQUISITION_PROFIL" << '\t' << "END-INHALE" << '\t' << "END-EXHALE" << '\t' << "AQUISITION_WAVE" << '\t' << "WAVE_STATISTICS" << '\t' << "MASK" << std::endl;
22 for (int i=0;i<length-76;i+=2)
32 stat="Sampling rate (Hz)";
38 if (buffer[i+75] == 0)
39 text_file << buffer[i+74] << '\t' << buffer[i+75] << '\t' << 0 << '\t' << " " << '\t' << " " << '\t' << " " << '\t' << buffer[i] << '\t' << buffer[i+1] << '\t' << stat << std::endl;
40 if (buffer[i+75] == 16384)
41 text_file << buffer[i+74] << '\t' << buffer[i+75] << '\t' << 0 << '\t' << buffer[i+74] << '\t' << " " << '\t' << " " << '\t' << buffer[i] << '\t' << buffer[i+1] << '\t' << stat << std::endl;
42 if (buffer[i+75] == 256)
43 text_file << buffer[i+74] << '\t' << buffer[i+75] << '\t' << 0 << '\t' << " " << '\t' << buffer[i+74] << '\t' << " " << '\t' << buffer[i] << '\t' << buffer[i+1] << '\t' << stat << std::endl;
44 if (buffer[i+75] == -32768)
45 text_file << buffer[i+74] << '\t' << buffer[i+75] << '\t' << 1 << '\t' << " " << '\t' << " " << '\t' << buffer[i+74] << '\t' << buffer[i] << '\t' << buffer[i+1] << '\t' << stat << std::endl;
46 if (buffer[i+75] == -16384)
47 text_file << buffer[i+74] << '\t' << buffer[i+75] << '\t' << 1 << '\t' << buffer[i+74] << '\t' << " " << '\t' << buffer[i+74] << '\t' << buffer[i] << '\t' << buffer[i+1] << '\t' << stat << std::endl;
48 if (buffer[i+75] == -32512)
49 text_file << buffer[i+74] << '\t' << buffer[i+75] << '\t' << 1 << '\t' << " " << '\t' << buffer[i+74] << '\t' << buffer[i+74] << '\t' << buffer[i] << '\t' << buffer[i+1] << '\t' << stat << std::endl;
53 if (buffer[i+75] == 0)
54 text_file << buffer[i+74] << '\t' << buffer[i+75] << '\t' << 0 << '\t' << " " << '\t' << " " << '\t' << " " << '\t' << " " << '\t' << " " << std::endl;
55 if (buffer[i+75] == 16384)
56 text_file << buffer[i+74] << '\t' << buffer[i+75] << '\t' << 0 << '\t' << buffer[i+74] << '\t' << " " << '\t' << " " << '\t' << " " << '\t' << " " << std::endl;
57 if (buffer[i+75] == 256)
58 text_file << buffer[i+74] << '\t' << buffer[i+75] << '\t' << 0 << '\t' << " " << '\t' << buffer[i+74] << '\t' << " " << '\t' << " " << '\t' << " " << std::endl;
59 if (buffer[i+75] == -32768)
60 text_file << buffer[i+74] << '\t' << buffer[i+75] << '\t' << 1 << '\t' << " " << '\t' << " " << '\t' << buffer[i+74] << '\t' << " " << '\t' << " " << std::endl;
61 if (buffer[i+75] == -16384)
62 text_file << buffer[i+74] << '\t' << buffer[i+75] << '\t' << 1 << '\t' << buffer[i+74] << '\t' << " " << '\t' << buffer[i+74] << '\t' << " " << '\t' << " " << std::endl;
63 if (buffer[i+75] == -32512)
64 text_file << buffer[i+74] << '\t' << buffer[i+75] << '\t' << 1 << '\t' << " " << '\t' << buffer[i+74] << '\t' << buffer[i+74] << '\t' << " " << '\t' << " " << std::endl;
71 int main(int argc, char * argv[])
73 GGO(clitkDicomWave2Text, args_info);
75 std::ofstream os(args_info.OutputFile_arg, std::ios::out | std::ios::trunc);
77 #if GDCM_MAJOR_VERSION < 2
79 gdcm::File * mDCMFile = new gdcm::File();
80 mDCMFile->SetFileName(args_info.InputFile_arg);
81 mDCMFile->AddForceLoadElement(0x01e1,0x1018); //Load wave data no matter its size
82 if ( !mDCMFile->OpenFile() )
84 std::cerr << "Failed to read: " << args_info.InputFile_arg << std::endl;
88 gdcm::DocEntrySet* item = mDCMFile;
90 gdcm::BinEntry * entry = item->GetBinEntry(0x01e1,0x1018);
91 T* buffer = reinterpret_cast<T*>(entry->GetBinArea());
92 int length=item->GetEntryLength(0x01e1,0x1018)/sizeof(T);
97 reader.SetFileName(args_info.InputFile_arg);
100 std::cerr << "Failed to read: " << args_info.InputFile_arg << std::endl;
103 const gdcm::DataSet& ds = reader.GetFile().GetDataSet();
104 const gdcm::PrivateTag twave(0x01e1,0x18,"ELSCINT1");
105 if( !ds.FindDataElement( twave ) ) return 1;
106 const gdcm::DataElement& wave = ds.GetDataElement( twave );
107 if ( wave.IsEmpty() ) return 1;
108 const gdcm::ByteValue * bv = wave.GetByteValue();
109 short * buffer = (short*)bv->GetPointer();
110 int length = bv->GetLength() / sizeof( short );
114 // Dump that to a CSV file:
115 wave2stream( os, buffer, length );