]> Creatis software - gdcm.git/blob - Testing/TestDicomDir.cxx
According to Benoit's suggestion, and without any objection from anybody
[gdcm.git] / Testing / TestDicomDir.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestDicomDir.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/08 15:03:58 $
7   Version:   $Revision: 1.24 $
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 "gdcmDocEntry.h"
19 #include "gdcmDicomDir.h"
20 #include "gdcmDicomDirPatient.h"
21 #include "gdcmDicomDirStudy.h"
22 #include "gdcmDicomDirSerie.h"
23 #include "gdcmDicomDirImage.h"
24 #include "gdcmTS.h"
25
26 #include <iostream>
27 #include <fstream>
28
29 int TestDicomDir(int argc, char* argv[])
30 {  
31    gdcm::DicomDir *e1;
32    
33    gdcm::ListDicomDirPatient::const_iterator  itPatient;
34    gdcm::ListDicomDirStudy::const_iterator    itStudy;
35    gdcm::ListDicomDirSerie::const_iterator    itSerie;
36    //gdcm::ListDicomDirImage::const_iterator    itImage;
37    gdcm::TSKey v;
38     
39    std::string file; 
40    if (argc > 1) 
41       file = argv[1];    
42    else {
43       file += GDCM_DATA_ROOT;
44       file += "/DICOMDIR";
45     }
46
47    e1 = new gdcm::DicomDir(file);
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 // Simple examples of structure exploitation 
60 // DON'T REMOVE neither the following code, nor the commented out lines
61
62 /*
63   cout << std::endl << std::endl  
64         << " = Liste des PATIENT ==========================================" 
65         << std::endl<< std::endl;
66
67
68    itPatient = e1->GetDicomDirPatients().begin();
69    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
70       std::cout << (*itPatient)->GetEntry(0x0010, 0x0010) << std::endl; // Patient's Name   
71       itPatient ++;    
72    }
73 */
74
75 /*        
76    cout << std::endl << std::endl  
77         << " = Liste des PATIENT/STUDY ==========================================" 
78         << std::endl<< std::endl;
79
80    itPatient = e1->GetDicomDirPatients().begin();
81    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
82       std::cout << (*itPatient)->GetEntry(0x0010, 0x0010) << std::endl; // Patient's Name 
83       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
84       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
85          std::cout << "--- "<< (*itStudy)->GetEntry(0x0008, 0x1030) << std::endl; // Study Description
86          ++itStudy;
87       }
88       itPatient ++;    
89    }   
90  */
91  
92    std::cout << std::endl << std::endl  
93              << " = Liste des PATIENT/STUDY/SERIE ==========================================" 
94              << std::endl<< std::endl;
95  
96    itPatient = e1->GetDicomDirPatients().begin();
97    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
98        // Patient's Name, Patient ID 
99       std::cout << "Pat.Name:[" << (*itPatient)->GetEntry(0x0010, 0x0010) <<"]";
100       std::cout << " Pat.ID:[";
101       std::cout << (*itPatient)->GetEntry(0x0010, 0x0020) << "]" << std::endl;
102       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
103       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
104          std::cout << "--- Stud.descr:["    << (*itStudy)->GetEntry(0x0008, 0x1030) << "]";// Study Description 
105          std::cout << " Stud.ID:["<< (*itStudy)->GetEntry(0x0020, 0x0010);                 // Study ID
106    std::cout << "]" << std::endl;
107          itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
108          while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
109             std::cout << "--- --- Ser.Descr:["<< (*itSerie)->GetEntry(0x0008, 0x103e)<< "]";// Serie Description
110             std::cout << " Ser.nb:[" <<   (*itSerie)->GetEntry(0x0020, 0x0011);            // Serie number
111             std::cout << "] Mod.:["    <<   (*itSerie)->GetEntry(0x0008, 0x0060) << "]";   // Modality
112             std::cout << std::endl;
113             ++itSerie;   
114          }
115          ++itStudy;
116       }
117       itPatient ++;    
118    } 
119    
120     
121  /*
122    cout << std::endl << std::endl  
123         << " = Liste des PATIENT/STUDY/SERIE/IMAGE ===================================" 
124         << std::endl<< std::endl;
125  
126    itPatient = e1->GetDicomDirPatients().begin();
127    while ( itPatient != e1->GetDicomDirPatients().end() ) {  // on degouline la liste de PATIENT
128       std::cout << (*itPatient)->GetEntry(0x0010, 0x0010) << std::endl; // Patient's Name
129       itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
130       while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
131          std::cout << "--- "<< (*itStudy)->GetEntry(0x0008, 0x1030) << std::endl; // Study Description
132          itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
133          while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
134             std::cout << "--- --- "<< (*itSerie)->GetEntry(0x0008, 0x103e) << std::endl; // Serie Description
135             itImage = ((*itSerie)->GetDicomDirImages()).begin();
136             while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les SERIES de cette study
137                std::cout << "--- --- --- "<< (*itImage)->GetEntry(0x0004, 0x1500) << std::endl; // File name
138                ++itImage;   
139             }
140             ++itSerie;   
141          }
142          ++itStudy;
143       }  
144       itPatient ++;    
145    }   
146  */  
147
148    std::cout << std::endl << std::endl  
149         << " = Contenu Complet du DICOMDIR ==========================================" 
150         << std::endl<< std::endl;
151    e1->Print();
152    
153    std::cout<<std::flush;
154    delete e1;
155
156    return(0);
157 }