/*========================================================================= Program: vv http://www.creatis.insa-lyon.fr/rio/vv Authors belong to: - University of LYON http://www.universite-lyon.fr/ - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the copyright notices for more information. It is distributed under dual licence - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html ===========================================================================**/ #include "clitkDicomWave2Text.h" #include "clitkDicomWave2Text_ggo.h" #include "clitkCommon.h" #include "gdcmFile.h" #if GDCM_MAJOR_VERSION < 2 #include "gdcmBinEntry.h" #else #include "gdcmReader.h" #include "gdcmPrivateTag.h" #endif #include #include bool wave2stream( std::ostream &text_file, const short *buffer, int length ) { std::string stat=""; 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; for (int i=0;iSetFileName(args_info.InputFile_arg); mDCMFile->AddForceLoadElement(0x01e1,0x1018); //Load wave data no matter its size if ( !mDCMFile->OpenFile() ) { std::cerr << "Failed to read: " << args_info.InputFile_arg << std::endl; return 1; } mDCMFile->Load(); gdcm::DocEntrySet* item = mDCMFile; #define T short gdcm::BinEntry * entry = item->GetBinEntry(0x01e1,0x1018); T* buffer = reinterpret_cast(entry->GetBinArea()); int length=item->GetEntryLength(0x01e1,0x1018)/sizeof(T); #else gdcm::Reader reader; reader.SetFileName(args_info.InputFile_arg); if( !reader.Read() ) { std::cerr << "Failed to read: " << args_info.InputFile_arg << std::endl; return 1; } const gdcm::DataSet& ds = reader.GetFile().GetDataSet(); const gdcm::PrivateTag twave(0x01e1,0x18,"ELSCINT1"); if( !ds.FindDataElement( twave ) ) return 1; const gdcm::DataElement& wave = ds.GetDataElement( twave ); if ( wave.IsEmpty() ) return 1; const gdcm::ByteValue * bv = wave.GetByteValue(); short * buffer = (short*)bv->GetPointer(); int length = bv->GetLength() / sizeof( short ); #endif // Dump that to a CSV file: wave2stream( os, buffer, length ); os.close(); return 0; }