1 /*=========================================================================
4 Module: $RCSfile: PrintDicomDir.cxx,v $
6 Date: $Date: 2005/07/07 17:31:53 $
7 Version: $Revision: 1.24 $
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.
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.
17 =========================================================================*/
18 #include "gdcmDocument.h"
19 #include "gdcmDicomDir.h"
20 #include "gdcmValEntry.h"
21 #include "gdcmDicomDirPatient.h"
22 #include "gdcmDicomDirStudy.h"
23 #include "gdcmDicomDirSerie.h"
24 #include "gdcmDicomDirImage.h"
26 #include "gdcmDebug.h"
28 #include "gdcmArgMgr.h"
33 int main(int argc, char* argv[])
36 " \n PrintDicomDir :\n",
37 " Display the tree-like structure of a DICOMDIR File",
38 " usage: PrintDicomDir filein=fileName [level=n] [debug] ",
39 " detail = 1 : Patients, 2 : Studies, 3 : Series, 4 : Images ",
41 " level = 0,1,2 : depending on user (what he wants to see)",
42 " debug : user wants to run the program in 'debug mode' ",
45 // Initialize Arguments Manager
46 gdcm::ArgMgr *am= new gdcm::ArgMgr(argc, argv);
50 am->ArgMgrUsage(usage); // Display 'usage'
58 gdcm::DicomDirPatient *pa;
59 gdcm::DicomDirStudy *st;
60 gdcm::DicomDirSerie *se;
61 gdcm::DicomDirImage *im;
64 fileName = am->ArgMgrWantString("filein",usage);
66 int level = am->ArgMgrGetInt("level", 2);
68 int detailLevel = am->ArgMgrGetInt("detail", 2);
70 if (am->ArgMgrDefined("debug"))
71 gdcm::Debug::DebugOn();
73 /* if unused Param we give up */
74 if ( am->ArgMgrPrintUnusedLabels() )
76 am->ArgMgrUsage(usage);
81 // new style is useless, since it has no effect for *reading* a DICOMDIR
82 // (only meaningfull when *creating* a DICOMDIR)
84 f = new gdcm::DicomDir( fileName );
86 //f = new gdcm::DicomDir();
87 //f->SetParseDir(false);
88 //f->Load( fileName );
90 // Test if the DicomDir is readable
91 if( !f->IsReadable() )
93 std::cout<<" DicomDir '"<<fileName
94 <<"' is not readable"<<std::endl
95 <<" ...Failed"<<std::endl;
101 f->SetPrintLevel(level);
103 // Test if the DicomDir contains any Patient
104 pa = f->GetFirstPatient();
107 std::cout<<" DicomDir '"<<fileName
108 <<" has no patient"<<std::endl
109 <<" ...Failed"<<std::endl;
115 // Structure use Examples
120 std::cout << std::endl << std::endl
121 << " = PATIENT List =========================================="
122 << std::endl<< std::endl;
124 pa = f->GetFirstPatient();
127 std::cout << pa->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
128 pa = f->GetNextPatient();
133 std::cout << std::endl << std::endl
134 << " = PATIENT/STUDY List ======================================="
135 << std::endl<< std::endl;
137 pa = f->GetFirstPatient();
138 while ( pa ) // on degouline les PATIENT de ce DICOMDIR
140 std::cout << pa->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
142 st = pa->GetFirstStudy();
143 while ( st ) { // on degouline les STUDY de ce patient
144 std::cout << "--- "<< st->GetEntryValue(0x0008, 0x1030) << std::endl; // Study Description
145 st = pa->GetNextStudy();
147 pa = f->GetNextPatient();
152 std::cout << std::endl << std::endl
153 << " = PATIENT/STUDY/SERIE List =================================="
154 << std::endl<< std::endl;
156 pa = f->GetFirstPatient();
157 while ( pa ) // on degouline les PATIENT de ce DICOMDIR
159 // Patient's Name, Patient ID
160 std::cout << "Pat.Name:[" << pa->GetEntryValue(0x0010, 0x0010) <<"]"; // Patient's Name
161 std::cout << " Pat.ID:[";
162 std::cout << pa->GetEntryValue(0x0010, 0x0020) << "]" << std::endl; // Patient ID
164 st = pa->GetFirstStudy();
165 while ( st ) { // on degouline les STUDY de ce patient
166 std::cout << "--- Stud.descr:[" << st->GetEntryValue(0x0008, 0x1030) << "]";// Study Description
167 std::cout << " Stud.ID:[" << st->GetEntryValue(0x0020, 0x0010); // Study ID
168 std::cout << "]" << std::endl;
170 se = st->GetFirstSerie();
171 while ( se ) { // on degouline les SERIES de cette study
172 std::cout << "--- --- Ser.Descr:["<< se->GetEntryValue(0x0008, 0x103e)<< "]"; // Series Description
173 std::cout << " Ser.nb:[" << se->GetEntryValue(0x0020, 0x0011); // Series number
174 std::cout << "] Mod.:[" << se->GetEntryValue(0x0008, 0x0060) << "]"; // Modality
175 std::cout << std::endl;
176 se = st->GetNextSerie();
178 st = pa->GetNextStudy();
180 pa = f->GetNextPatient();
185 std::cout << std::endl << std::endl
186 << " = PATIENT/STUDY/SERIE/IMAGE List ============================"
187 << std::endl<< std::endl;
189 pa = f->GetFirstPatient();
190 while ( pa ) { // les PATIENT de ce DICOMDIR
191 // Patient's Name, Patient ID
192 std::cout << "Pat.Name:[" << pa->GetEntryValue(0x0010, 0x0010) <<"]"; // Patient's Name
193 std::cout << " Pat.ID:[";
194 std::cout << pa->GetEntryValue(0x0010, 0x0020) << "]" << std::endl; // Patient ID
196 st = pa->GetFirstStudy();
197 while ( st ) { // on degouline les STUDY de ce patient
198 std::cout << "--- Stud.descr:[" << st->GetEntryValue(0x0008, 0x1030) << "]";// Study Description
199 std::cout << " Stud.ID:[" << st->GetEntryValue(0x0020, 0x0010); // Study ID
200 std::cout << "]" << std::endl;
202 se = st->GetFirstSerie();
203 while ( se ) { // on degouline les SERIES de cette study
204 std::cout << "--- --- Ser.Descr:["<< se->GetEntryValue(0x0008, 0x103e)<< "]"; // Series Description
205 std::cout << " Ser.nb:[" << se->GetEntryValue(0x0020, 0x0011); // Series number
206 std::cout << "] Mod.:[" << se->GetEntryValue(0x0008, 0x0060) << "]"; // Modality
207 std::cout << std::endl;
209 im = se->GetFirstImage();
210 while ( im ) { // on degouline les Images de cette serie
211 std::cout << "--- --- --- "<< im->GetEntryValue(0x0004, 0x1500) << std::endl; // File name
212 im = se->GetNextImage();
214 se = st->GetNextSerie();
216 st = pa->GetNextStudy();
218 pa = f->GetNextPatient();
223 std::cout << std::endl << std::endl
224 << " = DICOMDIR full content =========================================="
225 << std::endl<< std::endl;
234 // Kept as an example. Please don't remove
236 gdcm::ListDicomDirPatient::const_iterator itPatient;
237 gdcm::ListDicomDirStudy::const_iterator itStudy;
238 gdcm::ListDicomDirSerie::const_iterator itSerie;
239 gdcm::ListDicomDirImage::const_iterator itImage;
240 cout << std::endl << std::endl
241 << " = Liste des PATIENT/STUDY/SERIE/IMAGE ==================================="
242 << std::endl<< std::endl;
244 itPatient = f->GetDicomDirPatients().begin();
245 while ( itPatient != f->GetDicomDirPatients().end() ) { // on degouline les PATIENT de ce DICOMDIR
246 std::cout << (*itPatient)->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
247 itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
248 while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
249 std::cout << "--- "<< (*itStudy)->GetEntryValue(0x0008, 0x1030) << std::endl; // Study Description
250 itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
251 while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
252 std::cout << "--- --- "<< (*itSerie)->GetEntryValue(0x0008, 0x103e) << std::endl; // Serie Description
253 itImage = ((*itSerie)->GetDicomDirImages()).begin();
254 while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les IMAGES de cette serie
255 std::cout << "--- --- --- "<< (*itImage)->GetEntryValue(0x0004, 0x1500) << std::endl; // File name
268 std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
270 std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
271 std::cout<<std::flush;