]> Creatis software - gdcm.git/blob - Testing/TestDicomDir.cxx
* gdcmDirList : to parse a hard drive directory in recursive (or not)
[gdcm.git] / Testing / TestDicomDir.cxx
1 #include <iostream>
2 #include "gdcm.h"
3 #include "gdcmHeaderEntry.h"
4 #include "gdcmDicomDir.h"
5
6 #include <fstream>
7 #ifdef GDCM_NO_ANSI_STRING_STREAM
8 #  include <strstream>
9 #  define  ostringstream ostrstream
10 # else
11 #  include <sstream>
12 #endif
13 #include <string>
14 #include <iostream>
15
16 #define  ostringstream ostrstream
17 //extern "C"
18
19 using namespace std;
20
21
22 void aff(ListTag::iterator deb, ListTag::iterator fin, int nbFFFE) 
23 {
24    int count =0;
25    for (ListTag::iterator i= deb; i!= fin; i++) 
26    {  
27       if( (*i)->GetGroup() == 0xfffe) 
28       {
29          count ++;
30          if (count == nbFFFE) break;
31       }
32       (*i)->SetPrintLevel(0);
33       (*i)->Print();
34    } 
35 }
36
37
38 int main(int argc, char* argv[])
39 {  
40    gdcmDicomDir *e1;
41    ListTag::iterator deb , fin;
42    ListPatient::iterator  itPatient;
43    ListStudy::iterator itStudy;
44    ListSerie::iterator itSerie;
45    ListImage::iterator itImage;
46    TSKey v;
47     
48    std::string file; 
49    if (argc > 1) 
50       file = argv[1];    
51    else 
52       file = "../gdcmData/DICOMDIR";
53       
54    e1 = new gdcmDicomDir(file.c_str());
55         if (argc > 2) {
56            int level = atoi(argv[2]);   
57            e1->SetPrintLevel(level);
58         }
59
60    if(e1->GetPatients().begin() == e1->GetPatients().end() )
61    {
62       std::cout<<"Empty list"<<std::endl;
63       return(1);
64    }
65
66 // Exemples exploitation de la structure
67 // PATIENT
68 /*   cout << std::endl << std::endl  
69              << " = Liste des PATIENT ==========================================" 
70              << std::endl<< std::endl;  
71
72
73    itPatient = e1->GetPatients().begin();       
74    while ( itPatient != e1->GetPatients().end() ) {  // on degouline la liste de PATIENT
75       std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name   
76       itPatient ++;    
77    }    
78
79 // STUDY
80    cout << std::endl << std::endl  
81         << " = Liste des PATIENT/STUDY ==========================================" 
82         << std::endl<< std::endl;       
83
84    itPatient = e1->GetPatients().begin();       
85    while ( itPatient != e1->GetPatients().end() ) {  // on degouline la liste de PATIENT
86       std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name 
87       itStudy = ((*itPatient)->GetStudies()).begin();   
88       while (itStudy != (*itPatient)->GetStudies().end() ) { // on degouline les STUDY de ce patient    
89          std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Stdy Description
90          ++itStudy;             
91       }
92       itPatient ++;    
93    }
94
95 // SERIE
96    cout << std::endl << std::endl  
97              << " = Liste des PATIENT/STUDY/SERIE ==========================================" 
98              << std::endl<< std::endl;  
99  
100    itPatient = e1->GetPatients().begin();       
101    while ( itPatient != e1->GetPatients().end() ) {  // on degouline la liste de PATIENT
102       std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name 
103       itStudy = ((*itPatient)->GetStudies()).begin();   
104       while (itStudy != (*itPatient)->GetStudies().end() ) { // on degouline les STUDY de ce patient    
105          std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Study Description 
106          itSerie = ((*itStudy)->GetSeries()).begin();
107          while (itSerie != (*itStudy)->GetSeries().end() ) { // on degouline les SERIES de cette study     
108             std::cout << "--- ---  "<< (*itSerie)->GetEntryByNumber(0x0008, 0x103e) << std::endl; // Serie Description
109             ++itSerie;   
110          }
111          ++itStudy;             
112       }
113       itPatient ++;    
114    }
115  
116 // IMAGE
117    cout << std::endl << std::endl  
118              << " = Liste des PATIENT/STUDY/SERIE/IMAGE ===================================" 
119              << std::endl<< std::endl;
120  
121    itPatient = e1->GetPatients().begin();       
122    while ( itPatient != e1->GetPatients().end() ) {  // on degouline la liste de PATIENT
123       std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name
124       itStudy = ((*itPatient)->GetStudies()).begin();   
125       while (itStudy != (*itPatient)->GetStudies().end() ) { // on degouline les STUDY de ce patient    
126          std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Study Description
127          itSerie = ((*itStudy)->GetSeries()).begin();
128          while (itSerie != (*itStudy)->GetSeries().end() ) { // on degouline les SERIES de cette study     
129             std::cout << "--- --- "<< (*itSerie)->GetEntryByNumber(0x0008, 0x103e) << std::endl; // Serie Description
130             itImage = ((*itSerie)->GetImages()).begin();
131             while (itImage != (*itSerie)->GetImages().end() ) { // on degouline les SERIES de cette study          
132                std::cout << "--- --- --- "<< (*itImage)->GetEntryByNumber(0x0004, 0x1500) << std::endl; // File name
133                ++itImage;   
134             }
135             ++itSerie;   
136          }
137          ++itStudy;             
138       }  
139       itPatient ++;    
140    }*/
141  
142 // DICOM DIR
143    cout << std::endl << std::endl  
144         << " = Contenu Complet du DICOMDIR ==========================================" 
145         << std::endl<< std::endl;       
146    e1->Print();
147    
148         
149 /*   itPatient = e1->GetPatients().begin();     
150    while ( itPatient != e1->GetPatients().end() ) {  // on degouline la liste de PATIENT
151       cout << " = PATIENT ==========================================" << std::endl;     
152       deb = (*itPatient)->beginObj;     
153       fin =  (*((*itPatient)->GetStudies()).begin())->beginObj;
154       e1->SetPrintLevel(2);
155       aff(deb,fin,1);
156
157       itStudy = ((*itPatient)->GetStudies()).begin();   
158       while (itStudy != (*itPatient)->GetStudies().end() ) { // on degouline les STUDY de ce patient    
159          std::cout << " ==== STUDY ==========================================" <<std::endl;                
160          deb = (*itStudy)->beginObj;    
161          fin = (*((*itStudy)->GetSeries()).begin())->beginObj;
162          //e1->SetPrintLevel(2);
163          aff(deb,fin,1);                                        
164
165          itSerie = ((*itStudy)->GetSeries()).begin();
166          while (itSerie != (*itStudy)->GetSeries().end() ) { // on degouline les SERIES de cette study     
167             cout << " ======= SERIES ==========================================" << std::endl;        
168             deb = (*itSerie)->beginObj; 
169             fin = (*((*itSerie)->GetImages()).begin())->beginObj;
170             //e1->SetPrintLevel(2);
171             aff(deb,fin,1);           
172
173             itImage = ((*itSerie)->GetImages()).begin();
174             while (itImage != (*itSerie)->GetImages().end() ) {  // on degouline les IMAGE de cette serie 
175                cout << " ========== IMAGE ==========================================" << std::endl;     
176                std::cout << "--- --- --- File Name: "<< (*itImage)->GetEntryByNumber(0x0004, 0x1500) << std::endl; // Referenced File 
177
178                ++itImage;
179             }                         
180             ++itSerie;   
181          }      
182          ++itStudy;     
183       }                    
184       itPatient ++;    
185    }*/
186
187    delete e1;
188
189    return(0);
190 }