]> Creatis software - gdcm.git/blob - Testing/TestDicomDir.cxx
coding style
[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:47:23 $
7   Version:   $Revision: 1.29 $
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    e1 = new gdcm::DicomDir(file);
50    if (argc > 2) 
51    {
52       int level = atoi(argv[2]);   
53       e1->SetPrintLevel(level);
54    }
55
56    // Test if the DicomDir is readable
57    if( !e1->IsReadable() )
58    {
59       std::cout<<"          DicomDir '"<<file
60                <<"' is not readable"<<std::endl
61                <<"          ...Failed"<<std::endl;
62
63       delete e1;
64       return 1;
65    }
66    else
67    {
68       std::cout<<"          DicomDir '"<<file
69                <<"' is readable"<<std::endl;
70    }
71
72    // Test if the DicomDir contains any Patient
73    e1->InitTraversal();
74    if( !e1->GetNextEntry() )
75    {
76       std::cout<<"          DicomDir '"<<file
77                <<" has no patient"<<std::endl
78                <<"          ...Failed"<<std::endl;
79
80       delete e1;
81       return 1;
82    }
83
84   // step by step structure full exploitation
85   
86    std::cout << std::endl << std::endl  
87              << " = PATIENT/STUDY/SERIE/IMAGE List ============================" 
88              << std::endl<< std::endl;
89   
90    e1->InitTraversal();
91    pa = e1->GetNextEntry(); 
92    while ( pa ) {  // we process all the PATIENT of this DICOMDIR 
93       std::cout << pa->GetEntry(0x0010, 0x0010) << std::endl; // Patient's Name
94       pa->InitTraversal();
95       st = pa->GetNextEntry();
96       while ( st ) { // we process all the STUDY of this patient
97          std::cout << "--- "<< st->GetEntry(0x0008, 0x1030) << std::endl;    // Study Description
98          std::cout << " Stud.ID:["          << st->GetEntry(0x0020, 0x0010); // Study ID
99          st->InitTraversal();
100          se = st->GetNextEntry();
101          while ( se ) { // we process all the SERIES of this study
102             std::cout << "--- --- "<< se->GetEntry(0x0008, 0x103e) << std::endl;      // Serie Description
103             std::cout << " Ser.nb:["         <<  se->GetEntry(0x0020, 0x0011);        // Series number
104             std::cout << "] Mod.:["          <<  se->GetEntry(0x0008, 0x0060) << "]"; // Modality
105             se->InitTraversal();
106             im = se->GetNextEntry();
107             while ( im ) { // we process all the IMAGE of this serie
108                std::cout << "--- --- --- "<< im->GetEntry(0x0004, 0x1500) << std::endl; // File name
109                im = se->GetNextEntry();   
110             }
111             se = st->GetNextEntry();   
112          }
113          st = pa->GetNextEntry();
114      }  
115      pa = e1->GetNextEntry();
116   }  
117       
118     
119    std::cout << std::endl << std::endl  
120              << " = DICOMDIR full content ====================================" 
121              << std::endl<< std::endl;
122    e1->Print();
123    
124    std::cout<<std::flush;
125    delete e1;
126
127    return 0;
128 }