1 /*=========================================================================
4 Module: $RCSfile: TestDicomDir.cxx,v $
6 Date: $Date: 2005/01/29 11:56:53 $
7 Version: $Revision: 1.34 $
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 "gdcmDocEntry.h"
19 #include "gdcmValEntry.h"
20 #include "gdcmDicomDir.h"
21 #include "gdcmDicomDirPatient.h"
22 #include "gdcmDicomDirStudy.h"
23 #include "gdcmDicomDirSerie.h"
24 #include "gdcmDicomDirImage.h"
30 // check *all* the dicom elements (gdcm::DocEntry)
31 // of this gdcm::DicomDirObject
32 int CompareSQItem(gdcm::SQItem *pa1, gdcm::SQItem *pa2 )
37 e2 = pa2->GetFirstEntry();
40 // locate the corresponding element in 'source' file
41 e1 = pa1->GetDocEntry( e2->GetGroup(),e2->GetElement() );
44 // an element doesn't exist in source file
45 std::cout << "DicomDir element " << std::hex
46 << e2->GetGroup() << "," <<e2->GetElement() << std::endl;
49 // skip SeqEntries (I don't want to deal with 'recursion pbs' here)
50 if ( !dynamic_cast<gdcm::ValEntry*>(e1) ||
51 !dynamic_cast<gdcm::ValEntry*>(e2) )
54 if ( ((gdcm::ValEntry*)e1)->GetValue() !=
55 ((gdcm::ValEntry*)e2)->GetValue() )
57 // serious trouble : values differ in source and destination file
58 std::cout << "for gdcm DicomDir element (" << std::hex
59 << e2->GetGroup() << "," <<e2->GetElement()
60 << ") values differ ["
61 << ((gdcm::ValEntry*)e1)->GetValue() << "] != ["
62 << ((gdcm::ValEntry*)e2)->GetValue() << "]"
70 int TestDicomDir(int argc, char* argv[])
72 gdcm::DicomDir *dicomdir;
74 gdcm::DicomDirPatient * pa1;
75 gdcm::DicomDirStudy *st1;
76 gdcm::DicomDirSerie *se1;
77 gdcm::DicomDirImage *im1;
86 file += GDCM_DATA_ROOT;
90 dicomdir = new gdcm::DicomDir(file);
93 int level = atoi(argv[2]);
94 dicomdir->SetPrintLevel(level);
97 // Test if the DicomDir is readable
98 if( !dicomdir->IsReadable() )
100 std::cout<<" DicomDir '"<<file
101 <<"' is not readable"<<std::endl
102 <<" ...Failed"<<std::endl;
109 std::cout<<" DicomDir '"<<file
110 <<"' is readable"<<std::endl;
113 // Test if the DicomDir contains any patient
114 if( !dicomdir->GetFirstPatient() )
116 std::cout<<" DicomDir '"<<file
117 <<" has no patient"<<std::endl
118 <<" ...Failed"<<std::endl;
124 // step by step structure full exploitation
125 std::cout << std::endl << std::endl
126 << " = PATIENT/STUDY/SERIE/IMAGE List ============================"
127 << std::endl<< std::endl;
129 pa1 = dicomdir->GetFirstPatient();
131 { // we process all the PATIENT of this DICOMDIR
132 std::cout << pa1->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
134 st1 = pa1->GetFirstStudy();
136 { // we process all the STUDY of this patient
137 std::cout << "--- "<< st1->GetEntryValue(0x0008, 0x1030) // Study Description
139 std::cout << " Stud.ID:[" << st1->GetEntryValue(0x0020, 0x0010) // Study ID
142 se1 = st1->GetFirstSerie();
144 { // we process all the SERIES of this study
145 std::cout << "--- --- "<< se1->GetEntryValue(0x0008, 0x103e) << std::endl; // Serie Description
146 std::cout << " Ser.nb:[" << se1->GetEntryValue(0x0020, 0x0011); // Series number
147 std::cout << "] Mod.:[" << se1->GetEntryValue(0x0008, 0x0060) << "]"; // Modality
149 im1 = se1->GetFirstImage();
150 while ( im1 ) { // we process all the IMAGE of this serie
151 std::cout << "--- --- --- "<< im1->GetEntryValue(0x0004, 0x1500) << std::endl; // File name
152 im1 = se1->GetNextImage();
154 se1 = st1->GetNextSerie();
156 st1 = pa1->GetNextStudy();
158 pa1 = dicomdir->GetNextPatient();
161 std::cout << std::endl << std::endl
162 << " = DICOMDIR full content ===================================="
163 << std::endl<< std::endl;
164 // dicomdir->Print();
166 // ------------------------- second stage ---------------------------
168 // Write on disc what we read
169 dicomdir->WriteDicomDir("NewDICOMDIR");
171 std::cout << std::endl << std::endl
172 << "NewDICOMDIR written on disc ================================="
173 << std::endl<< std::endl;
174 // Read what we wrote
175 gdcm::DicomDir *d2 = new gdcm::DicomDir("NewDICOMDIR");
179 std::cout << std::endl << std::endl
180 << "Read NewDicomDir from disc failed ========================"
181 << std::endl<< std::endl;
184 std::cout << std::endl << std::endl
185 << "NewDICOMDIR successfully read from disc ================================="
186 << std::endl<< std::endl;
188 gdcm::DicomDirPatient *pa2;
189 gdcm::DicomDirStudy *st2;
190 gdcm::DicomDirSerie *se2;
191 gdcm::DicomDirImage *im2;
193 pa1 = dicomdir->GetFirstPatient();
194 pa2 = d2->GetFirstPatient();
198 std::cout << "NewDICOMDIR contains no Patient ?!?" << std::endl;
205 { // we process all the PATIENT of this DICOMDIR
207 if ( CompareSQItem(pa2,pa1) == 1 )
210 // just to allow human reader to be sure ...
211 std::cout << pa2->GetEntryValue(0x0010, 0x0010)
212 << std::endl; // Patient's Name
214 st1 = pa1->GetFirstStudy();
215 st2 = pa2->GetFirstStudy();
219 if ( CompareSQItem(st2,st1) == 1 )
222 // just to allow human reader to be sure ...
223 std::cout << "--- "<< st2->GetEntryValue(0x0008, 0x1030);
224 // << std::endl; // Study Description
225 std::cout << " Stud.ID:["
226 << st2->GetEntryValue(0x0020, 0x0010)
227 << "]" << std::endl; // Study ID
229 se1 = st1->GetFirstSerie();
230 se2 = st2->GetFirstSerie();
233 { // we process all the SERIE of this study
234 if ( CompareSQItem(se2,se1) == 1 )
236 std::cout << "--- --- " << se2->GetEntryValue(0x0008, 0x103e); // Serie Description
237 std::cout << " Ser.nb:["<< se2->GetEntryValue(0x0020, 0x0011); // Series number
238 std::cout << "] Mod.:[" << se2->GetEntryValue(0x0008, 0x0060) << "]" << std::endl; // Modality
239 im1 = se1->GetFirstImage();
240 im2 = se2->GetFirstImage();
242 while ( im1 && im2 ) // we process all the IMAGE of this serie
244 if ( CompareSQItem(im2,im1) == 1 )
247 im1 = se1->GetNextImage();
248 im2 = se2->GetNextImage();
250 se1 = st1->GetNextSerie();
251 se2 = st2->GetNextSerie();
253 st1 = pa1->GetNextStudy();
254 st2 = pa2->GetNextStudy();
256 pa1 = dicomdir->GetNextPatient();
257 pa2 = dicomdir->GetNextPatient();
260 std::cout << std::flush;