Program: gdcm
Module: $RCSfile: MakeDicomDir.cxx,v $
Language: C++
- Date: $Date: 2005/06/03 15:40:53 $
- Version: $Revision: 1.3 $
+ Date: $Date: 2007/09/28 14:09:20 $
+ Version: $Revision: 1.25 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmDicomDirPatient.h"
#include "gdcmDirList.h"
#include "gdcmDebug.h"
+#include "gdcmArgMgr.h"
-#include <iostream>
-
-// ---
-void StartMethod(void *toto) {
- (void)toto;
- std::cout<<"Start parsing"<<std::endl;
-}
+//#include <sys/times.h> // Linux Only
-void EndMethod(void *toto) {
- (void)toto;
- std::cout<<"End parsing"<<std::endl;
-}
-// ---
+#include <iostream>
/**
- * \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
- * and writes a file named NewDICOMDIR..
+ * and writes a file named DICOMDIR. (user may choose an other name)
*/
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 'DICOMDIR' ",
+ " ",
+ " usage: MakeDicomDir dirname=rootDirectoryName ",
+ " name=DICOMDIR file name ",
+ " [noshadowseq][noshadow][noseq] [debug] [check] ",
+ " ",
+ " name : the default name for the generated dicomdir is 'DICOMDIR' ",
+ " 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 : developper wants to run the program in 'debug mode' ",
+ " check : the dicomdir is checked as 'gdcm readable' ",
+ FINISH_USAGE
+
+ // ----- Initialize Arguments Manager ------
+ GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv);
+
+ if (argc == 1 || am->ArgMgrDefined("usage"))
{
- dirName = argv[1];
+ am->ArgMgrUsage(usage); // Display 'usage'
+ delete am;
+ return 0;
}
- else
+
+ const char *dirName;
+ dirName = am->ArgMgrGetString("dirName",".");
+
+ const char *name;
+ name = am->ArgMgrGetString("name","DICOMDIR");
+
+ int loadMode = GDCM_NAME_SPACE::LD_ALL;
+ if ( am->ArgMgrDefined("noshadowseq") )
+ loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ;
+ else
{
- dirName = GDCM_DATA_ROOT;
+ if ( am->ArgMgrDefined("noshadow") )
+ loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW;
+ if ( am->ArgMgrDefined("noseq") )
+ loadMode |= GDCM_NAME_SPACE::LD_NOSEQ;
+ }
+
+ if (am->ArgMgrDefined("debug"))
+ GDCM_NAME_SPACE::Debug::DebugOn();
+
+ int check = am->ArgMgrDefined("check");
+
+ // 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
- gdcm::DicomDir *dcmdir;
- // we ask for Directory parsing
-
- // Old style (still available) :
- // dcmdir = new gdcm::DicomDir(dirName, true);
+ // ----- Begin Processing -----
- // new style (user is allowed no to load Sequences an/or Shadow Groups)
- 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);
+ GDCM_NAME_SPACE::DicomDir *dcmdir;
+
+ // we ask for Directory parsing
- dcmdir->SetLoadMode(NO_SEQ);
- dcmdir->Load(dirName);
+ dcmdir = GDCM_NAME_SPACE::DicomDir::New( );
- dcmdir->SetStartMethod(StartMethod, (void *) NULL);
- dcmdir->SetEndMethod(EndMethod);
+ dcmdir->SetLoadMode(loadMode);
+ dcmdir->SetDirectoryName(dirName);
+ //dcmdir->SetParseDir(true);
+
+ // struct tms tms1, tms2; // Time measurements
+ // times(&tms1);
+
+ dcmdir->Load(); // Reads all the files and creates the GDCM_NAME_SPACE::DicomDir
+ //times(&tms2);
+ //std::cout
+ // << (long) ((tms2.tms_utime) - (tms1.tms_utime))
+ // << std::endl;
+
+ if ( GDCM_NAME_SPACE::Debug::GetDebugFlag() )
+ std::cout << "======================= End Parsing Directory" << std::endl;
+
+ // ----- Check the result
+
if ( !dcmdir->GetFirstPatient() )
{
std::cout << "makeDicomDir: no patient found. Exiting."
<< std::endl;
-
- delete dcmdir;
+ dcmdir->Delete();
return 1;
}
- // Create the corresponding DicomDir
- dcmdir->WriteDicomDir("NewDICOMDIR");
- delete dcmdir;
+ // ----- Writes the corresponding DICOMDIR file (from the GDCM_NAME_SPACE::DicomDir)
- // Read from disc the just written DicomDir
- gdcm::DicomDir *newDicomDir = new gdcm::DicomDir("NewDICOMDIR");
- if( !newDicomDir->IsReadable() )
- {
- std::cout<<" Written DicomDir 'NewDICOMDIR'"
- <<" is not readable"<<std::endl
- <<" ...Failed"<<std::endl;
-
- delete newDicomDir;
- return 1;
- }
-
- if( !newDicomDir->GetFirstPatient() )
+ dcmdir->Write(name);
+ dcmdir->Delete();
+
+ if (check)
{
- std::cout<<" Written DicomDir 'NewDICOMDIR'"
- <<" has no patient"<<std::endl
- <<" ...Failed"<<std::endl;
+ if ( GDCM_NAME_SPACE::Debug::GetDebugFlag() )
+ std::cout << "======================= End Writting DICOMDIR"
+ << std::endl;
- delete newDicomDir;
- return(1);
+ // Read from disc the just written DicomDir
+
+ GDCM_NAME_SPACE::DicomDir *newDicomDir = GDCM_NAME_SPACE::DicomDir::New();
+ newDicomDir->SetFileName( name );
+ newDicomDir->Load();
+ if ( GDCM_NAME_SPACE::Debug::GetDebugFlag() )
+ std::cout << "======================= End Parsing DICOMDIR"
+ << std::endl;
+ if( !newDicomDir->IsReadable() )
+ {
+ std::cout<<" Written DicomDir [" << name << "] "
+ <<" is not readable"<<std::endl
+ <<" ...Failed"<<std::endl;
+
+ newDicomDir->Delete();
+ return 1;
+ }
+
+ if( !newDicomDir->GetFirstPatient() )
+ {
+ std::cout <<" Written DicomDir [" << name << "] "
+ <<" has no patient"<<std::endl
+ <<" ...Failed"<<std::endl;
+
+ newDicomDir->Delete();
+ return(1);
+ }
+ std::cout<<std::flush;
+ newDicomDir->Delete();
}
-
- std::cout<<std::flush;
-
- delete newDicomDir;
return 0;
}