]> Creatis software - gdcm.git/blob - Example/BuildUpDicomDir.cxx
update my tasks
[gdcm.git] / Example / BuildUpDicomDir.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: BuildUpDicomDir.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/11/16 04:26:17 $
7   Version:   $Revision: 1.8 $
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 <iostream>
19 #include "gdcm.h"
20 #include "gdcmDocEntry.h"
21 #include "gdcmDicomDir.h"
22 #include "gdcmDicomDirPatient.h"
23 #include "gdcmDirList.h"
24 #include "gdcmDebug.h"
25
26 #include <fstream>
27 #ifdef GDCM_NO_ANSI_STRING_STREAM
28 #  include <strstream>
29 #  define  ostringstream ostrstream
30 # else
31 #  include <sstream>
32 #endif
33
34 #define  ostringstream ostrstream
35
36 #include <sys/types.h>
37 #include <errno.h>
38
39 // for Directory pb
40 #if defined(_MSC_VER) || defined(__BORLANDC__) 
41    #include <windows.h> 
42    #include <direct.h>
43    #include <stdio.h>
44 #else
45    #include <dirent.h>   
46    #include <unistd.h>
47 #endif
48
49 #include <vector>
50 #include <algorithm>
51
52 // ===============================================================
53 /**
54   * \ingroup Test
55   * \brief   Builds up ex-nihilo a DICOMDIR file 
56   *          adding Patient, Study, Serie, Image descriptions
57   *          to an empty gdcmDicomDir occurence
58   *          and writes a file named NewDICOMDIR. 
59   */
60   
61 int main(int argc, char* argv[])
62 {
63    std::string dirName = "NewDICOMDIR";
64
65    if ( argc > 2 )
66       {
67       std::cerr << "Usage: " << argv[0] << " [dicomdirname] ";
68       dirName = argv[1];
69       }
70
71    gdcm::DicomDir *dcmdir;
72    dcmdir = new gdcm::DicomDir();
73
74    printf( "\n------- BuildUpDicomDir: Test Print Meta only -----\n");
75    ((gdcm::Document *)dcmdir)->Print();
76
77    gdcm::DicomDirPatient *p1=dcmdir->NewPatient();
78    p1->SetEntryByNumber("patientONE",0x0010, 0x0010);
79
80      
81    gdcm::DicomDirPatient *p2=dcmdir->NewPatient();
82    p2->SetEntryByNumber("patientTWO",0x0010, 0x0010);     
83    gdcm::DicomDirStudy *s21=p2->NewStudy();  
84        s21->SetEntryByNumber("StudyDescrTwo.One",0x0008, 0x1030);        
85    gdcm::DicomDirSerie *s211=s21->NewSerie();   
86    gdcm::DicomDirImage *s2111=s211->NewImage();
87    (void)s2111; //not used
88
89    gdcm::DicomDirStudy *s11=p1->NewStudy();  
90    s11->SetEntryByNumber("StudyDescrOne.One",0x0008, 0x1030);
91    // Name of the physician reading study
92    // Header Entry to be created
93    s11->SetEntryByNumber("Dr Mabuse",0x0008, 0x1060);
94
95    gdcm::DicomDirPatient *p3 = dcmdir->NewPatient();
96    p3->SetEntryByNumber("patientTHREE",0x0010, 0x0010);
97
98    std::cout << "\n------- BuildUpDicomDir: Test Print of Patient ONE -----\n";
99    p1->Print();
100    std::cout << "\n------- BuildUpDicomDir: Test Print of Patient THREE -----\n";
101    p3->Print();
102    std::cout << "\n------- BuildUpDicomDir: Test Print of Patient TWO -------\n";
103    p2->Print();
104    std::cout << "\n------- BuildUpDicomDir: Test Full Print-------------------\n";
105    dcmdir->SetPrintLevel(-1);
106    dcmdir->Print();
107
108    dcmdir->WriteDicomDir( dirName );
109    std::cout << std::endl;
110
111    delete dcmdir;
112
113    return 0;
114 }