]> Creatis software - gdcm.git/blobdiff - Example/ToInTag.cxx
ENH: add new types for CSA siemens stuff
[gdcm.git] / Example / ToInTag.cxx
index 119779d11bfd39ecd50da686a05b454aea94800e..f7e18ec8fb1019db38bcdae622fd9de42aaedc55 100755 (executable)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: ToInTag.cxx,v $
   Language:  C++
-  Date:      $Date: 2007/06/22 11:01:57 $
-  Version:   $Revision: 1.14 $
+  Date:      $Date: 2007/07/04 17:39:28 $
+  Version:   $Revision: 1.17 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -83,9 +83,9 @@ int main(int argc, char *argv[])
    "                  {  [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                                ",
@@ -97,6 +97,7 @@ int main(int argc, char *argv[])
    "        e.g : 1030,1035,1043                                              ", 
    " 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                                                         ",
@@ -104,6 +105,7 @@ int main(int argc, char *argv[])
    "        --- Position                                                      ",
    "        ---- 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                           ",
@@ -147,7 +149,9 @@ int main(int argc, char *argv[])
    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;
@@ -168,6 +172,7 @@ int main(int argc, char *argv[])
       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() )
@@ -351,7 +356,7 @@ int main(int argc, char *argv[])
            f->Delete();
            continue;
         }
-      }      
+      } 
 
       userFileIdentifier=s->CreateUserDefinedFileIdentifier(f); 
       tokens.clear();
@@ -360,7 +365,7 @@ int main(int argc, char *argv[])
       int imageNum; // Within FileName
       char newName[1024];
       
-      if ( tokens[3] == "gdcmUnfound")  // sometimes Trigger Time is not found. CreateUserDefinedFileIdentifier is not aware of the pb.
+      if ( tokens[3] == GDCM_NAME_SPACE::GDCM_UNFOUND)  // sometimes Trigger Time is not found. CreateUserDefinedFileIdentifier is not aware of the pb.
       {
          ///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
@@ -377,10 +382,18 @@ int main(int argc, char *argv[])
          else
             tokens[3] = 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 + tokens[5] + token;
-      }   
+                    + tokens[3] + token + tokens[4] + token + tokens[5] + token +  tokens[6] + token;
+      }
+         
       if (verbose) 
          std::cout << "[" << userFileIdentifier  << "] : " << *it << std::endl;
                
@@ -473,12 +486,11 @@ int main(int argc, char *argv[])
       
       if (previousPatientName != currentPatientName)
       {      
-         if ( currentFile->GetEntryString(0x0020,0x000d) == GDCM_NAME_SPACE::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_NAME_SPACE::Util::CreateUniqueUID();
-            currentFile->InsertEntryString(defaultStudyUID, 0x0020, 0x000d, "UI" );
          }
   
          previousPatientName = currentPatientName;
@@ -500,6 +512,8 @@ 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'
 
@@ -514,7 +528,7 @@ int main(int argc, char *argv[])
             if (verbose)   
                std::cout << "--- --- new  Serie UID created" << std::endl;
             defaultSerieUID =  GDCM_NAME_SPACE::Util::CreateUniqueUID();
-            currentFile->InsertEntryString(defaultSerieUID, 0x0020, 0x000e, "UI" );
+           // currentFile->InsertEntryString(defaultSerieUID, 0x0020, 0x000e, "UI" );
          }       
       
          if (split)
@@ -528,6 +542,8 @@ int main(int argc, char *argv[])
          previousImagePosition          = ""; //currentImagePosition;
          previousPhaseEncodingDirection = ""; //currentPhaseEncodingDirection;
       }
+      currentFile->InsertEntryString(defaultSerieUID, 0x0020, 0x000e, "UI" );
+            
       // end of modelName != "TrioTim "
    
       if (previousImagePosition != currentImagePosition)
@@ -687,8 +703,8 @@ int main(int argc, char *argv[])
             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     
       {     
@@ -719,13 +735,15 @@ int main(int argc, char *argv[])
       uint8_t *imageData = fh->GetImageDataRaw(); // Don't convert (Gray Pixels + LUT) into (RGB pixels) ?!?
       fh->SetWriteTypeToDcmExplVR();     
       
-      // 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;
-
+      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)