1 /*=========================================================================
4 Module: $RCSfile: MakeDicomDir.cxx,v $
6 Date: $Date: 2005/07/08 10:15:04 $
7 Version: $Revision: 1.9 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
18 #include "gdcmDocEntry.h"
19 #include "gdcmDicomDir.h"
20 #include "gdcmDicomDirPatient.h"
21 #include "gdcmDirList.h"
22 #include "gdcmDebug.h"
24 #include "gdcmArgMgr.h"
29 void StartMethod(void *toto) {
31 std::cout<<"Start parsing"<<std::endl;
34 void EndMethod(void *toto) {
36 std::cout<<"End parsing"<<std::endl;
41 * \brief Explores recursively the given directory
42 * orders the gdcm-readable found Files
43 * according their Patient/Study/Serie/Image characteristics
44 * makes the gdcmDicomDir
45 * and writes a file named NewDICOMDIR..
48 int main(int argc, char *argv[])
51 " \n MakeDicomDir :\n",
52 " Explores recursively the given directory, makes the relevant DICOMDIR",
53 " and writes it as 'NewDICOMDIR'",
54 " usage: MakeDicomDir dirname=rootDirectoryName [noshadowseq][noshadow][noseq] [debug] ",
55 " noshadowseq: user doesn't want to load Private Sequences",
56 " noshadow : user doesn't want to load Private groups (odd number)",
57 " noseq : user doesn't want to load Sequences ",
58 " debug : user wants to run the program in 'debug mode' ",
61 // ----- Initialize Arguments Manager ------
62 gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
64 if (argc == 1 || am->ArgMgrDefined("usage"))
66 am->ArgMgrUsage(usage); // Display 'usage'
72 dirName = am->ArgMgrGetString("dirName",(char *)".");
74 int loadMode = 0x00000000;
75 if ( am->ArgMgrDefined("noshadowseq") )
76 loadMode |= NO_SHADOWSEQ;
79 if ( am->ArgMgrDefined("noshadow") )
80 loadMode |= NO_SHADOW;
81 if ( am->ArgMgrDefined("noseq") )
85 if (am->ArgMgrDefined("debug"))
86 gdcm::Debug::DebugOn();
88 // if unused Param we give up
89 if ( am->ArgMgrPrintUnusedLabels() )
91 am->ArgMgrUsage(usage);
96 delete am; // we don't need Argument Manager any longer
98 // ----- Begin Processing -----
100 gdcm::DicomDir *dcmdir;
102 // we ask for Directory parsing
104 dcmdir = new gdcm::DicomDir( );
106 dcmdir->SetStartMethod(StartMethod, (void *) NULL);
107 dcmdir->SetEndMethod(EndMethod);
109 dcmdir->SetLoadMode(loadMode);
110 dcmdir->SetDirectoryName(dirName);
111 dcmdir->SetParseDir(true);
114 // ----- Check the result
116 if ( !dcmdir->GetFirstPatient() )
118 std::cout << "makeDicomDir: no patient found. Exiting."
124 // ----- Create the corresponding DicomDir
126 dcmdir->WriteDicomDir("NewDICOMDIR");
129 // Read from disc the just written DicomDir
130 gdcm::DicomDir *newDicomDir = new gdcm::DicomDir("NewDICOMDIR");
131 if( !newDicomDir->IsReadable() )
133 std::cout<<" Written DicomDir 'NewDICOMDIR'"
134 <<" is not readable"<<std::endl
135 <<" ...Failed"<<std::endl;
141 if( !newDicomDir->GetFirstPatient() )
143 std::cout<<" Written DicomDir 'NewDICOMDIR'"
144 <<" has no patient"<<std::endl
145 <<" ...Failed"<<std::endl;
151 std::cout<<std::flush;