]> Creatis software - gdcm.git/commitdiff
" Extracts user supplied tags (identified by group number-element number)",
authorjpr <jpr>
Wed, 26 Jul 2006 17:19:39 +0000 (17:19 +0000)
committerjpr <jpr>
Wed, 26 Jul 2006 17:19:39 +0000 (17:19 +0000)
   "   and writes their values in a text file.                                ",
   "   (file will be used as input by BrainVisa software )                    ",

Example/toBrainVisa.cxx [new file with mode: 0755]

diff --git a/Example/toBrainVisa.cxx b/Example/toBrainVisa.cxx
new file mode 100755 (executable)
index 0000000..2008367
--- /dev/null
@@ -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"
+                 <<std::endl;
+       f->Delete();
+       return 0;
+   }
+   if (verbose)
+      std::cout << "[" << filein << "] is readable " << std::endl;
+   
+   for(int i=0; i<nbTags; i++)
+   {
+      std::string toto = f->GetEntryString(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);        
+   
+}