]> Creatis software - gdcm.git/blob - Example/MakeDicomDir.cxx
We don't SetLoadMode(NO_SEQ | NO_SHADOW),
[gdcm.git] / Example / MakeDicomDir.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: MakeDicomDir.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/06/03 15:40:53 $
7   Version:   $Revision: 1.3 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18 #include "gdcmDocEntry.h"
19 #include "gdcmDicomDir.h"
20 #include "gdcmDicomDirPatient.h"
21 #include "gdcmDirList.h"
22 #include "gdcmDebug.h"
23
24 #include <iostream>
25
26 // ---
27 void StartMethod(void *toto) {
28   (void)toto;
29    std::cout<<"Start parsing"<<std::endl;
30 }
31
32 void EndMethod(void *toto) {
33   (void)toto;
34    std::cout<<"End parsing"<<std::endl;
35 }
36 // ---
37
38 /**
39   * \ingroup Test
40   * \brief   Explores recursively the given directory (or GDCM_DATA_ROOT by default)
41   *          orders the gdcm-readable found Files
42   *          according their Patient/Study/Serie/Image characteristics
43   *          makes the gdcmDicomDir 
44   *          and writes a file named NewDICOMDIR..
45   */  
46
47 int main(int argc, char *argv[]) 
48 {
49   // gdcm::Debug::DebugOn();
50    std::string dirName;   
51
52    if (argc > 1)
53    {
54       dirName = argv[1];
55    }
56    else
57    {
58       dirName = GDCM_DATA_ROOT;
59    }
60
61    gdcm::DicomDir *dcmdir;
62     // we ask for Directory parsing
63  
64     // Old style (still available) :
65     // dcmdir = new gdcm::DicomDir(dirName, true);
66
67    // new style (user is allowed no to load Sequences an/or Shadow Groups)
68    dcmdir = new gdcm::DicomDir( );
69    dcmdir->SetParseDir(true);
70 // some images have a wrong length for element 0x0000 of private groups
71 //   dcmdir->SetLoadMode(NO_SEQ | NO_SHADOW);
72
73    dcmdir->SetLoadMode(NO_SEQ);
74    dcmdir->Load(dirName);
75
76    dcmdir->SetStartMethod(StartMethod, (void *) NULL);
77    dcmdir->SetEndMethod(EndMethod);
78    
79    if ( !dcmdir->GetFirstPatient() ) 
80    {
81       std::cout << "makeDicomDir: no patient found. Exiting."
82                 << std::endl;
83
84       delete dcmdir;
85       return 1;
86    }
87     
88    // Create the corresponding DicomDir
89    dcmdir->WriteDicomDir("NewDICOMDIR");
90    delete dcmdir;
91
92    // Read from disc the just written DicomDir
93    gdcm::DicomDir *newDicomDir = new gdcm::DicomDir("NewDICOMDIR");
94    if( !newDicomDir->IsReadable() )
95    {
96       std::cout<<"          Written DicomDir 'NewDICOMDIR'"
97                <<" is not readable"<<std::endl
98                <<"          ...Failed"<<std::endl;
99
100       delete newDicomDir;
101       return 1;
102    }
103
104    if( !newDicomDir->GetFirstPatient() )
105    {
106       std::cout<<"          Written DicomDir 'NewDICOMDIR'"
107                <<" has no patient"<<std::endl
108                <<"          ...Failed"<<std::endl;
109
110       delete newDicomDir;
111       return(1);
112    }
113
114    std::cout<<std::flush;
115
116    delete newDicomDir;
117    return 0;
118 }