Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

gdcm::SerieHelper Class Reference

More...

#include <gdcmSerieHelper.h>

Inheritance diagram for gdcm::SerieHelper:

Inheritance graph
[legend]
Collaboration diagram for gdcm::SerieHelper:

Collaboration graph
[legend]
List of all members.

Public Types

typedef std::map< std::string,
FileList * > 
SingleSerieUIDFileSetmap
typedef std::vector< File * > FileVector

Public Member Functions

virtual ~SerieHelper ()
 Canonical destructor.
void Print (std::ostream &os=std::cout, std::string const &indent="")
 Canonical printer.
void AddFileName (std::string const &filename)
 add a gdcm::File to the Fileset corresponding to its Serie UID
void AddGdcmFile (File *header)
 add a gdcm::File to the first (and supposed to be unique) file set of the gdcm::SerieHelper.
void SetDirectory (std::string const &dir, bool recursive=false)
 Sets the root Directory.
bool IsCoherent (FileList *fileSet)
 Elementary coherence checking of the files with the same Serie UID Only sizes and pixel type are checked right now ...
void OrderFileList (FileList *fileSet)
 Sorts the given Fileset.
const FileListGetFileList ()
 Gets the FIRST Single SerieUID Fileset. Deprecated; kept not to break the API.
 GDCM_LEGACY (FileList *GetFirstCoherentFileList())
 GDCM_LEGACY (FileList *GetNextCoherentFileList())
 GDCM_LEGACY (FileList *GetCoherentFileList(std::string serieUID))
FileListGetFirstSingleSerieUIDFileSet ()
 Get the first Fileset while visiting the SingleSerieUIDFileSetmap.
FileListGetNextSingleSerieUIDFileSet ()
 Get the next Fileset while visiting the SingleSerieUIDFileSetmap.
FileListGetSingleSerieUIDFileSet (std::string serieUID)
 Get the SingleSerieUIDFileSet according to its Serie UID.
std::string GetCurrentSerieUIDFileSetUID ()
 brief returns the 'Series Instance UID' Single SerieUID FileSet
 GDCM_LEGACY (void AddRestriction(TagKey const &key, std::string const &value))
void AddRestriction (TagKey const &key, std::string const &value, int op)
 add a rules for restricting a DICOM file to be in the serie we are trying to find. For example you can select only the DICOM file from a directory which would have a particular EchoTime==4.0. This method is a user level, value is not required to be formatted as a DICOM string
void SetLoadMode (int mode)
 Sets the LoadMode as a boolean string. LD_NOSEQ, LD_NOSHADOW, LD_NOSHADOWSEQ ... (nothing more, right now) WARNING : before using LD_NOSHADOW, be sure *all* your files contain accurate values in the 0x0000 element (if any) of *each* Shadow Group. The parser will fail if the size is wrong !
void SetSortOrderToDirect ()
 Brief User wants the files to be sorted Direct Order (default value).
void SetSortOrderToReverse ()
 Brief User wants the files to be sorted Reverse Order.
void SetUserLessThanFunction (BOOL_FUNCTION_PFILE_PFILE_POINTER userFunc)
 to allow user to give is own comparison function
XCoherentFileSetmap SplitOnOrientation (FileList *fileSet)
 Splits a Single SerieUID Fileset according to the Orientations.
XCoherentFileSetmap SplitOnPosition (FileList *fileSet)
 Splits a 'Single SerieUID' Fileset according to the Positions.
XCoherentFileSetmap SplitOnTagValue (FileList *fileSet, uint16_t group, uint16_t elem)
 Splits a 'Single SerieUID' File set Coherent according to the value of a given Tag.
void Delete ()
 Delete the object.
void Register ()
 Register the object.
void Unregister ()
 Unregister the object.
const unsigned long & GetRefCount () const
 Get the reference counting.
void SetPrintLevel (int level)
 Sets the print level for the Dicom Header Elements.
int GetPrintLevel ()
 Gets the print level for the Dicom Entries.

Static Public Member Functions

static SerieHelperNew ()

Protected Member Functions

 SerieHelper ()
 Constructor from a given SerieHelper.

Protected Attributes

int PrintLevel
 Amount of printed details for each Dicom Entries : 0 : stands for the least detail level.

Private Types

typedef std::pair< TagKey,
std::string > 
Rule
typedef std::vector< RuleSerieRestrictions
typedef std::vector< ExRuleSerieExRestrictions

Private Member Functions

 gdcmTypeMacro (SerieHelper)
void ClearAll ()
 Preventively, clear everything at constructor time. ( use it at destructor time.).
bool UserOrdering (FileList *fileSet)
 sorts the images, according to user supplied function
bool ImagePositionPatientOrdering (FileList *fileSet)
 sorts the images, according to their Patient Position We may order, considering :
  1. Image Position Patient
  2. Image Number
  3. File Name
  4. More to come :-)

bool ImageNumberOrdering (FileList *fileSet)
 sorts the images, according to their Image Number
bool FileNameOrdering (FileList *fileSet)
 sorts the images, according to their File Name

Static Private Member Functions

static bool ImageNumberLessThan (File *file1, File *file2)
static bool ImageNumberGreaterThan (File *file1, File *file2)
static bool FileNameLessThan (File *file1, File *file2)
static bool FileNameGreaterThan (File *file1, File *file2)

Private Attributes

SingleSerieUIDFileSetmap SingleSerieUIDFileSetHT
SingleSerieUIDFileSetmap::iterator ItFileSetHt
SerieRestrictions Restrictions
SerieExRestrictions ExRestrictions
int LoadMode
 Bit string integer (each one considered as a boolean) Bit 0 : Skip Sequences, if possible Bit 1 : Skip Shadow Groups if possible Probabely, some more to add.
bool DirectOrder
 whether we want to sort in direct order or not (reverse order). To be used by aware user only
BOOL_FUNCTION_PFILE_PFILE_POINTER UserLessThanFunction
 If user knows more about his images than gdcm does, he may supply his own comparison function.

Classes

struct  ExRule

Detailed Description

Definition at line 59 of file gdcmSerieHelper.h.


Member Typedef Documentation

typedef std::vector<File* > gdcm::SerieHelper::FileVector
 

Definition at line 69 of file gdcmSerieHelper.h.

typedef std::pair<TagKey, std::string> gdcm::SerieHelper::Rule [private]
 

Definition at line 151 of file gdcmSerieHelper.h.

typedef std::vector<ExRule> gdcm::SerieHelper::SerieExRestrictions [private]
 

Definition at line 162 of file gdcmSerieHelper.h.

typedef std::vector<Rule> gdcm::SerieHelper::SerieRestrictions [private]
 

Definition at line 152 of file gdcmSerieHelper.h.

typedef std::map<std::string, FileList *> gdcm::SerieHelper::SingleSerieUIDFileSetmap
 

SingleSerieUIDFileSetmap replaces the former CoherentFileListmap ( List were actually std::vectors, and wher no coherent at all : They were only Single SeriesInstanceUID File sets)

Definition at line 67 of file gdcmSerieHelper.h.


Constructor & Destructor Documentation

gdcm::SerieHelper::~SerieHelper  )  [virtual]
 

Canonical destructor.

Definition at line 51 of file gdcmSerieHelper.cxx.

References ClearAll().

00052 {
00053    ClearAll();
00054 }

gdcm::SerieHelper::SerieHelper  )  [protected]
 

Constructor from a given SerieHelper.

Definition at line 41 of file gdcmSerieHelper.cxx.

References ClearAll(), DirectOrder, and UserLessThanFunction.

00042 {
00043    ClearAll();
00044    UserLessThanFunction = 0;
00045    DirectOrder = true;
00046 }


Member Function Documentation

void gdcm::SerieHelper::AddFileName std::string const &  filename  ) 
 

add a gdcm::File to the Fileset corresponding to its Serie UID

Todo:
should return bool or throw error ?

Definition at line 88 of file gdcmSerieHelper.cxx.

References gdcm::Util::CompareDicomString(), gdcm::RefCounter::Delete(), gdcm::SerieHelper::ExRule::elem, ExRestrictions, gdcmDebugMacro, gdcmWarningMacro, gdcm::DocEntrySet::GetEntryString(), gdcm::SerieHelper::ExRule::group, gdcm::File::IsReadable(), gdcm::File::Load(), LoadMode, gdcm::File::New(), gdcm::SerieHelper::ExRule::op, gdcm::Document::SetFileName(), gdcm::Document::SetLoadMode(), SingleSerieUIDFileSetHT, and gdcm::SerieHelper::ExRule::value.

Referenced by SetDirectory().

00089 {
00090    // Create a DICOM file
00091    File *header = File::New();
00092    header->SetLoadMode(LoadMode);
00093    header->SetFileName( filename ); 
00094    header->Load();
00095 
00096    if ( header->IsReadable() )
00097    {
00098       int allrules = 1;
00099       // First step : the user defined a set of rules for the DICOM file
00100       // he is looking for.
00101       // Make sure the file corresponds to his set of rules:
00102 
00103       std::string s;
00104       for(SerieExRestrictions::iterator it2 = ExRestrictions.begin();
00105           it2 != ExRestrictions.end();
00106           ++it2)
00107       {
00108          const ExRule &r = *it2;
00109          s = header->GetEntryString( r.group, r.elem );
00110          if ( !Util::CompareDicomString(s, r.value.c_str(), r.op) )
00111          {
00112            // Argh ! This rule is unmatched; let's just quit
00113 
00114            allrules = 0;
00115            break;
00116          }
00117       }
00118 
00119       if ( allrules ) // all rules are respected:
00120       {
00121          // Allright! we have a found a DICOM that matches the user expectation. 
00122          // Let's add it!
00123 
00124          // 0020 000e UI REL Series Instance UID
00125          const std::string &uid = header->GetEntryString(0x0020, 0x000e);
00126          // if uid == GDCM_UNFOUND then consistently we should find GDCM_UNFOUND
00127          // no need here to do anything special
00128 
00129 
00130          if ( SingleSerieUIDFileSetHT.count(uid) == 0 )
00131          {
00132             gdcmDebugMacro(" New Serie UID :[" << uid << "]");
00133             // create a std::list in 'uid' position
00134             SingleSerieUIDFileSetHT[uid] = new FileList;
00135          }
00136          // Current Serie UID and DICOM header seems to match; add the file:
00137          SingleSerieUIDFileSetHT[uid]->push_back( header );
00138       }
00139       else
00140       {
00141          // at least one rule was unmatched we need to deallocate the file:
00142          header->Delete();
00143       }
00144    }
00145    else
00146    {
00147       gdcmWarningMacro("Could not read file: " << filename );
00148       header->Delete();
00149    }
00150 }

void gdcm::SerieHelper::AddGdcmFile File header  ) 
 

add a gdcm::File to the first (and supposed to be unique) file set of the gdcm::SerieHelper.

Warning:
: this method should be used by aware users only! Passing a gdcm::File* has the same effect than passing a file name!
Todo:
: decide which one is wrong (the method, or the commentary)! the following comment doesn't match the method :-( User is supposed to know the files he want to deal with and consider them they belong to the same Serie (even if their Serie UID is different) user will probabely OrderFileList() this list (actually, ordering user choosen gdm::File is the sole interest of this method) Moreover, using vtkGdcmReader::SetCoherentFileList() will avoid vtkGdcmReader parsing twice the same files. *no* coherence check is performed, but those specified by SerieHelper::AddRestriction()
Parameters:
header gdcm::File* of the file to deal with

Definition at line 170 of file gdcmSerieHelper.cxx.

References gdcm::Util::DicomStringEqual(), gdcmDebugMacro, Restrictions, and SingleSerieUIDFileSetHT.

00171 {
00172       int allrules = 1;
00173       // First step the user has defined a set of rules for the DICOM 
00174       // he is looking for.
00175       // make sure the file correspond to his set of rules:
00176       for(SerieRestrictions::iterator it =  Restrictions.begin();
00177                                       it != Restrictions.end();
00178                                     ++it)
00179       {
00180          const Rule &r = *it;
00181          const std::string s;// = header->GetEntryValue( r.first );
00182          if ( !Util::DicomStringEqual(s, r.second.c_str()) )
00183          {
00184            // Argh ! This rule is unmatch let's just quit
00185            allrules = 0;
00186            break;
00187          }
00188       }
00189       if ( allrules ) // all rules are respected:
00190       {
00191          // Allright ! we have a found a DICOM that match the user expectation. 
00192          // Let's add it !
00193 
00194          const std::string &uid = "0";
00195          // Serie UID of the gdcm::File* may be different.
00196          // User is supposed to know what he wants
00197 
00198          if ( SingleSerieUIDFileSetHT.count(uid) == 0 )
00199          {
00200             gdcmDebugMacro(" New Serie UID :[" << uid << "]");
00201             // create a std::list in 'uid' position
00202             SingleSerieUIDFileSetHT[uid] = new FileList;
00203          }
00204          // Current Serie UID and DICOM header seems to match; add the file:
00205          SingleSerieUIDFileSetHT[uid]->push_back( header );
00206       }
00207          // Even if a rule was unmatch we don't deallocate the gdcm::File:
00208 }

void gdcm::SerieHelper::AddRestriction TagKey const &  key,
std::string const &  value,
int  op
 

add a rules for restricting a DICOM file to be in the serie we are trying to find. For example you can select only the DICOM file from a directory which would have a particular EchoTime==4.0. This method is a user level, value is not required to be formatted as a DICOM string

Parameters:
group Group number of the target tag.
elem Element number of the target tag.
value value to be checked to exclude File
op operator we want to use to check

Definition at line 221 of file gdcmSerieHelper.cxx.

References gdcm::SerieHelper::ExRule::elem, ExRestrictions, gdcm::SerieHelper::ExRule::group, gdcm::SerieHelper::ExRule::op, and gdcm::SerieHelper::ExRule::value.

00223 {
00224    ExRule r;
00225    r.group = key[0];
00226    r.elem  = key[1];
00227    r.value = value;
00228    r.op    = op;
00229    ExRestrictions.push_back( r ); 
00230 }

void gdcm::SerieHelper::ClearAll  )  [private]
 

Preventively, clear everything at constructor time. ( use it at destructor time.).

Definition at line 60 of file gdcmSerieHelper.cxx.

References GetFirstSingleSerieUIDFileSet(), and GetNextSingleSerieUIDFileSet().

Referenced by SerieHelper(), and ~SerieHelper().

00061 {
00062    // For all the 'Single SerieUID' Filesets that may already exist 
00063    FileList *l = GetFirstSingleSerieUIDFileSet();
00064    while (l)
00065    { 
00066       // For all the gdcm::File of a File set
00067       for (gdcm::FileList::iterator it  = l->begin();
00068                                     it != l->end(); 
00069                                   ++it)
00070       {
00071          (*it)->Delete(); // remove each entry
00072       }
00073       l->clear();
00074       delete l;     // remove the container
00075       l = GetNextSingleSerieUIDFileSet();
00076    }
00077 }

void gdcm::RefCounter::Delete  )  [inline, inherited]
 

Delete the object.

Remarks:
The object is deleted only if its reference counting is to zero

Definition at line 40 of file gdcmRefCounter.h.

Referenced by AddFileName(), gdcm::Document::Backtrack(), gdcm::FileHelper::CheckMandatoryElements(), gdcm::FileHelper::CheckMandatoryEntry(), gdcm::FileHelper::CopyMandatoryEntry(), gdcm::DicomDir::CreateDicomDirChainedList(), gdcm::File::DoTheLoadingJob(), gdcm::Dict::DoTheLoadingJob(), gdcm::DicomDirObject::FillObject(), gdcm::DocEntrySet::InsertEntryBinArea(), gdcm::DocEntrySet::InsertEntryString(), gdcm::DocEntrySet::InsertSeqEntry(), gdcm::DicomDir::NewMeta(), gdcm::DicomDirStudy::NewVisit(), gdcm::Document::ParseDES(), gdcm::Document::ParseSQ(), gdcm::Document::ReadNextDocEntry(), gdcm::DicomDir::SetElement(), gdcm::FileHelper::SetMandatoryEntry(), gdcm::FileHelper::SetWriteFileTypeToExplicitVR(), gdcm::FileHelper::SetWriteFileTypeToImplicitVR(), gdcm::FileHelper::SetWriteFileTypeToJPEG(), gdcm::FileHelper::SetWriteToLibido(), gdcm::FileHelper::SetWriteToNoLibido(), gdcm::FileHelper::SetWriteToRaw(), gdcm::FileHelper::SetWriteToRGB(), gdcm::DicomDir::~DicomDir(), and gdcm::Global::~Global().

00040 { Unregister(); }

bool gdcm::SerieHelper::FileNameGreaterThan File file1,
File file2
[static, private]
 

Definition at line 766 of file gdcmSerieHelper.cxx.

References gdcm::Document::GetFileName().

Referenced by FileNameOrdering().

00767 {
00768    return file1->GetFileName() > file2->GetFileName();
00769 }

bool gdcm::SerieHelper::FileNameLessThan File file1,
File file2
[static, private]
 

Definition at line 761 of file gdcmSerieHelper.cxx.

References gdcm::Document::GetFileName().

Referenced by FileNameOrdering().

00762 {
00763    return file1->GetFileName() < file2->GetFileName();
00764 }

bool gdcm::SerieHelper::FileNameOrdering FileList fileList  )  [private]
 

sorts the images, according to their File Name

Parameters:
fileList Coherent File list (same Serie UID) to sort
Returns:
false only if the header is bugged !

Definition at line 775 of file gdcmSerieHelper.cxx.

References DirectOrder, FileNameGreaterThan(), and FileNameLessThan().

Referenced by OrderFileList().

00776 {
00777    if (DirectOrder) 
00778       std::sort(fileList->begin(), fileList->end(), 
00779                                        SerieHelper::FileNameLessThan);
00780    else
00781       std::sort(fileList->begin(), fileList->end(), 
00782                                        SerieHelper::FileNameGreaterThan);
00783 
00784    return true;
00785 }

gdcm::SerieHelper::GDCM_LEGACY void   AddRestriction(TagKey const &key, std::string const &value)  ) 
 

All the following allow user to restrict DICOM file to be part of a particular serie

gdcm::SerieHelper::GDCM_LEGACY FileList GetCoherentFileList(std::string serieUID)  ) 
 

gdcm::SerieHelper::GDCM_LEGACY FileList GetNextCoherentFileList()  ) 
 

gdcm::SerieHelper::GDCM_LEGACY FileList GetFirstCoherentFileList()  ) 
 

gdcm::SerieHelper::gdcmTypeMacro SerieHelper   )  [private]
 

std::string gdcm::SerieHelper::GetCurrentSerieUIDFileSetUID  )  [inline]
 

brief returns the 'Series Instance UID' Single SerieUID FileSet

Definition at line 99 of file gdcmSerieHelper.h.

00100                              { return  (*ItFileSetHt).first; }

const FileList& gdcm::SerieHelper::GetFileList  )  [inline]
 

Gets the FIRST Single SerieUID Fileset. Deprecated; kept not to break the API.

Note:
Caller must call OrderFileList first
Returns:
the (first) Single SerieUID Fileset

Definition at line 88 of file gdcmSerieHelper.h.

00089                            { return *SingleSerieUIDFileSetHT.begin()->second; }

FileList * gdcm::SerieHelper::GetFirstSingleSerieUIDFileSet  ) 
 

Get the first Fileset while visiting the SingleSerieUIDFileSetmap.

Returns:
The first FileList (SingleSerieUIDFileSet) if found, otherwhise 0

Definition at line 356 of file gdcmSerieHelper.cxx.

References ItFileSetHt, and SingleSerieUIDFileSetHT.

Referenced by ClearAll().

00357 {
00358    ItFileSetHt = SingleSerieUIDFileSetHT.begin();
00359    if ( ItFileSetHt != SingleSerieUIDFileSetHT.end() )
00360       return ItFileSetHt->second;
00361    return NULL;
00362 }

FileList * gdcm::SerieHelper::GetNextSingleSerieUIDFileSet  ) 
 

Get the next Fileset while visiting the SingleSerieUIDFileSetmap.

Note:
: meaningfull only if GetNextSingleSerieUIDFileSet() already called
Returns:
The next FileList (SingleSerieUIDFileSet) if found, otherwhise 0

Definition at line 369 of file gdcmSerieHelper.cxx.

References gdcmAssertMacro, ItFileSetHt, and SingleSerieUIDFileSetHT.

Referenced by ClearAll().

00370 {
00371    gdcmAssertMacro (ItFileSetHt != SingleSerieUIDFileSetHT.end());
00372   
00373    ++ItFileSetHt;
00374    if ( ItFileSetHt != SingleSerieUIDFileSetHT.end() )
00375       return ItFileSetHt->second;
00376    return NULL;
00377 }

int gdcm::Base::GetPrintLevel  )  [inline, inherited]
 

Gets the print level for the Dicom Entries.

Definition at line 50 of file gdcmBase.h.

00050 { return PrintLevel; }

const unsigned long& gdcm::RefCounter::GetRefCount  )  const [inline, inherited]
 

Get the reference counting.

Returns:
Reference count

Definition at line 57 of file gdcmRefCounter.h.

00058    {
00059       return RefCount;
00060    }

FileList * gdcm::SerieHelper::GetSingleSerieUIDFileSet std::string  SerieUID  ) 
 

Get the SingleSerieUIDFileSet according to its Serie UID.

Parameters:
SerieUID SerieUID to retrieve
Returns:
pointer to the FileList (SingleSerieUIDFileSet) if found, otherwhise 0

Definition at line 384 of file gdcmSerieHelper.cxx.

References SingleSerieUIDFileSetHT.

00385 {
00386    if ( SingleSerieUIDFileSetHT.count(SerieUID) == 0 )
00387       return 0;     
00388    return SingleSerieUIDFileSetHT[SerieUID];
00389 }

bool gdcm::SerieHelper::ImageNumberGreaterThan File file1,
File file2
[static, private]
 

Definition at line 716 of file gdcmSerieHelper.cxx.

References gdcm::File::GetImageNumber().

Referenced by ImageNumberOrdering().

00717 {
00718   return file1->GetImageNumber() > file2->GetImageNumber();
00719 }

bool gdcm::SerieHelper::ImageNumberLessThan File file1,
File file2
[static, private]
 

Definition at line 711 of file gdcmSerieHelper.cxx.

References gdcm::File::GetImageNumber().

Referenced by ImageNumberOrdering().

00712 {
00713   return file1->GetImageNumber() < file2->GetImageNumber();
00714 }

bool gdcm::SerieHelper::ImageNumberOrdering FileList fileList  )  [private]
 

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)
Parameters:
fileList File set (same Serie UID) to sort
Returns:
false if non bona fide stuff encountered

Definition at line 729 of file gdcmSerieHelper.cxx.

References DirectOrder, gdcmWarningMacro, ImageNumberGreaterThan(), and ImageNumberLessThan().

Referenced by OrderFileList().

00730 {
00731    int min, max, pos;
00732    int n = fileList->size();
00733 
00734    FileList::const_iterator it = fileList->begin();
00735    min = max = (*it)->GetImageNumber();
00736 
00737    for (; it != fileList->end(); ++it, ++n)
00738    {
00739       pos = (*it)->GetImageNumber();
00740       min = (min < pos) ? min : pos;
00741       max = (max > pos) ? max : pos;
00742    }
00743 
00744    // Find out if image numbers are coherent (consecutive)
00745    if ( min == max || max == 0 || max >= (n+min) )
00746    {
00747       gdcmWarningMacro( " 'Image numbers' not coherent. "
00748                         << " No ImageNumberOrdering sort performed.");
00749       return false;
00750    }
00751    if (DirectOrder) 
00752       std::sort(fileList->begin(), fileList->end(), 
00753                                           SerieHelper::ImageNumberLessThan );
00754    else
00755       std::sort(fileList->begin(), fileList->end(),
00756                                           SerieHelper::ImageNumberGreaterThan );
00757 
00758    return true;
00759 }

bool gdcm::SerieHelper::ImagePositionPatientOrdering FileList fileList  )  [private]
 

sorts the images, according to their Patient Position We may order, considering :

  1. Image Position Patient
  2. Image Number
  3. File Name
  4. More to come :-)

Note:
: FileList = std::vector<File* >
Parameters:
fileList Coherent File list (same Serie UID) to sort
Returns:
false only if the header is bugged !
Todo:
rewrite this for loop.

Definition at line 576 of file gdcmSerieHelper.cxx.

References DirectOrder, and gdcmWarningMacro.

Referenced by OrderFileList().

00578 {
00579    //iop is calculated based on the file file
00580    float cosines[6];
00581    float normal[3];
00582    float ipp[3];
00583    float dist;
00584    float min = 0, max = 0;
00585    bool first = true;
00586    int n=0;
00587    std::vector<float> distlist;
00588 
00590    for ( FileList::const_iterator 
00591          it = fileList->begin();
00592          it != fileList->end(); ++it )
00593    {
00594       if ( first ) 
00595       {
00596          (*it)->GetImageOrientationPatient( cosines );
00597       
00598          // You only have to do this once for all slices in the volume. Next, 
00599          // for each slice, calculate the distance along the slice normal 
00600          // using the IPP ("Image Position Patient") tag.
00601          // ("dist" is initialized to zero before reading the first slice) :
00602          normal[0] = cosines[1]*cosines[5] - cosines[2]*cosines[4];
00603          normal[1] = cosines[2]*cosines[3] - cosines[0]*cosines[5];
00604          normal[2] = cosines[0]*cosines[4] - cosines[1]*cosines[3];
00605   
00606          ipp[0] = (*it)->GetXOrigin();
00607          ipp[1] = (*it)->GetYOrigin();
00608          ipp[2] = (*it)->GetZOrigin();
00609 
00610          dist = 0;
00611          for ( int i = 0; i < 3; ++i )
00612          {
00613             dist += normal[i]*ipp[i];
00614          }
00615     
00616          distlist.push_back( dist );
00617 
00618          max = min = dist;
00619          first = false;
00620       }
00621       else 
00622       {
00623          ipp[0] = (*it)->GetXOrigin();
00624          ipp[1] = (*it)->GetYOrigin();
00625          ipp[2] = (*it)->GetZOrigin();
00626   
00627          dist = 0;
00628          for ( int i = 0; i < 3; ++i )
00629          {
00630             dist += normal[i]*ipp[i];
00631          }
00632 
00633          distlist.push_back( dist );
00634 
00635          min = (min < dist) ? min : dist;
00636          max = (max > dist) ? max : dist;
00637       }
00638       ++n;
00639    }
00640 
00641    // Then I order the slices according to the value "dist". Finally, once
00642    // I've read in all the slices, I calculate the z-spacing as the difference
00643    // between the "dist" values for the first two slices.
00644    FileVector CoherentFileVector(n);
00645    // CoherentFileVector.reserve( n );
00646    CoherentFileVector.resize( n );
00647    // gdcmAssertMacro( CoherentFileVector.capacity() >= n );
00648 
00649    // Find out if min/max are coherent
00650    if ( min == max )
00651    {
00652      gdcmWarningMacro("Looks like all images have the exact same image position"
00653                       << ". No PositionPatientOrdering sort performed" );
00654      return false;
00655    }
00656 
00657    float step = (max - min)/(n - 1);
00658    int pos;
00659    n = 0;
00660     
00661    //VC++ don't understand what scope is !! it -> it2
00662    for (FileList::const_iterator it2  = fileList->begin();
00663         it2 != fileList->end(); ++it2, ++n)
00664    {
00665       //2*n sort algo !!
00666       //Assumption: all files are present (no one missing)
00667       pos = (int)( fabs( (distlist[n]-min)/step) + .5 );
00668 
00669       // a Dicom 'Serie' may contain scout views
00670       // and images may have differents directions
00671       // -> More than one may have the same 'pos'
00672       // Sorting has then NO meaning !
00673       if (CoherentFileVector[pos]==NULL)
00674          CoherentFileVector[pos] = *it2;
00675       else
00676       {
00677          gdcmWarningMacro( "At least 2 files with same position."
00678                         << " No PositionPatientOrdering sort performed");
00679          return false;
00680       }
00681    }
00682 
00683    fileList->clear();  // doesn't delete list elements, only nodes
00684 
00685    if (DirectOrder)
00686    {  
00687       //VC++ don't understand what scope is !! it -> it3
00688       for (FileVector::const_iterator it3  = CoherentFileVector.begin();
00689            it3 != CoherentFileVector.end(); ++it3)
00690       {
00691          fileList->push_back( *it3 );
00692       }
00693    }
00694    else // user asked for reverse order
00695    {
00696       FileVector::const_iterator it4;
00697       it4 = CoherentFileVector.end();
00698       do
00699       {
00700          it4--;
00701          fileList->push_back( *it4 );
00702       } while (it4 != CoherentFileVector.begin() );
00703    } 
00704 
00705    distlist.clear();
00706    CoherentFileVector.clear();
00707 
00708    return true;
00709 }

bool gdcm::SerieHelper::IsCoherent FileList fileSet  ) 
 

Elementary coherence checking of the files with the same Serie UID Only sizes and pixel type are checked right now ...

Definition at line 292 of file gdcmSerieHelper.cxx.

00293 {
00294    if(fileSet->size() == 1)
00295    return true;
00296 
00297    FileList::const_iterator it = fileSet->begin();
00298 
00299    int nX =               (*it)->GetXSize();
00300    int nY =               (*it)->GetYSize();
00301    int pixelSize =        (*it)->GetPixelSize();
00302    bool signedPixelData = (*it)->IsSignedPixelData();
00303    it ++;
00304    for ( ;
00305          it != fileSet->end();
00306        ++it)
00307    {
00308       if ( (*it)->GetXSize() != nX )
00309          return false;
00310       if ( (*it)->GetYSize() != nY )
00311          return false;
00312       if ( (*it)->GetPixelSize() != pixelSize )
00313          return false;
00314       if ( (*it)->IsSignedPixelData() != signedPixelData )
00315          return false;
00316       // probabely more is to be checked (?)      
00317    }
00318    return true;
00319 }

static SerieHelper* gdcm::SerieHelper::New  )  [inline, static]
 

Definition at line 71 of file gdcmSerieHelper.h.

00071 {return new SerieHelper();}

void gdcm::SerieHelper::OrderFileList FileList fileSet  ) 
 

Sorts the given Fileset.

Warning:
This could be implemented in a 'Strategy Pattern' approach But as I don't know how to do it, I leave it this way BTW, this is also a Strategy, I don't know this is the best approach :)

Definition at line 266 of file gdcmSerieHelper.cxx.

References FileNameOrdering(), ImageNumberOrdering(), ImagePositionPatientOrdering(), UserLessThanFunction, and UserOrdering().

00267 {
00268 
00269    if ( SerieHelper::UserLessThanFunction )
00270    {
00271       UserOrdering( fileSet );
00272       return; 
00273    }
00274    else if ( ImagePositionPatientOrdering( fileSet ) )
00275    {
00276       return ;
00277    }
00278    else if ( ImageNumberOrdering(fileSet ) )
00279    {
00280       return ;
00281    }
00282    else  
00283    {
00284       FileNameOrdering(fileSet );
00285    }
00286 }

void gdcm::SerieHelper::Print std::ostream &  os = std::cout,
std::string const &  indent = ""
[virtual]
 

Canonical printer.

Reimplemented from gdcm::Base.

Definition at line 808 of file gdcmSerieHelper.cxx.

References gdcmWarningMacro, and SingleSerieUIDFileSetHT.

00809 {
00810    // For all the Coherent File lists of the gdcm::Serie
00811    SingleSerieUIDFileSetmap::iterator itl = SingleSerieUIDFileSetHT.begin();
00812    if ( itl == SingleSerieUIDFileSetHT.end() )
00813    {
00814       gdcmWarningMacro( "No SingleSerieUID File set found" );
00815       return;
00816    }
00817    while (itl != SingleSerieUIDFileSetHT.end())
00818    { 
00819       os << "Serie UID :[" << itl->first << "]" << std::endl;
00820 
00821       // For all the files of a SingleSerieUID File set
00822       for (FileList::iterator it =  (itl->second)->begin();
00823                                   it != (itl->second)->end(); 
00824                                 ++it)
00825       {
00826          os << indent << " --- " << (*it)->GetFileName() << std::endl;
00827       }
00828       ++itl;
00829    }
00830 }

void gdcm::RefCounter::Register  )  [inline, inherited]
 

Register the object.

Remarks:
It increments the reference counting

Definition at line 45 of file gdcmRefCounter.h.

Referenced by gdcm::SQItem::AddEntry(), gdcm::ElementSet::AddEntry(), gdcm::Dict::AddEntry(), gdcm::SeqEntry::AddSQItem(), gdcm::DocEntry::DocEntry(), gdcm::FileHelper::FileHelper(), gdcm::DocEntrySet::GetDictEntry(), gdcm::DocEntryArchive::Push(), gdcm::Dict::ReplaceEntry(), and gdcm::SeqEntry::SetDelimitationItem().

00045 { RefCount++; }

void gdcm::SerieHelper::SetDirectory std::string const &  dir,
bool  recursive = false
 

Sets the root Directory.

Parameters:
dir Name of the directory to deal with
recursive whether we want explore recursively the root Directory

Definition at line 247 of file gdcmSerieHelper.cxx.

References AddFileName(), and gdcm::DirList::GetFilenames().

00248 {
00249    DirList dirList(dir, recursive); // OS specific
00250   
00251    DirListType filenames_list = dirList.GetFilenames();
00252    for( DirListType::const_iterator it = filenames_list.begin(); 
00253         it != filenames_list.end(); ++it)
00254    {
00255       AddFileName( *it );
00256    }
00257 }

void gdcm::SerieHelper::SetLoadMode int  mode  )  [inline]
 

Sets the LoadMode as a boolean string. LD_NOSEQ, LD_NOSHADOW, LD_NOSHADOWSEQ ... (nothing more, right now) WARNING : before using LD_NOSHADOW, be sure *all* your files contain accurate values in the 0x0000 element (if any) of *each* Shadow Group. The parser will fail if the size is wrong !

Parameters:
mode Load mode to be used

Definition at line 115 of file gdcmSerieHelper.h.

00115 { LoadMode = mode; }

void gdcm::Base::SetPrintLevel int  level  )  [inline, inherited]
 

Sets the print level for the Dicom Header Elements.

Note:
0 for Light Print; 1 for 'medium' Print, 2 for Heavy Print

Definition at line 47 of file gdcmBase.h.

Referenced by gdcm::SQItem::Print(), gdcm::SeqEntry::Print(), gdcm::FileHelper::Print(), gdcm::ElementSet::Print(), and gdcm::DicomDir::Print().

00047 { PrintLevel = level; }

void gdcm::SerieHelper::SetSortOrderToDirect  )  [inline]
 

Brief User wants the files to be sorted Direct Order (default value).

Definition at line 118 of file gdcmSerieHelper.h.

00118 { DirectOrder = true;  }

void gdcm::SerieHelper::SetSortOrderToReverse  )  [inline]
 

Brief User wants the files to be sorted Reverse Order.

Definition at line 121 of file gdcmSerieHelper.h.

00121 { DirectOrder = false; }

void gdcm::SerieHelper::SetUserLessThanFunction BOOL_FUNCTION_PFILE_PFILE_POINTER  userFunc  )  [inline]
 

to allow user to give is own comparison function

Definition at line 124 of file gdcmSerieHelper.h.

00125                         { UserLessThanFunction = userFunc; }  

XCoherentFileSetmap gdcm::SerieHelper::SplitOnOrientation FileList fileSet  ) 
 

Splits a Single SerieUID Fileset according to the Orientations.

Parameters:
fileSet File Set to be splitted
Returns:
std::map of 'Xcoherent' File sets

Definition at line 397 of file gdcmSerieHelper.cxx.

References gdcmDebugMacro.

00398 {
00399    XCoherentFileSetmap CoherentFileSet;
00400 
00401    int nb = fileSet->size();
00402    if (nb == 0 )
00403       return CoherentFileSet;
00404    float iop[6];
00405 
00406    std::string strOrient;
00407    std::ostringstream ossOrient;   
00408    FileList::const_iterator it = fileSet->begin();
00409    it ++;
00410    for ( ;
00411          it != fileSet->end();
00412        ++it)
00413    {     
00414       // Information is in :      
00415       // 0020 0037 : Image Orientation (Patient) or
00416       // 0020 0035 : Image Orientation (RET)
00417 
00418       // Let's build again the 'cosines' string, to be sure of it's format      
00419       (*it)->GetImageOrientationPatient(iop);
00420 
00421       ossOrient << iop[0];      
00422       for (int i = 1; i < 6; i++)
00423       {
00424         ossOrient << "\\";
00425         ossOrient << iop[i]; 
00426       }      
00427       strOrient = ossOrient.str();
00428       ossOrient.str("");
00429       // FIXME : is it a 'cleaner' way to initialize an ostringstream? 
00430 
00431       if ( CoherentFileSet.count(strOrient) == 0 )
00432       {
00433          gdcmDebugMacro(" New Orientation :[" << strOrient << "]");
00434          // create a File set in 'orientation' position
00435          CoherentFileSet[strOrient] = new FileList;
00436       }
00437       // Current Orientation and DICOM header match; add the file:
00438       CoherentFileSet[strOrient]->push_back( (*it) );
00439    } 
00440    return CoherentFileSet;
00441 }

XCoherentFileSetmap gdcm::SerieHelper::SplitOnPosition FileList fileSet  ) 
 

Splits a 'Single SerieUID' Fileset according to the Positions.

Parameters:
fileSet File Set to be splitted
Returns:
std::map of 'Xcoherent' File sets

Definition at line 449 of file gdcmSerieHelper.cxx.

References gdcm::GDCM_UNFOUND, gdcmDebugMacro, and gdcmWarningMacro.

00450 {
00451    XCoherentFileSetmap CoherentFileSet;
00452 
00453    int nb = fileSet->size();
00454    if (nb == 0 )
00455       return CoherentFileSet;
00456    float pos[3];
00457    std::string strImPos;  // read on disc
00458    std::ostringstream ossPosition;
00459    std::string strPosition; // re computed
00460    FileList::const_iterator it = fileSet->begin();
00461    it ++;
00462    for ( ;
00463          it != fileSet->end();
00464        ++it)
00465    {     
00466       // Information is in :      
00467       // 0020,0032 : Image Position Patient
00468       // 0020,0030 : Image Position (RET)
00469 
00470       strImPos = (*it)->GetEntryString(0x0020,0x0032);
00471       if ( strImPos == GDCM_UNFOUND)
00472       {
00473          gdcmWarningMacro( "Unfound Image Position Patient (0020,0032)");
00474          strImPos = (*it)->GetEntryString(0x0020,0x0030); // For ACR-NEMA images
00475          if ( strImPos == GDCM_UNFOUND )
00476          {
00477             gdcmWarningMacro( "Unfound Image Position (RET) (0020,0030)");
00478             // User wants to split on the 'Position'
00479             // No 'Position' info found.
00480             // We return an empty Htable !
00481             return CoherentFileSet;
00482          }  
00483       }
00484 
00485       if ( sscanf( strImPos.c_str(), "%f \\%f \\%f ", 
00486                                               &pos[0], &pos[1], &pos[2]) != 3 )
00487       {
00488             gdcmWarningMacro( "Wrong number for Position : ["
00489                        << strImPos << "]" );
00490              return CoherentFileSet;
00491       }
00492 
00493       // Let's build again the 'position' string, to be sure of it's format      
00494 
00495       ossPosition << pos[0];      
00496       for (int i = 1; i < 3; i++)
00497       {
00498         ossPosition << "\\";
00499         ossPosition << pos[i]; 
00500       }      
00501       strPosition = ossPosition.str();
00502       ossPosition.str("");
00503             
00504       if ( CoherentFileSet.count(strPosition) == 0 )
00505       {
00506          gdcmDebugMacro(" New Position :[" << strPosition << "]");
00507          // create a File set in 'position' position
00508          CoherentFileSet[strPosition] = new FileList;
00509       }
00510       // Current Position and DICOM header match; add the file:
00511       CoherentFileSet[strPosition]->push_back( (*it) );
00512    }   
00513    return CoherentFileSet;
00514 }

XCoherentFileSetmap gdcm::SerieHelper::SplitOnTagValue FileList fileSet,
uint16_t  group,
uint16_t  elem
 

Splits a 'Single SerieUID' File set Coherent according to the value of a given Tag.

Parameters:
fileSet File Set to be splitted
group group number of the target Element
elem element number of the target Element
Returns:
std::map of 'Xcoherent' File sets

Definition at line 525 of file gdcmSerieHelper.cxx.

References gdcmDebugMacro.

00527 {
00528    XCoherentFileSetmap CoherentFileSet;
00529 
00530    int nb = fileSet->size();
00531    if (nb == 0 )
00532       return CoherentFileSet;
00533 
00534    std::string strTagValue;  // read on disc
00535 
00536    FileList::const_iterator it = fileSet->begin();
00537    it ++;
00538    for ( ;
00539          it != fileSet->end();
00540        ++it)
00541    {     
00542       // Information is in :      
00543       // 0020,0032 : Image Position Patient
00544       // 0020,0030 : Image Position (RET)
00545 
00546       strTagValue = (*it)->GetEntryString(group,elem);
00547       
00548       if ( CoherentFileSet.count(strTagValue) == 0 )
00549       {
00550          gdcmDebugMacro(" New Tag Value :[" << strTagValue << "]");
00551          // create a File set in 'position' position
00552          CoherentFileSet[strTagValue] = new FileList;
00553       }
00554       // Current Tag value and DICOM header match; add the file:
00555       CoherentFileSet[strTagValue]->push_back( (*it) );
00556    }
00557    return CoherentFileSet;
00558 }

void gdcm::RefCounter::Unregister  )  [inline, inherited]
 

Unregister the object.

Remarks:
It decrements the reference counting

Definition at line 49 of file gdcmRefCounter.h.

Referenced by gdcm::SeqEntry::ClearSQItem(), gdcm::DocEntrySet::GetDictEntry(), gdcm::DocEntrySet::NewDataEntry(), gdcm::DocEntrySet::NewSeqEntry(), gdcm::Document::ReadNextDocEntry(), gdcm::SQItem::RemoveEntry(), gdcm::ElementSet::RemoveEntry(), gdcm::SeqEntry::SetDelimitationItem(), gdcm::DocEntry::~DocEntry(), and gdcm::FileHelper::~FileHelper().

00050    {
00051       RefCount--;
00052       if(RefCount<=0)
00053          delete this;
00054    }

bool gdcm::SerieHelper::UserOrdering FileList fileList  )  [private]
 

sorts the images, according to user supplied function

Parameters:
fileList Coherent File list (same Serie UID) to sort
Returns:
false only if the header is bugged !

Definition at line 792 of file gdcmSerieHelper.cxx.

References DirectOrder, and UserLessThanFunction.

Referenced by OrderFileList().

00793 {
00794    std::sort(fileList->begin(), fileList->end(), 
00795                                     SerieHelper::UserLessThanFunction);
00796    if (!DirectOrder) 
00797    {
00798       std::reverse(fileList->begin(), fileList->end());
00799    }
00800    return true;
00801 }


Member Data Documentation

bool gdcm::SerieHelper::DirectOrder [private]
 

whether we want to sort in direct order or not (reverse order). To be used by aware user only

Definition at line 173 of file gdcmSerieHelper.h.

Referenced by FileNameOrdering(), ImageNumberOrdering(), ImagePositionPatientOrdering(), SerieHelper(), and UserOrdering().

SerieExRestrictions gdcm::SerieHelper::ExRestrictions [private]
 

Definition at line 163 of file gdcmSerieHelper.h.

Referenced by AddFileName(), and AddRestriction().

SingleSerieUIDFileSetmap::iterator gdcm::SerieHelper::ItFileSetHt [private]
 

Definition at line 149 of file gdcmSerieHelper.h.

Referenced by GetFirstSingleSerieUIDFileSet(), and GetNextSingleSerieUIDFileSet().

int gdcm::SerieHelper::LoadMode [private]
 

Bit string integer (each one considered as a boolean) Bit 0 : Skip Sequences, if possible Bit 1 : Skip Shadow Groups if possible Probabely, some more to add.

Definition at line 169 of file gdcmSerieHelper.h.

Referenced by AddFileName().

int gdcm::Base::PrintLevel [protected, inherited]
 

Amount of printed details for each Dicom Entries : 0 : stands for the least detail level.

Definition at line 55 of file gdcmBase.h.

Referenced by gdcm::SQItem::Print(), gdcm::SeqEntry::Print(), gdcm::FileHelper::Print(), gdcm::ElementSet::Print(), gdcm::DocEntry::Print(), gdcm::DictEntry::Print(), gdcm::DicomDirStudy::Print(), gdcm::DicomDirSerie::Print(), gdcm::DicomDirPatient::Print(), gdcm::DicomDirMeta::Print(), gdcm::DicomDir::Print(), and gdcm::DataEntry::Print().

SerieRestrictions gdcm::SerieHelper::Restrictions [private]
 

Definition at line 153 of file gdcmSerieHelper.h.

Referenced by AddGdcmFile().

SingleSerieUIDFileSetmap gdcm::SerieHelper::SingleSerieUIDFileSetHT [private]
 

Definition at line 148 of file gdcmSerieHelper.h.

Referenced by AddFileName(), AddGdcmFile(), GetFirstSingleSerieUIDFileSet(), GetNextSingleSerieUIDFileSet(), GetSingleSerieUIDFileSet(), and Print().

BOOL_FUNCTION_PFILE_PFILE_POINTER gdcm::SerieHelper::UserLessThanFunction [private]
 

If user knows more about his images than gdcm does, he may supply his own comparison function.

Definition at line 177 of file gdcmSerieHelper.h.

Referenced by OrderFileList(), SerieHelper(), and UserOrdering().


The documentation for this class was generated from the following files:
Generated on Fri Nov 18 15:58:47 2005 for gdcm by  doxygen 1.4.4