]> Creatis software - gdcm.git/blob - Example/toBrainVisa.cxx
Fix mistypings
[gdcm.git] / Example / toBrainVisa.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: toBrainVisa.cxx,v $
5   Language:  C++
6   Date:      $Date: 2007/09/13 12:48:37 $
7   Version:   $Revision: 1.3 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 #include "gdcmFile.h"
19 #include "gdcmFileHelper.h"
20 #include "gdcmDocument.h"
21 #include "gdcmDataEntry.h"
22 #include "gdcmArgMgr.h"
23
24    START_USAGE(usage)
25    " \n toBrainVisa :\n                                                       ",
26    "   Extracts user supplied tags (identified by group number-element number)",
27    "   and writes their values in a text file.                                ",
28    "   (file will be used as input by BrainVisa software )                    ",
29    " usage :                                                                  ",
30    " toBrainVisa      filein=inputFileName  (a DICOM file)                    ",
31    "                  fileoutout=outputFileName                               ",
32    "                  tags= list of tags to process                           ",
33    "                  [verbose] [debug]                                       ",
34    "                                                                          ",
35    " e.g. : tags=0020-0052,0008-0021,0018-1030 (no space!)                    ",
36    " dirout : will be created (as a text file) if doesn't exist               ",
37    " verbose  : user wants to run the program in 'verbose mode'               ",
38    " debug    : *developer*  wants to run the program in 'debug mode'         ",
39    FINISH_USAGE
40    
41 int main (int argc , char *argv[])
42 {
43    // ============== Initialize Arguments Manager =============================
44       
45    GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv);
46   
47    if (argc == 1 || am->ArgMgrDefined("usage")) 
48    {
49       am->ArgMgrUsage(usage); // Display 'usage'
50       delete am;
51       return 0;
52    }
53
54    const char *filein;   
55    filein  = am->ArgMgrGetString("filein","."); 
56
57    const char *fileout;   
58    fileout  = am->ArgMgrGetString("fileout",".");
59          
60    int verbose  = am->ArgMgrDefined("verbose");
61    
62    int nbTags;
63    uint16_t *tags = am->ArgMgrGetXInt16Enum("tags", &nbTags);   
64    
65    // if unused Param we give up
66    if ( am->ArgMgrPrintUnusedLabels() )
67    { 
68       am->ArgMgrUsage(usage);
69       delete am;
70       return 0;
71    }
72    delete am;  // we don't need Argument Manager any longer
73
74    // ==================== Begin Processing =====================================
75
76    FILE *fp;
77    fp=fopen(fileout, "w");
78    if (fp == 0)
79    {
80       std::cout << "Failed to open [" << fileout << "] for writting" << std::endl;
81       return 0;
82    }      
83    GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
84    f->SetLoadMode( GDCM_NAME_SPACE::LD_ALL);
85    f->SetFileName( filein );
86    bool res = f->Load(); 
87          
88    if (!res) 
89    {
90        std::cout << "Sorry, [" << filein << "]  not a gdcm-readable "
91                  << "DICOM / ACR File"
92                  <<std::endl;
93        f->Delete();
94        return 0;
95    }
96    if (verbose)
97       std::cout << "[" << filein << "] is readable " << std::endl;
98    
99    for(int i=0; i<nbTags; i++)
100    {
101       std::string toto = f->GetEntryString(tags[2*i], tags[2*i+1]);
102       fprintf(fp, "%s\n", toto.c_str() );
103       if (verbose)
104          std::cout << "[" << toto << "]" << std::endl;
105    }
106    
107   f->Delete();
108   fclose (fp);        
109    
110 }