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