]> Creatis software - gdcm.git/blobdiff - src/gdcmSerieHelper.cxx
ENH: A user does not know (and should not) what we internally use for representing...
[gdcm.git] / src / gdcmSerieHelper.cxx
index 47b2b57c7543109f331b92cd5cf53caf7de92c4e..23e60112f8a1c034b658593be36d4c05d34d7194 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSerieHelper.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/21 08:49:36 $
-  Version:   $Revision: 1.26 $
+  Date:      $Date: 2005/11/08 16:31:21 $
+  Version:   $Revision: 1.34 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -54,8 +54,8 @@ SerieHelper::~SerieHelper()
 }
 
 /**
- * \brief  Preventively, clear everything at constructor time.
- *         - use it at destructor time.
+ * \brief  Preventively, clear everything at constructor time.
+ *         ( use it at destructor time.)
  */
 void SerieHelper::ClearAll()
 {
@@ -68,7 +68,7 @@ void SerieHelper::ClearAll()
                                     it != l->end(); 
                                   ++it)
       {
-         delete *it; // remove each entry
+         (*it)->Delete(); // remove each entry
       }
       l->clear();
       delete l;     // remove the container
@@ -88,7 +88,7 @@ void SerieHelper::ClearAll()
 void SerieHelper::AddFileName(std::string const &filename)
 {
    // Create a DICOM file
-   File *header = new File ();
+   File *header = File::New();
    header->SetLoadMode(LoadMode);
    header->SetFileName( filename ); 
    header->Load();
@@ -110,6 +110,7 @@ void SerieHelper::AddFileName(std::string const &filename)
          if ( !Util::CompareDicomString(s, r.value.c_str(), r.op) )
          {
            // Argh ! This rule is unmatched; let's just quit
+
            allrules = 0;
            break;
          }
@@ -125,6 +126,7 @@ void SerieHelper::AddFileName(std::string const &filename)
          // if uid == GDCM_UNFOUND then consistently we should find GDCM_UNFOUND
          // no need here to do anything special
 
+
          if ( SingleSerieUIDFileSetHT.count(uid) == 0 )
          {
             gdcmDebugMacro(" New Serie UID :[" << uid << "]");
@@ -137,13 +139,13 @@ void SerieHelper::AddFileName(std::string const &filename)
       else
       {
          // at least one rule was unmatched we need to deallocate the file:
-         delete header;
+         header->Delete();
       }
    }
    else
    {
       gdcmWarningMacro("Could not read file: " << filename );
-      delete header;
+      header->Delete();
    }
 }
 
@@ -216,30 +218,18 @@ void SerieHelper::AddGdcmFile(File *header)
  * @param value value to be checked to exclude File
  * @param op  operator we want to use to check
  */
-void SerieHelper::AddRestriction(uint16_t group, uint16_t elem
+void SerieHelper::AddRestriction(TagKey const &key
                                  std::string const &value, int op)
 {
    ExRule r;
-   r.group = group;
-   r.elem  = elem;
+   r.group = key[0];
+   r.elem  = key[1];
    r.value = value;
    r.op    = op;
    ExRestrictions.push_back( r ); 
 }
 
 #ifndef GDCM_LEGACY_REMOVE
-/**
- * \brief 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
- * @param   group  Group number of the target tag.
- * @param   elem Element number of the target tag.
- * @param value value to be checked to exclude File 
- * @deprecated use : AddRestriction(uint16_t group, uint16_t elem, 
- *                                 std::string const &value, int op);
- */
 void SerieHelper::AddRestriction(TagKey const &key, std::string const &value)
 {
    Rule r;
@@ -306,10 +296,10 @@ bool SerieHelper::IsCoherent(FileList *fileSet)
 
    FileList::const_iterator it = fileSet->begin();
 
-   int nX = (*it)->GetXSize();
-   int nY = (*it)->GetYSize();
-   int pixelSize = (*it)->GetPixelSize();
-
+   int nX =               (*it)->GetXSize();
+   int nY =               (*it)->GetYSize();
+   int pixelSize =        (*it)->GetPixelSize();
+   bool signedPixelData = (*it)->IsSignedPixelData();
    it ++;
    for ( ;
          it != fileSet->end();
@@ -321,17 +311,15 @@ bool SerieHelper::IsCoherent(FileList *fileSet)
          return false;
       if ( (*it)->GetPixelSize() != pixelSize )
          return false;
-      // probabely more is to be checked (?)
+      if ( (*it)->IsSignedPixelData() != signedPixelData )
+         return false;
+      // probabely more is to be checked (?)      
    }
    return true;
 }
 
 #ifndef GDCM_LEGACY_REMOVE
-/* *
- * \brief   accessor (DEPRECATED :  use GetFirstSingleSerieUIDFileSet )
- *          Warning : 'coherent' means here they have the same Serie UID
- * @return  The first FileList if found, otherwhise NULL
- */
+
 FileList *SerieHelper::GetFirstCoherentFileList()
 {
    ItFileSetHt = SingleSerieUIDFileSetHT.begin();
@@ -340,12 +328,7 @@ FileList *SerieHelper::GetFirstCoherentFileList()
    return NULL;
 }
 
-/* *
- * \brief   accessor (DEPRECATED :  use GetNextSingleSerieUIDFileSet )
- *          Warning : 'coherent' means here they have the same Serie UID
- * \note : meaningfull only if GetFirstCoherentFileList() already called 
- * @return  The next FileList if found, otherwhise NULL
- */
+
 FileList *SerieHelper::GetNextCoherentFileList()
 {
    gdcmAssertMacro (ItFileSetHt != SingleSerieUIDFileSetHT.end());
@@ -356,12 +339,7 @@ FileList *SerieHelper::GetNextCoherentFileList()
    return NULL;
 }
 
-/* *
- * \brief   accessor (DEPRECATED :  use GetSingleSerieUIDFileSet )
-  *          Warning : 'coherent' means here they have the same Serie UID
- * @param SerieUID SerieUID
- * \return  pointer to the FileList if found, otherwhise NULL
- */
+
 FileList *SerieHelper::GetCoherentFileList(std::string SerieUID)
 {
    if ( SingleSerieUIDFileSetHT.count(SerieUID) == 0 )
@@ -424,9 +402,9 @@ XCoherentFileSetmap SerieHelper::SplitOnOrientation(FileList *fileSet)
    if (nb == 0 )
       return CoherentFileSet;
    float iop[6];
-   std::ostringstream ossOrient;
+
    std::string strOrient;
-   
+   std::ostringstream ossOrient;   
    FileList::const_iterator it = fileSet->begin();
    it ++;
    for ( ;
@@ -439,6 +417,7 @@ XCoherentFileSetmap SerieHelper::SplitOnOrientation(FileList *fileSet)
 
       // Let's build again the 'cosines' string, to be sure of it's format      
       (*it)->GetImageOrientationPatient(iop);
+
       ossOrient << iop[0];      
       for (int i = 1; i < 6; i++)
       {
@@ -446,7 +425,9 @@ XCoherentFileSetmap SerieHelper::SplitOnOrientation(FileList *fileSet)
         ossOrient << iop[i]; 
       }      
       strOrient = ossOrient.str();
-      
+      ossOrient.str("");
+      // FIXME : is it a 'cleaner' way to initialize an ostringstream? 
+
       if ( CoherentFileSet.count(strOrient) == 0 )
       {
          gdcmDebugMacro(" New Orientation :[" << strOrient << "]");
@@ -455,12 +436,12 @@ XCoherentFileSetmap SerieHelper::SplitOnOrientation(FileList *fileSet)
       }
       // Current Orientation and DICOM header match; add the file:
       CoherentFileSet[strOrient]->push_back( (*it) );
-   }   
+   } 
    return CoherentFileSet;
 }
 
 /**
- * \brief   Splits a Single SerieUID Fileset according to the Positions
+ * \brief   Splits a 'Single SerieUID' Fileset according to the Positions
  * @param fileSet File Set to be splitted
  * \return  std::map of 'Xcoherent' File sets
  */
@@ -518,7 +499,8 @@ XCoherentFileSetmap SerieHelper::SplitOnPosition(FileList *fileSet)
         ossPosition << pos[i]; 
       }      
       strPosition = ossPosition.str();
-      
+      ossPosition.str("");
+            
       if ( CoherentFileSet.count(strPosition) == 0 )
       {
          gdcmDebugMacro(" New Position :[" << strPosition << "]");
@@ -532,7 +514,7 @@ XCoherentFileSetmap SerieHelper::SplitOnPosition(FileList *fileSet)
 }
 
 /**
- * \brief   Splits a SingleSerieUID File set Coherent according to the
+ * \brief   Splits a 'Single SerieUID' File set Coherent according to the
  *          value of a given Tag
  * @param fileSet File Set to be splitted
  * @param   group  group number of the target Element
@@ -585,8 +567,9 @@ XCoherentFileSetmap SerieHelper::SplitOnTagValue(FileList *fileSet,
  *  We may order, considering :
  *   -# Image Position Patient
  *   -# Image Number
+ *   -# File Name
  *   -# More to come :-)
- * WARNING : FileList = std::vector<File* >
+ * \note : FileList = std::vector<File* >
  * @param fileList Coherent File list (same Serie UID) to sort
  * @return false only if the header is bugged !
  */
@@ -740,7 +723,7 @@ bool SerieHelper::ImageNumberGreaterThan(File *file1, File *file2)
  * \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 fileList Coherent File list (same Serie UID) to sort 
+ * @param fileList  File set (same Serie UID) to sort 
  * @return false if non bona fide stuff encountered
  */
 bool SerieHelper::ImageNumberOrdering(FileList *fileList)