X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Example%2FMakeDicomDir.cxx;h=bb97ae6b2a66609fcaaf2e15a40d0174c430e892;hb=c556c62e38ad8f5b0423a91d919c13ac85a23f32;hp=0be2432f2f0cfe0337a1f681ddc29fe26a4f8ed8;hpb=11398e16aeaac3fb32225d94c4613cc5f65d851b;p=gdcm.git diff --git a/Example/MakeDicomDir.cxx b/Example/MakeDicomDir.cxx index 0be2432f..bb97ae6b 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/03 15:40:53 $ - Version: $Revision: 1.3 $ + Date: $Date: 2005/10/25 14:52:26 $ + Version: $Revision: 1.16 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -20,6 +20,7 @@ #include "gdcmDicomDirPatient.h" #include "gdcmDirList.h" #include "gdcmDebug.h" +#include "gdcmArgMgr.h" #include @@ -36,8 +37,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,58 +46,99 @@ 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 = gdcm::LD_ALL; + if ( am->ArgMgrDefined("noshadowseq") ) + loadMode |= gdcm::LD_NOSHADOWSEQ; + else { - dirName = GDCM_DATA_ROOT; + if ( am->ArgMgrDefined("noshadow") ) + loadMode |= gdcm::LD_NOSHADOW; + if ( am->ArgMgrDefined("noseq") ) + loadMode |= gdcm::LD_NOSEQ; } - 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 ----- - // 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::DicomDir *dcmdir; + + // we ask for Directory parsing - dcmdir->SetLoadMode(NO_SEQ); - dcmdir->Load(dirName); + dcmdir = gdcm::DicomDir::New( ); - dcmdir->SetStartMethod(StartMethod, (void *) NULL); + dcmdir->SetStartMethod(StartMethod); 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; + dcmdir->Delete(); return 1; } - // Create the corresponding DicomDir - dcmdir->WriteDicomDir("NewDICOMDIR"); - delete dcmdir; + // ----- Create the corresponding DicomDir + + dcmdir->Write("NewDICOMDIR"); + dcmdir->Delete(); // Read from disc the just written DicomDir - gdcm::DicomDir *newDicomDir = new gdcm::DicomDir("NewDICOMDIR"); + gdcm::DicomDir *newDicomDir = gdcm::DicomDir::New(); + newDicomDir->SetFileName( "NewDICOMDIR" ); + newDicomDir->Load(); if( !newDicomDir->IsReadable() ) { std::cout<<" Written DicomDir 'NewDICOMDIR'" <<" is not readable"<Delete(); return 1; } @@ -107,12 +148,12 @@ int main(int argc, char *argv[]) <<" has no patient"<Delete(); return(1); } std::cout<Delete(); return 0; }