]> Creatis software - gdcm.git/commitdiff
ENH: Adding feature for user to refine the search of dicom file within a directory...
authormalaterre <malaterre>
Fri, 27 May 2005 21:19:03 +0000 (21:19 +0000)
committermalaterre <malaterre>
Fri, 27 May 2005 21:19:03 +0000 (21:19 +0000)
src/gdcmSerieHelper.cxx
src/gdcmSerieHelper.h

index 32389631c0f909288eb548e54af200d2eec937ac..1d85f6ace2edcf00e2131affec114accb354dff0 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSerieHelper.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/05/26 18:49:46 $
-  Version:   $Revision: 1.7 $
+  Date:      $Date: 2005/05/27 21:19:03 $
+  Version:   $Revision: 1.8 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -20,6 +20,7 @@
 #include "gdcmDirList.h"
 #include "gdcmFile.h"
 #include "gdcmDebug.h"
+#include "gdcmUtil.h"
 
 #include <math.h>
 #include <vector>
@@ -85,23 +86,50 @@ SerieHelper::~SerieHelper()
  */
 void SerieHelper::AddFileName(std::string const &filename)
 {
-   //directly use string and not const char*:
+   // Create a DICOM file
    File *header = new File( filename ); 
    if( header->IsReadable() )
    {
-      // 0020 000e UI REL Series Instance UID
-      std::string uid =  header->GetEntryValue (0x0020, 0x000e);
-      // if uid == GDCM_UNFOUND then consistently we should find GDCM_UNFOUND
-      // no need here to do anything special
+      int allrules = 1;
+      // First step the user has defined s set of rules for the DICOM he is looking for
+      // make sure the file correspond to his set of rules:
+      for(SerieRestrictions::iterator it = Restrictions.begin();
+          it != Restrictions.end();
+          ++it)
+      {
+         const Rule &r = *it;
+         const std::string s;// = header->GetEntryValue( r.first );
+         if( !Util::DicomStringEqual(s, r.second.c_str()))
+         {
+           // Argh ! This rule is unmatch let's just quit
+           allrules = 0;
+           break;
+         }
+      }
+      if( allrules ) // all rules are respected:
+      {
+         // Alright ! we have a found a DICOM that match the user expectation. 
+         // Let's add it !
+
+         // 0020 000e UI REL Series Instance UID
+         const std::string &uid = header->GetEntryValue (0x0020, 0x000e);
+         // if uid == GDCM_UNFOUND then consistently we should find GDCM_UNFOUND
+         // no need here to do anything special
 
-      if ( CoherentFileListHT.count(uid) == 0 )
+         if ( CoherentFileListHT.count(uid) == 0 )
+         {
+            gdcmDebugMacro(" New Serie UID :[" << uid << "]");
+            // create a std::list in 'uid' position
+            CoherentFileListHT[uid] = new FileList;
+         }
+         // Current Serie UID and DICOM header seems to match add the file:
+         CoherentFileListHT[uid]->push_back( header );
+      }
+      else
       {
-         gdcmWarningMacro(" New Serie UID :[" << uid << "]");
-         // create a std::list in 'uid' position
-         CoherentFileListHT[uid] = new FileList;
+         // at least one rule was unmatch we need to deallocate the file:
+         delete header;
       }
-      // Current Serie UID and DICOM header seems to match add the file:
-      CoherentFileListHT[uid]->push_back( header );
    }
    else
    {
@@ -109,6 +137,20 @@ void SerieHelper::AddFileName(std::string const &filename)
       delete header;
    }
 }
+/**
+ * \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
+ */
+void SerieHelper::AddRestriction(TagKey const &key, std::string const &value)
+{
+   Rule r;
+   r.first = key;
+   r.second = value;
+   Restrictions.push_back( r ); 
+}
 
 /**
  * \brief Sets the root Directory
index cea132ebde5d9ab3134117a83e0a96869e6ccd47..4ce6f299be4fbb5414db13e07ed3efaacee633c5 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSerieHelper.h,v $
   Language:  C++
-  Date:      $Date: 2005/05/26 18:49:46 $
-  Version:   $Revision: 1.8 $
+  Date:      $Date: 2005/05/27 21:19:04 $
+  Version:   $Revision: 1.9 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -63,6 +63,11 @@ public:
    FileList *GetNextCoherentFileList();
    FileList *GetCoherentFileList(std::string serieUID);
 
+   /// All the following allow user to restrict DICOM file to be part
+   /// of a particular serie
+   void AddRestriction(TagKey const &key, std::string const &value);
+  
+
 private:
    bool ImagePositionPatientOrdering(FileList *coherentFileList);
    bool ImageNumberOrdering(FileList *coherentFileList);
@@ -72,6 +77,10 @@ private:
    static bool FileNameLessThan(File *file1, File *file2);
    CoherentFileListmap CoherentFileListHT;
    CoherentFileListmap::iterator ItListHt;
+
+   typedef std::pair<std::string, std::string> Rule;
+   typedef std::vector<Rule> SerieRestrictions;
+   SerieRestrictions Restrictions;
 };
 
 } // end namespace gdcm