1 /*=========================================================================
4 Module: $RCSfile: MakeDicomDir.cxx,v $
6 Date: $Date: 2005/10/25 14:52:26 $
7 Version: $Revision: 1.16 $
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"
23 #include "gdcmArgMgr.h"
28 void StartMethod(void *toto) {
30 std::cout<<"Start parsing"<<std::endl;
33 void EndMethod(void *toto) {
35 std::cout<<"End parsing"<<std::endl;
40 * \brief Explores recursively the given directory
41 * orders the gdcm-readable found Files
42 * according their Patient/Study/Serie/Image characteristics
43 * makes the gdcmDicomDir
44 * and writes a file named NewDICOMDIR..
47 int main(int argc, char *argv[])
50 " \n MakeDicomDir :\n ",
51 " Explores recursively the given directory, makes the relevant DICOMDIR ",
52 " and writes it as 'NewDICOMDIR' ",
54 " usage: MakeDicomDir dirname=rootDirectoryName ",
55 " [noshadowseq][noshadow][noseq] [debug] ",
57 " noshadowseq: user doesn't want to load Private Sequences ",
58 " noshadow : user doesn't want to load Private groups (odd number) ",
59 " noseq : user doesn't want to load Sequences ",
60 " debug : user wants to run the program in 'debug mode' ",
63 // ----- Initialize Arguments Manager ------
64 gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
66 if (argc == 1 || am->ArgMgrDefined("usage"))
68 am->ArgMgrUsage(usage); // Display 'usage'
74 dirName = am->ArgMgrGetString("dirName",(char *)".");
76 int loadMode = gdcm::LD_ALL;
77 if ( am->ArgMgrDefined("noshadowseq") )
78 loadMode |= gdcm::LD_NOSHADOWSEQ;
81 if ( am->ArgMgrDefined("noshadow") )
82 loadMode |= gdcm::LD_NOSHADOW;
83 if ( am->ArgMgrDefined("noseq") )
84 loadMode |= gdcm::LD_NOSEQ;
87 if (am->ArgMgrDefined("debug"))
88 gdcm::Debug::DebugOn();
90 // if unused Param we give up
91 if ( am->ArgMgrPrintUnusedLabels() )
93 am->ArgMgrUsage(usage);
98 delete am; // we don't need Argument Manager any longer
100 // ----- Begin Processing -----
102 gdcm::DicomDir *dcmdir;
104 // we ask for Directory parsing
106 dcmdir = gdcm::DicomDir::New( );
108 dcmdir->SetStartMethod(StartMethod);
109 dcmdir->SetEndMethod(EndMethod);
111 dcmdir->SetLoadMode(loadMode);
112 dcmdir->SetDirectoryName(dirName);
113 //dcmdir->SetParseDir(true);
116 // ----- Check the result
118 if ( !dcmdir->GetFirstPatient() )
120 std::cout << "makeDicomDir: no patient found. Exiting."
126 // ----- Create the corresponding DicomDir
128 dcmdir->Write("NewDICOMDIR");
131 // Read from disc the just written DicomDir
132 gdcm::DicomDir *newDicomDir = gdcm::DicomDir::New();
133 newDicomDir->SetFileName( "NewDICOMDIR" );
135 if( !newDicomDir->IsReadable() )
137 std::cout<<" Written DicomDir 'NewDICOMDIR'"
138 <<" is not readable"<<std::endl
139 <<" ...Failed"<<std::endl;
141 newDicomDir->Delete();
145 if( !newDicomDir->GetFirstPatient() )
147 std::cout<<" Written DicomDir 'NewDICOMDIR'"
148 <<" has no patient"<<std::endl
149 <<" ...Failed"<<std::endl;
151 newDicomDir->Delete();
155 std::cout<<std::flush;
157 newDicomDir->Delete();