From: jpr Date: Wed, 26 Jul 2006 17:19:39 +0000 (+0000) Subject: " Extracts user supplied tags (identified by group number-element number)", X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=e0261b5c230737aab332460b33ba7aa77aa9832f;p=gdcm.git " Extracts user supplied tags (identified by group number-element number)", " and writes their values in a text file. ", " (file will be used as input by BrainVisa software ) ", --- diff --git a/Example/toBrainVisa.cxx b/Example/toBrainVisa.cxx new file mode 100755 index 00000000..2008367f --- /dev/null +++ b/Example/toBrainVisa.cxx @@ -0,0 +1,93 @@ +#include "gdcmFile.h" +#include "gdcmFileHelper.h" +#include "gdcmDocument.h" +#include "gdcmDataEntry.h" +#include "gdcmArgMgr.h" + + START_USAGE(usage) + " \n toBrainVisa :\n ", + " Extracts user supplied tags (identified by group number-element number)", + " and writes their values in a text file. ", + " (file will be used as input by BrainVisa software ) ", + " usage : ", + " toBrainVisa filein=inputFileName (a DICOM file) ", + " fileoutout=outputFileName ", + " tags= list of tags to process ", + " [verbose] [debug] ", + " ", + " e.g. : tags=0020-0052,0008-0021,0018-1030 (no space!) ", + " dirout : will be created (as a text file) if doesn't exist ", + " verbose : user wants to run the program in 'verbose mode' ", + " debug : *developer* wants to run the program in 'debug mode' ", + FINISH_USAGE + +int main (int argc , char *argv[]) +{ + // ============== Initialize Arguments Manager ============================= + + gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv); + + if (argc == 1 || am->ArgMgrDefined("usage")) + { + am->ArgMgrUsage(usage); // Display 'usage' + delete am; + return 0; + } + + const char *filein; + filein = am->ArgMgrGetString("filein","."); + + const char *fileout; + fileout = am->ArgMgrGetString("fileout","."); + + int verbose = am->ArgMgrDefined("verbose"); + + int nbTags; + uint16_t *tags = am->ArgMgrGetXInt16Enum("tags", &nbTags); + + // if unused Param we give up + if ( am->ArgMgrPrintUnusedLabels() ) + { + am->ArgMgrUsage(usage); + delete am; + return 0; + } + delete am; // we don't need Argument Manager any longer + + // ==================== Begin Processing ===================================== + + FILE *fp; + fp=fopen(fileout, "w"); + if (fp == 0) + { + std::cout << "Failed to open [" << fileout << "] for writting" << std::endl; + return 0; + } + gdcm::File *f = gdcm::File::New(); + f->SetLoadMode( gdcm::LD_ALL); + f->SetFileName( filein ); + bool res = f->Load(); + + if (!res) + { + std::cout << "Sorry, [" << filein << "] not a gdcm-readable " + << "DICOM / ACR File" + <Delete(); + return 0; + } + if (verbose) + std::cout << "[" << filein << "] is readable " << std::endl; + + for(int i=0; iGetEntryString(tags[2*i], tags[2*i+1]); + fprintf(fp, "%s\n", toto.c_str() ); + if (verbose) + std::cout << "[" << toto << "]" << std::endl; + } + + f->Delete(); + fclose (fp); + +}