X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Example%2FMakeDicomDir.cxx;h=2cb6d11825e86fd07e57fb4c05f23f2db2d8b69b;hb=ed8f0888f5c1f2bfb64d5759a5dc9590858b31f2;hp=4a14581f8d4175f4f76a65869aea7a2402b2ca98;hpb=1184bb0a9f829f36d0aecb170427259a10c2d4e7;p=gdcm.git diff --git a/Example/MakeDicomDir.cxx b/Example/MakeDicomDir.cxx index 4a14581f..2cb6d118 100644 --- a/Example/MakeDicomDir.cxx +++ b/Example/MakeDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: MakeDicomDir.cxx,v $ Language: C++ - Date: $Date: 2005/06/15 09:54:49 $ - Version: $Revision: 1.6 $ + Date: $Date: 2006/07/17 13:25:00 $ + Version: $Revision: 1.21 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -20,69 +20,71 @@ #include "gdcmDicomDirPatient.h" #include "gdcmDirList.h" #include "gdcmDebug.h" - #include "gdcmArgMgr.h" -#include - -// --- -void StartMethod(void *toto) { - (void)toto; - std::cout<<"Start parsing"< -void EndMethod(void *toto) { - (void)toto; - std::cout<<"End parsing"< /** * \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[]) { 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' ", + " \n MakeDicomDir :\n ", + " Explores recursively the given directory, makes the relevant DICOMDIR ", + " and writes it as 'NewDICOMDIR' ", + " ", + " 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 : user wants to run the program in 'debug mode' ", + " check : the dicomdir is checked as 'gdcm readable' ", FINISH_USAGE // ----- Initialize Arguments Manager ------ gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv); - if (am->ArgMgrDefined("usage")) + if (argc == 1 || am->ArgMgrDefined("usage")) { am->ArgMgrUsage(usage); // Display 'usage' delete am; return 0; } - char *dirName; - dirName = am->ArgMgrGetString("dirName",(char *)"."); + const 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 - loadMode = 0; + const char *name; + name = am->ArgMgrGetString("name","DICOMDIR"); + + int loadMode = gdcm::LD_ALL; + if ( am->ArgMgrDefined("noshadowseq") ) + loadMode |= gdcm::LD_NOSHADOWSEQ; + else + { + if ( am->ArgMgrDefined("noshadow") ) + loadMode |= gdcm::LD_NOSHADOW; + if ( am->ArgMgrDefined("noseq") ) + loadMode |= gdcm::LD_NOSEQ; + } if (am->ArgMgrDefined("debug")) gdcm::Debug::DebugOn(); - + + int check = am->ArgMgrDefined("check"); + // if unused Param we give up if ( am->ArgMgrPrintUnusedLabels() ) { @@ -90,63 +92,84 @@ int main(int argc, char *argv[]) delete am; return 0; } - + delete am; // we don't need Argument Manager any longer // ----- Begin Processing ----- gdcm::DicomDir *dcmdir; - // we ask for Directory parsing - dcmdir = new gdcm::DicomDir( ); - dcmdir->SetParseDir(true); + + // we ask for Directory parsing - dcmdir->SetStartMethod(StartMethod, (void *) NULL); - dcmdir->SetEndMethod(EndMethod); + dcmdir = gdcm::DicomDir::New( ); dcmdir->SetLoadMode(loadMode); - dcmdir->Load(dirName); - + dcmdir->SetDirectoryName(dirName); + //dcmdir->SetParseDir(true); + + struct tms tms1, tms2; // Time measurements + times(&tms1); + dcmdir->Load(); + times(&tms2); + std::cout + << (long) ((tms2.tms_utime) - (tms1.tms_utime)) + << std::endl; + + if ( gdcm::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; - - // 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"<GetFirstPatient() ) + dcmdir->Write(name); + dcmdir->Delete(); + + if (check) { - std::cout<<" Written DicomDir 'NewDICOMDIR'" - <<" has no patient"<SetFileName( name ); + newDicomDir->Load(); + if ( gdcm::Debug::GetDebugFlag() ) + std::cout << "======================= End Parsing DICOMDIR" + << std::endl; + if( !newDicomDir->IsReadable() ) + { + std::cout<<" Written DicomDir [" << name << "] " + <<" is not readable"<Delete(); + return 1; + } + + if( !newDicomDir->GetFirstPatient() ) + { + std::cout <<" Written DicomDir [" << name << "] " + <<" has no patient"<Delete(); + return(1); + } + std::cout<Delete(); } - - std::cout<