]> Creatis software - gdcm.git/blob - Example/makeDicomDir.cxx
a1feba5ca5dd4c3a069d284d91198cfc7ffb3efe
[gdcm.git] / Example / makeDicomDir.cxx
1 #include <iostream>
2 #include "gdcm.h"
3 #include "gdcmDocEntry.h"
4 #include "gdcmDicomDir.h"
5 #include "gdcmDicomDirPatient.h"
6 #include "gdcmDirList.h"
7
8 #include <fstream>
9 #ifdef GDCM_NO_ANSI_STRING_STREAM
10 #  include <strstream>
11 #  define  ostringstream ostrstream
12 # else
13 #  include <sstream>
14 #endif
15
16 #define  ostringstream ostrstream
17
18 #include <sys/types.h>
19 #include <errno.h>
20
21 // for Directory pb
22 #ifdef _MSC_VER 
23    #include <windows.h> 
24    #include <direct.h>
25 #else
26    #include <dirent.h>   
27    #include <unistd.h>
28 #endif
29
30 #include <vector>
31 #include <algorithm>
32
33 // ---
34 void StartMethod(void *toto) {
35   (void)toto;
36    std::cout<<"Start parsing"<<std::endl;
37 }
38
39 void EndMethod(void *toto) {
40   (void)toto;
41    std::cout<<"End parsing"<<std::endl;
42 }
43 // ---
44
45 /**
46   * \ingroup Test
47   * \brief   Explores recursively the given directory (or GDCM_DATA_ROOT by default)
48   *          orders the gdcm-readable found Files
49   *          according their Patient/Study/Serie/Image characteristics
50   *          makes the gdcmDicomDir 
51   *          and writes a file named NewDICOMDIR..
52   */  
53
54 int main(int argc, char* argv[]) {
55    gdcmDicomDir *dcmdir;
56    std::string dirName;   
57
58    if (argc > 1)
59       dirName = argv[1];
60    else
61       dirName = GDCM_DATA_ROOT;
62
63    dcmdir=new gdcmDicomDir(dirName, true); // we ask for Directory parsing
64
65    dcmdir->SetStartMethod(StartMethod, (void *) NULL);
66    dcmdir->SetEndMethod(EndMethod);
67    
68    ListDicomDirPatient lp = dcmdir->GetDicomDirPatients();
69    if (! lp.size() ) 
70    {
71       std::cout << "makeDicomDir: no patient list present. Exiting."
72                 << std::endl;
73       return 1;
74    }
75     
76    dcmdir->WriteDicomDir("NewDICOMDIR");
77    std::cout<<std::flush;
78
79    delete dcmdir;
80    return 0;
81 }