1 /*=========================================================================
4 Module: $RCSfile: PrintDicomDir.cxx,v $
6 Date: $Date: 2005/07/08 10:15:04 $
7 Version: $Revision: 1.25 $
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);
83 f = new gdcm::DicomDir();
84 f->SetFileName ( fileName );
87 // Test if the DicomDir is readable
88 if( !f->IsReadable() )
90 std::cout<<" DicomDir '"<<fileName
91 <<"' is not readable"<<std::endl
92 <<" ...Failed"<<std::endl;
98 f->SetPrintLevel(level);
100 // Test if the DicomDir contains any Patient
101 pa = f->GetFirstPatient();
104 std::cout<<" DicomDir '"<<fileName
105 <<" has no patient"<<std::endl
106 <<" ...Failed"<<std::endl;
112 // Structure use Examples
117 std::cout << std::endl << std::endl
118 << " = PATIENT List =========================================="
119 << std::endl<< std::endl;
121 pa = f->GetFirstPatient();
124 std::cout << pa->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
125 pa = f->GetNextPatient();
130 std::cout << std::endl << std::endl
131 << " = PATIENT/STUDY List ======================================="
132 << std::endl<< std::endl;
134 pa = f->GetFirstPatient();
135 while ( pa ) // on degouline les PATIENT de ce DICOMDIR
137 std::cout << pa->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
139 st = pa->GetFirstStudy();
140 while ( st ) { // on degouline les STUDY de ce patient
141 std::cout << "--- "<< st->GetEntryValue(0x0008, 0x1030) << std::endl; // Study Description
142 st = pa->GetNextStudy();
144 pa = f->GetNextPatient();
149 std::cout << std::endl << std::endl
150 << " = PATIENT/STUDY/SERIE List =================================="
151 << std::endl<< std::endl;
153 pa = f->GetFirstPatient();
154 while ( pa ) // on degouline les PATIENT de ce DICOMDIR
156 // Patient's Name, Patient ID
157 std::cout << "Pat.Name:[" << pa->GetEntryValue(0x0010, 0x0010) <<"]"; // Patient's Name
158 std::cout << " Pat.ID:[";
159 std::cout << pa->GetEntryValue(0x0010, 0x0020) << "]" << std::endl; // Patient ID
161 st = pa->GetFirstStudy();
162 while ( st ) { // on degouline les STUDY de ce patient
163 std::cout << "--- Stud.descr:[" << st->GetEntryValue(0x0008, 0x1030) << "]";// Study Description
164 std::cout << " Stud.ID:[" << st->GetEntryValue(0x0020, 0x0010); // Study ID
165 std::cout << "]" << std::endl;
167 se = st->GetFirstSerie();
168 while ( se ) { // on degouline les SERIES de cette study
169 std::cout << "--- --- Ser.Descr:["<< se->GetEntryValue(0x0008, 0x103e)<< "]"; // Series Description
170 std::cout << " Ser.nb:[" << se->GetEntryValue(0x0020, 0x0011); // Series number
171 std::cout << "] Mod.:[" << se->GetEntryValue(0x0008, 0x0060) << "]"; // Modality
172 std::cout << std::endl;
173 se = st->GetNextSerie();
175 st = pa->GetNextStudy();
177 pa = f->GetNextPatient();
182 std::cout << std::endl << std::endl
183 << " = PATIENT/STUDY/SERIE/IMAGE List ============================"
184 << std::endl<< std::endl;
186 pa = f->GetFirstPatient();
187 while ( pa ) { // les PATIENT de ce DICOMDIR
188 // Patient's Name, Patient ID
189 std::cout << "Pat.Name:[" << pa->GetEntryValue(0x0010, 0x0010) <<"]"; // Patient's Name
190 std::cout << " Pat.ID:[";
191 std::cout << pa->GetEntryValue(0x0010, 0x0020) << "]" << std::endl; // Patient ID
193 st = pa->GetFirstStudy();
194 while ( st ) { // on degouline les STUDY de ce patient
195 std::cout << "--- Stud.descr:[" << st->GetEntryValue(0x0008, 0x1030) << "]";// Study Description
196 std::cout << " Stud.ID:[" << st->GetEntryValue(0x0020, 0x0010); // Study ID
197 std::cout << "]" << std::endl;
199 se = st->GetFirstSerie();
200 while ( se ) { // on degouline les SERIES de cette study
201 std::cout << "--- --- Ser.Descr:["<< se->GetEntryValue(0x0008, 0x103e)<< "]"; // Series Description
202 std::cout << " Ser.nb:[" << se->GetEntryValue(0x0020, 0x0011); // Series number
203 std::cout << "] Mod.:[" << se->GetEntryValue(0x0008, 0x0060) << "]"; // Modality
204 std::cout << std::endl;
206 im = se->GetFirstImage();
207 while ( im ) { // on degouline les Images de cette serie
208 std::cout << "--- --- --- "<< im->GetEntryValue(0x0004, 0x1500) << std::endl; // File name
209 im = se->GetNextImage();
211 se = st->GetNextSerie();
213 st = pa->GetNextStudy();
215 pa = f->GetNextPatient();
220 std::cout << std::endl << std::endl
221 << " = DICOMDIR full content =========================================="
222 << std::endl<< std::endl;
231 // Kept as an example. Please don't remove
233 gdcm::ListDicomDirPatient::const_iterator itPatient;
234 gdcm::ListDicomDirStudy::const_iterator itStudy;
235 gdcm::ListDicomDirSerie::const_iterator itSerie;
236 gdcm::ListDicomDirImage::const_iterator itImage;
237 cout << std::endl << std::endl
238 << " = Liste des PATIENT/STUDY/SERIE/IMAGE ==================================="
239 << std::endl<< std::endl;
241 itPatient = f->GetDicomDirPatients().begin();
242 while ( itPatient != f->GetDicomDirPatients().end() ) { // on degouline les PATIENT de ce DICOMDIR
243 std::cout << (*itPatient)->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
244 itStudy = ((*itPatient)->GetDicomDirStudies()).begin();
245 while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient
246 std::cout << "--- "<< (*itStudy)->GetEntryValue(0x0008, 0x1030) << std::endl; // Study Description
247 itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
248 while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study
249 std::cout << "--- --- "<< (*itSerie)->GetEntryValue(0x0008, 0x103e) << std::endl; // Serie Description
250 itImage = ((*itSerie)->GetDicomDirImages()).begin();
251 while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les IMAGES de cette serie
252 std::cout << "--- --- --- "<< (*itImage)->GetEntryValue(0x0004, 0x1500) << std::endl; // File name
265 std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
267 std::cout <<std::endl<<fileName<<" is NOT Readable"<<std::endl;
268 std::cout<<std::flush;