From: malaterre Date: Tue, 16 Nov 2004 18:33:33 +0000 (+0000) Subject: ENH: Apply patch from ITK back to gdcm. Solve problem when iterating over arbitrary... X-Git-Tag: Version1.0.bp~589 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=a54ca199a2f222f2ed483be663bc1b95a6c6f7a3;p=gdcm.git ENH: Apply patch from ITK back to gdcm. Solve problem when iterating over arbitrary DICOM file with no relation one to the other --- diff --git a/src/gdcmHeaderHelper.cxx b/src/gdcmHeaderHelper.cxx index c57ac307..77d4d166 100644 --- a/src/gdcmHeaderHelper.cxx +++ b/src/gdcmHeaderHelper.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmHeaderHelper.cxx,v $ Language: C++ - Date: $Date: 2004/11/09 22:15:36 $ - Version: $Revision: 1.44 $ + Date: $Date: 2004/11/16 18:33:33 $ + Version: $Revision: 1.45 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -81,9 +81,16 @@ void SerieHeader::SetDirectory(std::string const & dir) for( DirList::const_iterator it = filenames_list.begin(); it != filenames_list.end(); ++it) { - //use string and not const char*: + //directly use string and not const char*: Header *header = new Header( *it ); - CoherentGdcmFileList.push_back( header ); + if( header->IsReadable() ) + { + CoherentGdcmFileList.push_back( header ); + } + else + { + delete header; + } } } @@ -247,12 +254,12 @@ bool SerieHeader::ImagePositionPatientOrdering() bool SerieHeader::ImageNumberOrdering() { - int min, pos; - int n = 0;//CoherentGdcmFileList.size() is a O(N) operation !! + int min, max, pos; + int n = 0;//CoherentGdcmFileList.size() is a O(N) operation unsigned char *partition; GdcmHeaderList::const_iterator it = CoherentGdcmFileList.begin(); - min = (*it)->GetImageNumber(); + min = max = (*it)->GetImageNumber(); for (; it != CoherentGdcmFileList.end(); ++it, ++n) { @@ -260,9 +267,13 @@ bool SerieHeader::ImageNumberOrdering() //else min = (min < pos) ? min : pos; + max = (max > pos) ? max : pos; } - //bzeros(partition, n); //Cette fonction est déconseillée, utilisez plutôt memset. + // Find out if sorting worked: + if( min == max || max == 0 || max > (n+min)) return false; + + //bzeros(partition, n); //This function is deprecated, better use memset. partition = new unsigned char[n]; memset(partition, 0, n);