1 /*=========================================================================
4 Module: $RCSfile: TestMakeDicomDir.cxx,v $
6 Date: $Date: 2005/11/28 15:20:29 $
7 Version: $Revision: 1.11 $
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"
25 class CommandStart : public gdcm::Command
27 gdcmTypeMacro(CommandStart);
28 gdcmNewMacro(CommandStart);
31 virtual void Execute()
33 std::cerr << "Start parsing" << std::endl;
40 class CommandEnd : public gdcm::Command
42 gdcmTypeMacro(CommandEnd);
43 gdcmNewMacro(CommandEnd);
46 virtual void Execute()
48 std::cerr << "End parsing" << std::endl;
55 class CommandProgress : public gdcm::Command
57 gdcmTypeMacro(CommandProgress);
58 gdcmNewMacro(CommandProgress);
61 virtual void Execute()
63 gdcm::DicomDir *dd=dynamic_cast<gdcm::DicomDir *>(GetObject());
66 std::cerr << "Progress parsing (" << dd->GetProgress() << ")" << std::endl;
68 std::cerr << "Progress parsing (NULL)" << std::endl;
75 void EndMethod(void *endMethod)
78 std::cout<<"End parsing"<<std::endl;
83 * \brief - Explores recursively the given directory
84 * (or GDCM_DATA_ROOT by default)
85 * - Orders the gdcm-readable found Files
86 * according their Patient/Study/Serie/Image characteristics
87 * - Makes the gdcm::DicomDir.
88 * - Writes a file named "NewDICOMDIR".
89 * - Reads "NewDICOMDIR" file.
92 int TestMakeDicomDir(int argc, char *argv[])
94 //gdcm::Debug::DebugOn();
103 dirName = GDCM_DATA_ROOT;
106 gdcm::DicomDir *dcmdir;
108 // new style (user is allowed no to load Sequences an/or Shadow Groups)
109 dcmdir = gdcm::DicomDir::New( );
112 cmd = CommandStart::New();
113 dcmdir->SetCommand(gdcm::CMD_STARTPROGRESS,cmd);
115 cmd = CommandProgress::New();
116 dcmdir->SetCommand(gdcm::CMD_PROGRESS,cmd);
118 cmd = CommandEnd::New();
119 dcmdir->SetCommand(gdcm::CMD_ENDPROGRESS,cmd);
122 // dcmdir->SetLoadMode(gdcm::LD_NOSEQ | gdcm::LD_NOSHADOW);
123 // some images have a wrong length for element 0x0000 of private groups
124 dcmdir->SetLoadMode(gdcm::LD_NOSEQ);
125 dcmdir->SetDirectoryName(dirName);
128 if ( !dcmdir->GetFirstPatient() )
130 std::cout << "makeDicomDir: no patient found. Exiting."
137 // Create the corresponding DicomDir
138 dcmdir->Write("NewDICOMDIR");
141 // Read from disc the just written DicomDir
142 gdcm::DicomDir *newDicomDir = gdcm::DicomDir::New();
143 newDicomDir->SetFileName("NewDICOMDIR");
146 if( !newDicomDir->IsReadable() )
148 std::cout<<" Written DicomDir 'NewDICOMDIR'"
149 <<" is not readable"<<std::endl
150 <<" ...Failed"<<std::endl;
152 newDicomDir->Delete();
156 if( !newDicomDir->GetFirstPatient() )
158 std::cout<<" Written DicomDir 'NewDICOMDIR'"
159 <<" has no patient"<<std::endl
160 <<" ...Failed"<<std::endl;
162 newDicomDir->Delete();
166 std::cout<<std::flush;
167 newDicomDir->Delete();