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