Program: gdcm
Module: $RCSfile: gdcmSerieHeader.cxx,v $
Language: C++
- Date: $Date: 2005/01/11 00:21:48 $
- Version: $Revision: 1.5 $
+ Date: $Date: 2005/01/18 11:56:52 $
+ Version: $Revision: 1.11 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmSerieHeader.h"
#include "gdcmDirList.h"
#include "gdcmHeader.h"
+#include "gdcmDebug.h"
#include <math.h>
#include <algorithm>
SerieHeader::SerieHeader()
{
CoherentGdcmFileList.clear();
+ // Later will contain: 0020 000e UI REL Series Instance UID
+ CurrentSerieUID = "";
}
SerieHeader::~SerieHeader()
*/
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;
+ }
}
/**
*/
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 );
}
}
//-----------------------------------------------------------------------------
// Private
/**
- * \ingroup Header
* \brief sorts the images, according to their Patient Position
* We may order, considering :
* -# Image Number
//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;
if( dist == 0 )
{
- delete[] cosines;
return false;
}
if( dist == 0 )
{
- delete[] cosines;
return false;
}
//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
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 !
*/
/**
- * \ingroup Header
* \brief sorts the images, according to their File Name
* @return false only if the header is bugged !
*/