]> Creatis software - gdcm.git/blob - Example/PrintDicomDir.cxx
Remove copy/paste spurious line
[gdcm.git] / Example / PrintDicomDir.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: PrintDicomDir.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/06/08 08:09:07 $
7   Version:   $Revision: 1.23 $
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 "gdcmDocument.h"
19 #include "gdcmDicomDir.h"
20 #include "gdcmValEntry.h"
21 #include "gdcmDicomDirPatient.h"
22 #include "gdcmDicomDirStudy.h"
23 #include "gdcmDicomDirSerie.h"
24 #include "gdcmDicomDirImage.h"
25 #include "gdcmTS.h"
26 #include "gdcmDebug.h"
27
28 #include "gdcmArgMgr.h"
29
30 #include <fstream>
31 #include <iostream>
32
33 int main(int argc, char* argv[])
34 {
35    START_USAGE(usage)
36    " \n PrintDicomDir :\n",
37    " Display the tree-like structure of a DICOMDIR File",
38    " usage: PrintDicomDir filein=fileName [level=n] [debug] ",
39    "        detail = 1 : Patients, 2 : Studies, 3 : Series, 4 : Images ",
40    "                 5 : Full Content ",
41    "        level = 0,1,2 : depending on user (what he wants to see)",
42    "        debug    : user wants to run the program in 'debug mode' ",
43    FINISH_USAGE
44
45    // Initialize Arguments Manager   
46    gdcm::ArgMgr *am= new gdcm::ArgMgr(argc, argv);
47   
48    if (argc == 1) 
49    {
50       am->ArgMgrUsage(usage); // Display 'usage'
51       delete am;
52       return 0;
53    }
54   
55    gdcm::DicomDir *e1;
56    gdcm::TSKey v;
57
58    gdcm::DicomDirPatient *pa;
59    gdcm::DicomDirStudy *st;
60    gdcm::DicomDirSerie *se;
61    gdcm::DicomDirImage *im;
62   
63    char *fileName;
64    fileName  = am->ArgMgrWantString("filein",usage); 
65
66    int level  = am->ArgMgrGetInt("level", 2);
67
68    int detailLevel = am->ArgMgrGetInt("detail", 2);
69
70    if (am->ArgMgrDefined("debug"))
71       gdcm::Debug::DebugOn();
72
73    /* if unused Param we give up */
74    if ( am->ArgMgrPrintUnusedLabels() )
75    { 
76       am->ArgMgrUsage(usage);
77       delete am;
78       return 0;
79    } 
80
81    // new style is useless, since it has no effect for *reading* a DICOMDIR
82    // (only meaningfull when *creating* a DICOMDIR)
83
84    e1 = new gdcm::DicomDir( fileName );
85
86    //e1 = new gdcm::DicomDir();
87    //e1->SetParseDir(false);
88    //e1->Load(  fileName );
89
90    // Test if the DicomDir is readable
91    if( !e1->IsReadable() )
92    {
93       std::cout<<"          DicomDir '"<<fileName
94                <<"' is not readable"<<std::endl
95                <<"          ...Failed"<<std::endl;
96
97       delete e1;
98       return 1;
99    }
100
101    e1->SetPrintLevel(level);
102
103    // Test if the DicomDir contains any Patient
104    pa = e1->GetFirstPatient();
105    if ( pa  == 0)
106    {
107       std::cout<<"          DicomDir '"<<fileName
108                <<" has no patient"<<std::endl
109                <<"          ...Failed"<<std::endl;
110
111       delete e1;
112       return 1;
113    }
114
115 // Structure use Examples 
116
117    switch (detailLevel)
118   { 
119   case 1:
120      std::cout << std::endl << std::endl  
121        << " =  PATIENT List ==========================================" 
122        << std::endl<< std::endl;
123
124       pa = e1->GetFirstPatient();
125       while (pa) 
126       {
127          std::cout << pa->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name   
128          pa = e1->GetNextPatient();    
129       }
130       break;
131
132    case 2:    
133       std::cout << std::endl << std::endl  
134         << " = PATIENT/STUDY List =======================================" 
135         << std::endl<< std::endl;
136
137       pa = e1->GetFirstPatient();
138       while ( pa ) // on degouline les PATIENT de ce DICOMDIR
139       {  
140          std::cout << pa->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name 
141
142          st = pa->GetFirstStudy();
143          while ( st ) { // on degouline les STUDY de ce patient
144             std::cout << "--- "<< st->GetEntryValue(0x0008, 0x1030) << std::endl; // Study Description
145             st = pa->GetNextStudy();
146          }
147          pa = e1->GetNextPatient();    
148       }   
149       break;
150
151    case 3: 
152       std::cout << std::endl << std::endl  
153         << " =  PATIENT/STUDY/SERIE List ==================================" 
154         << std::endl<< std::endl;
155
156       pa = e1->GetFirstPatient(); 
157       while ( pa )   // on degouline les PATIENT de ce DICOMDIR
158       {
159        // Patient's Name, Patient ID 
160          std::cout << "Pat.Name:[" << pa->GetEntryValue(0x0010, 0x0010) <<"]"; // Patient's Name
161          std::cout << " Pat.ID:[";
162          std::cout << pa->GetEntryValue(0x0010, 0x0020) << "]" << std::endl; // Patient ID
163
164          st = pa->GetFirstStudy();
165          while ( st ) { // on degouline les STUDY de ce patient
166             std::cout << "--- Stud.descr:["    << st->GetEntryValue(0x0008, 0x1030) << "]";// Study Description 
167             std::cout << " Stud.ID:["          << st->GetEntryValue(0x0020, 0x0010);       // Study ID
168             std::cout << "]" << std::endl;
169
170             se = st->GetFirstSerie();
171             while ( se ) { // on degouline les SERIES de cette study
172                std::cout << "--- --- Ser.Descr:["<< se->GetEntryValue(0x0008, 0x103e)<< "]";  // Series Description
173                std::cout << " Ser.nb:["         <<  se->GetEntryValue(0x0020, 0x0011);        // Series number
174                std::cout << "] Mod.:["          <<  se->GetEntryValue(0x0008, 0x0060) << "]"; // Modality
175                std::cout << std::endl;    
176                se = st->GetNextSerie();   
177             }
178             st = pa->GetNextStudy();
179          }
180          pa = e1->GetNextPatient();    
181       } 
182       break;
183
184    case 4:  
185       std::cout << std::endl << std::endl  
186            << " = PATIENT/STUDY/SERIE/IMAGE List ============================" 
187            << std::endl<< std::endl;
188  
189       pa = e1->GetFirstPatient(); 
190       while ( pa ) {  // les PATIENT de ce DICOMDIR
191        // Patient's Name, Patient ID 
192          std::cout << "Pat.Name:[" << pa->GetEntryValue(0x0010, 0x0010) <<"]"; // Patient's Name
193          std::cout << " Pat.ID:[";
194          std::cout << pa->GetEntryValue(0x0010, 0x0020) << "]" << std::endl; // Patient ID
195
196          st = pa->GetFirstStudy();
197          while ( st ) { // on degouline les STUDY de ce patient
198             std::cout << "--- Stud.descr:["    << st->GetEntryValue(0x0008, 0x1030) << "]";// Study Description 
199             std::cout << " Stud.ID:["          << st->GetEntryValue(0x0020, 0x0010);       // Study ID
200             std::cout << "]" << std::endl;
201
202             se = st->GetFirstSerie();
203             while ( se ) { // on degouline les SERIES de cette study
204                std::cout << "--- --- Ser.Descr:["<< se->GetEntryValue(0x0008, 0x103e)<< "]";  // Series Description
205                std::cout << " Ser.nb:["         <<  se->GetEntryValue(0x0020, 0x0011);        // Series number
206                std::cout << "] Mod.:["          <<  se->GetEntryValue(0x0008, 0x0060) << "]"; // Modality
207                std::cout << std::endl;    
208
209                im = se->GetFirstImage();
210                while ( im ) { // on degouline les Images de cette serie
211                   std::cout << "--- --- --- "<< im->GetEntryValue(0x0004, 0x1500) << std::endl; // File name
212                   im = se->GetNextImage();   
213                }
214                se = st->GetNextSerie();   
215            }
216             st = pa->GetNextStudy();
217         }     
218         pa = e1->GetNextPatient();    
219       }
220       break;
221
222    case 5:
223       std::cout << std::endl << std::endl  
224            << " = DICOMDIR full content ==========================================" 
225            << std::endl<< std::endl;
226       e1->Print();
227       break;
228
229    }  // end switch
230
231
232  /*
233    // Previous code.
234    // Kept as an example. Please don't remove
235  
236    gdcm::ListDicomDirPatient::const_iterator  itPatient;
237    gdcm::ListDicomDirStudy::const_iterator    itStudy;
238    gdcm::ListDicomDirSerie::const_iterator    itSerie;
239    gdcm::ListDicomDirImage::const_iterator    itImage;
240    cout << std::endl << std::endl
241         << " = Liste des PATIENT/STUDY/SERIE/IMAGE ===================================" 
242         << std::endl<< std::endl;
243  
244    itPatient = e1->GetDicomDirPatients().begin();
245    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline les PATIENT de ce DICOMDIR
246       std::cout << (*itPatient)->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
247       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
248       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
249          std::cout << "--- "<< (*itStudy)->GetEntryValue(0x0008, 0x1030) << std::endl; // Study Description
250          itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
251          while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
252             std::cout << "--- --- "<< (*itSerie)->GetEntryValue(0x0008, 0x103e) << std::endl; // Serie Description
253             itImage = ((*itSerie)->GetDicomDirImages()).begin();
254             while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les IMAGES de cette serie
255                std::cout << "--- --- --- "<< (*itImage)->GetEntryValue(0x0004, 0x1500) << std::endl; // File name
256                ++itImage;   
257             }
258             ++itSerie;   
259          }
260          ++itStudy;
261       }  
262       itPatient ++;    
263    }   
264  */  
265
266
267    if(e1->IsReadable())
268       std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
269    else
270       std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
271    std::cout<<std::flush;
272    delete e1;
273
274    return(0);
275 }