]> Creatis software - gdcm.git/blobdiff - Example/PhilipsToBrucker.cxx
Replace deprecated InsertValEntryString method by InsertEntryString()
[gdcm.git] / Example / PhilipsToBrucker.cxx
index 6991deecb918364e04e01e340ccbc342afdc753a..a1cbe760c4ca4ff6492046818e8c62d46d797d71 100755 (executable)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: PhilipsToBrucker.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/12/22 16:23:02 $
-  Version:   $Revision: 1.3 $
+  Date:      $Date: 2006/01/26 15:52:42 $
+  Version:   $Revision: 1.6 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -36,7 +36,7 @@
   *            according to their Patient/Study/Serie/Image characteristics
   *          - fills a single level Directory with *all* the files,
   *            converted into a Brucker-like Dicom, Intags compliant
-  *          
+  * 
   */  
 
 typedef std::map<std::string, gdcm::File*> SortedFiles;
@@ -92,11 +92,11 @@ int main(int argc, char *argv[])
       return 0;
    }
 
-   char *dirNamein;   
-   dirNamein  = am->ArgMgrGetString("dirin",(char *)"."); 
+   const char *dirNamein;
+   dirNamein  = am->ArgMgrGetString("dirin","."); 
 
-   char *dirNameout;   
-   dirNameout  = am->ArgMgrGetString("dirout",(char *)".");  
+   const char *dirNameout;   
+   dirNameout  = am->ArgMgrGetString("dirout",".");  
    
    int loadMode = gdcm::LD_ALL;
    if ( am->ArgMgrDefined("noshadowseq") )
@@ -126,7 +126,7 @@ int main(int argc, char *argv[])
       return 0;         
    }
    
-   char *extent  = am->ArgMgrGetString("extent",".DCM");
+   const char *extent  = am->ArgMgrGetString("extent",".DCM");
         
    // if unused Param we give up
    if ( am->ArgMgrPrintUnusedLabels() )
@@ -141,33 +141,48 @@ int main(int argc, char *argv[])
    
    if ( ! gdcm::DirList::IsDirectory(dirNamein) )
    {
-      std::cout << "not a directory : [" << dirNamein << "]" << std::endl;
+      std::cout << "KO : [" << dirNamein << "] is not a Directory : " << std::endl;
       exit(0);
    }
+   else
+   {
+      std::cout << "OK : [" << dirNamein << "]" << " is a Directory" << std::endl;
+   }
+
+
    std::string systemCommand;
-   if ( ! gdcm::DirList::IsDirectory(dirNameout) ) // dirout not found
+   if ( ! gdcm::DirList::IsDirectory(dirNameout) )     // dirout not found
    {
-      std::string strDirNameout(dirNameout); // to please gcc 4
-      systemCommand = "mkdir " +strDirNameout;      // create it!
+      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
       {
-          std::cout << "not a dir : [" << dirNameout << "]" << std::endl;
+          std::cout << "KO : not a dir : [" << dirNameout << "] (creation failure ?)" << std::endl;
           exit(0);
       }
+      else
+     {
+        std::cout << "Directory [" << dirNameout << "]" << " created" << std::endl;
+     }
+   }
+   else
+   {
+       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
    
- /*  
+/*   
    std::cout << "---------------List of found files ------------" << std::endl;
    dirList.Print();
  */   
 
    gdcm::DirListType fileNames;
    fileNames = dirList.GetFilenames();
-   gdcm::SerieHelper *s;     // Needed only to may use SerieHelper::AddSeriesDetail()
+   gdcm::SerieHelper *s;              // Needed only to may use SerieHelper::AddSeriesDetail()
    s = gdcm::SerieHelper::New();
 
 /*       
@@ -180,7 +195,7 @@ int main(int argc, char *argv[])
   
    gdcm::File *f;
    gdcm::FileHelper *fh;
-/*    
+/*   
    std::cout << "---------------Print Unique Series identifiers---------"  
              << std::endl;     
    std::string uniqueSeriesIdentifier;
@@ -243,7 +258,10 @@ int main(int argc, char *argv[])
             }
          }
          if ( !keep)
-            continue; 
+         {
+            f->Delete();
+            continue;
+         } 
       }
       // drop all unrequested Series
       bool drop = false;
@@ -254,13 +272,16 @@ int main(int argc, char *argv[])
          for (j=0;j<nbSeriesToDrop; j++)
          {
             if(seriesNumber == seriesToDrop[j])
-            { 
+            {
                drop = true;
                break;
             }
         }
         if (drop)
+        {
+           f->Delete();
            continue;
+        }
       }      
 
       userFileIdentifier=s->CreateUserDefinedFileIdentifier(f);        
@@ -323,6 +344,8 @@ int main(int argc, char *argv[])
          if ( ! gdcm::DirList::IsDirectory(currentWriteDir) )
            {
               systemCommand   = "mkdir " + currentWriteDir;
+              if (verbose)
+                 std::cout << systemCommand << std::endl;
               system ( systemCommand.c_str() );
          }
       }
@@ -355,11 +378,13 @@ int main(int argc, char *argv[])
          previousPhaseEncodingDirection = currentPhaseEncodingDirection;
       }      
       frameIndex++; 
-      
       if (verbose)
+         std::cout << "--- --- --- --- --- " << (it2->second)->GetFileName() 
+                   << std::endl;
+      if ( gdcm::Debug::GetDebugFlag())
          std::cout << "--- --- --- --- --- " << it2->first << "  " 
                    << (it2->second)->GetFileName() << " " 
-                   << gdcm::Util::GetName( fullFilename ) <<std::endl;           
+                   << gdcm::Util::GetName( fullFilename ) << std::endl;           
       
       // Transform the image to be 'Brucker-Like'
       // ----------------------------------------   
@@ -393,19 +418,20 @@ int main(int argc, char *argv[])
       currentFile->InsertEntryString(chFrameIndex, 0x0021, 0x1040, "IS"); 
                     
       std::string strExtent(extent);
-      std::string fullWriteFilename = currentWriteDir + "/" + lastFilename + strExtent;
+      std::string fullWriteFilename = currentWriteDir + gdcm::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(f);     
-      fh->GetImageDataRaw(); // Don't convert Grey Pixels + LUT into RGB pixels (?!?)
+      // Load the pixels in RAM.      
+      
+      fh = gdcm::FileHelper::New(currentFile);     
+      fh->GetImageDataRaw(); // Don't convert (Gray Pixels + LUT) into (RGB pixels) ?!?
       fh->SetWriteTypeToDcmExplVR();
       fh->Write(fullWriteFilename);
-      fh->gdcm::FileHelper::Delete();          
+      fh->Delete();       
    }
  }