1 /*=========================================================================
4 Module: $RCSfile: TestMakeDicomDir.cxx,v $
6 Date: $Date: 2005/11/28 16:31:19 $
7 Version: $Revision: 1.12 $
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 "gdcmCommandManager.h"
23 #include "gdcmDebug.h"
26 class CommandStart : public gdcm::Command
28 gdcmTypeMacro(CommandStart);
29 gdcmNewMacro(CommandStart);
32 virtual void Execute()
34 std::cerr << "Start parsing" << std::endl;
41 class CommandEnd : public gdcm::Command
43 gdcmTypeMacro(CommandEnd);
44 gdcmNewMacro(CommandEnd);
47 virtual void Execute()
49 std::cerr << "End parsing" << std::endl;
56 class CommandProgress : public gdcm::Command
58 gdcmTypeMacro(CommandProgress);
59 gdcmNewMacro(CommandProgress);
62 virtual void Execute()
64 gdcm::DicomDir *dd=dynamic_cast<gdcm::DicomDir *>(GetObject());
67 std::cerr << "Progress parsing (" << dd->GetProgress() << ")" << std::endl;
69 std::cerr << "Progress parsing (NULL)" << std::endl;
76 void EndMethod(void *endMethod)
79 std::cout<<"End parsing"<<std::endl;
84 * \brief - Explores recursively the given directory
85 * (or GDCM_DATA_ROOT by default)
86 * - Orders the gdcm-readable found Files
87 * according their Patient/Study/Serie/Image characteristics
88 * - Makes the gdcm::DicomDir.
89 * - Writes a file named "NewDICOMDIR".
90 * - Reads "NewDICOMDIR" file.
93 int TestMakeDicomDir(int argc, char *argv[])
95 //gdcm::Debug::DebugOn();
104 dirName = GDCM_DATA_ROOT;
107 gdcm::DicomDir *dcmdir;
109 // new style (user is allowed no to load Sequences an/or Shadow Groups)
110 dcmdir = gdcm::DicomDir::New( );
113 cmd = CommandStart::New();
114 gdcm::CommandManager::SetCommand(dcmdir,gdcm::CMD_STARTPROGRESS,cmd);
116 cmd = CommandProgress::New();
117 gdcm::CommandManager::SetCommand(dcmdir,gdcm::CMD_PROGRESS,cmd);
119 cmd = CommandEnd::New();
120 gdcm::CommandManager::SetCommand(dcmdir,gdcm::CMD_ENDPROGRESS,cmd);
123 // dcmdir->SetLoadMode(gdcm::LD_NOSEQ | gdcm::LD_NOSHADOW);
124 // some images have a wrong length for element 0x0000 of private groups
125 dcmdir->SetLoadMode(gdcm::LD_NOSEQ);
126 dcmdir->SetDirectoryName(dirName);
129 if ( !dcmdir->GetFirstPatient() )
131 std::cout << "makeDicomDir: no patient found. Exiting."
138 // Create the corresponding DicomDir
139 dcmdir->Write("NewDICOMDIR");
142 // Read from disc the just written DicomDir
143 gdcm::DicomDir *newDicomDir = gdcm::DicomDir::New();
144 newDicomDir->SetFileName("NewDICOMDIR");
147 if( !newDicomDir->IsReadable() )
149 std::cout<<" Written DicomDir 'NewDICOMDIR'"
150 <<" is not readable"<<std::endl
151 <<" ...Failed"<<std::endl;
153 newDicomDir->Delete();
157 if( !newDicomDir->GetFirstPatient() )
159 std::cout<<" Written DicomDir 'NewDICOMDIR'"
160 <<" has no patient"<<std::endl
161 <<" ...Failed"<<std::endl;
163 newDicomDir->Delete();
167 std::cout<<std::flush;
168 newDicomDir->Delete();