]> Creatis software - gdcm.git/blob - Example/BuildUpDicomDir.cxx
ENH: Refactor some code
[gdcm.git] / Example / BuildUpDicomDir.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 #include "gdcmDebug.h"
8
9 #include <fstream>
10 #ifdef GDCM_NO_ANSI_STRING_STREAM
11 #  include <strstream>
12 #  define  ostringstream ostrstream
13 # else
14 #  include <sstream>
15 #endif
16
17 #define  ostringstream ostrstream
18
19 #include <sys/types.h>
20 #include <errno.h>
21
22 // for Directory pb
23 #ifdef _MSC_VER 
24    #include <windows.h> 
25    #include <direct.h>
26 #else
27    #include <dirent.h>   
28    #include <unistd.h>
29 #endif
30
31 #include <vector>
32 #include <algorithm>
33
34 // ===============================================================
35 /**
36   * \ingroup Test
37   * \brief   Builds up ex-nihilo a DICOMDIR file 
38   *          adding Patient, Study, Serie, Image descriptions
39   *          to an empty gdcmDicomDir occurence
40   *          and writes a file named NewDICOMDIR. 
41   */
42   
43 int main(int argc, char* argv[])
44 {
45    std::string dirName = "NewDICOMDIR";
46
47    if ( argc > 2 )
48       {
49       std::cerr << "Usage: " << argv[0] << " [dicomdirname] ";
50       dirName = argv[1];
51       }
52
53    gdcmDicomDir *dcmdir;
54    
55
56    printf( "BuildUpDicomDir: entering  BuildUpDicomDir\n");
57
58    dcmdir=new gdcmDicomDir();
59    printf( "BuildUpDicomDir: exiting new DicomDir\n");
60
61    printf( "\n------- BuildUpDicomDir: Test Print Meta only -----\n");
62    ((gdcmDocument *)dcmdir)->Print();
63
64    gdcmDicomDirPatient *p1=dcmdir->NewPatient();
65    p1->SetEntryByNumber("patientONE",0x0010, 0x0010);
66
67      
68    gdcmDicomDirPatient *p2=dcmdir->NewPatient();
69    p2->SetEntryByNumber("patientTWO",0x0010, 0x0010);     
70    gdcmDicomDirStudy *s21=p2->NewStudy();  
71        s21->SetEntryByNumber("StudyDescrTwo.One",0x0008, 0x1030);        
72    gdcmDicomDirSerie *s211=s21->NewSerie();   
73    gdcmDicomDirImage *s2111=s211->NewImage();
74    (void)s2111; //not used
75
76    gdcmDicomDirStudy *s11=p1->NewStudy();  
77    s11->SetEntryByNumber("StudyDescrOne.One",0x0008, 0x1030);
78    // Name of the physician reading study
79    // Header Entry to be created
80    s11->SetEntryByNumber("Dr Mabuse",0x0008, 0x1060);
81
82    gdcmDicomDirPatient *p3 = dcmdir->NewPatient();
83    p3->SetEntryByNumber("patientTHREE",0x0010, 0x0010);
84
85    std::cout << "\n------- BuildUpDicomDir: Test Print of Patient ONE -----\n";
86    p1->Print();
87    std::cout << "\n------- BuildUpDicomDir: Test Print of Patient THREE -----\n";
88    p3->Print();
89    std::cout << "\n------- BuildUpDicomDir: Test Print of Patient TWO -------\n";
90    p2->Print();
91    std::cout << "\n------- BuildUpDicomDir: Test Full Print-------------------\n";
92    dcmdir->SetPrintLevel(-1);
93    dcmdir->Print();
94
95    dcmdir->Write( dirName );
96    std::cout << std::endl;
97
98    delete dcmdir;
99
100    return 0;
101 }