1 /*=========================================================================
4 Module: $RCSfile: MakeDicomDir.cxx,v $
6 Date: $Date: 2005/06/07 11:12:10 $
7 Version: $Revision: 1.4 $
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;
42 * \brief Explores recursively the given directory
43 * orders the gdcm-readable found Files
44 * according their Patient/Study/Serie/Image characteristics
45 * makes the gdcmDicomDir
46 * and writes a file named NewDICOMDIR..
49 int main(int argc, char *argv[])
52 " \n MakeDicomDir :\n",
53 " Explores recursively the given directory, makes the relevant DICOMDIR",
54 " and writes it as 'NewDICOMDIR'",
55 " usage: MakeDicomDir dirname=rootDirectoryName [noshadow] [noseq] [debug] ",
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 (am->ArgMgrDefined("usage"))
66 am->ArgMgrUsage(usage); // Display 'usage'
72 dirName = am->ArgMgrGetString("dirName",".");
75 if ( am->ArgMgrDefined("noshadow") && am->ArgMgrDefined("noseq") )
76 loadMode = NO_SEQ | NO_SHADOW;
77 else if ( am->ArgMgrDefined("noshadow") )
79 else if ( am->ArgMgrDefined("noseq") )
84 if (am->ArgMgrDefined("debug"))
85 gdcm::Debug::DebugOn();
87 // if unused Param we give up
88 if ( am->ArgMgrPrintUnusedLabels() )
90 am->ArgMgrUsage(usage);
95 delete am; // we don't need Argument Manager any longer
97 // ----- Begin Processing -----
99 gdcm::DicomDir *dcmdir;
101 // we ask for Directory parsing
103 dcmdir = new gdcm::DicomDir( );
104 dcmdir->SetParseDir(true);
106 dcmdir->SetStartMethod(StartMethod, (void *) NULL);
107 dcmdir->SetEndMethod(EndMethod);
109 dcmdir->SetLoadMode(loadMode);
110 dcmdir->Load(dirName);
112 // ----- Check the result
114 if ( !dcmdir->GetFirstPatient() )
116 std::cout << "makeDicomDir: no patient found. Exiting."
122 // ----- Create the corresponding DicomDir
124 dcmdir->WriteDicomDir("NewDICOMDIR");
127 // Read from disc the just written DicomDir
128 gdcm::DicomDir *newDicomDir = new gdcm::DicomDir("NewDICOMDIR");
129 if( !newDicomDir->IsReadable() )
131 std::cout<<" Written DicomDir 'NewDICOMDIR'"
132 <<" is not readable"<<std::endl
133 <<" ...Failed"<<std::endl;
139 if( !newDicomDir->GetFirstPatient() )
141 std::cout<<" Written DicomDir 'NewDICOMDIR'"
142 <<" has no patient"<<std::endl
143 <<" ...Failed"<<std::endl;
149 std::cout<<std::flush;