]> Creatis software - gdcm.git/blob - Example/PrintDicomDir.cxx
ENH: Add license to examples since they belong to gdcm
[gdcm.git] / Example / PrintDicomDir.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: PrintDicomDir.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/11/16 04:26:17 $
7   Version:   $Revision: 1.6 $
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 <iostream>
19 #include "gdcm.h"
20 #include "gdcmDocument.h"
21 #include "gdcmDicomDir.h"
22 #include "gdcmValEntry.h"
23
24 #include <fstream>
25
26 using namespace std;
27
28 int main(int argc, char* argv[])
29 {  
30    gdcm::DicomDir *e1;
31    
32    gdcm::ListDicomDirPatient::const_iterator  itPatient;
33    gdcm::ListDicomDirStudy::const_iterator    itStudy;
34    gdcm::ListDicomDirSerie::const_iterator    itSerie;
35    gdcm::ListDicomDirImage::const_iterator    itImage;
36    gdcm::TSKey v;
37     
38    std::string file; 
39    if (argc > 1) 
40       file = argv[1];    
41    else {
42       file += GDCM_DATA_ROOT;
43       file += "/DICOMDIR";
44    }
45
46    e1 = new gdcm::DicomDir( file );
47
48    if (argc > 2) {
49       int level = atoi(argv[2]);   
50       e1->SetPrintLevel(level);
51    }
52
53    if(e1->GetDicomDirPatients().begin() == e1->GetDicomDirPatients().end() )
54    {
55       std::cout<<"Empty list"<<std::endl;
56       return(1);
57    }
58
59 // Structure use Examples 
60 // DON'T REMOVE neither the following code, nor the commented out lines
61
62 /*
63   cout << std::endl << std::endl  
64        << " =  PATIENT List ==========================================" 
65        << std::endl<< std::endl;
66
67    itPatient = e1->GetDicomDirPatients().begin();
68    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
69       std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name   
70       itPatient ++;    
71    }
72 */
73
74 /*       
75    cout << std::endl << std::endl  
76         << " = PATIENT/STUDY List =======================================" 
77         << std::endl<< std::endl;
78
79    itPatient = e1->GetDicomDirPatients().begin();
80    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
81       std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name 
82       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
83       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
84          std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Study Description
85          ++itStudy;
86       }
87       itPatient ++;    
88    }   
89
90 */
91
92  
93    cout << std::endl << std::endl  
94         << " =  PATIENT/STUDY/SERIE List ==================================" 
95         << std::endl<< std::endl;
96  
97    itPatient = e1->GetDicomDirPatients().begin();
98    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
99        // Patient's Name, Patient ID 
100       std::cout << "Pat.Name:[" << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) <<"]"; // Patient's Name
101       std::cout << " Pat.ID:[";
102       std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0020) << "]" << std::endl; // Patient ID
103       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
104       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
105          std::cout << "--- Stud.descr:["    << (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << "]";// Study Description 
106          std::cout << " Stud.ID:["          << (*itStudy)->GetEntryByNumber(0x0020, 0x0010);       // Study ID
107          std::cout << "]" << std::endl;
108          itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
109          while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
110             std::cout << "--- --- Ser.Descr:["<< (*itSerie)->GetEntryByNumber(0x0008, 0x103e)<< "]";  // Series Description
111             std::cout << " Ser.nb:["         <<  (*itSerie)->GetEntryByNumber(0x0020, 0x0011);        // Series number
112             std::cout << "] Mod.:["          <<  (*itSerie)->GetEntryByNumber(0x0008, 0x0060) << "]"; // Modality
113             std::cout << std::endl;    
114             ++itSerie;   
115          }
116          ++itStudy;
117       }
118       itPatient ++;    
119    } 
120   
121     
122  /*
123    cout << std::endl << std::endl  
124         << " = PATIENT/STUDY/SERIE/IMAGE List ============================" 
125         << std::endl<< std::endl;
126  
127    itPatient = e1->GetDicomDirPatients().begin();
128    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
129       std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name
130       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
131       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
132          std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Study Description
133          itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
134          while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
135             std::cout << "--- --- "<< (*itSerie)->GetEntryByNumber(0x0008, 0x103e) << std::endl; // Serie Description
136             itImage = ((*itSerie)->GetDicomDirImages()).begin();
137             while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les SERIES de cette study
138                std::cout << "--- --- --- "<< (*itImage)->GetEntryByNumber(0x0004, 0x1500) << std::endl; // File name
139                ++itImage;   
140             }
141             ++itSerie;   
142          }
143          ++itStudy;
144       }  
145       itPatient ++;    
146    }   
147  */  
148
149
150 //   cout << std::endl << std::endl  
151 //        << " = DICOMDIR full content ==========================================" 
152 //        << std::endl<< std::endl;
153 //   e1->Print();
154
155    std::cout<<std::flush;
156    delete e1;
157
158    return(0);
159 }