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