X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmSerieHeader.cxx;h=2bee2ffae739369ed6c40e325887fe01fd377410;hb=c907ef7411a7ddef4192414a95fb7909798e5d02;hp=6360e0a46ac892eaf22627468428c1bd71f12a0c;hpb=a0e1e2a8b7226c17d30c3368f438e3e5c439105f;p=gdcm.git diff --git a/src/gdcmSerieHeader.cxx b/src/gdcmSerieHeader.cxx index 6360e0a4..2bee2ffa 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/14 21:03:54 $ - Version: $Revision: 1.6 $ + Date: $Date: 2005/01/21 11:40:55 $ + Version: $Revision: 1.12 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -18,7 +18,7 @@ #include "gdcmSerieHeader.h" #include "gdcmDirList.h" -#include "gdcmHeader.h" +#include "gdcmFile.h" #include "gdcmDebug.h" #include @@ -28,20 +28,20 @@ namespace gdcm { -typedef std::vector GdcmHeaderVector; +typedef std::vector GdcmFileVector; //----------------------------------------------------------------------------- // Constructor / Destructor SerieHeader::SerieHeader() { CoherentGdcmFileList.clear(); - // Later will contains: 0020 000e UI REL Series Instance UID + // Later will contain: 0020 000e UI REL Series Instance UID CurrentSerieUID = ""; } SerieHeader::~SerieHeader() { /// \todo - for ( GdcmHeaderList::const_iterator it = CoherentGdcmFileList.begin(); + for ( GdcmFileList::const_iterator it = CoherentGdcmFileList.begin(); it != CoherentGdcmFileList.end(); ++it) { delete *it; @@ -61,11 +61,13 @@ SerieHeader::~SerieHeader() void SerieHeader::AddFileName(std::string const &filename) { //directly use string and not const char*: - Header *header = new Header( filename ); + File *header = new File( 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 @@ -88,31 +90,17 @@ void SerieHeader::AddFileName(std::string const &filename) } } -/** - * \brief add a File to the list - * @param file Header to add - */ -void SerieHeader::AddGdcmFile(Header *file) -{ - if( file->IsReadable() ) - { - CoherentGdcmFileList.push_back( file ); - } - else - { - gdcmVerboseMacro("Could not add file: " << file->GetFileName() ); - } -} - /** * \brief Sets the Directory * @param dir Name of the directory to deal with */ 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) { AddFileName( *it ); @@ -147,7 +135,6 @@ void SerieHeader::OrderGdcmFileList() //----------------------------------------------------------------------------- // Private /** - * \ingroup Header * \brief sorts the images, according to their Patient Position * We may order, considering : * -# Image Number @@ -169,7 +156,7 @@ bool SerieHeader::ImagePositionPatientOrdering() std::vector distlist; //!\todo rewrite this for loop. - for ( GdcmHeaderList::const_iterator + for ( GdcmFileList::const_iterator it = CoherentGdcmFileList.begin(); it != CoherentGdcmFileList.end(); ++it ) { @@ -233,7 +220,7 @@ bool SerieHeader::ImagePositionPatientOrdering() // Then I order the slices according to the value "dist". Finally, once // I've read in all the slices, I calculate the z-spacing as the difference // between the "dist" values for the first two slices. - GdcmHeaderVector CoherentGdcmFileVector(n); + GdcmFileVector CoherentGdcmFileVector(n); // CoherentGdcmFileVector.reserve( n ); CoherentGdcmFileVector.resize( n ); // gdcmAssertMacro( CoherentGdcmFileVector.capacity() >= n ); @@ -243,20 +230,27 @@ bool SerieHeader::ImagePositionPatientOrdering() n = 0; //VC++ don't understand what scope is !! it -> it2 - for (GdcmHeaderList::const_iterator it2 = CoherentGdcmFileList.begin(); + for (GdcmFileList::const_iterator it2 = CoherentGdcmFileList.begin(); it2 != CoherentGdcmFileList.end(); ++it2, ++n) { //2*n sort algo !! //Assumption: all files are present (no one missing) pos = (int)( fabs( (distlist[n]-min)/step) + .5 ); - - CoherentGdcmFileVector[pos] = *it2; + + // a Dicom 'Serie' may contain scout views + // and images may have differents directions + // -> More than one may have the same 'pos' + // Sorting has then NO meaning ! + if (CoherentGdcmFileVector[pos]==NULL) + CoherentGdcmFileVector[pos] = *it2; + else + return false; } CoherentGdcmFileList.clear(); //this doesn't delete list's element, node only //VC++ don't understand what scope is !! it -> it3 - for (GdcmHeaderVector::const_iterator it3 = CoherentGdcmFileVector.begin(); + for (GdcmFileVector::const_iterator it3 = CoherentGdcmFileVector.begin(); it3 != CoherentGdcmFileVector.end(); ++it3) { CoherentGdcmFileList.push_back( *it3 ); @@ -269,7 +263,6 @@ bool SerieHeader::ImagePositionPatientOrdering() } /** - * \ingroup Header * \brief sorts the images, according to their Image Number * @return false only if the header is bugged ! */ @@ -280,7 +273,7 @@ bool SerieHeader::ImageNumberOrdering() int n = 0;//CoherentGdcmFileList.size() is a O(N) operation unsigned char *partition; - GdcmHeaderList::const_iterator it = CoherentGdcmFileList.begin(); + GdcmFileList::const_iterator it = CoherentGdcmFileList.begin(); min = max = (*it)->GetImageNumber(); for (; it != CoherentGdcmFileList.end(); ++it, ++n) @@ -299,10 +292,10 @@ bool SerieHeader::ImageNumberOrdering() partition = new unsigned char[n]; memset(partition, 0, n); - GdcmHeaderVector CoherentGdcmFileVector(n); + GdcmFileVector CoherentGdcmFileVector(n); //VC++ don't understand what scope is !! it -> it2 - for (GdcmHeaderList::const_iterator it2 = CoherentGdcmFileList.begin(); + for (GdcmFileList::const_iterator it2 = CoherentGdcmFileList.begin(); it2 != CoherentGdcmFileList.end(); ++it2) { pos = (*it2)->GetImageNumber(); @@ -318,7 +311,7 @@ bool SerieHeader::ImageNumberOrdering() //VC++ don't understand what scope is !! it -> it3 CoherentGdcmFileList.clear(); //this doesn't delete list's element, node only - for ( GdcmHeaderVector::const_iterator it3 = CoherentGdcmFileVector.begin(); + for ( GdcmFileVector::const_iterator it3 = CoherentGdcmFileVector.begin(); it3 != CoherentGdcmFileVector.end(); ++it3 ) { CoherentGdcmFileList.push_back( *it3 ); @@ -332,7 +325,6 @@ bool SerieHeader::ImageNumberOrdering() /** - * \ingroup Header * \brief sorts the images, according to their File Name * @return false only if the header is bugged ! */