]> Creatis software - gdcm.git/blobdiff - src/gdcmSerieHelper.cxx
UserDefinedFileIdentifier is now more human readable
[gdcm.git] / src / gdcmSerieHelper.cxx
index 0be2e44aa43c79f6b7bf9c4745b38ebc2f4e086e..1ea94c9f496dac94ec900eaa562131abda8870b5 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSerieHelper.cxx,v $
   Language:  C++
-  Date:      $Date: 2007/06/04 08:51:24 $
-  Version:   $Revision: 1.56 $
+  Date:      $Date: 2007/09/20 12:44:16 $
+  Version:   $Revision: 1.60 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -43,6 +43,7 @@ SerieHelper::SerieHelper()
    ClearAll();
    UserLessThanFunction = 0;
    DirectOrder = true;
+   
 }
 
 /**
@@ -235,15 +236,14 @@ void SerieHelper::AddRestriction(uint16_t group, uint16_t elem,
 
 /**
  * \brief add an extra  'SerieDetail' for building a 'Serie Identifier'
- *        that ensures (hope so) File constistency (Series Instance UID doesn't.
+ *        that ensures (hope so) File consistency (Series Instance UID doesn't)
  * @param   group tag group number we want restrict on a given value
  * @param   elem  tag element number we want restrict on a given value
  * @param  convert wether we want 'convertion', to allow further ordering
  *         e.g : 100 would be *before* 20; 000020.00 vs 00100.00 : OK 
  */
 void SerieHelper::AddSeriesDetail(uint16_t group, uint16_t elem, bool convert)
-{
-   
+{   
    ExDetail d;
    d.group   = group;
    d.elem    = elem;
@@ -267,6 +267,22 @@ void SerieHelper::SetDirectory(std::string const &dir, bool recursive)
    }
 }
 
+/**
+ * \brief Sets the DicomDirSerie
+ * @param   se DicomDirSerie to deal with
+ */
+void SerieHelper::SetDicomDirSerie(DicomDirSerie *se)
+{
+   DirList dirList(se);
+  
+   DirListType filenames_list = dirList.GetFilenames();
+   for( DirListType::const_iterator it = filenames_list.begin(); 
+        it != filenames_list.end(); ++it)
+   {
+      AddFileName( *it );
+   }
+}
+
 /**
  * \brief Sorts the given Fileset
  * \warning This could be implemented in a 'Strategy Pattern' approach
@@ -439,7 +455,7 @@ XCoherentFileSetmap SerieHelper::SplitOnOrientation(FileList *fileSet)
    std::ostringstream ossOrient;
 
    FileList::const_iterator it = fileSet->begin();
-   it ++;
+   //it ++;
    for ( ;
          it != fileSet->end();
        ++it)
@@ -489,7 +505,7 @@ XCoherentFileSetmap SerieHelper::SplitOnPosition(FileList *fileSet)
    std::ostringstream ossPosition;
    std::string strPosition; // re computed
    FileList::const_iterator it = fileSet->begin();
-   it ++;
+   //it ++;
    for ( ;
          it != fileSet->end();
        ++it)
@@ -565,7 +581,7 @@ XCoherentFileSetmap SerieHelper::SplitOnTagValue(FileList *fileSet,
    std::string strTagValue;  // read on disc
 
    FileList::const_iterator it = fileSet->begin();
-   it ++;
+   //it ++;
    for ( ;
          it != fileSet->end();
        ++it)
@@ -721,7 +737,8 @@ bool SerieHelper::ImagePositionPatientOrdering( FileList *fileList )
    }
    if (!ok)
    {
-      return false;
+      if (! DropDuplicatePositions)
+         return false;
    }
 
 // Now, we could calculate Z Spacing as the difference
@@ -748,6 +765,12 @@ bool SerieHelper::ImagePositionPatientOrdering( FileList *fileList )
            ++it3)
       {
          fileList->push_back( (*it3).second );
+         if (DropDuplicatePositions)
+         {
+            it3 =  distmultimap.upper_bound((*it3).first); // skip all duplicates
+            if (it3 == distmultimap.end() )  // if last image, stop iterate
+               break;
+         }
       }
    }
    else // user asked for reverse order
@@ -758,6 +781,12 @@ bool SerieHelper::ImagePositionPatientOrdering( FileList *fileList )
       {
          it4--;
          fileList->push_back( (*it4).second );
+         if (DropDuplicatePositions)  // skip all duplicates
+         {
+           it4 =  distmultimap.upper_bound((*it4).first);
+           if (it4 == distmultimap.begin() ) // if first image, stop iterate
+               break;
+         } 
       } while (it4 != distmultimap.begin() );
    }
 
@@ -923,7 +952,7 @@ void SerieHelper::CreateDefaultUniqueSeriesIdentifier()
  *         then additional identifying information is used.
  *  We allow user to add his own critierions, using AddSeriesDetail
  *        (he knows more than we do about his images!)
- *        ex : in tagging series, the only pertnent tag is
+ *        ex : in tagging series, the only pertinent tag is
  *        0018|1312 [In-plane Phase Encoding Direction] value : ROW/COLUMN
  * @param inFile GDCM_NAME_SPACE::File we want to build a Serie Identifier for.
  * @return the SeriesIdentifier
@@ -985,7 +1014,7 @@ std::string SerieHelper::CreateUniqueSeriesIdentifier( File *inFile )
  *       -File class? FileHelper class?-
  * @return FileIdentifier (Tokenizable on '%%%'. Hope it's enough !)
  */
-std::string SerieHelper::CreateUserDefinedFileIdentifier( File * inFile )
+std::string SerieHelper::CreateUserDefinedFileIdentifier( File *inFile )
 {
   //     Deal with all user supplied tags.
   //      (user knows more than we do about his images!)
@@ -1020,19 +1049,22 @@ std::string SerieHelper::CreateUserDefinedFileIdentifier( File * inFile )
       for(unsigned int i=0; i<s.size(); i++)
       {
          while(i<s.size()
-               && !( s[i] == '.' || s[i] == '%'
+               && !( s[i] == '.' || s[i] == '%' || s[i] == '_'
+                 || (s[i] >= '+' && s[i] <= '-')       
                  || (s[i] >= 'a' && s[i] <= 'z')
                  || (s[i] >= '0' && s[i] <= '9')
                  || (s[i] >= 'A' && s[i] <= 'Z')))
          {
-            s.erase(i, 1);
+            //s.erase(i, 1);
+            s.replace(i, 1, "_");  // ImagePositionPatient related stuff will be more human readable
          }
       }
       
       id += s.c_str();
       id += "%%%"; // make the FileIdentifier Tokenizable
    }
-   
+   id += inFile->GetFileName();
+   id += "%%%"; 
    return id;             
 }