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