]> Creatis software - gdcm.git/blob - Example/BuildUpDicomDir.cxx
a56fa9f8ab66a7ac01fe03f5422336609bf9f044
[gdcm.git] / Example / BuildUpDicomDir.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: BuildUpDicomDir.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/24 16:10:49 $
7   Version:   $Revision: 1.12 $
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 "gdcmDocEntry.h"
19 #include "gdcmDicomDir.h"
20 #include "gdcmDicomDirPatient.h"
21 #include "gdcmDirList.h"
22 #include "gdcmDebug.h"
23 #include "gdcmDicomDirStudy.h"
24 #include "gdcmDicomDirSerie.h"
25 #include "gdcmDicomDirImage.h"
26
27 // ===============================================================
28 /**
29   * \ingroup Test
30   * \brief   Builds up ex-nihilo a DICOMDIR file 
31   *          adding Patient, Study, Serie, Image descriptions
32   *          to an empty gdcmDicomDir occurence
33   *          and writes a file named NewDICOMDIR. 
34   */
35   
36 int main(int argc, char* argv[])
37 {
38    std::string dirName = "NewDICOMDIR";
39
40    if ( argc > 2 )
41       {
42       std::cerr << "Usage: " << argv[0] << " [dicomdirname] ";
43       dirName = argv[1];
44       }
45
46    gdcm::DicomDir *dcmdir;
47    dcmdir = new gdcm::DicomDir();
48
49    std::cout << "\n------- BuildUpDicomDir: Test Print Meta only -----" << std::endl;
50    ((gdcm::Document *)dcmdir)->Print();
51
52    gdcm::DicomDirPatient *p1=dcmdir->NewPatient();
53    p1->SetEntryValue("patientONE",0x0010, 0x0010);
54
55      
56    gdcm::DicomDirPatient *p2=dcmdir->NewPatient();
57    p2->SetEntryValue("patientTWO",0x0010, 0x0010);     
58    gdcm::DicomDirStudy *s21=p2->NewStudy();  
59        s21->SetEntryValue("StudyDescrTwo.One",0x0008, 0x1030);        
60    gdcm::DicomDirSerie *s211=s21->NewSerie();   
61    gdcm::DicomDirImage *s2111=s211->NewImage();
62    (void)s2111; //not used
63
64    gdcm::DicomDirStudy *s11=p1->NewStudy();  
65    s11->SetEntryValue("StudyDescrOne.One",0x0008, 0x1030);
66    // Name of the physician reading study
67    // Header Entry to be created
68    s11->SetEntryValue("Dr Mabuse",0x0008, 0x1060);
69
70    gdcm::DicomDirPatient *p3 = dcmdir->NewPatient();
71    p3->SetEntryValue("patientTHREE",0x0010, 0x0010);
72
73    std::cout << "\n------- BuildUpDicomDir: Test Print of Patient ONE -----\n";
74    p1->Print();
75    std::cout << "\n------- BuildUpDicomDir: Test Print of Patient THREE -----\n";
76    p3->Print();
77    std::cout << "\n------- BuildUpDicomDir: Test Print of Patient TWO -------\n";
78    p2->Print();
79    std::cout << "\n------- BuildUpDicomDir: Test Full Print-------------------\n";
80    dcmdir->SetPrintLevel(-1);
81    dcmdir->Print();
82
83    dcmdir->WriteDicomDir( dirName );
84    std::cout << std::endl;
85
86    delete dcmdir;
87
88    return 0;
89 }