]> Creatis software - gdcm.git/commitdiff
Fix bug on SplitOnly
authorjpr <jpr>
Wed, 20 Apr 2011 15:03:54 +0000 (15:03 +0000)
committerjpr <jpr>
Wed, 20 Apr 2011 15:03:54 +0000 (15:03 +0000)
vtk/test4DSplitter.cxx
vtk/vtkGdcm4DSplitter.cxx
vtk/vtkGdcm4DSplitter.h

index e2a9ed0b5c745f51675f9a32ec6f270573cf22ac..059de647001e64d31b3cb6e3b8188dff60b9ee93 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: test4DSplitter.cxx,v $
   Language:  C++
-  Date:      $Date: 2011/04/11 11:28:31 $
-  Version:   $Revision: 1.6 $
+  Date:      $Date: 2011/04/20 15:03:54 $
+  Version:   $Revision: 1.7 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -49,20 +49,26 @@ typedef std::map<std::string, GDCM_NAME_SPACE::File*> SortedFiles;
 bool myCompareFunction(GDCM_NAME_SPACE::File *file1, GDCM_NAME_SPACE::File *file2)
  { 
    return atof(file1->GetEntryString(0x0018,0x1060).c_str()) < atof(file2->GetEntryString(0x0018,0x1060).c_str()); 
+ }
+bool myCompareFunction0008_0032(GDCM_NAME_SPACE::File *file1, GDCM_NAME_SPACE::File *file2)
+ { 
+   return atof(file1->GetEntryString(0x0008,0x0032).c_str()) < atof(file2->GetEntryString(0x0008,0x0032).c_str()); 
  } 
-
 int main(int argc, char *argv[])
 {
   
   
-   std::cout << "... inside " << argv[0] << std::endl;
+   std::cout << "... inside " << argv[0] << std::endl;
 
 // 3D     
-std::string strDirName("/home/jpr/Desktop/Patients_Emilie/Patient.3T/AUB Jos/AUBERTIN JOSEPH/PROSTATE - 305629373/dSSh_DWISENSE_602");
+//std::string strDirName("/home/jpr/Desktop/Patients_Emilie/Patient.3T/AUB Jos/AUBERTIN JOSEPH/PROSTATE - 305629373/dSSh_DWISENSE_602");
 
 // 4D
 //std::string strDirName("/home/jpr/Desktop/Patients_Emilie/Patient.3T/AUB Jos/AUBERTIN JOSEPH/PROSTATE - 305629373/DYN7INJDYN6_901");
-   
+
+// n directories 
+std::string strDirName("/home/jpr/Desktop/patient Andrei Dyn/dyn");
 
    // ----- Begin Processing -----  
    
@@ -76,24 +82,36 @@ std::string strDirName("/home/jpr/Desktop/Patients_Emilie/Patient.3T/AUB Jos/AUB
 // en sortie, chaque vtkImageData contiendra une coupe au cours du temps
 // n * 2D+T
 
-std::vector<vtkImageData*> *output;
+  std::vector<vtkImageData*> *output;
+  std::vector<vtkImageData*>::iterator it;
+
+//  ========================================
+//  Split on Position (IPP)
+//  Sort on UserFunction (use 0008|0032 : Aquisition Time )
+//
+// Should give a vector of 2D+T vtkImageData*
+//  ========================================
+
+//vtkGdcm4DSplitter *spl = new vtkGdcm4DSplitter();
+
+if (1) {
+
+   std::cout << "Try with :  Split on Position (IPP) / Sort on UserFunction (use 0008|0032 : Aquisition Time )" << std::endl;
 
- if (1) {
    vtkGdcm4DSplitter *spl = new vtkGdcm4DSplitter();
+   spl->setFlipY(false);
    spl->setDirName(strDirName);
-   spl->setRecursive(false);
+   spl->setRecursive(true);
+   
    spl->setSplitOnPosition();
-   //spl->setSplitOnOrientation();
-   // Time triger : 0018|1060
-   grSort=0x0018;
-   elSort=0x1060;
    
-   // ==> Big troubles with SortOnTag
-   //spl->setSortOnTag(grSort, elSort);
-   //spl->setSortConvertToFloat(true); 
+   // Time triger : 0018|1060
+   //grSort=0x0018;
+   //elSort=0x1060;
       
    // ==> use SortOnUserFunction !
-   spl->setSortOnUserFunction(myCompareFunction);   
+   spl->setSortOnUserFunction(myCompareFunction0008_0032);  
+   
 
    std::cout << "Everything set" << std::endl;  
    bool res=spl->Go();
@@ -105,7 +123,64 @@ std::vector<vtkImageData*> *output;
     } 
 
    output = spl->GetImageDataVector();
-}
+
+
+std::cout << "--------------------------------" << std::endl;
+std::cout << "Vector size " << output->size()   << std::endl;
+std::cout << "--------------------------------" << std::endl;
+
+// Print the first one (why not?)
+//(*output)[0]->PrintSelf(std::cout, vtkIndent(2));
+
+   for(it=output->begin(); it!=output->end(); ++it) {
+      //std::cout << "========================================" << std::endl;
+      //(*it)->PrintSelf(std::cout, vtkIndent(2));
+   }
+   //delete spl; 
+} 
+
+
+for(int i=0; i<3; i++)
+   std::cout << "---------------------------------------------" << std::endl;
+
+
+
+//  ========================================
+//  Split on Tag 0008|0032 (Aquisition Time)
+//  Sort on Position (IPP)
+//
+// Should give a vector of 'true 3D' vtkImageData*
+//  ========================================
+ if (1) {
+   std::cout << "Try with :  Split on Tag 0008|0032 (Aquisition Time) / Sort on Position (IPP)" << std::endl; 
+
+   vtkGdcm4DSplitter *spl = new vtkGdcm4DSplitter();
+   spl->setFlipY(false);
+   spl->setDirName(strDirName);
+   spl->setRecursive(true);
+   
+   // Time triger : 0018|1060
+   //grSort=0x0018;
+   //elSort=0x1060;
+ // Aquisition Time  : 0008|0032
+spl->setSplitOnTag(0x0008, 0x0032); 
+   
+spl->setSortOnPosition();
+
+   std::cout << "Everything set" << std::endl;  
+   bool res=spl->Go();
+   
+    std::cout << "GO() done, status " << res << std::endl;
+    if(!res)
+    {
+       std::cout << "plantage!" << std::endl;
+    } 
+
+   output = spl->GetImageDataVector();
+
 
 std::cout << "--------------------------------" << std::endl;
 std::cout << "Vector size " << output->size()   << std::endl;
@@ -114,17 +189,18 @@ std::cout << "--------------------------------" << std::endl;
 // Print the first one (why not?)
 //(*output)[0]->PrintSelf(std::cout, vtkIndent(2));
 
- std::vector<vtkImageData*>::iterator it;
- for(it=output->begin(); it!=output->end(); ++it) {
-   std::cout << "========================================" << std::endl;
-   (*it)->PrintSelf(std::cout, vtkIndent(2));
- }
+
+   for(it=output->begin(); it!=output->end(); ++it) {
+      //std::cout << "========================================" << std::endl;
+      //(*it)->PrintSelf(std::cout, vtkIndent(2));
+   }
+   
+  // delete spl;
+}
 
 // Pour un directory '4D'
 // en sortie, chaque  vtkImageData contiendra un volume au cours du temps.
 // 3D + T
 
-}
-  
-
 
+}
index 8296e635730fb72991be2b313e6a8433cddc314c..85a71d1ed2960ef9630f0ea12814d634c10593bd 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: vtkGdcm4DSplitter.cxx,v $
   Language:  C++
-  Date:      $Date: 2011/04/15 15:23:14 $
-  Version:   $Revision: 1.12 $
+  Date:      $Date: 2011/04/20 15:03:54 $
+  Version:   $Revision: 1.13 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -143,12 +143,12 @@ Avoid loosing CPU time using :
  */
  vtkGdcm4DSplitter::vtkGdcm4DSplitter() :
                  SplitOnPosition(false), SplitOnOrientation(false), SplitOnTag(false),
-                 SplitGroup(0), SplitElem(0), SplitConvertToFloat(false),
+                 SplitGroup(0), SplitElem(0), SplitConvertToFloat(false), SplitOnly(false),
 
-                 SortOnPosition(false),  SortOnOrientation(false),  SortOnTag(false), SortOnFileName(false), SortOnUserFunction(false),
-                 SortGroup(0),  SortElem(0), SortConvertToFloat(false),
+                 SortOnPosition(false),  SortOnOrientation(false), /* SortOnTag(false),*/ SortOnFileName(false), SortOnUserFunction(false),
+                 /*SortGroup(0),  SortElem(0), SortConvertToFloat(false),*/
 
-                 Recursive(false), TypeDir(0),
+                 Recursive(false),FlipY(true), TypeDir(0),
                  verbose(false) 
  {
  
@@ -211,7 +211,7 @@ void  vtkGdcm4DSplitter::setRecursive(bool recursive)
  }
 
 /**
- * \brief Sets a list of files read
+ * \brief Sets a list of files names to read
  * @param   vectFileName vector of file names to deal with
  */ 
  bool vtkGdcm4DSplitter::setVectFileName(std::vector<std::string> &vectFileName)
@@ -227,8 +227,8 @@ void  vtkGdcm4DSplitter::setRecursive(bool recursive)
  }      
 
 /**
- * \brief Sets a vector of gdcm::File *
- * @param   vectGdcmFileName vector of gdcm::File *
+ * \brief Sets an already filled std::vector of gdcm::File *
+ * @param   vectGdcmFileName std::vector of gdcm::File *
  */
  
  bool vtkGdcm4DSplitter::setVectGdcmFile(GDCM_NAME_SPACE::FileList *vectGdcmFile)
@@ -243,28 +243,30 @@ void  vtkGdcm4DSplitter::setRecursive(bool recursive)
  } 
 
 
-       // Split
-       // =====
+       // Split criterion
+       // ===============
+       //
 
 /**
  * \brief   asks for splitting  Filesets according to the Position
- */
-       
+ */      
  void  vtkGdcm4DSplitter::setSplitOnPosition()
  {
     SplitOnPosition=true;
     SplitOnOrientation=false;
     SplitOnTag=false;
  }
 /**
  * \brief   asks for splitting  Filesets according to the Orientation
- */ 
+ */
  void  vtkGdcm4DSplitter::setSplitOnOrientation()
  {
     SplitOnPosition=false;
     SplitOnOrientation=true; 
     SplitOnTag=false;
  }
 /**
  * \brief   asks for splitting  Filesets according to the value of a given Tag
  * @param   group  group number of the target Element
@@ -278,6 +280,7 @@ void  vtkGdcm4DSplitter::setRecursive(bool recursive)
     SplitGroup=splitGroup;
     SplitElem=splitElem;
  }
 /**
  * \brief   asks for converting to 'float' the tag values used as a splitting criteria (lexicographic order may not be suitable)
  */   
@@ -290,29 +293,34 @@ void  vtkGdcm4DSplitter::setRecursive(bool recursive)
  {
     SplitOnly = s;
  }
-       // Sort
-       // ====
-
+       // Sort criterion
+       // ==============
+       //
+/**
+ * \brief   asks for IPP sorting each XCoherent gdcm::FILE set
+ */  
  void  vtkGdcm4DSplitter::setSortOnPosition() 
  {
     SortOnPosition=true;
     SortOnOrientation=false;
-    SortOnTag=false;
+    //SortOnTag=false;
     SortOnFileName=false;
     SortOnUserFunction=false;
     SortOnPosition=true;
  }
  
     // use setSortOnUserFunction, instead!
     // void setSortOnTag(unsigned short int sortGroup, unsigned short int sortElem)
     // {
     //    SortOnPosition=false;
     //    SortOnOrientation=false;
     //    SortOnTag=true;
     //    SortOnFileName=false;
     //    SortOnUserFunction=false;
     //    SortGroup=sortGroup;  SortElem=sortElem;
     // }
+ // use setSortOnUserFunction, instead!
+ // void setSortOnTag(unsigned short int sortGroup, unsigned short int sortElem)
+ // {
+ //    SortOnPosition=false;
+ //    SortOnOrientation=false;
+ //    SortOnTag=true;
+ //    SortOnFileName=false;
+ //    SortOnUserFunction=false;
+ //    SortGroup=sortGroup;  SortElem=sortElem;
+ // }
 
 
 /**
@@ -324,38 +332,31 @@ void  vtkGdcm4DSplitter::setRecursive(bool recursive)
     UserCompareFunction=f;
     SortOnPosition=false;
     SortOnOrientation=false;
-    SortOnTag=false;
+    //SortOnTag=false;
     SortOnFileName=false;
     SortOnUserFunction=true;
   }
 
-
  //  void setSortConvertToFloat(bool conv)
  //  {
  //     SortConvertToFloat=conv;
  //  }
 
 /**
- * \brief asks for sorting  the images, according to their File Name
+ * \brief asks for sorting each XCoherent gdcm::FILE set, according to the File names
  */
  void  vtkGdcm4DSplitter::setSortOnFileName()
  {
     SortOnPosition=false;
     SortOnOrientation=false;
-    SortOnTag=false;
+    //SortOnTag=false;
     SortOnFileName=true;
     SortOnUserFunction=false;
  }
 
-
- std::vector<vtkImageData*> * vtkGdcm4DSplitter::GetImageDataVector() 
- { 
-    if (SplitOnly)
-       return NULL;
-
-     return ImageDataVector;
- }
+/**
+ * \brief returns a std::vector of gdcm::FileList* (gdcm::FileList : actually, a std::vector of gdcm::File*)
+ */ 
  std::vector<GDCM_NAME_SPACE::FileList *> *vtkGdcm4DSplitter::GetVectGdcmFileLists()
  {
     if (SplitOnly)
@@ -370,42 +371,42 @@ void  vtkGdcm4DSplitter::setRecursive(bool recursive)
     } 
     return  &VectGdcmFileLists;         
  }
 
+/**
+ * \brief returns a std::vector of [2D/3D, depending on what was passed] vtkImageData*
+ */
+ std::vector<vtkImageData*> * vtkGdcm4DSplitter::GetImageDataVector() 
+ { 
+    if (SplitOnly)
+       return NULL;
+     return ImageDataVector;
+ }
+
+/**
+ * \brief when user _knows_ only _one_ vtkImageData* is returned he may be interested in not getting a vector...
+ */
  vtkImageData *vtkGdcm4DSplitter::GetImageData() 
  {
    if (SplitOnly)
       return NULL;
-   return (*ImageDataVector)[0]; 
+   return (*ImageDataVector)[0];
  }      
 
  
- bool vtkGdcm4DSplitter::CompareOnSortTagConvertToFloat(GDCM_NAME_SPACE::File *file1, GDCM_NAME_SPACE::File *file2)
- { 
-  /* if (verbose) printf ("%04x %04x\n", this->SortGroup,this->SortElem);
-     if (verbose) std :: cout << file1->GetEntryString(SortGroup,SortElem).c_str() << " : " 
-                            << atof(file1->GetEntryString(SortGroup,SortElem).c_str())
-                            << std::endl;
-*/
+// bool vtkGdcm4DSplitter::CompareOnSortTagConvertToFloat(GDCM_NAME_SPACE::File *file1, GDCM_NAME_SPACE::File *file2)
+// {
 //   return atof(file1->GetEntryString(vtkGdcm4DSplitter::SortGroup,vtkGdcm4DSplitter::SortElem).c_str()) < atof(file2->GetEntryString(vtkGdcm4DSplitter::SortGroup,vtkGdcm4DSplitter::SortElem).c_str()); 
-   return atof(file1->GetEntryString(SortGroup,SortElem).c_str()) < atof(file2->GetEntryString(SortGroup,SortElem).c_str()); 
- } 
+//   return atof(file1->GetEntryString(SortGroup,SortElem).c_str()) < atof(file2->GetEntryString(SortGroup,SortElem).c_str()); 
+// } 
 
- bool vtkGdcm4DSplitter::CompareOnSortTag(GDCM_NAME_SPACE::File *file1, GDCM_NAME_SPACE::File *file2)
- {
-   return file1->GetEntryString(vtkGdcm4DSplitter::SortGroup,vtkGdcm4DSplitter::SortElem) < file2->GetEntryString(vtkGdcm4DSplitter::SortGroup,vtkGdcm4DSplitter::SortElem);  
- }
+// bool vtkGdcm4DSplitter::CompareOnSortTag(GDCM_NAME_SPACE::File *file1, GDCM_NAME_SPACE::File *file2)
+// {
+//   return file1->GetEntryString(vtkGdcm4DSplitter::SortGroup,vtkGdcm4DSplitter::SortElem) < file2->GetEntryString(vtkGdcm4DSplitter::SortGroup,vtkGdcm4DSplitter::SortElem);  
+// }
  
  
  bool vtkGdcm4DSplitter::Go()
  {
-   if (!SplitOnPosition && !SplitOnOrientation && !SplitOnTag) 
-   {
-       ///\TODO (?) Throw an exception "Choose Splitting mode before!"
-       std::cout << "Choose Splitting mode before!" << std::endl;
-       return false;
-   }
-
    /// How To :
    /*
    entree nom de directory / Vecteur de noms?
@@ -417,80 +418,26 @@ void  vtkGdcm4DSplitter::setRecursive(bool recursive)
    trier chaque Coherent file set
    passer chacun a un vtkGcdmReader
    retourner le (vecteur de) vtkImageData
-   */
-   
-   GDCM_NAME_SPACE::SerieHelper *s;  
-   s = GDCM_NAME_SPACE::SerieHelper::New();
+   */ 
 
-   GDCM_NAME_SPACE::File *f;
-   GDCM_NAME_SPACE::DirListType fileNames;
- //
- // Fill  fileNames with the user supplied file names (in any)
- // --------------------------------------
- //
-   if (TypeDir == 0 )
-   {
-      ///\TODO (?) Throw an exception "Set input Directory name(s) / file names  before!"
-      std::cout << "Set input Directory name(s) / file names  before!" << std::endl;
-      return false;
-   }
-   else if (TypeDir == 1)
-   {
-      GDCM_NAME_SPACE::DirList dirlist(DirName, Recursive); // NO recursive exploration
-      fileNames = dirlist.GetFilenames(); // all the file names
-   }
-   
-   else if (TypeDir == 2)
+   if (!SplitOnPosition && !SplitOnOrientation && !SplitOnTag) 
    {
-      int nbDir = VectDirName.size();
-      GDCM_NAME_SPACE::DirListType tmpFileNames;
-      for (int iDir=0; iDir<nbDir; iDir++)
-      {
-        GDCM_NAME_SPACE::DirList dirlist(VectDirName[iDir], Recursive);
-        tmpFileNames = dirlist.GetFilenames();
-        // Concat two std::vector
-        //vector1.insert( vector1.end(), vector2.begin(), vector2.end() );
-        fileNames.insert( fileNames.end(), tmpFileNames.begin(), tmpFileNames.end() );
-      }    
+       ///\TODO (?) Throw an exception "Choose Splitting mode before!"
+       std::cout << "Choose Splitting mode before!" << std::endl;
+       return false;
    }
-   else if (TypeDir == 3)
-   {
-      fileNames=VectFileName;
-   }  
-
- //
- // Fill l with the gdcm::File* corresponding to the files
- // --------------------------------------
- //
 
-   GDCM_NAME_SPACE::FileList *l = new GDCM_NAME_SPACE::FileList; // (set of gdcm::File)
+   GDCM_NAME_SPACE::FileList *l;
    
-   if (TypeDir == 4)
-   {
-   // User passed a vector of gdcm::File* 
-      l = VectGdcmFile;
-   } 
-   else
-   { 
-      double floatTagvalue;  
-      // Loop on all the gdcm-readable files
-      for (GDCM_NAME_SPACE::DirListType::iterator it = fileNames.begin();
-                                                  it != fileNames.end();
-                                                ++it)
-      {
-         int maxSize  = 0x7fff;         // load Elements of any length
-         f = GDCM_NAME_SPACE::File::New();
-         f->SetMaxSizeLoadEntry(maxSize);
-         f->SetFileName( *it );
-         if (f->Load())
-            l->push_back(f);
-         else 
-            std::cout << " Fail to load [" <<  *it << "]" << std::endl;          
-      }
-   } 
-
-
+   GDCM_NAME_SPACE::SerieHelper *s;  
+   s = GDCM_NAME_SPACE::SerieHelper::New();
+   
+//
+// Load the gdcm::File* set, according to user's requierements
+// ------------------------------------------------------------
+//   
+   l = getGdcmFileList();
+std::cout << l->size() << " gdcm::File read" << std::endl;
 //
 // Split the gdcm::File* set, according to user's requierements
 // ------------------------------------------------------------
@@ -521,22 +468,22 @@ void  vtkGdcm4DSplitter::setRecursive(bool recursive)
                xcm = s->SplitOnTagValue(l, SplitGroup, SplitElem);
             else 
             {
-                xcm = s->SplitOnTagValueConvertToFloat(l, SplitGroup, SplitElem);
+               xcm = s->SplitOnTagValueConvertToFloat(l, SplitGroup, SplitElem);
             }
-   }
+  }
   
    if (xcm.size() == 0)
    {
-      if(verbose) std::cout << "Empty XCoherent File Set after 'split' ?!?" << std::endl;
+      if(verbose)
+         std::cout << "Empty XCoherent File Set after 'split' ?!?" << std::endl;
       return false;
    }
-/*
-   else if (xcm.size() == 1)
-      TypeResult=1;
    else
-      TypeResult=2;
-*/
+   {
+      std::cout << xcm.size() << " XCoherent entries found" << std::endl;
+   }
 
+std::cout <<"SplitOnly " << SplitOnly << std::endl;
    if(SplitOnly)
       return true;   
 //
@@ -544,6 +491,7 @@ void  vtkGdcm4DSplitter::setRecursive(bool recursive)
 // ------------------------------------------------------------
 //
    ImageDataVector = new std::vector<vtkImageData*>;
+
    /// \TODO move inside the loop, or be clever using vtk!
   // vtkGdcmReader *reader = vtkGdcmReader::New(); // move inside the loop, or be clever using vtk!
    
@@ -592,30 +540,30 @@ void  vtkGdcm4DSplitter::setRecursive(bool recursive)
          if (verbose) std::cout << "Out of SortOnFileName" << std::endl;
       }
 
-      else if (SortOnTag)
-      {  
-         if (verbose) std::cout << "SortOnTag" << std::endl;   
-         printf ("--> %04x %04x\n", SortGroup,SortElem);
-         std::cout << "Sorry, troubles not solved yet; use SortOnUserFunction, right now!" << std::endl;
+//      else if (SortOnTag)
+//      {  
+//         if (verbose) std::cout << "SortOnTag" << std::endl;   
+//         printf ("--> %04x %04x\n", SortGroup,SortElem);
+//         std::cout << "Sorry, troubles not solved yet; use SortOnUserFunction, right now!" << std::endl;
  
         /*        ==> WARNING : This one has troubles; do NOT use it, right now!
         // a pointer to fonction cannot be casted as a pointer to member function!
         // Use SortOnUserFunction, instead!
 
         //  if ( SortConvertToFloat )
-         //    s->SetUserLessThanFunction( reinterpret_cast<bool (*)(gdcm13::File*, gdcm13::File*)> 
-                                                                 ( &vtkGdcm4DSplitter::CompareOnSortTagConvertToFloat));     
+        //    s->SetUserLessThanFunction( reinterpret_cast<bool (*)(gdcm13::File*, gdcm13::File*)> 
+        //                                                         ( &vtkGdcm4DSplitter::CompareOnSortTagConvertToFloat));     
         //  else
         //     s->SetUserLessThanFunction( reinterpret_cast<bool (*)(gdcm13::File*, gdcm13::File*)>
-                                                                 ( &vtkGdcm4DSplitter::CompareOnSortTag)); 
+                                                                    ( &vtkGdcm4DSplitter::CompareOnSortTag)); 
        
          // Anything like this, in GDCM2? 
         //  s->UserOrdering((*i).second);
         */
 
-         //if (verbose) std::cout << "Out of SortOnTag" << std::endl;
-         std::cout << "NO ordering performed  :-( " << std::endl;
-      }
+//         //if (verbose) std::cout << "Out of SortOnTag" << std::endl;
+//         std::cout << "NO ordering performed  :-( " << std::endl;
+//      }
       
       else if (SortOnUserFunction)
       {   
@@ -631,30 +579,111 @@ void  vtkGdcm4DSplitter::setRecursive(bool recursive)
        
        /// \TODO : remove the following
        if (verbose) {
-          std::cout << "reader->GetOutput() :" << std::endl;
-          reader->GetOutput()->PrintSelf(std::cout, vtkIndent(2));
+         // std::cout << "reader->GetOutput() :" << std::endl;
+         // reader->GetOutput()->PrintSelf(std::cout, vtkIndent(2));
        }
        
        ImageDataVector->push_back(reader->GetOutput() );
        
        std::vector<vtkImageData*>::iterator it; 
-       if (verbose)      
+       //if (verbose) // JPR
+   
        for(it=ImageDataVector->begin(); it!=ImageDataVector->end(); ++it) {
-         std::cout << "-in vtkGdcm4DSplitter--------------------------" << std::endl;
-         (*it)->PrintSelf(std::cout, vtkIndent(2));
+        // std::cout << "-in vtkGdcm4DSplitter --------------------------" << std::endl;
+        // (*it)->PrintSelf(std::cout, vtkIndent(2));
        }
-       std::cout << std::endl;
+       //std::cout << std::endl;
    }
 
    //reader->Delete();  // \TODO : fix
    s->Delete(); 
-   f->Delete();
+  // f->Delete();
    delete l;
    
    return true;
  }
 
 
+/**
+ * \brief Load the gdcm::File* set, according to user's requierements
+ * returns a std::vector of gdcm::File* (gdcm::FileList : actually, a std::vector of gdcm::File*)
+ */
+
+GDCM_NAME_SPACE::FileList *vtkGdcm4DSplitter::getGdcmFileList()
+{
+
+  GDCM_NAME_SPACE::File *f;
+  GDCM_NAME_SPACE::DirListType fileNames;
+
+ //
+ // Fill fileNames with the user supplied file names (in any)
+ // ------------------------------------------------
+ //
+   if (TypeDir == 0 )  // Nothing was set as input...
+   {
+      ///\TODO (?) Throw an exception "Set input Directory name(s) / file names  before!"
+      std::cout << "Set input Directory name(s) / file names  before!" << std::endl;
+      return false;
+   }
+   else if (TypeDir == 1) // A root directory name was set as input
+   {
+      GDCM_NAME_SPACE::DirList dirlist(DirName, Recursive); // NO recursive exploration
+      fileNames = dirlist.GetFilenames(); // all the file names
+   }
+   
+   else if (TypeDir == 2) // a std::vector of directory names was set as input
+   {
+      int nbDir = VectDirName.size();
+      GDCM_NAME_SPACE::DirListType tmpFileNames;
+      for (int iDir=0; iDir<nbDir; iDir++)
+      {
+        GDCM_NAME_SPACE::DirList dirlist(VectDirName[iDir], Recursive);
+        tmpFileNames = dirlist.GetFilenames();
+        // Concat two std::vector
+        //vector1.insert( vector1.end(), vector2.begin(), vector2.end() );
+        fileNames.insert( fileNames.end(), tmpFileNames.begin(), tmpFileNames.end() );
+      }    
+   }
+   else if (TypeDir == 3) // a list of files names was set as input
+   {
+      fileNames=VectFileName;
+   }  
+
+ //
+ // Fill l with the gdcm::File* corresponding to the files
+ // --------------------------------------
+ //
+
+   GDCM_NAME_SPACE::FileList *l = new GDCM_NAME_SPACE::FileList; // (set of gdcm::File*)
+   
+   if (TypeDir == 4) // an already existing std::vector of gdcm::File* was set as input
+   {
+      l = VectGdcmFile;
+   }
+   else
+   { 
+      double floatTagvalue;  
+      // Loop on all the gdcm-readable files
+      for (GDCM_NAME_SPACE::DirListType::iterator it = fileNames.begin();
+                                                  it != fileNames.end();
+                                                ++it)
+      {
+         int maxSize  = 0x7fff;         // load Elements of any length
+         f = GDCM_NAME_SPACE::File::New();
+         f->SetMaxSizeLoadEntry(maxSize);
+         f->SetFileName( *it );
+         if (f->Load())
+            l->push_back(f);
+         else 
+            std::cout << " Fail to load [" <<  *it << "]" << std::endl;          
+      }
+   }
+   return l; 
+}
+
+
+
  void vtkGdcm4DSplitter::reorgXCoherentFileSetmap(GDCM_NAME_SPACE::XCoherentFileSetmap &xcm)
  {
  /*
@@ -670,7 +699,7 @@ void  vtkGdcm4DSplitter::setRecursive(bool recursive)
    ELEM e;   
    std::vector<ELEM> vectElem;
 
-/* remenber :
+/* just to remember :
    typedef struct 
    {
       std::string strIPP;
@@ -730,6 +759,7 @@ void  vtkGdcm4DSplitter::setRecursive(bool recursive)
 bool vtkGdcm4DSplitter::sortVectElem(std::vector<ELEM> *fileList)
 {
 //based on Jolinda Smith's algorithm
+//
 // NOTE : if you need to use Jolinda Smith's algorithm, get the one inside gdcm::SerieHelper
 // this one is a light version.
 
index 1c479a3f80f25aa6cf715f8bc9cd18d18a06495f..482f509c915aee1218925ecba624c976817c2610 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: vtkGdcm4DSplitter.h,v $
   Language:  C++
-  Date:      $Date: 2011/04/15 15:23:14 $
-  Version:   $Revision: 1.11 $
+  Date:      $Date: 2011/04/20 15:03:54 $
+  Version:   $Revision: 1.12 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -55,7 +55,7 @@ typedef  bool (*FoncComp)(GDCM_NAME_SPACE::File *file1, GDCM_NAME_SPACE::File *f
        
        bool setVectGdcmFile(std::vector<GDCM_NAME_SPACE::File *> *vectGdcmFile);
        
-       void SetFlipY(bool f) { FlipY = f; }
+       void setFlipY(bool f) { FlipY = f; }
 
        // Split
        // =====
@@ -97,12 +97,17 @@ typedef  bool (*FoncComp)(GDCM_NAME_SPACE::File *file1, GDCM_NAME_SPACE::File *f
        bool CompareOnSortTagConvertToFloat(GDCM_NAME_SPACE::File *file1, GDCM_NAME_SPACE::File *file2);
        void reorgXCoherentFileSetmap      (GDCM_NAME_SPACE::XCoherentFileSetmap &xcm);
        bool sortVectElem(std::vector<ELEM> *le);
-
+      GDCM_NAME_SPACE::FileList * getGdcmFileList();
     // Data
     // ----
     public:
     protected:
     private:
+    
+       //
+       // Set by user
+       //
        std::string DirName;
        std::vector<std::string> VectDirName;
        std::vector<std::string> VectFileName;
@@ -118,28 +123,33 @@ typedef  bool (*FoncComp)(GDCM_NAME_SPACE::File *file1, GDCM_NAME_SPACE::File *f
  
        bool SortOnPosition;
        bool SortOnOrientation;
-       bool SortOnTag;
+       //bool SortOnTag;
        bool SortOnFileName;
        bool SortOnUserFunction;
 
        FoncComp UserCompareFunction;
 
-       unsigned short int SortGroup;
-       unsigned short int SortElem;
-       bool SortConvertToFloat;
+       //unsigned short int SortGroup;
+       //unsigned short int SortElem;
+       //bool SortConvertToFloat;
 
        bool Recursive;
-       int TypeDir;
-       //int TypeResult;
+       bool FlipY;
        bool verbose;
-       std::vector<vtkImageData*> *ImageDataVector;
-       vtkImageData *ImageData;
-       //std::vector<GDCM_NAME_SPACE::File *> VectGdcmFile;
-       GDCM_NAME_SPACE::FileList *VectGdcmFile; 
+       
+       //
+       // needed, to work
+       //       
+       int TypeDir;
        GDCM_NAME_SPACE::XCoherentFileSetmap xcm;
-       //std::vector<std::vector<GDCM_NAME_SPACE::File *> > VectGdcmFileLists;
-       std::vector<GDCM_NAME_SPACE::FileList *> VectGdcmFileLists;
-       bool FlipY;
+       
+       //
+       // may be got by user
+       //
+       std::vector<vtkImageData*> *ImageDataVector;
+       GDCM_NAME_SPACE::FileList *VectGdcmFile;       // std::vector of gdcm::File*
+       
+       std::vector<GDCM_NAME_SPACE::FileList *> VectGdcmFileLists; // result of the splitting operation
   };
 
 //} // end namespace gdcm