]> Creatis software - gdcm.git/blob - Example/MakeDicomDir.cxx
Use new style (NO_SHADOW NO_SEQ) for making a DICOMDIR
[gdcm.git] / Example / MakeDicomDir.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: MakeDicomDir.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/04/14 15:15:15 $
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
24 #include <iostream>
25
26 // ---
27 void StartMethod(void *toto) {
28   (void)toto;
29    std::cout<<"Start parsing"<<std::endl;
30 }
31
32 void EndMethod(void *toto) {
33   (void)toto;
34    std::cout<<"End parsing"<<std::endl;
35 }
36 // ---
37
38 /**
39   * \ingroup Test
40   * \brief   Explores recursively the given directory (or GDCM_DATA_ROOT by default)
41   *          orders the gdcm-readable found Files
42   *          according their Patient/Study/Serie/Image characteristics
43   *          makes the gdcmDicomDir 
44   *          and writes a file named NewDICOMDIR..
45   */  
46
47 int main(int argc, char *argv[]) 
48 {
49    //gdcm::Debug::DebugOn();
50    std::string dirName;   
51
52    if (argc > 1)
53    {
54       dirName = argv[1];
55    }
56    else
57    {
58       dirName = GDCM_DATA_ROOT;
59    }
60
61    gdcm::DicomDir *dcmdir;
62     // we ask for Directory parsing
63  
64     // Old style (still available) :
65     // dcmdir = new gdcm::DicomDir(dirName, true);
66
67    // new style (user is allowed no to load Sequences an/or Shadow Groups)
68    dcmdir = new gdcm::DicomDir( );
69    dcmdir->SetParseDir(true);
70    dcmdir->SetLoadMode(NO_SEQ | NO_SHADOW);
71    dcmdir->Load(dirName);
72
73    dcmdir->SetStartMethod(StartMethod, (void *) NULL);
74    dcmdir->SetEndMethod(EndMethod);
75    
76    if ( !dcmdir->GetFirstPatient() ) 
77    {
78       std::cout << "makeDicomDir: no patient found. Exiting."
79                 << std::endl;
80
81       delete dcmdir;
82       return 1;
83    }
84     
85    // Create the corresponding DicomDir
86    dcmdir->WriteDicomDir("NewDICOMDIR");
87    delete dcmdir;
88
89    // Read from disc the just written DicomDir
90    gdcm::DicomDir *newDicomDir = new gdcm::DicomDir("NewDICOMDIR");
91    if( !newDicomDir->IsReadable() )
92    {
93       std::cout<<"          Written DicomDir 'NewDICOMDIR'"
94                <<" is not readable"<<std::endl
95                <<"          ...Failed"<<std::endl;
96
97       delete newDicomDir;
98       return 1;
99    }
100
101    if( !newDicomDir->GetFirstPatient() )
102    {
103       std::cout<<"          Written DicomDir 'NewDICOMDIR'"
104                <<" has no patient"<<std::endl
105                <<"          ...Failed"<<std::endl;
106
107       delete newDicomDir;
108       return(1);
109    }
110
111    std::cout<<std::flush;
112
113    delete newDicomDir;
114    return 0;
115 }