X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=inline;f=src%2FgdcmSerieHeader.cxx;h=7158a0bf102548e83b3be1e27c59689d0f45ab98;hb=7350639601914cd8ab02bfb0d6668c5bf56ce2f4;hp=93402bf19ca773cbe8c26ed9ac35009fb5cba4fa;hpb=1ce6ae86daabc8b64c9309acce4ecf137ee79f07;p=gdcm.git diff --git a/src/gdcmSerieHeader.cxx b/src/gdcmSerieHeader.cxx index 93402bf1..7158a0bf 100644 --- a/src/gdcmSerieHeader.cxx +++ b/src/gdcmSerieHeader.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSerieHeader.cxx,v $ Language: C++ - Date: $Date: 2005/01/31 12:19:34 $ - Version: $Revision: 1.17 $ + Date: $Date: 2005/02/01 11:02:27 $ + Version: $Revision: 1.20 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -37,62 +37,49 @@ typedef std::vector GdcmFileVector; */ SerieHeader::SerieHeader() { - //TODO - //CoherentGdcmFileList.clear(); -} - -/** - * \brief Canonical destructor. - */ -SerieHeader::~SerieHeader() -{ - // For all the Coherent File lists of the gdcm::Serie + // For all the File lists of the gdcm::Serie GdcmFileList *l = GetFirstCoherentFileList(); while (l) { - // For all the files of a Coherent File list - for (GdcmFileList::iterator it = l->begin(); + // For all the files of a File list + for (GdcmFileList::iterator it = l->begin(); it != l->end(); ++it) { delete *it; } l->clear(); + delete l;; l = GetNextCoherentFileList(); } } -//----------------------------------------------------------------------------- -// Print - /** - * \brief Canonical printer. + * \brief Canonical destructor. */ -void SerieHeader::Print() +SerieHeader::~SerieHeader() { // For all the Coherent File lists of the gdcm::Serie - CoherentFileListmap::iterator itl = CoherentGdcmFileListHT.begin(); - if ( itl == CoherentGdcmFileListHT.end() ) - { - gdcmVerboseMacro( "No Coherent File list found" ); - return; - } - while (itl != CoherentGdcmFileListHT.end()) + GdcmFileList *l = GetFirstCoherentFileList(); + while (l) { - std::cout << "Serie UID :[" << itl->first << "]" << std::endl; - // For all the files of a Coherent File list - for (GdcmFileList::iterator it = (itl->second)->begin(); - it != (itl->second)->end(); + for (GdcmFileList::iterator it = l->begin(); + it != l->end(); ++it) { - std::cout << " --- " << (*it)->GetFileName() << std::endl; + delete *it; } - ++itl; + l->clear(); + delete l; + l = GetNextCoherentFileList(); } } //----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- + // Public /** * \brief add a gdcm::File to the list corresponding to its Serie UID @@ -205,7 +192,6 @@ GdcmFileList *SerieHeader::GetCoherentFileList(std::string SerieUID) return CoherentGdcmFileListHT[SerieUID]; } - //----------------------------------------------------------------------------- // Protected @@ -323,7 +309,10 @@ bool SerieHeader::ImagePositionPatientOrdering( if (CoherentGdcmFileVector[pos]==NULL) CoherentGdcmFileVector[pos] = *it2; else + { + gdcmVerboseMacro( "2 files same position"); return false; + } } CoherentGdcmFileList->clear(); // doesn't delete list elements, only node @@ -343,8 +332,11 @@ bool SerieHeader::ImagePositionPatientOrdering( /** * \brief sorts the images, according to their Image Number + * \note Works only on bona fide files (i.e image number is a character string + * corresponding to an integer) + * within a bona fide serie (i.e image numbers are consecutive) * @param CoherentGdcmFileList Coherent File list (same Serie UID) to sort - * @return false only if the header is bugged ! + * @return false if non nona fide stuff encountered */ bool SerieHeader::ImageNumberOrdering(GdcmFileList *CoherentGdcmFileList) { @@ -358,22 +350,20 @@ bool SerieHeader::ImageNumberOrdering(GdcmFileList *CoherentGdcmFileList) for (; it != CoherentGdcmFileList->end(); ++it, ++n) { pos = (*it)->GetImageNumber(); - - //else min = (min < pos) ? min : pos; max = (max > pos) ? max : pos; } - // Find out if sorting worked: - if( min == max || max == 0 || max > (n+min)) return false; + // Find out if image numbers are coherent (consecutive) + 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); + memset(partition, 0, n); GdcmFileVector CoherentGdcmFileVector(n); - //VC++ don't understand what scope is !! it -> it2 + //VC++ doesn't understand what scope is !! it -> it2 for (GdcmFileList::const_iterator it2 = CoherentGdcmFileList->begin(); it2 != CoherentGdcmFileList->end(); ++it2) { @@ -388,15 +378,14 @@ bool SerieHeader::ImageNumberOrdering(GdcmFileList *CoherentGdcmFileList) mult *= partition[i]; } - //VC++ don't understand what scope is !! it -> it3 - CoherentGdcmFileList->clear(); // doesn't delete list elements, only node + //VC++ doesn't understand what scope is !! it -> it3 + CoherentGdcmFileList->clear(); // doesn't delete list elements, only nodes for ( GdcmFileVector::const_iterator it3 = CoherentGdcmFileVector.begin(); it3 != CoherentGdcmFileVector.end(); ++it3 ) { CoherentGdcmFileList->push_back( *it3 ); } - CoherentGdcmFileVector.clear(); - + CoherentGdcmFileVector.clear(); delete[] partition; return mult != 0; @@ -409,10 +398,39 @@ bool SerieHeader::ImageNumberOrdering(GdcmFileList *CoherentGdcmFileList) */ bool SerieHeader::FileNameOrdering(GdcmFileList *) { - //using the sort + //TODO using the sort //sort(CoherentGdcmFileList.begin(), CoherentGdcmFileList.end()); return true; } -} // end namespace gdcm //----------------------------------------------------------------------------- +// Print +/** + * \brief Canonical printer. + */ +void SerieHeader::Print() +{ + // For all the Coherent File lists of the gdcm::Serie + CoherentFileListmap::iterator itl = CoherentGdcmFileListHT.begin(); + if ( itl == CoherentGdcmFileListHT.end() ) + { + gdcmVerboseMacro( "No Coherent File list found" ); + return; + } + while (itl != CoherentGdcmFileListHT.end()) + { + std::cout << "Serie UID :[" << itl->first << "]" << std::endl; + + // For all the files of a Coherent File list + for (GdcmFileList::iterator it = (itl->second)->begin(); + it != (itl->second)->end(); + ++it) + { + std::cout << " --- " << (*it)->GetFileName() << std::endl; + } + ++itl; + } +} + +//----------------------------------------------------------------------------- +} // end namespace gdcm