]> Creatis software - gdcm.git/blob - src/gdcmDicomDir.h
Now the tree-like structure describing a DICOMDIR comming from an already
[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    inline float GetProgress(void)  {return(progress);};
79    inline void  AbortProgress(void){abort=true;      };
80    inline bool  IsAborted(void)    {return(abort);   };
81    
82 // Adding
83   gdcmDicomDirPatient * NewPatient(void);
84
85 // Write
86    bool Write(std::string fileName);
87
88 // Types
89    typedef enum
90    {
91       GDCM_DICOMDIR_NONE,
92       GDCM_DICOMDIR_META,
93       GDCM_DICOMDIR_PATIENT,
94       GDCM_DICOMDIR_STUDY,
95       GDCM_DICOMDIR_SERIE,
96       GDCM_DICOMDIR_IMAGE,
97    } gdcmDicomDirType;
98    
99 protected:
100    void CreateDicomDirChainedList(std::string path);
101
102    void CallStartMethod(void);
103    void CallProgressMethod(void);
104    void CallEndMethod(void);
105
106 private:
107    void CreateDicomDir(void);
108    void AddObjectToEnd(gdcmDicomDirType type,
109                                 ListTag::iterator begin,ListTag::iterator end);
110    void AddDicomDirMetaToEnd   (ListTag::iterator begin,ListTag::iterator end);
111    void AddDicomDirPatientToEnd(ListTag::iterator begin,ListTag::iterator end);
112    void AddDicomDirStudyToEnd  (ListTag::iterator begin,ListTag::iterator end);
113    void AddDicomDirSerieToEnd  (ListTag::iterator begin,ListTag::iterator end);
114    void AddDicomDirImageToEnd  (ListTag::iterator begin,ListTag::iterator end);
115
116    void SetElements(std::string &path,ListHeader &list);
117    void SetElement (std::string &path,gdcmDicomDirType type,gdcmHeader *header);
118    
119    void UpdateDirectoryRecordSequenceLength(void);
120
121    static bool HeaderLessThan(gdcmHeader *header1,gdcmHeader *header2);
122    void WriteDicomDirEntries(FILE *_fp);   
123    
124 // Variables
125 /**
126 * \brief pointer on *the* gdcmObject 'DicomDirMeta Elements'
127 */
128    gdcmDicomDirMeta *metaElems;
129 /**
130 * \brief chained list of DicomDirPatient (to be exploited recursively)
131 */   
132    ListDicomDirPatient patients;
133
134    gdcmMethod *startMethod;
135    gdcmMethod *progressMethod;
136    gdcmMethod *endMethod;
137    gdcmMethod *startMethodArgDelete;
138    gdcmMethod *progressMethodArgDelete;
139    gdcmMethod *endMethodArgDelete;
140    void *startArg;
141    void *progressArg;
142    void *endArg;
143
144    float progress;
145    bool abort;
146 };
147
148 //-----------------------------------------------------------------------------
149 #endif