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