From 6383e4f567672c46fefb1c67c0bb821dee5b8bff Mon Sep 17 00:00:00 2001 From: jpr Date: Sun, 3 Jul 2005 12:45:53 +0000 Subject: [PATCH] - Speed up DICOMDIR analyse - Avoid infinite loop when a 'no Patient / no Study / no Serie / no Image' Item is found Thx to Loic Boussel for providing data to fix the bug. --- src/gdcmDicomDir.cxx | 56 ++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index a67ed04b..05981583 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDir.cxx,v $ Language: C++ - Date: $Date: 2005/06/24 10:55:58 $ - Version: $Revision: 1.142 $ + Date: $Date: 2005/07/03 12:45:53 $ + Version: $Revision: 1.143 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -702,51 +702,61 @@ void DicomDir::CreateDicomDir() continue; } - if ( v == "PATIENT " ) + // A decent DICOMDIR has much more images than series, + // more series than studies, and so on. + // This is the right order to preform the tests + + if ( v == "IMAGE " ) { - si = new DicomDirPatient(true); - if ( !AddPatientToEnd( static_cast(si)) ) + si = new DicomDirImage(true); + if ( !AddImageToEnd( static_cast(si)) ) { delete si; si = NULL; - gdcmErrorMacro( "Add PatientToEnd failed"); + gdcmErrorMacro( "Add AddImageToEnd failed"); } } - else if ( v == "STUDY " ) + else if ( v == "SERIES" ) { - si = new DicomDirStudy(true); - if ( !AddStudyToEnd( static_cast(si)) ) + si = new DicomDirSerie(true); + if ( !AddSerieToEnd( static_cast(si)) ) { delete si; si = NULL; - gdcmErrorMacro( "Add AddStudyToEnd failed"); + gdcmErrorMacro( "Add AddSerieToEnd failed"); } } - else if ( v == "SERIES" ) + else if ( v == "STUDY " ) { - si = new DicomDirSerie(true); - if ( !AddSerieToEnd( static_cast(si)) ) + si = new DicomDirStudy(true); + if ( !AddStudyToEnd( static_cast(si)) ) { delete si; si = NULL; - gdcmErrorMacro( "Add AddSerieToEnd failed"); + gdcmErrorMacro( "Add AddStudyToEnd failed"); } } - else if ( v == "IMAGE " ) + else if ( v == "PATIENT " ) { - si = new DicomDirImage(true); - if ( !AddImageToEnd( static_cast(si)) ) + si = new DicomDirPatient(true); + if ( !AddPatientToEnd( static_cast(si)) ) { delete si; si = NULL; - gdcmErrorMacro( "Add AddImageToEnd failed"); + gdcmErrorMacro( "Add PatientToEnd failed"); } } else { - // It was not a 'PATIENT', nor a 'STUDY', nor a 'SERIE', - // neither an 'IMAGE' SQItem. Skip to next item. - continue; + // It was neither a 'PATIENT', nor a 'STUDY', nor a 'SERIE', + // nor an 'IMAGE' SQItem. Skip to next item. + gdcmWarningMacro( " -------------------------------------------" + << "a non PATIENT/STUDY/SERIE/IMAGE SQItem was found : " + << v); + + // FIXME : deal with other item types ! + tmpSI=s->GetNextSQItem(); // To avoid infinite loop + continue; } if ( si ) MoveSQItem(si,tmpSI); @@ -866,7 +876,7 @@ void DicomDir::SetElements(std::string const &path, VectDocument const &list) first = true; } - // if new Study Deal with 'STUDY' Elements + // if new Study, deal with 'STUDY' Elements if ( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID || first ) { @@ -874,7 +884,7 @@ void DicomDir::SetElements(std::string const &path, VectDocument const &list) first = true; } - // if new Serie Deal with 'SERIE' Elements + // if new Serie, deal with 'SERIE' Elements if ( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID || first ) { -- 2.48.1