1 /*=========================================================================
4 Module: $RCSfile: MakeDicomDir.cxx,v $
6 Date: $Date: 2005/07/21 04:55:50 $
7 Version: $Revision: 1.10 $
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' ",
55 " usage: MakeDicomDir dirname=rootDirectoryName ",
56 " [noshadowseq][noshadow][noseq] [debug] ",
58 " noshadowseq: user doesn't want to load Private Sequences ",
59 " noshadow : user doesn't want to load Private groups (odd number) ",
60 " noseq : user doesn't want to load Sequences ",
61 " debug : user wants to run the program in 'debug mode' ",
64 // ----- Initialize Arguments Manager ------
65 gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
67 if (argc == 1 || am->ArgMgrDefined("usage"))
69 am->ArgMgrUsage(usage); // Display 'usage'
75 dirName = am->ArgMgrGetString("dirName",(char *)".");
77 int loadMode = 0x00000000;
78 if ( am->ArgMgrDefined("noshadowseq") )
79 loadMode |= NO_SHADOWSEQ;
82 if ( am->ArgMgrDefined("noshadow") )
83 loadMode |= NO_SHADOW;
84 if ( am->ArgMgrDefined("noseq") )
88 if (am->ArgMgrDefined("debug"))
89 gdcm::Debug::DebugOn();
91 // if unused Param we give up
92 if ( am->ArgMgrPrintUnusedLabels() )
94 am->ArgMgrUsage(usage);
99 delete am; // we don't need Argument Manager any longer
101 // ----- Begin Processing -----
103 gdcm::DicomDir *dcmdir;
105 // we ask for Directory parsing
107 dcmdir = new gdcm::DicomDir( );
109 dcmdir->SetStartMethod(StartMethod, (void *) NULL);
110 dcmdir->SetEndMethod(EndMethod);
112 dcmdir->SetLoadMode(loadMode);
113 dcmdir->SetDirectoryName(dirName);
114 //dcmdir->SetParseDir(true);
117 // ----- Check the result
119 if ( !dcmdir->GetFirstPatient() )
121 std::cout << "makeDicomDir: no patient found. Exiting."
127 // ----- Create the corresponding DicomDir
129 dcmdir->WriteDicomDir("NewDICOMDIR");
132 // Read from disc the just written DicomDir
133 gdcm::DicomDir *newDicomDir = new gdcm::DicomDir("NewDICOMDIR");
134 if( !newDicomDir->IsReadable() )
136 std::cout<<" Written DicomDir 'NewDICOMDIR'"
137 <<" is not readable"<<std::endl
138 <<" ...Failed"<<std::endl;
144 if( !newDicomDir->GetFirstPatient() )
146 std::cout<<" Written DicomDir 'NewDICOMDIR'"
147 <<" has no patient"<<std::endl
148 <<" ...Failed"<<std::endl;
154 std::cout<<std::flush;