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