1 /*=========================================================================
4 Module: $RCSfile: MakeDicomDir.cxx,v $
6 Date: $Date: 2006/01/26 15:52:42 $
7 Version: $Revision: 1.20 $
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 * \brief Explores recursively the given directory
29 * orders the gdcm-readable found Files
30 * according their Patient/Study/Serie/Image characteristics
31 * makes the gdcmDicomDir
32 * and writes a file named DICOMDIR. (user may choose an other name)
35 int main(int argc, char *argv[])
38 " \n MakeDicomDir :\n ",
39 " Explores recursively the given directory, makes the relevant DICOMDIR ",
40 " and writes it as 'NewDICOMDIR' ",
42 " usage: MakeDicomDir dirname=rootDirectoryName ",
43 " name=DICOMDIR file name ",
44 " [noshadowseq][noshadow][noseq] [debug] [check] ",
46 " name : the default name for the generated dicomdir is 'DICOMDIR' ",
47 " noshadowseq: user doesn't want to load Private Sequences ",
48 " noshadow : user doesn't want to load Private groups (odd number) ",
49 " noseq : user doesn't want to load Sequences ",
50 " debug : user wants to run the program in 'debug mode' ",
51 " check : the dicomdir is checked as 'gdcm readable' ",
54 // ----- Initialize Arguments Manager ------
55 gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
57 if (argc == 1 || am->ArgMgrDefined("usage"))
59 am->ArgMgrUsage(usage); // Display 'usage'
65 dirName = am->ArgMgrGetString("dirName",".");
68 name = am->ArgMgrGetString("name","DICOMDIR");
70 int loadMode = gdcm::LD_ALL;
71 if ( am->ArgMgrDefined("noshadowseq") )
72 loadMode |= gdcm::LD_NOSHADOWSEQ;
75 if ( am->ArgMgrDefined("noshadow") )
76 loadMode |= gdcm::LD_NOSHADOW;
77 if ( am->ArgMgrDefined("noseq") )
78 loadMode |= gdcm::LD_NOSEQ;
81 if (am->ArgMgrDefined("debug"))
82 gdcm::Debug::DebugOn();
84 int check = am->ArgMgrDefined("check");
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 = gdcm::DicomDir::New( );
104 dcmdir->SetLoadMode(loadMode);
105 dcmdir->SetDirectoryName(dirName);
106 //dcmdir->SetParseDir(true);
109 if ( gdcm::Debug::GetDebugFlag() )
110 std::cout << "======================= End Parsing Directory" << std::endl;
112 // ----- Check the result
114 if ( !dcmdir->GetFirstPatient() )
116 std::cout << "makeDicomDir: no patient found. Exiting."
122 // ----- Create the corresponding DicomDir
129 if ( gdcm::Debug::GetDebugFlag() )
130 std::cout << "======================= End Writting DICOMDIR"
133 // Read from disc the just written DicomDir
135 gdcm::DicomDir *newDicomDir = gdcm::DicomDir::New();
136 newDicomDir->SetFileName( name );
138 if ( gdcm::Debug::GetDebugFlag() )
139 std::cout << "======================= End Parsing DICOMDIR"
141 if( !newDicomDir->IsReadable() )
143 std::cout<<" Written DicomDir [" << name << "] "
144 <<" is not readable"<<std::endl
145 <<" ...Failed"<<std::endl;
147 newDicomDir->Delete();
151 if( !newDicomDir->GetFirstPatient() )
153 std::cout <<" Written DicomDir [" << name << "] "
154 <<" has no patient"<<std::endl
155 <<" ...Failed"<<std::endl;
157 newDicomDir->Delete();
160 std::cout<<std::flush;
161 newDicomDir->Delete();