X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmSerieHeader.cxx;h=05f2ecef1d6be1e665e3924081ef317802459609;hb=963480c814326423065a4a02fa1bf8bc1243ae4f;hp=ff773d8b3bab92d1e88f816bdd69f9393b7a692b;hpb=ba78e6c6d47d6db1528e8e88e5ebde7296a26692;p=gdcm.git diff --git a/src/gdcmSerieHeader.cxx b/src/gdcmSerieHeader.cxx index ff773d8b..05f2ecef 100644 --- a/src/gdcmSerieHeader.cxx +++ b/src/gdcmSerieHeader.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSerieHeader.cxx,v $ Language: C++ - Date: $Date: 2004/12/03 20:16:58 $ - Version: $Revision: 1.2 $ + Date: $Date: 2005/01/18 08:01:42 $ + Version: $Revision: 1.10 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -19,6 +19,7 @@ #include "gdcmSerieHeader.h" #include "gdcmDirList.h" #include "gdcmHeader.h" +#include "gdcmDebug.h" #include #include @@ -33,6 +34,8 @@ typedef std::vector GdcmHeaderVector; SerieHeader::SerieHeader() { CoherentGdcmFileList.clear(); + // Later will contain: 0020 000e UI REL Series Instance UID + CurrentSerieUID = ""; } SerieHeader::~SerieHeader() @@ -55,42 +58,52 @@ SerieHeader::~SerieHeader() * \brief add a File to the list based on file name * @param filename Name of the file to deal with */ -void SerieHeader::AddFileName(std::string const & filename) +void SerieHeader::AddFileName(std::string const &filename) { - Header *header = new Header( filename ); - CoherentGdcmFileList.push_back( header ); -} - -/** - * \brief add a File to the list - * @param file Header to add - */ -void SerieHeader::AddGdcmFile(Header *file) -{ - CoherentGdcmFileList.push_back( file ); + //directly use string and not const char*: + Header *header = new Header( filename ); + if( header->IsReadable() ) + { + // 0020 000e UI REL Series Instance UID + std::string uid = header->GetEntry (0x0020, 0x000e); + // if uid == GDCM_UNFOUND then consistenly we should find GDCM_UNFOUND + // no need here to do anything special + if( CurrentSerieUID == "" ) + { + // Set the current one + CurrentSerieUID = uid; + } + if( CurrentSerieUID == uid ) + { + // Current Serie UID and DICOM header seems to match add the file: + CoherentGdcmFileList.push_back( header ); + } + else + { + gdcmVerboseMacro("Wrong Serie Instance UID should be:" << CurrentSerieUID ); + } + } + else + { + gdcmVerboseMacro("Could not read file: " << filename ); + delete header; + } } /** * \brief Sets the Directory * @param dir Name of the directory to deal with */ -void SerieHeader::SetDirectory(std::string const & dir) +void SerieHeader::SetDirectory(std::string const &dir) { - DirList filenames_list(dir); //OS specific + CurrentSerieUID = ""; //Reset previous Serie Instance UID + DirList dirList(dir); //OS specific - for( DirList::const_iterator it = filenames_list.begin(); + DirListType filenames_list = dirList.GetFilenames(); + for( DirListType::const_iterator it = filenames_list.begin(); it != filenames_list.end(); ++it) { - //directly use string and not const char*: - Header *header = new Header( *it ); - if( header->IsReadable() ) - { - CoherentGdcmFileList.push_back( header ); - } - else - { - delete header; - } + AddFileName( *it ); } } @@ -122,7 +135,6 @@ void SerieHeader::OrderGdcmFileList() //----------------------------------------------------------------------------- // Private /** - * \ingroup Header * \brief sorts the images, according to their Patient Position * We may order, considering : * -# Image Number @@ -134,7 +146,7 @@ bool SerieHeader::ImagePositionPatientOrdering() //based on Jolinda's algorithm { //iop is calculated based on the file file - float *cosines = new float[6]; + float cosines[6]; float normal[3]; float ipp[3]; float dist; @@ -172,7 +184,6 @@ bool SerieHeader::ImagePositionPatientOrdering() if( dist == 0 ) { - delete[] cosines; return false; } @@ -195,7 +206,6 @@ bool SerieHeader::ImagePositionPatientOrdering() if( dist == 0 ) { - delete[] cosines; return false; } @@ -213,7 +223,7 @@ bool SerieHeader::ImagePositionPatientOrdering() GdcmHeaderVector CoherentGdcmFileVector(n); // CoherentGdcmFileVector.reserve( n ); CoherentGdcmFileVector.resize( n ); - // assert( CoherentGdcmFileVector.capacity() >= n ); + // gdcmAssertMacro( CoherentGdcmFileVector.capacity() >= n ); float step = (max - min)/(n - 1); int pos; @@ -241,13 +251,11 @@ bool SerieHeader::ImagePositionPatientOrdering() distlist.clear(); CoherentGdcmFileVector.clear(); - delete[] cosines; return true; } /** - * \ingroup Header * \brief sorts the images, according to their Image Number * @return false only if the header is bugged ! */ @@ -305,12 +313,11 @@ bool SerieHeader::ImageNumberOrdering() delete[] partition; - return (mult != 0); + return mult != 0; } /** - * \ingroup Header * \brief sorts the images, according to their File Name * @return false only if the header is bugged ! */