]> Creatis software - gdcm.git/blobdiff - Example/ToInTag.cxx
Deal with any type on input + cosmetics
[gdcm.git] / Example / ToInTag.cxx
index dde01a4cb8a8c7cf96b3118dd0f1483906d88776..0515287754699e1406020ebc4258467d65de0605 100755 (executable)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: ToInTag.cxx,v $
   Language:  C++
-  Date:      $Date: 2006/06/30 09:58:08 $
-  Version:   $Revision: 1.6 $
+  Date:      $Date: 2009/01/19 17:05:13 $
+  Version:   $Revision: 1.21 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 #include "gdcmFileHelper.h"
 #include "gdcmDirList.h"
 #include "gdcmDebug.h"
-#include "gdcmArgMgr.h"
 #include "gdcmUtil.h"
 #include "gdcmSerieHelper.h"
 
+#include "gdcmArgMgr.h"
+
 #include <iostream>
 
 /**
@@ -38,7 +39,7 @@
   *            converted into a Brucker-like Dicom, Intags compliant
   */  
 
-typedef std::map<std::string, gdcm::File*> SortedFiles;
+typedef std::map<std::string, GDCM_NAME_SPACE::File*> SortedFiles;
 
 int main(int argc, char *argv[]) 
 {
@@ -55,27 +56,37 @@ int main(int argc, char *argv[])
    " - fills a single level (*) Directory with *all* the files,               ",
    "           converted into a Brucker-like Dicom, InTags compliant          ",
    "   (*) actually : creates as many directories as Patients                 ",
-   "                  -that shouldn't appear, but being carefull is better ! -",
+   "                  -that shouldn't appear, but being carefull is better!-  ",
    " or                                                                       ",
    " - fills a tree-like structure of directories as :                        ",
    "        - Patient                                                         ",
    "        -- Serie                                                          ",
    "        --- Position                                                      ",
-   "            Images are (sorted by Trigger Time /                          ",
-   "                     Encoding Direction (Row, Column)                     ",
-   "      use :                                                               ",
+   "        ---- Images (sorted by Trigger Time /                             ",
+   "                               Encoding Direction (Row, Column)           ",
+   "                                                                          ",
+   "      Note : when (0008|1090) [Model Name ] equals 'TrioTim ' :           ",
+   "         - (0008|103e)[Series Description ] is checked for                ",
+   "            '90' (-> COL) or '0' (-> ROW)                                 ",
+   "         - (0x0020, 0x000e) [Series Instance UID] is NOT dealt with,      ",
+   "           since row an col tagging are in 2 different Series             ",
+   "           DO NOT supply a directory holding different exams              ",
+   "           for the same Slice level!                                      ",
+   "      uses :                                                              ",
    "           0x0021, 0x1020 : 'SLICE INDEX'                                 ",
    "           0x0021, 0x1040 : 'FRAME INDEX'                                 ",
    "           0x0020, 0x0012 : 'SESSION INDEX'  (Acquisition Number)         ",
+   "                                                                          ",
    " usage:                                                                   ",
-   " PhilipsToBrucker dirin=rootDirectoryName                                 ",
+   " -----                                                                    ",
+   " ToInTag          dirin=rootDirectoryName                                 ",
    "                  dirout=outputDirectoryName                              ",
    "                  {  [keep= list of seriesNumber to process]              ",
    "                   | [drop= list of seriesNumber to ignore] }             ",
    "                  [taggrid] [skel]                                        ",
-   "                  [input = {ACR|DCM}]                                     ", 
+   "                  [input = {ACR|DCM|IDO}]                                 ", 
    "                  [extent=image suffix (.IMA, .NEMA, .DCM, ...)]          ",
-   "                  [listonly] [split]                                      ",
+   "                  [listonly] [split] [rubout]                             ",
    "                  [noshadowseq][noshadow][noseq] [verbose] [debug]        ",
    "                                                                          ",
    " dirout : will be created if doesn't exist                                ",
@@ -85,15 +96,17 @@ int main(int argc, char *argv[])
    "            he gives the list of 'SeriesNumber' (tag 0020|0011)           ",   
    "        SeriesNumber are short enough to be human readable                ",
    "        e.g : 1030,1035,1043                                              ", 
-   " taggrid : user knows all the images are 'grid' -ie : not 'col', not 'raw'",
+   " taggrid : user knows all the images are 'grid' -ie: not 'col', not 'raw'-",
    " extent : DO NOT forget the leading '.' !                                 ",
+   " input : IDO when *realy* old libIDO images                               ",
    " skel: name skeleton eg : patName_1.nema -> skel=patName_                 ",
    " split: creates a tree-like structure of directories as :                 ",
    "        - Patient                                                         ",
    "        -- Serie                                                          ",
    "        --- Position                                                      ",
-   "            Images are (sorted by Trigger Time /                          ",
-   "                     Encoding Direction (Row, Column)                     ",
+   "        ---- Images (sorted by Trigger Time /                             ",
+   "                               Encoding Direction (Row, Column)           ",
+   " rubout : user asks to rubout burnt-in image number                       ",
    " noshadowseq: user doesn't want to load Private Sequences                 ",
    " noshadow : user doesn't want to load Private groups (odd number)         ",
    " noseq    : user doesn't want to load Sequences                           ",
@@ -101,11 +114,23 @@ int main(int argc, char *argv[])
    " debug    : *developer*  wants to run the program in 'debug mode'         ",
    FINISH_USAGE
 
+
+   enum Index
+   { 
+      IND_PatientName,
+      IND_SerieInstanceUID,
+      IND_ImagePosition,
+      IND_TriggerTime,
+      IND_PhaseEncodingDirection,
+      IND_seriesDescription,
+      IND_FileName       
+   };
+   
    std::cout << "inside ToInTag" << std::endl;
    
    // ----- Initialize Arguments Manager ------
       
-   gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
+   GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv);
   
    if (argc == 1 || am->ArgMgrDefined("usage")) 
    {
@@ -115,29 +140,31 @@ int main(int argc, char *argv[])
    }
 
    const char *dirNamein;   
-   dirNamein  = am->ArgMgrGetString("dirin","."); 
+   dirNamein  = am->ArgMgrGetString("dirin",".");
 
    const char *dirNameout;   
-   dirNameout  = am->ArgMgrGetString("dirout",".");  
+   dirNameout  = am->ArgMgrGetString("dirout",".");
    
-   int loadMode = gdcm::LD_ALL;
+   int loadMode = GDCM_NAME_SPACE::LD_ALL;
    if ( am->ArgMgrDefined("noshadowseq") )
-      loadMode |= gdcm::LD_NOSHADOWSEQ;
+      loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ;
    else 
    {
    if ( am->ArgMgrDefined("noshadow") )
-         loadMode |= gdcm::LD_NOSHADOW;
+         loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW;
       if ( am->ArgMgrDefined("noseq") )
-         loadMode |= gdcm::LD_NOSEQ;
+         loadMode |= GDCM_NAME_SPACE::LD_NOSEQ;
    }
 
    if (am->ArgMgrDefined("debug"))
-      gdcm::Debug::DebugOn();
+      GDCM_NAME_SPACE::Debug::DebugOn();
       
    int verbose  = am->ArgMgrDefined("verbose");
    int split    = am->ArgMgrDefined("split");
    int listonly = am->ArgMgrDefined("listonly");
-         
+   
+   bool rubout = ( 0 != am->ArgMgrDefined("rubout") ); 
+           
    int nbSeriesToKeep;
    int *seriesToKeep = am->ArgMgrGetListOfInt("keep", &nbSeriesToKeep);
    int nbSeriesToDrop;
@@ -150,14 +177,15 @@ int main(int argc, char *argv[])
       return 0;         
    }
    
-   int taggrid = am->ArgMgrDefined("taggrid");
-   
-   int hasSkel = am->ArgMgrDefined("skel");
+   bool taggrid = ( 0 != am->ArgMgrDefined("taggrid") );
+      
+   bool hasSkel = ( 0 != am->ArgMgrDefined("hasSkel") );    
    const char *skel;
    if (hasSkel)
-      skel = am->ArgMgrGetString("skel");   
+      skel = am->ArgMgrGetString("skel");
       
    const char *extent  = am->ArgMgrGetString("extent",".DCM");
+   const char *input   = am->ArgMgrGetString("input","DCM");
    
    // if unused Param we give up
    if ( am->ArgMgrPrintUnusedLabels() )
@@ -170,7 +198,7 @@ int main(int argc, char *argv[])
 
    // ----- Begin Processing -----
    
-   if ( ! gdcm::DirList::IsDirectory(dirNamein) )
+   if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirNamein) )
    {
       std::cout << "KO : [" << dirNamein << "] is not a Directory." << std::endl;
       return 0;
@@ -185,14 +213,14 @@ int main(int argc, char *argv[])
    
    std::cout << "Check for output directory :[" << dirNameout << "]."
              <<std::endl;
-   if ( ! gdcm::DirList::IsDirectory(dirNameout) )    // dirout not found
+   if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirNameout) )    // dirout not found
    {
       std::string strDirNameout(dirNameout);          // to please gcc 4
       systemCommand = "mkdir " +strDirNameout;        // create it!
       if (verbose)
          std::cout << systemCommand << std::endl;
       system (systemCommand.c_str());
-      if ( ! gdcm::DirList::IsDirectory(dirNameout) ) // be sure it worked
+      if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirNameout) ) // be sure it worked
       {
           std::cout << "KO : not a dir : [" << dirNameout << "] (creation failure ?)" << std::endl;
       return 0;
@@ -207,9 +235,11 @@ int main(int argc, char *argv[])
    {
        std::cout << "Output Directory [" << dirNameout << "] already exists; Used as is." << std::endl;
    }
     
    std::string strDirNamein(dirNamein);
-   gdcm::DirList dirList(strDirNamein, true); // get recursively the list of files
+   GDCM_NAME_SPACE::DirList dirList(strDirNamein, true); // get recursively the list of files
    
    if (listonly)
    {
@@ -218,10 +248,10 @@ int main(int argc, char *argv[])
       std::cout << std::endl;
    }
    
-   gdcm::DirListType fileNames;
+   GDCM_NAME_SPACE::DirListType fileNames;
    fileNames = dirList.GetFilenames();
-   gdcm::SerieHelper *s;              // Needed only to may use SerieHelper::AddSeriesDetail()
-   s = gdcm::SerieHelper::New();
+   GDCM_NAME_SPACE::SerieHelper *s;              // Needed to use SerieHelper::AddSeriesDetail()
+   s = GDCM_NAME_SPACE::SerieHelper::New();
 
    std::string token = "%%%"; // Hope it's enough!
 /*       
@@ -232,22 +262,33 @@ int main(int argc, char *argv[])
    s->Print();
 */
   
-   gdcm::File *f;
-   gdcm::FileHelper *fh;
+   GDCM_NAME_SPACE::File *f;
+   GDCM_NAME_SPACE::FileHelper *fh;
    std::vector<std::string> tokens;
    std::vector<std::string> tokensForFileName;
+   
+   // For Siemens pb, we need Manufacturer's Model Name
+   // (We read only the first file, to know)   
+   GDCM_NAME_SPACE::DirListType::iterator it1 = fileNames.begin();
+   f = GDCM_NAME_SPACE::File::New();
+   f->SetLoadMode(GDCM_NAME_SPACE::LD_ALL);
+   f->SetFileName( *it1 );
+   f->Load();
+   std::string modelName = f->GetEntryString(0x0008,0x1090);
+   f->Delete();   
+   
 /*   
    std::cout << "---------------Print Unique Series identifiers---------"  
              << std::endl;     
    std::string uniqueSeriesIdentifier;
  
-   for (gdcm::DirListType::iterator it) = fileNames.begin();  
+   for (GDCM_NAME_SPACE::DirListType::iterator it) = fileNames.begin();  
                                     it != fileNames.end();
                                   ++it)
    {
       std::cout << "File Name : " << *it << std::endl;
-      f = gdcm::File::New();
-      f->SetLoadMode(gdcm::LD_ALL);
+      f = GDCM_NAME_SPACE::File::New();
+      f->SetLoadMode(GDCM_NAME_SPACE::LD_ALL);
       f->SetFileName( *it );
       f->Load();
         
@@ -261,27 +302,31 @@ int main(int argc, char *argv[])
    if (verbose)
       std::cout << "------------------Print Break levels-----------------" << std::endl;
 
-   std::string userFileIdentifier; 
+   std::string userFileIdentifier;
    SortedFiles sf;
 
    s->AddSeriesDetail(0x0010, 0x0010, false); // Patient's Name
-   s->AddSeriesDetail(0x0020, 0x000e, false); // Series Instance UID
-   s->AddSeriesDetail(0x0020, 0x0032, false); // Image Position (Patient)     
-   s->AddSeriesDetail(0x0018, 0x1060, true);  // Trigger Time (true: convert to keep numerical order)
-   s->AddSeriesDetail(0x0018, 0x1312, false); // In-plane Phase Encoding Direction 
+   // for Siemens TrioTim, don't deal with 'Series Instance UID'
+   if ( !GDCM_NAME_SPACE::Util::DicomStringEqual(modelName,"TrioTim") )
+      s->AddSeriesDetail(0x0020, 0x000e, false); // Series Instance UID
+   else
+      s->AddSeriesDetail(0x9999, 0x9999, false); // dirty trick to ignore 'Series Instance UID'
+      s->AddSeriesDetail(0x0020, 0x0032, false); // Image Position (Patient)
+      s->AddSeriesDetail(0x0018, 0x1060, true);  // Trigger Time (true: convert to keep numerical order)
+      s->AddSeriesDetail(0x0018, 0x1312, false); // In-plane Phase Encoding Direction
+      s->AddSeriesDetail(0x0008, 0x103e, false); // Series Description (special Siemens ...)
 
    //uint8_t *imageData; // Useless : pixels will not be loaded 
                          //          (images are overwritten)
          
-   for (gdcm::DirListType::iterator it = fileNames.begin();  
+   for (GDCM_NAME_SPACE::DirListType::iterator it = fileNames.begin();  
                                     it != fileNames.end();
                                   ++it)
    {
-      f = gdcm::File::New();
+      f = GDCM_NAME_SPACE::File::New();
       f->SetLoadMode(loadMode);
       f->SetFileName( *it );
       f->Load();
-      
 
       std::string strSeriesNumber;
       int seriesNumber;
@@ -290,7 +335,7 @@ int main(int argc, char *argv[])
       // keep only requested Series      
       bool keep = false;
       if (nbSeriesToKeep != 0)
-      {     
+      {
          strSeriesNumber = f->GetEntryString(0x0020, 0x0011 );
          seriesNumber = atoi( strSeriesNumber.c_str() );
          for (j=0;j<nbSeriesToKeep; j++)
@@ -326,38 +371,51 @@ int main(int argc, char *argv[])
            f->Delete();
            continue;
         }
-      }      
+      }
 
-      userFileIdentifier=s->CreateUserDefinedFileIdentifier(f); 
+      userFileIdentifier=s->CreateUserDefinedFileIdentifier(f);
       tokens.clear();
-      gdcm::Util::Tokenize (userFileIdentifier, tokens, token); 
-   
+      GDCM_NAME_SPACE::Util::Tokenize (userFileIdentifier, tokens, token);
+
       int imageNum; // Within FileName
       char newName[1024];
-      
-      if ( tokens[3] == "gdcmUnfound")  // sometimes Trigger Time is not found. CreateUserDefinedFileIdentifier is not aware of the pb.
+
+      // sometimes Trigger Time is not found.
+      // CreateUserDefinedFileIdentifier is not aware of the pb.
+      // We use File name instead (hope it's significant)
+
+      if ( tokens[IND_TriggerTime] == GDCM_NAME_SPACE::GDCM_UNFOUND)
       {
          ///this is a trick to build up a lexicographical compliant name :
          ///     eg : fich001.ima vs fich100.ima as opposed to fich1.ima vs fich100.ima
-         std::string name = gdcm::Util::GetName( *it );
+         std::string name = GDCM_NAME_SPACE::Util::GetName( *it );
          if (hasSkel)
          {
-            gdcm::Util::Tokenize (name, tokensForFileName, skel);
+            GDCM_NAME_SPACE::Util::Tokenize (name, tokensForFileName, skel);
             imageNum = atoi ( tokensForFileName[0].c_str() );
             // probabely we could write something much more complicated using C++ !
             sprintf (newName, "%s%06d%s", skel, imageNum, extent);
-            tokens[3] = newName;
+            tokens[IND_TriggerTime] = newName;
             tokensForFileName.clear();    
          }
          else
-            tokens[3] = name;
+            tokens[IND_TriggerTime] = name;
+
+         // Patient's Name
+         // Series Instance UID
+         // Image Position (Patient)
+         // Trigger Time
+         // In-plane Phase Encoding Direction
+         // Series Description
+         // FileName
  
-         userFileIdentifier = tokens[0] + token + tokens[1] + token + tokens[2] + token 
-                    + tokens[3] + token + tokens[4] + token;
-      }   
+         userFileIdentifier = tokens[IND_PatientName] + token + tokens[IND_SerieInstanceUID] + token + tokens[IND_ImagePosition] + token 
+                    + tokens[IND_TriggerTime] + token + tokens[IND_PhaseEncodingDirection] + token + tokens[IND_seriesDescription] + token
+                    + tokens[IND_FileName] + token;
+      }
+         
       if (verbose) 
-         std::cout << "[" << userFileIdentifier  << "]" << std::endl;
+         std::cout << "[" << userFileIdentifier  << "] : " << *it << std::endl;
                
       // storing in a map ensures automatic sorting !      
       sf[userFileIdentifier] = f;
@@ -373,7 +431,8 @@ int main(int argc, char *argv[])
    std::string previousPhaseEncodingDirection, currentPhaseEncodingDirection;
    std::string previousTriggerTime, currentTriggerTime;
    
-   std::string currentStudyUID;   
+   std::string currentStudyUID;
+   std::string seriesDescription;  
       
    std::string writeDir, currentWriteDir;
    std::string currentPatientWriteDir, currentSerieWriteDir, 
@@ -382,7 +441,7 @@ int main(int argc, char *argv[])
    std::string fullWriteFilename;
    std::string strExtent(extent); 
            
-   writeDir = gdcm::Util::NormalizePath(dirNameout);     
+   writeDir = GDCM_NAME_SPACE::Util::NormalizePath(dirNameout);     
    SortedFiles::iterator it2;
  
    previousPatientName            = "";
@@ -397,45 +456,61 @@ int main(int argc, char *argv[])
        frameIndex = 0;
    else
        frameIndex = 1;
-              
+      
    int flag       = 0;
        
-   gdcm::File *currentFile;
+   GDCM_NAME_SPACE::File *currentFile;
+
+   std::string defaultStudyUID =  GDCM_NAME_SPACE::Util::CreateUniqueUID();
+   std::string defaultSerieUID;
 
-   std::string defaultStudyUID =  gdcm::Util::CreateUniqueUID();
-   std::string defaultSerieUID; 
-     
    for (it2 = sf.begin() ; it2 != sf.end(); ++it2)
    {  
       currentFile = it2->second;
        
       fullFilename =  currentFile->GetFileName();
-      lastFilename =  gdcm::Util::GetName( fullFilename ); 
-      std::cout << " --------------------------------------------------"
-                << " Rewrite [" <<lastFilename << "]" << std::endl;
+      lastFilename =  GDCM_NAME_SPACE::Util::GetName( fullFilename );
+      if (verbose) 
+      std::cout <<" ------------------------------------------------------------------------------" 
+                << std::endl << " Deal with [" << it2->first << "] : ["<<fullFilename << "]" 
+                << std::endl;
      
       tokens.clear();
-      gdcm::Util::Tokenize (it2->first, tokens, token);
-      
-      currentPatientName            = tokens[0];
-      currentSerieInstanceUID       = tokens[1];
-      currentImagePosition          = tokens[2];
-      currentTriggerTime            = tokens[3];
-      currentPhaseEncodingDirection = tokens[4]; 
+      GDCM_NAME_SPACE::Util::Tokenize (it2->first, tokens, token);
+   
+      currentPatientName            = tokens[IND_PatientName];
+      currentSerieInstanceUID       = tokens[IND_SerieInstanceUID];
+      currentImagePosition          = tokens[IND_ImagePosition];
+      currentTriggerTime            = tokens[IND_TriggerTime];
+      currentPhaseEncodingDirection = tokens[IND_PhaseEncodingDirection];
+      seriesDescription             = tokens[IND_seriesDescription];  // For Siemens pb
 
       if ( currentImagePosition[0] == '-')
           currentImagePosition[0] = 'M';
       if ( currentImagePosition[0] == '+')
           currentImagePosition[0] = 'P'; 
-      
+
+      // Add a default ImagePositionPatient to avoid confusion at post processing time
+      if ( currentFile->GetEntryString(0x0020,0x0032) == GDCM_NAME_SPACE::GDCM_UNFOUND && 
+           currentFile->GetEntryString(0x0020,0x0030) == GDCM_NAME_SPACE::GDCM_UNFOUND )
+      {
+         currentFile->InsertEntryString("0.\\0.\\0.",0x0020, 0x0032, "DS" );
+      }
+
+      // Add a default ImageOrientationPatient to avoid confusion at post processing time
+      if ( currentFile->GetEntryString(0x0020,0x0037) == GDCM_NAME_SPACE::GDCM_UNFOUND && 
+           currentFile->GetEntryString(0x0020,0x0035) == GDCM_NAME_SPACE::GDCM_UNFOUND )
+      {
+         currentFile->InsertEntryString("1.\\0.\\0.\\0.\\1.\\0.",0x0020, 0x0037, "DS" );
+      }
+
       if (previousPatientName != currentPatientName)
       {      
-         if ( currentFile->GetEntryString(0x0020,0x000d) == gdcm::GDCM_UNFOUND)
+         if ( currentFile->GetEntryString(0x0020,0x000d) == GDCM_NAME_SPACE::GDCM_UNFOUND) // Study UID
          {
             if (verbose)   
                std::cout << "--- new  Study UID created" << std::endl;
-            defaultStudyUID =  gdcm::Util::CreateUniqueUID();
-            currentFile->InsertEntryString(defaultStudyUID, 0x0020, 0x000d, "UI" );
+            defaultStudyUID =  GDCM_NAME_SPACE::Util::CreateUniqueUID();
          }
   
          previousPatientName = currentPatientName;
@@ -449,7 +524,7 @@ int main(int argc, char *argv[])
          previousPhaseEncodingDirection = ""; //currentPhaseEncodingDirection;
   
          currentPatientWriteDir = writeDir + currentPatientName;
-         //if ( ! gdcm::DirList::IsDirectory(currentPatientWriteDir) )
+         //if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(currentPatientWriteDir) )
            {
               systemCommand   = "mkdir " + currentPatientWriteDir;
               if (verbose)
@@ -457,24 +532,28 @@ int main(int argc, char *argv[])
               system ( systemCommand.c_str() );
          }
       }
+      currentFile->InsertEntryString(defaultStudyUID, 0x0020, 0x000d, "UI" );
+      
+
+      if ( GDCM_NAME_SPACE::Util::DicomStringEqual(modelName,"TrioTim") ) // for Siemens TrioTim , don't deal with 'Series Instance UID'
 
       if (previousSerieInstanceUID != currentSerieInstanceUID)
       {        
-         if (verbose)   
+         if (verbose)
             std::cout << "==== === new Serie [" << currentSerieInstanceUID << "]"
                       << std::endl;
       
-         if ( currentFile->GetEntryString(0x0020,0x000e) == gdcm::GDCM_UNFOUND)
+         if ( currentFile->GetEntryString(0x0020,0x000e) == GDCM_NAME_SPACE::GDCM_UNFOUND)
          {
             if (verbose)   
                std::cout << "--- --- new  Serie UID created" << std::endl;
-            defaultSerieUID =  gdcm::Util::CreateUniqueUID();
-            currentFile->InsertEntryString(defaultSerieUID, 0x0020, 0x000e, "UI" );
-         }       
-      
+            defaultSerieUID =  GDCM_NAME_SPACE::Util::CreateUniqueUID();
+           // currentFile->InsertEntryString(defaultSerieUID, 0x0020, 0x000e, "UI" );
+         }
+
          if (split)
          {
-             currentSerieWriteDir  = currentPatientWriteDir + gdcm::GDCM_FILESEPARATOR
+             currentSerieWriteDir  = currentPatientWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
                              + currentSerieInstanceUID;
              systemCommand   = "mkdir " + currentSerieWriteDir;  
              system (systemCommand.c_str());
@@ -483,7 +562,10 @@ int main(int argc, char *argv[])
          previousImagePosition          = ""; //currentImagePosition;
          previousPhaseEncodingDirection = ""; //currentPhaseEncodingDirection;
       }
-
+      currentFile->InsertEntryString(defaultSerieUID, 0x0020, 0x000e, "UI" );
+            
+      // end of modelName != "TrioTim "
+   
       if (previousImagePosition != currentImagePosition)
       {
          frameIndex = 1;
@@ -493,7 +575,7 @@ int main(int argc, char *argv[])
                       << std::endl;
          if (split)
          {
-             currentPositionWriteDir  = currentSerieWriteDir + gdcm::GDCM_FILESEPARATOR
+             currentPositionWriteDir  = currentSerieWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
                              + currentImagePosition;
              systemCommand   = "mkdir " + currentPositionWriteDir;     
              system (systemCommand.c_str()); 
@@ -505,38 +587,32 @@ int main(int argc, char *argv[])
          else
             sliceIndex += 1;
       }
-      if (verbose)
-         std::cout << "Slice Index : " << sliceIndex << std::endl;      
 
 // We don't split on Row/Column!
 /*
       if (previousPhaseEncodingDirection != currentPhaseEncodingDirection)
       {        
-         if (verbose)   
+         if (verbose)
             std::cout << "==== === === === new PhaseEncodingDirection [" 
                       << currentPhaseEncodingDirection  << "]" << std::endl;
       
          if (split)
          {
              currentPhaseEncodingDirectionWriteDir  = currentPositionWriteDir 
-                             + gdcm::GDCM_FILESEPARATOR
+                             + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
                              + currentPhaseEncodingDirection;
              systemCommand   = "mkdir " + currentPhaseEncodingDirectionWriteDir;     
-             system (systemCommand.c_str());     
-         }      
-    
+             system (systemCommand.c_str());
+         }
+
          previousPhaseEncodingDirection = currentPhaseEncodingDirection;
-      } 
-*/    
-      
-      if (verbose)
-         std::cout << "--- --- --- --- --- " << (it2->second)->GetFileName() 
-                   << std::endl;
+      }
+*/
    
-      if ( gdcm::Debug::GetDebugFlag())
+      if ( GDCM_NAME_SPACE::Debug::GetDebugFlag())
          std::cout << "--- --- --- --- --- " << it2->first << "  " 
                    << (it2->second)->GetFileName() << " " 
-                   << gdcm::Util::GetName( fullFilename ) << std::endl;           
+                   << GDCM_NAME_SPACE::Util::GetName( fullFilename ) << std::endl;           
       
       // Transform the image to be 'Brucker-Like'
       // ----------------------------------------   
@@ -557,22 +633,52 @@ int main(int argc, char *argv[])
       // Deal with 0x0020, 0x0012 : 'SESSION INDEX'  (Acquisition Number)
       std::string chSessionIndex;
       // CLEANME
-      if (taggrid) 
+
+      if (taggrid)
+      { 
          chSessionIndex = "1";
+      }
       else
       {
-         if (currentPhaseEncodingDirection == "COL" || currentPhaseEncodingDirection == "COL " || currentPhaseEncodingDirection == " COL")
-            chSessionIndex = "1";
-         else if (currentPhaseEncodingDirection == "ROW" || currentPhaseEncodingDirection == "ROW "|| currentPhaseEncodingDirection == " ROW")
-            chSessionIndex = "2"; 
-         else
+      /* for SIEMENS MRI :
+        D 0008|1090 [LO] [Manufacturer's Model Name ] [Triotim ]
+        we have to deal with :
+     
+        D 0008|103e [LO]  [Series Description ] [fl2d9_line PA 15 90deg] or anything that contains '90' !
+        D 0008|103e [LO]  [Series Description ] [fl2d9_line PA 15 0deg ]
+        (everything is flagged as 'ROW')
+      */  
+
+         if ( GDCM_NAME_SPACE::Util::DicomStringEqual(modelName,"TrioTim") )  
+         {
+            if (seriesDescription.find("90", 0) != std::string::npos)
+               chSessionIndex = "1";  // 90 deg -> COL
+            else if (seriesDescription.find("0", 0)!= std::string::npos)
+               chSessionIndex = "2";  // 0 deg -> ROW
+            else
+            {
+               std::cout << "====================== seriesDescription doesn't contain"
+                         << " neither '90' nor '0' (?!?) : ["
+                         << seriesDescription << "]" << std::endl;
+               chSessionIndex = "1";
+            }    
+         } 
+         else  // for all other 'normal' cases
          {
-            std::cout << "====================== PhaseEncodingDirection "
-                      << " neither COL nor ROW (?!?) : [ "
-                      << currentPhaseEncodingDirection << "]" << std::endl;
-            chSessionIndex = "1";
+            if (currentPhaseEncodingDirection == "COL" || currentPhaseEncodingDirection == "COL " || currentPhaseEncodingDirection == " COL")
+               chSessionIndex = "1";
+            else if (currentPhaseEncodingDirection == "ROW" || currentPhaseEncodingDirection == "ROW "|| currentPhaseEncodingDirection == " ROW")
+               chSessionIndex = "2"; 
+            else
+            {
+               std::cout << "====================== PhaseEncodingDirection "
+                         << " neither COL nor ROW (?!?) : [ "
+                         << currentPhaseEncodingDirection << "]" << std::endl;
+               chSessionIndex = "1";
+            }
          }
       }
+      
       if (currentFile->IsVRCoherent(0x0020) == 1 )     
          currentFile->InsertEntryString(chSessionIndex, 0x0020, 0x0012, "  ");
       else
@@ -594,11 +700,16 @@ int main(int argc, char *argv[])
         stringVR = "IS";
   
       currentFile->InsertEntryString(strChSliceIndex, 0x0021, 0x1020, stringVR);
-      currentFile->InsertEntryString(chFrameIndex,    0x0021, 0x1040, stringVR); 
+      currentFile->InsertEntryString(chFrameIndex,    0x0021, 0x1040, stringVR);
+      
+      if (verbose) {     
+         std::cout << "0x0021, 0x1020 : strChSliceIndex " << strChSliceIndex << std::endl;
+         std::cout << "0x0021, 0x1040 : chFrameIndex  "   << chFrameIndex    << std::endl; 
+         std::cout << "0x0020, 0x0012 : chSessionIndex "  << chSessionIndex  << std::endl; 
+      }
+        
       std::string strImagePositionPatient    = currentFile->GetEntryString(0x0020, 0x0032 );
-      if (strImagePositionPatient == gdcm::GDCM_UNFOUND)
+      if (strImagePositionPatient == GDCM_NAME_SPACE::GDCM_UNFOUND)
       {
          if (verbose)
             std::cout << "Duplicate ImagePosition into ImagePositionPatient" << std::endl;
@@ -606,14 +717,14 @@ int main(int argc, char *argv[])
       }  
       
       std::string strImageOrientationPatient = f->GetEntryString(0x0020, 0x0037 );
-      if (strImageOrientationPatient == gdcm::GDCM_UNFOUND)
+      if (strImageOrientationPatient == GDCM_NAME_SPACE::GDCM_UNFOUND)
       {
          if (verbose)
-            std::cout << "Duplicate ImageOrientation into ImageOrientationPatient" << std::endl;      
+            std::cout << "Duplicate ImageOrientation into ImageOrientationPatient" << std::endl;          
          currentFile->InsertEntryString(currentFile->GetEntryString(0x0020, 0x0035), 0x0020, 0x0037, "DS" );       
       }
-                
-      if (taggrid)
+       
+      if (taggrid  || strcmp(input, "IDO")==0 || strcmp(input, "ido")==0 )
          frameIndex++;
       else     
       {     
@@ -627,44 +738,39 @@ int main(int argc, char *argv[])
             flag = 0;
          }
       } 
-      if (verbose)
-         std::cout << "Frame Index : " << frameIndex << std::endl; 
                  
       if (split)
       
-         //fullWriteFilename = currentPhaseEncodingDirectionWriteDir + gdcm::GDCM_FILESEPARATOR 
+         //fullWriteFilename = currentPhaseEncodingDirectionWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR 
          //                                + lastFilename + strExtent;      
-         fullWriteFilename = currentPositionWriteDir + gdcm::GDCM_FILESEPARATOR 
+         fullWriteFilename = currentPositionWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR 
                                          + lastFilename + strExtent; 
       else
-         fullWriteFilename = currentPatientWriteDir + gdcm::GDCM_FILESEPARATOR 
+         fullWriteFilename = currentPatientWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR 
                                          + lastFilename + strExtent; 
-      
-      /*           
-      systemCommand  = "cp " + fullFilename + " " + fullWriteFilename;
-      std::cout << systemCommand << std::endl;
-      system (  systemCommand.c_str() );
-      */
             
       // Load the pixels in RAM.    
       
-      fh = gdcm::FileHelper::New(currentFile);     
+      fh = GDCM_NAME_SPACE::FileHelper::New(currentFile);     
       uint8_t *imageData = fh->GetImageDataRaw(); // Don't convert (Gray Pixels + LUT) into (RGB pixels) ?!?
-      fh->SetWriteTypeToDcmExplVR();
-      // We didn't modify pixels -> keep unchanged the following :
+      fh->SetWriteTypeToDcmExplVR();     
+      
+      if (rubout) {
+         // Put to Black the burnt-in number.
+         nX = currentFile->GetXSize();
+         nY = currentFile->GetYSize();
+         for(int y=nY-15; y<nY; y++)
+            for(int x=nX/3; x<nX/2+50; x++)
+              imageData[ y*nX*2 + x ] = 0;
+      }
+      
+      // We didn't make any computation on the pixels -> keep unchanged the following :
       // 'Media Storage SOP Class UID' (0x0002,0x0002)
       // 'SOP Class UID'               (0x0008,0x0016)
       // 'Image Type'                  (0x0008,0x0008)
-      // 'Conversion Type'             (0x0008,0x0064)
+      // 'Conversion Type'             (0x0008,0x0064)        
+      fh->SetContentType(GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE);
       
-      // Put to Black the burnt-in number.
-      nX = currentFile->GetXSize();
-      nY = currentFile->GetYSize();
-      for(int y=nY-15; y<nY; y++)
-         for(int x=nX/3; x<nX/2+50; x++)
-           imageData[ y*nX*2 + x ] = 0;   
-        
-      fh->SetContentType(gdcm::UNMODIFIED_PIXELS_IMAGE);
       if (!fh->Write(fullWriteFilename))
       {
          std::cout << "Fail to write :[" << fullWriteFilename << "]"
@@ -674,3 +780,4 @@ int main(int argc, char *argv[])
    }
    return 0;
  }
+