]> Creatis software - gdcm.git/commitdiff
Add new method :
authorjpr <jpr>
Fri, 8 Jun 2007 12:49:37 +0000 (12:49 +0000)
committerjpr <jpr>
Fri, 8 Jun 2007 12:49:37 +0000 (12:49 +0000)
 SerieHelper::SetDicomDirSerie(DicomDirSerie *se)

src/gdcmDirList.cxx
src/gdcmDirList.h
src/gdcmSerieHelper.cxx
src/gdcmSerieHelper.h

index d881e59f825c64bd32ca69edf04c666cade8c909..a777d9ea5efdee0cedcd36fc0db8c59493fe0390 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDirList.cxx,v $
   Language:  C++
-  Date:      $Date: 2007/05/23 14:18:09 $
-  Version:   $Revision: 1.61 $
+  Date:      $Date: 2007/06/08 12:49:37 $
+  Version:   $Revision: 1.62 $
                                                                                 
   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,8 @@
 #include "gdcmUtil.h"
 #include "gdcmDebug.h"
 
+#include "gdcmDicomDirImage.h"
+
 #include <iterator>
 #include <assert.h>
 #include <errno.h>
@@ -48,6 +50,15 @@ DirList::DirList(std::string const &dirName, bool recursive)
    Explore(dirName, recursive);
 }
 
+/**
+ * \brief Constructor  
+ * @param  dirName root directory name
+ * @param  recursive whether we want to explore recursively or not 
+ */
+DirList::DirList(DicomDirSerie *se)
+{
+   Explore(se);
+}
 /**
  * \brief  Destructor
  */
@@ -115,6 +126,26 @@ std::string DirList::GetNext()
 
 //-----------------------------------------------------------------------------
 // Private
+
+/**
+ * \brief   Explores a DicomDirSerie
+ *          return number of files found
+ * @param  se DicomDirSerie to explore
+ */
+int DirList::Explore(DicomDirSerie *se)
+{
+   int numberOfFiles = 0;
+
+   DicomDirImage *im = se->GetFirstImage();
+   while ( im ) 
+   { 
+      Filenames.push_back( im->GetEntryString(0x0004, 0x1500) );// File name (Referenced File ID)
+      numberOfFiles++;           
+      im = se->GetNextImage();   
+   }
+   return numberOfFiles;
+}   
+   
 /**
  * \brief   Explore a directory with possibility of recursion
  *          return number of files read
index 9891970ce6f67493b349de886d43abd58678db57..cda6dd317c78e1377a6549b5ed38fb756bf64ec8 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDirList.h,v $
   Language:  C++
-  Date:      $Date: 2007/05/23 14:18:09 $
-  Version:   $Revision: 1.33 $
+  Date:      $Date: 2007/06/08 12:49:37 $
+  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
@@ -20,6 +20,7 @@
 #define GDCMDIRLIST_H
 
 #include "gdcmBase.h"
+#include "gdcmDicomDirSerie.h"
 
 #include <string>
 #include <vector>
@@ -43,6 +44,7 @@ class GDCM_EXPORT DirList : public Base
 {
 public :
    DirList(std::string const &dirName, bool recursive);
+   DirList(DicomDirSerie *s);   
    ~DirList();
 
    void Print(std::ostream &os = std::cout, std::string const &indent = "" );
@@ -63,7 +65,8 @@ public :
    
 private :
    int Explore(std::string const &dirName, bool recursive=false);
-
+   int Explore(DicomDirSerie *s);
+   
    /// List of file names
    DirListType Filenames;
    /// name of the root directory to explore
index 0be2e44aa43c79f6b7bf9c4745b38ebc2f4e086e..8d800cea5c626f2eda30e068e3ee2ef406f1bf4c 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/06/08 12:49:37 $
+  Version:   $Revision: 1.57 $
                                                                                 
   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;
+   
 }
 
 /**
@@ -242,8 +243,7 @@ void SerieHelper::AddRestriction(uint16_t group, uint16_t elem,
  *         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
@@ -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() );
    }
 
index 363970f7a5bb8e20056839806fce4a6916f25791..1345de5b56109a7636b549dbf0d440c4eb3f7eb1 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSerieHelper.h,v $
   Language:  C++
-  Date:      $Date: 2007/05/23 14:18:11 $
-  Version:   $Revision: 1.42 $
+  Date:      $Date: 2007/06/08 12:49:37 $
+  Version:   $Revision: 1.43 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -22,6 +22,8 @@
 #include "gdcmRefCounter.h"
 #include "gdcmTagKey.h" 
 #include "gdcmDebug.h"  // for LEGACY
+
+#include "gdcmDicomDirSerie.h"
  
 #include <vector>
 #include <iostream>
@@ -82,6 +84,8 @@ public:
  //  GDCM_LEGACY(bool AddGdcmFile(File* header))
 
    void SetDirectory(std::string const &dir, bool recursive=false);
+   void SetDicomDirSerie(DicomDirSerie *se);
+      
    bool IsCoherent(FileList *fileSet);
    void OrderFileList(FileList *fileSet);
    void Clear() { ClearAll(); }
@@ -139,7 +143,7 @@ public:
    /// 0018 0024 Sequence Name
    /// 0018 0050 Slice Thickness
    /// 0028 0010 Rows
-   /// 0028 0011 Columns
+   /// 0028 0011 Columns   
    void CreateDefaultUniqueSeriesIdentifier();
 
    void AddSeriesDetail(uint16_t group, uint16_t elem, bool convert);
@@ -161,6 +165,12 @@ public:
  * @param   mode Load mode to be used    
  */
    void SetLoadMode (int mode) { LoadMode = mode; }
+   
+/**
+ * \brief Sets the DropDuplicatePositions as a boolean.
+ * @param   drop  DropDuplicatePositions mode to be used   
+ */   
+   void SetDropDuplicatePositions (bool drop) { DropDuplicatePositions = drop; }   
 
 /// Brief User wants the files to be sorted Direct Order (default value)
    void SetSortOrderToDirect()  { DirectOrder = true;  }
@@ -236,6 +246,8 @@ private:
    ///        he may supply his own comparison function.
    BOOL_FUNCTION_PFILE_PFILE_POINTER UserLessThanFunction;
 
+   bool DropDuplicatePositions;
+
    void Sort(FileList *fileList, bool (*pt2Func)( File *file1, File *file2) );
 
    bool m_UseSeriesDetails;