1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
19 #include "clitkDicomWave2Text.h"
20 #include "clitkDicomWave2Text_ggo.h"
22 #include "clitkCommon.h"
25 #if GDCM_MAJOR_VERSION < 2
26 #include "gdcmBinEntry.h"
28 #include "gdcmReader.h"
29 #include "gdcmPrivateTag.h"
36 bool wave2stream( std::ostream &text_file, const short *buffer, int length )
39 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;
40 for (int i=0;i<length-76;i+=2)
50 stat="Sampling rate (Hz)";
56 if (buffer[i+75] == 0)
57 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;
58 if (buffer[i+75] == 16384)
59 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;
60 if (buffer[i+75] == 256)
61 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;
62 if (buffer[i+75] == -32768)
63 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;
64 if (buffer[i+75] == -16384)
65 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;
66 if (buffer[i+75] == -32512)
67 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;
71 if (buffer[i+75] == 0)
72 text_file << buffer[i+74] << '\t' << buffer[i+75] << '\t' << 0 << '\t' << " " << '\t' << " " << '\t' << " " << '\t' << " " << '\t' << " " << std::endl;
73 if (buffer[i+75] == 16384)
74 text_file << buffer[i+74] << '\t' << buffer[i+75] << '\t' << 0 << '\t' << buffer[i+74] << '\t' << " " << '\t' << " " << '\t' << " " << '\t' << " " << std::endl;
75 if (buffer[i+75] == 256)
76 text_file << buffer[i+74] << '\t' << buffer[i+75] << '\t' << 0 << '\t' << " " << '\t' << buffer[i+74] << '\t' << " " << '\t' << " " << '\t' << " " << std::endl;
77 if (buffer[i+75] == -32768)
78 text_file << buffer[i+74] << '\t' << buffer[i+75] << '\t' << 1 << '\t' << " " << '\t' << " " << '\t' << buffer[i+74] << '\t' << " " << '\t' << " " << std::endl;
79 if (buffer[i+75] == -16384)
80 text_file << buffer[i+74] << '\t' << buffer[i+75] << '\t' << 1 << '\t' << buffer[i+74] << '\t' << " " << '\t' << buffer[i+74] << '\t' << " " << '\t' << " " << std::endl;
81 if (buffer[i+75] == -32512)
82 text_file << buffer[i+74] << '\t' << buffer[i+75] << '\t' << 1 << '\t' << " " << '\t' << buffer[i+74] << '\t' << buffer[i+74] << '\t' << " " << '\t' << " " << std::endl;
89 int main(int argc, char * argv[])
91 GGO(clitkDicomWave2Text, args_info);
93 std::ofstream os(args_info.OutputFile_arg, std::ios::out | std::ios::trunc);
95 #if GDCM_MAJOR_VERSION < 2
97 gdcm::File * mDCMFile = new gdcm::File();
98 mDCMFile->SetFileName(args_info.InputFile_arg);
99 mDCMFile->AddForceLoadElement(0x01e1,0x1018); //Load wave data no matter its size
100 if ( !mDCMFile->OpenFile() )
102 std::cerr << "Failed to read: " << args_info.InputFile_arg << std::endl;
106 gdcm::DocEntrySet* item = mDCMFile;
108 gdcm::BinEntry * entry = item->GetBinEntry(0x01e1,0x1018);
109 T* buffer = reinterpret_cast<T*>(entry->GetBinArea());
110 int length=item->GetEntryLength(0x01e1,0x1018)/sizeof(T);
115 reader.SetFileName(args_info.InputFile_arg);
118 std::cerr << "Failed to read: " << args_info.InputFile_arg << std::endl;
121 const gdcm::DataSet& ds = reader.GetFile().GetDataSet();
122 const gdcm::PrivateTag twave(0x01e1,0x18,"ELSCINT1");
123 if( !ds.FindDataElement( twave ) ) return 1;
124 const gdcm::DataElement& wave = ds.GetDataElement( twave );
125 if ( wave.IsEmpty() ) return 1;
126 const gdcm::ByteValue * bv = wave.GetByteValue();
127 short * buffer = (short*)bv->GetPointer();
128 int length = bv->GetLength() / sizeof( short );
132 // Dump that to a CSV file:
133 wave2stream( os, buffer, length );