]> Creatis software - gdcm.git/blob - Example/exBuildUpDicomDir.cxx
Unify user interface
[gdcm.git] / Example / exBuildUpDicomDir.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: exBuildUpDicomDir.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/07/07 17:31:54 $
7   Version:   $Revision: 1.2 $
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 -----" 
50              << std::endl;
51    ((gdcm::Document *)dcmdir)->Print();
52
53    gdcm::DicomDirPatient *p1=dcmdir->NewPatient();
54    p1->SetValEntry("patientONE",0x0010, 0x0010);
55
56      
57    gdcm::DicomDirPatient *p2=dcmdir->NewPatient();
58    p2->SetValEntry("patientTWO",0x0010, 0x0010);     
59    gdcm::DicomDirStudy *s21=p2->NewStudy();  
60        s21->SetValEntry("StudyDescrTwo.One",0x0008, 0x1030);        
61    gdcm::DicomDirSerie *s211=s21->NewSerie();   
62    gdcm::DicomDirImage *s2111=s211->NewImage();
63    (void)s2111; //not used
64
65    gdcm::DicomDirStudy *s11=p1->NewStudy();  
66    s11->SetValEntry("StudyDescrOne.One",0x0008, 0x1030);
67    // Name of the physician reading study
68    // Header Entry to be created
69    s11->SetValEntry("Dr Mabuse",0x0008, 0x1060);
70
71    gdcm::DicomDirPatient *p3 = dcmdir->NewPatient();
72    p3->SetValEntry("patientTHREE",0x0010, 0x0010);
73
74    std::cout << "\n------- BuildUpDicomDir: Test Print of Patient ONE -----\n";
75    p1->Print();
76    std::cout << "\n------- BuildUpDicomDir: Test Print of Patient THREE -----\n";
77    p3->Print();
78    std::cout << "\n------- BuildUpDicomDir: Test Print of Patient TWO -------\n";
79    p2->Print();
80    std::cout << "\n------- BuildUpDicomDir: Test Full Print-------------------\n";
81    dcmdir->SetPrintLevel(-1);
82    dcmdir->Print();
83
84    dcmdir->WriteDicomDir( dirName );
85    std::cout << std::endl;
86
87    delete dcmdir;
88
89    return 0;
90 }