]> Creatis software - gdcm.git/commitdiff
Use Argument Manager in 'utilities'
authorjpr <jpr>
Tue, 7 Jun 2005 11:12:10 +0000 (11:12 +0000)
committerjpr <jpr>
Tue, 7 Jun 2005 11:12:10 +0000 (11:12 +0000)
Example/Anonymize.cxx [new file with mode: 0644]
Example/AnonymizeDicomDir.cxx
Example/CMakeLists.txt
Example/MakeDicomDir.cxx
Example/PrintDicomDir.cxx
Example/PrintFile.cxx
Example/ReWrite.cxx [new file with mode: 0644]

diff --git a/Example/Anonymize.cxx b/Example/Anonymize.cxx
new file mode 100644 (file)
index 0000000..5af051c
--- /dev/null
@@ -0,0 +1,146 @@
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: Anonymize.cxx,v $
+  Language:  C++
+  Date:      $Date: 2005/06/07 11:12:10 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
+                                                                                
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                                
+=========================================================================*/
+#include "gdcmFile.h"
+#include "gdcmFileHelper.h"
+#include "gdcmCommon.h"
+#include "gdcmDebug.h"
+
+#include "gdcmArgMgr.h"
+
+#include <iostream>
+
+int main(int argc, char *argv[])
+{
+   START_USAGE(usage)
+   " \n Anonymize :\n",
+   " Anonymize a full gdcm-readable Dicom image",
+   "          Warning : probably segfaults if pixels are not gdcm readable.",
+   "                    Use exAnonymizeNoLoad instead.",
+   " usage: Anonymize filein=inputFileName fileout=anonymizedFileName[debug] ",
+   "        debug    : user wants to run the program in 'debug mode' ",
+   FINISH_USAGE
+
+   // ----- Initialize Arguments Manager ------   
+   gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
+  
+   if (am->ArgMgrDefined("usage")) 
+   {
+      am->ArgMgrUsage(usage); // Display 'usage'
+      delete am;
+      return 0;
+   }
+   char *fileName = am->ArgMgrWantString("filein",usage);
+   if ( fileName == NULL )
+   {
+      delete am;
+      return 0;
+   }
+
+   char *outputFileName = am->ArgMgrWantString("fileout",usage);
+   if ( outputFileName == NULL )
+   {
+      delete am;
+      return 0;
+   }
+   if (am->ArgMgrDefined("debug"))
+      gdcm::Debug::DebugOn();
+   // if unused Param we give up
+   if ( am->ArgMgrPrintUnusedLabels() )
+   { 
+      am->ArgMgrUsage(usage);
+      delete am;
+      return 0;
+   }
+
+   delete am;  // we don't need Argument Manager any longer
+
+   // ============================================================
+   //   Read the input file.
+   // ============================================================
+
+   gdcm::File *f1;
+
+   f1 = new gdcm::File( fileName );
+   if (!f1->IsReadable()) 
+   {
+       std::cerr << "Sorry, " << fileName <<"  not a gdcm-readable "
+                 << "DICOM / ACR File" <<std::endl;
+       delete f1;  
+       return 0;
+   }
+   std::cout << " ... is readable " << std::endl;
+
+   // ============================================================
+   //   Load the pixels in memory.
+   // ============================================================
+
+   // We need a gdcm::FileHelper, since we want to load the pixels        
+   gdcm::FileHelper *fh1 = new gdcm::FileHelper(f1);
+
+   // (unit8_t DOESN'T mean it's mandatory for the image to be a 8 bits one) 
+
+   uint8_t *imageData = fh1->GetImageData();
+
+   if ( imageData == 0 )
+   {
+       std::cerr << "Sorry, Pixels of" << fileName <<"  are not "
+           << " gdcm-readable."       << std::endl
+                 << "Use exAnonymizeNoLoad" << std::endl;
+       delete f1;  
+       delete fh1;    
+       return 0;
+   } 
+
+   // ============================================================
+   //  Choose the fields to anonymize.
+   // ============================================================
+   // Institution name 
+   f1->AddAnonymizeElement(0x0008, 0x0080, "Xanadoo"); 
+   // Patient's name 
+   f1->AddAnonymizeElement(0x0010, 0x0010, "Fantomas");   
+   // Patient's ID
+   f1->AddAnonymizeElement( 0x0010, 0x0020,"1515" );   
+   // Study Instance UID
+   f1->AddAnonymizeElement(0x0020, 0x000d, "9.99.999.9999" );
+   // Telephone
+   f1->AddAnonymizeElement(0x0010, 0x2154, "3615" );
+
+   // Aware user will add more fields to anonymize here
+
+   // The gdcm::File is modified in memory
+
+   f1->AnonymizeFile();
+
+   // ============================================================
+   //   Write a new file
+   // ============================================================
+
+   fh1->WriteDcmExplVR(outputFileName);
+   std::cout <<"End Anonymize" << std::cout;
+
+   // ============================================================
+   //   Remove the Anonymize list
+   // ============================================================  
+   f1->ClearAnonymizeList();
+    
+   delete f1;
+   delete fh1; 
+   return 0;
+}
+
index 1c86608cd4f5d22b11861ab5b73318c1994d6fd9..424390b5ddc444c250747ff763b2bda29b294536 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: AnonymizeDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/03/09 19:15:04 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2005/06/07 11:12:10 $
+  Version:   $Revision: 1.2 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -27,6 +27,8 @@
 #include "gdcmDocument.h"
 #include "gdcmFile.h"
 
+#include "gdcmArgMgr.h"
+
 #include <iostream>
 
 void AnoNoLoad(gdcm::SQItem *s, std::fstream *fp, 
@@ -65,45 +67,49 @@ void AnoNoLoad(gdcm::SQItem *s, std::fstream *fp,
 }
 
 int main(int argc, char *argv[])
-{  
-   gdcm::File *f1;
-   gdcm::Debug::DebugOn();
-   std::cout << "------------------------------------------------" << std::endl;
-   std::cout << "Anonymize a gdcm-readable DICOMDIR   "            << std::endl;
-   std::cout << "even some Objects are not yet taken into account" << std::endl;
-   std::cout << "Warning : the DICOMDIR is overwritten"            << std::endl;
-   std::cout << "        : to preserve file integrity "
-             << " think unto using a copy .. "                     << std::endl;
+{ 
+
+   START_USAGE(usage)
+   " \n AnonymizeDicomDir :\n",
+   " Anonymize a gdcm-readable DICOMDIR ",
+   "           even when some 'Objects' are not yet taken into account",
+   "           Warning : the DICOMDIR is overwritten",
+   " usage: AnonymizeDicomDir filein=dicomDirName [debug] ",
+   "        debug    : user wants to run the program in 'debug mode' ",
+   FINISH_USAGE
+
+   // ----- Initialize Arguments Manager ------   
+   gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
+  
+   if (am->ArgMgrDefined("usage")) 
+   {
+      am->ArgMgrUsage(usage); // Display 'usage'
+      delete am;
+      return 0;
+   }
  
-   if( argc < 3 )
-    {
-    std::cerr << "Usage " << argv[0] << " DICOMDIR to anonymize  " 
-              << std::endl;
-    return 1;
-    }
+   char *fileName  = am->ArgMgrWantString("filein",usage); 
 
-   std::string fileName       = argv[1];
+   delete am;  // we don't need Argument Manager any longer
 
 // ============================================================
 //   Read the input DICOMDIR
 // ============================================================
 
-   std::cout << argv[1] << std::endl;
-
-   f1 = new gdcm::File( fileName );
+   gdcm::File *f1 = new gdcm::File( fileName );
    if (!f1->IsReadable()) {
        std::cerr << "Sorry, " << fileName <<"  not a gdcm-readable "
                  << "file" <<std::endl;
    }
    std::cout << " ... is readable " << std::endl;
 
-
    // Directory record sequence
    gdcm::DocEntry *e = f1->GetDocEntry(0x0004, 0x1220);
    if ( !e )
    {
       std::cout << "No Directory Record Sequence (0004,1220) found" <<std::endl;;
+      delete f1;
+      delete e;
       return 0;         
    }
    
@@ -111,11 +117,13 @@ int main(int argc, char *argv[])
    if ( !s )
    {
       std::cout << "Element (0004,1220) is not a Sequence ?!?" <<std::endl;
+      delete f1;
+      delete e;
       return 0;
    }
 
    // Open the file LTTG (aka ALAP)
-   std::fstream *fp = new std::fstream(fileName.c_str()
+   std::fstream *fp = new std::fstream(fileName, 
                               std::ios::in | std::ios::out | std::ios::binary);
    gdcm::DocEntry *d;
    std::string v;
@@ -165,8 +173,9 @@ int main(int argc, char *argv[])
    // Close the file ASAP
 
    fp->close();
+
    delete fp;
-    
+   delete e;   
    delete f1;
    return 0;
 }
index 58ec6c0a0b60444fa2834037446c84ed986ad9c9..b03bbe763b92926fe1cc2798724ee23f1cc4a975 100644 (file)
@@ -23,13 +23,15 @@ SET(EXAMPLE_SOURCES
   FindTags
   MakeDicomDir
   AnonymizeDicomDir # without loading it as a gdcm::DicomDir
-
+  Anonymize         # for full gdcm readable files
+  AnonymizeNoLoad   # without loading the Pixel Data 
+  ReWrite
+  
 #the following will be transformed into 'examples', or 'utilities'
 #              or will be removed
 #
 # Better you don't use them (not fully checked ...)
  
-  #test
   FlatHashTablePrint
   TestCopyDicom
   TestChangeHeader
index 0be2432f2f0cfe0337a1f681ddc29fe26a4f8ed8..72ff4ffa541ad43f61250daac6620f9a5c8295e9 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: MakeDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/06/03 15:40:53 $
-  Version:   $Revision: 1.3 $
+  Date:      $Date: 2005/06/07 11:12:10 $
+  Version:   $Revision: 1.4 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -21,6 +21,8 @@
 #include "gdcmDirList.h"
 #include "gdcmDebug.h"
 
+#include "gdcmArgMgr.h"
+
 #include <iostream>
 
 // ---
@@ -37,7 +39,7 @@ void EndMethod(void *toto) {
 
 /**
   * \ingroup Test
-  * \brief   Explores recursively the given directory (or GDCM_DATA_ROOT by default)
+  * \brief   Explores recursively the given directory
   *          orders the gdcm-readable found Files
   *          according their Patient/Study/Serie/Image characteristics
   *          makes the gdcmDicomDir 
@@ -46,46 +48,79 @@ void EndMethod(void *toto) {
 
 int main(int argc, char *argv[]) 
 {
-  // gdcm::Debug::DebugOn();
-   std::string dirName;   
-
-   if (argc > 1)
+   START_USAGE(usage)
+   " \n MakeDicomDir :\n",
+   " Explores recursively the given directory, makes the relevant DICOMDIR",
+   "          and writes it as 'NewDICOMDIR'",
+   " usage: MakeDicomDir dirname=rootDirectoryName [noshadow] [noseq] [debug] ",
+   "        noshadow : user doesn't want to load Private groups (odd number)",
+   "        noseq    : user doesn't want to load Sequences ",
+   "        debug    : user wants to run the program in 'debug mode' ",
+   FINISH_USAGE
+
+   // ----- Initialize Arguments Manager ------   
+   gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
+  
+   if (am->ArgMgrDefined("usage")) 
    {
-      dirName = argv[1];
+      am->ArgMgrUsage(usage); // Display 'usage'
+      delete am;
+      return 0;
    }
+
+   char *dirName;   
+   dirName  = am->ArgMgrGetString("dirName","."); 
+
+   int loadMode;
+   if ( am->ArgMgrDefined("noshadow") && am->ArgMgrDefined("noseq") )
+       loadMode = NO_SEQ | NO_SHADOW;  
+   else if ( am->ArgMgrDefined("noshadow") )
+      loadMode = NO_SHADOW;
+   else if ( am->ArgMgrDefined("noseq") )
+      loadMode = NO_SEQ;
    else
-   {
-      dirName = GDCM_DATA_ROOT;
+      loadMode = 0;
+
+   if (am->ArgMgrDefined("debug"))
+      gdcm::Debug::DebugOn();
+   // if unused Param we give up
+   if ( am->ArgMgrPrintUnusedLabels() )
+   { 
+      am->ArgMgrUsage(usage);
+      delete am;
+      return 0;
    }
 
+   delete am;  // we don't need Argument Manager any longer
+
+   // ----- Begin Processing -----
+
    gdcm::DicomDir *dcmdir;
-    // we ask for Directory parsing
-    // Old style (still available) :
-    // dcmdir = new gdcm::DicomDir(dirName, true);
 
-   // new style (user is allowed no to load Sequences an/or Shadow Groups)
+   // we ask for Directory parsing
+
    dcmdir = new gdcm::DicomDir( );
    dcmdir->SetParseDir(true);
-// some images have a wrong length for element 0x0000 of private groups
-//   dcmdir->SetLoadMode(NO_SEQ | NO_SHADOW);
-
-   dcmdir->SetLoadMode(NO_SEQ);
-   dcmdir->Load(dirName);
 
    dcmdir->SetStartMethod(StartMethod, (void *) NULL);
    dcmdir->SetEndMethod(EndMethod);
-   
+
+   dcmdir->SetLoadMode(loadMode);
+   dcmdir->Load(dirName);
+
+    // ----- Check the result
+    
    if ( !dcmdir->GetFirstPatient() ) 
    {
       std::cout << "makeDicomDir: no patient found. Exiting."
                 << std::endl;
-
       delete dcmdir;
       return 1;
    }
     
-   // Create the corresponding DicomDir
+   // ----- Create the corresponding DicomDir
+
    dcmdir->WriteDicomDir("NewDICOMDIR");
    delete dcmdir;
 
index 8d3f714e176dfc56a3b81d87aa5c33526fce92a8..e448c2a3e56b51b5526a17e6502ba4bb08908c8d 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: PrintDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/04/26 16:21:54 $
-  Version:   $Revision: 1.21 $
+  Date:      $Date: 2005/06/07 11:12:10 $
+  Version:   $Revision: 1.22 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 #include "gdcmTS.h"
 #include "gdcmDebug.h"
 
+#include "gdcmArgMgr.h"
+
 #include <fstream>
 #include <iostream>
 
 int main(int argc, char* argv[])
-{  
+{
+   START_USAGE(usage)
+   " \n PrintDicomDir :\n",
+   " Display the tree-like structure of a DICOMDIR File",
+   " usage: PrintDicomDir filein=fileName [level=n] [debug] ",
+   "        detail = 1 : Patients, 2 : Studies, 3 : Series, 4 : Images ",
+   "                 5 : Full Content ",
+   "        level = 0,1,2 : depending on user (what he wants to see)",
+   "        debug    : user wants to run the program in 'debug mode' ",
+   FINISH_USAGE
+
+   // Initialize Arguments Manager   
+   gdcm::ArgMgr *am= new gdcm::ArgMgr(argc, argv);
+  
+   if (argc == 1) 
+   {
+      am->ArgMgrUsage(usage); // Display 'usage'
+      delete am;
+      return 0;
+   }
+  
    gdcm::DicomDir *e1;
    gdcm::TSKey v;
 
@@ -38,19 +60,26 @@ int main(int argc, char* argv[])
    gdcm::DicomDirSerie *se;
    gdcm::DicomDirImage *im;
   
-   std::string fileName; 
-   if (argc > 1) 
-      fileName = argv[1];    
-   else 
-   {
-      fileName = GDCM_DATA_ROOT;
-      fileName += "/DICOMDIR";
-   }
+   char *fileName;
+   fileName  = am->ArgMgrWantString("filein",usage); 
+
+   int level  = am->ArgMgrGetInt("level", 2);
+
+   int detailLevel = am->ArgMgrGetInt("detail", 2);
 
-   if (argc > 3)
+   if (am->ArgMgrDefined("debug"))
       gdcm::Debug::DebugOn();
 
-   // new style is useless, since it has no effect fore *reading* a DICOMDIR
+   /* if unused Param we give up */
+   if ( am->ArgMgrPrintUnusedLabels() )
+   { 
+      am->ArgMgrUsage(usage);
+      delete e1;
+      delete am;
+      return 0;
+   } 
+
+   // new style is useless, since it has no effect for *reading* a DICOMDIR
    // (only meaningfull when *creating* a DICOMDIR)
 
    e1 = new gdcm::DicomDir( fileName );
@@ -70,12 +99,7 @@ int main(int argc, char* argv[])
       return 1;
    }
 
-   e1->SetPrintLevel(2);
-   int detailLevel;
-   if (argc > 2)
-      detailLevel = atoi(argv[2]);   
-   else
-      detailLevel = 3;
+   e1->SetPrintLevel(level);
 
    // Test if the DicomDir contains any Patient
    pa = e1->GetFirstPatient();
@@ -165,18 +189,23 @@ int main(int argc, char* argv[])
  
       pa = e1->GetFirstPatient(); 
       while ( pa ) {  // les PATIENT de ce DICOMDIR
-         std::cout << pa->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name
+       // Patient's Name, Patient ID 
+         std::cout << "Pat.Name:[" << pa->GetEntryValue(0x0010, 0x0010) <<"]"; // Patient's Name
+         std::cout << " Pat.ID:[";
+         std::cout << pa->GetEntryValue(0x0010, 0x0020) << "]" << std::endl; // Patient ID
 
          st = pa->GetFirstStudy();
          while ( st ) { // on degouline les STUDY de ce patient
-            std::cout << "--- "<< st->GetEntryValue(0x0008, 0x1030) << std::endl;    // Study Description
-            std::cout << " Stud.ID:["          << st->GetEntryValue(0x0020, 0x0010); // Study ID
+            std::cout << "--- Stud.descr:["    << st->GetEntryValue(0x0008, 0x1030) << "]";// Study Description 
+            std::cout << " Stud.ID:["          << st->GetEntryValue(0x0020, 0x0010);       // Study ID
+            std::cout << "]" << std::endl;
 
             se = st->GetFirstSerie();
             while ( se ) { // on degouline les SERIES de cette study
-               std::cout << "--- --- "<< se->GetEntryValue(0x0008, 0x103e) << std::endl;      // Serie Description
+               std::cout << "--- --- Ser.Descr:["<< se->GetEntryValue(0x0008, 0x103e)<< "]";  // Series Description
                std::cout << " Ser.nb:["         <<  se->GetEntryValue(0x0020, 0x0011);        // Series number
                std::cout << "] Mod.:["          <<  se->GetEntryValue(0x0008, 0x0060) << "]"; // Modality
+               std::cout << std::endl;    
 
                im = se->GetFirstImage();
                while ( im ) { // on degouline les Images de cette serie
index 5e01af3c9c6e366b2fce19a0267ce2a5020f8c08..0bf9ff33a7253a1d58f7ccc3fc7042b5f13e1a98 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: PrintFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/06/06 12:41:04 $
-  Version:   $Revision: 1.37 $
+  Date:      $Date: 2005/06/07 11:12:10 $
+  Version:   $Revision: 1.38 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -16,8 +16,8 @@
                                                                                 
 =========================================================================*/
 #include "gdcmFile.h"
-#include "gdcmDebug.h"
 #include "gdcmFileHelper.h"
+#include "gdcmDebug.h"
 
 #include "gdcmArgMgr.h"
 
@@ -36,51 +36,49 @@ int main(int argc, char *argv[])
    "        debug    : user wants to run the program in 'debug mode' ",
    FINISH_USAGE
 
-   gdcm::File *e1;
-   gdcm::FileHelper   *f1;
-   char *fileName;
-
    // Initialize Arguments Manager   
    gdcm::ArgMgr *am= new gdcm::ArgMgr(argc, argv);
   
-   if (argc == 1) 
+   if (argc == 1)
    {
       am->ArgMgrUsage(usage); // Display 'usage'
       delete am;
       return 0;
    }
 
-   fileName  = am->ArgMgrWantString("filein",usage);
-
-   if (am->ArgMgrDefined("debug"))
-      gdcm::Debug::DebugOn();
-
-   e1 = new gdcm::File();
+   char *fileName = am->ArgMgrWantString("filein",usage);
 
+   int loadMode;
    if ( am->ArgMgrDefined("noshadow") && am->ArgMgrDefined("noseq") )
-       e1->SetLoadMode(NO_SEQ | NO_SHADOW);  
+       loadMode = NO_SEQ | NO_SHADOW;  
    else if ( am->ArgMgrDefined("noshadow") )
-      e1->SetLoadMode(NO_SHADOW);
+      loadMode = NO_SHADOW;
    else if ( am->ArgMgrDefined("noseq") )
-      e1->SetLoadMode(NO_SEQ);
+      loadMode = NO_SEQ;
+   else
+      loadMode = 0;
 
    int level = am->ArgMgrGetInt("level", 2);
 
+   if (am->ArgMgrDefined("debug"))
+      gdcm::Debug::DebugOn();
+
    /* if unused Param we give up */
    if ( am->ArgMgrPrintUnusedLabels() )
    { 
       am->ArgMgrUsage(usage);
-      delete e1;
       delete am;
       return 0;
    } 
-   bool res; 
  
    // gdcm::File::IsReadable() is no usable here, because we deal with
    // any kind of gdcm-Parsable *document* 
    // not only gdcm::File (as opposed to gdcm::DicomDir)
 
-   res = e1->Load( fileName );
+   gdcm::File *e1 = new gdcm::File();
+   e1->SetLoadMode(loadMode);
+
+   bool res = e1->Load( fileName );
    if ( !res )
    {
       delete e1;
@@ -88,7 +86,7 @@ int main(int argc, char *argv[])
       return 0;
    }
 
-   f1 = new gdcm::FileHelper(e1);
+   gdcm::FileHelper *f1 = new gdcm::FileHelper(e1);
    f1->SetPrintLevel( level );
 
    f1->Print();   
diff --git a/Example/ReWrite.cxx b/Example/ReWrite.cxx
new file mode 100644 (file)
index 0000000..ee5583c
--- /dev/null
@@ -0,0 +1,181 @@
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: ReWrite.cxx,v $
+  Language:  C++
+  Date:      $Date: 2005/06/07 11:12:10 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
+                                                                                
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                                
+=========================================================================*/
+#include "gdcmFile.h"
+#include "gdcmFileHelper.h"
+#include "gdcmDebug.h"
+
+#include "gdcmArgMgr.h"
+
+#include <iostream>
+
+int main(int argc, char *argv[])
+{
+   START_USAGE(usage)
+   " \n ReWrite :\n",
+   " Re write a full gdcm-readable Dicom image",
+   "     (usefull when the file header is not very straight).",
+   "                 ",
+   " usage: ReWrite filein=inputFileName fileout=anonymizedFileName ",
+   "       [mode=write mode] [noshadow] [noseq][debug] ", 
+   "        mode = a (ACR), x (Explicit VR Dicom), r (RAW : only pixels)",
+   "        noshadow : user doesn't want to load Private groups (odd number)",
+   "        noseq    : user doesn't want to load Sequences ",
+   "        debug    : user wants to run the program in 'debug mode' ",
+   FINISH_USAGE
+
+   // ----- Initialize Arguments Manager ------   
+   gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
+  
+   if (am->ArgMgrDefined("usage")) 
+   {
+      am->ArgMgrUsage(usage); // Display 'usage'
+      delete am;
+      return 0;
+   }
+   char *fileName = am->ArgMgrWantString("filein",usage);
+   if ( fileName == NULL )
+   {
+      delete am;
+      return 0;
+   }
+
+   char *outputFileName = am->ArgMgrWantString("fileout",usage);
+   if ( outputFileName == NULL )
+   {
+      delete am;
+      return 0;
+   }
+
+   char *mode = am->ArgMgrGetString("filein","X");
+
+   int loadMode;
+   if ( am->ArgMgrDefined("noshadow") && am->ArgMgrDefined("noseq") )
+       loadMode = NO_SEQ | NO_SHADOW;  
+   else if ( am->ArgMgrDefined("noshadow") )
+      loadMode = NO_SHADOW;
+   else if ( am->ArgMgrDefined("noseq") )
+      loadMode = NO_SEQ;
+   else
+      loadMode = 0;
+
+   if (am->ArgMgrDefined("debug"))
+      gdcm::Debug::DebugOn();
+   // if unused Param we give up
+   if ( am->ArgMgrPrintUnusedLabels() )
+   { 
+      am->ArgMgrUsage(usage);
+      delete am;
+      return 0;
+   }
+
+   delete am;  // we don't need Argument Manager any longer
+
+   void *imageData;
+   int dataSize;
+
+   gdcm::File *e1 = new gdcm::File();
+   e1->SetLoadMode(loadMode);
+
+   bool res = e1->Load( fileName );
+   if ( !res )
+   {
+      delete e1;
+      delete am;
+      return 0;
+   }
+   if (!e1->IsReadable())
+   {
+       std::cerr << "Sorry, not a Readable DICOM / ACR File"  <<std::endl;
+       delete e1;
+       delete am; 
+       return 0;
+   }
+   
+   gdcm::FileHelper *f1 = new gdcm::FileHelper(e1);
+
+// ---     
+
+   dataSize = f1->GetImageDataSize();
+   std::cout <<std::endl <<" dataSize " << dataSize << std::endl;
+   int nX,nY,nZ,sPP,planarConfig;
+   std::string pixelType, transferSyntaxName;
+   nX=e1->GetXSize();
+   nY=e1->GetYSize();
+   nZ=e1->GetZSize();
+   std::cout << " DIMX=" << nX << " DIMY=" << nY << " DIMZ=" << nZ << std::endl;
+
+   pixelType    = e1->GetPixelType();
+   sPP          = e1->GetSamplesPerPixel();
+   planarConfig = e1->GetPlanarConfiguration();
+   
+   std::cout << " pixelType="           << pixelType 
+             << " SampleserPixel="      << sPP
+             << " PlanarConfiguration=" << planarConfig 
+             << " PhotometricInterpretation=" 
+                                << e1->GetEntryValue(0x0028,0x0004) 
+             << std::endl;
+
+   int numberOfScalarComponents=e1->GetNumberOfScalarComponents();
+   std::cout << "NumberOfScalarComponents " << numberOfScalarComponents <<std::endl;
+   transferSyntaxName = e1->GetTransferSyntaxName();
+   std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl;
+   
+   imageData= f1->GetImageData();
+
+   switch (mode[0])
+   {
+   case 'A' :
+            // Writting an ACR file
+            // from a full gdcm readable File
+
+      std::cout << "WriteACR" << std::endl;
+      f1->WriteAcr(outputFileName);
+      break;
+
+   case 'D' : // Not documented in the 'usage', because the method is known to be bugged. 
+
+           // Writting a DICOM Implicit VR file
+           // from a full gdcm readable File
+
+      std::cout << "WriteDCM Implicit VR" << std::endl;
+      f1->WriteDcmImplVR(outputFileName);
+      break;
+
+   case 'X' :
+              // writting a DICOM Explicit VR 
+              // from a full gdcm readable File
+
+      std::cout << "WriteDCM Explicit VR" << std::endl;
+      f1->WriteDcmExplVR(outputFileName);
+      break;
+
+   case 'R' :
+             //  Writting a Raw File, 
+
+      std::cout << "WriteRaw" << std::endl;
+      f1->WriteRawData(outputFileName);
+      break;
+
+   }
+   delete e1;
+   delete f1;
+   delete am;
+   return 0;
+}
+