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