]> Creatis software - gdcm.git/blob - src/gdcmDicomDir.h
ENH: Cautiously apply first cleanup patch
[gdcm.git] / src / gdcmDicomDir.h
1 /*=========================================================================
2   
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDir.h,v $
5   Language:  C++
6   Date:      $Date: 2004/07/17 22:36:55 $
7   Version:   $Revision: 1.24 $
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.htm 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
19 #ifndef GDCMDICOMDIR_H
20 #define GDCMDICOMDIR_H
21
22 #include "gdcmCommon.h"
23 #include "gdcmDocument.h"
24 #include "gdcmDicomDirPatient.h"
25 #include "gdcmDicomDirMeta.h"
26 #include "gdcmDicomDirElement.h"
27
28 #include <list>
29 #include <vector>
30
31 //-----------------------------------------------------------------------------
32 typedef std::list<gdcmDicomDirPatient*>   ListDicomDirPatient;
33 typedef std::vector<gdcmDocument*>  VectDocument;
34
35 typedef GDCM_EXPORT void(gdcmMethod)(void * = NULL);
36 //-----------------------------------------------------------------------------
37
38 /**
39  * \ingroup gdcmDicomDir
40  * \brief    gdcmDicomDir defines an object representing a DICOMDIR in memory.
41  *
42  */
43 class GDCM_EXPORT gdcmDicomDir: public gdcmDocument
44 {
45 public:
46    gdcmDicomDir(std::string const & fileName, 
47                 bool parseDir = false,
48                 bool exception_on_error = false);
49    gdcmDicomDir(bool exception_on_error = false); 
50                    
51    ~gdcmDicomDir();
52
53    /// \brief Sets the print level for the Dicom Header 
54    /// \note    0 for Light Print; 1 for 'medium' Print, 2 for Heavy
55    void SetPrintLevel(int level) 
56       { printLevel = level; };
57
58    /// \brief   canonical Printer 
59    /// \sa    SetPrintLevel
60    virtual void Print(std::ostream &os = std::cout);
61
62 // Informations contained in the parser
63    virtual bool IsReadable();
64
65    /// Returns a pointer to the gdcmDicomDirMeta for this DICOMDIR. 
66    gdcmDicomDirMeta* GetDicomDirMeta() { return metaElems; };
67
68    /// Returns the PATIENT chained List for this DICOMDIR.    
69    ListDicomDirPatient &GetDicomDirPatients() { return patients; };
70
71 // Parsing
72    void ParseDirectory();
73    
74    void SetStartMethod(gdcmMethod *,void * =NULL,gdcmMethod * =NULL);
75    void SetStartMethodArgDelete(gdcmMethod *);
76    void SetProgressMethod(gdcmMethod *,void * =NULL,gdcmMethod * =NULL);
77    void SetProgressMethodArgDelete(gdcmMethod *);
78    void SetEndMethod(gdcmMethod *,void * =NULL,gdcmMethod * =NULL);
79    void SetEndMethodArgDelete(gdcmMethod *);
80
81    /// GetProgress GetProgress
82    float GetProgress()  { return progress; };
83
84    /// AbortProgress AbortProgress
85    void  AbortProgress() {abort = true; };
86
87    /// IsAborted IsAborted
88    bool  IsAborted() { return abort; };
89    
90 // Adding
91    gdcmDicomDirMeta*    NewMeta();
92    gdcmDicomDirPatient* NewPatient();
93
94 // Write
95    void WriteEntries(FILE *_fp);   
96    bool Write(std::string const & fileName);
97
98    /// Types of the gdcmObject within the gdcmDicomDir
99    typedef enum
100    {
101       GDCM_DICOMDIR_NONE,
102       GDCM_DICOMDIR_META,
103       GDCM_DICOMDIR_PATIENT,
104       GDCM_DICOMDIR_STUDY,
105       GDCM_DICOMDIR_SERIE,
106       GDCM_DICOMDIR_IMAGE,
107    } gdcmDicomDirType;
108    
109 protected:
110    void CreateDicomDirChainedList(std::string const & path);
111    void CallStartMethod();
112    void CallProgressMethod();
113    void CallEndMethod();
114
115 private:
116    void Initialize();
117    void CreateDicomDir();
118    void AddDicomDirMeta();
119    void AddDicomDirPatientToEnd(gdcmSQItem *s);
120    void AddDicomDirStudyToEnd  (gdcmSQItem *s);
121    void AddDicomDirSerieToEnd  (gdcmSQItem *s);
122    void AddDicomDirImageToEnd  (gdcmSQItem *s);
123
124    void SetElements(std::string &path, VectDocument &list);
125    void SetElement (std::string &path,gdcmDicomDirType type,
126                     gdcmDocument *header);
127    
128    void UpdateDirectoryRecordSequenceLength();
129
130    static bool HeaderLessThan(gdcmDocument *header1,gdcmDocument *header2);
131    
132 // Variables
133
134    /// Pointer on *the* gdcmObject 'DicomDirMeta Elements'
135    gdcmDicomDirMeta *metaElems;
136
137    /// Chained list of DicomDirPatient (to be exploited recursively) 
138    ListDicomDirPatient patients;
139
140 /// pointer to the initialisation method for any progress bar   
141    gdcmMethod *startMethod;
142 /// pointer to the incrementation method for any progress bar
143     gdcmMethod *progressMethod;
144 /// pointer to the termination method for any progress bar
145    gdcmMethod *endMethod;
146 /// pointer to the ??? method for any progress bar   
147    gdcmMethod *startMethodArgDelete;
148 /// pointer to the ??? method for any progress bar
149    gdcmMethod *progressMethodArgDelete;
150 /// pointer to the ??? method for any progress bar
151    gdcmMethod *endMethodArgDelete;
152 /// pointer to the ??? for any progress bar   
153    void *startArg;
154 /// pointer to the ??? for any progress bar
155    void *progressArg;
156 /// pointer to the ??? for any progress bar   
157    void *endArg;
158 /// value of the ??? for any progress bar
159    float progress;
160 /// value of the ??? for any progress bar   
161    bool abort;
162 };
163
164 //-----------------------------------------------------------------------------
165 #endif