]> Creatis software - gdcm.git/blob - Example/BuildUpDicomDir.cxx
ENH: gdcm now compiles on borland
[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 #if defined(_MSC_VER) || defined(__BORLANDC__) 
24    #include <windows.h> 
25    #include <direct.h>
26    #include <stdio.h>
27 #else
28    #include <dirent.h>   
29    #include <unistd.h>
30 #endif
31
32 #include <vector>
33 #include <algorithm>
34
35 // ===============================================================
36 /**
37   * \ingroup Test
38   * \brief   Builds up ex-nihilo a DICOMDIR file 
39   *          adding Patient, Study, Serie, Image descriptions
40   *          to an empty gdcmDicomDir occurence
41   *          and writes a file named NewDICOMDIR. 
42   */
43   
44 int main(int argc, char* argv[])
45 {
46    std::string dirName = "NewDICOMDIR";
47
48    if ( argc > 2 )
49       {
50       std::cerr << "Usage: " << argv[0] << " [dicomdirname] ";
51       dirName = argv[1];
52       }
53
54    gdcm::DicomDir *dcmdir;
55    dcmdir = new gdcm::DicomDir();
56
57    printf( "\n------- BuildUpDicomDir: Test Print Meta only -----\n");
58    ((gdcm::Document *)dcmdir)->Print();
59
60    gdcm::DicomDirPatient *p1=dcmdir->NewPatient();
61    p1->SetEntryByNumber("patientONE",0x0010, 0x0010);
62
63      
64    gdcm::DicomDirPatient *p2=dcmdir->NewPatient();
65    p2->SetEntryByNumber("patientTWO",0x0010, 0x0010);     
66    gdcm::DicomDirStudy *s21=p2->NewStudy();  
67        s21->SetEntryByNumber("StudyDescrTwo.One",0x0008, 0x1030);        
68    gdcm::DicomDirSerie *s211=s21->NewSerie();   
69    gdcm::DicomDirImage *s2111=s211->NewImage();
70    (void)s2111; //not used
71
72    gdcm::DicomDirStudy *s11=p1->NewStudy();  
73    s11->SetEntryByNumber("StudyDescrOne.One",0x0008, 0x1030);
74    // Name of the physician reading study
75    // Header Entry to be created
76    s11->SetEntryByNumber("Dr Mabuse",0x0008, 0x1060);
77
78    gdcm::DicomDirPatient *p3 = dcmdir->NewPatient();
79    p3->SetEntryByNumber("patientTHREE",0x0010, 0x0010);
80
81    std::cout << "\n------- BuildUpDicomDir: Test Print of Patient ONE -----\n";
82    p1->Print();
83    std::cout << "\n------- BuildUpDicomDir: Test Print of Patient THREE -----\n";
84    p3->Print();
85    std::cout << "\n------- BuildUpDicomDir: Test Print of Patient TWO -------\n";
86    p2->Print();
87    std::cout << "\n------- BuildUpDicomDir: Test Full Print-------------------\n";
88    dcmdir->SetPrintLevel(-1);
89    dcmdir->Print();
90
91    dcmdir->WriteDicomDir( dirName );
92    std::cout << std::endl;
93
94    delete dcmdir;
95
96    return 0;
97 }