]> Creatis software - gdcm.git/blobdiff - Example/MakeDicomDir.cxx
Unify user interface
[gdcm.git] / Example / MakeDicomDir.cxx
index 5cf73764724fa4490e850ab7c8545068d14b79b0..9f87f5dfaab071a577579a93b0e10ba8fe89b237 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: MakeDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/04/14 15:15:15 $
-  Version:   $Revision: 1.2 $
+  Date:      $Date: 2005/07/21 04:55:50 $
+  Version:   $Revision: 1.10 $
                                                                                 
   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>
 
 // ---
@@ -36,8 +38,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,43 +47,85 @@ 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                            ",
+   "        [noshadowseq][noshadow][noseq] [debug]                            ",
+   "                                                                          ",
+   "        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                    ",
+   "        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->ArgMgrDefined("usage")) 
    {
-      dirName = argv[1];
+      am->ArgMgrUsage(usage); // Display 'usage'
+      delete am;
+      return 0;
    }
-   else
+
+   char *dirName;   
+   dirName  = am->ArgMgrGetString("dirName",(char *)"."); 
+
+   int loadMode = 0x00000000;
+   if ( am->ArgMgrDefined("noshadowseq") )
+      loadMode |= NO_SHADOWSEQ;
+   else 
    {
-      dirName = GDCM_DATA_ROOT;
+   if ( am->ArgMgrDefined("noshadow") )
+         loadMode |= NO_SHADOW;
+      if ( am->ArgMgrDefined("noseq") )
+         loadMode |= NO_SEQ;
    }
 
-   gdcm::DicomDir *dcmdir;
-    // we ask for Directory parsing
+   if (am->ArgMgrDefined("debug"))
+      gdcm::Debug::DebugOn();
  
-    // Old style (still available) :
-    // dcmdir = new gdcm::DicomDir(dirName, true);
+   // 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
 
-   // new style (user is allowed no to load Sequences an/or Shadow Groups)
    dcmdir = new gdcm::DicomDir( );
-   dcmdir->SetParseDir(true);
-   dcmdir->SetLoadMode(NO_SEQ | NO_SHADOW);
-   dcmdir->Load(dirName);
 
    dcmdir->SetStartMethod(StartMethod, (void *) NULL);
    dcmdir->SetEndMethod(EndMethod);
-   
+
+   dcmdir->SetLoadMode(loadMode);
+   dcmdir->SetDirectoryName(dirName);
+   //dcmdir->SetParseDir(true);
+   dcmdir->Load();
+
+    // ----- 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;