1 /*=========================================================================
4 Module: $RCSfile: MakeDicomDir.cxx,v $
6 Date: $Date: 2005/11/28 17:09:22 $
7 Version: $Revision: 1.17 $
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 NewDICOMDIR..
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 " [noshadowseq][noshadow][noseq] [debug] ",
45 " noshadowseq: user doesn't want to load Private Sequences ",
46 " noshadow : user doesn't want to load Private groups (odd number) ",
47 " noseq : user doesn't want to load Sequences ",
48 " debug : user wants to run the program in 'debug mode' ",
51 // ----- Initialize Arguments Manager ------
52 gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
54 if (argc == 1 || am->ArgMgrDefined("usage"))
56 am->ArgMgrUsage(usage); // Display 'usage'
62 dirName = am->ArgMgrGetString("dirName",(char *)".");
64 int loadMode = gdcm::LD_ALL;
65 if ( am->ArgMgrDefined("noshadowseq") )
66 loadMode |= gdcm::LD_NOSHADOWSEQ;
69 if ( am->ArgMgrDefined("noshadow") )
70 loadMode |= gdcm::LD_NOSHADOW;
71 if ( am->ArgMgrDefined("noseq") )
72 loadMode |= gdcm::LD_NOSEQ;
75 if (am->ArgMgrDefined("debug"))
76 gdcm::Debug::DebugOn();
78 // if unused Param we give up
79 if ( am->ArgMgrPrintUnusedLabels() )
81 am->ArgMgrUsage(usage);
86 delete am; // we don't need Argument Manager any longer
88 // ----- Begin Processing -----
90 gdcm::DicomDir *dcmdir;
92 // we ask for Directory parsing
94 dcmdir = gdcm::DicomDir::New( );
96 dcmdir->SetLoadMode(loadMode);
97 dcmdir->SetDirectoryName(dirName);
98 //dcmdir->SetParseDir(true);
101 // ----- Check the result
103 if ( !dcmdir->GetFirstPatient() )
105 std::cout << "makeDicomDir: no patient found. Exiting."
111 // ----- Create the corresponding DicomDir
113 dcmdir->Write("NewDICOMDIR");
116 // Read from disc the just written DicomDir
117 gdcm::DicomDir *newDicomDir = gdcm::DicomDir::New();
118 newDicomDir->SetFileName( "NewDICOMDIR" );
120 if( !newDicomDir->IsReadable() )
122 std::cout<<" Written DicomDir 'NewDICOMDIR'"
123 <<" is not readable"<<std::endl
124 <<" ...Failed"<<std::endl;
126 newDicomDir->Delete();
130 if( !newDicomDir->GetFirstPatient() )
132 std::cout<<" Written DicomDir 'NewDICOMDIR'"
133 <<" has no patient"<<std::endl
134 <<" ...Failed"<<std::endl;
136 newDicomDir->Delete();
140 std::cout<<std::flush;
142 newDicomDir->Delete();