]> Creatis software - gdcm.git/blob - Testing/TestDicomDir.cxx
Oops.
[gdcm.git] / Testing / TestDicomDir.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestDicomDir.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/17 13:24:15 $
7   Version:   $Revision: 1.28 $
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::DicomDirPatient *pa;
34    gdcm::DicomDirStudy *st;
35    gdcm::DicomDirSerie *se;
36    gdcm::DicomDirImage *im;
37
38    gdcm::TSKey v;
39     
40    std::string file; 
41    if (argc > 1) 
42       file = argv[1];    
43    else 
44    {
45       file += GDCM_DATA_ROOT;
46       file += "/DICOMDIR";
47    }
48
49 std::cout << "----------------- " << file << "-----" <<std::endl;
50    e1 = new gdcm::DicomDir(file);
51    if (argc > 2) 
52    {
53       int level = atoi(argv[2]);   
54       e1->SetPrintLevel(level);
55    }
56
57    // Test if the DicomDir is readable
58    if( !e1->IsReadable() )
59    {
60       std::cout<<"          DicomDir '"<<file
61                <<"' is not readable"<<std::endl
62                <<"          ...Failed"<<std::endl;
63
64       delete e1;
65       return 1;
66    }
67    else
68    {
69       std::cout<<"          DicomDir '"<<file
70                <<"' is readable"<<std::endl;
71    }
72
73    e1->InitTraversal();
74    // Test if the DicomDir contains any Patient
75    if( !e1->GetNextEntry() )
76    {
77       std::cout<<"          DicomDir '"<<file
78                <<" has no patient"<<std::endl
79                <<"          ...Failed"<<std::endl;
80
81       delete e1;
82       return 1;
83    }
84
85
86   // step by step structure full exploitation
87   
88    std::cout << std::endl << std::endl  
89              << " = PATIENT/STUDY/SERIE/IMAGE List ============================" 
90              << std::endl<< std::endl;
91   
92    e1->InitTraversal();
93    pa = e1->GetNextEntry(); 
94    while ( pa ) {  // on degouline la liste de PATIENT
95       std::cout << pa->GetEntry(0x0010, 0x0010) << std::endl; // Patient's Name
96       pa->InitTraversal();
97       st = pa->GetNextEntry();
98       while ( st ) { // on degouline les STUDY de ce patient
99          std::cout << "--- "<< st->GetEntry(0x0008, 0x1030) << std::endl;    // Study Description
100          std::cout << " Stud.ID:["          << st->GetEntry(0x0020, 0x0010); // Study ID
101          st->InitTraversal();
102          se = st->GetNextEntry();
103          while ( se ) { // on degouline les SERIES de cette study
104             std::cout << "--- --- "<< se->GetEntry(0x0008, 0x103e) << std::endl;      // Serie Description
105             std::cout << " Ser.nb:["         <<  se->GetEntry(0x0020, 0x0011);        // Series number
106             std::cout << "] Mod.:["          <<  se->GetEntry(0x0008, 0x0060) << "]"; // Modality
107             se->InitTraversal();
108             im = se->GetNextEntry();
109             while ( im ) { // on degouline les Images de cette serie
110                std::cout << "--- --- --- "<< im->GetEntry(0x0004, 0x1500) << std::endl; // File name
111                im = se->GetNextEntry();   
112             }
113             se = st->GetNextEntry();   
114          }
115          st = pa->GetNextEntry();
116      }  
117      pa = e1->GetNextEntry();
118   }  
119       
120     
121    std::cout << std::endl << std::endl  
122              << " = DICOMDIR full content ====================================" 
123              << std::endl<< std::endl;
124    e1->Print();
125    
126    std::cout<<std::flush;
127    delete e1;
128
129    return 0;
130 }