]> Creatis software - gdcm.git/blob - src/gdcmDicomDir.h
* src/gdcmParser.[cxx|h] and gdcmHeader.[cxx.h]: gdcmHeader::Write split
[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 class GDCM_EXPORT gdcmDicomDir: public gdcmParser
28 {
29 public:
30 //   gdcmDicomDir(ListTag *l,
31 //                bool exception_on_error = false);
32    gdcmDicomDir(const char *FileName, 
33                 bool parseDir = false,
34                 bool exception_on_error = false);
35    gdcmDicomDir(bool exception_on_error = false); 
36                    
37    ~gdcmDicomDir(void);
38
39    /**
40     * \ingroup gdcmParser
41     * \brief   Sets the print level for the Dicom Header 
42     * \note    0 for Light Print; 1 for 'medium' Print, 2 for Heavy
43     */
44    void SetPrintLevel(int level) 
45       { printLevel = level; };
46   /**
47     * \ingroup gdcmParser
48     * \brief   canonical Printer 
49     * \sa    SetPrintLevel
50   */     
51    virtual void Print(std::ostream &os = std::cout);
52
53 // Informations contained in the parser
54    virtual bool IsReadable(void);
55 /**
56  * \ingroup gdcmDicomDir
57  * \brief   returns a pointer to the gdcmDicomDirMeta for this DICOMDIR.
58  */   
59    inline gdcmDicomDirMeta   *GetDicomDirMeta()      
60       {return metaElems;};
61 /**
62  * \ingroup gdcmDicomDir
63  * \brief   returns the PATIENT chained List for this DICOMDIR.
64  */      
65    inline ListDicomDirPatient &GetDicomDirPatients() 
66       {return patients;};
67
68 // Parsing
69    void ParseDirectory(void);
70    void CheckBoundaries(void);
71    
72    void SetStartMethod(gdcmMethod *,void * =NULL,gdcmMethod * =NULL);
73    void SetStartMethodArgDelete(gdcmMethod *);
74    void SetProgressMethod(gdcmMethod *,void * =NULL,gdcmMethod * =NULL);
75    void SetProgressMethodArgDelete(gdcmMethod *);
76    void SetEndMethod(gdcmMethod *,void * =NULL,gdcmMethod * =NULL);
77    void SetEndMethodArgDelete(gdcmMethod *);
78 /**
79  * \ingroup gdcmDicomDir
80  * \brief   GetProgress.
81  */ 
82    inline float GetProgress(void)  
83       {return(progress);};
84 /**
85  * \ingroup gdcmDicomDir
86  * \brief   AbortProgress.
87  */   inline void  AbortProgress(void)
88       {abort=true;      };
89 /**
90  * \ingroup gdcmDicomDir
91  * \brief   IsAborted.
92  */   inline bool  IsAborted(void)
93       {return(abort);   };
94    
95 // Adding
96   gdcmDicomDirPatient * NewPatient(void);
97
98 // Write
99    void WriteEntries(FILE *_fp);   
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    
137 // Variables
138 /**
139 * \brief pointer on *the* gdcmObject 'DicomDirMeta Elements'
140 */
141    gdcmDicomDirMeta *metaElems;
142 /**
143 * \brief chained list of DicomDirPatient (to be exploited recursively)
144 */   
145    ListDicomDirPatient patients;
146
147 /// pointer to the initialisation method for any progress bar   
148    gdcmMethod *startMethod;
149 /// pointer to the incrementation method for any progress bar
150     gdcmMethod *progressMethod;
151 /// pointer to the tremination method for any progress bar
152    gdcmMethod *endMethod;
153 /// pointer to the ??? method for any progress bar   
154    gdcmMethod *startMethodArgDelete;
155 /// pointer to the ??? method for any progress bar
156    gdcmMethod *progressMethodArgDelete;
157 /// pointer to the ??? method for any progress bar
158    gdcmMethod *endMethodArgDelete;
159 /// pointer to the ??? for any progress bar   
160    void *startArg;
161 /// pointer to the ??? for any progress bar
162    void *progressArg;
163 /// pointer to the ??? for any progress bar   
164    void *endArg;
165 /// value of the ??? for any progress bar
166    float progress;
167 /// value of the ??? for any progress bar   
168    bool abort;
169 };
170
171 //-----------------------------------------------------------------------------
172 #endif