]> Creatis software - gdcm.git/blob - Example/makeDicomDir.cxx
JPR
[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);
64    std::cout << "---after constructor; Print as a gdcmDocument ------" << std::endl;
65    ((gdcmDocument *)dcmdir)->Print();
66    std::cout << "---after constructor; Print as a DICOMDIR     ------" << std::endl;
67    dcmdir->Print();
68
69    dcmdir->SetStartMethod(StartMethod, (void *) NULL);
70    dcmdir->SetEndMethod(EndMethod);
71
72     std::cout << "---before ParseDirectory------------------" << std::endl;   
73    dcmdir->ParseDirectory();   
74    std::cout << "---after   ParseDirectory------------------" << std::endl;
75    
76    ListDicomDirPatient lp = dcmdir->GetDicomDirPatients();
77    if (! lp.size() ) 
78    {
79       std::cout << "makeDicomDir: no patient list present. Exiting."
80                 << std::endl;
81       return 1;
82    }
83    gdcmDicomDirPatient *p = *(lp.begin());
84    dcmdir->SetPrintLevel(2);
85    p->Print();
86    std::cout << "---------------------" << std::endl;   
87
88    dcmdir->SetPrintLevel(-1);
89    dcmdir->Print();
90
91    dcmdir->Write("NewDICOMDIR");
92    std::cout<<std::flush;
93
94    delete dcmdir;
95
96    return 0;
97 }