1 /*=========================================================================
4 Module: $RCSfile: MakeDicomDir.cxx,v $
6 Date: $Date: 2005/06/15 09:54:49 $
7 Version: $Revision: 1.6 $
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 [noshadow] [noseq] [debug] ",
55 " noshadow : user doesn't want to load Private groups (odd number)",
56 " noseq : user doesn't want to load Sequences ",
57 " debug : user wants to run the program in 'debug mode' ",
60 // ----- Initialize Arguments Manager ------
61 gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
63 if (am->ArgMgrDefined("usage"))
65 am->ArgMgrUsage(usage); // Display 'usage'
71 dirName = am->ArgMgrGetString("dirName",(char *)".");
74 if ( am->ArgMgrDefined("noshadow") && am->ArgMgrDefined("noseq") )
75 loadMode = NO_SEQ | NO_SHADOW;
76 else if ( am->ArgMgrDefined("noshadow") )
78 else if ( am->ArgMgrDefined("noseq") )
83 if (am->ArgMgrDefined("debug"))
84 gdcm::Debug::DebugOn();
86 // if unused Param we give up
87 if ( am->ArgMgrPrintUnusedLabels() )
89 am->ArgMgrUsage(usage);
94 delete am; // we don't need Argument Manager any longer
96 // ----- Begin Processing -----
98 gdcm::DicomDir *dcmdir;
100 // we ask for Directory parsing
102 dcmdir = new gdcm::DicomDir( );
103 dcmdir->SetParseDir(true);
105 dcmdir->SetStartMethod(StartMethod, (void *) NULL);
106 dcmdir->SetEndMethod(EndMethod);
108 dcmdir->SetLoadMode(loadMode);
109 dcmdir->Load(dirName);
111 // ----- Check the result
113 if ( !dcmdir->GetFirstPatient() )
115 std::cout << "makeDicomDir: no patient found. Exiting."
121 // ----- Create the corresponding DicomDir
123 dcmdir->WriteDicomDir("NewDICOMDIR");
126 // Read from disc the just written DicomDir
127 gdcm::DicomDir *newDicomDir = new gdcm::DicomDir("NewDICOMDIR");
128 if( !newDicomDir->IsReadable() )
130 std::cout<<" Written DicomDir 'NewDICOMDIR'"
131 <<" is not readable"<<std::endl
132 <<" ...Failed"<<std::endl;
138 if( !newDicomDir->GetFirstPatient() )
140 std::cout<<" Written DicomDir 'NewDICOMDIR'"
141 <<" has no patient"<<std::endl
142 <<" ...Failed"<<std::endl;
148 std::cout<<std::flush;