X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Testing%2FTestDicomDir.cxx;h=886120b3b6076f19fa162ad3a4d6b3c98e7d538c;hb=6a7c2fbcb5bfc240a3b9875ad4836f5dc058e069;hp=1bd8fd227ad93a80c9ebb554a789051108cc97e1;hpb=9331f4535478b96fd574029e2d609a524c62d2c6;p=gdcm.git diff --git a/Testing/TestDicomDir.cxx b/Testing/TestDicomDir.cxx index 1bd8fd22..886120b3 100644 --- a/Testing/TestDicomDir.cxx +++ b/Testing/TestDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestDicomDir.cxx,v $ Language: C++ - Date: $Date: 2004/12/07 09:08:45 $ - Version: $Revision: 1.23 $ + Date: $Date: 2005/10/18 08:35:46 $ + Version: $Revision: 1.41 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -16,6 +16,7 @@ =========================================================================*/ #include "gdcmDocEntry.h" +#include "gdcmDataEntry.h" #include "gdcmDicomDir.h" #include "gdcmDicomDirPatient.h" #include "gdcmDicomDirStudy.h" @@ -26,132 +27,267 @@ #include #include -int TestDicomDir(int argc, char* argv[]) +// check *all* the dicom elements (gdcm::DocEntry) +// of this gdcm::DicomDirObject +int CompareSQItem(gdcm::SQItem *pa1, gdcm::SQItem *pa2 ) +{ + gdcm::DocEntry *e1; + gdcm::DocEntry *e2; + + e2 = pa2->GetFirstEntry(); + while (!e2) + { + // locate the corresponding element in 'source' file + e1 = pa1->GetDocEntry( e2->GetGroup(),e2->GetElement() ); + + // an element doesn't exist in origin file + if (!e1) + { + std::cout << "DicomDir element " << std::hex + << e2->GetGroup() << "," <GetElement() << std::endl; + return 1; + } + // skip SeqEntries (I don't want to deal with 'recursion pbs' here) + if ( !dynamic_cast(e1) || + !dynamic_cast(e2) ) + continue; + + // a value is read as GDCM_UNFOUND + if ( ((gdcm::DataEntry *)e1)->GetString() == gdcm::GDCM_UNFOUND ) + { + std::cout << "for gdcm source DicomDir : element (" << std::hex + << e1->GetGroup() << "," <GetElement() + << ") has values [" << gdcm::GDCM_UNFOUND << "]" + << std::endl; + return 1; + } + + // values differ in source file and destination file + if ( ((gdcm::DataEntry *)e1)->GetString() != + ((gdcm::DataEntry *)e2)->GetString() ) + { + + // serious trouble : values differ in source and destination file + std::cout << "for gdcm DicomDir element (" << std::hex + << e2->GetGroup() << "," <GetElement() + << ") values differ [" + << ((gdcm::DataEntry *)e1)->GetString() << "] != [" + << ((gdcm::DataEntry *)e2)->GetString() << "]" + << std::endl; + return 1; + } + } + return 0; +} + +int TestDicomDir(int argc, char *argv[]) { - gdcm::DicomDir *e1; + gdcm::DicomDir *dicomdir; - gdcm::ListDicomDirPatient::const_iterator itPatient; - gdcm::ListDicomDirStudy::const_iterator itStudy; - gdcm::ListDicomDirSerie::const_iterator itSerie; - //gdcm::ListDicomDirImage::const_iterator itImage; + gdcm::DicomDirPatient *pa1; + gdcm::DicomDirStudy *st1; + gdcm::DicomDirSerie *se1; + gdcm::DicomDirImage *im1; + gdcm::TSKey v; std::string file; if (argc > 1) file = argv[1]; - else { + else + { file += GDCM_DATA_ROOT; file += "/DICOMDIR"; - } + } - e1 = new gdcm::DicomDir(file); - if (argc > 2) { + dicomdir = new gdcm::DicomDir( ); + dicomdir->SetFileName(file); + dicomdir->Load( ); + if (argc > 2) + { int level = atoi(argv[2]); - e1->SetPrintLevel(level); + dicomdir->SetPrintLevel(level); } - if(e1->GetDicomDirPatients().begin() == e1->GetDicomDirPatients().end() ) + // Test if the DicomDir is readable + if( !dicomdir->IsReadable() ) { - std::cout<<"Empty list"<GetFirstPatient() ) + { + std::cout<<" DicomDir '"<GetFirstPatient(); + while ( pa1 ) + { // we process all the PATIENT of this DICOMDIR + std::cout << pa1->GetEntryString(0x0010, 0x0010) << std::endl; // Patient's Name + + st1 = pa1->GetFirstStudy(); + while ( st1 ) + { // we process all the STUDY of this patient + std::cout << "--- "<< st1->GetEntryString(0x0008, 0x1030) // Study Description + << std::endl; + std::cout << " Stud.ID:[" << st1->GetEntryString(0x0020, 0x0010) // Study ID + << "]"; + + se1 = st1->GetFirstSerie(); + while ( se1 ) + { // we process all the SERIES of this study + std::cout << "--- --- "<< se1->GetEntryString(0x0008, 0x103e) << std::endl; // Serie Description + std::cout << " Ser.nb:[" << se1->GetEntryString(0x0020, 0x0011); // Series number + std::cout << "] Mod.:[" << se1->GetEntryString(0x0008, 0x0060) << "]"; // Modality + + im1 = se1->GetFirstImage(); + while ( im1 ) { // we process all the IMAGE of this serie + std::cout << "--- --- --- "<< im1->GetEntryString(0x0004, 0x1500) << std::endl; // File name + im1 = se1->GetNextImage(); + } + se1 = st1->GetNextSerie(); + } + st1 = pa1->GetNextStudy(); + } + pa1 = dicomdir->GetNextPatient(); + } -/* - cout << std::endl << std::endl - << " = Liste des PATIENT ==========================================" - << std::endl<< std::endl; + std::cout << std::endl << std::endl + << " = DICOMDIR full content ====================================" + << std::endl<< std::endl; + // dicomdir->Print(); + // ------------------------- second stage --------------------------- + + // Write on disc what we read + dicomdir->Write("NewDICOMDIR"); - itPatient = e1->GetDicomDirPatients().begin(); - while ( itPatient != e1->GetDicomDirPatients().end() ) { // on degouline la liste de PATIENT - std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name - itPatient ++; + std::cout << std::endl << std::endl + << "NewDICOMDIR written on disc =================================" + << std::endl<< std::endl; + // Read what we wrote + gdcm::DicomDir *d2 = new gdcm::DicomDir( ); + d2->SetFileName("NewDICOMDIR"); + d2->Load( ); + if (!d2->IsReadable( )) + { + std::cout << std::endl << std::endl + << "Read NewDicomDir from disc failed ========================" + << std::endl<< std::endl; + return 1; } -*/ - -/* - cout << std::endl << std::endl - << " = Liste des PATIENT/STUDY ==========================================" - << std::endl<< std::endl; - - itPatient = e1->GetDicomDirPatients().begin(); - while ( itPatient != e1->GetDicomDirPatients().end() ) { // on degouline la liste de PATIENT - std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name - itStudy = ((*itPatient)->GetDicomDirStudies()).begin(); - while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient - std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Study Description - ++itStudy; - } - itPatient ++; - } - */ - std::cout << std::endl << std::endl - << " = Liste des PATIENT/STUDY/SERIE ==========================================" + << "NewDICOMDIR successfully read from disc =================================" << std::endl<< std::endl; - - itPatient = e1->GetDicomDirPatients().begin(); - while ( itPatient != e1->GetDicomDirPatients().end() ) { // on degouline la liste de PATIENT - // Patient's Name, Patient ID - std::cout << "Pat.Name:[" << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) <<"]"; - std::cout << " Pat.ID:["; - std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0020) << "]" << std::endl; - itStudy = ((*itPatient)->GetDicomDirStudies()).begin(); - while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient - std::cout << "--- Stud.descr:[" << (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << "]";// Study Description - std::cout << " Stud.ID:["<< (*itStudy)->GetEntryByNumber(0x0020, 0x0010); // Study ID - std::cout << "]" << std::endl; - itSerie = ((*itStudy)->GetDicomDirSeries()).begin(); - while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study - std::cout << "--- --- Ser.Descr:["<< (*itSerie)->GetEntryByNumber(0x0008, 0x103e)<< "]";// Serie Description - std::cout << " Ser.nb:[" << (*itSerie)->GetEntryByNumber(0x0020, 0x0011); // Serie number - std::cout << "] Mod.:[" << (*itSerie)->GetEntryByNumber(0x0008, 0x0060) << "]"; // Modality - std::cout << std::endl; - ++itSerie; - } - ++itStudy; - } - itPatient ++; - } + + gdcm::DicomDirPatient *pa2; + gdcm::DicomDirStudy *st2; + gdcm::DicomDirSerie *se2; + gdcm::DicomDirImage *im2; + + pa1 = dicomdir->GetFirstPatient(); + pa2 = d2->GetFirstPatient(); + + if (!d2) + { + std::cout << "NewDICOMDIR contains no Patient ?!?" << std::endl; + delete dicomdir; + delete d2; + return 1; + } - - /* - cout << std::endl << std::endl - << " = Liste des PATIENT/STUDY/SERIE/IMAGE ===================================" - << std::endl<< std::endl; + while ( pa1 && pa2 ) + { // we process all the PATIENT of this DICOMDIR + + if ( CompareSQItem(pa2,pa1) == 1 ) + { + delete dicomdir; + delete d2; + return 1; + } + + // just to allow human reader to be sure ... + std::cout << pa2->GetEntryString(0x0010, 0x0010) + << std::endl; // Patient's Name - itPatient = e1->GetDicomDirPatients().begin(); - while ( itPatient != e1->GetDicomDirPatients().end() ) { // on degouline la liste de PATIENT - std::cout << (*itPatient)->GetEntryByNumber(0x0010, 0x0010) << std::endl; // Patient's Name - itStudy = ((*itPatient)->GetDicomDirStudies()).begin(); - while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient - std::cout << "--- "<< (*itStudy)->GetEntryByNumber(0x0008, 0x1030) << std::endl; // Study Description - itSerie = ((*itStudy)->GetDicomDirSeries()).begin(); - while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study - std::cout << "--- --- "<< (*itSerie)->GetEntryByNumber(0x0008, 0x103e) << std::endl; // Serie Description - itImage = ((*itSerie)->GetDicomDirImages()).begin(); - while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les SERIES de cette study - std::cout << "--- --- --- "<< (*itImage)->GetEntryByNumber(0x0004, 0x1500) << std::endl; // File name - ++itImage; - } - ++itSerie; + st1 = pa1->GetFirstStudy(); + st2 = pa2->GetFirstStudy(); + + while ( st1 && st2 ) + { + if ( CompareSQItem(st2,st1) == 1 ) + { + delete dicomdir; + delete d2; + return 1; } - ++itStudy; - } - itPatient ++; - } - */ - std::cout << std::endl << std::endl - << " = Contenu Complet du DICOMDIR ==========================================" - << std::endl<< std::endl; - e1->Print(); + // just to allow human reader to be sure ... + std::cout << "--- "<< st2->GetEntryString(0x0008, 0x1030); + // << std::endl; // Study Description + std::cout << " Stud.ID:[" + << st2->GetEntryString(0x0020, 0x0010) + << "]" << std::endl; // Study ID + + se1 = st1->GetFirstSerie(); + se2 = st2->GetFirstSerie(); + + while ( se1 && se2 ) + { // we process all the SERIE of this study + if ( CompareSQItem(se2,se1) == 1 ) + return 1; + std::cout << "--- --- " << se2->GetEntryString(0x0008, 0x103e); // Serie Description + std::cout << " Ser.nb:["<< se2->GetEntryString(0x0020, 0x0011); // Series number + std::cout << "] Mod.:[" << se2->GetEntryString(0x0008, 0x0060) << "]" << std::endl; // Modality + im1 = se1->GetFirstImage(); + im2 = se2->GetFirstImage(); + + while ( im1 && im2 ) // we process all the IMAGE of this serie + { + if ( CompareSQItem(im2,im1) == 1 ) + { + delete dicomdir; + delete d2; + return 1; + } + + im1 = se1->GetNextImage(); + im2 = se2->GetNextImage(); + } + se1 = st1->GetNextSerie(); + se2 = st2->GetNextSerie(); + } + st1 = pa1->GetNextStudy(); + st2 = pa2->GetNextStudy(); + } + pa1 = dicomdir->GetNextPatient(); + pa2 = dicomdir->GetNextPatient(); + } - std::cout<