1 /*=========================================================================
4 Module: $RCSfile: TestMakeDicomDir.cxx,v $
6 Date: $Date: 2008/09/15 15:49:21 $
7 Version: $Revision: 1.14 $
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_NAME_SPACE::Command
28 gdcmTypeMacro(CommandStart);
29 gdcmNewMacro(CommandStart);
32 virtual void Execute()
34 std::cerr << "Start parsing" << std::endl;
41 class CommandEnd : public GDCM_NAME_SPACE::Command
43 gdcmTypeMacro(CommandEnd);
44 gdcmNewMacro(CommandEnd);
47 virtual void Execute()
49 std::cerr << "End parsing" << std::endl;
56 class CommandProgress : public GDCM_NAME_SPACE::Command
58 gdcmTypeMacro(CommandProgress);
59 gdcmNewMacro(CommandProgress);
62 virtual void Execute()
64 GDCM_NAME_SPACE::DicomDir *dd=dynamic_cast<GDCM_NAME_SPACE::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_NAME_SPACE::DicomDir.
89 * - Writes a file named "NewDICOMDIR".
90 * - Reads "NewDICOMDIR" file.
93 int TestMakeDicomDir(int argc, char *argv[])
95 //GDCM_NAME_SPACE::Debug::DebugOn();
104 dirName = GDCM_DATA_ROOT;
107 GDCM_NAME_SPACE::DicomDir *dcmdir;
109 // new style (user is allowed no to load Sequences an/or Shadow Groups)
110 dcmdir = GDCM_NAME_SPACE::DicomDir::New( );
112 GDCM_NAME_SPACE::Command *cmd;
113 cmd = CommandStart::New();
114 GDCM_NAME_SPACE::CommandManager::SetCommand(dcmdir,GDCM_NAME_SPACE::CMD_STARTPROGRESS,cmd);
116 cmd = CommandProgress::New();
117 GDCM_NAME_SPACE::CommandManager::SetCommand(dcmdir,GDCM_NAME_SPACE::CMD_PROGRESS,cmd);
119 cmd = CommandEnd::New();
120 GDCM_NAME_SPACE::CommandManager::SetCommand(dcmdir,GDCM_NAME_SPACE::CMD_ENDPROGRESS,cmd);
123 // dcmdir->SetLoadMode(GDCM_NAME_SPACE::LD_NOSEQ | GDCM_NAME_SPACE::LD_NOSHADOW);
124 // some images have a wrong length for element 0x0000 of private groups
125 dcmdir->SetLoadMode(GDCM_NAME_SPACE::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_NAME_SPACE::DicomDir *newDicomDir = GDCM_NAME_SPACE::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();